cojson-core-napi 0.18.22
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.txt +19 -0
- package/README.md +346 -0
- package/index.d.ts +222 -0
- package/index.js +586 -0
- package/package.json +114 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright 2025, Garden Computing, Inc.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
# cojson-core-napi
|
|
2
|
+
|
|
3
|
+
A high-performance Node.js native addon for cryptographic operations, built with Rust and NAPI. This package provides essential cryptographic primitives for the Jazz framework, including hashing, encryption, digital signatures, and key management.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **BLAKE3 Hashing**: Fast, secure cryptographic hashing with incremental support
|
|
8
|
+
- **Ed25519 Digital Signatures**: High-performance elliptic curve digital signatures
|
|
9
|
+
- **X25519 Key Exchange**: Secure key exchange for encrypted communications
|
|
10
|
+
- **XSalsa20 Encryption**: Stream cipher encryption with optional authentication
|
|
11
|
+
- **Session Management**: Transaction logging and cryptographic session handling
|
|
12
|
+
- **Cross-Platform**: Pre-built binaries for multiple platforms and architectures
|
|
13
|
+
|
|
14
|
+
## Jazz Framework Integration
|
|
15
|
+
|
|
16
|
+
This package is a core component of the Jazz framework, providing the cryptographic foundation for:
|
|
17
|
+
|
|
18
|
+
- **CoJSON**: Collaborative JSON documents with cryptographic integrity
|
|
19
|
+
- **Real-time Collaboration**: Secure peer-to-peer synchronization
|
|
20
|
+
- **Authentication**: Cryptographic identity and session management
|
|
21
|
+
- **End-to-End Encryption**: Secure data transmission and storage
|
|
22
|
+
|
|
23
|
+
The package is used throughout the Jazz ecosystem by other packages like `cojson`, `jazz-tools`, and various examples in the monorepo.
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
### In the Jazz Monorepo
|
|
28
|
+
|
|
29
|
+
If you're working within the Jazz monorepo, the package is already available as a workspace dependency:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
# From the monorepo root
|
|
33
|
+
pnpm install
|
|
34
|
+
|
|
35
|
+
# Build the NAPI package specifically
|
|
36
|
+
pnpm run build:napi
|
|
37
|
+
|
|
38
|
+
# Run tests for the NAPI package
|
|
39
|
+
pnpm test:napi
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### As a Standalone Package
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pnpm install cojson-core-napi
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The package includes pre-built binaries for the following platforms:
|
|
49
|
+
- macOS (x64, ARM64)
|
|
50
|
+
- Linux (x64, ARM64, ARM, musl)
|
|
51
|
+
|
|
52
|
+
## API Reference
|
|
53
|
+
|
|
54
|
+
### Hashing Functions
|
|
55
|
+
|
|
56
|
+
#### `blake3HashOnce(data: Uint8Array): Uint8Array`
|
|
57
|
+
|
|
58
|
+
Hash data once using BLAKE3. Returns 32 bytes of hash output.
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
import { blake3HashOnce } from 'cojson-core-napi';
|
|
62
|
+
|
|
63
|
+
const data = new TextEncoder().encode("Hello, World!");
|
|
64
|
+
const hash = blake3HashOnce(data);
|
|
65
|
+
console.log(hash.length); // 32
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
#### `blake3HashOnceWithContext(data: Uint8Array, context: Uint8Array): Uint8Array`
|
|
69
|
+
|
|
70
|
+
Hash data with a context prefix for domain separation.
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
import { blake3HashOnceWithContext } from 'cojson-core-napi';
|
|
74
|
+
|
|
75
|
+
const data = new TextEncoder().encode("message");
|
|
76
|
+
const context = new TextEncoder().encode("domain");
|
|
77
|
+
const hash = blake3HashOnceWithContext(data, context);
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
#### `Blake3Hasher`
|
|
81
|
+
|
|
82
|
+
Incremental hashing for large datasets.
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
import { Blake3Hasher } from 'cojson-core-napi';
|
|
86
|
+
|
|
87
|
+
const hasher = new Blake3Hasher();
|
|
88
|
+
hasher.update(new TextEncoder().encode("part1"));
|
|
89
|
+
hasher.update(new TextEncoder().encode("part2"));
|
|
90
|
+
const hash = hasher.finalize();
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Digital Signatures (Ed25519)
|
|
94
|
+
|
|
95
|
+
#### `newEd25519SigningKey(): Uint8Array`
|
|
96
|
+
|
|
97
|
+
Generate a new Ed25519 signing key.
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
import { newEd25519SigningKey, ed25519VerifyingKey, ed25519Sign, ed25519Verify } from 'cojson-core-napi';
|
|
101
|
+
|
|
102
|
+
const signingKey = newEd25519SigningKey();
|
|
103
|
+
const verifyingKey = ed25519VerifyingKey(signingKey);
|
|
104
|
+
|
|
105
|
+
const message = new TextEncoder().encode("Hello, World!");
|
|
106
|
+
const signature = ed25519Sign(signingKey, message);
|
|
107
|
+
const isValid = ed25519Verify(verifyingKey, message, signature);
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
#### Key Management Functions
|
|
111
|
+
|
|
112
|
+
- `ed25519SigningKeyFromBytes(bytes: Uint8Array): Uint8Array` - Validate and copy signing key bytes
|
|
113
|
+
- `ed25519VerifyingKeyFromBytes(bytes: Uint8Array): Uint8Array` - Validate and copy verifying key bytes
|
|
114
|
+
- `ed25519SignatureFromBytes(bytes: Uint8Array): Uint8Array` - Validate and copy signature bytes
|
|
115
|
+
- `ed25519SigningKeyToPublic(signingKey: Uint8Array): Uint8Array` - Derive public key from signing key
|
|
116
|
+
- `ed25519SigningKeySign(signingKey: Uint8Array, message: Uint8Array): Uint8Array` - Sign with signing key
|
|
117
|
+
|
|
118
|
+
### Key Exchange (X25519)
|
|
119
|
+
|
|
120
|
+
#### `newX25519PrivateKey(): Uint8Array`
|
|
121
|
+
|
|
122
|
+
Generate a new X25519 private key.
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
import { newX25519PrivateKey, x25519PublicKey, x25519DiffieHellman } from 'cojson-core-napi';
|
|
126
|
+
|
|
127
|
+
const alicePrivate = newX25519PrivateKey();
|
|
128
|
+
const alicePublic = x25519PublicKey(alicePrivate);
|
|
129
|
+
|
|
130
|
+
const bobPrivate = newX25519PrivateKey();
|
|
131
|
+
const bobPublic = x25519PublicKey(bobPrivate);
|
|
132
|
+
|
|
133
|
+
// Perform key exchange
|
|
134
|
+
const aliceShared = x25519DiffieHellman(alicePrivate, bobPublic);
|
|
135
|
+
const bobShared = x25519DiffieHellman(bobPrivate, alicePublic);
|
|
136
|
+
// aliceShared and bobShared are identical
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Encryption Functions
|
|
140
|
+
|
|
141
|
+
#### `encrypt(value: Uint8Array, keySecret: string, nonceMaterial: Uint8Array): Uint8Array`
|
|
142
|
+
#### `decrypt(ciphertext: Uint8Array, keySecret: string, nonceMaterial: Uint8Array): Uint8Array`
|
|
143
|
+
|
|
144
|
+
Encrypt/decrypt data with a key secret and nonce material.
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
import { encrypt, decrypt } from 'cojson-core-napi';
|
|
148
|
+
|
|
149
|
+
const keySecret = "keySecret_z11111111111111111111111111111111"; // Base58-encoded key
|
|
150
|
+
const nonceMaterial = new TextEncoder().encode("nonce");
|
|
151
|
+
const plaintext = new TextEncoder().encode("Secret message");
|
|
152
|
+
|
|
153
|
+
const ciphertext = encrypt(plaintext, keySecret, nonceMaterial);
|
|
154
|
+
const decrypted = decrypt(ciphertext, keySecret, nonceMaterial);
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
#### `encryptXsalsa20(key: Uint8Array, nonceMaterial: Uint8Array, plaintext: Uint8Array): Uint8Array`
|
|
158
|
+
#### `decryptXsalsa20(key: Uint8Array, nonceMaterial: Uint8Array, ciphertext: Uint8Array): Uint8Array`
|
|
159
|
+
|
|
160
|
+
XSalsa20 stream cipher encryption (without authentication).
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
import { encryptXsalsa20, decryptXsalsa20 } from 'cojson-core-napi';
|
|
164
|
+
|
|
165
|
+
const key = new Uint8Array(32); // 32-byte key
|
|
166
|
+
const nonceMaterial = new TextEncoder().encode("nonce");
|
|
167
|
+
const plaintext = new TextEncoder().encode("Message");
|
|
168
|
+
|
|
169
|
+
const ciphertext = encryptXsalsa20(key, nonceMaterial, plaintext);
|
|
170
|
+
const decrypted = decryptXsalsa20(key, nonceMaterial, ciphertext);
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Sealing/Unsealing (Authenticated Encryption)
|
|
174
|
+
|
|
175
|
+
#### `seal(message: Uint8Array, senderSecret: string, recipientId: string, nonceMaterial: Uint8Array): Uint8Array`
|
|
176
|
+
#### `unseal(sealedMessage: Uint8Array, recipientSecret: string, senderId: string, nonceMaterial: Uint8Array): Uint8Array`
|
|
177
|
+
|
|
178
|
+
Authenticated encryption with perfect forward secrecy using X25519 + XSalsa20-Poly1305.
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
import { seal, unseal, getSealerId } from 'cojson-core-napi';
|
|
182
|
+
|
|
183
|
+
const senderSecret = "sealerSecret_z..."; // Base58-encoded private key
|
|
184
|
+
const recipientId = "sealer_z..."; // Base58-encoded public key
|
|
185
|
+
const nonceMaterial = new TextEncoder().encode("nonce");
|
|
186
|
+
const message = new TextEncoder().encode("Secret message");
|
|
187
|
+
|
|
188
|
+
const sealed = seal(message, senderSecret, recipientId, nonceMaterial);
|
|
189
|
+
const unsealed = unseal(sealed, senderSecret, recipientId, nonceMaterial);
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Signing/Verification (Base58-wrapped)
|
|
193
|
+
|
|
194
|
+
#### `sign(message: Uint8Array, secret: Uint8Array): string`
|
|
195
|
+
#### `verify(signature: Uint8Array, message: Uint8Array, id: Uint8Array): boolean`
|
|
196
|
+
|
|
197
|
+
Sign and verify messages with base58-encoded signatures and IDs.
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
import { sign, verify, getSignerId } from 'cojson-core-napi';
|
|
201
|
+
|
|
202
|
+
const secret = new TextEncoder().encode("signerSecret_z...");
|
|
203
|
+
const message = new TextEncoder().encode("Hello, World!");
|
|
204
|
+
|
|
205
|
+
const signature = sign(message, secret);
|
|
206
|
+
const isValid = verify(new TextEncoder().encode(signature), message, new TextEncoder().encode("signer_z..."));
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Utility Functions
|
|
210
|
+
|
|
211
|
+
#### `generateNonce(nonceMaterial: Uint8Array): Uint8Array`
|
|
212
|
+
|
|
213
|
+
Generate a 24-byte nonce from input material using BLAKE3.
|
|
214
|
+
|
|
215
|
+
```typescript
|
|
216
|
+
import { generateNonce } from 'cojson-core-napi';
|
|
217
|
+
|
|
218
|
+
const nonceMaterial = new TextEncoder().encode("input");
|
|
219
|
+
const nonce = generateNonce(nonceMaterial);
|
|
220
|
+
console.log(nonce.length); // 24
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
#### `getSealerId(secret: Uint8Array): string`
|
|
224
|
+
#### `getSignerId(secret: Uint8Array): string`
|
|
225
|
+
|
|
226
|
+
Derive sealer/signer IDs from secrets.
|
|
227
|
+
|
|
228
|
+
```typescript
|
|
229
|
+
import { getSealerId, getSignerId } from 'cojson-core-napi';
|
|
230
|
+
|
|
231
|
+
const sealerSecret = new TextEncoder().encode("sealerSecret_z...");
|
|
232
|
+
const sealerId = getSealerId(sealerSecret);
|
|
233
|
+
console.log(sealerId); // "sealer_z..."
|
|
234
|
+
|
|
235
|
+
const signerSecret = new TextEncoder().encode("signerSecret_z...");
|
|
236
|
+
const signerId = getSignerId(signerSecret);
|
|
237
|
+
console.log(signerId); // "signer_z..."
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### Session Management
|
|
241
|
+
|
|
242
|
+
#### `SessionLog`
|
|
243
|
+
|
|
244
|
+
Manage cryptographic sessions and transactions.
|
|
245
|
+
|
|
246
|
+
```typescript
|
|
247
|
+
import { SessionLog } from 'cojson-core-napi';
|
|
248
|
+
|
|
249
|
+
const session = new SessionLog("coId", "sessionId", "signerId");
|
|
250
|
+
|
|
251
|
+
// Add a new private transaction
|
|
252
|
+
const result = session.addNewPrivateTransaction(
|
|
253
|
+
'{"changes": "..."}',
|
|
254
|
+
"signerSecret_z...",
|
|
255
|
+
"keySecret_z...",
|
|
256
|
+
"keyId",
|
|
257
|
+
Date.now(),
|
|
258
|
+
"metadata"
|
|
259
|
+
);
|
|
260
|
+
|
|
261
|
+
// Add a new trusting transaction
|
|
262
|
+
const signature = session.addNewTrustingTransaction(
|
|
263
|
+
'{"changes": "..."}',
|
|
264
|
+
"signerSecret_z...",
|
|
265
|
+
Date.now(),
|
|
266
|
+
"metadata"
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
// Decrypt transaction data
|
|
270
|
+
const changes = session.decryptNextTransactionChangesJson(0, "keySecret_z...");
|
|
271
|
+
const meta = session.decryptNextTransactionMetaJson(0, "keySecret_z...");
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
## Error Handling
|
|
275
|
+
|
|
276
|
+
All functions throw `Error` objects with descriptive messages for invalid inputs or cryptographic failures.
|
|
277
|
+
|
|
278
|
+
```typescript
|
|
279
|
+
try {
|
|
280
|
+
const hash = blake3HashOnce(invalidData);
|
|
281
|
+
} catch (error) {
|
|
282
|
+
console.error('Hashing failed:', error.message);
|
|
283
|
+
}
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
## Performance
|
|
287
|
+
|
|
288
|
+
This package is built with Rust for maximum performance:
|
|
289
|
+
- BLAKE3 hashing is significantly faster than SHA-256
|
|
290
|
+
- Ed25519 signatures are faster than RSA
|
|
291
|
+
- X25519 key exchange is faster than RSA key exchange
|
|
292
|
+
- Native code execution avoids JavaScript overhead
|
|
293
|
+
|
|
294
|
+
## Platform Support
|
|
295
|
+
|
|
296
|
+
The package includes pre-built binaries for:
|
|
297
|
+
- **Windows**: x64, x86, ARM64
|
|
298
|
+
- **macOS**: x64, ARM64 (Apple Silicon)
|
|
299
|
+
- **Linux**: x64, ARM64, ARM, musl
|
|
300
|
+
- **FreeBSD**: x64
|
|
301
|
+
- **Android**: ARM64, ARM
|
|
302
|
+
|
|
303
|
+
## Development
|
|
304
|
+
|
|
305
|
+
### Within the Jazz Monorepo
|
|
306
|
+
|
|
307
|
+
```bash
|
|
308
|
+
# From the monorepo root - install all dependencies
|
|
309
|
+
pnpm install
|
|
310
|
+
|
|
311
|
+
# Build only the NAPI package
|
|
312
|
+
pnpm run build:napi
|
|
313
|
+
|
|
314
|
+
# Build all packages including NAPI
|
|
315
|
+
pnpm run build:packages
|
|
316
|
+
|
|
317
|
+
# Run tests for the NAPI package
|
|
318
|
+
pnpm test:napi
|
|
319
|
+
|
|
320
|
+
# Run all tests (excluding NAPI tests)
|
|
321
|
+
pnpm test
|
|
322
|
+
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
### Using in Other Jazz Packages
|
|
326
|
+
|
|
327
|
+
```typescript
|
|
328
|
+
// In any Jazz package, import directly
|
|
329
|
+
import {
|
|
330
|
+
blake3HashOnce,
|
|
331
|
+
newEd25519SigningKey,
|
|
332
|
+
encrypt,
|
|
333
|
+
decrypt
|
|
334
|
+
} from 'cojson-core-napi';
|
|
335
|
+
|
|
336
|
+
// The package is available as a workspace dependency
|
|
337
|
+
// No additional installation needed
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
## License
|
|
341
|
+
|
|
342
|
+
MIT License - see LICENSE file for details.
|
|
343
|
+
|
|
344
|
+
## Contributing
|
|
345
|
+
|
|
346
|
+
Contributions are welcome! Please see the main Jazz repository for contribution guidelines.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/* auto-generated by NAPI-RS */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export declare class Blake3Hasher {
|
|
4
|
+
constructor()
|
|
5
|
+
update(data: Uint8Array): void
|
|
6
|
+
finalize(): Uint8Array
|
|
7
|
+
clone(): Blake3Hasher
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export declare class SessionLog {
|
|
11
|
+
constructor(coId: string, sessionId: string, signerId?: string | undefined | null)
|
|
12
|
+
clone(): SessionLog
|
|
13
|
+
tryAdd(transactionsJson: Array<string>, newSignatureStr: string, skipVerify: boolean): void
|
|
14
|
+
addNewPrivateTransaction(changesJson: string, signerSecret: string, encryptionKey: string, keyId: string, madeAt: number, meta?: string | undefined | null): string
|
|
15
|
+
addNewTrustingTransaction(changesJson: string, signerSecret: string, madeAt: number, meta?: string | undefined | null): string
|
|
16
|
+
decryptNextTransactionChangesJson(txIndex: number, encryptionKey: string): string
|
|
17
|
+
decryptNextTransactionMetaJson(txIndex: number, encryptionKey: string): string | null
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Hash data once using BLAKE3.
|
|
22
|
+
* - `data`: Raw bytes to hash
|
|
23
|
+
* Returns 32 bytes of hash output.
|
|
24
|
+
* This is the simplest way to compute a BLAKE3 hash of a single piece of data.
|
|
25
|
+
*/
|
|
26
|
+
export declare function blake3HashOnce(data: Uint8Array): Uint8Array
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Hash data once using BLAKE3 with a context prefix.
|
|
30
|
+
* - `data`: Raw bytes to hash
|
|
31
|
+
* - `context`: Context bytes to prefix to the data
|
|
32
|
+
* Returns 32 bytes of hash output.
|
|
33
|
+
* This is useful for domain separation - the same data hashed with different contexts will produce different outputs.
|
|
34
|
+
*/
|
|
35
|
+
export declare function blake3HashOnceWithContext(data: Uint8Array, context: Uint8Array): Uint8Array
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* NAPI-exposed function to decrypt bytes with a key secret and nonce material.
|
|
39
|
+
* - `ciphertext`: The encrypted bytes to decrypt
|
|
40
|
+
* - `key_secret`: A base58-encoded key secret with "keySecret_z" prefix
|
|
41
|
+
* - `nonce_material`: Raw bytes used to generate the nonce (must match encryption)
|
|
42
|
+
* Returns the decrypted bytes or throws a JsError if decryption fails.
|
|
43
|
+
*/
|
|
44
|
+
export declare function decrypt(ciphertext: Uint8Array, keySecret: string, nonceMaterial: Uint8Array): Uint8Array
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* NAPI-exposed function for XSalsa20 decryption without authentication.
|
|
48
|
+
* - `key`: 32-byte key for decryption (must match encryption key)
|
|
49
|
+
* - `nonce_material`: Raw bytes used to generate a 24-byte nonce (must match encryption)
|
|
50
|
+
* - `ciphertext`: Encrypted bytes to decrypt
|
|
51
|
+
* Returns the decrypted bytes or throws a JsError if decryption fails.
|
|
52
|
+
* Note: This function does not provide authentication. Use decrypt_xsalsa20_poly1305 for authenticated decryption.
|
|
53
|
+
*/
|
|
54
|
+
export declare function decryptXsalsa20(key: Uint8Array, nonceMaterial: Uint8Array, ciphertext: Uint8Array): Uint8Array
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* NAPI-exposed function to sign a message using Ed25519.
|
|
58
|
+
* - `signing_key`: 32 bytes of signing key material
|
|
59
|
+
* - `message`: Raw bytes to sign
|
|
60
|
+
* Returns 64 bytes of signature material or throws JsError if signing fails.
|
|
61
|
+
*/
|
|
62
|
+
export declare function ed25519Sign(signingKey: Uint8Array, message: Uint8Array): Uint8Array
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* NAPI-exposed function to validate and copy Ed25519 signature bytes.
|
|
66
|
+
* - `bytes`: 64 bytes of signature material to validate
|
|
67
|
+
* Returns the same 64 bytes if valid or throws JsError if invalid.
|
|
68
|
+
*/
|
|
69
|
+
export declare function ed25519SignatureFromBytes(bytes: Uint8Array): Uint8Array
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* NAPI-exposed function to validate and copy Ed25519 signing key bytes.
|
|
73
|
+
* - `bytes`: 32 bytes of signing key material to validate
|
|
74
|
+
* Returns the same 32 bytes if valid or throws JsError if invalid.
|
|
75
|
+
*/
|
|
76
|
+
export declare function ed25519SigningKeyFromBytes(bytes: Uint8Array): Uint8Array
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* NAPI-exposed function to sign a message with an Ed25519 signing key.
|
|
80
|
+
* - `signing_key`: 32 bytes of signing key material
|
|
81
|
+
* - `message`: Raw bytes to sign
|
|
82
|
+
* Returns 64 bytes of signature material or throws JsError if signing fails.
|
|
83
|
+
*/
|
|
84
|
+
export declare function ed25519SigningKeySign(signingKey: Uint8Array, message: Uint8Array): Uint8Array
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* NAPI-exposed function to derive the public key from an Ed25519 signing key.
|
|
88
|
+
* - `signing_key`: 32 bytes of signing key material
|
|
89
|
+
* Returns 32 bytes of public key material or throws JsError if key is invalid.
|
|
90
|
+
*/
|
|
91
|
+
export declare function ed25519SigningKeyToPublic(signingKey: Uint8Array): Uint8Array
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* NAPI-exposed function to verify an Ed25519 signature.
|
|
95
|
+
* - `verifying_key`: 32 bytes of verifying key material
|
|
96
|
+
* - `message`: Raw bytes that were signed
|
|
97
|
+
* - `signature`: 64 bytes of signature material
|
|
98
|
+
* Returns true if signature is valid, false otherwise, or throws JsError if verification fails.
|
|
99
|
+
*/
|
|
100
|
+
export declare function ed25519Verify(verifyingKey: Uint8Array, message: Uint8Array, signature: Uint8Array): boolean
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* NAPI-exposed function to derive an Ed25519 verifying key from a signing key.
|
|
104
|
+
* - `signing_key`: 32 bytes of signing key material
|
|
105
|
+
* Returns 32 bytes of verifying key material or throws JsError if key is invalid.
|
|
106
|
+
*/
|
|
107
|
+
export declare function ed25519VerifyingKey(signingKey: Uint8Array): Uint8Array
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* NAPI-exposed function to validate and copy Ed25519 verifying key bytes.
|
|
111
|
+
* - `bytes`: 32 bytes of verifying key material to validate
|
|
112
|
+
* Returns the same 32 bytes if valid or throws JsError if invalid.
|
|
113
|
+
*/
|
|
114
|
+
export declare function ed25519VerifyingKeyFromBytes(bytes: Uint8Array): Uint8Array
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* NAPI-exposed function to encrypt bytes with a key secret and nonce material.
|
|
118
|
+
* - `value`: The raw bytes to encrypt
|
|
119
|
+
* - `key_secret`: A base58-encoded key secret with "keySecret_z" prefix
|
|
120
|
+
* - `nonce_material`: Raw bytes used to generate the nonce
|
|
121
|
+
* Returns the encrypted bytes or throws a JsError if encryption fails.
|
|
122
|
+
*/
|
|
123
|
+
export declare function encrypt(value: Uint8Array, keySecret: string, nonceMaterial: Uint8Array): Uint8Array
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* NAPI-exposed function for XSalsa20 encryption without authentication.
|
|
127
|
+
* - `key`: 32-byte key for encryption
|
|
128
|
+
* - `nonce_material`: Raw bytes used to generate a 24-byte nonce via BLAKE3
|
|
129
|
+
* - `plaintext`: Raw bytes to encrypt
|
|
130
|
+
* Returns the encrypted bytes or throws a JsError if encryption fails.
|
|
131
|
+
* Note: This function does not provide authentication. Use encrypt_xsalsa20_poly1305 for authenticated encryption.
|
|
132
|
+
*/
|
|
133
|
+
export declare function encryptXsalsa20(key: Uint8Array, nonceMaterial: Uint8Array, plaintext: Uint8Array): Uint8Array
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Generate a 24-byte nonce from input material using BLAKE3.
|
|
137
|
+
* - `nonce_material`: Raw bytes to derive the nonce from
|
|
138
|
+
* Returns 24 bytes suitable for use as a nonce in cryptographic operations.
|
|
139
|
+
* This function is deterministic - the same input will produce the same nonce.
|
|
140
|
+
*/
|
|
141
|
+
export declare function generateNonce(nonceMaterial: Uint8Array): Uint8Array
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* NAPI-exposed function to derive a sealer ID from a sealer secret.
|
|
145
|
+
* - `secret`: Raw bytes of the sealer secret
|
|
146
|
+
* Returns a base58-encoded sealer ID with "sealer_z" prefix or throws JsError if derivation fails.
|
|
147
|
+
*/
|
|
148
|
+
export declare function getSealerId(secret: Uint8Array): string
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* NAPI-exposed function to derive a signer ID from a signing key.
|
|
152
|
+
* - `secret`: Raw Ed25519 signing key bytes
|
|
153
|
+
* Returns base58-encoded verifying key with "signer_z" prefix or throws JsError if derivation fails.
|
|
154
|
+
*/
|
|
155
|
+
export declare function getSignerId(secret: Uint8Array): string
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Generate a new Ed25519 signing key using secure random number generation.
|
|
159
|
+
* Returns 32 bytes of raw key material suitable for use with other Ed25519 functions.
|
|
160
|
+
*/
|
|
161
|
+
export declare function newEd25519SigningKey(): Uint8Array
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Generate a new X25519 private key using secure random number generation.
|
|
165
|
+
* Returns 32 bytes of raw key material suitable for use with other X25519 functions.
|
|
166
|
+
* This key can be reused for multiple Diffie-Hellman exchanges.
|
|
167
|
+
*/
|
|
168
|
+
export declare function newX25519PrivateKey(): Uint8Array
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* NAPI-exposed function for sealing a message using X25519 + XSalsa20-Poly1305.
|
|
172
|
+
* Provides authenticated encryption with perfect forward secrecy.
|
|
173
|
+
* - `message`: Raw bytes to seal
|
|
174
|
+
* - `sender_secret`: Base58-encoded sender's private key with "sealerSecret_z" prefix
|
|
175
|
+
* - `recipient_id`: Base58-encoded recipient's public key with "sealer_z" prefix
|
|
176
|
+
* - `nonce_material`: Raw bytes used to generate the nonce
|
|
177
|
+
* Returns sealed bytes or throws JsError if sealing fails.
|
|
178
|
+
*/
|
|
179
|
+
export declare function seal(message: Uint8Array, senderSecret: string, recipientId: string, nonceMaterial: Uint8Array): Uint8Array
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* NAPI-exposed function to sign a message using Ed25519.
|
|
183
|
+
* - `message`: Raw bytes to sign
|
|
184
|
+
* - `secret`: Raw Ed25519 signing key bytes
|
|
185
|
+
* Returns base58-encoded signature with "signature_z" prefix or throws JsError if signing fails.
|
|
186
|
+
*/
|
|
187
|
+
export declare function sign(message: Uint8Array, secret: Uint8Array): string
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* NAPI-exposed function for unsealing a message using X25519 + XSalsa20-Poly1305.
|
|
191
|
+
* Provides authenticated decryption with perfect forward secrecy.
|
|
192
|
+
* - `sealed_message`: The sealed bytes to decrypt
|
|
193
|
+
* - `recipient_secret`: Base58-encoded recipient's private key with "sealerSecret_z" prefix
|
|
194
|
+
* - `sender_id`: Base58-encoded sender's public key with "sealer_z" prefix
|
|
195
|
+
* - `nonce_material`: Raw bytes used to generate the nonce (must match sealing)
|
|
196
|
+
* Returns unsealed bytes or throws JsError if unsealing fails.
|
|
197
|
+
*/
|
|
198
|
+
export declare function unseal(sealedMessage: Uint8Array, recipientSecret: string, senderId: string, nonceMaterial: Uint8Array): Uint8Array
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* NAPI-exposed function to verify an Ed25519 signature.
|
|
202
|
+
* - `signature`: Raw signature bytes
|
|
203
|
+
* - `message`: Raw bytes that were signed
|
|
204
|
+
* - `id`: Raw Ed25519 verifying key bytes
|
|
205
|
+
* Returns true if signature is valid, false otherwise, or throws JsError if verification fails.
|
|
206
|
+
*/
|
|
207
|
+
export declare function verify(signature: Uint8Array, message: Uint8Array, id: Uint8Array): boolean
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* NAPI-exposed function to perform X25519 Diffie-Hellman key exchange.
|
|
211
|
+
* - `private_key`: 32 bytes of private key material
|
|
212
|
+
* - `public_key`: 32 bytes of public key material
|
|
213
|
+
* Returns 32 bytes of shared secret material or throws JsError if key exchange fails.
|
|
214
|
+
*/
|
|
215
|
+
export declare function x25519DiffieHellman(privateKey: Uint8Array, publicKey: Uint8Array): Uint8Array
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* NAPI-exposed function to derive an X25519 public key from a private key.
|
|
219
|
+
* - `private_key`: 32 bytes of private key material
|
|
220
|
+
* Returns 32 bytes of public key material or throws JsError if key is invalid.
|
|
221
|
+
*/
|
|
222
|
+
export declare function x25519PublicKey(privateKey: Uint8Array): Uint8Array
|
package/index.js
ADDED
|
@@ -0,0 +1,586 @@
|
|
|
1
|
+
// prettier-ignore
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* auto-generated by NAPI-RS */
|
|
5
|
+
|
|
6
|
+
const { createRequire } = require('node:module')
|
|
7
|
+
require = createRequire(__filename)
|
|
8
|
+
|
|
9
|
+
const { readFileSync } = require('node:fs')
|
|
10
|
+
let nativeBinding = null
|
|
11
|
+
const loadErrors = []
|
|
12
|
+
|
|
13
|
+
const isMusl = () => {
|
|
14
|
+
let musl = false
|
|
15
|
+
if (process.platform === 'linux') {
|
|
16
|
+
musl = isMuslFromFilesystem()
|
|
17
|
+
if (musl === null) {
|
|
18
|
+
musl = isMuslFromReport()
|
|
19
|
+
}
|
|
20
|
+
if (musl === null) {
|
|
21
|
+
musl = isMuslFromChildProcess()
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return musl
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
|
|
28
|
+
|
|
29
|
+
const isMuslFromFilesystem = () => {
|
|
30
|
+
try {
|
|
31
|
+
return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
|
|
32
|
+
} catch {
|
|
33
|
+
return null
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const isMuslFromReport = () => {
|
|
38
|
+
let report = null
|
|
39
|
+
if (typeof process.report?.getReport === 'function') {
|
|
40
|
+
process.report.excludeNetwork = true
|
|
41
|
+
report = process.report.getReport()
|
|
42
|
+
}
|
|
43
|
+
if (!report) {
|
|
44
|
+
return null
|
|
45
|
+
}
|
|
46
|
+
if (report.header && report.header.glibcVersionRuntime) {
|
|
47
|
+
return false
|
|
48
|
+
}
|
|
49
|
+
if (Array.isArray(report.sharedObjects)) {
|
|
50
|
+
if (report.sharedObjects.some(isFileMusl)) {
|
|
51
|
+
return true
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return false
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const isMuslFromChildProcess = () => {
|
|
58
|
+
try {
|
|
59
|
+
return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
|
|
60
|
+
} catch (e) {
|
|
61
|
+
// If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
|
|
62
|
+
return false
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function requireNative() {
|
|
67
|
+
if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
|
|
68
|
+
try {
|
|
69
|
+
return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
|
|
70
|
+
} catch (err) {
|
|
71
|
+
loadErrors.push(err)
|
|
72
|
+
}
|
|
73
|
+
} else if (process.platform === 'android') {
|
|
74
|
+
if (process.arch === 'arm64') {
|
|
75
|
+
try {
|
|
76
|
+
return require('./cojson-core-napi.android-arm64.node')
|
|
77
|
+
} catch (e) {
|
|
78
|
+
loadErrors.push(e)
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
const binding = require('cojson-core-napi-android-arm64')
|
|
82
|
+
const bindingPackageVersion = require('cojson-core-napi-android-arm64/package.json').version
|
|
83
|
+
if (bindingPackageVersion !== '0.18.22' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
84
|
+
throw new Error(`Native binding package version mismatch, expected 0.18.22 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
85
|
+
}
|
|
86
|
+
return binding
|
|
87
|
+
} catch (e) {
|
|
88
|
+
loadErrors.push(e)
|
|
89
|
+
}
|
|
90
|
+
} else if (process.arch === 'arm') {
|
|
91
|
+
try {
|
|
92
|
+
return require('./cojson-core-napi.android-arm-eabi.node')
|
|
93
|
+
} catch (e) {
|
|
94
|
+
loadErrors.push(e)
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
const binding = require('cojson-core-napi-android-arm-eabi')
|
|
98
|
+
const bindingPackageVersion = require('cojson-core-napi-android-arm-eabi/package.json').version
|
|
99
|
+
if (bindingPackageVersion !== '0.18.22' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
100
|
+
throw new Error(`Native binding package version mismatch, expected 0.18.22 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
101
|
+
}
|
|
102
|
+
return binding
|
|
103
|
+
} catch (e) {
|
|
104
|
+
loadErrors.push(e)
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
|
|
108
|
+
}
|
|
109
|
+
} else if (process.platform === 'win32') {
|
|
110
|
+
if (process.arch === 'x64') {
|
|
111
|
+
try {
|
|
112
|
+
return require('./cojson-core-napi.win32-x64-msvc.node')
|
|
113
|
+
} catch (e) {
|
|
114
|
+
loadErrors.push(e)
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
const binding = require('cojson-core-napi-win32-x64-msvc')
|
|
118
|
+
const bindingPackageVersion = require('cojson-core-napi-win32-x64-msvc/package.json').version
|
|
119
|
+
if (bindingPackageVersion !== '0.18.22' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
120
|
+
throw new Error(`Native binding package version mismatch, expected 0.18.22 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
121
|
+
}
|
|
122
|
+
return binding
|
|
123
|
+
} catch (e) {
|
|
124
|
+
loadErrors.push(e)
|
|
125
|
+
}
|
|
126
|
+
} else if (process.arch === 'ia32') {
|
|
127
|
+
try {
|
|
128
|
+
return require('./cojson-core-napi.win32-ia32-msvc.node')
|
|
129
|
+
} catch (e) {
|
|
130
|
+
loadErrors.push(e)
|
|
131
|
+
}
|
|
132
|
+
try {
|
|
133
|
+
const binding = require('cojson-core-napi-win32-ia32-msvc')
|
|
134
|
+
const bindingPackageVersion = require('cojson-core-napi-win32-ia32-msvc/package.json').version
|
|
135
|
+
if (bindingPackageVersion !== '0.18.22' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
136
|
+
throw new Error(`Native binding package version mismatch, expected 0.18.22 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
137
|
+
}
|
|
138
|
+
return binding
|
|
139
|
+
} catch (e) {
|
|
140
|
+
loadErrors.push(e)
|
|
141
|
+
}
|
|
142
|
+
} else if (process.arch === 'arm64') {
|
|
143
|
+
try {
|
|
144
|
+
return require('./cojson-core-napi.win32-arm64-msvc.node')
|
|
145
|
+
} catch (e) {
|
|
146
|
+
loadErrors.push(e)
|
|
147
|
+
}
|
|
148
|
+
try {
|
|
149
|
+
const binding = require('cojson-core-napi-win32-arm64-msvc')
|
|
150
|
+
const bindingPackageVersion = require('cojson-core-napi-win32-arm64-msvc/package.json').version
|
|
151
|
+
if (bindingPackageVersion !== '0.18.22' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
152
|
+
throw new Error(`Native binding package version mismatch, expected 0.18.22 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
153
|
+
}
|
|
154
|
+
return binding
|
|
155
|
+
} catch (e) {
|
|
156
|
+
loadErrors.push(e)
|
|
157
|
+
}
|
|
158
|
+
} else {
|
|
159
|
+
loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
|
|
160
|
+
}
|
|
161
|
+
} else if (process.platform === 'darwin') {
|
|
162
|
+
try {
|
|
163
|
+
return require('./cojson-core-napi.darwin-universal.node')
|
|
164
|
+
} catch (e) {
|
|
165
|
+
loadErrors.push(e)
|
|
166
|
+
}
|
|
167
|
+
try {
|
|
168
|
+
const binding = require('cojson-core-napi-darwin-universal')
|
|
169
|
+
const bindingPackageVersion = require('cojson-core-napi-darwin-universal/package.json').version
|
|
170
|
+
if (bindingPackageVersion !== '0.18.22' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
171
|
+
throw new Error(`Native binding package version mismatch, expected 0.18.22 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
172
|
+
}
|
|
173
|
+
return binding
|
|
174
|
+
} catch (e) {
|
|
175
|
+
loadErrors.push(e)
|
|
176
|
+
}
|
|
177
|
+
if (process.arch === 'x64') {
|
|
178
|
+
try {
|
|
179
|
+
return require('./cojson-core-napi.darwin-x64.node')
|
|
180
|
+
} catch (e) {
|
|
181
|
+
loadErrors.push(e)
|
|
182
|
+
}
|
|
183
|
+
try {
|
|
184
|
+
const binding = require('cojson-core-napi-darwin-x64')
|
|
185
|
+
const bindingPackageVersion = require('cojson-core-napi-darwin-x64/package.json').version
|
|
186
|
+
if (bindingPackageVersion !== '0.18.22' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
187
|
+
throw new Error(`Native binding package version mismatch, expected 0.18.22 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
188
|
+
}
|
|
189
|
+
return binding
|
|
190
|
+
} catch (e) {
|
|
191
|
+
loadErrors.push(e)
|
|
192
|
+
}
|
|
193
|
+
} else if (process.arch === 'arm64') {
|
|
194
|
+
try {
|
|
195
|
+
return require('./cojson-core-napi.darwin-arm64.node')
|
|
196
|
+
} catch (e) {
|
|
197
|
+
loadErrors.push(e)
|
|
198
|
+
}
|
|
199
|
+
try {
|
|
200
|
+
const binding = require('cojson-core-napi-darwin-arm64')
|
|
201
|
+
const bindingPackageVersion = require('cojson-core-napi-darwin-arm64/package.json').version
|
|
202
|
+
if (bindingPackageVersion !== '0.18.22' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
203
|
+
throw new Error(`Native binding package version mismatch, expected 0.18.22 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
204
|
+
}
|
|
205
|
+
return binding
|
|
206
|
+
} catch (e) {
|
|
207
|
+
loadErrors.push(e)
|
|
208
|
+
}
|
|
209
|
+
} else {
|
|
210
|
+
loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
|
|
211
|
+
}
|
|
212
|
+
} else if (process.platform === 'freebsd') {
|
|
213
|
+
if (process.arch === 'x64') {
|
|
214
|
+
try {
|
|
215
|
+
return require('./cojson-core-napi.freebsd-x64.node')
|
|
216
|
+
} catch (e) {
|
|
217
|
+
loadErrors.push(e)
|
|
218
|
+
}
|
|
219
|
+
try {
|
|
220
|
+
const binding = require('cojson-core-napi-freebsd-x64')
|
|
221
|
+
const bindingPackageVersion = require('cojson-core-napi-freebsd-x64/package.json').version
|
|
222
|
+
if (bindingPackageVersion !== '0.18.22' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
223
|
+
throw new Error(`Native binding package version mismatch, expected 0.18.22 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
224
|
+
}
|
|
225
|
+
return binding
|
|
226
|
+
} catch (e) {
|
|
227
|
+
loadErrors.push(e)
|
|
228
|
+
}
|
|
229
|
+
} else if (process.arch === 'arm64') {
|
|
230
|
+
try {
|
|
231
|
+
return require('./cojson-core-napi.freebsd-arm64.node')
|
|
232
|
+
} catch (e) {
|
|
233
|
+
loadErrors.push(e)
|
|
234
|
+
}
|
|
235
|
+
try {
|
|
236
|
+
const binding = require('cojson-core-napi-freebsd-arm64')
|
|
237
|
+
const bindingPackageVersion = require('cojson-core-napi-freebsd-arm64/package.json').version
|
|
238
|
+
if (bindingPackageVersion !== '0.18.22' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
239
|
+
throw new Error(`Native binding package version mismatch, expected 0.18.22 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
240
|
+
}
|
|
241
|
+
return binding
|
|
242
|
+
} catch (e) {
|
|
243
|
+
loadErrors.push(e)
|
|
244
|
+
}
|
|
245
|
+
} else {
|
|
246
|
+
loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
|
|
247
|
+
}
|
|
248
|
+
} else if (process.platform === 'linux') {
|
|
249
|
+
if (process.arch === 'x64') {
|
|
250
|
+
if (isMusl()) {
|
|
251
|
+
try {
|
|
252
|
+
return require('./cojson-core-napi.linux-x64-musl.node')
|
|
253
|
+
} catch (e) {
|
|
254
|
+
loadErrors.push(e)
|
|
255
|
+
}
|
|
256
|
+
try {
|
|
257
|
+
const binding = require('cojson-core-napi-linux-x64-musl')
|
|
258
|
+
const bindingPackageVersion = require('cojson-core-napi-linux-x64-musl/package.json').version
|
|
259
|
+
if (bindingPackageVersion !== '0.18.22' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
260
|
+
throw new Error(`Native binding package version mismatch, expected 0.18.22 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
261
|
+
}
|
|
262
|
+
return binding
|
|
263
|
+
} catch (e) {
|
|
264
|
+
loadErrors.push(e)
|
|
265
|
+
}
|
|
266
|
+
} else {
|
|
267
|
+
try {
|
|
268
|
+
return require('./cojson-core-napi.linux-x64-gnu.node')
|
|
269
|
+
} catch (e) {
|
|
270
|
+
loadErrors.push(e)
|
|
271
|
+
}
|
|
272
|
+
try {
|
|
273
|
+
const binding = require('cojson-core-napi-linux-x64-gnu')
|
|
274
|
+
const bindingPackageVersion = require('cojson-core-napi-linux-x64-gnu/package.json').version
|
|
275
|
+
if (bindingPackageVersion !== '0.18.22' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
276
|
+
throw new Error(`Native binding package version mismatch, expected 0.18.22 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
277
|
+
}
|
|
278
|
+
return binding
|
|
279
|
+
} catch (e) {
|
|
280
|
+
loadErrors.push(e)
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
} else if (process.arch === 'arm64') {
|
|
284
|
+
if (isMusl()) {
|
|
285
|
+
try {
|
|
286
|
+
return require('./cojson-core-napi.linux-arm64-musl.node')
|
|
287
|
+
} catch (e) {
|
|
288
|
+
loadErrors.push(e)
|
|
289
|
+
}
|
|
290
|
+
try {
|
|
291
|
+
const binding = require('cojson-core-napi-linux-arm64-musl')
|
|
292
|
+
const bindingPackageVersion = require('cojson-core-napi-linux-arm64-musl/package.json').version
|
|
293
|
+
if (bindingPackageVersion !== '0.18.22' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
294
|
+
throw new Error(`Native binding package version mismatch, expected 0.18.22 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
295
|
+
}
|
|
296
|
+
return binding
|
|
297
|
+
} catch (e) {
|
|
298
|
+
loadErrors.push(e)
|
|
299
|
+
}
|
|
300
|
+
} else {
|
|
301
|
+
try {
|
|
302
|
+
return require('./cojson-core-napi.linux-arm64-gnu.node')
|
|
303
|
+
} catch (e) {
|
|
304
|
+
loadErrors.push(e)
|
|
305
|
+
}
|
|
306
|
+
try {
|
|
307
|
+
const binding = require('cojson-core-napi-linux-arm64-gnu')
|
|
308
|
+
const bindingPackageVersion = require('cojson-core-napi-linux-arm64-gnu/package.json').version
|
|
309
|
+
if (bindingPackageVersion !== '0.18.22' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
310
|
+
throw new Error(`Native binding package version mismatch, expected 0.18.22 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
311
|
+
}
|
|
312
|
+
return binding
|
|
313
|
+
} catch (e) {
|
|
314
|
+
loadErrors.push(e)
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
} else if (process.arch === 'arm') {
|
|
318
|
+
if (isMusl()) {
|
|
319
|
+
try {
|
|
320
|
+
return require('./cojson-core-napi.linux-arm-musleabihf.node')
|
|
321
|
+
} catch (e) {
|
|
322
|
+
loadErrors.push(e)
|
|
323
|
+
}
|
|
324
|
+
try {
|
|
325
|
+
const binding = require('cojson-core-napi-linux-arm-musleabihf')
|
|
326
|
+
const bindingPackageVersion = require('cojson-core-napi-linux-arm-musleabihf/package.json').version
|
|
327
|
+
if (bindingPackageVersion !== '0.18.22' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
328
|
+
throw new Error(`Native binding package version mismatch, expected 0.18.22 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
329
|
+
}
|
|
330
|
+
return binding
|
|
331
|
+
} catch (e) {
|
|
332
|
+
loadErrors.push(e)
|
|
333
|
+
}
|
|
334
|
+
} else {
|
|
335
|
+
try {
|
|
336
|
+
return require('./cojson-core-napi.linux-arm-gnueabihf.node')
|
|
337
|
+
} catch (e) {
|
|
338
|
+
loadErrors.push(e)
|
|
339
|
+
}
|
|
340
|
+
try {
|
|
341
|
+
const binding = require('cojson-core-napi-linux-arm-gnueabihf')
|
|
342
|
+
const bindingPackageVersion = require('cojson-core-napi-linux-arm-gnueabihf/package.json').version
|
|
343
|
+
if (bindingPackageVersion !== '0.18.22' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
344
|
+
throw new Error(`Native binding package version mismatch, expected 0.18.22 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
345
|
+
}
|
|
346
|
+
return binding
|
|
347
|
+
} catch (e) {
|
|
348
|
+
loadErrors.push(e)
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
} else if (process.arch === 'loong64') {
|
|
352
|
+
if (isMusl()) {
|
|
353
|
+
try {
|
|
354
|
+
return require('./cojson-core-napi.linux-loong64-musl.node')
|
|
355
|
+
} catch (e) {
|
|
356
|
+
loadErrors.push(e)
|
|
357
|
+
}
|
|
358
|
+
try {
|
|
359
|
+
const binding = require('cojson-core-napi-linux-loong64-musl')
|
|
360
|
+
const bindingPackageVersion = require('cojson-core-napi-linux-loong64-musl/package.json').version
|
|
361
|
+
if (bindingPackageVersion !== '0.18.22' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
362
|
+
throw new Error(`Native binding package version mismatch, expected 0.18.22 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
363
|
+
}
|
|
364
|
+
return binding
|
|
365
|
+
} catch (e) {
|
|
366
|
+
loadErrors.push(e)
|
|
367
|
+
}
|
|
368
|
+
} else {
|
|
369
|
+
try {
|
|
370
|
+
return require('./cojson-core-napi.linux-loong64-gnu.node')
|
|
371
|
+
} catch (e) {
|
|
372
|
+
loadErrors.push(e)
|
|
373
|
+
}
|
|
374
|
+
try {
|
|
375
|
+
const binding = require('cojson-core-napi-linux-loong64-gnu')
|
|
376
|
+
const bindingPackageVersion = require('cojson-core-napi-linux-loong64-gnu/package.json').version
|
|
377
|
+
if (bindingPackageVersion !== '0.18.22' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
378
|
+
throw new Error(`Native binding package version mismatch, expected 0.18.22 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
379
|
+
}
|
|
380
|
+
return binding
|
|
381
|
+
} catch (e) {
|
|
382
|
+
loadErrors.push(e)
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
} else if (process.arch === 'riscv64') {
|
|
386
|
+
if (isMusl()) {
|
|
387
|
+
try {
|
|
388
|
+
return require('./cojson-core-napi.linux-riscv64-musl.node')
|
|
389
|
+
} catch (e) {
|
|
390
|
+
loadErrors.push(e)
|
|
391
|
+
}
|
|
392
|
+
try {
|
|
393
|
+
const binding = require('cojson-core-napi-linux-riscv64-musl')
|
|
394
|
+
const bindingPackageVersion = require('cojson-core-napi-linux-riscv64-musl/package.json').version
|
|
395
|
+
if (bindingPackageVersion !== '0.18.22' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
396
|
+
throw new Error(`Native binding package version mismatch, expected 0.18.22 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
397
|
+
}
|
|
398
|
+
return binding
|
|
399
|
+
} catch (e) {
|
|
400
|
+
loadErrors.push(e)
|
|
401
|
+
}
|
|
402
|
+
} else {
|
|
403
|
+
try {
|
|
404
|
+
return require('./cojson-core-napi.linux-riscv64-gnu.node')
|
|
405
|
+
} catch (e) {
|
|
406
|
+
loadErrors.push(e)
|
|
407
|
+
}
|
|
408
|
+
try {
|
|
409
|
+
const binding = require('cojson-core-napi-linux-riscv64-gnu')
|
|
410
|
+
const bindingPackageVersion = require('cojson-core-napi-linux-riscv64-gnu/package.json').version
|
|
411
|
+
if (bindingPackageVersion !== '0.18.22' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
412
|
+
throw new Error(`Native binding package version mismatch, expected 0.18.22 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
413
|
+
}
|
|
414
|
+
return binding
|
|
415
|
+
} catch (e) {
|
|
416
|
+
loadErrors.push(e)
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
} else if (process.arch === 'ppc64') {
|
|
420
|
+
try {
|
|
421
|
+
return require('./cojson-core-napi.linux-ppc64-gnu.node')
|
|
422
|
+
} catch (e) {
|
|
423
|
+
loadErrors.push(e)
|
|
424
|
+
}
|
|
425
|
+
try {
|
|
426
|
+
const binding = require('cojson-core-napi-linux-ppc64-gnu')
|
|
427
|
+
const bindingPackageVersion = require('cojson-core-napi-linux-ppc64-gnu/package.json').version
|
|
428
|
+
if (bindingPackageVersion !== '0.18.22' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
429
|
+
throw new Error(`Native binding package version mismatch, expected 0.18.22 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
430
|
+
}
|
|
431
|
+
return binding
|
|
432
|
+
} catch (e) {
|
|
433
|
+
loadErrors.push(e)
|
|
434
|
+
}
|
|
435
|
+
} else if (process.arch === 's390x') {
|
|
436
|
+
try {
|
|
437
|
+
return require('./cojson-core-napi.linux-s390x-gnu.node')
|
|
438
|
+
} catch (e) {
|
|
439
|
+
loadErrors.push(e)
|
|
440
|
+
}
|
|
441
|
+
try {
|
|
442
|
+
const binding = require('cojson-core-napi-linux-s390x-gnu')
|
|
443
|
+
const bindingPackageVersion = require('cojson-core-napi-linux-s390x-gnu/package.json').version
|
|
444
|
+
if (bindingPackageVersion !== '0.18.22' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
445
|
+
throw new Error(`Native binding package version mismatch, expected 0.18.22 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
446
|
+
}
|
|
447
|
+
return binding
|
|
448
|
+
} catch (e) {
|
|
449
|
+
loadErrors.push(e)
|
|
450
|
+
}
|
|
451
|
+
} else {
|
|
452
|
+
loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
|
|
453
|
+
}
|
|
454
|
+
} else if (process.platform === 'openharmony') {
|
|
455
|
+
if (process.arch === 'arm64') {
|
|
456
|
+
try {
|
|
457
|
+
return require('./cojson-core-napi.openharmony-arm64.node')
|
|
458
|
+
} catch (e) {
|
|
459
|
+
loadErrors.push(e)
|
|
460
|
+
}
|
|
461
|
+
try {
|
|
462
|
+
const binding = require('cojson-core-napi-openharmony-arm64')
|
|
463
|
+
const bindingPackageVersion = require('cojson-core-napi-openharmony-arm64/package.json').version
|
|
464
|
+
if (bindingPackageVersion !== '0.18.22' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
465
|
+
throw new Error(`Native binding package version mismatch, expected 0.18.22 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
466
|
+
}
|
|
467
|
+
return binding
|
|
468
|
+
} catch (e) {
|
|
469
|
+
loadErrors.push(e)
|
|
470
|
+
}
|
|
471
|
+
} else if (process.arch === 'x64') {
|
|
472
|
+
try {
|
|
473
|
+
return require('./cojson-core-napi.openharmony-x64.node')
|
|
474
|
+
} catch (e) {
|
|
475
|
+
loadErrors.push(e)
|
|
476
|
+
}
|
|
477
|
+
try {
|
|
478
|
+
const binding = require('cojson-core-napi-openharmony-x64')
|
|
479
|
+
const bindingPackageVersion = require('cojson-core-napi-openharmony-x64/package.json').version
|
|
480
|
+
if (bindingPackageVersion !== '0.18.22' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
481
|
+
throw new Error(`Native binding package version mismatch, expected 0.18.22 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
482
|
+
}
|
|
483
|
+
return binding
|
|
484
|
+
} catch (e) {
|
|
485
|
+
loadErrors.push(e)
|
|
486
|
+
}
|
|
487
|
+
} else if (process.arch === 'arm') {
|
|
488
|
+
try {
|
|
489
|
+
return require('./cojson-core-napi.openharmony-arm.node')
|
|
490
|
+
} catch (e) {
|
|
491
|
+
loadErrors.push(e)
|
|
492
|
+
}
|
|
493
|
+
try {
|
|
494
|
+
const binding = require('cojson-core-napi-openharmony-arm')
|
|
495
|
+
const bindingPackageVersion = require('cojson-core-napi-openharmony-arm/package.json').version
|
|
496
|
+
if (bindingPackageVersion !== '0.18.22' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
497
|
+
throw new Error(`Native binding package version mismatch, expected 0.18.22 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
498
|
+
}
|
|
499
|
+
return binding
|
|
500
|
+
} catch (e) {
|
|
501
|
+
loadErrors.push(e)
|
|
502
|
+
}
|
|
503
|
+
} else {
|
|
504
|
+
loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`))
|
|
505
|
+
}
|
|
506
|
+
} else {
|
|
507
|
+
loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
nativeBinding = requireNative()
|
|
512
|
+
|
|
513
|
+
if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
|
|
514
|
+
let wasiBinding = null
|
|
515
|
+
let wasiBindingError = null
|
|
516
|
+
try {
|
|
517
|
+
wasiBinding = require('./cojson-core-napi.wasi.cjs')
|
|
518
|
+
nativeBinding = wasiBinding
|
|
519
|
+
} catch (err) {
|
|
520
|
+
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
521
|
+
wasiBindingError = err
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
if (!nativeBinding) {
|
|
525
|
+
try {
|
|
526
|
+
wasiBinding = require('cojson-core-napi-wasm32-wasi')
|
|
527
|
+
nativeBinding = wasiBinding
|
|
528
|
+
} catch (err) {
|
|
529
|
+
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
530
|
+
wasiBindingError.cause = err
|
|
531
|
+
loadErrors.push(err)
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
if (process.env.NAPI_RS_FORCE_WASI === 'error' && !wasiBinding) {
|
|
536
|
+
const error = new Error('WASI binding not found and NAPI_RS_FORCE_WASI is set to error')
|
|
537
|
+
error.cause = wasiBindingError
|
|
538
|
+
throw error
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
if (!nativeBinding) {
|
|
543
|
+
if (loadErrors.length > 0) {
|
|
544
|
+
throw new Error(
|
|
545
|
+
`Cannot find native binding. ` +
|
|
546
|
+
`npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
|
|
547
|
+
'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
|
|
548
|
+
{
|
|
549
|
+
cause: loadErrors.reduce((err, cur) => {
|
|
550
|
+
cur.cause = err
|
|
551
|
+
return cur
|
|
552
|
+
}),
|
|
553
|
+
},
|
|
554
|
+
)
|
|
555
|
+
}
|
|
556
|
+
throw new Error(`Failed to load native binding`)
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
module.exports = nativeBinding
|
|
560
|
+
module.exports.Blake3Hasher = nativeBinding.Blake3Hasher
|
|
561
|
+
module.exports.SessionLog = nativeBinding.SessionLog
|
|
562
|
+
module.exports.blake3HashOnce = nativeBinding.blake3HashOnce
|
|
563
|
+
module.exports.blake3HashOnceWithContext = nativeBinding.blake3HashOnceWithContext
|
|
564
|
+
module.exports.decrypt = nativeBinding.decrypt
|
|
565
|
+
module.exports.decryptXsalsa20 = nativeBinding.decryptXsalsa20
|
|
566
|
+
module.exports.ed25519Sign = nativeBinding.ed25519Sign
|
|
567
|
+
module.exports.ed25519SignatureFromBytes = nativeBinding.ed25519SignatureFromBytes
|
|
568
|
+
module.exports.ed25519SigningKeyFromBytes = nativeBinding.ed25519SigningKeyFromBytes
|
|
569
|
+
module.exports.ed25519SigningKeySign = nativeBinding.ed25519SigningKeySign
|
|
570
|
+
module.exports.ed25519SigningKeyToPublic = nativeBinding.ed25519SigningKeyToPublic
|
|
571
|
+
module.exports.ed25519Verify = nativeBinding.ed25519Verify
|
|
572
|
+
module.exports.ed25519VerifyingKey = nativeBinding.ed25519VerifyingKey
|
|
573
|
+
module.exports.ed25519VerifyingKeyFromBytes = nativeBinding.ed25519VerifyingKeyFromBytes
|
|
574
|
+
module.exports.encrypt = nativeBinding.encrypt
|
|
575
|
+
module.exports.encryptXsalsa20 = nativeBinding.encryptXsalsa20
|
|
576
|
+
module.exports.generateNonce = nativeBinding.generateNonce
|
|
577
|
+
module.exports.getSealerId = nativeBinding.getSealerId
|
|
578
|
+
module.exports.getSignerId = nativeBinding.getSignerId
|
|
579
|
+
module.exports.newEd25519SigningKey = nativeBinding.newEd25519SigningKey
|
|
580
|
+
module.exports.newX25519PrivateKey = nativeBinding.newX25519PrivateKey
|
|
581
|
+
module.exports.seal = nativeBinding.seal
|
|
582
|
+
module.exports.sign = nativeBinding.sign
|
|
583
|
+
module.exports.unseal = nativeBinding.unseal
|
|
584
|
+
module.exports.verify = nativeBinding.verify
|
|
585
|
+
module.exports.x25519DiffieHellman = nativeBinding.x25519DiffieHellman
|
|
586
|
+
module.exports.x25519PublicKey = nativeBinding.x25519PublicKey
|
package/package.json
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "cojson-core-napi",
|
|
3
|
+
"version": "0.18.22",
|
|
4
|
+
"description": "Node.js N-API bindings for the cojson-core Rust library, providing high-performance.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"napi-rs",
|
|
9
|
+
"NAPI",
|
|
10
|
+
"N-API",
|
|
11
|
+
"Rust",
|
|
12
|
+
"node-addon",
|
|
13
|
+
"node-addon-api"
|
|
14
|
+
],
|
|
15
|
+
"files": [
|
|
16
|
+
"index.d.ts",
|
|
17
|
+
"index.js"
|
|
18
|
+
],
|
|
19
|
+
"napi": {
|
|
20
|
+
"binaryName": "cojson-core-napi",
|
|
21
|
+
"packageName": "cojson-core-napi",
|
|
22
|
+
"targets": [
|
|
23
|
+
"x86_64-apple-darwin",
|
|
24
|
+
"x86_64-unknown-linux-gnu",
|
|
25
|
+
"x86_64-unknown-linux-musl",
|
|
26
|
+
"aarch64-unknown-linux-gnu",
|
|
27
|
+
"armv7-unknown-linux-gnueabihf",
|
|
28
|
+
"aarch64-apple-darwin",
|
|
29
|
+
"aarch64-unknown-linux-musl"
|
|
30
|
+
]
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">= 12.22.0 < 13 || >= 14.17.0 < 15 || >= 15.12.0 < 16 || >= 16.0.0"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"registry": "https://registry.npmjs.org/",
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@emnapi/core": "^1.5.0",
|
|
41
|
+
"@emnapi/runtime": "^1.5.0",
|
|
42
|
+
"@napi-rs/cli": "^3.2.0",
|
|
43
|
+
"@oxc-node/core": "^0.0.32",
|
|
44
|
+
"@scure/base": "1.2.1",
|
|
45
|
+
"@taplo/cli": "^0.7.0",
|
|
46
|
+
"@tybys/wasm-util": "^0.10.0",
|
|
47
|
+
"chalk": "^5.6.2",
|
|
48
|
+
"husky": "^9.1.7",
|
|
49
|
+
"lint-staged": "^16.1.6",
|
|
50
|
+
"npm-run-all2": "^8.0.4",
|
|
51
|
+
"oxlint": "^1.14.0",
|
|
52
|
+
"prettier": "^3.6.2",
|
|
53
|
+
"tinybench": "^5.0.1",
|
|
54
|
+
"typescript": "^5.9.2",
|
|
55
|
+
"vitest": "3.2.4"
|
|
56
|
+
},
|
|
57
|
+
"lint-staged": {
|
|
58
|
+
"*.@(js|ts|tsx)": [
|
|
59
|
+
"oxlint --fix"
|
|
60
|
+
],
|
|
61
|
+
"*.@(js|ts|tsx|yml|yaml|md|json)": [
|
|
62
|
+
"prettier --write"
|
|
63
|
+
],
|
|
64
|
+
"*.toml": [
|
|
65
|
+
"taplo format"
|
|
66
|
+
]
|
|
67
|
+
},
|
|
68
|
+
"ava": {
|
|
69
|
+
"extensions": {
|
|
70
|
+
"ts": "module"
|
|
71
|
+
},
|
|
72
|
+
"timeout": "2m",
|
|
73
|
+
"workerThreads": false,
|
|
74
|
+
"environmentVariables": {
|
|
75
|
+
"OXC_TSCONFIG_PATH": "./__test__/tsconfig.json"
|
|
76
|
+
},
|
|
77
|
+
"nodeArguments": [
|
|
78
|
+
"--import",
|
|
79
|
+
"@oxc-node/core/register"
|
|
80
|
+
]
|
|
81
|
+
},
|
|
82
|
+
"prettier": {
|
|
83
|
+
"printWidth": 120,
|
|
84
|
+
"semi": false,
|
|
85
|
+
"trailingComma": "all",
|
|
86
|
+
"singleQuote": true,
|
|
87
|
+
"arrowParens": "always"
|
|
88
|
+
},
|
|
89
|
+
"optionalDependencies": {
|
|
90
|
+
"cojson-core-napi-darwin-x64": "0.18.22",
|
|
91
|
+
"cojson-core-napi-linux-x64-gnu": "0.18.22",
|
|
92
|
+
"cojson-core-napi-linux-x64-musl": "0.18.22",
|
|
93
|
+
"cojson-core-napi-linux-arm64-gnu": "0.18.22",
|
|
94
|
+
"cojson-core-napi-linux-arm-gnueabihf": "0.18.22",
|
|
95
|
+
"cojson-core-napi-darwin-arm64": "0.18.22",
|
|
96
|
+
"cojson-core-napi-linux-arm64-musl": "0.18.22"
|
|
97
|
+
},
|
|
98
|
+
"scripts": {
|
|
99
|
+
"artifacts": "napi artifacts",
|
|
100
|
+
"build:napi": "napi build --platform --release",
|
|
101
|
+
"build:jsBinding": "napi build --platform --release && node --import @oxc-node/core/register scripts/build.ts",
|
|
102
|
+
"build:debug": "napi build --platform",
|
|
103
|
+
"format": "run-p format:prettier format:rs format:toml",
|
|
104
|
+
"format:prettier": "prettier . -w",
|
|
105
|
+
"format:toml": "taplo format",
|
|
106
|
+
"format:rs": "cargo fmt",
|
|
107
|
+
"lint": "oxlint . && cargo fmt -- --check",
|
|
108
|
+
"generate:npm": "napi create-npm-dirs",
|
|
109
|
+
"test": "vitest --watch --project cojson-core-napi",
|
|
110
|
+
"test:ci": "vitest run --watch=false",
|
|
111
|
+
"preversion": "napi build --platform && git add .",
|
|
112
|
+
"version": "napi version"
|
|
113
|
+
}
|
|
114
|
+
}
|