salty-crypto 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,9 +6,18 @@ crypto code (partly from [tweetnacl.js](https://github.com/dchest/tweetnacl-js),
6
6
  wrote [myself](https://leastfixedpoint.com/) from the RFCs) to get
7
7
  `Noise_*_25519_ChaChaPoly_BLAKE2s` working.
8
8
 
9
+ ## Status
10
+
9
11
  Includes (and passes) test vectors from [noise-c](https://github.com/rweather/noise-c/) and
10
12
  [snow](https://github.com/mcginty/snow/).
11
13
 
14
+ ## Potential next steps
15
+
16
+ - support AESGCM, SHA256, SHA512, perhaps via `Crypto.subtle`?
17
+ - support BLAKE2b, by implementing from the RFC just like BLAKE2s
18
+ - `fallback` pattern modifier
19
+ - deferred patterns
20
+
12
21
  ## Code overview
13
22
 
14
23
  - `src` directory:
@@ -0,0 +1,36 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <script src="https://tonyg.github.io/typescript-salty-crypto/dist/salty-crypto.js"></script>
5
+ <style>html { font-family: sans; } body { max-width: 40em; margin: 0 auto; }</style>
6
+ </head>
7
+ <body>
8
+ <h1>In-browser SaltyCrypto hello-world</h1>
9
+ <p>
10
+ This is a small "hello-world" program to show that the SaltyCrypto module loads and runs
11
+ in a browser.
12
+ </p>
13
+ <p>
14
+ The <code>BLAKE2s</code> hash of the empty input is
15
+ <code id="expected-answer">69217a3079908094e11121d042354a7c1f55b6482ca1a51e1b250dfd1ed0eef9</code>
16
+ </p>
17
+ <p>
18
+ The SaltyCrypto module computes it as: <code id="computed-answer"><i>Huh, no answer from the code! Broken somehow I guess?</i></code>
19
+ </p>
20
+ <script>
21
+ function toHex(bs) {
22
+ let s = '';
23
+ bs.forEach(b => {
24
+ s = s + '0123456789abcdef'[b >> 4];
25
+ s = s + '0123456789abcdef'[b & 15];
26
+ });
27
+ return s;
28
+ }
29
+ document.getElementById('computed-answer').innerText = toHex(SaltyCrypto.BLAKE2.BLAKE2s.digest(new Uint8Array()));
30
+ </script>
31
+ <p>
32
+ You can play with the module via the <code>SaltyCrypto</code> global variable in the
33
+ JavaScript console.
34
+ </p>
35
+ </body>
36
+ </html>
@@ -0,0 +1,328 @@
1
+ declare const AEAD_CHACHA20_POLY1305_KEYBYTES = 32;
2
+ declare const AEAD_CHACHA20_POLY1305_NONCEBYTES = 12;
3
+ declare const AEAD_CHACHA20_POLY1305_TAGBYTES = 16;
4
+ declare function aead_encrypt_detached(plaintext: Uint8Array, ciphertext: Uint8Array, messagelength: number, tag: Uint8Array, key: DataView, nonce: DataView, associated_data?: Uint8Array): void;
5
+ declare function aead_encrypt(plaintext: Uint8Array, key: DataView, nonce: DataView, associated_data?: Uint8Array): Uint8Array;
6
+ declare function aead_decrypt_detached(plaintext: Uint8Array, ciphertext: Uint8Array, messagelength: number, expected_tag: Uint8Array, key: DataView, nonce: DataView, associated_data?: Uint8Array): boolean;
7
+ declare class AuthenticationFailure extends Error {
8
+ }
9
+ declare function aead_decrypt(ciphertextAndTag: Uint8Array, key: DataView, nonce: DataView, associated_data?: Uint8Array): Uint8Array;
10
+
11
+ declare const aead_d_AEAD_CHACHA20_POLY1305_KEYBYTES: typeof AEAD_CHACHA20_POLY1305_KEYBYTES;
12
+ declare const aead_d_AEAD_CHACHA20_POLY1305_NONCEBYTES: typeof AEAD_CHACHA20_POLY1305_NONCEBYTES;
13
+ declare const aead_d_AEAD_CHACHA20_POLY1305_TAGBYTES: typeof AEAD_CHACHA20_POLY1305_TAGBYTES;
14
+ type aead_d_AuthenticationFailure = AuthenticationFailure;
15
+ declare const aead_d_AuthenticationFailure: typeof AuthenticationFailure;
16
+ declare const aead_d_aead_decrypt: typeof aead_decrypt;
17
+ declare const aead_d_aead_decrypt_detached: typeof aead_decrypt_detached;
18
+ declare const aead_d_aead_encrypt: typeof aead_encrypt;
19
+ declare const aead_d_aead_encrypt_detached: typeof aead_encrypt_detached;
20
+ declare namespace aead_d {
21
+ export {
22
+ aead_d_AEAD_CHACHA20_POLY1305_KEYBYTES as AEAD_CHACHA20_POLY1305_KEYBYTES,
23
+ aead_d_AEAD_CHACHA20_POLY1305_NONCEBYTES as AEAD_CHACHA20_POLY1305_NONCEBYTES,
24
+ aead_d_AEAD_CHACHA20_POLY1305_TAGBYTES as AEAD_CHACHA20_POLY1305_TAGBYTES,
25
+ aead_d_AuthenticationFailure as AuthenticationFailure,
26
+ aead_d_aead_decrypt as aead_decrypt,
27
+ aead_d_aead_decrypt_detached as aead_decrypt_detached,
28
+ aead_d_aead_encrypt as aead_encrypt,
29
+ aead_d_aead_encrypt_detached as aead_encrypt_detached,
30
+ };
31
+ }
32
+
33
+ declare class BLAKE2s {
34
+ outlen: number;
35
+ static readonly KEYBYTES = 32;
36
+ static readonly OUTBYTES = 32;
37
+ static readonly BLOCKLEN = 64;
38
+ b: Uint8Array;
39
+ bv: DataView;
40
+ h: Uint32Array;
41
+ t: Uint32Array;
42
+ c: number;
43
+ static digest(input: Uint8Array, outlen?: number, key?: Uint8Array): Uint8Array;
44
+ constructor(outlen?: number, key?: Uint8Array);
45
+ update(input: Uint8Array): void;
46
+ final(output?: Uint8Array): Uint8Array;
47
+ compress(last: boolean): void;
48
+ }
49
+
50
+ type blake2_d_BLAKE2s = BLAKE2s;
51
+ declare const blake2_d_BLAKE2s: typeof BLAKE2s;
52
+ declare namespace blake2_d {
53
+ export {
54
+ blake2_d_BLAKE2s as BLAKE2s,
55
+ };
56
+ }
57
+
58
+ declare const CHACHA20_KEYBYTES = 32;
59
+ declare const CHACHA20_NONCEBYTES = 12;
60
+ declare const CHACHA20_BLOCKBYTES = 64;
61
+ declare function chacha20_quarter_round(s: Uint32Array, a: number, b: number, c: number, d: number): void;
62
+ declare function chacha20_block(key: DataView, block: number, nonce: DataView): Uint32Array;
63
+ declare function chacha20(key: DataView, nonce: DataView, input: Uint8Array, output: Uint8Array, initial_counter?: number, messagelength?: number): void;
64
+
65
+ declare const chacha20_d_CHACHA20_BLOCKBYTES: typeof CHACHA20_BLOCKBYTES;
66
+ declare const chacha20_d_CHACHA20_KEYBYTES: typeof CHACHA20_KEYBYTES;
67
+ declare const chacha20_d_CHACHA20_NONCEBYTES: typeof CHACHA20_NONCEBYTES;
68
+ declare const chacha20_d_chacha20: typeof chacha20;
69
+ declare const chacha20_d_chacha20_block: typeof chacha20_block;
70
+ declare const chacha20_d_chacha20_quarter_round: typeof chacha20_quarter_round;
71
+ declare namespace chacha20_d {
72
+ export {
73
+ chacha20_d_CHACHA20_BLOCKBYTES as CHACHA20_BLOCKBYTES,
74
+ chacha20_d_CHACHA20_KEYBYTES as CHACHA20_KEYBYTES,
75
+ chacha20_d_CHACHA20_NONCEBYTES as CHACHA20_NONCEBYTES,
76
+ chacha20_d_chacha20 as chacha20,
77
+ chacha20_d_chacha20_block as chacha20_block,
78
+ chacha20_d_chacha20_quarter_round as chacha20_quarter_round,
79
+ };
80
+ }
81
+
82
+ type DHKeyPair = {
83
+ public: Uint8Array;
84
+ secret: Uint8Array;
85
+ };
86
+ declare class Nonce {
87
+ lo: number;
88
+ hi: number;
89
+ constructor(lo?: number, hi?: number);
90
+ increment(): void;
91
+ reset(lo?: number, hi?: number): void;
92
+ static get MAX(): Nonce;
93
+ }
94
+ declare function bytesXor(a: Uint8Array, b: Uint8Array): Uint8Array;
95
+ declare function bytesAppend(a: Uint8Array, b: Uint8Array): Uint8Array;
96
+ type HMAC = (key: Uint8Array, data: Uint8Array) => Uint8Array;
97
+ declare abstract class NoiseProtocolAlgorithms {
98
+ readonly dhlen: number;
99
+ readonly hmac: HMAC;
100
+ constructor(hmac?: HMAC);
101
+ abstract dhName(): string;
102
+ abstract generateKeypair(): DHKeyPair;
103
+ abstract dh(kp: DHKeyPair, pk: Uint8Array): Uint8Array;
104
+ abstract cipherName(): string;
105
+ abstract encrypt(key: DataView, nonce: Nonce, p: Uint8Array, associated_data?: Uint8Array): Uint8Array;
106
+ abstract decrypt(key: DataView, nonce: Nonce, c: Uint8Array, associated_data?: Uint8Array): Uint8Array;
107
+ abstract hashName(): string;
108
+ abstract hash(data: Uint8Array): Uint8Array;
109
+ abstract hashBlocklen(): number;
110
+ rekey(k: DataView): DataView;
111
+ _padOrHash(bs0: Uint8Array, len: number): Uint8Array;
112
+ hkdf(chainingKey: Uint8Array, input: Uint8Array, numOutputs: 2): [Uint8Array, Uint8Array];
113
+ hkdf(chainingKey: Uint8Array, input: Uint8Array, numOutputs: 3): [Uint8Array, Uint8Array, Uint8Array];
114
+ matchingPattern(protocol_name: string): string | null;
115
+ }
116
+ interface HandshakePattern {
117
+ name: string;
118
+ baseName: string;
119
+ messages: Token[][];
120
+ initiatorPreMessage: PreMessage;
121
+ responderPreMessage: PreMessage;
122
+ }
123
+ declare class CipherState {
124
+ algorithms: NoiseProtocolAlgorithms;
125
+ view: DataView | null;
126
+ nonce: Nonce;
127
+ constructor(algorithms: NoiseProtocolAlgorithms, key?: Uint8Array);
128
+ encrypt(plaintext: Uint8Array, associated_data?: Uint8Array): Uint8Array;
129
+ decrypt(ciphertext: Uint8Array, associated_data?: Uint8Array): Uint8Array;
130
+ rekey(): void;
131
+ }
132
+ type Role = 'initiator' | 'responder';
133
+ type NoiseProtocolOptions = {
134
+ prologue?: Uint8Array;
135
+ staticKeypair?: DHKeyPair;
136
+ remoteStaticPublicKey?: Uint8Array;
137
+ pregeneratedEphemeralKeypair?: DHKeyPair;
138
+ remotePregeneratedEphemeralPublicKey?: Uint8Array;
139
+ preSharedKeys?: Uint8Array[];
140
+ };
141
+ type KeyTransferToken = 'e' | 's';
142
+ type KeyMixToken = 'ee' | 'es' | 'se' | 'ss' | 'psk';
143
+ type Token = KeyTransferToken | KeyMixToken;
144
+ type PreMessage = ['e'] | ['s'] | ['e', 's'] | [];
145
+ type TransportState = {
146
+ send: CipherState;
147
+ recv: CipherState;
148
+ };
149
+ declare class NoiseHandshake {
150
+ algorithms: NoiseProtocolAlgorithms;
151
+ pattern: HandshakePattern;
152
+ role: Role;
153
+ staticKeypair: DHKeyPair;
154
+ remoteStaticPublicKey: Uint8Array | null;
155
+ ephemeralKeypair: DHKeyPair;
156
+ remoteEphemeralPublicKey: Uint8Array | null;
157
+ preSharedKeys?: Uint8Array[];
158
+ stepIndex: number;
159
+ cipherState: CipherState;
160
+ chainingKey: Uint8Array;
161
+ handshakeHash: Uint8Array;
162
+ constructor(algorithms: NoiseProtocolAlgorithms, pattern: HandshakePattern, role: Role, options?: NoiseProtocolOptions);
163
+ get isInitiator(): boolean;
164
+ mixHash(data: Uint8Array): void;
165
+ mixKey(input: Uint8Array): void;
166
+ mixKeyAndHashNextPSK(): void;
167
+ encryptAndHash(p: Uint8Array): Uint8Array;
168
+ decryptAndHash(c: Uint8Array): Uint8Array;
169
+ _split(): TransportState | null;
170
+ _nextStep(): Token[];
171
+ _processKeyMixToken(t: KeyMixToken): void;
172
+ writeMessage(payload: Uint8Array): {
173
+ packet: Uint8Array;
174
+ finished: TransportState | null;
175
+ };
176
+ readMessage(packet: Uint8Array): {
177
+ message: Uint8Array;
178
+ finished: TransportState | null;
179
+ };
180
+ completeHandshake(writePacket: (packet: Uint8Array) => Promise<void>, readPacket: () => Promise<Uint8Array>, handleMessage?: (_m: Uint8Array) => Promise<void>, produceMessage?: () => Promise<Uint8Array>): Promise<TransportState>;
181
+ }
182
+
183
+ type noise_d_CipherState = CipherState;
184
+ declare const noise_d_CipherState: typeof CipherState;
185
+ type noise_d_DHKeyPair = DHKeyPair;
186
+ type noise_d_HMAC = HMAC;
187
+ type noise_d_HandshakePattern = HandshakePattern;
188
+ type noise_d_KeyMixToken = KeyMixToken;
189
+ type noise_d_KeyTransferToken = KeyTransferToken;
190
+ type noise_d_NoiseHandshake = NoiseHandshake;
191
+ declare const noise_d_NoiseHandshake: typeof NoiseHandshake;
192
+ type noise_d_NoiseProtocolAlgorithms = NoiseProtocolAlgorithms;
193
+ declare const noise_d_NoiseProtocolAlgorithms: typeof NoiseProtocolAlgorithms;
194
+ type noise_d_NoiseProtocolOptions = NoiseProtocolOptions;
195
+ type noise_d_Nonce = Nonce;
196
+ declare const noise_d_Nonce: typeof Nonce;
197
+ type noise_d_PreMessage = PreMessage;
198
+ type noise_d_Role = Role;
199
+ type noise_d_Token = Token;
200
+ type noise_d_TransportState = TransportState;
201
+ declare const noise_d_bytesAppend: typeof bytesAppend;
202
+ declare const noise_d_bytesXor: typeof bytesXor;
203
+ declare namespace noise_d {
204
+ export {
205
+ noise_d_CipherState as CipherState,
206
+ noise_d_DHKeyPair as DHKeyPair,
207
+ noise_d_HMAC as HMAC,
208
+ noise_d_HandshakePattern as HandshakePattern,
209
+ noise_d_KeyMixToken as KeyMixToken,
210
+ noise_d_KeyTransferToken as KeyTransferToken,
211
+ noise_d_NoiseHandshake as NoiseHandshake,
212
+ noise_d_NoiseProtocolAlgorithms as NoiseProtocolAlgorithms,
213
+ noise_d_NoiseProtocolOptions as NoiseProtocolOptions,
214
+ noise_d_Nonce as Nonce,
215
+ noise_d_PreMessage as PreMessage,
216
+ noise_d_Role as Role,
217
+ noise_d_Token as Token,
218
+ noise_d_TransportState as TransportState,
219
+ noise_d_bytesAppend as bytesAppend,
220
+ noise_d_bytesXor as bytesXor,
221
+ };
222
+ }
223
+
224
+ declare const PATTERNS: {
225
+ [key: string]: HandshakePattern;
226
+ };
227
+ declare function isOneWay(pat: HandshakePattern): boolean;
228
+ declare function lookupPattern(name: string): HandshakePattern | null;
229
+
230
+ declare const patterns_d_PATTERNS: typeof PATTERNS;
231
+ declare const patterns_d_isOneWay: typeof isOneWay;
232
+ declare const patterns_d_lookupPattern: typeof lookupPattern;
233
+ declare namespace patterns_d {
234
+ export {
235
+ patterns_d_PATTERNS as PATTERNS,
236
+ patterns_d_isOneWay as isOneWay,
237
+ patterns_d_lookupPattern as lookupPattern,
238
+ };
239
+ }
240
+
241
+ declare class Poly1305 {
242
+ key: Uint8Array;
243
+ static readonly KEYBYTES = 32;
244
+ static readonly TAGBYTES = 16;
245
+ static readonly BLOCKBYTES = 16;
246
+ buffer: Uint8Array;
247
+ r: Uint16Array;
248
+ h: Uint16Array;
249
+ pad: Uint16Array;
250
+ leftover: number;
251
+ fin: number;
252
+ static digest(key: Uint8Array, input: Uint8Array): Uint8Array;
253
+ constructor(key: Uint8Array);
254
+ blocks(m: Uint8Array, mpos: number, bytes: number): void;
255
+ finish(mac: Uint8Array, macpos: number): void;
256
+ update(m: Uint8Array, mpos: number, bytes: number): void;
257
+ }
258
+
259
+ type poly1305_d_Poly1305 = Poly1305;
260
+ declare const poly1305_d_Poly1305: typeof Poly1305;
261
+ declare namespace poly1305_d {
262
+ export {
263
+ poly1305_d_Poly1305 as Poly1305,
264
+ };
265
+ }
266
+
267
+ declare class Noise_25519_ChaChaPoly_BLAKE2s extends NoiseProtocolAlgorithms {
268
+ constructor();
269
+ dhName(): string;
270
+ generateKeypair(): DHKeyPair;
271
+ dh(kp: DHKeyPair, pk: Uint8Array): Uint8Array;
272
+ cipherName(): string;
273
+ encrypt(key: DataView, nonce: Nonce, p: Uint8Array, associated_data?: Uint8Array): Uint8Array;
274
+ decrypt(key: DataView, nonce: Nonce, c: Uint8Array, associated_data?: Uint8Array): Uint8Array;
275
+ hashName(): string;
276
+ hash(data: Uint8Array): Uint8Array;
277
+ hashBlocklen(): number;
278
+ }
279
+
280
+ type profiles_d_Noise_25519_ChaChaPoly_BLAKE2s = Noise_25519_ChaChaPoly_BLAKE2s;
281
+ declare const profiles_d_Noise_25519_ChaChaPoly_BLAKE2s: typeof Noise_25519_ChaChaPoly_BLAKE2s;
282
+ declare namespace profiles_d {
283
+ export {
284
+ profiles_d_Noise_25519_ChaChaPoly_BLAKE2s as Noise_25519_ChaChaPoly_BLAKE2s,
285
+ };
286
+ }
287
+
288
+ declare const _randomBytes: (out: Uint8Array, n: number) => void;
289
+ declare function randomBytes(n: number): Uint8Array;
290
+
291
+ declare const random_d__randomBytes: typeof _randomBytes;
292
+ declare const random_d_randomBytes: typeof randomBytes;
293
+ declare namespace random_d {
294
+ export {
295
+ random_d__randomBytes as _randomBytes,
296
+ random_d_randomBytes as randomBytes,
297
+ };
298
+ }
299
+
300
+ declare const crypto_scalarmult_BYTES = 32;
301
+ declare const crypto_scalarmult_SCALARBYTES = 32;
302
+ declare function crypto_scalarmult(q: Uint8Array, n: Uint8Array, p: Uint8Array): void;
303
+ declare function crypto_scalarmult_base(q: Uint8Array, n: Uint8Array): void;
304
+ declare function scalarMult(n: Uint8Array, p: Uint8Array): Uint8Array;
305
+ declare namespace scalarMult {
306
+ var scalarLength: number;
307
+ var groupElementLength: number;
308
+ }
309
+ declare function scalarMultBase(n: Uint8Array): Uint8Array;
310
+
311
+ declare const x25519_d_crypto_scalarmult: typeof crypto_scalarmult;
312
+ declare const x25519_d_crypto_scalarmult_BYTES: typeof crypto_scalarmult_BYTES;
313
+ declare const x25519_d_crypto_scalarmult_SCALARBYTES: typeof crypto_scalarmult_SCALARBYTES;
314
+ declare const x25519_d_crypto_scalarmult_base: typeof crypto_scalarmult_base;
315
+ declare const x25519_d_scalarMult: typeof scalarMult;
316
+ declare const x25519_d_scalarMultBase: typeof scalarMultBase;
317
+ declare namespace x25519_d {
318
+ export {
319
+ x25519_d_crypto_scalarmult as crypto_scalarmult,
320
+ x25519_d_crypto_scalarmult_BYTES as crypto_scalarmult_BYTES,
321
+ x25519_d_crypto_scalarmult_SCALARBYTES as crypto_scalarmult_SCALARBYTES,
322
+ x25519_d_crypto_scalarmult_base as crypto_scalarmult_base,
323
+ x25519_d_scalarMult as scalarMult,
324
+ x25519_d_scalarMultBase as scalarMultBase,
325
+ };
326
+ }
327
+
328
+ export { aead_d as AEAD, blake2_d as BLAKE2, chacha20_d as ChaCha20, noise_d as Noise, profiles_d as NoiseProfiles, patterns_d as Patterns, poly1305_d as Poly1305, random_d as Random, x25519_d as X25519 };
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).SaltyCrypto={})}(this,(function(t){"use strict";function e(t,e){return t<<e|t>>>32-e}function s(t,s,i,h,r){t[s]+=t[i],t[r]^=t[s],t[r]=e(t[r],16),t[h]+=t[r],t[i]^=t[h],t[i]=e(t[i],12),t[s]+=t[i],t[r]^=t[s],t[r]=e(t[r],8),t[h]+=t[r],t[i]^=t[h],t[i]=e(t[i],7)}function i(t,e,s,i){t[0]+=1634760805,t[1]+=857760878,t[2]+=2036477234,t[3]+=1797285236,t[4]+=e.getUint32(0,!0),t[5]+=e.getUint32(4,!0),t[6]+=e.getUint32(8,!0),t[7]+=e.getUint32(12,!0),t[8]+=e.getUint32(16,!0),t[9]+=e.getUint32(20,!0),t[10]+=e.getUint32(24,!0),t[11]+=e.getUint32(28,!0),t[12]+=s,t[13]+=i.getUint32(0,!0),t[14]+=i.getUint32(4,!0),t[15]+=i.getUint32(8,!0)}function h(t,e,h){const r=new Uint32Array(16);i(r,t,e,h);for(let t=0;t<20;t+=2)s(r,0,4,8,12),s(r,1,5,9,13),s(r,2,6,10,14),s(r,3,7,11,15),s(r,0,5,10,15),s(r,1,6,11,12),s(r,2,7,8,13),s(r,3,4,9,14);return i(r,t,e,h),r}function r(t,e,s,i,r=0,n=s.byteLength){const a=n>>6,o=63&n;for(let n=0;n<a;n++){const a=h(t,r+n,e);for(let t=0;t<64;t++)i[(n<<6)+t]=s[(n<<6)+t]^a[t>>2]>>((3&t)<<3)}if(0!==o){const n=h(t,r+a,e);for(let t=0;t<o;t++)i[(a<<6)+t]=s[(a<<6)+t]^n[t>>2]>>((3&t)<<3)}}var n=Object.freeze({__proto__:null,CHACHA20_BLOCKBYTES:64,CHACHA20_KEYBYTES:32,CHACHA20_NONCEBYTES:12,chacha20:r,chacha20_block:h,chacha20_quarter_round:s});class a{static digest(t,e){const s=new a(t);s.update(e,0,e.byteLength);const i=new Uint8Array(a.TAGBYTES);return s.finish(i,0),i}constructor(t){this.key=t,this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.leftover=0,this.fin=0;const e=255&t[0]|(255&t[1])<<8;this.r[0]=8191&e;const s=255&t[2]|(255&t[3])<<8;this.r[1]=8191&(e>>>13|s<<3);const i=255&t[4]|(255&t[5])<<8;this.r[2]=7939&(s>>>10|i<<6);const h=255&t[6]|(255&t[7])<<8;this.r[3]=8191&(i>>>7|h<<9);const r=255&t[8]|(255&t[9])<<8;this.r[4]=255&(h>>>4|r<<12),this.r[5]=r>>>1&8190;const n=255&t[10]|(255&t[11])<<8;this.r[6]=8191&(r>>>14|n<<2);const a=255&t[12]|(255&t[13])<<8;this.r[7]=8065&(n>>>11|a<<5);const o=255&t[14]|(255&t[15])<<8;this.r[8]=8191&(a>>>8|o<<8),this.r[9]=o>>>5&127,this.pad[0]=255&t[16]|(255&t[17])<<8,this.pad[1]=255&t[18]|(255&t[19])<<8,this.pad[2]=255&t[20]|(255&t[21])<<8,this.pad[3]=255&t[22]|(255&t[23])<<8,this.pad[4]=255&t[24]|(255&t[25])<<8,this.pad[5]=255&t[26]|(255&t[27])<<8,this.pad[6]=255&t[28]|(255&t[29])<<8,this.pad[7]=255&t[30]|(255&t[31])<<8}blocks(t,e,s){const i=this.fin?0:2048;let h=this.h[0],r=this.h[1],n=this.h[2],a=this.h[3],o=this.h[4],l=this.h[5],c=this.h[6],f=this.h[7],u=this.h[8],y=this.h[9],p=this.r[0],d=this.r[1],m=this.r[2],g=this.r[3],b=this.r[4],K=this.r[5],w=this.r[6],_=this.r[7],A=this.r[8],E=this.r[9];for(;s>=16;){const U=255&t[e+0]|(255&t[e+1])<<8;h+=8191&U;const v=255&t[e+2]|(255&t[e+3])<<8;r+=8191&(U>>>13|v<<3);const M=255&t[e+4]|(255&t[e+5])<<8;n+=8191&(v>>>10|M<<6);const S=255&t[e+6]|(255&t[e+7])<<8;a+=8191&(M>>>7|S<<9);const k=255&t[e+8]|(255&t[e+9])<<8;o+=8191&(S>>>4|k<<12),l+=k>>>1&8191;const L=255&t[e+10]|(255&t[e+11])<<8;c+=8191&(k>>>14|L<<2);const H=255&t[e+12]|(255&t[e+13])<<8;f+=8191&(L>>>11|H<<5);const N=255&t[e+14]|(255&t[e+15])<<8;u+=8191&(H>>>8|N<<8),y+=N>>>5|i;let x=0,P=x;P+=h*p,P+=r*(5*E),P+=n*(5*A),P+=a*(5*_),P+=o*(5*w),x=P>>>13,P&=8191,P+=l*(5*K),P+=c*(5*b),P+=f*(5*g),P+=u*(5*m),P+=y*(5*d),x+=P>>>13,P&=8191;let B=x;B+=h*d,B+=r*p,B+=n*(5*E),B+=a*(5*A),B+=o*(5*_),x=B>>>13,B&=8191,B+=l*(5*w),B+=c*(5*K),B+=f*(5*b),B+=u*(5*g),B+=y*(5*m),x+=B>>>13,B&=8191;let T=x;T+=h*m,T+=r*d,T+=n*p,T+=a*(5*E),T+=o*(5*A),x=T>>>13,T&=8191,T+=l*(5*_),T+=c*(5*w),T+=f*(5*K),T+=u*(5*b),T+=y*(5*g),x+=T>>>13,T&=8191;let C=x;C+=h*g,C+=r*m,C+=n*d,C+=a*p,C+=o*(5*E),x=C>>>13,C&=8191,C+=l*(5*A),C+=c*(5*_),C+=f*(5*w),C+=u*(5*K),C+=y*(5*b),x+=C>>>13,C&=8191;let O=x;O+=h*b,O+=r*g,O+=n*m,O+=a*d,O+=o*p,x=O>>>13,O&=8191,O+=l*(5*E),O+=c*(5*A),O+=f*(5*_),O+=u*(5*w),O+=y*(5*K),x+=O>>>13,O&=8191;let Y=x;Y+=h*K,Y+=r*b,Y+=n*g,Y+=a*m,Y+=o*d,x=Y>>>13,Y&=8191,Y+=l*p,Y+=c*(5*E),Y+=f*(5*A),Y+=u*(5*_),Y+=y*(5*w),x+=Y>>>13,Y&=8191;let I=x;I+=h*w,I+=r*K,I+=n*b,I+=a*g,I+=o*m,x=I>>>13,I&=8191,I+=l*d,I+=c*p,I+=f*(5*E),I+=u*(5*A),I+=y*(5*_),x+=I>>>13,I&=8191;let z=x;z+=h*_,z+=r*w,z+=n*K,z+=a*b,z+=o*g,x=z>>>13,z&=8191,z+=l*m,z+=c*d,z+=f*p,z+=u*(5*E),z+=y*(5*A),x+=z>>>13,z&=8191;let X=x;X+=h*A,X+=r*_,X+=n*w,X+=a*K,X+=o*b,x=X>>>13,X&=8191,X+=l*g,X+=c*m,X+=f*d,X+=u*p,X+=y*(5*E),x+=X>>>13,X&=8191;let j=x;j+=h*E,j+=r*A,j+=n*_,j+=a*w,j+=o*K,x=j>>>13,j&=8191,j+=l*b,j+=c*g,j+=f*m,j+=u*d,j+=y*p,x+=j>>>13,j&=8191,x=(x<<2)+x|0,x=x+P|0,P=8191&x,x>>>=13,B+=x,h=P,r=B,n=T,a=C,o=O,l=Y,c=I,f=z,u=X,y=j,e+=16,s-=16}this.h[0]=h,this.h[1]=r,this.h[2]=n,this.h[3]=a,this.h[4]=o,this.h[5]=l,this.h[6]=c,this.h[7]=f,this.h[8]=u,this.h[9]=y}finish(t,e){if(this.leftover){let t=this.leftover;for(this.buffer[t++]=1;t<16;t++)this.buffer[t]=0;this.fin=1,this.blocks(this.buffer,0,16)}let s=this.h[1]>>>13;this.h[1]&=8191;for(let t=2;t<10;t++)this.h[t]+=s,s=this.h[t]>>>13,this.h[t]&=8191;this.h[0]+=5*s,s=this.h[0]>>>13,this.h[0]&=8191,this.h[1]+=s,s=this.h[1]>>>13,this.h[1]&=8191,this.h[2]+=s;const i=new Uint16Array(10);i[0]=this.h[0]+5,s=i[0]>>>13,i[0]&=8191;for(let t=1;t<10;t++)i[t]=this.h[t]+s,s=i[t]>>>13,i[t]&=8191;i[9]-=8192;let h=(1^s)-1;for(let t=0;t<10;t++)i[t]&=h;h=~h;for(let t=0;t<10;t++)this.h[t]=this.h[t]&h|i[t];this.h[0]=65535&(this.h[0]|this.h[1]<<13),this.h[1]=65535&(this.h[1]>>>3|this.h[2]<<10),this.h[2]=65535&(this.h[2]>>>6|this.h[3]<<7),this.h[3]=65535&(this.h[3]>>>9|this.h[4]<<4),this.h[4]=65535&(this.h[4]>>>12|this.h[5]<<1|this.h[6]<<14),this.h[5]=65535&(this.h[6]>>>2|this.h[7]<<11),this.h[6]=65535&(this.h[7]>>>5|this.h[8]<<8),this.h[7]=65535&(this.h[8]>>>8|this.h[9]<<5);let r=this.h[0]+this.pad[0];this.h[0]=65535&r;for(let t=1;t<8;t++)r=(this.h[t]+this.pad[t]|0)+(r>>>16)|0,this.h[t]=65535&r;t[e+0]=this.h[0]>>>0&255,t[e+1]=this.h[0]>>>8&255,t[e+2]=this.h[1]>>>0&255,t[e+3]=this.h[1]>>>8&255,t[e+4]=this.h[2]>>>0&255,t[e+5]=this.h[2]>>>8&255,t[e+6]=this.h[3]>>>0&255,t[e+7]=this.h[3]>>>8&255,t[e+8]=this.h[4]>>>0&255,t[e+9]=this.h[4]>>>8&255,t[e+10]=this.h[5]>>>0&255,t[e+11]=this.h[5]>>>8&255,t[e+12]=this.h[6]>>>0&255,t[e+13]=this.h[6]>>>8&255,t[e+14]=this.h[7]>>>0&255,t[e+15]=this.h[7]>>>8&255}update(t,e,s){if(this.leftover){let i=16-this.leftover;i>s&&(i=s);for(let s=0;s<i;s++)this.buffer[this.leftover+s]=t[e+s];if(s-=i,e+=i,this.leftover+=i,this.leftover<16)return;this.blocks(this.buffer,0,16),this.leftover=0}if(s>=16){const i=s-s%16;this.blocks(t,e,i),e+=i,s-=i}if(s){for(let i=0;i<s;i++)this.buffer[this.leftover+i]=t[e+i];this.leftover+=s}}}a.KEYBYTES=32,a.TAGBYTES=16,a.BLOCKBYTES=16;var o=Object.freeze({__proto__:null,Poly1305:a});const l=new Uint8Array(16);function c(t,e){const s=15&e;0!==s&&t.update(l,0,16-s)}function f(t,e,s,i,h,n){const o=new Uint8Array(a.KEYBYTES);r(e,s,o,o,0);const l=new a(o);void 0!==n&&(l.update(n,0,n.byteLength),c(l,n.byteLength)),l.update(i,0,h),c(l,h);const f=new Uint8Array(16),u=new DataView(f.buffer);void 0!==n&&u.setUint32(0,n.byteLength,!0),u.setUint32(8,h,!0),l.update(f,0,f.byteLength),l.finish(t,0)}function u(t,e,s,i,h,n,a){r(h,n,t,e,1,s),f(i,h,n,e,s,a)}function y(t,e,s,i,h,n,a){const o=new Uint8Array(16);f(o,h,n,e,s,a);const l=0===function(t,e,s){let i=0;for(let h=0;h<s;h++)i|=t[h]^e[h];return(1&i-1>>>8)-1}(o,i,o.byteLength);return l?r(h,n,e,t,1,s):t.fill(0,0,s),l}var p=Object.freeze({__proto__:null,AEAD_CHACHA20_POLY1305_KEYBYTES:32,AEAD_CHACHA20_POLY1305_NONCEBYTES:12,AEAD_CHACHA20_POLY1305_TAGBYTES:16,aead_decrypt_detached:y,aead_encrypt_detached:u});function d(t,e){return t>>>e|t<<32-e}function m(t,e,s,i,h,r,n){t[e]=t[e]+t[s]+r,t[h]=d(t[h]^t[e],16),t[i]=t[i]+t[h],t[s]=d(t[s]^t[i],12),t[e]=t[e]+t[s]+n,t[h]=d(t[h]^t[e],8),t[i]=t[i]+t[h],t[s]=d(t[s]^t[i],7)}const g=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),b=Uint8Array.from([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0]);function K(t,e){return b[(t<<4)+e]}class w{static digest(t,e,s){const i=new w(e,s);return i.update(t),i.final()}constructor(t=w.OUTBYTES,e){var s;this.outlen=t,this.b=new Uint8Array(64),this.bv=new DataView(this.b.buffer),this.h=Uint32Array.from(g),this.t=new Uint32Array(2),this.c=0;const i=null!==(s=null==e?void 0:e.byteLength)&&void 0!==s?s:0;if(0==t||t>32||i>32)throw new Error("illegal BLAKE2s parameter length(s)");this.h[0]^=16842752^i<<8^t,void 0!==e&&i>0&&(this.update(e),this.c=64)}update(t){for(let e=0;e<t.byteLength;e++)64==this.c&&(this.t[0]+=this.c,this.t[0]<this.c&&this.t[1]++,this.compress(!1),this.c=0),this.b[this.c++]=t[e]}final(t){for(this.t[0]+=this.c,this.t[0]<this.c&&this.t[1]++;this.c<64;)this.b[this.c++]=0;this.compress(!0),void 0===t&&(t=new Uint8Array(this.outlen));for(let e=0;e<this.outlen;e++)t[e]=this.h[e>>2]>>8*(3&e)&255;return t}compress(t){const e=new Uint32Array(16),s=new Uint32Array(16);for(let t=0;t<8;t++)e[t]=this.h[t],e[t+8]=g[t];e[12]^=this.t[0],e[13]^=this.t[1],t&&(e[14]=~e[14]);for(let t=0;t<16;t++)s[t]=this.bv.getUint32(t<<2,!0);for(let t=0;t<10;t++)m(e,0,4,8,12,s[K(t,0)],s[K(t,1)]),m(e,1,5,9,13,s[K(t,2)],s[K(t,3)]),m(e,2,6,10,14,s[K(t,4)],s[K(t,5)]),m(e,3,7,11,15,s[K(t,6)],s[K(t,7)]),m(e,0,5,10,15,s[K(t,8)],s[K(t,9)]),m(e,1,6,11,12,s[K(t,10)],s[K(t,11)]),m(e,2,7,8,13,s[K(t,12)],s[K(t,13)]),m(e,3,4,9,14,s[K(t,14)],s[K(t,15)]);for(let t=0;t<8;t++)this.h[t]^=e[t]^e[t+8]}}w.KEYBYTES=32,w.OUTBYTES=32,w.BLOCKLEN=64;var _=Object.freeze({__proto__:null,BLAKE2s:w});class A{constructor(t=0,e=0){this.lo=t,this.hi=e}increment(){const t=this.lo,e=t+1|0;this.lo=e,e<t&&(this.hi=this.hi+1|0)}reset(t=0,e=0){this.lo=t,this.hi=e}static get MAX(){return new A(4294967295,4294967295)}}function E(t,e){const s=Math.min(t.byteLength,e.byteLength),i=new Uint8Array(s);for(let h=0;h<s;h++)i[h]=t[h]^e[h];return i}function U(t,e){const s=new Uint8Array(t.byteLength+e.byteLength);return s.set(t,0),s.set(e,t.byteLength),s}const v=new Uint8Array(0);class M{constructor(t){const e=this.generateKeypair();this.dhlen=this.dh(e,e.public).byteLength,this.hmac=null!=t?t:function(t){const e=new Uint8Array(t.hashBlocklen());e.fill(54);const s=new Uint8Array(t.hashBlocklen());return s.fill(92),(i,h)=>{const r=t._padOrHash(i,t.hashBlocklen());return t.hash(U(E(r,s),t.hash(U(E(r,e),h))))}}(this)}rekey(t){return new DataView(this.encrypt(t,A.MAX,new Uint8Array(32)).buffer)}_padOrHash(t,e){const s=t.byteLength>e?this.hash(t):t;return U(s,new Uint8Array(e-s.byteLength))}hkdf(t,e,s){const i=this.hmac(t,e),h=this.hmac(i,Uint8Array.from([1])),r=this.hmac(i,U(h,Uint8Array.from([2])));switch(s){case 2:return[h,r];case 3:return[h,r,this.hmac(i,U(r,Uint8Array.from([3])))]}}matchingPattern(t){const e=new RegExp(`^Noise_([A-Za-z0-9+]+)_${this.dhName()}_${this.cipherName()}_${this.hashName()}$`).exec(t);return null===e?null:e[1]}}class S{constructor(t,e){this.algorithms=t,this.view=null,this.nonce=new A,void 0!==e&&(this.view=new DataView(e.buffer))}encrypt(t,e){if(null===this.view)return t;const s=this.algorithms.encrypt(this.view,this.nonce,t,e);return this.nonce.increment(),s}decrypt(t,e){if(null===this.view)return t;const s=this.algorithms.decrypt(this.view,this.nonce,t,e);return this.nonce.increment(),s}rekey(){null!==this.view&&(this.view=this.algorithms.rekey(this.view))}}var k=Object.freeze({__proto__:null,CipherState:S,NoiseHandshake:class{constructor(t,e,s,i={}){var h,r,n,a,o;this.algorithms=t,this.pattern=e,this.role=s,this.stepIndex=0,this.staticKeypair=null!==(h=i.staticKeypair)&&void 0!==h?h:this.algorithms.generateKeypair(),this.remoteStaticPublicKey=null!==(r=i.remoteStaticPublicKey)&&void 0!==r?r:null,this.ephemeralKeypair=null!==(n=i.pregeneratedEphemeralKeypair)&&void 0!==n?n:this.algorithms.generateKeypair(),this.remoteEphemeralPublicKey=null!==(a=i.remotePregeneratedEphemeralPublicKey)&&void 0!==a?a:null,this.preSharedKeys=i.preSharedKeys,this.preSharedKeys&&(this.preSharedKeys=this.preSharedKeys.slice(),0===this.preSharedKeys.length&&(this.preSharedKeys=void 0));const l=(new TextEncoder).encode("Noise_"+this.pattern.name+"_"+this.algorithms.dhName()+"_"+this.algorithms.cipherName()+"_"+this.algorithms.hashName());this.cipherState=new S(this.algorithms),this.chainingKey=this.algorithms._padOrHash(l,this.algorithms.hash(v).byteLength),this.handshakeHash=this.chainingKey,this.mixHash(null!==(o=i.prologue)&&void 0!==o?o:v),this.pattern.initiatorPreMessage.forEach((t=>this.mixHash("e"===t?this.isInitiator?this.ephemeralKeypair.public:this.remoteEphemeralPublicKey:this.isInitiator?this.staticKeypair.public:this.remoteStaticPublicKey))),this.pattern.responderPreMessage.forEach((t=>this.mixHash("e"===t?this.isInitiator?this.remoteEphemeralPublicKey:this.ephemeralKeypair.public:this.isInitiator?this.remoteStaticPublicKey:this.staticKeypair.public)))}get isInitiator(){return"initiator"===this.role}mixHash(t){this.handshakeHash=this.algorithms.hash(U(this.handshakeHash,t))}mixKey(t){const[e,s]=this.algorithms.hkdf(this.chainingKey,t,2);this.chainingKey=e,this.cipherState=new S(this.algorithms,s)}mixKeyAndHashNextPSK(){const t=this.preSharedKeys.shift(),[e,s,i]=this.algorithms.hkdf(this.chainingKey,t,3);this.chainingKey=e,this.mixHash(s),this.cipherState=new S(this.algorithms,i)}encryptAndHash(t){const e=this.cipherState.encrypt(t,this.handshakeHash);return this.mixHash(e),e}decryptAndHash(t){const e=this.cipherState.decrypt(t,this.handshakeHash);return this.mixHash(t),e}_split(){if(this.stepIndex<this.pattern.messages.length)return null;{let[t,e]=this.algorithms.hkdf(this.chainingKey,v,2).map((t=>new S(this.algorithms,t)));return this.isInitiator?{send:t,recv:e}:{send:e,recv:t}}}_nextStep(){if(this.stepIndex>=this.pattern.messages.length)throw new Error("Handshake already complete, cannot continue");return this.pattern.messages[this.stepIndex++]}_processKeyMixToken(t){switch(t){case"ee":this.mixKey(this.algorithms.dh(this.ephemeralKeypair,this.remoteEphemeralPublicKey));break;case"es":this.mixKey(this.isInitiator?this.algorithms.dh(this.ephemeralKeypair,this.remoteStaticPublicKey):this.algorithms.dh(this.staticKeypair,this.remoteEphemeralPublicKey));break;case"se":this.mixKey(this.isInitiator?this.algorithms.dh(this.staticKeypair,this.remoteEphemeralPublicKey):this.algorithms.dh(this.ephemeralKeypair,this.remoteStaticPublicKey));break;case"ss":this.mixKey(this.algorithms.dh(this.staticKeypair,this.remoteStaticPublicKey));break;case"psk":this.mixKeyAndHashNextPSK()}}writeMessage(t){const e=[];let s;if(this._nextStep().forEach((t=>{switch(t){case"e":e.push(this.ephemeralKeypair.public),this.mixHash(this.ephemeralKeypair.public),this.preSharedKeys&&this.mixKey(this.ephemeralKeypair.public);break;case"s":e.push(this.encryptAndHash(this.staticKeypair.public));break;default:this._processKeyMixToken(t)}})),e.push(this.encryptAndHash(t)),1===e.length)s=e[0];else{s=new Uint8Array(e.reduce(((t,e)=>t+e.byteLength),0));let t=0;e.forEach((e=>{s.set(e,t),t+=e.byteLength}))}return{packet:s,finished:this._split()}}readMessage(t){const e=e=>{const s=t.slice(0,e);return t=t.subarray(e),s};this._nextStep().forEach((t=>{switch(t){case"e":this.remoteEphemeralPublicKey=e(this.algorithms.dhlen),this.mixHash(this.remoteEphemeralPublicKey),this.preSharedKeys&&this.mixKey(this.remoteEphemeralPublicKey);break;case"s":this.remoteStaticPublicKey=this.decryptAndHash(e(this.algorithms.dhlen+(this.cipherState.view?16:0)));break;default:this._processKeyMixToken(t)}}));return{message:this.decryptAndHash(t),finished:this._split()}}async completeHandshake(t,e,s=(async t=>{}),i=(async()=>new Uint8Array(0))){const h=async()=>{const{packet:e,finished:s}=this.writeMessage(await i());return await t(e),s||r()},r=async()=>{const{message:t,finished:i}=this.readMessage(await e());return await s(t),i||h()};return this.isInitiator?h():r()}},NoiseProtocolAlgorithms:M,Nonce:A,bytesAppend:U,bytesXor:E});const L={};function H(t,e,s,i){const h={name:t,baseName:t,messages:e,initiatorPreMessage:s,responderPreMessage:i};L[h.name]=h}H("N",[["e","es"]],[],["s"]),H("K",[["e","es","ss"]],["s"],["s"]),H("X",[["e","es","s","ss"]],[],["s"]),H("NN",[["e"],["e","ee"]],[],[]),H("NK",[["e","es"],["e","ee"]],[],["s"]),H("NX",[["e"],["e","ee","s","es"]],[],[]),H("KN",[["e"],["e","ee","se"]],["s"],[]),H("KK",[["e","es","ss"],["e","ee","se"]],["s"],["s"]),H("KX",[["e"],["e","ee","se","s","es"]],["s"],[]),H("XN",[["e"],["e","ee"],["s","se"]],[],[]),H("XK",[["e","es"],["e","ee"],["s","se"]],[],["s"]),H("XX",[["e"],["e","ee","s","es"],["s","se"]],[],[]),H("IN",[["e","s"],["e","ee","se"]],[],[]),H("IK",[["e","es","s","ss"],["e","ee","se"]],[],["s"]),H("IX",[["e","s"],["e","ee","se","s","es"]],[],[]);const N=/^([NKX]|[NKXI]1?[NKX]1?)([a-z][a-z0-9]*(\+[a-z][a-z0-9]*)*)?$/,x=/^psk([0-9]+)$/;var P=Object.freeze({__proto__:null,PATTERNS:L,isOneWay:function(t){return 1===t.baseName.length},lookupPattern:function(t){var e,s,i;const h=N.exec(t);if(null===h)return null;const r=null!==(s=null===(e=h[2])||void 0===e?void 0:e.split("+"))&&void 0!==s?s:[];let n=null!==(i=L[h[1]])&&void 0!==i?i:null;return n?(r.forEach((t=>n=n&&function(t,e){const s=x.exec(e);if(null===s)return null;const i=parseInt(s[1],10),h=t.messages;return Object.assign(Object.assign({},t),{messages:0===i?[["psk",...h[0]],...h.slice(1)]:[...h.slice(0,i-1),[...h[i-1],"psk"],...h.slice(i)]})}(n,t))),n&&Object.assign(Object.assign({},n),{name:t})):null}});const B=(()=>{var t="undefined"!=typeof self?self.crypto||self.msCrypto:null;if(t&&t.getRandomValues){const e=65536;return(s,i)=>{for(let h=0;h<i;h+=e)t.getRandomValues(s.subarray(h,h+Math.min(i-h,e)))}}if("undefined"!=typeof require&&(t=require("crypto"))&&t.randomBytes)return(e,s)=>e.set(t.randomBytes(s));throw new Error("No usable randomness source found")})();function T(t){const e=new Uint8Array(t);return B(e,t),e}var C=Object.freeze({__proto__:null,_randomBytes:B,randomBytes:T});function O(){return new Float64Array(16)}const Y=new Uint8Array(32);Y[0]=9;const I=O();function z(t){let e=1;for(let s=0;s<16;s++){const i=t[s]+e+65535;e=Math.floor(i/65536),t[s]=i-65536*e}t[0]+=e-1+37*(e-1)}function X(t,e,s){const i=~(s-1);for(let s=0;s<16;s++){const h=i&(t[s]^e[s]);t[s]^=h,e[s]^=h}}function j(t,e,s){for(let i=0;i<16;i++)t[i]=e[i]+s[i]}function D(t,e,s){for(let i=0;i<16;i++)t[i]=e[i]-s[i]}function V(t,e,s){let i=0,h=0,r=0,n=0,a=0,o=0,l=0,c=0,f=0,u=0,y=0,p=0,d=0,m=0,g=0,b=0,K=0,w=0,_=0,A=0,E=0,U=0,v=0,M=0,S=0,k=0,L=0,H=0,N=0,x=0,P=0;const B=s[0],T=s[1],C=s[2],O=s[3],Y=s[4],I=s[5],z=s[6],X=s[7],j=s[8],D=s[9],V=s[10],R=s[11],$=s[12],q=s[13],G=s[14],F=s[15];let W=e[0];i+=W*B,h+=W*T,r+=W*C,n+=W*O,a+=W*Y,o+=W*I,l+=W*z,c+=W*X,f+=W*j,u+=W*D,y+=W*V,p+=W*R,d+=W*$,m+=W*q,g+=W*G,b+=W*F,W=e[1],h+=W*B,r+=W*T,n+=W*C,a+=W*O,o+=W*Y,l+=W*I,c+=W*z,f+=W*X,u+=W*j,y+=W*D,p+=W*V,d+=W*R,m+=W*$,g+=W*q,b+=W*G,K+=W*F,W=e[2],r+=W*B,n+=W*T,a+=W*C,o+=W*O,l+=W*Y,c+=W*I,f+=W*z,u+=W*X,y+=W*j,p+=W*D,d+=W*V,m+=W*R,g+=W*$,b+=W*q,K+=W*G,w+=W*F,W=e[3],n+=W*B,a+=W*T,o+=W*C,l+=W*O,c+=W*Y,f+=W*I,u+=W*z,y+=W*X,p+=W*j,d+=W*D,m+=W*V,g+=W*R,b+=W*$,K+=W*q,w+=W*G,_+=W*F,W=e[4],a+=W*B,o+=W*T,l+=W*C,c+=W*O,f+=W*Y,u+=W*I,y+=W*z,p+=W*X,d+=W*j,m+=W*D,g+=W*V,b+=W*R,K+=W*$,w+=W*q,_+=W*G,A+=W*F,W=e[5],o+=W*B,l+=W*T,c+=W*C,f+=W*O,u+=W*Y,y+=W*I,p+=W*z,d+=W*X,m+=W*j,g+=W*D,b+=W*V,K+=W*R,w+=W*$,_+=W*q,A+=W*G,E+=W*F,W=e[6],l+=W*B,c+=W*T,f+=W*C,u+=W*O,y+=W*Y,p+=W*I,d+=W*z,m+=W*X,g+=W*j,b+=W*D,K+=W*V,w+=W*R,_+=W*$,A+=W*q,E+=W*G,U+=W*F,W=e[7],c+=W*B,f+=W*T,u+=W*C,y+=W*O,p+=W*Y,d+=W*I,m+=W*z,g+=W*X,b+=W*j,K+=W*D,w+=W*V,_+=W*R,A+=W*$,E+=W*q,U+=W*G,v+=W*F,W=e[8],f+=W*B,u+=W*T,y+=W*C,p+=W*O,d+=W*Y,m+=W*I,g+=W*z,b+=W*X,K+=W*j,w+=W*D,_+=W*V,A+=W*R,E+=W*$,U+=W*q,v+=W*G,M+=W*F,W=e[9],u+=W*B,y+=W*T,p+=W*C,d+=W*O,m+=W*Y,g+=W*I,b+=W*z,K+=W*X,w+=W*j,_+=W*D,A+=W*V,E+=W*R,U+=W*$,v+=W*q,M+=W*G,S+=W*F,W=e[10],y+=W*B,p+=W*T,d+=W*C,m+=W*O,g+=W*Y,b+=W*I,K+=W*z,w+=W*X,_+=W*j,A+=W*D,E+=W*V,U+=W*R,v+=W*$,M+=W*q,S+=W*G,k+=W*F,W=e[11],p+=W*B,d+=W*T,m+=W*C,g+=W*O,b+=W*Y,K+=W*I,w+=W*z,_+=W*X,A+=W*j,E+=W*D,U+=W*V,v+=W*R,M+=W*$,S+=W*q,k+=W*G,L+=W*F,W=e[12],d+=W*B,m+=W*T,g+=W*C,b+=W*O,K+=W*Y,w+=W*I,_+=W*z,A+=W*X,E+=W*j,U+=W*D,v+=W*V,M+=W*R,S+=W*$,k+=W*q,L+=W*G,H+=W*F,W=e[13],m+=W*B,g+=W*T,b+=W*C,K+=W*O,w+=W*Y,_+=W*I,A+=W*z,E+=W*X,U+=W*j,v+=W*D,M+=W*V,S+=W*R,k+=W*$,L+=W*q,H+=W*G,N+=W*F,W=e[14],g+=W*B,b+=W*T,K+=W*C,w+=W*O,_+=W*Y,A+=W*I,E+=W*z,U+=W*X,v+=W*j,M+=W*D,S+=W*V,k+=W*R,L+=W*$,H+=W*q,N+=W*G,x+=W*F,W=e[15],b+=W*B,K+=W*T,w+=W*C,_+=W*O,A+=W*Y,E+=W*I,U+=W*z,v+=W*X,M+=W*j,S+=W*D,k+=W*V,L+=W*R,H+=W*$,N+=W*q,x+=W*G,P+=W*F,i+=38*K,h+=38*w,r+=38*_,n+=38*A,a+=38*E,o+=38*U,l+=38*v,c+=38*M,f+=38*S,u+=38*k,y+=38*L,p+=38*H,d+=38*N,m+=38*x,g+=38*P;let Z=1;W=i+Z+65535,Z=Math.floor(W/65536),i=W-65536*Z,W=h+Z+65535,Z=Math.floor(W/65536),h=W-65536*Z,W=r+Z+65535,Z=Math.floor(W/65536),r=W-65536*Z,W=n+Z+65535,Z=Math.floor(W/65536),n=W-65536*Z,W=a+Z+65535,Z=Math.floor(W/65536),a=W-65536*Z,W=o+Z+65535,Z=Math.floor(W/65536),o=W-65536*Z,W=l+Z+65535,Z=Math.floor(W/65536),l=W-65536*Z,W=c+Z+65535,Z=Math.floor(W/65536),c=W-65536*Z,W=f+Z+65535,Z=Math.floor(W/65536),f=W-65536*Z,W=u+Z+65535,Z=Math.floor(W/65536),u=W-65536*Z,W=y+Z+65535,Z=Math.floor(W/65536),y=W-65536*Z,W=p+Z+65535,Z=Math.floor(W/65536),p=W-65536*Z,W=d+Z+65535,Z=Math.floor(W/65536),d=W-65536*Z,W=m+Z+65535,Z=Math.floor(W/65536),m=W-65536*Z,W=g+Z+65535,Z=Math.floor(W/65536),g=W-65536*Z,W=b+Z+65535,Z=Math.floor(W/65536),b=W-65536*Z,i+=Z-1+37*(Z-1),Z=1,W=i+Z+65535,Z=Math.floor(W/65536),i=W-65536*Z,W=h+Z+65535,Z=Math.floor(W/65536),h=W-65536*Z,W=r+Z+65535,Z=Math.floor(W/65536),r=W-65536*Z,W=n+Z+65535,Z=Math.floor(W/65536),n=W-65536*Z,W=a+Z+65535,Z=Math.floor(W/65536),a=W-65536*Z,W=o+Z+65535,Z=Math.floor(W/65536),o=W-65536*Z,W=l+Z+65535,Z=Math.floor(W/65536),l=W-65536*Z,W=c+Z+65535,Z=Math.floor(W/65536),c=W-65536*Z,W=f+Z+65535,Z=Math.floor(W/65536),f=W-65536*Z,W=u+Z+65535,Z=Math.floor(W/65536),u=W-65536*Z,W=y+Z+65535,Z=Math.floor(W/65536),y=W-65536*Z,W=p+Z+65535,Z=Math.floor(W/65536),p=W-65536*Z,W=d+Z+65535,Z=Math.floor(W/65536),d=W-65536*Z,W=m+Z+65535,Z=Math.floor(W/65536),m=W-65536*Z,W=g+Z+65535,Z=Math.floor(W/65536),g=W-65536*Z,W=b+Z+65535,Z=Math.floor(W/65536),b=W-65536*Z,i+=Z-1+37*(Z-1),t[0]=i,t[1]=h,t[2]=r,t[3]=n,t[4]=a,t[5]=o,t[6]=l,t[7]=c,t[8]=f,t[9]=u,t[10]=y,t[11]=p,t[12]=d,t[13]=m,t[14]=g,t[15]=b}function R(t,e){V(t,e,e)}function $(t,e,s){const i=new Uint8Array(32),h=new Float64Array(80),r=O(),n=O(),a=O(),o=O(),l=O(),c=O();for(let t=0;t<31;t++)i[t]=e[t];i[31]=127&e[31]|64,i[0]&=248,function(t,e){for(let s=0;s<16;s++)t[s]=e[2*s]+(e[2*s+1]<<8);t[15]&=32767}(h,s);for(let t=0;t<16;t++)n[t]=h[t],o[t]=r[t]=a[t]=0;r[0]=o[0]=1;for(let t=254;t>=0;--t){const e=i[t>>>3]>>>(7&t)&1;X(r,n,e),X(a,o,e),j(l,r,a),D(r,r,a),j(a,n,o),D(n,n,o),R(o,l),R(c,r),V(r,a,r),V(a,n,l),j(l,r,a),D(r,r,a),R(n,r),D(a,o,c),V(r,a,I),j(r,r,o),V(a,a,r),V(r,o,c),V(o,n,h),R(n,l),X(r,n,e),X(a,o,e)}for(let t=0;t<16;t++)h[t+16]=r[t],h[t+32]=a[t],h[t+48]=n[t],h[t+64]=o[t];const f=h.subarray(32),u=h.subarray(16);!function(t,e){const s=O();for(let t=0;t<16;t++)s[t]=e[t];for(let t=253;t>=0;t--)R(s,s),2!==t&&4!==t&&V(s,s,e);for(let e=0;e<16;e++)t[e]=s[e]}(f,f),V(u,u,f),function(t,e){const s=O(),i=O();for(let t=0;t<16;t++)i[t]=e[t];z(i),z(i),z(i);for(let t=0;t<2;t++){s[0]=i[0]-65517;for(let t=1;t<15;t++)s[t]=i[t]-65535-(s[t-1]>>16&1),s[t-1]&=65535;s[15]=i[15]-32767-(s[14]>>16&1);const t=s[15]>>16&1;s[14]&=65535,X(i,s,1-t)}for(let e=0;e<16;e++)t[2*e]=255&i[e],t[2*e+1]=i[e]>>8}(t,u)}function q(t,e){$(t,e,Y)}function G(t,e){if(32!==t.length)throw new Error("bad n size");if(32!==e.length)throw new Error("bad p size");const s=new Uint8Array(32);return $(s,t,e),s}function F(t){if(32!==t.length)throw new Error("bad n size");const e=new Uint8Array(32);return q(e,t),e}I[0]=56129,I[1]=1,G.scalarLength=32,G.groupElementLength=32;var W=Object.freeze({__proto__:null,crypto_scalarmult:$,crypto_scalarmult_BYTES:32,crypto_scalarmult_SCALARBYTES:32,crypto_scalarmult_base:q,scalarMult:G,scalarMultBase:F});function Z(t){const e=new DataView(new ArrayBuffer(12));return e.setUint32(4,t.lo,!0),e.setUint32(8,t.hi,!0),e}var J=Object.freeze({__proto__:null,Noise_25519_ChaChaPoly_BLAKE2s:class extends M{constructor(){super()}dhName(){return"25519"}generateKeypair(){const t=T(G.scalarLength);return{public:F(t),secret:t}}dh(t,e){return G(t.secret,e)}cipherName(){return"ChaChaPoly"}encrypt(t,e,s,i){const h=new Uint8Array(s.byteLength+16);return u(s,h,s.byteLength,h.subarray(s.byteLength),t,Z(e),i),h}decrypt(t,e,s,i){const h=new Uint8Array(s.byteLength-16);if(!y(h,s,h.byteLength,s.subarray(h.byteLength),t,Z(e),i))throw new Error("packet decryption failed");return h}hashName(){return"BLAKE2s"}hash(t){return w.digest(t)}hashBlocklen(){return w.BLOCKLEN}}});t.AEAD=p,t.BLAKE2=_,t.ChaCha20=n,t.Noise=k,t.NoiseProfiles=J,t.Patterns=P,t.Poly1305=o,t.Random=C,t.X25519=W}));
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).SaltyCrypto={})}(this,(function(t){"use strict";function e(t,e){return t<<e|t>>>32-e}function s(t,s,i,h,r){t[s]+=t[i],t[r]^=t[s],t[r]=e(t[r],16),t[h]+=t[r],t[i]^=t[h],t[i]=e(t[i],12),t[s]+=t[i],t[r]^=t[s],t[r]=e(t[r],8),t[h]+=t[r],t[i]^=t[h],t[i]=e(t[i],7)}function i(t,e,s,i){t[0]+=1634760805,t[1]+=857760878,t[2]+=2036477234,t[3]+=1797285236,t[4]+=e.getUint32(0,!0),t[5]+=e.getUint32(4,!0),t[6]+=e.getUint32(8,!0),t[7]+=e.getUint32(12,!0),t[8]+=e.getUint32(16,!0),t[9]+=e.getUint32(20,!0),t[10]+=e.getUint32(24,!0),t[11]+=e.getUint32(28,!0),t[12]+=s,t[13]+=i.getUint32(0,!0),t[14]+=i.getUint32(4,!0),t[15]+=i.getUint32(8,!0)}function h(t,e,h){const r=new Uint32Array(16);i(r,t,e,h);for(let t=0;t<20;t+=2)s(r,0,4,8,12),s(r,1,5,9,13),s(r,2,6,10,14),s(r,3,7,11,15),s(r,0,5,10,15),s(r,1,6,11,12),s(r,2,7,8,13),s(r,3,4,9,14);return i(r,t,e,h),r}function r(t,e,s,i,r=0,n=s.byteLength){const a=n>>6,o=63&n;for(let n=0;n<a;n++){const a=h(t,r+n,e);for(let t=0;t<64;t++)i[(n<<6)+t]=s[(n<<6)+t]^a[t>>2]>>((3&t)<<3)}if(0!==o){const n=h(t,r+a,e);for(let t=0;t<o;t++)i[(a<<6)+t]=s[(a<<6)+t]^n[t>>2]>>((3&t)<<3)}}var n=Object.freeze({__proto__:null,CHACHA20_BLOCKBYTES:64,CHACHA20_KEYBYTES:32,CHACHA20_NONCEBYTES:12,chacha20:r,chacha20_block:h,chacha20_quarter_round:s});class a{static digest(t,e){const s=new a(t);s.update(e,0,e.byteLength);const i=new Uint8Array(a.TAGBYTES);return s.finish(i,0),i}constructor(t){this.key=t,this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.leftover=0,this.fin=0;const e=255&t[0]|(255&t[1])<<8;this.r[0]=8191&e;const s=255&t[2]|(255&t[3])<<8;this.r[1]=8191&(e>>>13|s<<3);const i=255&t[4]|(255&t[5])<<8;this.r[2]=7939&(s>>>10|i<<6);const h=255&t[6]|(255&t[7])<<8;this.r[3]=8191&(i>>>7|h<<9);const r=255&t[8]|(255&t[9])<<8;this.r[4]=255&(h>>>4|r<<12),this.r[5]=r>>>1&8190;const n=255&t[10]|(255&t[11])<<8;this.r[6]=8191&(r>>>14|n<<2);const a=255&t[12]|(255&t[13])<<8;this.r[7]=8065&(n>>>11|a<<5);const o=255&t[14]|(255&t[15])<<8;this.r[8]=8191&(a>>>8|o<<8),this.r[9]=o>>>5&127,this.pad[0]=255&t[16]|(255&t[17])<<8,this.pad[1]=255&t[18]|(255&t[19])<<8,this.pad[2]=255&t[20]|(255&t[21])<<8,this.pad[3]=255&t[22]|(255&t[23])<<8,this.pad[4]=255&t[24]|(255&t[25])<<8,this.pad[5]=255&t[26]|(255&t[27])<<8,this.pad[6]=255&t[28]|(255&t[29])<<8,this.pad[7]=255&t[30]|(255&t[31])<<8}blocks(t,e,s){const i=this.fin?0:2048;let h=this.h[0],r=this.h[1],n=this.h[2],a=this.h[3],o=this.h[4],c=this.h[5],l=this.h[6],u=this.h[7],f=this.h[8],y=this.h[9],p=this.r[0],d=this.r[1],m=this.r[2],g=this.r[3],b=this.r[4],K=this.r[5],w=this.r[6],A=this.r[7],_=this.r[8],E=this.r[9];for(;s>=16;){const U=255&t[e+0]|(255&t[e+1])<<8;h+=8191&U;const v=255&t[e+2]|(255&t[e+3])<<8;r+=8191&(U>>>13|v<<3);const M=255&t[e+4]|(255&t[e+5])<<8;n+=8191&(v>>>10|M<<6);const S=255&t[e+6]|(255&t[e+7])<<8;a+=8191&(M>>>7|S<<9);const N=255&t[e+8]|(255&t[e+9])<<8;o+=8191&(S>>>4|N<<12),c+=N>>>1&8191;const L=255&t[e+10]|(255&t[e+11])<<8;l+=8191&(N>>>14|L<<2);const k=255&t[e+12]|(255&t[e+13])<<8;u+=8191&(L>>>11|k<<5);const x=255&t[e+14]|(255&t[e+15])<<8;f+=8191&(k>>>8|x<<8),y+=x>>>5|i;let H=0,P=H;P+=h*p,P+=r*(5*E),P+=n*(5*_),P+=a*(5*A),P+=o*(5*w),H=P>>>13,P&=8191,P+=c*(5*K),P+=l*(5*b),P+=u*(5*g),P+=f*(5*m),P+=y*(5*d),H+=P>>>13,P&=8191;let B=H;B+=h*d,B+=r*p,B+=n*(5*E),B+=a*(5*_),B+=o*(5*A),H=B>>>13,B&=8191,B+=c*(5*w),B+=l*(5*K),B+=u*(5*b),B+=f*(5*g),B+=y*(5*m),H+=B>>>13,B&=8191;let X=H;X+=h*m,X+=r*d,X+=n*p,X+=a*(5*E),X+=o*(5*_),H=X>>>13,X&=8191,X+=c*(5*A),X+=l*(5*w),X+=u*(5*K),X+=f*(5*b),X+=y*(5*g),H+=X>>>13,X&=8191;let C=H;C+=h*g,C+=r*m,C+=n*d,C+=a*p,C+=o*(5*E),H=C>>>13,C&=8191,C+=c*(5*_),C+=l*(5*A),C+=u*(5*w),C+=f*(5*K),C+=y*(5*b),H+=C>>>13,C&=8191;let T=H;T+=h*b,T+=r*g,T+=n*m,T+=a*d,T+=o*p,H=T>>>13,T&=8191,T+=c*(5*E),T+=l*(5*_),T+=u*(5*A),T+=f*(5*w),T+=y*(5*K),H+=T>>>13,T&=8191;let O=H;O+=h*K,O+=r*b,O+=n*g,O+=a*m,O+=o*d,H=O>>>13,O&=8191,O+=c*p,O+=l*(5*E),O+=u*(5*_),O+=f*(5*A),O+=y*(5*w),H+=O>>>13,O&=8191;let I=H;I+=h*w,I+=r*K,I+=n*b,I+=a*g,I+=o*m,H=I>>>13,I&=8191,I+=c*d,I+=l*p,I+=u*(5*E),I+=f*(5*_),I+=y*(5*A),H+=I>>>13,I&=8191;let Y=H;Y+=h*A,Y+=r*w,Y+=n*K,Y+=a*b,Y+=o*g,H=Y>>>13,Y&=8191,Y+=c*m,Y+=l*d,Y+=u*p,Y+=f*(5*E),Y+=y*(5*_),H+=Y>>>13,Y&=8191;let z=H;z+=h*_,z+=r*A,z+=n*w,z+=a*K,z+=o*b,H=z>>>13,z&=8191,z+=c*g,z+=l*m,z+=u*d,z+=f*p,z+=y*(5*E),H+=z>>>13,z&=8191;let j=H;j+=h*E,j+=r*_,j+=n*A,j+=a*w,j+=o*K,H=j>>>13,j&=8191,j+=c*b,j+=l*g,j+=u*m,j+=f*d,j+=y*p,H+=j>>>13,j&=8191,H=(H<<2)+H|0,H=H+P|0,P=8191&H,H>>>=13,B+=H,h=P,r=B,n=X,a=C,o=T,c=O,l=I,u=Y,f=z,y=j,e+=16,s-=16}this.h[0]=h,this.h[1]=r,this.h[2]=n,this.h[3]=a,this.h[4]=o,this.h[5]=c,this.h[6]=l,this.h[7]=u,this.h[8]=f,this.h[9]=y}finish(t,e){if(this.leftover){let t=this.leftover;for(this.buffer[t++]=1;t<16;t++)this.buffer[t]=0;this.fin=1,this.blocks(this.buffer,0,16)}let s=this.h[1]>>>13;this.h[1]&=8191;for(let t=2;t<10;t++)this.h[t]+=s,s=this.h[t]>>>13,this.h[t]&=8191;this.h[0]+=5*s,s=this.h[0]>>>13,this.h[0]&=8191,this.h[1]+=s,s=this.h[1]>>>13,this.h[1]&=8191,this.h[2]+=s;const i=new Uint16Array(10);i[0]=this.h[0]+5,s=i[0]>>>13,i[0]&=8191;for(let t=1;t<10;t++)i[t]=this.h[t]+s,s=i[t]>>>13,i[t]&=8191;i[9]-=8192;let h=(1^s)-1;for(let t=0;t<10;t++)i[t]&=h;h=~h;for(let t=0;t<10;t++)this.h[t]=this.h[t]&h|i[t];this.h[0]=65535&(this.h[0]|this.h[1]<<13),this.h[1]=65535&(this.h[1]>>>3|this.h[2]<<10),this.h[2]=65535&(this.h[2]>>>6|this.h[3]<<7),this.h[3]=65535&(this.h[3]>>>9|this.h[4]<<4),this.h[4]=65535&(this.h[4]>>>12|this.h[5]<<1|this.h[6]<<14),this.h[5]=65535&(this.h[6]>>>2|this.h[7]<<11),this.h[6]=65535&(this.h[7]>>>5|this.h[8]<<8),this.h[7]=65535&(this.h[8]>>>8|this.h[9]<<5);let r=this.h[0]+this.pad[0];this.h[0]=65535&r;for(let t=1;t<8;t++)r=(this.h[t]+this.pad[t]|0)+(r>>>16)|0,this.h[t]=65535&r;t[e+0]=this.h[0]>>>0&255,t[e+1]=this.h[0]>>>8&255,t[e+2]=this.h[1]>>>0&255,t[e+3]=this.h[1]>>>8&255,t[e+4]=this.h[2]>>>0&255,t[e+5]=this.h[2]>>>8&255,t[e+6]=this.h[3]>>>0&255,t[e+7]=this.h[3]>>>8&255,t[e+8]=this.h[4]>>>0&255,t[e+9]=this.h[4]>>>8&255,t[e+10]=this.h[5]>>>0&255,t[e+11]=this.h[5]>>>8&255,t[e+12]=this.h[6]>>>0&255,t[e+13]=this.h[6]>>>8&255,t[e+14]=this.h[7]>>>0&255,t[e+15]=this.h[7]>>>8&255}update(t,e,s){if(this.leftover){let i=16-this.leftover;i>s&&(i=s);for(let s=0;s<i;s++)this.buffer[this.leftover+s]=t[e+s];if(s-=i,e+=i,this.leftover+=i,this.leftover<16)return;this.blocks(this.buffer,0,16),this.leftover=0}if(s>=16){const i=s-s%16;this.blocks(t,e,i),e+=i,s-=i}if(s){for(let i=0;i<s;i++)this.buffer[this.leftover+i]=t[e+i];this.leftover+=s}}}a.KEYBYTES=32,a.TAGBYTES=16,a.BLOCKBYTES=16;var o=Object.freeze({__proto__:null,Poly1305:a});const c=new Uint8Array(16);function l(t,e){const s=15&e;0!==s&&t.update(c,0,16-s)}function u(t,e,s,i,h,n){const o=new Uint8Array(a.KEYBYTES);r(e,s,o,o,0);const c=new a(o);void 0!==n&&(c.update(n,0,n.byteLength),l(c,n.byteLength)),c.update(i,0,h),l(c,h);const u=new Uint8Array(16),f=new DataView(u.buffer);void 0!==n&&f.setUint32(0,n.byteLength,!0),f.setUint32(8,h,!0),c.update(u,0,u.byteLength),c.finish(t,0)}function f(t,e,s,i,h,n,a){r(h,n,t,e,1,s),u(i,h,n,e,s,a)}function y(t,e,s,i){const h=new Uint8Array(t.byteLength+16);return f(t,h,t.byteLength,h.subarray(t.byteLength),e,s,i),h}function p(t,e,s,i,h,n,a){const o=new Uint8Array(16);u(o,h,n,e,s,a);const c=0===function(t,e,s){let i=0;for(let h=0;h<s;h++)i|=t[h]^e[h];return(1&i-1>>>8)-1}(o,i,o.byteLength);return c&&r(h,n,e,t,1,s),c}class d extends Error{}function m(t,e,s,i){const h=new Uint8Array(t.byteLength-16);if(!p(h,t,h.byteLength,t.subarray(h.byteLength),e,s,i))throw new d("ChaCha20Poly1305 AEAD authentication failed");return h}var g=Object.freeze({__proto__:null,AEAD_CHACHA20_POLY1305_KEYBYTES:32,AEAD_CHACHA20_POLY1305_NONCEBYTES:12,AEAD_CHACHA20_POLY1305_TAGBYTES:16,AuthenticationFailure:d,aead_decrypt:m,aead_decrypt_detached:p,aead_encrypt:y,aead_encrypt_detached:f});function b(t,e){return t>>>e|t<<32-e}function K(t,e,s,i,h,r,n){t[e]=t[e]+t[s]+r,t[h]=b(t[h]^t[e],16),t[i]=t[i]+t[h],t[s]=b(t[s]^t[i],12),t[e]=t[e]+t[s]+n,t[h]=b(t[h]^t[e],8),t[i]=t[i]+t[h],t[s]=b(t[s]^t[i],7)}const w=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),A=Uint8Array.from([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0]);function _(t,e){return A[(t<<4)+e]}class E{static digest(t,e,s){const i=new E(e,s);return i.update(t),i.final()}constructor(t=E.OUTBYTES,e){var s;this.outlen=t,this.b=new Uint8Array(64),this.bv=new DataView(this.b.buffer),this.h=Uint32Array.from(w),this.t=new Uint32Array(2),this.c=0;const i=null!==(s=null==e?void 0:e.byteLength)&&void 0!==s?s:0;if(0==t||t>32||i>32)throw new Error("illegal BLAKE2s parameter length(s)");this.h[0]^=16842752^i<<8^t,void 0!==e&&i>0&&(this.update(e),this.c=64)}update(t){for(let e=0;e<t.byteLength;e++)64==this.c&&(this.t[0]+=this.c,this.t[0]<this.c&&this.t[1]++,this.compress(!1),this.c=0),this.b[this.c++]=t[e]}final(t){for(this.t[0]+=this.c,this.t[0]<this.c&&this.t[1]++;this.c<64;)this.b[this.c++]=0;this.compress(!0),void 0===t&&(t=new Uint8Array(this.outlen));for(let e=0;e<this.outlen;e++)t[e]=this.h[e>>2]>>8*(3&e)&255;return t}compress(t){const e=new Uint32Array(16),s=new Uint32Array(16);for(let t=0;t<8;t++)e[t]=this.h[t],e[t+8]=w[t];e[12]^=this.t[0],e[13]^=this.t[1],t&&(e[14]=~e[14]);for(let t=0;t<16;t++)s[t]=this.bv.getUint32(t<<2,!0);for(let t=0;t<10;t++)K(e,0,4,8,12,s[_(t,0)],s[_(t,1)]),K(e,1,5,9,13,s[_(t,2)],s[_(t,3)]),K(e,2,6,10,14,s[_(t,4)],s[_(t,5)]),K(e,3,7,11,15,s[_(t,6)],s[_(t,7)]),K(e,0,5,10,15,s[_(t,8)],s[_(t,9)]),K(e,1,6,11,12,s[_(t,10)],s[_(t,11)]),K(e,2,7,8,13,s[_(t,12)],s[_(t,13)]),K(e,3,4,9,14,s[_(t,14)],s[_(t,15)]);for(let t=0;t<8;t++)this.h[t]^=e[t]^e[t+8]}}E.KEYBYTES=32,E.OUTBYTES=32,E.BLOCKLEN=64;var U=Object.freeze({__proto__:null,BLAKE2s:E});class v{constructor(t=0,e=0){this.lo=t,this.hi=e}increment(){const t=this.lo,e=t+1|0;this.lo=e,e<t&&(this.hi=this.hi+1|0)}reset(t=0,e=0){this.lo=t,this.hi=e}static get MAX(){return new v(4294967295,4294967295)}}function M(t,e){const s=Math.min(t.byteLength,e.byteLength),i=new Uint8Array(s);for(let h=0;h<s;h++)i[h]=t[h]^e[h];return i}function S(t,e){const s=new Uint8Array(t.byteLength+e.byteLength);return s.set(t,0),s.set(e,t.byteLength),s}const N=new Uint8Array(0);class L{constructor(t){const e=this.generateKeypair();this.dhlen=this.dh(e,e.public).byteLength,this.hmac=null!=t?t:function(t){const e=new Uint8Array(t.hashBlocklen());e.fill(54);const s=new Uint8Array(t.hashBlocklen());return s.fill(92),(i,h)=>{const r=t._padOrHash(i,t.hashBlocklen());return t.hash(S(M(r,s),t.hash(S(M(r,e),h))))}}(this)}rekey(t){return new DataView(this.encrypt(t,v.MAX,new Uint8Array(32)).buffer)}_padOrHash(t,e){const s=t.byteLength>e?this.hash(t):t;return S(s,new Uint8Array(e-s.byteLength))}hkdf(t,e,s){const i=this.hmac(t,e),h=this.hmac(i,Uint8Array.from([1])),r=this.hmac(i,S(h,Uint8Array.from([2])));switch(s){case 2:return[h,r];case 3:return[h,r,this.hmac(i,S(r,Uint8Array.from([3])))]}}matchingPattern(t){const e=new RegExp(`^Noise_([A-Za-z0-9+]+)_${this.dhName()}_${this.cipherName()}_${this.hashName()}$`).exec(t);return null===e?null:e[1]}}class k{constructor(t,e){this.algorithms=t,this.view=null,this.nonce=new v,void 0!==e&&(this.view=new DataView(e.buffer))}encrypt(t,e){if(null===this.view)return t;const s=this.algorithms.encrypt(this.view,this.nonce,t,e);return this.nonce.increment(),s}decrypt(t,e){if(null===this.view)return t;const s=this.algorithms.decrypt(this.view,this.nonce,t,e);return this.nonce.increment(),s}rekey(){null!==this.view&&(this.view=this.algorithms.rekey(this.view))}}var x=Object.freeze({__proto__:null,CipherState:k,NoiseHandshake:class{constructor(t,e,s,i={}){var h,r,n,a,o;this.algorithms=t,this.pattern=e,this.role=s,this.stepIndex=0,this.staticKeypair=null!==(h=i.staticKeypair)&&void 0!==h?h:this.algorithms.generateKeypair(),this.remoteStaticPublicKey=null!==(r=i.remoteStaticPublicKey)&&void 0!==r?r:null,this.ephemeralKeypair=null!==(n=i.pregeneratedEphemeralKeypair)&&void 0!==n?n:this.algorithms.generateKeypair(),this.remoteEphemeralPublicKey=null!==(a=i.remotePregeneratedEphemeralPublicKey)&&void 0!==a?a:null,this.preSharedKeys=i.preSharedKeys,this.preSharedKeys&&(this.preSharedKeys=this.preSharedKeys.slice(),0===this.preSharedKeys.length&&(this.preSharedKeys=void 0));const c=(new TextEncoder).encode("Noise_"+this.pattern.name+"_"+this.algorithms.dhName()+"_"+this.algorithms.cipherName()+"_"+this.algorithms.hashName());this.cipherState=new k(this.algorithms),this.chainingKey=this.algorithms._padOrHash(c,this.algorithms.hash(N).byteLength),this.handshakeHash=this.chainingKey,this.mixHash(null!==(o=i.prologue)&&void 0!==o?o:N),this.pattern.initiatorPreMessage.forEach((t=>this.mixHash("e"===t?this.isInitiator?this.ephemeralKeypair.public:this.remoteEphemeralPublicKey:this.isInitiator?this.staticKeypair.public:this.remoteStaticPublicKey))),this.pattern.responderPreMessage.forEach((t=>this.mixHash("e"===t?this.isInitiator?this.remoteEphemeralPublicKey:this.ephemeralKeypair.public:this.isInitiator?this.remoteStaticPublicKey:this.staticKeypair.public)))}get isInitiator(){return"initiator"===this.role}mixHash(t){this.handshakeHash=this.algorithms.hash(S(this.handshakeHash,t))}mixKey(t){const[e,s]=this.algorithms.hkdf(this.chainingKey,t,2);this.chainingKey=e,this.cipherState=new k(this.algorithms,s)}mixKeyAndHashNextPSK(){const t=this.preSharedKeys.shift(),[e,s,i]=this.algorithms.hkdf(this.chainingKey,t,3);this.chainingKey=e,this.mixHash(s),this.cipherState=new k(this.algorithms,i)}encryptAndHash(t){const e=this.cipherState.encrypt(t,this.handshakeHash);return this.mixHash(e),e}decryptAndHash(t){const e=this.cipherState.decrypt(t,this.handshakeHash);return this.mixHash(t),e}_split(){if(this.stepIndex<this.pattern.messages.length)return null;{let[t,e]=this.algorithms.hkdf(this.chainingKey,N,2).map((t=>new k(this.algorithms,t)));return this.isInitiator?{send:t,recv:e}:{send:e,recv:t}}}_nextStep(){if(this.stepIndex>=this.pattern.messages.length)throw new Error("Handshake already complete, cannot continue");return this.pattern.messages[this.stepIndex++]}_processKeyMixToken(t){switch(t){case"ee":this.mixKey(this.algorithms.dh(this.ephemeralKeypair,this.remoteEphemeralPublicKey));break;case"es":this.mixKey(this.isInitiator?this.algorithms.dh(this.ephemeralKeypair,this.remoteStaticPublicKey):this.algorithms.dh(this.staticKeypair,this.remoteEphemeralPublicKey));break;case"se":this.mixKey(this.isInitiator?this.algorithms.dh(this.staticKeypair,this.remoteEphemeralPublicKey):this.algorithms.dh(this.ephemeralKeypair,this.remoteStaticPublicKey));break;case"ss":this.mixKey(this.algorithms.dh(this.staticKeypair,this.remoteStaticPublicKey));break;case"psk":this.mixKeyAndHashNextPSK()}}writeMessage(t){const e=[];let s;if(this._nextStep().forEach((t=>{switch(t){case"e":e.push(this.ephemeralKeypair.public),this.mixHash(this.ephemeralKeypair.public),this.preSharedKeys&&this.mixKey(this.ephemeralKeypair.public);break;case"s":e.push(this.encryptAndHash(this.staticKeypair.public));break;default:this._processKeyMixToken(t)}})),e.push(this.encryptAndHash(t)),1===e.length)s=e[0];else{s=new Uint8Array(e.reduce(((t,e)=>t+e.byteLength),0));let t=0;e.forEach((e=>{s.set(e,t),t+=e.byteLength}))}return{packet:s,finished:this._split()}}readMessage(t){const e=e=>{const s=t.slice(0,e);return t=t.subarray(e),s};this._nextStep().forEach((t=>{switch(t){case"e":this.remoteEphemeralPublicKey=e(this.algorithms.dhlen),this.mixHash(this.remoteEphemeralPublicKey),this.preSharedKeys&&this.mixKey(this.remoteEphemeralPublicKey);break;case"s":this.remoteStaticPublicKey=this.decryptAndHash(e(this.algorithms.dhlen+(this.cipherState.view?16:0)));break;default:this._processKeyMixToken(t)}}));return{message:this.decryptAndHash(t),finished:this._split()}}async completeHandshake(t,e,s=(async t=>{}),i=(async()=>new Uint8Array(0))){const h=async()=>{const{packet:e,finished:s}=this.writeMessage(await i());return await t(e),s||r()},r=async()=>{const{message:t,finished:i}=this.readMessage(await e());return await s(t),i||h()};return this.isInitiator?h():r()}},NoiseProtocolAlgorithms:L,Nonce:v,bytesAppend:S,bytesXor:M});const H={};function P(t,e,s,i){const h={name:t,baseName:t,messages:e,initiatorPreMessage:s,responderPreMessage:i};H[h.name]=h}P("I1K1",[["e","s"],["e","ee","es"],["se"]],[],["s"]),P("I1K",[["e","es","s"],["e","ee"],["se"]],[],["s"]),P("I1N",[["e","s"],["e","ee"],["se"]],[],[]),P("I1X1",[["e","s"],["e","ee","s"],["se","es"]],[],[]),P("I1X",[["e","s"],["e","ee","s","es"],["se"]],[],[]),P("IK1",[["e","s"],["e","ee","se","es"]],[],["s"]),P("IK",[["e","es","s","ss"],["e","ee","se"]],[],["s"]),P("IN",[["e","s"],["e","ee","se"]],[],[]),P("IX1",[["e","s"],["e","ee","se","s"],["es"]],[],[]),P("IX",[["e","s"],["e","ee","se","s","es"]],[],[]),P("K1K1",[["e"],["e","ee","es"],["se"]],["s"],["s"]),P("K1K",[["e","es"],["e","ee"],["se"]],["s"],["s"]),P("K1N",[["e"],["e","ee"],["se"]],["s"],[]),P("K1X1",[["e"],["e","ee","s"],["se","es"]],["s"],[]),P("K1X",[["e"],["e","ee","s","es"],["se"]],["s"],[]),P("K",[["e","es","ss"]],["s"],["s"]),P("KK1",[["e"],["e","ee","se","es"]],["s"],["s"]),P("KK",[["e","es","ss"],["e","ee","se"]],["s"],["s"]),P("KN",[["e"],["e","ee","se"]],["s"],[]),P("KX1",[["e"],["e","ee","se","s"],["es"]],["s"],[]),P("KX",[["e"],["e","ee","se","s","es"]],["s"],[]),P("N",[["e","es"]],[],["s"]),P("NK1",[["e"],["e","ee","es"]],[],["s"]),P("NK",[["e","es"],["e","ee"]],[],["s"]),P("NN",[["e"],["e","ee"]],[],[]),P("NX1",[["e"],["e","ee","s"],["es"]],[],[]),P("NX",[["e"],["e","ee","s","es"]],[],[]),P("X1K1",[["e"],["e","ee","es"],["s"],["se"]],[],["s"]),P("X1K",[["e","es"],["e","ee"],["s"],["se"]],[],["s"]),P("X1N",[["e"],["e","ee"],["s"],["se"]],[],[]),P("X1X1",[["e"],["e","ee","s"],["es","s"],["se"]],[],[]),P("X1X",[["e"],["e","ee","s","es"],["s"],["se"]],[],[]),P("X",[["e","es","s","ss"]],[],["s"]),P("XK1",[["e"],["e","ee","es"],["s","se"]],[],["s"]),P("XK",[["e","es"],["e","ee"],["s","se"]],[],["s"]),P("XN",[["e"],["e","ee"],["s","se"]],[],[]),P("XX1",[["e"],["e","ee","s"],["es","s","se"]],[],[]),P("XX",[["e"],["e","ee","s","es"],["s","se"]],[],[]);const B=/^([NKX]|[NKXI]1?[NKX]1?)([a-z][a-z0-9]*(\+[a-z][a-z0-9]*)*)?$/,X=/^psk([0-9]+)$/;var C=Object.freeze({__proto__:null,PATTERNS:H,isOneWay:function(t){return 1===t.baseName.length},lookupPattern:function(t){var e,s,i;const h=B.exec(t);if(null===h)return null;const r=null!==(s=null===(e=h[2])||void 0===e?void 0:e.split("+"))&&void 0!==s?s:[];let n=null!==(i=H[h[1]])&&void 0!==i?i:null;return n?(r.forEach((t=>n=n&&function(t,e){const s=X.exec(e);if(null===s)return null;const i=parseInt(s[1],10),h=t.messages;return Object.assign(Object.assign({},t),{messages:0===i?[["psk",...h[0]],...h.slice(1)]:[...h.slice(0,i-1),[...h[i-1],"psk"],...h.slice(i)]})}(n,t))),n&&Object.assign(Object.assign({},n),{name:t})):null}});const T=(()=>{var t="undefined"!=typeof self?self.crypto||self.msCrypto:null;if(t&&t.getRandomValues){const e=65536;return(s,i)=>{for(let h=0;h<i;h+=e)t.getRandomValues(s.subarray(h,h+Math.min(i-h,e)))}}if("undefined"!=typeof require&&(t=require("crypto"))&&t.randomBytes)return(e,s)=>e.set(t.randomBytes(s));throw new Error("No usable randomness source found")})();function O(t){const e=new Uint8Array(t);return T(e,t),e}var I=Object.freeze({__proto__:null,_randomBytes:T,randomBytes:O});function Y(){return new Float64Array(16)}const z=new Uint8Array(32);z[0]=9;const j=Y();function D(t){let e=1;for(let s=0;s<16;s++){const i=t[s]+e+65535;e=Math.floor(i/65536),t[s]=i-65536*e}t[0]+=e-1+37*(e-1)}function V(t,e,s){const i=~(s-1);for(let s=0;s<16;s++){const h=i&(t[s]^e[s]);t[s]^=h,e[s]^=h}}function R(t,e,s){for(let i=0;i<16;i++)t[i]=e[i]+s[i]}function $(t,e,s){for(let i=0;i<16;i++)t[i]=e[i]-s[i]}function q(t,e,s){let i=0,h=0,r=0,n=0,a=0,o=0,c=0,l=0,u=0,f=0,y=0,p=0,d=0,m=0,g=0,b=0,K=0,w=0,A=0,_=0,E=0,U=0,v=0,M=0,S=0,N=0,L=0,k=0,x=0,H=0,P=0;const B=s[0],X=s[1],C=s[2],T=s[3],O=s[4],I=s[5],Y=s[6],z=s[7],j=s[8],D=s[9],V=s[10],R=s[11],$=s[12],q=s[13],F=s[14],G=s[15];let W=e[0];i+=W*B,h+=W*X,r+=W*C,n+=W*T,a+=W*O,o+=W*I,c+=W*Y,l+=W*z,u+=W*j,f+=W*D,y+=W*V,p+=W*R,d+=W*$,m+=W*q,g+=W*F,b+=W*G,W=e[1],h+=W*B,r+=W*X,n+=W*C,a+=W*T,o+=W*O,c+=W*I,l+=W*Y,u+=W*z,f+=W*j,y+=W*D,p+=W*V,d+=W*R,m+=W*$,g+=W*q,b+=W*F,K+=W*G,W=e[2],r+=W*B,n+=W*X,a+=W*C,o+=W*T,c+=W*O,l+=W*I,u+=W*Y,f+=W*z,y+=W*j,p+=W*D,d+=W*V,m+=W*R,g+=W*$,b+=W*q,K+=W*F,w+=W*G,W=e[3],n+=W*B,a+=W*X,o+=W*C,c+=W*T,l+=W*O,u+=W*I,f+=W*Y,y+=W*z,p+=W*j,d+=W*D,m+=W*V,g+=W*R,b+=W*$,K+=W*q,w+=W*F,A+=W*G,W=e[4],a+=W*B,o+=W*X,c+=W*C,l+=W*T,u+=W*O,f+=W*I,y+=W*Y,p+=W*z,d+=W*j,m+=W*D,g+=W*V,b+=W*R,K+=W*$,w+=W*q,A+=W*F,_+=W*G,W=e[5],o+=W*B,c+=W*X,l+=W*C,u+=W*T,f+=W*O,y+=W*I,p+=W*Y,d+=W*z,m+=W*j,g+=W*D,b+=W*V,K+=W*R,w+=W*$,A+=W*q,_+=W*F,E+=W*G,W=e[6],c+=W*B,l+=W*X,u+=W*C,f+=W*T,y+=W*O,p+=W*I,d+=W*Y,m+=W*z,g+=W*j,b+=W*D,K+=W*V,w+=W*R,A+=W*$,_+=W*q,E+=W*F,U+=W*G,W=e[7],l+=W*B,u+=W*X,f+=W*C,y+=W*T,p+=W*O,d+=W*I,m+=W*Y,g+=W*z,b+=W*j,K+=W*D,w+=W*V,A+=W*R,_+=W*$,E+=W*q,U+=W*F,v+=W*G,W=e[8],u+=W*B,f+=W*X,y+=W*C,p+=W*T,d+=W*O,m+=W*I,g+=W*Y,b+=W*z,K+=W*j,w+=W*D,A+=W*V,_+=W*R,E+=W*$,U+=W*q,v+=W*F,M+=W*G,W=e[9],f+=W*B,y+=W*X,p+=W*C,d+=W*T,m+=W*O,g+=W*I,b+=W*Y,K+=W*z,w+=W*j,A+=W*D,_+=W*V,E+=W*R,U+=W*$,v+=W*q,M+=W*F,S+=W*G,W=e[10],y+=W*B,p+=W*X,d+=W*C,m+=W*T,g+=W*O,b+=W*I,K+=W*Y,w+=W*z,A+=W*j,_+=W*D,E+=W*V,U+=W*R,v+=W*$,M+=W*q,S+=W*F,N+=W*G,W=e[11],p+=W*B,d+=W*X,m+=W*C,g+=W*T,b+=W*O,K+=W*I,w+=W*Y,A+=W*z,_+=W*j,E+=W*D,U+=W*V,v+=W*R,M+=W*$,S+=W*q,N+=W*F,L+=W*G,W=e[12],d+=W*B,m+=W*X,g+=W*C,b+=W*T,K+=W*O,w+=W*I,A+=W*Y,_+=W*z,E+=W*j,U+=W*D,v+=W*V,M+=W*R,S+=W*$,N+=W*q,L+=W*F,k+=W*G,W=e[13],m+=W*B,g+=W*X,b+=W*C,K+=W*T,w+=W*O,A+=W*I,_+=W*Y,E+=W*z,U+=W*j,v+=W*D,M+=W*V,S+=W*R,N+=W*$,L+=W*q,k+=W*F,x+=W*G,W=e[14],g+=W*B,b+=W*X,K+=W*C,w+=W*T,A+=W*O,_+=W*I,E+=W*Y,U+=W*z,v+=W*j,M+=W*D,S+=W*V,N+=W*R,L+=W*$,k+=W*q,x+=W*F,H+=W*G,W=e[15],b+=W*B,K+=W*X,w+=W*C,A+=W*T,_+=W*O,E+=W*I,U+=W*Y,v+=W*z,M+=W*j,S+=W*D,N+=W*V,L+=W*R,k+=W*$,x+=W*q,H+=W*F,P+=W*G,i+=38*K,h+=38*w,r+=38*A,n+=38*_,a+=38*E,o+=38*U,c+=38*v,l+=38*M,u+=38*S,f+=38*N,y+=38*L,p+=38*k,d+=38*x,m+=38*H,g+=38*P;let Z=1;W=i+Z+65535,Z=Math.floor(W/65536),i=W-65536*Z,W=h+Z+65535,Z=Math.floor(W/65536),h=W-65536*Z,W=r+Z+65535,Z=Math.floor(W/65536),r=W-65536*Z,W=n+Z+65535,Z=Math.floor(W/65536),n=W-65536*Z,W=a+Z+65535,Z=Math.floor(W/65536),a=W-65536*Z,W=o+Z+65535,Z=Math.floor(W/65536),o=W-65536*Z,W=c+Z+65535,Z=Math.floor(W/65536),c=W-65536*Z,W=l+Z+65535,Z=Math.floor(W/65536),l=W-65536*Z,W=u+Z+65535,Z=Math.floor(W/65536),u=W-65536*Z,W=f+Z+65535,Z=Math.floor(W/65536),f=W-65536*Z,W=y+Z+65535,Z=Math.floor(W/65536),y=W-65536*Z,W=p+Z+65535,Z=Math.floor(W/65536),p=W-65536*Z,W=d+Z+65535,Z=Math.floor(W/65536),d=W-65536*Z,W=m+Z+65535,Z=Math.floor(W/65536),m=W-65536*Z,W=g+Z+65535,Z=Math.floor(W/65536),g=W-65536*Z,W=b+Z+65535,Z=Math.floor(W/65536),b=W-65536*Z,i+=Z-1+37*(Z-1),Z=1,W=i+Z+65535,Z=Math.floor(W/65536),i=W-65536*Z,W=h+Z+65535,Z=Math.floor(W/65536),h=W-65536*Z,W=r+Z+65535,Z=Math.floor(W/65536),r=W-65536*Z,W=n+Z+65535,Z=Math.floor(W/65536),n=W-65536*Z,W=a+Z+65535,Z=Math.floor(W/65536),a=W-65536*Z,W=o+Z+65535,Z=Math.floor(W/65536),o=W-65536*Z,W=c+Z+65535,Z=Math.floor(W/65536),c=W-65536*Z,W=l+Z+65535,Z=Math.floor(W/65536),l=W-65536*Z,W=u+Z+65535,Z=Math.floor(W/65536),u=W-65536*Z,W=f+Z+65535,Z=Math.floor(W/65536),f=W-65536*Z,W=y+Z+65535,Z=Math.floor(W/65536),y=W-65536*Z,W=p+Z+65535,Z=Math.floor(W/65536),p=W-65536*Z,W=d+Z+65535,Z=Math.floor(W/65536),d=W-65536*Z,W=m+Z+65535,Z=Math.floor(W/65536),m=W-65536*Z,W=g+Z+65535,Z=Math.floor(W/65536),g=W-65536*Z,W=b+Z+65535,Z=Math.floor(W/65536),b=W-65536*Z,i+=Z-1+37*(Z-1),t[0]=i,t[1]=h,t[2]=r,t[3]=n,t[4]=a,t[5]=o,t[6]=c,t[7]=l,t[8]=u,t[9]=f,t[10]=y,t[11]=p,t[12]=d,t[13]=m,t[14]=g,t[15]=b}function F(t,e){q(t,e,e)}function G(t,e,s){const i=new Uint8Array(32),h=new Float64Array(80),r=Y(),n=Y(),a=Y(),o=Y(),c=Y(),l=Y();for(let t=0;t<31;t++)i[t]=e[t];i[31]=127&e[31]|64,i[0]&=248,function(t,e){for(let s=0;s<16;s++)t[s]=e[2*s]+(e[2*s+1]<<8);t[15]&=32767}(h,s);for(let t=0;t<16;t++)n[t]=h[t],o[t]=r[t]=a[t]=0;r[0]=o[0]=1;for(let t=254;t>=0;--t){const e=i[t>>>3]>>>(7&t)&1;V(r,n,e),V(a,o,e),R(c,r,a),$(r,r,a),R(a,n,o),$(n,n,o),F(o,c),F(l,r),q(r,a,r),q(a,n,c),R(c,r,a),$(r,r,a),F(n,r),$(a,o,l),q(r,a,j),R(r,r,o),q(a,a,r),q(r,o,l),q(o,n,h),F(n,c),V(r,n,e),V(a,o,e)}for(let t=0;t<16;t++)h[t+16]=r[t],h[t+32]=a[t],h[t+48]=n[t],h[t+64]=o[t];const u=h.subarray(32),f=h.subarray(16);!function(t,e){const s=Y();for(let t=0;t<16;t++)s[t]=e[t];for(let t=253;t>=0;t--)F(s,s),2!==t&&4!==t&&q(s,s,e);for(let e=0;e<16;e++)t[e]=s[e]}(u,u),q(f,f,u),function(t,e){const s=Y(),i=Y();for(let t=0;t<16;t++)i[t]=e[t];D(i),D(i),D(i);for(let t=0;t<2;t++){s[0]=i[0]-65517;for(let t=1;t<15;t++)s[t]=i[t]-65535-(s[t-1]>>16&1),s[t-1]&=65535;s[15]=i[15]-32767-(s[14]>>16&1);const t=s[15]>>16&1;s[14]&=65535,V(i,s,1-t)}for(let e=0;e<16;e++)t[2*e]=255&i[e],t[2*e+1]=i[e]>>8}(t,f)}function W(t,e){G(t,e,z)}function Z(t,e){if(32!==t.length)throw new Error("bad n size");if(32!==e.length)throw new Error("bad p size");const s=new Uint8Array(32);return G(s,t,e),s}function J(t){if(32!==t.length)throw new Error("bad n size");const e=new Uint8Array(32);return W(e,t),e}j[0]=56129,j[1]=1,Z.scalarLength=32,Z.groupElementLength=32;var Q=Object.freeze({__proto__:null,crypto_scalarmult:G,crypto_scalarmult_BYTES:32,crypto_scalarmult_SCALARBYTES:32,crypto_scalarmult_base:W,scalarMult:Z,scalarMultBase:J});function tt(t){const e=new DataView(new ArrayBuffer(12));return e.setUint32(4,t.lo,!0),e.setUint32(8,t.hi,!0),e}var et=Object.freeze({__proto__:null,Noise_25519_ChaChaPoly_BLAKE2s:class extends L{constructor(){super()}dhName(){return"25519"}generateKeypair(){const t=O(Z.scalarLength);return{public:J(t),secret:t}}dh(t,e){return Z(t.secret,e)}cipherName(){return"ChaChaPoly"}encrypt(t,e,s,i){return y(s,t,tt(e),i)}decrypt(t,e,s,i){return m(s,t,tt(e),i)}hashName(){return"BLAKE2s"}hash(t){return E.digest(t)}hashBlocklen(){return E.BLOCKLEN}}});t.AEAD=g,t.BLAKE2=U,t.ChaCha20=n,t.Noise=x,t.NoiseProfiles=et,t.Patterns=C,t.Poly1305=o,t.Random=I,t.X25519=Q}));
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "salty-crypto",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "Noise Protocol Framework, plus X25519/ChaCha20Poly1305/BLAKE2s code, for browser and node.js",
5
5
  "author": "Tony Garnock-Jones <tonyg@leastfixedpoint.com>",
