@unknownncat/curve25519-node 2.0.0 → 2.1.1
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/LICENSE +1 -1
- package/NOTICE.md +89 -0
- package/README.en.md +149 -43
- package/README.md +141 -35
- package/SECURITY.md +34 -0
- package/THIRD_PARTY_NOTICE.md +3 -0
- package/THIRD_PARTY_NOTICES.md +5 -0
- package/dist/axlsign.d.ts.map +1 -1
- package/dist/axlsign.js +50 -7
- package/dist/axlsign.js.map +1 -1
- package/dist/cjs/axlsign.js +49 -6
- package/dist/cjs/axlsign.js.map +1 -1
- package/dist/cjs/ed25519.js +46 -10
- package/dist/cjs/ed25519.js.map +1 -1
- package/dist/cjs/index.js +27 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/internal/assert.js.map +1 -1
- package/dist/cjs/internal/axlsign-wasm/LICENSE +1 -1
- package/dist/cjs/internal/curve25519-wasm/LICENSE +21 -0
- package/dist/cjs/internal/curve25519-wasm/curve25519_wasm.d.ts +12 -0
- package/dist/cjs/internal/curve25519-wasm/curve25519_wasm.js +165 -0
- package/dist/cjs/internal/curve25519-wasm/curve25519_wasm_bg.wasm +0 -0
- package/dist/cjs/internal/curve25519-wasm/curve25519_wasm_bg.wasm.d.ts +13 -0
- package/dist/cjs/internal/curve25519-wasm/package.json +17 -0
- package/dist/cjs/wasm.js +249 -0
- package/dist/cjs/wasm.js.map +1 -0
- package/dist/cjs/x25519.js +73 -12
- package/dist/cjs/x25519.js.map +1 -1
- package/dist/ed25519.d.ts +21 -0
- package/dist/ed25519.d.ts.map +1 -1
- package/dist/ed25519.js +44 -13
- package/dist/ed25519.js.map +1 -1
- package/dist/index.d.ts +87 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/assert.js.map +1 -1
- package/dist/internal/axlsign-wasm/LICENSE +1 -1
- package/dist/internal/curve25519-wasm/LICENSE +21 -0
- package/dist/internal/curve25519-wasm/curve25519_wasm.d.ts +12 -0
- package/dist/internal/curve25519-wasm/curve25519_wasm.js +165 -0
- package/dist/internal/curve25519-wasm/curve25519_wasm_bg.wasm +0 -0
- package/dist/internal/curve25519-wasm/curve25519_wasm_bg.wasm.d.ts +13 -0
- package/dist/internal/curve25519-wasm/package.json +17 -0
- package/dist/types.d.ts +2 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/wasm.d.ts +92 -0
- package/dist/wasm.d.ts.map +1 -0
- package/dist/wasm.js +225 -0
- package/dist/wasm.js.map +1 -0
- package/dist/x25519.d.ts +29 -0
- package/dist/x25519.d.ts.map +1 -1
- package/dist/x25519.js +66 -12
- package/dist/x25519.js.map +1 -1
- package/package.json +30 -4
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
|
[](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
|
|
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
|
|
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,
|
|
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
|
|
|
@@ -253,20 +314,28 @@ Ambiente:
|
|
|
253
314
|
- Cores lógicos: `4`
|
|
254
315
|
- Vetores: `64`
|
|
255
316
|
|
|
256
|
-
### Tabela 1 - API moderna (
|
|
317
|
+
### Tabela 1 - API moderna (nativa + WASM)
|
|
257
318
|
|
|
258
319
|
`sign`/`verify` abaixo comparam throughput de API, não equivalência criptográfica (Ed25519 vs axlsign legado).
|
|
259
320
|
|
|
260
|
-
| Operação
|
|
261
|
-
|
|
|
262
|
-
| `x25519.generateKeyPair`
|
|
263
|
-
| `x25519.sharedKey`
|
|
264
|
-
| `
|
|
265
|
-
| `
|
|
266
|
-
| `ed25519.
|
|
267
|
-
| `ed25519.
|
|
268
|
-
| `ed25519.
|
|
269
|
-
| `ed25519.
|
|
321
|
+
| Operação | Moderno raw | Legado raw (`curve25519-js`) | Speedup raw | Moderno cached | Legado cached (`curve25519-js`) | Speedup cached |
|
|
322
|
+
| ----------------------------------- | ----------: | ---------------------------: | ----------: | -------------: | ------------------------------: | -------------: |
|
|
323
|
+
| `x25519.generateKeyPair` | 14,082 | 1,579 | 8.92x | 49,035 | 1,576 | 31.12x |
|
|
324
|
+
| `x25519.sharedKey` | 10,134 | 1,568 | 6.46x | 25,423 | 1,578 | 16.11x |
|
|
325
|
+
| `wasm.x25519.generateKeyPair` | 8,415 | 1,571 | 5.36x | 8,385 | 1,574 | 5.33x |
|
|
326
|
+
| `wasm.x25519.sharedKey` | 8,333 | 1,577 | 5.28x | 8,350 | 1,583 | 5.28x |
|
|
327
|
+
| `ed25519.sign (msg32)` | 11,273 | 142 | 79.56x | 23,886 | 137 | 174.75x |
|
|
328
|
+
| `wasm.ed25519.sign (msg32)` | 3,945 | 142 | 27.80x | 3,956 | 140 | 28.27x |
|
|
329
|
+
| `ed25519.sign (msg1024)` | 10,759 | 136 | 79.31x | 22,335 | 138 | 162.38x |
|
|
330
|
+
| `wasm.ed25519.sign (msg1024)` | 3,872 | 137 | 28.27x | 3,873 | 137 | 28.37x |
|
|
331
|
+
| `ed25519.verify (msg32)` | 7,333 | 142 | 51.65x | 8,186 | 141 | 58.01x |
|
|
332
|
+
| `wasm.ed25519.verify (msg32)` | 7,747 | 141 | 54.84x | 7,629 | 143 | 53.26x |
|
|
333
|
+
| `ed25519.verify (msg1024)` | 7,241 | 134 | 54.20x | 8,081 | 136 | 59.35x |
|
|
334
|
+
| `wasm.ed25519.verify (msg1024)` | 7,505 | 135 | 55.76x | 7,480 | 134 | 55.66x |
|
|
335
|
+
| `ed25519.signMessage (msg256)` | 10,859 | 140 | 77.67x | 23,607 | 132 | 178.57x |
|
|
336
|
+
| `wasm.ed25519.signMessage (msg256)` | 3,888 | 139 | 27.99x | 3,867 | 137 | 28.23x |
|
|
337
|
+
| `ed25519.openMessage (msg256)` | 7,113 | 145 | 49.03x | 8,012 | 141 | 56.96x |
|
|
338
|
+
| `wasm.ed25519.openMessage (msg256)` | 7,428 | 137 | 54.26x | 7,476 | 137 | 54.74x |
|
|
270
339
|
|
|
271
340
|
### Tabela 2 - Compatibilidade `axlsign` (equivalente ao `curve25519-js`)
|
|
272
341
|
|
|
@@ -274,18 +343,18 @@ Aqui a comparação é de mesmo esquema criptográfico (equivalência + throughp
|
|
|
274
343
|
|
|
275
344
|
| Operação | Moderno raw | Legado raw (`curve25519-js`) | Speedup raw | Moderno cached | Legado cached (`curve25519-js`) | Speedup cached |
|
|
276
345
|
| ----------------------------------------- | ----------: | ---------------------------: | ----------: | -------------: | ------------------------------: | -------------: |
|
|
277
|
-
| `axlsign.generateKeyPair` | 8,
|
|
278
|
-
| `axlsign.sharedKey` | 8,
|
|
279
|
-
| `axlsign.sign (msg32)` |
|
|
280
|
-
| `axlsign.sign (msg32,opt_random)` |
|
|
281
|
-
| `axlsign.sign (msg1024)` | 3,
|
|
282
|
-
| `axlsign.verify (msg32)` | 6,
|
|
283
|
-
| `axlsign.verify (msg32,opt_random)` | 6,
|
|
284
|
-
| `axlsign.verify (msg1024)` | 6,
|
|
285
|
-
| `axlsign.signMessage (msg256)` | 3,
|
|
286
|
-
| `axlsign.signMessage (msg256,opt_random)` | 3,
|
|
287
|
-
| `axlsign.openMessage (msg256)` | 6,
|
|
288
|
-
| `axlsign.openMessage (msg256,opt_random)` | 6,
|
|
346
|
+
| `axlsign.generateKeyPair` | 8,382 | 1,571 | 5.34x | 8,357 | 1,579 | 5.29x |
|
|
347
|
+
| `axlsign.sharedKey` | 8,361 | 1,583 | 5.28x | 8,422 | 1,564 | 5.39x |
|
|
348
|
+
| `axlsign.sign (msg32)` | 4,010 | 140 | 28.59x | 3,970 | 141 | 28.10x |
|
|
349
|
+
| `axlsign.sign (msg32,opt_random)` | 4,000 | 142 | 28.07x | 3,965 | 136 | 29.08x |
|
|
350
|
+
| `axlsign.sign (msg1024)` | 3,883 | 138 | 28.17x | 3,878 | 138 | 28.03x |
|
|
351
|
+
| `axlsign.verify (msg32)` | 6,604 | 144 | 45.83x | 6,585 | 143 | 46.17x |
|
|
352
|
+
| `axlsign.verify (msg32,opt_random)` | 6,531 | 143 | 45.69x | 6,527 | 142 | 46.08x |
|
|
353
|
+
| `axlsign.verify (msg1024)` | 6,428 | 138 | 46.47x | 6,377 | 136 | 46.82x |
|
|
354
|
+
| `axlsign.signMessage (msg256)` | 3,913 | 140 | 27.85x | 3,935 | 136 | 28.92x |
|
|
355
|
+
| `axlsign.signMessage (msg256,opt_random)` | 3,941 | 139 | 28.39x | 3,878 | 139 | 27.93x |
|
|
356
|
+
| `axlsign.openMessage (msg256)` | 6,440 | 138 | 46.78x | 6,407 | 136 | 47.18x |
|
|
357
|
+
| `axlsign.openMessage (msg256,opt_random)` | 6,513 | 134 | 48.53x | 6,431 | 133 | 48.19x |
|
|
289
358
|
|
|
290
359
|
Notas:
|
|
291
360
|
|
|
@@ -295,7 +364,7 @@ Notas:
|
|
|
295
364
|
|
|
296
365
|
---
|
|
297
366
|
|
|
298
|
-
## Build
|
|
367
|
+
## Build dos namespaces WASM (`axlsign` e `wasm`)
|
|
299
368
|
|
|
300
369
|
No pacote publicado no npm, os artefatos WASM já vêm prontos em `dist/`.
|
|
301
370
|
|
|
@@ -307,8 +376,33 @@ Para buildar a partir do código-fonte, você precisa:
|
|
|
307
376
|
Com isso, `npm run build` executa:
|
|
308
377
|
|
|
309
378
|
1. `wasm-pack build` (`wasm/axlsign`)
|
|
310
|
-
2. `
|
|
311
|
-
3.
|
|
379
|
+
2. `wasm-pack build` (`wasm/curve25519-wasm`)
|
|
380
|
+
3. `tsc` ESM + CJS
|
|
381
|
+
4. cópia dos artefatos WASM para `dist/internal/axlsign-wasm` e `dist/internal/curve25519-wasm`
|
|
382
|
+
|
|
383
|
+
Referência dos crates Rust: [wasm/README.md](./wasm/README.md)
|
|
384
|
+
|
|
385
|
+
---
|
|
386
|
+
|
|
387
|
+
## Contribuição
|
|
388
|
+
|
|
389
|
+
- Guia: [CONTRIBUTING.md](./CONTRIBUTING.md)
|
|
390
|
+
- Código de conduta: [CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md)
|
|
391
|
+
- Segurança: [SECURITY.md](./SECURITY.md)
|
|
392
|
+
|
|
393
|
+
Validação local completa:
|
|
394
|
+
|
|
395
|
+
```bash
|
|
396
|
+
npm run ci
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
Checagens extras de robustez/supply-chain:
|
|
400
|
+
|
|
401
|
+
```bash
|
|
402
|
+
npm run audit
|
|
403
|
+
npm run audit:prod
|
|
404
|
+
npm run release:check
|
|
405
|
+
```
|
|
312
406
|
|
|
313
407
|
---
|
|
314
408
|
|
|
@@ -316,6 +410,12 @@ Com isso, `npm run build` executa:
|
|
|
316
410
|
|
|
317
411
|
MIT
|
|
318
412
|
|
|
413
|
+
Documentos complementares:
|
|
414
|
+
|
|
415
|
+
- [NOTICE.md](./NOTICE.md) (aviso oficial de terceiros)
|
|
416
|
+
- [THIRD_PARTY_NOTICE.md](./THIRD_PARTY_NOTICE.md) e [THIRD_PARTY_NOTICES.md](./THIRD_PARTY_NOTICES.md) (aliases de compatibilidade)
|
|
417
|
+
- [SECURITY.md](./SECURITY.md) (política de segurança e reporte de vulnerabilidades)
|
|
418
|
+
|
|
319
419
|
---
|
|
320
420
|
|
|
321
421
|
## Créditos
|
|
@@ -325,6 +425,12 @@ MIT
|
|
|
325
425
|
- Trevor Perrin, ideia de assinaturas Curve25519: <https://moderncrypto.org/mail-archive/curves/2014/000205.html>
|
|
326
426
|
- [Documentação Node.js `crypto`](https://nodejs.org/api/crypto.html)
|
|
327
427
|
- [OpenSSL](https://www.openssl.org/)
|
|
428
|
+
- [RustCrypto](https://github.com/RustCrypto)
|
|
429
|
+
- [wasm-bindgen](https://github.com/wasm-bindgen/wasm-bindgen)
|
|
430
|
+
- [curve25519-dalek](https://github.com/dalek-cryptography/curve25519-dalek)
|
|
431
|
+
- [ed25519-dalek](https://github.com/dalek-cryptography/ed25519-dalek)
|
|
432
|
+
- [x25519-dalek](https://github.com/dalek-cryptography/x25519-dalek)
|
|
433
|
+
- [zeroize](https://github.com/RustCrypto/utils/tree/master/zeroize)
|
|
328
434
|
- [RFC 7748](https://www.rfc-editor.org/rfc/rfc7748)
|
|
329
435
|
- [RFC 8032](https://www.rfc-editor.org/rfc/rfc8032)
|
|
330
436
|
- [RFC 8410](https://www.rfc-editor.org/rfc/rfc8410)
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
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.
|
|
24
|
+
|
|
25
|
+
## Maintainer Security Checks
|
|
26
|
+
|
|
27
|
+
Before publishing a release, run:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm run ci
|
|
31
|
+
npm run audit
|
|
32
|
+
npm run audit:prod
|
|
33
|
+
npm run release:check
|
|
34
|
+
```
|
package/dist/axlsign.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"axlsign.d.ts","sourceRoot":"","sources":["../src/axlsign.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"axlsign.d.ts","sourceRoot":"","sources":["../src/axlsign.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AA4E9D;;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,48 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { dirname, isAbsolute, join } from "node:path";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import { asBytes32, asBytes64, assertBytes32, assertBytes64, assertUint8Array, } from "./internal/assert.js";
|
|
5
|
+
const SELF_PACKAGE_NAME = "@unknownncat/curve25519-node";
|
|
6
|
+
const requireBase = typeof __filename === "string"
|
|
7
|
+
? __filename
|
|
8
|
+
: typeof process.argv[1] === "string" && isAbsolute(process.argv[1])
|
|
9
|
+
? process.argv[1]
|
|
10
|
+
: join(process.cwd(), "package.json");
|
|
11
|
+
const nodeRequire = createRequire(requireBase);
|
|
12
|
+
let wasmModulePath;
|
|
13
|
+
let wasmAxl;
|
|
14
|
+
function resolveWasmModulePath() {
|
|
15
|
+
const candidates = [];
|
|
16
|
+
try {
|
|
17
|
+
const packageJsonPath = nodeRequire.resolve(`${SELF_PACKAGE_NAME}/package.json`);
|
|
18
|
+
candidates.push(join(dirname(packageJsonPath), "dist", "internal", "axlsign-wasm", "axlsign_wasm.js"));
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
// Fall back to local development paths below.
|
|
22
|
+
}
|
|
23
|
+
if (typeof __dirname === "string") {
|
|
24
|
+
candidates.push(join(__dirname, "internal", "axlsign-wasm", "axlsign_wasm.js"));
|
|
25
|
+
}
|
|
26
|
+
candidates.push(join(process.cwd(), "dist", "internal", "axlsign-wasm", "axlsign_wasm.js"));
|
|
27
|
+
candidates.push(join(process.cwd(), "src", "internal", "axlsign-wasm", "axlsign_wasm.js"));
|
|
28
|
+
for (const candidate of candidates) {
|
|
29
|
+
if (existsSync(candidate)) {
|
|
30
|
+
return candidate;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
throw new Error("Unable to locate axlsign WASM module. Run `npm run build` before using axlsign in local dev.");
|
|
34
|
+
}
|
|
35
|
+
function getWasmAxl() {
|
|
36
|
+
if (wasmAxl !== undefined) {
|
|
37
|
+
return wasmAxl;
|
|
38
|
+
}
|
|
39
|
+
if (wasmModulePath === undefined) {
|
|
40
|
+
wasmModulePath = resolveWasmModulePath();
|
|
41
|
+
}
|
|
42
|
+
// Lazy-load WASM bindings to keep modern-only imports lightweight.
|
|
43
|
+
wasmAxl = nodeRequire(wasmModulePath);
|
|
44
|
+
return wasmAxl;
|
|
45
|
+
}
|
|
3
46
|
function clampScalar(seed32) {
|
|
4
47
|
const out = new Uint8Array(32);
|
|
5
48
|
out.set(seed32);
|
|
@@ -18,7 +61,7 @@ function assertOptionalRandom64(value, fnName) {
|
|
|
18
61
|
*/
|
|
19
62
|
export function publicKey(secretKey32) {
|
|
20
63
|
assertBytes32(secretKey32, "secretKey32");
|
|
21
|
-
const out =
|
|
64
|
+
const out = getWasmAxl().axlsignPublicKey(secretKey32);
|
|
22
65
|
return asBytes32(out, "axlsign public key");
|
|
23
66
|
}
|
|
24
67
|
/**
|
|
@@ -27,7 +70,7 @@ export function publicKey(secretKey32) {
|
|
|
27
70
|
export function sharedKey(secretKey32, publicKey32) {
|
|
28
71
|
assertBytes32(secretKey32, "secretKey32");
|
|
29
72
|
assertBytes32(publicKey32, "publicKey32");
|
|
30
|
-
const out =
|
|
73
|
+
const out = getWasmAxl().axlsignSharedKey(secretKey32, publicKey32);
|
|
31
74
|
return asBytes32(out, "axlsign shared key");
|
|
32
75
|
}
|
|
33
76
|
/**
|
|
@@ -51,8 +94,8 @@ export function sign(secretKey32, msg, opt_random) {
|
|
|
51
94
|
assertUint8Array(msg, "msg");
|
|
52
95
|
assertOptionalRandom64(opt_random, "sign");
|
|
53
96
|
const signature = opt_random === undefined
|
|
54
|
-
?
|
|
55
|
-
:
|
|
97
|
+
? getWasmAxl().axlsignSign(secretKey32, msg)
|
|
98
|
+
: getWasmAxl().axlsignSignRnd(secretKey32, msg, opt_random);
|
|
56
99
|
return asBytes64(signature, "axlsign signature");
|
|
57
100
|
}
|
|
58
101
|
/**
|
|
@@ -62,7 +105,7 @@ export function verify(publicKey32, msg, signature64) {
|
|
|
62
105
|
assertBytes32(publicKey32, "publicKey32");
|
|
63
106
|
assertUint8Array(msg, "msg");
|
|
64
107
|
assertBytes64(signature64, "signature64");
|
|
65
|
-
return
|
|
108
|
+
return getWasmAxl().axlsignVerify(publicKey32, msg, signature64);
|
|
66
109
|
}
|
|
67
110
|
/**
|
|
68
111
|
* Returns signature || message (axlsign mode).
|
package/dist/axlsign.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"axlsign.js","sourceRoot":"","sources":["../src/axlsign.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"axlsign.js","sourceRoot":"","sources":["../src/axlsign.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EACL,SAAS,EACT,SAAS,EACT,aAAa,EACb,aAAa,EACb,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAI9B,MAAM,iBAAiB,GAAG,8BAA8B,CAAC;AAEzD,MAAM,WAAW,GACf,OAAO,UAAU,KAAK,QAAQ;IAC5B,CAAC,CAAC,UAAU;IACZ,CAAC,CAAC,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,IAAI,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;QACjB,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,CAAC,CAAC;AAE5C,MAAM,WAAW,GAAG,aAAa,CAAC,WAAW,CAAC,CAAC;AAE/C,IAAI,cAAkC,CAAC;AAEvC,IAAI,OAAyC,CAAC;AAE9C,SAAS,q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AAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC7B,sBAAsB,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;IAElD,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC;IACrD,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,EAAE,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC;IAChD,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;IACtB,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IACjB,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,WAAoB,EAAE,SAAqB;IACrE,aAAa,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;IAC1C,gBAAgB,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IAEzC,IAAI,SAAS,CAAC,UAAU,GAAG,EAAE,EAAE,CAAC;QAC9B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,WAAW,GAAG,SAAS,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,qBAAqB,CAAC,CAAC;IAChF,MAAM,GAAG,GAAG,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACnC,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,GAAG,EAAE,WAAW,CAAC,EAAE,CAAC;QAC3C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC;AAC7B,CAAC"}
|
package/dist/cjs/axlsign.js
CHANGED
|
@@ -7,8 +7,51 @@ exports.sign = sign;
|
|
|
7
7
|
exports.verify = verify;
|
|
8
8
|
exports.signMessage = signMessage;
|
|
9
9
|
exports.openMessage = openMessage;
|
|
10
|
+
const node_fs_1 = require("node:fs");
|
|
11
|
+
const node_path_1 = require("node:path");
|
|
12
|
+
const node_module_1 = require("node:module");
|
|
10
13
|
const assert_js_1 = require("./internal/assert.js");
|
|
11
|
-
const
|
|
14
|
+
const SELF_PACKAGE_NAME = "@unknownncat/curve25519-node";
|
|
15
|
+
const requireBase = typeof __filename === "string"
|
|
16
|
+
? __filename
|
|
17
|
+
: typeof process.argv[1] === "string" && (0, node_path_1.isAbsolute)(process.argv[1])
|
|
18
|
+
? process.argv[1]
|
|
19
|
+
: (0, node_path_1.join)(process.cwd(), "package.json");
|
|
20
|
+
const nodeRequire = (0, node_module_1.createRequire)(requireBase);
|
|
21
|
+
let wasmModulePath;
|
|
22
|
+
let wasmAxl;
|
|
23
|
+
function resolveWasmModulePath() {
|
|
24
|
+
const candidates = [];
|
|
25
|
+
try {
|
|
26
|
+
const packageJsonPath = nodeRequire.resolve(`${SELF_PACKAGE_NAME}/package.json`);
|
|
27
|
+
candidates.push((0, node_path_1.join)((0, node_path_1.dirname)(packageJsonPath), "dist", "internal", "axlsign-wasm", "axlsign_wasm.js"));
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
// Fall back to local development paths below.
|
|
31
|
+
}
|
|
32
|
+
if (typeof __dirname === "string") {
|
|
33
|
+
candidates.push((0, node_path_1.join)(__dirname, "internal", "axlsign-wasm", "axlsign_wasm.js"));
|
|
34
|
+
}
|
|
35
|
+
candidates.push((0, node_path_1.join)(process.cwd(), "dist", "internal", "axlsign-wasm", "axlsign_wasm.js"));
|
|
36
|
+
candidates.push((0, node_path_1.join)(process.cwd(), "src", "internal", "axlsign-wasm", "axlsign_wasm.js"));
|
|
37
|
+
for (const candidate of candidates) {
|
|
38
|
+
if ((0, node_fs_1.existsSync)(candidate)) {
|
|
39
|
+
return candidate;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
throw new Error("Unable to locate axlsign WASM module. Run `npm run build` before using axlsign in local dev.");
|
|
43
|
+
}
|
|
44
|
+
function getWasmAxl() {
|
|
45
|
+
if (wasmAxl !== undefined) {
|
|
46
|
+
return wasmAxl;
|
|
47
|
+
}
|
|
48
|
+
if (wasmModulePath === undefined) {
|
|
49
|
+
wasmModulePath = resolveWasmModulePath();
|
|
50
|
+
}
|
|
51
|
+
// Lazy-load WASM bindings to keep modern-only imports lightweight.
|
|
52
|
+
wasmAxl = nodeRequire(wasmModulePath);
|
|
53
|
+
return wasmAxl;
|
|
54
|
+
}
|
|
12
55
|
function clampScalar(seed32) {
|
|
13
56
|
const out = new Uint8Array(32);
|
|
14
57
|
out.set(seed32);
|
|
@@ -27,7 +70,7 @@ function assertOptionalRandom64(value, fnName) {
|
|
|
27
70
|
*/
|
|
28
71
|
function publicKey(secretKey32) {
|
|
29
72
|
(0, assert_js_1.assertBytes32)(secretKey32, "secretKey32");
|
|
30
|
-
const out =
|
|
73
|
+
const out = getWasmAxl().axlsignPublicKey(secretKey32);
|
|
31
74
|
return (0, assert_js_1.asBytes32)(out, "axlsign public key");
|
|
32
75
|
}
|
|
33
76
|
/**
|
|
@@ -36,7 +79,7 @@ function publicKey(secretKey32) {
|
|
|
36
79
|
function sharedKey(secretKey32, publicKey32) {
|
|
37
80
|
(0, assert_js_1.assertBytes32)(secretKey32, "secretKey32");
|
|
38
81
|
(0, assert_js_1.assertBytes32)(publicKey32, "publicKey32");
|
|
39
|
-
const out =
|
|
82
|
+
const out = getWasmAxl().axlsignSharedKey(secretKey32, publicKey32);
|
|
40
83
|
return (0, assert_js_1.asBytes32)(out, "axlsign shared key");
|
|
41
84
|
}
|
|
42
85
|
/**
|
|
@@ -60,8 +103,8 @@ function sign(secretKey32, msg, opt_random) {
|
|
|
60
103
|
(0, assert_js_1.assertUint8Array)(msg, "msg");
|
|
61
104
|
assertOptionalRandom64(opt_random, "sign");
|
|
62
105
|
const signature = opt_random === undefined
|
|
63
|
-
?
|
|
64
|
-
:
|
|
106
|
+
? getWasmAxl().axlsignSign(secretKey32, msg)
|
|
107
|
+
: getWasmAxl().axlsignSignRnd(secretKey32, msg, opt_random);
|
|
65
108
|
return (0, assert_js_1.asBytes64)(signature, "axlsign signature");
|
|
66
109
|
}
|
|
67
110
|
/**
|
|
@@ -71,7 +114,7 @@ function verify(publicKey32, msg, signature64) {
|
|
|
71
114
|
(0, assert_js_1.assertBytes32)(publicKey32, "publicKey32");
|
|
72
115
|
(0, assert_js_1.assertUint8Array)(msg, "msg");
|
|
73
116
|
(0, assert_js_1.assertBytes64)(signature64, "signature64");
|
|
74
|
-
return
|
|
117
|
+
return getWasmAxl().axlsignVerify(publicKey32, msg, signature64);
|
|
75
118
|
}
|
|
76
119
|
/**
|
|
77
120
|
* Returns signature || message (axlsign mode).
|
package/dist/cjs/axlsign.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"axlsign.js","sourceRoot":"","sources":["../../src/axlsign.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"axlsign.js","sourceRoot":"","sources":["../../src/axlsign.ts"],"names":[],"mappings":";;AAyFA,8BAIC;AAKD,8BAKC;AAKD,0CAQC;AAMD,oBAUC;AAKD,wBAKC;AAKD,kCAcC;AAKD,kCAeC;AArLD,qCAAqC;AACrC,yCAAsD;AACtD,6CAA4C;AAC5C,oDAM8B;AAI9B,MAAM,iBAAiB,GAAG,8BAA8B,CAAC;AAEzD,MAAM,WAAW,GACf,OAAO,UAAU,KAAK,QAAQ;IAC5B,CAAC,CAAC,UAAU;IACZ,CAAC,CAAC,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,IAAI,IAAA,sBAAU,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;QACjB,CAAC,CAAC,IAAA,gBAAI,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,CAAC,CAAC;AAE5C,MAAM,WAAW,GAAG,IAAA,2BAAa,EAAC,WAAW,CAAC,CAAC;AAE/C,IAAI,cAAkC,CAAC;AAEvC,IAAI,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