@twin.org/crypto 0.0.3-next.25 → 0.0.3-next.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,38 @@
1
+ // Copyright 2026 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import { argon2idAsync } from "@noble/hashes/argon2.js";
4
+ import { Guards } from "@twin.org/core";
5
+ /**
6
+ * Implementation of the Argon2id password based key derivation function.
7
+ */
8
+ export class Argon2id {
9
+ /**
10
+ * Runtime name for the class.
11
+ */
12
+ static CLASS_NAME = "Argon2id";
13
+ /**
14
+ * Derive a key from the parameters using Argon2id.
15
+ * @param password The password to derive the key from.
16
+ * @param salt The salt for the derivation.
17
+ * @param options The options for the derivation.
18
+ * @param options.t Number of iterations to perform, default 1.
19
+ * @param options.m Amount of memory to use in kibibytes, default 8.
20
+ * @param options.p Number of parallel threads to use, default 1.
21
+ * @param options.dkLen The length of the derived key in bytes, default 32.
22
+ * @param options.maxmem The maximum amount of memory to use in bytes, default 2^30.
23
+ * @returns The derived key.
24
+ */
25
+ static async hash(password, salt, options) {
26
+ Guards.uint8Array(Argon2id.CLASS_NAME, "password", password);
27
+ Guards.uint8Array(Argon2id.CLASS_NAME, "salt", salt);
28
+ const localOptions = {
29
+ t: options?.t ?? 1,
30
+ m: options?.m ?? 8,
31
+ p: options?.p ?? 1,
32
+ dkLen: options?.dkLen ?? 32,
33
+ maxmem: options?.maxmem ?? 2 ** 30
34
+ };
35
+ return argon2idAsync(password, salt, localOptions);
36
+ }
37
+ }
38
+ //# sourceMappingURL=argon2id.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"argon2id.js","sourceRoot":"","sources":["../../../src/hashes/argon2id.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGxC;;GAEG;AACH,MAAM,OAAO,QAAQ;IACpB;;OAEG;IACI,MAAM,CAAU,UAAU,cAA8B;IAE/D;;;;;;;;;;;OAWG;IACI,MAAM,CAAC,KAAK,CAAC,IAAI,CACvB,QAAoB,EACpB,IAAgB,EAChB,OAMC;QAED,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,UAAU,cAAoB,QAAQ,CAAC,CAAC;QACnE,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,UAAU,UAAgB,IAAI,CAAC,CAAC;QAC3D,MAAM,YAAY,GAAG;YACpB,CAAC,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC;YAClB,CAAC,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC;YAClB,CAAC,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC;YAClB,KAAK,EAAE,OAAO,EAAE,KAAK,IAAI,EAAE;YAC3B,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC,IAAI,EAAE;SAClC,CAAC;QACF,OAAO,aAAa,CAAC,QAAQ,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;IACpD,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { argon2idAsync } from \"@noble/hashes/argon2.js\";\nimport { Guards } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\n\n/**\n * Implementation of the Argon2id password based key derivation function.\n */\nexport class Argon2id {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<Argon2id>();\n\n\t/**\n\t * Derive a key from the parameters using Argon2id.\n\t * @param password The password to derive the key from.\n\t * @param salt The salt for the derivation.\n\t * @param options The options for the derivation.\n\t * @param options.t Number of iterations to perform, default 1.\n\t * @param options.m Amount of memory to use in kibibytes, default 8.\n\t * @param options.p Number of parallel threads to use, default 1.\n\t * @param options.dkLen The length of the derived key in bytes, default 32.\n\t * @param options.maxmem The maximum amount of memory to use in bytes, default 2^30.\n\t * @returns The derived key.\n\t */\n\tpublic static async hash(\n\t\tpassword: Uint8Array,\n\t\tsalt: Uint8Array,\n\t\toptions?: {\n\t\t\tt?: number;\n\t\t\tm?: number;\n\t\t\tp?: number;\n\t\t\tdkLen?: number;\n\t\t\tmaxmem?: number;\n\t\t}\n\t): Promise<Uint8Array> {\n\t\tGuards.uint8Array(Argon2id.CLASS_NAME, nameof(password), password);\n\t\tGuards.uint8Array(Argon2id.CLASS_NAME, nameof(salt), salt);\n\t\tconst localOptions = {\n\t\t\tt: options?.t ?? 1,\n\t\t\tm: options?.m ?? 8,\n\t\t\tp: options?.p ?? 1,\n\t\t\tdkLen: options?.dkLen ?? 32,\n\t\t\tmaxmem: options?.maxmem ?? 2 ** 30\n\t\t};\n\t\treturn argon2idAsync(password, salt, localOptions);\n\t}\n}\n"]}
package/dist/es/index.js CHANGED
@@ -7,6 +7,7 @@ export * from "./curves/ed25519.js";
7
7
  export * from "./curves/secp256k1.js";
