@fgv/ts-extras-argon2 5.1.0-27 → 5.1.0-28
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/.rush/temp/8a928d1da9c45991e3e0e971522b429d0ffc824a.tar.log +48 -0
- package/.rush/temp/chunked-rush-logs/ts-extras-argon2.build.chunks.jsonl +9 -0
- package/.rush/temp/operation/build/all.log +9 -0
- package/.rush/temp/operation/build/log-chunks.jsonl +9 -0
- package/.rush/temp/operation/build/state.json +3 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/packlets/argon2/index.js +24 -0
- package/dist/packlets/argon2/index.js.map +1 -0
- package/dist/packlets/argon2/nodeArgon2Provider.js +80 -0
- package/dist/packlets/argon2/nodeArgon2Provider.js.map +1 -0
- package/dist/test/unit/argon2/crossRuntime.test.js +96 -0
- package/dist/test/unit/argon2/crossRuntime.test.js.map +1 -0
- package/dist/test/unit/argon2/nodeArgon2Provider.test.js +100 -0
- package/dist/test/unit/argon2/nodeArgon2Provider.test.js.map +1 -0
- package/dist/ts-extras-argon2.d.ts +32 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +26 -0
- package/lib/index.js.map +1 -0
- package/lib/packlets/argon2/index.d.ts +3 -0
- package/lib/packlets/argon2/index.d.ts.map +1 -0
- package/lib/packlets/argon2/index.js +29 -0
- package/lib/packlets/argon2/index.js.map +1 -0
- package/lib/packlets/argon2/nodeArgon2Provider.d.ts +28 -0
- package/lib/packlets/argon2/nodeArgon2Provider.d.ts.map +1 -0
- package/lib/packlets/argon2/nodeArgon2Provider.js +117 -0
- package/lib/packlets/argon2/nodeArgon2Provider.js.map +1 -0
- package/lib/test/unit/argon2/crossRuntime.test.d.ts +2 -0
- package/lib/test/unit/argon2/crossRuntime.test.d.ts.map +1 -0
- package/lib/test/unit/argon2/crossRuntime.test.js +98 -0
- package/lib/test/unit/argon2/crossRuntime.test.js.map +1 -0
- package/lib/test/unit/argon2/nodeArgon2Provider.test.d.ts +2 -0
- package/lib/test/unit/argon2/nodeArgon2Provider.test.d.ts.map +1 -0
- package/lib/test/unit/argon2/nodeArgon2Provider.test.js +102 -0
- package/lib/test/unit/argon2/nodeArgon2Provider.test.js.map +1 -0
- package/package.json +20 -20
- package/rush-logs/ts-extras-argon2.build.cache.log +3 -0
- package/rush-logs/ts-extras-argon2.build.log +9 -0
- package/temp/build/lint/_eslint-5eVG3S6w.json +26 -0
- package/temp/build/typescript/ts_8nwakTlr.json +1 -0
- package/temp/ts-extras-argon2.api.json +382 -0
- package/temp/ts-extras-argon2.api.md +20 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
Start time: Wed May 13 2026 09:54:14 GMT+0000 (Coordinated Universal Time)
|
|
2
|
+
Invoking "/usr/bin/tar -c -f /home/runner/work/fgv/fgv/common/temp/build-cache/8a928d1da9c45991e3e0e971522b429d0ffc824a-f35be0a8b8309d8d.temp -z --files-from=-"
|
|
3
|
+
|
|
4
|
+
======= BEGIN PROCESS INPUT ======
|
|
5
|
+
.rush/temp/operation/build/all.log
|
|
6
|
+
.rush/temp/operation/build/log-chunks.jsonl
|
|
7
|
+
.rush/temp/operation/build/state.json
|
|
8
|
+
dist/index.js
|
|
9
|
+
dist/index.js.map
|
|
10
|
+
dist/packlets/argon2/index.js
|
|
11
|
+
dist/packlets/argon2/index.js.map
|
|
12
|
+
dist/packlets/argon2/nodeArgon2Provider.js
|
|
13
|
+
dist/packlets/argon2/nodeArgon2Provider.js.map
|
|
14
|
+
dist/test/unit/argon2/crossRuntime.test.js
|
|
15
|
+
dist/test/unit/argon2/crossRuntime.test.js.map
|
|
16
|
+
dist/test/unit/argon2/nodeArgon2Provider.test.js
|
|
17
|
+
dist/test/unit/argon2/nodeArgon2Provider.test.js.map
|
|
18
|
+
dist/ts-extras-argon2.d.ts
|
|
19
|
+
dist/tsdoc-metadata.json
|
|
20
|
+
lib/index.d.ts
|
|
21
|
+
lib/index.d.ts.map
|
|
22
|
+
lib/index.js
|
|
23
|
+
lib/index.js.map
|
|
24
|
+
lib/packlets/argon2/index.d.ts
|
|
25
|
+
lib/packlets/argon2/index.d.ts.map
|
|
26
|
+
lib/packlets/argon2/index.js
|
|
27
|
+
lib/packlets/argon2/index.js.map
|
|
28
|
+
lib/packlets/argon2/nodeArgon2Provider.d.ts
|
|
29
|
+
lib/packlets/argon2/nodeArgon2Provider.d.ts.map
|
|
30
|
+
lib/packlets/argon2/nodeArgon2Provider.js
|
|
31
|
+
lib/packlets/argon2/nodeArgon2Provider.js.map
|
|
32
|
+
lib/test/unit/argon2/crossRuntime.test.d.ts
|
|
33
|
+
lib/test/unit/argon2/crossRuntime.test.d.ts.map
|
|
34
|
+
lib/test/unit/argon2/crossRuntime.test.js
|
|
35
|
+
lib/test/unit/argon2/crossRuntime.test.js.map
|
|
36
|
+
lib/test/unit/argon2/nodeArgon2Provider.test.d.ts
|
|
37
|
+
lib/test/unit/argon2/nodeArgon2Provider.test.d.ts.map
|
|
38
|
+
lib/test/unit/argon2/nodeArgon2Provider.test.js
|
|
39
|
+
lib/test/unit/argon2/nodeArgon2Provider.test.js.map
|
|
40
|
+
temp/build/lint/_eslint-5eVG3S6w.json
|
|
41
|
+
temp/build/typescript/ts_8nwakTlr.json
|
|
42
|
+
temp/ts-extras-argon2.api.json
|
|
43
|
+
temp/ts-extras-argon2.api.md
|
|
44
|
+
======== END PROCESS INPUT =======
|
|
45
|
+
======= BEGIN PROCESS OUTPUT =======
|
|
46
|
+
======== END PROCESS OUTPUT ========
|
|
47
|
+
|
|
48
|
+
Exited with code "0"
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{"kind":"O","text":"Invoking: heft build --clean \n"}
|
|
2
|
+
{"kind":"O","text":" ---- build started ---- \n"}
|
|
3
|
+
{"kind":"O","text":"[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.\n"}
|
|
4
|
+
{"kind":"O","text":"[build:typescript] Using TypeScript version 5.9.3\n"}
|
|
5
|
+
{"kind":"O","text":"[build:lint] Using ESLint version 9.39.4\n"}
|
|
6
|
+
{"kind":"O","text":"[build:api-extractor] Using API Extractor version 7.58.7\n"}
|
|
7
|
+
{"kind":"O","text":"[build:api-extractor] Analysis will use the bundled TypeScript version 5.9.3\n"}
|
|
8
|
+
{"kind":"O","text":" ---- build finished (14.582s) ---- \n"}
|
|
9
|
+
{"kind":"O","text":"-------------------- Finished (14.59s) --------------------\n"}
|
|
@@ -0,0 +1,9 @@
|
|
|
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.4
|
|
6
|
+
[build:api-extractor] Using API Extractor version 7.58.7
|
|
7
|
+
[build:api-extractor] Analysis will use the bundled TypeScript version 5.9.3
|
|
8
|
+
---- build finished (14.582s) ----
|
|
9
|
+
-------------------- Finished (14.59s) --------------------
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{"kind":"O","text":"Invoking: heft build --clean \n"}
|
|
2
|
+
{"kind":"O","text":" ---- build started ---- \n"}
|
|
3
|
+
{"kind":"O","text":"[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.\n"}
|
|
4
|
+
{"kind":"O","text":"[build:typescript] Using TypeScript version 5.9.3\n"}
|
|
5
|
+
{"kind":"O","text":"[build:lint] Using ESLint version 9.39.4\n"}
|
|
6
|
+
{"kind":"O","text":"[build:api-extractor] Using API Extractor version 7.58.7\n"}
|
|
7
|
+
{"kind":"O","text":"[build:api-extractor] Analysis will use the bundled TypeScript version 5.9.3\n"}
|
|
8
|
+
{"kind":"O","text":" ---- build finished (14.582s) ---- \n"}
|
|
9
|
+
{"kind":"O","text":"-------------------- Finished (14.59s) --------------------\n"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
export { NodeArgon2Provider, CryptoUtils } from './packlets/argon2';
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.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,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,mBAAmB,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\nexport { NodeArgon2Provider, CryptoUtils } from './packlets/argon2';\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
export { NodeArgon2Provider } from './nodeArgon2Provider';
|
|
21
|
+
// Re-export CryptoUtils namespace from ts-extras for consumer convenience
|
|
22
|
+
// (provides IArgon2idProvider, IArgon2idParams, ARGON2ID_OWASP_MIN, ARGON2ID_PASSPHRASE).
|
|
23
|
+
export { CryptoUtils } from '@fgv/ts-extras';
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/argon2/index.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,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,0EAA0E;AAC1E,0FAA0F;AAC1F,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,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\nexport { NodeArgon2Provider } from './nodeArgon2Provider';\n\n// Re-export CryptoUtils namespace from ts-extras for consumer convenience\n// (provides IArgon2idProvider, IArgon2idParams, ARGON2ID_OWASP_MIN, ARGON2ID_PASSPHRASE).\nexport { CryptoUtils } from '@fgv/ts-extras';\n"]}
|
|
@@ -0,0 +1,80 @@
|
|
|
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
|
+
import * as argon2 from 'argon2';
|
|
21
|
+
import { captureAsyncResult, fail, succeed } from '@fgv/ts-utils';
|
|
22
|
+
/**
|
|
23
|
+
* Node.js implementation of {@link @fgv/ts-extras#IArgon2idProvider} backed by the
|
|
24
|
+
* `argon2` (kelektiv) native binding.
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
export class NodeArgon2Provider {
|
|
28
|
+
constructor() { }
|
|
29
|
+
/**
|
|
30
|
+
* Creates a new {@link NodeArgon2Provider} instance.
|
|
31
|
+
* @returns Success with a new provider instance.
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
static create() {
|
|
35
|
+
return succeed(new NodeArgon2Provider());
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Derives a key using Argon2id.
|
|
39
|
+
*
|
|
40
|
+
* @param password - The password or passphrase (string or raw bytes).
|
|
41
|
+
* @param salt - The salt (must be at least 8 bytes; 16+ bytes recommended).
|
|
42
|
+
* @param params - Argon2id parameters. All values are validated before derivation.
|
|
43
|
+
* @returns Success with the derived key bytes, or Failure with a descriptive message.
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
46
|
+
async argon2id(password, salt, params) {
|
|
47
|
+
const error = NodeArgon2Provider._validateParams(params);
|
|
48
|
+
if (error !== undefined) {
|
|
49
|
+
return fail(error);
|
|
50
|
+
}
|
|
51
|
+
return captureAsyncResult(async () => {
|
|
52
|
+
const result = await argon2.hash(password instanceof Uint8Array ? Buffer.from(password) : password, {
|
|
53
|
+
type: argon2.argon2id,
|
|
54
|
+
salt: Buffer.from(salt),
|
|
55
|
+
memoryCost: params.memoryKiB,
|
|
56
|
+
timeCost: params.iterations,
|
|
57
|
+
parallelism: params.parallelism,
|
|
58
|
+
hashLength: params.outputBytes,
|
|
59
|
+
raw: true
|
|
60
|
+
});
|
|
61
|
+
return Uint8Array.from(result);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
static _validateParams(params) {
|
|
65
|
+
if (params.memoryKiB < 8) {
|
|
66
|
+
return `argon2id: memoryKiB must be >= 8, got ${params.memoryKiB}`;
|
|
67
|
+
}
|
|
68
|
+
if (params.iterations < 1) {
|
|
69
|
+
return `argon2id: iterations must be >= 1, got ${params.iterations}`;
|
|
70
|
+
}
|
|
71
|
+
if (params.parallelism < 1 || params.parallelism > 255) {
|
|
72
|
+
return `argon2id: parallelism must be 1..255, got ${params.parallelism}`;
|
|
73
|
+
}
|
|
74
|
+
if (params.outputBytes < 4) {
|
|
75
|
+
return `argon2id: outputBytes must be >= 4, got ${params.outputBytes}`;
|
|
76
|
+
}
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=nodeArgon2Provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodeArgon2Provider.js","sourceRoot":"","sources":["../../../src/packlets/argon2/nodeArgon2Provider.ts"],"names":[],"mappings":"AAA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U,EAAE,MAAM,CAAC,WAAW;gBAC9B,GAAG,EAAE,IAAI;aACV,CAAC,CAAC;YACH,OAAO,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACjC,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,MAAM,CAAC,eAAe,CAAC,MAAmC;QAChE,IAAI,MAAM,CAAC,SAAS,GAAG,CAAC,EAAE,CAAC;YACzB,OAAO,yCAAyC,MAAM,CAAC,SAAS,EAAE,CAAC;QACrE,CAAC;QACD,IAAI,MAAM,CAAC,UAAU,GAAG,CAAC,EAAE,CAAC;YAC1B,OAAO,0CAA0C,MAAM,CAAC,UAAU,EAAE,CAAC;QACvE,CAAC;QACD,IAAI,MAAM,CAAC,WAAW,GAAG,CAAC,IAAI,MAAM,CAAC,WAAW,GAAG,GAAG,EAAE,CAAC;YACvD,OAAO,6CAA6C,MAAM,CAAC,WAAW,EAAE,CAAC;QAC3E,CAAC;QACD,IAAI,MAAM,CAAC,WAAW,GAAG,CAAC,EAAE,CAAC;YAC3B,OAAO,2CAA2C,MAAM,CAAC,WAAW,EAAE,CAAC;QACzE,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF","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 * as argon2 from 'argon2';\nimport { Result, captureAsyncResult, fail, succeed } from '@fgv/ts-utils';\nimport { CryptoUtils } from '@fgv/ts-extras';\n\n/**\n * Node.js implementation of {@link @fgv/ts-extras#IArgon2idProvider} backed by the\n * `argon2` (kelektiv) native binding.\n * @public\n */\nexport class NodeArgon2Provider implements CryptoUtils.IArgon2idProvider {\n private constructor() {}\n\n /**\n * Creates a new {@link NodeArgon2Provider} instance.\n * @returns Success with a new provider instance.\n * @public\n */\n public static create(): Result<NodeArgon2Provider> {\n return succeed(new NodeArgon2Provider());\n }\n\n /**\n * Derives a key using Argon2id.\n *\n * @param password - The password or passphrase (string or raw bytes).\n * @param salt - The salt (must be at least 8 bytes; 16+ bytes recommended).\n * @param params - Argon2id parameters. All values are validated before derivation.\n * @returns Success with the derived key bytes, or Failure with a descriptive message.\n * @public\n */\n public async argon2id(\n password: Uint8Array | string,\n salt: Uint8Array,\n params: CryptoUtils.IArgon2idParams\n ): Promise<Result<Uint8Array>> {\n const error = NodeArgon2Provider._validateParams(params);\n if (error !== undefined) {\n return fail(error);\n }\n\n return captureAsyncResult(async () => {\n const result = await argon2.hash(password instanceof Uint8Array ? Buffer.from(password) : password, {\n type: argon2.argon2id,\n salt: Buffer.from(salt),\n memoryCost: params.memoryKiB,\n timeCost: params.iterations,\n parallelism: params.parallelism,\n hashLength: params.outputBytes,\n raw: true\n });\n return Uint8Array.from(result);\n });\n }\n\n private static _validateParams(params: CryptoUtils.IArgon2idParams): string | undefined {\n if (params.memoryKiB < 8) {\n return `argon2id: memoryKiB must be >= 8, got ${params.memoryKiB}`;\n }\n if (params.iterations < 1) {\n return `argon2id: iterations must be >= 1, got ${params.iterations}`;\n }\n if (params.parallelism < 1 || params.parallelism > 255) {\n return `argon2id: parallelism must be 1..255, got ${params.parallelism}`;\n }\n if (params.outputBytes < 4) {\n return `argon2id: outputBytes must be >= 4, got ${params.outputBytes}`;\n }\n return undefined;\n }\n}\n"]}
|
|
@@ -0,0 +1,96 @@
|
|
|
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
|
+
import '@fgv/ts-utils-jest';
|
|
21
|
+
import { NodeArgon2Provider } from '../../../packlets/argon2';
|
|
22
|
+
import { BrowserArgon2Provider } from '@fgv/ts-web-extras-argon2';
|
|
23
|
+
// RFC 9106 §B.3 parameter set (no secret/AD — our IArgon2idParams interface does not expose
|
|
24
|
+
// those optional Argon2 fields). Both implementations must agree on this exact output.
|
|
25
|
+
const RFC_PARAMS = {
|
|
26
|
+
memoryKiB: 32,
|
|
27
|
+
iterations: 3,
|
|
28
|
+
parallelism: 4,
|
|
29
|
+
outputBytes: 32
|
|
30
|
+
};
|
|
31
|
+
const RFC_PASSWORD = new Uint8Array(32).fill(0x01);
|
|
32
|
+
const RFC_SALT = new Uint8Array(16).fill(0x02);
|
|
33
|
+
// Verified independently against both argon2 (kelektiv) and hash-wasm.
|
|
34
|
+
const RFC_EXPECTED_HEX = '03aab965c12001c9d7d0d2de33192c0494b684bb148196d73c1df1acaf6d0c2e';
|
|
35
|
+
const SWEEP = [
|
|
36
|
+
{
|
|
37
|
+
label: 'RFC §B.3 base case',
|
|
38
|
+
password: RFC_PASSWORD,
|
|
39
|
+
salt: RFC_SALT,
|
|
40
|
+
params: RFC_PARAMS
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
label: 'string password',
|
|
44
|
+
password: 'correct horse battery staple',
|
|
45
|
+
salt: RFC_SALT,
|
|
46
|
+
params: RFC_PARAMS
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
label: 'higher memoryKiB',
|
|
50
|
+
password: RFC_PASSWORD,
|
|
51
|
+
salt: RFC_SALT,
|
|
52
|
+
params: Object.assign(Object.assign({}, RFC_PARAMS), { memoryKiB: 64 })
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
label: 'more iterations',
|
|
56
|
+
password: RFC_PASSWORD,
|
|
57
|
+
salt: RFC_SALT,
|
|
58
|
+
params: Object.assign(Object.assign({}, RFC_PARAMS), { iterations: 5 })
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
label: 'parallelism=1',
|
|
62
|
+
password: RFC_PASSWORD,
|
|
63
|
+
salt: RFC_SALT,
|
|
64
|
+
params: Object.assign(Object.assign({}, RFC_PARAMS), { parallelism: 1 })
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
label: 'longer output (64 bytes)',
|
|
68
|
+
password: RFC_PASSWORD,
|
|
69
|
+
salt: RFC_SALT,
|
|
70
|
+
params: Object.assign(Object.assign({}, RFC_PARAMS), { outputBytes: 64 })
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
label: 'different salt',
|
|
74
|
+
password: RFC_PASSWORD,
|
|
75
|
+
salt: new Uint8Array(16).fill(0x07),
|
|
76
|
+
params: RFC_PARAMS
|
|
77
|
+
}
|
|
78
|
+
];
|
|
79
|
+
describe('cross-runtime equivalence: NodeArgon2Provider vs BrowserArgon2Provider', () => {
|
|
80
|
+
let node;
|
|
81
|
+
let browser;
|
|
82
|
+
beforeEach(() => {
|
|
83
|
+
node = NodeArgon2Provider.create().orThrow();
|
|
84
|
+
browser = BrowserArgon2Provider.create().orThrow();
|
|
85
|
+
});
|
|
86
|
+
test('RFC §B.3 parameter set matches known-good hex output', async () => {
|
|
87
|
+
const nodeBytes = (await node.argon2id(RFC_PASSWORD, RFC_SALT, RFC_PARAMS)).orThrow();
|
|
88
|
+
expect(Buffer.from(nodeBytes).toString('hex')).toBe(RFC_EXPECTED_HEX);
|
|
89
|
+
});
|
|
90
|
+
test.each(SWEEP)('$label: outputs are byte-identical', async ({ password, salt, params }) => {
|
|
91
|
+
const nodeBytes = (await node.argon2id(password, salt, params)).orThrow();
|
|
92
|
+
const browserBytes = (await browser.argon2id(password, salt, params)).orThrow();
|
|
93
|
+
expect(nodeBytes).toEqual(browserBytes);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
//# sourceMappingURL=crossRuntime.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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;AAChF,+EAA+E;AAC/E,4EAA4E;AAC5E,wEAAwE;AACxE,2DAA2D;AAC3D,EAAE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AC,QAAQ,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;QAC1E,MAAM,YAAY,GAAG,CAAC,MAAM,OAAO,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;QAChF,MAAM,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAC1C,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"]}
|
|
@@ -0,0 +1,100 @@
|
|
|
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
|
+
import '@fgv/ts-utils-jest';
|
|
21
|
+
import { NodeArgon2Provider } from '../../../packlets/argon2';
|
|
22
|
+
// RFC 9106 §B.3 parameter set (no secret/AD — our interface does not expose those fields).
|
|
23
|
+
// t=3, m=32, p=4, tag=32. Used for determinism and cross-runtime agreement.
|
|
24
|
+
const RFC_PARAMS = {
|
|
25
|
+
memoryKiB: 32,
|
|
26
|
+
iterations: 3,
|
|
27
|
+
parallelism: 4,
|
|
28
|
+
outputBytes: 32
|
|
29
|
+
};
|
|
30
|
+
const RFC_PASSWORD = new Uint8Array(32).fill(0x01);
|
|
31
|
+
const RFC_SALT = new Uint8Array(16).fill(0x02);
|
|
32
|
+
describe('NodeArgon2Provider', () => {
|
|
33
|
+
let provider;
|
|
34
|
+
beforeEach(() => {
|
|
35
|
+
provider = NodeArgon2Provider.create().orThrow();
|
|
36
|
+
});
|
|
37
|
+
describe('create()', () => {
|
|
38
|
+
test('returns a provider instance', () => {
|
|
39
|
+
expect(NodeArgon2Provider.create()).toSucceedAndSatisfy((p) => {
|
|
40
|
+
expect(p).toBeInstanceOf(NodeArgon2Provider);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
describe('argon2id()', () => {
|
|
45
|
+
test('derives a key with Uint8Array password', async () => {
|
|
46
|
+
expect(await provider.argon2id(RFC_PASSWORD, RFC_SALT, RFC_PARAMS)).toSucceedAndSatisfy((bytes) => {
|
|
47
|
+
expect(bytes).toBeInstanceOf(Uint8Array);
|
|
48
|
+
expect(bytes.length).toBe(RFC_PARAMS.outputBytes);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
test('derives a key with string password', async () => {
|
|
52
|
+
expect(await provider.argon2id('password', RFC_SALT, RFC_PARAMS)).toSucceedAndSatisfy((bytes) => {
|
|
53
|
+
expect(bytes).toBeInstanceOf(Uint8Array);
|
|
54
|
+
expect(bytes.length).toBe(RFC_PARAMS.outputBytes);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
test('is deterministic — same inputs produce identical bytes', async () => {
|
|
58
|
+
const r1 = (await provider.argon2id(RFC_PASSWORD, RFC_SALT, RFC_PARAMS)).orThrow();
|
|
59
|
+
const r2 = (await provider.argon2id(RFC_PASSWORD, RFC_SALT, RFC_PARAMS)).orThrow();
|
|
60
|
+
expect(r1).toEqual(r2);
|
|
61
|
+
});
|
|
62
|
+
test('different passwords produce different bytes', async () => {
|
|
63
|
+
const a = (await provider.argon2id(new Uint8Array(32).fill(0x01), RFC_SALT, RFC_PARAMS)).orThrow();
|
|
64
|
+
const b = (await provider.argon2id(new Uint8Array(32).fill(0x02), RFC_SALT, RFC_PARAMS)).orThrow();
|
|
65
|
+
expect(a).not.toEqual(b);
|
|
66
|
+
});
|
|
67
|
+
test('different salts produce different bytes', async () => {
|
|
68
|
+
const a = (await provider.argon2id(RFC_PASSWORD, new Uint8Array(16).fill(0x02), RFC_PARAMS)).orThrow();
|
|
69
|
+
const b = (await provider.argon2id(RFC_PASSWORD, new Uint8Array(16).fill(0x03), RFC_PARAMS)).orThrow();
|
|
70
|
+
expect(a).not.toEqual(b);
|
|
71
|
+
});
|
|
72
|
+
test('respects outputBytes', async () => {
|
|
73
|
+
expect(await provider.argon2id(RFC_PASSWORD, RFC_SALT, Object.assign(Object.assign({}, RFC_PARAMS), { outputBytes: 64 }))).toSucceedAndSatisfy((bytes) => {
|
|
74
|
+
expect(bytes.length).toBe(64);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
test('returns failure when underlying library rejects (salt too short)', async () => {
|
|
78
|
+
const tinySalt = new Uint8Array(1).fill(0x02); // argon2 requires >= 8 bytes
|
|
79
|
+
expect(await provider.argon2id(RFC_PASSWORD, tinySalt, RFC_PARAMS)).toFail();
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
describe('parameter validation', () => {
|
|
83
|
+
test('fails when memoryKiB < 8', async () => {
|
|
84
|
+
expect(await provider.argon2id(RFC_PASSWORD, RFC_SALT, Object.assign(Object.assign({}, RFC_PARAMS), { memoryKiB: 7 }))).toFailWith(/memoryKiB must be >= 8/i);
|
|
85
|
+
});
|
|
86
|
+
test('fails when iterations < 1', async () => {
|
|
87
|
+
expect(await provider.argon2id(RFC_PASSWORD, RFC_SALT, Object.assign(Object.assign({}, RFC_PARAMS), { iterations: 0 }))).toFailWith(/iterations must be >= 1/i);
|
|
88
|
+
});
|
|
89
|
+
test('fails when parallelism < 1', async () => {
|
|
90
|
+
expect(await provider.argon2id(RFC_PASSWORD, RFC_SALT, Object.assign(Object.assign({}, RFC_PARAMS), { parallelism: 0 }))).toFailWith(/parallelism must be 1\.\.255/i);
|
|
91
|
+
});
|
|
92
|
+
test('fails when parallelism > 255', async () => {
|
|
93
|
+
expect(await provider.argon2id(RFC_PASSWORD, RFC_SALT, Object.assign(Object.assign({}, RFC_PARAMS), { parallelism: 256 }))).toFailWith(/parallelism must be 1\.\.255/i);
|
|
94
|
+
});
|
|
95
|
+
test('fails when outputBytes < 4', async () => {
|
|
96
|
+
expect(await provider.argon2id(RFC_PASSWORD, RFC_SALT, Object.assign(Object.assign({}, RFC_PARAMS), { outputBytes: 3 }))).toFailWith(/outputBytes must be >= 4/i);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
//# sourceMappingURL=nodeArgon2Provider.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,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W,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('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"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { CryptoUtils } from '@fgv/ts-extras';
|
|
2
|
+
import { Result } from '@fgv/ts-utils';
|
|
3
|
+
|
|
4
|
+
export { CryptoUtils }
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Node.js implementation of {@link @fgv/ts-extras#IArgon2idProvider} backed by the
|
|
8
|
+
* `argon2` (kelektiv) native binding.
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export declare class NodeArgon2Provider implements CryptoUtils.IArgon2idProvider {
|
|
12
|
+
private constructor();
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new {@link NodeArgon2Provider} instance.
|
|
15
|
+
* @returns Success with a new provider instance.
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
static create(): Result<NodeArgon2Provider>;
|
|
19
|
+
/**
|
|
20
|
+
* Derives a key using Argon2id.
|
|
21
|
+
*
|
|
22
|
+
* @param password - The password or passphrase (string or raw bytes).
|
|
23
|
+
* @param salt - The salt (must be at least 8 bytes; 16+ bytes recommended).
|
|
24
|
+
* @param params - Argon2id parameters. All values are validated before derivation.
|
|
25
|
+
* @returns Success with the derived key bytes, or Failure with a descriptive message.
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
argon2id(password: Uint8Array | string, salt: Uint8Array, params: CryptoUtils.IArgon2idParams): Promise<Result<Uint8Array>>;
|
|
29
|
+
private static _validateParams;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { }
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
|
2
|
+
// It should be published with your NPM package. It should not be tracked by Git.
|
|
3
|
+
{
|
|
4
|
+
"tsdocVersion": "0.12",
|
|
5
|
+
"toolPackages": [
|
|
6
|
+
{
|
|
7
|
+
"packageName": "@microsoft/api-extractor",
|
|
8
|
+
"packageVersion": "7.58.7"
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
exports.CryptoUtils = exports.NodeArgon2Provider = void 0;
|
|
23
|
+
var argon2_1 = require("./packlets/argon2");
|
|
24
|
+
Object.defineProperty(exports, "NodeArgon2Provider", { enumerable: true, get: function () { return argon2_1.NodeArgon2Provider; } });
|
|
25
|
+
Object.defineProperty(exports, "CryptoUtils", { enumerable: true, get: function () { return argon2_1.CryptoUtils; } });
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.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,4CAAoE;AAA3D,4GAAA,kBAAkB,OAAA;AAAE,qGAAA,WAAW,OAAA","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\nexport { NodeArgon2Provider, CryptoUtils } from './packlets/argon2';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/argon2/index.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAI1D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
exports.CryptoUtils = exports.NodeArgon2Provider = void 0;
|
|
23
|
+
var nodeArgon2Provider_1 = require("./nodeArgon2Provider");
|
|
24
|
+
Object.defineProperty(exports, "NodeArgon2Provider", { enumerable: true, get: function () { return nodeArgon2Provider_1.NodeArgon2Provider; } });
|
|
25
|
+
// Re-export CryptoUtils namespace from ts-extras for consumer convenience
|
|
26
|
+
// (provides IArgon2idProvider, IArgon2idParams, ARGON2ID_OWASP_MIN, ARGON2ID_PASSPHRASE).
|
|
27
|
+
var ts_extras_1 = require("@fgv/ts-extras");
|
|
28
|
+
Object.defineProperty(exports, "CryptoUtils", { enumerable: true, get: function () { return ts_extras_1.CryptoUtils; } });
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/argon2/index.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,2DAA0D;AAAjD,wHAAA,kBAAkB,OAAA;AAE3B,0EAA0E;AAC1E,0FAA0F;AAC1F,4CAA6C;AAApC,wGAAA,WAAW,OAAA","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\nexport { NodeArgon2Provider } from './nodeArgon2Provider';\n\n// Re-export CryptoUtils namespace from ts-extras for consumer convenience\n// (provides IArgon2idProvider, IArgon2idParams, ARGON2ID_OWASP_MIN, ARGON2ID_PASSPHRASE).\nexport { CryptoUtils } from '@fgv/ts-extras';\n"]}
|