@unknownncat/curve25519-node 2.1.0 → 2.1.2
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 +6 -6
- package/README.en.md +34 -391
- package/README.md +35 -392
- package/SECURITY.md +11 -0
- package/dist/axlsign.d.ts +1 -1
- package/dist/axlsign.d.ts.map +1 -1
- package/dist/axlsign.js +8 -29
- package/dist/axlsign.js.map +1 -1
- package/dist/cjs/axlsign.js +8 -29
- package/dist/cjs/axlsign.js.map +1 -1
- package/dist/cjs/index.js +2 -11
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/internal/assert.js +1 -1
- package/dist/cjs/internal/assert.js.map +1 -1
- package/dist/cjs/internal/axlsign-wasm/LICENSE +1 -1
- package/dist/cjs/internal/axlsign-wasm/axlsign_wasm.js +129 -65
- package/dist/cjs/internal/axlsign-wasm/axlsign_wasm_bg.wasm +0 -0
- package/dist/cjs/internal/axlsign-wasm/axlsign_wasm_bg.wasm.d.ts +8 -10
- package/dist/index.d.ts +1 -59
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -10
- package/dist/index.js.map +1 -1
- package/dist/internal/assert.js +1 -1
- package/dist/internal/assert.js.map +1 -1
- package/dist/internal/axlsign-wasm/LICENSE +1 -1
- package/dist/internal/axlsign-wasm/axlsign_wasm.js +129 -65
- package/dist/internal/axlsign-wasm/axlsign_wasm_bg.wasm +0 -0
- package/dist/internal/axlsign-wasm/axlsign_wasm_bg.wasm.d.ts +8 -10
- package/package.json +12 -25
- package/dist/cjs/internal/curve25519-wasm/LICENSE +0 -21
- package/dist/cjs/internal/curve25519-wasm/curve25519_wasm.d.ts +0 -12
- package/dist/cjs/internal/curve25519-wasm/curve25519_wasm.js +0 -165
- package/dist/cjs/internal/curve25519-wasm/curve25519_wasm_bg.wasm +0 -0
- package/dist/cjs/internal/curve25519-wasm/curve25519_wasm_bg.wasm.d.ts +0 -13
- package/dist/cjs/internal/curve25519-wasm/package.json +0 -17
- package/dist/cjs/wasm.js +0 -228
- package/dist/cjs/wasm.js.map +0 -1
- package/dist/internal/curve25519-wasm/LICENSE +0 -21
- package/dist/internal/curve25519-wasm/curve25519_wasm.d.ts +0 -12
- package/dist/internal/curve25519-wasm/curve25519_wasm.js +0 -165
- package/dist/internal/curve25519-wasm/curve25519_wasm_bg.wasm +0 -0
- package/dist/internal/curve25519-wasm/curve25519_wasm_bg.wasm.d.ts +0 -13
- package/dist/internal/curve25519-wasm/package.json +0 -17
- package/dist/wasm.d.ts +0 -92
- package/dist/wasm.d.ts.map +0 -1
- package/dist/wasm.js +0 -204
- package/dist/wasm.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,422 +1,65 @@
|
|
|
1
1
|
# @unknownncat/curve25519-node
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> English version: [README.en.md](./README.en.md)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Implementacao para Node.js com API limpa:
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
7
|
+
- `x25519` e `ed25519` via `node:crypto` (OpenSSL)
|
|
8
|
+
- `axlsign` compativel com legado, acelerado por backend Rust/WASM interno
|
|
9
|
+
- sem namespace `wasm`
|
|
10
|
+
- sem namespace `napi`
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
[](https://nodejs.org/)
|
|
13
|
-
[](./dist/index.d.ts)
|
|
14
|
-

|
|
15
|
-

|
|
16
|
-
[](./LICENSE)
|
|
17
|
-
|
|
18
|
-
- Node: `>= 20`
|
|
19
|
-
- Dependências de runtime: `0`
|
|
20
|
-
- TypeScript: `strict`
|
|
21
|
-
- Formatos de módulo: ESM + CJS
|
|
22
|
-
|
|
23
|
-
---
|
|
24
|
-
|
|
25
|
-
## Instalação
|
|
12
|
+
## Instalar
|
|
26
13
|
|
|
27
14
|
```bash
|
|
28
15
|
npm i @unknownncat/curve25519-node
|
|
29
16
|
```
|
|
30
17
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
## Uso Rápido
|
|
18
|
+
## Uso rapido
|
|
34
19
|
|
|
35
20
|
```ts
|
|
36
21
|
import { randomBytes } from "node:crypto";
|
|
37
|
-
import { asBytes32, x25519, ed25519 } from "@unknownncat/curve25519-node";
|
|
22
|
+
import { asBytes32, x25519, ed25519, axlsign } from "@unknownncat/curve25519-node";
|
|
38
23
|
|
|
39
|
-
const
|
|
40
|
-
const
|
|
24
|
+
const seedA = asBytes32(randomBytes(32));
|
|
25
|
+
const seedB = asBytes32(randomBytes(32));
|
|
41
26
|
|
|
42
|
-
const
|
|
43
|
-
const
|
|
27
|
+
const alice = x25519.generateKeyPair(seedA);
|
|
28
|
+
const bob = x25519.generateKeyPair(seedB);
|
|
29
|
+
const shared = x25519.sharedKey(alice.private, bob.public);
|
|
44
30
|
|
|
45
|
-
const segredo1 = x25519.sharedKey(aliceX.private, bobX.public);
|
|
46
|
-
const segredo2 = x25519.sharedKey(bobX.private, aliceX.public);
|
|
47
|
-
// segredo1 === segredo2
|
|
48
|
-
|
|
49
|
-
const signerSeed = asBytes32(randomBytes(32));
|
|
50
|
-
const signer = ed25519.generateKeyPair(signerSeed);
|
|
51
31
|
const msg = new TextEncoder().encode("hello");
|
|
32
|
+
const sig = ed25519.sign(seedA, msg);
|
|
33
|
+
const ok = ed25519.verify(ed25519.publicKey(seedA), msg, sig);
|
|
52
34
|
|
|
53
|
-
const
|
|
54
|
-
const
|
|
35
|
+
const axlSig = axlsign.sign(alice.private, msg, randomBytes(64));
|
|
36
|
+
const axlOk = axlsign.verify(alice.public, msg, axlSig);
|
|
55
37
|
```
|
|
56
38
|
|
|
57
39
|
CommonJS:
|
|
58
40
|
|
|
59
41
|
```js
|
|
60
|
-
const { x25519, ed25519,
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
Legado axlsign via WASM:
|
|
64
|
-
|
|
65
|
-
```ts
|
|
66
|
-
import { asBytes32, axlsign } from "@unknownncat/curve25519-node";
|
|
67
|
-
|
|
68
|
-
const seed = asBytes32(new Uint8Array(32));
|
|
69
|
-
const kp = axlsign.generateKeyPair(seed); // X25519 keypair compatível com curve25519-js
|
|
70
|
-
const sig = axlsign.sign(kp.private, new TextEncoder().encode("hello"), new Uint8Array(64));
|
|
71
|
-
const ok = axlsign.verify(kp.public, new TextEncoder().encode("hello"), sig);
|
|
72
|
-
```
|
|
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
|
-
|
|
88
|
-
---
|
|
89
|
-
|
|
90
|
-
## API
|
|
91
|
-
|
|
92
|
-
### `x25519`
|
|
93
|
-
|
|
94
|
-
- `createPrivateKeyObject(secretKey32: Bytes32): KeyObject`
|
|
95
|
-
- `createPublicKeyObject(publicKey32: Bytes32): KeyObject`
|
|
96
|
-
- `publicKeyFromPrivateKeyObject(privateKey: KeyObject): Bytes32`
|
|
97
|
-
- `publicKey(secretKey32: Bytes32): Bytes32`
|
|
98
|
-
- `sharedKeyFromKeyObjects(privateKey: KeyObject, publicKey: KeyObject): Bytes32`
|
|
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`
|
|
103
|
-
- `generateKeyPair(seed32: Bytes32): { public: Bytes32; private: Bytes32 }`
|
|
104
|
-
|
|
105
|
-
### `ed25519`
|
|
106
|
-
|
|
107
|
-
- `createPrivateKeyObject(secretSeed32: Bytes32): KeyObject`
|
|
108
|
-
- `createPublicKeyObject(publicKey32: Bytes32): KeyObject`
|
|
109
|
-
- `publicKeyFromPrivateKeyObject(privateKey: KeyObject): Bytes32`
|
|
110
|
-
- `publicKey(secretSeed32: Bytes32): Bytes32`
|
|
111
|
-
- `generateKeyPair(seed32: Bytes32): { public: Bytes32; private: Bytes32 }`
|
|
112
|
-
- `sign(secretSeed32: Bytes32, msg: Uint8Array): Bytes64`
|
|
113
|
-
- `signWithPrivateKey(privateKey: KeyObject, msg: Uint8Array): Bytes64`
|
|
114
|
-
- `verify(publicKey32: Bytes32, msg: Uint8Array, signature64: Bytes64): boolean`
|
|
115
|
-
- `verifyWithPublicKey(publicKey: KeyObject, msg: Uint8Array, signature64: Bytes64): boolean`
|
|
116
|
-
- `signMessage(secretSeed32: Bytes32, msg: Uint8Array): Uint8Array` (`assinatura || mensagem`)
|
|
117
|
-
- `openMessage(publicKey32: Bytes32, signedMsg: Uint8Array): Uint8Array | null`
|
|
118
|
-
|
|
119
|
-
### `axlsign` (compatibilidade legado, via WASM)
|
|
120
|
-
|
|
121
|
-
- `publicKey(secretKey32: Bytes32): Bytes32`
|
|
122
|
-
- `sharedKey(secretKey32: Bytes32, publicKey32: Bytes32): Bytes32`
|
|
123
|
-
- `generateKeyPair(seed32: Bytes32): { public: Bytes32; private: Bytes32 }`
|
|
124
|
-
- `sign(secretKey32: Bytes32, msg: Uint8Array, opt_random?: Bytes64): Bytes64`
|
|
125
|
-
- `verify(publicKey32: Bytes32, msg: Uint8Array, signature64: Bytes64): boolean`
|
|
126
|
-
- `signMessage(secretKey32: Bytes32, msg: Uint8Array, opt_random?: Bytes64): Uint8Array`
|
|
127
|
-
- `openMessage(publicKey32: Bytes32, signedMsg: Uint8Array): Uint8Array | null`
|
|
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
|
-
|
|
158
|
-
### Aliases de compatibilidade (top-level)
|
|
159
|
-
|
|
160
|
-
- `sharedKey = x25519.sharedKey`
|
|
161
|
-
- `sharedKeyStrict = x25519.sharedKeyStrict`
|
|
162
|
-
- `generateKeyPair = x25519.generateKeyPair`
|
|
163
|
-
- `sign`, `verify`, `signMessage`, `openMessage` (semântica Ed25519)
|
|
164
|
-
- `generateKeyPairX25519`, `generateKeyPairEd25519`
|
|
165
|
-
|
|
166
|
-
---
|
|
167
|
-
|
|
168
|
-
## Notas de Compatibilidade
|
|
169
|
-
|
|
170
|
-
Este pacote suporta três modos:
|
|
171
|
-
|
|
172
|
-
- **moderno nativo (recomendado):** `x25519` + `ed25519` via `node:crypto`
|
|
173
|
-
- **moderno WASM (opcional):** namespace `wasm` (`wasm.x25519` + `wasm.ed25519`)
|
|
174
|
-
- **legado:** `axlsign` via WASM para compatibilidade com `curve25519-js`
|
|
175
|
-
|
|
176
|
-
| Recurso | `curve25519-js` | `curve25519-node` |
|
|
177
|
-
| ----------------------------------- | --------------- | -------------------------------------------- |
|
|
178
|
-
| Esquema de assinatura (moderno) | axlsign | Ed25519 (padrão) |
|
|
179
|
-
| Esquema moderno alternativo | não | Ed25519 via WASM (`wasm.ed25519`) |
|
|
180
|
-
| Esquema de assinatura (legado) | axlsign | axlsign (namespace `axlsign`) |
|
|
181
|
-
| Acordo de chave | X25519 | X25519 |
|
|
182
|
-
| Acordo moderno alternativo | não | X25519 via WASM (`wasm.x25519`) |
|
|
183
|
-
| Mesma chave para assinatura + ECDH | sim | apenas no namespace `axlsign` |
|
|
184
|
-
| `opt_random` nas APIs de assinatura | sim | sim no `axlsign`, não no top-level/`ed25519` |
|
|
185
|
-
| Backend OpenSSL | não | sim |
|
|
186
|
-
|
|
187
|
-
Importante:
|
|
188
|
-
|
|
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.
|
|
191
|
-
- `node:crypto` não expõe API para converter public key X25519 ↔ Ed25519.
|
|
192
|
-
- Top-level `sign`/`signMessage` e namespace `ed25519` continuam com semântica Ed25519 e rejeitam `opt_random`.
|
|
193
|
-
- Para compatibilidade com `curve25519-js` (incluindo `opt_random`), use o namespace `axlsign`.
|
|
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).
|
|
196
|
-
|
|
197
|
-
---
|
|
198
|
-
|
|
199
|
-
## Motivação
|
|
200
|
-
|
|
201
|
-
O `curve25519-js` é um projeto importante, mas usa aritmética de campo manual em JS (`Float64Array`, estilo TweetNaCl).
|
|
202
|
-
|
|
203
|
-
Este pacote foca em Node moderno com primitivas do OpenSSL:
|
|
204
|
-
|
|
205
|
-
- caminho de implementação mais seguro
|
|
206
|
-
- melhor desempenho em Node >= 20
|
|
207
|
-
- API menor e explícita
|
|
208
|
-
- tipagem forte com zero dependências de runtime
|
|
209
|
-
|
|
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.
|
|
214
|
-
|
|
215
|
-
---
|
|
216
|
-
|
|
217
|
-
## Tipos Branded
|
|
218
|
-
|
|
219
|
-
- `Bytes32`
|
|
220
|
-
- `Bytes64`
|
|
221
|
-
|
|
222
|
-
Helpers (validam sem copiar):
|
|
223
|
-
|
|
224
|
-
- `asBytes32(u8)`
|
|
225
|
-
- `asBytes64(u8)`
|
|
226
|
-
|
|
227
|
-
---
|
|
228
|
-
|
|
229
|
-
## Mapa de RFCs (uso no projeto)
|
|
230
|
-
|
|
231
|
-
| RFC | Seções usadas | Uso no projeto | Onde no código |
|
|
232
|
-
| --------------------------------- | ------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------- |
|
|
233
|
-
| RFC 7748 (X25519) | Seção 5 (`The X25519 and X448 Functions`) | Regras de clamping/decoding do escalar e comportamento da função X25519 (zera 3 bits baixos, zera bit mais alto, seta o segundo bit mais alto). | `src/x25519.ts` |
|
|
234
|
-
| RFC 7748 (X25519) | Seção 5.2 (`Test Vectors`), Seção 6.1 (`Diffie-Hellman / Curve25519`) | Vetores oficiais para validação de interoperabilidade e corretude. | `test/x25519.test.mjs` |
|
|
235
|
-
| RFC 8032 (Ed25519) | Seção 5.1.5 (`Key Generation`), 5.1.6 (`Sign`), 5.1.7 (`Verify`) | Semântica de keygen/sign/verify Ed25519 (executada por OpenSSL via `node:crypto`). | `src/ed25519.ts` |
|
|
236
|
-
| RFC 8032 (Ed25519) | Seção 7.1 (`Test Vectors for Ed25519`) | Vetores determinísticos para validação de chave pública e assinatura. | `test/ed25519.test.mjs` |
|
|
237
|
-
| RFC 8410 (X25519/Ed25519 em PKIX) | Seção 3 (identificadores de algoritmo), Seção 4 (`Subject Public Key Fields`), Seção 7 (`Private Key Format`) | Estrutura DER para import/export de chaves raw de 32 bytes em SPKI/PKCS#8 com OIDs de X25519 e Ed25519. | `src/internal/der.ts` |
|
|
238
|
-
|
|
239
|
-
Referências indiretas por estrutura ASN.1/PKIX:
|
|
240
|
-
|
|
241
|
-
- RFC 5958 (OneAsymmetricKey / família PKCS#8)
|
|
242
|
-
- RFC 5280, Seção 4.1.2.7 (`Subject Public Key Info`)
|
|
243
|
-
|
|
244
|
-
Observações:
|
|
245
|
-
|
|
246
|
-
- O projeto não reimplementa aritmética de curva em JS; as operações criptográficas usam OpenSSL via `node:crypto`.
|
|
247
|
-
- A suíte de testes cobre vetores oficiais do RFC 7748 e RFC 8032.
|
|
248
|
-
|
|
249
|
-
Rodar testes:
|
|
250
|
-
|
|
251
|
-
```bash
|
|
252
|
-
npm test
|
|
253
|
-
```
|
|
254
|
-
|
|
255
|
-
---
|
|
256
|
-
|
|
257
|
-
## Detalhes Técnicos (DER / RFC 8410)
|
|
258
|
-
|
|
259
|
-
Chaves raw de 32 bytes são importadas/exportadas com prefixos fixos:
|
|
260
|
-
|
|
261
|
-
- X25519 PKCS#8: `302e020100300506032b656e04220420`
|
|
262
|
-
- X25519 SPKI: `302a300506032b656e032100`
|
|
263
|
-
- Ed25519 PKCS#8: `302e020100300506032b657004220420`
|
|
264
|
-
- Ed25519 SPKI: `302a300506032b6570032100`
|
|
265
|
-
|
|
266
|
-
Notas de implementação:
|
|
267
|
-
|
|
268
|
-
- buffers prealocados + `.set`
|
|
269
|
-
- views zero-copy de `Uint8Array` quando seguro
|
|
270
|
-
- sem `Buffer.concat` em hot path
|
|
271
|
-
|
|
272
|
-
---
|
|
273
|
-
|
|
274
|
-
## Notas de Performance
|
|
275
|
-
|
|
276
|
-
- Evita cópias desnecessárias de bytes nos caminhos críticos.
|
|
277
|
-
- `signMessage` monta `assinatura || mensagem` com um único `Uint8Array` prealocado.
|
|
278
|
-
- Para throughput máximo em loops longos, use os helpers de `KeyObject` (`create*KeyObject`, `*FromKeyObjects`) para reduzir overhead de parse ASN.1.
|
|
279
|
-
|
|
280
|
-
---
|
|
281
|
-
|
|
282
|
-
## Notas de Segurança
|
|
283
|
-
|
|
284
|
-
- validação estrita de tipo/tamanho nas APIs públicas
|
|
285
|
-
- sem log de segredos
|
|
286
|
-
- `timingSafeEqual` em comparações internas de tamanho fixo quando necessário
|
|
287
|
-
|
|
288
|
-
---
|
|
289
|
-
|
|
290
|
-
## Benchmarks
|
|
291
|
-
|
|
292
|
-
A suíte de benchmark fica isolada em `bench/` (subprojeto separado) e compara com `curve25519-js`.
|
|
293
|
-
|
|
294
|
-
```bash
|
|
295
|
-
npm run build
|
|
296
|
-
cd bench
|
|
297
|
-
npm install
|
|
298
|
-
npm run bench
|
|
299
|
-
```
|
|
300
|
-
|
|
301
|
-
### Snapshot real de benchmark (`npm run bench:ci`) no GitHub Codespaces
|
|
302
|
-
|
|
303
|
-
Comando:
|
|
304
|
-
|
|
305
|
-
```bash
|
|
306
|
-
node --expose-gc bench.mjs --rounds=16 --roundMs=350 --warmupMs=500 --vectors=64 --variants=raw,cached --strict --verifyEvery=64 --jsonFile=results/bench-results.json
|
|
307
|
-
```
|
|
308
|
-
|
|
309
|
-
Ambiente:
|
|
310
|
-
|
|
311
|
-
- Node: `v24.11.1`
|
|
312
|
-
- OpenSSL: `3.5.4`
|
|
313
|
-
- CPU: `AMD EPYC 7763 64-Core Processor`
|
|
314
|
-
- Cores lógicos: `4`
|
|
315
|
-
- Vetores: `64`
|
|
316
|
-
|
|
317
|
-
### Tabela 1 - API moderna (`x25519` + `ed25519`)
|
|
318
|
-
|
|
319
|
-
`sign`/`verify` abaixo comparam throughput de API, não equivalência criptográfica (Ed25519 vs axlsign legado).
|
|
320
|
-
|
|
321
|
-
| Operação | Moderno raw | Legado raw (`curve25519-js`) | Speedup raw | Moderno cached | Legado cached (`curve25519-js`) | Speedup cached |
|
|
322
|
-
| ------------------------------ | ----------: | ---------------------------: | ----------: | -------------: | ------------------------------: | -------------: |
|
|
323
|
-
| `x25519.generateKeyPair` | 14,378 | 1,591 | 9.04x | 41,120 | 1,478 | 27.83x |
|
|
324
|
-
| `x25519.sharedKey` | 9,970 | 1,591 | 6.27x | 23,995 | 1,554 | 15.44x |
|
|
325
|
-
| `ed25519.sign (msg32)` | 11,273 | 143 | 78.95x | 23,696 | 133 | 178.10x |
|
|
326
|
-
| `ed25519.sign (msg1024)` | 10,800 | 138 | 78.07x | 22,502 | 147 | 152.92x |
|
|
327
|
-
| `ed25519.verify (msg32)` | 7,280 | 136 | 53.36x | 8,271 | 155 | 53.37x |
|
|
328
|
-
| `ed25519.verify (msg1024)` | 7,160 | 132 | 54.33x | 8,159 | 154 | 52.90x |
|
|
329
|
-
| `ed25519.signMessage (msg256)` | 10,624 | 131 | 81.09x | 23,304 | 148 | 156.97x |
|
|
330
|
-
| `ed25519.openMessage (msg256)` | 6,574 | 124 | 52.93x | 8,129 | 154 | 52.64x |
|
|
331
|
-
|
|
332
|
-
### Tabela 2 - Compatibilidade `axlsign` (equivalente ao `curve25519-js`)
|
|
333
|
-
|
|
334
|
-
Aqui a comparação é de mesmo esquema criptográfico (equivalência + throughput).
|
|
335
|
-
|
|
336
|
-
| Operação | Moderno raw | Legado raw (`curve25519-js`) | Speedup raw | Moderno cached | Legado cached (`curve25519-js`) | Speedup cached |
|
|
337
|
-
| ----------------------------------------- | ----------: | ---------------------------: | ----------: | -------------: | ------------------------------: | -------------: |
|
|
338
|
-
| `axlsign.generateKeyPair` | 8,429 | 1,583 | 5.33x | 8,384 | 1,585 | 5.29x |
|
|
339
|
-
| `axlsign.sharedKey` | 8,452 | 1,583 | 5.34x | 8,396 | 1,570 | 5.35x |
|
|
340
|
-
| `axlsign.sign (msg32)` | 3,973 | 144 | 27.61x | 3,952 | 140 | 28.28x |
|
|
341
|
-
| `axlsign.sign (msg32,opt_random)` | 3,969 | 147 | 27.03x | 3,984 | 139 | 28.58x |
|
|
342
|
-
| `axlsign.sign (msg1024)` | 3,881 | 143 | 27.16x | 3,864 | 139 | 27.72x |
|
|
343
|
-
| `axlsign.verify (msg32)` | 6,527 | 146 | 44.70x | 6,534 | 143 | 45.72x |
|
|
344
|
-
| `axlsign.verify (msg32,opt_random)` | 6,506 | 144 | 45.07x | 6,469 | 141 | 45.80x |
|
|
345
|
-
| `axlsign.verify (msg1024)` | 6,361 | 141 | 45.03x | 6,337 | 135 | 46.92x |
|
|
346
|
-
| `axlsign.signMessage (msg256)` | 3,902 | 140 | 27.79x | 3,935 | 141 | 27.98x |
|
|
347
|
-
| `axlsign.signMessage (msg256,opt_random)` | 3,885 | 142 | 27.40x | 3,864 | 145 | 26.60x |
|
|
348
|
-
| `axlsign.openMessage (msg256)` | 6,441 | 138 | 46.57x | 6,300 | 131 | 47.93x |
|
|
349
|
-
| `axlsign.openMessage (msg256,opt_random)` | 6,362 | 141 | 45.24x | 6,285 | 130 | 48.22x |
|
|
350
|
-
|
|
351
|
-
Notas:
|
|
352
|
-
|
|
353
|
-
- `raw` inclui custo fim-a-fim da API.
|
|
354
|
-
- `cached` reduz overhead de setup para evidenciar melhor o throughput criptográfico.
|
|
355
|
-
- Fonte dos números: saída JSON de `bench:ci` (`results/bench-results.json`).
|
|
356
|
-
|
|
357
|
-
---
|
|
358
|
-
|
|
359
|
-
## Build dos namespaces WASM (`axlsign` e `wasm`)
|
|
360
|
-
|
|
361
|
-
No pacote publicado no npm, os artefatos WASM já vêm prontos em `dist/`.
|
|
362
|
-
|
|
363
|
-
Para buildar a partir do código-fonte, você precisa:
|
|
364
|
-
|
|
365
|
-
- Rust toolchain
|
|
366
|
-
- `wasm-pack` instalado
|
|
367
|
-
|
|
368
|
-
Com isso, `npm run build` executa:
|
|
369
|
-
|
|
370
|
-
1. `wasm-pack build` (`wasm/axlsign`)
|
|
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
|
|
42
|
+
const { x25519, ed25519, axlsign } = require("@unknownncat/curve25519-node");
|
|
389
43
|
```
|
|
390
44
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
## Licença
|
|
394
|
-
|
|
395
|
-
MIT
|
|
45
|
+
## Exports
|
|
396
46
|
|
|
397
|
-
|
|
47
|
+
- `x25519`
|
|
48
|
+
- `ed25519`
|
|
49
|
+
- `axlsign`
|
|
50
|
+
- aliases top-level: `sharedKey`, `sharedKeyStrict`, `generateKeyPair`, `sign`, `verify`, `signMessage`, `openMessage`
|
|
51
|
+
- tipos/helpers: `Bytes32`, `Bytes64`, `asBytes32`, `asBytes64`
|
|
398
52
|
|
|
399
|
-
|
|
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)
|
|
53
|
+
## Observacoes
|
|
402
54
|
|
|
403
|
-
|
|
55
|
+
- `sign`/`verify` top-level seguem semantica Ed25519 e rejeitam `opt_random`.
|
|
56
|
+
- Para fluxo legado compativel com `curve25519-js`, use `axlsign.*`.
|
|
57
|
+
- Se voce precisa de WASM no navegador, use `@unknownncat/curve25519-browser`.
|
|
404
58
|
|
|
405
|
-
##
|
|
59
|
+
## Licenca e avisos
|
|
406
60
|
|
|
407
|
-
- [
|
|
408
|
-
- [
|
|
409
|
-
-
|
|
410
|
-
- [
|
|
411
|
-
- [
|
|
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)
|
|
418
|
-
- [RFC 7748](https://www.rfc-editor.org/rfc/rfc7748)
|
|
419
|
-
- [RFC 8032](https://www.rfc-editor.org/rfc/rfc8032)
|
|
420
|
-
- [RFC 8410](https://www.rfc-editor.org/rfc/rfc8410)
|
|
421
|
-
- [RFC 5958](https://www.rfc-editor.org/rfc/rfc5958)
|
|
422
|
-
- [RFC 5280](https://www.rfc-editor.org/rfc/rfc5280)
|
|
61
|
+
- [LICENSE](./LICENSE)
|
|
62
|
+
- [NOTICE.md](./NOTICE.md)
|
|
63
|
+
- [THIRD_PARTY_NOTICE.md](./THIRD_PARTY_NOTICE.md)
|
|
64
|
+
- [THIRD_PARTY_NOTICES.md](./THIRD_PARTY_NOTICES.md)
|
|
65
|
+
- [SECURITY.md](./SECURITY.md)
|
package/SECURITY.md
CHANGED
|
@@ -21,3 +21,14 @@ If private reporting is not available, open a public issue without sensitive det
|
|
|
21
21
|
|
|
22
22
|
- Cryptographic flaws, incorrect input validation, and integrity/confidentiality issues are high priority.
|
|
23
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Bytes32, Bytes64, KeyPair32 } from "./types.js";
|
|
2
2
|
/**
|
|
3
|
-
* Derives an axlsign-compatible public key (Montgomery/X25519 format).
|
|
3
|
+
* Derives an axlsign-compatible public key (Montgomery/X25519 format) in Node runtime.
|
|
4
4
|
*/
|
|
5
5
|
export declare function publicKey(secretKey32: Bytes32): Bytes32;
|
|
6
6
|
/**
|
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":"AAQA,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAyB9D;;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,27 +1,6 @@
|
|
|
1
|
-
import { dirname, join } from "node:path";
|
|
2
|
-
import { createRequire } from "node:module";
|
|
3
1
|
import { asBytes32, asBytes64, assertBytes32, assertBytes64, assertUint8Array, } from "./internal/assert.js";
|
|
4
|
-
|
|
5
|
-
const
|
|
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
|
-
}
|
|
2
|
+
import * as rustAxlsign from "./internal/axlsign-wasm/axlsign_wasm.js";
|
|
3
|
+
const rustBindings = rustAxlsign;
|
|
25
4
|
function clampScalar(seed32) {
|
|
26
5
|
const out = new Uint8Array(32);
|
|
27
6
|
out.set(seed32);
|
|
@@ -36,11 +15,11 @@ function assertOptionalRandom64(value, fnName) {
|
|
|
36
15
|
assertBytes64(value, `${fnName} opt_random`);
|
|
37
16
|
}
|
|
38
17
|
/**
|
|
39
|
-
* Derives an axlsign-compatible public key (Montgomery/X25519 format).
|
|
18
|
+
* Derives an axlsign-compatible public key (Montgomery/X25519 format) in Node runtime.
|
|
40
19
|
*/
|
|
41
20
|
export function publicKey(secretKey32) {
|
|
42
21
|
assertBytes32(secretKey32, "secretKey32");
|
|
43
|
-
const out =
|
|
22
|
+
const out = rustBindings.axlsignPublicKey(secretKey32);
|
|
44
23
|
return asBytes32(out, "axlsign public key");
|
|
45
24
|
}
|
|
46
25
|
/**
|
|
@@ -49,7 +28,7 @@ export function publicKey(secretKey32) {
|
|
|
49
28
|
export function sharedKey(secretKey32, publicKey32) {
|
|
50
29
|
assertBytes32(secretKey32, "secretKey32");
|
|
51
30
|
assertBytes32(publicKey32, "publicKey32");
|
|
52
|
-
const out =
|
|
31
|
+
const out = rustBindings.axlsignSharedKey(secretKey32, publicKey32);
|
|
53
32
|
return asBytes32(out, "axlsign shared key");
|
|
54
33
|
}
|
|
55
34
|
/**
|
|
@@ -73,8 +52,8 @@ export function sign(secretKey32, msg, opt_random) {
|
|
|
73
52
|
assertUint8Array(msg, "msg");
|
|
74
53
|
assertOptionalRandom64(opt_random, "sign");
|
|
75
54
|
const signature = opt_random === undefined
|
|
76
|
-
?
|
|
77
|
-
:
|
|
55
|
+
? rustBindings.axlsignSign(secretKey32, msg)
|
|
56
|
+
: rustBindings.axlsignSignRnd(secretKey32, msg, opt_random);
|
|
78
57
|
return asBytes64(signature, "axlsign signature");
|
|
79
58
|
}
|
|
80
59
|
/**
|
|
@@ -84,7 +63,7 @@ export function verify(publicKey32, msg, signature64) {
|
|
|
84
63
|
assertBytes32(publicKey32, "publicKey32");
|
|
85
64
|
assertUint8Array(msg, "msg");
|
|
86
65
|
assertBytes64(signature64, "signature64");
|
|
87
|
-
return
|
|
66
|
+
return rustBindings.axlsignVerify(publicKey32, msg, signature64);
|
|
88
67
|
}
|
|
89
68
|
/**
|
|
90
69
|
* 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,
|
|
1
|
+
{"version":3,"file":"axlsign.js","sourceRoot":"","sources":["../src/axlsign.ts"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verify;
|
|
8
8
|
exports.signMessage = signMessage;
|
|
9
9
|
exports.openMessage = openMessage;
|
|
10
|
-
const node_path_1 = require("node:path");
|
|
11
|
-
const node_module_1 = require("node:module");
|
|
12
10
|
const assert_js_1 = require("./internal/assert.js");
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
? __filename
|
|
16
|
-
: typeof process.argv[1] === "string"
|
|
17
|
-
? process.argv[1]
|
|
18
|
-
: (0, node_path_1.join)(process.cwd(), "index.js");
|
|
19
|
-
const nodeRequire = (0, node_module_1.createRequire)(requireBase);
|
|
20
|
-
let wasmModulePath;
|
|
21
|
-
let wasmAxl;
|
|
22
|
-
function getWasmAxl() {
|
|
23
|
-
if (wasmAxl !== undefined) {
|
|
24
|
-
return wasmAxl;
|
|
25
|
-
}
|
|
26
|
-
if (wasmModulePath === undefined) {
|
|
27
|
-
const packageJsonPath = nodeRequire.resolve(`${SELF_PACKAGE_NAME}/package.json`);
|
|
28
|
-
wasmModulePath = (0, node_path_1.join)((0, node_path_1.dirname)(packageJsonPath), "dist", "internal", "axlsign-wasm", "axlsign_wasm.js");
|
|
29
|
-
}
|
|
30
|
-
// Lazy-load WASM bindings to keep modern-only imports lightweight.
|
|
31
|
-
wasmAxl = nodeRequire(wasmModulePath);
|
|
32
|
-
return wasmAxl;
|
|
33
|
-
}
|
|
11
|
+
const rustAxlsign = require("./internal/axlsign-wasm/axlsign_wasm.js");
|
|
12
|
+
const rustBindings = rustAxlsign;
|
|
34
13
|
function clampScalar(seed32) {
|
|
35
14
|
const out = new Uint8Array(32);
|
|
36
15
|
out.set(seed32);
|
|
@@ -45,11 +24,11 @@ function assertOptionalRandom64(value, fnName) {
|
|
|
45
24
|
(0, assert_js_1.assertBytes64)(value, `${fnName} opt_random`);
|
|
46
25
|
}
|
|
47
26
|
/**
|
|
48
|
-
* Derives an axlsign-compatible public key (Montgomery/X25519 format).
|
|
27
|
+
* Derives an axlsign-compatible public key (Montgomery/X25519 format) in Node runtime.
|
|
49
28
|
*/
|
|
50
29
|
function publicKey(secretKey32) {
|
|
51
30
|
(0, assert_js_1.assertBytes32)(secretKey32, "secretKey32");
|
|
52
|
-
const out =
|
|
31
|
+
const out = rustBindings.axlsignPublicKey(secretKey32);
|
|
53
32
|
return (0, assert_js_1.asBytes32)(out, "axlsign public key");
|
|
54
33
|
}
|
|
55
34
|
/**
|
|
@@ -58,7 +37,7 @@ function publicKey(secretKey32) {
|
|
|
58
37
|
function sharedKey(secretKey32, publicKey32) {
|
|
59
38
|
(0, assert_js_1.assertBytes32)(secretKey32, "secretKey32");
|
|
60
39
|
(0, assert_js_1.assertBytes32)(publicKey32, "publicKey32");
|
|
61
|
-
const out =
|
|
40
|
+
const out = rustBindings.axlsignSharedKey(secretKey32, publicKey32);
|
|
62
41
|
return (0, assert_js_1.asBytes32)(out, "axlsign shared key");
|
|
63
42
|
}
|
|
64
43
|
/**
|
|
@@ -82,8 +61,8 @@ function sign(secretKey32, msg, opt_random) {
|
|
|
82
61
|
(0, assert_js_1.assertUint8Array)(msg, "msg");
|
|
83
62
|
assertOptionalRandom64(opt_random, "sign");
|
|
84
63
|
const signature = opt_random === undefined
|
|
85
|
-
?
|
|
86
|
-
:
|
|
64
|
+
? rustBindings.axlsignSign(secretKey32, msg)
|
|
65
|
+
: rustBindings.axlsignSignRnd(secretKey32, msg, opt_random);
|
|
87
66
|
return (0, assert_js_1.asBytes64)(signature, "axlsign signature");
|
|
88
67
|
}
|
|
89
68
|
/**
|
|
@@ -93,7 +72,7 @@ function verify(publicKey32, msg, signature64) {
|
|
|
93
72
|
(0, assert_js_1.assertBytes32)(publicKey32, "publicKey32");
|
|
94
73
|
(0, assert_js_1.assertUint8Array)(msg, "msg");
|
|
95
74
|
(0, assert_js_1.assertBytes64)(signature64, "signature64");
|
|
96
|
-
return
|
|
75
|
+
return rustBindings.axlsignVerify(publicKey32, msg, signature64);
|
|
97
76
|
}
|
|
98
77
|
/**
|
|
99
78
|
* Returns signature || message (axlsign mode).
|