@unknownncat/curve25519-node 2.0.0 → 2.1.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 (52) hide show
  1. package/NOTICE.md +89 -0
  2. package/README.en.md +110 -20
  3. package/README.md +102 -12
  4. package/SECURITY.md +23 -0
  5. package/THIRD_PARTY_NOTICE.md +3 -0
  6. package/THIRD_PARTY_NOTICES.md +5 -0
  7. package/dist/axlsign.d.ts.map +1 -1
  8. package/dist/axlsign.js +29 -7
  9. package/dist/axlsign.js.map +1 -1
  10. package/dist/cjs/axlsign.js +28 -6
  11. package/dist/cjs/axlsign.js.map +1 -1
  12. package/dist/cjs/ed25519.js +46 -10
  13. package/dist/cjs/ed25519.js.map +1 -1
  14. package/dist/cjs/index.js +27 -1
  15. package/dist/cjs/index.js.map +1 -1
  16. package/dist/cjs/internal/assert.js.map +1 -1
  17. package/dist/cjs/internal/curve25519-wasm/LICENSE +21 -0
  18. package/dist/cjs/internal/curve25519-wasm/curve25519_wasm.d.ts +12 -0
  19. package/dist/cjs/internal/curve25519-wasm/curve25519_wasm.js +165 -0
  20. package/dist/cjs/internal/curve25519-wasm/curve25519_wasm_bg.wasm +0 -0
  21. package/dist/cjs/internal/curve25519-wasm/curve25519_wasm_bg.wasm.d.ts +13 -0
  22. package/dist/cjs/internal/curve25519-wasm/package.json +17 -0
  23. package/dist/cjs/wasm.js +228 -0
  24. package/dist/cjs/wasm.js.map +1 -0
  25. package/dist/cjs/x25519.js +73 -12
  26. package/dist/cjs/x25519.js.map +1 -1
  27. package/dist/ed25519.d.ts +21 -0
  28. package/dist/ed25519.d.ts.map +1 -1
  29. package/dist/ed25519.js +44 -13
  30. package/dist/ed25519.js.map +1 -1
  31. package/dist/index.d.ts +87 -0
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +26 -0
  34. package/dist/index.js.map +1 -1
  35. package/dist/internal/assert.js.map +1 -1
  36. package/dist/internal/curve25519-wasm/LICENSE +21 -0
  37. package/dist/internal/curve25519-wasm/curve25519_wasm.d.ts +12 -0
  38. package/dist/internal/curve25519-wasm/curve25519_wasm.js +165 -0
  39. package/dist/internal/curve25519-wasm/curve25519_wasm_bg.wasm +0 -0
  40. package/dist/internal/curve25519-wasm/curve25519_wasm_bg.wasm.d.ts +13 -0
  41. package/dist/internal/curve25519-wasm/package.json +17 -0
  42. package/dist/types.d.ts +2 -5
  43. package/dist/types.d.ts.map +1 -1
  44. package/dist/wasm.d.ts +92 -0
  45. package/dist/wasm.d.ts.map +1 -0
  46. package/dist/wasm.js +204 -0
  47. package/dist/wasm.js.map +1 -0
  48. package/dist/x25519.d.ts +29 -0
  49. package/dist/x25519.d.ts.map +1 -1
  50. package/dist/x25519.js +66 -12
  51. package/dist/x25519.js.map +1 -1
  52. package/package.json +28 -5
package/NOTICE.md ADDED
@@ -0,0 +1,89 @@
1
+ # NOTICE
2
+
3
+ This repository is distributed under the MIT license and includes third-party software components.
4
+
5
+ Primary package: `@unknownncat/curve25519-node`
6
+ Repository: <https://github.com/unknownncat/curve25519-node>
7
+
8
+ ## Security and Disclosure
9
+
10
+ - Security policy: [SECURITY.md](./SECURITY.md)
11
+ - Vulnerability reporting should follow the private disclosure flow described in that file.
12
+
13
+ ## Direct ecosystem references
14
+
15
+ - `curve25519-js` — MIT or CC0 (as declared upstream)
16
+ <https://github.com/harveyconnor/curve25519-js>
17
+ - `TweetNaCl.js` — Public Domain (as declared upstream)
18
+ <https://tweetnacl.js.org/>
19
+ - OpenSSL (used through Node.js `node:crypto`) — Apache-2.0
20
+ <https://www.openssl.org/>
21
+
22
+ ## Rust/WASM dependency notices
23
+
24
+ The project contains two Rust/WASM crates:
25
+
26
+ - `wasm/curve25519-wasm`
27
+ - `wasm/axlsign`
28
+
29
+ License inventory was collected with:
30
+
31
+ ```bash
32
+ cargo license -t
33
+ ```
34
+
35
+ ### Crates present in both Rust projects
36
+
37
+ | Crate | License |
38
+ | -------------------------- | ----------------------------------- |
39
+ | block-buffer | Apache-2.0 OR MIT |
40
+ | bumpalo | Apache-2.0 OR MIT |
41
+ | cfg-if | Apache-2.0 OR MIT |
42
+ | cpufeatures | Apache-2.0 OR MIT |
43
+ | crypto-common | Apache-2.0 OR MIT |
44
+ | curve25519-dalek | BSD-3-Clause |
45
+ | curve25519-dalek-derive | Apache-2.0 OR MIT |
46
+ | digest | Apache-2.0 OR MIT |
47
+ | ed25519 | Apache-2.0 OR MIT |
48
+ | ed25519-dalek | BSD-3-Clause |
49
+ | fiat-crypto | Apache-2.0 OR BSD-1-Clause OR MIT |
50
+ | generic-array | MIT |
51
+ | libc | Apache-2.0 OR MIT |
52
+ | once_cell | Apache-2.0 OR MIT |
53
+ | proc-macro2 | Apache-2.0 OR MIT |
54
+ | quote | Apache-2.0 OR MIT |
55
+ | rand_core | Apache-2.0 OR MIT |
56
+ | rustc_version | Apache-2.0 OR MIT |
57
+ | rustversion | Apache-2.0 OR MIT |
58
+ | semver | Apache-2.0 OR MIT |
59
+ | sha2 | Apache-2.0 OR MIT |
60
+ | signature | Apache-2.0 OR MIT |
61
+ | subtle | BSD-3-Clause |
62
+ | syn | Apache-2.0 OR MIT |
63
+ | typenum | Apache-2.0 OR MIT |
64
+ | unicode-ident | (Apache-2.0 OR MIT) AND Unicode-3.0 |
65
+ | version_check | Apache-2.0 OR MIT |
66
+ | wasm-bindgen | Apache-2.0 OR MIT |
67
+ | wasm-bindgen-macro | Apache-2.0 OR MIT |
68
+ | wasm-bindgen-macro-support | Apache-2.0 OR MIT |
69
+ | wasm-bindgen-shared | Apache-2.0 OR MIT |
70
+ | x25519-dalek | BSD-3-Clause |
71
+
72
+ ### Crates present only in `wasm/axlsign`
73
+
74
+ | Crate | License |
75
+ | ------- | ----------------- |
76
+ | zeroize | Apache-2.0 OR MIT |
77
+
78
+ ### Local Rust crates
79
+
80
+ | Crate | License |
81
+ | ----------------------- | ------- |
82
+ | curve25519-node-wasm | MIT |
83
+ | curve25519-node-axlsign | MIT |
84
+
85
+ ## Notes
86
+
87
+ - Upstream licenses remain with their respective authors and projects.
88
+ - This NOTICE summarizes dependencies and does not replace upstream license texts.
89
+ - For full build/runtime details, see `README.md`, `README.en.md`, and `wasm/README.md`.
package/README.en.md CHANGED
@@ -5,6 +5,7 @@
5
5
  Zero-runtime-dependency implementation of:
