@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
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { WasmBIP32 } from "./wasm/wasm_utxo.js";
|
|
2
|
+
/**
|
|
3
|
+
* BIP32 wrapper class for extended key operations
|
|
4
|
+
*/
|
|
5
|
+
export class BIP32 {
|
|
6
|
+
_wasm;
|
|
7
|
+
constructor(_wasm) {
|
|
8
|
+
this._wasm = _wasm;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Create a BIP32 instance from a WasmBIP32 instance (internal use)
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
static fromWasm(wasm) {
|
|
15
|
+
return new BIP32(wasm);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Convert BIP32Arg to BIP32 instance
|
|
19
|
+
* @param key - The BIP32 key in various formats
|
|
20
|
+
* @returns BIP32 instance
|
|
21
|
+
*/
|
|
22
|
+
static from(key) {
|
|
23
|
+
// Short-circuit if already a BIP32 instance
|
|
24
|
+
if (key instanceof BIP32) {
|
|
25
|
+
return key;
|
|
26
|
+
}
|
|
27
|
+
// If it's a WasmBIP32 instance, wrap it
|
|
28
|
+
if (key instanceof WasmBIP32) {
|
|
29
|
+
return new BIP32(key);
|
|
30
|
+
}
|
|
31
|
+
// If it's a string, parse from base58
|
|
32
|
+
if (typeof key === "string") {
|
|
33
|
+
const wasm = WasmBIP32.from_base58(key);
|
|
34
|
+
return new BIP32(wasm);
|
|
35
|
+
}
|
|
36
|
+
// If it's an object (BIP32Interface), use from_bip32_interface
|
|
37
|
+
if (typeof key === "object" && key !== null) {
|
|
38
|
+
const wasm = WasmBIP32.from_bip32_interface(key);
|
|
39
|
+
return new BIP32(wasm);
|
|
40
|
+
}
|
|
41
|
+
throw new Error("Invalid BIP32Arg type");
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Create a BIP32 key from a base58 string (xpub/xprv/tpub/tprv)
|
|
45
|
+
* @param base58Str - The base58-encoded extended key string
|
|
46
|
+
* @returns A BIP32 instance
|
|
47
|
+
*/
|
|
48
|
+
static fromBase58(base58Str) {
|
|
49
|
+
const wasm = WasmBIP32.from_base58(base58Str);
|
|
50
|
+
return new BIP32(wasm);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Create a BIP32 master key from a seed
|
|
54
|
+
* @param seed - The seed bytes
|
|
55
|
+
* @param network - Optional network string
|
|
56
|
+
* @returns A BIP32 instance
|
|
57
|
+
*/
|
|
58
|
+
static fromSeed(seed, network) {
|
|
59
|
+
const wasm = WasmBIP32.from_seed(seed, network);
|
|
60
|
+
return new BIP32(wasm);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Get the chain code as a Uint8Array
|
|
64
|
+
*/
|
|
65
|
+
get chainCode() {
|
|
66
|
+
return this._wasm.chain_code;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get the depth
|
|
70
|
+
*/
|
|
71
|
+
get depth() {
|
|
72
|
+
return this._wasm.depth;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Get the child index
|
|
76
|
+
*/
|
|
77
|
+
get index() {
|
|
78
|
+
return this._wasm.index;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Get the parent fingerprint
|
|
82
|
+
*/
|
|
83
|
+
get parentFingerprint() {
|
|
84
|
+
return this._wasm.parent_fingerprint;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Get the private key as a Uint8Array (if available)
|
|
88
|
+
*/
|
|
89
|
+
get privateKey() {
|
|
90
|
+
return this._wasm.private_key;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Get the public key as a Uint8Array
|
|
94
|
+
*/
|
|
95
|
+
get publicKey() {
|
|
96
|
+
return this._wasm.public_key;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Get the identifier as a Uint8Array
|
|
100
|
+
*/
|
|
101
|
+
get identifier() {
|
|
102
|
+
return this._wasm.identifier;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Get the fingerprint as a Uint8Array
|
|
106
|
+
*/
|
|
107
|
+
get fingerprint() {
|
|
108
|
+
return this._wasm.fingerprint;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Check if this is a neutered (public) key
|
|
112
|
+
* @returns True if the key is public-only (neutered)
|
|
113
|
+
*/
|
|
114
|
+
isNeutered() {
|
|
115
|
+
return this._wasm.is_neutered();
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Get the neutered (public) version of this key
|
|
119
|
+
* @returns A new BIP32 instance containing only the public key
|
|
120
|
+
*/
|
|
121
|
+
neutered() {
|
|
122
|
+
const wasm = this._wasm.neutered();
|
|
123
|
+
return new BIP32(wasm);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Serialize to base58 string
|
|
127
|
+
* @returns The base58-encoded extended key string
|
|
128
|
+
*/
|
|
129
|
+
toBase58() {
|
|
130
|
+
return this._wasm.to_base58();
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Get the WIF encoding of the private key
|
|
134
|
+
* @returns The WIF-encoded private key
|
|
135
|
+
*/
|
|
136
|
+
toWIF() {
|
|
137
|
+
return this._wasm.to_wif();
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Derive a normal (non-hardened) child key
|
|
141
|
+
* @param index - The child index
|
|
142
|
+
* @returns A new BIP32 instance for the derived key
|
|
143
|
+
*/
|
|
144
|
+
derive(index) {
|
|
145
|
+
const wasm = this._wasm.derive(index);
|
|
146
|
+
return new BIP32(wasm);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Derive a hardened child key (only works for private keys)
|
|
150
|
+
* @param index - The child index
|
|
151
|
+
* @returns A new BIP32 instance for the derived key
|
|
152
|
+
*/
|
|
153
|
+
deriveHardened(index) {
|
|
154
|
+
const wasm = this._wasm.derive_hardened(index);
|
|
155
|
+
return new BIP32(wasm);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Derive a key using a derivation path (e.g., "0/1/2" or "m/0/1/2")
|
|
159
|
+
* @param path - The derivation path string
|
|
160
|
+
* @returns A new BIP32 instance for the derived key
|
|
161
|
+
*/
|
|
162
|
+
derivePath(path) {
|
|
163
|
+
const wasm = this._wasm.derive_path(path);
|
|
164
|
+
return new BIP32(wasm);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Get the underlying WASM instance (internal use only)
|
|
168
|
+
* @internal
|
|
169
|
+
*/
|
|
170
|
+
get wasm() {
|
|
171
|
+
return this._wasm;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { WasmECPair } from "./wasm/wasm_utxo.js";
|
|
2
|
+
/**
|
|
3
|
+
* ECPairArg represents the various forms that ECPair keys can take
|
|
4
|
+
* before being converted to a WasmECPair instance
|
|
5
|
+
*/
|
|
6
|
+
export type ECPairArg =
|
|
7
|
+
/** Private key (32 bytes) or compressed public key (33 bytes) as Buffer/Uint8Array */
|
|
8
|
+
Uint8Array
|
|
9
|
+
/** ECPair instance */
|
|
10
|
+
| ECPair
|
|
11
|
+
/** WasmECPair instance */
|
|
12
|
+
| WasmECPair;
|
|
13
|
+
/**
|
|
14
|
+
* ECPair interface for elliptic curve key pair operations
|
|
15
|
+
*/
|
|
16
|
+
export interface ECPairInterface {
|
|
17
|
+
publicKey: Uint8Array;
|
|
18
|
+
privateKey?: Uint8Array;
|
|
19
|
+
toWIF(): string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* ECPair wrapper class for elliptic curve key pair operations
|
|
23
|
+
*/
|
|
24
|
+
export declare class ECPair implements ECPairInterface {
|
|
25
|
+
private _wasm;
|
|
26
|
+
private constructor();
|
|
27
|
+
/**
|
|
28
|
+
* Create an ECPair instance from a WasmECPair instance (internal use)
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
static fromWasm(wasm: WasmECPair): ECPair;
|
|
32
|
+
/**
|
|
33
|
+
* Convert ECPairArg to ECPair instance
|
|
34
|
+
* @param key - The ECPair key in various formats
|
|
35
|
+
* @returns ECPair instance
|
|
36
|
+
*/
|
|
37
|
+
static from(key: ECPairArg): ECPair;
|
|
38
|
+
/**
|
|
39
|
+
* Create an ECPair from a private key (always uses compressed keys)
|
|
40
|
+
* @param buffer - The 32-byte private key
|
|
41
|
+
* @returns An ECPair instance
|
|
42
|
+
*/
|
|
43
|
+
static fromPrivateKey(buffer: Uint8Array): ECPair;
|
|
44
|
+
/**
|
|
45
|
+
* Create an ECPair from a compressed public key
|
|
46
|
+
* @param buffer - The compressed public key bytes (33 bytes)
|
|
47
|
+
* @returns An ECPair instance
|
|
48
|
+
*/
|
|
49
|
+
static fromPublicKey(buffer: Uint8Array): ECPair;
|
|
50
|
+
/**
|
|
51
|
+
* Create an ECPair from a WIF string (auto-detects network from WIF)
|
|
52
|
+
* @param wifString - The WIF-encoded private key string
|
|
53
|
+
* @returns An ECPair instance
|
|
54
|
+
*/
|
|
55
|
+
static fromWIF(wifString: string): ECPair;
|
|
56
|
+
/**
|
|
57
|
+
* Create an ECPair from a mainnet WIF string
|
|
58
|
+
* @param wifString - The WIF-encoded private key string
|
|
59
|
+
* @returns An ECPair instance
|
|
60
|
+
*/
|
|
61
|
+
static fromWIFMainnet(wifString: string): ECPair;
|
|
62
|
+
/**
|
|
63
|
+
* Create an ECPair from a testnet WIF string
|
|
64
|
+
* @param wifString - The WIF-encoded private key string
|
|
65
|
+
* @returns An ECPair instance
|
|
66
|
+
*/
|
|
67
|
+
static fromWIFTestnet(wifString: string): ECPair;
|
|
68
|
+
/**
|
|
69
|
+
* Get the private key as a Uint8Array (if available)
|
|
70
|
+
*/
|
|
71
|
+
get privateKey(): Uint8Array | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* Get the public key as a Uint8Array
|
|
74
|
+
*/
|
|
75
|
+
get publicKey(): Uint8Array;
|
|
76
|
+
/**
|
|
77
|
+
* Convert to WIF string (mainnet)
|
|
78
|
+
* @returns The WIF-encoded private key
|
|
79
|
+
*/
|
|
80
|
+
toWIF(): string;
|
|
81
|
+
/**
|
|
82
|
+
* Convert to mainnet WIF string
|
|
83
|
+
* @returns The WIF-encoded private key
|
|
84
|
+
*/
|
|
85
|
+
toWIFMainnet(): string;
|
|
86
|
+
/**
|
|
87
|
+
* Convert to testnet WIF string
|
|
88
|
+
* @returns The WIF-encoded private key
|
|
89
|
+
*/
|
|
90
|
+
toWIFTestnet(): string;
|
|
91
|
+
/**
|
|
92
|
+
* Get the underlying WASM instance (internal use only)
|
|
93
|
+
* @internal
|
|
94
|
+
*/
|
|
95
|
+
get wasm(): WasmECPair;
|
|
96
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { WasmECPair } from "./wasm/wasm_utxo.js";
|
|
2
|
+
/**
|
|
3
|
+
* ECPair wrapper class for elliptic curve key pair operations
|
|
4
|
+
*/
|
|
5
|
+
export class ECPair {
|
|
6
|
+
_wasm;
|
|
7
|
+
constructor(_wasm) {
|
|
8
|
+
this._wasm = _wasm;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Create an ECPair instance from a WasmECPair instance (internal use)
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
static fromWasm(wasm) {
|
|
15
|
+
return new ECPair(wasm);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Convert ECPairArg to ECPair instance
|
|
19
|
+
* @param key - The ECPair key in various formats
|
|
20
|
+
* @returns ECPair instance
|
|
21
|
+
*/
|
|
22
|
+
static from(key) {
|
|
23
|
+
// Short-circuit if already an ECPair instance
|
|
24
|
+
if (key instanceof ECPair) {
|
|
25
|
+
return key;
|
|
26
|
+
}
|
|
27
|
+
// If it's a WasmECPair instance, wrap it
|
|
28
|
+
if (key instanceof WasmECPair) {
|
|
29
|
+
return new ECPair(key);
|
|
30
|
+
}
|
|
31
|
+
// Parse from Buffer/Uint8Array
|
|
32
|
+
// Check length to determine if it's a private key (32 bytes) or public key (33 bytes)
|
|
33
|
+
if (key.length === 32) {
|
|
34
|
+
const wasm = WasmECPair.from_private_key(key);
|
|
35
|
+
return new ECPair(wasm);
|
|
36
|
+
}
|
|
37
|
+
else if (key.length === 33) {
|
|
38
|
+
const wasm = WasmECPair.from_public_key(key);
|
|
39
|
+
return new ECPair(wasm);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
throw new Error(`Invalid key length: ${key.length}. Expected 32 bytes (private key) or 33 bytes (compressed public key)`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Create an ECPair from a private key (always uses compressed keys)
|
|
47
|
+
* @param buffer - The 32-byte private key
|
|
48
|
+
* @returns An ECPair instance
|
|
49
|
+
*/
|
|
50
|
+
static fromPrivateKey(buffer) {
|
|
51
|
+
const wasm = WasmECPair.from_private_key(buffer);
|
|
52
|
+
return new ECPair(wasm);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Create an ECPair from a compressed public key
|
|
56
|
+
* @param buffer - The compressed public key bytes (33 bytes)
|
|
57
|
+
* @returns An ECPair instance
|
|
58
|
+
*/
|
|
59
|
+
static fromPublicKey(buffer) {
|
|
60
|
+
const wasm = WasmECPair.from_public_key(buffer);
|
|
61
|
+
return new ECPair(wasm);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Create an ECPair from a WIF string (auto-detects network from WIF)
|
|
65
|
+
* @param wifString - The WIF-encoded private key string
|
|
66
|
+
* @returns An ECPair instance
|
|
67
|
+
*/
|
|
68
|
+
static fromWIF(wifString) {
|
|
69
|
+
const wasm = WasmECPair.from_wif(wifString);
|
|
70
|
+
return new ECPair(wasm);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Create an ECPair from a mainnet WIF string
|
|
74
|
+
* @param wifString - The WIF-encoded private key string
|
|
75
|
+
* @returns An ECPair instance
|
|
76
|
+
*/
|
|
77
|
+
static fromWIFMainnet(wifString) {
|
|
78
|
+
const wasm = WasmECPair.from_wif_mainnet(wifString);
|
|
79
|
+
return new ECPair(wasm);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Create an ECPair from a testnet WIF string
|
|
83
|
+
* @param wifString - The WIF-encoded private key string
|
|
84
|
+
* @returns An ECPair instance
|
|
85
|
+
*/
|
|
86
|
+
static fromWIFTestnet(wifString) {
|
|
87
|
+
const wasm = WasmECPair.from_wif_testnet(wifString);
|
|
88
|
+
return new ECPair(wasm);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Get the private key as a Uint8Array (if available)
|
|
92
|
+
*/
|
|
93
|
+
get privateKey() {
|
|
94
|
+
return this._wasm.private_key;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Get the public key as a Uint8Array
|
|
98
|
+
*/
|
|
99
|
+
get publicKey() {
|
|
100
|
+
return this._wasm.public_key;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Convert to WIF string (mainnet)
|
|
104
|
+
* @returns The WIF-encoded private key
|
|
105
|
+
*/
|
|
106
|
+
toWIF() {
|
|
107
|
+
return this._wasm.to_wif();
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Convert to mainnet WIF string
|
|
111
|
+
* @returns The WIF-encoded private key
|
|
112
|
+
*/
|
|
113
|
+
toWIFMainnet() {
|
|
114
|
+
return this._wasm.to_wif_mainnet();
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Convert to testnet WIF string
|
|
118
|
+
* @returns The WIF-encoded private key
|
|
119
|
+
*/
|
|
120
|
+
toWIFTestnet() {
|
|
121
|
+
return this._wasm.to_wif_testnet();
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Get the underlying WASM instance (internal use only)
|
|
125
|
+
* @internal
|
|
126
|
+
*/
|
|
127
|
+
get wasm() {
|
|
128
|
+
return this._wasm;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { type WalletKeysArg } from "./RootWalletKeys.js";
|
|
2
|
+
import { type ReplayProtectionArg } from "./ReplayProtection.js";
|
|
3
|
+
import { type BIP32Arg } from "../bip32.js";
|
|
4
|
+
import { type ECPairArg } from "../ecpair.js";
|
|
5
|
+
import type { UtxolibName } from "../utxolibCompat.js";
|
|
6
|
+
import type { CoinName } from "../coinName.js";
|
|
7
|
+
export type NetworkName = UtxolibName | CoinName;
|
|
8
|
+
export type ScriptId = {
|
|
9
|
+
chain: number;
|
|
10
|
+
index: number;
|
|
11
|
+
};
|
|
12
|
+
export type InputScriptType = "p2shP2pk" | "p2sh" | "p2shP2wsh" | "p2wsh" | "p2trLegacy" | "p2trMusig2ScriptPath" | "p2trMusig2KeyPath";
|
|
13
|
+
export type ParsedInput = {
|
|
14
|
+
address: string;
|
|
15
|
+
script: Uint8Array;
|
|
16
|
+
value: bigint;
|
|
17
|
+
scriptId: ScriptId | null;
|
|
18
|
+
scriptType: InputScriptType;
|
|
19
|
+
};
|
|
20
|
+
export type ParsedOutput = {
|
|
21
|
+
address: string | null;
|
|
22
|
+
script: Uint8Array;
|
|
23
|
+
value: bigint;
|
|
24
|
+
scriptId: ScriptId | null;
|
|
25
|
+
};
|
|
26
|
+
export type ParsedTransaction = {
|
|
27
|
+
inputs: ParsedInput[];
|
|
28
|
+
outputs: ParsedOutput[];
|
|
29
|
+
spendAmount: bigint;
|
|
30
|
+
minerFee: bigint;
|
|
31
|
+
virtualSize: number;
|
|
32
|
+
};
|
|
33
|
+
export declare class BitGoPsbt {
|
|
34
|
+
private wasm;
|
|
35
|
+
private constructor();
|
|
36
|
+
/**
|
|
37
|
+
* Deserialize a PSBT from bytes
|
|
38
|
+
* @param bytes - The PSBT bytes
|
|
39
|
+
* @param network - The network to use for deserialization (either utxolib name like "bitcoin" or coin name like "btc")
|
|
40
|
+
* @returns A BitGoPsbt instance
|
|
41
|
+
*/
|
|
42
|
+
static fromBytes(bytes: Uint8Array, network: NetworkName): BitGoPsbt;
|
|
43
|
+
/**
|
|
44
|
+
* Get the unsigned transaction ID
|
|
45
|
+
* @returns The unsigned transaction ID
|
|
46
|
+
*/
|
|
47
|
+
unsignedTxid(): string;
|
|
48
|
+
/**
|
|
49
|
+
* Parse transaction with wallet keys to identify wallet inputs/outputs
|
|
50
|
+
* @param walletKeys - The wallet keys to use for identification
|
|
51
|
+
* @param replayProtection - Scripts that are allowed as inputs without wallet validation
|
|
52
|
+
* @returns Parsed transaction information
|
|
53
|
+
*/
|
|
54
|
+
parseTransactionWithWalletKeys(walletKeys: WalletKeysArg, replayProtection: ReplayProtectionArg): ParsedTransaction;
|
|
55
|
+
/**
|
|
56
|
+
* Parse outputs with wallet keys to identify which outputs belong to a wallet
|
|
57
|
+
* with the given wallet keys.
|
|
58
|
+
*
|
|
59
|
+
* This is useful in cases where we want to identify outputs that belong to a different
|
|
60
|
+
* wallet than the inputs.
|
|
61
|
+
*
|
|
62
|
+
* @param walletKeys - The wallet keys to use for identification
|
|
63
|
+
* @returns Array of parsed outputs
|
|
64
|
+
* @note This method does NOT validate wallet inputs. It only parses outputs.
|
|
65
|
+
*/
|
|
66
|
+
parseOutputsWithWalletKeys(walletKeys: WalletKeysArg): ParsedOutput[];
|
|
67
|
+
/**
|
|
68
|
+
* Verify if a valid signature exists for a given key at the specified input index.
|
|
69
|
+
*
|
|
70
|
+
* This method can verify signatures using either:
|
|
71
|
+
* - Extended public key (xpub): Derives the public key using the derivation path from PSBT
|
|
72
|
+
* - ECPair (private key): Extracts the public key and verifies directly
|
|
73
|
+
*
|
|
74
|
+
* When using xpub, it supports:
|
|
75
|
+
* - ECDSA signatures (for legacy/SegWit inputs)
|
|
76
|
+
* - Schnorr signatures (for Taproot script path inputs)
|
|
77
|
+
* - MuSig2 partial signatures (for Taproot keypath MuSig2 inputs)
|
|
78
|
+
*
|
|
79
|
+
* When using ECPair, it supports:
|
|
80
|
+
* - ECDSA signatures (for legacy/SegWit inputs)
|
|
81
|
+
* - Schnorr signatures (for Taproot script path inputs)
|
|
82
|
+
* Note: MuSig2 inputs require xpubs for derivation
|
|
83
|
+
*
|
|
84
|
+
* @param inputIndex - The index of the input to check (0-based)
|
|
85
|
+
* @param key - Either an extended public key (base58 string, BIP32 instance, or WasmBIP32) or an ECPair (private key Buffer, ECPair instance, or WasmECPair)
|
|
86
|
+
* @returns true if a valid signature exists, false if no signature exists
|
|
87
|
+
* @throws Error if input index is out of bounds, key is invalid, or verification fails
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* // Verify wallet input signature with xpub
|
|
92
|
+
* const hasUserSig = psbt.verifySignature(0, userXpub);
|
|
93
|
+
*
|
|
94
|
+
* // Verify signature with ECPair (private key)
|
|
95
|
+
* const ecpair = ECPair.fromPrivateKey(privateKeyBuffer);
|
|
96
|
+
* const hasReplaySig = psbt.verifySignature(1, ecpair);
|
|
97
|
+
*
|
|
98
|
+
* // Or pass private key directly
|
|
99
|
+
* const hasReplaySig2 = psbt.verifySignature(1, privateKeyBuffer);
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
verifySignature(inputIndex: number, key: BIP32Arg | ECPairArg): boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Sign a single input with a private key
|
|
105
|
+
*
|
|
106
|
+
* This method signs a specific input using the provided key. It accepts either:
|
|
107
|
+
* - An xpriv (BIP32Arg: base58 string, BIP32 instance, or WasmBIP32) for wallet inputs - derives the key and signs
|
|
108
|
+
* - A raw privkey (ECPairArg: Buffer, ECPair instance, or WasmECPair) for replay protection inputs - signs directly
|
|
109
|
+
*
|
|
110
|
+
* This method automatically detects and handles different input types:
|
|
111
|
+
* - For regular inputs: uses standard PSBT signing
|
|
112
|
+
* - For MuSig2 inputs: uses the FirstRound state stored by generateMusig2Nonces()
|
|
113
|
+
* - For replay protection inputs: signs with legacy P2SH sighash
|
|
114
|
+
*
|
|
115
|
+
* @param inputIndex - The index of the input to sign (0-based)
|
|
116
|
+
* @param key - Either an xpriv (BIP32Arg) or a raw privkey (ECPairArg)
|
|
117
|
+
* @throws Error if signing fails, or if generateMusig2Nonces() was not called first for MuSig2 inputs
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* // Parse transaction to identify input types
|
|
122
|
+
* const parsed = psbt.parseTransactionWithWalletKeys(walletKeys, replayProtection);
|
|
123
|
+
*
|
|
124
|
+
* // Sign regular wallet inputs with xpriv
|
|
125
|
+
* for (let i = 0; i < parsed.inputs.length; i++) {
|
|
126
|
+
* const input = parsed.inputs[i];
|
|
127
|
+
* if (input.scriptId !== null && input.scriptType !== "p2shP2pk") {
|
|
128
|
+
* psbt.sign(i, userXpriv);
|
|
129
|
+
* }
|
|
130
|
+
* }
|
|
131
|
+
*
|
|
132
|
+
* // Sign replay protection inputs with raw privkey
|
|
133
|
+
* const userPrivkey = bip32.fromBase58(userXpriv).privateKey!;
|
|
134
|
+
* for (let i = 0; i < parsed.inputs.length; i++) {
|
|
135
|
+
* const input = parsed.inputs[i];
|
|
136
|
+
* if (input.scriptType === "p2shP2pk") {
|
|
137
|
+
* psbt.sign(i, userPrivkey);
|
|
138
|
+
* }
|
|
139
|
+
* }
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
sign(inputIndex: number, key: BIP32Arg | ECPairArg): void;
|
|
143
|
+
/**
|
|
144
|
+
* @deprecated - use verifySignature with the replay protection key instead
|
|
145
|
+
*
|
|
146
|
+
* Verify if a replay protection input has a valid signature.
|
|
147
|
+
*
|
|
148
|
+
* This method checks if a given input is a replay protection input (like P2shP2pk) and verifies
|
|
149
|
+
* the signature. Replay protection inputs don't use standard derivation paths, so this method
|
|
150
|
+
* verifies signatures without deriving from xpub.
|
|
151
|
+
*
|
|
152
|
+
* For P2PK replay protection inputs, this:
|
|
153
|
+
* - Extracts the signature from final_script_sig
|
|
154
|
+
* - Extracts the public key from redeem_script
|
|
155
|
+
* - Computes the legacy P2SH sighash
|
|
156
|
+
* - Verifies the ECDSA signature cryptographically
|
|
157
|
+
*
|
|
158
|
+
* @param inputIndex - The index of the input to check (0-based)
|
|
159
|
+
* @param replayProtection - Scripts that identify replay protection inputs (same format as parseTransactionWithWalletKeys)
|
|
160
|
+
* @returns true if the input is a replay protection input and has a valid signature, false if no valid signature
|
|
161
|
+
* @throws Error if the input is not a replay protection input, index is out of bounds, or scripts are invalid
|
|
162
|
+
*/
|
|
163
|
+
verifyReplayProtectionSignature(inputIndex: number, replayProtection: ReplayProtectionArg): boolean;
|
|
164
|
+
/**
|
|
165
|
+
* Serialize the PSBT to bytes
|
|
166
|
+
*
|
|
167
|
+
* @returns The serialized PSBT as a byte array
|
|
168
|
+
*/
|
|
169
|
+
serialize(): Uint8Array;
|
|
170
|
+
/**
|
|
171
|
+
* Generate and store MuSig2 nonces for all MuSig2 inputs
|
|
172
|
+
*
|
|
173
|
+
* This method generates nonces using the State-Machine API and stores them in the PSBT.
|
|
174
|
+
* The nonces are stored as proprietary fields in the PSBT and will be included when serialized.
|
|
175
|
+
* After ALL participants have generated their nonces, you can sign MuSig2 inputs using
|
|
176
|
+
* sign().
|
|
177
|
+
*
|
|
178
|
+
* @param key - The extended private key (xpriv) for signing. Can be a base58 string, BIP32 instance, or WasmBIP32
|
|
179
|
+
* @param sessionId - Optional 32-byte session ID for nonce generation. **Only allowed on testnets**.
|
|
180
|
+
* On mainnets, a secure random session ID is always generated automatically.
|
|
181
|
+
* Must be unique per signing session.
|
|
182
|
+
* @throws Error if nonce generation fails, sessionId length is invalid, or custom sessionId is
|
|
183
|
+
* provided on a mainnet (security restriction)
|
|
184
|
+
*
|
|
185
|
+
* @security The sessionId MUST be cryptographically random and unique for each signing session.
|
|
186
|
+
* Never reuse a sessionId with the same key! On mainnets, sessionId is always randomly
|
|
187
|
+
* generated for security. Custom sessionId is only allowed on testnets for testing purposes.
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```typescript
|
|
191
|
+
* // Phase 1: Both parties generate nonces (with auto-generated session ID)
|
|
192
|
+
* psbt.generateMusig2Nonces(userXpriv);
|
|
193
|
+
* // Nonces are stored in the PSBT
|
|
194
|
+
* // Send PSBT to counterparty
|
|
195
|
+
*
|
|
196
|
+
* // Phase 2: After receiving counterparty PSBT with their nonces
|
|
197
|
+
* const counterpartyPsbt = BitGoPsbt.fromBytes(counterpartyPsbtBytes, network);
|
|
198
|
+
* psbt.combineMusig2Nonces(counterpartyPsbt);
|
|
199
|
+
* // Sign MuSig2 key path inputs
|
|
200
|
+
* const parsed = psbt.parseTransactionWithWalletKeys(walletKeys, replayProtection);
|
|
201
|
+
* for (let i = 0; i < parsed.inputs.length; i++) {
|
|
202
|
+
* if (parsed.inputs[i].scriptType === "p2trMusig2KeyPath") {
|
|
203
|
+
* psbt.sign(i, userXpriv);
|
|
204
|
+
* }
|
|
205
|
+
* }
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
generateMusig2Nonces(key: BIP32Arg, sessionId?: Uint8Array): void;
|
|
209
|
+
/**
|
|
210
|
+
* Combine/merge data from another PSBT into this one
|
|
211
|
+
*
|
|
212
|
+
* This method copies MuSig2 nonces and signatures (proprietary key-value pairs) from the
|
|
213
|
+
* source PSBT to this PSBT. This is useful for merging PSBTs during the nonce exchange
|
|
214
|
+
* and signature collection phases.
|
|
215
|
+
*
|
|
216
|
+
* @param sourcePsbt - The source PSBT containing data to merge
|
|
217
|
+
* @throws Error if networks don't match
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```typescript
|
|
221
|
+
* // After receiving counterparty's PSBT with their nonces
|
|
222
|
+
* const counterpartyPsbt = BitGoPsbt.fromBytes(counterpartyPsbtBytes, network);
|
|
223
|
+
* psbt.combineMusig2Nonces(counterpartyPsbt);
|
|
224
|
+
* // Now can sign with all nonces present
|
|
225
|
+
* psbt.sign(0, userXpriv);
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
combineMusig2Nonces(sourcePsbt: BitGoPsbt): void;
|
|
229
|
+
/**
|
|
230
|
+
* Finalize all inputs in the PSBT
|
|
231
|
+
*
|
|
232
|
+
* @throws Error if any input failed to finalize
|
|
233
|
+
*/
|
|
234
|
+
finalizeAllInputs(): void;
|
|
235
|
+
/**
|
|
236
|
+
* Extract the final transaction from a finalized PSBT
|
|
237
|
+
*
|
|
238
|
+
* @returns The serialized transaction bytes
|
|
239
|
+
* @throws Error if the PSBT is not fully finalized or extraction fails
|
|
240
|
+
*/
|
|
241
|
+
extractTransaction(): Uint8Array;
|
|
242
|
+
}
|