@fgv/ts-extras-argon2 5.1.0-47 → 5.1.0-49

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.
Files changed (37) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +18 -8
  3. package/.rush/temp/chunked-rush-logs/ts-extras-argon2.build.chunks.jsonl +0 -9
  4. package/.rush/temp/eb061fb1c7e3a355a03b204add873a27586efa0d.tar.log +0 -48
  5. package/.rush/temp/operation/build/all.log +0 -9
  6. package/.rush/temp/operation/build/log-chunks.jsonl +0 -9
  7. package/.rush/temp/operation/build/state.json +0 -3
  8. package/.rush/temp/shrinkwrap-deps.json +0 -694
  9. package/config/api-extractor.json +0 -343
  10. package/config/jest.config.json +0 -14
  11. package/config/rig.json +0 -4
  12. package/dist/test/unit/argon2/crossRuntime.test.js +0 -117
  13. package/dist/test/unit/argon2/crossRuntime.test.js.map +0 -1
  14. package/dist/test/unit/argon2/nodeArgon2Provider.test.js +0 -144
  15. package/dist/test/unit/argon2/nodeArgon2Provider.test.js.map +0 -1
  16. package/eslint.config.js +0 -15
  17. package/etc/ts-extras-argon2.api.md +0 -20
  18. package/lib/test/unit/argon2/crossRuntime.test.d.ts +0 -2
  19. package/lib/test/unit/argon2/crossRuntime.test.d.ts.map +0 -1
  20. package/lib/test/unit/argon2/crossRuntime.test.js +0 -119
  21. package/lib/test/unit/argon2/crossRuntime.test.js.map +0 -1
  22. package/lib/test/unit/argon2/nodeArgon2Provider.test.d.ts +0 -2
  23. package/lib/test/unit/argon2/nodeArgon2Provider.test.d.ts.map +0 -1
  24. package/lib/test/unit/argon2/nodeArgon2Provider.test.js +0 -146
  25. package/lib/test/unit/argon2/nodeArgon2Provider.test.js.map +0 -1
  26. package/rush-logs/ts-extras-argon2.build.cache.log +0 -3
  27. package/rush-logs/ts-extras-argon2.build.log +0 -9
  28. package/src/index.ts +0 -21
  29. package/src/packlets/argon2/index.ts +0 -25
  30. package/src/packlets/argon2/nodeArgon2Provider.ts +0 -101
  31. package/src/test/unit/argon2/crossRuntime.test.ts +0 -137
  32. package/src/test/unit/argon2/nodeArgon2Provider.test.ts +0 -186
  33. package/temp/build/lint/_eslint-5eVG3S6w.json +0 -26
  34. package/temp/build/typescript/ts_8nwakTlr.json +0 -1
  35. package/temp/ts-extras-argon2.api.json +0 -399
  36. package/temp/ts-extras-argon2.api.md +0 -20
  37. package/tsconfig.json +0 -8