8
8
  export * from "./curves/x25519.js";
9
9
  export * from "./curves/zip215.js";
10
+ export * from "./hashes/argon2id.js";
10
11
  export * from "./hashes/blake2b.js";
11
12
  export * from "./hashes/blake3.js";
12
13
  export * from "./hashes/hmacSha1.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,kCAAkC,CAAC;AACjD,cAAc,kCAAkC,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./address/bech32.js\";\nexport * from \"./address/bip44.js\";\nexport * from \"./ciphers/chaCha20Poly1305.js\";\nexport * from \"./curves/ed25519.js\";\nexport * from \"./curves/secp256k1.js\";\nexport * from \"./curves/x25519.js\";\nexport * from \"./curves/zip215.js\";\nexport * from \"./hashes/blake2b.js\";\nexport * from \"./hashes/blake3.js\";\nexport * from \"./hashes/hmacSha1.js\";\nexport * from \"./hashes/hmacSha256.js\";\nexport * from \"./hashes/hmacSha512.js\";\nexport * from \"./hashes/pbkdf2.js\";\nexport * from \"./hashes/sha1.js\";\nexport * from \"./hashes/sha256.js\";\nexport * from \"./hashes/sha3.js\";\nexport * from \"./hashes/sha512.js\";\nexport * from \"./helpers/integrityHelper.js\";\nexport * from \"./helpers/pemHelper.js\";\nexport * from \"./keys/bip32Path.js\";\nexport * from \"./keys/bip39.js\";\nexport * from \"./keys/slip0010.js\";\nexport * from \"./models/integrityAlgorithm.js\";\nexport * from \"./models/keyType.js\";\nexport * from \"./otp/hotp.js\";\nexport * from \"./otp/totp.js\";\nexport * from \"./passwords/passwordGenerator.js\";\nexport * from \"./passwords/passwordValidator.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,kCAAkC,CAAC;AACjD,cAAc,kCAAkC,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./address/bech32.js\";\nexport * from \"./address/bip44.js\";\nexport * from \"./ciphers/chaCha20Poly1305.js\";\nexport * from \"./curves/ed25519.js\";\nexport * from \"./curves/secp256k1.js\";\nexport * from \"./curves/x25519.js\";\nexport * from \"./curves/zip215.js\";\nexport * from \"./hashes/argon2id.js\";\nexport * from \"./hashes/blake2b.js\";\nexport * from \"./hashes/blake3.js\";\nexport * from \"./hashes/hmacSha1.js\";\nexport * from \"./hashes/hmacSha256.js\";\nexport * from \"./hashes/hmacSha512.js\";\nexport * from \"./hashes/pbkdf2.js\";\nexport * from \"./hashes/sha1.js\";\nexport * from \"./hashes/sha256.js\";\nexport * from \"./hashes/sha3.js\";\nexport * from \"./hashes/sha512.js\";\nexport * from \"./helpers/integrityHelper.js\";\nexport * from \"./helpers/pemHelper.js\";\nexport * from \"./keys/bip32Path.js\";\nexport * from \"./keys/bip39.js\";\nexport * from \"./keys/slip0010.js\";\nexport * from \"./models/integrityAlgorithm.js\";\nexport * from \"./models/keyType.js\";\nexport * from \"./otp/hotp.js\";\nexport * from \"./otp/totp.js\";\nexport * from \"./passwords/passwordGenerator.js\";\nexport * from \"./passwords/passwordValidator.js\";\n"]}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Implementation of the Argon2id password based key derivation function.
