@dxos/hypercore 0.1.53 → 0.1.54-main.a3a8e76
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
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import import$
|
|
3
|
-
import
|
|
4
|
-
import * as import$
|
|
5
|
-
import * as import$
|
|
6
|
-
import * as import$
|
|
7
|
-
import * as import$
|
|
8
|
-
import * as import$
|
|
9
|
-
import * as import$
|
|
10
|
-
import
|
|
1
|
+
import "@dxos/node-std/globals";
|
|
2
|
+
import import$sodium_universal from 'sodium-universal';
|
|
3
|
+
import import$_dxos_node_std_events from '@dxos/node-std/events';
|
|
4
|
+
import * as import$sodium_universal_memory from 'sodium-universal/memory';
|
|
5
|
+
import * as import$sodium_universal_crypto_aead from 'sodium-universal/crypto_aead';
|
|
6
|
+
import * as import$sodium_universal_helpers from 'sodium-universal/helpers';
|
|
7
|
+
import * as import$sodium_universal_crypto_generichash from 'sodium-universal/crypto_generichash';
|
|
8
|
+
import * as import$sodium_universal_crypto_kx from 'sodium-universal/crypto_kx';
|
|
9
|
+
import * as import$sodium_universal_crypto_scalarmult from 'sodium-universal/crypto_scalarmult';
|
|
10
|
+
import * as import$streamx from 'streamx';
|
|
11
11
|
var __create = Object.create;
|
|
12
12
|
var __defProp = Object.defineProperty;
|
|
13
13
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -2529,15 +2529,15 @@ var require_safe_buffer_equals = __commonJS({
|
|
|
2529
2529
|
// node_modules/.pnpm/nanoassert@2.0.0/node_modules/nanoassert/index.js
|
|
2530
2530
|
var require_nanoassert = __commonJS({
|
|
2531
2531
|
"node_modules/.pnpm/nanoassert@2.0.0/node_modules/nanoassert/index.js"(exports, module) {
|
|
2532
|
-
module.exports =
|
|
2532
|
+
module.exports = assert;
|
|
2533
2533
|
var AssertionError = class extends Error {
|
|
2534
2534
|
};
|
|
2535
2535
|
AssertionError.prototype.name = "AssertionError";
|
|
2536
|
-
function
|
|
2536
|
+
function assert(t, m) {
|
|
2537
2537
|
if (!t) {
|
|
2538
2538
|
var err = new AssertionError(m);
|
|
2539
2539
|
if (Error.captureStackTrace)
|
|
2540
|
-
Error.captureStackTrace(err,
|
|
2540
|
+
Error.captureStackTrace(err, assert);
|
|
2541
2541
|
throw err;
|
|
2542
2542
|
}
|
|
2543
2543
|
}
|
|
@@ -2755,13 +2755,13 @@ var require_cipher = __commonJS({
|
|
|
2755
2755
|
crypto_aead_chacha20poly1305_ietf_encrypt,
|
|
2756
2756
|
crypto_aead_chacha20poly1305_ietf_decrypt
|
|
2757
2757
|
} = import$sodium_universal_crypto_aead;
|
|
2758
|
-
var
|
|
2758
|
+
var assert = require_nanoassert();
|
|
2759
2759
|
var KEYLEN = 32;
|
|
2760
2760
|
var NONCELEN = 8;
|
|
2761
2761
|
var MACLEN = 16;
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2762
|
+
assert(crypto_aead_chacha20poly1305_ietf_KEYBYTES === KEYLEN);
|
|
2763
|
+
assert(crypto_aead_chacha20poly1305_ietf_NPUBBYTES === 4 + NONCELEN);
|
|
2764
|
+
assert(crypto_aead_chacha20poly1305_ietf_ABYTES === MACLEN);
|
|
2765
2765
|
module.exports = {
|
|
2766
2766
|
KEYLEN,
|
|
2767
2767
|
NONCELEN,
|
|
@@ -2772,10 +2772,10 @@ var require_cipher = __commonJS({
|
|
|
2772
2772
|
};
|
|
2773
2773
|
var ElongatedNonce = sodium_malloc(crypto_aead_chacha20poly1305_ietf_NPUBBYTES);
|
|
2774
2774
|
function encrypt(out, k, n, ad, plaintext) {
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2775
|
+
assert(out.byteLength >= plaintext.byteLength + MACLEN, "output buffer must be at least plaintext plus MACLEN bytes long");
|
|
2776
|
+
assert(k.byteLength === KEYLEN);
|
|
2777
|
+
assert(n.byteLength === NONCELEN);
|
|
2778
|
+
assert(ad == null ? true : ad.byteLength != null);
|
|
2779
2779
|
sodium_memzero(ElongatedNonce);
|
|
2780
2780
|
ElongatedNonce.set(n, 4);
|
|
2781
2781
|
encrypt.bytesWritten = crypto_aead_chacha20poly1305_ietf_encrypt(out.subarray(0, plaintext.byteLength + MACLEN), plaintext, ad, null, ElongatedNonce, k);
|
|
@@ -2785,10 +2785,10 @@ var require_cipher = __commonJS({
|
|
|
2785
2785
|
encrypt.bytesWritten = 0;
|
|
2786
2786
|
encrypt.bytesRead = 0;
|
|
2787
2787
|
function decrypt(out, k, n, ad, ciphertext) {
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2788
|
+
assert(out.byteLength >= ciphertext.byteLength - MACLEN);
|
|
2789
|
+
assert(k.byteLength === KEYLEN);
|
|
2790
|
+
assert(n.byteLength === NONCELEN);
|
|
2791
|
+
assert(ad == null ? true : ad.byteLength != null);
|
|
2792
2792
|
sodium_memzero(ElongatedNonce);
|
|
2793
2793
|
ElongatedNonce.set(n, 4);
|
|
2794
2794
|
decrypt.bytesWritten = crypto_aead_chacha20poly1305_ietf_decrypt(out.subarray(0, ciphertext.byteLength - MACLEN), null, ciphertext, ad, ElongatedNonce, k);
|
|
@@ -2803,8 +2803,8 @@ var require_cipher = __commonJS({
|
|
|
2803
2803
|
var IntermediateKey = sodium_malloc(KEYLEN + MACLEN);
|
|
2804
2804
|
sodium_memzero(IntermediateKey);
|
|
2805
2805
|
function rekey(out, k) {
|
|
2806
|
-
|
|
2807
|
-
|
|
2806
|
+
assert(out.byteLength === KEYLEN);
|
|
2807
|
+
assert(k.byteLength === KEYLEN);
|
|
2808
2808
|
sodium_memzero(IntermediateKey);
|
|
2809
2809
|
IntermediateKey.set(k);
|
|
2810
2810
|
encrypt(IntermediateKey, k, maxnonce, zerolen, zeros);
|
|
@@ -2823,7 +2823,7 @@ var require_cipher_state = __commonJS({
|
|
|
2823
2823
|
"node_modules/.pnpm/noise-protocol@3.0.1/node_modules/noise-protocol/cipher-state.js"(exports, module) {
|
|
2824
2824
|
var { sodium_memzero } = import$sodium_universal_memory;
|
|
2825
2825
|
var { sodium_increment, sodium_memcmp, sodium_is_zero } = import$sodium_universal_helpers;
|
|
2826
|
-
var
|
|
2826
|
+
var assert = require_nanoassert();
|
|
2827
2827
|
var cipher = require_cipher();
|
|
2828
2828
|
var STATELEN = cipher.KEYLEN + cipher.NONCELEN;
|
|
2829
2829
|
var NONCELEN = cipher.NONCELEN;
|
|
@@ -2844,8 +2844,8 @@ var require_cipher_state = __commonJS({
|
|
|
2844
2844
|
var NONCE_BEGIN = KEY_END;
|
|
2845
2845
|
var NONCE_END = NONCE_BEGIN + cipher.NONCELEN;
|
|
2846
2846
|
function initializeKey(state, key) {
|
|
2847
|
-
|
|
2848
|
-
|
|
2847
|
+
assert(state.byteLength === STATELEN);
|
|
2848
|
+
assert(key == null ? true : key.byteLength === cipher.KEYLEN);
|
|
2849
2849
|
if (key == null) {
|
|
2850
2850
|
sodium_memzero(state.subarray(KEY_BEGIN, KEY_END));
|
|
2851
2851
|
return;
|
|
@@ -2854,20 +2854,20 @@ var require_cipher_state = __commonJS({
|
|
|
2854
2854
|
sodium_memzero(state.subarray(NONCE_BEGIN, NONCE_END));
|
|
2855
2855
|
}
|
|
2856
2856
|
function hasKey(state) {
|
|
2857
|
-
|
|
2857
|
+
assert(state.byteLength === STATELEN);
|
|
2858
2858
|
var k = state.subarray(KEY_BEGIN, KEY_END);
|
|
2859
2859
|
return sodium_is_zero(k) === false;
|
|
2860
2860
|
}
|
|
2861
2861
|
function setNonce(state, nonce) {
|
|
2862
|
-
|
|
2863
|
-
|
|
2862
|
+
assert(state.byteLength === STATELEN);
|
|
2863
|
+
assert(nonce.byteLength === NONCELEN);
|
|
2864
2864
|
state.set(nonce, NONCE_BEGIN);
|
|
2865
2865
|
}
|
|
2866
2866
|
var maxnonce = new Uint8Array(8).fill(255);
|
|
2867
2867
|
function encryptWithAd(state, out, ad, plaintext) {
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2868
|
+
assert(state.byteLength === STATELEN);
|
|
2869
|
+
assert(out.byteLength != null);
|
|
2870
|
+
assert(plaintext.byteLength != null);
|
|
2871
2871
|
var n = state.subarray(NONCE_BEGIN, NONCE_END);
|
|
2872
2872
|
if (sodium_memcmp(n, maxnonce))
|
|
2873
2873
|
throw new Error("Nonce overflow");
|
|
@@ -2892,9 +2892,9 @@ var require_cipher_state = __commonJS({
|
|
|
2892
2892
|
encryptWithAd.bytesRead = 0;
|
|
2893
2893
|
encryptWithAd.bytesWritten = 0;
|
|
2894
2894
|
function decryptWithAd(state, out, ad, ciphertext) {
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2895
|
+
assert(state.byteLength === STATELEN);
|
|
2896
|
+
assert(out.byteLength != null);
|
|
2897
|
+
assert(ciphertext.byteLength != null);
|
|
2898
2898
|
var n = state.subarray(NONCE_BEGIN, NONCE_END);
|
|
2899
2899
|
if (sodium_memcmp(n, maxnonce))
|
|
2900
2900
|
throw new Error("Nonce overflow");
|
|
@@ -2919,7 +2919,7 @@ var require_cipher_state = __commonJS({
|
|
|
2919
2919
|
decryptWithAd.bytesRead = 0;
|
|
2920
2920
|
decryptWithAd.bytesWritten = 0;
|
|
2921
2921
|
function rekey(state) {
|
|
2922
|
-
|
|
2922
|
+
assert(state.byteLength === STATELEN);
|
|
2923
2923
|
var k = state.subarray(KEY_BEGIN, KEY_END);
|
|
2924
2924
|
cipher.rekey(k, k);
|
|
2925
2925
|
rekey.bytesRead = cipher.rekey.bytesRead;
|
|
@@ -2933,21 +2933,21 @@ var require_cipher_state = __commonJS({
|
|
|
2933
2933
|
// node_modules/.pnpm/nanoassert@1.1.0/node_modules/nanoassert/index.js
|
|
2934
2934
|
var require_nanoassert2 = __commonJS({
|
|
2935
2935
|
"node_modules/.pnpm/nanoassert@1.1.0/node_modules/nanoassert/index.js"(exports, module) {
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
module.exports =
|
|
2936
|
+
assert.notEqual = notEqual;
|
|
2937
|
+
assert.notOk = notOk;
|
|
2938
|
+
assert.equal = equal;
|
|
2939
|
+
assert.ok = assert;
|
|
2940
|
+
module.exports = assert;
|
|
2941
2941
|
function equal(a, b, m) {
|
|
2942
|
-
|
|
2942
|
+
assert(a == b, m);
|
|
2943
2943
|
}
|
|
2944
2944
|
function notEqual(a, b, m) {
|
|
2945
|
-
|
|
2945
|
+
assert(a != b, m);
|
|
2946
2946
|
}
|
|
2947
2947
|
function notOk(t, m) {
|
|
2948
|
-
|
|
2948
|
+
assert(!t, m);
|
|
2949
2949
|
}
|
|
2950
|
-
function
|
|
2950
|
+
function assert(t, m) {
|
|
2951
2951
|
if (!t)
|
|
2952
2952
|
throw new Error(m || "AssertionError");
|
|
2953
2953
|
}
|
|
@@ -2959,7 +2959,7 @@ var require_hmac_blake2b = __commonJS({
|
|
|
2959
2959
|
"node_modules/.pnpm/hmac-blake2b@2.0.0/node_modules/hmac-blake2b/index.js"(exports, module) {
|
|
2960
2960
|
var { sodium_malloc, sodium_memzero } = import$sodium_universal_memory;
|
|
2961
2961
|
var { crypto_generichash, crypto_generichash_batch } = import$sodium_universal_crypto_generichash;
|
|
2962
|
-
var
|
|
2962
|
+
var assert = require_nanoassert2();
|
|
2963
2963
|
var HASHLEN = 64;
|
|
2964
2964
|
var BLOCKLEN = 128;
|
|
2965
2965
|
var scratch = sodium_malloc(BLOCKLEN * 3);
|
|
@@ -2967,9 +2967,9 @@ var require_hmac_blake2b = __commonJS({
|
|
|
2967
2967
|
var OuterKeyPad = scratch.subarray(BLOCKLEN * 1, BLOCKLEN * 2);
|
|
2968
2968
|
var InnerKeyPad = scratch.subarray(BLOCKLEN * 2, BLOCKLEN * 3);
|
|
2969
2969
|
module.exports = function hmac(out, data, key) {
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2970
|
+
assert(out.byteLength === HASHLEN);
|
|
2971
|
+
assert(key.byteLength != null);
|
|
2972
|
+
assert(Array.isArray(data) ? data.every((d) => d.byteLength != null) : data.byteLength != null);
|
|
2973
2973
|
if (key.byteLength > BLOCKLEN) {
|
|
2974
2974
|
crypto_generichash(HMACKey.subarray(0, HASHLEN), key);
|
|
2975
2975
|
sodium_memzero(HMACKey.subarray(HASHLEN));
|
|
@@ -2997,7 +2997,7 @@ var require_dh = __commonJS({
|
|
|
2997
2997
|
"node_modules/.pnpm/noise-protocol@3.0.1/node_modules/noise-protocol/dh.js"(exports, module) {
|
|
2998
2998
|
var { crypto_kx_SEEDBYTES, crypto_kx_keypair, crypto_kx_seed_keypair } = import$sodium_universal_crypto_kx;
|
|
2999
2999
|
var { crypto_scalarmult_BYTES, crypto_scalarmult_SCALARBYTES, crypto_scalarmult } = import$sodium_universal_crypto_scalarmult;
|
|
3000
|
-
var
|
|
3000
|
+
var assert = require_nanoassert();
|
|
3001
3001
|
var DHLEN = crypto_scalarmult_BYTES;
|
|
3002
3002
|
var PKLEN = crypto_scalarmult_BYTES;
|
|
3003
3003
|
var SKLEN = crypto_scalarmult_SCALARBYTES;
|
|
@@ -3012,20 +3012,20 @@ var require_dh = __commonJS({
|
|
|
3012
3012
|
dh
|
|
3013
3013
|
};
|
|
3014
3014
|
function generateKeypair(pk, sk) {
|
|
3015
|
-
|
|
3016
|
-
|
|
3015
|
+
assert(pk.byteLength === PKLEN);
|
|
3016
|
+
assert(sk.byteLength === SKLEN);
|
|
3017
3017
|
crypto_kx_keypair(pk, sk);
|
|
3018
3018
|
}
|
|
3019
3019
|
function generateSeedKeypair(pk, sk, seed) {
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3020
|
+
assert(pk.byteLength === PKLEN);
|
|
3021
|
+
assert(sk.byteLength === SKLEN);
|
|
3022
|
+
assert(seed.byteLength === SKLEN);
|
|
3023
3023
|
crypto_kx_seed_keypair(pk, sk, seed);
|
|
3024
3024
|
}
|
|
3025
3025
|
function dh(output, lsk, pk) {
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3026
|
+
assert(output.byteLength === DHLEN);
|
|
3027
|
+
assert(lsk.byteLength === SKLEN);
|
|
3028
|
+
assert(pk.byteLength === PKLEN);
|
|
3029
3029
|
crypto_scalarmult(
|
|
3030
3030
|
output,
|
|
3031
3031
|
lsk,
|
|
@@ -3040,13 +3040,13 @@ var require_hash = __commonJS({
|
|
|
3040
3040
|
"node_modules/.pnpm/noise-protocol@3.0.1/node_modules/noise-protocol/hash.js"(exports, module) {
|
|
3041
3041
|
var { sodium_malloc, sodium_memzero } = import$sodium_universal_memory;
|
|
3042
3042
|
var { crypto_generichash_batch } = import$sodium_universal_crypto_generichash;
|
|
3043
|
-
var
|
|
3043
|
+
var assert = require_nanoassert();
|
|
3044
3044
|
var hmacBlake2b = require_hmac_blake2b();
|
|
3045
3045
|
var dh = require_dh();
|
|
3046
3046
|
var HASHLEN = 64;
|
|
3047
3047
|
var BLOCKLEN = 128;
|
|
3048
|
-
|
|
3049
|
-
|
|
3048
|
+
assert(hmacBlake2b.KEYBYTES === BLOCKLEN, "mismatching hmac BLOCKLEN");
|
|
3049
|
+
assert(hmacBlake2b.BYTES === HASHLEN, "mismatching hmac HASHLEN");
|
|
3050
3050
|
module.exports = {
|
|
3051
3051
|
HASHLEN,
|
|
3052
3052
|
BLOCKLEN,
|
|
@@ -3054,8 +3054,8 @@ var require_hash = __commonJS({
|
|
|
3054
3054
|
hkdf
|
|
3055
3055
|
};
|
|
3056
3056
|
function hash(out, data) {
|
|
3057
|
-
|
|
3058
|
-
|
|
3057
|
+
assert(out.byteLength === HASHLEN);
|
|
3058
|
+
assert(Array.isArray(data));
|
|
3059
3059
|
crypto_generichash_batch(out, data);
|
|
3060
3060
|
}
|
|
3061
3061
|
function hmac(out, key, data) {
|
|
@@ -3066,11 +3066,11 @@ var require_hash = __commonJS({
|
|
|
3066
3066
|
var Byte0x02 = new Uint8Array([2]);
|
|
3067
3067
|
var Byte0x03 = new Uint8Array([3]);
|
|
3068
3068
|
function hkdf(out1, out2, out3, chainingKey, inputKeyMaterial) {
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3069
|
+
assert(out1.byteLength === HASHLEN);
|
|
3070
|
+
assert(out2.byteLength === HASHLEN);
|
|
3071
|
+
assert(out3 == null ? true : out3.byteLength === HASHLEN);
|
|
3072
|
+
assert(chainingKey.byteLength === HASHLEN);
|
|
3073
|
+
assert([0, 32, dh.DHLEN, dh.PKLEN].includes(inputKeyMaterial.byteLength));
|
|
3074
3074
|
sodium_memzero(TempKey);
|
|
3075
3075
|
hmac(TempKey, chainingKey, [inputKeyMaterial]);
|
|
3076
3076
|
hmac(out1, TempKey, [Byte0x01]);
|
|
@@ -3087,7 +3087,7 @@ var require_hash = __commonJS({
|
|
|
3087
3087
|
var require_symmetric_state = __commonJS({
|
|
3088
3088
|
"node_modules/.pnpm/noise-protocol@3.0.1/node_modules/noise-protocol/symmetric-state.js"(exports, module) {
|
|
3089
3089
|
var { sodium_malloc, sodium_memzero } = import$sodium_universal_memory;
|
|
3090
|
-
var
|
|
3090
|
+
var assert = require_nanoassert();
|
|
3091
3091
|
var cipherState = require_cipher_state();
|
|
3092
3092
|
var hash = require_hash();
|
|
3093
3093
|
var STATELEN = hash.HASHLEN + hash.HASHLEN + cipherState.STATELEN;
|
|
@@ -3111,8 +3111,8 @@ var require_symmetric_state = __commonJS({
|
|
|
3111
3111
|
var CIPHER_BEGIN = HASH_END;
|
|
3112
3112
|
var CIPHER_END = CIPHER_BEGIN + cipherState.STATELEN;
|
|
3113
3113
|
function initializeSymmetric(state, protocolName) {
|
|
3114
|
-
|
|
3115
|
-
|
|
3114
|
+
assert(state.byteLength === STATELEN);
|
|
3115
|
+
assert(protocolName.byteLength != null);
|
|
3116
3116
|
sodium_memzero(state);
|
|
3117
3117
|
if (protocolName.byteLength <= HASHLEN)
|
|
3118
3118
|
state.set(protocolName, HASH_BEGIN);
|
|
@@ -3123,8 +3123,8 @@ var require_symmetric_state = __commonJS({
|
|
|
3123
3123
|
}
|
|
3124
3124
|
var TempKey = sodium_malloc(HASHLEN);
|
|
3125
3125
|
function mixKey(state, inputKeyMaterial) {
|
|
3126
|
-
|
|
3127
|
-
|
|
3126
|
+
assert(state.byteLength === STATELEN);
|
|
3127
|
+
assert(inputKeyMaterial.byteLength != null);
|
|
3128
3128
|
hash.hkdf(
|
|
3129
3129
|
state.subarray(CHAINING_KEY_BEGIN, CHAINING_KEY_END),
|
|
3130
3130
|
TempKey,
|
|
@@ -3136,14 +3136,14 @@ var require_symmetric_state = __commonJS({
|
|
|
3136
3136
|
sodium_memzero(TempKey);
|
|
3137
3137
|
}
|
|
3138
3138
|
function mixHash(state, data) {
|
|
3139
|
-
|
|
3139
|
+
assert(state.byteLength === STATELEN);
|
|
3140
3140
|
var h = state.subarray(HASH_BEGIN, HASH_END);
|
|
3141
3141
|
hash.hash(h, [h, data]);
|
|
3142
3142
|
}
|
|
3143
3143
|
var TempHash = sodium_malloc(HASHLEN);
|
|
3144
3144
|
function mixKeyAndHash(state, inputKeyMaterial) {
|
|
3145
|
-
|
|
3146
|
-
|
|
3145
|
+
assert(state.byteLength === STATELEN);
|
|
3146
|
+
assert(inputKeyMaterial.byteLength != null);
|
|
3147
3147
|
hash.hkdf(
|
|
3148
3148
|
state.subarray(CHAINING_KEY_BEGIN, CHAINING_KEY_END),
|
|
3149
3149
|
TempHash,
|
|
@@ -3157,14 +3157,14 @@ var require_symmetric_state = __commonJS({
|
|
|
3157
3157
|
sodium_memzero(TempKey);
|
|
3158
3158
|
}
|
|
3159
3159
|
function getHandshakeHash(state, out) {
|
|
3160
|
-
|
|
3161
|
-
|
|
3160
|
+
assert(state.byteLength === STATELEN);
|
|
3161
|
+
assert(out.byteLength === HASHLEN);
|
|
3162
3162
|
out.set(state.subarray(HASH_BEGIN, HASH_END));
|
|
3163
3163
|
}
|
|
3164
3164
|
function encryptAndHash(state, ciphertext, plaintext) {
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3165
|
+
assert(state.byteLength === STATELEN);
|
|
3166
|
+
assert(ciphertext.byteLength != null);
|
|
3167
|
+
assert(plaintext.byteLength != null);
|
|
3168
3168
|
var cstate = state.subarray(CIPHER_BEGIN, CIPHER_END);
|
|
3169
3169
|
var h = state.subarray(HASH_BEGIN, HASH_END);
|
|
3170
3170
|
cipherState.encryptWithAd(cstate, ciphertext, h, plaintext);
|
|
@@ -3175,9 +3175,9 @@ var require_symmetric_state = __commonJS({
|
|
|
3175
3175
|
encryptAndHash.bytesRead = 0;
|
|
3176
3176
|
encryptAndHash.bytesWritten = 0;
|
|
3177
3177
|
function decryptAndHash(state, plaintext, ciphertext) {
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3178
|
+
assert(state.byteLength === STATELEN);
|
|
3179
|
+
assert(plaintext.byteLength != null);
|
|
3180
|
+
assert(ciphertext.byteLength != null);
|
|
3181
3181
|
var cstate = state.subarray(CIPHER_BEGIN, CIPHER_END);
|
|
3182
3182
|
var h = state.subarray(HASH_BEGIN, HASH_END);
|
|
3183
3183
|
cipherState.decryptWithAd(cstate, plaintext, h, ciphertext);
|
|
@@ -3191,9 +3191,9 @@ var require_symmetric_state = __commonJS({
|
|
|
3191
3191
|
var TempKey2 = sodium_malloc(HASHLEN);
|
|
3192
3192
|
var zerolen = new Uint8Array(0);
|
|
3193
3193
|
function split(state, cipherstate1, cipherstate2) {
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3194
|
+
assert(state.byteLength === STATELEN);
|
|
3195
|
+
assert(cipherstate1.byteLength === cipherState.STATELEN);
|
|
3196
|
+
assert(cipherstate2.byteLength === cipherState.STATELEN);
|
|
3197
3197
|
hash.hkdf(
|
|
3198
3198
|
TempKey1,
|
|
3199
3199
|
TempKey2,
|
|
@@ -3216,7 +3216,7 @@ var require_symmetric_state = __commonJS({
|
|
|
3216
3216
|
var require_handshake_state = __commonJS({
|
|
3217
3217
|
"node_modules/.pnpm/noise-protocol@3.0.1/node_modules/noise-protocol/handshake-state.js"(exports, module) {
|
|
3218
3218
|
var { sodium_malloc, sodium_memzero, sodium_free } = import$sodium_universal_memory;
|
|
3219
|
-
var
|
|
3219
|
+
var assert = require_nanoassert();
|
|
3220
3220
|
var clone = require_clone();
|
|
3221
3221
|
var symmetricState = require_symmetric_state();
|
|
3222
3222
|
var cipherState = require_cipher_state();
|
|
@@ -3385,36 +3385,36 @@ var require_handshake_state = __commonJS({
|
|
|
3385
3385
|
return buf;
|
|
3386
3386
|
}
|
|
3387
3387
|
function initialize(handshakePattern, initiator, prologue, s, e, rs, re) {
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3388
|
+
assert(Object.keys(PATTERNS).includes(handshakePattern), "Unsupported handshake pattern");
|
|
3389
|
+
assert(typeof initiator === "boolean", "Initiator must be a boolean");
|
|
3390
|
+
assert(prologue.byteLength != null, "prolouge must be a Buffer");
|
|
3391
|
+
assert(e == null ? true : e.publicKey.byteLength === dh.PKLEN, `e.publicKey must be ${dh.PKLEN} bytes`);
|
|
3392
|
+
assert(e == null ? true : e.secretKey.byteLength === dh.SKLEN, `e.secretKey must be ${dh.SKLEN} bytes`);
|
|
3393
|
+
assert(rs == null ? true : rs.byteLength === dh.PKLEN, `rs must be ${dh.PKLEN} bytes`);
|
|
3394
|
+
assert(re == null ? true : re.byteLength === dh.PKLEN, `re must be ${dh.PKLEN} bytes`);
|
|
3395
3395
|
var state = new HandshakeState();
|
|
3396
3396
|
var protocolName = Uint8Array.from(`Noise_${handshakePattern}_25519_ChaChaPoly_BLAKE2b`, toCharCode);
|
|
3397
3397
|
symmetricState.initializeSymmetric(state.symmetricState, protocolName);
|
|
3398
3398
|
symmetricState.mixHash(state.symmetricState, prologue);
|
|
3399
3399
|
state.role = initiator === true ? INITIATOR : RESPONDER;
|
|
3400
3400
|
if (s != null) {
|
|
3401
|
-
|
|
3402
|
-
|
|
3401
|
+
assert(s.publicKey.byteLength === dh.PKLEN, `s.publicKey must be ${dh.PKLEN} bytes`);
|
|
3402
|
+
assert(s.secretKey.byteLength === dh.SKLEN, `s.secretKey must be ${dh.SKLEN} bytes`);
|
|
3403
3403
|
state.spk = sodiumBufferCopy(s.publicKey);
|
|
3404
3404
|
state.ssk = sodiumBufferCopy(s.secretKey);
|
|
3405
3405
|
}
|
|
3406
3406
|
if (e != null) {
|
|
3407
|
-
|
|
3408
|
-
|
|
3407
|
+
assert(e.publicKey.byteLength === dh.PKLEN);
|
|
3408
|
+
assert(e.secretKey.byteLength === dh.SKLEN);
|
|
3409
3409
|
state.epk = sodiumBufferCopy(e.publicKey);
|
|
3410
3410
|
state.esk = sodiumBufferCopy(e.secretKey);
|
|
3411
3411
|
}
|
|
3412
3412
|
if (rs != null) {
|
|
3413
|
-
|
|
3413
|
+
assert(rs.byteLength === dh.PKLEN);
|
|
3414
3414
|
state.rs = sodiumBufferCopy(rs);
|
|
3415
3415
|
}
|
|
3416
3416
|
if (re != null) {
|
|
3417
|
-
|
|
3417
|
+
assert(re.byteLength === dh.PKLEN);
|
|
3418
3418
|
state.re = sodiumBufferCopy(re);
|
|
3419
3419
|
}
|
|
3420
3420
|
var pat = PATTERNS[handshakePattern];
|
|
@@ -3423,11 +3423,11 @@ var require_handshake_state = __commonJS({
|
|
|
3423
3423
|
for (var token of pattern) {
|
|
3424
3424
|
switch (token) {
|
|
3425
3425
|
case TOK_E:
|
|
3426
|
-
|
|
3426
|
+
assert(state.role === patternRole ? state.epk.byteLength != null : state.re.byteLength != null);
|
|
3427
3427
|
symmetricState.mixHash(state.symmetricState, state.role === patternRole ? state.epk : state.re);
|
|
3428
3428
|
break;
|
|
3429
3429
|
case TOK_S:
|
|
3430
|
-
|
|
3430
|
+
assert(state.role === patternRole ? state.spk.byteLength != null : state.rs.byteLength != null);
|
|
3431
3431
|
symmetricState.mixHash(state.symmetricState, state.role === patternRole ? state.spk : state.rs);
|
|
3432
3432
|
break;
|
|
3433
3433
|
default:
|
|
@@ -3436,7 +3436,7 @@ var require_handshake_state = __commonJS({
|
|
|
3436
3436
|
}
|
|
3437
3437
|
}
|
|
3438
3438
|
state.messagePatterns = clone(pat.messagePatterns);
|
|
3439
|
-
|
|
3439
|
+
assert(
|
|
3440
3440
|
state.messagePatterns.filter((p) => p[0] === INITIATOR).some((p) => p.includes(TOK_S)) ? state.spk !== null && state.ssk !== null : true,
|
|
3441
3441
|
// Default if none is found
|
|
3442
3442
|
"This handshake pattern requires a static keypair"
|
|
@@ -3445,18 +3445,18 @@ var require_handshake_state = __commonJS({
|
|
|
3445
3445
|
}
|
|
3446
3446
|
var DhResult = sodium_malloc(dh.DHLEN);
|
|
3447
3447
|
function writeMessage(state, payload, messageBuffer) {
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
|
|
3448
|
+
assert(state instanceof HandshakeState);
|
|
3449
|
+
assert(payload.byteLength != null);
|
|
3450
|
+
assert(messageBuffer.byteLength != null);
|
|
3451
3451
|
var mpat = state.messagePatterns.shift();
|
|
3452
3452
|
var moffset = 0;
|
|
3453
|
-
|
|
3454
|
-
|
|
3453
|
+
assert(mpat != null);
|
|
3454
|
+
assert(state.role === mpat.shift());
|
|
3455
3455
|
for (var token of mpat) {
|
|
3456
3456
|
switch (token) {
|
|
3457
3457
|
case TOK_E:
|
|
3458
|
-
|
|
3459
|
-
|
|
3458
|
+
assert(state.epk == null);
|
|
3459
|
+
assert(state.esk == null);
|
|
3460
3460
|
state.epk = sodium_malloc(dh.PKLEN);
|
|
3461
3461
|
state.esk = sodium_malloc(dh.SKLEN);
|
|
3462
3462
|
dh.generateKeypair(state.epk, state.esk);
|
|
@@ -3465,7 +3465,7 @@ var require_handshake_state = __commonJS({
|
|
|
3465
3465
|
symmetricState.mixHash(state.symmetricState, state.epk);
|
|
3466
3466
|
break;
|
|
3467
3467
|
case TOK_S:
|
|
3468
|
-
|
|
3468
|
+
assert(state.spk.byteLength === dh.PKLEN);
|
|
3469
3469
|
symmetricState.encryptAndHash(state.symmetricState, messageBuffer.subarray(moffset), state.spk);
|
|
3470
3470
|
moffset += symmetricState.encryptAndHash.bytesWritten;
|
|
3471
3471
|
break;
|
|
@@ -3511,25 +3511,25 @@ var require_handshake_state = __commonJS({
|
|
|
3511
3511
|
}
|
|
3512
3512
|
writeMessage.bytes = 0;
|
|
3513
3513
|
function readMessage(state, message, payloadBuffer) {
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3514
|
+
assert(state instanceof HandshakeState);
|
|
3515
|
+
assert(message.byteLength != null);
|
|
3516
|
+
assert(payloadBuffer.byteLength != null);
|
|
3517
3517
|
var mpat = state.messagePatterns.shift();
|
|
3518
3518
|
var moffset = 0;
|
|
3519
|
-
|
|
3520
|
-
|
|
3519
|
+
assert(mpat != null);
|
|
3520
|
+
assert(mpat.shift() !== state.role);
|
|
3521
3521
|
for (var token of mpat) {
|
|
3522
3522
|
switch (token) {
|
|
3523
3523
|
case TOK_E:
|
|
3524
|
-
|
|
3525
|
-
|
|
3524
|
+
assert(state.re == null);
|
|
3525
|
+
assert(message.byteLength - moffset >= dh.PKLEN);
|
|
3526
3526
|
state.re = sodium_malloc(dh.PKLEN);
|
|
3527
3527
|
state.re.set(message.subarray(moffset, moffset + dh.PKLEN));
|
|
3528
3528
|
moffset += dh.PKLEN;
|
|
3529
3529
|
symmetricState.mixHash(state.symmetricState, state.re);
|
|
3530
3530
|
break;
|
|
3531
3531
|
case TOK_S:
|
|
3532
|
-
|
|
3532
|
+
assert(state.rs == null);
|
|
3533
3533
|
state.rs = sodium_malloc(dh.PKLEN);
|
|
3534
3534
|
var bytes = 0;
|
|
3535
3535
|
if (symmetricState._hasKey(state.symmetricState)) {
|
|
@@ -3537,7 +3537,7 @@ var require_handshake_state = __commonJS({
|
|
|
3537
3537
|
} else {
|
|
3538
3538
|
bytes = dh.PKLEN;
|
|
3539
3539
|
}
|
|
3540
|
-
|
|
3540
|
+
assert(message.byteLength - moffset >= bytes);
|
|
3541
3541
|
symmetricState.decryptAndHash(
|
|
3542
3542
|
state.symmetricState,
|
|
3543
3543
|
state.rs,
|
|
@@ -3654,7 +3654,7 @@ var require_simple_handshake = __commonJS({
|
|
|
3654
3654
|
var noise = require_noise_protocol();
|
|
3655
3655
|
var NoiseSymmetricState = require_symmetric_state();
|
|
3656
3656
|
var NoiseHash = require_hash();
|
|
3657
|
-
var
|
|
3657
|
+
var assert = require_nanoassert();
|
|
3658
3658
|
var EMPTY = Buffer.alloc(0);
|
|
3659
3659
|
function SimpleHandshake(isInitiator, opts) {
|
|
3660
3660
|
if (!(this instanceof SimpleHandshake))
|
|
@@ -3689,11 +3689,11 @@ var require_simple_handshake = __commonJS({
|
|
|
3689
3689
|
}
|
|
3690
3690
|
SimpleHandshake.prototype.recv = function recv(data, cb) {
|
|
3691
3691
|
var self = this;
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
|
|
3692
|
+
assert(self.finished === false, "Should not call recv if finished");
|
|
3693
|
+
assert(data != null, "must have data");
|
|
3694
|
+
assert(data.byteLength <= self._rx.byteLength, "too much data received");
|
|
3695
|
+
assert(self.waiting === true, "Wrong state, not ready to receive data");
|
|
3696
|
+
assert(self.split == null, "split should be null");
|
|
3697
3697
|
var hasREBefore = self.state.re != null;
|
|
3698
3698
|
var hasRSBefore = self.state.rs != null;
|
|
3699
3699
|
try {
|
|
@@ -3726,9 +3726,9 @@ var require_simple_handshake = __commonJS({
|
|
|
3726
3726
|
}
|
|
3727
3727
|
};
|
|
3728
3728
|
SimpleHandshake.prototype.send = function send(data, cb) {
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
|
|
3729
|
+
assert(this.finished === false, "Should not call send if finished");
|
|
3730
|
+
assert(this.waiting === false, "Wrong state, not ready to send data");
|
|
3731
|
+
assert(this.split == null, "split should be null");
|
|
3732
3732
|
data = data || EMPTY;
|
|
3733
3733
|
try {
|
|
3734
3734
|
this.split = noise.writeMessage(this.state, data, this._tx);
|
|
@@ -3746,7 +3746,7 @@ var require_simple_handshake = __commonJS({
|
|
|
3746
3746
|
});
|
|
3747
3747
|
};
|
|
3748
3748
|
SimpleHandshake.prototype._finish = function _finish(err, msg, cb) {
|
|
3749
|
-
|
|
3749
|
+
assert(this.finished === false, "Already finished");
|
|
3750
3750
|
const self = this;
|
|
3751
3751
|
self.finished = true;
|
|
3752
3752
|
self.waiting = false;
|
|
@@ -11281,8 +11281,8 @@ var require_hypercore = __commonJS({
|
|
|
11281
11281
|
var import_hypercore2 = __toESM(require_hypercore());
|
|
11282
11282
|
|
|
11283
11283
|
// packages/common/hypercore/src/crypto.ts
|
|
11284
|
-
import assert from "@dxos/node-std/assert";
|
|
11285
11284
|
import { callbackify } from "@dxos/node-std/util";
|
|
11285
|
+
import invariant from "tiny-invariant";
|
|
11286
11286
|
import { verifySignature } from "@dxos/crypto";
|
|
11287
11287
|
import { arrayToBuffer } from "@dxos/util";
|
|
11288
11288
|
var createCodecEncoding = (codec, opts) => ({
|
|
@@ -11290,8 +11290,8 @@ var createCodecEncoding = (codec, opts) => ({
|
|
|
11290
11290
|
decode: (buffer) => codec.decode(buffer, opts)
|
|
11291
11291
|
});
|
|
11292
11292
|
var createCrypto = (signer, publicKey) => {
|
|
11293
|
-
|
|
11294
|
-
|
|
11293
|
+
invariant(signer);
|
|
11294
|
+
invariant(publicKey);
|
|
11295
11295
|
return {
|
|
11296
11296
|
sign: (message, secretKey, cb) => {
|
|
11297
11297
|
callbackify(signer.sign.bind(signer))(publicKey, message, (err, result) => {
|
|
@@ -11337,7 +11337,7 @@ var defaultReplicateOptions = {
|
|
|
11337
11337
|
|
|
11338
11338
|
// packages/common/hypercore/src/hypercore-factory.ts
|
|
11339
11339
|
var import_hypercore = __toESM(require_hypercore());
|
|
11340
|
-
import
|
|
11340
|
+
import invariant2 from "tiny-invariant";
|
|
11341
11341
|
import { createStorage, StorageType } from "@dxos/random-access-storage";
|
|
11342
11342
|
|
|
11343
11343
|
// packages/common/hypercore/src/util.ts
|
|
@@ -11352,7 +11352,7 @@ var HypercoreFactory = class {
|
|
|
11352
11352
|
}).createDirectory(), _options) {
|
|
11353
11353
|
this._root = _root;
|
|
11354
11354
|
this._options = _options;
|
|
11355
|
-
|
|
11355
|
+
invariant2(this._root);
|
|
11356
11356
|
}
|
|
11357
11357
|
/**
|
|
11358
11358
|
* Creates a feed using a storage factory prefixed with the feed's key.
|