hd-wallet-wasm 0.1.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/src/index.d.ts ADDED
@@ -0,0 +1,609 @@
1
+ /**
2
+ * HD Wallet WASM - TypeScript Definitions
3
+ *
4
+ * Comprehensive HD wallet implementation with:
5
+ * - BIP-32/39/44/49/84 support
6
+ * - Multi-curve cryptography (secp256k1, Ed25519, P-256, P-384, X25519)
7
+ * - Multi-chain support (Bitcoin, Ethereum, Solana, Cosmos, Polkadot)
8
+ * - Hardware wallet abstraction (requires bridge)
9
+ * - Transaction building and signing
10
+ */
11
+
12
+ // =============================================================================
13
+ // Module Types
14
+ // =============================================================================
15
+
16
+ export interface HDWalletModule {
17
+ // Module info
18
+ getVersion(): string;
19
+ hasCryptopp(): boolean;
20
+ isFipsMode(): boolean;
21
+ getSupportedCoins(): string[];
22
+ getSupportedCurves(): string[];
23
+
24
+ // WASI bridge
25
+ wasiHasFeature(feature: WasiFeature): boolean;
26
+ wasiGetWarning(feature: WasiFeature): WasiWarning;
27
+ wasiGetWarningMessage(feature: WasiFeature): string;
28
+
29
+ // Entropy
30
+ injectEntropy(entropy: Uint8Array): void;
31
+ getEntropyStatus(): EntropyStatus;
32
+
33
+ // BIP-39 Mnemonic
34
+ mnemonic: MnemonicAPI;
35
+
36
+ // BIP-32 HD Keys
37
+ hdkey: HDKeyAPI;
38
+
39
+ // Multi-curve cryptography
40
+ curves: CurvesAPI;
41
+
42
+ // Bitcoin
43
+ bitcoin: BitcoinAPI;
44
+
45
+ // Ethereum
46
+ ethereum: EthereumAPI;
47
+
48
+ // Cosmos
49
+ cosmos: CosmosAPI;
50
+
51
+ // Solana
52
+ solana: SolanaAPI;
53
+
54
+ // Polkadot
55
+ polkadot: PolkadotAPI;
56
+
57
+ // Hardware wallets (requires bridge)
58
+ hardware: HardwareWalletAPI;
59
+
60
+ // Keyring
61
+ keyring: KeyringAPI;
62
+
63
+ // Utilities
64
+ utils: UtilsAPI;
65
+ }
66
+
67
+ // =============================================================================
68
+ // Enums
69
+ // =============================================================================
70
+
71
+ export enum Curve {
72
+ SECP256K1 = 0,
73
+ ED25519 = 1,
74
+ P256 = 2,
75
+ P384 = 3,
76
+ X25519 = 4
77
+ }
78
+
79
+ export enum CoinType {
80
+ BITCOIN = 0,
81
+ BITCOIN_TESTNET = 1,
82
+ LITECOIN = 2,
83
+ DOGECOIN = 3,
84
+ ETHEREUM = 60,
85
+ ETHEREUM_CLASSIC = 61,
86
+ COSMOS = 118,
87
+ STELLAR = 148,
88
+ BITCOIN_CASH = 145,
89
+ POLKADOT = 354,
90
+ KUSAMA = 434,
91
+ SOLANA = 501,
92
+ BINANCE = 714,
93
+ CARDANO = 1815
94
+ }
95
+
96
+ export enum Language {
97
+ ENGLISH = 0,
98
+ JAPANESE = 1,
99
+ KOREAN = 2,
100
+ SPANISH = 3,
101
+ CHINESE_SIMPLIFIED = 4,
102
+ CHINESE_TRADITIONAL = 5,
103
+ FRENCH = 6,
104
+ ITALIAN = 7,
105
+ CZECH = 8,
106
+ PORTUGUESE = 9
107
+ }
108
+
109
+ export enum WasiFeature {
110
+ RANDOM = 0,
111
+ FILESYSTEM = 1,
112
+ NETWORK = 2,
113
+ USB_HID = 3,
114
+ CLOCK = 4,
115
+ ENVIRONMENT = 5
116
+ }
117
+
118
+ export enum WasiWarning {
119
+ NONE = 0,
120
+ NEEDS_ENTROPY = 1,
121
+ NEEDS_BRIDGE = 2,
122
+ NOT_AVAILABLE_WASI = 3,
123
+ DISABLED_FIPS = 4,
124
+ NEEDS_CAPABILITY = 5
125
+ }
126
+
127
+ export enum EntropyStatus {
128
+ NOT_INITIALIZED = 0,
129
+ INITIALIZED = 1,
130
+ SUFFICIENT = 2
131
+ }
132
+
133
+ export enum BitcoinAddressType {
134
+ P2PKH = 0,
135
+ P2SH = 1,
136
+ P2WPKH = 2,
137
+ P2WSH = 3,
138
+ P2TR = 4
139
+ }
140
+
141
+ export enum Network {
142
+ MAINNET = 0,
143
+ TESTNET = 1
144
+ }
145
+
146
+ // =============================================================================
147
+ // BIP-39 Mnemonic API
148
+ // =============================================================================
149
+
150
+ export interface MnemonicAPI {
151
+ /**
152
+ * Generate a random mnemonic phrase
153
+ * @param wordCount Number of words (12, 15, 18, 21, or 24)
154
+ * @param language Wordlist language
155
+ * @throws If entropy not available (WASI) or invalid word count
156
+ */
157
+ generate(wordCount?: number, language?: Language): string;
158
+
159
+ /**
160
+ * Validate a mnemonic phrase
161
+ */
162
+ validate(mnemonic: string, language?: Language): boolean;
163
+
164
+ /**
165
+ * Convert mnemonic to 64-byte seed
166
+ */
167
+ toSeed(mnemonic: string, passphrase?: string): Uint8Array;
168
+
169
+ /**
170
+ * Convert mnemonic to entropy bytes
171
+ */
172
+ toEntropy(mnemonic: string, language?: Language): Uint8Array;
173
+
174
+ /**
175
+ * Convert entropy to mnemonic
176
+ */
177
+ fromEntropy(entropy: Uint8Array, language?: Language): string;
178
+
179
+ /**
180
+ * Get wordlist for language
181
+ */
182
+ getWordlist(language?: Language): string[];
183
+
184
+ /**
185
+ * Get word suggestions for autocomplete
186
+ */
187
+ suggestWords(prefix: string, language?: Language, maxSuggestions?: number): string[];
188
+
189
+ /**
190
+ * Check if word is in wordlist
191
+ */
192
+ checkWord(word: string, language?: Language): boolean;
193
+ }
194
+
195
+ // =============================================================================
196
+ // BIP-32 HD Key API
197
+ // =============================================================================
198
+
199
+ export interface HDKey {
200
+ /** Derivation path */
201
+ readonly path: string;
202
+
203
+ /** Key depth in derivation tree */
204
+ readonly depth: number;
205
+
206
+ /** Parent fingerprint */
207
+ readonly parentFingerprint: number;
208
+
209
+ /** Child index */
210
+ readonly childIndex: number;
211
+
212
+ /** Is this a neutered (public-only) key? */
213
+ readonly isNeutered: boolean;
214
+
215
+ /** Elliptic curve */
216
+ readonly curve: Curve;
217
+
218
+ /** Get private key (throws if neutered) */
219
+ privateKey(): Uint8Array;
220
+
221
+ /** Get public key (compressed) */
222
+ publicKey(): Uint8Array;
223
+
224
+ /** Get public key (uncompressed) */
225
+ publicKeyUncompressed(): Uint8Array;
226
+
227
+ /** Get chain code */
228
+ chainCode(): Uint8Array;
229
+
230
+ /** Get key fingerprint */
231
+ fingerprint(): number;
232
+
233
+ /** Derive child key */
234
+ deriveChild(index: number): HDKey;
235
+
236
+ /** Derive child key (hardened) */
237
+ deriveHardened(index: number): HDKey;
238
+
239
+ /** Derive key at path */
240
+ derivePath(path: string): HDKey;
241
+
242
+ /** Get neutered (public-only) version */
243
+ neutered(): HDKey;
244
+
245
+ /** Serialize as xprv */
246
+ toXprv(): string;
247
+
248
+ /** Serialize as xpub */
249
+ toXpub(): string;
250
+
251
+ /** Securely wipe key from memory */
252
+ wipe(): void;
253
+
254
+ /** Clone key */
255
+ clone(): HDKey;
256
+ }
257
+
258
+ export interface HDKeyAPI {
259
+ /**
260
+ * Create master key from seed
261
+ */
262
+ fromSeed(seed: Uint8Array, curve?: Curve): HDKey;
263
+
264
+ /**
265
+ * Parse extended private key
266
+ */
267
+ fromXprv(xprv: string): HDKey;
268
+
269
+ /**
270
+ * Parse extended public key
271
+ */
272
+ fromXpub(xpub: string): HDKey;
273
+
274
+ /**
275
+ * Build BIP-44 path
276
+ */
277
+ buildPath(purpose: number, coinType: number, account?: number, change?: number, index?: number): string;
278
+
279
+ /**
280
+ * Parse BIP-44 path
281
+ */
282
+ parsePath(path: string): {
283
+ purpose: number;
284
+ coinType: number;
285
+ account: number;
286
+ change: number;
287
+ index: number;
288
+ };
289
+ }
290
+
291
+ // =============================================================================
292
+ // Multi-Curve API
293
+ // =============================================================================
294
+
295
+ export interface CurvesAPI {
296
+ /**
297
+ * Derive public key from private key
298
+ */
299
+ publicKeyFromPrivate(privateKey: Uint8Array, curve: Curve): Uint8Array;
300
+
301
+ /**
302
+ * Compress public key
303
+ */
304
+ compressPublicKey(publicKey: Uint8Array, curve: Curve): Uint8Array;
305
+
306
+ /**
307
+ * Decompress public key
308
+ */
309
+ decompressPublicKey(publicKey: Uint8Array, curve: Curve): Uint8Array;
310
+
311
+ // ECDSA (secp256k1)
312
+ secp256k1: {
313
+ sign(message: Uint8Array, privateKey: Uint8Array): Uint8Array;
314
+ signRecoverable(message: Uint8Array, privateKey: Uint8Array): { signature: Uint8Array; recoveryId: number };
315
+ verify(message: Uint8Array, signature: Uint8Array, publicKey: Uint8Array): boolean;
316
+ recover(message: Uint8Array, signature: Uint8Array, recoveryId: number): Uint8Array;
317
+ ecdh(privateKey: Uint8Array, publicKey: Uint8Array): Uint8Array;
318
+ };
319
+
320
+ // EdDSA (Ed25519)
321
+ ed25519: {
322
+ sign(message: Uint8Array, privateKey: Uint8Array): Uint8Array;
323
+ verify(message: Uint8Array, signature: Uint8Array, publicKey: Uint8Array): boolean;
324
+ };
325
+
326
+ // ECDSA (P-256)
327
+ p256: {
328
+ sign(message: Uint8Array, privateKey: Uint8Array): Uint8Array;
329
+ verify(message: Uint8Array, signature: Uint8Array, publicKey: Uint8Array): boolean;
330
+ ecdh(privateKey: Uint8Array, publicKey: Uint8Array): Uint8Array;
331
+ };
332
+
333
+ // ECDSA (P-384)
334
+ p384: {
335
+ sign(message: Uint8Array, privateKey: Uint8Array): Uint8Array;
336
+ verify(message: Uint8Array, signature: Uint8Array, publicKey: Uint8Array): boolean;
337
+ ecdh(privateKey: Uint8Array, publicKey: Uint8Array): Uint8Array;
338
+ };
339
+
340
+ // X25519 (key exchange only)
341
+ x25519: {
342
+ ecdh(privateKey: Uint8Array, publicKey: Uint8Array): Uint8Array;
343
+ };
344
+ }
345
+
346
+ // =============================================================================
347
+ // Bitcoin API
348
+ // =============================================================================
349
+
350
+ export interface BitcoinAPI {
351
+ /**
352
+ * Get address from public key
353
+ */
354
+ getAddress(publicKey: Uint8Array, type: BitcoinAddressType, network?: Network): string;
355
+
356
+ /**
357
+ * Validate Bitcoin address
358
+ */
359
+ validateAddress(address: string): boolean;
360
+
361
+ /**
362
+ * Decode Bitcoin address
363
+ */
364
+ decodeAddress(address: string): { type: BitcoinAddressType; hash: Uint8Array; network: Network };
365
+
366
+ /**
367
+ * Sign message (Bitcoin Signed Message format)
368
+ */
369
+ signMessage(message: string, privateKey: Uint8Array): string;
370
+
371
+ /**
372
+ * Verify signed message
373
+ */
374
+ verifyMessage(message: string, signature: string, address: string): boolean;
375
+
376
+ /**
377
+ * Transaction builder
378
+ */
379
+ tx: BitcoinTxBuilder;
380
+ }
381
+
382
+ export interface BitcoinTxBuilder {
383
+ create(): BitcoinTx;
384
+ }
385
+
386
+ export interface BitcoinTx {
387
+ addInput(txid: string, vout: number, sequence?: number): this;
388
+ addOutput(address: string, amount: bigint): this;
389
+ sign(inputIndex: number, privateKey: Uint8Array, redeemScript?: Uint8Array): this;
390
+ serialize(): Uint8Array;
391
+ getTxid(): string;
392
+ getSize(): number;
393
+ getVsize(): number;
394
+ }
395
+
396
+ // =============================================================================
397
+ // Ethereum API
398
+ // =============================================================================
399
+
400
+ export interface EthereumAPI {
401
+ /**
402
+ * Get address from public key
403
+ */
404
+ getAddress(publicKey: Uint8Array): string;
405
+
406
+ /**
407
+ * Get checksummed address (EIP-55)
408
+ */
409
+ getChecksumAddress(address: string): string;
410
+
411
+ /**
412
+ * Validate Ethereum address
413
+ */
414
+ validateAddress(address: string): boolean;
415
+
416
+ /**
417
+ * Sign message (EIP-191)
418
+ */
419
+ signMessage(message: string, privateKey: Uint8Array): string;
420
+
421
+ /**
422
+ * Sign typed data (EIP-712)
423
+ */
424
+ signTypedData(typedData: object, privateKey: Uint8Array): string;
425
+
426
+ /**
427
+ * Verify message signature
428
+ */
429
+ verifyMessage(message: string, signature: string): string;
430
+
431
+ /**
432
+ * Transaction builder
433
+ */
434
+ tx: EthereumTxBuilder;
435
+ }
436
+
437
+ export interface EthereumTxBuilder {
438
+ create(params: {
439
+ nonce: number;
440
+ gasPrice?: bigint;
441
+ gasLimit: bigint;
442
+ to?: string;
443
+ value?: bigint;
444
+ data?: Uint8Array;
445
+ chainId: number;
446
+ }): EthereumTx;
447
+
448
+ createEIP1559(params: {
449
+ nonce: number;
450
+ maxFeePerGas: bigint;
451
+ maxPriorityFeePerGas: bigint;
452
+ gasLimit: bigint;
453
+ to?: string;
454
+ value?: bigint;
455
+ data?: Uint8Array;
456
+ chainId: number;
457
+ }): EthereumTx;
458
+ }
459
+
460
+ export interface EthereumTx {
461
+ sign(privateKey: Uint8Array): this;
462
+ serialize(): Uint8Array;
463
+ getHash(): string;
464
+ }
465
+
466
+ // =============================================================================
467
+ // Cosmos API
468
+ // =============================================================================
469
+
470
+ export interface CosmosAPI {
471
+ getAddress(publicKey: Uint8Array, prefix?: string): string;
472
+ validateAddress(address: string): boolean;
473
+ signAmino(doc: object, privateKey: Uint8Array): object;
474
+ signDirect(bodyBytes: Uint8Array, authInfoBytes: Uint8Array, chainId: string, accountNumber: bigint, privateKey: Uint8Array): object;
475
+ verify(signature: Uint8Array, message: Uint8Array, publicKey: Uint8Array): boolean;
476
+ }
477
+
478
+ // =============================================================================
479
+ // Solana API
480
+ // =============================================================================
481
+
482
+ export interface SolanaAPI {
483
+ getAddress(publicKey: Uint8Array): string;
484
+ validateAddress(address: string): boolean;
485
+ signMessage(message: Uint8Array, privateKey: Uint8Array): Uint8Array;
486
+ verifyMessage(message: Uint8Array, signature: Uint8Array, publicKey: Uint8Array): boolean;
487
+ }
488
+
489
+ // =============================================================================
490
+ // Polkadot API
491
+ // =============================================================================
492
+
493
+ export interface PolkadotAPI {
494
+ getAddress(publicKey: Uint8Array, ss58Prefix?: number): string;
495
+ validateAddress(address: string): boolean;
496
+ signMessage(message: Uint8Array, privateKey: Uint8Array): Uint8Array;
497
+ verifyMessage(message: Uint8Array, signature: Uint8Array, publicKey: Uint8Array): boolean;
498
+ }
499
+
500
+ // =============================================================================
501
+ // Hardware Wallet API (requires bridge)
502
+ // =============================================================================
503
+
504
+ export interface HardwareWalletAPI {
505
+ /**
506
+ * Check if hardware wallet features are available
507
+ * Returns false in WASI without bridge
508
+ */
509
+ isAvailable(): boolean;
510
+
511
+ /**
512
+ * Enumerate connected hardware wallets
513
+ */
514
+ enumerate(): Promise<HardwareWalletDevice[]>;
515
+
516
+ /**
517
+ * Connect to a hardware wallet
518
+ */
519
+ connect(devicePath: string): Promise<HardwareWallet>;
520
+ }
521
+
522
+ export interface HardwareWalletDevice {
523
+ vendorId: number;
524
+ productId: number;
525
+ serialNumber: string;
526
+ manufacturer: string;
527
+ product: string;
528
+ path: string;
529
+ }
530
+
531
+ export interface HardwareWallet {
532
+ readonly vendor: string;
533
+ readonly model: string;
534
+ readonly firmwareVersion: string;
535
+ readonly isConnected: boolean;
536
+
537
+ getPublicKey(path: string, curve?: Curve): Promise<Uint8Array>;
538
+ signTransaction(path: string, transaction: Uint8Array): Promise<Uint8Array>;
539
+ signMessage(path: string, message: string): Promise<Uint8Array>;
540
+ ping(): Promise<boolean>;
541
+ disconnect(): void;
542
+ }
543
+
544
+ // =============================================================================
545
+ // Keyring API
546
+ // =============================================================================
547
+
548
+ export interface KeyringAPI {
549
+ create(): Keyring;
550
+ }
551
+
552
+ export interface Keyring {
553
+ addWallet(seed: Uint8Array, name?: string): string;
554
+ removeWallet(id: string): void;
555
+ getWalletCount(): number;
556
+ getAccounts(walletId: string, coinType: CoinType, count?: number): string[];
557
+ signTransaction(walletId: string, path: string, transaction: Uint8Array): Uint8Array;
558
+ signMessage(walletId: string, path: string, message: Uint8Array): Uint8Array;
559
+ destroy(): void;
560
+ }
561
+
562
+ // =============================================================================
563
+ // Utilities API
564
+ // =============================================================================
565
+
566
+ export interface UtilsAPI {
567
+ // Hashing
568
+ sha256(data: Uint8Array): Uint8Array;
569
+ sha512(data: Uint8Array): Uint8Array;
570
+ keccak256(data: Uint8Array): Uint8Array;
571
+ ripemd160(data: Uint8Array): Uint8Array;
572
+ hash160(data: Uint8Array): Uint8Array;
573
+ blake2b(data: Uint8Array, outputLength?: number): Uint8Array;
574
+ blake2s(data: Uint8Array, outputLength?: number): Uint8Array;
575
+
576
+ // Key derivation
577
+ hkdf(ikm: Uint8Array, salt: Uint8Array, info: Uint8Array, length: number): Uint8Array;
578
+ pbkdf2(password: Uint8Array, salt: Uint8Array, iterations: number, length: number): Uint8Array;
579
+ scrypt(password: Uint8Array, salt: Uint8Array, n: number, r: number, p: number, length: number): Uint8Array;
580
+
581
+ // Encoding
582
+ encodeBase58(data: Uint8Array): string;
583
+ decodeBase58(str: string): Uint8Array;
584
+ encodeBase58Check(data: Uint8Array): string;
585
+ decodeBase58Check(str: string): Uint8Array;
586
+ encodeBech32(hrp: string, data: Uint8Array): string;
587
+ decodeBech32(str: string): { hrp: string; data: Uint8Array };
588
+ encodeHex(data: Uint8Array): string;
589
+ decodeHex(str: string): Uint8Array;
590
+ encodeBase64(data: Uint8Array): string;
591
+ decodeBase64(str: string): Uint8Array;
592
+
593
+ // Memory
594
+ secureWipe(data: Uint8Array): void;
595
+ }
596
+
597
+ // =============================================================================
598
+ // Module Initialization
599
+ // =============================================================================
600
+
601
+ /**
602
+ * Initialize the HD Wallet WASM module
603
+ */
604
+ export default function init(): Promise<HDWalletModule>;
605
+
606
+ /**
607
+ * Create HD Wallet instance (alternative syntax)
608
+ */
609
+ export function createHDWallet(): Promise<HDWalletModule>;