salty-crypto 0.3.1 → 1.0.0-rc.0

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 (107) hide show
  1. package/README.md +3 -3
  2. package/browser-demo.html +1 -1
  3. package/dist/salty-crypto.d.mts +348 -0
  4. package/dist/salty-crypto.d.ts +36 -87
  5. package/dist/salty-crypto.global.js +2 -0
  6. package/dist/salty-crypto.global.js.map +1 -0
  7. package/dist/salty-crypto.js +2 -1
  8. package/dist/salty-crypto.js.map +1 -0
  9. package/dist/salty-crypto.mjs +2 -0
  10. package/dist/salty-crypto.mjs.map +1 -0
  11. package/lib/aead/chacha20poly1305.d.ts +1 -1
  12. package/lib/aead/chacha20poly1305.js +5 -5
  13. package/lib/aead/chacha20poly1305.js.map +1 -1
  14. package/lib/aead.d.ts +2 -2
  15. package/lib/aead.js +2 -2
  16. package/lib/aead.js.map +1 -1
  17. package/lib/bytes.d.ts +1 -1
  18. package/lib/bytes.js +1 -1
  19. package/lib/bytes.js.map +1 -1
  20. package/lib/cipher/chacha20.d.ts +1 -1
  21. package/lib/cipher/chacha20.js +1 -1
  22. package/lib/cipher/chacha20.js.map +1 -1
  23. package/lib/cipher.d.ts +2 -2
  24. package/lib/cipher.js +2 -2
  25. package/lib/cipher.js.map +1 -1
  26. package/lib/dh/x25519.js +1 -1
  27. package/lib/dh/x25519.js.map +1 -1
  28. package/lib/dh.js +3 -3
  29. package/lib/dh.js.map +1 -1
  30. package/lib/hash/blake2s.d.ts +4 -4
  31. package/lib/hash/blake2s.js +5 -5
  32. package/lib/hash/blake2s.js.map +1 -1
  33. package/lib/hash/poly1305.d.ts +4 -4
  34. package/lib/hash/poly1305.js +4 -4
  35. package/lib/hash/poly1305.js.map +1 -1
  36. package/lib/hash.d.ts +2 -2
  37. package/lib/hash.js +3 -3
  38. package/lib/hash.js.map +1 -1
  39. package/lib/hkdf.d.ts +1 -1
  40. package/lib/hkdf.js +2 -2
  41. package/lib/hkdf.js.map +1 -1
  42. package/lib/hmac.d.ts +1 -1
  43. package/lib/hmac.js +2 -2
  44. package/lib/hmac.js.map +1 -1
  45. package/lib/index.d.ts +22 -22
  46. package/lib/index.js +23 -23
  47. package/lib/index.js.map +1 -1
  48. package/lib/io.js +2 -0
  49. package/lib/io.js.map +1 -1
  50. package/lib/noise/algorithms.d.ts +6 -6
  51. package/lib/noise/algorithms.js +1 -1
  52. package/lib/noise/algorithms.js.map +1 -1
  53. package/lib/noise/cipherstate.d.ts +2 -2
  54. package/lib/noise/cipherstate.js +3 -3
  55. package/lib/noise/cipherstate.js.map +1 -1
  56. package/lib/noise/handshake.d.ts +7 -7
  57. package/lib/noise/handshake.js +6 -6
  58. package/lib/noise/handshake.js.map +1 -1
  59. package/lib/noise/patterns.js +1 -1
  60. package/lib/noise/patterns.js.map +1 -1
  61. package/lib/noise/profiles.d.ts +1 -1
  62. package/lib/noise/profiles.js +4 -4
  63. package/lib/noise/profiles.js.map +1 -1
  64. package/lib/noise/rekey.d.ts +1 -1
  65. package/lib/noise/rekey.js +2 -2
  66. package/lib/noise/rekey.js.map +1 -1
  67. package/lib/noise.js +1 -1
  68. package/lib/noise.js.map +1 -1
  69. package/lib/nonce.js +1 -1
  70. package/lib/nonce.js.map +1 -1
  71. package/lib/random.js +2 -3
  72. package/lib/random.js.map +1 -1
  73. package/package.json +29 -23
  74. package/src/.DS_Store +0 -0
  75. package/src/aead/chacha20poly1305.ts +7 -7
  76. package/src/aead.ts +3 -3
  77. package/src/bytes.ts +1 -1
  78. package/src/cipher/chacha20.ts +3 -3
  79. package/src/cipher.ts +3 -3
  80. package/src/dh/x25519.ts +1 -1
  81. package/src/dh.ts +3 -3
  82. package/src/hash/blake2s.ts +2 -2
  83. package/src/hash/poly1305.ts +2 -2
  84. package/src/hash.ts +3 -3
  85. package/src/hkdf.ts +3 -3
  86. package/src/hmac.ts +3 -3
  87. package/src/index.ts +23 -23
  88. package/src/io.ts +3 -0
  89. package/src/noise/algorithms.ts +7 -7
  90. package/src/noise/cipherstate.ts +4 -4
  91. package/src/noise/handshake.ts +8 -8
  92. package/src/noise/patterns.ts +1 -1
  93. package/src/noise/profiles.ts +5 -5
  94. package/src/noise/rekey.ts +3 -3
  95. package/src/noise.ts +1 -1
  96. package/src/nonce.ts +1 -1
  97. package/src/random.ts +2 -3
  98. package/test/{tests/aead.test.ts → aead.test.ts} +2 -2
  99. package/test/{tests/blake2.test.ts → blake2.test.ts} +2 -2
  100. package/test/{tests/chacha20.test.ts → chacha20.test.ts} +2 -2
  101. package/test/{tests/io.test.ts → io.test.ts} +2 -2
  102. package/test/{tests/noise.test.ts → noise.test.ts} +2 -2
  103. package/test/{tests/poly1305.test.ts → poly1305.test.ts} +2 -2
  104. package/tsup.config.ts +14 -0
  105. package/rollup.config.js +0 -19
  106. package/test/harness.ts +0 -74
  107. package/test/tsconfig.json +0 -18
