Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/wasm-miniscript/.prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
js/wasm
target/
test/fixtures/
target/
5 changes: 1 addition & 4 deletions packages/wasm-miniscript/src/try_into_js_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,7 @@ impl<Pk: MiniscriptKey + TryIntoJsValue> TryIntoJsValue for WshInner<Pk> {

impl<Pk: MiniscriptKey + TryIntoJsValue> TryIntoJsValue for Tr<Pk> {
fn try_to_js_value(&self) -> Result<JsValue, JsError> {
js_obj!(
"internalKey" => self.internal_key(),
"tree" => self.tap_tree()
)
Ok(js_arr!(self.internal_key(), self.tap_tree()))
}
}

Expand Down
6 changes: 6 additions & 0 deletions packages/wasm-miniscript/test/descriptorFixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,12 @@ export const fixtures = {
script: "a914767e9119ff3b3ac0cb6dcfe21de1842ccf85f1c487",
checksumRequired: false,
},
{
descriptor:
"tr(50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0,multi_a(2,xpub661MyMwAqRbcFXS2qwsTkaFc7PEpwDXWgY1Hx2MS7XywhW24sTjQzxiUgnGNW5v6DsW9Z8JcAqf8a22v21jDSA3DwLbbpt2ra3WbP83QNvP/0/0,xpub661MyMwAqRbcGfiaWcoeKLerFu3qRfy6zSYAwnmxSKW8JSauRajFsAsRHs2pV4q5rxkb4ynx4Bm8t54McTCp8V27s7XsdpD8T4s56etpjro/0/0,xpub661MyMwAqRbcH4HzWiCwmYajy1SXZngxHvpYDNEX4xjrDAneAm6rnpPuPPXcBRsSgxupDBmH2tzPHkikNrnLbsvTHemPFHSFbZxonZcCwFi/0/0))#82q34xv2",
script: "51207e8c409f0ab01197f9676efc3a9505f1f09ed0f21693e46a3aa3b6b54d437aa2",
checksumRequired: true,
},
],
invalid: [
{
Expand Down
20 changes: 20 additions & 0 deletions packages/wasm-miniscript/test/descriptorUtil.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
import * as fs from "fs/promises";
import * as utxolib from "@bitgo/utxo-lib";
import { Descriptor } from "../js";
import * as assert from "node:assert";

async function assertEqualJSON(path: string, value: unknown): Promise<void> {
try {
const data = JSON.parse(await fs.readFile(path, "utf8"));
assert.deepStrictEqual(data, value);
} catch (e: any) {
if (e.code === "ENOENT") {
await fs.writeFile(path, JSON.stringify(value, null, 2));
throw new Error("Expected file not found, wrote it instead");
}
throw e;
}
}

export async function assertEqualAst(path: string, descriptor: Descriptor): Promise<void> {
await assertEqualJSON(path, { descriptor: descriptor.toString(), ast: descriptor.node() });
}

/** Expand a template with the given root wallet keys and chain code */
function expand(template: string, rootWalletKeys: utxolib.bitgo.RootWalletKeys, chainCode: number) {
Expand Down
12 changes: 12 additions & 0 deletions packages/wasm-miniscript/test/fixtures/0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"descriptor": "pk(03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd)#9pcxlpvx",
"ast": {
"Bare": {
"Check": {
"PkK": {
"Single": "03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd"
}
}
}
}
}
12 changes: 12 additions & 0 deletions packages/wasm-miniscript/test/fixtures/1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"descriptor": "pk(03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd)#9pcxlpvx",
"ast": {
"Bare": {
"Check": {
"PkK": {
"Single": "03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd"
}
}
}
}
}
8 changes: 8 additions & 0 deletions packages/wasm-miniscript/test/fixtures/10.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"descriptor": "pkh(04a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd5b8dec5235a0fa8722476c7709c02559e3aa73aa03918ba2d492eea75abea235)#9907vvwz",
"ast": {
"Pkh": {
"Single": "04a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd5b8dec5235a0fa8722476c7709c02559e3aa73aa03918ba2d492eea75abea235"
}
}
}
8 changes: 8 additions & 0 deletions packages/wasm-miniscript/test/fixtures/11.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"descriptor": "pkh(04a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd5b8dec5235a0fa8722476c7709c02559e3aa73aa03918ba2d492eea75abea235)#9907vvwz",
"ast": {
"Pkh": {
"Single": "04a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd5b8dec5235a0fa8722476c7709c02559e3aa73aa03918ba2d492eea75abea235"
}
}
}
14 changes: 14 additions & 0 deletions packages/wasm-miniscript/test/fixtures/12.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"descriptor": "sh(pk(03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd))#s53ls94y",
"ast": {
"Sh": {
"Ms": {
"Check": {
"PkK": {
"Single": "03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd"
}
}
}
}
}
}
14 changes: 14 additions & 0 deletions packages/wasm-miniscript/test/fixtures/13.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"descriptor": "sh(pk(03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd))#s53ls94y",
"ast": {
"Sh": {
"Ms": {
"Check": {
"PkK": {
"Single": "03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd"
}
}
}
}
}
}
14 changes: 14 additions & 0 deletions packages/wasm-miniscript/test/fixtures/14.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"descriptor": "sh(pkh(03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd))#dr3u9ynx",
"ast": {
"Sh": {
"Ms": {
"Check": {
"PkH": {
"Single": "03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd"
}
}
}
}
}
}
14 changes: 14 additions & 0 deletions packages/wasm-miniscript/test/fixtures/15.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"descriptor": "sh(pkh(03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd))#dr3u9ynx",
"ast": {
"Sh": {
"Ms": {
"Check": {
"PkH": {
"Single": "03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd"
}
}
}
}
}
}
14 changes: 14 additions & 0 deletions packages/wasm-miniscript/test/fixtures/16.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"descriptor": "wsh(pk(03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd))#35m26dd5",
"ast": {
"Wsh": {
"Ms": {
"Check": {
"PkK": {
"Single": "03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd"
}
}
}
}
}
}
14 changes: 14 additions & 0 deletions packages/wasm-miniscript/test/fixtures/17.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"descriptor": "wsh(pk(03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd))#35m26dd5",
"ast": {
"Wsh": {
"Ms": {
"Check": {
"PkK": {
"Single": "03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd"
}
}
}
}
}
}
14 changes: 14 additions & 0 deletions packages/wasm-miniscript/test/fixtures/18.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"descriptor": "wsh(pkh(03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd))#c2m8h006",
"ast": {
"Wsh": {
"Ms": {
"Check": {
"PkH": {
"Single": "03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd"
}
}
}
}
}
}
14 changes: 14 additions & 0 deletions packages/wasm-miniscript/test/fixtures/19.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"descriptor": "wsh(pkh(03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd))#c2m8h006",
"ast": {
"Wsh": {
"Ms": {
"Check": {
"PkH": {
"Single": "03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd"
}
}
}
}
}
}
8 changes: 8 additions & 0 deletions packages/wasm-miniscript/test/fixtures/2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"descriptor": "pkh(03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd)#wf36a0pg",
"ast": {
"Pkh": {
"Single": "03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd"
}
}
}
16 changes: 16 additions & 0 deletions packages/wasm-miniscript/test/fixtures/20.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"descriptor": "sh(wsh(pk(03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd)))#3kkw724y",
"ast": {
"Sh": {
"Wsh": {
"Ms": {
"Check": {
"PkK": {
"Single": "03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd"
}
}
}
}
}
}
}
16 changes: 16 additions & 0 deletions packages/wasm-miniscript/test/fixtures/21.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"descriptor": "sh(wsh(pk(03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd)))#3kkw724y",
"ast": {
"Sh": {
"Wsh": {
"Ms": {
"Check": {
"PkK": {
"Single": "03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd"
}
}
}
}
}
}
}
16 changes: 16 additions & 0 deletions packages/wasm-miniscript/test/fixtures/22.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"descriptor": "sh(wsh(pkh(03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd)))#8mnh2d6x",
"ast": {
"Sh": {
"Wsh": {
"Ms": {
"Check": {
"PkH": {
"Single": "03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd"
}
}
}
}
}
}
}
16 changes: 16 additions & 0 deletions packages/wasm-miniscript/test/fixtures/23.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"descriptor": "sh(wsh(pkh(03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd)))#8mnh2d6x",
"ast": {
"Sh": {
"Wsh": {
"Ms": {
"Check": {
"PkH": {
"Single": "03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd"
}
}
}
}
}
}
}
12 changes: 12 additions & 0 deletions packages/wasm-miniscript/test/fixtures/24.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"descriptor": "pk(xpub68NZiKmJWnxxS6aaHmn81bvJeTESw724CRDs6HbuccFQN9Ku14VQrADWgqbhhTHBaohPX4CjNLf9fq9MYo6oDaPPLPxSb7gwQN3ih19Zm4Y/0)#9rspda0y",
"ast": {
"Bare": {
"Check": {
"PkK": {
"XPub": "xpub68NZiKmJWnxxS6aaHmn81bvJeTESw724CRDs6HbuccFQN9Ku14VQrADWgqbhhTHBaohPX4CjNLf9fq9MYo6oDaPPLPxSb7gwQN3ih19Zm4Y/0"
}
}
}
}
}
12 changes: 12 additions & 0 deletions packages/wasm-miniscript/test/fixtures/25.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"descriptor": "pk(xpub68NZiKmJWnxxS6aaHmn81bvJeTESw724CRDs6HbuccFQN9Ku14VQrADWgqbhhTHBaohPX4CjNLf9fq9MYo6oDaPPLPxSb7gwQN3ih19Zm4Y/0)#9rspda0y",
"ast": {
"Bare": {
"Check": {
"PkK": {
"XPub": "xpub68NZiKmJWnxxS6aaHmn81bvJeTESw724CRDs6HbuccFQN9Ku14VQrADWgqbhhTHBaohPX4CjNLf9fq9MYo6oDaPPLPxSb7gwQN3ih19Zm4Y/0"
}
}
}
}
}
8 changes: 8 additions & 0 deletions packages/wasm-miniscript/test/fixtures/26.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"descriptor": "pkh([bd16bee5/2147483647']xpub69H7F5dQzmVd3vPuLKtcXJziMEQByuDidnX3YdwgtNsecY5HRGtAAQC5mXTt4dsv9RzyjgDjAQs9VGVV6ydYCHnprc9vvaA5YtqWyL6hyds/0)#j6nhxk2j",
"ast": {
"Pkh": {
"XPub": "[bd16bee5/2147483647']xpub69H7F5dQzmVd3vPuLKtcXJziMEQByuDidnX3YdwgtNsecY5HRGtAAQC5mXTt4dsv9RzyjgDjAQs9VGVV6ydYCHnprc9vvaA5YtqWyL6hyds/0"
}
}
}
8 changes: 8 additions & 0 deletions packages/wasm-miniscript/test/fixtures/27.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"descriptor": "wpkh([ffffffff/13']xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH/1/2/*)#66s997t5",
"ast": {
"Wpkh": {
"XPub": "[ffffffff/13']xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH/1/2/*"
}
}
}
8 changes: 8 additions & 0 deletions packages/wasm-miniscript/test/fixtures/28.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"descriptor": "wpkh([ffffffff/13']xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH/1/2/*)#66s997t5",
"ast": {
"Wpkh": {
"XPub": "[ffffffff/13']xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH/1/2/*"
}
}
}
8 changes: 8 additions & 0 deletions packages/wasm-miniscript/test/fixtures/29.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"descriptor": "wpkh([ffffffff/13']xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH/1/2/*)#66s997t5",
"ast": {
"Wpkh": {
"XPub": "[ffffffff/13']xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH/1/2/*"
}
}
}
8 changes: 8 additions & 0 deletions packages/wasm-miniscript/test/fixtures/3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"descriptor": "pkh([deadbeef/1/2'/3/4']03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd)#v0p5w8jl",
"ast": {
"Pkh": {
"Single": "[deadbeef/1/2'/3/4']03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd"
}
}
}
Loading