6
6
  "homepage": "https://github.com/tonyg/typescript-salty-crypto",
7
7
  "license": "MIT",
8
8
  "main": "dist/salty-crypto.js",
9
- "module": "lib/src/index.js",
10
- "types": "lib/src/index.d.ts",
9
+ "module": "lib/index.js",
10
+ "types": "lib/index.d.ts",
11
11
  "publishConfig": {
12
12
  "access": "public"
13
13
  },
@@ -16,14 +16,16 @@
16
16
  "url": "https://github.com/tonyg/typescript-salty-crypto"
17
17
  },
18
18
  "scripts": {
19
- "prepare": "yarn compile && yarn rollup",
19
+ "prepare": "yarn clean && yarn compile && yarn rollup",
20
20
  "compile": "yarn tsc",
21
21
  "compile:watch": "yarn compile -w",
22
22
  "rollup": "rollup -c",
23
23
  "rollup:watch": "yarn rollup -w",
24
- "test": "node -r esm lib/test/harness.js",
25
- "test:watch": "inotifytest yarn test",
26
- "clean": "rm -rf lib/",
24
+ "test-compile": "yarn tsc -p test/tsconfig.json",
25
+ "test-compile:watch": "yarn test-compile -w",
26
+ "test": "node -r esm lib-test/harness.js",
27
+ "test:watch": "mkdir -p lib-test && cd lib-test && inotifytest yarn test",
28
+ "clean": "rm -rf lib/ lib-test/ dist/",
27
29
  "fixcopyright": "fixcopyright.rkt --preset-typescript --file-pattern 'src/**.ts' MIT && fixcopyright.rkt --preset-typescript --file-pattern 'test/**.ts' MIT"
28
30
  },
