@arbidocs/client 0.4.109 → 0.4.111
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/dist/index.cjs +42 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6451 -3385
- package/dist/index.d.ts +6451 -3385
- package/dist/index.js +36 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -352,6 +352,41 @@ function parseCallFragment(hash) {
|
|
|
352
352
|
const v = Number(params.get("v"));
|
|
353
353
|
return { key, linkVersion: Number.isInteger(v) && v > 0 ? v : null };
|
|
354
354
|
}
|
|
355
|
+
var CHAT_KEY_BYTES = 32;
|
|
356
|
+
async function deriveDirectChatKey(peerPublicKeyBase64, mySecretKey) {
|
|
357
|
+
await initSodium();
|
|
358
|
+
return sodium__default.default.crypto_box_beforenm(base64ToBytes(peerPublicKeyBase64), mySecretKey);
|
|
359
|
+
}
|
|
360
|
+
async function generateChatKey() {
|
|
361
|
+
await initSodium();
|
|
362
|
+
return sodium__default.default.randombytes_buf(CHAT_KEY_BYTES);
|
|
363
|
+
}
|
|
364
|
+
async function sealChatKey(key, publicKeyBase64) {
|
|
365
|
+
await initSodium();
|
|
366
|
+
return bytesToBase64(sodium__default.default.crypto_box_seal(key, base64ToBytes(publicKeyBase64)));
|
|
367
|
+
}
|
|
368
|
+
async function openSealedChatKey(sealedBase64, mySecretKey) {
|
|
369
|
+
await initSodium();
|
|
370
|
+
const key = sealedBoxDecrypt(sealedBase64, mySecretKey);
|
|
371
|
+
if (key.length !== CHAT_KEY_BYTES) throw new Error("Sealed chat key has the wrong length");
|
|
372
|
+
return key;
|
|
373
|
+
}
|
|
374
|
+
async function encryptWithChatKey(plaintext, key) {
|
|
375
|
+
await initSodium();
|
|
376
|
+
const nonce = sodium__default.default.randombytes_buf(sodium__default.default.crypto_secretbox_NONCEBYTES);
|
|
377
|
+
const box = sodium__default.default.crypto_secretbox_easy(sodium__default.default.from_string(plaintext), nonce, key);
|
|
378
|
+
const out = new Uint8Array(nonce.length + box.length);
|
|
379
|
+
out.set(nonce, 0);
|
|
380
|
+
out.set(box, nonce.length);
|
|
381
|
+
return bytesToBase64(out);
|
|
382
|
+
}
|
|
383
|
+
async function decryptWithChatKey(ciphertext, key) {
|
|
384
|
+
await initSodium();
|
|
385
|
+
const raw = base64ToBytes(ciphertext);
|
|
386
|
+
const nonce = raw.slice(0, sodium__default.default.crypto_secretbox_NONCEBYTES);
|
|
387
|
+
const box = raw.slice(sodium__default.default.crypto_secretbox_NONCEBYTES);
|
|
388
|
+
return sodium__default.default.to_string(sodium__default.default.crypto_secretbox_open_easy(box, nonce, key));
|
|
389
|
+
}
|
|
355
390
|
|
|
356
391
|
// src/crypto/keypairs.ts
|
|
357
392
|
async function generateUserKeypairs(username, password, deploymentDomain) {
|
|
@@ -1428,6 +1463,7 @@ function isMessageType(msg, type) {
|
|
|
1428
1463
|
|
|
1429
1464
|
exports.API_PREFIX = API_PREFIX;
|
|
1430
1465
|
exports.CALL_KEY_BYTES = CALL_KEY_BYTES;
|
|
1466
|
+
exports.CHAT_KEY_BYTES = CHAT_KEY_BYTES;
|
|
1431
1467
|
exports.base64Decode = base64Decode;
|
|
1432
1468
|
exports.base64Encode = base64Encode;
|
|
1433
1469
|
exports.base64ToBytes = base64ToBytes;
|
|
@@ -1452,6 +1488,8 @@ exports.decryptCallTitle = decryptCallTitle;
|
|
|
1452
1488
|
exports.decryptFile = decryptFile;
|
|
1453
1489
|
exports.decryptMessage = decryptMessage;
|
|
1454
1490
|
exports.decryptMessageWithSharedSecret = decryptMessageWithSharedSecret;
|
|
1491
|
+
exports.decryptWithChatKey = decryptWithChatKey;
|
|
1492
|
+
exports.deriveDirectChatKey = deriveDirectChatKey;
|
|
1455
1493
|
exports.deriveEncryptionKeypairFromSigning = deriveEncryptionKeypairFromSigning;
|
|
1456
1494
|
exports.derivePublicKey = derivePublicKey;
|
|
1457
1495
|
exports.encodeCallKey = encodeCallKey;
|
|
@@ -1459,7 +1497,9 @@ exports.encryptCallTitle = encryptCallTitle;
|
|
|
1459
1497
|
exports.encryptFile = encryptFile;
|
|
1460
1498
|
exports.encryptMessage = encryptMessage;
|
|
1461
1499
|
exports.encryptMessageWithSharedSecret = encryptMessageWithSharedSecret;
|
|
1500
|
+
exports.encryptWithChatKey = encryptWithChatKey;
|
|
1462
1501
|
exports.generateCallKey = generateCallKey;
|
|
1502
|
+
exports.generateChatKey = generateChatKey;
|
|
1463
1503
|
exports.generateIdentityKeypair = generateIdentityKeypair;
|
|
1464
1504
|
exports.generateKeyPairs = generateKeyPairs;
|
|
1465
1505
|
exports.generateLoginCredentials = generateLoginCredentials;
|
|
@@ -1476,12 +1516,14 @@ exports.initSodium = initSodium;
|
|
|
1476
1516
|
exports.initializeDatabase = initializeDatabase;
|
|
1477
1517
|
exports.isMessageType = isMessageType;
|
|
1478
1518
|
exports.openSealedCallKey = openSealedCallKey;
|
|
1519
|
+
exports.openSealedChatKey = openSealedChatKey;
|
|
1479
1520
|
exports.parseCallFragment = parseCallFragment;
|
|
1480
1521
|
exports.parseServerMessage = parseServerMessage;
|
|
1481
1522
|
exports.passwordChangeErrorMessage = passwordChangeErrorMessage;
|
|
1482
1523
|
exports.prewarmKeyPairs = prewarmKeyPairs;
|
|
1483
1524
|
exports.saveSession = saveSession;
|
|
1484
1525
|
exports.sealCallKey = sealCallKey;
|
|
1526
|
+
exports.sealChatKey = sealChatKey;
|
|
1485
1527
|
exports.sealKeyForSession = sealKeyForSession;
|
|
1486
1528
|
exports.sealedBoxDecrypt = sealedBoxDecrypt;
|
|
1487
1529
|
exports.sealedBoxEncrypt = sealedBoxEncrypt;
|