@effected/github 0.32.1 → 0.34.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/ActionsOidc.js +31 -0
- package/ArtifactMetadata.js +1 -1
- package/Attestation.js +1 -1
- package/AuthenticatedApp.js +1 -1
- package/ChangelogInfo.js +1 -1
- package/CheckRun.js +1 -1
- package/CodeScanning.js +1 -1
- package/DeploymentEnvironment.js +1 -1
- package/GitBranch.js +1 -1
- package/GitCommit.js +1 -1
- package/GitHubApp.js +3 -3
- package/GitHubClient.js +1 -1
- package/GitHubCommit.js +1 -1
- package/GitHubContent.js +2 -2
- package/GitHubError.js +1 -1
- package/GitHubIssue.js +1 -1
- package/GitHubRelease.js +1 -1
- package/GitHubRepository.js +1 -1
- package/GitHubUserAuth.js +3 -3
- package/GitTag.js +2 -2
- package/GraphQL.js +1 -1
- package/InstallationTokenStore.js +1 -1
- package/PullRequest.js +1 -1
- package/PullRequestComment.js +1 -1
- package/RepositorySecret.js +4 -3
- package/RepositorySecurity.js +1 -1
- package/RepositoryVariable.js +1 -1
- package/Ruleset.js +1 -1
- package/WorkflowDispatch.js +1 -1
- package/index.d.ts +18 -0
- package/index.js +1 -1
- package/internal/blake2b.js +407 -0
- package/internal/crypto.js +41 -24
- package/internal/octokit.js +3 -3
- package/internal/x25519.js +248 -0
- package/internal/xsalsa20poly1305.js +432 -0
- package/package.json +2 -4
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
// src/internal/x25519.ts
|
|
2
|
+
/**
|
|
3
|
+
* X25519 (RFC 7748) scalar multiplication, vendored from `@noble/curves`,
|
|
4
|
+
* trimmed to the Montgomery ladder over curve25519 and the field helpers it
|
|
5
|
+
* needs.
|
|
6
|
+
*
|
|
7
|
+
* Upstream: https://github.com/paulmillr/noble-curves
|
|
8
|
+
* Version: 2.4.0, commit 656c4364dffa44c64aa0c49914b8000b278b67a9
|
|
9
|
+
* Files: `src/abstract/montgomery.ts` (`cmask`, `cswap`, `montgomeryLadder`,
|
|
10
|
+
* `decodeU`, `decodeScalar`, the low-order input check, `scalarMult`),
|
|
11
|
+
* `src/ed25519.ts` (`ed25519_pow_2_252_3`, `adjustScalarBytes`, the x25519
|
|
12
|
+
* `powPminus2`), `src/abstract/modular.ts` (`mod`, `pow2`), and the byte/number
|
|
13
|
+
* conversions from `src/utils.ts`. `@noble/curves` 1.0.0 was audited by Cure53
|
|
14
|
+
* in 2023.
|
|
15
|
+
*
|
|
16
|
+
* Changes from upstream: merged into one file; removed the `TArg`/`TRet` type
|
|
17
|
+
* helpers, `@example` blocks, X448, the generic `montgomery()` factory and its
|
|
18
|
+
* option validation, `keygen`/`randomSecretKey` (the caller draws secret keys
|
|
19
|
+
* from `globalThis.crypto.getRandomValues`), the Edwards-table fixed-base
|
|
20
|
+
* shortcut (the base point goes through the same ladder as any other point, which
|
|
21
|
+
* upstream does when no shortcut is supplied), and the `__TEST` hook. Byte and
|
|
22
|
+
* number conversions are inlined for fixed 32-byte little-endian values. The
|
|
23
|
+
* ladder, `cswap`/`cmask`, the `x^(p-2)` addition chain, scalar clamping and
|
|
24
|
+
* the low-order rejection are unchanged.
|
|
25
|
+
*
|
|
26
|
+
* The MIT License (MIT)
|
|
27
|
+
*
|
|
28
|
+
* Copyright (c) 2022 Paul Miller (https://paulmillr.com)
|
|
29
|
+
*
|
|
30
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
31
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
32
|
+
* in the Software without restriction, including without limitation the rights
|
|
33
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
34
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
35
|
+
* furnished to do so, subject to the following conditions:
|
|
36
|
+
*
|
|
37
|
+
* The above copyright notice and this permission notice shall be included in
|
|
38
|
+
* all copies or substantial portions of the Software.
|
|
39
|
+
*
|
|
40
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
41
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
42
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
43
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
44
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
45
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
46
|
+
* THE SOFTWARE.
|
|
47
|
+
*
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
50
|
+
const _0n = /* @__PURE__ */ BigInt(0);
|
|
51
|
+
const _1n = /* @__PURE__ */ BigInt(1);
|
|
52
|
+
const _2n = /* @__PURE__ */ BigInt(2);
|
|
53
|
+
const _3n = /* @__PURE__ */ BigInt(3);
|
|
54
|
+
const _5n = /* @__PURE__ */ BigInt(5);
|
|
55
|
+
const FIELD_BYTES = 32;
|
|
56
|
+
const P = /* @__PURE__ */ BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed");
|
|
57
|
+
const Gu = /* @__PURE__ */ BigInt(9);
|
|
58
|
+
const a24 = /* @__PURE__ */ BigInt(121665);
|
|
59
|
+
const minScalar = _2n ** BigInt(254);
|
|
60
|
+
const maxScalar = minScalar + BigInt(8) * (_2n ** BigInt(251) - _1n) + _1n;
|
|
61
|
+
const mod = (a, b) => {
|
|
62
|
+
const result = a % b;
|
|
63
|
+
return result >= _0n ? result : b + result;
|
|
64
|
+
};
|
|
65
|
+
function pow2(x, power, modulo) {
|
|
66
|
+
let res = x;
|
|
67
|
+
while (power-- > _0n) {
|
|
68
|
+
res *= res;
|
|
69
|
+
res %= modulo;
|
|
70
|
+
}
|
|
71
|
+
return res;
|
|
72
|
+
}
|
|
73
|
+
const modP = (n) => mod(n, P);
|
|
74
|
+
const bytesToNumberLE = (bytes) => {
|
|
75
|
+
let n = _0n;
|
|
76
|
+
for (let i = bytes.length - 1; i >= 0; i--) n = n << BigInt(8) | BigInt(bytes[i]);
|
|
77
|
+
return n;
|
|
78
|
+
};
|
|
79
|
+
const numberToBytesLE = (n, len) => {
|
|
80
|
+
const out = new Uint8Array(len);
|
|
81
|
+
let rest = n;
|
|
82
|
+
for (let i = 0; i < len; i++) {
|
|
83
|
+
out[i] = Number(rest & BigInt(255));
|
|
84
|
+
rest >>= BigInt(8);
|
|
85
|
+
}
|
|
86
|
+
return out;
|
|
87
|
+
};
|
|
88
|
+
function ed25519_pow_2_252_3(x) {
|
|
89
|
+
const _10n = BigInt(10), _20n = BigInt(20), _40n = BigInt(40), _80n = BigInt(80);
|
|
90
|
+
const b2 = x * x % P * x % P;
|
|
91
|
+
const b5 = pow2(pow2(b2, _2n, P) * b2 % P, _1n, P) * x % P;
|
|
92
|
+
const b10 = pow2(b5, _5n, P) * b5 % P;
|
|
93
|
+
const b20 = pow2(b10, _10n, P) * b10 % P;
|
|
94
|
+
const b40 = pow2(b20, _20n, P) * b20 % P;
|
|
95
|
+
const b80 = pow2(b40, _40n, P) * b40 % P;
|
|
96
|
+
return {
|
|
97
|
+
pow_p_5_8: pow2(pow2(pow2(pow2(b80, _80n, P) * b80 % P, _80n, P) * b80 % P, _10n, P) * b10 % P, _2n, P) * x % P,
|
|
98
|
+
b2
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function adjustScalarBytes(bytes) {
|
|
102
|
+
bytes[0] &= 248;
|
|
103
|
+
bytes[31] &= 127;
|
|
104
|
+
bytes[31] |= 64;
|
|
105
|
+
return bytes;
|
|
106
|
+
}
|
|
107
|
+
const powPminus2 = (x) => {
|
|
108
|
+
const { pow_p_5_8, b2 } = ed25519_pow_2_252_3(x);
|
|
109
|
+
return mod(pow2(pow_p_5_8, _3n, P) * b2, P);
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Selector for cswap(): `P` to keep, `P + 1` to swap, chosen by the low bit of `swap`.
|
|
113
|
+
* Higher bits are ignored, and `swap` is passed in whole rather than as a {0n, 1n} bit on
|
|
114
|
+
* purpose: `P + (swap & _1n)` would short-circuit the addition whenever the bit is clear, which
|
|
115
|
+
* is the very leak this construction avoids, one round-trip further down. Subtracting `swap`
|
|
116
|
+
* with its low bit cleared keeps every operand full-width instead.
|
|
117
|
+
* @param P - Field modulus.
|
|
118
|
+
* @param swap - Value whose low bit selects; ignored above that bit.
|
|
119
|
+
* @returns `P` when the low bit is clear, `P + 1` when it is set.
|
|
120
|
+
*/
|
|
121
|
+
function cmask(P, swap) {
|
|
122
|
+
return P + swap - (swap >> _1n << _1n);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Swap two field elements when `mask` is `P + 1`, keep them when it is `P`:
|
|
126
|
+
*
|
|
127
|
+
* d = 6P + x_3 - x_2
|
|
128
|
+
* x_2' = d * mask + x_2 (mod P) x_3' = (x_2 + x_3) - x_2'
|
|
129
|
+
*
|
|
130
|
+
* The extra `6P * mask` vanishes modulo P, so `mask === P` leaves x_2 and `mask === P + 1`
|
|
131
|
+
* leaves x_3. Without the offset, the reduction dividend changes sign with input order and crosses
|
|
132
|
+
* BigInt limb boundaries; those classes measured differently on the tested Node/V8 build. For
|
|
133
|
+
* canonical inputs, the deliberately left-associative `offset + x_3 - x_2` is between 5P and 7P,
|
|
134
|
+
* keeping the dividend positive and in one word-count band for both RFC fields and masks. Six is
|
|
135
|
+
* the smallest coefficient `c` for which the shared offset `cP` has that property.
|
|
136
|
+
*
|
|
137
|
+
* This reduced the tested sign/size timing ratios, but JavaScript BigInt has no constant-time
|
|
138
|
+
* contract and the contents of the multiply and remainder still vary. Valid ladder states can
|
|
139
|
+
* contain genuine zero coordinates; this construction does not mask those value-shape effects.
|
|
140
|
+
* Computing `x_3'` independently as `((6P + x_2 - x_3) * mask + x_3) % P` is more symmetric.
|
|
141
|
+
* On the tested Node/V8 build, it reduced the timing difference between keeping `(0, v)` and
|
|
142
|
+
* swapping `(v, 0)`—both return `(0, v)`—from about 10%/13% for X25519/X448 to about 3%.
|
|
143
|
+
* Successful calls cannot reach that zero-in-the-first-output case. For the case they can reach,
|
|
144
|
+
* swapping `(0, v)` and keeping `(v, 0)` both return `(v, 0)`; the difference instead grew from
|
|
145
|
+
* about 0.7%/1.1% to 2.7%/2.8%. The extra multiply/remainder also made public
|
|
146
|
+
* `getSharedSecret()` about 16% slower. The retained one-remainder form measured about 2.5%
|
|
147
|
+
* slower than the prior helper for public X25519 `getSharedSecret()` in the same environment.
|
|
148
|
+
* x_3' falls out of the sum, which a swap leaves invariant: no second multiply or reduction is
|
|
149
|
+
* needed. Bind `6P` once per field so production and the timing regression exercise the same
|
|
150
|
+
* configured helper without paying for the multiplication in every ladder round.
|
|
151
|
+
*
|
|
152
|
+
* The returned function is called twice per ladder round, so it validates nothing. Both elements
|
|
153
|
+
* MUST already be reduced mod P; unreduced input silently corrupts the kept-side output.
|
|
154
|
+
* @param P - Field modulus.
|
|
155
|
+
* @returns A field-bound swap function taking mask, x_2, and x_3.
|
|
156
|
+
*/
|
|
157
|
+
function cswap(P) {
|
|
158
|
+
const offset = BigInt(6) * P;
|
|
159
|
+
return (mask, x_2, x_3) => {
|
|
160
|
+
const sum = x_2 + x_3;
|
|
161
|
+
const a = ((offset + x_3 - x_2) * mask + x_2) % P;
|
|
162
|
+
return {
|
|
163
|
+
x_2: a,
|
|
164
|
+
x_3: sum - a
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
/** Internal helpers, exported for tests only. Not part of the public API. */
|
|
169
|
+
const lowOrderU = /* @__PURE__ */ new Set([
|
|
170
|
+
_0n,
|
|
171
|
+
_1n,
|
|
172
|
+
P - _1n,
|
|
173
|
+
BigInt("325606250916557431795983626356110631294008115727848805560023387167927233504"),
|
|
174
|
+
BigInt("39382357235489614581723060781553021112529911719440698176882885853963445705823")
|
|
175
|
+
]);
|
|
176
|
+
const swap = cswap(P);
|
|
177
|
+
function decodeU(u) {
|
|
178
|
+
const _u = Uint8Array.from(u);
|
|
179
|
+
_u[31] &= 127;
|
|
180
|
+
return modP(bytesToNumberLE(_u));
|
|
181
|
+
}
|
|
182
|
+
function decodeScalar(scalar) {
|
|
183
|
+
return bytesToNumberLE(adjustScalarBytes(Uint8Array.from(scalar)));
|
|
184
|
+
}
|
|
185
|
+
function inRange(title, n, min, max) {
|
|
186
|
+
if (!(min <= n && n < max)) throw new RangeError("expected valid " + title);
|
|
187
|
+
}
|
|
188
|
+
function montgomeryLadder(u, scalar) {
|
|
189
|
+
inRange("u", u, _0n, P);
|
|
190
|
+
inRange("scalar", scalar, minScalar, maxScalar);
|
|
191
|
+
const k = scalar;
|
|
192
|
+
const x_1 = u;
|
|
193
|
+
let x_2 = _1n;
|
|
194
|
+
let z_2 = _0n;
|
|
195
|
+
let x_3 = u;
|
|
196
|
+
let z_3 = _1n;
|
|
197
|
+
const kx = k ^ k >> _1n;
|
|
198
|
+
for (let t = BigInt(254); t >= _0n; t--) {
|
|
199
|
+
const mask = cmask(P, kx >> t);
|
|
200
|
+
({x_2, x_3} = swap(mask, x_2, x_3));
|
|
201
|
+
({x_2: z_2, x_3: z_3} = swap(mask, z_2, z_3));
|
|
202
|
+
const A = x_2 + z_2;
|
|
203
|
+
const AA = modP(A * A);
|
|
204
|
+
const B = x_2 - z_2;
|
|
205
|
+
const BB = modP(B * B);
|
|
206
|
+
const E = AA - BB;
|
|
207
|
+
const C = x_3 + z_3;
|
|
208
|
+
const D = x_3 - z_3;
|
|
209
|
+
const DA = modP(D * A);
|
|
210
|
+
const CB = modP(C * B);
|
|
211
|
+
const dacb = DA + CB;
|
|
212
|
+
const da_cb = DA - CB;
|
|
213
|
+
x_3 = modP(dacb * dacb);
|
|
214
|
+
z_3 = modP(x_1 * modP(da_cb * da_cb));
|
|
215
|
+
x_2 = modP(AA * BB);
|
|
216
|
+
z_2 = modP(E * (AA + modP(a24 * E)));
|
|
217
|
+
}
|
|
218
|
+
const mask = cmask(P, k);
|
|
219
|
+
({x_2, x_3} = swap(mask, x_2, x_3));
|
|
220
|
+
({x_2: z_2, x_3: z_3} = swap(mask, z_2, z_3));
|
|
221
|
+
const z2 = powPminus2(z_2);
|
|
222
|
+
return modP(x_2 * z2);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* X25519 scalar multiplication: the shared secret of `secretKey` and the peer's
|
|
226
|
+
* `u` coordinate, or a public key when `u` is the base point.
|
|
227
|
+
*
|
|
228
|
+
* @remarks
|
|
229
|
+
* Throws on a low-order `u`, which no honest peer produces: the check runs before
|
|
230
|
+
* the ladder so an attacker-chosen point never touches the secret scalar.
|
|
231
|
+
*
|
|
232
|
+
* @internal
|
|
233
|
+
*/
|
|
234
|
+
function x25519(secretKey, u) {
|
|
235
|
+
if (secretKey.length !== FIELD_BYTES) throw new RangeError(`x25519 scalar must be ${FIELD_BYTES} bytes`);
|
|
236
|
+
if (u.length !== FIELD_BYTES) throw new RangeError(`x25519 u coordinate must be ${FIELD_BYTES} bytes`);
|
|
237
|
+
const pointU = decodeU(u);
|
|
238
|
+
if (lowOrderU.has(pointU)) throw new Error("invalid private or public key received");
|
|
239
|
+
const pu = montgomeryLadder(pointU, decodeScalar(secretKey));
|
|
240
|
+
if (pu === _0n) throw new Error("invalid private or public key received");
|
|
241
|
+
return numberToBytesLE(modP(pu), FIELD_BYTES);
|
|
242
|
+
}
|
|
243
|
+
/** The base point's u-coordinate, encoded: `9` followed by 31 zero bytes. */
|
|
244
|
+
const BASE_POINT = /* @__PURE__ */ numberToBytesLE(Gu, FIELD_BYTES);
|
|
245
|
+
/** The X25519 public key for `secretKey`. */
|
|
246
|
+
const x25519PublicKey = (secretKey) => x25519(secretKey, BASE_POINT);
|
|
247
|
+
|
|
248
|
+
export { x25519, x25519PublicKey };
|
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
// src/internal/xsalsa20poly1305.ts
|
|
2
|
+
/**
|
|
3
|
+
* XSalsa20-Poly1305 (the NaCl / libsodium `secretbox`) and HSalsa20, vendored
|
|
4
|
+
* from `@noble/ciphers`, trimmed to the one-shot `crypto_box` building blocks a
|
|
5
|
+
* sealed box needs.
|
|
6
|
+
*
|
|
7
|
+
* Upstream: https://github.com/paulmillr/noble-ciphers
|
|
8
|
+
* Version: 2.4.0, commit d9e8a6a599e7ed729d9be03854c46a3c73bd9a79
|
|
9
|
+
* Files: `src/salsa.ts` (`salsaCore`, `hsalsa`, the `xsalsa20poly1305`
|
|
10
|
+
* construction), `src/_arx.ts` (`runCipher` and the sigma constant, the stream
|
|
11
|
+
* driver `createCipher` builds), `src/_poly1305.ts` (`Poly1305`). `@noble/ciphers`
|
|
12
|
+
* 1.0.0 was audited by Cure53 in 2024.
|
|
13
|
+
*
|
|
14
|
+
* Changes from upstream: merged into one file; removed the `TArg`/`TRet` type
|
|
15
|
+
* helpers, `@example` blocks, the plain `salsa20` and `secretbox` exports, the
|
|
16
|
+
* `createCipher` option machinery (short keys, counter layout options, PRGs) and
|
|
17
|
+
* the `wrapCipher` argument wrapper; the stream driver is specialised to
|
|
18
|
+
* XSalsa20 and works on explicit little-endian word loads and stores instead of
|
|
19
|
+
* `Uint32Array` views over the caller's buffers, which drops the host
|
|
20
|
+
* endianness, alignment and buffer-overlap handling; `Poly1305` is trimmed to a
|
|
21
|
+
* one-shot `poly1305(message, key)` and decrypt is not carried, since a sealed
|
|
22
|
+
* box is only ever written here. `salsaCore`, `hsalsa`, and the `Poly1305`
|
|
23
|
+
* `process` and `finalize` arithmetic are unchanged.
|
|
24
|
+
*
|
|
25
|
+
* The MIT License (MIT)
|
|
26
|
+
*
|
|
27
|
+
* Copyright (c) 2022 Paul Miller (https://paulmillr.com)
|
|
28
|
+
*
|
|
29
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
30
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
31
|
+
* in the Software without restriction, including without limitation the rights
|
|
32
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
33
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
34
|
+
* furnished to do so, subject to the following conditions:
|
|
35
|
+
*
|
|
36
|
+
* The above copyright notice and this permission notice shall be included in
|
|
37
|
+
* all copies or substantial portions of the Software.
|
|
38
|
+
*
|
|
39
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
40
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
41
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
42
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
43
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
44
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
45
|
+
* THE SOFTWARE.
|
|
46
|
+
*
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
/** XSalsa20 needs a 32-byte key and a 24-byte nonce; Poly1305 tags are 16 bytes. */
|
|
50
|
+
const KEY_BYTES = 32;
|
|
51
|
+
const NONCE_BYTES = 24;
|
|
52
|
+
const TAG_BYTES = 16;
|
|
53
|
+
const rotl = (a, b) => a << b | a >>> 32 - b;
|
|
54
|
+
/** Little-endian 32-bit load, independent of host endianness and alignment. */
|
|
55
|
+
const load32 = (bytes, offset) => bytes[offset] | bytes[offset + 1] << 8 | bytes[offset + 2] << 16 | bytes[offset + 3] << 24 | 0;
|
|
56
|
+
/** The words of `bytes`, read little-endian. */
|
|
57
|
+
const words = (bytes) => {
|
|
58
|
+
const out = new Uint32Array(bytes.length / 4);
|
|
59
|
+
for (let i = 0; i < out.length; i++) out[i] = load32(bytes, i * 4);
|
|
60
|
+
return out;
|
|
61
|
+
};
|
|
62
|
+
const sigma32_32 = /* @__PURE__ */ (() => words(Uint8Array.from("expand 32-byte k", (c) => c.charCodeAt(0))))();
|
|
63
|
+
/** Uses only the low 32 bits of Salsa20's 64-bit counter state. */
|
|
64
|
+
function salsaCore(s, k, n, out, cnt, rounds = 20, cntHi = 0) {
|
|
65
|
+
const y00 = s[0], y01 = k[0], y02 = k[1], y03 = k[2], y04 = k[3], y05 = s[1], y06 = n[0], y07 = n[1], y08 = cnt, y09 = cntHi, y10 = s[2], y11 = k[4], y12 = k[5], y13 = k[6], y14 = k[7], y15 = s[3];
|
|
66
|
+
let x00 = y00, x01 = y01, x02 = y02, x03 = y03, x04 = y04, x05 = y05, x06 = y06, x07 = y07, x08 = y08, x09 = y09, x10 = y10, x11 = y11, x12 = y12, x13 = y13, x14 = y14, x15 = y15;
|
|
67
|
+
for (let r = 0; r < rounds; r += 2) {
|
|
68
|
+
x04 ^= rotl(x00 + x12 | 0, 7);
|
|
69
|
+
x08 ^= rotl(x04 + x00 | 0, 9);
|
|
70
|
+
x12 ^= rotl(x08 + x04 | 0, 13);
|
|
71
|
+
x00 ^= rotl(x12 + x08 | 0, 18);
|
|
72
|
+
x09 ^= rotl(x05 + x01 | 0, 7);
|
|
73
|
+
x13 ^= rotl(x09 + x05 | 0, 9);
|
|
74
|
+
x01 ^= rotl(x13 + x09 | 0, 13);
|
|
75
|
+
x05 ^= rotl(x01 + x13 | 0, 18);
|
|
76
|
+
x14 ^= rotl(x10 + x06 | 0, 7);
|
|
77
|
+
x02 ^= rotl(x14 + x10 | 0, 9);
|
|
78
|
+
x06 ^= rotl(x02 + x14 | 0, 13);
|
|
79
|
+
x10 ^= rotl(x06 + x02 | 0, 18);
|
|
80
|
+
x03 ^= rotl(x15 + x11 | 0, 7);
|
|
81
|
+
x07 ^= rotl(x03 + x15 | 0, 9);
|
|
82
|
+
x11 ^= rotl(x07 + x03 | 0, 13);
|
|
83
|
+
x15 ^= rotl(x11 + x07 | 0, 18);
|
|
84
|
+
x01 ^= rotl(x00 + x03 | 0, 7);
|
|
85
|
+
x02 ^= rotl(x01 + x00 | 0, 9);
|
|
86
|
+
x03 ^= rotl(x02 + x01 | 0, 13);
|
|
87
|
+
x00 ^= rotl(x03 + x02 | 0, 18);
|
|
88
|
+
x06 ^= rotl(x05 + x04 | 0, 7);
|
|
89
|
+
x07 ^= rotl(x06 + x05 | 0, 9);
|
|
90
|
+
x04 ^= rotl(x07 + x06 | 0, 13);
|
|
91
|
+
x05 ^= rotl(x04 + x07 | 0, 18);
|
|
92
|
+
x11 ^= rotl(x10 + x09 | 0, 7);
|
|
93
|
+
x08 ^= rotl(x11 + x10 | 0, 9);
|
|
94
|
+
x09 ^= rotl(x08 + x11 | 0, 13);
|
|
95
|
+
x10 ^= rotl(x09 + x08 | 0, 18);
|
|
96
|
+
x12 ^= rotl(x15 + x14 | 0, 7);
|
|
97
|
+
x13 ^= rotl(x12 + x15 | 0, 9);
|
|
98
|
+
x14 ^= rotl(x13 + x12 | 0, 13);
|
|
99
|
+
x15 ^= rotl(x14 + x13 | 0, 18);
|
|
100
|
+
}
|
|
101
|
+
let oi = 0;
|
|
102
|
+
out[oi++] = y00 + x00 | 0;
|
|
103
|
+
out[oi++] = y01 + x01 | 0;
|
|
104
|
+
out[oi++] = y02 + x02 | 0;
|
|
105
|
+
out[oi++] = y03 + x03 | 0;
|
|
106
|
+
out[oi++] = y04 + x04 | 0;
|
|
107
|
+
out[oi++] = y05 + x05 | 0;
|
|
108
|
+
out[oi++] = y06 + x06 | 0;
|
|
109
|
+
out[oi++] = y07 + x07 | 0;
|
|
110
|
+
out[oi++] = y08 + x08 | 0;
|
|
111
|
+
out[oi++] = y09 + x09 | 0;
|
|
112
|
+
out[oi++] = y10 + x10 | 0;
|
|
113
|
+
out[oi++] = y11 + x11 | 0;
|
|
114
|
+
out[oi++] = y12 + x12 | 0;
|
|
115
|
+
out[oi++] = y13 + x13 | 0;
|
|
116
|
+
out[oi++] = y14 + x14 | 0;
|
|
117
|
+
out[oi++] = y15 + x15 | 0;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* HSalsa20: hashes key and nonce-prefix words into the 32-byte subkey used by
|
|
121
|
+
* XSalsa20 and by `crypto_box`'s shared-key derivation.
|
|
122
|
+
*/
|
|
123
|
+
function hsalsa(s, k, i, out) {
|
|
124
|
+
const t = /* @__PURE__ */ new Uint32Array(16);
|
|
125
|
+
salsaCore(s, k, i.subarray(0, 2), t, i[2], 20, i[3]);
|
|
126
|
+
let oi = 0;
|
|
127
|
+
out[oi++] = t[0] - s[0] | 0;
|
|
128
|
+
out[oi++] = t[5] - s[1] | 0;
|
|
129
|
+
out[oi++] = t[10] - s[2] | 0;
|
|
130
|
+
out[oi++] = t[15] - s[3] | 0;
|
|
131
|
+
out[oi++] = t[6] - i[0] | 0;
|
|
132
|
+
out[oi++] = t[7] - i[1] | 0;
|
|
133
|
+
out[oi++] = t[8] - i[2] | 0;
|
|
134
|
+
out[oi++] = t[9] - i[3] | 0;
|
|
135
|
+
t.fill(0);
|
|
136
|
+
}
|
|
137
|
+
/** `crypto_box_beforenm`'s second step: HSalsa20 of a shared secret with a zero nonce prefix. */
|
|
138
|
+
const hsalsaKey = (sharedSecret) => {
|
|
139
|
+
const out = /* @__PURE__ */ new Uint32Array(8);
|
|
140
|
+
hsalsa(sigma32_32, words(sharedSecret), /* @__PURE__ */ new Uint32Array(4), out);
|
|
141
|
+
const bytes = new Uint8Array(KEY_BYTES);
|
|
142
|
+
storeWords(out, bytes);
|
|
143
|
+
return bytes;
|
|
144
|
+
};
|
|
145
|
+
/** Little-endian store of `source` words into `target` bytes. */
|
|
146
|
+
const storeWords = (source, target) => {
|
|
147
|
+
for (let i = 0; i < source.length; i++) {
|
|
148
|
+
const w = source[i];
|
|
149
|
+
target[i * 4] = w;
|
|
150
|
+
target[i * 4 + 1] = w >>> 8;
|
|
151
|
+
target[i * 4 + 2] = w >>> 16;
|
|
152
|
+
target[i * 4 + 3] = w >>> 24;
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* XSalsa20 keystream XORed over `data` in place, starting at block 0. The first
|
|
157
|
+
* 16 nonce bytes derive a subkey through HSalsa20; the last 8 are the Salsa20
|
|
158
|
+
* nonce.
|
|
159
|
+
*/
|
|
160
|
+
function xsalsa20(key, nonce, data) {
|
|
161
|
+
const k32 = words(key);
|
|
162
|
+
hsalsa(sigma32_32, k32, words(nonce.subarray(0, 16)), k32);
|
|
163
|
+
const n32 = /* @__PURE__ */ new Uint32Array(3);
|
|
164
|
+
n32.set(words(nonce.subarray(16, 24)));
|
|
165
|
+
const block = /* @__PURE__ */ new Uint8Array(64);
|
|
166
|
+
const b32 = /* @__PURE__ */ new Uint32Array(16);
|
|
167
|
+
for (let pos = 0, counter = 0; pos < data.length; counter++) {
|
|
168
|
+
salsaCore(sigma32_32, k32, n32, b32, counter);
|
|
169
|
+
storeWords(b32, block);
|
|
170
|
+
const take = Math.min(64, data.length - pos);
|
|
171
|
+
for (let j = 0; j < take; j++) data[pos + j] ^= block[j];
|
|
172
|
+
pos += take;
|
|
173
|
+
}
|
|
174
|
+
k32.fill(0);
|
|
175
|
+
block.fill(0);
|
|
176
|
+
b32.fill(0);
|
|
177
|
+
}
|
|
178
|
+
function u8to16(a, i) {
|
|
179
|
+
return a[i++] & 255 | (a[i++] & 255) << 8;
|
|
180
|
+
}
|
|
181
|
+
/** Incremental Poly1305 MAC state; `poly1305` below is its one-shot use. */
|
|
182
|
+
var Poly1305 = class {
|
|
183
|
+
blockLen = 16;
|
|
184
|
+
outputLen = 16;
|
|
185
|
+
buffer = /* @__PURE__ */ new Uint8Array(16);
|
|
186
|
+
r = /* @__PURE__ */ new Uint16Array(10);
|
|
187
|
+
h = /* @__PURE__ */ new Uint16Array(10);
|
|
188
|
+
pad = /* @__PURE__ */ new Uint16Array(8);
|
|
189
|
+
pos = 0;
|
|
190
|
+
constructor(key) {
|
|
191
|
+
const t0 = u8to16(key, 0);
|
|
192
|
+
const t1 = u8to16(key, 2);
|
|
193
|
+
const t2 = u8to16(key, 4);
|
|
194
|
+
const t3 = u8to16(key, 6);
|
|
195
|
+
const t4 = u8to16(key, 8);
|
|
196
|
+
const t5 = u8to16(key, 10);
|
|
197
|
+
const t6 = u8to16(key, 12);
|
|
198
|
+
const t7 = u8to16(key, 14);
|
|
199
|
+
this.r[0] = t0 & 8191;
|
|
200
|
+
this.r[1] = (t0 >>> 13 | t1 << 3) & 8191;
|
|
201
|
+
this.r[2] = (t1 >>> 10 | t2 << 6) & 7939;
|
|
202
|
+
this.r[3] = (t2 >>> 7 | t3 << 9) & 8191;
|
|
203
|
+
this.r[4] = (t3 >>> 4 | t4 << 12) & 255;
|
|
204
|
+
this.r[5] = t4 >>> 1 & 8190;
|
|
205
|
+
this.r[6] = (t4 >>> 14 | t5 << 2) & 8191;
|
|
206
|
+
this.r[7] = (t5 >>> 11 | t6 << 5) & 8065;
|
|
207
|
+
this.r[8] = (t6 >>> 8 | t7 << 8) & 8191;
|
|
208
|
+
this.r[9] = t7 >>> 5 & 127;
|
|
209
|
+
for (let i = 0; i < 8; i++) this.pad[i] = u8to16(key, 16 + 2 * i);
|
|
210
|
+
}
|
|
211
|
+
process(data, offset, isLast = false) {
|
|
212
|
+
const hibit = isLast ? 0 : 2048;
|
|
213
|
+
const { h, r } = this;
|
|
214
|
+
const r0 = r[0];
|
|
215
|
+
const r1 = r[1];
|
|
216
|
+
const r2 = r[2];
|
|
217
|
+
const r3 = r[3];
|
|
218
|
+
const r4 = r[4];
|
|
219
|
+
const r5 = r[5];
|
|
220
|
+
const r6 = r[6];
|
|
221
|
+
const r7 = r[7];
|
|
222
|
+
const r8 = r[8];
|
|
223
|
+
const r9 = r[9];
|
|
224
|
+
const t0 = u8to16(data, offset + 0);
|
|
225
|
+
const t1 = u8to16(data, offset + 2);
|
|
226
|
+
const t2 = u8to16(data, offset + 4);
|
|
227
|
+
const t3 = u8to16(data, offset + 6);
|
|
228
|
+
const t4 = u8to16(data, offset + 8);
|
|
229
|
+
const t5 = u8to16(data, offset + 10);
|
|
230
|
+
const t6 = u8to16(data, offset + 12);
|
|
231
|
+
const t7 = u8to16(data, offset + 14);
|
|
232
|
+
const h0 = h[0] + (t0 & 8191);
|
|
233
|
+
const h1 = h[1] + ((t0 >>> 13 | t1 << 3) & 8191);
|
|
234
|
+
const h2 = h[2] + ((t1 >>> 10 | t2 << 6) & 8191);
|
|
235
|
+
const h3 = h[3] + ((t2 >>> 7 | t3 << 9) & 8191);
|
|
236
|
+
const h4 = h[4] + ((t3 >>> 4 | t4 << 12) & 8191);
|
|
237
|
+
const h5 = h[5] + (t4 >>> 1 & 8191);
|
|
238
|
+
const h6 = h[6] + ((t4 >>> 14 | t5 << 2) & 8191);
|
|
239
|
+
const h7 = h[7] + ((t5 >>> 11 | t6 << 5) & 8191);
|
|
240
|
+
const h8 = h[8] + ((t6 >>> 8 | t7 << 8) & 8191);
|
|
241
|
+
const h9 = h[9] + (t7 >>> 5 | hibit);
|
|
242
|
+
let c = 0;
|
|
243
|
+
let d0 = c + h0 * r0 + h1 * (5 * r9) + h2 * (5 * r8) + h3 * (5 * r7) + h4 * (5 * r6);
|
|
244
|
+
c = d0 >>> 13;
|
|
245
|
+
d0 &= 8191;
|
|
246
|
+
d0 += h5 * (5 * r5) + h6 * (5 * r4) + h7 * (5 * r3) + h8 * (5 * r2) + h9 * (5 * r1);
|
|
247
|
+
c += d0 >>> 13;
|
|
248
|
+
d0 &= 8191;
|
|
249
|
+
let d1 = c + h0 * r1 + h1 * r0 + h2 * (5 * r9) + h3 * (5 * r8) + h4 * (5 * r7);
|
|
250
|
+
c = d1 >>> 13;
|
|
251
|
+
d1 &= 8191;
|
|
252
|
+
d1 += h5 * (5 * r6) + h6 * (5 * r5) + h7 * (5 * r4) + h8 * (5 * r3) + h9 * (5 * r2);
|
|
253
|
+
c += d1 >>> 13;
|
|
254
|
+
d1 &= 8191;
|
|
255
|
+
let d2 = c + h0 * r2 + h1 * r1 + h2 * r0 + h3 * (5 * r9) + h4 * (5 * r8);
|
|
256
|
+
c = d2 >>> 13;
|
|
257
|
+
d2 &= 8191;
|
|
258
|
+
d2 += h5 * (5 * r7) + h6 * (5 * r6) + h7 * (5 * r5) + h8 * (5 * r4) + h9 * (5 * r3);
|
|
259
|
+
c += d2 >>> 13;
|
|
260
|
+
d2 &= 8191;
|
|
261
|
+
let d3 = c + h0 * r3 + h1 * r2 + h2 * r1 + h3 * r0 + h4 * (5 * r9);
|
|
262
|
+
c = d3 >>> 13;
|
|
263
|
+
d3 &= 8191;
|
|
264
|
+
d3 += h5 * (5 * r8) + h6 * (5 * r7) + h7 * (5 * r6) + h8 * (5 * r5) + h9 * (5 * r4);
|
|
265
|
+
c += d3 >>> 13;
|
|
266
|
+
d3 &= 8191;
|
|
267
|
+
let d4 = c + h0 * r4 + h1 * r3 + h2 * r2 + h3 * r1 + h4 * r0;
|
|
268
|
+
c = d4 >>> 13;
|
|
269
|
+
d4 &= 8191;
|
|
270
|
+
d4 += h5 * (5 * r9) + h6 * (5 * r8) + h7 * (5 * r7) + h8 * (5 * r6) + h9 * (5 * r5);
|
|
271
|
+
c += d4 >>> 13;
|
|
272
|
+
d4 &= 8191;
|
|
273
|
+
let d5 = c + h0 * r5 + h1 * r4 + h2 * r3 + h3 * r2 + h4 * r1;
|
|
274
|
+
c = d5 >>> 13;
|
|
275
|
+
d5 &= 8191;
|
|
276
|
+
d5 += h5 * r0 + h6 * (5 * r9) + h7 * (5 * r8) + h8 * (5 * r7) + h9 * (5 * r6);
|
|
277
|
+
c += d5 >>> 13;
|
|
278
|
+
d5 &= 8191;
|
|
279
|
+
let d6 = c + h0 * r6 + h1 * r5 + h2 * r4 + h3 * r3 + h4 * r2;
|
|
280
|
+
c = d6 >>> 13;
|
|
281
|
+
d6 &= 8191;
|
|
282
|
+
d6 += h5 * r1 + h6 * r0 + h7 * (5 * r9) + h8 * (5 * r8) + h9 * (5 * r7);
|
|
283
|
+
c += d6 >>> 13;
|
|
284
|
+
d6 &= 8191;
|
|
285
|
+
let d7 = c + h0 * r7 + h1 * r6 + h2 * r5 + h3 * r4 + h4 * r3;
|
|
286
|
+
c = d7 >>> 13;
|
|
287
|
+
d7 &= 8191;
|
|
288
|
+
d7 += h5 * r2 + h6 * r1 + h7 * r0 + h8 * (5 * r9) + h9 * (5 * r8);
|
|
289
|
+
c += d7 >>> 13;
|
|
290
|
+
d7 &= 8191;
|
|
291
|
+
let d8 = c + h0 * r8 + h1 * r7 + h2 * r6 + h3 * r5 + h4 * r4;
|
|
292
|
+
c = d8 >>> 13;
|
|
293
|
+
d8 &= 8191;
|
|
294
|
+
d8 += h5 * r3 + h6 * r2 + h7 * r1 + h8 * r0 + h9 * (5 * r9);
|
|
295
|
+
c += d8 >>> 13;
|
|
296
|
+
d8 &= 8191;
|
|
297
|
+
let d9 = c + h0 * r9 + h1 * r8 + h2 * r7 + h3 * r6 + h4 * r5;
|
|
298
|
+
c = d9 >>> 13;
|
|
299
|
+
d9 &= 8191;
|
|
300
|
+
d9 += h5 * r4 + h6 * r3 + h7 * r2 + h8 * r1 + h9 * r0;
|
|
301
|
+
c += d9 >>> 13;
|
|
302
|
+
d9 &= 8191;
|
|
303
|
+
c = (c << 2) + c | 0;
|
|
304
|
+
c = c + d0 | 0;
|
|
305
|
+
d0 = c & 8191;
|
|
306
|
+
c = c >>> 13;
|
|
307
|
+
d1 += c;
|
|
308
|
+
h[0] = d0;
|
|
309
|
+
h[1] = d1;
|
|
310
|
+
h[2] = d2;
|
|
311
|
+
h[3] = d3;
|
|
312
|
+
h[4] = d4;
|
|
313
|
+
h[5] = d5;
|
|
314
|
+
h[6] = d6;
|
|
315
|
+
h[7] = d7;
|
|
316
|
+
h[8] = d8;
|
|
317
|
+
h[9] = d9;
|
|
318
|
+
}
|
|
319
|
+
finalize() {
|
|
320
|
+
const { h, pad } = this;
|
|
321
|
+
const g = /* @__PURE__ */ new Uint16Array(10);
|
|
322
|
+
let c = h[1] >>> 13;
|
|
323
|
+
h[1] &= 8191;
|
|
324
|
+
for (let i = 2; i < 10; i++) {
|
|
325
|
+
h[i] += c;
|
|
326
|
+
c = h[i] >>> 13;
|
|
327
|
+
h[i] &= 8191;
|
|
328
|
+
}
|
|
329
|
+
h[0] += c * 5;
|
|
330
|
+
c = h[0] >>> 13;
|
|
331
|
+
h[0] &= 8191;
|
|
332
|
+
h[1] += c;
|
|
333
|
+
c = h[1] >>> 13;
|
|
334
|
+
h[1] &= 8191;
|
|
335
|
+
h[2] += c;
|
|
336
|
+
g[0] = h[0] + 5;
|
|
337
|
+
c = g[0] >>> 13;
|
|
338
|
+
g[0] &= 8191;
|
|
339
|
+
for (let i = 1; i < 10; i++) {
|
|
340
|
+
g[i] = h[i] + c;
|
|
341
|
+
c = g[i] >>> 13;
|
|
342
|
+
g[i] &= 8191;
|
|
343
|
+
}
|
|
344
|
+
g[9] -= 8192;
|
|
345
|
+
let mask = (c ^ 1) - 1;
|
|
346
|
+
for (let i = 0; i < 10; i++) g[i] &= mask;
|
|
347
|
+
mask = ~mask;
|
|
348
|
+
for (let i = 0; i < 10; i++) h[i] = h[i] & mask | g[i];
|
|
349
|
+
h[0] = (h[0] | h[1] << 13) & 65535;
|
|
350
|
+
h[1] = (h[1] >>> 3 | h[2] << 10) & 65535;
|
|
351
|
+
h[2] = (h[2] >>> 6 | h[3] << 7) & 65535;
|
|
352
|
+
h[3] = (h[3] >>> 9 | h[4] << 4) & 65535;
|
|
353
|
+
h[4] = (h[4] >>> 12 | h[5] << 1 | h[6] << 14) & 65535;
|
|
354
|
+
h[5] = (h[6] >>> 2 | h[7] << 11) & 65535;
|
|
355
|
+
h[6] = (h[7] >>> 5 | h[8] << 8) & 65535;
|
|
356
|
+
h[7] = (h[8] >>> 8 | h[9] << 5) & 65535;
|
|
357
|
+
let f = h[0] + pad[0];
|
|
358
|
+
h[0] = f & 65535;
|
|
359
|
+
for (let i = 1; i < 8; i++) {
|
|
360
|
+
f = (h[i] + pad[i] | 0) + (f >>> 16) | 0;
|
|
361
|
+
h[i] = f & 65535;
|
|
362
|
+
}
|
|
363
|
+
g.fill(0);
|
|
364
|
+
}
|
|
365
|
+
update(data) {
|
|
366
|
+
const { buffer, blockLen } = this;
|
|
367
|
+
const len = data.length;
|
|
368
|
+
for (let pos = 0; pos < len;) {
|
|
369
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
370
|
+
if (take === blockLen) {
|
|
371
|
+
for (; blockLen <= len - pos; pos += blockLen) this.process(data, pos);
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
375
|
+
this.pos += take;
|
|
376
|
+
pos += take;
|
|
377
|
+
if (this.pos === blockLen) {
|
|
378
|
+
this.process(buffer, 0, false);
|
|
379
|
+
this.pos = 0;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
return this;
|
|
383
|
+
}
|
|
384
|
+
digest() {
|
|
385
|
+
const { buffer, h } = this;
|
|
386
|
+
let { pos } = this;
|
|
387
|
+
if (pos) {
|
|
388
|
+
buffer[pos++] = 1;
|
|
389
|
+
for (; pos < 16; pos++) buffer[pos] = 0;
|
|
390
|
+
this.process(buffer, 0, true);
|
|
391
|
+
}
|
|
392
|
+
this.finalize();
|
|
393
|
+
const res = new Uint8Array(this.outputLen);
|
|
394
|
+
let opos = 0;
|
|
395
|
+
for (let i = 0; i < 8; i++) {
|
|
396
|
+
res[opos++] = h[i] >>> 0;
|
|
397
|
+
res[opos++] = h[i] >>> 8;
|
|
398
|
+
}
|
|
399
|
+
this.r.fill(0);
|
|
400
|
+
this.h.fill(0);
|
|
401
|
+
this.pad.fill(0);
|
|
402
|
+
buffer.fill(0);
|
|
403
|
+
return res;
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
/** Poly1305 MAC (RFC 8439 §2.5) of `message` under a 32-byte one-time `key`. */
|
|
407
|
+
const poly1305 = (message, key) => new Poly1305(key).update(message).digest();
|
|
408
|
+
/**
|
|
409
|
+
* Encrypt and authenticate `plaintext` with XSalsa20-Poly1305 (libsodium's
|
|
410
|
+
* `crypto_secretbox_easy`): returns `tag (16 bytes) || ciphertext`.
|
|
411
|
+
*
|
|
412
|
+
* @param plaintext - The message.
|
|
413
|
+
* @param nonce - 24 bytes.
|
|
414
|
+
* @param key - 32 bytes.
|
|
415
|
+
*
|
|
416
|
+
* @internal
|
|
417
|
+
*/
|
|
418
|
+
function secretbox(plaintext, nonce, key) {
|
|
419
|
+
if (key.length !== KEY_BYTES) throw new RangeError(`secretbox key must be ${KEY_BYTES} bytes, got ${key.length}`);
|
|
420
|
+
if (nonce.length !== NONCE_BYTES) throw new RangeError(`secretbox nonce must be ${NONCE_BYTES} bytes, got ${nonce.length}`);
|
|
421
|
+
const work = new Uint8Array(KEY_BYTES + plaintext.length);
|
|
422
|
+
work.set(plaintext, KEY_BYTES);
|
|
423
|
+
xsalsa20(key, nonce, work);
|
|
424
|
+
const tag = poly1305(work.subarray(KEY_BYTES), work.subarray(0, KEY_BYTES));
|
|
425
|
+
const sealed = new Uint8Array(TAG_BYTES + plaintext.length);
|
|
426
|
+
sealed.set(tag);
|
|
427
|
+
sealed.set(work.subarray(KEY_BYTES), TAG_BYTES);
|
|
428
|
+
work.fill(0);
|
|
429
|
+
return sealed;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
export { hsalsa, hsalsaKey, secretbox };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effected/github",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.34.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Typed GitHub REST and GraphQL services over the octokit core request surface, with app auth and resource helpers.",
|
|
6
6
|
"keywords": [
|
|
@@ -45,9 +45,7 @@
|
|
|
45
45
|
"@effected/semver": "^0.24.0",
|
|
46
46
|
"@octokit/core": "^7.0.6",
|
|
47
47
|
"@octokit/plugin-paginate-rest": "^16.0.0",
|
|
48
|
-
"@octokit/types": "^18.0.0"
|
|
49
|
-
"blakejs": "1.2.1",
|
|
50
|
-
"tweetnacl": "1.0.3"
|
|
48
|
+
"@octokit/types": "^18.0.0"
|
|
51
49
|
},
|
|
52
50
|
"peerDependencies": {
|
|
53
51
|
"effect": "~4.1.0"
|