-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
37 lines (30 loc) · 1.03 KB
/
example.js
File metadata and controls
37 lines (30 loc) · 1.03 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
// To run it: "node ./example.js"
const { compilePolicy, compilePolicyTaproot, ready } = require("./dist/index.js");
(async () => {
await ready;
const p2wshPolicy = "or(and(pk(A),older(8640)),pk(B))";
const taprootPolicy =
"or(and(thresh(2,pk(A),pk(B),pk(C)),and(thresh(2,pk(D),sha256(H),older(144)),after(700000))),and(pk(E),hash160(H)))";
const p2wsh = compilePolicy(p2wshPolicy);
const taproot = compilePolicyTaproot(taprootPolicy);
if (!p2wsh.issane) {
console.warn("Policy result is not sane for P2WSH:", p2wsh.miniscript);
} else {
console.log({
policy: p2wshPolicy,
miniscript: p2wsh.miniscript,
asm: p2wsh.asm,
issane: p2wsh.issane,
});
}
if (!taproot.issane) {
console.warn("Policy result is not sane for tapscript:", taproot.miniscript);
} else {
console.log({
policy: taprootPolicy,
taprootMiniscript: taproot.miniscript,
hasMultiA: taproot.miniscript.includes("multi_a("),
hasNestedThresh: taproot.miniscript.includes("thresh(")
});
}
})();