-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.scratch.ts
More file actions
90 lines (86 loc) · 4 KB
/
.scratch.ts
File metadata and controls
90 lines (86 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// TODO:
/* https://github.com/BlockstreamResearch/SimplicityHL/blob/master/examples/escrow_with_delay.simf
* https://docs.ivylang.org/bitcoin/language/ExampleContracts.html#escrowwithdelay */
//function EscrowProgram ({
//sender = '0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798',
//recipient = '0xc6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5',
//escrow = '0xf9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9',
//timeout = '1000',
//} = {}) { return `
//fn main () {
//// Depending on provided witness:
//match witness::TRANSFER_OR_TIMEOUT {
//// Transfer to receiver:
//Left(maybe_sigs: [Option<Signature>; 3]) => spend_confirm(maybe_sigs),
//// or return to sender:
//Right(sender_sig: Signature) => spend_revoke(sender_sig), } }
//fn spend_revoke (sender_sig: Signature) {
//checksig(${sender}, sender_sig);
//jet::check_lock_distance(${timeout}); }
//fn spend_confirm (maybe_sigs: [Option<Signature>; 3]) {
//let threshold: u8 = 2;
//let [sig1, sig2, sig3]: [Option<Signature>; 3] = maybe_sigs;
//let counter1: u8 = checksig_add(0, ${sender}, sig1);
//let counter2: u8 = checksig_add(counter1, ${recipient}, sig2);
//let counter3: u8 = checksig_add(counter2, ${escrow}, sig3);
//assert!(jet::eq_8(counter3, threshold)); }
//fn checksig_add (counter: u8, pk: Pubkey, maybe_sig: Option<Signature>) -> u8 {
//match maybe_sig {
//None => counter,
//Some(sig: Signature) => {
//checksig(pk, sig);
//let (carry, new_counter): (bool, u8) = jet::increment_8(counter);
//assert!(not(carry));
//new_counter } } }
//fn checksig (pk: Pubkey, sig: Signature) {
//jet::bip_0340_verify((pk, jet::sig_all_hash()), sig); }
//fn not (bit: bool) -> bool {
//<u1>::into(jet::complement_1(<bool>::into(bit))) }
//` }
//function EscrowProgramWitness (
//value = "Right(0xedb6865094260f8558728233aae017dd0969a2afe5f08c282e1ab659bf2462684c99a64a2a57246358a0d632671778d016e6df7381293dd5bb9f0999d38640d4)",
//) { return { TRANSFER_OR_TIMEOUT: Either('[Option<Signature>; 3]', 'Signature', value) } }
//[>* Test cmr_to_p2tr on a given example. <]
//function testAddress ({ cmr, p2tr: expectedP2TR }: Example) {
//return (cmrToP2TR: Fn) => {
//throws(()=>cmrToP2TR());
//if (cmr) {
//const p2tr = cmrToP2TR(cmr);
//if (expectedP2TR) equal(p2tr, expectedP2TR);
//}
//return cmrToP2TR
//}
//}
//[>* Test compile on a given example. <]
//function testCompile ({ src, cmr }: Example) {
//return Fn.Name(`Compile (${src.length}b)`, (compile: Fn) => {
//const result = compile(src, {}) as { toJSON: Fn.Returns<{ cmr: unknown }> };
//if (cmr) equal(result.toJSON().cmr, cmr);
//return compile;
//});
//}
//// - more complex signing
//Example("pay to pubkey hash", `fn sha2 (string: u256) -> u256 {
//let hasher: Ctx8 = jet::sha_256_ctx_8_init();
//let hasher: Ctx8 = jet::sha_256_ctx_8_add_32(hasher, string);
//jet::sha_256_ctx_8_finalize(hasher)
//}
//fn main () {
//let pk: Pubkey = witness::PUB;
//assert!(jet::eq_256(sha2(pk), param::PKH));
//jet::bip_0340_verify((pk, jet::sig_all_hash()), witness::SIG)
//}`, {
//fee: 2.7e-7,
//cmr: 'e65e19e139a13583a0a7efb24be13c20d578f06f51b2a7fe7c7b9097072dbabe',
//p2tr: 'ert1psfhg3z9z6mjravcyysv84krhgg6wv8em0w7rpxcfac8nshkzy0tscparek',
//paramTypes: { PKH: "u256" },
//witnessTypes: { SIG: "[u8; 64]", PUB: "u256" },
//provideParams: () => ({
//PKH: SimplicityHL.Arg.Pubkey(KEYPAIR.xOnlyPublicKey()) [>FIXME hashit<]
//}),
//provideWitness: (sighash: Uint8Array<ArrayBufferLike>) => ({
//SIG: SimplicityHL.Arg.Signature(KEYPAIR.signSchnorr(sighash)),
//PUB: SimplicityHL.Arg.Pubkey(KEYPAIR.xOnlyPublicKey()),
//}),
//}),
//// - multisig: TODO