@twin.org/crypto 0.0.2-next.19 → 0.0.2-next.21
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/index.cjs +124 -143
- package/dist/esm/index.mjs +124 -143
- package/dist/types/address/bech32.d.ts +4 -0
- package/dist/types/address/bip44.d.ts +4 -0
- package/dist/types/ciphers/chaCha20Poly1305.d.ts +4 -0
- package/dist/types/curves/ed25519.d.ts +4 -0
- package/dist/types/curves/secp256k1.d.ts +4 -0
- package/dist/types/curves/x25519.d.ts +4 -0
- package/dist/types/curves/zip215.d.ts +4 -0
- package/dist/types/hashes/blake2b.d.ts +4 -0
- package/dist/types/hashes/blake3.d.ts +4 -0
- package/dist/types/hashes/hmacSha1.d.ts +4 -0
- package/dist/types/hashes/hmacSha256.d.ts +4 -0
- package/dist/types/hashes/hmacSha512.d.ts +4 -0
- package/dist/types/hashes/pbkdf2.d.ts +4 -0
- package/dist/types/hashes/sha1.d.ts +4 -0
- package/dist/types/hashes/sha256.d.ts +4 -0
- package/dist/types/hashes/sha3.d.ts +4 -0
- package/dist/types/hashes/sha512.d.ts +4 -0
- package/dist/types/helpers/pemHelper.d.ts +4 -0
- package/dist/types/keys/bip39.d.ts +4 -0
- package/dist/types/keys/slip0010.d.ts +4 -0
- package/dist/types/otp/hotp.d.ts +4 -0
- package/docs/changelog.md +37 -0
- package/docs/reference/classes/Bech32.md +8 -0
- package/docs/reference/classes/Bip39.md +8 -0
- package/docs/reference/classes/Bip44.md +8 -0
- package/docs/reference/classes/Blake2b.md +8 -0
- package/docs/reference/classes/Blake3.md +8 -0
- package/docs/reference/classes/ChaCha20Poly1305.md +8 -0
- package/docs/reference/classes/Ed25519.md +8 -0
- package/docs/reference/classes/HmacSha1.md +8 -0
- package/docs/reference/classes/HmacSha256.md +8 -0
- package/docs/reference/classes/HmacSha512.md +8 -0
- package/docs/reference/classes/Hotp.md +8 -0
- package/docs/reference/classes/Pbkdf2.md +8 -0
- package/docs/reference/classes/PemHelper.md +8 -0
- package/docs/reference/classes/Secp256k1.md +8 -0
- package/docs/reference/classes/Sha1.md +8 -0
- package/docs/reference/classes/Sha256.md +8 -0
- package/docs/reference/classes/Sha3.md +8 -0
- package/docs/reference/classes/Sha512.md +8 -0
- package/docs/reference/classes/Slip0010.md +8 -0
- package/docs/reference/classes/X25519.md +8 -0
- package/docs/reference/classes/Zip215.md +8 -0
- package/locales/en.json +9 -28
- package/package.json +19 -4
package/dist/cjs/index.cjs
CHANGED
|
@@ -46,9 +46,8 @@ var otp__namespace = /*#__PURE__*/_interopNamespaceDefault(otp);
|
|
|
46
46
|
class Bech32 {
|
|
47
47
|
/**
|
|
48
48
|
* Runtime name for the class.
|
|
49
|
-
* @internal
|
|
50
49
|
*/
|
|
51
|
-
static
|
|
50
|
+
static CLASS_NAME = "Bech32";
|
|
52
51
|
/**
|
|
53
52
|
* Encode the buffer.
|
|
54
53
|
* @param humanReadablePart The header.
|
|
@@ -56,8 +55,8 @@ class Bech32 {
|
|
|
56
55
|
* @returns The encoded data.
|
|
57
56
|
*/
|
|
58
57
|
static encode(humanReadablePart, data) {
|
|
59
|
-
core.Guards.stringValue(Bech32.
|
|
60
|
-
core.Guards.uint8Array(Bech32.
|
|
58
|
+
core.Guards.stringValue(Bech32.CLASS_NAME, "humanReadablePart", humanReadablePart);
|
|
59
|
+
core.Guards.uint8Array(Bech32.CLASS_NAME, "data", data);
|
|
61
60
|
return base.bech32.encode(humanReadablePart, base.bech32.toWords(data));
|
|
62
61
|
}
|
|
63
62
|
/**
|
|
@@ -67,7 +66,7 @@ class Bech32 {
|
|
|
67
66
|
* @throws An error if the decoding fails.
|
|
68
67
|
*/
|
|
69
68
|
static decode(bech) {
|
|
70
|
-
core.Guards.stringValue(Bech32.
|
|
69
|
+
core.Guards.stringValue(Bech32.CLASS_NAME, "bech", bech);
|
|
71
70
|
try {
|
|
72
71
|
const result = base.bech32.decodeToBytes(bech);
|
|
73
72
|
return {
|
|
@@ -77,19 +76,19 @@ class Bech32 {
|
|
|
77
76
|
}
|
|
78
77
|
catch (err) {
|
|
79
78
|
if (core.BaseError.isErrorMessage(err, /checksum/)) {
|
|
80
|
-
throw new core.GeneralError(Bech32.
|
|
79
|
+
throw new core.GeneralError(Bech32.CLASS_NAME, "invalidChecksum", { bech32: base.bech32 });
|
|
81
80
|
}
|
|
82
81
|
else if (core.BaseError.isErrorMessage(err, /between prefix and data only/i)) {
|
|
83
|
-
throw new core.GeneralError(Bech32.
|
|
82
|
+
throw new core.GeneralError(Bech32.CLASS_NAME, "separatorMisused", { bech32: base.bech32 });
|
|
84
83
|
}
|
|
85
84
|
else if (core.BaseError.isErrorMessage(err, /lowercase or uppercase/i)) {
|
|
86
|
-
throw new core.GeneralError(Bech32.
|
|
85
|
+
throw new core.GeneralError(Bech32.CLASS_NAME, "lowerUpper", { bech32: base.bech32 });
|
|
87
86
|
}
|
|
88
87
|
else if (core.BaseError.isErrorMessage(err, /must be at least/i) ||
|
|
89
88
|
core.BaseError.isErrorMessage(err, /wrong string length/i)) {
|
|
90
|
-
throw new core.GeneralError(Bech32.
|
|
89
|
+
throw new core.GeneralError(Bech32.CLASS_NAME, "dataTooShort", { bech32: base.bech32 });
|
|
91
90
|
}
|
|
92
|
-
throw new core.GeneralError(Bech32.
|
|
91
|
+
throw new core.GeneralError(Bech32.CLASS_NAME, "decodeFailed", { bech32: base.bech32 }, err);
|
|
93
92
|
}
|
|
94
93
|
}
|
|
95
94
|
/**
|
|
@@ -125,9 +124,8 @@ class Ed25519 {
|
|
|
125
124
|
static PUBLIC_KEY_SIZE = 32;
|
|
126
125
|
/**
|
|
127
126
|
* Runtime name for the class.
|
|
128
|
-
* @internal
|
|
129
127
|
*/
|
|
130
|
-
static
|
|
128
|
+
static CLASS_NAME = "Ed25519";
|
|
131
129
|
/**
|
|
132
130
|
* Public returns the PublicKey corresponding to private.
|
|
133
131
|
* @param privateKey The private key to get the corresponding public key.
|
|
@@ -135,9 +133,9 @@ class Ed25519 {
|
|
|
135
133
|
* @throws Error if the private key is not the correct length.
|
|
136
134
|
*/
|
|
137
135
|
static publicKeyFromPrivateKey(privateKey) {
|
|
138
|
-
core.Guards.uint8Array(Ed25519.
|
|
136
|
+
core.Guards.uint8Array(Ed25519.CLASS_NAME, "privateKey", privateKey);
|
|
139
137
|
if (privateKey.length !== Ed25519.PRIVATE_KEY_SIZE) {
|
|
140
|
-
throw new core.GeneralError(Ed25519.
|
|
138
|
+
throw new core.GeneralError(Ed25519.CLASS_NAME, "privateKeyLength", {
|
|
141
139
|
requiredSize: Ed25519.PRIVATE_KEY_SIZE,
|
|
142
140
|
actualSize: privateKey.length
|
|
143
141
|
});
|
|
@@ -152,10 +150,10 @@ class Ed25519 {
|
|
|
152
150
|
* @throws Error if the private key is not the correct length.
|
|
153
151
|
*/
|
|
154
152
|
static sign(privateKey, block) {
|
|
155
|
-
core.Guards.uint8Array(Ed25519.
|
|
156
|
-
core.Guards.uint8Array(Ed25519.
|
|
153
|
+
core.Guards.uint8Array(Ed25519.CLASS_NAME, "privateKey", privateKey);
|
|
154
|
+
core.Guards.uint8Array(Ed25519.CLASS_NAME, "block", block);
|
|
157
155
|
if (privateKey.length !== Ed25519.PRIVATE_KEY_SIZE) {
|
|
158
|
-
throw new core.GeneralError(Ed25519.
|
|
156
|
+
throw new core.GeneralError(Ed25519.CLASS_NAME, "privateKeyLength", {
|
|
159
157
|
requiredSize: Ed25519.PRIVATE_KEY_SIZE,
|
|
160
158
|
actualSize: privateKey ? privateKey.length : 0
|
|
161
159
|
});
|
|
@@ -171,11 +169,11 @@ class Ed25519 {
|
|
|
171
169
|
* @throws Error if the public key is not the correct length.
|
|
172
170
|
*/
|
|
173
171
|
static verify(publicKey, block, signature) {
|
|
174
|
-
core.Guards.uint8Array(Ed25519.
|
|
175
|
-
core.Guards.uint8Array(Ed25519.
|
|
176
|
-
core.Guards.uint8Array(Ed25519.
|
|
172
|
+
core.Guards.uint8Array(Ed25519.CLASS_NAME, "publicKey", publicKey);
|
|
173
|
+
core.Guards.uint8Array(Ed25519.CLASS_NAME, "block", block);
|
|
174
|
+
core.Guards.uint8Array(Ed25519.CLASS_NAME, "signature", signature);
|
|
177
175
|
if (publicKey.length !== Ed25519.PUBLIC_KEY_SIZE) {
|
|
178
|
-
throw new core.GeneralError(Ed25519.
|
|
176
|
+
throw new core.GeneralError(Ed25519.CLASS_NAME, "publicKeyLength", {
|
|
179
177
|
requiredSize: Ed25519.PUBLIC_KEY_SIZE,
|
|
180
178
|
actualSize: publicKey ? publicKey.length : 0
|
|
181
179
|
});
|
|
@@ -193,9 +191,9 @@ class Ed25519 {
|
|
|
193
191
|
* @returns The private key in PKCS8 format.
|
|
194
192
|
*/
|
|
195
193
|
static async privateKeyToPkcs8(privateKey) {
|
|
196
|
-
core.Guards.uint8Array(Ed25519.
|
|
194
|
+
core.Guards.uint8Array(Ed25519.CLASS_NAME, "privateKey", privateKey);
|
|
197
195
|
if (privateKey.length !== Ed25519.PRIVATE_KEY_SIZE) {
|
|
198
|
-
throw new core.GeneralError(Ed25519.
|
|
196
|
+
throw new core.GeneralError(Ed25519.CLASS_NAME, "privateKeyLength", {
|
|
199
197
|
requiredSize: Ed25519.PRIVATE_KEY_SIZE,
|
|
200
198
|
actualSize: privateKey.length
|
|
201
199
|
});
|
|
@@ -214,7 +212,7 @@ class Ed25519 {
|
|
|
214
212
|
* @returns The raw private key.
|
|
215
213
|
*/
|
|
216
214
|
static async pkcs8ToPrivateKey(cryptoKey) {
|
|
217
|
-
core.Guards.defined(Ed25519.
|
|
215
|
+
core.Guards.defined(Ed25519.CLASS_NAME, "cryptoKey", cryptoKey);
|
|
218
216
|
// crypto.subtle.exportKey does not support Ed25519 keys in raw format.
|
|
219
217
|
// so we export as PKCS8 and remove the ASN.1 sequence prefix.
|
|
220
218
|
const pkcs8Bytes = await crypto.subtle.exportKey("pkcs8", cryptoKey);
|
|
@@ -238,9 +236,8 @@ class Secp256k1 {
|
|
|
238
236
|
static PUBLIC_KEY_SIZE = 33;
|
|
239
237
|
/**
|
|
240
238
|
* Runtime name for the class.
|
|
241
|
-
* @internal
|
|
242
239
|
*/
|
|
243
|
-
static
|
|
240
|
+
static CLASS_NAME = "Secp256k1";
|
|
244
241
|
/**
|
|
245
242
|
* Public returns the PublicKey corresponding to private.
|
|
246
243
|
* @param privateKey The private key to get the corresponding public key.
|
|
@@ -248,9 +245,9 @@ class Secp256k1 {
|
|
|
248
245
|
* @throws Error if the private key is not the correct length.
|
|
249
246
|
*/
|
|
250
247
|
static publicKeyFromPrivateKey(privateKey) {
|
|
251
|
-
core.Guards.uint8Array(Secp256k1.
|
|
248
|
+
core.Guards.uint8Array(Secp256k1.CLASS_NAME, "privateKey", privateKey);
|
|
252
249
|
if (privateKey.length !== Secp256k1.PRIVATE_KEY_SIZE) {
|
|
253
|
-
throw new core.GeneralError(Secp256k1.
|
|
250
|
+
throw new core.GeneralError(Secp256k1.CLASS_NAME, "privateKeyLength", {
|
|
254
251
|
requiredSize: Secp256k1.PRIVATE_KEY_SIZE,
|
|
255
252
|
actualSize: privateKey.length
|
|
256
253
|
});
|
|
@@ -265,10 +262,10 @@ class Secp256k1 {
|
|
|
265
262
|
* @throws Error if the private key is not the correct length.
|
|
266
263
|
*/
|
|
267
264
|
static sign(privateKey, block) {
|
|
268
|
-
core.Guards.uint8Array(Secp256k1.
|
|
269
|
-
core.Guards.uint8Array(Secp256k1.
|
|
265
|
+
core.Guards.uint8Array(Secp256k1.CLASS_NAME, "privateKey", privateKey);
|
|
266
|
+
core.Guards.uint8Array(Secp256k1.CLASS_NAME, "block", block);
|
|
270
267
|
if (privateKey.length !== Secp256k1.PRIVATE_KEY_SIZE) {
|
|
271
|
-
throw new core.GeneralError(Secp256k1.
|
|
268
|
+
throw new core.GeneralError(Secp256k1.CLASS_NAME, "privateKeyLength", {
|
|
272
269
|
requiredSize: Secp256k1.PRIVATE_KEY_SIZE,
|
|
273
270
|
actualSize: privateKey.length
|
|
274
271
|
});
|
|
@@ -285,11 +282,11 @@ class Secp256k1 {
|
|
|
285
282
|
* @throws Error if the public key is not the correct length.
|
|
286
283
|
*/
|
|
287
284
|
static verify(publicKey, block, signature) {
|
|
288
|
-
core.Guards.uint8Array(Secp256k1.
|
|
289
|
-
core.Guards.uint8Array(Secp256k1.
|
|
290
|
-
core.Guards.uint8Array(Secp256k1.
|
|
285
|
+
core.Guards.uint8Array(Secp256k1.CLASS_NAME, "publicKey", publicKey);
|
|
286
|
+
core.Guards.uint8Array(Secp256k1.CLASS_NAME, "block", block);
|
|
287
|
+
core.Guards.uint8Array(Secp256k1.CLASS_NAME, "signature", signature);
|
|
291
288
|
if (publicKey.length !== Secp256k1.PUBLIC_KEY_SIZE) {
|
|
292
|
-
throw new core.GeneralError(Secp256k1.
|
|
289
|
+
throw new core.GeneralError(Secp256k1.CLASS_NAME, "publicKeyLength", {
|
|
293
290
|
requiredSize: Secp256k1.PUBLIC_KEY_SIZE,
|
|
294
291
|
actualSize: publicKey ? publicKey.length : 0
|
|
295
292
|
});
|
|
@@ -323,9 +320,8 @@ class Blake2b {
|
|
|
323
320
|
static SIZE_512 = 64;
|
|
324
321
|
/**
|
|
325
322
|
* Runtime name for the class.
|
|
326
|
-
* @internal
|
|
327
323
|
*/
|
|
328
|
-
static
|
|
324
|
+
static CLASS_NAME = "Blake2b";
|
|
329
325
|
/**
|
|
330
326
|
* The instance of the hash.
|
|
331
327
|
* @internal
|
|
@@ -350,7 +346,7 @@ class Blake2b {
|
|
|
350
346
|
* @returns The sum 160 of the block.
|
|
351
347
|
*/
|
|
352
348
|
static sum160(block, key) {
|
|
353
|
-
core.Guards.uint8Array(Blake2b.
|
|
349
|
+
core.Guards.uint8Array(Blake2b.CLASS_NAME, "block", block);
|
|
354
350
|
return new Blake2b(Blake2b.SIZE_160, key).update(block).digest();
|
|
355
351
|
}
|
|
356
352
|
/**
|
|
@@ -360,7 +356,7 @@ class Blake2b {
|
|
|
360
356
|
* @returns The sum 256 of the block.
|
|
361
357
|
*/
|
|
362
358
|
static sum256(block, key) {
|
|
363
|
-
core.Guards.uint8Array(Blake2b.
|
|
359
|
+
core.Guards.uint8Array(Blake2b.CLASS_NAME, "block", block);
|
|
364
360
|
return new Blake2b(Blake2b.SIZE_256, key).update(block).digest();
|
|
365
361
|
}
|
|
366
362
|
/**
|
|
@@ -370,7 +366,7 @@ class Blake2b {
|
|
|
370
366
|
* @returns The sum 512 of the block.
|
|
371
367
|
*/
|
|
372
368
|
static sum512(block, key) {
|
|
373
|
-
core.Guards.uint8Array(Blake2b.
|
|
369
|
+
core.Guards.uint8Array(Blake2b.CLASS_NAME, "block", block);
|
|
374
370
|
return new Blake2b(Blake2b.SIZE_512, key).update(block).digest();
|
|
375
371
|
}
|
|
376
372
|
/**
|
|
@@ -379,7 +375,7 @@ class Blake2b {
|
|
|
379
375
|
* @returns The instance for chaining.
|
|
380
376
|
*/
|
|
381
377
|
update(block) {
|
|
382
|
-
core.Guards.uint8Array(Blake2b.
|
|
378
|
+
core.Guards.uint8Array(Blake2b.CLASS_NAME, "block", block);
|
|
383
379
|
this._instance.update(block);
|
|
384
380
|
return this;
|
|
385
381
|
}
|
|
@@ -490,9 +486,8 @@ const KeyType = {
|
|
|
490
486
|
class Slip0010 {
|
|
491
487
|
/**
|
|
492
488
|
* Runtime name for the class.
|
|
493
|
-
* @internal
|
|
494
489
|
*/
|
|
495
|
-
static
|
|
490
|
+
static CLASS_NAME = "Slip0010";
|
|
496
491
|
/**
|
|
497
492
|
* Get the master key from the seed.
|
|
498
493
|
* @param seed The seed to generate the master key from.
|
|
@@ -511,7 +506,7 @@ class Slip0010 {
|
|
|
511
506
|
};
|
|
512
507
|
}
|
|
513
508
|
catch (error) {
|
|
514
|
-
throw new core.GeneralError(Slip0010.
|
|
509
|
+
throw new core.GeneralError(Slip0010.CLASS_NAME, "invalidSeed", { seed: core.Converter.bytesToUtf8(seed) }, error);
|
|
515
510
|
}
|
|
516
511
|
}
|
|
517
512
|
/**
|
|
@@ -567,9 +562,8 @@ class Slip0010 {
|
|
|
567
562
|
class Bip44 {
|
|
568
563
|
/**
|
|
569
564
|
* Runtime name for the class.
|
|
570
|
-
* @internal
|
|
571
565
|
*/
|
|
572
|
-
static
|
|
566
|
+
static CLASS_NAME = "Bip44";
|
|
573
567
|
/**
|
|
574
568
|
* Generate a bip44 key pair from the seed and parts.
|
|
575
569
|
* @param seed The account seed.
|
|
@@ -598,7 +592,7 @@ class Bip44 {
|
|
|
598
592
|
publicKey
|
|
599
593
|
};
|
|
600
594
|
}
|
|
601
|
-
throw new core.GeneralError(Bip44.
|
|
595
|
+
throw new core.GeneralError(Bip44.CLASS_NAME, "unsupportedKeyType", { keyType });
|
|
602
596
|
}
|
|
603
597
|
/**
|
|
604
598
|
* Generate a bip44 path based on all its parts.
|
|
@@ -673,9 +667,8 @@ class Bip44 {
|
|
|
673
667
|
class ChaCha20Poly1305 {
|
|
674
668
|
/**
|
|
675
669
|
* Runtime name for the class.
|
|
676
|
-
* @internal
|
|
677
670
|
*/
|
|
678
|
-
static
|
|
671
|
+
static CLASS_NAME = "ChaCha20Poly1305";
|
|
679
672
|
/**
|
|
680
673
|
* The cipher instance.
|
|
681
674
|
* @internal
|
|
@@ -688,8 +681,8 @@ class ChaCha20Poly1305 {
|
|
|
688
681
|
* @param aad The additional authenticated data.
|
|
689
682
|
*/
|
|
690
683
|
constructor(key, nonce, aad) {
|
|
691
|
-
core.Guards.uint8Array(ChaCha20Poly1305.
|
|
692
|
-
core.Guards.uint8Array(ChaCha20Poly1305.
|
|
684
|
+
core.Guards.uint8Array(ChaCha20Poly1305.CLASS_NAME, "key", key);
|
|
685
|
+
core.Guards.uint8Array(ChaCha20Poly1305.CLASS_NAME, "nonce", nonce);
|
|
693
686
|
this._instance = chacha_js.chacha20poly1305(key, nonce, aad);
|
|
694
687
|
}
|
|
695
688
|
/**
|
|
@@ -698,7 +691,7 @@ class ChaCha20Poly1305 {
|
|
|
698
691
|
* @returns The block encrypted.
|
|
699
692
|
*/
|
|
700
693
|
encrypt(block) {
|
|
701
|
-
core.Guards.uint8Array(ChaCha20Poly1305.
|
|
694
|
+
core.Guards.uint8Array(ChaCha20Poly1305.CLASS_NAME, "block", block);
|
|
702
695
|
return this._instance.encrypt(block);
|
|
703
696
|
}
|
|
704
697
|
/**
|
|
@@ -707,7 +700,7 @@ class ChaCha20Poly1305 {
|
|
|
707
700
|
* @returns The block decrypted.
|
|
708
701
|
*/
|
|
709
702
|
decrypt(block) {
|
|
710
|
-
core.Guards.uint8Array(ChaCha20Poly1305.
|
|
703
|
+
core.Guards.uint8Array(ChaCha20Poly1305.CLASS_NAME, "block", block);
|
|
711
704
|
return this._instance.decrypt(block);
|
|
712
705
|
}
|
|
713
706
|
}
|
|
@@ -720,16 +713,15 @@ class ChaCha20Poly1305 {
|
|
|
720
713
|
class X25519 {
|
|
721
714
|
/**
|
|
722
715
|
* Runtime name for the class.
|
|
723
|
-
* @internal
|
|
724
716
|
*/
|
|
725
|
-
static
|
|
717
|
+
static CLASS_NAME = "X25519";
|
|
726
718
|
/**
|
|
727
719
|
* Convert Ed25519 private key to X25519 private key.
|
|
728
720
|
* @param ed25519PrivateKey The ed25519 private key to convert.
|
|
729
721
|
* @returns The x25519 private key.
|
|
730
722
|
*/
|
|
731
723
|
static convertPrivateKeyToX25519(ed25519PrivateKey) {
|
|
732
|
-
core.Guards.uint8Array(X25519.
|
|
724
|
+
core.Guards.uint8Array(X25519.CLASS_NAME, "ed25519PrivateKey", ed25519PrivateKey);
|
|
733
725
|
return ed25519_js.ed25519.utils.toMontgomerySecret(ed25519PrivateKey.slice(0, Ed25519.PRIVATE_KEY_SIZE));
|
|
734
726
|
}
|
|
735
727
|
/**
|
|
@@ -739,7 +731,7 @@ class X25519 {
|
|
|
739
731
|
* @throws GeneralError On invalid public key.
|
|
740
732
|
*/
|
|
741
733
|
static convertPublicKeyToX25519(ed25519PublicKey) {
|
|
742
|
-
core.Guards.uint8Array(X25519.
|
|
734
|
+
core.Guards.uint8Array(X25519.CLASS_NAME, "ed25519PublicKey", ed25519PublicKey);
|
|
743
735
|
return ed25519_js.ed25519.utils.toMontgomery(ed25519PublicKey);
|
|
744
736
|
}
|
|
745
737
|
}
|
|
@@ -752,9 +744,8 @@ class X25519 {
|
|
|
752
744
|
class Zip215 {
|
|
753
745
|
/**
|
|
754
746
|
* Runtime name for the class.
|
|
755
|
-
* @internal
|
|
756
747
|
*/
|
|
757
|
-
static
|
|
748
|
+
static CLASS_NAME = "Zip215";
|
|
758
749
|
/**
|
|
759
750
|
* Verify reports whether sig is a valid signature of block by
|
|
760
751
|
* publicKey, using precisely-specified validation criteria (ZIP 215) suitable
|
|
@@ -765,9 +756,9 @@ class Zip215 {
|
|
|
765
756
|
* @returns True if the signature is valid.
|
|
766
757
|
*/
|
|
767
758
|
static verify(publicKey, block, sig) {
|
|
768
|
-
core.Guards.uint8Array(Zip215.
|
|
769
|
-
core.Guards.uint8Array(Zip215.
|
|
770
|
-
core.Guards.uint8Array(Zip215.
|
|
759
|
+
core.Guards.uint8Array(Zip215.CLASS_NAME, "publicKey", publicKey);
|
|
760
|
+
core.Guards.uint8Array(Zip215.CLASS_NAME, "block", block);
|
|
761
|
+
core.Guards.uint8Array(Zip215.CLASS_NAME, "sig", sig);
|
|
771
762
|
if (publicKey.length !== Ed25519.PUBLIC_KEY_SIZE) {
|
|
772
763
|
return false;
|
|
773
764
|
}
|
|
@@ -791,9 +782,8 @@ class Blake3 {
|
|
|
791
782
|
static SIZE_512 = 64;
|
|
792
783
|
/**
|
|
793
784
|
* Runtime name for the class.
|
|
794
|
-
* @internal
|
|
795
785
|
*/
|
|
796
|
-
static
|
|
786
|
+
static CLASS_NAME = "Blake3";
|
|
797
787
|
/**
|
|
798
788
|
* The instance of the hash.
|
|
799
789
|
* @internal
|
|
@@ -818,7 +808,7 @@ class Blake3 {
|
|
|
818
808
|
* @returns The sum 256 of the block.
|
|
819
809
|
*/
|
|
820
810
|
static sum256(block, key) {
|
|
821
|
-
core.Guards.uint8Array(Blake3.
|
|
811
|
+
core.Guards.uint8Array(Blake3.CLASS_NAME, "block", block);
|
|
822
812
|
return new Blake3(Blake3.SIZE_256, key).update(block).digest();
|
|
823
813
|
}
|
|
824
814
|
/**
|
|
@@ -828,7 +818,7 @@ class Blake3 {
|
|
|
828
818
|
* @returns The sum 512 of the block.
|
|
829
819
|
*/
|
|
830
820
|
static sum512(block, key) {
|
|
831
|
-
core.Guards.uint8Array(Blake3.
|
|
821
|
+
core.Guards.uint8Array(Blake3.CLASS_NAME, "block", block);
|
|
832
822
|
return new Blake3(Blake3.SIZE_512, key).update(block).digest();
|
|
833
823
|
}
|
|
834
824
|
/**
|
|
@@ -837,7 +827,7 @@ class Blake3 {
|
|
|
837
827
|
* @returns The instance for chaining.
|
|
838
828
|
*/
|
|
839
829
|
update(block) {
|
|
840
|
-
core.Guards.uint8Array(Blake3.
|
|
830
|
+
core.Guards.uint8Array(Blake3.CLASS_NAME, "block", block);
|
|
841
831
|
this._instance.update(block);
|
|
842
832
|
return this;
|
|
843
833
|
}
|
|
@@ -858,9 +848,8 @@ class Blake3 {
|
|
|
858
848
|
class HmacSha1 {
|
|
859
849
|
/**
|
|
860
850
|
* Runtime name for the class.
|
|
861
|
-
* @internal
|
|
862
851
|
*/
|
|
863
|
-
static
|
|
852
|
+
static CLASS_NAME = "HmacSha1";
|
|
864
853
|
/**
|
|
865
854
|
* The instance of the hash.
|
|
866
855
|
* @internal
|
|
@@ -881,8 +870,8 @@ class HmacSha1 {
|
|
|
881
870
|
* @returns The sum of the block.
|
|
882
871
|
*/
|
|
883
872
|
static sum(key, block) {
|
|
884
|
-
core.Guards.uint8Array(HmacSha1.
|
|
885
|
-
core.Guards.uint8Array(HmacSha1.
|
|
873
|
+
core.Guards.uint8Array(HmacSha1.CLASS_NAME, "key", key);
|
|
874
|
+
core.Guards.uint8Array(HmacSha1.CLASS_NAME, "block", block);
|
|
886
875
|
return new HmacSha1(key).update(block).digest();
|
|
887
876
|
}
|
|
888
877
|
/**
|
|
@@ -891,7 +880,7 @@ class HmacSha1 {
|
|
|
891
880
|
* @returns The instance for chaining.
|
|
892
881
|
*/
|
|
893
882
|
update(block) {
|
|
894
|
-
core.Guards.uint8Array(HmacSha1.
|
|
883
|
+
core.Guards.uint8Array(HmacSha1.CLASS_NAME, "block", block);
|
|
895
884
|
this._instance.update(block);
|
|
896
885
|
return this;
|
|
897
886
|
}
|
|
@@ -920,9 +909,8 @@ class HmacSha256 {
|
|
|
920
909
|
static SIZE_224 = 224;
|
|
921
910
|
/**
|
|
922
911
|
* Runtime name for the class.
|
|
923
|
-
* @internal
|
|
924
912
|
*/
|
|
925
|
-
static
|
|
913
|
+
static CLASS_NAME = "HmacSha256";
|
|
926
914
|
/**
|
|
927
915
|
* The instance of the hash.
|
|
928
916
|
* @internal
|
|
@@ -936,7 +924,7 @@ class HmacSha256 {
|
|
|
936
924
|
*/
|
|
937
925
|
constructor(key, bits = HmacSha256.SIZE_256) {
|
|
938
926
|
if (bits !== HmacSha256.SIZE_224 && bits !== HmacSha256.SIZE_256) {
|
|
939
|
-
throw new core.GeneralError(HmacSha256.
|
|
927
|
+
throw new core.GeneralError(HmacSha256.CLASS_NAME, "bitSize", { bitSize: bits });
|
|
940
928
|
}
|
|
941
929
|
this._instance = hmac_js.hmac.create(bits === HmacSha256.SIZE_256 ? sha2_js.sha256 : sha2_js.sha224, key);
|
|
942
930
|
}
|
|
@@ -947,8 +935,8 @@ class HmacSha256 {
|
|
|
947
935
|
* @returns The sum 224 of the block.
|
|
948
936
|
*/
|
|
949
937
|
static sum224(key, block) {
|
|
950
|
-
core.Guards.uint8Array(HmacSha256.
|
|
951
|
-
core.Guards.uint8Array(HmacSha256.
|
|
938
|
+
core.Guards.uint8Array(HmacSha256.CLASS_NAME, "key", key);
|
|
939
|
+
core.Guards.uint8Array(HmacSha256.CLASS_NAME, "block", block);
|
|
952
940
|
const instance = new HmacSha256(key, HmacSha256.SIZE_224);
|
|
953
941
|
instance.update(block);
|
|
954
942
|
return instance.digest();
|
|
@@ -960,8 +948,8 @@ class HmacSha256 {
|
|
|
960
948
|
* @returns The sum 256 of the block.
|
|
961
949
|
*/
|
|
962
950
|
static sum256(key, block) {
|
|
963
|
-
core.Guards.uint8Array(HmacSha256.
|
|
964
|
-
core.Guards.uint8Array(HmacSha256.
|
|
951
|
+
core.Guards.uint8Array(HmacSha256.CLASS_NAME, "key", key);
|
|
952
|
+
core.Guards.uint8Array(HmacSha256.CLASS_NAME, "block", block);
|
|
965
953
|
const instance = new HmacSha256(key, HmacSha256.SIZE_256);
|
|
966
954
|
instance.update(block);
|
|
967
955
|
return instance.digest();
|
|
@@ -972,7 +960,7 @@ class HmacSha256 {
|
|
|
972
960
|
* @returns The instance for chaining.
|
|
973
961
|
*/
|
|
974
962
|
update(block) {
|
|
975
|
-
core.Guards.uint8Array(HmacSha256.
|
|
963
|
+
core.Guards.uint8Array(HmacSha256.CLASS_NAME, "block", block);
|
|
976
964
|
this._instance.update(block);
|
|
977
965
|
return this;
|
|
978
966
|
}
|
|
@@ -1010,9 +998,8 @@ class HmacSha512 {
|
|
|
1010
998
|
static SIZE_512 = 512;
|
|
1011
999
|
/**
|
|
1012
1000
|
* Runtime name for the class.
|
|
1013
|
-
* @internal
|
|
1014
1001
|
*/
|
|
1015
|
-
static
|
|
1002
|
+
static CLASS_NAME = "HmacSha512";
|
|
1016
1003
|
/**
|
|
1017
1004
|
* The instance of the hash.
|
|
1018
1005
|
* @internal
|
|
@@ -1029,7 +1016,7 @@ class HmacSha512 {
|
|
|
1029
1016
|
bits !== HmacSha512.SIZE_256 &&
|
|
1030
1017
|
bits !== HmacSha512.SIZE_384 &&
|
|
1031
1018
|
bits !== HmacSha512.SIZE_512) {
|
|
1032
|
-
throw new core.GeneralError(HmacSha512.
|
|
1019
|
+
throw new core.GeneralError(HmacSha512.CLASS_NAME, "bitSize", { bitSize: bits });
|
|
1033
1020
|
}
|
|
1034
1021
|
if (bits === HmacSha512.SIZE_224) {
|
|
1035
1022
|
this._instance = hmac_js.hmac.create(sha2_js.sha512_224, key);
|
|
@@ -1051,8 +1038,8 @@ class HmacSha512 {
|
|
|
1051
1038
|
* @returns The sum 512 of the block.
|
|
1052
1039
|
*/
|
|
1053
1040
|
static sum512(key, block) {
|
|
1054
|
-
core.Guards.uint8Array(HmacSha512.
|
|
1055
|
-
core.Guards.uint8Array(HmacSha512.
|
|
1041
|
+
core.Guards.uint8Array(HmacSha512.CLASS_NAME, "key", key);
|
|
1042
|
+
core.Guards.uint8Array(HmacSha512.CLASS_NAME, "block", block);
|
|
1056
1043
|
const instance = new HmacSha512(key, HmacSha512.SIZE_512);
|
|
1057
1044
|
instance.update(block);
|
|
1058
1045
|
return instance.digest();
|
|
@@ -1064,8 +1051,8 @@ class HmacSha512 {
|
|
|
1064
1051
|
* @returns The sum 384 of the block.
|
|
1065
1052
|
*/
|
|
1066
1053
|
static sum384(key, block) {
|
|
1067
|
-
core.Guards.uint8Array(HmacSha512.
|
|
1068
|
-
core.Guards.uint8Array(HmacSha512.
|
|
1054
|
+
core.Guards.uint8Array(HmacSha512.CLASS_NAME, "key", key);
|
|
1055
|
+
core.Guards.uint8Array(HmacSha512.CLASS_NAME, "block", block);
|
|
1069
1056
|
const instance = new HmacSha512(key, HmacSha512.SIZE_384);
|
|
1070
1057
|
instance.update(block);
|
|
1071
1058
|
return instance.digest();
|
|
@@ -1077,8 +1064,8 @@ class HmacSha512 {
|
|
|
1077
1064
|
* @returns The sum 256 of the block.
|
|
1078
1065
|
*/
|
|
1079
1066
|
static sum256(key, block) {
|
|
1080
|
-
core.Guards.uint8Array(HmacSha512.
|
|
1081
|
-
core.Guards.uint8Array(HmacSha512.
|
|
1067
|
+
core.Guards.uint8Array(HmacSha512.CLASS_NAME, "key", key);
|
|
1068
|
+
core.Guards.uint8Array(HmacSha512.CLASS_NAME, "block", block);
|
|
1082
1069
|
const instance = new HmacSha512(key, HmacSha512.SIZE_256);
|
|
1083
1070
|
instance.update(block);
|
|
1084
1071
|
return instance.digest();
|
|
@@ -1090,8 +1077,8 @@ class HmacSha512 {
|
|
|
1090
1077
|
* @returns The sum 224 of the block.
|
|
1091
1078
|
*/
|
|
1092
1079
|
static sum224(key, block) {
|
|
1093
|
-
core.Guards.uint8Array(HmacSha512.
|
|
1094
|
-
core.Guards.uint8Array(HmacSha512.
|
|
1080
|
+
core.Guards.uint8Array(HmacSha512.CLASS_NAME, "key", key);
|
|
1081
|
+
core.Guards.uint8Array(HmacSha512.CLASS_NAME, "block", block);
|
|
1095
1082
|
const instance = new HmacSha512(key, HmacSha512.SIZE_224);
|
|
1096
1083
|
instance.update(block);
|
|
1097
1084
|
return instance.digest();
|
|
@@ -1102,7 +1089,7 @@ class HmacSha512 {
|
|
|
1102
1089
|
* @returns The instance for chaining.
|
|
1103
1090
|
*/
|
|
1104
1091
|
update(block) {
|
|
1105
|
-
core.Guards.uint8Array(HmacSha512.
|
|
1092
|
+
core.Guards.uint8Array(HmacSha512.CLASS_NAME, "block", block);
|
|
1106
1093
|
this._instance.update(block);
|
|
1107
1094
|
return this;
|
|
1108
1095
|
}
|
|
@@ -1123,9 +1110,8 @@ class HmacSha512 {
|
|
|
1123
1110
|
class Pbkdf2 {
|
|
1124
1111
|
/**
|
|
1125
1112
|
* Runtime name for the class.
|
|
1126
|
-
* @internal
|
|
1127
1113
|
*/
|
|
1128
|
-
static
|
|
1114
|
+
static CLASS_NAME = "Pbkdf2";
|
|
1129
1115
|
/**
|
|
1130
1116
|
* Derive a key from the parameters using Sha256.
|
|
1131
1117
|
* @param password The password to derive the key from.
|
|
@@ -1135,10 +1121,10 @@ class Pbkdf2 {
|
|
|
1135
1121
|
* @returns The derived key.
|
|
1136
1122
|
*/
|
|
1137
1123
|
static sha256(password, salt, iterations, keyLength) {
|
|
1138
|
-
core.Guards.uint8Array(Pbkdf2.
|
|
1139
|
-
core.Guards.uint8Array(Pbkdf2.
|
|
1140
|
-
core.Guards.number(Pbkdf2.
|
|
1141
|
-
core.Guards.number(Pbkdf2.
|
|
1124
|
+
core.Guards.uint8Array(Pbkdf2.CLASS_NAME, "password", password);
|
|
1125
|
+
core.Guards.uint8Array(Pbkdf2.CLASS_NAME, "salt", salt);
|
|
1126
|
+
core.Guards.number(Pbkdf2.CLASS_NAME, "iterations", iterations);
|
|
1127
|
+
core.Guards.number(Pbkdf2.CLASS_NAME, "keyLength", keyLength);
|
|
1142
1128
|
return pbkdf2_js.pbkdf2(sha2_js.sha256, password, salt, { c: iterations, dkLen: keyLength });
|
|
1143
1129
|
}
|
|
1144
1130
|
/**
|
|
@@ -1150,10 +1136,10 @@ class Pbkdf2 {
|
|
|
1150
1136
|
* @returns The derived key.
|
|
1151
1137
|
*/
|
|
1152
1138
|
static sha512(password, salt, iterations, keyLength) {
|
|
1153
|
-
core.Guards.uint8Array(Pbkdf2.
|
|
1154
|
-
core.Guards.uint8Array(Pbkdf2.
|
|
1155
|
-
core.Guards.number(Pbkdf2.
|
|
1156
|
-
core.Guards.number(Pbkdf2.
|
|
1139
|
+
core.Guards.uint8Array(Pbkdf2.CLASS_NAME, "password", password);
|
|
1140
|
+
core.Guards.uint8Array(Pbkdf2.CLASS_NAME, "salt", salt);
|
|
1141
|
+
core.Guards.number(Pbkdf2.CLASS_NAME, "iterations", iterations);
|
|
1142
|
+
core.Guards.number(Pbkdf2.CLASS_NAME, "keyLength", keyLength);
|
|
1157
1143
|
return pbkdf2_js.pbkdf2(sha2_js.sha512, password, salt, { c: iterations, dkLen: keyLength });
|
|
1158
1144
|
}
|
|
1159
1145
|
}
|
|
@@ -1166,9 +1152,8 @@ class Pbkdf2 {
|
|
|
1166
1152
|
class Sha1 {
|
|
1167
1153
|
/**
|
|
1168
1154
|
* Runtime name for the class.
|
|
1169
|
-
* @internal
|
|
1170
1155
|
*/
|
|
1171
|
-
static
|
|
1156
|
+
static CLASS_NAME = "Sha1";
|
|
1172
1157
|
/**
|
|
1173
1158
|
* The instance of the hash.
|
|
1174
1159
|
* @internal
|
|
@@ -1187,7 +1172,7 @@ class Sha1 {
|
|
|
1187
1172
|
* @returns The sum of the block.
|
|
1188
1173
|
*/
|
|
1189
1174
|
static sum(block) {
|
|
1190
|
-
core.Guards.uint8Array(Sha1.
|
|
1175
|
+
core.Guards.uint8Array(Sha1.CLASS_NAME, "block", block);
|
|
1191
1176
|
return new Sha1().update(block).digest();
|
|
1192
1177
|
}
|
|
1193
1178
|
/**
|
|
@@ -1196,7 +1181,7 @@ class Sha1 {
|
|
|
1196
1181
|
* @returns The instance for chaining.
|
|
1197
1182
|
*/
|
|
1198
1183
|
update(block) {
|
|
1199
|
-
core.Guards.uint8Array(Sha1.
|
|
1184
|
+
core.Guards.uint8Array(Sha1.CLASS_NAME, "block", block);
|
|
1200
1185
|
this._instance.update(block);
|
|
1201
1186
|
return this;
|
|
1202
1187
|
}
|
|
@@ -1225,9 +1210,8 @@ class Sha256 {
|
|
|
1225
1210
|
static SIZE_224 = 224;
|
|
1226
1211
|
/**
|
|
1227
1212
|
* Runtime name for the class.
|
|
1228
|
-
* @internal
|
|
1229
1213
|
*/
|
|
1230
|
-
static
|
|
1214
|
+
static CLASS_NAME = "Sha256";
|
|
1231
1215
|
/**
|
|
1232
1216
|
* The instance of the hash.
|
|
1233
1217
|
* @internal
|
|
@@ -1240,7 +1224,7 @@ class Sha256 {
|
|
|
1240
1224
|
*/
|
|
1241
1225
|
constructor(bits = Sha256.SIZE_256) {
|
|
1242
1226
|
if (bits !== Sha256.SIZE_224 && bits !== Sha256.SIZE_256) {
|
|
1243
|
-
throw new core.GeneralError(Sha256.
|
|
1227
|
+
throw new core.GeneralError(Sha256.CLASS_NAME, "bitSize", { bitSize: bits });
|
|
1244
1228
|
}
|
|
1245
1229
|
this._instance = bits === Sha256.SIZE_256 ? sha2_js.sha256.create() : sha2_js.sha224.create();
|
|
1246
1230
|
}
|
|
@@ -1270,7 +1254,7 @@ class Sha256 {
|
|
|
1270
1254
|
* @returns The instance for chaining.
|
|
1271
1255
|
*/
|
|
1272
1256
|
update(block) {
|
|
1273
|
-
core.Guards.uint8Array(Sha256.
|
|
1257
|
+
core.Guards.uint8Array(Sha256.CLASS_NAME, "block", block);
|
|
1274
1258
|
this._instance.update(block);
|
|
1275
1259
|
return this;
|
|
1276
1260
|
}
|
|
@@ -1308,9 +1292,8 @@ class Sha3 {
|
|
|
1308
1292
|
static SIZE_512 = 512;
|
|
1309
1293
|
/**
|
|
1310
1294
|
* Runtime name for the class.
|
|
1311
|
-
* @internal
|
|
1312
1295
|
*/
|
|
1313
|
-
static
|
|
1296
|
+
static CLASS_NAME = "Sha3";
|
|
1314
1297
|
/**
|
|
1315
1298
|
* The instance of the hash.
|
|
1316
1299
|
* @internal
|
|
@@ -1326,7 +1309,7 @@ class Sha3 {
|
|
|
1326
1309
|
bits !== Sha3.SIZE_256 &&
|
|
1327
1310
|
bits !== Sha3.SIZE_384 &&
|
|
1328
1311
|
bits !== Sha3.SIZE_512) {
|
|
1329
|
-
throw new core.GeneralError(Sha3.
|
|
1312
|
+
throw new core.GeneralError(Sha3.CLASS_NAME, "bitSize", { bitSize: bits });
|
|
1330
1313
|
}
|
|
1331
1314
|
if (bits === Sha3.SIZE_224) {
|
|
1332
1315
|
// eslint-disable-next-line camelcase
|
|
@@ -1391,7 +1374,7 @@ class Sha3 {
|
|
|
1391
1374
|
* @returns The instance for chaining.
|
|
1392
1375
|
*/
|
|
1393
1376
|
update(block) {
|
|
1394
|
-
core.Guards.uint8Array(Sha3.
|
|
1377
|
+
core.Guards.uint8Array(Sha3.CLASS_NAME, "block", block);
|
|
1395
1378
|
this._instance.update(block);
|
|
1396
1379
|
return this;
|
|
1397
1380
|
}
|
|
@@ -1429,9 +1412,8 @@ class Sha512 {
|
|
|
1429
1412
|
static SIZE_512 = 512;
|
|
1430
1413
|
/**
|
|
1431
1414
|
* Runtime name for the class.
|
|
1432
|
-
* @internal
|
|
1433
1415
|
*/
|
|
1434
|
-
static
|
|
1416
|
+
static CLASS_NAME = "Sha512";
|
|
1435
1417
|
/**
|
|
1436
1418
|
* The instance of the hash.
|
|
1437
1419
|
* @internal
|
|
@@ -1447,7 +1429,7 @@ class Sha512 {
|
|
|
1447
1429
|
bits !== Sha512.SIZE_256 &&
|
|
1448
1430
|
bits !== Sha512.SIZE_384 &&
|
|
1449
1431
|
bits !== Sha512.SIZE_512) {
|
|
1450
|
-
throw new core.GeneralError(Sha512.
|
|
1432
|
+
throw new core.GeneralError(Sha512.CLASS_NAME, "bitSize", { bitSize: bits });
|
|
1451
1433
|
}
|
|
1452
1434
|
if (bits === Sha512.SIZE_224) {
|
|
1453
1435
|
this._instance = sha2_js.sha512_224.create();
|
|
@@ -1508,7 +1490,7 @@ class Sha512 {
|
|
|
1508
1490
|
* @returns The instance for chaining.
|
|
1509
1491
|
*/
|
|
1510
1492
|
update(block) {
|
|
1511
|
-
core.Guards.uint8Array(Sha512.
|
|
1493
|
+
core.Guards.uint8Array(Sha512.CLASS_NAME, "block", block);
|
|
1512
1494
|
this._instance.update(block);
|
|
1513
1495
|
return this;
|
|
1514
1496
|
}
|
|
@@ -1529,16 +1511,15 @@ class Sha512 {
|
|
|
1529
1511
|
class PemHelper {
|
|
1530
1512
|
/**
|
|
1531
1513
|
* Runtime name for the class.
|
|
1532
|
-
* @internal
|
|
1533
1514
|
*/
|
|
1534
|
-
static
|
|
1515
|
+
static CLASS_NAME = "PemHelper";
|
|
1535
1516
|
/**
|
|
1536
1517
|
* Strip the PEM content of its headers, footers, and newlines.
|
|
1537
1518
|
* @param pemContent The PEM content to strip.
|
|
1538
1519
|
* @returns The stripped PEM content in bas64 format.
|
|
1539
1520
|
*/
|
|
1540
1521
|
static stripPemMarkers(pemContent) {
|
|
1541
|
-
core.Guards.string(PemHelper.
|
|
1522
|
+
core.Guards.string(PemHelper.CLASS_NAME, "pemContent", pemContent);
|
|
1542
1523
|
return pemContent
|
|
1543
1524
|
.replace(/-----BEGIN.*-----/, "")
|
|
1544
1525
|
.replace(/-----END.*-----/, "")
|
|
@@ -1553,8 +1534,8 @@ class PemHelper {
|
|
|
1553
1534
|
* @returns The formatted PEM content.
|
|
1554
1535
|
*/
|
|
1555
1536
|
static formatPem(marker, base64Content, lineLength = 64) {
|
|
1556
|
-
core.Guards.stringValue(PemHelper.
|
|
1557
|
-
core.Guards.stringBase64(PemHelper.
|
|
1537
|
+
core.Guards.stringValue(PemHelper.CLASS_NAME, "marker", marker);
|
|
1538
|
+
core.Guards.stringBase64(PemHelper.CLASS_NAME, "base64Content", base64Content);
|
|
1558
1539
|
const lines = [];
|
|
1559
1540
|
for (let i = 0; i < base64Content.length; i += lineLength) {
|
|
1560
1541
|
lines.push(base64Content.slice(i, i + lineLength));
|
|
@@ -1571,9 +1552,8 @@ class PemHelper {
|
|
|
1571
1552
|
class Bip39 {
|
|
1572
1553
|
/**
|
|
1573
1554
|
* Runtime name for the class.
|
|
1574
|
-
* @internal
|
|
1575
1555
|
*/
|
|
1576
|
-
static
|
|
1556
|
+
static CLASS_NAME = "Bip39";
|
|
1577
1557
|
/**
|
|
1578
1558
|
* Generate a random mnemonic.
|
|
1579
1559
|
* @param strength The strength of the mnemonic to generate, defaults to 256.
|
|
@@ -1582,10 +1562,10 @@ class Bip39 {
|
|
|
1582
1562
|
* @throws Error if the length is not a multiple of 32.
|
|
1583
1563
|
*/
|
|
1584
1564
|
static randomMnemonic(strength = 256, words = english_js.wordlist) {
|
|
1585
|
-
core.Guards.number(Bip39.
|
|
1586
|
-
core.Guards.arrayValue(Bip39.
|
|
1565
|
+
core.Guards.number(Bip39.CLASS_NAME, "strength", strength);
|
|
1566
|
+
core.Guards.arrayValue(Bip39.CLASS_NAME, "words", words);
|
|
1587
1567
|
if (strength % 32 !== 0) {
|
|
1588
|
-
throw new core.GuardError(Bip39.
|
|
1568
|
+
throw new core.GuardError(Bip39.CLASS_NAME, "guard.length32Multiple", "strength", strength);
|
|
1589
1569
|
}
|
|
1590
1570
|
return bip39__namespace.generateMnemonic(words, strength);
|
|
1591
1571
|
}
|
|
@@ -1597,10 +1577,10 @@ class Bip39 {
|
|
|
1597
1577
|
* @throws Error if the length of the entropy is not a multiple of 4, or is less than 16 or greater than 32.
|
|
1598
1578
|
*/
|
|
1599
1579
|
static entropyToMnemonic(entropy, words = english_js.wordlist) {
|
|
1600
|
-
core.Guards.uint8Array(Bip39.
|
|
1601
|
-
core.Guards.arrayValue(Bip39.
|
|
1580
|
+
core.Guards.uint8Array(Bip39.CLASS_NAME, "entropy", entropy);
|
|
1581
|
+
core.Guards.arrayValue(Bip39.CLASS_NAME, "words", words);
|
|
1602
1582
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
|
1603
|
-
throw new core.GuardError(Bip39.
|
|
1583
|
+
throw new core.GuardError(Bip39.CLASS_NAME, "guard.lengthEntropy", "entropy", entropy.length);
|
|
1604
1584
|
}
|
|
1605
1585
|
return bip39__namespace.entropyToMnemonic(entropy, words);
|
|
1606
1586
|
}
|
|
@@ -1611,7 +1591,7 @@ class Bip39 {
|
|
|
1611
1591
|
* @returns The seed.
|
|
1612
1592
|
*/
|
|
1613
1593
|
static mnemonicToSeed(mnemonic, password) {
|
|
1614
|
-
core.Guards.stringValue(Bip39.
|
|
1594
|
+
core.Guards.stringValue(Bip39.CLASS_NAME, "mnemonic", mnemonic);
|
|
1615
1595
|
return bip39__namespace.mnemonicToSeedSync(mnemonic, password);
|
|
1616
1596
|
}
|
|
1617
1597
|
/**
|
|
@@ -1622,8 +1602,8 @@ class Bip39 {
|
|
|
1622
1602
|
* @throws Error if the number of words is not a multiple of 3.
|
|
1623
1603
|
*/
|
|
1624
1604
|
static mnemonicToEntropy(mnemonic, words = english_js.wordlist) {
|
|
1625
|
-
core.Guards.stringValue(Bip39.
|
|
1626
|
-
core.Guards.arrayValue(Bip39.
|
|
1605
|
+
core.Guards.stringValue(Bip39.CLASS_NAME, "mnemonic", mnemonic);
|
|
1606
|
+
core.Guards.arrayValue(Bip39.CLASS_NAME, "words", words);
|
|
1627
1607
|
return bip39__namespace.mnemonicToEntropy(mnemonic, words);
|
|
1628
1608
|
}
|
|
1629
1609
|
/**
|
|
@@ -1634,8 +1614,8 @@ class Bip39 {
|
|
|
1634
1614
|
* @returns True if the mnemonic is valid.
|
|
1635
1615
|
*/
|
|
1636
1616
|
static validateMnemonic(mnemonic, wordCount = 24, words = english_js.wordlist) {
|
|
1637
|
-
core.Guards.string(Bip39.
|
|
1638
|
-
core.Guards.integer(Bip39.
|
|
1617
|
+
core.Guards.string(Bip39.CLASS_NAME, "mnemonic", mnemonic);
|
|
1618
|
+
core.Guards.integer(Bip39.CLASS_NAME, "wordCount", wordCount);
|
|
1639
1619
|
const mnemonicSplit = mnemonic.split(/\s+/);
|
|
1640
1620
|
if (mnemonicSplit.length !== wordCount) {
|
|
1641
1621
|
return false;
|
|
@@ -1653,9 +1633,8 @@ class Bip39 {
|
|
|
1653
1633
|
class Hotp {
|
|
1654
1634
|
/**
|
|
1655
1635
|
* Runtime name for the class.
|
|
1656
|
-
* @internal
|
|
1657
1636
|
*/
|
|
1658
|
-
static
|
|
1637
|
+
static CLASS_NAME = "Hotp";
|
|
1659
1638
|
/**
|
|
1660
1639
|
* Generate a counter based One Time Password.
|
|
1661
1640
|
* @param key Key for the one time password.
|
|
@@ -1664,8 +1643,8 @@ class Hotp {
|
|
|
1664
1643
|
* @returns The one time password.
|
|
1665
1644
|
*/
|
|
1666
1645
|
static generate(key, counter) {
|
|
1667
|
-
core.Guards.uint8Array(Hotp.
|
|
1668
|
-
core.Guards.number(Hotp.
|
|
1646
|
+
core.Guards.uint8Array(Hotp.CLASS_NAME, "key", key);
|
|
1647
|
+
core.Guards.number(Hotp.CLASS_NAME, "counter", counter);
|
|
1669
1648
|
return otp__namespace.hotp({ secret: key, digits: 6, algorithm: "sha1", interval: 30 }, counter);
|
|
1670
1649
|
}
|
|
1671
1650
|
}
|
|
@@ -1701,7 +1680,7 @@ class Totp {
|
|
|
1701
1680
|
for (let i = -window; i < window; i++) {
|
|
1702
1681
|
const intervalWindow = i * interval * 1000;
|
|
1703
1682
|
if (timestamp + intervalWindow > 0) {
|
|
1704
|
-
const gen =
|
|
1683
|
+
const gen = Totp.generate(key, interval, timestamp + intervalWindow);
|
|
1705
1684
|
if (gen === token) {
|
|
1706
1685
|
// We have found a matching code
|
|
1707
1686
|
return i;
|
|
@@ -1796,7 +1775,8 @@ class PasswordValidator {
|
|
|
1796
1775
|
property,
|
|
1797
1776
|
reason: "validation.minLengthRequired",
|
|
1798
1777
|
properties: {
|
|
1799
|
-
minLength
|
|
1778
|
+
minLength,
|
|
1779
|
+
actualLength: password.length
|
|
1800
1780
|
}
|
|
1801
1781
|
});
|
|
1802
1782
|
}
|
|
@@ -1806,7 +1786,8 @@ class PasswordValidator {
|
|
|
1806
1786
|
property,
|
|
1807
1787
|
reason: "validation.maxLengthRequired",
|
|
1808
1788
|
properties: {
|
|
1809
|
-
maxLength
|
|
1789
|
+
maxLength,
|
|
1790
|
+
actualLength: password.length
|
|
1810
1791
|
}
|
|
1811
1792
|
});
|
|
1812
1793
|
}
|