libsodium-wrappers 0.8.2 → 0.8.3

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/README.md CHANGED
@@ -73,8 +73,8 @@ await sodium.ready;
73
73
 
74
74
  let key = sodium.crypto_secretstream_xchacha20poly1305_keygen();
75
75
 
76
- let res = sodium.crypto_secretstream_xchacha20poly1305_init_push(key);
77
- let [state_out, header] = [res.state, res.header];
76
+ let { state: state_out, header } =
77
+ sodium.crypto_secretstream_xchacha20poly1305_init_push(key);
78
78
  let c1 = sodium.crypto_secretstream_xchacha20poly1305_push(state_out,
79
79
  sodium.from_string('message 1'), null,
80
80
  sodium.crypto_secretstream_xchacha20poly1305_TAG_MESSAGE);
@@ -84,9 +84,11 @@ let c2 = sodium.crypto_secretstream_xchacha20poly1305_push(state_out,
84
84
 
85
85
  let state_in = sodium.crypto_secretstream_xchacha20poly1305_init_pull(header, key);
86
86
  let r1 = sodium.crypto_secretstream_xchacha20poly1305_pull(state_in, c1);
87
- let [m1, tag1] = [sodium.to_string(r1.message), r1.tag];
87
+ let { message: m1_bytes, tag: tag1 } = r1;
88
+ let m1 = sodium.to_string(m1_bytes);
88
89
  let r2 = sodium.crypto_secretstream_xchacha20poly1305_pull(state_in, c2);
89
- let [m2, tag2] = [sodium.to_string(r2.message), r2.tag];
90
+ let { message: m2_bytes, tag: tag2 } = r2;
91
+ let m2 = sodium.to_string(m2_bytes);
90
92
 
91
93
  console.log(m1);
92
94
  console.log(m2);
@@ -219,6 +221,13 @@ returns the following object:
219
221
  { publicKey: (Uint8Array), privateKey: (Uint8Array), keyType: 'x25519' }
220
222
  ```
221
223
 
224
+ This also applies to newer APIs such as:
225
+ ```javascript
226
+ { state: (StateAddress), header: (Uint8Array) }
227
+ { ciphertext: (Uint8Array), sharedSecret: (Uint8Array) }
228
+ ```
229
+ for `crypto_secretstream_xchacha20poly1305_init_push()` and `crypto_kem_enc()`.
230
+
222
231
  ### Standard vs Sumo version
223
232
 
224
233
  The standard version (in the `dist/browsers`, `dist/modules`, and
@@ -247,9 +256,10 @@ need to be installed on your system:
247
256
  * bun
248
257
  * make
249
258
 
250
- Running `make` will install the dev dependencies, clone libsodium,
251
- build it, test it, build the wrapper, and create the modules and
252
- minified distribution files.
259
+ Running `make` will install the dev dependencies if needed, build the
260
+ standard and sumo distributions, regenerate API docs and TypeScript
261
+ bindings, pack the generated outputs, and rebuild the browser test
262
+ artifacts.
253
263
 
254
264
  ### Benchmarks
255
265
 
@@ -161,6 +161,8 @@ export const crypto_generichash_blake2b_PERSONALBYTES: number;
161
161
  export const crypto_generichash_blake2b_SALTBYTES: number;
162
162
  export const crypto_hash_BYTES: number;
163
163
  export const crypto_hash_sha256_BYTES: number;
164
+ export const crypto_hash_sha3256_BYTES: number;
165
+ export const crypto_hash_sha3512_BYTES: number;
164
166
  export const crypto_hash_sha512_BYTES: number;
165
167
  export const crypto_ipcrypt_BYTES: number;
166
168
  export const crypto_ipcrypt_KEYBYTES: number;
@@ -188,6 +190,22 @@ export const crypto_kdf_hkdf_sha256_KEYBYTES: number;
188
190
  export const crypto_kdf_hkdf_sha512_BYTES_MAX: number;
189
191
  export const crypto_kdf_hkdf_sha512_BYTES_MIN: number;
190
192
  export const crypto_kdf_hkdf_sha512_KEYBYTES: number;
193
+ export const crypto_kem_CIPHERTEXTBYTES: number;
194
+ export const crypto_kem_PRIMITIVE: string;
195
+ export const crypto_kem_PUBLICKEYBYTES: number;
196
+ export const crypto_kem_SECRETKEYBYTES: number;
197
+ export const crypto_kem_SEEDBYTES: number;
198
+ export const crypto_kem_SHAREDSECRETBYTES: number;
199
+ export const crypto_kem_mlkem768_CIPHERTEXTBYTES: number;
200
+ export const crypto_kem_mlkem768_PUBLICKEYBYTES: number;
201
+ export const crypto_kem_mlkem768_SECRETKEYBYTES: number;
202
+ export const crypto_kem_mlkem768_SEEDBYTES: number;
203
+ export const crypto_kem_mlkem768_SHAREDSECRETBYTES: number;
204
+ export const crypto_kem_xwing_CIPHERTEXTBYTES: number;
205
+ export const crypto_kem_xwing_PUBLICKEYBYTES: number;
206
+ export const crypto_kem_xwing_SECRETKEYBYTES: number;
207
+ export const crypto_kem_xwing_SEEDBYTES: number;
208
+ export const crypto_kem_xwing_SHAREDSECRETBYTES: number;
191
209
  export const crypto_kx_PUBLICKEYBYTES: number;
192
210
  export const crypto_kx_SECRETKEYBYTES: number;
193
211
  export const crypto_kx_SEEDBYTES: number;
@@ -1235,6 +1253,52 @@ export function crypto_hash_sha256_init(): StateAddress;
1235
1253
  * @param message_chunk
1236
1254
  */
1237
1255
  export function crypto_hash_sha256_update(state_address: StateAddress, message_chunk: Uint8Array | string): void;
1256
+ /**
1257
+ * @param message
1258
+ * @param outputFormat Output format (default: Uint8Array)
1259
+ * @returns Uint8Array | string (CRYPTO_HASH_SHA3256_BYTES bytes)
1260
+ */
1261
+ export function crypto_hash_sha3256(message: Uint8Array | string, outputFormat?: Uint8ArrayOutputFormat | null): Uint8Array;
1262
+ export function crypto_hash_sha3256(message: Uint8Array | string, outputFormat: StringOutputFormat): string;
1263
+ /**
1264
+ * @param state_address
1265
+ * @param outputFormat Output format (default: Uint8Array)
1266
+ * @returns Uint8Array | string (CRYPTO_HASH_SHA3256_BYTES bytes)
1267
+ */
1268
+ export function crypto_hash_sha3256_final(state_address: StateAddress, outputFormat?: Uint8ArrayOutputFormat | null): Uint8Array;
1269
+ export function crypto_hash_sha3256_final(state_address: StateAddress, outputFormat: StringOutputFormat): string;
1270
+ /**
1271
+ * @returns StateAddress
1272
+ */
1273
+ export function crypto_hash_sha3256_init(): StateAddress;
1274
+ /**
1275
+ * @param state_address
1276
+ * @param message_chunk
1277
+ */
1278
+ export function crypto_hash_sha3256_update(state_address: StateAddress, message_chunk: Uint8Array | string): void;
1279
+ /**
1280
+ * @param message
1281
+ * @param outputFormat Output format (default: Uint8Array)
1282
+ * @returns Uint8Array | string (CRYPTO_HASH_SHA3512_BYTES bytes)
1283
+ */
1284
+ export function crypto_hash_sha3512(message: Uint8Array | string, outputFormat?: Uint8ArrayOutputFormat | null): Uint8Array;
1285
+ export function crypto_hash_sha3512(message: Uint8Array | string, outputFormat: StringOutputFormat): string;
1286
+ /**
1287
+ * @param state_address
1288
+ * @param outputFormat Output format (default: Uint8Array)
1289
+ * @returns Uint8Array | string (CRYPTO_HASH_SHA3512_BYTES bytes)
1290
+ */
1291
+ export function crypto_hash_sha3512_final(state_address: StateAddress, outputFormat?: Uint8ArrayOutputFormat | null): Uint8Array;
1292
+ export function crypto_hash_sha3512_final(state_address: StateAddress, outputFormat: StringOutputFormat): string;
1293
+ /**
1294
+ * @returns StateAddress
1295
+ */
1296
+ export function crypto_hash_sha3512_init(): StateAddress;
1297
+ /**
1298
+ * @param state_address
1299
+ * @param message_chunk
1300
+ */
1301
+ export function crypto_hash_sha3512_update(state_address: StateAddress, message_chunk: Uint8Array | string): void;
1238
1302
  /**
1239
1303
  * @param message
1240
1304
  * @param outputFormat Output format (default: Uint8Array)
@@ -1364,6 +1428,110 @@ export function crypto_kdf_derive_from_key(subkey_len: number, subkey_id: number
1364
1428
  */
1365
1429
  export function crypto_kdf_keygen(outputFormat?: Uint8ArrayOutputFormat | null): Uint8Array;
1366
1430
  export function crypto_kdf_keygen(outputFormat: StringOutputFormat): string;
1431
+ /**
1432
+ * @param ciphertext (CRYPTO_KEM_CIPHERTEXTBYTES bytes)
1433
+ * @param privateKey (CRYPTO_KEM_SECRETKEYBYTES bytes)
1434
+ * @param outputFormat Output format (default: Uint8Array)
1435
+ * @returns Uint8Array | string (CRYPTO_KEM_SHAREDSECRETBYTES bytes)
1436
+ */
1437
+ export function crypto_kem_dec(ciphertext: Uint8Array, privateKey: Uint8Array, outputFormat?: Uint8ArrayOutputFormat | null): Uint8Array;
1438
+ export function crypto_kem_dec(ciphertext: Uint8Array, privateKey: Uint8Array, outputFormat: StringOutputFormat): string;
1439
+ /**
1440
+ * @param publicKey (CRYPTO_KEM_PUBLICKEYBYTES bytes)
1441
+ * @param outputFormat Output format (default: Uint8Array)
1442
+ * @returns {ciphertext, sharedSecret} (CRYPTO_KEM_CIPHERTEXTBYTES bytes)
1443
+ */
1444
+ export function crypto_kem_enc(publicKey: Uint8Array, outputFormat?: Uint8ArrayOutputFormat | null): { ciphertext: Uint8Array; sharedSecret: Uint8Array };
1445
+ export function crypto_kem_enc(publicKey: Uint8Array, outputFormat: StringOutputFormat): { ciphertext: string; sharedSecret: string };
1446
+ /**
1447
+ * @param outputFormat Output format (default: Uint8Array)
1448
+ * @returns {publicKey, privateKey, keyType} (CRYPTO_KEM_PUBLICKEYBYTES bytes)
1449
+ */
1450
+ export function crypto_kem_keypair(outputFormat?: Uint8ArrayOutputFormat | null): { publicKey: Uint8Array; privateKey: Uint8Array; keyType: string };
1451
+ export function crypto_kem_keypair(outputFormat: StringOutputFormat): { publicKey: string; privateKey: string; keyType: string };
1452
+ /**
1453
+ * @param ciphertext (CRYPTO_KEM_MLKEM768_CIPHERTEXTBYTES bytes)
1454
+ * @param privateKey (CRYPTO_KEM_MLKEM768_SECRETKEYBYTES bytes)
1455
+ * @param outputFormat Output format (default: Uint8Array)
1456
+ * @returns Uint8Array | string (CRYPTO_KEM_MLKEM768_SHAREDSECRETBYTES bytes)
1457
+ */
1458
+ export function crypto_kem_mlkem768_dec(ciphertext: Uint8Array, privateKey: Uint8Array, outputFormat?: Uint8ArrayOutputFormat | null): Uint8Array;
1459
+ export function crypto_kem_mlkem768_dec(ciphertext: Uint8Array, privateKey: Uint8Array, outputFormat: StringOutputFormat): string;
1460
+ /**
1461
+ * @param publicKey (CRYPTO_KEM_MLKEM768_PUBLICKEYBYTES bytes)
1462
+ * @param outputFormat Output format (default: Uint8Array)
1463
+ * @returns {ciphertext, sharedSecret} (CRYPTO_KEM_MLKEM768_CIPHERTEXTBYTES bytes)
1464
+ */
1465
+ export function crypto_kem_mlkem768_enc(publicKey: Uint8Array, outputFormat?: Uint8ArrayOutputFormat | null): { ciphertext: Uint8Array; sharedSecret: Uint8Array };
1466
+ export function crypto_kem_mlkem768_enc(publicKey: Uint8Array, outputFormat: StringOutputFormat): { ciphertext: string; sharedSecret: string };
1467
+ /**
1468
+ * @param publicKey (CRYPTO_KEM_MLKEM768_PUBLICKEYBYTES bytes)
1469
+ * @param seed
1470
+ * @param outputFormat Output format (default: Uint8Array)
1471
+ * @returns {ciphertext, sharedSecret} (CRYPTO_KEM_MLKEM768_CIPHERTEXTBYTES bytes)
1472
+ */
1473
+ export function crypto_kem_mlkem768_enc_deterministic(publicKey: Uint8Array, seed: Uint8Array, outputFormat?: Uint8ArrayOutputFormat | null): { ciphertext: Uint8Array; sharedSecret: Uint8Array };
1474
+ export function crypto_kem_mlkem768_enc_deterministic(publicKey: Uint8Array, seed: Uint8Array, outputFormat: StringOutputFormat): { ciphertext: string; sharedSecret: string };
1475
+ /**
1476
+ * @param outputFormat Output format (default: Uint8Array)
1477
+ * @returns {publicKey, privateKey, keyType} (CRYPTO_KEM_MLKEM768_PUBLICKEYBYTES bytes)
1478
+ */
1479
+ export function crypto_kem_mlkem768_keypair(outputFormat?: Uint8ArrayOutputFormat | null): { publicKey: Uint8Array; privateKey: Uint8Array; keyType: string };
1480
+ export function crypto_kem_mlkem768_keypair(outputFormat: StringOutputFormat): { publicKey: string; privateKey: string; keyType: string };
1481
+ /**
1482
+ * @param seed (CRYPTO_KEM_MLKEM768_SEEDBYTES bytes)
1483
+ * @param outputFormat Output format (default: Uint8Array)
1484
+ * @returns {publicKey, privateKey, keyType} (CRYPTO_KEM_MLKEM768_PUBLICKEYBYTES bytes)
1485
+ */
1486
+ export function crypto_kem_mlkem768_seed_keypair(seed: Uint8Array, outputFormat?: Uint8ArrayOutputFormat | null): { publicKey: Uint8Array; privateKey: Uint8Array; keyType: string };
1487
+ export function crypto_kem_mlkem768_seed_keypair(seed: Uint8Array, outputFormat: StringOutputFormat): { publicKey: string; privateKey: string; keyType: string };
1488
+ /**
1489
+ * @returns string
1490
+ */
1491
+ export function crypto_kem_primitive(): string;
1492
+ /**
1493
+ * @param seed (CRYPTO_KEM_SEEDBYTES bytes)
1494
+ * @param outputFormat Output format (default: Uint8Array)
1495
+ * @returns {publicKey, privateKey, keyType} (CRYPTO_KEM_PUBLICKEYBYTES bytes)
1496
+ */
1497
+ export function crypto_kem_seed_keypair(seed: Uint8Array, outputFormat?: Uint8ArrayOutputFormat | null): { publicKey: Uint8Array; privateKey: Uint8Array; keyType: string };
1498
+ export function crypto_kem_seed_keypair(seed: Uint8Array, outputFormat: StringOutputFormat): { publicKey: string; privateKey: string; keyType: string };
1499
+ /**
1500
+ * @param ciphertext (CRYPTO_KEM_XWING_CIPHERTEXTBYTES bytes)
1501
+ * @param privateKey (CRYPTO_KEM_XWING_SECRETKEYBYTES bytes)
1502
+ * @param outputFormat Output format (default: Uint8Array)
1503
+ * @returns Uint8Array | string (CRYPTO_KEM_XWING_SHAREDSECRETBYTES bytes)
1504
+ */
1505
+ export function crypto_kem_xwing_dec(ciphertext: Uint8Array, privateKey: Uint8Array, outputFormat?: Uint8ArrayOutputFormat | null): Uint8Array;
1506
+ export function crypto_kem_xwing_dec(ciphertext: Uint8Array, privateKey: Uint8Array, outputFormat: StringOutputFormat): string;
1507
+ /**
1508
+ * @param publicKey (CRYPTO_KEM_XWING_PUBLICKEYBYTES bytes)
1509
+ * @param outputFormat Output format (default: Uint8Array)
1510
+ * @returns {ciphertext, sharedSecret} (CRYPTO_KEM_XWING_CIPHERTEXTBYTES bytes)
1511
+ */
1512
+ export function crypto_kem_xwing_enc(publicKey: Uint8Array, outputFormat?: Uint8ArrayOutputFormat | null): { ciphertext: Uint8Array; sharedSecret: Uint8Array };
1513
+ export function crypto_kem_xwing_enc(publicKey: Uint8Array, outputFormat: StringOutputFormat): { ciphertext: string; sharedSecret: string };
1514
+ /**
1515
+ * @param publicKey (CRYPTO_KEM_XWING_PUBLICKEYBYTES bytes)
1516
+ * @param seed
1517
+ * @param outputFormat Output format (default: Uint8Array)
1518
+ * @returns {ciphertext, sharedSecret} (CRYPTO_KEM_XWING_CIPHERTEXTBYTES bytes)
1519
+ */
1520
+ export function crypto_kem_xwing_enc_deterministic(publicKey: Uint8Array, seed: Uint8Array, outputFormat?: Uint8ArrayOutputFormat | null): { ciphertext: Uint8Array; sharedSecret: Uint8Array };
1521
+ export function crypto_kem_xwing_enc_deterministic(publicKey: Uint8Array, seed: Uint8Array, outputFormat: StringOutputFormat): { ciphertext: string; sharedSecret: string };
1522
+ /**
1523
+ * @param outputFormat Output format (default: Uint8Array)
1524
+ * @returns {publicKey, privateKey, keyType} (CRYPTO_KEM_XWING_PUBLICKEYBYTES bytes)
1525
+ */
1526
+ export function crypto_kem_xwing_keypair(outputFormat?: Uint8ArrayOutputFormat | null): { publicKey: Uint8Array; privateKey: Uint8Array; keyType: string };
1527
+ export function crypto_kem_xwing_keypair(outputFormat: StringOutputFormat): { publicKey: string; privateKey: string; keyType: string };
1528
+ /**
1529
+ * @param seed (CRYPTO_KEM_XWING_SEEDBYTES bytes)
1530
+ * @param outputFormat Output format (default: Uint8Array)
1531
+ * @returns {publicKey, privateKey, keyType} (CRYPTO_KEM_XWING_PUBLICKEYBYTES bytes)
1532
+ */
1533
+ export function crypto_kem_xwing_seed_keypair(seed: Uint8Array, outputFormat?: Uint8ArrayOutputFormat | null): { publicKey: Uint8Array; privateKey: Uint8Array; keyType: string };
1534
+ export function crypto_kem_xwing_seed_keypair(seed: Uint8Array, outputFormat: StringOutputFormat): { publicKey: string; privateKey: string; keyType: string };
1367
1535
  /**
1368
1536
  * @param clientPublicKey (CRYPTO_KX_PUBLICKEYBYTES bytes)
1369
1537
  * @param clientSecretKey (CRYPTO_KX_SECRETKEYBYTES bytes)
@@ -1449,9 +1617,9 @@ export function crypto_pwhash(keyLength: number, password: Uint8Array | string,
1449
1617
  * @param password
1450
1618
  * @param opsLimit
1451
1619
  * @param memLimit
1452
- * @returns Uint8Array (CRYPTO_PWHASH_STRBYTES bytes)
1620
+ * @returns string (CRYPTO_PWHASH_STRBYTES bytes)
1453
1621
  */
1454
- export function crypto_pwhash_str(password: Uint8Array | string, opsLimit: number, memLimit: number): Uint8Array;
1622
+ export function crypto_pwhash_str(password: Uint8Array | string, opsLimit: number, memLimit: number): string;
1455
1623
  /**
1456
1624
  * @param hashed_password
1457
1625
  * @param opsLimit
@@ -1968,9 +2136,9 @@ export function randombytes_stir(): void;
1968
2136
  export function randombytes_uniform(upper_bound: number): number;
1969
2137
  /**
1970
2138
  * @param bin
1971
- * @returns Uint8Array
2139
+ * @returns string
1972
2140
  */
1973
- export function sodium_bin2ip(bin: Uint8Array): Uint8Array;
2141
+ export function sodium_bin2ip(bin: Uint8Array): string;
1974
2142
  /**
1975
2143
  * @param ip
1976
2144
  * @param outputFormat Output format (default: Uint8Array)