3
+ */
4
+ export declare class Argon2id {
5
+ /**
6
+ * Runtime name for the class.
7
+ */
8
+ static readonly CLASS_NAME: string;
9
+ /**
10
+ * Derive a key from the parameters using Argon2id.
11
+ * @param password The password to derive the key from.
12
+ * @param salt The salt for the derivation.
13
+ * @param options The options for the derivation.
14
+ * @param options.t Number of iterations to perform, default 1.
15
+ * @param options.m Amount of memory to use in kibibytes, default 8.
16
+ * @param options.p Number of parallel threads to use, default 1.
17
+ * @param options.dkLen The length of the derived key in bytes, default 32.
18
+ * @param options.maxmem The maximum amount of memory to use in bytes, default 2^30.
19
+ * @returns The derived key.
20
+ */
21
+ static hash(password: Uint8Array, salt: Uint8Array, options?: {
22
+ t?: number;
23
+ m?: number;
24
+ p?: number;
25
+ dkLen?: number;
26
+ maxmem?: number;
27
+ }): Promise<Uint8Array>;
28
+ }
@@ -5,6 +5,7 @@ export * from "./curves/ed25519.js";
5
5
  export * from "./curves/secp256k1.js";
6
6
  export * from "./curves/x25519.js";
7
7
  export * from "./curves/zip215.js";
8
+ export * from "./hashes/argon2id.js";
8
9
  export * from "./hashes/blake2b.js";
9
10
  export * from "./hashes/blake3.js";
10
11
  export * from "./hashes/hmacSha1.js";
