@twin.org/crypto 0.0.1 → 0.0.2-next.10
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 +106 -53
- package/dist/esm/index.mjs +77 -25
- package/dist/types/helpers/pemHelper.d.ts +19 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/keys/bip39.d.ts +8 -0
- package/docs/changelog.md +195 -0
- package/docs/reference/classes/Bip39.md +34 -0
- package/docs/reference/classes/PemHelper.md +69 -0
- package/docs/reference/index.md +1 -0
- package/docs/reference/variables/KeyType.md +1 -1
- package/locales/en.json +4 -0
- package/package.json +11 -10
package/dist/cjs/index.cjs
CHANGED
|
@@ -2,21 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
var base = require('@scure/base');
|
|
4
4
|
var core = require('@twin.org/core');
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
5
|
+
var ed25519_js = require('@noble/curves/ed25519.js');
|
|
6
|
+
var secp256k1_js = require('@noble/curves/secp256k1.js');
|
|
7
|
+
var blake2_js = require('@noble/hashes/blake2.js');
|
|
8
8
|
var bip32 = require('@scure/bip32');
|
|
9
9
|
var slip10_js = require('micro-key-producer/slip10.js');
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
var
|
|
15
|
-
var
|
|
16
|
-
var
|
|
17
|
-
var sha3 = require('@noble/hashes/sha3');
|
|
10
|
+
var chacha_js = require('@noble/ciphers/chacha.js');
|
|
11
|
+
var blake3_js = require('@noble/hashes/blake3.js');
|
|
12
|
+
var hmac_js = require('@noble/hashes/hmac.js');
|
|
13
|
+
var legacy_js = require('@noble/hashes/legacy.js');
|
|
14
|
+
var sha2_js = require('@noble/hashes/sha2.js');
|
|
15
|
+
var pbkdf2_js = require('@noble/hashes/pbkdf2.js');
|
|
16
|
+
var sha3_js = require('@noble/hashes/sha3.js');
|
|
18
17
|
var bip39 = require('@scure/bip39');
|
|
19
|
-
var
|
|
18
|
+
var english_js = require('@scure/bip39/wordlists/english.js');
|
|
20
19
|
var otp = require('micro-key-producer/otp.js');
|
|
21
20
|
|
|
22
21
|
function _interopNamespaceDefault(e) {
|
|
@@ -143,7 +142,7 @@ class Ed25519 {
|
|
|
143
142
|
actualSize: privateKey.length
|
|
144
143
|
});
|
|
145
144
|
}
|
|
146
|
-
return
|
|
145
|
+
return ed25519_js.ed25519.getPublicKey(privateKey);
|
|
147
146
|
}
|
|
148
147
|
/**
|
|
149
148
|
* Sign the block with privateKey and returns a signature.
|
|
@@ -161,7 +160,7 @@ class Ed25519 {
|
|
|
161
160
|
actualSize: privateKey ? privateKey.length : 0
|
|
162
161
|
});
|
|
163
162
|
}
|
|
164
|
-
return
|
|
163
|
+
return ed25519_js.ed25519.sign(block, privateKey);
|
|
165
164
|
}
|
|
166
165
|
/**
|
|
167
166
|
* Verify reports whether sig is a valid signature of block by publicKey.
|
|
@@ -182,7 +181,7 @@ class Ed25519 {
|
|
|
182
181
|
});
|
|
183
182
|
}
|
|
184
183
|
try {
|
|
185
|
-
return
|
|
184
|
+
return ed25519_js.ed25519.verify(signature, block, publicKey);
|
|
186
185
|
}
|
|
187
186
|
catch {
|
|
188
187
|
return false;
|
|
@@ -207,7 +206,7 @@ class Ed25519 {
|
|
|
207
206
|
// The ASN.1 sequence is 48 46 02 01 00 30 05 06 03 2b 65 70 04 20 04 20 (0x302e020100300506032b657004220420)
|
|
208
207
|
const pkcs8Prefix = new Uint8Array([48, 46, 2, 1, 0, 48, 5, 6, 3, 43, 101, 112, 4, 34, 4, 32]);
|
|
209
208
|
const fullKey = core.Uint8ArrayHelper.concat([pkcs8Prefix, privateKey]);
|
|
210
|
-
return crypto.subtle.importKey("pkcs8", fullKey, "Ed25519", true, ["sign"]);
|
|
209
|
+
return crypto.subtle.importKey("pkcs8", new Uint8Array(fullKey), "Ed25519", true, ["sign"]);
|
|
211
210
|
}
|
|
212
211
|
/**
|
|
213
212
|
* Convert a crypto key to raw private key.
|
|
@@ -256,7 +255,7 @@ class Secp256k1 {
|
|
|
256
255
|
actualSize: privateKey.length
|
|
257
256
|
});
|
|
258
257
|
}
|
|
259
|
-
return
|
|
258
|
+
return secp256k1_js.secp256k1.getPublicKey(privateKey);
|
|
260
259
|
}
|
|
261
260
|
/**
|
|
262
261
|
* Sign the block with privateKey and returns a signature.
|
|
@@ -271,11 +270,11 @@ class Secp256k1 {
|
|
|
271
270
|
if (privateKey.length !== Secp256k1.PRIVATE_KEY_SIZE) {
|
|
272
271
|
throw new core.GeneralError(Secp256k1._CLASS_NAME, "privateKeyLength", {
|
|
273
272
|
requiredSize: Secp256k1.PRIVATE_KEY_SIZE,
|
|
274
|
-
actualSize: privateKey
|
|
273
|
+
actualSize: privateKey.length
|
|
275
274
|
});
|
|
276
275
|
}
|
|
277
|
-
const res =
|
|
278
|
-
return res
|
|
276
|
+
const res = secp256k1_js.secp256k1.sign(block, privateKey, { prehash: false });
|
|
277
|
+
return res;
|
|
279
278
|
}
|
|
280
279
|
/**
|
|
281
280
|
* Verify reports whether sig is a valid signature of block by publicKey.
|
|
@@ -296,7 +295,7 @@ class Secp256k1 {
|
|
|
296
295
|
});
|
|
297
296
|
}
|
|
298
297
|
try {
|
|
299
|
-
return
|
|
298
|
+
return secp256k1_js.secp256k1.verify(signature, block, publicKey, { prehash: false });
|
|
300
299
|
}
|
|
301
300
|
catch {
|
|
302
301
|
return false;
|
|
@@ -339,7 +338,7 @@ class Blake2b {
|
|
|
339
338
|
* @param key Optional key for the hash.
|
|
340
339
|
*/
|
|
341
340
|
constructor(outputLength, key) {
|
|
342
|
-
this._instance =
|
|
341
|
+
this._instance = blake2_js.blake2b.create({
|
|
343
342
|
dkLen: outputLength,
|
|
344
343
|
key
|
|
345
344
|
});
|
|
@@ -484,7 +483,6 @@ const KeyType = {
|
|
|
484
483
|
|
|
485
484
|
// Copyright 2024 IOTA Stiftung.
|
|
486
485
|
// SPDX-License-Identifier: Apache-2.0.
|
|
487
|
-
/* eslint-disable no-bitwise */
|
|
488
486
|
/**
|
|
489
487
|
* Class to help with slip0010 key derivation
|
|
490
488
|
* https://github.com/satoshilabs/slips/blob/master/slip-0010.md.
|
|
@@ -692,7 +690,7 @@ class ChaCha20Poly1305 {
|
|
|
692
690
|
constructor(key, nonce, aad) {
|
|
693
691
|
core.Guards.uint8Array(ChaCha20Poly1305._CLASS_NAME, "key", key);
|
|
694
692
|
core.Guards.uint8Array(ChaCha20Poly1305._CLASS_NAME, "nonce", nonce);
|
|
695
|
-
this._instance =
|
|
693
|
+
this._instance = chacha_js.chacha20poly1305(key, nonce, aad);
|
|
696
694
|
}
|
|
697
695
|
/**
|
|
698
696
|
* Encrypt the block.
|
|
@@ -716,9 +714,6 @@ class ChaCha20Poly1305 {
|
|
|
716
714
|
|
|
717
715
|
// Copyright 2024 IOTA Stiftung.
|
|
718
716
|
// SPDX-License-Identifier: Apache-2.0.
|
|
719
|
-
/**
|
|
720
|
-
* This is a TypeScript port of https://github.com/katzenpost/core/blob/master/crypto/extra25519/extra25519.go.
|
|
721
|
-
*/
|
|
722
717
|
/**
|
|
723
718
|
* Implementation of X25519.
|
|
724
719
|
*/
|
|
@@ -735,7 +730,7 @@ class X25519 {
|
|
|
735
730
|
*/
|
|
736
731
|
static convertPrivateKeyToX25519(ed25519PrivateKey) {
|
|
737
732
|
core.Guards.uint8Array(X25519._CLASS_NAME, "ed25519PrivateKey", ed25519PrivateKey);
|
|
738
|
-
return ed25519.
|
|
733
|
+
return ed25519_js.ed25519.utils.toMontgomerySecret(ed25519PrivateKey.slice(0, Ed25519.PRIVATE_KEY_SIZE));
|
|
739
734
|
}
|
|
740
735
|
/**
|
|
741
736
|
* Convert Ed25519 public key to X25519 public key.
|
|
@@ -745,7 +740,7 @@ class X25519 {
|
|
|
745
740
|
*/
|
|
746
741
|
static convertPublicKeyToX25519(ed25519PublicKey) {
|
|
747
742
|
core.Guards.uint8Array(X25519._CLASS_NAME, "ed25519PublicKey", ed25519PublicKey);
|
|
748
|
-
return ed25519.
|
|
743
|
+
return ed25519_js.ed25519.utils.toMontgomery(ed25519PublicKey);
|
|
749
744
|
}
|
|
750
745
|
}
|
|
751
746
|
|
|
@@ -776,7 +771,7 @@ class Zip215 {
|
|
|
776
771
|
if (publicKey.length !== Ed25519.PUBLIC_KEY_SIZE) {
|
|
777
772
|
return false;
|
|
778
773
|
}
|
|
779
|
-
return
|
|
774
|
+
return ed25519_js.ed25519.verify(sig, block, publicKey, { zip215: true });
|
|
780
775
|
}
|
|
781
776
|
}
|
|
782
777
|
|
|
@@ -811,7 +806,7 @@ class Blake3 {
|
|
|
811
806
|
* @param key Optional key for the hash.
|
|
812
807
|
*/
|
|
813
808
|
constructor(outputLength, key) {
|
|
814
|
-
this._instance =
|
|
809
|
+
this._instance = blake3_js.blake3.create({
|
|
815
810
|
dkLen: outputLength,
|
|
816
811
|
key
|
|
817
812
|
});
|
|
@@ -877,7 +872,7 @@ class HmacSha1 {
|
|
|
877
872
|
* @param key The key for the hmac.
|
|
878
873
|
*/
|
|
879
874
|
constructor(key) {
|
|
880
|
-
this._instance =
|
|
875
|
+
this._instance = hmac_js.hmac.create(legacy_js.sha1, key);
|
|
881
876
|
}
|
|
882
877
|
/**
|
|
883
878
|
* Perform Sum on the block.
|
|
@@ -943,7 +938,7 @@ class HmacSha256 {
|
|
|
943
938
|
if (bits !== HmacSha256.SIZE_224 && bits !== HmacSha256.SIZE_256) {
|
|
944
939
|
throw new core.GeneralError(HmacSha256._CLASS_NAME, "bitSize", { bitSize: bits });
|
|
945
940
|
}
|
|
946
|
-
this._instance =
|
|
941
|
+
this._instance = hmac_js.hmac.create(bits === HmacSha256.SIZE_256 ? sha2_js.sha256 : sha2_js.sha224, key);
|
|
947
942
|
}
|
|
948
943
|
/**
|
|
949
944
|
* Perform Sum 224 on the block.
|
|
@@ -1037,16 +1032,16 @@ class HmacSha512 {
|
|
|
1037
1032
|
throw new core.GeneralError(HmacSha512._CLASS_NAME, "bitSize", { bitSize: bits });
|
|
1038
1033
|
}
|
|
1039
1034
|
if (bits === HmacSha512.SIZE_224) {
|
|
1040
|
-
this._instance =
|
|
1035
|
+
this._instance = hmac_js.hmac.create(sha2_js.sha512_224, key);
|
|
1041
1036
|
}
|
|
1042
1037
|
else if (bits === HmacSha512.SIZE_256) {
|
|
1043
|
-
this._instance =
|
|
1038
|
+
this._instance = hmac_js.hmac.create(sha2_js.sha512_256, key);
|
|
1044
1039
|
}
|
|
1045
1040
|
else if (bits === HmacSha512.SIZE_384) {
|
|
1046
|
-
this._instance =
|
|
1041
|
+
this._instance = hmac_js.hmac.create(sha2_js.sha384, key);
|
|
1047
1042
|
}
|
|
1048
1043
|
else {
|
|
1049
|
-
this._instance =
|
|
1044
|
+
this._instance = hmac_js.hmac.create(sha2_js.sha512, key);
|
|
1050
1045
|
}
|
|
1051
1046
|
}
|
|
1052
1047
|
/**
|
|
@@ -1144,7 +1139,7 @@ class Pbkdf2 {
|
|
|
1144
1139
|
core.Guards.uint8Array(Pbkdf2._CLASS_NAME, "salt", salt);
|
|
1145
1140
|
core.Guards.number(Pbkdf2._CLASS_NAME, "iterations", iterations);
|
|
1146
1141
|
core.Guards.number(Pbkdf2._CLASS_NAME, "keyLength", keyLength);
|
|
1147
|
-
return
|
|
1142
|
+
return pbkdf2_js.pbkdf2(sha2_js.sha256, password, salt, { c: iterations, dkLen: keyLength });
|
|
1148
1143
|
}
|
|
1149
1144
|
/**
|
|
1150
1145
|
* Derive a key from the parameters using Sha512.
|
|
@@ -1159,7 +1154,7 @@ class Pbkdf2 {
|
|
|
1159
1154
|
core.Guards.uint8Array(Pbkdf2._CLASS_NAME, "salt", salt);
|
|
1160
1155
|
core.Guards.number(Pbkdf2._CLASS_NAME, "iterations", iterations);
|
|
1161
1156
|
core.Guards.number(Pbkdf2._CLASS_NAME, "keyLength", keyLength);
|
|
1162
|
-
return
|
|
1157
|
+
return pbkdf2_js.pbkdf2(sha2_js.sha512, password, salt, { c: iterations, dkLen: keyLength });
|
|
1163
1158
|
}
|
|
1164
1159
|
}
|
|
1165
1160
|
|
|
@@ -1184,7 +1179,7 @@ class Sha1 {
|
|
|
1184
1179
|
* Create a new instance of Sha1.
|
|
1185
1180
|
*/
|
|
1186
1181
|
constructor() {
|
|
1187
|
-
this._instance =
|
|
1182
|
+
this._instance = legacy_js.sha1.create();
|
|
1188
1183
|
}
|
|
1189
1184
|
/**
|
|
1190
1185
|
* Perform Sum on the block.
|
|
@@ -1247,7 +1242,7 @@ class Sha256 {
|
|
|
1247
1242
|
if (bits !== Sha256.SIZE_224 && bits !== Sha256.SIZE_256) {
|
|
1248
1243
|
throw new core.GeneralError(Sha256._CLASS_NAME, "bitSize", { bitSize: bits });
|
|
1249
1244
|
}
|
|
1250
|
-
this._instance = bits === Sha256.SIZE_256 ?
|
|
1245
|
+
this._instance = bits === Sha256.SIZE_256 ? sha2_js.sha256.create() : sha2_js.sha224.create();
|
|
1251
1246
|
}
|
|
1252
1247
|
/**
|
|
1253
1248
|
* Perform Sum 256 on the block.
|
|
@@ -1335,19 +1330,19 @@ class Sha3 {
|
|
|
1335
1330
|
}
|
|
1336
1331
|
if (bits === Sha3.SIZE_224) {
|
|
1337
1332
|
// eslint-disable-next-line camelcase
|
|
1338
|
-
this._instance =
|
|
1333
|
+
this._instance = sha3_js.sha3_224.create();
|
|
1339
1334
|
}
|
|
1340
1335
|
else if (bits === Sha3.SIZE_256) {
|
|
1341
1336
|
// eslint-disable-next-line camelcase
|
|
1342
|
-
this._instance =
|
|
1337
|
+
this._instance = sha3_js.sha3_256.create();
|
|
1343
1338
|
}
|
|
1344
1339
|
else if (bits === Sha3.SIZE_384) {
|
|
1345
1340
|
// eslint-disable-next-line camelcase
|
|
1346
|
-
this._instance =
|
|
1341
|
+
this._instance = sha3_js.sha3_384.create();
|
|
1347
1342
|
}
|
|
1348
1343
|
else {
|
|
1349
1344
|
// eslint-disable-next-line camelcase
|
|
1350
|
-
this._instance =
|
|
1345
|
+
this._instance = sha3_js.sha3_512.create();
|
|
1351
1346
|
}
|
|
1352
1347
|
}
|
|
1353
1348
|
/**
|
|
@@ -1455,16 +1450,16 @@ class Sha512 {
|
|
|
1455
1450
|
throw new core.GeneralError(Sha512._CLASS_NAME, "bitSize", { bitSize: bits });
|
|
1456
1451
|
}
|
|
1457
1452
|
if (bits === Sha512.SIZE_224) {
|
|
1458
|
-
this._instance =
|
|
1453
|
+
this._instance = sha2_js.sha512_224.create();
|
|
1459
1454
|
}
|
|
1460
1455
|
else if (bits === Sha512.SIZE_256) {
|
|
1461
|
-
this._instance =
|
|
1456
|
+
this._instance = sha2_js.sha512_256.create();
|
|
1462
1457
|
}
|
|
1463
1458
|
else if (bits === Sha512.SIZE_384) {
|
|
1464
|
-
this._instance =
|
|
1459
|
+
this._instance = sha2_js.sha384.create();
|
|
1465
1460
|
}
|
|
1466
1461
|
else {
|
|
1467
|
-
this._instance =
|
|
1462
|
+
this._instance = sha2_js.sha512.create();
|
|
1468
1463
|
}
|
|
1469
1464
|
}
|
|
1470
1465
|
/**
|
|
@@ -1526,6 +1521,48 @@ class Sha512 {
|
|
|
1526
1521
|
}
|
|
1527
1522
|
}
|
|
1528
1523
|
|
|
1524
|
+
// Copyright 2024 IOTA Stiftung.
|
|
1525
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
1526
|
+
/**
|
|
1527
|
+
* Helper class for working with PEM (Privacy-Enhanced Mail) formatted data.
|
|
1528
|
+
*/
|
|
1529
|
+
class PemHelper {
|
|
1530
|
+
/**
|
|
1531
|
+
* Runtime name for the class.
|
|
1532
|
+
* @internal
|
|
1533
|
+
*/
|
|
1534
|
+
static _CLASS_NAME = "PemHelper";
|
|
1535
|
+
/**
|
|
1536
|
+
* Strip the PEM content of its headers, footers, and newlines.
|
|
1537
|
+
* @param pemContent The PEM content to strip.
|
|
1538
|
+
* @returns The stripped PEM content in bas64 format.
|
|
1539
|
+
*/
|
|
1540
|
+
static stripPemMarkers(pemContent) {
|
|
1541
|
+
core.Guards.string(PemHelper._CLASS_NAME, "pemContent", pemContent);
|
|
1542
|
+
return pemContent
|
|
1543
|
+
.replace(/-----BEGIN.*-----/, "")
|
|
1544
|
+
.replace(/-----END.*-----/, "")
|
|
1545
|
+
.replace(/\n/g, "")
|
|
1546
|
+
.trim();
|
|
1547
|
+
}
|
|
1548
|
+
/**
|
|
1549
|
+
* Format the PEM content to have a specific line length.
|
|
1550
|
+
* @param marker The marker for the PEM content, e.g. RSA PRIVATE KEY
|
|
1551
|
+
* @param base64Content The base64 content to format.
|
|
1552
|
+
* @param lineLength The length of each line in the PEM content, default is 64 characters.
|
|
1553
|
+
* @returns The formatted PEM content.
|
|
1554
|
+
*/
|
|
1555
|
+
static formatPem(marker, base64Content, lineLength = 64) {
|
|
1556
|
+
core.Guards.stringValue(PemHelper._CLASS_NAME, "marker", marker);
|
|
1557
|
+
core.Guards.stringBase64(PemHelper._CLASS_NAME, "base64Content", base64Content);
|
|
1558
|
+
const lines = [];
|
|
1559
|
+
for (let i = 0; i < base64Content.length; i += lineLength) {
|
|
1560
|
+
lines.push(base64Content.slice(i, i + lineLength));
|
|
1561
|
+
}
|
|
1562
|
+
return [`-----BEGIN ${marker}-----`, ...lines, `-----END ${marker}-----`].join("\n");
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
|
|
1529
1566
|
// Copyright 2024 IOTA Stiftung.
|
|
1530
1567
|
// SPDX-License-Identifier: Apache-2.0.
|
|
1531
1568
|
/**
|
|
@@ -1544,7 +1581,7 @@ class Bip39 {
|
|
|
1544
1581
|
* @returns The random mnemonic.
|
|
1545
1582
|
* @throws Error if the length is not a multiple of 32.
|
|
1546
1583
|
*/
|
|
1547
|
-
static randomMnemonic(strength = 256, words =
|
|
1584
|
+
static randomMnemonic(strength = 256, words = english_js.wordlist) {
|
|
1548
1585
|
core.Guards.number(Bip39._CLASS_NAME, "strength", strength);
|
|
1549
1586
|
core.Guards.arrayValue(Bip39._CLASS_NAME, "words", words);
|
|
1550
1587
|
if (strength % 32 !== 0) {
|
|
@@ -1559,7 +1596,7 @@ class Bip39 {
|
|
|
1559
1596
|
* @returns The mnemonic.
|
|
1560
1597
|
* @throws Error if the length of the entropy is not a multiple of 4, or is less than 16 or greater than 32.
|
|
1561
1598
|
*/
|
|
1562
|
-
static entropyToMnemonic(entropy, words =
|
|
1599
|
+
static entropyToMnemonic(entropy, words = english_js.wordlist) {
|
|
1563
1600
|
core.Guards.uint8Array(Bip39._CLASS_NAME, "entropy", entropy);
|
|
1564
1601
|
core.Guards.arrayValue(Bip39._CLASS_NAME, "words", words);
|
|
1565
1602
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
|
@@ -1584,16 +1621,31 @@ class Bip39 {
|
|
|
1584
1621
|
* @returns The entropy.
|
|
1585
1622
|
* @throws Error if the number of words is not a multiple of 3.
|
|
1586
1623
|
*/
|
|
1587
|
-
static mnemonicToEntropy(mnemonic, words =
|
|
1624
|
+
static mnemonicToEntropy(mnemonic, words = english_js.wordlist) {
|
|
1588
1625
|
core.Guards.stringValue(Bip39._CLASS_NAME, "mnemonic", mnemonic);
|
|
1589
1626
|
core.Guards.arrayValue(Bip39._CLASS_NAME, "words", words);
|
|
1590
1627
|
return bip39__namespace.mnemonicToEntropy(mnemonic, words);
|
|
1591
1628
|
}
|
|
1629
|
+
/**
|
|
1630
|
+
* Validate the mnemonic.
|
|
1631
|
+
* @param mnemonic The mnemonic to validate.
|
|
1632
|
+
* @param wordCount The expected number of words in the mnemonic, defaults to 24.
|
|
1633
|
+
* @param words The wordlist to use, defaults to the English wordlist.
|
|
1634
|
+
* @returns True if the mnemonic is valid.
|
|
1635
|
+
*/
|
|
1636
|
+
static validateMnemonic(mnemonic, wordCount = 24, words = english_js.wordlist) {
|
|
1637
|
+
core.Guards.string(Bip39._CLASS_NAME, "mnemonic", mnemonic);
|
|
1638
|
+
core.Guards.integer(Bip39._CLASS_NAME, "wordCount", wordCount);
|
|
1639
|
+
const mnemonicSplit = mnemonic.split(/\s+/);
|
|
1640
|
+
if (mnemonicSplit.length !== wordCount) {
|
|
1641
|
+
return false;
|
|
1642
|
+
}
|
|
1643
|
+
return bip39__namespace.validateMnemonic(mnemonic, words);
|
|
1644
|
+
}
|
|
1592
1645
|
}
|
|
1593
1646
|
|
|
1594
1647
|
// Copyright 2024 IOTA Stiftung.
|
|
1595
1648
|
// SPDX-License-Identifier: Apache-2.0.
|
|
1596
|
-
/* eslint-disable no-bitwise */
|
|
1597
1649
|
/**
|
|
1598
1650
|
* Perform HOTP.
|
|
1599
1651
|
* Implementation of https://datatracker.ietf.org/doc/html/rfc4226 .
|
|
@@ -1812,6 +1864,7 @@ exports.KeyType = KeyType;
|
|
|
1812
1864
|
exports.PasswordGenerator = PasswordGenerator;
|
|
1813
1865
|
exports.PasswordValidator = PasswordValidator;
|
|
1814
1866
|
exports.Pbkdf2 = Pbkdf2;
|
|
1867
|
+
exports.PemHelper = PemHelper;
|
|
1815
1868
|
exports.Secp256k1 = Secp256k1;
|
|
1816
1869
|
exports.Sha1 = Sha1;
|
|
1817
1870
|
exports.Sha256 = Sha256;
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import { bech32 } from '@scure/base';
|
|
2
2
|
import { Guards, BaseError, GeneralError, Is, Uint8ArrayHelper, Converter, GuardError, Base32, RandomHelper, Validation } from '@twin.org/core';
|
|
3
|
-
import { ed25519
|
|
4
|
-
import { secp256k1 } from '@noble/curves/secp256k1';
|
|
5
|
-
import { blake2b } from '@noble/hashes/
|
|
3
|
+
import { ed25519 } from '@noble/curves/ed25519.js';
|
|
4
|
+
import { secp256k1 } from '@noble/curves/secp256k1.js';
|
|
5
|
+
import { blake2b } from '@noble/hashes/blake2.js';
|
|
6
6
|
import { HDKey as HDKey$1 } from '@scure/bip32';
|
|
7
7
|
import { HDKey } from 'micro-key-producer/slip10.js';
|
|
8
|
-
import { chacha20poly1305 } from '@noble/ciphers/chacha';
|
|
9
|
-
import { blake3 } from '@noble/hashes/blake3';
|
|
10
|
-
import { hmac } from '@noble/hashes/hmac';
|
|
11
|
-
import { sha1 } from '@noble/hashes/
|
|
12
|
-
import { sha256, sha224 } from '@noble/hashes/
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import { sha3_224, sha3_256, sha3_384, sha3_512 } from '@noble/hashes/sha3';
|
|
8
|
+
import { chacha20poly1305 } from '@noble/ciphers/chacha.js';
|
|
9
|
+
import { blake3 } from '@noble/hashes/blake3.js';
|
|
10
|
+
import { hmac } from '@noble/hashes/hmac.js';
|
|
11
|
+
import { sha1 } from '@noble/hashes/legacy.js';
|
|
12
|
+
import { sha256, sha224, sha512_224, sha512_256, sha384, sha512 } from '@noble/hashes/sha2.js';
|
|
13
|
+
import { pbkdf2 } from '@noble/hashes/pbkdf2.js';
|
|
14
|
+
import { sha3_224, sha3_256, sha3_384, sha3_512 } from '@noble/hashes/sha3.js';
|
|
16
15
|
import * as bip39 from '@scure/bip39';
|
|
17
|
-
import { wordlist } from '@scure/bip39/wordlists/english';
|
|
16
|
+
import { wordlist } from '@scure/bip39/wordlists/english.js';
|
|
18
17
|
import * as otp from 'micro-key-producer/otp.js';
|
|
19
18
|
|
|
20
19
|
// Copyright 2024 IOTA Stiftung.
|
|
@@ -185,7 +184,7 @@ class Ed25519 {
|
|
|
185
184
|
// The ASN.1 sequence is 48 46 02 01 00 30 05 06 03 2b 65 70 04 20 04 20 (0x302e020100300506032b657004220420)
|
|
186
185
|
const pkcs8Prefix = new Uint8Array([48, 46, 2, 1, 0, 48, 5, 6, 3, 43, 101, 112, 4, 34, 4, 32]);
|
|
187
186
|
const fullKey = Uint8ArrayHelper.concat([pkcs8Prefix, privateKey]);
|
|
188
|
-
return crypto.subtle.importKey("pkcs8", fullKey, "Ed25519", true, ["sign"]);
|
|
187
|
+
return crypto.subtle.importKey("pkcs8", new Uint8Array(fullKey), "Ed25519", true, ["sign"]);
|
|
189
188
|
}
|
|
190
189
|
/**
|
|
191
190
|
* Convert a crypto key to raw private key.
|
|
@@ -249,11 +248,11 @@ class Secp256k1 {
|
|
|
249
248
|
if (privateKey.length !== Secp256k1.PRIVATE_KEY_SIZE) {
|
|
250
249
|
throw new GeneralError(Secp256k1._CLASS_NAME, "privateKeyLength", {
|
|
251
250
|
requiredSize: Secp256k1.PRIVATE_KEY_SIZE,
|
|
252
|
-
actualSize: privateKey
|
|
251
|
+
actualSize: privateKey.length
|
|
253
252
|
});
|
|
254
253
|
}
|
|
255
|
-
const res = secp256k1.sign(block, privateKey);
|
|
256
|
-
return res
|
|
254
|
+
const res = secp256k1.sign(block, privateKey, { prehash: false });
|
|
255
|
+
return res;
|
|
257
256
|
}
|
|
258
257
|
/**
|
|
259
258
|
* Verify reports whether sig is a valid signature of block by publicKey.
|
|
@@ -274,7 +273,7 @@ class Secp256k1 {
|
|
|
274
273
|
});
|
|
275
274
|
}
|
|
276
275
|
try {
|
|
277
|
-
return secp256k1.verify(signature, block, publicKey);
|
|
276
|
+
return secp256k1.verify(signature, block, publicKey, { prehash: false });
|
|
278
277
|
}
|
|
279
278
|
catch {
|
|
280
279
|
return false;
|
|
@@ -462,7 +461,6 @@ const KeyType = {
|
|
|
462
461
|
|
|
463
462
|
// Copyright 2024 IOTA Stiftung.
|
|
464
463
|
// SPDX-License-Identifier: Apache-2.0.
|
|
465
|
-
/* eslint-disable no-bitwise */
|
|
466
464
|
/**
|
|
467
465
|
* Class to help with slip0010 key derivation
|
|
468
466
|
* https://github.com/satoshilabs/slips/blob/master/slip-0010.md.
|
|
@@ -694,9 +692,6 @@ class ChaCha20Poly1305 {
|
|
|
694
692
|
|
|
695
693
|
// Copyright 2024 IOTA Stiftung.
|
|
696
694
|
// SPDX-License-Identifier: Apache-2.0.
|
|
697
|
-
/**
|
|
698
|
-
* This is a TypeScript port of https://github.com/katzenpost/core/blob/master/crypto/extra25519/extra25519.go.
|
|
699
|
-
*/
|
|
700
695
|
/**
|
|
701
696
|
* Implementation of X25519.
|
|
702
697
|
*/
|
|
@@ -713,7 +708,7 @@ class X25519 {
|
|
|
713
708
|
*/
|
|
714
709
|
static convertPrivateKeyToX25519(ed25519PrivateKey) {
|
|
715
710
|
Guards.uint8Array(X25519._CLASS_NAME, "ed25519PrivateKey", ed25519PrivateKey);
|
|
716
|
-
return
|
|
711
|
+
return ed25519.utils.toMontgomerySecret(ed25519PrivateKey.slice(0, Ed25519.PRIVATE_KEY_SIZE));
|
|
717
712
|
}
|
|
718
713
|
/**
|
|
719
714
|
* Convert Ed25519 public key to X25519 public key.
|
|
@@ -723,7 +718,7 @@ class X25519 {
|
|
|
723
718
|
*/
|
|
724
719
|
static convertPublicKeyToX25519(ed25519PublicKey) {
|
|
725
720
|
Guards.uint8Array(X25519._CLASS_NAME, "ed25519PublicKey", ed25519PublicKey);
|
|
726
|
-
return
|
|
721
|
+
return ed25519.utils.toMontgomery(ed25519PublicKey);
|
|
727
722
|
}
|
|
728
723
|
}
|
|
729
724
|
|
|
@@ -1504,6 +1499,48 @@ class Sha512 {
|
|
|
1504
1499
|
}
|
|
1505
1500
|
}
|
|
1506
1501
|
|
|
1502
|
+
// Copyright 2024 IOTA Stiftung.
|
|
1503
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
1504
|
+
/**
|
|
1505
|
+
* Helper class for working with PEM (Privacy-Enhanced Mail) formatted data.
|
|
1506
|
+
*/
|
|
1507
|
+
class PemHelper {
|
|
1508
|
+
/**
|
|
1509
|
+
* Runtime name for the class.
|
|
1510
|
+
* @internal
|
|
1511
|
+
*/
|
|
1512
|
+
static _CLASS_NAME = "PemHelper";
|
|
1513
|
+
/**
|
|
1514
|
+
* Strip the PEM content of its headers, footers, and newlines.
|
|
1515
|
+
* @param pemContent The PEM content to strip.
|
|
1516
|
+
* @returns The stripped PEM content in bas64 format.
|
|
1517
|
+
*/
|
|
1518
|
+
static stripPemMarkers(pemContent) {
|
|
1519
|
+
Guards.string(PemHelper._CLASS_NAME, "pemContent", pemContent);
|
|
1520
|
+
return pemContent
|
|
1521
|
+
.replace(/-----BEGIN.*-----/, "")
|
|
1522
|
+
.replace(/-----END.*-----/, "")
|
|
1523
|
+
.replace(/\n/g, "")
|
|
1524
|
+
.trim();
|
|
1525
|
+
}
|
|
1526
|
+
/**
|
|
1527
|
+
* Format the PEM content to have a specific line length.
|
|
1528
|
+
* @param marker The marker for the PEM content, e.g. RSA PRIVATE KEY
|
|
1529
|
+
* @param base64Content The base64 content to format.
|
|
1530
|
+
* @param lineLength The length of each line in the PEM content, default is 64 characters.
|
|
1531
|
+
* @returns The formatted PEM content.
|
|
1532
|
+
*/
|
|
1533
|
+
static formatPem(marker, base64Content, lineLength = 64) {
|
|
1534
|
+
Guards.stringValue(PemHelper._CLASS_NAME, "marker", marker);
|
|
1535
|
+
Guards.stringBase64(PemHelper._CLASS_NAME, "base64Content", base64Content);
|
|
1536
|
+
const lines = [];
|
|
1537
|
+
for (let i = 0; i < base64Content.length; i += lineLength) {
|
|
1538
|
+
lines.push(base64Content.slice(i, i + lineLength));
|
|
1539
|
+
}
|
|
1540
|
+
return [`-----BEGIN ${marker}-----`, ...lines, `-----END ${marker}-----`].join("\n");
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1507
1544
|
// Copyright 2024 IOTA Stiftung.
|
|
1508
1545
|
// SPDX-License-Identifier: Apache-2.0.
|
|
1509
1546
|
/**
|
|
@@ -1567,11 +1604,26 @@ class Bip39 {
|
|
|
1567
1604
|
Guards.arrayValue(Bip39._CLASS_NAME, "words", words);
|
|
1568
1605
|
return bip39.mnemonicToEntropy(mnemonic, words);
|
|
1569
1606
|
}
|
|
1607
|
+
/**
|
|
1608
|
+
* Validate the mnemonic.
|
|
1609
|
+
* @param mnemonic The mnemonic to validate.
|
|
1610
|
+
* @param wordCount The expected number of words in the mnemonic, defaults to 24.
|
|
1611
|
+
* @param words The wordlist to use, defaults to the English wordlist.
|
|
1612
|
+
* @returns True if the mnemonic is valid.
|
|
1613
|
+
*/
|
|
1614
|
+
static validateMnemonic(mnemonic, wordCount = 24, words = wordlist) {
|
|
1615
|
+
Guards.string(Bip39._CLASS_NAME, "mnemonic", mnemonic);
|
|
1616
|
+
Guards.integer(Bip39._CLASS_NAME, "wordCount", wordCount);
|
|
1617
|
+
const mnemonicSplit = mnemonic.split(/\s+/);
|
|
1618
|
+
if (mnemonicSplit.length !== wordCount) {
|
|
1619
|
+
return false;
|
|
1620
|
+
}
|
|
1621
|
+
return bip39.validateMnemonic(mnemonic, words);
|
|
1622
|
+
}
|
|
1570
1623
|
}
|
|
1571
1624
|
|
|
1572
1625
|
// Copyright 2024 IOTA Stiftung.
|
|
1573
1626
|
// SPDX-License-Identifier: Apache-2.0.
|
|
1574
|
-
/* eslint-disable no-bitwise */
|
|
1575
1627
|
/**
|
|
1576
1628
|
* Perform HOTP.
|
|
1577
1629
|
* Implementation of https://datatracker.ietf.org/doc/html/rfc4226 .
|
|
@@ -1774,4 +1826,4 @@ class PasswordValidator {
|
|
|
1774
1826
|
}
|
|
1775
1827
|
}
|
|
1776
1828
|
|
|
1777
|
-
export { Bech32, Bip32Path, Bip39, Bip44, Blake2b, Blake3, ChaCha20Poly1305, Ed25519, HmacSha1, HmacSha256, HmacSha512, Hotp, KeyType, PasswordGenerator, PasswordValidator, Pbkdf2, Secp256k1, Sha1, Sha256, Sha3, Sha512, Slip0010, Totp, X25519, Zip215 };
|
|
1829
|
+
export { Bech32, Bip32Path, Bip39, Bip44, Blake2b, Blake3, ChaCha20Poly1305, Ed25519, HmacSha1, HmacSha256, HmacSha512, Hotp, KeyType, PasswordGenerator, PasswordValidator, Pbkdf2, PemHelper, Secp256k1, Sha1, Sha256, Sha3, Sha512, Slip0010, Totp, X25519, Zip215 };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper class for working with PEM (Privacy-Enhanced Mail) formatted data.
|
|
3
|
+
*/
|
|
4
|
+
export declare class PemHelper {
|
|
5
|
+
/**
|
|
6
|
+
* Strip the PEM content of its headers, footers, and newlines.
|
|
7
|
+
* @param pemContent The PEM content to strip.
|
|
8
|
+
* @returns The stripped PEM content in bas64 format.
|
|
9
|
+
*/
|
|
10
|
+
static stripPemMarkers(pemContent: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Format the PEM content to have a specific line length.
|
|
13
|
+
* @param marker The marker for the PEM content, e.g. RSA PRIVATE KEY
|
|
14
|
+
* @param base64Content The base64 content to format.
|
|
15
|
+
* @param lineLength The length of each line in the PEM content, default is 64 characters.
|
|
16
|
+
* @returns The formatted PEM content.
|
|
17
|
+
*/
|
|
18
|
+
static formatPem(marker: string, base64Content: string, lineLength?: number): string;
|
|
19
|
+
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export * from "./hashes/sha1";
|
|
|
15
15
|
export * from "./hashes/sha256";
|
|
16
16
|
export * from "./hashes/sha3";
|
|
17
17
|
export * from "./hashes/sha512";
|
|
18
|
+
export * from "./helpers/pemHelper";
|
|
18
19
|
export * from "./keys/bip32Path";
|
|
19
20
|
export * from "./keys/bip39";
|
|
20
21
|
export * from "./keys/slip0010";
|
|
@@ -33,4 +33,12 @@ export declare class Bip39 {
|
|
|
33
33
|
* @throws Error if the number of words is not a multiple of 3.
|
|
34
34
|
*/
|
|
35
35
|
static mnemonicToEntropy(mnemonic: string, words?: string[]): Uint8Array;
|
|
36
|
+
/**
|
|
37
|
+
* Validate the mnemonic.
|
|
38
|
+
* @param mnemonic The mnemonic to validate.
|
|
39
|
+
* @param wordCount The expected number of words in the mnemonic, defaults to 24.
|
|
40
|
+
* @param words The wordlist to use, defaults to the English wordlist.
|
|
41
|
+
* @returns True if the mnemonic is valid.
|
|
42
|
+
*/
|
|
43
|
+
static validateMnemonic(mnemonic: string, wordCount?: number, words?: string[]): boolean;
|
|
36
44
|
}
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,200 @@
|
|
|
1
1
|
# @twin.org/crypto - Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.2-next.10](https://github.com/twinfoundation/framework/compare/crypto-v0.0.2-next.9...crypto-v0.0.2-next.10) (2025-09-11)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Miscellaneous Chores
|
|
7
|
+
|
|
8
|
+
* **crypto:** Synchronize repo versions
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @twin.org/core bumped from 0.0.2-next.9 to 0.0.2-next.10
|
|
16
|
+
* @twin.org/nameof bumped from 0.0.2-next.9 to 0.0.2-next.10
|
|
17
|
+
* devDependencies
|
|
18
|
+
* @twin.org/nameof-transformer bumped from 0.0.2-next.9 to 0.0.2-next.10
|
|
19
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.9 to 0.0.2-next.10
|
|
20
|
+
|
|
21
|
+
## [0.0.2-next.9](https://github.com/twinfoundation/framework/compare/crypto-v0.0.2-next.8...crypto-v0.0.2-next.9) (2025-09-08)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### Features
|
|
25
|
+
|
|
26
|
+
* add mnemonic validation ([4b43491](https://github.com/twinfoundation/framework/commit/4b43491cf04bb626c27faea66e5c74b3971b111d))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### Dependencies
|
|
30
|
+
|
|
31
|
+
* The following workspace dependencies were updated
|
|
32
|
+
* dependencies
|
|
33
|
+
* @twin.org/core bumped from 0.0.2-next.8 to 0.0.2-next.9
|
|
34
|
+
* @twin.org/nameof bumped from 0.0.2-next.8 to 0.0.2-next.9
|
|
35
|
+
* devDependencies
|
|
36
|
+
* @twin.org/nameof-transformer bumped from 0.0.2-next.8 to 0.0.2-next.9
|
|
37
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.8 to 0.0.2-next.9
|
|
38
|
+
|
|
39
|
+
## [0.0.2-next.8](https://github.com/twinfoundation/framework/compare/crypto-v0.0.2-next.7...crypto-v0.0.2-next.8) (2025-09-05)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
### Miscellaneous Chores
|
|
43
|
+
|
|
44
|
+
* **crypto:** Synchronize repo versions
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
### Dependencies
|
|
48
|
+
|
|
49
|
+
* The following workspace dependencies were updated
|
|
50
|
+
* dependencies
|
|
51
|
+
* @twin.org/core bumped from 0.0.2-next.7 to 0.0.2-next.8
|
|
52
|
+
* @twin.org/nameof bumped from 0.0.2-next.7 to 0.0.2-next.8
|
|
53
|
+
* devDependencies
|
|
54
|
+
* @twin.org/nameof-transformer bumped from 0.0.2-next.7 to 0.0.2-next.8
|
|
55
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.7 to 0.0.2-next.8
|
|
56
|
+
|
|
57
|
+
## [0.0.2-next.7](https://github.com/twinfoundation/framework/compare/crypto-v0.0.2-next.6...crypto-v0.0.2-next.7) (2025-08-29)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
### Features
|
|
61
|
+
|
|
62
|
+
* eslint migration to flat config ([74427d7](https://github.com/twinfoundation/framework/commit/74427d78d342167f7850e49ab87269326355befe))
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
### Dependencies
|
|
66
|
+
|
|
67
|
+
* The following workspace dependencies were updated
|
|
68
|
+
* dependencies
|
|
69
|
+
* @twin.org/core bumped from 0.0.2-next.6 to 0.0.2-next.7
|
|
70
|
+
* @twin.org/nameof bumped from 0.0.2-next.6 to 0.0.2-next.7
|
|
71
|
+
* devDependencies
|
|
72
|
+
* @twin.org/nameof-transformer bumped from 0.0.2-next.6 to 0.0.2-next.7
|
|
73
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.6 to 0.0.2-next.7
|
|
74
|
+
|
|
75
|
+
## [0.0.2-next.6](https://github.com/twinfoundation/framework/compare/crypto-v0.0.2-next.5...crypto-v0.0.2-next.6) (2025-08-27)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
### Miscellaneous Chores
|
|
79
|
+
|
|
80
|
+
* **crypto:** Synchronize repo versions
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
### Dependencies
|
|
84
|
+
|
|
85
|
+
* The following workspace dependencies were updated
|
|
86
|
+
* dependencies
|
|
87
|
+
* @twin.org/core bumped from 0.0.2-next.5 to 0.0.2-next.6
|
|
88
|
+
* @twin.org/nameof bumped from 0.0.2-next.5 to 0.0.2-next.6
|
|
89
|
+
* devDependencies
|
|
90
|
+
* @twin.org/nameof-transformer bumped from 0.0.2-next.5 to 0.0.2-next.6
|
|
91
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.5 to 0.0.2-next.6
|
|
92
|
+
|
|
93
|
+
## [0.0.2-next.5](https://github.com/twinfoundation/framework/compare/crypto-v0.0.2-next.4...crypto-v0.0.2-next.5) (2025-08-19)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
### Features
|
|
97
|
+
|
|
98
|
+
* use cause instead of inner for errors ([1f4acc4](https://github.com/twinfoundation/framework/commit/1f4acc4d7a6b71a134d9547da9bf40de1e1e49da))
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
### Dependencies
|
|
102
|
+
|
|
103
|
+
* The following workspace dependencies were updated
|
|
104
|
+
* dependencies
|
|
105
|
+
* @twin.org/core bumped from 0.0.2-next.4 to 0.0.2-next.5
|
|
106
|
+
* @twin.org/nameof bumped from 0.0.2-next.4 to 0.0.2-next.5
|
|
107
|
+
* devDependencies
|
|
108
|
+
* @twin.org/nameof-transformer bumped from 0.0.2-next.4 to 0.0.2-next.5
|
|
109
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.4 to 0.0.2-next.5
|
|
110
|
+
|
|
111
|
+
## [0.0.2-next.4](https://github.com/twinfoundation/framework/compare/crypto-v0.0.2-next.3...crypto-v0.0.2-next.4) (2025-08-15)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
### Features
|
|
115
|
+
|
|
116
|
+
* additional RSA methods and async ([1fceee2](https://github.com/twinfoundation/framework/commit/1fceee2d1248a24a7620846025fcf906495c07f4))
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
### Dependencies
|
|
120
|
+
|
|
121
|
+
* The following workspace dependencies were updated
|
|
122
|
+
* dependencies
|
|
123
|
+
* @twin.org/core bumped from 0.0.2-next.3 to 0.0.2-next.4
|
|
124
|
+
* @twin.org/nameof bumped from 0.0.2-next.3 to 0.0.2-next.4
|
|
125
|
+
* devDependencies
|
|
126
|
+
* @twin.org/nameof-transformer bumped from 0.0.2-next.3 to 0.0.2-next.4
|
|
127
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.3 to 0.0.2-next.4
|
|
128
|
+
|
|
129
|
+
## [0.0.2-next.3](https://github.com/twinfoundation/framework/compare/crypto-v0.0.2-next.2...crypto-v0.0.2-next.3) (2025-08-06)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
### Features
|
|
133
|
+
|
|
134
|
+
* add guards arrayEndsWith and arrayStartsWith ([95d875e](https://github.com/twinfoundation/framework/commit/95d875ec8ccb4713c145fdde941d4cfedcec2ed3))
|
|
135
|
+
* add rsa cipher support ([7af6cc6](https://github.com/twinfoundation/framework/commit/7af6cc67512d3363bd4a2f2e87bd7733c2800147))
|
|
136
|
+
* add RSA support for public key components ([7126259](https://github.com/twinfoundation/framework/commit/7126259103b758c291e52a8a03818eb822d1aad1))
|
|
137
|
+
* change method accessibility ([c1b77fc](https://github.com/twinfoundation/framework/commit/c1b77fcfb61c092a01c97aebb2fe2dc2bbaa221b))
|
|
138
|
+
* relocate core packages from tools ([bcab8f3](https://github.com/twinfoundation/framework/commit/bcab8f3160442ea4fcaf442947462504f3d6a17d))
|
|
139
|
+
* update dependencies ([f3bd015](https://github.com/twinfoundation/framework/commit/f3bd015efd169196b7e0335f5cab876ba6ca1d75))
|
|
140
|
+
* use new shared store mechanism ([#131](https://github.com/twinfoundation/framework/issues/131)) ([934385b](https://github.com/twinfoundation/framework/commit/934385b2fbaf9f5c00a505ebf9d093bd5a425f55))
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
### Dependencies
|
|
144
|
+
|
|
145
|
+
* The following workspace dependencies were updated
|
|
146
|
+
* dependencies
|
|
147
|
+
* @twin.org/core bumped from 0.0.2-next.2 to 0.0.2-next.3
|
|
148
|
+
* @twin.org/nameof bumped from 0.0.2-next.2 to 0.0.2-next.3
|
|
149
|
+
* devDependencies
|
|
150
|
+
* @twin.org/nameof-transformer bumped from 0.0.2-next.2 to 0.0.2-next.3
|
|
151
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.2 to 0.0.2-next.3
|
|
152
|
+
|
|
153
|
+
## [0.0.2-next.2](https://github.com/twinfoundation/framework/compare/crypto-v0.0.2-next.1...crypto-v0.0.2-next.2) (2025-08-06)
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
### Features
|
|
157
|
+
|
|
158
|
+
* add guards arrayEndsWith and arrayStartsWith ([95d875e](https://github.com/twinfoundation/framework/commit/95d875ec8ccb4713c145fdde941d4cfedcec2ed3))
|
|
159
|
+
* add rsa cipher support ([7af6cc6](https://github.com/twinfoundation/framework/commit/7af6cc67512d3363bd4a2f2e87bd7733c2800147))
|
|
160
|
+
* change method accessibility ([c1b77fc](https://github.com/twinfoundation/framework/commit/c1b77fcfb61c092a01c97aebb2fe2dc2bbaa221b))
|
|
161
|
+
* relocate core packages from tools ([bcab8f3](https://github.com/twinfoundation/framework/commit/bcab8f3160442ea4fcaf442947462504f3d6a17d))
|
|
162
|
+
* update dependencies ([f3bd015](https://github.com/twinfoundation/framework/commit/f3bd015efd169196b7e0335f5cab876ba6ca1d75))
|
|
163
|
+
* use new shared store mechanism ([#131](https://github.com/twinfoundation/framework/issues/131)) ([934385b](https://github.com/twinfoundation/framework/commit/934385b2fbaf9f5c00a505ebf9d093bd5a425f55))
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
### Dependencies
|
|
167
|
+
|
|
168
|
+
* The following workspace dependencies were updated
|
|
169
|
+
* dependencies
|
|
170
|
+
* @twin.org/core bumped from 0.0.2-next.1 to 0.0.2-next.2
|
|
171
|
+
* @twin.org/nameof bumped from 0.0.2-next.1 to 0.0.2-next.2
|
|
172
|
+
* devDependencies
|
|
173
|
+
* @twin.org/nameof-transformer bumped from 0.0.2-next.1 to 0.0.2-next.2
|
|
174
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.1 to 0.0.2-next.2
|
|
175
|
+
|
|
176
|
+
## [0.0.2-next.1](https://github.com/twinfoundation/framework/compare/crypto-v0.0.2-next.0...crypto-v0.0.2-next.1) (2025-08-06)
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
### Features
|
|
180
|
+
|
|
181
|
+
* add guards arrayEndsWith and arrayStartsWith ([95d875e](https://github.com/twinfoundation/framework/commit/95d875ec8ccb4713c145fdde941d4cfedcec2ed3))
|
|
182
|
+
* add rsa cipher support ([7af6cc6](https://github.com/twinfoundation/framework/commit/7af6cc67512d3363bd4a2f2e87bd7733c2800147))
|
|
183
|
+
* relocate core packages from tools ([bcab8f3](https://github.com/twinfoundation/framework/commit/bcab8f3160442ea4fcaf442947462504f3d6a17d))
|
|
184
|
+
* update dependencies ([f3bd015](https://github.com/twinfoundation/framework/commit/f3bd015efd169196b7e0335f5cab876ba6ca1d75))
|
|
185
|
+
* use new shared store mechanism ([#131](https://github.com/twinfoundation/framework/issues/131)) ([934385b](https://github.com/twinfoundation/framework/commit/934385b2fbaf9f5c00a505ebf9d093bd5a425f55))
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
### Dependencies
|
|
189
|
+
|
|
190
|
+
* The following workspace dependencies were updated
|
|
191
|
+
* dependencies
|
|
192
|
+
* @twin.org/core bumped from 0.0.2-next.0 to 0.0.2-next.1
|
|
193
|
+
* @twin.org/nameof bumped from 0.0.2-next.0 to 0.0.2-next.1
|
|
194
|
+
* devDependencies
|
|
195
|
+
* @twin.org/nameof-transformer bumped from 0.0.2-next.0 to 0.0.2-next.1
|
|
196
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.0 to 0.0.2-next.1
|
|
197
|
+
|
|
3
198
|
## 0.0.1 (2025-07-03)
|
|
4
199
|
|
|
5
200
|
|
|
@@ -135,3 +135,37 @@ The entropy.
|
|
|
135
135
|
#### Throws
|
|
136
136
|
|
|
137
137
|
Error if the number of words is not a multiple of 3.
|
|
138
|
+
|
|
139
|
+
***
|
|
140
|
+
|
|
141
|
+
### validateMnemonic()
|
|
142
|
+
|
|
143
|
+
> `static` **validateMnemonic**(`mnemonic`, `wordCount`, `words`): `boolean`
|
|
144
|
+
|
|
145
|
+
Validate the mnemonic.
|
|
146
|
+
|
|
147
|
+
#### Parameters
|
|
148
|
+
|
|
149
|
+
##### mnemonic
|
|
150
|
+
|
|
151
|
+
`string`
|
|
152
|
+
|
|
153
|
+
The mnemonic to validate.
|
|
154
|
+
|
|
155
|
+
##### wordCount
|
|
156
|
+
|
|
157
|
+
`number` = `24`
|
|
158
|
+
|
|
159
|
+
The expected number of words in the mnemonic, defaults to 24.
|
|
160
|
+
|
|
161
|
+
##### words
|
|
162
|
+
|
|
163
|
+
`string`[] = `wordlist`
|
|
164
|
+
|
|
165
|
+
The wordlist to use, defaults to the English wordlist.
|
|
166
|
+
|
|
167
|
+
#### Returns
|
|
168
|
+
|
|
169
|
+
`boolean`
|
|
170
|
+
|
|
171
|
+
True if the mnemonic is valid.
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Class: PemHelper
|
|
2
|
+
|
|
3
|
+
Helper class for working with PEM (Privacy-Enhanced Mail) formatted data.
|
|
4
|
+
|
|
5
|
+
## Constructors
|
|
6
|
+
|
|
7
|
+
### Constructor
|
|
8
|
+
|
|
9
|
+
> **new PemHelper**(): `PemHelper`
|
|
10
|
+
|
|
11
|
+
#### Returns
|
|
12
|
+
|
|
13
|
+
`PemHelper`
|
|
14
|
+
|
|
15
|
+
## Methods
|
|
16
|
+
|
|
17
|
+
### stripPemMarkers()
|
|
18
|
+
|
|
19
|
+
> `static` **stripPemMarkers**(`pemContent`): `string`
|
|
20
|
+
|
|
21
|
+
Strip the PEM content of its headers, footers, and newlines.
|
|
22
|
+
|
|
23
|
+
#### Parameters
|
|
24
|
+
|
|
25
|
+
##### pemContent
|
|
26
|
+
|
|
27
|
+
`string`
|
|
28
|
+
|
|
29
|
+
The PEM content to strip.
|
|
30
|
+
|
|
31
|
+
#### Returns
|
|
32
|
+
|
|
33
|
+
`string`
|
|
34
|
+
|
|
35
|
+
The stripped PEM content in bas64 format.
|
|
36
|
+
|
|
37
|
+
***
|
|
38
|
+
|
|
39
|
+
### formatPem()
|
|
40
|
+
|
|
41
|
+
> `static` **formatPem**(`marker`, `base64Content`, `lineLength`): `string`
|
|
42
|
+
|
|
43
|
+
Format the PEM content to have a specific line length.
|
|
44
|
+
|
|
45
|
+
#### Parameters
|
|
46
|
+
|
|
47
|
+
##### marker
|
|
48
|
+
|
|
49
|
+
`string`
|
|
50
|
+
|
|
51
|
+
The marker for the PEM content, e.g. RSA PRIVATE KEY
|
|
52
|
+
|
|
53
|
+
##### base64Content
|
|
54
|
+
|
|
55
|
+
`string`
|
|
56
|
+
|
|
57
|
+
The base64 content to format.
|
|
58
|
+
|
|
59
|
+
##### lineLength
|
|
60
|
+
|
|
61
|
+
`number` = `64`
|
|
62
|
+
|
|
63
|
+
The length of each line in the PEM content, default is 64 characters.
|
|
64
|
+
|
|
65
|
+
#### Returns
|
|
66
|
+
|
|
67
|
+
`string`
|
|
68
|
+
|
|
69
|
+
The formatted PEM content.
|
package/docs/reference/index.md
CHANGED
package/locales/en.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/crypto",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2-next.10",
|
|
4
4
|
"description": "Contains helper methods and classes which implement cryptographic functions",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,15 +14,16 @@
|
|
|
14
14
|
"node": ">=20.0.0"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@noble/ciphers": "
|
|
18
|
-
"@noble/curves": "
|
|
19
|
-
"@noble/hashes": "
|
|
20
|
-
"@scure/base": "
|
|
21
|
-
"@scure/bip32": "
|
|
22
|
-
"@scure/bip39": "
|
|
23
|
-
"@twin.org/core": "
|
|
24
|
-
"@twin.org/nameof": "
|
|
25
|
-
"
|
|
17
|
+
"@noble/ciphers": "2.0.0",
|
|
18
|
+
"@noble/curves": "2.0.0",
|
|
19
|
+
"@noble/hashes": "2.0.0",
|
|
20
|
+
"@scure/base": "2.0.0",
|
|
21
|
+
"@scure/bip32": "2.0.0",
|
|
22
|
+
"@scure/bip39": "2.0.0",
|
|
23
|
+
"@twin.org/core": "0.0.2-next.10",
|
|
24
|
+
"@twin.org/nameof": "0.0.2-next.10",
|
|
25
|
+
"crypto-browserify": "3.12.1",
|
|
26
|
+
"micro-key-producer": "0.8.1"
|
|
26
27
|
},
|
|
27
28
|
"main": "./dist/cjs/index.cjs",
|
|
28
29
|
"module": "./dist/esm/index.mjs",
|