@kasflow/passkey-wallet 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.
@@ -0,0 +1,893 @@
1
+ import { RpcClient, UtxoEntryReference, ISubmitTransactionRequest, IPaymentOutput, PendingTransaction, IGeneratorSettingsObject, Generator, PrivateKey } from '@onekeyfe/kaspa-wasm';
2
+ export { Address, Generator, IGeneratorSettingsObject, IPaymentOutput, ISubmitTransactionRequest, ISubmitTransactionResponse, IUtxoEntry, NetworkType, PendingTransaction, PrivateKey, PublicKey, Resolver, RpcClient, Transaction, UtxoContext, UtxoEntryReference, UtxoProcessor } from '@onekeyfe/kaspa-wasm';
3
+ import { KaspaPrefix, KaspaAddressVersion } from '@kluster/kaspa-address';
4
+
5
+ /** Kaspa network identifiers */
6
+ declare const NETWORK_ID: {
7
+ readonly MAINNET: "mainnet";
8
+ readonly TESTNET_10: "testnet-10";
9
+ readonly TESTNET_11: "testnet-11";
10
+ };
11
+ type NetworkId = (typeof NETWORK_ID)[keyof typeof NETWORK_ID];
12
+ /** Default network for development */
13
+ declare const DEFAULT_NETWORK: NetworkId;
14
+ /** Default priority fee in sompi (0.001 KAS) */
15
+ declare const DEFAULT_PRIORITY_FEE_SOMPI = 100000n;
16
+ /** Number of sompi (smallest unit) per KAS */
17
+ declare const SOMPI_PER_KAS = 100000000n;
18
+ /** Minimum transaction fee in sompi */
19
+ declare const MIN_FEE_SOMPI = 1000n;
20
+ declare const ERROR_MESSAGES: {
21
+ readonly WALLET_NOT_FOUND: "No wallet found. Please create a wallet first.";
22
+ readonly WALLET_ALREADY_EXISTS: "A wallet already exists. Delete it before creating a new one.";
23
+ readonly PASSKEY_REGISTRATION_FAILED: "Failed to register passkey. Please try again.";
24
+ readonly PASSKEY_AUTHENTICATION_FAILED: "Failed to authenticate with passkey. Please try again.";
25
+ readonly INVALID_ADDRESS: "Invalid Kaspa address format.";
26
+ readonly INSUFFICIENT_BALANCE: "Insufficient balance for this transaction.";
27
+ readonly WEBAUTHN_NOT_SUPPORTED: "WebAuthn is not supported in this browser.";
28
+ readonly USER_CANCELLED: "Operation was cancelled by the user.";
29
+ readonly WASM_NOT_INITIALIZED: "Kaspa WASM module not initialized. Call initKaspa() first.";
30
+ readonly RPC_NOT_CONNECTED: "Not connected to Kaspa network. Call connect() first.";
31
+ readonly RPC_CONNECTION_FAILED: "Failed to connect to Kaspa network.";
32
+ readonly TRANSACTION_FAILED: "Transaction failed to submit.";
33
+ readonly INVALID_AMOUNT: "Invalid transaction amount.";
34
+ };
35
+ type ErrorMessage = (typeof ERROR_MESSAGES)[keyof typeof ERROR_MESSAGES];
36
+
37
+ /**
38
+ * TypeScript types for @kasflow/passkey-wallet
39
+ */
40
+
41
+ /** Configuration options for creating a new wallet */
42
+ interface CreateWalletOptions {
43
+ /** Display name for the wallet (shown during passkey registration) */
44
+ name?: string;
45
+ /** Network to use (defaults to testnet) */
46
+ network?: NetworkId;
47
+ }
48
+ /** Configuration options for unlocking an existing wallet */
49
+ interface UnlockWalletOptions {
50
+ /** Network to use (should match the network used during creation) */
51
+ network?: NetworkId;
52
+ }
53
+ /** Wallet metadata stored in IndexedDB (no sensitive data) */
54
+ interface WalletMetadata {
55
+ /** Passkey public key (for deterministic key derivation) */
56
+ passkeyPublicKey: string;
57
+ /** Addresses for all networks (enables seamless network switching) */
58
+ addresses: {
59
+ [key in NetworkId]: string;
60
+ };
61
+ /** Primary/default network */
62
+ primaryNetwork: NetworkId;
63
+ /** Creation timestamp */
64
+ createdAt: number;
65
+ /** @deprecated Use addresses map instead */
66
+ address?: string;
67
+ /** @deprecated Use primaryNetwork instead */
68
+ network?: NetworkId;
69
+ }
70
+ /** Input for a transaction */
71
+ interface TransactionInput {
72
+ /** Previous transaction ID */
73
+ previousOutpoint: {
74
+ transactionId: string;
75
+ index: number;
76
+ };
77
+ /** Signature script (populated after signing) */
78
+ signatureScript?: string;
79
+ /** Sequence number */
80
+ sequence: bigint;
81
+ }
82
+ /** Output for a transaction */
83
+ interface TransactionOutput {
84
+ /** Amount in sompi */
85
+ amount: bigint;
86
+ /** Script public key (address) */
87
+ scriptPublicKey: string;
88
+ }
89
+ /** Unsigned transaction ready to be signed */
90
+ interface UnsignedTransaction {
91
+ /** Transaction inputs */
92
+ inputs: TransactionInput[];
93
+ /** Transaction outputs */
94
+ outputs: TransactionOutput[];
95
+ /** Lock time */
96
+ lockTime: bigint;
97
+ /** Subnetwork ID */
98
+ subnetworkId: string;
99
+ /** Transaction version */
100
+ version: number;
101
+ }
102
+ /** Signed transaction ready to be broadcast */
103
+ interface SignedTransaction extends UnsignedTransaction {
104
+ /** Transaction ID (hash) */
105
+ id: string;
106
+ }
107
+ /** WebAuthn credential stored after registration */
108
+ interface StoredCredential {
109
+ /** Credential ID as base64url */
110
+ id: string;
111
+ /** Raw credential ID as Uint8Array */
112
+ rawId: Uint8Array;
113
+ /** Public key as base64url (for verification) */
114
+ publicKey: string;
115
+ /** Counter for replay protection */
116
+ counter: number;
117
+ /** Transports supported by the authenticator */
118
+ transports?: AuthenticatorTransport[];
119
+ }
120
+ /** Result of WebAuthn registration */
121
+ interface RegistrationResult {
122
+ /** Whether registration was successful */
123
+ success: boolean;
124
+ /** Stored credential (if successful) */
125
+ credential?: StoredCredential;
126
+ /** User ID used for registration (for key derivation) */
127
+ userId?: Uint8Array;
128
+ /** Passkey's public key extracted from attestation (for deterministic key derivation) */
129
+ passkeyPublicKey?: Uint8Array;
130
+ /** Error message (if failed) */
131
+ error?: string;
132
+ }
133
+ /** Result of WebAuthn authentication */
134
+ interface AuthenticationResult {
135
+ /** Whether authentication was successful */
136
+ success: boolean;
137
+ /** Signature from the authenticator */
138
+ signature?: Uint8Array;
139
+ /** Client data JSON for key derivation */
140
+ clientDataJSON?: Uint8Array;
141
+ /** Authenticator data */
142
+ authenticatorData?: Uint8Array;
143
+ /** Error message (if failed) */
144
+ error?: string;
145
+ }
146
+ /** Generic result type for SDK operations */
147
+ interface Result<T> {
148
+ /** Whether the operation was successful */
149
+ success: boolean;
150
+ /** Data returned on success */
151
+ data?: T;
152
+ /** Error message on failure */
153
+ error?: string;
154
+ }
155
+ /** Balance information */
156
+ interface BalanceInfo {
157
+ /** Available balance in sompi */
158
+ available: bigint;
159
+ /** Pending balance in sompi */
160
+ pending: bigint;
161
+ /** Total balance in sompi */
162
+ total: bigint;
163
+ }
164
+ /** Events emitted by the wallet */
165
+ type WalletEvent = {
166
+ type: 'connected';
167
+ address: string;
168
+ } | {
169
+ type: 'disconnected';
170
+ } | {
171
+ type: 'balance_updated';
172
+ balance: BalanceInfo;
173
+ } | {
174
+ type: 'transaction_sent';
175
+ txId: string;
176
+ } | {
177
+ type: 'transaction_confirmed';
178
+ txId: string;
179
+ };
180
+ /** Event handler function */
181
+ type WalletEventHandler = (event: WalletEvent) => void;
182
+
183
+ /**
184
+ * RPC client for Kaspa network operations
185
+ * Wraps @onekeyfe/kaspa-wasm RpcClient with a simpler API
186
+ */
187
+
188
+ interface RpcConnectionOptions {
189
+ /** Network to connect to */
190
+ network: NetworkId;
191
+ /** Optional custom RPC URL (defaults to public resolver) */
192
+ url?: string;
193
+ /** Connection timeout in ms (defaults to RPC_TIMEOUT_MS) */
194
+ timeout?: number;
195
+ }
196
+ interface RpcEventHandlers {
197
+ onConnect?: (url: string) => void;
198
+ onDisconnect?: () => void;
199
+ onError?: (error: string) => void;
200
+ }
201
+ /**
202
+ * RPC client for Kaspa network operations
203
+ *
204
+ * @example
205
+ * ```typescript
206
+ * const rpc = new KaspaRpc();
207
+ *
208
+ * await rpc.connect({ network: 'testnet-11' });
209
+ *
210
+ * const balance = await rpc.getBalance('kaspatest:...');
211
+ * console.log('Balance:', balance.available);
212
+ *
213
+ * await rpc.disconnect();
214
+ * ```
215
+ */
216
+ declare class KaspaRpc {
217
+ private rpc;
218
+ private network;
219
+ private eventHandlers;
220
+ /**
221
+ * Check if connected to the network
222
+ */
223
+ get isConnected(): boolean;
224
+ /**
225
+ * Get the current network
226
+ */
227
+ get currentNetwork(): NetworkId | null;
228
+ /**
229
+ * Get the underlying RpcClient instance
230
+ * Only use for advanced operations
231
+ */
232
+ get client(): RpcClient | null;
233
+ /**
234
+ * Set event handlers for connection events
235
+ */
236
+ setEventHandlers(handlers: RpcEventHandlers): void;
237
+ /**
238
+ * Connect to the Kaspa network
239
+ *
240
+ * @param options - Connection options
241
+ * @throws Error if connection fails
242
+ */
243
+ connect(options: RpcConnectionOptions): Promise<void>;
244
+ /**
245
+ * Disconnect from the network
246
+ */
247
+ disconnect(): Promise<void>;
248
+ /**
249
+ * Ensure RPC is connected, throw if not
250
+ */
251
+ private ensureConnected;
252
+ /**
253
+ * Get balance for an address
254
+ *
255
+ * @param address - Kaspa address
256
+ * @returns Balance info with available, pending, and total amounts
257
+ */
258
+ getBalance(address: string): Promise<BalanceInfo>;
259
+ /**
260
+ * Get UTXOs for an address
261
+ *
262
+ * @param address - Kaspa address
263
+ * @returns Array of UTXO entries
264
+ */
265
+ getUtxos(address: string): Promise<UtxoEntryReference[]>;
266
+ /**
267
+ * Get UTXOs for multiple addresses
268
+ *
269
+ * @param addresses - Array of Kaspa addresses
270
+ * @returns Array of UTXO entries
271
+ */
272
+ getUtxosForAddresses(addresses: string[]): Promise<UtxoEntryReference[]>;
273
+ /**
274
+ * Submit a signed transaction to the network
275
+ *
276
+ * @param transaction - Signed transaction object
277
+ * @param allowOrphan - Allow orphan transactions (default: false)
278
+ * @returns Transaction ID
279
+ */
280
+ submitTransaction(transaction: ISubmitTransactionRequest['transaction'], allowOrphan?: boolean): Promise<string>;
281
+ /**
282
+ * Get the current block count
283
+ */
284
+ getBlockCount(): Promise<bigint>;
285
+ /**
286
+ * Get network info (DAG info)
287
+ */
288
+ getNetworkInfo(): Promise<{
289
+ network: string;
290
+ blockCount: bigint;
291
+ headerCount: bigint;
292
+ tipHashes: string[];
293
+ difficulty: number;
294
+ pastMedianTime: bigint;
295
+ virtualParentHashes: string[];
296
+ pruningPointHash: string;
297
+ virtualDaaScore: bigint;
298
+ sink: string;
299
+ }>;
300
+ /**
301
+ * Get the current server info
302
+ */
303
+ getServerInfo(): Promise<{
304
+ serverVersion: string;
305
+ rpcApiVersion: number[];
306
+ isSynced: boolean;
307
+ hasUtxoIndex: boolean;
308
+ }>;
309
+ }
310
+ /**
311
+ * Get or create the default RPC instance
312
+ */
313
+ declare const getDefaultRpc: () => KaspaRpc;
314
+ /**
315
+ * Reset the default RPC instance
316
+ */
317
+ declare const resetDefaultRpc: () => Promise<void>;
318
+
319
+ /**
320
+ * Transaction building and signing utilities for @kasflow/passkey-wallet
321
+ * Uses @onekeyfe/kaspa-wasm Generator and createTransactions
322
+ */
323
+
324
+ interface SendOptions {
325
+ /** Destination address */
326
+ to: string;
327
+ /** Amount to send in sompi */
328
+ amount: bigint;
329
+ /** Priority fee in sompi (defaults to DEFAULT_PRIORITY_FEE_SOMPI) */
330
+ priorityFee?: bigint;
331
+ }
332
+ interface SendResult {
333
+ /** Transaction ID (hash) */
334
+ transactionId: string;
335
+ /** Amount sent in sompi */
336
+ amount: bigint;
337
+ /** Fee paid in sompi */
338
+ fee: bigint;
339
+ }
340
+ interface TransactionEstimate {
341
+ /** Total number of transactions needed (1 for simple sends) */
342
+ transactionCount: number;
343
+ /** Total fees in sompi */
344
+ fees: bigint;
345
+ /** Number of UTXOs being consumed */
346
+ utxoCount: number;
347
+ /** Final amount including fees */
348
+ finalAmount: bigint;
349
+ }
350
+ /**
351
+ * Build transactions for sending KAS
352
+ * Returns pending transactions ready for signing
353
+ *
354
+ * @param utxos - Array of UTXO entries from the wallet
355
+ * @param outputs - Payment outputs (destination and amount)
356
+ * @param changeAddress - Address to receive change
357
+ * @param priorityFee - Priority fee in sompi
358
+ * @param network - Network identifier
359
+ */
360
+ declare const buildTransactions: (utxos: UtxoEntryReference[], outputs: IPaymentOutput[], changeAddress: string, priorityFee: bigint | undefined, network: NetworkId) => Promise<{
361
+ transactions: PendingTransaction[];
362
+ summary: {
363
+ transactionCount: number;
364
+ fees: bigint;
365
+ utxoCount: number;
366
+ finalAmount: bigint | undefined;
367
+ };
368
+ }>;
369
+ /**
370
+ * Estimate fees for a transaction without building it
371
+ *
372
+ * @param utxos - Array of UTXO entries from the wallet
373
+ * @param outputs - Payment outputs (destination and amount)
374
+ * @param changeAddress - Address to receive change
375
+ * @param priorityFee - Priority fee in sompi
376
+ * @param network - Network identifier
377
+ */
378
+ declare const estimateFee: (utxos: UtxoEntryReference[], outputs: IPaymentOutput[], changeAddress: string, priorityFee: bigint | undefined, network: NetworkId) => Promise<TransactionEstimate>;
379
+ /**
380
+ * Sign pending transactions with a private key
381
+ * Uses PendingTransaction.sign() method for proper signature handling
382
+ *
383
+ * @param transactions - Array of pending transactions
384
+ * @param privateKeyHex - Private key as hex string
385
+ * @returns Array of signed transactions (same array, mutated)
386
+ */
387
+ declare const signTransactions: (transactions: PendingTransaction[], privateKeyHex: string) => Promise<PendingTransaction[]>;
388
+ /**
389
+ * Submit signed transactions to the network
390
+ *
391
+ * @param transactions - Array of signed pending transactions
392
+ * @param rpc - RPC client instance
393
+ * @returns Array of transaction IDs
394
+ */
395
+ declare const submitTransactions: (transactions: PendingTransaction[], rpc: KaspaRpc) => Promise<string[]>;
396
+ /**
397
+ * Complete send flow: build, sign, and submit a transaction
398
+ *
399
+ * @param options - Send options (to, amount, priorityFee)
400
+ * @param utxos - UTXOs to spend from
401
+ * @param changeAddress - Address to receive change
402
+ * @param privateKeyHex - Private key for signing
403
+ * @param rpc - Connected RPC client
404
+ * @param network - Network identifier
405
+ * @returns Send result with transaction ID and details
406
+ */
407
+ declare const sendTransaction: (options: SendOptions, utxos: UtxoEntryReference[], changeAddress: string, privateKeyHex: string, rpc: KaspaRpc, network: NetworkId) => Promise<SendResult>;
408
+ /**
409
+ * Create a transaction generator for streaming transaction generation
410
+ * Useful for complex transactions that may need multiple passes
411
+ *
412
+ * @param settings - Generator settings
413
+ * @returns Generator instance
414
+ */
415
+ declare const createGenerator: (settings: IGeneratorSettingsObject) => Promise<Generator>;
416
+
417
+ /**
418
+ * PasskeyWallet - Main wallet class for @kasflow/passkey-wallet
419
+ * Provides a simple API for creating and managing passkey-protected Kaspa wallets
420
+ */
421
+
422
+ /**
423
+ * PasskeyWallet provides a simple interface for passkey-protected Kaspa wallets
424
+ *
425
+ * @example
426
+ * ```typescript
427
+ * // Create a new wallet
428
+ * const result = await PasskeyWallet.create({ name: 'My Wallet' });
429
+ * if (result.success) {
430
+ * const wallet = result.data;
431
+ * console.log('Address:', wallet.getAddress());
432
+ *
433
+ * // Connect to network
434
+ * await wallet.connect();
435
+ *
436
+ * // Get balance
437
+ * const balance = await wallet.getBalance();
438
+ * console.log('Balance:', balance.available);
439
+ *
440
+ * // Send KAS
441
+ * const tx = await wallet.send({
442
+ * to: 'kaspatest:...',
443
+ * amount: 100000000n, // 1 KAS in sompi
444
+ * });
445
+ * console.log('Transaction ID:', tx.transactionId);
446
+ * }
447
+ *
448
+ * // Unlock existing wallet
449
+ * const result = await PasskeyWallet.unlock();
450
+ * ```
451
+ */
452
+ declare class PasskeyWallet {
453
+ private privateKeyHex;
454
+ private publicKeyHex;
455
+ private address;
456
+ private network;
457
+ private eventHandlers;
458
+ private rpc;
459
+ private credentialId;
460
+ private passkeyPublicKey;
461
+ private constructor();
462
+ /**
463
+ * Check if WebAuthn/passkeys are supported in the current browser
464
+ */
465
+ static isSupported(): boolean;
466
+ /**
467
+ * Check if a wallet already exists in storage
468
+ */
469
+ static exists(): Promise<boolean>;
470
+ /**
471
+ * Create a new passkey-protected wallet
472
+ *
473
+ * @param options - Configuration options
474
+ * @returns Result containing the wallet instance or error
475
+ */
476
+ static create(options?: CreateWalletOptions): Promise<Result<PasskeyWallet>>;
477
+ /**
478
+ * Unlock an existing wallet using passkey authentication
479
+ *
480
+ * @param options - Configuration options
481
+ * @returns Result containing the wallet instance or error
482
+ */
483
+ static unlock(options?: UnlockWalletOptions): Promise<Result<PasskeyWallet>>;
484
+ /**
485
+ * Delete the wallet from storage
486
+ * This is irreversible - make sure user has backed up their keys!
487
+ */
488
+ static delete(): Promise<Result<void>>;
489
+ /**
490
+ * Get the wallet's Kaspa address
491
+ */
492
+ getAddress(): string;
493
+ /**
494
+ * Get the wallet's public key as hex string
495
+ */
496
+ getPublicKey(): string;
497
+ /**
498
+ * Get the current network
499
+ */
500
+ getNetwork(): NetworkId;
501
+ /**
502
+ * Sign a message with the wallet's private key
503
+ * Uses Kaspa's message signing scheme
504
+ *
505
+ * @param message - Message to sign
506
+ * @returns Signature as hex string
507
+ */
508
+ signMessage(message: string): Promise<string>;
509
+ /**
510
+ * Get the private key hex (for advanced usage like transaction signing)
511
+ * WARNING: Handle with care - this is sensitive data
512
+ */
513
+ getPrivateKeyHex(): string;
514
+ /**
515
+ * Check if connected to the network
516
+ */
517
+ get isConnected(): boolean;
518
+ /**
519
+ * Get the underlying RPC client for advanced usage
520
+ */
521
+ getRpcClient(): KaspaRpc;
522
+ /**
523
+ * Connect to the Kaspa network
524
+ *
525
+ * @param options - Optional connection options (defaults to current network with public resolver)
526
+ */
527
+ connect(options?: Partial<RpcConnectionOptions>): Promise<void>;
528
+ /**
529
+ * Disconnect from the Kaspa network
530
+ */
531
+ disconnectNetwork(): Promise<void>;
532
+ /**
533
+ * Switch to a different network without re-authentication
534
+ * Uses pre-computed addresses from wallet creation
535
+ *
536
+ * @param network - Target network to switch to
537
+ * @returns Result with success status
538
+ */
539
+ switchNetwork(network: NetworkId): Promise<Result<void>>;
540
+ /**
541
+ * Get the wallet's balance
542
+ *
543
+ * @returns Balance info with available, pending, and total amounts
544
+ * @throws Error if not connected to network
545
+ */
546
+ getBalance(): Promise<BalanceInfo>;
547
+ /**
548
+ * Send KAS to an address
549
+ *
550
+ * @param options - Send options (to, amount, priorityFee)
551
+ * @returns Send result with transaction ID and details
552
+ * @throws Error if not connected or insufficient balance
553
+ *
554
+ * @example
555
+ * ```typescript
556
+ * const result = await wallet.send({
557
+ * to: 'kaspatest:qz...',
558
+ * amount: 100000000n, // 1 KAS
559
+ * });
560
+ * console.log('Transaction ID:', result.transactionId);
561
+ * ```
562
+ */
563
+ send(options: SendOptions): Promise<SendResult>;
564
+ /**
565
+ * Send transaction with per-transaction passkey authentication
566
+ *
567
+ * **RECOMMENDED:** Use this method instead of `send()` for better security.
568
+ *
569
+ * This method prompts for passkey authentication for EACH transaction, using the
570
+ * transaction hash as the WebAuthn challenge. This provides cryptographic proof
571
+ * that the user approved THIS specific transaction.
572
+ *
573
+ * Benefits over `send()`:
574
+ * - Per-transaction authentication (user approves each transaction)
575
+ * - Transaction hash cryptographically bound to WebAuthn signature
576
+ * - Keys derived only when needed, not stored in memory
577
+ * - Matches standard wallet UX (MetaMask, hardware wallets)
578
+ *
579
+ * @param options - Send options (to, amount, priorityFee)
580
+ * @returns Transaction result with ID and fees
581
+ * @throws Error if authentication fails, insufficient balance, or network error
582
+ *
583
+ * @example
584
+ * ```typescript
585
+ * const result = await wallet.sendWithAuth({
586
+ * to: 'kaspatest:qz...',
587
+ * amount: 100000000n, // 1 KAS
588
+ * });
589
+ * console.log('Transaction ID:', result.transactionId);
590
+ * ```
591
+ */
592
+ sendWithAuth(options: SendOptions): Promise<SendResult>;
593
+ /**
594
+ * Estimate the fee for a transaction
595
+ *
596
+ * @param options - Send options (to, amount, priorityFee)
597
+ * @returns Transaction estimate with fees and UTXO count
598
+ * @throws Error if not connected
599
+ */
600
+ estimateFee(options: SendOptions): Promise<TransactionEstimate>;
601
+ /**
602
+ * Subscribe to wallet events
603
+ *
604
+ * @param handler - Event handler function
605
+ * @returns Unsubscribe function
606
+ */
607
+ on(handler: WalletEventHandler): () => void;
608
+ /**
609
+ * Emit an event to all subscribers
610
+ */
611
+ private emit;
612
+ /**
613
+ * Verify that WebAuthn authentication result is for specific transaction
614
+ *
615
+ * This method ensures the WebAuthn signature was created for THIS specific
616
+ * transaction by verifying that the challenge in clientDataJSON matches the
617
+ * transaction hash.
618
+ *
619
+ * This prevents replay attacks where an attacker could try to reuse a signature
620
+ * from a different transaction.
621
+ *
622
+ * @param authResult - Authentication result from passkey
623
+ * @param txHash - Transaction hash that should be in the challenge
624
+ * @returns true if verified, false otherwise
625
+ */
626
+ private verifyAuthenticationForTransaction;
627
+ /**
628
+ * Disconnect the wallet (clears in-memory keys and network connection)
629
+ */
630
+ disconnect(): Promise<void>;
631
+ }
632
+
633
+ /**
634
+ * Convert Uint8Array to hex string
635
+ */
636
+ declare const uint8ArrayToHex: (bytes: Uint8Array) => string;
637
+ /**
638
+ * Convert hex string to Uint8Array
639
+ */
640
+ declare const hexToUint8Array: (hex: string) => Uint8Array;
641
+
642
+ /**
643
+ * Kaspa utilities for @kasflow/passkey-wallet
644
+ * Uses @onekeyfe/kaspa-wasm for all Kaspa operations
645
+ */
646
+
647
+ /**
648
+ * Get the network type string for WASM SDK
649
+ * The WASM SDK accepts: 'mainnet', 'testnet-10', 'testnet-11', etc.
650
+ */
651
+ declare const getNetworkType: (network: NetworkId) => string;
652
+ /**
653
+ * Get the network ID string (same as getNetworkType, for API consistency)
654
+ */
655
+ declare const getNetworkIdString: (network: NetworkId) => string;
656
+ /**
657
+ * Generate a new random private key hex string
658
+ */
659
+ declare const generatePrivateKey: () => string;
660
+ /**
661
+ * Create a PrivateKey instance from hex string
662
+ */
663
+ declare const createPrivateKey: (privateKeyHex: string) => Promise<PrivateKey>;
664
+ /**
665
+ * Get public key hex from private key hex
666
+ */
667
+ declare const getPublicKeyHex: (privateKeyHex: string) => Promise<string>;
668
+ /**
669
+ * Get Kaspa address from private key
670
+ */
671
+ declare const getAddressFromPrivateKey: (privateKeyHex: string, network: NetworkId) => Promise<string>;
672
+ /**
673
+ * Validate a private key hex string
674
+ */
675
+ declare const isValidPrivateKey: (privateKeyHex: string) => Promise<boolean>;
676
+ /**
677
+ * Create a Kaspa address from a public key
678
+ */
679
+ declare const publicKeyToAddress: (publicKeyHex: string, network: NetworkId) => Promise<string>;
680
+ /**
681
+ * Validate a Kaspa address using @kluster/kaspa-address
682
+ */
683
+ declare const isValidAddress: (address: string) => boolean;
684
+ /**
685
+ * Parse a Kaspa address and extract components
686
+ */
687
+ declare const parseAddress: (address: string) => {
688
+ prefix: KaspaPrefix;
689
+ version: KaspaAddressVersion;
690
+ payload: Uint8Array;
691
+ };
692
+ /**
693
+ * Get the network from an address
694
+ */
695
+ declare const getNetworkFromAddress: (address: string) => NetworkId;
696
+ /**
697
+ * Sign a message with a private key
698
+ * Uses Kaspa's message signing scheme
699
+ *
700
+ * @param message - The message to sign
701
+ * @param privateKeyHex - Private key as hex string
702
+ * @returns Signature as hex string
703
+ */
704
+ declare const signMessageWithKey: (message: string, privateKeyHex: string) => Promise<string>;
705
+ /**
706
+ * Sign a transaction with private keys
707
+ * Returns the signed transaction
708
+ *
709
+ * @param transaction - The transaction to sign
710
+ * @param privateKeys - Array of private key hex strings or PrivateKey instances
711
+ * @param verifySig - Whether to verify signatures after signing
712
+ */
713
+ declare const signTransaction: (transaction: any, privateKeys: (string | PrivateKey)[], verifySig?: boolean) => Promise<any>;
714
+ /**
715
+ * Convert a KAS string to sompi (bigint)
716
+ * This function provides correct precision handling
717
+ */
718
+ declare const kasStringToSompi: (kasString: string) => bigint;
719
+ /**
720
+ * Convert sompi to a KAS string representation
721
+ */
722
+ declare const sompiToKasString: (sompi: bigint | number) => string;
723
+ /**
724
+ * Convert sompi to KAS string with network suffix (KAS, TKAS, etc.)
725
+ */
726
+ declare const sompiToKasStringWithSuffix: (sompi: bigint | number, network: NetworkId) => string;
727
+ /**
728
+ * Convert sompi to KAS as a number
729
+ */
730
+ declare const sompiToKas: (sompi: bigint) => number;
731
+ /**
732
+ * Convert KAS to sompi
733
+ */
734
+ declare const kasToSompi: (kas: number) => bigint;
735
+ /**
736
+ * Format KAS amount for display
737
+ */
738
+ declare const formatKas: (sompi: bigint, decimals?: number) => string;
739
+ /**
740
+ * Parse KAS string to sompi (alias for kasStringToSompi)
741
+ */
742
+ declare const parseKas: (kasString: string) => bigint;
743
+ /**
744
+ * Compute transaction hash for use as WebAuthn challenge
745
+ *
746
+ * This function extracts the transaction ID (hash) from a PendingTransaction
747
+ * and converts it to a Uint8Array suitable for use as a WebAuthn challenge.
748
+ *
749
+ * The transaction ID is the BLAKE2b-256 hash of the transaction data, which
750
+ * uniquely identifies the transaction and can be used to cryptographically
751
+ * bind a WebAuthn signature to a specific transaction.
752
+ *
753
+ * @param tx - PendingTransaction from WASM SDK
754
+ * @returns 32-byte transaction hash as Uint8Array
755
+ *
756
+ * @example
757
+ * ```typescript
758
+ * const tx = await buildTransaction(options);
759
+ * const txHash = computeTransactionHash(tx);
760
+ * const authResult = await authenticateWithChallenge(credentialId, txHash);
761
+ * ```
762
+ */
763
+ declare const computeTransactionHash: (tx: any) => Uint8Array;
764
+
765
+ /**
766
+ * WebAuthn utilities for @kasflow/passkey-wallet
767
+ * Handles passkey registration and authentication
768
+ */
769
+
770
+ /**
771
+ * Check if WebAuthn is supported in the current browser
772
+ */
773
+ declare const isWebAuthnSupported: () => boolean;
774
+ /**
775
+ * Authenticate with passkey using custom challenge (e.g., transaction hash)
776
+ *
777
+ * This function enables per-transaction authentication by using transaction-specific
778
+ * data as the WebAuthn challenge. The authenticator signs the challenge, creating
779
+ * cryptographic proof that the user approved THIS specific transaction.
780
+ *
781
+ * @param credentialId - Stored credential ID from wallet creation
782
+ * @param challenge - Custom challenge bytes (e.g., transaction hash)
783
+ * @returns Authentication result with signature
784
+ *
785
+ * @example
786
+ * ```typescript
787
+ * const txHash = await computeTransactionHash(transaction);
788
+ * const authResult = await authenticateWithChallenge(credentialId, txHash);
789
+ * // authResult.signature proves user approved this specific transaction
790
+ * ```
791
+ */
792
+ declare const authenticateWithChallenge: (credentialId: string, challenge: Uint8Array) => Promise<AuthenticationResult>;
793
+
794
+ /**
795
+ * COSE (CBOR Object Signing and Encryption) Parser
796
+ * Extracts public keys from WebAuthn attestation objects
797
+ */
798
+ /**
799
+ * Extract public key from WebAuthn attestation object
800
+ *
801
+ * @param attestationObjectBase64 - Base64url-encoded attestation object from WebAuthn
802
+ * @returns Uncompressed secp256k1 public key (65 bytes: 0x04 + x + y)
803
+ * @throws Error if attestation object is invalid or public key cannot be extracted
804
+ */
805
+ declare function extractPublicKeyFromAttestation(attestationObjectBase64: string): Uint8Array;
806
+
807
+ /**
808
+ * Deterministic Key Derivation
809
+ * Derives Kaspa wallet keys from passkey public keys
810
+ */
811
+ /**
812
+ * Derive deterministic Kaspa private key from passkey public key
813
+ *
814
+ * How it works:
815
+ * 1. Hash the passkey public key with SHA-256
816
+ * 2. Use the hash as the Kaspa private key seed
817
+ * 3. Same passkey public key → same hash → same Kaspa wallet
818
+ *
819
+ * This enables multi-device wallet access:
820
+ * - Create wallet on Device A with fingerprint
821
+ * - Passkey syncs via iCloud/Google
822
+ * - Unlock on Device B with same fingerprint → same wallet!
823
+ *
824
+ * @param passkeyPublicKey - Uncompressed passkey public key (65 bytes: 0x04 + x + y)
825
+ * @returns Private key hex and seed for Kaspa wallet
826
+ */
827
+ declare function deriveKaspaKeysFromPasskey(passkeyPublicKey: Uint8Array): {
828
+ privateKeyHex: string;
829
+ seed: Uint8Array;
830
+ };
831
+ /**
832
+ * Verify that same passkey public key produces same Kaspa keys (determinism check)
833
+ *
834
+ * @param passkeyPublicKey - Passkey public key to test
835
+ * @param expectedPrivateKeyHex - Expected private key hex
836
+ * @returns True if derivation is deterministic
837
+ */
838
+ declare function verifyDeterminism(passkeyPublicKey: Uint8Array, expectedPrivateKeyHex: string): boolean;
839
+
840
+ /**
841
+ * Logger utility for @kasflow/passkey-wallet
842
+ * Centralized logging with module prefixes
843
+ */
844
+ declare class Logger {
845
+ private module;
846
+ constructor(module: string);
847
+ private formatMessage;
848
+ /**
849
+ * Log info message
850
+ */
851
+ info(...args: unknown[]): void;
852
+ /**
853
+ * Log warning message
854
+ */
855
+ warn(...args: unknown[]): void;
856
+ /**
857
+ * Log error message
858
+ */
859
+ error(...args: unknown[]): void;
860
+ /**
861
+ * Log debug message (only in development)
862
+ */
863
+ debug(...args: unknown[]): void;
864
+ }
865
+ /**
866
+ * Create a logger instance for a module
867
+ *
868
+ * @param module - Module name (e.g., 'WebAuthn', 'Wallet', 'RPC')
869
+ * @returns Logger instance
870
+ *
871
+ * @example
872
+ * ```typescript
873
+ * import { createLogger } from './logger';
874
+ *
875
+ * const logger = createLogger('WebAuthn');
876
+ * logger.info('Starting registration...');
877
+ * logger.error('Registration failed:', error);
878
+ * ```
879
+ */
880
+ declare function createLogger(module: string): Logger;
881
+
882
+ /**
883
+ * WASM SDK re-exports for @kasflow/passkey-wallet
884
+ * Re-exports commonly used types and functions from @onekeyfe/kaspa-wasm
885
+ */
886
+
887
+ /**
888
+ * Initialize console panic hook for better debugging
889
+ * Call this in development to see WASM panic messages
890
+ */
891
+ declare const initDebugMode: () => Promise<void>;
892
+
893
+ export { type AuthenticationResult, type BalanceInfo, type CreateWalletOptions, DEFAULT_NETWORK, DEFAULT_PRIORITY_FEE_SOMPI, ERROR_MESSAGES, type ErrorMessage, KaspaRpc, MIN_FEE_SOMPI, NETWORK_ID, type NetworkId, PasskeyWallet, type RegistrationResult, type Result, type RpcConnectionOptions, type RpcEventHandlers, SOMPI_PER_KAS, type SendOptions, type SendResult, type SignedTransaction, type StoredCredential, type TransactionEstimate, type TransactionInput, type TransactionOutput, type UnlockWalletOptions, type UnsignedTransaction, type WalletEvent, type WalletEventHandler, type WalletMetadata, authenticateWithChallenge, buildTransactions, computeTransactionHash, createGenerator, createLogger, createPrivateKey, deriveKaspaKeysFromPasskey, estimateFee, extractPublicKeyFromAttestation, formatKas, generatePrivateKey, getAddressFromPrivateKey, getDefaultRpc, getNetworkFromAddress, getNetworkIdString, getNetworkType, getPublicKeyHex, hexToUint8Array, initDebugMode, isValidAddress, isValidPrivateKey, isWebAuthnSupported, kasStringToSompi, kasToSompi, parseAddress, parseKas, publicKeyToAddress, resetDefaultRpc, sendTransaction, signMessageWithKey, signTransaction, signTransactions, sompiToKas, sompiToKasString, sompiToKasStringWithSuffix, submitTransactions, uint8ArrayToHex, verifyDeterminism };