@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,407 @@
|
|
|
1
|
+
// src/internal/blake2b.ts
|
|
2
|
+
/**
|
|
3
|
+
* BLAKE2b (RFC 7693) with a variable output length, vendored from
|
|
4
|
+
* `@noble/hashes`, trimmed to an unkeyed one-shot `blake2b(message, outLen)`.
|
|
5
|
+
*
|
|
6
|
+
* Upstream: https://github.com/paulmillr/noble-hashes
|
|
7
|
+
* Version: 2.4.0, commit 663c2aeeffc308ac0cded59bd32f7c212adacfc2
|
|
8
|
+
* Files: `src/blake2.ts` (`G1b`, `G2b`, the compression round loop, the
|
|
9
|
+
* `_BLAKE2b` initialisation and digest layout), `src/_blake.ts` (`BSIGMA`),
|
|
10
|
+
* and the 64-bit helpers they use from `src/_ts`. `@noble/hashes` 1.0.0 was
|
|
11
|
+
* audited by Cure53 in 2022.
|
|
12
|
+
*
|
|
13
|
+
* Changes from upstream: merged into one file; removed the `TArg`/`TRet` type
|
|
14
|
+
* helpers, `@example` blocks, BLAKE2s, keyed, salted and personalised modes, and
|
|
15
|
+
* the incremental `update`/`digest`/`clone` class with its `Uint32Array` views
|
|
16
|
+
* over caller buffers, which the one-shot function replaces; message words are
|
|
17
|
+
* read with explicit little-endian loads, which drops the host-endianness and
|
|
18
|
+
* alignment handling; the `BSIGMA` table keeps only the twelve rows BLAKE2b
|
|
19
|
+
* uses. `G1b`, `G2b`, the u64 helpers, the IV and the compression function are
|
|
20
|
+
* unchanged.
|
|
21
|
+
*
|
|
22
|
+
* The MIT License (MIT)
|
|
23
|
+
*
|
|
24
|
+
* Copyright (c) 2022 Paul Miller (https://paulmillr.com)
|
|
25
|
+
*
|
|
26
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
27
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
28
|
+
* in the Software without restriction, including without limitation the rights
|
|
29
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
30
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
31
|
+
* furnished to do so, subject to the following conditions:
|
|
32
|
+
*
|
|
33
|
+
* The above copyright notice and this permission notice shall be included in
|
|
34
|
+
* all copies or substantial portions of the Software.
|
|
35
|
+
*
|
|
36
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
37
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
38
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
39
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
40
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
41
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
42
|
+
* THE SOFTWARE.
|
|
43
|
+
*
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
const BLOCK_BYTES = 128;
|
|
47
|
+
const MAX_OUT_BYTES = 64;
|
|
48
|
+
const rotrSH = (h, l, s) => h >>> s | l << 32 - s;
|
|
49
|
+
const rotrSL = (h, l, s) => h << 32 - s | l >>> s;
|
|
50
|
+
const rotrBH = (h, l, s) => h << 64 - s | l >>> s - 32;
|
|
51
|
+
const rotrBL = (h, l, s) => h >>> s - 32 | l << 64 - s;
|
|
52
|
+
const rotr32H = (_h, l) => l;
|
|
53
|
+
const rotr32L = (h, _l) => h;
|
|
54
|
+
function add(Ah, Al, Bh, Bl) {
|
|
55
|
+
const l = (Al >>> 0) + (Bl >>> 0);
|
|
56
|
+
return {
|
|
57
|
+
h: Ah + Bh + (l / 2 ** 32 | 0) | 0,
|
|
58
|
+
l: l | 0
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
const add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
|
|
62
|
+
const add3H = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
|
|
63
|
+
const fromNumH = (n) => n / 2 ** 32 | 0;
|
|
64
|
+
const fromNumL = (n) => n >>> 0;
|
|
65
|
+
const BSIGMA = /* @__PURE__ */ Uint8Array.from([
|
|
66
|
+
0,
|
|
67
|
+
1,
|
|
68
|
+
2,
|
|
69
|
+
3,
|
|
70
|
+
4,
|
|
71
|
+
5,
|
|
72
|
+
6,
|
|
73
|
+
7,
|
|
74
|
+
8,
|
|
75
|
+
9,
|
|
76
|
+
10,
|
|
77
|
+
11,
|
|
78
|
+
12,
|
|
79
|
+
13,
|
|
80
|
+
14,
|
|
81
|
+
15,
|
|
82
|
+
14,
|
|
83
|
+
10,
|
|
84
|
+
4,
|
|
85
|
+
8,
|
|
86
|
+
9,
|
|
87
|
+
15,
|
|
88
|
+
13,
|
|
89
|
+
6,
|
|
90
|
+
1,
|
|
91
|
+
12,
|
|
92
|
+
0,
|
|
93
|
+
2,
|
|
94
|
+
11,
|
|
95
|
+
7,
|
|
96
|
+
5,
|
|
97
|
+
3,
|
|
98
|
+
11,
|
|
99
|
+
8,
|
|
100
|
+
12,
|
|
101
|
+
0,
|
|
102
|
+
5,
|
|
103
|
+
2,
|
|
104
|
+
15,
|
|
105
|
+
13,
|
|
106
|
+
10,
|
|
107
|
+
14,
|
|
108
|
+
3,
|
|
109
|
+
6,
|
|
110
|
+
7,
|
|
111
|
+
1,
|
|
112
|
+
9,
|
|
113
|
+
4,
|
|
114
|
+
7,
|
|
115
|
+
9,
|
|
116
|
+
3,
|
|
117
|
+
1,
|
|
118
|
+
13,
|
|
119
|
+
12,
|
|
120
|
+
11,
|
|
121
|
+
14,
|
|
122
|
+
2,
|
|
123
|
+
6,
|
|
124
|
+
5,
|
|
125
|
+
10,
|
|
126
|
+
4,
|
|
127
|
+
0,
|
|
128
|
+
15,
|
|
129
|
+
8,
|
|
130
|
+
9,
|
|
131
|
+
0,
|
|
132
|
+
5,
|
|
133
|
+
7,
|
|
134
|
+
2,
|
|
135
|
+
4,
|
|
136
|
+
10,
|
|
137
|
+
15,
|
|
138
|
+
14,
|
|
139
|
+
1,
|
|
140
|
+
11,
|
|
141
|
+
12,
|
|
142
|
+
6,
|
|
143
|
+
8,
|
|
144
|
+
3,
|
|
145
|
+
13,
|
|
146
|
+
2,
|
|
147
|
+
12,
|
|
148
|
+
6,
|
|
149
|
+
10,
|
|
150
|
+
0,
|
|
151
|
+
11,
|
|
152
|
+
8,
|
|
153
|
+
3,
|
|
154
|
+
4,
|
|
155
|
+
13,
|
|
156
|
+
7,
|
|
157
|
+
5,
|
|
158
|
+
15,
|
|
159
|
+
14,
|
|
160
|
+
1,
|
|
161
|
+
9,
|
|
162
|
+
12,
|
|
163
|
+
5,
|
|
164
|
+
1,
|
|
165
|
+
15,
|
|
166
|
+
14,
|
|
167
|
+
13,
|
|
168
|
+
4,
|
|
169
|
+
10,
|
|
170
|
+
0,
|
|
171
|
+
7,
|
|
172
|
+
6,
|
|
173
|
+
3,
|
|
174
|
+
9,
|
|
175
|
+
2,
|
|
176
|
+
8,
|
|
177
|
+
11,
|
|
178
|
+
13,
|
|
179
|
+
11,
|
|
180
|
+
7,
|
|
181
|
+
14,
|
|
182
|
+
12,
|
|
183
|
+
1,
|
|
184
|
+
3,
|
|
185
|
+
9,
|
|
186
|
+
5,
|
|
187
|
+
0,
|
|
188
|
+
15,
|
|
189
|
+
4,
|
|
190
|
+
8,
|
|
191
|
+
6,
|
|
192
|
+
2,
|
|
193
|
+
10,
|
|
194
|
+
6,
|
|
195
|
+
15,
|
|
196
|
+
14,
|
|
197
|
+
9,
|
|
198
|
+
11,
|
|
199
|
+
3,
|
|
200
|
+
0,
|
|
201
|
+
8,
|
|
202
|
+
12,
|
|
203
|
+
2,
|
|
204
|
+
13,
|
|
205
|
+
7,
|
|
206
|
+
1,
|
|
207
|
+
4,
|
|
208
|
+
10,
|
|
209
|
+
5,
|
|
210
|
+
10,
|
|
211
|
+
2,
|
|
212
|
+
8,
|
|
213
|
+
4,
|
|
214
|
+
7,
|
|
215
|
+
6,
|
|
216
|
+
1,
|
|
217
|
+
5,
|
|
218
|
+
15,
|
|
219
|
+
11,
|
|
220
|
+
9,
|
|
221
|
+
14,
|
|
222
|
+
3,
|
|
223
|
+
12,
|
|
224
|
+
13,
|
|
225
|
+
0,
|
|
226
|
+
0,
|
|
227
|
+
1,
|
|
228
|
+
2,
|
|
229
|
+
3,
|
|
230
|
+
4,
|
|
231
|
+
5,
|
|
232
|
+
6,
|
|
233
|
+
7,
|
|
234
|
+
8,
|
|
235
|
+
9,
|
|
236
|
+
10,
|
|
237
|
+
11,
|
|
238
|
+
12,
|
|
239
|
+
13,
|
|
240
|
+
14,
|
|
241
|
+
15,
|
|
242
|
+
14,
|
|
243
|
+
10,
|
|
244
|
+
4,
|
|
245
|
+
8,
|
|
246
|
+
9,
|
|
247
|
+
15,
|
|
248
|
+
13,
|
|
249
|
+
6,
|
|
250
|
+
1,
|
|
251
|
+
12,
|
|
252
|
+
0,
|
|
253
|
+
2,
|
|
254
|
+
11,
|
|
255
|
+
7,
|
|
256
|
+
5,
|
|
257
|
+
3
|
|
258
|
+
]);
|
|
259
|
+
const B2B_IV = /* @__PURE__ */ Uint32Array.from([
|
|
260
|
+
0xf3bcc908,
|
|
261
|
+
0x6a09e667,
|
|
262
|
+
0x84caa73b,
|
|
263
|
+
0xbb67ae85,
|
|
264
|
+
0xfe94f82b,
|
|
265
|
+
0x3c6ef372,
|
|
266
|
+
0x5f1d36f1,
|
|
267
|
+
0xa54ff53a,
|
|
268
|
+
0xade682d1,
|
|
269
|
+
0x510e527f,
|
|
270
|
+
725511199,
|
|
271
|
+
0x9b05688c,
|
|
272
|
+
0xfb41bd6b,
|
|
273
|
+
528734635,
|
|
274
|
+
327033209,
|
|
275
|
+
0x5be0cd19
|
|
276
|
+
]);
|
|
277
|
+
const BBUF = /* @__PURE__ */ new Uint32Array(32);
|
|
278
|
+
function G1b(a, b, c, d, msg, x) {
|
|
279
|
+
const Xl = msg[x], Xh = msg[x + 1];
|
|
280
|
+
let Al = BBUF[2 * a], Ah = BBUF[2 * a + 1];
|
|
281
|
+
let Bl = BBUF[2 * b], Bh = BBUF[2 * b + 1];
|
|
282
|
+
let Cl = BBUF[2 * c], Ch = BBUF[2 * c + 1];
|
|
283
|
+
let Dl = BBUF[2 * d], Dh = BBUF[2 * d + 1];
|
|
284
|
+
const ll = add3L(Al, Bl, Xl);
|
|
285
|
+
Ah = add3H(ll, Ah, Bh, Xh);
|
|
286
|
+
Al = ll | 0;
|
|
287
|
+
let xh = Dh ^ Ah, xl = Dl ^ Al;
|
|
288
|
+
Dh = rotr32H(xh, xl);
|
|
289
|
+
Dl = rotr32L(xh, xl);
|
|
290
|
+
({h: Ch, l: Cl} = add(Ch, Cl, Dh, Dl));
|
|
291
|
+
xh = Bh ^ Ch;
|
|
292
|
+
xl = Bl ^ Cl;
|
|
293
|
+
Bh = rotrSH(xh, xl, 24);
|
|
294
|
+
Bl = rotrSL(xh, xl, 24);
|
|
295
|
+
BBUF[2 * a] = Al;
|
|
296
|
+
BBUF[2 * a + 1] = Ah;
|
|
297
|
+
BBUF[2 * b] = Bl;
|
|
298
|
+
BBUF[2 * b + 1] = Bh;
|
|
299
|
+
BBUF[2 * c] = Cl;
|
|
300
|
+
BBUF[2 * c + 1] = Ch;
|
|
301
|
+
BBUF[2 * d] = Dl;
|
|
302
|
+
BBUF[2 * d + 1] = Dh;
|
|
303
|
+
}
|
|
304
|
+
function G2b(a, b, c, d, msg, x) {
|
|
305
|
+
const Xl = msg[x], Xh = msg[x + 1];
|
|
306
|
+
let Al = BBUF[2 * a], Ah = BBUF[2 * a + 1];
|
|
307
|
+
let Bl = BBUF[2 * b], Bh = BBUF[2 * b + 1];
|
|
308
|
+
let Cl = BBUF[2 * c], Ch = BBUF[2 * c + 1];
|
|
309
|
+
let Dl = BBUF[2 * d], Dh = BBUF[2 * d + 1];
|
|
310
|
+
const ll = add3L(Al, Bl, Xl);
|
|
311
|
+
Ah = add3H(ll, Ah, Bh, Xh);
|
|
312
|
+
Al = ll | 0;
|
|
313
|
+
let xh = Dh ^ Ah, xl = Dl ^ Al;
|
|
314
|
+
Dh = rotrSH(xh, xl, 16);
|
|
315
|
+
Dl = rotrSL(xh, xl, 16);
|
|
316
|
+
({h: Ch, l: Cl} = add(Ch, Cl, Dh, Dl));
|
|
317
|
+
xh = Bh ^ Ch;
|
|
318
|
+
xl = Bl ^ Cl;
|
|
319
|
+
Bh = rotrBH(xh, xl, 63);
|
|
320
|
+
Bl = rotrBL(xh, xl, 63);
|
|
321
|
+
BBUF[2 * a] = Al;
|
|
322
|
+
BBUF[2 * a + 1] = Ah;
|
|
323
|
+
BBUF[2 * b] = Bl;
|
|
324
|
+
BBUF[2 * b + 1] = Bh;
|
|
325
|
+
BBUF[2 * c] = Cl;
|
|
326
|
+
BBUF[2 * c + 1] = Ch;
|
|
327
|
+
BBUF[2 * d] = Dl;
|
|
328
|
+
BBUF[2 * d + 1] = Dh;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* BLAKE2b digest of `message`, `outLen` bytes long (1..64). Unkeyed.
|
|
332
|
+
*
|
|
333
|
+
* @param message - The bytes to hash.
|
|
334
|
+
* @param outLen - The digest length in bytes; libsodium's sealed-box nonce is 24.
|
|
335
|
+
*
|
|
336
|
+
* @internal
|
|
337
|
+
*/
|
|
338
|
+
function blake2b(message, outLen) {
|
|
339
|
+
if (!Number.isInteger(outLen) || outLen < 1 || outLen > MAX_OUT_BYTES) throw new RangeError(`blake2b outLen must be 1..${MAX_OUT_BYTES}, got ${outLen}`);
|
|
340
|
+
const state = Uint32Array.from(B2B_IV.subarray(0, 16));
|
|
341
|
+
state[0] ^= outLen | 16842752;
|
|
342
|
+
const block = new Uint8Array(BLOCK_BYTES);
|
|
343
|
+
const msg = /* @__PURE__ */ new Uint32Array(32);
|
|
344
|
+
const total = message.length;
|
|
345
|
+
let pos = 0;
|
|
346
|
+
let length = 0;
|
|
347
|
+
for (;;) {
|
|
348
|
+
const take = Math.min(BLOCK_BYTES, total - pos);
|
|
349
|
+
const isLast = total - pos <= BLOCK_BYTES;
|
|
350
|
+
block.fill(0);
|
|
351
|
+
block.set(message.subarray(pos, pos + take));
|
|
352
|
+
for (let i = 0; i < 32; i++) {
|
|
353
|
+
const o = i * 4;
|
|
354
|
+
msg[i] = block[o] | block[o + 1] << 8 | block[o + 2] << 16 | block[o + 3] << 24 | 0;
|
|
355
|
+
}
|
|
356
|
+
pos += take;
|
|
357
|
+
length += take;
|
|
358
|
+
compress(state, msg, length, isLast);
|
|
359
|
+
if (isLast) break;
|
|
360
|
+
}
|
|
361
|
+
const out = new Uint8Array(MAX_OUT_BYTES);
|
|
362
|
+
for (let i = 0; i < 16; i++) {
|
|
363
|
+
const w = state[i];
|
|
364
|
+
out[i * 4] = w;
|
|
365
|
+
out[i * 4 + 1] = w >>> 8;
|
|
366
|
+
out[i * 4 + 2] = w >>> 16;
|
|
367
|
+
out[i * 4 + 3] = w >>> 24;
|
|
368
|
+
}
|
|
369
|
+
return out.slice(0, outLen);
|
|
370
|
+
}
|
|
371
|
+
/** One BLAKE2b compression: folds `msg` (32 LE words) into `state` (16 LE words). */
|
|
372
|
+
function compress(state, msg, length, isLast) {
|
|
373
|
+
BBUF.set(state);
|
|
374
|
+
BBUF.set(B2B_IV, 16);
|
|
375
|
+
const l = fromNumL(length);
|
|
376
|
+
const h = fromNumH(length);
|
|
377
|
+
BBUF[24] = B2B_IV[8] ^ l;
|
|
378
|
+
BBUF[25] = B2B_IV[9] ^ h;
|
|
379
|
+
if (isLast) {
|
|
380
|
+
BBUF[28] = ~BBUF[28];
|
|
381
|
+
BBUF[29] = ~BBUF[29];
|
|
382
|
+
}
|
|
383
|
+
let j = 0;
|
|
384
|
+
const s = BSIGMA;
|
|
385
|
+
for (let i = 0; i < 12; i++) {
|
|
386
|
+
G1b(0, 4, 8, 12, msg, 2 * s[j++]);
|
|
387
|
+
G2b(0, 4, 8, 12, msg, 2 * s[j++]);
|
|
388
|
+
G1b(1, 5, 9, 13, msg, 2 * s[j++]);
|
|
389
|
+
G2b(1, 5, 9, 13, msg, 2 * s[j++]);
|
|
390
|
+
G1b(2, 6, 10, 14, msg, 2 * s[j++]);
|
|
391
|
+
G2b(2, 6, 10, 14, msg, 2 * s[j++]);
|
|
392
|
+
G1b(3, 7, 11, 15, msg, 2 * s[j++]);
|
|
393
|
+
G2b(3, 7, 11, 15, msg, 2 * s[j++]);
|
|
394
|
+
G1b(0, 5, 10, 15, msg, 2 * s[j++]);
|
|
395
|
+
G2b(0, 5, 10, 15, msg, 2 * s[j++]);
|
|
396
|
+
G1b(1, 6, 11, 12, msg, 2 * s[j++]);
|
|
397
|
+
G2b(1, 6, 11, 12, msg, 2 * s[j++]);
|
|
398
|
+
G1b(2, 7, 8, 13, msg, 2 * s[j++]);
|
|
399
|
+
G2b(2, 7, 8, 13, msg, 2 * s[j++]);
|
|
400
|
+
G1b(3, 4, 9, 14, msg, 2 * s[j++]);
|
|
401
|
+
G2b(3, 4, 9, 14, msg, 2 * s[j++]);
|
|
402
|
+
}
|
|
403
|
+
for (let i = 0; i < 16; i++) state[i] ^= BBUF[i] ^ BBUF[i + 16];
|
|
404
|
+
BBUF.fill(0);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
export { blake2b };
|
package/internal/crypto.js
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
import { Result } from "effect";
|
|
2
2
|
import * as Base64 from "effect/encoding/Base64";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
3
|
+
import * as EncodingError from "effect/encoding/EncodingError";
|
|
4
|
+
import { blake2b } from "./blake2b.js";
|
|
5
|
+
import { x25519, x25519PublicKey } from "./x25519.js";
|
|
6
|
+
import { hsalsaKey, secretbox } from "./xsalsa20poly1305.js";
|
|
5
7
|
|
|
6
8
|
// src/internal/crypto.ts
|
|
7
|
-
const { blake2b } = blakejs;
|
|
8
9
|
/** A sealed box opens with the recipient's key; the nonce is derived, not sent. */
|
|
9
10
|
const NONCE_BYTES = 24;
|
|
10
11
|
const PUBLIC_KEY_BYTES = 32;
|
|
11
12
|
const utf8 = new TextEncoder();
|
|
13
|
+
const invalidKey = (publicKey, message) => new EncodingError.EncodingError({
|
|
14
|
+
kind: "Decode",
|
|
15
|
+
module: "SealedBox",
|
|
16
|
+
input: publicKey,
|
|
17
|
+
message
|
|
18
|
+
});
|
|
12
19
|
/**
|
|
13
20
|
* Encrypt a secret with libsodium's sealed-box algorithm, the format GitHub's
|
|
14
21
|
* secrets API requires.
|
|
@@ -29,16 +36,17 @@ const utf8 = new TextEncoder();
|
|
|
29
36
|
* corrupt secret rather than as an error here.
|
|
30
37
|
*
|
|
31
38
|
* ## Nothing here is Node-specific
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
* garbage from the API is input, and
|
|
39
|
+
|
|
40
|
+
Base64 goes through core's `Base64`, text through `TextEncoder`, and the
|
|
41
|
+
ephemeral secret key through `globalThis.crypto.getRandomValues`, so this
|
|
42
|
+
module's graph imports **no builtin** and runs on workerd. The primitives
|
|
43
|
+
(X25519, HSalsa20, XSalsa20-Poly1305 and BLAKE2b) are in-house copies of audited
|
|
44
|
+
`@noble` code, each carrying its provenance header; they are one-shot functions
|
|
45
|
+
with no dependency of their own.
|
|
46
|
+
|
|
47
|
+
A malformed `publicKey` (not base64, not 32 bytes, or a low-order point) fails as
|
|
48
|
+
* a typed `Result` rather than throwing: garbage from the API is input, and
|
|
49
|
+
* input failures are typed.
|
|
42
50
|
*
|
|
43
51
|
* @param publicKey - The repository, environment or organization public key,
|
|
44
52
|
* base64, as returned by GitHub's `.../secrets/public-key` endpoints.
|
|
@@ -47,17 +55,26 @@ const utf8 = new TextEncoder();
|
|
|
47
55
|
*
|
|
48
56
|
* @internal
|
|
49
57
|
*/
|
|
50
|
-
const encryptSecret = (publicKey, secretValue) => Result.
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
const encryptSecret = (publicKey, secretValue) => Result.flatMap(Base64.decode(publicKey), (publicKeyBytes) => {
|
|
59
|
+
if (publicKeyBytes.length !== PUBLIC_KEY_BYTES) return Result.fail(invalidKey(publicKey, `a sealed-box public key is ${PUBLIC_KEY_BYTES} bytes, got ${publicKeyBytes.length}`));
|
|
60
|
+
const ephemeralSecretKey = globalThis.crypto.getRandomValues(new Uint8Array(PUBLIC_KEY_BYTES));
|
|
61
|
+
try {
|
|
62
|
+
const ephemeralPublicKey = x25519PublicKey(ephemeralSecretKey);
|
|
63
|
+
const nonceInput = /* @__PURE__ */ new Uint8Array(64);
|
|
64
|
+
nonceInput.set(ephemeralPublicKey);
|
|
65
|
+
nonceInput.set(publicKeyBytes, PUBLIC_KEY_BYTES);
|
|
66
|
+
const nonce = blake2b(nonceInput, NONCE_BYTES);
|
|
67
|
+
const sharedKey = hsalsaKey(x25519(ephemeralSecretKey, publicKeyBytes));
|
|
68
|
+
const ciphertext = secretbox(utf8.encode(secretValue), nonce, sharedKey);
|
|
69
|
+
const sealed = new Uint8Array(ephemeralPublicKey.length + ciphertext.length);
|
|
70
|
+
sealed.set(ephemeralPublicKey);
|
|
71
|
+
sealed.set(ciphertext, ephemeralPublicKey.length);
|
|
72
|
+
return Result.succeed(Base64.encode(sealed));
|
|
73
|
+
} catch {
|
|
74
|
+
return Result.fail(invalidKey(publicKey, "the public key is a low-order curve point"));
|
|
75
|
+
} finally {
|
|
76
|
+
ephemeralSecretKey.fill(0);
|
|
77
|
+
}
|
|
61
78
|
});
|
|
62
79
|
|
|
63
80
|
export { encryptSecret };
|
package/internal/octokit.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import { Octokit } from "@octokit/core";
|
|
2
|
+
import { composePaginateRest } from "@octokit/plugin-paginate-rest";
|
|
3
|
+
import { Clock, Effect, Option, Redacted, Ref } from "effect";
|
|
1
4
|
import { GitHubError, readRateLimitHeaders } from "../GitHubError.js";
|
|
2
5
|
import { GitHubGraphQLError } from "../GraphQL.js";
|
|
3
6
|
import { RateLimitSnapshot } from "../Resilience.js";
|
|
4
7
|
import { rawRequestRefusal, refusedRequest, reservedParamReason, routeReason } from "./confinement.js";
|
|
5
8
|
import { DOTCOM_API_BASE_URL, originOf } from "./uploads.js";
|
|
6
|
-
import { Clock, Effect, Option, Redacted, Ref } from "effect";
|
|
7
|
-
import { Octokit } from "@octokit/core";
|
|
8
|
-
import { composePaginateRest } from "@octokit/plugin-paginate-rest";
|
|
9
9
|
|
|
10
10
|
// src/internal/octokit.ts
|
|
11
11
|
const SILENT_LOG = {
|