navio-sdk 0.1.0 → 0.1.2
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/README.md +277 -13
- package/dist/index.d.mts +435 -2
- package/dist/index.d.ts +435 -2
- package/dist/index.js +908 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +891 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -2
package/dist/index.d.ts
CHANGED
|
@@ -167,6 +167,10 @@ declare class KeyManager {
|
|
|
167
167
|
private timeFirstKey;
|
|
168
168
|
private fViewKeyDefined;
|
|
169
169
|
private fSpendKeyDefined;
|
|
170
|
+
private encrypted;
|
|
171
|
+
private encryptionSalt;
|
|
172
|
+
private passwordVerificationHash;
|
|
173
|
+
private encryptionKey;
|
|
170
174
|
/**
|
|
171
175
|
* Check if HD is enabled (has a seed)
|
|
172
176
|
* @returns True if HD is enabled
|
|
@@ -177,6 +181,82 @@ declare class KeyManager {
|
|
|
177
181
|
* @returns True if HD is enabled
|
|
178
182
|
*/
|
|
179
183
|
canGenerateKeys(): boolean;
|
|
184
|
+
/**
|
|
185
|
+
* Check if the wallet is encrypted
|
|
186
|
+
* @returns True if the wallet has been encrypted with a password
|
|
187
|
+
*/
|
|
188
|
+
isEncrypted(): boolean;
|
|
189
|
+
/**
|
|
190
|
+
* Check if the wallet is unlocked (decryption key is cached)
|
|
191
|
+
* @returns True if the wallet is unlocked and can access private keys
|
|
192
|
+
*/
|
|
193
|
+
isUnlocked(): boolean;
|
|
194
|
+
/**
|
|
195
|
+
* Set a password to encrypt the wallet
|
|
196
|
+
* This encrypts all private keys and stores them in encrypted form
|
|
197
|
+
*
|
|
198
|
+
* @param password - The password to encrypt the wallet with
|
|
199
|
+
* @throws Error if wallet is already encrypted
|
|
200
|
+
*/
|
|
201
|
+
setPassword(password: string): Promise<void>;
|
|
202
|
+
/**
|
|
203
|
+
* Unlock an encrypted wallet with the password
|
|
204
|
+
* This derives the encryption key and caches it for decrypting private keys
|
|
205
|
+
*
|
|
206
|
+
* @param password - The wallet password
|
|
207
|
+
* @returns True if the password is correct and wallet is unlocked
|
|
208
|
+
*/
|
|
209
|
+
unlock(password: string): Promise<boolean>;
|
|
210
|
+
/**
|
|
211
|
+
* Lock the wallet, clearing the cached encryption key
|
|
212
|
+
* After locking, private keys cannot be accessed without unlocking again
|
|
213
|
+
*/
|
|
214
|
+
lock(): void;
|
|
215
|
+
/**
|
|
216
|
+
* Change the wallet password
|
|
217
|
+
*
|
|
218
|
+
* @param oldPassword - The current password
|
|
219
|
+
* @param newPassword - The new password
|
|
220
|
+
* @returns True if password was changed successfully
|
|
221
|
+
* @throws Error if wallet is not encrypted or old password is incorrect
|
|
222
|
+
*/
|
|
223
|
+
changePassword(oldPassword: string, newPassword: string): Promise<boolean>;
|
|
224
|
+
/**
|
|
225
|
+
* Get encryption parameters for storage
|
|
226
|
+
* @returns Encryption salt and verification hash, or null if not encrypted
|
|
227
|
+
*/
|
|
228
|
+
getEncryptionParams(): {
|
|
229
|
+
salt: string;
|
|
230
|
+
verificationHash: string;
|
|
231
|
+
} | null;
|
|
232
|
+
/**
|
|
233
|
+
* Set encryption parameters from storage (for loading encrypted wallet)
|
|
234
|
+
* @param salt - Hex-encoded salt
|
|
235
|
+
* @param verificationHash - Hex-encoded verification hash
|
|
236
|
+
*/
|
|
237
|
+
setEncryptionParams(salt: string, verificationHash: string): void;
|
|
238
|
+
/**
|
|
239
|
+
* Encrypt all private keys in the wallet
|
|
240
|
+
* Internal method called when setting password
|
|
241
|
+
*/
|
|
242
|
+
private encryptAllKeys;
|
|
243
|
+
/**
|
|
244
|
+
* Decrypt essential keys needed for wallet operations
|
|
245
|
+
* Called after successful unlock
|
|
246
|
+
*/
|
|
247
|
+
private decryptEssentialKeys;
|
|
248
|
+
/**
|
|
249
|
+
* Re-encrypt all keys with a new key (for password change)
|
|
250
|
+
*/
|
|
251
|
+
private reEncryptAllKeys;
|
|
252
|
+
/**
|
|
253
|
+
* Serialize EncryptedData to bytes for storage
|
|
254
|
+
*/
|
|
255
|
+
private serializeEncryptedToBytes;
|
|
256
|
+
/**
|
|
257
|
+
* Deserialize EncryptedData from bytes
|
|
258
|
+
*/
|
|
259
|
+
private deserializeEncryptedFromBytes;
|
|
180
260
|
/**
|
|
181
261
|
* Generate a new random seed
|
|
182
262
|
* @returns A new random Scalar (seed)
|
|
@@ -203,6 +283,65 @@ declare class KeyManager {
|
|
|
203
283
|
* @returns The master seed Scalar
|
|
204
284
|
*/
|
|
205
285
|
getMasterSeedKey(): ScalarType;
|
|
286
|
+
/**
|
|
287
|
+
* Generate a new random mnemonic phrase (24 words)
|
|
288
|
+
* @param strength - Entropy strength in bits (128=12 words, 160=15 words, 192=18 words, 224=21 words, 256=24 words)
|
|
289
|
+
* @returns A BIP39 mnemonic phrase
|
|
290
|
+
*/
|
|
291
|
+
static generateMnemonic(strength?: 128 | 160 | 192 | 224 | 256): string;
|
|
292
|
+
/**
|
|
293
|
+
* Validate a mnemonic phrase
|
|
294
|
+
* @param mnemonic - The mnemonic phrase to validate
|
|
295
|
+
* @returns True if the mnemonic is valid
|
|
296
|
+
*/
|
|
297
|
+
static validateMnemonic(mnemonic: string): boolean;
|
|
298
|
+
/**
|
|
299
|
+
* Convert a mnemonic phrase to seed bytes
|
|
300
|
+
* Uses BIP39 standard derivation with optional passphrase
|
|
301
|
+
* @param mnemonic - The mnemonic phrase
|
|
302
|
+
* @param passphrase - Optional passphrase for additional security
|
|
303
|
+
* @returns 64-byte seed derived from mnemonic
|
|
304
|
+
*/
|
|
305
|
+
static mnemonicToSeedBytes(mnemonic: string, passphrase?: string): Uint8Array;
|
|
306
|
+
/**
|
|
307
|
+
* Convert a seed (Scalar) to a mnemonic phrase
|
|
308
|
+
* Note: This converts the 32-byte scalar to mnemonic using it as entropy
|
|
309
|
+
* @param seed - The seed Scalar
|
|
310
|
+
* @returns A 24-word mnemonic phrase
|
|
311
|
+
*/
|
|
312
|
+
static seedToMnemonic(seed: ScalarType): string;
|
|
313
|
+
/**
|
|
314
|
+
* Convert a mnemonic phrase to a Scalar seed
|
|
315
|
+
* For direct entropy-based conversion (mnemonic as entropy, not BIP39 derivation)
|
|
316
|
+
* @param mnemonic - The mnemonic phrase
|
|
317
|
+
* @returns A Scalar seed
|
|
318
|
+
*/
|
|
319
|
+
static mnemonicToScalar(mnemonic: string): ScalarType;
|
|
320
|
+
/**
|
|
321
|
+
* Generate a new mnemonic and set it as the HD seed
|
|
322
|
+
* @param strength - Entropy strength in bits (default: 256 for 24 words)
|
|
323
|
+
* @returns The mnemonic phrase that can be used to recover this wallet
|
|
324
|
+
* @note The returned mnemonic is derived from the stored seed, which ensures
|
|
325
|
+
* it will produce the same wallet when used for restoration. Due to BLS
|
|
326
|
+
* Scalar normalization, this may differ from the initially generated entropy.
|
|
327
|
+
*/
|
|
328
|
+
generateNewMnemonic(strength?: 128 | 160 | 192 | 224 | 256): string;
|
|
329
|
+
/**
|
|
330
|
+
* Set the HD seed from a mnemonic phrase
|
|
331
|
+
* Uses direct entropy conversion (mnemonic words encode the seed directly)
|
|
332
|
+
* @param mnemonic - The mnemonic phrase
|
|
333
|
+
*/
|
|
334
|
+
setHDSeedFromMnemonic(mnemonic: string): void;
|
|
335
|
+
/**
|
|
336
|
+
* Get the mnemonic phrase for the current seed
|
|
337
|
+
* @returns The mnemonic phrase for the current master seed
|
|
338
|
+
*/
|
|
339
|
+
getMnemonic(): string;
|
|
340
|
+
/**
|
|
341
|
+
* Get the master seed as a hex string
|
|
342
|
+
* @returns The master seed as a 64-character hex string (32 bytes)
|
|
343
|
+
*/
|
|
344
|
+
getMasterSeedHex(): string;
|
|
206
345
|
/**
|
|
207
346
|
* Get the private view key
|
|
208
347
|
* @returns The view key
|
|
@@ -220,6 +359,24 @@ declare class KeyManager {
|
|
|
220
359
|
* @returns The sub-address (SubAddr)
|
|
221
360
|
*/
|
|
222
361
|
getSubAddress(id?: SubAddressIdentifier): SubAddrType;
|
|
362
|
+
/**
|
|
363
|
+
* Get a bech32m encoded address string for the given sub-address identifier
|
|
364
|
+
* @param id - The sub-address identifier (defaults to account 0, address 0)
|
|
365
|
+
* @param network - The network type ('mainnet' or 'testnet', defaults to 'mainnet')
|
|
366
|
+
* @returns The bech32m encoded address string
|
|
367
|
+
* @example
|
|
368
|
+
* ```typescript
|
|
369
|
+
* const keyManager = new KeyManager();
|
|
370
|
+
* keyManager.setHDSeed(seed);
|
|
371
|
+
*
|
|
372
|
+
* // Get mainnet address
|
|
373
|
+
* const mainnetAddress = keyManager.getSubAddressBech32m({ account: 0, address: 0 }, 'mainnet');
|
|
374
|
+
*
|
|
375
|
+
* // Get testnet address
|
|
376
|
+
* const testnetAddress = keyManager.getSubAddressBech32m({ account: 0, address: 0 }, 'testnet');
|
|
377
|
+
* ```
|
|
378
|
+
*/
|
|
379
|
+
getSubAddressBech32m(id?: SubAddressIdentifier, network?: 'mainnet' | 'testnet'): string;
|
|
223
380
|
/**
|
|
224
381
|
* Generate a new sub-address for the given account
|
|
225
382
|
* @param account - The account number (0 for main, -1 for change, -2 for staking)
|
|
@@ -462,6 +619,7 @@ declare class KeyManager {
|
|
|
462
619
|
*/
|
|
463
620
|
private hash160;
|
|
464
621
|
private bytesToHex;
|
|
622
|
+
private hexToBytes;
|
|
465
623
|
/**
|
|
466
624
|
* Get the private spending key
|
|
467
625
|
* Replicates GetSpendingKey from keyman.cpp
|
|
@@ -837,6 +995,13 @@ declare class WalletDB {
|
|
|
837
995
|
* @returns The restored KeyManager instance
|
|
838
996
|
*/
|
|
839
997
|
restoreWallet(seedHex: string, creationHeight?: number): Promise<KeyManager>;
|
|
998
|
+
/**
|
|
999
|
+
* Restore wallet from mnemonic phrase
|
|
1000
|
+
* @param mnemonic - The BIP39 mnemonic phrase (12-24 words)
|
|
1001
|
+
* @param creationHeight - Optional block height to start scanning from (for faster restore)
|
|
1002
|
+
* @returns The restored KeyManager instance
|
|
1003
|
+
*/
|
|
1004
|
+
restoreWalletFromMnemonic(mnemonic: string, creationHeight?: number): Promise<KeyManager>;
|
|
840
1005
|
/**
|
|
841
1006
|
* Save wallet metadata to database
|
|
842
1007
|
*/
|
|
@@ -917,6 +1082,110 @@ declare class WalletDB {
|
|
|
917
1082
|
* @returns Array of all wallet outputs
|
|
918
1083
|
*/
|
|
919
1084
|
getAllOutputs(): Promise<WalletOutput[]>;
|
|
1085
|
+
/**
|
|
1086
|
+
* Check if the database has encryption enabled
|
|
1087
|
+
* @returns True if encryption is enabled
|
|
1088
|
+
*/
|
|
1089
|
+
isEncrypted(): boolean;
|
|
1090
|
+
/**
|
|
1091
|
+
* Save encryption metadata to the database
|
|
1092
|
+
* @param salt - Hex-encoded salt
|
|
1093
|
+
* @param verificationHash - Hex-encoded password verification hash
|
|
1094
|
+
*/
|
|
1095
|
+
saveEncryptionMetadata(salt: string, verificationHash: string): void;
|
|
1096
|
+
/**
|
|
1097
|
+
* Load encryption metadata from the database
|
|
1098
|
+
* @returns Encryption metadata or null if not encrypted
|
|
1099
|
+
*/
|
|
1100
|
+
getEncryptionMetadata(): {
|
|
1101
|
+
salt: string;
|
|
1102
|
+
verificationHash: string;
|
|
1103
|
+
} | null;
|
|
1104
|
+
/**
|
|
1105
|
+
* Save an encrypted key to the database
|
|
1106
|
+
* @param keyId - Key identifier (hex)
|
|
1107
|
+
* @param publicKey - Public key (hex)
|
|
1108
|
+
* @param encryptedSecret - Encrypted secret (JSON string)
|
|
1109
|
+
*/
|
|
1110
|
+
saveEncryptedKey(keyId: string, publicKey: string, encryptedSecret: string): void;
|
|
1111
|
+
/**
|
|
1112
|
+
* Load an encrypted key from the database
|
|
1113
|
+
* @param keyId - Key identifier (hex)
|
|
1114
|
+
* @returns Encrypted key data or null if not found
|
|
1115
|
+
*/
|
|
1116
|
+
getEncryptedKey(keyId: string): {
|
|
1117
|
+
publicKey: string;
|
|
1118
|
+
encryptedSecret: string;
|
|
1119
|
+
} | null;
|
|
1120
|
+
/**
|
|
1121
|
+
* Get all encrypted keys from the database
|
|
1122
|
+
* @returns Array of encrypted key data
|
|
1123
|
+
*/
|
|
1124
|
+
getAllEncryptedKeys(): Array<{
|
|
1125
|
+
keyId: string;
|
|
1126
|
+
publicKey: string;
|
|
1127
|
+
encryptedSecret: string;
|
|
1128
|
+
}>;
|
|
1129
|
+
/**
|
|
1130
|
+
* Save an encrypted output key to the database
|
|
1131
|
+
* @param outId - Output identifier (hex)
|
|
1132
|
+
* @param publicKey - Public key (hex)
|
|
1133
|
+
* @param encryptedSecret - Encrypted secret (JSON string)
|
|
1134
|
+
*/
|
|
1135
|
+
saveEncryptedOutKey(outId: string, publicKey: string, encryptedSecret: string): void;
|
|
1136
|
+
/**
|
|
1137
|
+
* Load an encrypted output key from the database
|
|
1138
|
+
* @param outId - Output identifier (hex)
|
|
1139
|
+
* @returns Encrypted output key data or null if not found
|
|
1140
|
+
*/
|
|
1141
|
+
getEncryptedOutKey(outId: string): {
|
|
1142
|
+
publicKey: string;
|
|
1143
|
+
encryptedSecret: string;
|
|
1144
|
+
} | null;
|
|
1145
|
+
/**
|
|
1146
|
+
* Get all encrypted output keys from the database
|
|
1147
|
+
* @returns Array of encrypted output key data
|
|
1148
|
+
*/
|
|
1149
|
+
getAllEncryptedOutKeys(): Array<{
|
|
1150
|
+
outId: string;
|
|
1151
|
+
publicKey: string;
|
|
1152
|
+
encryptedSecret: string;
|
|
1153
|
+
}>;
|
|
1154
|
+
/**
|
|
1155
|
+
* Delete plaintext keys (after encryption)
|
|
1156
|
+
* This removes the unencrypted keys from the database
|
|
1157
|
+
*/
|
|
1158
|
+
deletePlaintextKeys(): void;
|
|
1159
|
+
/**
|
|
1160
|
+
* Export the database as an encrypted binary blob
|
|
1161
|
+
* Uses the encryption module to encrypt the entire SQLite database
|
|
1162
|
+
*
|
|
1163
|
+
* @param password - Password to encrypt the export
|
|
1164
|
+
* @returns Encrypted database bytes
|
|
1165
|
+
*/
|
|
1166
|
+
exportEncrypted(password: string): Promise<Uint8Array>;
|
|
1167
|
+
/**
|
|
1168
|
+
* Load a database from an encrypted binary blob
|
|
1169
|
+
*
|
|
1170
|
+
* @param encryptedData - Encrypted database bytes
|
|
1171
|
+
* @param password - Password to decrypt
|
|
1172
|
+
* @param dbPath - Path for the new database instance
|
|
1173
|
+
* @returns New WalletDB instance with decrypted data
|
|
1174
|
+
*/
|
|
1175
|
+
static loadEncrypted(encryptedData: Uint8Array, password: string, dbPath?: string): Promise<WalletDB>;
|
|
1176
|
+
/**
|
|
1177
|
+
* Get the raw database bytes (unencrypted)
|
|
1178
|
+
* @returns Database bytes
|
|
1179
|
+
*/
|
|
1180
|
+
export(): Uint8Array;
|
|
1181
|
+
/**
|
|
1182
|
+
* Load a database from raw bytes
|
|
1183
|
+
*
|
|
1184
|
+
* @param data - Raw database bytes
|
|
1185
|
+
* @param dbPath - Path for the new database instance
|
|
1186
|
+
* @returns New WalletDB instance
|
|
1187
|
+
*/
|
|
1188
|
+
static loadFromBytes(data: Uint8Array, dbPath?: string): Promise<WalletDB>;
|
|
920
1189
|
}
|
|
921
1190
|
|
|
922
1191
|
/**
|
|
@@ -1947,8 +2216,10 @@ interface NavioClientConfig {
|
|
|
1947
2216
|
createWalletIfNotExists?: boolean;
|
|
1948
2217
|
/** Restore wallet from seed (hex string) */
|
|
1949
2218
|
restoreFromSeed?: string;
|
|
2219
|
+
/** Restore wallet from mnemonic phrase (24 words) */
|
|
2220
|
+
restoreFromMnemonic?: string;
|
|
1950
2221
|
/**
|
|
1951
|
-
* Block height to start scanning from when restoring a wallet from seed.
|
|
2222
|
+
* Block height to start scanning from when restoring a wallet from seed or mnemonic.
|
|
1952
2223
|
* This is the height when the wallet was originally created.
|
|
1953
2224
|
* Setting this avoids scanning blocks before the wallet existed.
|
|
1954
2225
|
*
|
|
@@ -2221,6 +2492,168 @@ type BlockHash = HexString;
|
|
|
2221
2492
|
*/
|
|
2222
2493
|
type OutputHash = HexString;
|
|
2223
2494
|
|
|
2495
|
+
/**
|
|
2496
|
+
* Wallet encryption module using Argon2id for key derivation and AES-256-GCM for encryption.
|
|
2497
|
+
*
|
|
2498
|
+
* This module provides secure password-based encryption for wallet data.
|
|
2499
|
+
*
|
|
2500
|
+
* @module crypto/encryption
|
|
2501
|
+
*/
|
|
2502
|
+
type WebCryptoKey = Awaited<ReturnType<SubtleCrypto['importKey']>>;
|
|
2503
|
+
/**
|
|
2504
|
+
* Encrypted data structure containing ciphertext and encryption parameters
|
|
2505
|
+
*/
|
|
2506
|
+
interface EncryptedData {
|
|
2507
|
+
/** The encrypted ciphertext (includes auth tag for GCM) */
|
|
2508
|
+
ciphertext: Uint8Array;
|
|
2509
|
+
/** Initialization vector (12 bytes for AES-GCM) */
|
|
2510
|
+
iv: Uint8Array;
|
|
2511
|
+
/** Salt used for Argon2 key derivation (16 bytes) */
|
|
2512
|
+
salt: Uint8Array;
|
|
2513
|
+
}
|
|
2514
|
+
/**
|
|
2515
|
+
* Serialized format for encrypted data (for storage)
|
|
2516
|
+
*/
|
|
2517
|
+
interface SerializedEncryptedData {
|
|
2518
|
+
/** Base64-encoded ciphertext */
|
|
2519
|
+
ciphertext: string;
|
|
2520
|
+
/** Base64-encoded IV */
|
|
2521
|
+
iv: string;
|
|
2522
|
+
/** Base64-encoded salt */
|
|
2523
|
+
salt: string;
|
|
2524
|
+
/** Encryption version for future compatibility */
|
|
2525
|
+
version: number;
|
|
2526
|
+
}
|
|
2527
|
+
/**
|
|
2528
|
+
* Current encryption version for forward compatibility
|
|
2529
|
+
*/
|
|
2530
|
+
declare const ENCRYPTION_VERSION = 1;
|
|
2531
|
+
/**
|
|
2532
|
+
* IV length for AES-GCM (96 bits / 12 bytes is recommended)
|
|
2533
|
+
*/
|
|
2534
|
+
declare const IV_LENGTH = 12;
|
|
2535
|
+
/**
|
|
2536
|
+
* Salt length for Argon2 (16 bytes is recommended minimum)
|
|
2537
|
+
*/
|
|
2538
|
+
declare const SALT_LENGTH = 16;
|
|
2539
|
+
/**
|
|
2540
|
+
* Generate cryptographically secure random bytes
|
|
2541
|
+
* @param length - Number of bytes to generate
|
|
2542
|
+
* @returns Random bytes
|
|
2543
|
+
*/
|
|
2544
|
+
declare function randomBytes(length: number): Uint8Array;
|
|
2545
|
+
/**
|
|
2546
|
+
* Derive an AES-256 encryption key from a password using Argon2id
|
|
2547
|
+
*
|
|
2548
|
+
* @param password - The user's password
|
|
2549
|
+
* @param salt - Random salt (16 bytes recommended)
|
|
2550
|
+
* @returns CryptoKey suitable for AES-256-GCM encryption
|
|
2551
|
+
*/
|
|
2552
|
+
declare function deriveKey(password: string, salt: Uint8Array): Promise<WebCryptoKey>;
|
|
2553
|
+
/**
|
|
2554
|
+
* Derive raw key bytes from a password using Argon2id
|
|
2555
|
+
* Useful for creating a password verification hash
|
|
2556
|
+
*
|
|
2557
|
+
* @param password - The user's password
|
|
2558
|
+
* @param salt - Random salt (16 bytes recommended)
|
|
2559
|
+
* @returns 32 bytes of derived key material
|
|
2560
|
+
*/
|
|
2561
|
+
declare function deriveKeyBytes(password: string, salt: Uint8Array): Promise<Uint8Array>;
|
|
2562
|
+
/**
|
|
2563
|
+
* Encrypt data using AES-256-GCM with a password
|
|
2564
|
+
*
|
|
2565
|
+
* @param data - The plaintext data to encrypt
|
|
2566
|
+
* @param password - The user's password
|
|
2567
|
+
* @returns Encrypted data with IV and salt
|
|
2568
|
+
*/
|
|
2569
|
+
declare function encrypt(data: Uint8Array, password: string): Promise<EncryptedData>;
|
|
2570
|
+
/**
|
|
2571
|
+
* Encrypt data using AES-256-GCM with a pre-derived CryptoKey
|
|
2572
|
+
* More efficient when encrypting multiple items with the same password
|
|
2573
|
+
*
|
|
2574
|
+
* @param data - The plaintext data to encrypt
|
|
2575
|
+
* @param key - Pre-derived CryptoKey
|
|
2576
|
+
* @param salt - Salt used to derive the key (for storage)
|
|
2577
|
+
* @returns Encrypted data with IV and salt
|
|
2578
|
+
*/
|
|
2579
|
+
declare function encryptWithKey(data: Uint8Array, key: WebCryptoKey, salt: Uint8Array): Promise<EncryptedData>;
|
|
2580
|
+
/**
|
|
2581
|
+
* Decrypt data using AES-256-GCM with a password
|
|
2582
|
+
*
|
|
2583
|
+
* @param encrypted - The encrypted data with IV and salt
|
|
2584
|
+
* @param password - The user's password
|
|
2585
|
+
* @returns Decrypted plaintext data
|
|
2586
|
+
* @throws Error if decryption fails (wrong password or corrupted data)
|
|
2587
|
+
*/
|
|
2588
|
+
declare function decrypt(encrypted: EncryptedData, password: string): Promise<Uint8Array>;
|
|
2589
|
+
/**
|
|
2590
|
+
* Decrypt data using AES-256-GCM with a pre-derived CryptoKey
|
|
2591
|
+
* More efficient when decrypting multiple items with the same password
|
|
2592
|
+
*
|
|
2593
|
+
* @param encrypted - The encrypted data with IV and salt
|
|
2594
|
+
* @param key - Pre-derived CryptoKey
|
|
2595
|
+
* @returns Decrypted plaintext data
|
|
2596
|
+
* @throws Error if decryption fails (wrong key or corrupted data)
|
|
2597
|
+
*/
|
|
2598
|
+
declare function decryptWithKey(encrypted: EncryptedData, key: WebCryptoKey): Promise<Uint8Array>;
|
|
2599
|
+
/**
|
|
2600
|
+
* Serialize encrypted data for storage (converts to base64 strings)
|
|
2601
|
+
*
|
|
2602
|
+
* @param encrypted - Encrypted data to serialize
|
|
2603
|
+
* @returns Serialized format suitable for JSON storage
|
|
2604
|
+
*/
|
|
2605
|
+
declare function serializeEncryptedData(encrypted: EncryptedData): SerializedEncryptedData;
|
|
2606
|
+
/**
|
|
2607
|
+
* Deserialize encrypted data from storage
|
|
2608
|
+
*
|
|
2609
|
+
* @param serialized - Serialized encrypted data
|
|
2610
|
+
* @returns Encrypted data ready for decryption
|
|
2611
|
+
* @throws Error if version is unsupported
|
|
2612
|
+
*/
|
|
2613
|
+
declare function deserializeEncryptedData(serialized: SerializedEncryptedData): EncryptedData;
|
|
2614
|
+
/**
|
|
2615
|
+
* Encrypt an entire database buffer
|
|
2616
|
+
*
|
|
2617
|
+
* @param dbBuffer - Raw database file bytes
|
|
2618
|
+
* @param password - The user's password
|
|
2619
|
+
* @returns Encrypted database buffer with header
|
|
2620
|
+
*/
|
|
2621
|
+
declare function encryptDatabase(dbBuffer: Uint8Array, password: string): Promise<Uint8Array>;
|
|
2622
|
+
/**
|
|
2623
|
+
* Decrypt an entire database buffer
|
|
2624
|
+
*
|
|
2625
|
+
* @param encryptedBuffer - Encrypted database buffer with header
|
|
2626
|
+
* @param password - The user's password
|
|
2627
|
+
* @returns Decrypted database file bytes
|
|
2628
|
+
* @throws Error if decryption fails
|
|
2629
|
+
*/
|
|
2630
|
+
declare function decryptDatabase(encryptedBuffer: Uint8Array, password: string): Promise<Uint8Array>;
|
|
2631
|
+
/**
|
|
2632
|
+
* Check if a buffer appears to be an encrypted database
|
|
2633
|
+
*
|
|
2634
|
+
* @param buffer - Buffer to check
|
|
2635
|
+
* @returns True if buffer starts with valid encryption header
|
|
2636
|
+
*/
|
|
2637
|
+
declare function isEncryptedDatabase(buffer: Uint8Array): boolean;
|
|
2638
|
+
/**
|
|
2639
|
+
* Create a password verification hash
|
|
2640
|
+
* This is stored to verify the password is correct before attempting decryption
|
|
2641
|
+
*
|
|
2642
|
+
* @param password - The user's password
|
|
2643
|
+
* @param salt - Salt to use (same as encryption salt)
|
|
2644
|
+
* @returns Verification hash (32 bytes)
|
|
2645
|
+
*/
|
|
2646
|
+
declare function createPasswordVerification(password: string, salt: Uint8Array): Promise<Uint8Array>;
|
|
2647
|
+
/**
|
|
2648
|
+
* Verify a password against a stored verification hash
|
|
2649
|
+
*
|
|
2650
|
+
* @param password - Password to verify
|
|
2651
|
+
* @param salt - Salt used for key derivation
|
|
2652
|
+
* @param storedHash - Previously stored verification hash
|
|
2653
|
+
* @returns True if password is correct
|
|
2654
|
+
*/
|
|
2655
|
+
declare function verifyPassword(password: string, salt: Uint8Array, storedHash: Uint8Array): Promise<boolean>;
|
|
2656
|
+
|
|
2224
2657
|
/**
|
|
2225
2658
|
* Electrum Sync Provider
|
|
2226
2659
|
*
|
|
@@ -2497,4 +2930,4 @@ declare class P2PSyncProvider extends BaseSyncProvider {
|
|
|
2497
2930
|
private decodeVarInt;
|
|
2498
2931
|
}
|
|
2499
2932
|
|
|
2500
|
-
export { type AmountRecoveryResult, type BackendType, type BackgroundSyncOptions, BaseSyncProvider, type BlockHash, type BlockHeader, type BlockHeadersResult, type BlockLocator, type BlockTransactionKeys, type BlockTransactionKeysRange, type CTxDestination, type CTxOut, type CTxOutBLSCTData, type ChainTip, DefaultPorts, ElectrumClient, ElectrumError, type ElectrumOptions, type ElectrumSyncOptions, ElectrumSyncProvider, type HDChain, type HexString, InvType, type InvVector, KeyManager, type KeyStorage, type MessageHeader, MessageType, NavioClient, type NavioClientConfig, type NavioNetwork, NetworkMagic, type NetworkType, type OutputHash, P2PClient, type P2PConnectionOptions, type P2PMessage, type P2POptions, type P2PSyncOptions, P2PSyncProvider, PROTOCOL_VERSION, type PublicKey$1 as PublicKey, type ReorganizationInfo, type SecretKey, type SeedType, ServiceFlags, type SubAddress, type SubAddressIdentifier, type SyncBlockHeader, type SyncOptions, type SyncProgressCallback, type SyncProvider, type SyncProviderOptions, type SyncState, type TransactionKeys, TransactionKeysSync, type TxHash, type VersionPayload, WalletDB, type WalletOutput };
|
|
2933
|
+
export { type AmountRecoveryResult, type BackendType, type BackgroundSyncOptions, BaseSyncProvider, type BlockHash, type BlockHeader, type BlockHeadersResult, type BlockLocator, type BlockTransactionKeys, type BlockTransactionKeysRange, type CTxDestination, type CTxOut, type CTxOutBLSCTData, type ChainTip, DefaultPorts, ENCRYPTION_VERSION, ElectrumClient, ElectrumError, type ElectrumOptions, type ElectrumSyncOptions, ElectrumSyncProvider, type EncryptedData, type HDChain, type HexString, IV_LENGTH, InvType, type InvVector, KeyManager, type KeyStorage, type MessageHeader, MessageType, NavioClient, type NavioClientConfig, type NavioNetwork, NetworkMagic, type NetworkType, type OutputHash, P2PClient, type P2PConnectionOptions, type P2PMessage, type P2POptions, type P2PSyncOptions, P2PSyncProvider, PROTOCOL_VERSION, type PublicKey$1 as PublicKey, type ReorganizationInfo, SALT_LENGTH, type SecretKey, type SeedType, type SerializedEncryptedData, ServiceFlags, type SubAddress, type SubAddressIdentifier, type SyncBlockHeader, type SyncOptions, type SyncProgressCallback, type SyncProvider, type SyncProviderOptions, type SyncState, type TransactionKeys, TransactionKeysSync, type TxHash, type VersionPayload, WalletDB, type WalletOutput, createPasswordVerification, decrypt, decryptDatabase, decryptWithKey, deriveKey, deriveKeyBytes, deserializeEncryptedData, encrypt, encryptDatabase, encryptWithKey, isEncryptedDatabase, randomBytes, serializeEncryptedData, verifyPassword };
|