@bitgo/wasm-utxo 1.6.0 → 1.8.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/BitGoPsbt.d.ts +242 -0
- package/dist/cjs/js/fixedScriptWallet/BitGoPsbt.js +274 -0
- 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 +333 -15
- package/dist/cjs/js/wasm/wasm_utxo.js +1311 -201
- package/dist/cjs/js/wasm/wasm_utxo_bg.wasm +0 -0
- package/dist/cjs/js/wasm/wasm_utxo_bg.wasm.d.ts +64 -15
- 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/BitGoPsbt.d.ts +242 -0
- package/dist/esm/js/fixedScriptWallet/BitGoPsbt.js +270 -0
- 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 +333 -15
- package/dist/esm/js/wasm/wasm_utxo_bg.js +1301 -199
- package/dist/esm/js/wasm/wasm_utxo_bg.wasm +0 -0
- package/dist/esm/js/wasm/wasm_utxo_bg.wasm.d.ts +64 -15
- 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 +12 -2
- package/dist/esm/test/fixedScript/fixtureUtil.js +28 -7
- package/dist/esm/test/fixedScript/musig2Nonces.d.ts +1 -0
- package/dist/esm/test/fixedScript/musig2Nonces.js +77 -0
- package/dist/esm/test/fixedScript/parseTransactionWithWalletKeys.js +7 -7
- package/dist/esm/test/fixedScript/signAndVerifySignature.d.ts +1 -0
- package/dist/esm/test/fixedScript/signAndVerifySignature.js +268 -0
- package/dist/esm/test/fixedScript/walletKeys.util.d.ts +12 -0
- package/dist/esm/test/fixedScript/walletKeys.util.js +17 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/cjs/js/fixedScriptWallet.d.ts +0 -146
- package/dist/cjs/js/fixedScriptWallet.js +0 -138
- package/dist/esm/js/fixedScriptWallet.d.ts +0 -146
- package/dist/esm/js/fixedScriptWallet.js +0 -132
- package/dist/esm/test/fixedScript/verifySignature.js +0 -141
- /package/dist/esm/test/{fixedScript/verifySignature.d.ts → bip32.d.ts} +0 -0
|
Binary file
|
|
@@ -1,28 +1,83 @@
|
|
|
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_wasmreplayprotection_free: (a: number, b: number) => void;
|
|
6
|
+
export const __wbg_wrapminiscript_free: (a: number, b: number) => void;
|
|
7
|
+
export const utxolibcompatnamespace_from_output_script: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
8
|
+
export const utxolibcompatnamespace_to_output_script: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
9
|
+
export const wasmreplayprotection_from_addresses: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
10
|
+
export const wasmreplayprotection_from_output_scripts: (a: number, b: number) => number;
|
|
11
|
+
export const wasmreplayprotection_from_public_keys: (a: number, b: number, c: number) => void;
|
|
12
|
+
export const wrapminiscript_encode: (a: number, b: number) => void;
|
|
13
|
+
export const wrapminiscript_fromBitcoinScript: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
14
|
+
export const wrapminiscript_fromString: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
15
|
+
export const wrapminiscript_node: (a: number, b: number) => void;
|
|
16
|
+
export const wrapminiscript_toAsmString: (a: number, b: number) => void;
|
|
17
|
+
export const wrapminiscript_toString: (a: number, b: number) => void;
|
|
4
18
|
export const __wbg_addressnamespace_free: (a: number, b: number) => void;
|
|
5
|
-
export const
|
|
6
|
-
export const
|
|
19
|
+
export const __wbg_wasmbip32_free: (a: number, b: number) => void;
|
|
20
|
+
export const __wbg_wasmecpair_free: (a: number, b: number) => void;
|
|
21
|
+
export const __wbg_wasmrootwalletkeys_free: (a: number, b: number) => void;
|
|
7
22
|
export const addressnamespace_from_output_script_with_coin: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
8
23
|
export const addressnamespace_to_output_script_with_coin: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
24
|
+
export const wasmbip32_chain_code: (a: number) => number;
|
|
25
|
+
export const wasmbip32_depth: (a: number) => number;
|
|
26
|
+
export const wasmbip32_derive: (a: number, b: number, c: number) => void;
|
|
27
|
+
export const wasmbip32_derive_hardened: (a: number, b: number, c: number) => void;
|
|
28
|
+
export const wasmbip32_derive_path: (a: number, b: number, c: number, d: number) => void;
|
|
29
|
+
export const wasmbip32_fingerprint: (a: number) => number;
|
|
30
|
+
export const wasmbip32_from_base58: (a: number, b: number, c: number) => void;
|
|
31
|
+
export const wasmbip32_from_bip32_interface: (a: number, b: number) => void;
|
|
32
|
+
export const wasmbip32_from_seed: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
33
|
+
export const wasmbip32_from_xprv: (a: number, b: number, c: number) => void;
|
|
34
|
+
export const wasmbip32_from_xpub: (a: number, b: number, c: number) => void;
|
|
35
|
+
export const wasmbip32_identifier: (a: number) => number;
|
|
36
|
+
export const wasmbip32_index: (a: number) => number;
|
|
37
|
+
export const wasmbip32_is_neutered: (a: number) => number;
|
|
38
|
+
export const wasmbip32_neutered: (a: number) => number;
|
|
39
|
+
export const wasmbip32_parent_fingerprint: (a: number) => number;
|
|
40
|
+
export const wasmbip32_private_key: (a: number) => number;
|
|
41
|
+
export const wasmbip32_public_key: (a: number) => number;
|
|
42
|
+
export const wasmbip32_to_base58: (a: number, b: number) => void;
|
|
43
|
+
export const wasmbip32_to_wif: (a: number, b: number) => void;
|
|
44
|
+
export const wasmecpair_from_private_key: (a: number, b: number, c: number) => void;
|
|
45
|
+
export const wasmecpair_from_public_key: (a: number, b: number, c: number) => void;
|
|
46
|
+
export const wasmecpair_from_wif: (a: number, b: number, c: number) => void;
|
|
47
|
+
export const wasmecpair_from_wif_mainnet: (a: number, b: number, c: number) => void;
|
|
48
|
+
export const wasmecpair_from_wif_testnet: (a: number, b: number, c: number) => void;
|
|
49
|
+
export const wasmecpair_private_key: (a: number) => number;
|
|
50
|
+
export const wasmecpair_public_key: (a: number) => number;
|
|
51
|
+
export const wasmecpair_to_wif: (a: number, b: number) => void;
|
|
52
|
+
export const wasmecpair_to_wif_mainnet: (a: number, b: number) => void;
|
|
53
|
+
export const wasmecpair_to_wif_testnet: (a: number, b: number) => void;
|
|
54
|
+
export const wasmrootwalletkeys_backup_key: (a: number) => number;
|
|
55
|
+
export const wasmrootwalletkeys_bitgo_key: (a: number) => number;
|
|
56
|
+
export const wasmrootwalletkeys_new: (a: number, b: number, c: number, d: number) => void;
|
|
57
|
+
export const wasmrootwalletkeys_user_key: (a: number) => number;
|
|
58
|
+
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;
|
|
59
|
+
export const wasmbip32_from_bip32_properties: (a: number, b: number) => void;
|
|
60
|
+
export const __wbg_bitgopsbt_free: (a: number, b: number) => void;
|
|
61
|
+
export const __wbg_fixedscriptwalletnamespace_free: (a: number, b: number) => void;
|
|
62
|
+
export const __wbg_wrapdescriptor_free: (a: number, b: number) => void;
|
|
63
|
+
export const __wbg_wrappsbt_free: (a: number, b: number) => void;
|
|
64
|
+
export const bitgopsbt_combine_musig2_nonces: (a: number, b: number, c: number) => void;
|
|
9
65
|
export const bitgopsbt_extract_transaction: (a: number, b: number) => void;
|
|
10
66
|
export const bitgopsbt_finalize_all_inputs: (a: number, b: number) => void;
|
|
11
67
|
export const bitgopsbt_from_bytes: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
68
|
+
export const bitgopsbt_generate_musig2_nonces: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
69
|
+
export const bitgopsbt_network: (a: number, b: number) => void;
|
|
12
70
|
export const bitgopsbt_parse_outputs_with_wallet_keys: (a: number, b: number, c: number) => void;
|
|
13
71
|
export const bitgopsbt_parse_transaction_with_wallet_keys: (a: number, b: number, c: number, d: number) => void;
|
|
14
72
|
export const bitgopsbt_serialize: (a: number, b: number) => void;
|
|
73
|
+
export const bitgopsbt_sign_with_privkey: (a: number, b: number, c: number, d: number) => void;
|
|
74
|
+
export const bitgopsbt_sign_with_xpriv: (a: number, b: number, c: number, d: number) => void;
|
|
15
75
|
export const bitgopsbt_unsigned_txid: (a: number, b: number) => void;
|
|
16
76
|
export const bitgopsbt_verify_replay_protection_signature: (a: number, b: number, c: number, d: number) => void;
|
|
17
|
-
export const
|
|
77
|
+
export const bitgopsbt_verify_signature_with_pub: (a: number, b: number, c: number, d: number) => void;
|
|
78
|
+
export const bitgopsbt_verify_signature_with_xpub: (a: number, b: number, c: number, d: number) => void;
|
|
18
79
|
export const fixedscriptwalletnamespace_address: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
19
80
|
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
81
|
export const wrapdescriptor_atDerivationIndex: (a: number, b: number, c: number) => void;
|
|
27
82
|
export const wrapdescriptor_descType: (a: number, b: number) => void;
|
|
28
83
|
export const wrapdescriptor_encode: (a: number, b: number) => void;
|
|
@@ -34,12 +89,6 @@ export const wrapdescriptor_node: (a: number, b: number) => void;
|
|
|
34
89
|
export const wrapdescriptor_scriptPubkey: (a: number, b: number) => void;
|
|
35
90
|
export const wrapdescriptor_toAsmString: (a: number, b: number) => void;
|
|
36
91
|
export const wrapdescriptor_toString: (a: number, b: number) => void;
|
|
37
|
-
export const wrapminiscript_encode: (a: number, b: number) => void;
|
|
38
|
-
export const wrapminiscript_fromBitcoinScript: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
39
|
-
export const wrapminiscript_fromString: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
40
|
-
export const wrapminiscript_node: (a: number, b: number) => void;
|
|
41
|
-
export const wrapminiscript_toAsmString: (a: number, b: number) => void;
|
|
42
|
-
export const wrapminiscript_toString: (a: number, b: number) => void;
|
|
43
92
|
export const wrappsbt_clone: (a: number) => number;
|
|
44
93
|
export const wrappsbt_deserialize: (a: number, b: number, c: number) => void;
|
|
45
94
|
export const wrappsbt_finalize: (a: number, b: number) => void;
|
|
@@ -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,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { RootWalletKeys } from "../../js/fixedScriptWallet/RootWalletKeys.js";
|
|
2
|
+
import { ECPair } from "../../js/ecpair.js";
|
|
3
|
+
import type { BitGoPsbt, NetworkName } from "../../js/fixedScriptWallet/index.js";
|
|
2
4
|
export type SignatureState = "unsigned" | "halfsigned" | "fullsigned";
|
|
3
5
|
export type Triple<T> = [T, T, T];
|
|
4
6
|
export type Bip32Derivation = {
|
|
@@ -79,6 +81,13 @@ export type Fixture = {
|
|
|
79
81
|
* Get PSBT buffer from a fixture
|
|
80
82
|
*/
|
|
81
83
|
export declare function getPsbtBuffer(fixture: Fixture): Buffer;
|
|
84
|
+
/**
|
|
85
|
+
* Get BitGoPsbt from a fixture
|
|
86
|
+
* @param fixture - The test fixture
|
|
87
|
+
* @param networkName - The network name for deserializing the PSBT
|
|
88
|
+
* @returns A BitGoPsbt instance
|
|
89
|
+
*/
|
|
90
|
+
export declare function getBitGoPsbt(fixture: Fixture, networkName: NetworkName): BitGoPsbt;
|
|
82
91
|
/**
|
|
83
92
|
* Load a PSBT fixture from JSON file
|
|
84
93
|
*/
|
|
@@ -86,7 +95,8 @@ export declare function loadPsbtFixture(network: string, signatureState: string)
|
|
|
86
95
|
/**
|
|
87
96
|
* Load wallet keys from fixture
|
|
88
97
|
*/
|
|
89
|
-
export declare function loadWalletKeysFromFixture(
|
|
98
|
+
export declare function loadWalletKeysFromFixture(fixture: Fixture): RootWalletKeys;
|
|
99
|
+
export declare function loadReplayProtectionKeyFromFixture(fixture: Fixture): ECPair;
|
|
90
100
|
/**
|
|
91
101
|
* Get extracted transaction hex from fixture
|
|
92
102
|
*/
|
|
@@ -1,8 +1,12 @@
|
|
|
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";
|
|
9
|
+
import { fixedScriptWallet } from "../../js/index.js";
|
|
6
10
|
const __filename = fileURLToPath(import.meta.url);
|
|
7
11
|
const __dirname = dirname(__filename);
|
|
8
12
|
/**
|
|
@@ -11,6 +15,15 @@ const __dirname = dirname(__filename);
|
|
|
11
15
|
export function getPsbtBuffer(fixture) {
|
|
12
16
|
return Buffer.from(fixture.psbtBase64, "base64");
|
|
13
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Get BitGoPsbt from a fixture
|
|
20
|
+
* @param fixture - The test fixture
|
|
21
|
+
* @param networkName - The network name for deserializing the PSBT
|
|
22
|
+
* @returns A BitGoPsbt instance
|
|
23
|
+
*/
|
|
24
|
+
export function getBitGoPsbt(fixture, networkName) {
|
|
25
|
+
return fixedScriptWallet.BitGoPsbt.fromBytes(getPsbtBuffer(fixture), networkName);
|
|
26
|
+
}
|
|
14
27
|
/**
|
|
15
28
|
* Load a PSBT fixture from JSON file
|
|
16
29
|
*/
|
|
@@ -22,16 +35,24 @@ export function loadPsbtFixture(network, signatureState) {
|
|
|
22
35
|
/**
|
|
23
36
|
* Load wallet keys from fixture
|
|
24
37
|
*/
|
|
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);
|
|
38
|
+
export function loadWalletKeysFromFixture(fixture) {
|
|
29
39
|
// Parse xprvs and convert to xpubs
|
|
30
40
|
const xpubs = fixture.walletKeys.map((xprv) => {
|
|
31
|
-
const key =
|
|
41
|
+
const key = BIP32.fromBase58(xprv);
|
|
32
42
|
return key.neutered();
|
|
33
43
|
});
|
|
34
|
-
|
|
44
|
+
const walletKeysLike = {
|
|
45
|
+
triple: xpubs,
|
|
46
|
+
derivationPrefixes: ["0/0", "0/0", "0/0"],
|
|
47
|
+
};
|
|
48
|
+
return RootWalletKeys.from(walletKeysLike);
|
|
49
|
+
}
|
|
50
|
+
export function loadReplayProtectionKeyFromFixture(fixture) {
|
|
51
|
+
// underived user key
|
|
52
|
+
const userBip32 = BIP32.fromBase58(fixture.walletKeys[0]);
|
|
53
|
+
assert(userBip32.privateKey);
|
|
54
|
+
const userECPair = ECPair.fromPrivateKey(Buffer.from(userBip32.privateKey));
|
|
55
|
+
return userECPair;
|
|
35
56
|
}
|
|
36
57
|
/**
|
|
37
58
|
* Get extracted transaction hex from fixture
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|