@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,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;
|