@libp2p/noise 1.0.0-049bfa0fa
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 +95 -0
- package/dist/index.min.js +23 -0
- package/dist/index.min.js.map +7 -0
- package/dist/src/constants.d.ts +5 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.js +5 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/crypto/index.browser.d.ts +2 -0
- package/dist/src/crypto/index.browser.d.ts.map +1 -0
- package/dist/src/crypto/index.browser.js +3 -0
- package/dist/src/crypto/index.browser.js.map +1 -0
- package/dist/src/crypto/index.d.ts +3 -0
- package/dist/src/crypto/index.d.ts.map +1 -0
- package/dist/src/crypto/index.js +188 -0
- package/dist/src/crypto/index.js.map +1 -0
- package/dist/src/crypto/js.d.ts +3 -0
- package/dist/src/crypto/js.d.ts.map +1 -0
- package/dist/src/crypto/js.js +43 -0
- package/dist/src/crypto/js.js.map +1 -0
- package/dist/src/crypto.d.ts +14 -0
- package/dist/src/crypto.d.ts.map +1 -0
- package/dist/src/crypto.js +11 -0
- package/dist/src/crypto.js.map +1 -0
- package/dist/src/encoder.d.ts +10 -0
- package/dist/src/encoder.d.ts.map +1 -0
- package/dist/src/encoder.js +22 -0
- package/dist/src/encoder.js.map +1 -0
- package/dist/src/errors.d.ts +6 -0
- package/dist/src/errors.d.ts.map +1 -0
- package/dist/src/errors.js +9 -0
- package/dist/src/errors.js.map +1 -0
- package/dist/src/index.d.ts +52 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +43 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/logger.d.ts +10 -0
- package/dist/src/logger.d.ts.map +1 -0
- package/dist/src/logger.js +56 -0
- package/dist/src/logger.js.map +1 -0
- package/dist/src/metrics.d.ts +4 -0
- package/dist/src/metrics.d.ts.map +1 -0
- package/dist/src/metrics.js +20 -0
- package/dist/src/metrics.js.map +1 -0
- package/dist/src/noise.d.ts +58 -0
- package/dist/src/noise.d.ts.map +1 -0
- package/dist/src/noise.js +174 -0
- package/dist/src/noise.js.map +1 -0
- package/dist/src/nonce.d.ts +17 -0
- package/dist/src/nonce.d.ts.map +1 -0
- package/dist/src/nonce.js +42 -0
- package/dist/src/nonce.js.map +1 -0
- package/dist/src/performHandshake.d.ts +5 -0
- package/dist/src/performHandshake.d.ts.map +1 -0
- package/dist/src/performHandshake.js +69 -0
- package/dist/src/performHandshake.js.map +1 -0
- package/dist/src/proto/payload.d.ts +22 -0
- package/dist/src/proto/payload.d.ts.map +1 -0
- package/dist/src/proto/payload.js +133 -0
- package/dist/src/proto/payload.js.map +1 -0
- package/dist/src/protocol.d.ts +71 -0
- package/dist/src/protocol.d.ts.map +1 -0
- package/dist/src/protocol.js +257 -0
- package/dist/src/protocol.js.map +1 -0
- package/dist/src/types.d.ts +98 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/utils.d.ts +11 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +176 -0
- package/dist/src/utils.js.map +1 -0
- package/package.json +94 -0
- package/src/constants.ts +5 -0
- package/src/crypto/index.browser.ts +3 -0
- package/src/crypto/index.ts +219 -0
- package/src/crypto/js.ts +56 -0
- package/src/crypto.ts +27 -0
- package/src/encoder.ts +24 -0
- package/src/errors.ts +10 -0
- package/src/index.ts +58 -0
- package/src/logger.ts +65 -0
- package/src/metrics.ts +32 -0
- package/src/noise.ts +237 -0
- package/src/nonce.ts +49 -0
- package/src/performHandshake.ts +91 -0
- package/src/proto/payload.proto +12 -0
- package/src/proto/payload.ts +170 -0
- package/src/protocol.ts +313 -0
- package/src/types.ts +105 -0
- package/src/utils.ts +221 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,0BAA0B,QAAQ,CAAA;AAC/C,eAAO,MAAM,sCAAsC,QAAkC,CAAA;AAErF,eAAO,MAAM,iBAAiB,SAAsD,CAAA;AACpF,eAAO,MAAM,iBAAiB,KAAK,CAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export const NOISE_MSG_MAX_LENGTH_BYTES = 65535;
|
|
2
|
+
export const NOISE_MSG_MAX_LENGTH_BYTES_WITHOUT_TAG = NOISE_MSG_MAX_LENGTH_BYTES - 16;
|
|
3
|
+
export const DUMP_SESSION_KEYS = Boolean(globalThis.process?.env?.DUMP_SESSION_KEYS);
|
|
4
|
+
export const CHACHA_TAG_LENGTH = 16;
|
|
5
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,0BAA0B,GAAG,KAAK,CAAA;AAC/C,MAAM,CAAC,MAAM,sCAAsC,GAAG,0BAA0B,GAAG,EAAE,CAAA;AAErF,MAAM,CAAC,MAAM,iBAAiB,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,EAAE,iBAAiB,CAAC,CAAA;AACpF,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.browser.d.ts","sourceRoot":"","sources":["../../../src/crypto/index.browser.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,yCAAe,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.browser.js","sourceRoot":"","sources":["../../../src/crypto/index.browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAEtC,MAAM,CAAC,MAAM,aAAa,GAAG,YAAY,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/crypto/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAuHpD,eAAO,MAAM,aAAa,EAAE,gBAuF3B,CAAA"}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import { newInstance, ChaCha20Poly1305 } from '@chainsafe/as-chacha20poly1305';
|
|
3
|
+
import { digest } from '@chainsafe/as-sha256';
|
|
4
|
+
import { Uint8ArrayList } from 'uint8arraylist';
|
|
5
|
+
import { isElectronMain } from 'wherearewe';
|
|
6
|
+
import { pureJsCrypto } from './js.js';
|
|
7
|
+
const ctx = newInstance();
|
|
8
|
+
const asImpl = new ChaCha20Poly1305(ctx);
|
|
9
|
+
const CHACHA_POLY1305 = 'chacha20-poly1305';
|
|
10
|
+
const PKCS8_PREFIX = Buffer.from([0x30, 0x2e, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x6e, 0x04, 0x22, 0x04, 0x20]);
|
|
11
|
+
const X25519_PREFIX = Buffer.from([0x30, 0x2a, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x6e, 0x03, 0x21, 0x00]);
|
|
12
|
+
const nodeCrypto = {
|
|
13
|
+
hashSHA256(data) {
|
|
14
|
+
const hash = crypto.createHash('sha256');
|
|
15
|
+
if (data instanceof Uint8Array) {
|
|
16
|
+
return hash.update(data).digest();
|
|
17
|
+
}
|
|
18
|
+
for (const buf of data) {
|
|
19
|
+
hash.update(buf);
|
|
20
|
+
}
|
|
21
|
+
return hash.digest();
|
|
22
|
+
},
|
|
23
|
+
chaCha20Poly1305Encrypt(plaintext, nonce, ad, k) {
|
|
24
|
+
const cipher = crypto.createCipheriv(CHACHA_POLY1305, k, nonce, {
|
|
25
|
+
authTagLength: 16
|
|
26
|
+
});
|
|
27
|
+
cipher.setAAD(ad, { plaintextLength: plaintext.byteLength });
|
|
28
|
+
if (plaintext instanceof Uint8Array) {
|
|
29
|
+
const updated = cipher.update(plaintext);
|
|
30
|
+
const final = cipher.final();
|
|
31
|
+
const tag = cipher.getAuthTag();
|
|
32
|
+
return Buffer.concat([updated, final, tag], updated.byteLength + final.byteLength + tag.byteLength);
|
|
33
|
+
}
|
|
34
|
+
const output = new Uint8ArrayList();
|
|
35
|
+
for (const buf of plaintext) {
|
|
36
|
+
output.append(cipher.update(buf));
|
|
37
|
+
}
|
|
38
|
+
const final = cipher.final();
|
|
39
|
+
if (final.byteLength > 0) {
|
|
40
|
+
output.append(final);
|
|
41
|
+
}
|
|
42
|
+
output.append(cipher.getAuthTag());
|
|
43
|
+
return output;
|
|
44
|
+
},
|
|
45
|
+
chaCha20Poly1305Decrypt(ciphertext, nonce, ad, k, _dst) {
|
|
46
|
+
const authTag = ciphertext.subarray(ciphertext.length - 16);
|
|
47
|
+
const decipher = crypto.createDecipheriv(CHACHA_POLY1305, k, nonce, {
|
|
48
|
+
authTagLength: 16
|
|
49
|
+
});
|
|
50
|
+
let text;
|
|
51
|
+
if (ciphertext instanceof Uint8Array) {
|
|
52
|
+
text = ciphertext.subarray(0, ciphertext.length - 16);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
text = ciphertext.sublist(0, ciphertext.length - 16);
|
|
56
|
+
}
|
|
57
|
+
decipher.setAAD(ad, {
|
|
58
|
+
plaintextLength: text.byteLength
|
|
59
|
+
});
|
|
60
|
+
decipher.setAuthTag(authTag);
|
|
61
|
+
if (text instanceof Uint8Array) {
|
|
62
|
+
const output = decipher.update(text);
|
|
63
|
+
const final = decipher.final();
|
|
64
|
+
if (final.byteLength > 0) {
|
|
65
|
+
return Buffer.concat([output, final], output.byteLength + final.byteLength);
|
|
66
|
+
}
|
|
67
|
+
return output;
|
|
68
|
+
}
|
|
69
|
+
const output = new Uint8ArrayList();
|
|
70
|
+
for (const buf of text) {
|
|
71
|
+
output.append(decipher.update(buf));
|
|
72
|
+
}
|
|
73
|
+
const final = decipher.final();
|
|
74
|
+
if (final.byteLength > 0) {
|
|
75
|
+
output.append(final);
|
|
76
|
+
}
|
|
77
|
+
return output;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const asCrypto = {
|
|
81
|
+
hashSHA256(data) {
|
|
82
|
+
return digest(data.subarray());
|
|
83
|
+
},
|
|
84
|
+
chaCha20Poly1305Encrypt(plaintext, nonce, ad, k) {
|
|
85
|
+
return asImpl.seal(k, nonce, plaintext.subarray(), ad);
|
|
86
|
+
},
|
|
87
|
+
chaCha20Poly1305Decrypt(ciphertext, nonce, ad, k, dst) {
|
|
88
|
+
const plaintext = asImpl.open(k, nonce, ciphertext.subarray(), ad, dst);
|
|
89
|
+
if (!plaintext) {
|
|
90
|
+
throw new Error('Invalid chacha20poly1305 decryption');
|
|
91
|
+
}
|
|
92
|
+
return plaintext;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
// benchmarks show that for chacha20poly1305
|
|
96
|
+
// the as implementation is faster for smaller payloads(<1200)
|
|
97
|
+
// and the node implementation is faster for larger payloads
|
|
98
|
+
export const defaultCrypto = {
|
|
99
|
+
...pureJsCrypto,
|
|
100
|
+
hashSHA256(data) {
|
|
101
|
+
return nodeCrypto.hashSHA256(data);
|
|
102
|
+
},
|
|
103
|
+
chaCha20Poly1305Encrypt(plaintext, nonce, ad, k) {
|
|
104
|
+
if (plaintext.byteLength < 1200) {
|
|
105
|
+
return asCrypto.chaCha20Poly1305Encrypt(plaintext, nonce, ad, k);
|
|
106
|
+
}
|
|
107
|
+
return nodeCrypto.chaCha20Poly1305Encrypt(plaintext, nonce, ad, k);
|
|
108
|
+
},
|
|
109
|
+
chaCha20Poly1305Decrypt(ciphertext, nonce, ad, k, dst) {
|
|
110
|
+
if (ciphertext.byteLength < 1200) {
|
|
111
|
+
return asCrypto.chaCha20Poly1305Decrypt(ciphertext, nonce, ad, k, dst);
|
|
112
|
+
}
|
|
113
|
+
return nodeCrypto.chaCha20Poly1305Decrypt(ciphertext, nonce, ad, k, dst);
|
|
114
|
+
},
|
|
115
|
+
generateX25519KeyPair() {
|
|
116
|
+
const { publicKey, privateKey } = crypto.generateKeyPairSync('x25519', {
|
|
117
|
+
publicKeyEncoding: {
|
|
118
|
+
type: 'spki',
|
|
119
|
+
format: 'der'
|
|
120
|
+
},
|
|
121
|
+
privateKeyEncoding: {
|
|
122
|
+
type: 'pkcs8',
|
|
123
|
+
format: 'der'
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
return {
|
|
127
|
+
publicKey: publicKey.subarray(X25519_PREFIX.length),
|
|
128
|
+
privateKey: privateKey.subarray(PKCS8_PREFIX.length)
|
|
129
|
+
};
|
|
130
|
+
},
|
|
131
|
+
generateX25519KeyPairFromSeed(seed) {
|
|
132
|
+
const privateKey = crypto.createPrivateKey({
|
|
133
|
+
key: Buffer.concat([
|
|
134
|
+
PKCS8_PREFIX,
|
|
135
|
+
seed
|
|
136
|
+
], PKCS8_PREFIX.byteLength + seed.byteLength),
|
|
137
|
+
type: 'pkcs8',
|
|
138
|
+
format: 'der'
|
|
139
|
+
});
|
|
140
|
+
const publicKey = crypto.createPublicKey(privateKey)
|
|
141
|
+
.export({
|
|
142
|
+
type: 'spki',
|
|
143
|
+
format: 'der'
|
|
144
|
+
}).subarray(X25519_PREFIX.length);
|
|
145
|
+
return {
|
|
146
|
+
publicKey,
|
|
147
|
+
privateKey: seed
|
|
148
|
+
};
|
|
149
|
+
},
|
|
150
|
+
generateX25519SharedKey(privateKey, publicKey) {
|
|
151
|
+
if (publicKey instanceof Uint8Array) {
|
|
152
|
+
publicKey = Buffer.concat([
|
|
153
|
+
X25519_PREFIX,
|
|
154
|
+
publicKey
|
|
155
|
+
], X25519_PREFIX.byteLength + publicKey.byteLength);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
publicKey = new Uint8ArrayList(X25519_PREFIX, publicKey).subarray();
|
|
159
|
+
}
|
|
160
|
+
if (privateKey instanceof Uint8Array) {
|
|
161
|
+
privateKey = Buffer.concat([
|
|
162
|
+
PKCS8_PREFIX,
|
|
163
|
+
privateKey
|
|
164
|
+
], PKCS8_PREFIX.byteLength + privateKey.byteLength);
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
privateKey = new Uint8ArrayList(PKCS8_PREFIX, privateKey).subarray();
|
|
168
|
+
}
|
|
169
|
+
return crypto.diffieHellman({
|
|
170
|
+
publicKey: crypto.createPublicKey({
|
|
171
|
+
key: Buffer.from(publicKey.buffer, publicKey.byteOffset, publicKey.byteLength),
|
|
172
|
+
type: 'spki',
|
|
173
|
+
format: 'der'
|
|
174
|
+
}),
|
|
175
|
+
privateKey: crypto.createPrivateKey({
|
|
176
|
+
key: Buffer.from(privateKey.buffer, privateKey.byteOffset, privateKey.byteLength),
|
|
177
|
+
type: 'pkcs8',
|
|
178
|
+
format: 'der'
|
|
179
|
+
})
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
// no chacha20-poly1305 in electron https://github.com/electron/electron/issues/24024
|
|
184
|
+
if (isElectronMain) {
|
|
185
|
+
defaultCrypto.chaCha20Poly1305Encrypt = asCrypto.chaCha20Poly1305Encrypt;
|
|
186
|
+
defaultCrypto.chaCha20Poly1305Decrypt = asCrypto.chaCha20Poly1305Decrypt;
|
|
187
|
+
}
|
|
188
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/crypto/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAA;AAChC,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AAC9E,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,EAAE,YAAY,E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AAC;IACnB,aAAa,CAAC,uBAAuB,GAAG,QAAQ,CAAC,uBAAuB,CAAA;IACxE,aAAa,CAAC,uBAAuB,GAAG,QAAQ,CAAC,uBAAuB,CAAA;AAC1E,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"js.d.ts","sourceRoot":"","sources":["../../../src/crypto/js.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAIpD,eAAO,MAAM,YAAY,EAAE,gBA+C1B,CAAA"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { chacha20poly1305 } from '@noble/ciphers/chacha';
|
|
2
|
+
import { x25519 } from '@noble/curves/ed25519';
|
|
3
|
+
import { extract, expand } from '@noble/hashes/hkdf';
|
|
4
|
+
import { sha256 } from '@noble/hashes/sha2';
|
|
5
|
+
export const pureJsCrypto = {
|
|
6
|
+
hashSHA256(data) {
|
|
7
|
+
return sha256(data.subarray());
|
|
8
|
+
},
|
|
9
|
+
getHKDF(ck, ikm) {
|
|
10
|
+
const prk = extract(sha256, ikm, ck);
|
|
11
|
+
const okmU8Array = expand(sha256, prk, undefined, 96);
|
|
12
|
+
const okm = okmU8Array;
|
|
13
|
+
const k1 = okm.subarray(0, 32);
|
|
14
|
+
const k2 = okm.subarray(32, 64);
|
|
15
|
+
const k3 = okm.subarray(64, 96);
|
|
16
|
+
return [k1, k2, k3];
|
|
17
|
+
},
|
|
18
|
+
generateX25519KeyPair() {
|
|
19
|
+
const secretKey = x25519.utils.randomSecretKey();
|
|
20
|
+
const publicKey = x25519.getPublicKey(secretKey);
|
|
21
|
+
return {
|
|
22
|
+
publicKey,
|
|
23
|
+
privateKey: secretKey
|
|
24
|
+
};
|
|
25
|
+
},
|
|
26
|
+
generateX25519KeyPairFromSeed(seed) {
|
|
27
|
+
const publicKey = x25519.getPublicKey(seed);
|
|
28
|
+
return {
|
|
29
|
+
publicKey,
|
|
30
|
+
privateKey: seed
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
generateX25519SharedKey(privateKey, publicKey) {
|
|
34
|
+
return x25519.getSharedSecret(privateKey.subarray(), publicKey.subarray());
|
|
35
|
+
},
|
|
36
|
+
chaCha20Poly1305Encrypt(plaintext, nonce, ad, k) {
|
|
37
|
+
return chacha20poly1305(k, nonce, ad).encrypt(plaintext.subarray());
|
|
38
|
+
},
|
|
39
|
+
chaCha20Poly1305Decrypt(ciphertext, nonce, ad, k, dst) {
|
|
40
|
+
return chacha20poly1305(k, nonce, ad).decrypt(ciphertext.subarray(), dst);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=js.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"js.js","sourceRoot":"","sources":["../../../src/crypto/js.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAK3C,MAAM,CAAC,MAAM,YAAY,GAAqB;IAC5C,UAAU,CAAE,IAAiC;QAC3C,OAAO,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAA;IAChC,CAAC;IAED,OAAO,CAAE,EAAc,EAAE,GAAe;QACtC,MAAM,GAAG,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,CAAA;QACpC,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,CAAC,CAAA;QACrD,MAAM,GAAG,GAAG,UAAU,CAAA;QAEtB,MAAM,EAAE,GAAG,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;QAC9B,MAAM,EAAE,GAA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} from './types.js';
|
|
2
|
+
import type { Uint8ArrayList } from 'uint8arraylist';
|
|
3
|
+
/** Underlying crypto implementation, meant to be overridable */
|
|
4
|
+
export interface ICryptoInterface {
|
|
5
|
+
hashSHA256(data: Uint8Array | Uint8ArrayList): Uint8Array;
|
|
6
|
+
getHKDF(ck: Uint8Array, ikm: Uint8Array): [Uint8Array, Uint8Array, Uint8Array];
|
|
7
|
+
generateX25519KeyPair(): KeyPair;
|
|
8
|
+
generateX25519KeyPairFromSeed(seed: Uint8Array): KeyPair;
|
|
9
|
+
generateX25519SharedKey(privateKey: Uint8Array | Uint8ArrayList, publicKey: Uint8Array | Uint8ArrayList): Uint8Array;
|
|
10
|
+
chaCha20Poly1305Encrypt(plaintext: Uint8Array | Uint8ArrayList, nonce: Uint8Array, ad: Uint8Array, k: Uint8Array): Uint8ArrayList | Uint8Array;
|
|
11
|
+
chaCha20Poly1305Decrypt(ciphertext: Uint8Array | Uint8ArrayList, nonce: Uint8Array, ad: Uint8Array, k: Uint8Array, dst?: Uint8Array): Uint8ArrayList | Uint8Array;
|
|
12
|
+
}
|
|
13
|
+
export declare function wrapCrypto(crypto: ICryptoInterface): ICrypto;
|
|
14
|
+
//# sourceMappingURL=crypto.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../src/crypto.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD,gEAAgE;AAChE,MAAM,WAAW,gBAAgB;IAC/B,UAAU,CAAC,IAAI,EAAE,UAAU,GAAG,cAAc,GAAG,UAAU,CAAA;IAEzD,OAAO,CAAC,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,GAAG,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,CAAC,CAAA;IAE9E,qBAAqB,IAAI,OAAO,CAAA;IAChC,6BAA6B,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAA;IACxD,uBAAuB,CAAC,UAAU,EAAE,UAAU,GAAG,cAAc,EAAE,SAAS,EAAE,UAAU,GAAG,cAAc,GAAG,UAAU,CAAA;IAEpH,uBAAuB,CAAC,SAAS,EAAE,UAAU,GAAG,cAAc,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,cAAc,GAAG,UAAU,CAAA;IAC9I,uBAAuB,CAAC,UAAU,EAAE,UAAU,GAAG,cAAc,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,EAAE,GAAG,CAAC,EAAE,UAAU,GAAG,cAAc,GAAG,UAAU,CAAA;CAClK;AAED,wBAAgB,UAAU,CAAE,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAS7D"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function wrapCrypto(crypto) {
|
|
2
|
+
return {
|
|
3
|
+
generateKeypair: crypto.generateX25519KeyPair,
|
|
4
|
+
dh: (keypair, publicKey) => crypto.generateX25519SharedKey(keypair.privateKey, publicKey).subarray(0, 32),
|
|
5
|
+
encrypt: crypto.chaCha20Poly1305Encrypt,
|
|
6
|
+
decrypt: crypto.chaCha20Poly1305Decrypt,
|
|
7
|
+
hash: crypto.hashSHA256,
|
|
8
|
+
hkdf: crypto.getHKDF
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=crypto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../src/crypto.ts"],"names":[],"mappings":"AAiBA,MAAM,UAAU,UAAU,CAAE,MAAwB;IAClD,OAAO;QACL,eAAe,EAAE,MAAM,CAAC,qBAAqB;QAC7C,EAAE,EAAE,CAAC,OAAO,EAAE,SAAS,EAAE,EAAE,CAAC,MAAM,CAAC,uBAAuB,CAAC,OAAO,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC;QACzG,OAAO,EAAE,MAAM,CAAC,uBAAuB;QACvC,OAAO,EAAE,MAAM,CAAC,uBAAuB;QACvC,IAAI,EAAE,MAAM,CAAC,UAAU;QACvB,IAAI,EAAE,MAAM,CAAC,OAAO;KACrB,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Uint8ArrayList } from 'uint8arraylist';
|
|
2
|
+
export declare const uint16BEEncode: {
|
|
3
|
+
(value: number): Uint8Array;
|
|
4
|
+
bytes: number;
|
|
5
|
+
};
|
|
6
|
+
export declare const uint16BEDecode: {
|
|
7
|
+
(data: Uint8Array | Uint8ArrayList): number;
|
|
8
|
+
bytes: number;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=encoder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encoder.d.ts","sourceRoot":"","sources":["../../src/encoder.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD,eAAO,MAAM,cAAc;YAAW,MAAM,GAAG,UAAU;;CAKxD,CAAA;AAGD,eAAO,MAAM,cAAc;WAAU,UAAU,GAAG,cAAc,GAAG,MAAM;;CAWxE,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { allocUnsafe as uint8ArrayAllocUnsafe } from 'uint8arrays/alloc';
|
|
2
|
+
export const uint16BEEncode = (value) => {
|
|
3
|
+
const target = uint8ArrayAllocUnsafe(2);
|
|
4
|
+
target[0] = value >> 8;
|
|
5
|
+
target[1] = value;
|
|
6
|
+
return target;
|
|
7
|
+
};
|
|
8
|
+
uint16BEEncode.bytes = 2;
|
|
9
|
+
export const uint16BEDecode = (data) => {
|
|
10
|
+
if (data.length < 2) {
|
|
11
|
+
throw RangeError('Could not decode int16BE');
|
|
12
|
+
}
|
|
13
|
+
if (data instanceof Uint8Array) {
|
|
14
|
+
let value = 0;
|
|
15
|
+
value += data[0] << 8;
|
|
16
|
+
value += data[1];
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
return data.getUint16(0);
|
|
20
|
+
};
|
|
21
|
+
uint16BEDecode.bytes = 2;
|
|
22
|
+
//# sourceMappingURL=encoder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encoder.js","sourceRoot":"","sources":["../../src/encoder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,IAAI,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAGxE,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAa,EAAc,EAAE;IAC1D,MAAM,MAAM,GAAG,qBAAqB,CAAC,CAAC,CAAC,CAAA;IACvC,MAAM,CAAC,CAAC,CAAC,GAAG,KAAK,IAAI,CAAC,CAAA;IACtB,MAAM,CAAC,CAAC,CAAC,GAAG,KAAK,CAAA;IACjB,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AACD,cAAc,CAAC,KAAK,GAAG,CAAC,CAAA;AAExB,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,IAAiC,EAAU,EAAE;IAC1E,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAAC,MAAM,UAAU,CAAC,0BAA0B,CAAC,CAAA;IAAC,CAAC;IAErE,IAAI,IAAI,YAAY,UAAU,EAAE,CAAC;QAC/B,IAAI,KAAK,GAAG,CAAC,CAAA;QACb,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;QACrB,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,CAAA;QAChB,OAAO,KAAK,CAAA;IACd,CAAC;IAED,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;AAC1B,CAAC,CAAA;AACD,cAAc,CAAC,KAAK,GAAG,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,0BAA2B,SAAQ,KAAK;IAC5C,IAAI,EAAE,MAAM,CAAA;gBAEN,OAAO,SAA4B;IAKhD,MAAM,CAAC,QAAQ,CAAC,IAAI,iCAAgC;CACrD"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export class InvalidCryptoExchangeError extends Error {
|
|
2
|
+
code;
|
|
3
|
+
constructor(message = 'Invalid crypto exchange') {
|
|
4
|
+
super(message);
|
|
5
|
+
this.code = InvalidCryptoExchangeError.code;
|
|
6
|
+
}
|
|
7
|
+
static code = 'ERR_INVALID_CRYPTO_EXCHANGE';
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,0BAA2B,SAAQ,KAAK;IAC5C,IAAI,CAAQ;IAEnB,YAAa,OAAO,GAAG,yBAAyB;QAC9C,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC,IAAI,CAAA;IAC7C,CAAC;IAED,MAAM,CAAU,IAAI,GAAG,6BAA6B,CAAA"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
*
|
|
4
|
+
* This repository contains TypeScript implementation of noise protocol, an encryption protocol used in libp2p.
|
|
5
|
+
*
|
|
6
|
+
* ## Usage
|
|
7
|
+
*
|
|
8
|
+
* Install with `yarn add @libp2p/noise` or `npm i @libp2p/noise`.
|
|
9
|
+
*
|
|
10
|
+
* Example of using default noise configuration and passing it to the libp2p config:
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* import {createLibp2p} from "libp2p"
|
|
14
|
+
* import {noise} from "@libp2p/noise"
|
|
15
|
+
*
|
|
16
|
+
* //custom noise configuration, pass it instead of `noise()`
|
|
17
|
+
* //x25519 private key
|
|
18
|
+
* const n = noise({ staticNoiseKey });
|
|
19
|
+
*
|
|
20
|
+
* const libp2p = await createLibp2p({
|
|
21
|
+
* connectionEncrypters: [noise()],
|
|
22
|
+
* //... other options
|
|
23
|
+
* })
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* See the [NoiseInit](https://github.com/ChainSafe/js-libp2p-noise/blob/master/src/noise.ts#L22-L30) interface for noise configuration options.
|
|
27
|
+
*
|
|
28
|
+
* ## API
|
|
29
|
+
*
|
|
30
|
+
* This module exposes an implementation of the [ConnectionEncrypter](https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface.ConnectionEncrypter.html) interface.
|
|
31
|
+
*
|
|
32
|
+
* ## Bring your own crypto
|
|
33
|
+
*
|
|
34
|
+
* You can provide a custom crypto implementation (instead of the default, based on [@noble](https://paulmillr.com/noble/)) by adding a `crypto` field to the init argument passed to the `Noise` factory.
|
|
35
|
+
*
|
|
36
|
+
* The implementation must conform to the `ICryptoInterface`, defined in <https://github.com/ChainSafe/js-libp2p-noise/blob/master/src/crypto.ts>
|
|
37
|
+
*/
|
|
38
|
+
import type { NoiseInit, NoiseExtensions } from './noise.js';
|
|
39
|
+
import type { KeyPair } from './types.js';
|
|
40
|
+
import type { ComponentLogger, ConnectionEncrypter, Metrics, PeerId, PrivateKey, Upgrader } from '@libp2p/interface';
|
|
41
|
+
export { pureJsCrypto } from './crypto/js.js';
|
|
42
|
+
export type { ICryptoInterface } from './crypto.js';
|
|
43
|
+
export type { NoiseInit, NoiseExtensions, KeyPair };
|
|
44
|
+
export interface NoiseComponents {
|
|
45
|
+
peerId: PeerId;
|
|
46
|
+
privateKey: PrivateKey;
|
|
47
|
+
logger: ComponentLogger;
|
|
48
|
+
upgrader: Upgrader;
|
|
49
|
+
metrics?: Metrics;
|
|
50
|
+
}
|
|
51
|
+
export declare function noise(init?: NoiseInit): (components: NoiseComponents) => ConnectionEncrypter<NoiseExtensions>;
|
|
52
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAC5D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACzC,OAAO,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAEpH,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AACnD,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,CAAA;AAEnD,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,UAAU,CAAA;IACtB,MAAM,EAAE,eAAe,CAAA;IACvB,QAAQ,EAAE,QAAQ,CAAA;IAClB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,wBAAgB,KAAK,CAAE,IAAI,GAAE,SAAc,GAAG,CAAC,UAAU,EAAE,eAAe,KAAK,mBAAmB,CAAC,eAAe,CAAC,CAElH"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
*
|
|
4
|
+
* This repository contains TypeScript implementation of noise protocol, an encryption protocol used in libp2p.
|
|
5
|
+
*
|
|
6
|
+
* ## Usage
|
|
7
|
+
*
|
|
8
|
+
* Install with `yarn add @libp2p/noise` or `npm i @libp2p/noise`.
|
|
9
|
+
*
|
|
10
|
+
* Example of using default noise configuration and passing it to the libp2p config:
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* import {createLibp2p} from "libp2p"
|
|
14
|
+
* import {noise} from "@libp2p/noise"
|
|
15
|
+
*
|
|
16
|
+
* //custom noise configuration, pass it instead of `noise()`
|
|
17
|
+
* //x25519 private key
|
|
18
|
+
* const n = noise({ staticNoiseKey });
|
|
19
|
+
*
|
|
20
|
+
* const libp2p = await createLibp2p({
|
|
21
|
+
* connectionEncrypters: [noise()],
|
|
22
|
+
* //... other options
|
|
23
|
+
* })
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* See the [NoiseInit](https://github.com/ChainSafe/js-libp2p-noise/blob/master/src/noise.ts#L22-L30) interface for noise configuration options.
|
|
27
|
+
*
|
|
28
|
+
* ## API
|
|
29
|
+
*
|
|
30
|
+
* This module exposes an implementation of the [ConnectionEncrypter](https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface.ConnectionEncrypter.html) interface.
|
|
31
|
+
*
|
|
32
|
+
* ## Bring your own crypto
|
|
33
|
+
*
|
|
34
|
+
* You can provide a custom crypto implementation (instead of the default, based on [@noble](https://paulmillr.com/noble/)) by adding a `crypto` field to the init argument passed to the `Noise` factory.
|
|
35
|
+
*
|
|
36
|
+
* The implementation must conform to the `ICryptoInterface`, defined in <https://github.com/ChainSafe/js-libp2p-noise/blob/master/src/crypto.ts>
|
|
37
|
+
*/
|
|
38
|
+
import { Noise } from './noise.js';
|
|
39
|
+
export { pureJsCrypto } from './crypto/js.js';
|
|
40
|
+
export function noise(init = {}) {
|
|
41
|
+
return (components) => new Noise(components, init);
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAKlC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAY7C,MAAM,UAAU,KAAK,CAAE,OAAkB,EAAE;IACzC,OAAO,CAAC,UAA2B,EAAE,EAAE,CAAC,IAAI,KAAK,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;AACrE,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { CipherState } from './protocol.js';
|
|
2
|
+
import type { KeyPair } from './types.js';
|
|
3
|
+
import type { Logger } from '@libp2p/interface';
|
|
4
|
+
import type { Uint8ArrayList } from 'uint8arraylist';
|
|
5
|
+
export declare function logLocalStaticKeys(s: KeyPair | undefined, keyLogger: Logger): void;
|
|
6
|
+
export declare function logLocalEphemeralKeys(e: KeyPair | undefined, keyLogger: Logger): void;
|
|
7
|
+
export declare function logRemoteStaticKey(rs: Uint8Array | Uint8ArrayList | undefined, keyLogger: Logger): void;
|
|
8
|
+
export declare function logRemoteEphemeralKey(re: Uint8Array | Uint8ArrayList | undefined, keyLogger: Logger): void;
|
|
9
|
+
export declare function logCipherState(cs1: CipherState, cs2: CipherState, keyLogger: Logger): void;
|
|
10
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAChD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACzC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD,wBAAgB,kBAAkB,CAAE,CAAC,EAAE,OAAO,GAAG,SAAS,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAWnF;AAED,wBAAgB,qBAAqB,CAAE,CAAC,EAAE,OAAO,GAAG,SAAS,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAWtF;AAED,wBAAgB,kBAAkB,CAAE,EAAE,EAAE,UAAU,GAAG,cAAc,GAAG,SAAS,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAUxG;AAED,wBAAgB,qBAAqB,CAAE,EAAE,EAAE,UAAU,GAAG,cAAc,GAAG,SAAS,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAU3G;AAED,wBAAgB,cAAc,CAAE,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAO3F"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
|
|
2
|
+
import { DUMP_SESSION_KEYS } from './constants.js';
|
|
3
|
+
export function logLocalStaticKeys(s, keyLogger) {
|
|
4
|
+
if (!keyLogger.enabled || !DUMP_SESSION_KEYS) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
if (s) {
|
|
8
|
+
keyLogger(`LOCAL_STATIC_PUBLIC_KEY ${uint8ArrayToString(s.publicKey, 'hex')}`);
|
|
9
|
+
keyLogger(`LOCAL_STATIC_PRIVATE_KEY ${uint8ArrayToString(s.privateKey, 'hex')}`);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
keyLogger('Missing local static keys.');
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export function logLocalEphemeralKeys(e, keyLogger) {
|
|
16
|
+
if (!keyLogger.enabled || !DUMP_SESSION_KEYS) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (e) {
|
|
20
|
+
keyLogger(`LOCAL_PUBLIC_EPHEMERAL_KEY ${uint8ArrayToString(e.publicKey, 'hex')}`);
|
|
21
|
+
keyLogger(`LOCAL_PRIVATE_EPHEMERAL_KEY ${uint8ArrayToString(e.privateKey, 'hex')}`);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
keyLogger('Missing local ephemeral keys.');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export function logRemoteStaticKey(rs, keyLogger) {
|
|
28
|
+
if (!keyLogger.enabled || !DUMP_SESSION_KEYS) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (rs) {
|
|
32
|
+
keyLogger(`REMOTE_STATIC_PUBLIC_KEY ${uint8ArrayToString(rs.subarray(), 'hex')}`);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
keyLogger('Missing remote static public key.');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export function logRemoteEphemeralKey(re, keyLogger) {
|
|
39
|
+
if (!keyLogger.enabled || !DUMP_SESSION_KEYS) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (re) {
|
|
43
|
+
keyLogger(`REMOTE_EPHEMERAL_PUBLIC_KEY ${uint8ArrayToString(re.subarray(), 'hex')}`);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
keyLogger('Missing remote ephemeral keys.');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export function logCipherState(cs1, cs2, keyLogger) {
|
|
50
|
+
if (!keyLogger.enabled || !DUMP_SESSION_KEYS) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
keyLogger(`CIPHER_STATE_1 ${cs1.n.getUint64()} ${cs1.k && uint8ArrayToString(cs1.k, 'hex')}`);
|
|
54
|
+
keyLogger(`CIPHER_STATE_2 ${cs2.n.getUint64()} ${cs2.k && uint8ArrayToString(cs2.k, 'hex')}`);
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,kBAAkB,EAAE,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AE,OAAO,GAAG,eAAe,CA2BlE"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function registerMetrics(metrics) {
|
|
2
|
+
return {
|
|
3
|
+
xxHandshakeSuccesses: metrics.registerCounter('libp2p_noise_xxhandshake_successes_total', {
|
|
4
|
+
help: 'Total count of noise xxHandshakes successes_'
|
|
5
|
+
}),
|
|
6
|
+
xxHandshakeErrors: metrics.registerCounter('libp2p_noise_xxhandshake_error_total', {
|
|
7
|
+
help: 'Total count of noise xxHandshakes errors'
|
|
8
|
+
}),
|
|
9
|
+
encryptedPackets: metrics.registerCounter('libp2p_noise_encrypted_packets_total', {
|
|
10
|
+
help: 'Total count of noise encrypted packets successfully'
|
|
11
|
+
}),
|
|
12
|
+
decryptedPackets: metrics.registerCounter('libp2p_noise_decrypted_packets_total', {
|
|
13
|
+
help: 'Total count of noise decrypted packets'
|
|
14
|
+
}),
|
|
15
|
+
decryptErrors: metrics.registerCounter('libp2p_noise_decrypt_errors_total', {
|
|
16
|
+
help: 'Total count of noise decrypt errors'
|
|
17
|
+
})
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=metrics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../src/metrics.ts"],"names":[],"mappings":"AAIA,MAAM,UAAU,eAAe,CAAE,OAAgB;IAC/C,OAAO;QACL,oBAAoB,EAAE,OAAO,CAAC,eAAe,CAC3C,0CAA0C,EAAE;YAC1C,IAAI,EAAE,8CAA8C;SACrD,CAAC;QAEJ,iBAAiB,EAAE,OAAO,CAAC,eAAe,CACxC,sCAAsC,EAAE;YACtC,IAAI,EAAE,0CAA0C;SACjD,CAAC;QAEJ,gBAAgB,EAAE,OAAO,CAAC,eAAe,CACvC,sCAAsC,EAAE;YACtC,IAAI,EAAE,qDAAqD;SAC5D,CAAC;QAEJ,gBAAgB,EAAE,OAAO,CAAC,eAAe,CACvC,sCAAsC,EAAE;YACtC,IAAI,EAAE,wCAAwC;SAC/C,CAAC;QAEJ,aAAa,EAAE,OAAO,CAAC,eAAe,CACpC,mCAAmC,EAAE;YACnC,IAAI,EAAE,qCAAqC;SAC5C,CAAC;KACL,CAAA;AACH,CAAC"}
|