Skip to content

Commit 3c3d34c

Browse files
Merge pull request #50 from BitGo/BTC-1829.fix-taproot
feat: improve taproot descriptors support
2 parents 02d179a + ca1c430 commit 3c3d34c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1287
-52
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
js/wasm
2-
target/
2+
test/fixtures/
3+
target/

packages/wasm-miniscript/src/try_into_js_value.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,7 @@ impl<Pk: MiniscriptKey + TryIntoJsValue> TryIntoJsValue for WshInner<Pk> {
208208

209209
impl<Pk: MiniscriptKey + TryIntoJsValue> TryIntoJsValue for Tr<Pk> {
210210
fn try_to_js_value(&self) -> Result<JsValue, JsError> {
211-
js_obj!(
212-
"internalKey" => self.internal_key(),
213-
"tree" => self.tap_tree()
214-
)
211+
Ok(js_arr!(self.internal_key(), self.tap_tree()))
215212
}
216213
}
217214

packages/wasm-miniscript/test/descriptorFixtures.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,12 @@ export const fixtures = {
345345
script: "a914767e9119ff3b3ac0cb6dcfe21de1842ccf85f1c487",
346346
checksumRequired: false,
347347
},
348+
{
349+
descriptor:
350+
"tr(50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0,multi_a(2,xpub661MyMwAqRbcFXS2qwsTkaFc7PEpwDXWgY1Hx2MS7XywhW24sTjQzxiUgnGNW5v6DsW9Z8JcAqf8a22v21jDSA3DwLbbpt2ra3WbP83QNvP/0/0,xpub661MyMwAqRbcGfiaWcoeKLerFu3qRfy6zSYAwnmxSKW8JSauRajFsAsRHs2pV4q5rxkb4ynx4Bm8t54McTCp8V27s7XsdpD8T4s56etpjro/0/0,xpub661MyMwAqRbcH4HzWiCwmYajy1SXZngxHvpYDNEX4xjrDAneAm6rnpPuPPXcBRsSgxupDBmH2tzPHkikNrnLbsvTHemPFHSFbZxonZcCwFi/0/0))#82q34xv2",
351+
script: "51207e8c409f0ab01197f9676efc3a9505f1f09ed0f21693e46a3aa3b6b54d437aa2",
352+
checksumRequired: true,
353+
},
348354
],
349355
invalid: [
350356
{

packages/wasm-miniscript/test/descriptorUtil.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
1+
import * as fs from "fs/promises";
12
import * as utxolib from "@bitgo/utxo-lib";
3+
import { Descriptor } from "../js";
4+
import * as assert from "node:assert";
5+
6+
async function assertEqualJSON(path: string, value: unknown): Promise<void> {
7+
try {
8+
const data = JSON.parse(await fs.readFile(path, "utf8"));
9+
assert.deepStrictEqual(data, value);
10+
} catch (e: any) {
11+
if (e.code === "ENOENT") {
12+
await fs.writeFile(path, JSON.stringify(value, null, 2));
13+
throw new Error("Expected file not found, wrote it instead");
14+
}
15+
throw e;
16+
}
17+
}
18+
19+
export async function assertEqualAst(path: string, descriptor: Descriptor): Promise<void> {
20+
await assertEqualJSON(path, { descriptor: descriptor.toString(), ast: descriptor.node() });
21+
}
222

323
/** Expand a template with the given root wallet keys and chain code */
424
function expand(template: string, rootWalletKeys: utxolib.bitgo.RootWalletKeys, chainCode: number) {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"descriptor": "pk(03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd)#9pcxlpvx",
3+
"ast": {
4+
"Bare": {
5+
"Check": {
6+
"PkK": {
7+
"Single": "03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd"
8+
}
9+
}
10+
}
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"descriptor": "pk(03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd)#9pcxlpvx",
3+
"ast": {
4+
"Bare": {
5+
"Check": {
6+
"PkK": {
7+
"Single": "03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd"
8+
}
9+
}
10+
}
11+
}
12+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"descriptor": "pkh(04a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd5b8dec5235a0fa8722476c7709c02559e3aa73aa03918ba2d492eea75abea235)#9907vvwz",
3+
"ast": {
4+
"Pkh": {
5+
"Single": "04a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd5b8dec5235a0fa8722476c7709c02559e3aa73aa03918ba2d492eea75abea235"
6+
}
7+
}
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"descriptor": "pkh(04a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd5b8dec5235a0fa8722476c7709c02559e3aa73aa03918ba2d492eea75abea235)#9907vvwz",
3+
"ast": {
4+
"Pkh": {
5+
"Single": "04a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd5b8dec5235a0fa8722476c7709c02559e3aa73aa03918ba2d492eea75abea235"
6+
}
7+
}
8+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"descriptor": "sh(pk(03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd))#s53ls94y",
3+
"ast": {
4+
"Sh": {
5+
"Ms": {
6+
"Check": {
7+
"PkK": {
8+
"Single": "03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd"
9+
}
10+
}
11+
}
12+
}
13+
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"descriptor": "sh(pk(03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd))#s53ls94y",
3+
"ast": {
4+
"Sh": {
5+
"Ms": {
6+
"Check": {
7+
"PkK": {
8+
"Single": "03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd"
9+
}
10+
}
11+
}
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)