salty-crypto 0.0.4 → 0.1.0

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
@@ -16,7 +16,6 @@ Includes (and passes) test vectors from [noise-c](https://github.com/rweather/no
16
16
  - support AESGCM, SHA256, SHA512, perhaps via `Crypto.subtle`?
17
17
  - support BLAKE2b, by implementing from the RFC just like BLAKE2s
18
18
  - `fallback` pattern modifier
19
- - deferred patterns
20
19
 
21
20
  ## Code overview
22
21
 
package/browser-demo.html CHANGED
@@ -1,7 +1,7 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
3
  <head>
4
- <script src="https://tonyg.github.io/typescript-salty-crypto/dist/salty-crypto.js"></script>
4
+ <script src="dist/salty-crypto.js"></script>
5
5
  <style>html { font-family: sans; } body { max-width: 40em; margin: 0 auto; }</style>
6
6
  </head>
7
7
  <body>
@@ -26,7 +26,7 @@
26
26
  });
27
27
  return s;
28
28
  }
29
- document.getElementById('computed-answer').innerText = toHex(SaltyCrypto.BLAKE2.BLAKE2s.digest(new Uint8Array()));
29
+ document.getElementById('computed-answer').innerText = toHex(SaltyCrypto.BLAKE2s.digest(new Uint8Array()));
30
30
  </script>
31
31
  <p>
32
32
  You can play with the module via the <code>SaltyCrypto</code> global variable in the
