@bitcoinerlab/miniscript-policies 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Makefile +14 -0
- package/README.md +34 -0
- package/dist/index.js +204 -0
- package/example.js +34 -0
- package/js_bindings.cpp +154 -0
- package/package.json +52 -0
- package/patches/uppercase-h.patch +11 -0
- package/rollup.config.js +13 -0
- package/src/index.js +5 -0
- package/src/miniscript.js +149 -0
- package/test/fixtures.js +898 -0
- package/test/miniscript.test.js +21 -0
- package/test/policy.test.js +20 -0
- package/types/index.d.ts +14 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { compileMiniscript, ready } from '../dist/index.js';
|
|
2
|
+
import { primitives, timeLocks, other } from './fixtures.js';
|
|
3
|
+
|
|
4
|
+
const createGroupTest = (description, fixtures) =>
|
|
5
|
+
describe(description, () => {
|
|
6
|
+
beforeAll(async () => {
|
|
7
|
+
await ready;
|
|
8
|
+
});
|
|
9
|
+
for (const [testName, fixture] of Object.entries(fixtures)) {
|
|
10
|
+
if (!fixture.throws) {
|
|
11
|
+
test(testName, () => {
|
|
12
|
+
const script = compileMiniscript(fixture.miniscript).asm;
|
|
13
|
+
expect(script).toEqual(fixture.script);
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
createGroupTest('Primitives', primitives);
|
|
20
|
+
createGroupTest('Timelocks', timeLocks);
|
|
21
|
+
createGroupTest('Other', other);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { compileMiniscript, compilePolicy, ready } from '../dist/index.js';
|
|
2
|
+
|
|
3
|
+
describe('Policy compile smoke test', () => {
|
|
4
|
+
beforeAll(async () => {
|
|
5
|
+
await ready;
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
test('compilePolicy round-trips to compileMiniscript', () => {
|
|
9
|
+
const policy = 'or(and(pk(A),older(8640)),pk(B))';
|
|
10
|
+
const { miniscript, asm: asmFromPolicy, issane: issaneFromPolicy } =
|
|
11
|
+
compilePolicy(policy);
|
|
12
|
+
|
|
13
|
+
const { asm: asmFromMiniscript, issane: issaneFromMiniscript } =
|
|
14
|
+
compileMiniscript(miniscript);
|
|
15
|
+
|
|
16
|
+
expect(miniscript.length).toBeGreaterThan(0);
|
|
17
|
+
expect(asmFromPolicy).toEqual(asmFromMiniscript);
|
|
18
|
+
expect(issaneFromPolicy).toEqual(issaneFromMiniscript);
|
|
19
|
+
});
|
|
20
|
+
});
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const compilePolicy: (miniscript: string) => {
|
|
2
|
+
miniscript: string;
|
|
3
|
+
asm: string;
|
|
4
|
+
issane: boolean;
|
|
5
|
+
issanesublevel: boolean;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export declare const compileMiniscript: (miniscript: string) => {
|
|
9
|
+
asm: string;
|
|
10
|
+
issane: boolean;
|
|
11
|
+
issanesublevel: boolean;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export declare const ready: Promise<void>;
|