@@ -1,13 +1,13 @@
1
1
  /// SPDX-License-Identifier: MIT
2
- /// SPDX-FileCopyrightText: Copyright © 2023 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
2
+ /// SPDX-FileCopyrightText: Copyright © 2023-2025 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
3
3
 
4
- import { AEAD } from '../aead';
5
- import { Hash } from '../hash';
6
- import { DH } from '../dh';
7
- import { HMAC } from '../hmac';
8
- import { HKDF } from '../hkdf';
4
+ import { AEAD } from '../aead.js';
5
+ import { Hash } from '../hash.js';
6
+ import { DH } from '../dh.js';
7
+ import { HMAC } from '../hmac.js';
8
+ import { HKDF } from '../hkdf.js';
9
9
 
10
- import { Rekey } from './rekey';
10
+ import { Rekey } from './rekey.js';
11
11
 
12
12
  export interface Algorithms {
13
13
  dh: DH,
@@ -1,9 +1,9 @@
1
1
  /// SPDX-License-Identifier: MIT
2
- /// SPDX-FileCopyrightText: Copyright © 2023 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
2
+ /// SPDX-FileCopyrightText: Copyright © 2023-2025 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
3
3
 
4
- import { Nonce } from '../nonce';
5
- import { makeRekey } from './rekey';
6
- import { Algorithms } from './algorithms';
4
+ import { Nonce } from '../nonce.js';
5
+ import { makeRekey } from './rekey.js';
6
+ import { Algorithms } from './algorithms.js';
7
7
 
8
8
  export class CipherState {
9
9
  view: DataView | null = null;
@@ -1,14 +1,14 @@
1
1
  /// SPDX-License-Identifier: MIT
2
- /// SPDX-FileCopyrightText: Copyright © 2023 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
2
+ /// SPDX-FileCopyrightText: Copyright © 2023-2025 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
3
3
 
4
- import { DHKeyPair } from '../dh';
5
- import * as Bytes from '../bytes';
4
+ import { DHKeyPair } from '../dh.js';
5
+ import * as Bytes from '../bytes.js';
6
6
 
7
- import { Algorithms } from './algorithms';
8
- import { CipherState } from './cipherstate';
9
- import { HandshakePattern, KeyMixToken, lookupPattern, Token } from './patterns';
10
- import { HKDF, makeHKDF } from '../hkdf';
11
- import { makeHMAC } from '../hmac';
7
+ import { Algorithms } from './algorithms.js';
8
+ import { CipherState } from './cipherstate.js';
9
+ import { HandshakePattern, KeyMixToken, lookupPattern, Token } from './patterns.js';
10
+ import { HKDF, makeHKDF } from '../hkdf.js';
11
+ import { makeHMAC } from '../hmac.js';
12
12
 
13
13
  export type Role = 'initiator' | 'responder';
14
14
 
@@ -1,5 +1,5 @@
1
1
  /// SPDX-License-Identifier: MIT
2
- /// SPDX-FileCopyrightText: Copyright © 2023 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
2
+ /// SPDX-FileCopyrightText: Copyright © 2023-2025 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
3
3
 
4
4
  export type KeyTransferToken = 'e' | 's';
5
5
  export type KeyMixToken = 'ee' | 'es' | 'se' | 'ss' | 'psk';
@@ -1,10 +1,10 @@
1
1
  /// SPDX-License-Identifier: MIT
2
- /// SPDX-FileCopyrightText: Copyright © 2023 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
2
+ /// SPDX-FileCopyrightText: Copyright © 2023-2025 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
3
3
 
4
- import { Algorithms } from './algorithms';
5
- import { BLAKE2s } from '../hash';
6
- import { ChaCha20Poly1305_RFC8439 } from '../aead';
7
- import { X25519 } from '../dh';
4
+ import { Algorithms } from './algorithms.js';
5
+ import { BLAKE2s } from '../hash.js';
6
+ import { ChaCha20Poly1305_RFC8439 } from '../aead.js';
7
+ import { X25519 } from '../dh.js';
8
8
 
9
9
  export const Noise_25519_ChaChaPoly_BLAKE2s: Algorithms = {
10
10
  dh: X25519,
@@ -1,8 +1,8 @@
1
1
  /// SPDX-License-Identifier: MIT
2
- /// SPDX-FileCopyrightText: Copyright © 2023 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
2
+ /// SPDX-FileCopyrightText: Copyright © 2023-2025 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
3
3
 
4
- import { AEAD } from '../aead';
5
- import { Nonce } from '../nonce';
4
+ import { AEAD } from '../aead.js';
5
+ import { Nonce } from '../nonce.js';
6
6
 
7
7
  export type Rekey = (k: DataView) => DataView;
8
8
 
package/src/noise.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /// SPDX-License-Identifier: MIT
2
- /// SPDX-FileCopyrightText: Copyright © 2023 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
2
+ /// SPDX-FileCopyrightText: Copyright © 2023-2025 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
3
3
 
4
4
  export { Algorithms, matchPattern } from './noise/algorithms';
5
5
  export { CipherState } from './noise/cipherstate';
package/src/nonce.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /// SPDX-License-Identifier: MIT
2
- /// SPDX-FileCopyrightText: Copyright © 2023 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
2
+ /// SPDX-FileCopyrightText: Copyright © 2023-2025 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
3
3
 
4
4
  export class Nonce {
5
5
  constructor(public lo = 0, public hi = 0, public extra = 0) {}
package/src/random.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /// SPDX-License-Identifier: MIT
2
- /// SPDX-FileCopyrightText: Copyright © 2023 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
2
+ /// SPDX-FileCopyrightText: Copyright © 2023-2025 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
3
3
 
4
4
  // TypeScript port of the randomness-generation code from nacl-fast.js from tweetnacl.
5
5
  //
@@ -12,7 +12,6 @@
12
12
  // // See for details: http://tweetnacl.cr.yp.to/
13
13
 
14
14
  export const _randomBytes: (out: Uint8Array, n: number) => void = (() => {
15
- var crypto: any = typeof self !== 'undefined' ? (self.crypto || (self as any).msCrypto) : null;
16
15
  if (crypto && crypto.getRandomValues) {
17
16
  const QUOTA = 65536;
18
17
  return (x: Uint8Array, n: number) => {
@@ -21,7 +20,7 @@ export const _randomBytes: (out: Uint8Array, n: number) => void = (() => {
21
20
  }
22
21
  };
23
22
  } else if (typeof require !== 'undefined') {
24
- crypto = require('crypto');
23
+ const crypto = require('crypto');
25
24
  if (crypto && crypto.randomBytes) {
26
25
  return (x: Uint8Array, n: number) => x.set(crypto.randomBytes(n));
27
26
  }
@@ -1,5 +1,5 @@
1
- import { ChaCha20Poly1305_RFC8439, Nonce } from '../../dist/salty-crypto.js';
2
- import { it, expect } from '../harness';
1
+ import { ChaCha20Poly1305_RFC8439, Nonce } from '../dist/salty-crypto.js';
2
+ import { it, expect } from 'vitest';
3
3
 
4
4
  it('section 2.8.2 from rfc 8439', () => {
5
5
  const sunscreen_str = "Ladies and Gentlemen of the class of '99: If I could offer you only one tip for the future, sunscreen would be it.";
@@ -1,5 +1,5 @@
1
- import { BLAKE2s } from '../../dist/salty-crypto.js';
2
- import { it, expect } from '../harness';
1
+ import { BLAKE2s } from '../dist/salty-crypto.js';
2
+ import { it, expect } from 'vitest';
3
3
 
4
4
  it('Appendix B of RFC 7693', () => {
5
5
  expect(BLAKE2s.digest(new TextEncoder().encode("abc"))).toEqual(Uint8Array.from([
@@ -1,6 +1,6 @@
1
- import { ChaCha20, INTERNALS, Nonce } from '../../dist/salty-crypto.js';
1
+ import { ChaCha20, INTERNALS, Nonce } from '../dist/salty-crypto.js';
2
2
  const { chacha20_quarter_round, chacha20_block } = INTERNALS.cipher.chacha20;
3
- import { it, expect } from '../harness';
3
+ import { it, expect } from 'vitest';
4
4
 
5
5
  it('chacha20_quarter_round 1', () => {
6
6
  const s = new Uint32Array(4);
@@ -1,5 +1,5 @@
1
- import { IO } from '../../dist/salty-crypto.js';
2
- import { describe, it, expect } from '../harness';
1
+ import { IO } from '../dist/salty-crypto.js';
2
+ import { describe, it, expect } from 'vitest';
3
3
 
4
4
  describe('basic', async () => {
5
5
  const s =
@@ -8,8 +8,8 @@ import {
8
8
  isOneWay,
9
9
  lookupPattern,
10
10
  matchPattern,
11
- } from '../../dist/salty-crypto.js';
12
- import { describe, it, expect } from '../harness';
11
+ } from '../dist/salty-crypto.js';
12
+ import { describe, it, expect } from 'vitest';
13
13
 
14
14
  import fs from 'fs';
15
15
  import path from 'path';
@@ -1,6 +1,6 @@
1
- import { Poly1305 } from '../../dist/salty-crypto.js';
1
+ import { Poly1305 } from '../dist/salty-crypto.js';
2
2
 
3
- import { it, expect } from '../harness';
3
+ import { it, expect } from 'vitest';
4
4
 
5
5
  it('section 2.5.2 from rfc 8439', () => {
6
6
  const key = Uint8Array.from([
package/tsup.config.ts ADDED
@@ -0,0 +1,14 @@
1
+ import { defineConfig } from 'tsup';
2
+
3
+ export default defineConfig({
4
+ entry: {
5
+ 'salty-crypto': 'src/index.ts',
6
+ },
7
+ format: ['cjs', 'esm', 'iife'],
8
+ globalName: 'SaltyCrypto',
9
+ dts: true,
10
+ sourcemap: true,
11
+ clean: true,
12
+ minify: true,
13
+ target: 'es2017',
14
+ });
package/rollup.config.js DELETED
@@ -1,19 +0,0 @@
1
- module.exports = [
2
- {
3
- input: 'lib/index.js',
4
- plugins: [require('@rollup/plugin-terser')()],
5
- output: {
6
- file: 'dist/salty-crypto.js',
7
- format: 'umd',
8
- name: 'SaltyCrypto',
9
- },
10
- },
11
- {
12
- input: 'lib/index.d.ts',
13
- plugins: [require('rollup-plugin-dts').default()],
14
- output: {
15
- file: 'dist/salty-crypto.d.ts',
16
- format: 'es',
17
- },
18
- },
19
- ];
package/test/harness.ts DELETED
@@ -1,74 +0,0 @@
1
- export { expect } from 'expect';
2
- import { JestAssertionError } from 'expect';
3
- import { glob } from 'glob';
4
- import path from 'path';
5
-
6
- export class Stats {
7
- total = 0;
8
- passed = 0;
9
- failed = 0;
10
- errors = 0;
11
-
12
- merge(s: Stats) {
13
- this.total += s.total;
14
- this.passed += s.passed;
15
- this.failed += s.failed;
16
- this.errors += s.errors;
17
- }
18
- }
19
-
20
- export let testDepth = 0;
21
- export let testStats = new Stats();
22
-
23
- function indent(msg: string) {
24
- let str = '';
25
- for (let i = 0; i < testDepth; i++) str = str + ' ';
26
- console.log(str + msg);
27
- }
28
-
29
- export async function describe(what: string, f: () => (Promise<void> | void)): Promise<void> {
30
- indent('- ' + what);
31
- testDepth++;
32
- await f();
33
- testDepth--;
34
- }
35
-
36
- export async function it(what: string, f: () => (Promise<void> | void)): Promise<void> {
37
- try {
38
- testStats.total++;
39
- await f();
40
- testStats.passed++;
41
- indent('✓ ' + what);
42
- } catch (exn) {
43
- if (exn instanceof JestAssertionError) {
44
- testStats.failed++;
45
- indent('\x1b[33m✗ ' + what + '\x1b[0m')
46
- console.error(`${'\x1b[31m'}${exn.message}${'\x1b[0m'}`);
47
- } else {
48
- testStats.errors++;
49
- throw exn;
50
- }
51
- }
52
- }
53
-
54
- export async function runTests(patterns: string[]): Promise<void> {
55
- for (const pattern of patterns) {
56
- const files = glob.sync(pattern, { nodir: true });
57
- for (const mod of files) {
58
- await describe(mod, async () => {
59
- await import(path.resolve(process.cwd(), mod));
60
- });
61
- }
62
- }
63
- }
64
-
65
- (async () => {
66
- if (Object.is(require.main, module)) {
67
- console.time('tests');
68
- let patterns = process.argv.slice(2);
69
- if (patterns.length === 0) patterns = ['./lib-test/**/*.test.js'];
70
- await runTests(patterns);
71
- console.timeEnd('tests');
72
- console.log(testStats);
73
- }
74
- })();
@@ -1,18 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es2017",
4
- "lib": ["ES2017", "DOM"],
5
- "declaration": true,
6
- "baseUrl": ".",
7
- "rootDir": ".",
8
- "outDir": "../lib-test",
9
- "declarationDir": "../lib-test",
10
- "esModuleInterop": true,
11
- "moduleResolution": "node",
12
- "module": "esnext",
13
- "sourceMap": true,
14
- "strict": true,
15
- "allowJs": true
16
- },
17
- "include": ["**/*"]
18
- }