@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
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { WasmBIP32 } from "./wasm/wasm_utxo.js";
|
|
2
|
+
/**
|
|
3
|
+
* BIP32Arg represents the various forms that BIP32 keys can take
|
|
4
|
+
* before being converted to a WasmBIP32 instance
|
|
5
|
+
*/
|
|
6
|
+
export type BIP32Arg =
|
|
7
|
+
/** base58-encoded extended key string (xpub/xprv/tpub/tprv) */
|
|
8
|
+
string
|
|
9
|
+
/** BIP32 instance */
|
|
10
|
+
| BIP32
|
|
11
|
+
/** WasmBIP32 instance */
|
|
12
|
+
| WasmBIP32
|
|
13
|
+
/** BIP32Interface compatible object */
|
|
14
|
+
| BIP32Interface;
|
|
15
|
+
/**
|
|
16
|
+
* BIP32 interface for extended key operations
|
|
17
|
+
*/
|
|
18
|
+
export interface BIP32Interface {
|
|
19
|
+
chainCode: Uint8Array;
|
|
20
|
+
depth: number;
|
|
21
|
+
index: number;
|
|
22
|
+
parentFingerprint: number;
|
|
23
|
+
privateKey?: Uint8Array;
|
|
24
|
+
publicKey: Uint8Array;
|
|
25
|
+
identifier: Uint8Array;
|
|
26
|
+
fingerprint: Uint8Array;
|
|
27
|
+
isNeutered(): boolean;
|
|
28
|
+
neutered(): BIP32Interface;
|
|
29
|
+
toBase58(): string;
|
|
30
|
+
toWIF(): string;
|
|
31
|
+
derive(index: number): BIP32Interface;
|
|
32
|
+
deriveHardened(index: number): BIP32Interface;
|
|
33
|
+
derivePath(path: string): BIP32Interface;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* BIP32 wrapper class for extended key operations
|
|
37
|
+
*/
|
|
38
|
+
export declare class BIP32 implements BIP32Interface {
|
|
39
|
+
private _wasm;
|
|
40
|
+
private constructor();
|
|
41
|
+
/**
|
|
42
|
+
* Create a BIP32 instance from a WasmBIP32 instance (internal use)
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
static fromWasm(wasm: WasmBIP32): BIP32;
|
|
46
|
+
/**
|
|
47
|
+
* Convert BIP32Arg to BIP32 instance
|
|
48
|
+
* @param key - The BIP32 key in various formats
|
|
49
|
+
* @returns BIP32 instance
|
|
50
|
+
*/
|
|
51
|
+
static from(key: BIP32Arg): BIP32;
|
|
52
|
+
/**
|
|
53
|
+
* Create a BIP32 key from a base58 string (xpub/xprv/tpub/tprv)
|
|
54
|
+
* @param base58Str - The base58-encoded extended key string
|
|
55
|
+
* @returns A BIP32 instance
|
|
56
|
+
*/
|
|
57
|
+
static fromBase58(base58Str: string): BIP32;
|
|
58
|
+
/**
|
|
59
|
+
* Create a BIP32 master key from a seed
|
|
60
|
+
* @param seed - The seed bytes
|
|
61
|
+
* @param network - Optional network string
|
|
62
|
+
* @returns A BIP32 instance
|
|
63
|
+
*/
|
|
64
|
+
static fromSeed(seed: Uint8Array, network?: string | null): BIP32;
|
|
65
|
+
/**
|
|
66
|
+
* Get the chain code as a Uint8Array
|
|
67
|
+
*/
|
|
68
|
+
get chainCode(): Uint8Array;
|
|
69
|
+
/**
|
|
70
|
+
* Get the depth
|
|
71
|
+
*/
|
|
72
|
+
get depth(): number;
|
|
73
|
+
/**
|
|
74
|
+
* Get the child index
|
|
75
|
+
*/
|
|
76
|
+
get index(): number;
|
|
77
|
+
/**
|
|
78
|
+
* Get the parent fingerprint
|
|
79
|
+
*/
|
|
80
|
+
get parentFingerprint(): number;
|
|
81
|
+
/**
|
|
82
|
+
* Get the private key as a Uint8Array (if available)
|
|
83
|
+
*/
|
|
84
|
+
get privateKey(): Uint8Array | undefined;
|
|
85
|
+
/**
|
|
86
|
+
* Get the public key as a Uint8Array
|
|
87
|
+
*/
|
|
88
|
+
get publicKey(): Uint8Array;
|
|
89
|
+
/**
|
|
90
|
+
* Get the identifier as a Uint8Array
|
|
91
|
+
*/
|
|
92
|
+
get identifier(): Uint8Array;
|
|
93
|
+
/**
|
|
94
|
+
* Get the fingerprint as a Uint8Array
|
|
95
|
+
*/
|
|
96
|
+
get fingerprint(): Uint8Array;
|
|
97
|
+
/**
|
|
98
|
+
* Check if this is a neutered (public) key
|
|
99
|
+
* @returns True if the key is public-only (neutered)
|
|
100
|
+
*/
|
|
101
|
+
isNeutered(): boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Get the neutered (public) version of this key
|
|
104
|
+
* @returns A new BIP32 instance containing only the public key
|
|
105
|
+
*/
|
|
106
|
+
neutered(): BIP32;
|
|
107
|
+
/**
|
|
108
|
+
* Serialize to base58 string
|
|
109
|
+
* @returns The base58-encoded extended key string
|
|
110
|
+
*/
|
|
111
|
+
toBase58(): string;
|
|
112
|
+
/**
|
|
113
|
+
* Get the WIF encoding of the private key
|
|
114
|
+
* @returns The WIF-encoded private key
|
|
115
|
+
*/
|
|
116
|
+
toWIF(): string;
|
|
117
|
+
/**
|
|
118
|
+
* Derive a normal (non-hardened) child key
|
|
119
|
+
* @param index - The child index
|
|
120
|
+
* @returns A new BIP32 instance for the derived key
|
|
121
|
+
*/
|
|
122
|
+
derive(index: number): BIP32;
|
|
123
|
+
/**
|
|
124
|
+
* Derive a hardened child key (only works for private keys)
|
|
125
|
+
* @param index - The child index
|
|
126
|
+
* @returns A new BIP32 instance for the derived key
|
|
127
|
+
*/
|
|
128
|
+
deriveHardened(index: number): BIP32;
|
|
129
|
+
/**
|
|
130
|
+
* Derive a key using a derivation path (e.g., "0/1/2" or "m/0/1/2")
|
|
131
|
+
* @param path - The derivation path string
|
|
132
|
+
* @returns A new BIP32 instance for the derived key
|
|
133
|
+
*/
|
|
134
|
+
derivePath(path: string): BIP32;
|
|
135
|
+
/**
|
|
136
|
+
* Get the underlying WASM instance (internal use only)
|
|
137
|
+
* @internal
|
|
138
|
+
*/
|
|
139
|
+
get wasm(): WasmBIP32;
|
|
140
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BIP32 = void 0;
|
|
4
|
+
const wasm_utxo_js_1 = require("./wasm/wasm_utxo.js");
|
|
5
|
+
/**
|
|
6
|
+
* BIP32 wrapper class for extended key operations
|
|
7
|
+
*/
|
|
8
|
+
class BIP32 {
|
|
9
|
+
_wasm;
|
|
10
|
+
constructor(_wasm) {
|
|
11
|
+
this._wasm = _wasm;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Create a BIP32 instance from a WasmBIP32 instance (internal use)
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
static fromWasm(wasm) {
|
|
18
|
+
return new BIP32(wasm);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Convert BIP32Arg to BIP32 instance
|
|
22
|
+
* @param key - The BIP32 key in various formats
|
|
23
|
+
* @returns BIP32 instance
|
|
24
|
+
*/
|
|
25
|
+
static from(key) {
|
|
26
|
+
// Short-circuit if already a BIP32 instance
|
|
27
|
+
if (key instanceof BIP32) {
|
|
28
|
+
return key;
|
|
29
|
+
}
|
|
30
|
+
// If it's a WasmBIP32 instance, wrap it
|
|
31
|
+
if (key instanceof wasm_utxo_js_1.WasmBIP32) {
|
|
32
|
+
return new BIP32(key);
|
|
33
|
+
}
|
|
34
|
+
// If it's a string, parse from base58
|
|
35
|
+
if (typeof key === "string") {
|
|
36
|
+
const wasm = wasm_utxo_js_1.WasmBIP32.from_base58(key);
|
|
37
|
+
return new BIP32(wasm);
|
|
38
|
+
}
|
|
39
|
+
// If it's an object (BIP32Interface), use from_bip32_interface
|
|
40
|
+
if (typeof key === "object" && key !== null) {
|
|
41
|
+
const wasm = wasm_utxo_js_1.WasmBIP32.from_bip32_interface(key);
|
|
42
|
+
return new BIP32(wasm);
|
|
43
|
+
}
|
|
44
|
+
throw new Error("Invalid BIP32Arg type");
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Create a BIP32 key from a base58 string (xpub/xprv/tpub/tprv)
|
|
48
|
+
* @param base58Str - The base58-encoded extended key string
|
|
49
|
+
* @returns A BIP32 instance
|
|
50
|
+
*/
|
|
51
|
+
static fromBase58(base58Str) {
|
|
52
|
+
const wasm = wasm_utxo_js_1.WasmBIP32.from_base58(base58Str);
|
|
53
|
+
return new BIP32(wasm);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Create a BIP32 master key from a seed
|
|
57
|
+
* @param seed - The seed bytes
|
|
58
|
+
* @param network - Optional network string
|
|
59
|
+
* @returns A BIP32 instance
|
|
60
|
+
*/
|
|
61
|
+
static fromSeed(seed, network) {
|
|
62
|
+
const wasm = wasm_utxo_js_1.WasmBIP32.from_seed(seed, network);
|
|
63
|
+
return new BIP32(wasm);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get the chain code as a Uint8Array
|
|
67
|
+
*/
|
|
68
|
+
get chainCode() {
|
|
69
|
+
return this._wasm.chain_code;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Get the depth
|
|
73
|
+
*/
|
|
74
|
+
get depth() {
|
|
75
|
+
return this._wasm.depth;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Get the child index
|
|
79
|
+
*/
|
|
80
|
+
get index() {
|
|
81
|
+
return this._wasm.index;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Get the parent fingerprint
|
|
85
|
+
*/
|
|
86
|
+
get parentFingerprint() {
|
|
87
|
+
return this._wasm.parent_fingerprint;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Get the private key as a Uint8Array (if available)
|
|
91
|
+
*/
|
|
92
|
+
get privateKey() {
|
|
93
|
+
return this._wasm.private_key;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Get the public key as a Uint8Array
|
|
97
|
+
*/
|
|
98
|
+
get publicKey() {
|
|
99
|
+
return this._wasm.public_key;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Get the identifier as a Uint8Array
|
|
103
|
+
*/
|
|
104
|
+
get identifier() {
|
|
105
|
+
return this._wasm.identifier;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Get the fingerprint as a Uint8Array
|
|
109
|
+
*/
|
|
110
|
+
get fingerprint() {
|
|
111
|
+
return this._wasm.fingerprint;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Check if this is a neutered (public) key
|
|
115
|
+
* @returns True if the key is public-only (neutered)
|
|
116
|
+
*/
|
|
117
|
+
isNeutered() {
|
|
118
|
+
return this._wasm.is_neutered();
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Get the neutered (public) version of this key
|
|
122
|
+
* @returns A new BIP32 instance containing only the public key
|
|
123
|
+
*/
|
|
124
|
+
neutered() {
|
|
125
|
+
const wasm = this._wasm.neutered();
|
|
126
|
+
return new BIP32(wasm);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Serialize to base58 string
|
|
130
|
+
* @returns The base58-encoded extended key string
|
|
131
|
+
*/
|
|
132
|
+
toBase58() {
|
|
133
|
+
return this._wasm.to_base58();
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Get the WIF encoding of the private key
|
|
137
|
+
* @returns The WIF-encoded private key
|
|
138
|
+
*/
|
|
139
|
+
toWIF() {
|
|
140
|
+
return this._wasm.to_wif();
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Derive a normal (non-hardened) child key
|
|
144
|
+
* @param index - The child index
|
|
145
|
+
* @returns A new BIP32 instance for the derived key
|
|
146
|
+
*/
|
|
147
|
+
derive(index) {
|
|
148
|
+
const wasm = this._wasm.derive(index);
|
|
149
|
+
return new BIP32(wasm);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Derive a hardened child key (only works for private keys)
|
|
153
|
+
* @param index - The child index
|
|
154
|
+
* @returns A new BIP32 instance for the derived key
|
|
155
|
+
*/
|
|
156
|
+
deriveHardened(index) {
|
|
157
|
+
const wasm = this._wasm.derive_hardened(index);
|
|
158
|
+
return new BIP32(wasm);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Derive a key using a derivation path (e.g., "0/1/2" or "m/0/1/2")
|
|
162
|
+
* @param path - The derivation path string
|
|
163
|
+
* @returns A new BIP32 instance for the derived key
|
|
164
|
+
*/
|
|
165
|
+
derivePath(path) {
|
|
166
|
+
const wasm = this._wasm.derive_path(path);
|
|
167
|
+
return new BIP32(wasm);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Get the underlying WASM instance (internal use only)
|
|
171
|
+
* @internal
|
|
172
|
+
*/
|
|
173
|
+
get wasm() {
|
|
174
|
+
return this._wasm;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
exports.BIP32 = BIP32;
|
|
@@ -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,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ECPair = void 0;
|
|
4
|
+
const wasm_utxo_js_1 = require("./wasm/wasm_utxo.js");
|
|
5
|
+
/**
|
|
6
|
+
* ECPair wrapper class for elliptic curve key pair operations
|
|
7
|
+
*/
|
|
8
|
+
class ECPair {
|
|
9
|
+
_wasm;
|
|
10
|
+
constructor(_wasm) {
|
|
11
|
+
this._wasm = _wasm;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Create an ECPair instance from a WasmECPair instance (internal use)
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
static fromWasm(wasm) {
|
|
18
|
+
return new ECPair(wasm);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Convert ECPairArg to ECPair instance
|
|
22
|
+
* @param key - The ECPair key in various formats
|
|
23
|
+
* @returns ECPair instance
|
|
24
|
+
*/
|
|
25
|
+
static from(key) {
|
|
26
|
+
// Short-circuit if already an ECPair instance
|
|
27
|
+
if (key instanceof ECPair) {
|
|
28
|
+
return key;
|
|
29
|
+
}
|
|
30
|
+
// If it's a WasmECPair instance, wrap it
|
|
31
|
+
if (key instanceof wasm_utxo_js_1.WasmECPair) {
|
|
32
|
+
return new ECPair(key);
|
|
33
|
+
}
|
|
34
|
+
// Parse from Buffer/Uint8Array
|
|
35
|
+
// Check length to determine if it's a private key (32 bytes) or public key (33 bytes)
|
|
36
|
+
if (key.length === 32) {
|
|
37
|
+
const wasm = wasm_utxo_js_1.WasmECPair.from_private_key(key);
|
|
38
|
+
return new ECPair(wasm);
|
|
39
|
+
}
|
|
40
|
+
else if (key.length === 33) {
|
|
41
|
+
const wasm = wasm_utxo_js_1.WasmECPair.from_public_key(key);
|
|
42
|
+
return new ECPair(wasm);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
throw new Error(`Invalid key length: ${key.length}. Expected 32 bytes (private key) or 33 bytes (compressed public key)`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Create an ECPair from a private key (always uses compressed keys)
|
|
50
|
+
* @param buffer - The 32-byte private key
|
|
51
|
+
* @returns An ECPair instance
|
|
52
|
+
*/
|
|
53
|
+
static fromPrivateKey(buffer) {
|
|
54
|
+
const wasm = wasm_utxo_js_1.WasmECPair.from_private_key(buffer);
|
|
55
|
+
return new ECPair(wasm);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Create an ECPair from a compressed public key
|
|
59
|
+
* @param buffer - The compressed public key bytes (33 bytes)
|
|
60
|
+
* @returns An ECPair instance
|
|
61
|
+
*/
|
|
62
|
+
static fromPublicKey(buffer) {
|
|
63
|
+
const wasm = wasm_utxo_js_1.WasmECPair.from_public_key(buffer);
|
|
64
|
+
return new ECPair(wasm);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Create an ECPair from a WIF string (auto-detects network from WIF)
|
|
68
|
+
* @param wifString - The WIF-encoded private key string
|
|
69
|
+
* @returns An ECPair instance
|
|
70
|
+
*/
|
|
71
|
+
static fromWIF(wifString) {
|
|
72
|
+
const wasm = wasm_utxo_js_1.WasmECPair.from_wif(wifString);
|
|
73
|
+
return new ECPair(wasm);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Create an ECPair from a mainnet WIF string
|
|
77
|
+
* @param wifString - The WIF-encoded private key string
|
|
78
|
+
* @returns An ECPair instance
|
|
79
|
+
*/
|
|
80
|
+
static fromWIFMainnet(wifString) {
|
|
81
|
+
const wasm = wasm_utxo_js_1.WasmECPair.from_wif_mainnet(wifString);
|
|
82
|
+
return new ECPair(wasm);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Create an ECPair from a testnet WIF string
|
|
86
|
+
* @param wifString - The WIF-encoded private key string
|
|
87
|
+
* @returns An ECPair instance
|
|
88
|
+
*/
|
|
89
|
+
static fromWIFTestnet(wifString) {
|
|
90
|
+
const wasm = wasm_utxo_js_1.WasmECPair.from_wif_testnet(wifString);
|
|
91
|
+
return new ECPair(wasm);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Get the private key as a Uint8Array (if available)
|
|
95
|
+
*/
|
|
96
|
+
get privateKey() {
|
|
97
|
+
return this._wasm.private_key;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Get the public key as a Uint8Array
|
|
101
|
+
*/
|
|
102
|
+
get publicKey() {
|
|
103
|
+
return this._wasm.public_key;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Convert to WIF string (mainnet)
|
|
107
|
+
* @returns The WIF-encoded private key
|
|
108
|
+
*/
|
|
109
|
+
toWIF() {
|
|
110
|
+
return this._wasm.to_wif();
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Convert to mainnet WIF string
|
|
114
|
+
* @returns The WIF-encoded private key
|
|
115
|
+
*/
|
|
116
|
+
toWIFMainnet() {
|
|
117
|
+
return this._wasm.to_wif_mainnet();
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Convert to testnet WIF string
|
|
121
|
+
* @returns The WIF-encoded private key
|
|
122
|
+
*/
|
|
123
|
+
toWIFTestnet() {
|
|
124
|
+
return this._wasm.to_wif_testnet();
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Get the underlying WASM instance (internal use only)
|
|
128
|
+
* @internal
|
|
129
|
+
*/
|
|
130
|
+
get wasm() {
|
|
131
|
+
return this._wasm;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
exports.ECPair = ECPair;
|
|
@@ -1,35 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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";
|
|
5
7
|
export type NetworkName = UtxolibName | CoinName;
|
|
6
|
-
export type WalletKeys =
|
|
7
|
-
/** Just an xpub triple, will assume default derivation prefixes */
|
|
8
|
-
Triple<string>
|
|
9
|
-
/** Compatible with utxolib RootWalletKeys */
|
|
10
|
-
| UtxolibRootWalletKeys;
|
|
11
|
-
/**
|
|
12
|
-
* Create the output script for a given wallet keys and chain and index
|
|
13
|
-
*/
|
|
14
|
-
export declare function outputScript(keys: WalletKeys, chain: number, index: number, network: UtxolibNetwork): Uint8Array;
|
|
15
|
-
/**
|
|
16
|
-
* Create the address for a given wallet keys and chain and index and network.
|
|
17
|
-
* Wrapper for outputScript that also encodes the script to an address.
|
|
18
|
-
* @param keys - The wallet keys to use.
|
|
19
|
-
* @param chain - The chain to use.
|
|
20
|
-
* @param index - The index to use.
|
|
21
|
-
* @param network - The network to use.
|
|
22
|
-
* @param addressFormat - The address format to use.
|
|
23
|
-
* Only relevant for Bitcoin Cash and eCash networks, where:
|
|
24
|
-
* - "default" means base58check,
|
|
25
|
-
* - "cashaddr" means cashaddr.
|
|
26
|
-
*/
|
|
27
|
-
export declare function address(keys: WalletKeys, chain: number, index: number, network: UtxolibNetwork, addressFormat?: AddressFormat): string;
|
|
28
|
-
type ReplayProtection = {
|
|
29
|
-
outputScripts: Uint8Array[];
|
|
30
|
-
} | {
|
|
31
|
-
addresses: string[];
|
|
32
|
-
};
|
|
33
8
|
export type ScriptId = {
|
|
34
9
|
chain: number;
|
|
35
10
|
index: number;
|
|
@@ -76,7 +51,7 @@ export declare class BitGoPsbt {
|
|
|
76
51
|
* @param replayProtection - Scripts that are allowed as inputs without wallet validation
|
|
77
52
|
* @returns Parsed transaction information
|
|
78
53
|
*/
|
|
79
|
-
parseTransactionWithWalletKeys(walletKeys:
|
|
54
|
+
parseTransactionWithWalletKeys(walletKeys: WalletKeysArg, replayProtection: ReplayProtectionArg): ParsedTransaction;
|
|
80
55
|
/**
|
|
81
56
|
* Parse outputs with wallet keys to identify which outputs belong to a wallet
|
|
82
57
|
* with the given wallet keys.
|
|
@@ -88,23 +63,46 @@ export declare class BitGoPsbt {
|
|
|
88
63
|
* @returns Array of parsed outputs
|
|
89
64
|
* @note This method does NOT validate wallet inputs. It only parses outputs.
|
|
90
65
|
*/
|
|
91
|
-
parseOutputsWithWalletKeys(walletKeys:
|
|
66
|
+
parseOutputsWithWalletKeys(walletKeys: WalletKeysArg): ParsedOutput[];
|
|
92
67
|
/**
|
|
93
|
-
* Verify if a valid signature exists for a given
|
|
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
|
|
94
73
|
*
|
|
95
|
-
*
|
|
96
|
-
* PSBT input, then verifies the signature. It supports:
|
|
74
|
+
* When using xpub, it supports:
|
|
97
75
|
* - ECDSA signatures (for legacy/SegWit inputs)
|
|
98
76
|
* - Schnorr signatures (for Taproot script path inputs)
|
|
99
77
|
* - MuSig2 partial signatures (for Taproot keypath MuSig2 inputs)
|
|
100
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
|
+
*
|
|
101
84
|
* @param inputIndex - The index of the input to check (0-based)
|
|
102
|
-
* @param
|
|
85
|
+
* @param key - Either an extended public key (base58 string, BIP32 instance, or WasmBIP32) or an ECPair (private key Buffer, ECPair instance, or WasmECPair)
|
|
103
86
|
* @returns true if a valid signature exists, false if no signature exists
|
|
104
|
-
* @throws Error if input index is out of bounds,
|
|
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
|
+
* ```
|
|
105
101
|
*/
|
|
106
|
-
verifySignature(inputIndex: number,
|
|
102
|
+
verifySignature(inputIndex: number, key: BIP32Arg | ECPairArg): boolean;
|
|
107
103
|
/**
|
|
104
|
+
* @deprecated - use verifySignature with the replay protection key instead
|
|
105
|
+
*
|
|
108
106
|
* Verify if a replay protection input has a valid signature.
|
|
109
107
|
*
|
|
110
108
|
* This method checks if a given input is a replay protection input (like P2shP2pk) and verifies
|
|
@@ -122,7 +120,7 @@ export declare class BitGoPsbt {
|
|
|
122
120
|
* @returns true if the input is a replay protection input and has a valid signature, false if no valid signature
|
|
123
121
|
* @throws Error if the input is not a replay protection input, index is out of bounds, or scripts are invalid
|
|
124
122
|
*/
|
|
125
|
-
verifyReplayProtectionSignature(inputIndex: number, replayProtection:
|
|
123
|
+
verifyReplayProtectionSignature(inputIndex: number, replayProtection: ReplayProtectionArg): boolean;
|
|
126
124
|
/**
|
|
127
125
|
* Serialize the PSBT to bytes
|
|
128
126
|
*
|
|
@@ -143,4 +141,3 @@ export declare class BitGoPsbt {
|
|
|
143
141
|
*/
|
|
144
142
|
extractTransaction(): Uint8Array;
|
|
145
143
|
}
|
|
146
|
-
export {};
|