package/docs/changelog.md CHANGED
@@ -1,5 +1,43 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.0.3-next.27](https://github.com/twinfoundation/framework/compare/crypto-v0.0.3-next.26...crypto-v0.0.3-next.27) (2026-03-27)
4
+
5
+
6
+ ### Features
7
+
8
+ * add crypto argon2id ([#255](https://github.com/twinfoundation/framework/issues/255)) ([27fe3a7](https://github.com/twinfoundation/framework/commit/27fe3a72eeb0f398a278ebb3f1cb9c4dd459743c))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/core bumped from 0.0.3-next.26 to 0.0.3-next.27
16
+ * @twin.org/nameof bumped from 0.0.3-next.26 to 0.0.3-next.27
17
+ * devDependencies
18
+ * @twin.org/nameof-transformer bumped from 0.0.3-next.26 to 0.0.3-next.27
19
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.3-next.26 to 0.0.3-next.27
20
+ * @twin.org/validate-locales bumped from 0.0.3-next.26 to 0.0.3-next.27
21
+
22
+ ## [0.0.3-next.26](https://github.com/twinfoundation/framework/compare/crypto-v0.0.3-next.25...crypto-v0.0.3-next.26) (2026-03-24)
23
+
24
+
25
+ ### Miscellaneous Chores
26
+
27
+ * **crypto:** Synchronize repo versions
28
+
29
+
30
+ ### Dependencies
31
+
32
+ * The following workspace dependencies were updated
33
+ * dependencies
34
+ * @twin.org/core bumped from 0.0.3-next.25 to 0.0.3-next.26
35
+ * @twin.org/nameof bumped from 0.0.3-next.25 to 0.0.3-next.26
36
+ * devDependencies
37
+ * @twin.org/nameof-transformer bumped from 0.0.3-next.25 to 0.0.3-next.26
38
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.3-next.25 to 0.0.3-next.26
39
+ * @twin.org/validate-locales bumped from 0.0.3-next.25 to 0.0.3-next.26
40
+
3
41
  ## [0.0.3-next.25](https://github.com/twinfoundation/framework/compare/crypto-v0.0.3-next.24...crypto-v0.0.3-next.25) (2026-03-23)
4
42
 
5
43
 
@@ -0,0 +1,83 @@
1
+ # Class: Argon2id
2
+
3
+ Implementation of the Argon2id password based key derivation function.
4
+
5
+ ## Constructors
6
+
7
+ ### Constructor
8
+
9
+ > **new Argon2id**(): `Argon2id`
10
+
11
+ #### Returns
12
+
13
+ `Argon2id`
14
+
15
+ ## Properties
16
+
17
+ ### CLASS\_NAME {#class_name}
18
+
19
+ > `readonly` `static` **CLASS\_NAME**: `string`
20
+
21
+ Runtime name for the class.
22
+
23
+ ## Methods
24
+
25
+ ### hash() {#hash}
26
+
27
+ > `static` **hash**(`password`, `salt`, `options?`): `Promise`\<`Uint8Array`\<`ArrayBufferLike`\>\>
28
+
29
+ Derive a key from the parameters using Argon2id.
30
+
31
+ #### Parameters
32
+
33
+ ##### password
34
+
35
+ `Uint8Array`
36
+
37
+ The password to derive the key from.
38
+
39
+ ##### salt
40
+
41
+ `Uint8Array`
42
+
43
+ The salt for the derivation.
44
+
45
+ ##### options?
46
+
47
+ The options for the derivation.
48
+
49
+ ###### t?
50
+
51
+ `number`
52
+
53
+ Number of iterations to perform, default 1.
54
+
55
+ ###### m?
56
+
57
+ `number`
58
+
59
+ Amount of memory to use in kibibytes, default 8.
60
+
61
+ ###### p?
62
+
63
+ `number`
64
+
65
+ Number of parallel threads to use, default 1.
66
+
67
+ ###### dkLen?
68
+
69
+ `number`
70
+
71
+ The length of the derived key in bytes, default 32.
72
+
73
+ ###### maxmem?
74
+
75
+ `number`
76
+
77
+ The maximum amount of memory to use in bytes, default 2^30.
78
+
79
+ #### Returns
80
+
81
+ `Promise`\<`Uint8Array`\<`ArrayBufferLike`\>\>
82
+
83
+ The derived key.
@@ -9,6 +9,7 @@
9
9
  - [Secp256k1](classes/Secp256k1.md)
10
10
  - [X25519](classes/X25519.md)
11
11
  - [Zip215](classes/Zip215.md)
12
+ - [Argon2id](classes/Argon2id.md)
12
13
  - [Blake2b](classes/Blake2b.md)
13
14
  - [Blake3](classes/Blake3.md)
14
15
  - [HmacSha1](classes/HmacSha1.md)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/crypto",
3
- "version": "0.0.3-next.25",
3
+ "version": "0.0.3-next.27",
4
4
  "description": "Helper methods and classes which implement cryptographic functions",
5
5
  "repository": {
6
6
  "type": "git",
@@ -20,8 +20,8 @@
20
20
  "@scure/base": "2.0.0",
21
21
  "@scure/bip32": "2.0.1",
22
22
  "@scure/bip39": "2.0.1",
23
- "@twin.org/core": "0.0.3-next.25",
24
- "@twin.org/nameof": "0.0.3-next.25",
23
+ "@twin.org/core": "0.0.3-next.27",
24
+ "@twin.org/nameof": "0.0.3-next.27",
25
25
  "crypto-browserify": "3.12.1",
26
26
  "micro-key-producer": "0.8.5"
27
27
  },