salty-crypto 0.3.0 → 1.0.0-rc.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 +3 -3
- package/browser-demo.html +1 -1
- package/dist/salty-crypto.d.mts +348 -0
- package/dist/salty-crypto.d.ts +36 -87
- package/dist/salty-crypto.global.js +2 -0
- package/dist/salty-crypto.global.js.map +1 -0
- package/dist/salty-crypto.js +2 -1
- package/dist/salty-crypto.js.map +1 -0
- package/dist/salty-crypto.mjs +2 -0
- package/dist/salty-crypto.mjs.map +1 -0
- package/lib/aead/chacha20poly1305.d.ts +2 -0
- package/lib/aead/chacha20poly1305.js +53 -0
- package/lib/aead/chacha20poly1305.js.map +1 -0
- package/lib/aead.d.ts +16 -0
- package/lib/aead.js +18 -0
- package/lib/aead.js.map +1 -0
- package/lib/bytes.d.ts +4 -0
- package/lib/bytes.js +27 -0
- package/lib/bytes.js.map +1 -0
- package/lib/cipher/chacha20.d.ts +4 -0
- package/lib/cipher/chacha20.js +84 -0
- package/lib/cipher/chacha20.js.map +1 -0
- package/lib/cipher.d.ts +9 -0
- package/lib/cipher.js +4 -0
- package/lib/cipher.js.map +1 -0
- package/lib/dh/x25519.d.ts +10 -0
- package/lib/dh/x25519.js +624 -0
- package/lib/dh/x25519.js.map +1 -0
- package/lib/dh.d.ts +11 -0
- package/lib/dh.js +17 -0
- package/lib/dh.js.map +1 -0
- package/lib/hash/blake2s.d.ts +18 -0
- package/lib/hash/blake2s.js +120 -0
- package/lib/hash/blake2s.js.map +1 -0
- package/lib/hash/poly1305.d.ts +18 -0
- package/lib/hash/poly1305.js +376 -0
- package/lib/hash/poly1305.js.map +1 -0
- package/lib/hash.d.ts +14 -0
- package/lib/hash.js +5 -0
- package/lib/hash.js.map +1 -0
- package/lib/hkdf.d.ts +6 -0
- package/lib/hkdf.js +17 -0
- package/lib/hkdf.js.map +1 -0
- package/lib/hmac.d.ts +6 -0
- package/lib/hmac.js +17 -0
- package/lib/hmac.js.map +1 -0
- package/lib/index.d.ts +45 -0
- package/lib/index.js +48 -0
- package/lib/index.js.map +1 -0
- package/lib/io.d.ts +4 -0
- package/lib/io.js +37 -0
- package/lib/io.js.map +1 -0
- package/lib/noise/algorithms.d.ts +15 -0
- package/lib/noise/algorithms.js +10 -0
- package/lib/noise/algorithms.js.map +1 -0
- package/lib/noise/cipherstate.d.ts +14 -0
- package/lib/noise/cipherstate.js +62 -0
- package/lib/noise/cipherstate.js.map +1 -0
- package/lib/noise/handshake.d.ts +52 -0
- package/lib/noise/handshake.js +191 -0
- package/lib/noise/handshake.js.map +1 -0
- package/lib/noise/patterns.d.ts +16 -0
- package/lib/noise/patterns.js +73 -0
- package/lib/noise/patterns.js.map +1 -0
- package/lib/noise/profiles.d.ts +2 -0
- package/lib/noise/profiles.js +11 -0
- package/lib/noise/profiles.js.map +1 -0
- package/lib/noise/rekey.d.ts +3 -0
- package/lib/noise/rekey.js +9 -0
- package/lib/noise/rekey.js.map +1 -0
- package/lib/noise.d.ts +6 -0
- package/lib/noise.js +8 -0
- package/lib/noise.js.map +1 -0
- package/lib/nonce.d.ts +9 -0
- package/lib/nonce.js +25 -0
- package/lib/nonce.js.map +1 -0
- package/lib/random.d.ts +2 -0
- package/lib/random.js +34 -0
- package/lib/random.js.map +1 -0
- package/package.json +38 -22
- package/src/.DS_Store +0 -0
- package/src/aead/chacha20poly1305.ts +7 -7
- package/src/aead.ts +3 -3
- package/src/bytes.ts +1 -1
- package/src/cipher/chacha20.ts +3 -3
- package/src/cipher.ts +3 -3
- package/src/dh/x25519.ts +1 -1
- package/src/dh.ts +3 -3
- package/src/hash/blake2s.ts +2 -2
- package/src/hash/poly1305.ts +2 -2
- package/src/hash.ts +3 -3
- package/src/hkdf.ts +3 -3
- package/src/hmac.ts +3 -3
- package/src/index.ts +23 -23
- package/src/io.ts +3 -0
- package/src/noise/algorithms.ts +7 -7
- package/src/noise/cipherstate.ts +4 -4
- package/src/noise/handshake.ts +8 -8
- package/src/noise/patterns.ts +1 -1
- package/src/noise/profiles.ts +5 -5
- package/src/noise/rekey.ts +3 -3
- package/src/noise.ts +1 -1
- package/src/nonce.ts +1 -1
- package/src/random.ts +2 -3
- package/test/{tests/aead.test.ts → aead.test.ts} +2 -2
- package/test/{tests/blake2.test.ts → blake2.test.ts} +2 -2
- package/test/{tests/chacha20.test.ts → chacha20.test.ts} +2 -2
- package/test/{tests/io.test.ts → io.test.ts} +2 -2
- package/test/{tests/noise.test.ts → noise.test.ts} +2 -2
- package/test/{tests/poly1305.test.ts → poly1305.test.ts} +2 -2
- package/tsup.config.ts +14 -0
- package/rollup.config.js +0 -19
- package/speed.ts +0 -22
- package/test/harness.ts +0 -74
- package/test/tsconfig.json +0 -18
- package/test-vectors/noise-c-basic.txt +0 -19684
- package/test-vectors/snow.txt +0 -10348
- package/watchall +0 -22
package/README.md
CHANGED
|
@@ -73,17 +73,17 @@ Includes (and passes) test vectors from [noise-c](https://github.com/rweather/no
|
|
|
73
73
|
- [`src/nonce.ts`](src/nonce.ts): Representation of 64- (or 96-) bit nonces.
|
|
74
74
|
- [`src/random.ts`](src/random.ts): Port of [the randomness-generation code from tweetnacl.js](https://github.com/dchest/tweetnacl-js/blob/6a9594a35a27f9c723c5f1c107e376d1c65c23b3/nacl-fast.js#L2363-L2389).
|
|
75
75
|
- [`test-vectors`](test-vectors): Contains Noise test vectors (more-or-less in the [standard JSON format](https://github.com/noiseprotocol/noise_wiki/wiki/Test-vectors)) copied from other projects.
|
|
76
|
-
- [`test`](test): Contains
|
|
76
|
+
- [`test`](test): Contains test code.
|
|
77
77
|
|
|
78
78
|
## Copyright and License
|
|
79
79
|
|
|
80
|
-
These libraries are Copyright © 2023 Tony Garnock-Jones `<tonyg@leastfixedpoint.com>`.
|
|
80
|
+
These libraries are Copyright © 2023–2025 Tony Garnock-Jones `<tonyg@leastfixedpoint.com>`.
|
|
81
81
|
|
|
82
82
|
They are made available to you under the [MIT license](https://spdx.org/licenses/MIT.html).
|
|
83
83
|
|
|
84
84
|
MIT License
|
|
85
85
|
|
|
86
|
-
Copyright (c) 2023 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
|
86
|
+
Copyright (c) 2023–2025 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
|
87
87
|
|
|
88
88
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
89
89
|
of this software and associated documentation files (the "Software"), to deal
|
package/browser-demo.html
CHANGED
|
@@ -0,0 +1,348 @@
|
|
|
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;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
declare const ChaCha20Poly1305_RFC8439: AEAD;
|
|
12
|
+
|
|
13
|
+
declare const chacha20poly1305_ChaCha20Poly1305_RFC8439: typeof ChaCha20Poly1305_RFC8439;
|
|
14
|
+
declare namespace chacha20poly1305 {
|
|
15
|
+
export { chacha20poly1305_ChaCha20Poly1305_RFC8439 as ChaCha20Poly1305_RFC8439 };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
declare class AuthenticationFailure extends Error {
|
|
19
|
+
}
|
|
20
|
+
interface AEAD {
|
|
21
|
+
readonly NAME: string;
|
|
22
|
+
readonly KEYBYTES: number;
|
|
23
|
+
readonly NONCEBYTES: number;
|
|
24
|
+
readonly TAGBYTES: number;
|
|
25
|
+
encrypt_detached(plaintext: Uint8Array, ciphertext: Uint8Array, messagelength: number, tag: Uint8Array, key: DataView, nonce: Nonce, associated_data?: Uint8Array): void;
|
|
26
|
+
encrypt(plaintext: Uint8Array, key: DataView, nonce: Nonce, associated_data?: Uint8Array): Uint8Array;
|
|
27
|
+
decrypt_detached(plaintext: Uint8Array, ciphertext: Uint8Array, messagelength: number, expected_tag: Uint8Array, key: DataView, nonce: Nonce, associated_data?: Uint8Array): boolean;
|
|
28
|
+
decrypt(ciphertextAndTag: Uint8Array, key: DataView, nonce: Nonce, associated_data?: Uint8Array): Uint8Array;
|
|
29
|
+
}
|
|
30
|
+
declare function _encrypt(this: AEAD, plaintext: Uint8Array, key: DataView, nonce: Nonce, associated_data?: Uint8Array): Uint8Array;
|
|
31
|
+
declare function _decrypt(this: AEAD, ciphertextAndTag: Uint8Array, key: DataView, nonce: Nonce, associated_data?: Uint8Array): Uint8Array;
|
|
32
|
+
|
|
33
|
+
declare function equal(x: Uint8Array, y: Uint8Array, n: number): boolean;
|
|
34
|
+
declare function xor(a: Uint8Array, b: Uint8Array): Uint8Array;
|
|
35
|
+
declare function append(a: Uint8Array, b: Uint8Array): Uint8Array;
|
|
36
|
+
declare const EMPTY: Uint8Array<ArrayBuffer>;
|
|
37
|
+
|
|
38
|
+
declare const bytes_EMPTY: typeof EMPTY;
|
|
39
|
+
declare const bytes_append: typeof append;
|
|
40
|
+
declare const bytes_equal: typeof equal;
|
|
41
|
+
declare const bytes_xor: typeof xor;
|
|
42
|
+
declare namespace bytes {
|
|
43
|
+
export { bytes_EMPTY as EMPTY, bytes_append as append, bytes_equal as equal, bytes_xor as xor };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
declare function chacha20_quarter_round(s: Uint32Array, a: number, b: number, c: number, d: number): void;
|
|
47
|
+
declare function chacha20_block(key: DataView, block: number, nonce: DataView): Uint32Array;
|
|
48
|
+
declare const ChaCha20: StreamCipher;
|
|
49
|
+
|
|
50
|
+
declare const chacha20_ChaCha20: typeof ChaCha20;
|
|
51
|
+
declare const chacha20_chacha20_block: typeof chacha20_block;
|
|
52
|
+
declare const chacha20_chacha20_quarter_round: typeof chacha20_quarter_round;
|
|
53
|
+
declare namespace chacha20 {
|
|
54
|
+
export { chacha20_ChaCha20 as ChaCha20, chacha20_chacha20_block as chacha20_block, chacha20_chacha20_quarter_round as chacha20_quarter_round };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
interface StreamCipher {
|
|
58
|
+
readonly NAME: string;
|
|
59
|
+
readonly KEYBYTES: number;
|
|
60
|
+
readonly NONCEBYTES: number;
|
|
61
|
+
readonly BLOCKBYTES: number;
|
|
62
|
+
stream_xor(key: DataView, nonce: Nonce, input: Uint8Array, output: Uint8Array, initial_counter?: number, messagelength?: number): void;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
type DHKeyPair = {
|
|
66
|
+
public: Uint8Array;
|
|
67
|
+
secret: Uint8Array;
|
|
68
|
+
};
|
|
69
|
+
interface DH {
|
|
70
|
+
readonly NAME: string;
|
|
71
|
+
readonly DHLEN: number;
|
|
72
|
+
generateKeypair(): DHKeyPair;
|
|
73
|
+
dh(kp: DHKeyPair, pk: Uint8Array): Uint8Array;
|
|
74
|
+
}
|
|
75
|
+
declare const X25519: DH;
|
|
76
|
+
|
|
77
|
+
declare const BLAKE2s: {
|
|
78
|
+
new (key?: Uint8Array, outlen?: number): {
|
|
79
|
+
b: Uint8Array<ArrayBuffer>;
|
|
80
|
+
bv: DataView<ArrayBuffer>;
|
|
81
|
+
h: Uint32Array<ArrayBuffer>;
|
|
82
|
+
t: Uint32Array<ArrayBuffer>;
|
|
83
|
+
c: number;
|
|
84
|
+
outlen: number;
|
|
85
|
+
update(input: Uint8Array, offset?: number, length?: number): void;
|
|
86
|
+
final(output?: Uint8Array): Uint8Array;
|
|
87
|
+
compress(last: boolean): void;
|
|
88
|
+
};
|
|
89
|
+
readonly NAME: "BLAKE2s";
|
|
90
|
+
readonly KEYBYTES: 32;
|
|
91
|
+
readonly OUTBYTES: 32;
|
|
92
|
+
readonly BLOCKLEN: 64;
|
|
93
|
+
digest(input: Uint8Array, key?: Uint8Array, outlen?: number): Uint8Array;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
declare const blake2s_BLAKE2s: typeof BLAKE2s;
|
|
97
|
+
declare namespace blake2s {
|
|
98
|
+
export { blake2s_BLAKE2s as BLAKE2s };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
declare const Poly1305: {
|
|
102
|
+
new (key?: Uint8Array, outlen?: number): {
|
|
103
|
+
buffer: Uint8Array<ArrayBuffer>;
|
|
104
|
+
r: Uint16Array<ArrayBuffer>;
|
|
105
|
+
h: Uint16Array<ArrayBuffer>;
|
|
106
|
+
pad: Uint16Array<ArrayBuffer>;
|
|
107
|
+
leftover: number;
|
|
108
|
+
fin: number;
|
|
109
|
+
blocks(m: Uint8Array, mpos: number, bytes: number): void;
|
|
110
|
+
final(mac?: Uint8Array): Uint8Array;
|
|
111
|
+
update(m: Uint8Array, mpos?: number, bytes?: number): void;
|
|
112
|
+
};
|
|
113
|
+
readonly NAME: "Poly1305";
|
|
114
|
+
readonly KEYBYTES: 32;
|
|
115
|
+
readonly OUTBYTES: 16;
|
|
116
|
+
readonly BLOCKLEN: 16;
|
|
117
|
+
digest(input: Uint8Array, key?: Uint8Array, outlen?: number): Uint8Array;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
declare const poly1305_Poly1305: typeof Poly1305;
|
|
121
|
+
declare namespace poly1305 {
|
|
122
|
+
export { poly1305_Poly1305 as Poly1305 };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
interface Hash {
|
|
126
|
+
readonly NAME: string;
|
|
127
|
+
readonly KEYBYTES: number;
|
|
128
|
+
readonly OUTBYTES: number;
|
|
129
|
+
readonly BLOCKLEN: number;
|
|
130
|
+
digest(input: Uint8Array, key?: Uint8Array, outlen?: number): Uint8Array;
|
|
131
|
+
new (key?: Uint8Array, outlen?: number): HashAlgorithm;
|
|
132
|
+
}
|
|
133
|
+
interface HashAlgorithm {
|
|
134
|
+
update(input: Uint8Array, offset?: number, length?: number): void;
|
|
135
|
+
final(output?: Uint8Array): Uint8Array;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
type HMAC = {
|
|
139
|
+
(key: Uint8Array, data: Uint8Array): Uint8Array;
|
|
140
|
+
readonly NAME: string;
|
|
141
|
+
};
|
|
142
|
+
declare function makeHMAC(hash: Hash): HMAC;
|
|
143
|
+
|
|
144
|
+
type HKDF = {
|
|
145
|
+
(chainingKey: Uint8Array, input: Uint8Array, numOutputs: 2): [Uint8Array, Uint8Array];
|
|
146
|
+
(chainingKey: Uint8Array, input: Uint8Array, numOutputs: 3): [Uint8Array, Uint8Array, Uint8Array];
|
|
147
|
+
};
|
|
148
|
+
declare function makeHKDF(hmac: HMAC): HKDF;
|
|
149
|
+
|
|
150
|
+
declare function toHex(bs: Uint8Array): string;
|
|
151
|
+
declare function fromHex(s: string): Uint8Array;
|
|
152
|
+
declare function toBase64(bs: Uint8Array, withPadding?: boolean): string;
|
|
153
|
+
declare function fromBase64(s: string): Uint8Array;
|
|
154
|
+
|
|
155
|
+
declare const io_fromBase64: typeof fromBase64;
|
|
156
|
+
declare const io_fromHex: typeof fromHex;
|
|
157
|
+
declare const io_toBase64: typeof toBase64;
|
|
158
|
+
declare const io_toHex: typeof toHex;
|
|
159
|
+
declare namespace io {
|
|
160
|
+
export { io_fromBase64 as fromBase64, io_fromHex as fromHex, io_toBase64 as toBase64, io_toHex as toHex };
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
type Rekey = (k: DataView) => DataView;
|
|
164
|
+
declare function makeRekey(aead: AEAD): Rekey;
|
|
165
|
+
|
|
166
|
+
type rekey_Rekey = Rekey;
|
|
167
|
+
declare const rekey_makeRekey: typeof makeRekey;
|
|
168
|
+
declare namespace rekey {
|
|
169
|
+
export { type rekey_Rekey as Rekey, rekey_makeRekey as makeRekey };
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
interface Algorithms {
|
|
173
|
+
dh: DH;
|
|
174
|
+
aead: AEAD;
|
|
175
|
+
hash: Hash;
|
|
176
|
+
hmac?: HMAC;
|
|
177
|
+
hkdf?: HKDF;
|
|
178
|
+
rekey?: Rekey;
|
|
179
|
+
}
|
|
180
|
+
declare function matchPattern(a: Algorithms, protocol_name: string): string | null;
|
|
181
|
+
|
|
182
|
+
type algorithms_Algorithms = Algorithms;
|
|
183
|
+
declare const algorithms_matchPattern: typeof matchPattern;
|
|
184
|
+
declare namespace algorithms {
|
|
185
|
+
export { type algorithms_Algorithms as Algorithms, algorithms_matchPattern as matchPattern };
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
declare class CipherState {
|
|
189
|
+
algorithms: Algorithms;
|
|
190
|
+
view: DataView | null;
|
|
191
|
+
nonce: Nonce;
|
|
192
|
+
readonly maxPayload: number;
|
|
193
|
+
constructor(algorithms: Algorithms, key?: Uint8Array);
|
|
194
|
+
encrypt(plaintext: Uint8Array, associated_data?: Uint8Array): Uint8Array;
|
|
195
|
+
decrypt(ciphertext: Uint8Array, associated_data?: Uint8Array): Uint8Array;
|
|
196
|
+
rekey(): void;
|
|
197
|
+
encrypt_large(plaintext: Uint8Array): Uint8Array[];
|
|
198
|
+
decrypt_large(ciphertexts: Uint8Array[]): Uint8Array;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
type cipherstate_CipherState = CipherState;
|
|
202
|
+
declare const cipherstate_CipherState: typeof CipherState;
|
|
203
|
+
declare namespace cipherstate {
|
|
204
|
+
export { cipherstate_CipherState as CipherState };
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
type KeyTransferToken = 'e' | 's';
|
|
208
|
+
type KeyMixToken = 'ee' | 'es' | 'se' | 'ss' | 'psk';
|
|
209
|
+
type Token = KeyTransferToken | KeyMixToken;
|
|
210
|
+
type PreMessage = ['e'] | ['s'] | ['e', 's'] | [];
|
|
211
|
+
interface HandshakePattern {
|
|
212
|
+
name: string;
|
|
213
|
+
baseName: string;
|
|
214
|
+
messages: Token[][];
|
|
215
|
+
initiatorPreMessage: PreMessage;
|
|
216
|
+
responderPreMessage: PreMessage;
|
|
217
|
+
}
|
|
218
|
+
declare const PATTERNS: {
|
|
219
|
+
[key: string]: HandshakePattern;
|
|
220
|
+
};
|
|
221
|
+
declare function isOneWay(pat: HandshakePattern): boolean;
|
|
222
|
+
declare function lookupPattern(name: string): HandshakePattern | null;
|
|
223
|
+
|
|
224
|
+
type patterns_HandshakePattern = HandshakePattern;
|
|
225
|
+
type patterns_KeyMixToken = KeyMixToken;
|
|
226
|
+
type patterns_KeyTransferToken = KeyTransferToken;
|
|
227
|
+
declare const patterns_PATTERNS: typeof PATTERNS;
|
|
228
|
+
type patterns_PreMessage = PreMessage;
|
|
229
|
+
type patterns_Token = Token;
|
|
230
|
+
declare const patterns_isOneWay: typeof isOneWay;
|
|
231
|
+
declare const patterns_lookupPattern: typeof lookupPattern;
|
|
232
|
+
declare namespace patterns {
|
|
233
|
+
export { type patterns_HandshakePattern as HandshakePattern, type patterns_KeyMixToken as KeyMixToken, type patterns_KeyTransferToken as KeyTransferToken, patterns_PATTERNS as PATTERNS, type patterns_PreMessage as PreMessage, type patterns_Token as Token, patterns_isOneWay as isOneWay, patterns_lookupPattern as lookupPattern };
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
type Role = 'initiator' | 'responder';
|
|
237
|
+
type HandshakeOptions = {
|
|
238
|
+
prologue?: Uint8Array;
|
|
239
|
+
staticKeypair?: DHKeyPair;
|
|
240
|
+
remoteStaticPublicKey?: Uint8Array;
|
|
241
|
+
pregeneratedEphemeralKeypair?: DHKeyPair;
|
|
242
|
+
remotePregeneratedEphemeralPublicKey?: Uint8Array;
|
|
243
|
+
preSharedKeys?: Uint8Array[];
|
|
244
|
+
};
|
|
245
|
+
type TransportState = {
|
|
246
|
+
send: CipherState;
|
|
247
|
+
recv: CipherState;
|
|
248
|
+
};
|
|
249
|
+
declare class Handshake {
|
|
250
|
+
algorithms: Algorithms;
|
|
251
|
+
role: Role;
|
|
252
|
+
staticKeypair: DHKeyPair;
|
|
253
|
+
remoteStaticPublicKey: Uint8Array | null;
|
|
254
|
+
ephemeralKeypair: DHKeyPair;
|
|
255
|
+
remoteEphemeralPublicKey: Uint8Array | null;
|
|
256
|
+
preSharedKeys?: Uint8Array[];
|
|
257
|
+
stepIndex: number;
|
|
258
|
+
cipherState: CipherState;
|
|
259
|
+
chainingKey: Uint8Array;
|
|
260
|
+
handshakeHash: Uint8Array;
|
|
261
|
+
hkdf: HKDF;
|
|
262
|
+
pattern: HandshakePattern;
|
|
263
|
+
constructor(algorithms: Algorithms, pattern: HandshakePattern | string, role: Role, options?: HandshakeOptions);
|
|
264
|
+
get isInitiator(): boolean;
|
|
265
|
+
mixHash(data: Uint8Array): void;
|
|
266
|
+
mixKey(input: Uint8Array): void;
|
|
267
|
+
mixKeyAndHashNextPSK(): void;
|
|
268
|
+
encryptAndHash(p: Uint8Array): Uint8Array<ArrayBufferLike>;
|
|
269
|
+
decryptAndHash(c: Uint8Array): Uint8Array<ArrayBufferLike>;
|
|
270
|
+
_split(): TransportState | null;
|
|
271
|
+
_nextStep(): Token[];
|
|
272
|
+
_processKeyMixToken(t: KeyMixToken): void;
|
|
273
|
+
writeMessage(payload: Uint8Array): {
|
|
274
|
+
packet: Uint8Array;
|
|
275
|
+
finished: TransportState | null;
|
|
276
|
+
};
|
|
277
|
+
readMessage(packet: Uint8Array): {
|
|
278
|
+
message: Uint8Array;
|
|
279
|
+
finished: TransportState | null;
|
|
280
|
+
};
|
|
281
|
+
completeHandshake(writePacket: (packet: Uint8Array) => Promise<void>, readPacket: () => Promise<Uint8Array>, handleMessage?: (_m: Uint8Array) => Promise<void>, produceMessage?: () => Promise<Uint8Array>): Promise<TransportState>;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
type handshake_Handshake = Handshake;
|
|
285
|
+
declare const handshake_Handshake: typeof Handshake;
|
|
286
|
+
type handshake_HandshakeOptions = HandshakeOptions;
|
|
287
|
+
type handshake_Role = Role;
|
|
288
|
+
type handshake_TransportState = TransportState;
|
|
289
|
+
declare namespace handshake {
|
|
290
|
+
export { handshake_Handshake as Handshake, type handshake_HandshakeOptions as HandshakeOptions, type handshake_Role as Role, type handshake_TransportState as TransportState };
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
declare const Noise_25519_ChaChaPoly_BLAKE2s: Algorithms;
|
|
294
|
+
|
|
295
|
+
declare const profiles_Noise_25519_ChaChaPoly_BLAKE2s: typeof Noise_25519_ChaChaPoly_BLAKE2s;
|
|
296
|
+
declare namespace profiles {
|
|
297
|
+
export { profiles_Noise_25519_ChaChaPoly_BLAKE2s as Noise_25519_ChaChaPoly_BLAKE2s };
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
declare const _randomBytes: (out: Uint8Array, n: number) => void;
|
|
301
|
+
declare function randomBytes(n: number): Uint8Array;
|
|
302
|
+
|
|
303
|
+
declare const crypto_scalarmult_BYTES = 32;
|
|
304
|
+
declare const crypto_scalarmult_SCALARBYTES = 32;
|
|
305
|
+
declare function crypto_scalarmult(q: Uint8Array, n: Uint8Array, p: Uint8Array): void;
|
|
306
|
+
declare function crypto_scalarmult_base(q: Uint8Array, n: Uint8Array): void;
|
|
307
|
+
declare function scalarMult(n: Uint8Array, p: Uint8Array): Uint8Array;
|
|
308
|
+
declare namespace scalarMult {
|
|
309
|
+
var scalarLength: number;
|
|
310
|
+
var groupElementLength: number;
|
|
311
|
+
}
|
|
312
|
+
declare function scalarMultBase(n: Uint8Array): Uint8Array;
|
|
313
|
+
|
|
314
|
+
declare const x25519_crypto_scalarmult: typeof crypto_scalarmult;
|
|
315
|
+
declare const x25519_crypto_scalarmult_BYTES: typeof crypto_scalarmult_BYTES;
|
|
316
|
+
declare const x25519_crypto_scalarmult_SCALARBYTES: typeof crypto_scalarmult_SCALARBYTES;
|
|
317
|
+
declare const x25519_crypto_scalarmult_base: typeof crypto_scalarmult_base;
|
|
318
|
+
declare const x25519_scalarMult: typeof scalarMult;
|
|
319
|
+
declare const x25519_scalarMultBase: typeof scalarMultBase;
|
|
320
|
+
declare namespace x25519 {
|
|
321
|
+
export { x25519_crypto_scalarmult as crypto_scalarmult, x25519_crypto_scalarmult_BYTES as crypto_scalarmult_BYTES, x25519_crypto_scalarmult_SCALARBYTES as crypto_scalarmult_SCALARBYTES, x25519_crypto_scalarmult_base as crypto_scalarmult_base, x25519_scalarMult as scalarMult, x25519_scalarMultBase as scalarMultBase };
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
declare const INTERNALS: {
|
|
325
|
+
aead: {
|
|
326
|
+
chacha20poly1305: typeof chacha20poly1305;
|
|
327
|
+
};
|
|
328
|
+
cipher: {
|
|
329
|
+
chacha20: typeof chacha20;
|
|
330
|
+
};
|
|
331
|
+
dh: {
|
|
332
|
+
x25519: typeof x25519;
|
|
333
|
+
};
|
|
334
|
+
hash: {
|
|
335
|
+
blake2s: typeof blake2s;
|
|
336
|
+
poly1305: typeof poly1305;
|
|
337
|
+
};
|
|
338
|
+
noise: {
|
|
339
|
+
algorithms: typeof algorithms;
|
|
340
|
+
cipherstate: typeof cipherstate;
|
|
341
|
+
handshake: typeof handshake;
|
|
342
|
+
patterns: typeof patterns;
|
|
343
|
+
profiles: typeof profiles;
|
|
344
|
+
rekey: typeof rekey;
|
|
345
|
+
};
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
export { type AEAD, type Algorithms, AuthenticationFailure, BLAKE2s, bytes as Bytes, ChaCha20, ChaCha20Poly1305_RFC8439, CipherState, type DH, type DHKeyPair, type HKDF, type HMAC, Handshake, type HandshakeOptions, type HandshakePattern, type Hash, type HashAlgorithm, INTERNALS, io as IO, type KeyMixToken, type KeyTransferToken, Noise_25519_ChaChaPoly_BLAKE2s, Nonce, PATTERNS, Poly1305, type PreMessage, type Rekey, type Role, type StreamCipher, type Token, type TransportState, X25519, _decrypt, _encrypt, _randomBytes, isOneWay, lookupPattern, makeHKDF, makeHMAC, matchPattern, randomBytes };
|
package/dist/salty-crypto.d.ts
CHANGED
|
@@ -12,9 +12,7 @@ declare const ChaCha20Poly1305_RFC8439: AEAD;
|
|
|
12
12
|
|
|
13
13
|
declare const chacha20poly1305_ChaCha20Poly1305_RFC8439: typeof ChaCha20Poly1305_RFC8439;
|
|
14
14
|
declare namespace chacha20poly1305 {
|
|
15
|
-
export {
|
|
16
|
-
chacha20poly1305_ChaCha20Poly1305_RFC8439 as ChaCha20Poly1305_RFC8439,
|
|
17
|
-
};
|
|
15
|
+
export { chacha20poly1305_ChaCha20Poly1305_RFC8439 as ChaCha20Poly1305_RFC8439 };
|
|
18
16
|
}
|
|
19
17
|
|
|
20
18
|
declare class AuthenticationFailure extends Error {
|
|
@@ -35,19 +33,14 @@ declare function _decrypt(this: AEAD, ciphertextAndTag: Uint8Array, key: DataVie
|
|
|
35
33
|
declare function equal(x: Uint8Array, y: Uint8Array, n: number): boolean;
|
|
36
34
|
declare function xor(a: Uint8Array, b: Uint8Array): Uint8Array;
|
|
37
35
|
declare function append(a: Uint8Array, b: Uint8Array): Uint8Array;
|
|
38
|
-
declare const EMPTY: Uint8Array
|
|
39
|
-
|
|
40
|
-
declare const
|
|
41
|
-
declare const
|
|
42
|
-
declare const
|
|
43
|
-
declare const
|
|
44
|
-
declare namespace
|
|
45
|
-
export {
|
|
46
|
-
bytes_d_EMPTY as EMPTY,
|
|
47
|
-
bytes_d_append as append,
|
|
48
|
-
bytes_d_equal as equal,
|
|
49
|
-
bytes_d_xor as xor,
|
|
50
|
-
};
|
|
36
|
+
declare const EMPTY: Uint8Array<ArrayBuffer>;
|
|
37
|
+
|
|
38
|
+
declare const bytes_EMPTY: typeof EMPTY;
|
|
39
|
+
declare const bytes_append: typeof append;
|
|
40
|
+
declare const bytes_equal: typeof equal;
|
|
41
|
+
declare const bytes_xor: typeof xor;
|
|
42
|
+
declare namespace bytes {
|
|
43
|
+
export { bytes_EMPTY as EMPTY, bytes_append as append, bytes_equal as equal, bytes_xor as xor };
|
|
51
44
|
}
|
|
52
45
|
|
|
53
46
|
declare function chacha20_quarter_round(s: Uint32Array, a: number, b: number, c: number, d: number): void;
|
|
@@ -58,11 +51,7 @@ declare const chacha20_ChaCha20: typeof ChaCha20;
|
|
|
58
51
|
declare const chacha20_chacha20_block: typeof chacha20_block;
|
|
59
52
|
declare const chacha20_chacha20_quarter_round: typeof chacha20_quarter_round;
|
|
60
53
|
declare namespace chacha20 {
|
|
61
|
-
export {
|
|
62
|
-
chacha20_ChaCha20 as ChaCha20,
|
|
63
|
-
chacha20_chacha20_block as chacha20_block,
|
|
64
|
-
chacha20_chacha20_quarter_round as chacha20_quarter_round,
|
|
65
|
-
};
|
|
54
|
+
export { chacha20_ChaCha20 as ChaCha20, chacha20_chacha20_block as chacha20_block, chacha20_chacha20_quarter_round as chacha20_quarter_round };
|
|
66
55
|
}
|
|
67
56
|
|
|
68
57
|
interface StreamCipher {
|
|
@@ -87,10 +76,10 @@ declare const X25519: DH;
|
|
|
87
76
|
|
|
88
77
|
declare const BLAKE2s: {
|
|
89
78
|
new (key?: Uint8Array, outlen?: number): {
|
|
90
|
-
b: Uint8Array
|
|
91
|
-
bv: DataView
|
|
92
|
-
h: Uint32Array
|
|
93
|
-
t: Uint32Array
|
|
79
|
+
b: Uint8Array<ArrayBuffer>;
|
|
80
|
+
bv: DataView<ArrayBuffer>;
|
|
81
|
+
h: Uint32Array<ArrayBuffer>;
|
|
82
|
+
t: Uint32Array<ArrayBuffer>;
|
|
94
83
|
c: number;
|
|
95
84
|
outlen: number;
|
|
96
85
|
update(input: Uint8Array, offset?: number, length?: number): void;
|
|
@@ -106,17 +95,15 @@ declare const BLAKE2s: {
|
|
|
106
95
|
|
|
107
96
|
declare const blake2s_BLAKE2s: typeof BLAKE2s;
|
|
108
97
|
declare namespace blake2s {
|
|
109
|
-
export {
|
|
110
|
-
blake2s_BLAKE2s as BLAKE2s,
|
|
111
|
-
};
|
|
98
|
+
export { blake2s_BLAKE2s as BLAKE2s };
|
|
112
99
|
}
|
|
113
100
|
|
|
114
101
|
declare const Poly1305: {
|
|
115
102
|
new (key?: Uint8Array, outlen?: number): {
|
|
116
|
-
buffer: Uint8Array
|
|
117
|
-
r: Uint16Array
|
|
118
|
-
h: Uint16Array
|
|
119
|
-
pad: Uint16Array
|
|
103
|
+
buffer: Uint8Array<ArrayBuffer>;
|
|
104
|
+
r: Uint16Array<ArrayBuffer>;
|
|
105
|
+
h: Uint16Array<ArrayBuffer>;
|
|
106
|
+
pad: Uint16Array<ArrayBuffer>;
|
|
120
107
|
leftover: number;
|
|
121
108
|
fin: number;
|
|
122
109
|
blocks(m: Uint8Array, mpos: number, bytes: number): void;
|
|
@@ -132,9 +119,7 @@ declare const Poly1305: {
|
|
|
132
119
|
|
|
133
120
|
declare const poly1305_Poly1305: typeof Poly1305;
|
|
134
121
|
declare namespace poly1305 {
|
|
135
|
-
export {
|
|
136
|
-
poly1305_Poly1305 as Poly1305,
|
|
137
|
-
};
|
|
122
|
+
export { poly1305_Poly1305 as Poly1305 };
|
|
138
123
|
}
|
|
139
124
|
|
|
140
125
|
interface Hash {
|
|
@@ -167,17 +152,12 @@ declare function fromHex(s: string): Uint8Array;
|
|
|
167
152
|
declare function toBase64(bs: Uint8Array, withPadding?: boolean): string;
|
|
168
153
|
declare function fromBase64(s: string): Uint8Array;
|
|
169
154
|
|
|
170
|
-
declare const
|
|
171
|
-
declare const
|
|
172
|
-
declare const
|
|
173
|
-
declare const
|
|
174
|
-
declare namespace
|
|
175
|
-
export {
|
|
176
|
-
io_d_fromBase64 as fromBase64,
|
|
177
|
-
io_d_fromHex as fromHex,
|
|
178
|
-
io_d_toBase64 as toBase64,
|
|
179
|
-
io_d_toHex as toHex,
|
|
180
|
-
};
|
|
155
|
+
declare const io_fromBase64: typeof fromBase64;
|
|
156
|
+
declare const io_fromHex: typeof fromHex;
|
|
157
|
+
declare const io_toBase64: typeof toBase64;
|
|
158
|
+
declare const io_toHex: typeof toHex;
|
|
159
|
+
declare namespace io {
|
|
160
|
+
export { io_fromBase64 as fromBase64, io_fromHex as fromHex, io_toBase64 as toBase64, io_toHex as toHex };
|
|
181
161
|
}
|
|
182
162
|
|
|
183
163
|
type Rekey = (k: DataView) => DataView;
|
|
@@ -186,10 +166,7 @@ declare function makeRekey(aead: AEAD): Rekey;
|
|
|
186
166
|
type rekey_Rekey = Rekey;
|
|
187
167
|
declare const rekey_makeRekey: typeof makeRekey;
|
|
188
168
|
declare namespace rekey {
|
|
189
|
-
export {
|
|
190
|
-
rekey_Rekey as Rekey,
|
|
191
|
-
rekey_makeRekey as makeRekey,
|
|
192
|
-
};
|
|
169
|
+
export { type rekey_Rekey as Rekey, rekey_makeRekey as makeRekey };
|
|
193
170
|
}
|
|
194
171
|
|
|
195
172
|
interface Algorithms {
|
|
@@ -205,10 +182,7 @@ declare function matchPattern(a: Algorithms, protocol_name: string): string | nu
|
|
|
205
182
|
type algorithms_Algorithms = Algorithms;
|
|
206
183
|
declare const algorithms_matchPattern: typeof matchPattern;
|
|
207
184
|
declare namespace algorithms {
|
|
208
|
-
export {
|
|
209
|
-
algorithms_Algorithms as Algorithms,
|
|
210
|
-
algorithms_matchPattern as matchPattern,
|
|
211
|
-
};
|
|
185
|
+
export { type algorithms_Algorithms as Algorithms, algorithms_matchPattern as matchPattern };
|
|
212
186
|
}
|
|
213
187
|
|
|
214
188
|
declare class CipherState {
|
|
@@ -227,9 +201,7 @@ declare class CipherState {
|
|
|
227
201
|
type cipherstate_CipherState = CipherState;
|
|
228
202
|
declare const cipherstate_CipherState: typeof CipherState;
|
|
229
203
|
declare namespace cipherstate {
|
|
230
|
-
export {
|
|
231
|
-
cipherstate_CipherState as CipherState,
|
|
232
|
-
};
|
|
204
|
+
export { cipherstate_CipherState as CipherState };
|
|
233
205
|
}
|
|
234
206
|
|
|
235
207
|
type KeyTransferToken = 'e' | 's';
|
|
@@ -258,16 +230,7 @@ type patterns_Token = Token;
|
|
|
258
230
|
declare const patterns_isOneWay: typeof isOneWay;
|
|
259
231
|
declare const patterns_lookupPattern: typeof lookupPattern;
|
|
260
232
|
declare namespace patterns {
|
|
261
|
-
export {
|
|
262
|
-
patterns_HandshakePattern as HandshakePattern,
|
|
263
|
-
patterns_KeyMixToken as KeyMixToken,
|
|
264
|
-
patterns_KeyTransferToken as KeyTransferToken,
|
|
265
|
-
patterns_PATTERNS as PATTERNS,
|
|
266
|
-
patterns_PreMessage as PreMessage,
|
|
267
|
-
patterns_Token as Token,
|
|
268
|
-
patterns_isOneWay as isOneWay,
|
|
269
|
-
patterns_lookupPattern as lookupPattern,
|
|
270
|
-
};
|
|
233
|
+
export { type patterns_HandshakePattern as HandshakePattern, type patterns_KeyMixToken as KeyMixToken, type patterns_KeyTransferToken as KeyTransferToken, patterns_PATTERNS as PATTERNS, type patterns_PreMessage as PreMessage, type patterns_Token as Token, patterns_isOneWay as isOneWay, patterns_lookupPattern as lookupPattern };
|
|
271
234
|
}
|
|
272
235
|
|
|
273
236
|
type Role = 'initiator' | 'responder';
|
|
@@ -302,8 +265,8 @@ declare class Handshake {
|
|
|
302
265
|
mixHash(data: Uint8Array): void;
|
|
303
266
|
mixKey(input: Uint8Array): void;
|
|
304
267
|
mixKeyAndHashNextPSK(): void;
|
|
305
|
-
encryptAndHash(p: Uint8Array): Uint8Array
|
|
306
|
-
decryptAndHash(c: Uint8Array): Uint8Array
|
|
268
|
+
encryptAndHash(p: Uint8Array): Uint8Array<ArrayBufferLike>;
|
|
269
|
+
decryptAndHash(c: Uint8Array): Uint8Array<ArrayBufferLike>;
|
|
307
270
|
_split(): TransportState | null;
|
|
308
271
|
_nextStep(): Token[];
|
|
309
272
|
_processKeyMixToken(t: KeyMixToken): void;
|
|
@@ -324,21 +287,14 @@ type handshake_HandshakeOptions = HandshakeOptions;
|
|
|
324
287
|
type handshake_Role = Role;
|
|
325
288
|
type handshake_TransportState = TransportState;
|
|
326
289
|
declare namespace handshake {
|
|
327
|
-
export {
|
|
328
|
-
handshake_Handshake as Handshake,
|
|
329
|
-
handshake_HandshakeOptions as HandshakeOptions,
|
|
330
|
-
handshake_Role as Role,
|
|
331
|
-
handshake_TransportState as TransportState,
|
|
332
|
-
};
|
|
290
|
+
export { handshake_Handshake as Handshake, type handshake_HandshakeOptions as HandshakeOptions, type handshake_Role as Role, type handshake_TransportState as TransportState };
|
|
333
291
|
}
|
|
334
292
|
|
|
335
293
|
declare const Noise_25519_ChaChaPoly_BLAKE2s: Algorithms;
|
|
336
294
|
|
|
337
295
|
declare const profiles_Noise_25519_ChaChaPoly_BLAKE2s: typeof Noise_25519_ChaChaPoly_BLAKE2s;
|
|
338
296
|
declare namespace profiles {
|
|
339
|
-
export {
|
|
340
|
-
profiles_Noise_25519_ChaChaPoly_BLAKE2s as Noise_25519_ChaChaPoly_BLAKE2s,
|
|
341
|
-
};
|
|
297
|
+
export { profiles_Noise_25519_ChaChaPoly_BLAKE2s as Noise_25519_ChaChaPoly_BLAKE2s };
|
|
342
298
|
}
|
|
343
299
|
|
|
344
300
|
declare const _randomBytes: (out: Uint8Array, n: number) => void;
|
|
@@ -362,14 +318,7 @@ declare const x25519_crypto_scalarmult_base: typeof crypto_scalarmult_base;
|
|
|
362
318
|
declare const x25519_scalarMult: typeof scalarMult;
|
|
363
319
|
declare const x25519_scalarMultBase: typeof scalarMultBase;
|
|
364
320
|
declare namespace x25519 {
|
|
365
|
-
export {
|
|
366
|
-
x25519_crypto_scalarmult as crypto_scalarmult,
|
|
367
|
-
x25519_crypto_scalarmult_BYTES as crypto_scalarmult_BYTES,
|
|
368
|
-
x25519_crypto_scalarmult_SCALARBYTES as crypto_scalarmult_SCALARBYTES,
|
|
369
|
-
x25519_crypto_scalarmult_base as crypto_scalarmult_base,
|
|
370
|
-
x25519_scalarMult as scalarMult,
|
|
371
|
-
x25519_scalarMultBase as scalarMultBase,
|
|
372
|
-
};
|
|
321
|
+
export { x25519_crypto_scalarmult as crypto_scalarmult, x25519_crypto_scalarmult_BYTES as crypto_scalarmult_BYTES, x25519_crypto_scalarmult_SCALARBYTES as crypto_scalarmult_SCALARBYTES, x25519_crypto_scalarmult_base as crypto_scalarmult_base, x25519_scalarMult as scalarMult, x25519_scalarMultBase as scalarMultBase };
|
|
373
322
|
}
|
|
374
323
|
|
|
375
324
|
declare const INTERNALS: {
|
|
@@ -396,4 +345,4 @@ declare const INTERNALS: {
|
|
|
396
345
|
};
|
|
397
346
|
};
|
|
398
347
|
|
|
399
|
-
export { AEAD, Algorithms, AuthenticationFailure, BLAKE2s,
|
|
348
|
+
export { type AEAD, type Algorithms, AuthenticationFailure, BLAKE2s, bytes as Bytes, ChaCha20, ChaCha20Poly1305_RFC8439, CipherState, type DH, type DHKeyPair, type HKDF, type HMAC, Handshake, type HandshakeOptions, type HandshakePattern, type Hash, type HashAlgorithm, INTERNALS, io as IO, type KeyMixToken, type KeyTransferToken, Noise_25519_ChaChaPoly_BLAKE2s, Nonce, PATTERNS, Poly1305, type PreMessage, type Rekey, type Role, type StreamCipher, type Token, type TransportState, X25519, _decrypt, _encrypt, _randomBytes, isOneWay, lookupPattern, makeHKDF, makeHMAC, matchPattern, randomBytes };
|