@dxos/hypercore 0.1.53 → 0.1.54-next.b67d4c9
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/lib/browser/index.mjs +140 -140
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +130 -130
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/package.json +14 -16
- package/src/crypto.ts +3 -3
- package/src/hypercore-factory.ts +2 -2
package/dist/lib/node/index.cjs
CHANGED
|
@@ -2535,15 +2535,15 @@ var require_safe_buffer_equals = __commonJS({
|
|
|
2535
2535
|
// node_modules/.pnpm/nanoassert@2.0.0/node_modules/nanoassert/index.js
|
|
2536
2536
|
var require_nanoassert = __commonJS({
|
|
2537
2537
|
"node_modules/.pnpm/nanoassert@2.0.0/node_modules/nanoassert/index.js"(exports, module2) {
|
|
2538
|
-
module2.exports =
|
|
2538
|
+
module2.exports = assert;
|
|
2539
2539
|
var AssertionError = class extends Error {
|
|
2540
2540
|
};
|
|
2541
2541
|
AssertionError.prototype.name = "AssertionError";
|
|
2542
|
-
function
|
|
2542
|
+
function assert(t, m) {
|
|
2543
2543
|
if (!t) {
|
|
2544
2544
|
var err = new AssertionError(m);
|
|
2545
2545
|
if (Error.captureStackTrace)
|
|
2546
|
-
Error.captureStackTrace(err,
|
|
2546
|
+
Error.captureStackTrace(err, assert);
|
|
2547
2547
|
throw err;
|
|
2548
2548
|
}
|
|
2549
2549
|
}
|
|
@@ -2761,13 +2761,13 @@ var require_cipher = __commonJS({
|
|
|
2761
2761
|
crypto_aead_chacha20poly1305_ietf_encrypt,
|
|
2762
2762
|
crypto_aead_chacha20poly1305_ietf_decrypt
|
|
2763
2763
|
} = require("sodium-universal/crypto_aead");
|
|
2764
|
-
var
|
|
2764
|
+
var assert = require_nanoassert();
|
|
2765
2765
|
var KEYLEN = 32;
|
|
2766
2766
|
var NONCELEN = 8;
|
|
2767
2767
|
var MACLEN = 16;
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2768
|
+
assert(crypto_aead_chacha20poly1305_ietf_KEYBYTES === KEYLEN);
|
|
2769
|
+
assert(crypto_aead_chacha20poly1305_ietf_NPUBBYTES === 4 + NONCELEN);
|
|
2770
|
+
assert(crypto_aead_chacha20poly1305_ietf_ABYTES === MACLEN);
|
|
2771
2771
|
module2.exports = {
|
|
2772
2772
|
KEYLEN,
|
|
2773
2773
|
NONCELEN,
|
|
@@ -2778,10 +2778,10 @@ var require_cipher = __commonJS({
|
|
|
2778
2778
|
};
|
|
2779
2779
|
var ElongatedNonce = sodium_malloc(crypto_aead_chacha20poly1305_ietf_NPUBBYTES);
|
|
2780
2780
|
function encrypt(out, k, n, ad, plaintext) {
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2781
|
+
assert(out.byteLength >= plaintext.byteLength + MACLEN, "output buffer must be at least plaintext plus MACLEN bytes long");
|
|
2782
|
+
assert(k.byteLength === KEYLEN);
|
|
2783
|
+
assert(n.byteLength === NONCELEN);
|
|
2784
|
+
assert(ad == null ? true : ad.byteLength != null);
|
|
2785
2785
|
sodium_memzero(ElongatedNonce);
|
|
2786
2786
|
ElongatedNonce.set(n, 4);
|
|
2787
2787
|
encrypt.bytesWritten = crypto_aead_chacha20poly1305_ietf_encrypt(out.subarray(0, plaintext.byteLength + MACLEN), plaintext, ad, null, ElongatedNonce, k);
|
|
@@ -2791,10 +2791,10 @@ var require_cipher = __commonJS({
|
|
|
2791
2791
|
encrypt.bytesWritten = 0;
|
|
2792
2792
|
encrypt.bytesRead = 0;
|
|
2793
2793
|
function decrypt(out, k, n, ad, ciphertext) {
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2794
|
+
assert(out.byteLength >= ciphertext.byteLength - MACLEN);
|
|
2795
|
+
assert(k.byteLength === KEYLEN);
|
|
2796
|
+
assert(n.byteLength === NONCELEN);
|
|
2797
|
+
assert(ad == null ? true : ad.byteLength != null);
|
|
2798
2798
|
sodium_memzero(ElongatedNonce);
|
|
2799
2799
|
ElongatedNonce.set(n, 4);
|
|
2800
2800
|
decrypt.bytesWritten = crypto_aead_chacha20poly1305_ietf_decrypt(out.subarray(0, ciphertext.byteLength - MACLEN), null, ciphertext, ad, ElongatedNonce, k);
|
|
@@ -2809,8 +2809,8 @@ var require_cipher = __commonJS({
|
|
|
2809
2809
|
var IntermediateKey = sodium_malloc(KEYLEN + MACLEN);
|
|
2810
2810
|
sodium_memzero(IntermediateKey);
|
|
2811
2811
|
function rekey(out, k) {
|
|
2812
|
-
|
|
2813
|
-
|
|
2812
|
+
assert(out.byteLength === KEYLEN);
|
|
2813
|
+
assert(k.byteLength === KEYLEN);
|
|
2814
2814
|
sodium_memzero(IntermediateKey);
|
|
2815
2815
|
IntermediateKey.set(k);
|
|
2816
2816
|
encrypt(IntermediateKey, k, maxnonce, zerolen, zeros);
|
|
@@ -2829,7 +2829,7 @@ var require_cipher_state = __commonJS({
|
|
|
2829
2829
|
"node_modules/.pnpm/noise-protocol@3.0.1/node_modules/noise-protocol/cipher-state.js"(exports, module2) {
|
|
2830
2830
|
var { sodium_memzero } = require("sodium-universal/memory");
|
|
2831
2831
|
var { sodium_increment, sodium_memcmp, sodium_is_zero } = require("sodium-universal/helpers");
|
|
2832
|
-
var
|
|
2832
|
+
var assert = require_nanoassert();
|
|
2833
2833
|
var cipher = require_cipher();
|
|
2834
2834
|
var STATELEN = cipher.KEYLEN + cipher.NONCELEN;
|
|
2835
2835
|
var NONCELEN = cipher.NONCELEN;
|
|
@@ -2850,8 +2850,8 @@ var require_cipher_state = __commonJS({
|
|
|
2850
2850
|
var NONCE_BEGIN = KEY_END;
|
|
2851
2851
|
var NONCE_END = NONCE_BEGIN + cipher.NONCELEN;
|
|
2852
2852
|
function initializeKey(state, key) {
|
|
2853
|
-
|
|
2854
|
-
|
|
2853
|
+
assert(state.byteLength === STATELEN);
|
|
2854
|
+
assert(key == null ? true : key.byteLength === cipher.KEYLEN);
|
|
2855
2855
|
if (key == null) {
|
|
2856
2856
|
sodium_memzero(state.subarray(KEY_BEGIN, KEY_END));
|
|
2857
2857
|
return;
|
|
@@ -2860,20 +2860,20 @@ var require_cipher_state = __commonJS({
|
|
|
2860
2860
|
sodium_memzero(state.subarray(NONCE_BEGIN, NONCE_END));
|
|
2861
2861
|
}
|
|
2862
2862
|
function hasKey(state) {
|
|
2863
|
-
|
|
2863
|
+
assert(state.byteLength === STATELEN);
|
|
2864
2864
|
var k = state.subarray(KEY_BEGIN, KEY_END);
|
|
2865
2865
|
return sodium_is_zero(k) === false;
|
|
2866
2866
|
}
|
|
2867
2867
|
function setNonce(state, nonce) {
|
|
2868
|
-
|
|
2869
|
-
|
|
2868
|
+
assert(state.byteLength === STATELEN);
|
|
2869
|
+
assert(nonce.byteLength === NONCELEN);
|
|
2870
2870
|
state.set(nonce, NONCE_BEGIN);
|
|
2871
2871
|
}
|
|
2872
2872
|
var maxnonce = new Uint8Array(8).fill(255);
|
|
2873
2873
|
function encryptWithAd(state, out, ad, plaintext) {
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2874
|
+
assert(state.byteLength === STATELEN);
|
|
2875
|
+
assert(out.byteLength != null);
|
|
2876
|
+
assert(plaintext.byteLength != null);
|
|
2877
2877
|
var n = state.subarray(NONCE_BEGIN, NONCE_END);
|
|
2878
2878
|
if (sodium_memcmp(n, maxnonce))
|
|
2879
2879
|
throw new Error("Nonce overflow");
|
|
@@ -2898,9 +2898,9 @@ var require_cipher_state = __commonJS({
|
|
|
2898
2898
|
encryptWithAd.bytesRead = 0;
|
|
2899
2899
|
encryptWithAd.bytesWritten = 0;
|
|
2900
2900
|
function decryptWithAd(state, out, ad, ciphertext) {
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2901
|
+
assert(state.byteLength === STATELEN);
|
|
2902
|
+
assert(out.byteLength != null);
|
|
2903
|
+
assert(ciphertext.byteLength != null);
|
|
2904
2904
|
var n = state.subarray(NONCE_BEGIN, NONCE_END);
|
|
2905
2905
|
if (sodium_memcmp(n, maxnonce))
|
|
2906
2906
|
throw new Error("Nonce overflow");
|
|
@@ -2925,7 +2925,7 @@ var require_cipher_state = __commonJS({
|
|
|
2925
2925
|
decryptWithAd.bytesRead = 0;
|
|
2926
2926
|
decryptWithAd.bytesWritten = 0;
|
|
2927
2927
|
function rekey(state) {
|
|
2928
|
-
|
|
2928
|
+
assert(state.byteLength === STATELEN);
|
|
2929
2929
|
var k = state.subarray(KEY_BEGIN, KEY_END);
|
|
2930
2930
|
cipher.rekey(k, k);
|
|
2931
2931
|
rekey.bytesRead = cipher.rekey.bytesRead;
|
|
@@ -2939,21 +2939,21 @@ var require_cipher_state = __commonJS({
|
|
|
2939
2939
|
// node_modules/.pnpm/nanoassert@1.1.0/node_modules/nanoassert/index.js
|
|
2940
2940
|
var require_nanoassert2 = __commonJS({
|
|
2941
2941
|
"node_modules/.pnpm/nanoassert@1.1.0/node_modules/nanoassert/index.js"(exports, module2) {
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
module2.exports =
|
|
2942
|
+
assert.notEqual = notEqual;
|
|
2943
|
+
assert.notOk = notOk;
|
|
2944
|
+
assert.equal = equal;
|
|
2945
|
+
assert.ok = assert;
|
|
2946
|
+
module2.exports = assert;
|
|
2947
2947
|
function equal(a, b, m) {
|
|
2948
|
-
|
|
2948
|
+
assert(a == b, m);
|
|
2949
2949
|
}
|
|
2950
2950
|
function notEqual(a, b, m) {
|
|
2951
|
-
|
|
2951
|
+
assert(a != b, m);
|
|
2952
2952
|
}
|
|
2953
2953
|
function notOk(t, m) {
|
|
2954
|
-
|
|
2954
|
+
assert(!t, m);
|
|
2955
2955
|
}
|
|
2956
|
-
function
|
|
2956
|
+
function assert(t, m) {
|
|
2957
2957
|
if (!t)
|
|
2958
2958
|
throw new Error(m || "AssertionError");
|
|
2959
2959
|
}
|
|
@@ -2965,7 +2965,7 @@ var require_hmac_blake2b = __commonJS({
|
|
|
2965
2965
|
"node_modules/.pnpm/hmac-blake2b@2.0.0/node_modules/hmac-blake2b/index.js"(exports, module2) {
|
|
2966
2966
|
var { sodium_malloc, sodium_memzero } = require("sodium-universal/memory");
|
|
2967
2967
|
var { crypto_generichash, crypto_generichash_batch } = require("sodium-universal/crypto_generichash");
|
|
2968
|
-
var
|
|
2968
|
+
var assert = require_nanoassert2();
|
|
2969
2969
|
var HASHLEN = 64;
|
|
2970
2970
|
var BLOCKLEN = 128;
|
|
2971
2971
|
var scratch = sodium_malloc(BLOCKLEN * 3);
|
|
@@ -2973,9 +2973,9 @@ var require_hmac_blake2b = __commonJS({
|
|
|
2973
2973
|
var OuterKeyPad = scratch.subarray(BLOCKLEN * 1, BLOCKLEN * 2);
|
|
2974
2974
|
var InnerKeyPad = scratch.subarray(BLOCKLEN * 2, BLOCKLEN * 3);
|
|
2975
2975
|
module2.exports = function hmac(out, data, key) {
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2976
|
+
assert(out.byteLength === HASHLEN);
|
|
2977
|
+
assert(key.byteLength != null);
|
|
2978
|
+
assert(Array.isArray(data) ? data.every((d) => d.byteLength != null) : data.byteLength != null);
|
|
2979
2979
|
if (key.byteLength > BLOCKLEN) {
|
|
2980
2980
|
crypto_generichash(HMACKey.subarray(0, HASHLEN), key);
|
|
2981
2981
|
sodium_memzero(HMACKey.subarray(HASHLEN));
|
|
@@ -3003,7 +3003,7 @@ var require_dh = __commonJS({
|
|
|
3003
3003
|
"node_modules/.pnpm/noise-protocol@3.0.1/node_modules/noise-protocol/dh.js"(exports, module2) {
|
|
3004
3004
|
var { crypto_kx_SEEDBYTES, crypto_kx_keypair, crypto_kx_seed_keypair } = require("sodium-universal/crypto_kx");
|
|
3005
3005
|
var { crypto_scalarmult_BYTES, crypto_scalarmult_SCALARBYTES, crypto_scalarmult } = require("sodium-universal/crypto_scalarmult");
|
|
3006
|
-
var
|
|
3006
|
+
var assert = require_nanoassert();
|
|
3007
3007
|
var DHLEN = crypto_scalarmult_BYTES;
|
|
3008
3008
|
var PKLEN = crypto_scalarmult_BYTES;
|
|
3009
3009
|
var SKLEN = crypto_scalarmult_SCALARBYTES;
|
|
@@ -3018,20 +3018,20 @@ var require_dh = __commonJS({
|
|
|
3018
3018
|
dh
|
|
3019
3019
|
};
|
|
3020
3020
|
function generateKeypair(pk, sk) {
|
|
3021
|
-
|
|
3022
|
-
|
|
3021
|
+
assert(pk.byteLength === PKLEN);
|
|
3022
|
+
assert(sk.byteLength === SKLEN);
|
|
3023
3023
|
crypto_kx_keypair(pk, sk);
|
|
3024
3024
|
}
|
|
3025
3025
|
function generateSeedKeypair(pk, sk, seed) {
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3026
|
+
assert(pk.byteLength === PKLEN);
|
|
3027
|
+
assert(sk.byteLength === SKLEN);
|
|
3028
|
+
assert(seed.byteLength === SKLEN);
|
|
3029
3029
|
crypto_kx_seed_keypair(pk, sk, seed);
|
|
3030
3030
|
}
|
|
3031
3031
|
function dh(output, lsk, pk) {
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3032
|
+
assert(output.byteLength === DHLEN);
|
|
3033
|
+
assert(lsk.byteLength === SKLEN);
|
|
3034
|
+
assert(pk.byteLength === PKLEN);
|
|
3035
3035
|
crypto_scalarmult(
|
|
3036
3036
|
output,
|
|
3037
3037
|
lsk,
|
|
@@ -3046,13 +3046,13 @@ var require_hash = __commonJS({
|
|
|
3046
3046
|
"node_modules/.pnpm/noise-protocol@3.0.1/node_modules/noise-protocol/hash.js"(exports, module2) {
|
|
3047
3047
|
var { sodium_malloc, sodium_memzero } = require("sodium-universal/memory");
|
|
3048
3048
|
var { crypto_generichash_batch } = require("sodium-universal/crypto_generichash");
|
|
3049
|
-
var
|
|
3049
|
+
var assert = require_nanoassert();
|
|
3050
3050
|
var hmacBlake2b = require_hmac_blake2b();
|
|
3051
3051
|
var dh = require_dh();
|
|
3052
3052
|
var HASHLEN = 64;
|
|
3053
3053
|
var BLOCKLEN = 128;
|
|
3054
|
-
|
|
3055
|
-
|
|
3054
|
+
assert(hmacBlake2b.KEYBYTES === BLOCKLEN, "mismatching hmac BLOCKLEN");
|
|
3055
|
+
assert(hmacBlake2b.BYTES === HASHLEN, "mismatching hmac HASHLEN");
|
|
3056
3056
|
module2.exports = {
|
|
3057
3057
|
HASHLEN,
|
|
3058
3058
|
BLOCKLEN,
|
|
@@ -3060,8 +3060,8 @@ var require_hash = __commonJS({
|
|
|
3060
3060
|
hkdf
|
|
3061
3061
|
};
|
|
3062
3062
|
function hash(out, data) {
|
|
3063
|
-
|
|
3064
|
-
|
|
3063
|
+
assert(out.byteLength === HASHLEN);
|
|
3064
|
+
assert(Array.isArray(data));
|
|
3065
3065
|
crypto_generichash_batch(out, data);
|
|
3066
3066
|
}
|
|
3067
3067
|
function hmac(out, key, data) {
|
|
@@ -3072,11 +3072,11 @@ var require_hash = __commonJS({
|
|
|
3072
3072
|
var Byte0x02 = new Uint8Array([2]);
|
|
3073
3073
|
var Byte0x03 = new Uint8Array([3]);
|
|
3074
3074
|
function hkdf(out1, out2, out3, chainingKey, inputKeyMaterial) {
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3075
|
+
assert(out1.byteLength === HASHLEN);
|
|
3076
|
+
assert(out2.byteLength === HASHLEN);
|
|
3077
|
+
assert(out3 == null ? true : out3.byteLength === HASHLEN);
|
|
3078
|
+
assert(chainingKey.byteLength === HASHLEN);
|
|
3079
|
+
assert([0, 32, dh.DHLEN, dh.PKLEN].includes(inputKeyMaterial.byteLength));
|
|
3080
3080
|
sodium_memzero(TempKey);
|
|
3081
3081
|
hmac(TempKey, chainingKey, [inputKeyMaterial]);
|
|
3082
3082
|
hmac(out1, TempKey, [Byte0x01]);
|
|
@@ -3093,7 +3093,7 @@ var require_hash = __commonJS({
|
|
|
3093
3093
|
var require_symmetric_state = __commonJS({
|
|
3094
3094
|
"node_modules/.pnpm/noise-protocol@3.0.1/node_modules/noise-protocol/symmetric-state.js"(exports, module2) {
|
|
3095
3095
|
var { sodium_malloc, sodium_memzero } = require("sodium-universal/memory");
|
|
3096
|
-
var
|
|
3096
|
+
var assert = require_nanoassert();
|
|
3097
3097
|
var cipherState = require_cipher_state();
|
|
3098
3098
|
var hash = require_hash();
|
|
3099
3099
|
var STATELEN = hash.HASHLEN + hash.HASHLEN + cipherState.STATELEN;
|
|
@@ -3117,8 +3117,8 @@ var require_symmetric_state = __commonJS({
|
|
|
3117
3117
|
var CIPHER_BEGIN = HASH_END;
|
|
3118
3118
|
var CIPHER_END = CIPHER_BEGIN + cipherState.STATELEN;
|
|
3119
3119
|
function initializeSymmetric(state, protocolName) {
|
|
3120
|
-
|
|
3121
|
-
|
|
3120
|
+
assert(state.byteLength === STATELEN);
|
|
3121
|
+
assert(protocolName.byteLength != null);
|
|
3122
3122
|
sodium_memzero(state);
|
|
3123
3123
|
if (protocolName.byteLength <= HASHLEN)
|
|
3124
3124
|
state.set(protocolName, HASH_BEGIN);
|
|
@@ -3129,8 +3129,8 @@ var require_symmetric_state = __commonJS({
|
|
|
3129
3129
|
}
|
|
3130
3130
|
var TempKey = sodium_malloc(HASHLEN);
|
|
3131
3131
|
function mixKey(state, inputKeyMaterial) {
|
|
3132
|
-
|
|
3133
|
-
|
|
3132
|
+
assert(state.byteLength === STATELEN);
|
|
3133
|
+
assert(inputKeyMaterial.byteLength != null);
|
|
3134
3134
|
hash.hkdf(
|
|
3135
3135
|
state.subarray(CHAINING_KEY_BEGIN, CHAINING_KEY_END),
|
|
3136
3136
|
TempKey,
|
|
@@ -3142,14 +3142,14 @@ var require_symmetric_state = __commonJS({
|
|
|
3142
3142
|
sodium_memzero(TempKey);
|
|
3143
3143
|
}
|
|
3144
3144
|
function mixHash(state, data) {
|
|
3145
|
-
|
|
3145
|
+
assert(state.byteLength === STATELEN);
|
|
3146
3146
|
var h = state.subarray(HASH_BEGIN, HASH_END);
|
|
3147
3147
|
hash.hash(h, [h, data]);
|
|
3148
3148
|
}
|
|
3149
3149
|
var TempHash = sodium_malloc(HASHLEN);
|
|
3150
3150
|
function mixKeyAndHash(state, inputKeyMaterial) {
|
|
3151
|
-
|
|
3152
|
-
|
|
3151
|
+
assert(state.byteLength === STATELEN);
|
|
3152
|
+
assert(inputKeyMaterial.byteLength != null);
|
|
3153
3153
|
hash.hkdf(
|
|
3154
3154
|
state.subarray(CHAINING_KEY_BEGIN, CHAINING_KEY_END),
|
|
3155
3155
|
TempHash,
|
|
@@ -3163,14 +3163,14 @@ var require_symmetric_state = __commonJS({
|
|
|
3163
3163
|
sodium_memzero(TempKey);
|
|
3164
3164
|
}
|
|
3165
3165
|
function getHandshakeHash(state, out) {
|
|
3166
|
-
|
|
3167
|
-
|
|
3166
|
+
assert(state.byteLength === STATELEN);
|
|
3167
|
+
assert(out.byteLength === HASHLEN);
|
|
3168
3168
|
out.set(state.subarray(HASH_BEGIN, HASH_END));
|
|
3169
3169
|
}
|
|
3170
3170
|
function encryptAndHash(state, ciphertext, plaintext) {
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3171
|
+
assert(state.byteLength === STATELEN);
|
|
3172
|
+
assert(ciphertext.byteLength != null);
|
|
3173
|
+
assert(plaintext.byteLength != null);
|
|
3174
3174
|
var cstate = state.subarray(CIPHER_BEGIN, CIPHER_END);
|
|
3175
3175
|
var h = state.subarray(HASH_BEGIN, HASH_END);
|
|
3176
3176
|
cipherState.encryptWithAd(cstate, ciphertext, h, plaintext);
|
|
@@ -3181,9 +3181,9 @@ var require_symmetric_state = __commonJS({
|
|
|
3181
3181
|
encryptAndHash.bytesRead = 0;
|
|
3182
3182
|
encryptAndHash.bytesWritten = 0;
|
|
3183
3183
|
function decryptAndHash(state, plaintext, ciphertext) {
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3184
|
+
assert(state.byteLength === STATELEN);
|
|
3185
|
+
assert(plaintext.byteLength != null);
|
|
3186
|
+
assert(ciphertext.byteLength != null);
|
|
3187
3187
|
var cstate = state.subarray(CIPHER_BEGIN, CIPHER_END);
|
|
3188
3188
|
var h = state.subarray(HASH_BEGIN, HASH_END);
|
|
3189
3189
|
cipherState.decryptWithAd(cstate, plaintext, h, ciphertext);
|
|
@@ -3197,9 +3197,9 @@ var require_symmetric_state = __commonJS({
|
|
|
3197
3197
|
var TempKey2 = sodium_malloc(HASHLEN);
|
|
3198
3198
|
var zerolen = new Uint8Array(0);
|
|
3199
3199
|
function split(state, cipherstate1, cipherstate2) {
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3200
|
+
assert(state.byteLength === STATELEN);
|
|
3201
|
+
assert(cipherstate1.byteLength === cipherState.STATELEN);
|
|
3202
|
+
assert(cipherstate2.byteLength === cipherState.STATELEN);
|
|
3203
3203
|
hash.hkdf(
|
|
3204
3204
|
TempKey1,
|
|
3205
3205
|
TempKey2,
|
|
@@ -3222,7 +3222,7 @@ var require_symmetric_state = __commonJS({
|
|
|
3222
3222
|
var require_handshake_state = __commonJS({
|
|
3223
3223
|
"node_modules/.pnpm/noise-protocol@3.0.1/node_modules/noise-protocol/handshake-state.js"(exports, module2) {
|
|
3224
3224
|
var { sodium_malloc, sodium_memzero, sodium_free } = require("sodium-universal/memory");
|
|
3225
|
-
var
|
|
3225
|
+
var assert = require_nanoassert();
|
|
3226
3226
|
var clone = require_clone();
|
|
3227
3227
|
var symmetricState = require_symmetric_state();
|
|
3228
3228
|
var cipherState = require_cipher_state();
|
|
@@ -3391,36 +3391,36 @@ var require_handshake_state = __commonJS({
|
|
|
3391
3391
|
return buf;
|
|
3392
3392
|
}
|
|
3393
3393
|
function initialize(handshakePattern, initiator, prologue, s, e, rs, re) {
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3394
|
+
assert(Object.keys(PATTERNS).includes(handshakePattern), "Unsupported handshake pattern");
|
|
3395
|
+
assert(typeof initiator === "boolean", "Initiator must be a boolean");
|
|
3396
|
+
assert(prologue.byteLength != null, "prolouge must be a Buffer");
|
|
3397
|
+
assert(e == null ? true : e.publicKey.byteLength === dh.PKLEN, `e.publicKey must be ${dh.PKLEN} bytes`);
|
|
3398
|
+
assert(e == null ? true : e.secretKey.byteLength === dh.SKLEN, `e.secretKey must be ${dh.SKLEN} bytes`);
|
|
3399
|
+
assert(rs == null ? true : rs.byteLength === dh.PKLEN, `rs must be ${dh.PKLEN} bytes`);
|
|
3400
|
+
assert(re == null ? true : re.byteLength === dh.PKLEN, `re must be ${dh.PKLEN} bytes`);
|
|
3401
3401
|
var state = new HandshakeState();
|
|
3402
3402
|
var protocolName = Uint8Array.from(`Noise_${handshakePattern}_25519_ChaChaPoly_BLAKE2b`, toCharCode);
|
|
3403
3403
|
symmetricState.initializeSymmetric(state.symmetricState, protocolName);
|
|
3404
3404
|
symmetricState.mixHash(state.symmetricState, prologue);
|
|
3405
3405
|
state.role = initiator === true ? INITIATOR : RESPONDER;
|
|
3406
3406
|
if (s != null) {
|
|
3407
|
-
|
|
3408
|
-
|
|
3407
|
+
assert(s.publicKey.byteLength === dh.PKLEN, `s.publicKey must be ${dh.PKLEN} bytes`);
|
|
3408
|
+
assert(s.secretKey.byteLength === dh.SKLEN, `s.secretKey must be ${dh.SKLEN} bytes`);
|
|
3409
3409
|
state.spk = sodiumBufferCopy(s.publicKey);
|
|
3410
3410
|
state.ssk = sodiumBufferCopy(s.secretKey);
|
|
3411
3411
|
}
|
|
3412
3412
|
if (e != null) {
|
|
3413
|
-
|
|
3414
|
-
|
|
3413
|
+
assert(e.publicKey.byteLength === dh.PKLEN);
|
|
3414
|
+
assert(e.secretKey.byteLength === dh.SKLEN);
|
|
3415
3415
|
state.epk = sodiumBufferCopy(e.publicKey);
|
|
3416
3416
|
state.esk = sodiumBufferCopy(e.secretKey);
|
|
3417
3417
|
}
|
|
3418
3418
|
if (rs != null) {
|
|
3419
|
-
|
|
3419
|
+
assert(rs.byteLength === dh.PKLEN);
|
|
3420
3420
|
state.rs = sodiumBufferCopy(rs);
|
|
3421
3421
|
}
|
|
3422
3422
|
if (re != null) {
|
|
3423
|
-
|
|
3423
|
+
assert(re.byteLength === dh.PKLEN);
|
|
3424
3424
|
state.re = sodiumBufferCopy(re);
|
|
3425
3425
|
}
|
|
3426
3426
|
var pat = PATTERNS[handshakePattern];
|
|
@@ -3429,11 +3429,11 @@ var require_handshake_state = __commonJS({
|
|
|
3429
3429
|
for (var token of pattern) {
|
|
3430
3430
|
switch (token) {
|
|
3431
3431
|
case TOK_E:
|
|
3432
|
-
|
|
3432
|
+
assert(state.role === patternRole ? state.epk.byteLength != null : state.re.byteLength != null);
|
|
3433
3433
|
symmetricState.mixHash(state.symmetricState, state.role === patternRole ? state.epk : state.re);
|
|
3434
3434
|
break;
|
|
3435
3435
|
case TOK_S:
|
|
3436
|
-
|
|
3436
|
+
assert(state.role === patternRole ? state.spk.byteLength != null : state.rs.byteLength != null);
|
|
3437
3437
|
symmetricState.mixHash(state.symmetricState, state.role === patternRole ? state.spk : state.rs);
|
|
3438
3438
|
break;
|
|
3439
3439
|
default:
|
|
@@ -3442,7 +3442,7 @@ var require_handshake_state = __commonJS({
|
|
|
3442
3442
|
}
|
|
3443
3443
|
}
|
|
3444
3444
|
state.messagePatterns = clone(pat.messagePatterns);
|
|
3445
|
-
|
|
3445
|
+
assert(
|
|
3446
3446
|
state.messagePatterns.filter((p) => p[0] === INITIATOR).some((p) => p.includes(TOK_S)) ? state.spk !== null && state.ssk !== null : true,
|
|
3447
3447
|
// Default if none is found
|
|
3448
3448
|
"This handshake pattern requires a static keypair"
|
|
@@ -3451,18 +3451,18 @@ var require_handshake_state = __commonJS({
|
|
|
3451
3451
|
}
|
|
3452
3452
|
var DhResult = sodium_malloc(dh.DHLEN);
|
|
3453
3453
|
function writeMessage(state, payload, messageBuffer) {
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3454
|
+
assert(state instanceof HandshakeState);
|
|
3455
|
+
assert(payload.byteLength != null);
|
|
3456
|
+
assert(messageBuffer.byteLength != null);
|
|
3457
3457
|
var mpat = state.messagePatterns.shift();
|
|
3458
3458
|
var moffset = 0;
|
|
3459
|
-
|
|
3460
|
-
|
|
3459
|
+
assert(mpat != null);
|
|
3460
|
+
assert(state.role === mpat.shift());
|
|
3461
3461
|
for (var token of mpat) {
|
|
3462
3462
|
switch (token) {
|
|
3463
3463
|
case TOK_E:
|
|
3464
|
-
|
|
3465
|
-
|
|
3464
|
+
assert(state.epk == null);
|
|
3465
|
+
assert(state.esk == null);
|
|
3466
3466
|
state.epk = sodium_malloc(dh.PKLEN);
|
|
3467
3467
|
state.esk = sodium_malloc(dh.SKLEN);
|
|
3468
3468
|
dh.generateKeypair(state.epk, state.esk);
|
|
@@ -3471,7 +3471,7 @@ var require_handshake_state = __commonJS({
|
|
|
3471
3471
|
symmetricState.mixHash(state.symmetricState, state.epk);
|
|
3472
3472
|
break;
|
|
3473
3473
|
case TOK_S:
|
|
3474
|
-
|
|
3474
|
+
assert(state.spk.byteLength === dh.PKLEN);
|
|
3475
3475
|
symmetricState.encryptAndHash(state.symmetricState, messageBuffer.subarray(moffset), state.spk);
|
|
3476
3476
|
moffset += symmetricState.encryptAndHash.bytesWritten;
|
|
3477
3477
|
break;
|
|
@@ -3517,25 +3517,25 @@ var require_handshake_state = __commonJS({
|
|
|
3517
3517
|
}
|
|
3518
3518
|
writeMessage.bytes = 0;
|
|
3519
3519
|
function readMessage(state, message, payloadBuffer) {
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3520
|
+
assert(state instanceof HandshakeState);
|
|
3521
|
+
assert(message.byteLength != null);
|
|
3522
|
+
assert(payloadBuffer.byteLength != null);
|
|
3523
3523
|
var mpat = state.messagePatterns.shift();
|
|
3524
3524
|
var moffset = 0;
|
|
3525
|
-
|
|
3526
|
-
|
|
3525
|
+
assert(mpat != null);
|
|
3526
|
+
assert(mpat.shift() !== state.role);
|
|
3527
3527
|
for (var token of mpat) {
|
|
3528
3528
|
switch (token) {
|
|
3529
3529
|
case TOK_E:
|
|
3530
|
-
|
|
3531
|
-
|
|
3530
|
+
assert(state.re == null);
|
|
3531
|
+
assert(message.byteLength - moffset >= dh.PKLEN);
|
|
3532
3532
|
state.re = sodium_malloc(dh.PKLEN);
|
|
3533
3533
|
state.re.set(message.subarray(moffset, moffset + dh.PKLEN));
|
|
3534
3534
|
moffset += dh.PKLEN;
|
|
3535
3535
|
symmetricState.mixHash(state.symmetricState, state.re);
|
|
3536
3536
|
break;
|
|
3537
3537
|
case TOK_S:
|
|
3538
|
-
|
|
3538
|
+
assert(state.rs == null);
|
|
3539
3539
|
state.rs = sodium_malloc(dh.PKLEN);
|
|
3540
3540
|
var bytes = 0;
|
|
3541
3541
|
if (symmetricState._hasKey(state.symmetricState)) {
|
|
@@ -3543,7 +3543,7 @@ var require_handshake_state = __commonJS({
|
|
|
3543
3543
|
} else {
|
|
3544
3544
|
bytes = dh.PKLEN;
|
|
3545
3545
|
}
|
|
3546
|
-
|
|
3546
|
+
assert(message.byteLength - moffset >= bytes);
|
|
3547
3547
|
symmetricState.decryptAndHash(
|
|
3548
3548
|
state.symmetricState,
|
|
3549
3549
|
state.rs,
|
|
@@ -3660,7 +3660,7 @@ var require_simple_handshake = __commonJS({
|
|
|
3660
3660
|
var noise = require_noise_protocol();
|
|
3661
3661
|
var NoiseSymmetricState = require_symmetric_state();
|
|
3662
3662
|
var NoiseHash = require_hash();
|
|
3663
|
-
var
|
|
3663
|
+
var assert = require_nanoassert();
|
|
3664
3664
|
var EMPTY = Buffer.alloc(0);
|
|
3665
3665
|
function SimpleHandshake(isInitiator, opts) {
|
|
3666
3666
|
if (!(this instanceof SimpleHandshake))
|
|
@@ -3695,11 +3695,11 @@ var require_simple_handshake = __commonJS({
|
|
|
3695
3695
|
}
|
|
3696
3696
|
SimpleHandshake.prototype.recv = function recv(data, cb) {
|
|
3697
3697
|
var self = this;
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3698
|
+
assert(self.finished === false, "Should not call recv if finished");
|
|
3699
|
+
assert(data != null, "must have data");
|
|
3700
|
+
assert(data.byteLength <= self._rx.byteLength, "too much data received");
|
|
3701
|
+
assert(self.waiting === true, "Wrong state, not ready to receive data");
|
|
3702
|
+
assert(self.split == null, "split should be null");
|
|
3703
3703
|
var hasREBefore = self.state.re != null;
|
|
3704
3704
|
var hasRSBefore = self.state.rs != null;
|
|
3705
3705
|
try {
|
|
@@ -3732,9 +3732,9 @@ var require_simple_handshake = __commonJS({
|
|
|
3732
3732
|
}
|
|
3733
3733
|
};
|
|
3734
3734
|
SimpleHandshake.prototype.send = function send(data, cb) {
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
|
|
3735
|
+
assert(this.finished === false, "Should not call send if finished");
|
|
3736
|
+
assert(this.waiting === false, "Wrong state, not ready to send data");
|
|
3737
|
+
assert(this.split == null, "split should be null");
|
|
3738
3738
|
data = data || EMPTY;
|
|
3739
3739
|
try {
|
|
3740
3740
|
this.split = noise.writeMessage(this.state, data, this._tx);
|
|
@@ -3752,7 +3752,7 @@ var require_simple_handshake = __commonJS({
|
|
|
3752
3752
|
});
|
|
3753
3753
|
};
|
|
3754
3754
|
SimpleHandshake.prototype._finish = function _finish(err, msg, cb) {
|
|
3755
|
-
|
|
3755
|
+
assert(this.finished === false, "Already finished");
|
|
3756
3756
|
const self = this;
|
|
3757
3757
|
self.finished = true;
|
|
3758
3758
|
self.waiting = false;
|
|
@@ -10674,8 +10674,8 @@ module.exports = __toCommonJS(src_exports);
|
|
|
10674
10674
|
var import_hypercore2 = __toESM(require_hypercore());
|
|
10675
10675
|
|
|
10676
10676
|
// packages/common/hypercore/src/crypto.ts
|
|
10677
|
-
var import_node_assert = __toESM(require("node:assert"));
|
|
10678
10677
|
var import_node_util = require("node:util");
|
|
10678
|
+
var import_tiny_invariant = __toESM(require("tiny-invariant"));
|
|
10679
10679
|
var import_crypto = require("@dxos/crypto");
|
|
10680
10680
|
var import_util = require("@dxos/util");
|
|
10681
10681
|
var createCodecEncoding = (codec, opts) => ({
|
|
@@ -10683,8 +10683,8 @@ var createCodecEncoding = (codec, opts) => ({
|
|
|
10683
10683
|
decode: (buffer) => codec.decode(buffer, opts)
|
|
10684
10684
|
});
|
|
10685
10685
|
var createCrypto = (signer, publicKey) => {
|
|
10686
|
-
(0,
|
|
10687
|
-
(0,
|
|
10686
|
+
(0, import_tiny_invariant.default)(signer);
|
|
10687
|
+
(0, import_tiny_invariant.default)(publicKey);
|
|
10688
10688
|
return {
|
|
10689
10689
|
sign: (message, secretKey, cb) => {
|
|
10690
10690
|
(0, import_node_util.callbackify)(signer.sign.bind(signer))(publicKey, message, (err, result) => {
|
|
@@ -10730,7 +10730,7 @@ var defaultReplicateOptions = {
|
|
|
10730
10730
|
|
|
10731
10731
|
// packages/common/hypercore/src/hypercore-factory.ts
|
|
10732
10732
|
var import_hypercore = __toESM(require_hypercore());
|
|
10733
|
-
var
|
|
10733
|
+
var import_tiny_invariant2 = __toESM(require("tiny-invariant"));
|
|
10734
10734
|
var import_random_access_storage = require("@dxos/random-access-storage");
|
|
10735
10735
|
|
|
10736
10736
|
// packages/common/hypercore/src/util.ts
|
|
@@ -10745,7 +10745,7 @@ var HypercoreFactory = class {
|
|
|
10745
10745
|
}).createDirectory(), _options) {
|
|
10746
10746
|
this._root = _root;
|
|
10747
10747
|
this._options = _options;
|
|
10748
|
-
(0,
|
|
10748
|
+
(0, import_tiny_invariant2.default)(this._root);
|
|
10749
10749
|
}
|
|
10750
10750
|
/**
|
|
10751
10751
|
* Creates a feed using a storage factory prefixed with the feed's key.
|