@bitgo/wasm-utxo 1.29.0 → 1.30.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.
@@ -62,6 +62,14 @@ export declare class BIP32 implements BIP32Interface {
62
62
  * @returns A BIP32 instance
63
63
  */
64
64
  static fromSeed(seed: Uint8Array, network?: string | null): BIP32;
65
+ /**
66
+ * Create a BIP32 master key from a string by hashing it with SHA256.
67
+ * Useful for deterministic test key generation.
68
+ * @param seedString - The seed string to hash
69
+ * @param network - Optional network string
70
+ * @returns A BIP32 instance
71
+ */
72
+ static fromSeedSha256(seedString: string, network?: string | null): BIP32;
65
73
  /**
66
74
  * Get the chain code as a Uint8Array
67
75
  */
@@ -63,6 +63,17 @@ class BIP32 {
63
63
  const wasm = wasm_utxo_js_1.WasmBIP32.from_seed(seed, network);
64
64
  return new BIP32(wasm);
65
65
  }
66
+ /**
67
+ * Create a BIP32 master key from a string by hashing it with SHA256.
68
+ * Useful for deterministic test key generation.
69
+ * @param seedString - The seed string to hash
70
+ * @param network - Optional network string
71
+ * @returns A BIP32 instance
72
+ */
73
+ static fromSeedSha256(seedString, network) {
74
+ const wasm = wasm_utxo_js_1.WasmBIP32.from_seed_sha256(seedString, network);
75
+ return new BIP32(wasm);
76
+ }
66
77
  /**
67
78
  * Get the chain code as a Uint8Array
68
79
  */
@@ -6,6 +6,7 @@ export * as utxolibCompat from "./utxolibCompat.js";
6
6
  export * as fixedScriptWallet from "./fixedScriptWallet/index.js";
7
7
  export * as bip32 from "./bip32.js";
8
8
  export * as ecpair from "./ecpair.js";
9
+ export * as testutils from "./testutils/index.js";
9
10
  export { ECPair } from "./ecpair.js";
10
11
  export { BIP32 } from "./bip32.js";
11
12
  export { Dimensions } from "./fixedScriptWallet/Dimensions.js";
@@ -44,3 +45,4 @@ export { WrapDescriptor as Descriptor } from "./wasm/wasm_utxo.js";
44
45
  export { WrapMiniscript as Miniscript } from "./wasm/wasm_utxo.js";
45
46
  export { WrapPsbt as Psbt } from "./wasm/wasm_utxo.js";
46
47
  export { DashTransaction, Transaction, ZcashTransaction } from "./transaction.js";
48
+ export { hasPsbtMagic } from "./psbt.js";
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.ZcashTransaction = exports.Transaction = exports.DashTransaction = exports.Psbt = exports.Miniscript = exports.Descriptor = exports.Dimensions = exports.BIP32 = exports.ECPair = exports.ecpair = exports.bip32 = exports.fixedScriptWallet = exports.utxolibCompat = exports.inscriptions = exports.bip322 = exports.ast = exports.address = void 0;
36
+ exports.hasPsbtMagic = exports.ZcashTransaction = exports.Transaction = exports.DashTransaction = exports.Psbt = exports.Miniscript = exports.Descriptor = exports.Dimensions = exports.BIP32 = exports.ECPair = exports.testutils = exports.ecpair = exports.bip32 = exports.fixedScriptWallet = exports.utxolibCompat = exports.inscriptions = exports.bip322 = exports.ast = exports.address = void 0;
37
37
  const wasm = __importStar(require("./wasm/wasm_utxo.js"));
38
38
  // we need to access the wasm module here, otherwise webpack gets all weird
39
39
  // and forgets to include it in the bundle
@@ -48,6 +48,7 @@ exports.utxolibCompat = __importStar(require("./utxolibCompat.js"));
48
48
  exports.fixedScriptWallet = __importStar(require("./fixedScriptWallet/index.js"));
49
49
  exports.bip32 = __importStar(require("./bip32.js"));
50
50
  exports.ecpair = __importStar(require("./ecpair.js"));
51
+ exports.testutils = __importStar(require("./testutils/index.js"));
51
52
  // Only the most commonly used classes and types are exported at the top level for convenience
52
53
  var ecpair_js_1 = require("./ecpair.js");
53
54
  Object.defineProperty(exports, "ECPair", { enumerable: true, get: function () { return ecpair_js_1.ECPair; } });
@@ -65,3 +66,5 @@ var transaction_js_1 = require("./transaction.js");
65
66
  Object.defineProperty(exports, "DashTransaction", { enumerable: true, get: function () { return transaction_js_1.DashTransaction; } });
66
67
  Object.defineProperty(exports, "Transaction", { enumerable: true, get: function () { return transaction_js_1.Transaction; } });
67
68
  Object.defineProperty(exports, "ZcashTransaction", { enumerable: true, get: function () { return transaction_js_1.ZcashTransaction; } });
69
+ var psbt_js_1 = require("./psbt.js");
70
+ Object.defineProperty(exports, "hasPsbtMagic", { enumerable: true, get: function () { return psbt_js_1.hasPsbtMagic; } });
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Check if a byte array has the PSBT magic bytes
3
+ *
4
+ * PSBTs start with the magic bytes "psbt" (0x70 0x73 0x62 0x74) followed by a separator 0xff.
5
+ * This method checks if the given bytes start with these 5 magic bytes.
6
+ *
7
+ * @param bytes - The byte array to check
8
+ * @returns true if the bytes start with PSBT magic, false otherwise
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import { hasPsbtMagic } from "@bitgo/wasm-utxo";
13
+ *
14
+ * if (hasPsbtMagic(data)) {
15
+ * const psbt = BitGoPsbt.fromBytes(data, network);
16
+ * }
17
+ * ```
18
+ */
19
+ export declare function hasPsbtMagic(bytes: Uint8Array): boolean;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasPsbtMagic = hasPsbtMagic;
4
+ /** PSBT magic bytes: "psbt" (0x70 0x73 0x62 0x74) followed by separator 0xff */
5
+ const PSBT_MAGIC = new Uint8Array([0x70, 0x73, 0x62, 0x74, 0xff]);
6
+ /**
7
+ * Check if a byte array has the PSBT magic bytes
8
+ *
9
+ * PSBTs start with the magic bytes "psbt" (0x70 0x73 0x62 0x74) followed by a separator 0xff.
10
+ * This method checks if the given bytes start with these 5 magic bytes.
11
+ *
12
+ * @param bytes - The byte array to check
13
+ * @returns true if the bytes start with PSBT magic, false otherwise
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * import { hasPsbtMagic } from "@bitgo/wasm-utxo";
18
+ *
19
+ * if (hasPsbtMagic(data)) {
20
+ * const psbt = BitGoPsbt.fromBytes(data, network);
21
+ * }
22
+ * ```
23
+ */
24
+ function hasPsbtMagic(bytes) {
25
+ if (bytes.length < PSBT_MAGIC.length) {
26
+ return false;
27
+ }
28
+ for (let i = 0; i < PSBT_MAGIC.length; i++) {
29
+ if (bytes[i] !== PSBT_MAGIC[i]) {
30
+ return false;
31
+ }
32
+ }
33
+ return true;
34
+ }
@@ -1,37 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  Object.defineProperty(exports, "__esModule", { value: true });
36
3
  exports.getKey = getKey;
37
4
  exports.getKeyTriple = getKeyTriple;
@@ -39,7 +6,6 @@ exports.getWalletKeysForSeed = getWalletKeysForSeed;
39
6
  exports.getDefaultWalletKeys = getDefaultWalletKeys;
40
7
  exports.getKeyName = getKeyName;
41
8
  exports.getDefaultCosigner = getDefaultCosigner;
42
- const crypto = __importStar(require("crypto"));
43
9
  const bip32_js_1 = require("../bip32.js");
44
10
  const RootWalletKeys_js_1 = require("../fixedScriptWallet/RootWalletKeys.js");
45
11
  /**
@@ -56,7 +22,7 @@ const RootWalletKeys_js_1 = require("../fixedScriptWallet/RootWalletKeys.js");
56
22
  * ```
57
23
  */
58
24
  function getKey(seed) {
59
- return bip32_js_1.BIP32.fromSeed(crypto.createHash("sha256").update(seed).digest());
25
+ return bip32_js_1.BIP32.fromSeedSha256(seed);
60
26
  }
61
27
  /**
62
28
  * Generate a triple of BIP32 keys for a 2-of-3 multisig wallet.
@@ -772,6 +772,11 @@ export class WasmBIP32 {
772
772
  * Derive a hardened child key (only works for private keys)
773
773
  */
774
774
  derive_hardened(index: number): WasmBIP32;
775
+ /**
776
+ * Create a BIP32 master key from a string by hashing it with SHA256.
777
+ * This is useful for deterministic test key generation.
778
+ */
779
+ static from_seed_sha256(seed_string: string, network?: string | null): WasmBIP32;
775
780
  /**
776
781
  * Create a BIP32 key from a BIP32Interface JavaScript object properties
777
782
  * Expects an object with: network.bip32.public, depth, parentFingerprint,
@@ -2357,6 +2357,32 @@ class WasmBIP32 {
2357
2357
  wasm.__wbindgen_add_to_stack_pointer(16);
2358
2358
  }
2359
2359
  }
2360
+ /**
2361
+ * Create a BIP32 master key from a string by hashing it with SHA256.
2362
+ * This is useful for deterministic test key generation.
2363
+ * @param {string} seed_string
2364
+ * @param {string | null} [network]
2365
+ * @returns {WasmBIP32}
2366
+ */
2367
+ static from_seed_sha256(seed_string, network) {
2368
+ try {
2369
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
2370
+ const ptr0 = passStringToWasm0(seed_string, wasm.__wbindgen_export, wasm.__wbindgen_export2);
2371
+ const len0 = WASM_VECTOR_LEN;
2372
+ var ptr1 = isLikeNone(network) ? 0 : passStringToWasm0(network, wasm.__wbindgen_export, wasm.__wbindgen_export2);
2373
+ var len1 = WASM_VECTOR_LEN;
2374
+ wasm.wasmbip32_from_seed_sha256(retptr, ptr0, len0, ptr1, len1);
2375
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
2376
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
2377
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
2378
+ if (r2) {
2379
+ throw takeObject(r1);
2380
+ }
2381
+ return WasmBIP32.__wrap(r0);
2382
+ } finally {
2383
+ wasm.__wbindgen_add_to_stack_pointer(16);
2384
+ }
2385
+ }
2360
2386
  /**
2361
2387
  * Get the parent fingerprint
2362
2388
  * @returns {number}
Binary file
@@ -113,6 +113,7 @@ export const wasmbip32_fingerprint: (a: number) => number;
113
113
  export const wasmbip32_from_base58: (a: number, b: number, c: number) => void;
114
114
  export const wasmbip32_from_bip32_interface: (a: number, b: number) => void;
115
115
  export const wasmbip32_from_seed: (a: number, b: number, c: number, d: number, e: number) => void;
116
+ export const wasmbip32_from_seed_sha256: (a: number, b: number, c: number, d: number, e: number) => void;
116
117
  export const wasmbip32_from_xprv: (a: number, b: number, c: number) => void;
117
118
  export const wasmbip32_from_xpub: (a: number, b: number, c: number) => void;
118
119
  export const wasmbip32_identifier: (a: number) => number;
@@ -62,6 +62,14 @@ export declare class BIP32 implements BIP32Interface {
62
62
  * @returns A BIP32 instance
63
63
  */
64
64
  static fromSeed(seed: Uint8Array, network?: string | null): BIP32;
65
+ /**
66
+ * Create a BIP32 master key from a string by hashing it with SHA256.
67
+ * Useful for deterministic test key generation.
68
+ * @param seedString - The seed string to hash
69
+ * @param network - Optional network string
70
+ * @returns A BIP32 instance
71
+ */
72
+ static fromSeedSha256(seedString: string, network?: string | null): BIP32;
65
73
  /**
66
74
  * Get the chain code as a Uint8Array
67
75
  */
@@ -59,6 +59,17 @@ export class BIP32 {
59
59
  const wasm = WasmBIP32.from_seed(seed, network);
60
60
  return new BIP32(wasm);
61
61
  }
62
+ /**
63
+ * Create a BIP32 master key from a string by hashing it with SHA256.
64
+ * Useful for deterministic test key generation.
65
+ * @param seedString - The seed string to hash
66
+ * @param network - Optional network string
67
+ * @returns A BIP32 instance
68
+ */
69
+ static fromSeedSha256(seedString, network) {
70
+ const wasm = WasmBIP32.from_seed_sha256(seedString, network);
71
+ return new BIP32(wasm);
72
+ }
62
73
  /**
63
74
  * Get the chain code as a Uint8Array
64
75
  */
@@ -6,6 +6,7 @@ export * as utxolibCompat from "./utxolibCompat.js";
6
6
  export * as fixedScriptWallet from "./fixedScriptWallet/index.js";
7
7
  export * as bip32 from "./bip32.js";
8
8
  export * as ecpair from "./ecpair.js";
9
+ export * as testutils from "./testutils/index.js";
9
10
  export { ECPair } from "./ecpair.js";
10
11
  export { BIP32 } from "./bip32.js";
11
12
  export { Dimensions } from "./fixedScriptWallet/Dimensions.js";
@@ -44,3 +45,4 @@ export { WrapDescriptor as Descriptor } from "./wasm/wasm_utxo.js";
44
45
  export { WrapMiniscript as Miniscript } from "./wasm/wasm_utxo.js";
45
46
  export { WrapPsbt as Psbt } from "./wasm/wasm_utxo.js";
46
47
  export { DashTransaction, Transaction, ZcashTransaction } from "./transaction.js";
48
+ export { hasPsbtMagic } from "./psbt.js";
@@ -12,6 +12,7 @@ export * as utxolibCompat from "./utxolibCompat.js";
12
12
  export * as fixedScriptWallet from "./fixedScriptWallet/index.js";
13
13
  export * as bip32 from "./bip32.js";
14
14
  export * as ecpair from "./ecpair.js";
15
+ export * as testutils from "./testutils/index.js";
15
16
  // Only the most commonly used classes and types are exported at the top level for convenience
16
17
  export { ECPair } from "./ecpair.js";
17
18
  export { BIP32 } from "./bip32.js";
@@ -20,3 +21,4 @@ export { WrapDescriptor as Descriptor } from "./wasm/wasm_utxo.js";
20
21
  export { WrapMiniscript as Miniscript } from "./wasm/wasm_utxo.js";
21
22
  export { WrapPsbt as Psbt } from "./wasm/wasm_utxo.js";
22
23
  export { DashTransaction, Transaction, ZcashTransaction } from "./transaction.js";
24
+ export { hasPsbtMagic } from "./psbt.js";
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Check if a byte array has the PSBT magic bytes
3
+ *
4
+ * PSBTs start with the magic bytes "psbt" (0x70 0x73 0x62 0x74) followed by a separator 0xff.
5
+ * This method checks if the given bytes start with these 5 magic bytes.
6
+ *
7
+ * @param bytes - The byte array to check
8
+ * @returns true if the bytes start with PSBT magic, false otherwise
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import { hasPsbtMagic } from "@bitgo/wasm-utxo";
13
+ *
14
+ * if (hasPsbtMagic(data)) {
15
+ * const psbt = BitGoPsbt.fromBytes(data, network);
16
+ * }
17
+ * ```
18
+ */
19
+ export declare function hasPsbtMagic(bytes: Uint8Array): boolean;
@@ -0,0 +1,31 @@
1
+ /** PSBT magic bytes: "psbt" (0x70 0x73 0x62 0x74) followed by separator 0xff */
2
+ const PSBT_MAGIC = new Uint8Array([0x70, 0x73, 0x62, 0x74, 0xff]);
3
+ /**
4
+ * Check if a byte array has the PSBT magic bytes
5
+ *
6
+ * PSBTs start with the magic bytes "psbt" (0x70 0x73 0x62 0x74) followed by a separator 0xff.
7
+ * This method checks if the given bytes start with these 5 magic bytes.
8
+ *
9
+ * @param bytes - The byte array to check
10
+ * @returns true if the bytes start with PSBT magic, false otherwise
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import { hasPsbtMagic } from "@bitgo/wasm-utxo";
15
+ *
16
+ * if (hasPsbtMagic(data)) {
17
+ * const psbt = BitGoPsbt.fromBytes(data, network);
18
+ * }
19
+ * ```
20
+ */
21
+ export function hasPsbtMagic(bytes) {
22
+ if (bytes.length < PSBT_MAGIC.length) {
23
+ return false;
24
+ }
25
+ for (let i = 0; i < PSBT_MAGIC.length; i++) {
26
+ if (bytes[i] !== PSBT_MAGIC[i]) {
27
+ return false;
28
+ }
29
+ }
30
+ return true;
31
+ }
@@ -1,4 +1,3 @@
1
- import * as crypto from "crypto";
2
1
  import { BIP32 } from "../bip32.js";
3
2
  import { RootWalletKeys } from "../fixedScriptWallet/RootWalletKeys.js";
4
3
  /**
@@ -15,7 +14,7 @@ import { RootWalletKeys } from "../fixedScriptWallet/RootWalletKeys.js";
15
14
  * ```
16
15
  */
17
16
  export function getKey(seed) {
18
- return BIP32.fromSeed(crypto.createHash("sha256").update(seed).digest());
17
+ return BIP32.fromSeedSha256(seed);
19
18
  }
20
19
  /**
21
20
  * Generate a triple of BIP32 keys for a 2-of-3 multisig wallet.
@@ -772,6 +772,11 @@ export class WasmBIP32 {
772
772
  * Derive a hardened child key (only works for private keys)
773
773
  */
774
774
  derive_hardened(index: number): WasmBIP32;
775
+ /**
776
+ * Create a BIP32 master key from a string by hashing it with SHA256.
777
+ * This is useful for deterministic test key generation.
778
+ */
779
+ static from_seed_sha256(seed_string: string, network?: string | null): WasmBIP32;
775
780
  /**
776
781
  * Create a BIP32 key from a BIP32Interface JavaScript object properties
777
782
  * Expects an object with: network.bip32.public, depth, parentFingerprint,
@@ -2360,6 +2360,32 @@ export class WasmBIP32 {
2360
2360
  wasm.__wbindgen_add_to_stack_pointer(16);
2361
2361
  }
2362
2362
  }
2363
+ /**
2364
+ * Create a BIP32 master key from a string by hashing it with SHA256.
2365
+ * This is useful for deterministic test key generation.
2366
+ * @param {string} seed_string
2367
+ * @param {string | null} [network]
2368
+ * @returns {WasmBIP32}
2369
+ */
2370
+ static from_seed_sha256(seed_string, network) {
2371
+ try {
2372
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
2373
+ const ptr0 = passStringToWasm0(seed_string, wasm.__wbindgen_export, wasm.__wbindgen_export2);
2374
+ const len0 = WASM_VECTOR_LEN;
2375
+ var ptr1 = isLikeNone(network) ? 0 : passStringToWasm0(network, wasm.__wbindgen_export, wasm.__wbindgen_export2);
2376
+ var len1 = WASM_VECTOR_LEN;
2377
+ wasm.wasmbip32_from_seed_sha256(retptr, ptr0, len0, ptr1, len1);
2378
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
2379
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
2380
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
2381
+ if (r2) {
2382
+ throw takeObject(r1);
2383
+ }
2384
+ return WasmBIP32.__wrap(r0);
2385
+ } finally {
2386
+ wasm.__wbindgen_add_to_stack_pointer(16);
2387
+ }
2388
+ }
2363
2389
  /**
2364
2390
  * Get the parent fingerprint
2365
2391
  * @returns {number}
Binary file
@@ -113,6 +113,7 @@ export const wasmbip32_fingerprint: (a: number) => number;
113
113
  export const wasmbip32_from_base58: (a: number, b: number, c: number) => void;
114
114
  export const wasmbip32_from_bip32_interface: (a: number, b: number) => void;
115
115
  export const wasmbip32_from_seed: (a: number, b: number, c: number, d: number, e: number) => void;
116
+ export const wasmbip32_from_seed_sha256: (a: number, b: number, c: number, d: number, e: number) => void;
116
117
  export const wasmbip32_from_xprv: (a: number, b: number, c: number) => void;
117
118
  export const wasmbip32_from_xpub: (a: number, b: number, c: number) => void;
118
119
  export const wasmbip32_identifier: (a: number) => number;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bitgo/wasm-utxo",
3
3
  "description": "WebAssembly wrapper for rust-bitcoin (beta)",
4
- "version": "1.29.0",
4
+ "version": "1.30.0",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",