6
6
 
7
7
  - X25519 + Ed25519 (modern mode via OpenSSL in `node:crypto`)
8
+ - X25519 + Ed25519 (optional modern mode via WASM)
8
9
  - legacy axlsign (optional WASM mode, compatible with `curve25519-js`)
9
10
 
10
11
  [![npm](https://img.shields.io/npm/v/@unknownncat/curve25519-node)](https://www.npmjs.com/package/@unknownncat/curve25519-node)
@@ -66,30 +67,52 @@ import { asBytes32, axlsign } from "@unknownncat/curve25519-node";
66
67
 
67
68
  const seed = asBytes32(new Uint8Array(32));
68
69
  const kp = axlsign.generateKeyPair(seed); // curve25519-js-compatible X25519 keypair
69
- const sig = axlsign.sign(
70
- kp.private,
71
- new TextEncoder().encode("hello"),
72
- new Uint8Array(64),
73
- );
70
+ const sig = axlsign.sign(kp.private, new TextEncoder().encode("hello"), new Uint8Array(64));
74
71
  const ok = axlsign.verify(kp.public, new TextEncoder().encode("hello"), sig);
75
72
  ```
76
73
 
74
+ Modern WASM mode (`wasm`):
75
+
76
+ ```ts
77
+ import { asBytes32, wasm } from "@unknownncat/curve25519-node";
78
+
79
+ const seed = asBytes32(new Uint8Array(32));
80
+ const kp = wasm.x25519.generateKeyPair(seed);
81
+ const shared = wasm.x25519.sharedKey(kp.private, kp.public);
82
+
83
+ const msg = new TextEncoder().encode("hello");
84
+ const sig = wasm.ed25519.sign(seed, msg);
85
+ const ok = wasm.ed25519.verify(wasm.ed25519.publicKey(seed), msg, sig);
86
+ ```
87
+
77
88
  ---
78
89
 
79
90
  ## API
80
91
 
81
92
  ### `x25519`
82
93
 
94
+ - `createPrivateKeyObject(secretKey32: Bytes32): KeyObject`
95
+ - `createPublicKeyObject(publicKey32: Bytes32): KeyObject`
96
+ - `publicKeyFromPrivateKeyObject(privateKey: KeyObject): Bytes32`
83
97
  - `publicKey(secretKey32: Bytes32): Bytes32`
98
+ - `sharedKeyFromKeyObjects(privateKey: KeyObject, publicKey: KeyObject): Bytes32`
84
99
  - `sharedKey(secretKey32: Bytes32, publicKey32: Bytes32): Bytes32`
100
+ - `sharedKeyStrict(secretKey32: Bytes32, publicKey32: Bytes32): Bytes32` (rejects all-zero shared secret)
101
+ - `sharedKeyStrictFromKeyObjects(privateKey: KeyObject, publicKey: KeyObject): Bytes32` (rejects all-zero shared secret)
102
+ - `isAllZero32(bytes32: Bytes32): boolean`
85
103
  - `generateKeyPair(seed32: Bytes32): { public: Bytes32; private: Bytes32 }`
86
104
 
87
105
  ### `ed25519`
88
106
 
107
+ - `createPrivateKeyObject(secretSeed32: Bytes32): KeyObject`
108
+ - `createPublicKeyObject(publicKey32: Bytes32): KeyObject`
109
+ - `publicKeyFromPrivateKeyObject(privateKey: KeyObject): Bytes32`
89
110
  - `publicKey(secretSeed32: Bytes32): Bytes32`
90
111
  - `generateKeyPair(seed32: Bytes32): { public: Bytes32; private: Bytes32 }`
91
112
  - `sign(secretSeed32: Bytes32, msg: Uint8Array): Bytes64`
113
+ - `signWithPrivateKey(privateKey: KeyObject, msg: Uint8Array): Bytes64`
92
114
  - `verify(publicKey32: Bytes32, msg: Uint8Array, signature64: Bytes64): boolean`
115
+ - `verifyWithPublicKey(publicKey: KeyObject, msg: Uint8Array, signature64: Bytes64): boolean`
93
116
  - `signMessage(secretSeed32: Bytes32, msg: Uint8Array): Uint8Array` (`signature || message`)
94
117
  - `openMessage(publicKey32: Bytes32, signedMsg: Uint8Array): Uint8Array | null`
95
118
 
@@ -103,9 +126,39 @@ const ok = axlsign.verify(kp.public, new TextEncoder().encode("hello"), sig);
103
126
  - `signMessage(secretKey32: Bytes32, msg: Uint8Array, opt_random?: Bytes64): Uint8Array`
104
127
  - `openMessage(publicKey32: Bytes32, signedMsg: Uint8Array): Uint8Array | null`
105
128
 
129
+ ### `wasm` (optional modern mode via WASM)
130
+
131
+ `wasm.x25519`:
132
+
133
+ - `createPrivateKeyObject(secretKey32: Bytes32): WasmX25519PrivateKeyObject`
134
+ - `createPublicKeyObject(publicKey32: Bytes32): WasmX25519PublicKeyObject`
135
+ - `publicKeyFromPrivateKeyObject(privateKey: WasmX25519PrivateKeyObject): Bytes32`
136
+ - `publicKey(secretKey32: Bytes32): Bytes32`
137
+ - `sharedKeyFromKeyObjects(privateKey: WasmX25519PrivateKeyObject, publicKey: WasmX25519PublicKeyObject): Bytes32`
138
+ - `sharedKey(secretKey32: Bytes32, publicKey32: Bytes32): Bytes32`
139
+ - `sharedKeyStrict(secretKey32: Bytes32, publicKey32: Bytes32): Bytes32`
140
+ - `sharedKeyStrictFromKeyObjects(privateKey: WasmX25519PrivateKeyObject, publicKey: WasmX25519PublicKeyObject): Bytes32`
141
+ - `isAllZero32(bytes32: Bytes32): boolean`
142
+ - `generateKeyPair(seed32: Bytes32): { public: Bytes32; private: Bytes32 }`
143
+
144
+ `wasm.ed25519`:
145
+
146
+ - `createPrivateKeyObject(secretSeed32: Bytes32): WasmEd25519PrivateKeyObject`
147
+ - `createPublicKeyObject(publicKey32: Bytes32): WasmEd25519PublicKeyObject`
148
+ - `publicKeyFromPrivateKeyObject(privateKey: WasmEd25519PrivateKeyObject): Bytes32`
149
+ - `publicKey(secretSeed32: Bytes32): Bytes32`
150
+ - `generateKeyPair(seed32: Bytes32): { public: Bytes32; private: Bytes32 }`
151
+ - `sign(secretSeed32: Bytes32, msg: Uint8Array): Bytes64`
152
+ - `signWithPrivateKey(privateKey: WasmEd25519PrivateKeyObject, msg: Uint8Array): Bytes64`
153
+ - `verify(publicKey32: Bytes32, msg: Uint8Array, signature64: Bytes64): boolean`
154
+ - `verifyWithPublicKey(publicKey: WasmEd25519PublicKeyObject, msg: Uint8Array, signature64: Bytes64): boolean`
155
+ - `signMessage(secretSeed32: Bytes32, msg: Uint8Array): Uint8Array`
156
+ - `openMessage(publicKey32: Bytes32, signedMsg: Uint8Array): Uint8Array | null`
157
+
106
158
  ### Top-level compatibility aliases
107
159
 
108
160
  - `sharedKey = x25519.sharedKey`
161
+ - `sharedKeyStrict = x25519.sharedKeyStrict`
109
162
  - `generateKeyPair = x25519.generateKeyPair`
110
163
  - `sign`, `verify`, `signMessage`, `openMessage` (Ed25519 semantics)
111
164
  - `generateKeyPairX25519`, `generateKeyPairEd25519`
@@ -114,27 +167,32 @@ const ok = axlsign.verify(kp.public, new TextEncoder().encode("hello"), sig);
114
167
 
115
168
  ## Compatibility Notes
116
169
 
117
- This package provides two modes:
170
+ This package provides three modes:
118
171
 
119
- - **modern (recommended):** `x25519` + `ed25519` via `node:crypto`
172
+ - **modern native (recommended):** `x25519` + `ed25519` via `node:crypto`
173
+ - **modern WASM (optional):** `wasm` namespace (`wasm.x25519` + `wasm.ed25519`)
120
174
  - **legacy:** `axlsign` via WASM for `curve25519-js` compatibility
121
175
 
122
- | Feature | `curve25519-js` | `curve25519-node` |
123
- | ---------------------------- | --------------- | ------------------------------------------- |
124
- | Signature scheme (modern) | axlsign | Ed25519 (standard) |
125
- | Signature scheme (legacy) | axlsign | axlsign (namespace `axlsign`) |
126
- | Key agreement | X25519 | X25519 |
127
- | Same key for signing + ECDH | yes | only in `axlsign` namespace |
128
- | `opt_random` in signing APIs | yes | yes in `axlsign`, no in top-level/`ed25519` |
129
- | OpenSSL backend | no | yes |
176
+ | Feature | `curve25519-js` | `curve25519-node` |
177
+ | -------------------------------- | --------------- | ------------------------------------------- |
178
+ | Signature scheme (modern) | axlsign | Ed25519 (standard) |
179
+ | Alternative modern scheme | no | Ed25519 via WASM (`wasm.ed25519`) |
180
+ | Signature scheme (legacy) | axlsign | axlsign (namespace `axlsign`) |
181
+ | Key agreement | X25519 | X25519 |
182
+ | Alternative modern key agreement | no | X25519 via WASM (`wasm.x25519`) |
183
+ | Same key for signing + ECDH | yes | only in `axlsign` namespace |
184
+ | `opt_random` in signing APIs | yes | yes in `axlsign`, no in top-level/`ed25519` |
185
+ | OpenSSL backend | no | yes |
130
186
 
131
187
  Important:
132
188
 
133
189
  - X25519 public keys and Ed25519 public keys are different.
190
+ - For stricter protocol flows (Signal-like), prefer `sharedKeyStrict` to reject all-zero shared secrets.
134
191
  - `node:crypto` does not expose an API to convert X25519 public keys to/from Ed25519 public keys.
135
192
  - Top-level `sign`/`signMessage` and `ed25519` keep Ed25519 semantics and reject `opt_random`.
136
193
  - For `curve25519-js` compatibility (including `opt_random`), use namespace `axlsign`.
137
194
  - Ed25519 signatures here are deterministic (OpenSSL default behavior).
195
+ - WASM modules (`axlsign` and `wasm`) are lazy-loaded on first call (importing only `x25519`/`ed25519` does not initialize WASM).
138
196
 
139
197
  ---
140
198
 
@@ -149,7 +207,10 @@ This package targets modern Node using OpenSSL primitives:
149
207
  - smaller, explicit API surface
150
208
  - strong typing with zero runtime dependencies
151
209
 
152
- In addition, the WASM `axlsign` namespace enables progressive migration of legacy code without reintroducing manual curve arithmetic in JavaScript.
210
+ In addition:
211
+
212
+ - WASM `axlsign` enables progressive migration of legacy code.
213
+ - WASM `wasm` provides a modern backend option without relying on `node:crypto` in the crypto execution path.
153
214
 
154
215
  ---
155
216
 
@@ -214,7 +275,7 @@ Implementation notes:
214
275
 
215
276
  - Avoids unnecessary byte copies in critical paths.
216
277
  - `signMessage` builds `signature || message` with a single preallocated `Uint8Array`.
217
- - For high-throughput loops, caching `KeyObject` at application level reduces ASN.1 parse overhead.
278
+ - For high-throughput loops, use `KeyObject` helpers (`create*KeyObject`, `*FromKeyObjects`) to reduce ASN.1 parse overhead.
218
279
 
219
280
  ---
220
281
 
@@ -295,7 +356,7 @@ Notes:
295
356
 
296
357
  ---
297
358
 
298
- ## Building `axlsign`
359
+ ## Building WASM namespaces (`axlsign` and `wasm`)
299
360
 
300
361
  In the npm package, WASM artifacts are already prebuilt under `dist/`.
301
362
 
@@ -307,8 +368,25 @@ To build from source, you need:
307
368
  Then `npm run build` runs:
308
369
 
309
370
  1. `wasm-pack build` (`wasm/axlsign`)
310
- 2. TypeScript ESM + CJS build
311
- 3. copy of WASM artifacts to `dist/internal/axlsign-wasm`
371
+ 2. `wasm-pack build` (`wasm/curve25519-wasm`)
372
+ 3. TypeScript ESM + CJS build
373
+ 4. copy of WASM artifacts to `dist/internal/axlsign-wasm` and `dist/internal/curve25519-wasm`
374
+
375
+ Rust crates reference: [wasm/README.md](./wasm/README.md)
376
+
377
+ ---
378
+
379
+ ## Contributing
380
+
381
+ - Guide: [CONTRIBUTING.md](./CONTRIBUTING.md)
382
+ - Code of conduct: [CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md)
383
+ - Security: [SECURITY.md](./SECURITY.md)
384
+
385
+ Full local validation:
386
+
387
+ ```bash
388
+ npm run ci
389
+ ```
312
390
 
313
391
  ---
314
392
 
@@ -316,6 +394,12 @@ Then `npm run build` runs:
316
394
 
317
395
  MIT
318
396
 
397
+ Additional compliance/security documents:
398
+
399
+ - [NOTICE.md](./NOTICE.md) (canonical third-party notice)
400
+ - [THIRD_PARTY_NOTICE.md](./THIRD_PARTY_NOTICE.md) and [THIRD_PARTY_NOTICES.md](./THIRD_PARTY_NOTICES.md) (compatibility aliases)
401
+ - [SECURITY.md](./SECURITY.md) (security policy and vulnerability reporting)
402
+
319
403
  ---
320
404
 
321
405
  ## Credits
@@ -325,6 +409,12 @@ MIT
325
409
  - Trevor Perrin, Curve25519 signatures idea: <https://moderncrypto.org/mail-archive/curves/2014/000205.html>
326
410
  - [Node.js `crypto` docs](https://nodejs.org/api/crypto.html)
327
411
  - [OpenSSL](https://www.openssl.org/)
412
+ - [RustCrypto](https://github.com/RustCrypto)
413
+ - [wasm-bindgen](https://github.com/wasm-bindgen/wasm-bindgen)
414
+ - [curve25519-dalek](https://github.com/dalek-cryptography/curve25519-dalek)
415
+ - [ed25519-dalek](https://github.com/dalek-cryptography/ed25519-dalek)
416
+ - [x25519-dalek](https://github.com/dalek-cryptography/x25519-dalek)
417
+ - [zeroize](https://github.com/RustCrypto/utils/tree/master/zeroize)
328
418
  - [RFC 7748](https://www.rfc-editor.org/rfc/rfc7748)
329
419
  - [RFC 8032](https://www.rfc-editor.org/rfc/rfc8032)
330
420
  - [RFC 8410](https://www.rfc-editor.org/rfc/rfc8410)
package/README.md CHANGED
@@ -5,6 +5,7 @@
5
5
  Implementação sem dependências de runtime de:
6
6
 
7
7
  - X25519 + Ed25519 (modo moderno via OpenSSL em `node:crypto`)
8
+ - X25519 + Ed25519 (modo moderno opcional via WASM)
8
9
  - axlsign legado (modo opcional via WASM, compatível com `curve25519-js`)
9
10
 
10
11
  [![npm](https://img.shields.io/npm/v/@unknownncat/curve25519-node)](https://www.npmjs.com/package/@unknownncat/curve25519-node)
@@ -66,30 +67,52 @@ import { asBytes32, axlsign } from "@unknownncat/curve25519-node";
66
67
 
67
68
  const seed = asBytes32(new Uint8Array(32));
68
69
  const kp = axlsign.generateKeyPair(seed); // X25519 keypair compatível com curve25519-js
69
- const sig = axlsign.sign(
70
- kp.private,
71
- new TextEncoder().encode("hello"),
72
- new Uint8Array(64),
73
- );
70
+ const sig = axlsign.sign(kp.private, new TextEncoder().encode("hello"), new Uint8Array(64));
74
71
  const ok = axlsign.verify(kp.public, new TextEncoder().encode("hello"), sig);
75
72
  ```
76
73
 
74
+ Moderno via WASM (`wasm`):
75
+
76
+ ```ts
77
+ import { asBytes32, wasm } from "@unknownncat/curve25519-node";
78
+
79
+ const seed = asBytes32(new Uint8Array(32));
80
+ const kp = wasm.x25519.generateKeyPair(seed);
81
+ const shared = wasm.x25519.sharedKey(kp.private, kp.public);
82
+
83
+ const msg = new TextEncoder().encode("hello");
84
+ const sig = wasm.ed25519.sign(seed, msg);
85
+ const ok = wasm.ed25519.verify(wasm.ed25519.publicKey(seed), msg, sig);
86
+ ```
87
+
77
88
  ---
78
89
 
79
90
  ## API
80
91
 
81
92
  ### `x25519`
82
93
 
94
+ - `createPrivateKeyObject(secretKey32: Bytes32): KeyObject`
95
+ - `createPublicKeyObject(publicKey32: Bytes32): KeyObject`
96
+ - `publicKeyFromPrivateKeyObject(privateKey: KeyObject): Bytes32`
83
97
  - `publicKey(secretKey32: Bytes32): Bytes32`
98
+ - `sharedKeyFromKeyObjects(privateKey: KeyObject, publicKey: KeyObject): Bytes32`
84
99
  - `sharedKey(secretKey32: Bytes32, publicKey32: Bytes32): Bytes32`
100
+ - `sharedKeyStrict(secretKey32: Bytes32, publicKey32: Bytes32): Bytes32` (rejeita segredo all-zero)
101
+ - `sharedKeyStrictFromKeyObjects(privateKey: KeyObject, publicKey: KeyObject): Bytes32` (rejeita segredo all-zero)
102
+ - `isAllZero32(bytes32: Bytes32): boolean`
85
103
  - `generateKeyPair(seed32: Bytes32): { public: Bytes32; private: Bytes32 }`
86
104
 
87
105
  ### `ed25519`
88
106
 
107
+ - `createPrivateKeyObject(secretSeed32: Bytes32): KeyObject`
108
+ - `createPublicKeyObject(publicKey32: Bytes32): KeyObject`
109
+ - `publicKeyFromPrivateKeyObject(privateKey: KeyObject): Bytes32`
89
110
  - `publicKey(secretSeed32: Bytes32): Bytes32`
90
111
  - `generateKeyPair(seed32: Bytes32): { public: Bytes32; private: Bytes32 }`
91
112
  - `sign(secretSeed32: Bytes32, msg: Uint8Array): Bytes64`
113
+ - `signWithPrivateKey(privateKey: KeyObject, msg: Uint8Array): Bytes64`
92
114
  - `verify(publicKey32: Bytes32, msg: Uint8Array, signature64: Bytes64): boolean`
115
+ - `verifyWithPublicKey(publicKey: KeyObject, msg: Uint8Array, signature64: Bytes64): boolean`
93
116
  - `signMessage(secretSeed32: Bytes32, msg: Uint8Array): Uint8Array` (`assinatura || mensagem`)
94
117
  - `openMessage(publicKey32: Bytes32, signedMsg: Uint8Array): Uint8Array | null`
95
118
 
@@ -103,9 +126,39 @@ const ok = axlsign.verify(kp.public, new TextEncoder().encode("hello"), sig);
103
126
  - `signMessage(secretKey32: Bytes32, msg: Uint8Array, opt_random?: Bytes64): Uint8Array`
104
127
  - `openMessage(publicKey32: Bytes32, signedMsg: Uint8Array): Uint8Array | null`
105
128
 
129
+ ### `wasm` (modo moderno opcional, via WASM)
130
+
131
+ `wasm.x25519`:
132
+
133
+ - `createPrivateKeyObject(secretKey32: Bytes32): WasmX25519PrivateKeyObject`
134
+ - `createPublicKeyObject(publicKey32: Bytes32): WasmX25519PublicKeyObject`
135
+ - `publicKeyFromPrivateKeyObject(privateKey: WasmX25519PrivateKeyObject): Bytes32`
136
+ - `publicKey(secretKey32: Bytes32): Bytes32`
137
+ - `sharedKeyFromKeyObjects(privateKey: WasmX25519PrivateKeyObject, publicKey: WasmX25519PublicKeyObject): Bytes32`
138
+ - `sharedKey(secretKey32: Bytes32, publicKey32: Bytes32): Bytes32`
139
+ - `sharedKeyStrict(secretKey32: Bytes32, publicKey32: Bytes32): Bytes32` (rejeita segredo all-zero)
140
+ - `sharedKeyStrictFromKeyObjects(privateKey: WasmX25519PrivateKeyObject, publicKey: WasmX25519PublicKeyObject): Bytes32` (rejeita segredo all-zero)
141
+ - `isAllZero32(bytes32: Bytes32): boolean`
142
+ - `generateKeyPair(seed32: Bytes32): { public: Bytes32; private: Bytes32 }`
143
+
144
+ `wasm.ed25519`:
145
+
146
+ - `createPrivateKeyObject(secretSeed32: Bytes32): WasmEd25519PrivateKeyObject`
147
+ - `createPublicKeyObject(publicKey32: Bytes32): WasmEd25519PublicKeyObject`
148
+ - `publicKeyFromPrivateKeyObject(privateKey: WasmEd25519PrivateKeyObject): Bytes32`
149
+ - `publicKey(secretSeed32: Bytes32): Bytes32`
150
+ - `generateKeyPair(seed32: Bytes32): { public: Bytes32; private: Bytes32 }`
151
+ - `sign(secretSeed32: Bytes32, msg: Uint8Array): Bytes64`
152
+ - `signWithPrivateKey(privateKey: WasmEd25519PrivateKeyObject, msg: Uint8Array): Bytes64`
153
+ - `verify(publicKey32: Bytes32, msg: Uint8Array, signature64: Bytes64): boolean`
154
+ - `verifyWithPublicKey(publicKey: WasmEd25519PublicKeyObject, msg: Uint8Array, signature64: Bytes64): boolean`
155
+ - `signMessage(secretSeed32: Bytes32, msg: Uint8Array): Uint8Array`
156
+ - `openMessage(publicKey32: Bytes32, signedMsg: Uint8Array): Uint8Array | null`
157
+
106
158
  ### Aliases de compatibilidade (top-level)
107
159
 
108
160
  - `sharedKey = x25519.sharedKey`
161
+ - `sharedKeyStrict = x25519.sharedKeyStrict`
109
162
  - `generateKeyPair = x25519.generateKeyPair`
110
163
  - `sign`, `verify`, `signMessage`, `openMessage` (semântica Ed25519)
111
164
  - `generateKeyPairX25519`, `generateKeyPairEd25519`
@@ -114,16 +167,19 @@ const ok = axlsign.verify(kp.public, new TextEncoder().encode("hello"), sig);
114
167
 
115
168
  ## Notas de Compatibilidade
116
169
 
117
- Este pacote suporta dois modos:
170
+ Este pacote suporta três modos:
118
171
 
119
- - **moderno (recomendado):** `x25519` + `ed25519` via `node:crypto`
172
+ - **moderno nativo (recomendado):** `x25519` + `ed25519` via `node:crypto`
173
+ - **moderno WASM (opcional):** namespace `wasm` (`wasm.x25519` + `wasm.ed25519`)
120
174
  - **legado:** `axlsign` via WASM para compatibilidade com `curve25519-js`
121
175
 
122
176
  | Recurso | `curve25519-js` | `curve25519-node` |
123
177
  | ----------------------------------- | --------------- | -------------------------------------------- |
124
178
  | Esquema de assinatura (moderno) | axlsign | Ed25519 (padrão) |
179
+ | Esquema moderno alternativo | não | Ed25519 via WASM (`wasm.ed25519`) |
125
180
  | Esquema de assinatura (legado) | axlsign | axlsign (namespace `axlsign`) |
126
181
  | Acordo de chave | X25519 | X25519 |
182
+ | Acordo moderno alternativo | não | X25519 via WASM (`wasm.x25519`) |
127
183
  | Mesma chave para assinatura + ECDH | sim | apenas no namespace `axlsign` |
128
184
  | `opt_random` nas APIs de assinatura | sim | sim no `axlsign`, não no top-level/`ed25519` |
129
185
  | Backend OpenSSL | não | sim |
@@ -131,10 +187,12 @@ Este pacote suporta dois modos:
131
187
  Importante:
132
188
 
133
189
  - Chaves públicas X25519 e Ed25519 são diferentes.
190
+ - Para fluxos de protocolo mais rígidos (estilo Signal), prefira `sharedKeyStrict` para rejeitar segredo compartilhado all-zero.
134
191
  - `node:crypto` não expõe API para converter public key X25519 ↔ Ed25519.
135
192
  - Top-level `sign`/`signMessage` e namespace `ed25519` continuam com semântica Ed25519 e rejeitam `opt_random`.
136
193
  - Para compatibilidade com `curve25519-js` (incluindo `opt_random`), use o namespace `axlsign`.
137
194
  - Assinaturas Ed25519 continuam determinísticas (comportamento padrão do OpenSSL).
195
+ - Os módulos WASM (`axlsign` e `wasm`) são carregados sob demanda na primeira chamada (importar apenas `x25519`/`ed25519` não inicializa WASM).
138
196
 
139
197
  ---
140
198
 
@@ -149,7 +207,10 @@ Este pacote foca em Node moderno com primitivas do OpenSSL:
149
207
  - API menor e explícita
150
208
  - tipagem forte com zero dependências de runtime
151
209
 
152
- Além disso, o namespace `axlsign` via WASM permite migração progressiva de código legado sem reintroduzir aritmética de curva em JavaScript puro.
210
+ Além disso:
211
+
212
+ - o namespace `axlsign` via WASM permite migração progressiva de código legado;
213
+ - o namespace `wasm` via WASM oferece uma alternativa moderna sem dependência de `node:crypto` no caminho criptográfico.
153
214
 
154
215
  ---
155
216
 
@@ -214,7 +275,7 @@ Notas de implementação:
214
275
 
215
276
  - Evita cópias desnecessárias de bytes nos caminhos críticos.
216
277
  - `signMessage` monta `assinatura || mensagem` com um único `Uint8Array` prealocado.
217
- - Para throughput máximo em loops longos, cache de `KeyObject` no nível da aplicação reduz overhead de parse ASN.1.
278
+ - Para throughput máximo em loops longos, use os helpers de `KeyObject` (`create*KeyObject`, `*FromKeyObjects`) para reduzir overhead de parse ASN.1.
218
279
 
219
280
  ---
220
281
 
@@ -295,7 +356,7 @@ Notas:
295
356
 
296
357
  ---
297
358
 
298
- ## Build do namespace `axlsign`
359
+ ## Build dos namespaces WASM (`axlsign` e `wasm`)
299
360
 
300
361
  No pacote publicado no npm, os artefatos WASM já vêm prontos em `dist/`.
301
362
 
@@ -307,8 +368,25 @@ Para buildar a partir do código-fonte, você precisa:
307
368
  Com isso, `npm run build` executa:
308
369
 
309
370
  1. `wasm-pack build` (`wasm/axlsign`)
310
- 2. `tsc` ESM + CJS
311
- 3. cópia dos artefatos WASM para `dist/internal/axlsign-wasm`
371
+ 2. `wasm-pack build` (`wasm/curve25519-wasm`)
372
+ 3. `tsc` ESM + CJS
373
+ 4. cópia dos artefatos WASM para `dist/internal/axlsign-wasm` e `dist/internal/curve25519-wasm`
374
+
375
+ Referência dos crates Rust: [wasm/README.md](./wasm/README.md)
376
+
377
+ ---
378
+
379
+ ## Contribuição
380
+
381
+ - Guia: [CONTRIBUTING.md](./CONTRIBUTING.md)
382
+ - Código de conduta: [CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md)
383
+ - Segurança: [SECURITY.md](./SECURITY.md)
384
+
385
+ Validação local completa:
386
+
387
+ ```bash
388
+ npm run ci
389
+ ```
312
390
 
313
391
  ---
314
392
 
@@ -316,6 +394,12 @@ Com isso, `npm run build` executa:
316
394
 
317
395
  MIT
318
396
 
397
+ Documentos complementares:
398
+
399
+ - [NOTICE.md](./NOTICE.md) (aviso oficial de terceiros)
400
+ - [THIRD_PARTY_NOTICE.md](./THIRD_PARTY_NOTICE.md) e [THIRD_PARTY_NOTICES.md](./THIRD_PARTY_NOTICES.md) (aliases de compatibilidade)
401
+ - [SECURITY.md](./SECURITY.md) (política de segurança e reporte de vulnerabilidades)
402
+
319
403
  ---
320
404
 
321
405
  ## Créditos
@@ -325,6 +409,12 @@ MIT
325
409
  - Trevor Perrin, ideia de assinaturas Curve25519: <https://moderncrypto.org/mail-archive/curves/2014/000205.html>
326
410
  - [Documentação Node.js `crypto`](https://nodejs.org/api/crypto.html)
327
411
  - [OpenSSL](https://www.openssl.org/)
412
+ - [RustCrypto](https://github.com/RustCrypto)
413
+ - [wasm-bindgen](https://github.com/wasm-bindgen/wasm-bindgen)
414
+ - [curve25519-dalek](https://github.com/dalek-cryptography/curve25519-dalek)
415
+ - [ed25519-dalek](https://github.com/dalek-cryptography/ed25519-dalek)
416
+ - [x25519-dalek](https://github.com/dalek-cryptography/x25519-dalek)
417
+ - [zeroize](https://github.com/RustCrypto/utils/tree/master/zeroize)
328
418
  - [RFC 7748](https://www.rfc-editor.org/rfc/rfc7748)
329
419
  - [RFC 8032](https://www.rfc-editor.org/rfc/rfc8032)
330
420
  - [RFC 8410](https://www.rfc-editor.org/rfc/rfc8410)
package/SECURITY.md ADDED
@@ -0,0 +1,23 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ | Version | Supported |
6
+ | ------- | --------- |
7
+ | 2.x | Yes |
8
+ | < 2.0.0 | No |
9
+
10
+ ## Reporting a Vulnerability
11
+
12
+ Please use GitHub private vulnerability reporting whenever possible:
13
+
14
+ 1. Go to the repository `Security` tab.
15
+ 2. Click `Report a vulnerability`.
16
+ 3. Submit impact details and a minimal proof-of-concept.
17
+
18
+ If private reporting is not available, open a public issue without sensitive details and request private contact.
19
+
20
+ ## Scope
21
+
22
+ - Cryptographic flaws, incorrect input validation, and integrity/confidentiality issues are high priority.
23
+ - Include package version, runtime environment, and reproducible steps.
@@ -0,0 +1,3 @@
1
+ # Third-Party Notice
2
+
3
+ Canonical notice file: [NOTICE.md](./NOTICE.md)
@@ -0,0 +1,5 @@
1
+ # Third-Party Notices
2
+
3
+ This file is kept for compatibility.
4
+
5
+ Canonical notice file: [NOTICE.md](./NOTICE.md)
@@ -1 +1 @@
1
- {"version":3,"file":"axlsign.d.ts","sourceRoot":"","sources":["../src/axlsign.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAiB9D;;GAEG;AACH,wBAAgB,SAAS,CAAC,WAAW,EAAE,OAAO,GAAG,OAAO,CAIvD;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,WAAW,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO,GAAG,OAAO,CAK7E;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,OAAO,GAAG,SAAS,CAQ1D;AAED;;;GAGG;AACH,wBAAgB,IAAI,CAAC,WAAW,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,UAAU,CAAC,EAAE,UAAU,GAAG,OAAO,CAU5F;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,WAAW,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,GAAG,OAAO,CAK3F;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,WAAW,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,UAAU,CAAC,EAAE,UAAU,GAAG,UAAU,CAUtG;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,GAAG,UAAU,GAAG,IAAI,CAe1F"}
1
+ {"version":3,"file":"axlsign.d.ts","sourceRoot":"","sources":["../src/axlsign.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAqD9D;;GAEG;AACH,wBAAgB,SAAS,CAAC,WAAW,EAAE,OAAO,GAAG,OAAO,CAIvD;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,WAAW,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO,GAAG,OAAO,CAK7E;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,OAAO,GAAG,SAAS,CAQ1D;AAED;;;GAGG;AACH,wBAAgB,IAAI,CAAC,WAAW,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,UAAU,CAAC,EAAE,UAAU,GAAG,OAAO,CAU5F;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,WAAW,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,GAAG,OAAO,CAK3F;AAED;;GAEG;AACH,wBAAgB,WAAW,CACzB,WAAW,EAAE,OAAO,EACpB,GAAG,EAAE,UAAU,EACf,UAAU,CAAC,EAAE,UAAU,GACtB,UAAU,CAUZ;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,GAAG,UAAU,GAAG,IAAI,CAe1F"}
package/dist/axlsign.js CHANGED
@@ -1,5 +1,27 @@
1
- import { asBytes32, asBytes64, assertBytes32, assertBytes64, assertUint8Array } from "./internal/assert.js";
2
- import * as wasmAxl from "./internal/axlsign-wasm/axlsign_wasm.js";
1
+ import { dirname, join } from "node:path";
2
+ import { createRequire } from "node:module";
3
+ import { asBytes32, asBytes64, assertBytes32, assertBytes64, assertUint8Array, } from "./internal/assert.js";
4
+ const SELF_PACKAGE_NAME = "@unknownncat/curve25519-node";
5
+ const requireBase = typeof __filename === "string"
6
+ ? __filename
7
+ : typeof process.argv[1] === "string"
8
+ ? process.argv[1]
9
+ : join(process.cwd(), "index.js");
10
+ const nodeRequire = createRequire(requireBase);
11
+ let wasmModulePath;
12
+ let wasmAxl;
13
+ function getWasmAxl() {
14
+ if (wasmAxl !== undefined) {
15
+ return wasmAxl;
16
+ }
17
+ if (wasmModulePath === undefined) {
18
+ const packageJsonPath = nodeRequire.resolve(`${SELF_PACKAGE_NAME}/package.json`);
19
+ wasmModulePath = join(dirname(packageJsonPath), "dist", "internal", "axlsign-wasm", "axlsign_wasm.js");
20
+ }
21
+ // Lazy-load WASM bindings to keep modern-only imports lightweight.
22
+ wasmAxl = nodeRequire(wasmModulePath);
23
+ return wasmAxl;
24
+ }
3
25
  function clampScalar(seed32) {
4
26
  const out = new Uint8Array(32);
5
27
  out.set(seed32);
@@ -18,7 +40,7 @@ function assertOptionalRandom64(value, fnName) {
18
40
  */
19
41
  export function publicKey(secretKey32) {
20
42
  assertBytes32(secretKey32, "secretKey32");
21
- const out = wasmAxl.axlsignPublicKey(secretKey32);
43
+ const out = getWasmAxl().axlsignPublicKey(secretKey32);
22
44
  return asBytes32(out, "axlsign public key");
23
45
  }
24
46
  /**
@@ -27,7 +49,7 @@ export function publicKey(secretKey32) {
27
49
  export function sharedKey(secretKey32, publicKey32) {
28
50
  assertBytes32(secretKey32, "secretKey32");
29
51
  assertBytes32(publicKey32, "publicKey32");
30
- const out = wasmAxl.axlsignSharedKey(secretKey32, publicKey32);
52
+ const out = getWasmAxl().axlsignSharedKey(secretKey32, publicKey32);
31
53
  return asBytes32(out, "axlsign shared key");
32
54
  }
33
55
  /**
@@ -51,8 +73,8 @@ export function sign(secretKey32, msg, opt_random) {
51
73
  assertUint8Array(msg, "msg");
52
74
  assertOptionalRandom64(opt_random, "sign");
53
75
  const signature = opt_random === undefined
54
- ? wasmAxl.axlsignSign(secretKey32, msg)
55
- : wasmAxl.axlsignSignRnd(secretKey32, msg, opt_random);
76
+ ? getWasmAxl().axlsignSign(secretKey32, msg)
77
+ : getWasmAxl().axlsignSignRnd(secretKey32, msg, opt_random);
56
78
  return asBytes64(signature, "axlsign signature");
57
79
  }
58
80
  /**
@@ -62,7 +84,7 @@ export function verify(publicKey32, msg, signature64) {
62
84
  assertBytes32(publicKey32, "publicKey32");
63
85
  assertUint8Array(msg, "msg");
64
86
  assertBytes64(signature64, "signature64");
65
- return wasmAxl.axlsignVerify(publicKey32, msg, signature64);
87
+ return getWasmAxl().axlsignVerify(publicKey32, msg, signature64);
66
88
  }
67
89
  /**
68
90
  * Returns signature || message (axlsign mode).