@@ -1,136 +1,256 @@
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 {
1
+ declare class Nonce {
2
+ lo: number;
3
+ hi: number;
4
+ extra: number;
5
+ constructor(lo?: number, hi?: number, extra?: number);
6
+ increment(): void;
7
+ reset(lo?: number, hi?: number, extra?: number): void;
8
+ static get MAX(): Nonce;
8
9
  }
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 {
10
+
11
+ declare const ChaCha20Poly1305_RFC8439: AEAD;
12
+
13
+ declare const chacha20poly1305_ChaCha20Poly1305_RFC8439: typeof ChaCha20Poly1305_RFC8439;
14
+ declare namespace chacha20poly1305 {
21
15
  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,
16
+ chacha20poly1305_ChaCha20Poly1305_RFC8439 as ChaCha20Poly1305_RFC8439,
30
17
  };
31
18
  }
32
19
 
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;
20
+ declare class AuthenticationFailure extends Error {
48
21
  }
22
+ interface AEAD {
23
+ readonly NAME: string;
24
+ readonly KEYBYTES: number;
25
+ readonly NONCEBYTES: number;
26
+ readonly TAGBYTES: number;
27
+ encrypt_detached(plaintext: Uint8Array, ciphertext: Uint8Array, messagelength: number, tag: Uint8Array, key: DataView, nonce: Nonce, associated_data?: Uint8Array): void;
28
+ encrypt(plaintext: Uint8Array, key: DataView, nonce: Nonce, associated_data?: Uint8Array): Uint8Array;
29
+ decrypt_detached(plaintext: Uint8Array, ciphertext: Uint8Array, messagelength: number, expected_tag: Uint8Array, key: DataView, nonce: Nonce, associated_data?: Uint8Array): boolean;
30
+ decrypt(ciphertextAndTag: Uint8Array, key: DataView, nonce: Nonce, associated_data?: Uint8Array): Uint8Array;
31
+ }
32
+ declare function _encrypt(this: AEAD, plaintext: Uint8Array, key: DataView, nonce: Nonce, associated_data?: Uint8Array): Uint8Array;
33
+ declare function _decrypt(this: AEAD, ciphertextAndTag: Uint8Array, key: DataView, nonce: Nonce, associated_data?: Uint8Array): Uint8Array;
34
+
35
+ declare function equal(x: Uint8Array, y: Uint8Array, n: number): boolean;
36
+ declare function xor(a: Uint8Array, b: Uint8Array): Uint8Array;
37
+ declare function append(a: Uint8Array, b: Uint8Array): Uint8Array;
38
+ declare const EMPTY: Uint8Array;
49
39
 
50
- type blake2_d_BLAKE2s = BLAKE2s;
51
- declare const blake2_d_BLAKE2s: typeof BLAKE2s;
52
- declare namespace blake2_d {
40
+ declare const bytes_d_EMPTY: typeof EMPTY;
41
+ declare const bytes_d_append: typeof append;
42
+ declare const bytes_d_equal: typeof equal;
43
+ declare const bytes_d_xor: typeof xor;
44
+ declare namespace bytes_d {
53
45
  export {
54
- blake2_d_BLAKE2s as BLAKE2s,
46
+ bytes_d_EMPTY as EMPTY,
47
+ bytes_d_append as append,
48
+ bytes_d_equal as equal,
49
+ bytes_d_xor as xor,
55
50
  };
56
51
  }
57
52
 
58
- declare const CHACHA20_KEYBYTES = 32;
59
- declare const CHACHA20_NONCEBYTES = 12;
60
- declare const CHACHA20_BLOCKBYTES = 64;
61
53
  declare function chacha20_quarter_round(s: Uint32Array, a: number, b: number, c: number, d: number): void;
62
54
  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 {
55
+ declare const ChaCha20: StreamCipher;
56
+
57
+ declare const chacha20_ChaCha20: typeof ChaCha20;
58
+ declare const chacha20_chacha20_block: typeof chacha20_block;
59
+ declare const chacha20_chacha20_quarter_round: typeof chacha20_quarter_round;
60
+ declare namespace chacha20 {
72
61
  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,
62
+ chacha20_ChaCha20 as ChaCha20,
63
+ chacha20_chacha20_block as chacha20_block,
64
+ chacha20_chacha20_quarter_round as chacha20_quarter_round,
79
65
  };
80
66
  }
81
67
 
68
+ interface StreamCipher {
69
+ readonly NAME: string;
70
+ readonly KEYBYTES: number;
71
+ readonly NONCEBYTES: number;
72
+ readonly BLOCKBYTES: number;
73
+ stream_xor(key: DataView, nonce: Nonce, input: Uint8Array, output: Uint8Array, initial_counter?: number, messagelength?: number): void;
74
+ }
75
+
82
76
  type DHKeyPair = {
83
77
  public: Uint8Array;
84
78
  secret: Uint8Array;
85
79
  };
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;
80
+ interface DH {
81
+ readonly NAME: string;
82
+ readonly DHLEN: number;
83
+ generateKeypair(): DHKeyPair;
84
+ dh(kp: DHKeyPair, pk: Uint8Array): Uint8Array;
93
85
  }
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;
86
+ declare const X25519: DH;
87
+
88
+ declare const BLAKE2s: {
89
+ new (key?: Uint8Array, outlen?: number): {
90
+ b: Uint8Array;
91
+ bv: DataView;
92
+ h: Uint32Array;
93
+ t: Uint32Array;
94
+ c: number;
95
+ outlen: number;
96
+ update(input: Uint8Array, offset?: number, length?: number): void;
97
+ final(output?: Uint8Array): Uint8Array;
98
+ compress(last: boolean): void;
99
+ };
100
+ readonly NAME: "BLAKE2s";
101
+ readonly KEYBYTES: 32;
102
+ readonly OUTBYTES: 32;
103
+ readonly BLOCKLEN: 64;
104
+ digest(input: Uint8Array, key?: Uint8Array, outlen?: number): Uint8Array;
105
+ };
106
+
107
+ declare const blake2s_BLAKE2s: typeof BLAKE2s;
108
+ declare namespace blake2s {
109
+ export {
110
+ blake2s_BLAKE2s as BLAKE2s,
111
+ };
115
112
  }
116
- interface HandshakePattern {
117
- name: string;
118
- baseName: string;
119
- messages: Token[][];
120
- initiatorPreMessage: PreMessage;
121
- responderPreMessage: PreMessage;
113
+
114
+ declare const Poly1305: {
115
+ new (key?: Uint8Array, outlen?: number): {
116
+ buffer: Uint8Array;
117
+ r: Uint16Array;
118
+ h: Uint16Array;
119
+ pad: Uint16Array;
120
+ leftover: number;
121
+ fin: number;
122
+ blocks(m: Uint8Array, mpos: number, bytes: number): void;
123
+ final(mac?: Uint8Array): Uint8Array;
124
+ update(m: Uint8Array, mpos?: number, bytes?: number): void;
125
+ };
126
+ readonly NAME: "Poly1305";
127
+ readonly KEYBYTES: 32;
128
+ readonly OUTBYTES: 16;
129
+ readonly BLOCKLEN: 16;
130
+ digest(input: Uint8Array, key?: Uint8Array, outlen?: number): Uint8Array;
131
+ };
132
+
133
+ declare const poly1305_Poly1305: typeof Poly1305;
134
+ declare namespace poly1305 {
135
+ export {
136
+ poly1305_Poly1305 as Poly1305,
137
+ };
138
+ }
139
+
140
+ interface Hash {
141
+ readonly NAME: string;
142
+ readonly KEYBYTES: number;
143
+ readonly OUTBYTES: number;
144
+ readonly BLOCKLEN: number;
145
+ digest(input: Uint8Array, key?: Uint8Array, outlen?: number): Uint8Array;
146
+ new (key?: Uint8Array, outlen?: number): HashAlgorithm;
147
+ }
148
+ interface HashAlgorithm {
149
+ update(input: Uint8Array, offset?: number, length?: number): void;
150
+ final(output?: Uint8Array): Uint8Array;
151
+ }
152
+
153
+ type HMAC = {
154
+ (key: Uint8Array, data: Uint8Array): Uint8Array;
155
+ readonly NAME: string;
156
+ };
157
+ declare function makeHMAC(hash: Hash): HMAC;
158
+
159
+ type HKDF = {
160
+ (chainingKey: Uint8Array, input: Uint8Array, numOutputs: 2): [Uint8Array, Uint8Array];
161
+ (chainingKey: Uint8Array, input: Uint8Array, numOutputs: 3): [Uint8Array, Uint8Array, Uint8Array];
162
+ };
163
+ declare function makeHKDF(hmac: HMAC): HKDF;
164
+
165
+ type Rekey = (k: DataView) => DataView;
166
+ declare function makeRekey(aead: AEAD): Rekey;
167
+
168
+ type rekey_Rekey = Rekey;
169
+ declare const rekey_makeRekey: typeof makeRekey;
170
+ declare namespace rekey {
171
+ export {
172
+ rekey_Rekey as Rekey,
173
+ rekey_makeRekey as makeRekey,
174
+ };
122
175
  }
176
+
177
+ interface Algorithms {
178
+ dh: DH;
179
+ aead: AEAD;
180
+ hash: Hash;
181
+ hmac?: HMAC;
182
+ hkdf?: HKDF;
183
+ rekey?: Rekey;
184
+ }
185
+ declare function matchPattern(a: Algorithms, protocol_name: string): string | null;
186
+
187
+ type algorithms_Algorithms = Algorithms;
188
+ declare const algorithms_matchPattern: typeof matchPattern;
189
+ declare namespace algorithms {
190
+ export {
191
+ algorithms_Algorithms as Algorithms,
192
+ algorithms_matchPattern as matchPattern,
193
+ };
194
+ }
195
+
123
196
  declare class CipherState {
124
- algorithms: NoiseProtocolAlgorithms;
197
+ algorithms: Algorithms;
125
198
  view: DataView | null;
126
199
  nonce: Nonce;
127
- constructor(algorithms: NoiseProtocolAlgorithms, key?: Uint8Array);
200
+ constructor(algorithms: Algorithms, key?: Uint8Array);
128
201
  encrypt(plaintext: Uint8Array, associated_data?: Uint8Array): Uint8Array;
129
202
  decrypt(ciphertext: Uint8Array, associated_data?: Uint8Array): Uint8Array;
130
203
  rekey(): void;
131
204
  }
205
+
206
+ type cipherstate_CipherState = CipherState;
207
+ declare const cipherstate_CipherState: typeof CipherState;
208
+ declare namespace cipherstate {
209
+ export {
210
+ cipherstate_CipherState as CipherState,
211
+ };
212
+ }
213
+
214
+ type KeyTransferToken = 'e' | 's';
215
+ type KeyMixToken = 'ee' | 'es' | 'se' | 'ss' | 'psk';
216
+ type Token = KeyTransferToken | KeyMixToken;
217
+ type PreMessage = ['e'] | ['s'] | ['e', 's'] | [];
218
+ interface HandshakePattern {
219
+ name: string;
220
+ baseName: string;
221
+ messages: Token[][];
222
+ initiatorPreMessage: PreMessage;
223
+ responderPreMessage: PreMessage;
224
+ }
225
+ declare const PATTERNS: {
226
+ [key: string]: HandshakePattern;
227
+ };
228
+ declare function isOneWay(pat: HandshakePattern): boolean;
229
+ declare function lookupPattern(name: string): HandshakePattern | null;
230
+
231
+ type patterns_HandshakePattern = HandshakePattern;
232
+ type patterns_KeyMixToken = KeyMixToken;
233
+ type patterns_KeyTransferToken = KeyTransferToken;
234
+ declare const patterns_PATTERNS: typeof PATTERNS;
235
+ type patterns_PreMessage = PreMessage;
236
+ type patterns_Token = Token;
237
+ declare const patterns_isOneWay: typeof isOneWay;
238
+ declare const patterns_lookupPattern: typeof lookupPattern;
239
+ declare namespace patterns {
240
+ export {
241
+ patterns_HandshakePattern as HandshakePattern,
242
+ patterns_KeyMixToken as KeyMixToken,
243
+ patterns_KeyTransferToken as KeyTransferToken,
244
+ patterns_PATTERNS as PATTERNS,
245
+ patterns_PreMessage as PreMessage,
246
+ patterns_Token as Token,
247
+ patterns_isOneWay as isOneWay,
248
+ patterns_lookupPattern as lookupPattern,
249
+ };
250
+ }
251
+
132
252
  type Role = 'initiator' | 'responder';
133
- type NoiseProtocolOptions = {
253
+ type HandshakeOptions = {
134
254
  prologue?: Uint8Array;
135
255
  staticKeypair?: DHKeyPair;
136
256
  remoteStaticPublicKey?: Uint8Array;
@@ -138,16 +258,12 @@ type NoiseProtocolOptions = {
138
258
  remotePregeneratedEphemeralPublicKey?: Uint8Array;
139
259
  preSharedKeys?: Uint8Array[];
140
260
  };
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
261
  type TransportState = {
146
262
  send: CipherState;
147
263
  recv: CipherState;
148
264
  };
149
- declare class NoiseHandshake {
150
- algorithms: NoiseProtocolAlgorithms;
265
+ declare class Handshake {
266
+ algorithms: Algorithms;
151
267
  pattern: HandshakePattern;
152
268
  role: Role;
153
269
  staticKeypair: DHKeyPair;
@@ -159,7 +275,8 @@ declare class NoiseHandshake {
159
275
  cipherState: CipherState;
160
276
  chainingKey: Uint8Array;
161
277
  handshakeHash: Uint8Array;
162
- constructor(algorithms: NoiseProtocolAlgorithms, pattern: HandshakePattern, role: Role, options?: NoiseProtocolOptions);
278
+ hkdf: HKDF;
279
+ constructor(algorithms: Algorithms, pattern: HandshakePattern, role: Role, options?: HandshakeOptions);
163
280
  get isInitiator(): boolean;
164
281
  mixHash(data: Uint8Array): void;
165
282
  mixKey(input: Uint8Array): void;
@@ -180,123 +297,32 @@ declare class NoiseHandshake {
180
297
  completeHandshake(writePacket: (packet: Uint8Array) => Promise<void>, readPacket: () => Promise<Uint8Array>, handleMessage?: (_m: Uint8Array) => Promise<void>, produceMessage?: () => Promise<Uint8Array>): Promise<TransportState>;
181
298
  }
182
299
 
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 {
300
+ type handshake_Handshake = Handshake;
301
+ declare const handshake_Handshake: typeof Handshake;
302
+ type handshake_HandshakeOptions = HandshakeOptions;
303
+ type handshake_Role = Role;
304
+ type handshake_TransportState = TransportState;
305
+ declare namespace handshake {
204
306
  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,
307
+ handshake_Handshake as Handshake,
308
+ handshake_HandshakeOptions as HandshakeOptions,
309
+ handshake_Role as Role,
310
+ handshake_TransportState as TransportState,
221
311
  };
222
312
  }
223
313
 
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
- }
314
+ declare const Noise_25519_ChaChaPoly_BLAKE2s: Algorithms;
266
315
 
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 {
316
+ declare const profiles_Noise_25519_ChaChaPoly_BLAKE2s: typeof Noise_25519_ChaChaPoly_BLAKE2s;
317
+ declare namespace profiles {
283
318
  export {
284
- profiles_d_Noise_25519_ChaChaPoly_BLAKE2s as Noise_25519_ChaChaPoly_BLAKE2s,
319
+ profiles_Noise_25519_ChaChaPoly_BLAKE2s as Noise_25519_ChaChaPoly_BLAKE2s,
285
320
  };
286
321
  }
287
322
 
288
323
  declare const _randomBytes: (out: Uint8Array, n: number) => void;
289
324
  declare function randomBytes(n: number): Uint8Array;
290
325
 
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
326
  declare const crypto_scalarmult_BYTES = 32;
301
327
  declare const crypto_scalarmult_SCALARBYTES = 32;
302
328
  declare function crypto_scalarmult(q: Uint8Array, n: Uint8Array, p: Uint8Array): void;
@@ -308,21 +334,45 @@ declare namespace scalarMult {
308
334
  }
309
335
  declare function scalarMultBase(n: Uint8Array): Uint8Array;
310
336
 
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 {
337
+ declare const x25519_crypto_scalarmult: typeof crypto_scalarmult;
338
+ declare const x25519_crypto_scalarmult_BYTES: typeof crypto_scalarmult_BYTES;
339
+ declare const x25519_crypto_scalarmult_SCALARBYTES: typeof crypto_scalarmult_SCALARBYTES;
340
+ declare const x25519_crypto_scalarmult_base: typeof crypto_scalarmult_base;
341
+ declare const x25519_scalarMult: typeof scalarMult;
342
+ declare const x25519_scalarMultBase: typeof scalarMultBase;
343
+ declare namespace x25519 {
318
344
  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,
345
+ x25519_crypto_scalarmult as crypto_scalarmult,
346
+ x25519_crypto_scalarmult_BYTES as crypto_scalarmult_BYTES,
347
+ x25519_crypto_scalarmult_SCALARBYTES as crypto_scalarmult_SCALARBYTES,
348
+ x25519_crypto_scalarmult_base as crypto_scalarmult_base,
349
+ x25519_scalarMult as scalarMult,
350
+ x25519_scalarMultBase as scalarMultBase,
325
351
  };
326
352
  }
327
353
 
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 };
354
+ declare const INTERNALS: {
355
+ aead: {
356
+ chacha20poly1305: typeof chacha20poly1305;
357
+ };
358
+ cipher: {
359
+ chacha20: typeof chacha20;
360
+ };
361
+ dh: {
362
+ x25519: typeof x25519;
363
+ };
364
+ hash: {
365
+ blake2s: typeof blake2s;
366
+ poly1305: typeof poly1305;
367
+ };
368
+ noise: {
369
+ algorithms: typeof algorithms;
370
+ cipherstate: typeof cipherstate;
371
+ handshake: typeof handshake;
372
+ patterns: typeof patterns;
373
+ profiles: typeof profiles;
374
+ rekey: typeof rekey;
375
+ };
376
+ };
377
+
378
+ export { AEAD, Algorithms, AuthenticationFailure, BLAKE2s, bytes_d as Bytes, ChaCha20, ChaCha20Poly1305_RFC8439, CipherState, DH, DHKeyPair, HKDF, HMAC, Handshake, HandshakeOptions, HandshakePattern, Hash, HashAlgorithm, INTERNALS, KeyMixToken, KeyTransferToken, Noise_25519_ChaChaPoly_BLAKE2s, Nonce, PATTERNS, Poly1305, PreMessage, Rekey, Role, StreamCipher, Token, TransportState, X25519, _decrypt, _encrypt, _randomBytes, isOneWay, lookupPattern, makeHKDF, makeHMAC, matchPattern, randomBytes };