@bitgo/wasm-utxo 1.6.0 → 1.7.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/dist/cjs/js/bip32.d.ts +140 -0
- package/dist/cjs/js/bip32.js +177 -0
- package/dist/cjs/js/ecpair.d.ts +96 -0
- package/dist/cjs/js/ecpair.js +134 -0
- package/dist/cjs/js/{fixedScriptWallet.d.ts → fixedScriptWallet/BitGoPsbt.d.ts} +38 -41
- package/dist/cjs/js/{fixedScriptWallet.js → fixedScriptWallet/BitGoPsbt.js} +50 -36
- package/dist/cjs/js/fixedScriptWallet/ReplayProtection.d.ts +58 -0
- package/dist/cjs/js/fixedScriptWallet/ReplayProtection.js +89 -0
- package/dist/cjs/js/fixedScriptWallet/RootWalletKeys.d.ts +66 -0
- package/dist/cjs/js/fixedScriptWallet/RootWalletKeys.js +108 -0
- package/dist/cjs/js/fixedScriptWallet/address.d.ts +20 -0
- package/dist/cjs/js/fixedScriptWallet/address.js +29 -0
- package/dist/cjs/js/fixedScriptWallet/index.d.ts +4 -0
- package/dist/cjs/js/fixedScriptWallet/index.js +12 -0
- package/dist/cjs/js/index.d.ts +5 -1
- package/dist/cjs/js/index.js +11 -2
- package/dist/cjs/js/utxolibCompat.d.ts +0 -18
- package/dist/cjs/js/wasm/wasm_utxo.d.ts +254 -22
- package/dist/cjs/js/wasm/wasm_utxo.js +1081 -223
- package/dist/cjs/js/wasm/wasm_utxo_bg.wasm +0 -0
- package/dist/cjs/js/wasm/wasm_utxo_bg.wasm.d.ts +53 -8
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/js/bip32.d.ts +140 -0
- package/dist/esm/js/bip32.js +173 -0
- package/dist/esm/js/ecpair.d.ts +96 -0
- package/dist/esm/js/ecpair.js +130 -0
- package/dist/esm/js/{fixedScriptWallet.d.ts → fixedScriptWallet/BitGoPsbt.d.ts} +38 -41
- package/dist/esm/js/{fixedScriptWallet.js → fixedScriptWallet/BitGoPsbt.js} +49 -33
- package/dist/esm/js/fixedScriptWallet/ReplayProtection.d.ts +58 -0
- package/dist/esm/js/fixedScriptWallet/ReplayProtection.js +85 -0
- package/dist/esm/js/fixedScriptWallet/RootWalletKeys.d.ts +66 -0
- package/dist/esm/js/fixedScriptWallet/RootWalletKeys.js +104 -0
- package/dist/esm/js/fixedScriptWallet/address.d.ts +20 -0
- package/dist/esm/js/fixedScriptWallet/address.js +25 -0
- package/dist/esm/js/fixedScriptWallet/index.d.ts +4 -0
- package/dist/esm/js/fixedScriptWallet/index.js +4 -0
- package/dist/esm/js/index.d.ts +5 -1
- package/dist/esm/js/index.js +8 -1
- package/dist/esm/js/utxolibCompat.d.ts +0 -18
- package/dist/esm/js/wasm/wasm_utxo.d.ts +254 -22
- package/dist/esm/js/wasm/wasm_utxo_bg.js +1070 -220
- package/dist/esm/js/wasm/wasm_utxo_bg.wasm +0 -0
- package/dist/esm/js/wasm/wasm_utxo_bg.wasm.d.ts +53 -8
- package/dist/esm/test/bip32.d.ts +1 -0
- package/dist/esm/test/bip32.js +242 -0
- package/dist/esm/test/ecpair.d.ts +1 -0
- package/dist/esm/test/ecpair.js +137 -0
- package/dist/esm/test/fixedScript/fixtureUtil.d.ts +4 -2
- package/dist/esm/test/fixedScript/fixtureUtil.js +18 -7
- package/dist/esm/test/fixedScript/parseTransactionWithWalletKeys.js +7 -7
- package/dist/esm/test/fixedScript/verifySignature.js +72 -26
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
Binary file
|
|
@@ -1,28 +1,68 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const __wbg_utxolibcompatnamespace_free: (a: number, b: number) => void;
|
|
5
|
+
export const __wbg_wasmbip32_free: (a: number, b: number) => void;
|
|
6
|
+
export const __wbg_wasmecpair_free: (a: number, b: number) => void;
|
|
7
|
+
export const __wbg_wasmrootwalletkeys_free: (a: number, b: number) => void;
|
|
8
|
+
export const utxolibcompatnamespace_from_output_script: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
9
|
+
export const utxolibcompatnamespace_to_output_script: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
10
|
+
export const wasmbip32_chain_code: (a: number) => number;
|
|
11
|
+
export const wasmbip32_depth: (a: number) => number;
|
|
12
|
+
export const wasmbip32_derive: (a: number, b: number, c: number) => void;
|
|
13
|
+
export const wasmbip32_derive_hardened: (a: number, b: number, c: number) => void;
|
|
14
|
+
export const wasmbip32_derive_path: (a: number, b: number, c: number, d: number) => void;
|
|
15
|
+
export const wasmbip32_fingerprint: (a: number) => number;
|
|
16
|
+
export const wasmbip32_from_base58: (a: number, b: number, c: number) => void;
|
|
17
|
+
export const wasmbip32_from_bip32_interface: (a: number, b: number) => void;
|
|
18
|
+
export const wasmbip32_from_seed: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
19
|
+
export const wasmbip32_from_xprv: (a: number, b: number, c: number) => void;
|
|
20
|
+
export const wasmbip32_from_xpub: (a: number, b: number, c: number) => void;
|
|
21
|
+
export const wasmbip32_identifier: (a: number) => number;
|
|
22
|
+
export const wasmbip32_index: (a: number) => number;
|
|
23
|
+
export const wasmbip32_is_neutered: (a: number) => number;
|
|
24
|
+
export const wasmbip32_neutered: (a: number) => number;
|
|
25
|
+
export const wasmbip32_parent_fingerprint: (a: number) => number;
|
|
26
|
+
export const wasmbip32_private_key: (a: number) => number;
|
|
27
|
+
export const wasmbip32_public_key: (a: number) => number;
|
|
28
|
+
export const wasmbip32_to_base58: (a: number, b: number) => void;
|
|
29
|
+
export const wasmbip32_to_wif: (a: number, b: number) => void;
|
|
30
|
+
export const wasmecpair_from_private_key: (a: number, b: number, c: number) => void;
|
|
31
|
+
export const wasmecpair_from_public_key: (a: number, b: number, c: number) => void;
|
|
32
|
+
export const wasmecpair_from_wif: (a: number, b: number, c: number) => void;
|
|
33
|
+
export const wasmecpair_from_wif_mainnet: (a: number, b: number, c: number) => void;
|
|
34
|
+
export const wasmecpair_from_wif_testnet: (a: number, b: number, c: number) => void;
|
|
35
|
+
export const wasmecpair_private_key: (a: number) => number;
|
|
36
|
+
export const wasmecpair_public_key: (a: number) => number;
|
|
37
|
+
export const wasmecpair_to_wif: (a: number, b: number) => void;
|
|
38
|
+
export const wasmecpair_to_wif_mainnet: (a: number, b: number) => void;
|
|
39
|
+
export const wasmecpair_to_wif_testnet: (a: number, b: number) => void;
|
|
40
|
+
export const wasmrootwalletkeys_backup_key: (a: number) => number;
|
|
41
|
+
export const wasmrootwalletkeys_bitgo_key: (a: number) => number;
|
|
42
|
+
export const wasmrootwalletkeys_new: (a: number, b: number, c: number, d: number) => void;
|
|
43
|
+
export const wasmrootwalletkeys_user_key: (a: number) => number;
|
|
44
|
+
export const wasmrootwalletkeys_with_derivation_prefixes: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => void;
|
|
45
|
+
export const wasmbip32_from_bip32_properties: (a: number, b: number) => void;
|
|
4
46
|
export const __wbg_addressnamespace_free: (a: number, b: number) => void;
|
|
5
47
|
export const __wbg_bitgopsbt_free: (a: number, b: number) => void;
|
|
6
|
-
export const
|
|
48
|
+
export const __wbg_wrapdescriptor_free: (a: number, b: number) => void;
|
|
49
|
+
export const __wbg_wrapminiscript_free: (a: number, b: number) => void;
|
|
50
|
+
export const __wbg_wrappsbt_free: (a: number, b: number) => void;
|
|
7
51
|
export const addressnamespace_from_output_script_with_coin: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
8
52
|
export const addressnamespace_to_output_script_with_coin: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
9
53
|
export const bitgopsbt_extract_transaction: (a: number, b: number) => void;
|
|
10
54
|
export const bitgopsbt_finalize_all_inputs: (a: number, b: number) => void;
|
|
11
55
|
export const bitgopsbt_from_bytes: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
56
|
+
export const bitgopsbt_network: (a: number, b: number) => void;
|
|
12
57
|
export const bitgopsbt_parse_outputs_with_wallet_keys: (a: number, b: number, c: number) => void;
|
|
13
58
|
export const bitgopsbt_parse_transaction_with_wallet_keys: (a: number, b: number, c: number, d: number) => void;
|
|
14
59
|
export const bitgopsbt_serialize: (a: number, b: number) => void;
|
|
15
60
|
export const bitgopsbt_unsigned_txid: (a: number, b: number) => void;
|
|
16
61
|
export const bitgopsbt_verify_replay_protection_signature: (a: number, b: number, c: number, d: number) => void;
|
|
17
|
-
export const
|
|
62
|
+
export const bitgopsbt_verify_signature_with_pub: (a: number, b: number, c: number, d: number) => void;
|
|
63
|
+
export const bitgopsbt_verify_signature_with_xpub: (a: number, b: number, c: number, d: number) => void;
|
|
18
64
|
export const fixedscriptwalletnamespace_address: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
19
65
|
export const fixedscriptwalletnamespace_output_script: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
20
|
-
export const __wbg_utxolibcompatnamespace_free: (a: number, b: number) => void;
|
|
21
|
-
export const __wbg_wrapdescriptor_free: (a: number, b: number) => void;
|
|
22
|
-
export const __wbg_wrapminiscript_free: (a: number, b: number) => void;
|
|
23
|
-
export const __wbg_wrappsbt_free: (a: number, b: number) => void;
|
|
24
|
-
export const utxolibcompatnamespace_from_output_script: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
25
|
-
export const utxolibcompatnamespace_to_output_script: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
26
66
|
export const wrapdescriptor_atDerivationIndex: (a: number, b: number, c: number) => void;
|
|
27
67
|
export const wrapdescriptor_descType: (a: number, b: number) => void;
|
|
28
68
|
export const wrapdescriptor_encode: (a: number, b: number) => void;
|
|
@@ -48,6 +88,11 @@ export const wrappsbt_signWithPrv: (a: number, b: number, c: number, d: number)
|
|
|
48
88
|
export const wrappsbt_signWithXprv: (a: number, b: number, c: number, d: number) => void;
|
|
49
89
|
export const wrappsbt_updateInputWithDescriptor: (a: number, b: number, c: number, d: number) => void;
|
|
50
90
|
export const wrappsbt_updateOutputWithDescriptor: (a: number, b: number, c: number, d: number) => void;
|
|
91
|
+
export const __wbg_fixedscriptwalletnamespace_free: (a: number, b: number) => void;
|
|
92
|
+
export const __wbg_wasmreplayprotection_free: (a: number, b: number) => void;
|
|
93
|
+
export const wasmreplayprotection_from_addresses: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
94
|
+
export const wasmreplayprotection_from_output_scripts: (a: number, b: number) => number;
|
|
95
|
+
export const wasmreplayprotection_from_public_keys: (a: number, b: number, c: number) => void;
|
|
51
96
|
export const rustsecp256k1_v0_10_0_context_create: (a: number) => number;
|
|
52
97
|
export const rustsecp256k1_v0_10_0_context_destroy: (a: number) => void;
|
|
53
98
|
export const rustsecp256k1_v0_10_0_default_error_callback_fn: (a: number, b: number) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import * as assert from "assert";
|
|
2
|
+
import { bip32 as utxolibBip32 } from "@bitgo/utxo-lib";
|
|
3
|
+
import { BIP32 } from "../js/bip32.js";
|
|
4
|
+
const bip32 = { BIP32 };
|
|
5
|
+
describe("WasmBIP32", () => {
|
|
6
|
+
it("should create from base58 xpub", () => {
|
|
7
|
+
const xpub = "xpub6D4BDPcP2GT577Vvch3R8wDkScZWzQzMMUm3PWbmWvVJrZwQY4VUNgqFJPMM3No2dFDFGTsxxpG5uJh7n7epu4trkrX7x7DogT5Uv6fcLW5";
|
|
8
|
+
const key = bip32.BIP32.fromBase58(xpub);
|
|
9
|
+
assert.strictEqual(key.isNeutered(), true);
|
|
10
|
+
assert.strictEqual(key.depth, 3);
|
|
11
|
+
assert.strictEqual(key.toBase58(), xpub);
|
|
12
|
+
// Verify properties exist
|
|
13
|
+
assert.ok(key.chainCode instanceof Uint8Array);
|
|
14
|
+
assert.ok(key.publicKey instanceof Uint8Array);
|
|
15
|
+
assert.ok(key.identifier instanceof Uint8Array);
|
|
16
|
+
assert.ok(key.fingerprint instanceof Uint8Array);
|
|
17
|
+
assert.strictEqual(key.privateKey, undefined);
|
|
18
|
+
});
|
|
19
|
+
it("should create from base58 xprv", () => {
|
|
20
|
+
const xprv = "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi";
|
|
21
|
+
const key = bip32.BIP32.fromBase58(xprv);
|
|
22
|
+
assert.strictEqual(key.isNeutered(), false);
|
|
23
|
+
assert.strictEqual(key.depth, 0);
|
|
24
|
+
assert.strictEqual(key.toBase58(), xprv);
|
|
25
|
+
// Verify properties exist
|
|
26
|
+
assert.ok(key.chainCode instanceof Uint8Array);
|
|
27
|
+
assert.ok(key.publicKey instanceof Uint8Array);
|
|
28
|
+
assert.ok(key.privateKey instanceof Uint8Array);
|
|
29
|
+
assert.ok(key.identifier instanceof Uint8Array);
|
|
30
|
+
assert.ok(key.fingerprint instanceof Uint8Array);
|
|
31
|
+
});
|
|
32
|
+
it("should derive child keys", () => {
|
|
33
|
+
const xpub = "xpub6D4BDPcP2GT577Vvch3R8wDkScZWzQzMMUm3PWbmWvVJrZwQY4VUNgqFJPMM3No2dFDFGTsxxpG5uJh7n7epu4trkrX7x7DogT5Uv6fcLW5";
|
|
34
|
+
const key = bip32.BIP32.fromBase58(xpub);
|
|
35
|
+
const child = key.derive(0);
|
|
36
|
+
assert.strictEqual(child.depth, 4);
|
|
37
|
+
assert.strictEqual(child.isNeutered(), true);
|
|
38
|
+
});
|
|
39
|
+
it("should derive using path", () => {
|
|
40
|
+
const xprv = "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi";
|
|
41
|
+
const key = bip32.BIP32.fromBase58(xprv);
|
|
42
|
+
const derived1 = key.derivePath("0/1/2");
|
|
43
|
+
assert.strictEqual(derived1.depth, 3);
|
|
44
|
+
const derived2 = key.derivePath("m/0/1/2");
|
|
45
|
+
assert.strictEqual(derived2.depth, 3);
|
|
46
|
+
// Both should produce the same result
|
|
47
|
+
assert.strictEqual(derived1.toBase58(), derived2.toBase58());
|
|
48
|
+
});
|
|
49
|
+
it("should neutered a private key", () => {
|
|
50
|
+
const xprv = "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi";
|
|
51
|
+
const key = bip32.BIP32.fromBase58(xprv);
|
|
52
|
+
const neuteredKey = key.neutered();
|
|
53
|
+
assert.strictEqual(neuteredKey.isNeutered(), true);
|
|
54
|
+
assert.strictEqual(neuteredKey.privateKey, undefined);
|
|
55
|
+
assert.ok(neuteredKey.publicKey instanceof Uint8Array);
|
|
56
|
+
});
|
|
57
|
+
it("should derive hardened keys from private key", () => {
|
|
58
|
+
const xprv = "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi";
|
|
59
|
+
const key = bip32.BIP32.fromBase58(xprv);
|
|
60
|
+
const hardened = key.deriveHardened(0);
|
|
61
|
+
assert.strictEqual(hardened.depth, 1);
|
|
62
|
+
assert.strictEqual(hardened.isNeutered(), false);
|
|
63
|
+
});
|
|
64
|
+
it("should fail to derive hardened from public key", () => {
|
|
65
|
+
const xpub = "xpub6D4BDPcP2GT577Vvch3R8wDkScZWzQzMMUm3PWbmWvVJrZwQY4VUNgqFJPMM3No2dFDFGTsxxpG5uJh7n7epu4trkrX7x7DogT5Uv6fcLW5";
|
|
66
|
+
const key = bip32.BIP32.fromBase58(xpub);
|
|
67
|
+
assert.throws(() => {
|
|
68
|
+
key.deriveHardened(0);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
it("should export to WIF", () => {
|
|
72
|
+
const xprv = "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi";
|
|
73
|
+
const key = bip32.BIP32.fromBase58(xprv);
|
|
74
|
+
const wif = key.toWIF();
|
|
75
|
+
assert.ok(typeof wif === "string");
|
|
76
|
+
assert.ok(wif.length > 0);
|
|
77
|
+
});
|
|
78
|
+
it("should fail to export WIF from public key", () => {
|
|
79
|
+
const xpub = "xpub6D4BDPcP2GT577Vvch3R8wDkScZWzQzMMUm3PWbmWvVJrZwQY4VUNgqFJPMM3No2dFDFGTsxxpG5uJh7n7epu4trkrX7x7DogT5Uv6fcLW5";
|
|
80
|
+
const key = bip32.BIP32.fromBase58(xpub);
|
|
81
|
+
assert.throws(() => {
|
|
82
|
+
key.toWIF();
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
it("should create from seed", () => {
|
|
86
|
+
const seed = new Uint8Array(32);
|
|
87
|
+
for (let i = 0; i < 32; i++) {
|
|
88
|
+
seed[i] = i;
|
|
89
|
+
}
|
|
90
|
+
const key = bip32.BIP32.fromSeed(seed);
|
|
91
|
+
assert.strictEqual(key.depth, 0);
|
|
92
|
+
assert.strictEqual(key.isNeutered(), false);
|
|
93
|
+
assert.ok(key.privateKey instanceof Uint8Array);
|
|
94
|
+
});
|
|
95
|
+
it("should create from seed with network", () => {
|
|
96
|
+
const seed = new Uint8Array(32);
|
|
97
|
+
for (let i = 0; i < 32; i++) {
|
|
98
|
+
seed[i] = i;
|
|
99
|
+
}
|
|
100
|
+
const key = bip32.BIP32.fromSeed(seed, "BitcoinTestnet3");
|
|
101
|
+
assert.strictEqual(key.depth, 0);
|
|
102
|
+
assert.strictEqual(key.isNeutered(), false);
|
|
103
|
+
assert.ok(key.toBase58().startsWith("tprv"));
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
describe("WasmBIP32 parity with utxolib", () => {
|
|
107
|
+
function bufferEqual(a, b) {
|
|
108
|
+
if (a.length !== b.length)
|
|
109
|
+
return false;
|
|
110
|
+
for (let i = 0; i < a.length; i++) {
|
|
111
|
+
if (a[i] !== b[i])
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
it("should match utxolib when creating from base58 xpub", () => {
|
|
117
|
+
const xpub = "xpub6D4BDPcP2GT577Vvch3R8wDkScZWzQzMMUm3PWbmWvVJrZwQY4VUNgqFJPMM3No2dFDFGTsxxpG5uJh7n7epu4trkrX7x7DogT5Uv6fcLW5";
|
|
118
|
+
const wasmKey = bip32.BIP32.fromBase58(xpub);
|
|
119
|
+
const utxolibKey = utxolibBip32.fromBase58(xpub);
|
|
120
|
+
// Compare all properties
|
|
121
|
+
assert.strictEqual(wasmKey.toBase58(), utxolibKey.toBase58());
|
|
122
|
+
assert.strictEqual(wasmKey.depth, utxolibKey.depth);
|
|
123
|
+
assert.strictEqual(wasmKey.index, utxolibKey.index);
|
|
124
|
+
assert.strictEqual(wasmKey.parentFingerprint, utxolibKey.parentFingerprint);
|
|
125
|
+
assert.strictEqual(wasmKey.isNeutered(), utxolibKey.isNeutered());
|
|
126
|
+
assert.ok(bufferEqual(wasmKey.chainCode, utxolibKey.chainCode));
|
|
127
|
+
assert.ok(bufferEqual(wasmKey.publicKey, utxolibKey.publicKey));
|
|
128
|
+
assert.ok(bufferEqual(wasmKey.identifier, utxolibKey.identifier));
|
|
129
|
+
assert.ok(bufferEqual(wasmKey.fingerprint, utxolibKey.fingerprint));
|
|
130
|
+
});
|
|
131
|
+
it("should match utxolib when creating from base58 xprv", () => {
|
|
132
|
+
const xprv = "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi";
|
|
133
|
+
const wasmKey = bip32.BIP32.fromBase58(xprv);
|
|
134
|
+
const utxolibKey = utxolibBip32.fromBase58(xprv);
|
|
135
|
+
// Compare all properties
|
|
136
|
+
assert.strictEqual(wasmKey.toBase58(), utxolibKey.toBase58());
|
|
137
|
+
assert.strictEqual(wasmKey.depth, utxolibKey.depth);
|
|
138
|
+
assert.strictEqual(wasmKey.index, utxolibKey.index);
|
|
139
|
+
assert.strictEqual(wasmKey.parentFingerprint, utxolibKey.parentFingerprint);
|
|
140
|
+
assert.strictEqual(wasmKey.isNeutered(), utxolibKey.isNeutered());
|
|
141
|
+
assert.ok(bufferEqual(wasmKey.chainCode, utxolibKey.chainCode));
|
|
142
|
+
assert.ok(bufferEqual(wasmKey.publicKey, utxolibKey.publicKey));
|
|
143
|
+
assert.ok(bufferEqual(wasmKey.identifier, utxolibKey.identifier));
|
|
144
|
+
assert.ok(bufferEqual(wasmKey.fingerprint, utxolibKey.fingerprint));
|
|
145
|
+
assert.ok(wasmKey.privateKey &&
|
|
146
|
+
utxolibKey.privateKey &&
|
|
147
|
+
bufferEqual(wasmKey.privateKey, utxolibKey.privateKey));
|
|
148
|
+
});
|
|
149
|
+
it("should match utxolib when deriving normal child keys", () => {
|
|
150
|
+
const xprv = "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi";
|
|
151
|
+
const wasmKey = bip32.BIP32.fromBase58(xprv);
|
|
152
|
+
const utxolibKey = utxolibBip32.fromBase58(xprv);
|
|
153
|
+
// Derive several children and compare
|
|
154
|
+
for (const index of [0, 1, 10, 100, 2147483647]) {
|
|
155
|
+
const wasmChild = wasmKey.derive(index);
|
|
156
|
+
const utxolibChild = utxolibKey.derive(index);
|
|
157
|
+
assert.strictEqual(wasmChild.toBase58(), utxolibChild.toBase58(), `Failed at index ${index}`);
|
|
158
|
+
assert.ok(bufferEqual(wasmChild.publicKey, utxolibChild.publicKey));
|
|
159
|
+
assert.ok(bufferEqual(wasmChild.chainCode, utxolibChild.chainCode));
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
it("should match utxolib when deriving hardened child keys", () => {
|
|
163
|
+
const xprv = "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi";
|
|
164
|
+
const wasmKey = bip32.BIP32.fromBase58(xprv);
|
|
165
|
+
const utxolibKey = utxolibBip32.fromBase58(xprv);
|
|
166
|
+
// Derive several hardened children and compare
|
|
167
|
+
for (const index of [0, 1, 10, 2147483647]) {
|
|
168
|
+
const wasmChild = wasmKey.deriveHardened(index);
|
|
169
|
+
const utxolibChild = utxolibKey.deriveHardened(index);
|
|
170
|
+
assert.strictEqual(wasmChild.toBase58(), utxolibChild.toBase58(), `Failed at hardened index ${index}`);
|
|
171
|
+
assert.ok(bufferEqual(wasmChild.publicKey, utxolibChild.publicKey));
|
|
172
|
+
assert.ok(bufferEqual(wasmChild.chainCode, utxolibChild.chainCode));
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
it("should match utxolib when deriving using paths", () => {
|
|
176
|
+
const xprv = "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi";
|
|
177
|
+
const wasmKey = bip32.BIP32.fromBase58(xprv);
|
|
178
|
+
const utxolibKey = utxolibBip32.fromBase58(xprv);
|
|
179
|
+
const paths = ["0", "0/1", "0/1/2", "m/0/1/2", "0'/1", "m/44'/0'/0'", "m/44'/0'/0'/0/0"];
|
|
180
|
+
for (const path of paths) {
|
|
181
|
+
const wasmDerived = wasmKey.derivePath(path);
|
|
182
|
+
const utxolibDerived = utxolibKey.derivePath(path);
|
|
183
|
+
assert.strictEqual(wasmDerived.toBase58(), utxolibDerived.toBase58(), `Failed at path ${path}`);
|
|
184
|
+
assert.ok(bufferEqual(wasmDerived.publicKey, utxolibDerived.publicKey));
|
|
185
|
+
assert.ok(bufferEqual(wasmDerived.chainCode, utxolibDerived.chainCode));
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
it("should match utxolib when deriving from public keys", () => {
|
|
189
|
+
const xpub = "xpub6D4BDPcP2GT577Vvch3R8wDkScZWzQzMMUm3PWbmWvVJrZwQY4VUNgqFJPMM3No2dFDFGTsxxpG5uJh7n7epu4trkrX7x7DogT5Uv6fcLW5";
|
|
190
|
+
const wasmKey = bip32.BIP32.fromBase58(xpub);
|
|
191
|
+
const utxolibKey = utxolibBip32.fromBase58(xpub);
|
|
192
|
+
// Derive several children from public key
|
|
193
|
+
for (const index of [0, 1, 10, 100]) {
|
|
194
|
+
const wasmChild = wasmKey.derive(index);
|
|
195
|
+
const utxolibChild = utxolibKey.derive(index);
|
|
196
|
+
assert.strictEqual(wasmChild.toBase58(), utxolibChild.toBase58());
|
|
197
|
+
assert.ok(bufferEqual(wasmChild.publicKey, utxolibChild.publicKey));
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
it("should match utxolib when neutering", () => {
|
|
201
|
+
const xprv = "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi";
|
|
202
|
+
const wasmKey = bip32.BIP32.fromBase58(xprv);
|
|
203
|
+
const utxolibKey = utxolibBip32.fromBase58(xprv);
|
|
204
|
+
const wasmNeutered = wasmKey.neutered();
|
|
205
|
+
const utxolibNeutered = utxolibKey.neutered();
|
|
206
|
+
assert.strictEqual(wasmNeutered.toBase58(), utxolibNeutered.toBase58());
|
|
207
|
+
assert.ok(bufferEqual(wasmNeutered.publicKey, utxolibNeutered.publicKey));
|
|
208
|
+
assert.ok(bufferEqual(wasmNeutered.chainCode, utxolibNeutered.chainCode));
|
|
209
|
+
assert.strictEqual(wasmNeutered.privateKey, undefined);
|
|
210
|
+
});
|
|
211
|
+
it("should match utxolib when exporting to WIF", () => {
|
|
212
|
+
const xprv = "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi";
|
|
213
|
+
const wasmKey = bip32.BIP32.fromBase58(xprv);
|
|
214
|
+
const utxolibKey = utxolibBip32.fromBase58(xprv);
|
|
215
|
+
assert.strictEqual(wasmKey.toWIF(), utxolibKey.toWIF());
|
|
216
|
+
});
|
|
217
|
+
it("should match utxolib for BIP44 wallet derivation (m/44'/0'/0'/0/0)", () => {
|
|
218
|
+
const seed = Buffer.from("fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542", "hex");
|
|
219
|
+
const wasmMaster = bip32.BIP32.fromSeed(seed);
|
|
220
|
+
const utxolibMaster = utxolibBip32.fromSeed(seed);
|
|
221
|
+
// Standard BIP44 path for Bitcoin: m/44'/0'/0'/0/0
|
|
222
|
+
const path = "m/44'/0'/0'/0/0";
|
|
223
|
+
const wasmDerived = wasmMaster.derivePath(path);
|
|
224
|
+
const utxolibDerived = utxolibMaster.derivePath(path);
|
|
225
|
+
assert.strictEqual(wasmDerived.toBase58(), utxolibDerived.toBase58());
|
|
226
|
+
assert.ok(bufferEqual(wasmDerived.publicKey, utxolibDerived.publicKey));
|
|
227
|
+
assert.ok(bufferEqual(wasmDerived.chainCode, utxolibDerived.chainCode));
|
|
228
|
+
});
|
|
229
|
+
it("should produce same fingerprint for derived keys", () => {
|
|
230
|
+
const xprv = "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi";
|
|
231
|
+
const wasmKey = bip32.BIP32.fromBase58(xprv);
|
|
232
|
+
const utxolibKey = utxolibBip32.fromBase58(xprv);
|
|
233
|
+
// Derive a child and check its parent fingerprint matches the parent's fingerprint
|
|
234
|
+
const wasmChild = wasmKey.derive(0);
|
|
235
|
+
const utxolibChild = utxolibKey.derive(0);
|
|
236
|
+
// Parent fingerprints should match
|
|
237
|
+
assert.strictEqual(wasmChild.parentFingerprint, utxolibChild.parentFingerprint);
|
|
238
|
+
// The parent fingerprint should match the parent's fingerprint
|
|
239
|
+
const wasmParentFp = new DataView(wasmKey.fingerprint.buffer).getUint32(0, false);
|
|
240
|
+
assert.strictEqual(wasmChild.parentFingerprint, wasmParentFp);
|
|
241
|
+
});
|
|
242
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import * as assert from "assert";
|
|
2
|
+
import { ECPair } from "../js/ecpair.js";
|
|
3
|
+
describe("WasmECPair", () => {
|
|
4
|
+
const testPrivateKey = Buffer.from("1111111111111111111111111111111111111111111111111111111111111111", "hex");
|
|
5
|
+
const testWifMainnet = "KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn";
|
|
6
|
+
const testWifTestnet = "cMahea7zqjxrtgAbB7LSGbcQUr1uX1ojuat9jZodMN87JcbXMTcA";
|
|
7
|
+
it("should create from private key", () => {
|
|
8
|
+
const key = ECPair.fromPrivateKey(testPrivateKey);
|
|
9
|
+
assert.ok(key.privateKey instanceof Uint8Array);
|
|
10
|
+
assert.ok(key.publicKey instanceof Uint8Array);
|
|
11
|
+
assert.strictEqual(key.privateKey.length, 32);
|
|
12
|
+
assert.strictEqual(key.publicKey.length, 33); // Always compressed
|
|
13
|
+
});
|
|
14
|
+
it("should create from public key", () => {
|
|
15
|
+
const tempKey = ECPair.fromPrivateKey(testPrivateKey);
|
|
16
|
+
const publicKey = tempKey.publicKey;
|
|
17
|
+
const key = ECPair.fromPublicKey(publicKey);
|
|
18
|
+
assert.strictEqual(key.privateKey, undefined);
|
|
19
|
+
assert.ok(key.publicKey instanceof Uint8Array);
|
|
20
|
+
assert.strictEqual(key.publicKey.length, 33);
|
|
21
|
+
});
|
|
22
|
+
it("should create from mainnet WIF", () => {
|
|
23
|
+
const key = ECPair.fromWIF(testWifMainnet);
|
|
24
|
+
assert.ok(key.privateKey instanceof Uint8Array);
|
|
25
|
+
assert.ok(key.publicKey instanceof Uint8Array);
|
|
26
|
+
assert.strictEqual(key.privateKey.length, 32);
|
|
27
|
+
});
|
|
28
|
+
it("should create from testnet WIF", () => {
|
|
29
|
+
const key = ECPair.fromWIF(testWifTestnet);
|
|
30
|
+
assert.ok(key.privateKey instanceof Uint8Array);
|
|
31
|
+
assert.ok(key.publicKey instanceof Uint8Array);
|
|
32
|
+
assert.strictEqual(key.privateKey.length, 32);
|
|
33
|
+
});
|
|
34
|
+
it("should create from mainnet WIF using fromWIFMainnet", () => {
|
|
35
|
+
const key = ECPair.fromWIFMainnet(testWifMainnet);
|
|
36
|
+
assert.ok(key.privateKey instanceof Uint8Array);
|
|
37
|
+
assert.ok(key.publicKey instanceof Uint8Array);
|
|
38
|
+
});
|
|
39
|
+
it("should create from testnet WIF using fromWIFTestnet", () => {
|
|
40
|
+
const key = ECPair.fromWIFTestnet(testWifTestnet);
|
|
41
|
+
assert.ok(key.privateKey instanceof Uint8Array);
|
|
42
|
+
assert.ok(key.publicKey instanceof Uint8Array);
|
|
43
|
+
});
|
|
44
|
+
it("should fail when using wrong network WIF method", () => {
|
|
45
|
+
assert.throws(() => {
|
|
46
|
+
ECPair.fromWIFMainnet(testWifTestnet);
|
|
47
|
+
});
|
|
48
|
+
assert.throws(() => {
|
|
49
|
+
ECPair.fromWIFTestnet(testWifMainnet);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
it("should export to WIF mainnet", () => {
|
|
53
|
+
const key = ECPair.fromPrivateKey(testPrivateKey);
|
|
54
|
+
const wif = key.toWIF();
|
|
55
|
+
assert.ok(typeof wif === "string");
|
|
56
|
+
assert.ok(wif.length > 0);
|
|
57
|
+
assert.ok(wif.startsWith("K") || wif.startsWith("L")); // Mainnet compressed
|
|
58
|
+
});
|
|
59
|
+
it("should export to WIF testnet", () => {
|
|
60
|
+
const key = ECPair.fromPrivateKey(testPrivateKey);
|
|
61
|
+
const wif = key.toWIFTestnet();
|
|
62
|
+
assert.ok(typeof wif === "string");
|
|
63
|
+
assert.ok(wif.length > 0);
|
|
64
|
+
assert.ok(wif.startsWith("c")); // Testnet compressed
|
|
65
|
+
});
|
|
66
|
+
it("should roundtrip WIF mainnet", () => {
|
|
67
|
+
const key1 = ECPair.fromPrivateKey(testPrivateKey);
|
|
68
|
+
const wif = key1.toWIF();
|
|
69
|
+
const key2 = ECPair.fromWIF(wif);
|
|
70
|
+
assert.deepStrictEqual(key1.privateKey, key2.privateKey);
|
|
71
|
+
assert.deepStrictEqual(key1.publicKey, key2.publicKey);
|
|
72
|
+
});
|
|
73
|
+
it("should roundtrip WIF testnet", () => {
|
|
74
|
+
const key1 = ECPair.fromPrivateKey(testPrivateKey);
|
|
75
|
+
const wif = key1.toWIFTestnet();
|
|
76
|
+
const key2 = ECPair.fromWIF(wif);
|
|
77
|
+
assert.deepStrictEqual(key1.privateKey, key2.privateKey);
|
|
78
|
+
assert.deepStrictEqual(key1.publicKey, key2.publicKey);
|
|
79
|
+
});
|
|
80
|
+
it("should fail to export WIF from public key", () => {
|
|
81
|
+
const tempKey = ECPair.fromPrivateKey(testPrivateKey);
|
|
82
|
+
const publicKey = tempKey.publicKey;
|
|
83
|
+
const key = ECPair.fromPublicKey(publicKey);
|
|
84
|
+
assert.throws(() => {
|
|
85
|
+
key.toWIF();
|
|
86
|
+
});
|
|
87
|
+
assert.throws(() => {
|
|
88
|
+
key.toWIFMainnet();
|
|
89
|
+
});
|
|
90
|
+
assert.throws(() => {
|
|
91
|
+
key.toWIFTestnet();
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
it("should reject invalid private keys", () => {
|
|
95
|
+
// All zeros
|
|
96
|
+
assert.throws(() => {
|
|
97
|
+
ECPair.fromPrivateKey(new Uint8Array(32));
|
|
98
|
+
});
|
|
99
|
+
// Wrong length
|
|
100
|
+
assert.throws(() => {
|
|
101
|
+
ECPair.fromPrivateKey(new Uint8Array(31));
|
|
102
|
+
});
|
|
103
|
+
assert.throws(() => {
|
|
104
|
+
ECPair.fromPrivateKey(new Uint8Array(33));
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
it("should reject invalid public keys", () => {
|
|
108
|
+
// Wrong length
|
|
109
|
+
assert.throws(() => {
|
|
110
|
+
ECPair.fromPublicKey(new Uint8Array(32));
|
|
111
|
+
});
|
|
112
|
+
assert.throws(() => {
|
|
113
|
+
ECPair.fromPublicKey(new Uint8Array(34));
|
|
114
|
+
});
|
|
115
|
+
// Invalid format
|
|
116
|
+
assert.throws(() => {
|
|
117
|
+
const invalidPubkey = new Uint8Array(33);
|
|
118
|
+
invalidPubkey[0] = 0x01; // Invalid prefix
|
|
119
|
+
ECPair.fromPublicKey(invalidPubkey);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
it("should always produce compressed public keys", () => {
|
|
123
|
+
const key1 = ECPair.fromPrivateKey(testPrivateKey);
|
|
124
|
+
const key2 = ECPair.fromWIF(testWifMainnet);
|
|
125
|
+
// All public keys should be 33 bytes (compressed)
|
|
126
|
+
assert.strictEqual(key1.publicKey.length, 33);
|
|
127
|
+
assert.strictEqual(key2.publicKey.length, 33);
|
|
128
|
+
// All should start with 0x02 or 0x03 (compressed format)
|
|
129
|
+
assert.ok(key1.publicKey[0] === 0x02 || key1.publicKey[0] === 0x03);
|
|
130
|
+
assert.ok(key2.publicKey[0] === 0x02 || key2.publicKey[0] === 0x03);
|
|
131
|
+
});
|
|
132
|
+
it("should derive same public key from same private key", () => {
|
|
133
|
+
const key1 = ECPair.fromPrivateKey(testPrivateKey);
|
|
134
|
+
const key2 = ECPair.fromPrivateKey(testPrivateKey);
|
|
135
|
+
assert.deepStrictEqual(key1.publicKey, key2.publicKey);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { RootWalletKeys } from "../../js/fixedScriptWallet/RootWalletKeys.js";
|
|
2
|
+
import { ECPair } from "../../js/ecpair.js";
|
|
2
3
|
export type SignatureState = "unsigned" | "halfsigned" | "fullsigned";
|
|
3
4
|
export type Triple<T> = [T, T, T];
|
|
4
5
|
export type Bip32Derivation = {
|
|
@@ -86,7 +87,8 @@ export declare function loadPsbtFixture(network: string, signatureState: string)
|
|
|
86
87
|
/**
|
|
87
88
|
* Load wallet keys from fixture
|
|
88
89
|
*/
|
|
89
|
-
export declare function loadWalletKeysFromFixture(
|
|
90
|
+
export declare function loadWalletKeysFromFixture(fixture: Fixture): RootWalletKeys;
|
|
91
|
+
export declare function loadReplayProtectionKeyFromFixture(fixture: Fixture): ECPair;
|
|
90
92
|
/**
|
|
91
93
|
* Get extracted transaction hex from fixture
|
|
92
94
|
*/
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import assert from "node:assert";
|
|
1
2
|
import * as fs from "node:fs";
|
|
2
3
|
import * as path from "node:path";
|
|
3
4
|
import { fileURLToPath } from "node:url";
|
|
4
5
|
import { dirname } from "node:path";
|
|
5
|
-
import
|
|
6
|
+
import { BIP32 } from "../../js/bip32.js";
|
|
7
|
+
import { RootWalletKeys } from "../../js/fixedScriptWallet/RootWalletKeys.js";
|
|
8
|
+
import { ECPair } from "../../js/ecpair.js";
|
|
6
9
|
const __filename = fileURLToPath(import.meta.url);
|
|
7
10
|
const __dirname = dirname(__filename);
|
|
8
11
|
/**
|
|
@@ -22,16 +25,24 @@ export function loadPsbtFixture(network, signatureState) {
|
|
|
22
25
|
/**
|
|
23
26
|
* Load wallet keys from fixture
|
|
24
27
|
*/
|
|
25
|
-
export function loadWalletKeysFromFixture(
|
|
26
|
-
const fixturePath = path.join(__dirname, "..", "fixtures", "fixed-script", `psbt-lite.${network}.fullsigned.json`);
|
|
27
|
-
const fixtureContent = fs.readFileSync(fixturePath, "utf-8");
|
|
28
|
-
const fixture = JSON.parse(fixtureContent);
|
|
28
|
+
export function loadWalletKeysFromFixture(fixture) {
|
|
29
29
|
// Parse xprvs and convert to xpubs
|
|
30
30
|
const xpubs = fixture.walletKeys.map((xprv) => {
|
|
31
|
-
const key =
|
|
31
|
+
const key = BIP32.fromBase58(xprv);
|
|
32
32
|
return key.neutered();
|
|
33
33
|
});
|
|
34
|
-
|
|
34
|
+
const walletKeysLike = {
|
|
35
|
+
triple: xpubs,
|
|
36
|
+
derivationPrefixes: ["0/0", "0/0", "0/0"],
|
|
37
|
+
};
|
|
38
|
+
return RootWalletKeys.from(walletKeysLike);
|
|
39
|
+
}
|
|
40
|
+
export function loadReplayProtectionKeyFromFixture(fixture) {
|
|
41
|
+
// underived user key
|
|
42
|
+
const userBip32 = BIP32.fromBase58(fixture.walletKeys[0]);
|
|
43
|
+
assert(userBip32.privateKey);
|
|
44
|
+
const userECPair = ECPair.fromPrivateKey(Buffer.from(userBip32.privateKey));
|
|
45
|
+
return userECPair;
|
|
35
46
|
}
|
|
36
47
|
/**
|
|
37
48
|
* Get extracted transaction hex from fixture
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import assert from "node:assert";
|
|
2
2
|
import * as utxolib from "@bitgo/utxo-lib";
|
|
3
3
|
import { fixedScriptWallet } from "../../js/index.js";
|
|
4
|
-
import { loadPsbtFixture, loadWalletKeysFromFixture, getPsbtBuffer } from "./fixtureUtil.js";
|
|
4
|
+
import { loadPsbtFixture, loadWalletKeysFromFixture, getPsbtBuffer, loadReplayProtectionKeyFromFixture, } from "./fixtureUtil.js";
|
|
5
5
|
function getExpectedInputScriptType(fixtureScriptType) {
|
|
6
6
|
// Map fixture types to InputScriptType values
|
|
7
7
|
// Based on the Rust mapping in src/fixed_script_wallet/test_utils/fixtures.rs
|
|
@@ -26,8 +26,6 @@ function getOtherWalletKeys() {
|
|
|
26
26
|
return new utxolib.bitgo.RootWalletKeys(otherWalletKeys);
|
|
27
27
|
}
|
|
28
28
|
describe("parseTransactionWithWalletKeys", function () {
|
|
29
|
-
// Replay protection script that matches Rust tests
|
|
30
|
-
const replayProtectionScript = Buffer.from("a91420b37094d82a513451ff0ccd9db23aba05bc5ef387", "hex");
|
|
31
29
|
const supportedNetworks = utxolib.getNetworkList().filter((network) => {
|
|
32
30
|
return (utxolib.isMainnet(network) &&
|
|
33
31
|
network !== utxolib.networks.bitcoincash &&
|
|
@@ -42,12 +40,14 @@ describe("parseTransactionWithWalletKeys", function () {
|
|
|
42
40
|
let fullsignedPsbtBytes;
|
|
43
41
|
let bitgoPsbt;
|
|
44
42
|
let rootWalletKeys;
|
|
43
|
+
let replayProtectionKey;
|
|
45
44
|
let fixture;
|
|
46
45
|
before(function () {
|
|
47
46
|
fixture = loadPsbtFixture(networkName, "fullsigned");
|
|
48
47
|
fullsignedPsbtBytes = getPsbtBuffer(fixture);
|
|
49
48
|
bitgoPsbt = fixedScriptWallet.BitGoPsbt.fromBytes(fullsignedPsbtBytes, networkName);
|
|
50
|
-
rootWalletKeys = loadWalletKeysFromFixture(
|
|
49
|
+
rootWalletKeys = loadWalletKeysFromFixture(fixture);
|
|
50
|
+
replayProtectionKey = loadReplayProtectionKeyFromFixture(fixture);
|
|
51
51
|
});
|
|
52
52
|
it("should have matching unsigned transaction ID", function () {
|
|
53
53
|
const unsignedTxid = bitgoPsbt.unsignedTxid();
|
|
@@ -59,7 +59,7 @@ describe("parseTransactionWithWalletKeys", function () {
|
|
|
59
59
|
});
|
|
60
60
|
it("should parse transaction and identify internal/external outputs", function () {
|
|
61
61
|
const parsed = bitgoPsbt.parseTransactionWithWalletKeys(rootWalletKeys, {
|
|
62
|
-
|
|
62
|
+
publicKeys: [replayProtectionKey],
|
|
63
63
|
});
|
|
64
64
|
// Verify all inputs have addresses and values
|
|
65
65
|
parsed.inputs.forEach((input, i) => {
|
|
@@ -104,7 +104,7 @@ describe("parseTransactionWithWalletKeys", function () {
|
|
|
104
104
|
});
|
|
105
105
|
it("should parse inputs with correct scriptType", function () {
|
|
106
106
|
const parsed = bitgoPsbt.parseTransactionWithWalletKeys(rootWalletKeys, {
|
|
107
|
-
|
|
107
|
+
publicKeys: [replayProtectionKey],
|
|
108
108
|
});
|
|
109
109
|
// Verify all inputs have scriptType matching fixture
|
|
110
110
|
parsed.inputs.forEach((input, i) => {
|
|
@@ -116,7 +116,7 @@ describe("parseTransactionWithWalletKeys", function () {
|
|
|
116
116
|
it("should fail to parse with other wallet keys", function () {
|
|
117
117
|
assert.throws(() => {
|
|
118
118
|
bitgoPsbt.parseTransactionWithWalletKeys(getOtherWalletKeys(), {
|
|
119
|
-
|
|
119
|
+
publicKeys: [replayProtectionKey],
|
|
120
120
|
});
|
|
121
121
|
}, (error) => {
|
|
122
122
|
return error.message.includes("Failed to parse transaction: Input 0: wallet validation failed");
|