29
31
  "devDependencies": {
@@ -33,6 +35,7 @@
33
35
  "expect": "^29.4.0",
34
36
  "glob": "^8.1.0",
35
37
  "rollup": "^3.10.1",
38
+ "rollup-plugin-dts": "^5.1.1",
36
39
  "typescript": "4.9"
37
40
  },
38
41
  "dependencies": {}
package/rollup.config.js CHANGED
@@ -1,9 +1,19 @@
1
- module.exports = {
2
- input: 'lib/src/index.js',
3
- plugins: [require('@rollup/plugin-terser')()],
4
- output: {
5
- file: 'dist/salty-crypto.js',
6
- format: 'umd',
7
- name: 'SaltyCrypto',
1
+ module.exports = [
2
+ {
3
+ input: 'lib/index.js',
4
+ plugins: [require('@rollup/plugin-terser')()],
5
+ output: {
6
+ file: 'dist/salty-crypto.js',
7
+ format: 'umd',
8
+ name: 'SaltyCrypto',
9
+ },
8
10
  },
9
- };
11
+ {
12
+ input: 'lib/index.d.ts',
13
+ plugins: [require('rollup-plugin-dts').default()],
14
+ output: {
15
+ file: 'dist/salty-crypto.d.ts',
16
+ format: 'es',
17
+ },
18
+ },
19
+ ];
package/src/aead.ts CHANGED
@@ -47,18 +47,36 @@ function aead_tag(tag: Uint8Array,
47
47
  p.finish(tag, 0);
48
48
  }
49
49
 
50
- export function aead_encrypt_detached(plaintext: Uint8Array,
51
- ciphertext: Uint8Array,
52
- messagelength: number,
53
- tag: Uint8Array,
54
- key: DataView,
55
- nonce: DataView,
56
- associated_data?: Uint8Array)
57
- {
50
+ export function aead_encrypt_detached(
51
+ plaintext: Uint8Array,
52
+ ciphertext: Uint8Array,
53
+ messagelength: number,
54
+ tag: Uint8Array,
55
+ key: DataView,
56
+ nonce: DataView,
57
+ associated_data?: Uint8Array,
58
+ ): void {
58
59
  chacha20(key, nonce, plaintext, ciphertext, 1, messagelength);
59
60
  aead_tag(tag, key, nonce, ciphertext, messagelength, associated_data);
60
61
  }
61
62
 
63
+ export function aead_encrypt(
64
+ plaintext: Uint8Array,
65
+ key: DataView,
66
+ nonce: DataView,
67
+ associated_data?: Uint8Array,
68
+ ): Uint8Array {
69
+ const ciphertextAndTag = new Uint8Array(plaintext.byteLength + AEAD_CHACHA20_POLY1305_TAGBYTES);
70
+ aead_encrypt_detached(plaintext,
71
+ ciphertextAndTag,
72
+ plaintext.byteLength,
73
+ ciphertextAndTag.subarray(plaintext.byteLength),
74
+ key,
75
+ nonce,
76
+ associated_data);
77
+ return ciphertextAndTag;
78
+ }
79
+
62
80
  // `verify` from nacl-fast.js
63
81
  function verify(x: Uint8Array, y: Uint8Array, n: number): number {
64
82
  let d = 0;
@@ -77,10 +95,27 @@ export function aead_decrypt_detached(plaintext: Uint8Array,
77
95
  const actual_tag = new Uint8Array(AEAD_CHACHA20_POLY1305_TAGBYTES);
78
96
  aead_tag(actual_tag, key, nonce, ciphertext, messagelength, associated_data);
79
97
  const ok = verify(actual_tag, expected_tag, actual_tag.byteLength) === 0;
80
- if (ok) {
81
- chacha20(key, nonce, ciphertext, plaintext, 1, messagelength);
82
- } else {
83
- plaintext.fill(0, 0, messagelength);
84
- }
98
+ if (ok) chacha20(key, nonce, ciphertext, plaintext, 1, messagelength);
85
99
  return ok;
86
100
  }
101
+
102
+ export class AuthenticationFailure extends Error {}
103
+
104
+ export function aead_decrypt(
105
+ ciphertextAndTag: Uint8Array,
106
+ key: DataView,
107
+ nonce: DataView,
108
+ associated_data?: Uint8Array,
109
+ ): Uint8Array {
110
+ const plaintext = new Uint8Array(ciphertextAndTag.byteLength - AEAD_CHACHA20_POLY1305_TAGBYTES);
111
+ if (!aead_decrypt_detached(plaintext,
112
+ ciphertextAndTag,
113
+ plaintext.byteLength,
114
+ ciphertextAndTag.subarray(plaintext.byteLength),
115
+ key,
116
+ nonce,
117
+ associated_data)) {
118
+ throw new AuthenticationFailure("ChaCha20Poly1305 AEAD authentication failed");
119
+ }
120
+ return plaintext;
121
+ }
package/src/patterns.ts CHANGED
@@ -15,21 +15,44 @@ function _p(
15
15
  PATTERNS[pat.name] = pat;
16
16
  }
17
17
 
18
- _p("N", [["e", "es"]], [], ["s"]);
19
- _p("K", [["e", "es", "ss"]], ["s"], ["s"]);
20
- _p("X", [["e", "es", "s", "ss"]], [], ["s"]);
21
- _p("NN", [["e"], ["e", "ee"]], [], []);
22
- _p("NK", [["e", "es"], ["e", "ee"]], [], ["s"]);
23
- _p("NX", [["e"], ["e", "ee", "s", "es"]], [], []);
24
- _p("KN", [["e"], ["e", "ee", "se"]], ["s"], []);
25
- _p("KK", [["e", "es", "ss"], ["e", "ee", "se"]], ["s"], ["s"]);
26
- _p("KX", [["e"], ["e", "ee", "se", "s", "es"]], ["s"], []);
27
- _p("XN", [["e"], ["e", "ee"], ["s", "se"]], [], []);
28
- _p("XK", [["e", "es"], ["e", "ee"], ["s", "se"]], [], ["s"]);
29
- _p("XX", [["e"], ["e", "ee", "s", "es"], ["s", "se"]], [], []);
30
- _p("IN", [["e", "s"], ["e", "ee", "se"]], [], []);
31
- _p("IK", [["e", "es", "s", "ss"], ["e", "ee", "se"]], [], ["s"]);
32
- _p("IX", [["e", "s"], ["e", "ee", "se", "s", "es"]], [], []);
18
+ _p("I1K1", [["e","s"],["e","ee","es"],["se"]], [], ["s"]);
19
+ _p("I1K", [["e","es","s"],["e","ee"],["se"]], [], ["s"]);
20
+ _p("I1N", [["e","s"],["e","ee"],["se"]], [], []);
21
+ _p("I1X1", [["e","s"],["e","ee","s"],["se","es"]], [], []);
22
+ _p("I1X", [["e","s"],["e","ee","s","es"],["se"]], [], []);
23
+ _p("IK1", [["e","s"],["e","ee","se","es"]], [], ["s"]);
24
+ _p("IK", [["e","es","s","ss"],["e","ee","se"]], [], ["s"]);
25
+ _p("IN", [["e","s"],["e","ee","se"]], [], []);
26
+ _p("IX1", [["e","s"],["e","ee","se","s"],["es"]], [], []);
27
+ _p("IX", [["e","s"],["e","ee","se","s","es"]], [], []);
28
+ _p("K1K1", [["e"],["e","ee","es"],["se"]], ["s"], ["s"]);
29
+ _p("K1K", [["e","es"],["e","ee"],["se"]], ["s"], ["s"]);
30
+ _p("K1N", [["e"],["e","ee"],["se"]], ["s"], []);
31
+ _p("K1X1", [["e"],["e","ee","s"],["se","es"]], ["s"], []);
32
+ _p("K1X", [["e"],["e","ee","s","es"],["se"]], ["s"], []);
33
+ _p("K", [["e","es","ss"]], ["s"], ["s"]);
34
+ _p("KK1", [["e"],["e","ee","se","es"]], ["s"], ["s"]);
35
+ _p("KK", [["e","es","ss"],["e","ee","se"]], ["s"], ["s"]);
36
+ _p("KN", [["e"],["e","ee","se"]], ["s"], []);
37
+ _p("KX1", [["e"],["e","ee","se","s"],["es"]], ["s"], []);
38
+ _p("KX", [["e"],["e","ee","se","s","es"]], ["s"], []);
39
+ _p("N", [["e","es"]], [], ["s"]);
40
+ _p("NK1", [["e"],["e","ee","es"]], [], ["s"]);
41
+ _p("NK", [["e","es"],["e","ee"]], [], ["s"]);
42
+ _p("NN", [["e"],["e","ee"]], [], []);
43
+ _p("NX1", [["e"],["e","ee","s"],["es"]], [], []);
44
+ _p("NX", [["e"],["e","ee","s","es"]], [], []);
45
+ _p("X1K1", [["e"],["e","ee","es"],["s"],["se"]], [], ["s"]);
46
+ _p("X1K", [["e","es"],["e","ee"],["s"],["se"]], [], ["s"]);
47
+ _p("X1N", [["e"],["e","ee"],["s"],["se"]], [], []);
48
+ _p("X1X1", [["e"],["e","ee","s"],["es","s"],["se"]], [], []);
49
+ _p("X1X", [["e"],["e","ee","s","es"],["s"],["se"]], [], []);
50
+ _p("X", [["e","es","s","ss"]], [], ["s"]);
51
+ _p("XK1", [["e"],["e","ee","es"],["s","se"]], [], ["s"]);
52
+ _p("XK", [["e","es"],["e","ee"],["s","se"]], [], ["s"]);
53
+ _p("XN", [["e"],["e","ee"],["s","se"]], [], []);
54
+ _p("XX1", [["e"],["e","ee","s"],["es","s","se"]], [], []);
55
+ _p("XX", [["e"],["e","ee","s","es"],["s","se"]], [], []);
33
56
 
34
57
  export function isOneWay(pat: HandshakePattern): boolean {
35
58
  return pat.baseName.length === 1;
package/src/profiles.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  /// SPDX-FileCopyrightText: Copyright © 2023 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
3
3
 
4
4
  import { BLAKE2s } from './blake2';
5
- import { AEAD_CHACHA20_POLY1305_NONCEBYTES, AEAD_CHACHA20_POLY1305_TAGBYTES, aead_decrypt_detached, aead_encrypt_detached } from './aead';
5
+ import { AEAD_CHACHA20_POLY1305_NONCEBYTES, AEAD_CHACHA20_POLY1305_TAGBYTES, aead_decrypt, aead_encrypt } from './aead';
6
6
  import { DHKeyPair, NoiseProtocolAlgorithms, Nonce } from './noise';
7
7
  import { randomBytes } from './random';
8
8
  import { scalarMult, scalarMultBase } from './x25519';
@@ -31,17 +31,11 @@ export class Noise_25519_ChaChaPoly_BLAKE2s extends NoiseProtocolAlgorithms {
31
31
  }
32
32
 
33
33
  encrypt(key: DataView, nonce: Nonce, p: Uint8Array, associated_data?: Uint8Array): Uint8Array {
34
- const c = new Uint8Array(p.byteLength + AEAD_CHACHA20_POLY1305_TAGBYTES);
35
- aead_encrypt_detached(p, c, p.byteLength, c.subarray(p.byteLength), key, serializeNonce(nonce), associated_data);
36
- return c;
34
+ return aead_encrypt(p, key, serializeNonce(nonce), associated_data);
37
35
  }
38
36
 
39
37
  decrypt(key: DataView, nonce: Nonce, c: Uint8Array, associated_data?: Uint8Array): Uint8Array {
40
- const p = new Uint8Array(c.byteLength - AEAD_CHACHA20_POLY1305_TAGBYTES);
41
- if (!aead_decrypt_detached(p, c, p.byteLength, c.subarray(p.byteLength), key, serializeNonce(nonce), associated_data)) {
42
- throw new Error("packet decryption failed");
43
- }
44
- return p;
38
+ return aead_decrypt(c, key, serializeNonce(nonce), associated_data);
45
39
  }
46
40
 
47
41
  hashName(): string {
package/test/harness.ts CHANGED
@@ -26,14 +26,14 @@ function indent(msg: string) {
26
26
  console.log(str + msg);
27
27
  }
28
28
 
29
- export async function describe(what: string, f: () => (Promise<void> | void)) {
29
+ export async function describe(what: string, f: () => (Promise<void> | void)): Promise<void> {
30
30
  indent('- ' + what);
31
31
  testDepth++;
32
32
  await f();
33
33
  testDepth--;
34
34
  }
35
35
 
36
- export async function it(what: string, f: () => (Promise<void> | void)) {
36
+ export async function it(what: string, f: () => (Promise<void> | void)): Promise<void> {
37
37
  try {
38
38
  testStats.total++;
39
39
  await f();
@@ -62,12 +62,13 @@ export async function runTests(patterns: string[]): Promise<void> {
62
62
  }
63
63
  }
64
64
 
65
- if (Object.is(require.main, module)) {
66
- console.time('tests');
67
- let patterns = process.argv.slice(2);
68
- if (patterns.length === 0) patterns = ['./lib/**/*.test.js'];
69
- runTests(patterns).then(() => {
65
+ (async () => {
66
+ if (Object.is(require.main, module)) {
67
+ console.time('tests');
68
+ let patterns = process.argv.slice(2);
69
+ if (patterns.length === 0) patterns = ['./lib-test/**/*.test.js'];
70
+ await runTests(patterns);
70
71
  console.timeEnd('tests');
71
72
  console.log(testStats);
72
- });
73
- }
73
+ }
74
+ })();
@@ -1,4 +1,5 @@
1
- import { AEAD_CHACHA20_POLY1305_TAGBYTES, aead_encrypt_detached, aead_decrypt_detached } from '../../src/aead';
1
+ import { AEAD } from '../../dist/salty-crypto.js';
2
+ const { AEAD_CHACHA20_POLY1305_TAGBYTES, aead_encrypt_detached, aead_decrypt_detached } = AEAD;
2
3
  import { it, expect } from '../harness';
3
4
 
4
5
  it('section 2.8.2 from rfc 8439', () => {
@@ -22,9 +23,7 @@ it('section 2.8.2 from rfc 8439', () => {
22
23
  0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
23
24
  ]).buffer);
24
25
 
25
- const tag = new Uint8Array(AEAD_CHACHA20_POLY1305_TAGBYTES);
26
- aead_encrypt_detached(sunscreen, sunscreen, sunscreen.byteLength, tag, key, nonce, associated_data);
27
- expect(sunscreen).toEqual(new Uint8Array([
26
+ const expectedEncrypted = new Uint8Array([
28
27
  0xd3, 0x1a, 0x8d, 0x34, 0x64, 0x8e, 0x60, 0xdb, 0x7b, 0x86, 0xaf, 0xbc, 0x53, 0xef, 0x7e, 0xc2,
29
28
  0xa4, 0xad, 0xed, 0x51, 0x29, 0x6e, 0x08, 0xfe, 0xa9, 0xe2, 0xb5, 0xa7, 0x36, 0xee, 0x62, 0xd6,
30
29
  0x3d, 0xbe, 0xa4, 0x5e, 0x8c, 0xa9, 0x67, 0x12, 0x82, 0xfa, 0xfb, 0x69, 0xda, 0x92, 0x72, 0x8b,
@@ -33,7 +32,11 @@ it('section 2.8.2 from rfc 8439', () => {
33
32
  0xfa, 0xb3, 0x24, 0xe4, 0xfa, 0xd6, 0x75, 0x94, 0x55, 0x85, 0x80, 0x8b, 0x48, 0x31, 0xd7, 0xbc,
34
33
  0x3f, 0xf4, 0xde, 0xf0, 0x8e, 0x4b, 0x7a, 0x9d, 0xe5, 0x76, 0xd2, 0x65, 0x86, 0xce, 0xc6, 0x4b,
35
34
  0x61, 0x16,
36
- ]));
35
+ ]);
36
+
37
+ const tag = new Uint8Array(AEAD_CHACHA20_POLY1305_TAGBYTES);
38
+ aead_encrypt_detached(sunscreen, sunscreen, sunscreen.byteLength, tag, key, nonce, associated_data);
39
+ expect(sunscreen).toEqual(expectedEncrypted);
37
40
  expect(tag).toEqual(new Uint8Array([
38
41
  0x1a, 0xe1, 0x0b, 0x59, 0x4f, 0x09, 0xe2, 0x6a,
39
42
  0x7e, 0x90, 0x2e, 0xcb, 0xd0, 0x60, 0x06, 0x91,
@@ -45,5 +48,5 @@ it('section 2.8.2 from rfc 8439', () => {
45
48
 
46
49
  tag[0]++;
47
50
  expect(aead_decrypt_detached(sunscreen, sunscreen, sunscreen.byteLength, tag, key, nonce, associated_data)).toBe(false);
48
- expect(sunscreen).toEqual(new Uint8Array(sunscreen_str.length));
51
+ expect(sunscreen).toEqual(expectedEncrypted);
49
52
  });
@@ -1,4 +1,5 @@
1
- import { BLAKE2s } from '../../src/blake2';
1
+ import { BLAKE2 } from '../../dist/salty-crypto.js';
2
+ const { BLAKE2s } = BLAKE2;
2
3
  import { it, expect } from '../harness';
3
4
 
4
5
  it('Appendix B of RFC 7693', () => {
@@ -1,4 +1,4 @@
1
- import * as ChaCha from '../../src/chacha20';
1
+ import { ChaCha20 as ChaCha } from '../../dist/salty-crypto.js';
2
2
  import { it, expect } from '../harness';
3
3
 
4
4
  it('chacha20_quarter_round 1', () => {
@@ -1,7 +1,16 @@
1
- import { DHKeyPair, NoiseHandshake, NoiseProtocolAlgorithms, TransportState } from '../../src/noise';
2
- import { isOneWay, lookupPattern } from '../../src/patterns';
3
- import { Noise_25519_ChaChaPoly_BLAKE2s } from '../../src/profiles';
4
- import { scalarMultBase } from '../../src/x25519';
1
+ import { Noise, Patterns, NoiseProfiles, X25519 } from '../../dist/salty-crypto.js';
2
+
3
+ type DHKeyPair = Noise.DHKeyPair;
4
+ type TransportState = Noise.TransportState;
5
+ type NoiseProtocolAlgorithms = Noise.NoiseProtocolAlgorithms;
6
+ const { NoiseHandshake } = Noise;
7
+
8
+ const { isOneWay, lookupPattern } = Patterns;
9
+
10
+ const { Noise_25519_ChaChaPoly_BLAKE2s } = NoiseProfiles;
11
+
12
+ const { scalarMultBase } = X25519;
13
+
5
14
  import { describe, it, expect } from '../harness';
6
15
 
7
16
  import fs from 'fs';
@@ -1,4 +1,6 @@
1
- import { Poly1305 } from '../../src/poly1305';
1
+ import { Poly1305 as P } from '../../dist/salty-crypto.js';
2
+ const { Poly1305 } = P;
3
+
2
4
  import { it, expect } from '../harness';
3
5
 
4
6
  it('section 2.5.2 from rfc 8439', () => {
@@ -0,0 +1,18 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2017",
4
+ "lib": ["ES2017", "DOM"],
5
+ "declaration": true,
6
+ "baseUrl": ".",
7
+ "rootDir": ".",
8
+ "outDir": "../lib-test",
9
+ "declarationDir": "../lib-test",
10
+ "esModuleInterop": true,
11
+ "moduleResolution": "node",
12
+ "module": "esnext",
13
+ "sourceMap": true,
14
+ "strict": true,
15
+ "allowJs": true
16
+ },
17
+ "include": ["**/*"]
18
+ }
package/tsconfig.json CHANGED
@@ -3,10 +3,10 @@
3
3
  "target": "es2017",
4
4
  "lib": ["ES2017", "DOM"],
5
5
  "declaration": true,
6
- "baseUrl": ".",
7
- "rootDirs": ["src", "test"],
8
- "outDir": "lib",
9
- "declarationDir": "lib",
6
+ "baseUrl": "./src",
7
+ "rootDir": "./src",
8
+ "outDir": "./lib",
9
+ "declarationDir": "./lib",
10
10
  "esModuleInterop": true,
11
11
  "moduleResolution": "node",
12
12
  "module": "esnext",
@@ -14,5 +14,5 @@
14
14
  "strict": true,
15
15
  "allowJs": true
16
16
  },
17
- "include": ["src/**/*", "test/**/*"]
17
+ "include": ["src/**/*"]
18
18
  }
package/watchall ADDED
@@ -0,0 +1,22 @@
1
+ #!/bin/sh
2
+
3
+ cd $(dirname $0)
4
+
5
+ first=y
6
+
7
+ open() {
8
+ if [ "$first" = "y" ]
9
+ then
10
+ tmux new-window "$1"
11
+ first=n
12
+ else
13
+ tmux split-window "$1" \; select-layout tiled
14
+ fi
15
+ }
16
+
17
+ open "yarn compile:watch"
18
+ open "yarn rollup:watch"
19
+ open "yarn test-compile:watch"
20
+ open "yarn test:watch"
21
+
22
+ tmux select-layout even-vertical