@@ -1 +0,0 @@
1
- {"version":3,"file":"nodeArgon2Provider.test.js","sourceRoot":"","sources":["../../../../src/test/unit/argon2/nodeArgon2Provider.test.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,EAAE;AACF,+EAA+E;AAC/E,gFAAgF;AAChF,+EAA+E;AAC/E,4EAA4E;AAC5E,wEAAwE;AACxE,2DAA2D;AAC3D,EAAE;AACF,iFAAiF;AACjF,kDAAkD;AAClD,EAAE;AACF,6EAA6E;AAC7E,2EAA2E;AAC3E,8EAA8E;AAC9E,yEAAyE;AACzE,gFAAgF;AAChF,gFAAgF;AAChF,YAAY;AAEZ,OAAO,oBAAoB,CAAC;AAC5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAG9D,2FAA2F;AAC3F,4EAA4E;AAC5E,MAAM,UAAU,GAAgC;IAC9C,SAAS,EAAE,EAAE;IACb,UAAU,EAAE,CAAC;IACb,WAAW,EAAE,CAAC;IACd,WAAW,EAAE,EAAE;CAChB,CAAC;AACF,MAAM,YAAY,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACnD,MAAM,QAAQ,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAE/C,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAClC,IAAI,QAA4B,CAAC;IAEjC,UAAU,CAAC,GAAG,EAAE;QACd,QAAQ,GAAG,kBAAkB,CAAC,MAAM,EAAE,CAA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AI,EAAE;YAC3C,MAAM,CAAC,MAAM,QAAQ,CAAC,QAAQ,CAAC,YAAY,EAAE,QAAQ,kCAAO,UAAU,KAAE,UAAU,EAAE,CAAC,IAAG,CAAC,CAAC,UAAU,CAClG,0BAA0B,CAC3B,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,4BAA4B,EAAE,KAAK,IAAI,EAAE;YAC5C,MAAM,CAAC,MAAM,QAAQ,CAAC,QAAQ,CAAC,YAAY,EAAE,QAAQ,kCAAO,UAAU,KAAE,WAAW,EAAE,CAAC,IAAG,CAAC,CAAC,UAAU,CACnG,+BAA+B,CAChC,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,8BAA8B,EAAE,KAAK,IAAI,EAAE;YAC9C,MAAM,CAAC,MAAM,QAAQ,CAAC,QAAQ,CAAC,YAAY,EAAE,QAAQ,kCAAO,UAAU,KAAE,WAAW,EAAE,GAAG,IAAG,CAAC,CAAC,UAAU,CACrG,+BAA+B,CAChC,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,4BAA4B,EAAE,KAAK,IAAI,EAAE;YAC5C,MAAM,CAAC,MAAM,QAAQ,CAAC,QAAQ,CAAC,YAAY,EAAE,QAAQ,kCAAO,UAAU,KAAE,WAAW,EAAE,CAAC,IAAG,CAAC,CAAC,UAAU,CACnG,2BAA2B,CAC5B,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright (c) 2026 Erik Fortune\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in all\n// copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n// SOFTWARE.\n\nimport '@fgv/ts-utils-jest';\nimport { NodeArgon2Provider } from '../../../packlets/argon2';\nimport { CryptoUtils } from '@fgv/ts-extras';\n\n// RFC 9106 §B.3 parameter set (no secret/AD — our interface does not expose those fields).\n// t=3, m=32, p=4, tag=32. Used for determinism and cross-runtime agreement.\nconst RFC_PARAMS: CryptoUtils.IArgon2idParams = {\n memoryKiB: 32,\n iterations: 3,\n parallelism: 4,\n outputBytes: 32\n};\nconst RFC_PASSWORD = new Uint8Array(32).fill(0x01);\nconst RFC_SALT = new Uint8Array(16).fill(0x02);\n\ndescribe('NodeArgon2Provider', () => {\n let provider: NodeArgon2Provider;\n\n beforeEach(() => {\n provider = NodeArgon2Provider.create().orThrow();\n });\n\n describe('create()', () => {\n test('returns a provider instance', () => {\n expect(NodeArgon2Provider.create()).toSucceedAndSatisfy((p) => {\n expect(p).toBeInstanceOf(NodeArgon2Provider);\n });\n });\n });\n\n describe('argon2id()', () => {\n test('derives a key with Uint8Array password', async () => {\n expect(await provider.argon2id(RFC_PASSWORD, RFC_SALT, RFC_PARAMS)).toSucceedAndSatisfy((bytes) => {\n expect(bytes).toBeInstanceOf(Uint8Array);\n expect(bytes.length).toBe(RFC_PARAMS.outputBytes);\n });\n });\n\n test('derives a key with string password', async () => {\n expect(await provider.argon2id('password', RFC_SALT, RFC_PARAMS)).toSucceedAndSatisfy((bytes) => {\n expect(bytes).toBeInstanceOf(Uint8Array);\n expect(bytes.length).toBe(RFC_PARAMS.outputBytes);\n });\n });\n\n test('is deterministic — same inputs produce identical bytes', async () => {\n const r1 = (await provider.argon2id(RFC_PASSWORD, RFC_SALT, RFC_PARAMS)).orThrow();\n const r2 = (await provider.argon2id(RFC_PASSWORD, RFC_SALT, RFC_PARAMS)).orThrow();\n expect(r1).toEqual(r2);\n });\n\n test('different passwords produce different bytes', async () => {\n const a = (await provider.argon2id(new Uint8Array(32).fill(0x01), RFC_SALT, RFC_PARAMS)).orThrow();\n const b = (await provider.argon2id(new Uint8Array(32).fill(0x02), RFC_SALT, RFC_PARAMS)).orThrow();\n expect(a).not.toEqual(b);\n });\n\n test('different salts produce different bytes', async () => {\n const a = (await provider.argon2id(RFC_PASSWORD, new Uint8Array(16).fill(0x02), RFC_PARAMS)).orThrow();\n const b = (await provider.argon2id(RFC_PASSWORD, new Uint8Array(16).fill(0x03), RFC_PARAMS)).orThrow();\n expect(a).not.toEqual(b);\n });\n\n test('respects outputBytes', async () => {\n expect(\n await provider.argon2id(RFC_PASSWORD, RFC_SALT, { ...RFC_PARAMS, outputBytes: 64 })\n ).toSucceedAndSatisfy((bytes) => {\n expect(bytes.length).toBe(64);\n });\n });\n\n test('returns failure when underlying library rejects (salt too short)', async () => {\n const tinySalt = new Uint8Array(1).fill(0x02); // argon2 requires >= 8 bytes\n expect(await provider.argon2id(RFC_PASSWORD, tinySalt, RFC_PARAMS)).toFail();\n });\n });\n\n describe('keyed hashing (secret / associatedData)', () => {\n // RFC 9106 §5.3 Argon2id known-answer test vector:\n // password P = 32 bytes of 0x01, salt S = 16 bytes of 0x02,\n // secret K = 8 bytes of 0x03, associated data X = 12 bytes of 0x04,\n // t=3, m=32, p=4, tag=32.\n // expected tag = 0d640df58d78766c08c037a34a8b53c9d01ef0452d75b65eb52520e96b01e659\n const KAT_PARAMS: CryptoUtils.IArgon2idParams = {\n memoryKiB: 32,\n iterations: 3,\n parallelism: 4,\n outputBytes: 32\n };\n const KAT_PASSWORD = new Uint8Array(32).fill(0x01);\n const KAT_SALT = new Uint8Array(16).fill(0x02);\n const KAT_SECRET = new Uint8Array(8).fill(0x03);\n const KAT_AD = new Uint8Array(12).fill(0x04);\n const KAT_EXPECTED_HEX = '0d640df58d78766c08c037a34a8b53c9d01ef0452d75b65eb52520e96b01e659';\n\n test('reproduces the RFC 9106 §5.3 known-answer vector with secret + associatedData', async () => {\n expect(\n await provider.argon2id(KAT_PASSWORD, KAT_SALT, KAT_PARAMS, {\n secret: KAT_SECRET,\n associatedData: KAT_AD\n })\n ).toSucceedAndSatisfy((bytes) => {\n expect(Buffer.from(bytes).toString('hex')).toBe(KAT_EXPECTED_HEX);\n });\n });\n\n test('adding a secret changes the derived output', async () => {\n const withoutSecret = (await provider.argon2id(RFC_PASSWORD, RFC_SALT, RFC_PARAMS)).orThrow();\n const withSecret = (\n await provider.argon2id(RFC_PASSWORD, RFC_SALT, RFC_PARAMS, { secret: KAT_SECRET })\n ).orThrow();\n expect(withSecret).not.toEqual(withoutSecret);\n });\n\n test('adding associated data changes the derived output', async () => {\n const withoutAd = (await provider.argon2id(RFC_PASSWORD, RFC_SALT, RFC_PARAMS)).orThrow();\n const withAd = (\n await provider.argon2id(RFC_PASSWORD, RFC_SALT, RFC_PARAMS, { associatedData: KAT_AD })\n ).orThrow();\n expect(withAd).not.toEqual(withoutAd);\n });\n\n test('empty secret / associatedData are a no-op (byte-identical to omitting options)', async () => {\n const baseline = (await provider.argon2id(RFC_PASSWORD, RFC_SALT, RFC_PARAMS)).orThrow();\n const emptyOptions = (\n await provider.argon2id(RFC_PASSWORD, RFC_SALT, RFC_PARAMS, {\n secret: new Uint8Array(0),\n associatedData: new Uint8Array(0)\n })\n ).orThrow();\n expect(emptyOptions).toEqual(baseline);\n });\n });\n\n describe('parameter validation', () => {\n test('fails when memoryKiB < 8', async () => {\n expect(await provider.argon2id(RFC_PASSWORD, RFC_SALT, { ...RFC_PARAMS, memoryKiB: 7 })).toFailWith(\n /memoryKiB must be >= 8/i\n );\n });\n\n test('fails when iterations < 1', async () => {\n expect(await provider.argon2id(RFC_PASSWORD, RFC_SALT, { ...RFC_PARAMS, iterations: 0 })).toFailWith(\n /iterations must be >= 1/i\n );\n });\n\n test('fails when parallelism < 1', async () => {\n expect(await provider.argon2id(RFC_PASSWORD, RFC_SALT, { ...RFC_PARAMS, parallelism: 0 })).toFailWith(\n /parallelism must be 1\\.\\.255/i\n );\n });\n\n test('fails when parallelism > 255', async () => {\n expect(await provider.argon2id(RFC_PASSWORD, RFC_SALT, { ...RFC_PARAMS, parallelism: 256 })).toFailWith(\n /parallelism must be 1\\.\\.255/i\n );\n });\n\n test('fails when outputBytes < 4', async () => {\n expect(await provider.argon2id(RFC_PASSWORD, RFC_SALT, { ...RFC_PARAMS, outputBytes: 3 })).toFailWith(\n /outputBytes must be >= 4/i\n );\n });\n });\n});\n"]}
package/eslint.config.js DELETED
@@ -1,15 +0,0 @@
1
- // ESLint 9 flat config
2
- const nodeProfile = require('@rushstack/eslint-config/flat/profile/node');
3
- const packletsPlugin = require('@rushstack/eslint-config/flat/mixins/packlets');
4
- const tsdocPlugin = require('@rushstack/eslint-config/flat/mixins/tsdoc');
5
-
6
- module.exports = [
7
- ...nodeProfile,
8
- packletsPlugin,
9
- ...tsdocPlugin,
10
- {
11
- rules: {
12
- '@rushstack/packlets/mechanics': 'warn'
13
- }
14
- }
15
- ];
@@ -1,20 +0,0 @@
1
- ## API Report File for "@fgv/ts-extras-argon2"
2
-
3
- > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
4
-
5
- ```ts
6
-
7
- import { CryptoUtils } from '@fgv/ts-extras';
8
- import { Result } from '@fgv/ts-utils';
9
-
10
- export { CryptoUtils }
11
-
12
- // @public
13
- export class NodeArgon2Provider implements CryptoUtils.IArgon2idProvider {
14
- argon2id(password: Uint8Array | string, salt: Uint8Array, params: CryptoUtils.IArgon2idParams, options?: CryptoUtils.IArgon2idKeyingOptions): Promise<Result<Uint8Array>>;
15
- static create(): Result<NodeArgon2Provider>;
16
- }
17
-
18
- // (No @packageDocumentation comment for this package)
19
-
20
- ```
@@ -1,2 +0,0 @@
1
- import '@fgv/ts-utils-jest';
2
- //# sourceMappingURL=crossRuntime.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"crossRuntime.test.d.ts","sourceRoot":"","sources":["../../../../src/test/unit/argon2/crossRuntime.test.ts"],"names":[],"mappings":"AAoBA,OAAO,oBAAoB,CAAC"}
@@ -1,119 +0,0 @@
1
- "use strict";
2
- // Copyright (c) 2026 Erik Fortune
3
- //
4
- // Permission is hereby granted, free of charge, to any person obtaining a copy
5
- // of this software and associated documentation files (the "Software"), to deal
6
- // in the Software without restriction, including without limitation the rights
7
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- // copies of the Software, and to permit persons to whom the Software is
9
- // furnished to do so, subject to the following conditions:
10
- //
11
- // The above copyright notice and this permission notice shall be included in all
12
- // copies or substantial portions of the Software.
13
- //
14
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- // SOFTWARE.
21
- Object.defineProperty(exports, "__esModule", { value: true });
22
- require("@fgv/ts-utils-jest");
23
- const argon2_1 = require("../../../packlets/argon2");
24
- const ts_web_extras_argon2_1 = require("@fgv/ts-web-extras-argon2");
25
- // RFC 9106 §B.3 parameter set (no secret/AD — our IArgon2idParams interface does not expose
26
- // those optional Argon2 fields). Both implementations must agree on this exact output.
27
- const RFC_PARAMS = {
28
- memoryKiB: 32,
29
- iterations: 3,
30
- parallelism: 4,
31
- outputBytes: 32
32
- };
33
- const RFC_PASSWORD = new Uint8Array(32).fill(0x01);
34
- const RFC_SALT = new Uint8Array(16).fill(0x02);
35
- // Verified independently against both argon2 (kelektiv) and hash-wasm.
36
- const RFC_EXPECTED_HEX = '03aab965c12001c9d7d0d2de33192c0494b684bb148196d73c1df1acaf6d0c2e';
37
- const SWEEP = [
38
- {
39
- label: 'RFC §B.3 base case',
40
- password: RFC_PASSWORD,
41
- salt: RFC_SALT,
42
- params: RFC_PARAMS
43
- },
44
- {
45
- label: 'string password',
46
- password: 'correct horse battery staple',
47
- salt: RFC_SALT,
48
- params: RFC_PARAMS
49
- },
50
- {
51
- label: 'higher memoryKiB',
52
- password: RFC_PASSWORD,
53
- salt: RFC_SALT,
54
- params: Object.assign(Object.assign({}, RFC_PARAMS), { memoryKiB: 64 })
55
- },
56
- {
57
- label: 'more iterations',
58
- password: RFC_PASSWORD,
59
- salt: RFC_SALT,
60
- params: Object.assign(Object.assign({}, RFC_PARAMS), { iterations: 5 })
61
- },
62
- {
63
- label: 'parallelism=1',
64
- password: RFC_PASSWORD,
65
- salt: RFC_SALT,
66
- params: Object.assign(Object.assign({}, RFC_PARAMS), { parallelism: 1 })
67
- },
68
- {
69
- label: 'longer output (64 bytes)',
70
- password: RFC_PASSWORD,
71
- salt: RFC_SALT,
72
- params: Object.assign(Object.assign({}, RFC_PARAMS), { outputBytes: 64 })
73
- },
74
- {
75
- label: 'different salt',
76
- password: RFC_PASSWORD,
77
- salt: new Uint8Array(16).fill(0x07),
78
- params: RFC_PARAMS
79
- }
80
- ];
81
- describe('cross-runtime equivalence: NodeArgon2Provider vs BrowserArgon2Provider', () => {
82
- let node;
83
- let browser;
84
- beforeEach(() => {
85
- node = argon2_1.NodeArgon2Provider.create().orThrow();
86
- browser = ts_web_extras_argon2_1.BrowserArgon2Provider.create().orThrow();
87
- });
88
- test('RFC §B.3 parameter set matches known-good hex output', async () => {
89
- const nodeBytes = (await node.argon2id(RFC_PASSWORD, RFC_SALT, RFC_PARAMS)).orThrow();
90
- expect(Buffer.from(nodeBytes).toString('hex')).toBe(RFC_EXPECTED_HEX);
91
- });
92
- test.each(SWEEP)('$label: outputs are byte-identical', async ({ password, salt, params }) => {
93
- const nodeBytes = (await node.argon2id(password, salt, params)).orThrow();
94
- const browserBytes = (await browser.argon2id(password, salt, params)).orThrow();
95
- expect(nodeBytes).toEqual(browserBytes);
96
- });
97
- // A secret (RFC 9106 keyed hashing) is supported by both backends and must
98
- // stay byte-identical across them. Small params keep this fast.
99
- test('secret-only keyed hashing is byte-identical across runtimes', async () => {
100
- const params = {
101
- memoryKiB: 8,
102
- iterations: 1,
103
- parallelism: 1,
104
- outputBytes: 32
105
- };
106
- const secret = new Uint8Array(8).fill(0x03);
107
- const nodeBytes = (await node.argon2id(RFC_PASSWORD, RFC_SALT, params, { secret })).orThrow();
108
- const browserBytes = (await browser.argon2id(RFC_PASSWORD, RFC_SALT, params, { secret })).orThrow();
109
- expect(nodeBytes).toEqual(browserBytes);
110
- });
111
- // Associated data is Node-only: Node honors it, the WASM browser backend
112
- // rejects it loudly rather than silently dropping it (which would diverge).
113
- test('associatedData is Node-only: Node succeeds, browser rejects', async () => {
114
- const associatedData = new Uint8Array(12).fill(0x04);
115
- expect(await node.argon2id(RFC_PASSWORD, RFC_SALT, RFC_PARAMS, { associatedData })).toSucceed();
116
- expect(await browser.argon2id(RFC_PASSWORD, RFC_SALT, RFC_PARAMS, { associatedData })).toFailWith(/associatedData is not supported.*node-only/i);
117
- });
118
- });
119
- //# sourceMappingURL=crossRuntime.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"crossRuntime.test.js","sourceRoot":"","sources":["../../../../src/test/unit/argon2/crossRuntime.test.ts"],"names":[],"mappings":";AAAA,kCAAkC;AAClC,EAAE;AACF,+EAA+E;AAC/E,gFAAgF;AA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AAE,UAAU,EAAE,EAAE,cAAc,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;QAChG,MAAM,CAAC,MAAM,OAAO,CAAC,QAAQ,CAAC,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,cAAc,EAAE,CAAC,CAAC,CAAC,UAAU,CAC/F,6CAA6C,CAC9C,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright (c) 2026 Erik Fortune\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in all\n// copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n// SOFTWARE.\n\nimport '@fgv/ts-utils-jest';\nimport { NodeArgon2Provider } from '../../../packlets/argon2';\nimport { BrowserArgon2Provider } from '@fgv/ts-web-extras-argon2';\nimport { CryptoUtils } from '@fgv/ts-extras';\n\n// RFC 9106 §B.3 parameter set (no secret/AD — our IArgon2idParams interface does not expose\n// those optional Argon2 fields). Both implementations must agree on this exact output.\nconst RFC_PARAMS: CryptoUtils.IArgon2idParams = {\n memoryKiB: 32,\n iterations: 3,\n parallelism: 4,\n outputBytes: 32\n};\nconst RFC_PASSWORD = new Uint8Array(32).fill(0x01);\nconst RFC_SALT = new Uint8Array(16).fill(0x02);\n\n// Verified independently against both argon2 (kelektiv) and hash-wasm.\nconst RFC_EXPECTED_HEX = '03aab965c12001c9d7d0d2de33192c0494b684bb148196d73c1df1acaf6d0c2e';\n\n// Parameter sweep — covers variation in each dimension independently.\ninterface ITestCase {\n label: string;\n password: Uint8Array | string;\n salt: Uint8Array;\n params: CryptoUtils.IArgon2idParams;\n}\n\nconst SWEEP: ITestCase[] = [\n {\n label: 'RFC §B.3 base case',\n password: RFC_PASSWORD,\n salt: RFC_SALT,\n params: RFC_PARAMS\n },\n {\n label: 'string password',\n password: 'correct horse battery staple',\n salt: RFC_SALT,\n params: RFC_PARAMS\n },\n {\n label: 'higher memoryKiB',\n password: RFC_PASSWORD,\n salt: RFC_SALT,\n params: { ...RFC_PARAMS, memoryKiB: 64 }\n },\n {\n label: 'more iterations',\n password: RFC_PASSWORD,\n salt: RFC_SALT,\n params: { ...RFC_PARAMS, iterations: 5 }\n },\n {\n label: 'parallelism=1',\n password: RFC_PASSWORD,\n salt: RFC_SALT,\n params: { ...RFC_PARAMS, parallelism: 1 }\n },\n {\n label: 'longer output (64 bytes)',\n password: RFC_PASSWORD,\n salt: RFC_SALT,\n params: { ...RFC_PARAMS, outputBytes: 64 }\n },\n {\n label: 'different salt',\n password: RFC_PASSWORD,\n salt: new Uint8Array(16).fill(0x07),\n params: RFC_PARAMS\n }\n];\n\ndescribe('cross-runtime equivalence: NodeArgon2Provider vs BrowserArgon2Provider', () => {\n let node: NodeArgon2Provider;\n let browser: BrowserArgon2Provider;\n\n beforeEach(() => {\n node = NodeArgon2Provider.create().orThrow();\n browser = BrowserArgon2Provider.create().orThrow();\n });\n\n test('RFC §B.3 parameter set matches known-good hex output', async () => {\n const nodeBytes = (await node.argon2id(RFC_PASSWORD, RFC_SALT, RFC_PARAMS)).orThrow();\n expect(Buffer.from(nodeBytes).toString('hex')).toBe(RFC_EXPECTED_HEX);\n });\n\n test.each(SWEEP)('$label: outputs are byte-identical', async ({ password, salt, params }) => {\n const nodeBytes = (await node.argon2id(password, salt, params)).orThrow();\n const browserBytes = (await browser.argon2id(password, salt, params)).orThrow();\n expect(nodeBytes).toEqual(browserBytes);\n });\n\n // A secret (RFC 9106 keyed hashing) is supported by both backends and must\n // stay byte-identical across them. Small params keep this fast.\n test('secret-only keyed hashing is byte-identical across runtimes', async () => {\n const params: CryptoUtils.IArgon2idParams = {\n memoryKiB: 8,\n iterations: 1,\n parallelism: 1,\n outputBytes: 32\n };\n const secret = new Uint8Array(8).fill(0x03);\n const nodeBytes = (await node.argon2id(RFC_PASSWORD, RFC_SALT, params, { secret })).orThrow();\n const browserBytes = (await browser.argon2id(RFC_PASSWORD, RFC_SALT, params, { secret })).orThrow();\n expect(nodeBytes).toEqual(browserBytes);\n });\n\n // Associated data is Node-only: Node honors it, the WASM browser backend\n // rejects it loudly rather than silently dropping it (which would diverge).\n test('associatedData is Node-only: Node succeeds, browser rejects', async () => {\n const associatedData = new Uint8Array(12).fill(0x04);\n expect(await node.argon2id(RFC_PASSWORD, RFC_SALT, RFC_PARAMS, { associatedData })).toSucceed();\n expect(await browser.argon2id(RFC_PASSWORD, RFC_SALT, RFC_PARAMS, { associatedData })).toFailWith(\n /associatedData is not supported.*node-only/i\n );\n });\n});\n"]}
@@ -1,2 +0,0 @@
1
- import '@fgv/ts-utils-jest';
2
- //# sourceMappingURL=nodeArgon2Provider.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"nodeArgon2Provider.test.d.ts","sourceRoot":"","sources":["../../../../src/test/unit/argon2/nodeArgon2Provider.test.ts"],"names":[],"mappings":"AAoBA,OAAO,oBAAoB,CAAC"}
@@ -1,146 +0,0 @@
1
- "use strict";
2
- // Copyright (c) 2026 Erik Fortune
3
- //
4
- // Permission is hereby granted, free of charge, to any person obtaining a copy
5
- // of this software and associated documentation files (the "Software"), to deal
6
- // in the Software without restriction, including without limitation the rights
7
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- // copies of the Software, and to permit persons to whom the Software is
9
- // furnished to do so, subject to the following conditions:
10
- //
11
- // The above copyright notice and this permission notice shall be included in all
12
- // copies or substantial portions of the Software.
13
- //
14
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- // SOFTWARE.
21
- Object.defineProperty(exports, "__esModule", { value: true });
22
- require("@fgv/ts-utils-jest");
23
- const argon2_1 = require("../../../packlets/argon2");
24
- // RFC 9106 §B.3 parameter set (no secret/AD — our interface does not expose those fields).
25
- // t=3, m=32, p=4, tag=32. Used for determinism and cross-runtime agreement.
26
- const RFC_PARAMS = {
27
- memoryKiB: 32,
28
- iterations: 3,
29
- parallelism: 4,
30
- outputBytes: 32
31
- };
32
- const RFC_PASSWORD = new Uint8Array(32).fill(0x01);
33
- const RFC_SALT = new Uint8Array(16).fill(0x02);
34
- describe('NodeArgon2Provider', () => {
35
- let provider;
36
- beforeEach(() => {
37
- provider = argon2_1.NodeArgon2Provider.create().orThrow();
38
- });
39
- describe('create()', () => {
40
- test('returns a provider instance', () => {
41
- expect(argon2_1.NodeArgon2Provider.create()).toSucceedAndSatisfy((p) => {
42
- expect(p).toBeInstanceOf(argon2_1.NodeArgon2Provider);
43
- });
44
- });
45
- });
46
- describe('argon2id()', () => {
47
- test('derives a key with Uint8Array password', async () => {
48
- expect(await provider.argon2id(RFC_PASSWORD, RFC_SALT, RFC_PARAMS)).toSucceedAndSatisfy((bytes) => {
49
- expect(bytes).toBeInstanceOf(Uint8Array);
50
- expect(bytes.length).toBe(RFC_PARAMS.outputBytes);
51
- });
52
- });
53
- test('derives a key with string password', async () => {
54
- expect(await provider.argon2id('password', RFC_SALT, RFC_PARAMS)).toSucceedAndSatisfy((bytes) => {
55
- expect(bytes).toBeInstanceOf(Uint8Array);
56
- expect(bytes.length).toBe(RFC_PARAMS.outputBytes);
57
- });
58
- });
59
- test('is deterministic — same inputs produce identical bytes', async () => {
60
- const r1 = (await provider.argon2id(RFC_PASSWORD, RFC_SALT, RFC_PARAMS)).orThrow();
61
- const r2 = (await provider.argon2id(RFC_PASSWORD, RFC_SALT, RFC_PARAMS)).orThrow();
62
- expect(r1).toEqual(r2);
63
- });
64
- test('different passwords produce different bytes', async () => {
65
- const a = (await provider.argon2id(new Uint8Array(32).fill(0x01), RFC_SALT, RFC_PARAMS)).orThrow();
66
- const b = (await provider.argon2id(new Uint8Array(32).fill(0x02), RFC_SALT, RFC_PARAMS)).orThrow();
67
- expect(a).not.toEqual(b);
68
- });
69
- test('different salts produce different bytes', async () => {
70
- const a = (await provider.argon2id(RFC_PASSWORD, new Uint8Array(16).fill(0x02), RFC_PARAMS)).orThrow();
71
- const b = (await provider.argon2id(RFC_PASSWORD, new Uint8Array(16).fill(0x03), RFC_PARAMS)).orThrow();
72
- expect(a).not.toEqual(b);
73
- });
74
- test('respects outputBytes', async () => {
75
- expect(await provider.argon2id(RFC_PASSWORD, RFC_SALT, Object.assign(Object.assign({}, RFC_PARAMS), { outputBytes: 64 }))).toSucceedAndSatisfy((bytes) => {
76
- expect(bytes.length).toBe(64);
77
- });
78
- });
79
- test('returns failure when underlying library rejects (salt too short)', async () => {
80
- const tinySalt = new Uint8Array(1).fill(0x02); // argon2 requires >= 8 bytes
81
- expect(await provider.argon2id(RFC_PASSWORD, tinySalt, RFC_PARAMS)).toFail();
82
- });
83
- });
84
- describe('keyed hashing (secret / associatedData)', () => {
85
- // RFC 9106 §5.3 Argon2id known-answer test vector:
86
- // password P = 32 bytes of 0x01, salt S = 16 bytes of 0x02,
87
- // secret K = 8 bytes of 0x03, associated data X = 12 bytes of 0x04,
88
- // t=3, m=32, p=4, tag=32.
89
- // expected tag = 0d640df58d78766c08c037a34a8b53c9d01ef0452d75b65eb52520e96b01e659
90
- const KAT_PARAMS = {
91
- memoryKiB: 32,
92
- iterations: 3,
93
- parallelism: 4,
94
- outputBytes: 32
95
- };
96
- const KAT_PASSWORD = new Uint8Array(32).fill(0x01);
97
- const KAT_SALT = new Uint8Array(16).fill(0x02);
98
- const KAT_SECRET = new Uint8Array(8).fill(0x03);
99
- const KAT_AD = new Uint8Array(12).fill(0x04);
100
- const KAT_EXPECTED_HEX = '0d640df58d78766c08c037a34a8b53c9d01ef0452d75b65eb52520e96b01e659';
101
- test('reproduces the RFC 9106 §5.3 known-answer vector with secret + associatedData', async () => {
102
- expect(await provider.argon2id(KAT_PASSWORD, KAT_SALT, KAT_PARAMS, {
103
- secret: KAT_SECRET,
104
- associatedData: KAT_AD
105
- })).toSucceedAndSatisfy((bytes) => {
106
- expect(Buffer.from(bytes).toString('hex')).toBe(KAT_EXPECTED_HEX);
107
- });
108
- });
109
- test('adding a secret changes the derived output', async () => {
110
- const withoutSecret = (await provider.argon2id(RFC_PASSWORD, RFC_SALT, RFC_PARAMS)).orThrow();
111
- const withSecret = (await provider.argon2id(RFC_PASSWORD, RFC_SALT, RFC_PARAMS, { secret: KAT_SECRET })).orThrow();
112
- expect(withSecret).not.toEqual(withoutSecret);
113
- });
114
- test('adding associated data changes the derived output', async () => {
115
- const withoutAd = (await provider.argon2id(RFC_PASSWORD, RFC_SALT, RFC_PARAMS)).orThrow();
116
- const withAd = (await provider.argon2id(RFC_PASSWORD, RFC_SALT, RFC_PARAMS, { associatedData: KAT_AD })).orThrow();
117
- expect(withAd).not.toEqual(withoutAd);
118
- });
119
- test('empty secret / associatedData are a no-op (byte-identical to omitting options)', async () => {
120
- const baseline = (await provider.argon2id(RFC_PASSWORD, RFC_SALT, RFC_PARAMS)).orThrow();
121
- const emptyOptions = (await provider.argon2id(RFC_PASSWORD, RFC_SALT, RFC_PARAMS, {
122
- secret: new Uint8Array(0),
123
- associatedData: new Uint8Array(0)
124
- })).orThrow();
125
- expect(emptyOptions).toEqual(baseline);
126
- });
127
- });
128
- describe('parameter validation', () => {
129
- test('fails when memoryKiB < 8', async () => {
130
- expect(await provider.argon2id(RFC_PASSWORD, RFC_SALT, Object.assign(Object.assign({}, RFC_PARAMS), { memoryKiB: 7 }))).toFailWith(/memoryKiB must be >= 8/i);
131
- });
132
- test('fails when iterations < 1', async () => {
133
- expect(await provider.argon2id(RFC_PASSWORD, RFC_SALT, Object.assign(Object.assign({}, RFC_PARAMS), { iterations: 0 }))).toFailWith(/iterations must be >= 1/i);
134
- });
135
- test('fails when parallelism < 1', async () => {
136
- expect(await provider.argon2id(RFC_PASSWORD, RFC_SALT, Object.assign(Object.assign({}, RFC_PARAMS), { parallelism: 0 }))).toFailWith(/parallelism must be 1\.\.255/i);
137
- });
138
- test('fails when parallelism > 255', async () => {
139
- expect(await provider.argon2id(RFC_PASSWORD, RFC_SALT, Object.assign(Object.assign({}, RFC_PARAMS), { parallelism: 256 }))).toFailWith(/parallelism must be 1\.\.255/i);
140
- });
141
- test('fails when outputBytes < 4', async () => {
142
- expect(await provider.argon2id(RFC_PASSWORD, RFC_SALT, Object.assign(Object.assign({}, RFC_PARAMS), { outputBytes: 3 }))).toFailWith(/outputBytes must be >= 4/i);
143
- });
144
- });
145
- });
146
- //# sourceMappingURL=nodeArgon2Provider.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"nodeArgon2Provider.test.js","sourceRoot":"","sources":["../../../../src/test/unit/argon2/nodeArgon2Provider.test.ts"],"names":[],"mappings":";AAAA,kCAAkC;AAClC,EAAE;AACF,+EAA+E;AAC/E,gFAAgF;AAChF,+EAA+E;AAC/E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CAAC,QAAQ,CAAC,YAAY,EAAE,QAAQ,kCAAO,UAAU,KAAE,WAAW,EAAE,GAAG,IAAG,CAAC,CAAC,UAAU,CACrG,+BAA+B,CAChC,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,4BAA4B,EAAE,KAAK,IAAI,EAAE;YAC5C,MAAM,CAAC,MAAM,QAAQ,CAAC,QAAQ,CAAC,YAAY,EAAE,QAAQ,kCAAO,UAAU,KAAE,WAAW,EAAE,CAAC,IAAG,CAAC,CAAC,UAAU,CACnG,2BAA2B,CAC5B,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright (c) 2026 Erik Fortune\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in all\n// copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n// SOFTWARE.\n\nimport '@fgv/ts-utils-jest';\nimport { NodeArgon2Provider } from '../../../packlets/argon2';\nimport { CryptoUtils } from '@fgv/ts-extras';\n\n// RFC 9106 §B.3 parameter set (no secret/AD — our interface does not expose those fields).\n// t=3, m=32, p=4, tag=32. Used for determinism and cross-runtime agreement.\nconst RFC_PARAMS: CryptoUtils.IArgon2idParams = {\n memoryKiB: 32,\n iterations: 3,\n parallelism: 4,\n outputBytes: 32\n};\nconst RFC_PASSWORD = new Uint8Array(32).fill(0x01);\nconst RFC_SALT = new Uint8Array(16).fill(0x02);\n\ndescribe('NodeArgon2Provider', () => {\n let provider: NodeArgon2Provider;\n\n beforeEach(() => {\n provider = NodeArgon2Provider.create().orThrow();\n });\n\n describe('create()', () => {\n test('returns a provider instance', () => {\n expect(NodeArgon2Provider.create()).toSucceedAndSatisfy((p) => {\n expect(p).toBeInstanceOf(NodeArgon2Provider);\n });\n });\n });\n\n describe('argon2id()', () => {\n test('derives a key with Uint8Array password', async () => {\n expect(await provider.argon2id(RFC_PASSWORD, RFC_SALT, RFC_PARAMS)).toSucceedAndSatisfy((bytes) => {\n expect(bytes).toBeInstanceOf(Uint8Array);\n expect(bytes.length).toBe(RFC_PARAMS.outputBytes);\n });\n });\n\n test('derives a key with string password', async () => {\n expect(await provider.argon2id('password', RFC_SALT, RFC_PARAMS)).toSucceedAndSatisfy((bytes) => {\n expect(bytes).toBeInstanceOf(Uint8Array);\n expect(bytes.length).toBe(RFC_PARAMS.outputBytes);\n });\n });\n\n test('is deterministic — same inputs produce identical bytes', async () => {\n const r1 = (await provider.argon2id(RFC_PASSWORD, RFC_SALT, RFC_PARAMS)).orThrow();\n const r2 = (await provider.argon2id(RFC_PASSWORD, RFC_SALT, RFC_PARAMS)).orThrow();\n expect(r1).toEqual(r2);\n });\n\n test('different passwords produce different bytes', async () => {\n const a = (await provider.argon2id(new Uint8Array(32).fill(0x01), RFC_SALT, RFC_PARAMS)).orThrow();\n const b = (await provider.argon2id(new Uint8Array(32).fill(0x02), RFC_SALT, RFC_PARAMS)).orThrow();\n expect(a).not.toEqual(b);\n });\n\n test('different salts produce different bytes', async () => {\n const a = (await provider.argon2id(RFC_PASSWORD, new Uint8Array(16).fill(0x02), RFC_PARAMS)).orThrow();\n const b = (await provider.argon2id(RFC_PASSWORD, new Uint8Array(16).fill(0x03), RFC_PARAMS)).orThrow();\n expect(a).not.toEqual(b);\n });\n\n test('respects outputBytes', async () => {\n expect(\n await provider.argon2id(RFC_PASSWORD, RFC_SALT, { ...RFC_PARAMS, outputBytes: 64 })\n ).toSucceedAndSatisfy((bytes) => {\n expect(bytes.length).toBe(64);\n });\n });\n\n test('returns failure when underlying library rejects (salt too short)', async () => {\n const tinySalt = new Uint8Array(1).fill(0x02); // argon2 requires >= 8 bytes\n expect(await provider.argon2id(RFC_PASSWORD, tinySalt, RFC_PARAMS)).toFail();\n });\n });\n\n describe('keyed hashing (secret / associatedData)', () => {\n // RFC 9106 §5.3 Argon2id known-answer test vector:\n // password P = 32 bytes of 0x01, salt S = 16 bytes of 0x02,\n // secret K = 8 bytes of 0x03, associated data X = 12 bytes of 0x04,\n // t=3, m=32, p=4, tag=32.\n // expected tag = 0d640df58d78766c08c037a34a8b53c9d01ef0452d75b65eb52520e96b01e659\n const KAT_PARAMS: CryptoUtils.IArgon2idParams = {\n memoryKiB: 32,\n iterations: 3,\n parallelism: 4,\n outputBytes: 32\n };\n const KAT_PASSWORD = new Uint8Array(32).fill(0x01);\n const KAT_SALT = new Uint8Array(16).fill(0x02);\n const KAT_SECRET = new Uint8Array(8).fill(0x03);\n const KAT_AD = new Uint8Array(12).fill(0x04);\n const KAT_EXPECTED_HEX = '0d640df58d78766c08c037a34a8b53c9d01ef0452d75b65eb52520e96b01e659';\n\n test('reproduces the RFC 9106 §5.3 known-answer vector with secret + associatedData', async () => {\n expect(\n await provider.argon2id(KAT_PASSWORD, KAT_SALT, KAT_PARAMS, {\n secret: KAT_SECRET,\n associatedData: KAT_AD\n })\n ).toSucceedAndSatisfy((bytes) => {\n expect(Buffer.from(bytes).toString('hex')).toBe(KAT_EXPECTED_HEX);\n });\n });\n\n test('adding a secret changes the derived output', async () => {\n const withoutSecret = (await provider.argon2id(RFC_PASSWORD, RFC_SALT, RFC_PARAMS)).orThrow();\n const withSecret = (\n await provider.argon2id(RFC_PASSWORD, RFC_SALT, RFC_PARAMS, { secret: KAT_SECRET })\n ).orThrow();\n expect(withSecret).not.toEqual(withoutSecret);\n });\n\n test('adding associated data changes the derived output', async () => {\n const withoutAd = (await provider.argon2id(RFC_PASSWORD, RFC_SALT, RFC_PARAMS)).orThrow();\n const withAd = (\n await provider.argon2id(RFC_PASSWORD, RFC_SALT, RFC_PARAMS, { associatedData: KAT_AD })\n ).orThrow();\n expect(withAd).not.toEqual(withoutAd);\n });\n\n test('empty secret / associatedData are a no-op (byte-identical to omitting options)', async () => {\n const baseline = (await provider.argon2id(RFC_PASSWORD, RFC_SALT, RFC_PARAMS)).orThrow();\n const emptyOptions = (\n await provider.argon2id(RFC_PASSWORD, RFC_SALT, RFC_PARAMS, {\n secret: new Uint8Array(0),\n associatedData: new Uint8Array(0)\n })\n ).orThrow();\n expect(emptyOptions).toEqual(baseline);\n });\n });\n\n describe('parameter validation', () => {\n test('fails when memoryKiB < 8', async () => {\n expect(await provider.argon2id(RFC_PASSWORD, RFC_SALT, { ...RFC_PARAMS, memoryKiB: 7 })).toFailWith(\n /memoryKiB must be >= 8/i\n );\n });\n\n test('fails when iterations < 1', async () => {\n expect(await provider.argon2id(RFC_PASSWORD, RFC_SALT, { ...RFC_PARAMS, iterations: 0 })).toFailWith(\n /iterations must be >= 1/i\n );\n });\n\n test('fails when parallelism < 1', async () => {\n expect(await provider.argon2id(RFC_PASSWORD, RFC_SALT, { ...RFC_PARAMS, parallelism: 0 })).toFailWith(\n /parallelism must be 1\\.\\.255/i\n );\n });\n\n test('fails when parallelism > 255', async () => {\n expect(await provider.argon2id(RFC_PASSWORD, RFC_SALT, { ...RFC_PARAMS, parallelism: 256 })).toFailWith(\n /parallelism must be 1\\.\\.255/i\n );\n });\n\n test('fails when outputBytes < 4', async () => {\n expect(await provider.argon2id(RFC_PASSWORD, RFC_SALT, { ...RFC_PARAMS, outputBytes: 3 })).toFailWith(\n /outputBytes must be >= 4/i\n );\n });\n });\n});\n"]}
@@ -1,3 +0,0 @@
1
- Caching build output folders: dist, lib, temp, .rush/temp/operation/build
2
- Successfully set cache entry.
3
- Cache key: eb061fb1c7e3a355a03b204add873a27586efa0d
@@ -1,9 +0,0 @@
1
- Invoking: heft build --clean
2
- ---- build started ----
3
- [build:typescript] The TypeScript compiler version 5.9.3 is newer than the latest version that was tested with Heft (5.8); it may not work correctly.
4
- [build:typescript] Using TypeScript version 5.9.3
5
- [build:lint] Using ESLint version 9.39.5
6
- [build:api-extractor] Using API Extractor version 7.58.9
7
- [build:api-extractor] Analysis will use the bundled TypeScript version 5.9.3
8
- ---- build finished (14.490s) ----
9
- -------------------- Finished (14.497s) --------------------
package/src/index.ts DELETED
@@ -1,21 +0,0 @@
1
- // Copyright (c) 2026 Erik Fortune
2
- //
3
- // Permission is hereby granted, free of charge, to any person obtaining a copy
4
- // of this software and associated documentation files (the "Software"), to deal
5
- // in the Software without restriction, including without limitation the rights
6
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- // copies of the Software, and to permit persons to whom the Software is
8
- // furnished to do so, subject to the following conditions:
9
- //
10
- // The above copyright notice and this permission notice shall be included in all
11
- // copies or substantial portions of the Software.
12
- //
13
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
- // SOFTWARE.
20
-
21
- export { NodeArgon2Provider, CryptoUtils } from './packlets/argon2';
@@ -1,25 +0,0 @@
1
- // Copyright (c) 2026 Erik Fortune
2
- //
3
- // Permission is hereby granted, free of charge, to any person obtaining a copy
4
- // of this software and associated documentation files (the "Software"), to deal
5
- // in the Software without restriction, including without limitation the rights
6
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- // copies of the Software, and to permit persons to whom the Software is
8
- // furnished to do so, subject to the following conditions:
9
- //
10
- // The above copyright notice and this permission notice shall be included in all
11
- // copies or substantial portions of the Software.
12
- //
13
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
- // SOFTWARE.
20
-
21
- export { NodeArgon2Provider } from './nodeArgon2Provider';
22
-
23
- // Re-export CryptoUtils namespace from ts-extras for consumer convenience
24
- // (provides IArgon2idProvider, IArgon2idParams, ARGON2ID_OWASP_MIN, ARGON2ID_PASSPHRASE).
25
- export { CryptoUtils } from '@fgv/ts-extras';
@@ -1,101 +0,0 @@
1
- // Copyright (c) 2026 Erik Fortune
2
- //
3
- // Permission is hereby granted, free of charge, to any person obtaining a copy
4
- // of this software and associated documentation files (the "Software"), to deal
5
- // in the Software without restriction, including without limitation the rights
6
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- // copies of the Software, and to permit persons to whom the Software is
8
- // furnished to do so, subject to the following conditions:
9
- //
10
- // The above copyright notice and this permission notice shall be included in all
11
- // copies or substantial portions of the Software.
12
- //
13
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
- // SOFTWARE.
20
-
21
- import * as argon2 from 'argon2';
22
- import { Result, captureAsyncResult, fail, succeed } from '@fgv/ts-utils';
23
- import { CryptoUtils } from '@fgv/ts-extras';
24
-
25
- /**
26
- * Node.js implementation of {@link @fgv/ts-extras#IArgon2idProvider} backed by the
27
- * `argon2` (kelektiv) native binding.
28
- * @public
29
- */
30
- export class NodeArgon2Provider implements CryptoUtils.IArgon2idProvider {
31
- private constructor() {}
32
-
33
- /**
34
- * Creates a new {@link NodeArgon2Provider} instance.
35
- * @returns Success with a new provider instance.
36
- * @public
37
- */
38
- public static create(): Result<NodeArgon2Provider> {
39
- return succeed(new NodeArgon2Provider());
40
- }
41
-
42
- /**
43
- * Derives a key using Argon2id.
44
- *
45
- * @param password - The password or passphrase (string or raw bytes).
46
- * @param salt - The salt (must be at least 8 bytes; 16+ bytes recommended).
47
- * @param params - Argon2id parameters. All values are validated before derivation.
48
- * @param options - Optional {@link @fgv/ts-extras#CryptoUtils.IArgon2idKeyingOptions | keyed-hashing inputs}
49
- * (RFC 9106 secret K and/or associated data X). Both are wired through to the
50
- * underlying `argon2` binding when present and non-empty; omitting them (or
51
- * passing empty arrays) leaves the output byte-identical to prior behavior.
52
- * @returns Success with the derived key bytes, or Failure with a descriptive message.
53
- * @public
54
- */
55
- public async argon2id(
56
- password: Uint8Array | string,
57
- salt: Uint8Array,
58
- params: CryptoUtils.IArgon2idParams,
59
- options?: CryptoUtils.IArgon2idKeyingOptions
60
- ): Promise<Result<Uint8Array>> {
61
- const error = NodeArgon2Provider._validateParams(params);
62
- if (error !== undefined) {
63
- return fail(error);
64
- }
65
-
66
- return captureAsyncResult(async () => {
67
- const result = await argon2.hash(password instanceof Uint8Array ? Buffer.from(password) : password, {
68
- type: argon2.argon2id,
69
- salt: Buffer.from(salt),
70
- memoryCost: params.memoryKiB,
71
- timeCost: params.iterations,
72
- parallelism: params.parallelism,
73
- hashLength: params.outputBytes,
74
- raw: true,
75
- // Only pass secret/associatedData when present and non-empty so that
76
- // existing callers (and empty options) produce byte-identical output.
77
- ...(options?.secret && options.secret.length > 0 ? { secret: Buffer.from(options.secret) } : {}),
78
- ...(options?.associatedData && options.associatedData.length > 0
79
- ? { associatedData: Buffer.from(options.associatedData) }
80
- : {})
81
- });
82
- return Uint8Array.from(result);
83
- });
84
- }
85
-
86
- private static _validateParams(params: CryptoUtils.IArgon2idParams): string | undefined {
87
- if (params.memoryKiB < 8) {
88
- return `argon2id: memoryKiB must be >= 8, got ${params.memoryKiB}`;
89
- }
90
- if (params.iterations < 1) {
91
- return `argon2id: iterations must be >= 1, got ${params.iterations}`;
92
- }
93
- if (params.parallelism < 1 || params.parallelism > 255) {
94
- return `argon2id: parallelism must be 1..255, got ${params.parallelism}`;
95
- }
96
- if (params.outputBytes < 4) {
97
- return `argon2id: outputBytes must be >= 4, got ${params.outputBytes}`;
98
- }
99
- return undefined;
100
- }
101
- }