navio-sdk 0.1.2 → 0.1.4
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/index.d.mts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +44 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +44 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -4
package/dist/index.d.mts
CHANGED
|
@@ -208,7 +208,7 @@ declare class KeyManager {
|
|
|
208
208
|
*/
|
|
209
209
|
unlock(password: string): Promise<boolean>;
|
|
210
210
|
/**
|
|
211
|
-
* Lock the wallet, clearing the cached encryption key
|
|
211
|
+
* Lock the wallet, clearing the cached encryption key and unencrypted keys
|
|
212
212
|
* After locking, private keys cannot be accessed without unlocking again
|
|
213
213
|
*/
|
|
214
214
|
lock(): void;
|
|
@@ -235,6 +235,16 @@ declare class KeyManager {
|
|
|
235
235
|
* @param verificationHash - Hex-encoded verification hash
|
|
236
236
|
*/
|
|
237
237
|
setEncryptionParams(salt: string, verificationHash: string): void;
|
|
238
|
+
/**
|
|
239
|
+
* Get key storage statistics (for testing/debugging)
|
|
240
|
+
* @returns Object with counts of plain and encrypted keys
|
|
241
|
+
*/
|
|
242
|
+
getKeyStats(): {
|
|
243
|
+
plainKeys: number;
|
|
244
|
+
plainOutKeys: number;
|
|
245
|
+
encryptedKeys: number;
|
|
246
|
+
encryptedOutKeys: number;
|
|
247
|
+
};
|
|
238
248
|
/**
|
|
239
249
|
* Encrypt all private keys in the wallet
|
|
240
250
|
* Internal method called when setting password
|
package/dist/index.d.ts
CHANGED
|
@@ -208,7 +208,7 @@ declare class KeyManager {
|
|
|
208
208
|
*/
|
|
209
209
|
unlock(password: string): Promise<boolean>;
|
|
210
210
|
/**
|
|
211
|
-
* Lock the wallet, clearing the cached encryption key
|
|
211
|
+
* Lock the wallet, clearing the cached encryption key and unencrypted keys
|
|
212
212
|
* After locking, private keys cannot be accessed without unlocking again
|
|
213
213
|
*/
|
|
214
214
|
lock(): void;
|
|
@@ -235,6 +235,16 @@ declare class KeyManager {
|
|
|
235
235
|
* @param verificationHash - Hex-encoded verification hash
|
|
236
236
|
*/
|
|
237
237
|
setEncryptionParams(salt: string, verificationHash: string): void;
|
|
238
|
+
/**
|
|
239
|
+
* Get key storage statistics (for testing/debugging)
|
|
240
|
+
* @returns Object with counts of plain and encrypted keys
|
|
241
|
+
*/
|
|
242
|
+
getKeyStats(): {
|
|
243
|
+
plainKeys: number;
|
|
244
|
+
plainOutKeys: number;
|
|
245
|
+
encryptedKeys: number;
|
|
246
|
+
encryptedOutKeys: number;
|
|
247
|
+
};
|
|
238
248
|
/**
|
|
239
249
|
* Encrypt all private keys in the wallet
|
|
240
250
|
* Internal method called when setting password
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var hashWasm = require('hash-wasm');
|
|
4
4
|
var sha256 = require('@noble/hashes/sha256');
|
|
5
5
|
var ripemd160 = require('@noble/hashes/ripemd160');
|
|
6
6
|
var bip39 = require('@scure/bip39');
|
|
@@ -8,8 +8,6 @@ var english_js = require('@scure/bip39/wordlists/english.js');
|
|
|
8
8
|
var blsctModule = require('navio-blsct');
|
|
9
9
|
var net = require('net');
|
|
10
10
|
|
|
11
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
-
|
|
13
11
|
function _interopNamespace(e) {
|
|
14
12
|
if (e && e.__esModule) return e;
|
|
15
13
|
var n = Object.create(null);
|
|
@@ -28,7 +26,6 @@ function _interopNamespace(e) {
|
|
|
28
26
|
return Object.freeze(n);
|
|
29
27
|
}
|
|
30
28
|
|
|
31
|
-
var argon2__default = /*#__PURE__*/_interopDefault(argon2);
|
|
32
29
|
var bip39__namespace = /*#__PURE__*/_interopNamespace(bip39);
|
|
33
30
|
var blsctModule__namespace = /*#__PURE__*/_interopNamespace(blsctModule);
|
|
34
31
|
var net__namespace = /*#__PURE__*/_interopNamespace(net);
|
|
@@ -68,19 +65,20 @@ function randomBytes(length) {
|
|
|
68
65
|
return bytes;
|
|
69
66
|
}
|
|
70
67
|
async function deriveKey(password, salt) {
|
|
71
|
-
const
|
|
72
|
-
|
|
68
|
+
const hashHex = await hashWasm.argon2id({
|
|
69
|
+
password,
|
|
73
70
|
salt,
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
time: ARGON2_PARAMS.iterations,
|
|
71
|
+
memorySize: ARGON2_PARAMS.memorySize,
|
|
72
|
+
iterations: ARGON2_PARAMS.iterations,
|
|
77
73
|
parallelism: ARGON2_PARAMS.parallelism,
|
|
78
|
-
|
|
74
|
+
hashLength: ARGON2_PARAMS.hashLength,
|
|
75
|
+
outputType: "hex"
|
|
79
76
|
});
|
|
77
|
+
const hashBytes = hexToBytes(hashHex);
|
|
80
78
|
const crypto = getCrypto();
|
|
81
79
|
const key = await crypto.subtle.importKey(
|
|
82
80
|
"raw",
|
|
83
|
-
toBufferSource(
|
|
81
|
+
toBufferSource(hashBytes),
|
|
84
82
|
{ name: "AES-GCM", length: 256 },
|
|
85
83
|
false,
|
|
86
84
|
// not extractable
|
|
@@ -89,16 +87,16 @@ async function deriveKey(password, salt) {
|
|
|
89
87
|
return key;
|
|
90
88
|
}
|
|
91
89
|
async function deriveKeyBytes(password, salt) {
|
|
92
|
-
const
|
|
93
|
-
|
|
90
|
+
const hashHex = await hashWasm.argon2id({
|
|
91
|
+
password,
|
|
94
92
|
salt,
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
time: ARGON2_PARAMS.iterations,
|
|
93
|
+
memorySize: ARGON2_PARAMS.memorySize,
|
|
94
|
+
iterations: ARGON2_PARAMS.iterations,
|
|
98
95
|
parallelism: ARGON2_PARAMS.parallelism,
|
|
99
|
-
|
|
96
|
+
hashLength: ARGON2_PARAMS.hashLength,
|
|
97
|
+
outputType: "hex"
|
|
100
98
|
});
|
|
101
|
-
return
|
|
99
|
+
return hexToBytes(hashHex);
|
|
102
100
|
}
|
|
103
101
|
async function encrypt(data, password) {
|
|
104
102
|
const crypto = getCrypto();
|
|
@@ -222,6 +220,13 @@ async function verifyPassword(password, salt, storedHash) {
|
|
|
222
220
|
}
|
|
223
221
|
return result === 0;
|
|
224
222
|
}
|
|
223
|
+
function hexToBytes(hex) {
|
|
224
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
225
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
226
|
+
bytes[i] = parseInt(hex.substr(i * 2, 2), 16);
|
|
227
|
+
}
|
|
228
|
+
return bytes;
|
|
229
|
+
}
|
|
225
230
|
function bytesToBase64(bytes) {
|
|
226
231
|
if (typeof Buffer !== "undefined") {
|
|
227
232
|
return Buffer.from(bytes).toString("base64");
|
|
@@ -249,13 +254,12 @@ var ARGON2_PARAMS; exports.ENCRYPTION_VERSION = void 0; exports.IV_LENGTH = void
|
|
|
249
254
|
var init_encryption = __esm({
|
|
250
255
|
"src/crypto/encryption.ts"() {
|
|
251
256
|
ARGON2_PARAMS = {
|
|
252
|
-
|
|
253
|
-
memory
|
|
254
|
-
// 64 MB
|
|
257
|
+
memorySize: 65536,
|
|
258
|
+
// 64 MB (hash-wasm uses memorySize instead of memory)
|
|
255
259
|
iterations: 3,
|
|
256
260
|
parallelism: 4,
|
|
257
|
-
|
|
258
|
-
// 256 bits for AES-256
|
|
261
|
+
hashLength: 32
|
|
262
|
+
// 256 bits for AES-256 (hash-wasm uses hashLength instead of hashLen)
|
|
259
263
|
};
|
|
260
264
|
exports.ENCRYPTION_VERSION = 1;
|
|
261
265
|
exports.IV_LENGTH = 12;
|
|
@@ -425,7 +429,7 @@ var KeyManager = class _KeyManager {
|
|
|
425
429
|
return true;
|
|
426
430
|
}
|
|
427
431
|
/**
|
|
428
|
-
* Lock the wallet, clearing the cached encryption key
|
|
432
|
+
* Lock the wallet, clearing the cached encryption key and unencrypted keys
|
|
429
433
|
* After locking, private keys cannot be accessed without unlocking again
|
|
430
434
|
*/
|
|
431
435
|
lock() {
|
|
@@ -433,6 +437,8 @@ var KeyManager = class _KeyManager {
|
|
|
433
437
|
return;
|
|
434
438
|
}
|
|
435
439
|
this.encryptionKey = null;
|
|
440
|
+
this.keys.clear();
|
|
441
|
+
this.outKeys.clear();
|
|
436
442
|
}
|
|
437
443
|
/**
|
|
438
444
|
* Change the wallet password
|
|
@@ -481,6 +487,18 @@ var KeyManager = class _KeyManager {
|
|
|
481
487
|
this.passwordVerificationHash = this.hexToBytes(verificationHash);
|
|
482
488
|
this.encrypted = true;
|
|
483
489
|
}
|
|
490
|
+
/**
|
|
491
|
+
* Get key storage statistics (for testing/debugging)
|
|
492
|
+
* @returns Object with counts of plain and encrypted keys
|
|
493
|
+
*/
|
|
494
|
+
getKeyStats() {
|
|
495
|
+
return {
|
|
496
|
+
plainKeys: this.keys.size,
|
|
497
|
+
plainOutKeys: this.outKeys.size,
|
|
498
|
+
encryptedKeys: this.cryptedKeys.size,
|
|
499
|
+
encryptedOutKeys: this.cryptedOutKeys.size
|
|
500
|
+
};
|
|
501
|
+
}
|
|
484
502
|
/**
|
|
485
503
|
* Encrypt all private keys in the wallet
|
|
486
504
|
* Internal method called when setting password
|
|
@@ -507,6 +525,8 @@ var KeyManager = class _KeyManager {
|
|
|
507
525
|
encryptedSecret: this.serializeEncryptedToBytes(encrypted)
|
|
508
526
|
});
|
|
509
527
|
}
|
|
528
|
+
this.keys.clear();
|
|
529
|
+
this.outKeys.clear();
|
|
510
530
|
}
|
|
511
531
|
/**
|
|
512
532
|
* Decrypt essential keys needed for wallet operations
|