@paigy/mcp 0.40.8 → 0.40.10
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/dist/{chunk-DRRAJMEE.js → chunk-AK5AVPF6.js} +9 -43
- package/dist/{chunk-BT5S7VT2.js → chunk-HCCUK3ZL.js} +101 -2750
- package/dist/{chunk-GQ5J6WW5.js → chunk-QAQET3PZ.js} +5 -5
- package/dist/{chunk-XOL6UX6P.js → chunk-UFOR2QEP.js} +32 -150
- package/dist/enable.js +3 -3
- package/dist/index.js +10 -27
- package/dist/listen.js +3 -6
- package/dist/onboard.js +6 -9
- package/dist/slot.js +3 -3
- package/dist/statusline.js +1 -1
- package/package.json +2 -3
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
// ../../packages/sdk/dist/index.js
|
|
2
2
|
import { createRequire as __sdkCreateRequire } from "module";
|
|
3
|
+
import { execFileSync } from "child_process";
|
|
3
4
|
import { createHash, randomUUID } from "crypto";
|
|
5
|
+
import { readFileSync } from "fs";
|
|
6
|
+
import { homedir } from "os";
|
|
7
|
+
import { join } from "path";
|
|
4
8
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
5
9
|
import { setTimeout as sleep2 } from "timers/promises";
|
|
6
10
|
import { z as z3 } from "zod";
|
|
@@ -10,2266 +14,12 @@ import { ZodFirstPartyTypeKind } from "zod/v3";
|
|
|
10
14
|
import { ZodFirstPartyTypeKind as ZodFirstPartyTypeKind2 } from "zod/v3";
|
|
11
15
|
import { z } from "zod";
|
|
12
16
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
13
|
-
import { closeSync, existsSync, mkdirSync, openSync, readFileSync, rmSync, statSync, writeFileSync } from "fs";
|
|
14
|
-
import { homedir } from "os";
|
|
15
|
-
import { join } from "path";
|
|
17
|
+
import { closeSync, existsSync, mkdirSync, openSync, readFileSync as readFileSync2, rmSync, statSync, writeFileSync } from "fs";
|
|
18
|
+
import { homedir as homedir2 } from "os";
|
|
19
|
+
import { join as join2 } from "path";
|
|
16
20
|
import { randomUUID as randomUUID4 } from "crypto";
|
|
17
21
|
import { WebSocket } from "undici";
|
|
18
22
|
var require2 = __sdkCreateRequire(import.meta.url);
|
|
19
|
-
var __create = Object.create;
|
|
20
|
-
var __defProp = Object.defineProperty;
|
|
21
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
22
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
23
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
24
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
25
|
-
var __require = /* @__PURE__ */ ((x) => typeof require2 !== "undefined" ? require2 : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
26
|
-
get: (a, b) => (typeof require2 !== "undefined" ? require2 : a)[b]
|
|
27
|
-
}) : x)(function(x) {
|
|
28
|
-
if (typeof require2 !== "undefined") return require2.apply(this, arguments);
|
|
29
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
30
|
-
});
|
|
31
|
-
var __commonJS = (cb, mod) => function __require2() {
|
|
32
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
33
|
-
};
|
|
34
|
-
var __copyProps = (to, from, except, desc) => {
|
|
35
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
36
|
-
for (let key of __getOwnPropNames(from))
|
|
37
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
38
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
39
|
-
}
|
|
40
|
-
return to;
|
|
41
|
-
};
|
|
42
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
43
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
44
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
45
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
46
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
47
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
48
|
-
mod
|
|
49
|
-
));
|
|
50
|
-
var require_nacl_fast = __commonJS({
|
|
51
|
-
"../../node_modules/.pnpm/tweetnacl@1.0.3/node_modules/tweetnacl/nacl-fast.js"(exports, module) {
|
|
52
|
-
"use strict";
|
|
53
|
-
(function(nacl6) {
|
|
54
|
-
"use strict";
|
|
55
|
-
var gf = function(init) {
|
|
56
|
-
var i, r = new Float64Array(16);
|
|
57
|
-
if (init) for (i = 0; i < init.length; i++) r[i] = init[i];
|
|
58
|
-
return r;
|
|
59
|
-
};
|
|
60
|
-
var randombytes = function() {
|
|
61
|
-
throw new Error("no PRNG");
|
|
62
|
-
};
|
|
63
|
-
var _0 = new Uint8Array(16);
|
|
64
|
-
var _9 = new Uint8Array(32);
|
|
65
|
-
_9[0] = 9;
|
|
66
|
-
var gf0 = gf(), gf1 = gf([1]), _121665 = gf([56129, 1]), D = gf([30883, 4953, 19914, 30187, 55467, 16705, 2637, 112, 59544, 30585, 16505, 36039, 65139, 11119, 27886, 20995]), D2 = gf([61785, 9906, 39828, 60374, 45398, 33411, 5274, 224, 53552, 61171, 33010, 6542, 64743, 22239, 55772, 9222]), X = gf([54554, 36645, 11616, 51542, 42930, 38181, 51040, 26924, 56412, 64982, 57905, 49316, 21502, 52590, 14035, 8553]), Y = gf([26200, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214]), I = gf([41136, 18958, 6951, 50414, 58488, 44335, 6150, 12099, 55207, 15867, 153, 11085, 57099, 20417, 9344, 11139]);
|
|
67
|
-
function ts64(x, i, h, l) {
|
|
68
|
-
x[i] = h >> 24 & 255;
|
|
69
|
-
x[i + 1] = h >> 16 & 255;
|
|
70
|
-
x[i + 2] = h >> 8 & 255;
|
|
71
|
-
x[i + 3] = h & 255;
|
|
72
|
-
x[i + 4] = l >> 24 & 255;
|
|
73
|
-
x[i + 5] = l >> 16 & 255;
|
|
74
|
-
x[i + 6] = l >> 8 & 255;
|
|
75
|
-
x[i + 7] = l & 255;
|
|
76
|
-
}
|
|
77
|
-
function vn(x, xi, y, yi, n) {
|
|
78
|
-
var i, d = 0;
|
|
79
|
-
for (i = 0; i < n; i++) d |= x[xi + i] ^ y[yi + i];
|
|
80
|
-
return (1 & d - 1 >>> 8) - 1;
|
|
81
|
-
}
|
|
82
|
-
function crypto_verify_16(x, xi, y, yi) {
|
|
83
|
-
return vn(x, xi, y, yi, 16);
|
|
84
|
-
}
|
|
85
|
-
function crypto_verify_32(x, xi, y, yi) {
|
|
86
|
-
return vn(x, xi, y, yi, 32);
|
|
87
|
-
}
|
|
88
|
-
function core_salsa20(o, p, k, c) {
|
|
89
|
-
var j0 = c[0] & 255 | (c[1] & 255) << 8 | (c[2] & 255) << 16 | (c[3] & 255) << 24, j1 = k[0] & 255 | (k[1] & 255) << 8 | (k[2] & 255) << 16 | (k[3] & 255) << 24, j2 = k[4] & 255 | (k[5] & 255) << 8 | (k[6] & 255) << 16 | (k[7] & 255) << 24, j3 = k[8] & 255 | (k[9] & 255) << 8 | (k[10] & 255) << 16 | (k[11] & 255) << 24, j4 = k[12] & 255 | (k[13] & 255) << 8 | (k[14] & 255) << 16 | (k[15] & 255) << 24, j5 = c[4] & 255 | (c[5] & 255) << 8 | (c[6] & 255) << 16 | (c[7] & 255) << 24, j6 = p[0] & 255 | (p[1] & 255) << 8 | (p[2] & 255) << 16 | (p[3] & 255) << 24, j7 = p[4] & 255 | (p[5] & 255) << 8 | (p[6] & 255) << 16 | (p[7] & 255) << 24, j8 = p[8] & 255 | (p[9] & 255) << 8 | (p[10] & 255) << 16 | (p[11] & 255) << 24, j9 = p[12] & 255 | (p[13] & 255) << 8 | (p[14] & 255) << 16 | (p[15] & 255) << 24, j10 = c[8] & 255 | (c[9] & 255) << 8 | (c[10] & 255) << 16 | (c[11] & 255) << 24, j11 = k[16] & 255 | (k[17] & 255) << 8 | (k[18] & 255) << 16 | (k[19] & 255) << 24, j12 = k[20] & 255 | (k[21] & 255) << 8 | (k[22] & 255) << 16 | (k[23] & 255) << 24, j13 = k[24] & 255 | (k[25] & 255) << 8 | (k[26] & 255) << 16 | (k[27] & 255) << 24, j14 = k[28] & 255 | (k[29] & 255) << 8 | (k[30] & 255) << 16 | (k[31] & 255) << 24, j15 = c[12] & 255 | (c[13] & 255) << 8 | (c[14] & 255) << 16 | (c[15] & 255) << 24;
|
|
90
|
-
var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7, x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14, x15 = j15, u;
|
|
91
|
-
for (var i = 0; i < 20; i += 2) {
|
|
92
|
-
u = x0 + x12 | 0;
|
|
93
|
-
x4 ^= u << 7 | u >>> 32 - 7;
|
|
94
|
-
u = x4 + x0 | 0;
|
|
95
|
-
x8 ^= u << 9 | u >>> 32 - 9;
|
|
96
|
-
u = x8 + x4 | 0;
|
|
97
|
-
x12 ^= u << 13 | u >>> 32 - 13;
|
|
98
|
-
u = x12 + x8 | 0;
|
|
99
|
-
x0 ^= u << 18 | u >>> 32 - 18;
|
|
100
|
-
u = x5 + x1 | 0;
|
|
101
|
-
x9 ^= u << 7 | u >>> 32 - 7;
|
|
102
|
-
u = x9 + x5 | 0;
|
|
103
|
-
x13 ^= u << 9 | u >>> 32 - 9;
|
|
104
|
-
u = x13 + x9 | 0;
|
|
105
|
-
x1 ^= u << 13 | u >>> 32 - 13;
|
|
106
|
-
u = x1 + x13 | 0;
|
|
107
|
-
x5 ^= u << 18 | u >>> 32 - 18;
|
|
108
|
-
u = x10 + x6 | 0;
|
|
109
|
-
x14 ^= u << 7 | u >>> 32 - 7;
|
|
110
|
-
u = x14 + x10 | 0;
|
|
111
|
-
x2 ^= u << 9 | u >>> 32 - 9;
|
|
112
|
-
u = x2 + x14 | 0;
|
|
113
|
-
x6 ^= u << 13 | u >>> 32 - 13;
|
|
114
|
-
u = x6 + x2 | 0;
|
|
115
|
-
x10 ^= u << 18 | u >>> 32 - 18;
|
|
116
|
-
u = x15 + x11 | 0;
|
|
117
|
-
x3 ^= u << 7 | u >>> 32 - 7;
|
|
118
|
-
u = x3 + x15 | 0;
|
|
119
|
-
x7 ^= u << 9 | u >>> 32 - 9;
|
|
120
|
-
u = x7 + x3 | 0;
|
|
121
|
-
x11 ^= u << 13 | u >>> 32 - 13;
|
|
122
|
-
u = x11 + x7 | 0;
|
|
123
|
-
x15 ^= u << 18 | u >>> 32 - 18;
|
|
124
|
-
u = x0 + x3 | 0;
|
|
125
|
-
x1 ^= u << 7 | u >>> 32 - 7;
|
|
126
|
-
u = x1 + x0 | 0;
|
|
127
|
-
x2 ^= u << 9 | u >>> 32 - 9;
|
|
128
|
-
u = x2 + x1 | 0;
|
|
129
|
-
x3 ^= u << 13 | u >>> 32 - 13;
|
|
130
|
-
u = x3 + x2 | 0;
|
|
131
|
-
x0 ^= u << 18 | u >>> 32 - 18;
|
|
132
|
-
u = x5 + x4 | 0;
|
|
133
|
-
x6 ^= u << 7 | u >>> 32 - 7;
|
|
134
|
-
u = x6 + x5 | 0;
|
|
135
|
-
x7 ^= u << 9 | u >>> 32 - 9;
|
|
136
|
-
u = x7 + x6 | 0;
|
|
137
|
-
x4 ^= u << 13 | u >>> 32 - 13;
|
|
138
|
-
u = x4 + x7 | 0;
|
|
139
|
-
x5 ^= u << 18 | u >>> 32 - 18;
|
|
140
|
-
u = x10 + x9 | 0;
|
|
141
|
-
x11 ^= u << 7 | u >>> 32 - 7;
|
|
142
|
-
u = x11 + x10 | 0;
|
|
143
|
-
x8 ^= u << 9 | u >>> 32 - 9;
|
|
144
|
-
u = x8 + x11 | 0;
|
|
145
|
-
x9 ^= u << 13 | u >>> 32 - 13;
|
|
146
|
-
u = x9 + x8 | 0;
|
|
147
|
-
x10 ^= u << 18 | u >>> 32 - 18;
|
|
148
|
-
u = x15 + x14 | 0;
|
|
149
|
-
x12 ^= u << 7 | u >>> 32 - 7;
|
|
150
|
-
u = x12 + x15 | 0;
|
|
151
|
-
x13 ^= u << 9 | u >>> 32 - 9;
|
|
152
|
-
u = x13 + x12 | 0;
|
|
153
|
-
x14 ^= u << 13 | u >>> 32 - 13;
|
|
154
|
-
u = x14 + x13 | 0;
|
|
155
|
-
x15 ^= u << 18 | u >>> 32 - 18;
|
|
156
|
-
}
|
|
157
|
-
x0 = x0 + j0 | 0;
|
|
158
|
-
x1 = x1 + j1 | 0;
|
|
159
|
-
x2 = x2 + j2 | 0;
|
|
160
|
-
x3 = x3 + j3 | 0;
|
|
161
|
-
x4 = x4 + j4 | 0;
|
|
162
|
-
x5 = x5 + j5 | 0;
|
|
163
|
-
x6 = x6 + j6 | 0;
|
|
164
|
-
x7 = x7 + j7 | 0;
|
|
165
|
-
x8 = x8 + j8 | 0;
|
|
166
|
-
x9 = x9 + j9 | 0;
|
|
167
|
-
x10 = x10 + j10 | 0;
|
|
168
|
-
x11 = x11 + j11 | 0;
|
|
169
|
-
x12 = x12 + j12 | 0;
|
|
170
|
-
x13 = x13 + j13 | 0;
|
|
171
|
-
x14 = x14 + j14 | 0;
|
|
172
|
-
x15 = x15 + j15 | 0;
|
|
173
|
-
o[0] = x0 >>> 0 & 255;
|
|
174
|
-
o[1] = x0 >>> 8 & 255;
|
|
175
|
-
o[2] = x0 >>> 16 & 255;
|
|
176
|
-
o[3] = x0 >>> 24 & 255;
|
|
177
|
-
o[4] = x1 >>> 0 & 255;
|
|
178
|
-
o[5] = x1 >>> 8 & 255;
|
|
179
|
-
o[6] = x1 >>> 16 & 255;
|
|
180
|
-
o[7] = x1 >>> 24 & 255;
|
|
181
|
-
o[8] = x2 >>> 0 & 255;
|
|
182
|
-
o[9] = x2 >>> 8 & 255;
|
|
183
|
-
o[10] = x2 >>> 16 & 255;
|
|
184
|
-
o[11] = x2 >>> 24 & 255;
|
|
185
|
-
o[12] = x3 >>> 0 & 255;
|
|
186
|
-
o[13] = x3 >>> 8 & 255;
|
|
187
|
-
o[14] = x3 >>> 16 & 255;
|
|
188
|
-
o[15] = x3 >>> 24 & 255;
|
|
189
|
-
o[16] = x4 >>> 0 & 255;
|
|
190
|
-
o[17] = x4 >>> 8 & 255;
|
|
191
|
-
o[18] = x4 >>> 16 & 255;
|
|
192
|
-
o[19] = x4 >>> 24 & 255;
|
|
193
|
-
o[20] = x5 >>> 0 & 255;
|
|
194
|
-
o[21] = x5 >>> 8 & 255;
|
|
195
|
-
o[22] = x5 >>> 16 & 255;
|
|
196
|
-
o[23] = x5 >>> 24 & 255;
|
|
197
|
-
o[24] = x6 >>> 0 & 255;
|
|
198
|
-
o[25] = x6 >>> 8 & 255;
|
|
199
|
-
o[26] = x6 >>> 16 & 255;
|
|
200
|
-
o[27] = x6 >>> 24 & 255;
|
|
201
|
-
o[28] = x7 >>> 0 & 255;
|
|
202
|
-
o[29] = x7 >>> 8 & 255;
|
|
203
|
-
o[30] = x7 >>> 16 & 255;
|
|
204
|
-
o[31] = x7 >>> 24 & 255;
|
|
205
|
-
o[32] = x8 >>> 0 & 255;
|
|
206
|
-
o[33] = x8 >>> 8 & 255;
|
|
207
|
-
o[34] = x8 >>> 16 & 255;
|
|
208
|
-
o[35] = x8 >>> 24 & 255;
|
|
209
|
-
o[36] = x9 >>> 0 & 255;
|
|
210
|
-
o[37] = x9 >>> 8 & 255;
|
|
211
|
-
o[38] = x9 >>> 16 & 255;
|
|
212
|
-
o[39] = x9 >>> 24 & 255;
|
|
213
|
-
o[40] = x10 >>> 0 & 255;
|
|
214
|
-
o[41] = x10 >>> 8 & 255;
|
|
215
|
-
o[42] = x10 >>> 16 & 255;
|
|
216
|
-
o[43] = x10 >>> 24 & 255;
|
|
217
|
-
o[44] = x11 >>> 0 & 255;
|
|
218
|
-
o[45] = x11 >>> 8 & 255;
|
|
219
|
-
o[46] = x11 >>> 16 & 255;
|
|
220
|
-
o[47] = x11 >>> 24 & 255;
|
|
221
|
-
o[48] = x12 >>> 0 & 255;
|
|
222
|
-
o[49] = x12 >>> 8 & 255;
|
|
223
|
-
o[50] = x12 >>> 16 & 255;
|
|
224
|
-
o[51] = x12 >>> 24 & 255;
|
|
225
|
-
o[52] = x13 >>> 0 & 255;
|
|
226
|
-
o[53] = x13 >>> 8 & 255;
|
|
227
|
-
o[54] = x13 >>> 16 & 255;
|
|
228
|
-
o[55] = x13 >>> 24 & 255;
|
|
229
|
-
o[56] = x14 >>> 0 & 255;
|
|
230
|
-
o[57] = x14 >>> 8 & 255;
|
|
231
|
-
o[58] = x14 >>> 16 & 255;
|
|
232
|
-
o[59] = x14 >>> 24 & 255;
|
|
233
|
-
o[60] = x15 >>> 0 & 255;
|
|
234
|
-
o[61] = x15 >>> 8 & 255;
|
|
235
|
-
o[62] = x15 >>> 16 & 255;
|
|
236
|
-
o[63] = x15 >>> 24 & 255;
|
|
237
|
-
}
|
|
238
|
-
function core_hsalsa20(o, p, k, c) {
|
|
239
|
-
var j0 = c[0] & 255 | (c[1] & 255) << 8 | (c[2] & 255) << 16 | (c[3] & 255) << 24, j1 = k[0] & 255 | (k[1] & 255) << 8 | (k[2] & 255) << 16 | (k[3] & 255) << 24, j2 = k[4] & 255 | (k[5] & 255) << 8 | (k[6] & 255) << 16 | (k[7] & 255) << 24, j3 = k[8] & 255 | (k[9] & 255) << 8 | (k[10] & 255) << 16 | (k[11] & 255) << 24, j4 = k[12] & 255 | (k[13] & 255) << 8 | (k[14] & 255) << 16 | (k[15] & 255) << 24, j5 = c[4] & 255 | (c[5] & 255) << 8 | (c[6] & 255) << 16 | (c[7] & 255) << 24, j6 = p[0] & 255 | (p[1] & 255) << 8 | (p[2] & 255) << 16 | (p[3] & 255) << 24, j7 = p[4] & 255 | (p[5] & 255) << 8 | (p[6] & 255) << 16 | (p[7] & 255) << 24, j8 = p[8] & 255 | (p[9] & 255) << 8 | (p[10] & 255) << 16 | (p[11] & 255) << 24, j9 = p[12] & 255 | (p[13] & 255) << 8 | (p[14] & 255) << 16 | (p[15] & 255) << 24, j10 = c[8] & 255 | (c[9] & 255) << 8 | (c[10] & 255) << 16 | (c[11] & 255) << 24, j11 = k[16] & 255 | (k[17] & 255) << 8 | (k[18] & 255) << 16 | (k[19] & 255) << 24, j12 = k[20] & 255 | (k[21] & 255) << 8 | (k[22] & 255) << 16 | (k[23] & 255) << 24, j13 = k[24] & 255 | (k[25] & 255) << 8 | (k[26] & 255) << 16 | (k[27] & 255) << 24, j14 = k[28] & 255 | (k[29] & 255) << 8 | (k[30] & 255) << 16 | (k[31] & 255) << 24, j15 = c[12] & 255 | (c[13] & 255) << 8 | (c[14] & 255) << 16 | (c[15] & 255) << 24;
|
|
240
|
-
var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7, x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14, x15 = j15, u;
|
|
241
|
-
for (var i = 0; i < 20; i += 2) {
|
|
242
|
-
u = x0 + x12 | 0;
|
|
243
|
-
x4 ^= u << 7 | u >>> 32 - 7;
|
|
244
|
-
u = x4 + x0 | 0;
|
|
245
|
-
x8 ^= u << 9 | u >>> 32 - 9;
|
|
246
|
-
u = x8 + x4 | 0;
|
|
247
|
-
x12 ^= u << 13 | u >>> 32 - 13;
|
|
248
|
-
u = x12 + x8 | 0;
|
|
249
|
-
x0 ^= u << 18 | u >>> 32 - 18;
|
|
250
|
-
u = x5 + x1 | 0;
|
|
251
|
-
x9 ^= u << 7 | u >>> 32 - 7;
|
|
252
|
-
u = x9 + x5 | 0;
|
|
253
|
-
x13 ^= u << 9 | u >>> 32 - 9;
|
|
254
|
-
u = x13 + x9 | 0;
|
|
255
|
-
x1 ^= u << 13 | u >>> 32 - 13;
|
|
256
|
-
u = x1 + x13 | 0;
|
|
257
|
-
x5 ^= u << 18 | u >>> 32 - 18;
|
|
258
|
-
u = x10 + x6 | 0;
|
|
259
|
-
x14 ^= u << 7 | u >>> 32 - 7;
|
|
260
|
-
u = x14 + x10 | 0;
|
|
261
|
-
x2 ^= u << 9 | u >>> 32 - 9;
|
|
262
|
-
u = x2 + x14 | 0;
|
|
263
|
-
x6 ^= u << 13 | u >>> 32 - 13;
|
|
264
|
-
u = x6 + x2 | 0;
|
|
265
|
-
x10 ^= u << 18 | u >>> 32 - 18;
|
|
266
|
-
u = x15 + x11 | 0;
|
|
267
|
-
x3 ^= u << 7 | u >>> 32 - 7;
|
|
268
|
-
u = x3 + x15 | 0;
|
|
269
|
-
x7 ^= u << 9 | u >>> 32 - 9;
|
|
270
|
-
u = x7 + x3 | 0;
|
|
271
|
-
x11 ^= u << 13 | u >>> 32 - 13;
|
|
272
|
-
u = x11 + x7 | 0;
|
|
273
|
-
x15 ^= u << 18 | u >>> 32 - 18;
|
|
274
|
-
u = x0 + x3 | 0;
|
|
275
|
-
x1 ^= u << 7 | u >>> 32 - 7;
|
|
276
|
-
u = x1 + x0 | 0;
|
|
277
|
-
x2 ^= u << 9 | u >>> 32 - 9;
|
|
278
|
-
u = x2 + x1 | 0;
|
|
279
|
-
x3 ^= u << 13 | u >>> 32 - 13;
|
|
280
|
-
u = x3 + x2 | 0;
|
|
281
|
-
x0 ^= u << 18 | u >>> 32 - 18;
|
|
282
|
-
u = x5 + x4 | 0;
|
|
283
|
-
x6 ^= u << 7 | u >>> 32 - 7;
|
|
284
|
-
u = x6 + x5 | 0;
|
|
285
|
-
x7 ^= u << 9 | u >>> 32 - 9;
|
|
286
|
-
u = x7 + x6 | 0;
|
|
287
|
-
x4 ^= u << 13 | u >>> 32 - 13;
|
|
288
|
-
u = x4 + x7 | 0;
|
|
289
|
-
x5 ^= u << 18 | u >>> 32 - 18;
|
|
290
|
-
u = x10 + x9 | 0;
|
|
291
|
-
x11 ^= u << 7 | u >>> 32 - 7;
|
|
292
|
-
u = x11 + x10 | 0;
|
|
293
|
-
x8 ^= u << 9 | u >>> 32 - 9;
|
|
294
|
-
u = x8 + x11 | 0;
|
|
295
|
-
x9 ^= u << 13 | u >>> 32 - 13;
|
|
296
|
-
u = x9 + x8 | 0;
|
|
297
|
-
x10 ^= u << 18 | u >>> 32 - 18;
|
|
298
|
-
u = x15 + x14 | 0;
|
|
299
|
-
x12 ^= u << 7 | u >>> 32 - 7;
|
|
300
|
-
u = x12 + x15 | 0;
|
|
301
|
-
x13 ^= u << 9 | u >>> 32 - 9;
|
|
302
|
-
u = x13 + x12 | 0;
|
|
303
|
-
x14 ^= u << 13 | u >>> 32 - 13;
|
|
304
|
-
u = x14 + x13 | 0;
|
|
305
|
-
x15 ^= u << 18 | u >>> 32 - 18;
|
|
306
|
-
}
|
|
307
|
-
o[0] = x0 >>> 0 & 255;
|
|
308
|
-
o[1] = x0 >>> 8 & 255;
|
|
309
|
-
o[2] = x0 >>> 16 & 255;
|
|
310
|
-
o[3] = x0 >>> 24 & 255;
|
|
311
|
-
o[4] = x5 >>> 0 & 255;
|
|
312
|
-
o[5] = x5 >>> 8 & 255;
|
|
313
|
-
o[6] = x5 >>> 16 & 255;
|
|
314
|
-
o[7] = x5 >>> 24 & 255;
|
|
315
|
-
o[8] = x10 >>> 0 & 255;
|
|
316
|
-
o[9] = x10 >>> 8 & 255;
|
|
317
|
-
o[10] = x10 >>> 16 & 255;
|
|
318
|
-
o[11] = x10 >>> 24 & 255;
|
|
319
|
-
o[12] = x15 >>> 0 & 255;
|
|
320
|
-
o[13] = x15 >>> 8 & 255;
|
|
321
|
-
o[14] = x15 >>> 16 & 255;
|
|
322
|
-
o[15] = x15 >>> 24 & 255;
|
|
323
|
-
o[16] = x6 >>> 0 & 255;
|
|
324
|
-
o[17] = x6 >>> 8 & 255;
|
|
325
|
-
o[18] = x6 >>> 16 & 255;
|
|
326
|
-
o[19] = x6 >>> 24 & 255;
|
|
327
|
-
o[20] = x7 >>> 0 & 255;
|
|
328
|
-
o[21] = x7 >>> 8 & 255;
|
|
329
|
-
o[22] = x7 >>> 16 & 255;
|
|
330
|
-
o[23] = x7 >>> 24 & 255;
|
|
331
|
-
o[24] = x8 >>> 0 & 255;
|
|
332
|
-
o[25] = x8 >>> 8 & 255;
|
|
333
|
-
o[26] = x8 >>> 16 & 255;
|
|
334
|
-
o[27] = x8 >>> 24 & 255;
|
|
335
|
-
o[28] = x9 >>> 0 & 255;
|
|
336
|
-
o[29] = x9 >>> 8 & 255;
|
|
337
|
-
o[30] = x9 >>> 16 & 255;
|
|
338
|
-
o[31] = x9 >>> 24 & 255;
|
|
339
|
-
}
|
|
340
|
-
function crypto_core_salsa20(out, inp, k, c) {
|
|
341
|
-
core_salsa20(out, inp, k, c);
|
|
342
|
-
}
|
|
343
|
-
function crypto_core_hsalsa20(out, inp, k, c) {
|
|
344
|
-
core_hsalsa20(out, inp, k, c);
|
|
345
|
-
}
|
|
346
|
-
var sigma = new Uint8Array([101, 120, 112, 97, 110, 100, 32, 51, 50, 45, 98, 121, 116, 101, 32, 107]);
|
|
347
|
-
function crypto_stream_salsa20_xor(c, cpos, m, mpos, b, n, k) {
|
|
348
|
-
var z4 = new Uint8Array(16), x = new Uint8Array(64);
|
|
349
|
-
var u, i;
|
|
350
|
-
for (i = 0; i < 16; i++) z4[i] = 0;
|
|
351
|
-
for (i = 0; i < 8; i++) z4[i] = n[i];
|
|
352
|
-
while (b >= 64) {
|
|
353
|
-
crypto_core_salsa20(x, z4, k, sigma);
|
|
354
|
-
for (i = 0; i < 64; i++) c[cpos + i] = m[mpos + i] ^ x[i];
|
|
355
|
-
u = 1;
|
|
356
|
-
for (i = 8; i < 16; i++) {
|
|
357
|
-
u = u + (z4[i] & 255) | 0;
|
|
358
|
-
z4[i] = u & 255;
|
|
359
|
-
u >>>= 8;
|
|
360
|
-
}
|
|
361
|
-
b -= 64;
|
|
362
|
-
cpos += 64;
|
|
363
|
-
mpos += 64;
|
|
364
|
-
}
|
|
365
|
-
if (b > 0) {
|
|
366
|
-
crypto_core_salsa20(x, z4, k, sigma);
|
|
367
|
-
for (i = 0; i < b; i++) c[cpos + i] = m[mpos + i] ^ x[i];
|
|
368
|
-
}
|
|
369
|
-
return 0;
|
|
370
|
-
}
|
|
371
|
-
function crypto_stream_salsa20(c, cpos, b, n, k) {
|
|
372
|
-
var z4 = new Uint8Array(16), x = new Uint8Array(64);
|
|
373
|
-
var u, i;
|
|
374
|
-
for (i = 0; i < 16; i++) z4[i] = 0;
|
|
375
|
-
for (i = 0; i < 8; i++) z4[i] = n[i];
|
|
376
|
-
while (b >= 64) {
|
|
377
|
-
crypto_core_salsa20(x, z4, k, sigma);
|
|
378
|
-
for (i = 0; i < 64; i++) c[cpos + i] = x[i];
|
|
379
|
-
u = 1;
|
|
380
|
-
for (i = 8; i < 16; i++) {
|
|
381
|
-
u = u + (z4[i] & 255) | 0;
|
|
382
|
-
z4[i] = u & 255;
|
|
383
|
-
u >>>= 8;
|
|
384
|
-
}
|
|
385
|
-
b -= 64;
|
|
386
|
-
cpos += 64;
|
|
387
|
-
}
|
|
388
|
-
if (b > 0) {
|
|
389
|
-
crypto_core_salsa20(x, z4, k, sigma);
|
|
390
|
-
for (i = 0; i < b; i++) c[cpos + i] = x[i];
|
|
391
|
-
}
|
|
392
|
-
return 0;
|
|
393
|
-
}
|
|
394
|
-
function crypto_stream(c, cpos, d, n, k) {
|
|
395
|
-
var s = new Uint8Array(32);
|
|
396
|
-
crypto_core_hsalsa20(s, n, k, sigma);
|
|
397
|
-
var sn = new Uint8Array(8);
|
|
398
|
-
for (var i = 0; i < 8; i++) sn[i] = n[i + 16];
|
|
399
|
-
return crypto_stream_salsa20(c, cpos, d, sn, s);
|
|
400
|
-
}
|
|
401
|
-
function crypto_stream_xor(c, cpos, m, mpos, d, n, k) {
|
|
402
|
-
var s = new Uint8Array(32);
|
|
403
|
-
crypto_core_hsalsa20(s, n, k, sigma);
|
|
404
|
-
var sn = new Uint8Array(8);
|
|
405
|
-
for (var i = 0; i < 8; i++) sn[i] = n[i + 16];
|
|
406
|
-
return crypto_stream_salsa20_xor(c, cpos, m, mpos, d, sn, s);
|
|
407
|
-
}
|
|
408
|
-
var poly1305 = function(key) {
|
|
409
|
-
this.buffer = new Uint8Array(16);
|
|
410
|
-
this.r = new Uint16Array(10);
|
|
411
|
-
this.h = new Uint16Array(10);
|
|
412
|
-
this.pad = new Uint16Array(8);
|
|
413
|
-
this.leftover = 0;
|
|
414
|
-
this.fin = 0;
|
|
415
|
-
var t0, t1, t2, t3, t4, t5, t6, t7;
|
|
416
|
-
t0 = key[0] & 255 | (key[1] & 255) << 8;
|
|
417
|
-
this.r[0] = t0 & 8191;
|
|
418
|
-
t1 = key[2] & 255 | (key[3] & 255) << 8;
|
|
419
|
-
this.r[1] = (t0 >>> 13 | t1 << 3) & 8191;
|
|
420
|
-
t2 = key[4] & 255 | (key[5] & 255) << 8;
|
|
421
|
-
this.r[2] = (t1 >>> 10 | t2 << 6) & 7939;
|
|
422
|
-
t3 = key[6] & 255 | (key[7] & 255) << 8;
|
|
423
|
-
this.r[3] = (t2 >>> 7 | t3 << 9) & 8191;
|
|
424
|
-
t4 = key[8] & 255 | (key[9] & 255) << 8;
|
|
425
|
-
this.r[4] = (t3 >>> 4 | t4 << 12) & 255;
|
|
426
|
-
this.r[5] = t4 >>> 1 & 8190;
|
|
427
|
-
t5 = key[10] & 255 | (key[11] & 255) << 8;
|
|
428
|
-
this.r[6] = (t4 >>> 14 | t5 << 2) & 8191;
|
|
429
|
-
t6 = key[12] & 255 | (key[13] & 255) << 8;
|
|
430
|
-
this.r[7] = (t5 >>> 11 | t6 << 5) & 8065;
|
|
431
|
-
t7 = key[14] & 255 | (key[15] & 255) << 8;
|
|
432
|
-
this.r[8] = (t6 >>> 8 | t7 << 8) & 8191;
|
|
433
|
-
this.r[9] = t7 >>> 5 & 127;
|
|
434
|
-
this.pad[0] = key[16] & 255 | (key[17] & 255) << 8;
|
|
435
|
-
this.pad[1] = key[18] & 255 | (key[19] & 255) << 8;
|
|
436
|
-
this.pad[2] = key[20] & 255 | (key[21] & 255) << 8;
|
|
437
|
-
this.pad[3] = key[22] & 255 | (key[23] & 255) << 8;
|
|
438
|
-
this.pad[4] = key[24] & 255 | (key[25] & 255) << 8;
|
|
439
|
-
this.pad[5] = key[26] & 255 | (key[27] & 255) << 8;
|
|
440
|
-
this.pad[6] = key[28] & 255 | (key[29] & 255) << 8;
|
|
441
|
-
this.pad[7] = key[30] & 255 | (key[31] & 255) << 8;
|
|
442
|
-
};
|
|
443
|
-
poly1305.prototype.blocks = function(m, mpos, bytes) {
|
|
444
|
-
var hibit = this.fin ? 0 : 1 << 11;
|
|
445
|
-
var t0, t1, t2, t3, t4, t5, t6, t7, c;
|
|
446
|
-
var d0, d1, d2, d3, d4, d5, d6, d7, d8, d9;
|
|
447
|
-
var h0 = this.h[0], h1 = this.h[1], h2 = this.h[2], h3 = this.h[3], h4 = this.h[4], h5 = this.h[5], h6 = this.h[6], h7 = this.h[7], h8 = this.h[8], h9 = this.h[9];
|
|
448
|
-
var r0 = this.r[0], r1 = this.r[1], r2 = this.r[2], r3 = this.r[3], r4 = this.r[4], r5 = this.r[5], r6 = this.r[6], r7 = this.r[7], r8 = this.r[8], r9 = this.r[9];
|
|
449
|
-
while (bytes >= 16) {
|
|
450
|
-
t0 = m[mpos + 0] & 255 | (m[mpos + 1] & 255) << 8;
|
|
451
|
-
h0 += t0 & 8191;
|
|
452
|
-
t1 = m[mpos + 2] & 255 | (m[mpos + 3] & 255) << 8;
|
|
453
|
-
h1 += (t0 >>> 13 | t1 << 3) & 8191;
|
|
454
|
-
t2 = m[mpos + 4] & 255 | (m[mpos + 5] & 255) << 8;
|
|
455
|
-
h2 += (t1 >>> 10 | t2 << 6) & 8191;
|
|
456
|
-
t3 = m[mpos + 6] & 255 | (m[mpos + 7] & 255) << 8;
|
|
457
|
-
h3 += (t2 >>> 7 | t3 << 9) & 8191;
|
|
458
|
-
t4 = m[mpos + 8] & 255 | (m[mpos + 9] & 255) << 8;
|
|
459
|
-
h4 += (t3 >>> 4 | t4 << 12) & 8191;
|
|
460
|
-
h5 += t4 >>> 1 & 8191;
|
|
461
|
-
t5 = m[mpos + 10] & 255 | (m[mpos + 11] & 255) << 8;
|
|
462
|
-
h6 += (t4 >>> 14 | t5 << 2) & 8191;
|
|
463
|
-
t6 = m[mpos + 12] & 255 | (m[mpos + 13] & 255) << 8;
|
|
464
|
-
h7 += (t5 >>> 11 | t6 << 5) & 8191;
|
|
465
|
-
t7 = m[mpos + 14] & 255 | (m[mpos + 15] & 255) << 8;
|
|
466
|
-
h8 += (t6 >>> 8 | t7 << 8) & 8191;
|
|
467
|
-
h9 += t7 >>> 5 | hibit;
|
|
468
|
-
c = 0;
|
|
469
|
-
d0 = c;
|
|
470
|
-
d0 += h0 * r0;
|
|
471
|
-
d0 += h1 * (5 * r9);
|
|
472
|
-
d0 += h2 * (5 * r8);
|
|
473
|
-
d0 += h3 * (5 * r7);
|
|
474
|
-
d0 += h4 * (5 * r6);
|
|
475
|
-
c = d0 >>> 13;
|
|
476
|
-
d0 &= 8191;
|
|
477
|
-
d0 += h5 * (5 * r5);
|
|
478
|
-
d0 += h6 * (5 * r4);
|
|
479
|
-
d0 += h7 * (5 * r3);
|
|
480
|
-
d0 += h8 * (5 * r2);
|
|
481
|
-
d0 += h9 * (5 * r1);
|
|
482
|
-
c += d0 >>> 13;
|
|
483
|
-
d0 &= 8191;
|
|
484
|
-
d1 = c;
|
|
485
|
-
d1 += h0 * r1;
|
|
486
|
-
d1 += h1 * r0;
|
|
487
|
-
d1 += h2 * (5 * r9);
|
|
488
|
-
d1 += h3 * (5 * r8);
|
|
489
|
-
d1 += h4 * (5 * r7);
|
|
490
|
-
c = d1 >>> 13;
|
|
491
|
-
d1 &= 8191;
|
|
492
|
-
d1 += h5 * (5 * r6);
|
|
493
|
-
d1 += h6 * (5 * r5);
|
|
494
|
-
d1 += h7 * (5 * r4);
|
|
495
|
-
d1 += h8 * (5 * r3);
|
|
496
|
-
d1 += h9 * (5 * r2);
|
|
497
|
-
c += d1 >>> 13;
|
|
498
|
-
d1 &= 8191;
|
|
499
|
-
d2 = c;
|
|
500
|
-
d2 += h0 * r2;
|
|
501
|
-
d2 += h1 * r1;
|
|
502
|
-
d2 += h2 * r0;
|
|
503
|
-
d2 += h3 * (5 * r9);
|
|
504
|
-
d2 += h4 * (5 * r8);
|
|
505
|
-
c = d2 >>> 13;
|
|
506
|
-
d2 &= 8191;
|
|
507
|
-
d2 += h5 * (5 * r7);
|
|
508
|
-
d2 += h6 * (5 * r6);
|
|
509
|
-
d2 += h7 * (5 * r5);
|
|
510
|
-
d2 += h8 * (5 * r4);
|
|
511
|
-
d2 += h9 * (5 * r3);
|
|
512
|
-
c += d2 >>> 13;
|
|
513
|
-
d2 &= 8191;
|
|
514
|
-
d3 = c;
|
|
515
|
-
d3 += h0 * r3;
|
|
516
|
-
d3 += h1 * r2;
|
|
517
|
-
d3 += h2 * r1;
|
|
518
|
-
d3 += h3 * r0;
|
|
519
|
-
d3 += h4 * (5 * r9);
|
|
520
|
-
c = d3 >>> 13;
|
|
521
|
-
d3 &= 8191;
|
|
522
|
-
d3 += h5 * (5 * r8);
|
|
523
|
-
d3 += h6 * (5 * r7);
|
|
524
|
-
d3 += h7 * (5 * r6);
|
|
525
|
-
d3 += h8 * (5 * r5);
|
|
526
|
-
d3 += h9 * (5 * r4);
|
|
527
|
-
c += d3 >>> 13;
|
|
528
|
-
d3 &= 8191;
|
|
529
|
-
d4 = c;
|
|
530
|
-
d4 += h0 * r4;
|
|
531
|
-
d4 += h1 * r3;
|
|
532
|
-
d4 += h2 * r2;
|
|
533
|
-
d4 += h3 * r1;
|
|
534
|
-
d4 += h4 * r0;
|
|
535
|
-
c = d4 >>> 13;
|
|
536
|
-
d4 &= 8191;
|
|
537
|
-
d4 += h5 * (5 * r9);
|
|
538
|
-
d4 += h6 * (5 * r8);
|
|
539
|
-
d4 += h7 * (5 * r7);
|
|
540
|
-
d4 += h8 * (5 * r6);
|
|
541
|
-
d4 += h9 * (5 * r5);
|
|
542
|
-
c += d4 >>> 13;
|
|
543
|
-
d4 &= 8191;
|
|
544
|
-
d5 = c;
|
|
545
|
-
d5 += h0 * r5;
|
|
546
|
-
d5 += h1 * r4;
|
|
547
|
-
d5 += h2 * r3;
|
|
548
|
-
d5 += h3 * r2;
|
|
549
|
-
d5 += h4 * r1;
|
|
550
|
-
c = d5 >>> 13;
|
|
551
|
-
d5 &= 8191;
|
|
552
|
-
d5 += h5 * r0;
|
|
553
|
-
d5 += h6 * (5 * r9);
|
|
554
|
-
d5 += h7 * (5 * r8);
|
|
555
|
-
d5 += h8 * (5 * r7);
|
|
556
|
-
d5 += h9 * (5 * r6);
|
|
557
|
-
c += d5 >>> 13;
|
|
558
|
-
d5 &= 8191;
|
|
559
|
-
d6 = c;
|
|
560
|
-
d6 += h0 * r6;
|
|
561
|
-
d6 += h1 * r5;
|
|
562
|
-
d6 += h2 * r4;
|
|
563
|
-
d6 += h3 * r3;
|
|
564
|
-
d6 += h4 * r2;
|
|
565
|
-
c = d6 >>> 13;
|
|
566
|
-
d6 &= 8191;
|
|
567
|
-
d6 += h5 * r1;
|
|
568
|
-
d6 += h6 * r0;
|
|
569
|
-
d6 += h7 * (5 * r9);
|
|
570
|
-
d6 += h8 * (5 * r8);
|
|
571
|
-
d6 += h9 * (5 * r7);
|
|
572
|
-
c += d6 >>> 13;
|
|
573
|
-
d6 &= 8191;
|
|
574
|
-
d7 = c;
|
|
575
|
-
d7 += h0 * r7;
|
|
576
|
-
d7 += h1 * r6;
|
|
577
|
-
d7 += h2 * r5;
|
|
578
|
-
d7 += h3 * r4;
|
|
579
|
-
d7 += h4 * r3;
|
|
580
|
-
c = d7 >>> 13;
|
|
581
|
-
d7 &= 8191;
|
|
582
|
-
d7 += h5 * r2;
|
|
583
|
-
d7 += h6 * r1;
|
|
584
|
-
d7 += h7 * r0;
|
|
585
|
-
d7 += h8 * (5 * r9);
|
|
586
|
-
d7 += h9 * (5 * r8);
|
|
587
|
-
c += d7 >>> 13;
|
|
588
|
-
d7 &= 8191;
|
|
589
|
-
d8 = c;
|
|
590
|
-
d8 += h0 * r8;
|
|
591
|
-
d8 += h1 * r7;
|
|
592
|
-
d8 += h2 * r6;
|
|
593
|
-
d8 += h3 * r5;
|
|
594
|
-
d8 += h4 * r4;
|
|
595
|
-
c = d8 >>> 13;
|
|
596
|
-
d8 &= 8191;
|
|
597
|
-
d8 += h5 * r3;
|
|
598
|
-
d8 += h6 * r2;
|
|
599
|
-
d8 += h7 * r1;
|
|
600
|
-
d8 += h8 * r0;
|
|
601
|
-
d8 += h9 * (5 * r9);
|
|
602
|
-
c += d8 >>> 13;
|
|
603
|
-
d8 &= 8191;
|
|
604
|
-
d9 = c;
|
|
605
|
-
d9 += h0 * r9;
|
|
606
|
-
d9 += h1 * r8;
|
|
607
|
-
d9 += h2 * r7;
|
|
608
|
-
d9 += h3 * r6;
|
|
609
|
-
d9 += h4 * r5;
|
|
610
|
-
c = d9 >>> 13;
|
|
611
|
-
d9 &= 8191;
|
|
612
|
-
d9 += h5 * r4;
|
|
613
|
-
d9 += h6 * r3;
|
|
614
|
-
d9 += h7 * r2;
|
|
615
|
-
d9 += h8 * r1;
|
|
616
|
-
d9 += h9 * r0;
|
|
617
|
-
c += d9 >>> 13;
|
|
618
|
-
d9 &= 8191;
|
|
619
|
-
c = (c << 2) + c | 0;
|
|
620
|
-
c = c + d0 | 0;
|
|
621
|
-
d0 = c & 8191;
|
|
622
|
-
c = c >>> 13;
|
|
623
|
-
d1 += c;
|
|
624
|
-
h0 = d0;
|
|
625
|
-
h1 = d1;
|
|
626
|
-
h2 = d2;
|
|
627
|
-
h3 = d3;
|
|
628
|
-
h4 = d4;
|
|
629
|
-
h5 = d5;
|
|
630
|
-
h6 = d6;
|
|
631
|
-
h7 = d7;
|
|
632
|
-
h8 = d8;
|
|
633
|
-
h9 = d9;
|
|
634
|
-
mpos += 16;
|
|
635
|
-
bytes -= 16;
|
|
636
|
-
}
|
|
637
|
-
this.h[0] = h0;
|
|
638
|
-
this.h[1] = h1;
|
|
639
|
-
this.h[2] = h2;
|
|
640
|
-
this.h[3] = h3;
|
|
641
|
-
this.h[4] = h4;
|
|
642
|
-
this.h[5] = h5;
|
|
643
|
-
this.h[6] = h6;
|
|
644
|
-
this.h[7] = h7;
|
|
645
|
-
this.h[8] = h8;
|
|
646
|
-
this.h[9] = h9;
|
|
647
|
-
};
|
|
648
|
-
poly1305.prototype.finish = function(mac, macpos) {
|
|
649
|
-
var g = new Uint16Array(10);
|
|
650
|
-
var c, mask, f, i;
|
|
651
|
-
if (this.leftover) {
|
|
652
|
-
i = this.leftover;
|
|
653
|
-
this.buffer[i++] = 1;
|
|
654
|
-
for (; i < 16; i++) this.buffer[i] = 0;
|
|
655
|
-
this.fin = 1;
|
|
656
|
-
this.blocks(this.buffer, 0, 16);
|
|
657
|
-
}
|
|
658
|
-
c = this.h[1] >>> 13;
|
|
659
|
-
this.h[1] &= 8191;
|
|
660
|
-
for (i = 2; i < 10; i++) {
|
|
661
|
-
this.h[i] += c;
|
|
662
|
-
c = this.h[i] >>> 13;
|
|
663
|
-
this.h[i] &= 8191;
|
|
664
|
-
}
|
|
665
|
-
this.h[0] += c * 5;
|
|
666
|
-
c = this.h[0] >>> 13;
|
|
667
|
-
this.h[0] &= 8191;
|
|
668
|
-
this.h[1] += c;
|
|
669
|
-
c = this.h[1] >>> 13;
|
|
670
|
-
this.h[1] &= 8191;
|
|
671
|
-
this.h[2] += c;
|
|
672
|
-
g[0] = this.h[0] + 5;
|
|
673
|
-
c = g[0] >>> 13;
|
|
674
|
-
g[0] &= 8191;
|
|
675
|
-
for (i = 1; i < 10; i++) {
|
|
676
|
-
g[i] = this.h[i] + c;
|
|
677
|
-
c = g[i] >>> 13;
|
|
678
|
-
g[i] &= 8191;
|
|
679
|
-
}
|
|
680
|
-
g[9] -= 1 << 13;
|
|
681
|
-
mask = (c ^ 1) - 1;
|
|
682
|
-
for (i = 0; i < 10; i++) g[i] &= mask;
|
|
683
|
-
mask = ~mask;
|
|
684
|
-
for (i = 0; i < 10; i++) this.h[i] = this.h[i] & mask | g[i];
|
|
685
|
-
this.h[0] = (this.h[0] | this.h[1] << 13) & 65535;
|
|
686
|
-
this.h[1] = (this.h[1] >>> 3 | this.h[2] << 10) & 65535;
|
|
687
|
-
this.h[2] = (this.h[2] >>> 6 | this.h[3] << 7) & 65535;
|
|
688
|
-
this.h[3] = (this.h[3] >>> 9 | this.h[4] << 4) & 65535;
|
|
689
|
-
this.h[4] = (this.h[4] >>> 12 | this.h[5] << 1 | this.h[6] << 14) & 65535;
|
|
690
|
-
this.h[5] = (this.h[6] >>> 2 | this.h[7] << 11) & 65535;
|
|
691
|
-
this.h[6] = (this.h[7] >>> 5 | this.h[8] << 8) & 65535;
|
|
692
|
-
this.h[7] = (this.h[8] >>> 8 | this.h[9] << 5) & 65535;
|
|
693
|
-
f = this.h[0] + this.pad[0];
|
|
694
|
-
this.h[0] = f & 65535;
|
|
695
|
-
for (i = 1; i < 8; i++) {
|
|
696
|
-
f = (this.h[i] + this.pad[i] | 0) + (f >>> 16) | 0;
|
|
697
|
-
this.h[i] = f & 65535;
|
|
698
|
-
}
|
|
699
|
-
mac[macpos + 0] = this.h[0] >>> 0 & 255;
|
|
700
|
-
mac[macpos + 1] = this.h[0] >>> 8 & 255;
|
|
701
|
-
mac[macpos + 2] = this.h[1] >>> 0 & 255;
|
|
702
|
-
mac[macpos + 3] = this.h[1] >>> 8 & 255;
|
|
703
|
-
mac[macpos + 4] = this.h[2] >>> 0 & 255;
|
|
704
|
-
mac[macpos + 5] = this.h[2] >>> 8 & 255;
|
|
705
|
-
mac[macpos + 6] = this.h[3] >>> 0 & 255;
|
|
706
|
-
mac[macpos + 7] = this.h[3] >>> 8 & 255;
|
|
707
|
-
mac[macpos + 8] = this.h[4] >>> 0 & 255;
|
|
708
|
-
mac[macpos + 9] = this.h[4] >>> 8 & 255;
|
|
709
|
-
mac[macpos + 10] = this.h[5] >>> 0 & 255;
|
|
710
|
-
mac[macpos + 11] = this.h[5] >>> 8 & 255;
|
|
711
|
-
mac[macpos + 12] = this.h[6] >>> 0 & 255;
|
|
712
|
-
mac[macpos + 13] = this.h[6] >>> 8 & 255;
|
|
713
|
-
mac[macpos + 14] = this.h[7] >>> 0 & 255;
|
|
714
|
-
mac[macpos + 15] = this.h[7] >>> 8 & 255;
|
|
715
|
-
};
|
|
716
|
-
poly1305.prototype.update = function(m, mpos, bytes) {
|
|
717
|
-
var i, want;
|
|
718
|
-
if (this.leftover) {
|
|
719
|
-
want = 16 - this.leftover;
|
|
720
|
-
if (want > bytes)
|
|
721
|
-
want = bytes;
|
|
722
|
-
for (i = 0; i < want; i++)
|
|
723
|
-
this.buffer[this.leftover + i] = m[mpos + i];
|
|
724
|
-
bytes -= want;
|
|
725
|
-
mpos += want;
|
|
726
|
-
this.leftover += want;
|
|
727
|
-
if (this.leftover < 16)
|
|
728
|
-
return;
|
|
729
|
-
this.blocks(this.buffer, 0, 16);
|
|
730
|
-
this.leftover = 0;
|
|
731
|
-
}
|
|
732
|
-
if (bytes >= 16) {
|
|
733
|
-
want = bytes - bytes % 16;
|
|
734
|
-
this.blocks(m, mpos, want);
|
|
735
|
-
mpos += want;
|
|
736
|
-
bytes -= want;
|
|
737
|
-
}
|
|
738
|
-
if (bytes) {
|
|
739
|
-
for (i = 0; i < bytes; i++)
|
|
740
|
-
this.buffer[this.leftover + i] = m[mpos + i];
|
|
741
|
-
this.leftover += bytes;
|
|
742
|
-
}
|
|
743
|
-
};
|
|
744
|
-
function crypto_onetimeauth(out, outpos, m, mpos, n, k) {
|
|
745
|
-
var s = new poly1305(k);
|
|
746
|
-
s.update(m, mpos, n);
|
|
747
|
-
s.finish(out, outpos);
|
|
748
|
-
return 0;
|
|
749
|
-
}
|
|
750
|
-
function crypto_onetimeauth_verify(h, hpos, m, mpos, n, k) {
|
|
751
|
-
var x = new Uint8Array(16);
|
|
752
|
-
crypto_onetimeauth(x, 0, m, mpos, n, k);
|
|
753
|
-
return crypto_verify_16(h, hpos, x, 0);
|
|
754
|
-
}
|
|
755
|
-
function crypto_secretbox(c, m, d, n, k) {
|
|
756
|
-
var i;
|
|
757
|
-
if (d < 32) return -1;
|
|
758
|
-
crypto_stream_xor(c, 0, m, 0, d, n, k);
|
|
759
|
-
crypto_onetimeauth(c, 16, c, 32, d - 32, c);
|
|
760
|
-
for (i = 0; i < 16; i++) c[i] = 0;
|
|
761
|
-
return 0;
|
|
762
|
-
}
|
|
763
|
-
function crypto_secretbox_open(m, c, d, n, k) {
|
|
764
|
-
var i;
|
|
765
|
-
var x = new Uint8Array(32);
|
|
766
|
-
if (d < 32) return -1;
|
|
767
|
-
crypto_stream(x, 0, 32, n, k);
|
|
768
|
-
if (crypto_onetimeauth_verify(c, 16, c, 32, d - 32, x) !== 0) return -1;
|
|
769
|
-
crypto_stream_xor(m, 0, c, 0, d, n, k);
|
|
770
|
-
for (i = 0; i < 32; i++) m[i] = 0;
|
|
771
|
-
return 0;
|
|
772
|
-
}
|
|
773
|
-
function set25519(r, a) {
|
|
774
|
-
var i;
|
|
775
|
-
for (i = 0; i < 16; i++) r[i] = a[i] | 0;
|
|
776
|
-
}
|
|
777
|
-
function car25519(o) {
|
|
778
|
-
var i, v, c = 1;
|
|
779
|
-
for (i = 0; i < 16; i++) {
|
|
780
|
-
v = o[i] + c + 65535;
|
|
781
|
-
c = Math.floor(v / 65536);
|
|
782
|
-
o[i] = v - c * 65536;
|
|
783
|
-
}
|
|
784
|
-
o[0] += c - 1 + 37 * (c - 1);
|
|
785
|
-
}
|
|
786
|
-
function sel25519(p, q, b) {
|
|
787
|
-
var t, c = ~(b - 1);
|
|
788
|
-
for (var i = 0; i < 16; i++) {
|
|
789
|
-
t = c & (p[i] ^ q[i]);
|
|
790
|
-
p[i] ^= t;
|
|
791
|
-
q[i] ^= t;
|
|
792
|
-
}
|
|
793
|
-
}
|
|
794
|
-
function pack25519(o, n) {
|
|
795
|
-
var i, j, b;
|
|
796
|
-
var m = gf(), t = gf();
|
|
797
|
-
for (i = 0; i < 16; i++) t[i] = n[i];
|
|
798
|
-
car25519(t);
|
|
799
|
-
car25519(t);
|
|
800
|
-
car25519(t);
|
|
801
|
-
for (j = 0; j < 2; j++) {
|
|
802
|
-
m[0] = t[0] - 65517;
|
|
803
|
-
for (i = 1; i < 15; i++) {
|
|
804
|
-
m[i] = t[i] - 65535 - (m[i - 1] >> 16 & 1);
|
|
805
|
-
m[i - 1] &= 65535;
|
|
806
|
-
}
|
|
807
|
-
m[15] = t[15] - 32767 - (m[14] >> 16 & 1);
|
|
808
|
-
b = m[15] >> 16 & 1;
|
|
809
|
-
m[14] &= 65535;
|
|
810
|
-
sel25519(t, m, 1 - b);
|
|
811
|
-
}
|
|
812
|
-
for (i = 0; i < 16; i++) {
|
|
813
|
-
o[2 * i] = t[i] & 255;
|
|
814
|
-
o[2 * i + 1] = t[i] >> 8;
|
|
815
|
-
}
|
|
816
|
-
}
|
|
817
|
-
function neq25519(a, b) {
|
|
818
|
-
var c = new Uint8Array(32), d = new Uint8Array(32);
|
|
819
|
-
pack25519(c, a);
|
|
820
|
-
pack25519(d, b);
|
|
821
|
-
return crypto_verify_32(c, 0, d, 0);
|
|
822
|
-
}
|
|
823
|
-
function par25519(a) {
|
|
824
|
-
var d = new Uint8Array(32);
|
|
825
|
-
pack25519(d, a);
|
|
826
|
-
return d[0] & 1;
|
|
827
|
-
}
|
|
828
|
-
function unpack25519(o, n) {
|
|
829
|
-
var i;
|
|
830
|
-
for (i = 0; i < 16; i++) o[i] = n[2 * i] + (n[2 * i + 1] << 8);
|
|
831
|
-
o[15] &= 32767;
|
|
832
|
-
}
|
|
833
|
-
function A(o, a, b) {
|
|
834
|
-
for (var i = 0; i < 16; i++) o[i] = a[i] + b[i];
|
|
835
|
-
}
|
|
836
|
-
function Z(o, a, b) {
|
|
837
|
-
for (var i = 0; i < 16; i++) o[i] = a[i] - b[i];
|
|
838
|
-
}
|
|
839
|
-
function M(o, a, b) {
|
|
840
|
-
var v, c, t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0, t8 = 0, t9 = 0, t10 = 0, t11 = 0, t12 = 0, t13 = 0, t14 = 0, t15 = 0, t16 = 0, t17 = 0, t18 = 0, t19 = 0, t20 = 0, t21 = 0, t22 = 0, t23 = 0, t24 = 0, t25 = 0, t26 = 0, t27 = 0, t28 = 0, t29 = 0, t30 = 0, b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3], b4 = b[4], b5 = b[5], b6 = b[6], b7 = b[7], b8 = b[8], b9 = b[9], b10 = b[10], b11 = b[11], b12 = b[12], b13 = b[13], b14 = b[14], b15 = b[15];
|
|
841
|
-
v = a[0];
|
|
842
|
-
t0 += v * b0;
|
|
843
|
-
t1 += v * b1;
|
|
844
|
-
t2 += v * b2;
|
|
845
|
-
t3 += v * b3;
|
|
846
|
-
t4 += v * b4;
|
|
847
|
-
t5 += v * b5;
|
|
848
|
-
t6 += v * b6;
|
|
849
|
-
t7 += v * b7;
|
|
850
|
-
t8 += v * b8;
|
|
851
|
-
t9 += v * b9;
|
|
852
|
-
t10 += v * b10;
|
|
853
|
-
t11 += v * b11;
|
|
854
|
-
t12 += v * b12;
|
|
855
|
-
t13 += v * b13;
|
|
856
|
-
t14 += v * b14;
|
|
857
|
-
t15 += v * b15;
|
|
858
|
-
v = a[1];
|
|
859
|
-
t1 += v * b0;
|
|
860
|
-
t2 += v * b1;
|
|
861
|
-
t3 += v * b2;
|
|
862
|
-
t4 += v * b3;
|
|
863
|
-
t5 += v * b4;
|
|
864
|
-
t6 += v * b5;
|
|
865
|
-
t7 += v * b6;
|
|
866
|
-
t8 += v * b7;
|
|
867
|
-
t9 += v * b8;
|
|
868
|
-
t10 += v * b9;
|
|
869
|
-
t11 += v * b10;
|
|
870
|
-
t12 += v * b11;
|
|
871
|
-
t13 += v * b12;
|
|
872
|
-
t14 += v * b13;
|
|
873
|
-
t15 += v * b14;
|
|
874
|
-
t16 += v * b15;
|
|
875
|
-
v = a[2];
|
|
876
|
-
t2 += v * b0;
|
|
877
|
-
t3 += v * b1;
|
|
878
|
-
t4 += v * b2;
|
|
879
|
-
t5 += v * b3;
|
|
880
|
-
t6 += v * b4;
|
|
881
|
-
t7 += v * b5;
|
|
882
|
-
t8 += v * b6;
|
|
883
|
-
t9 += v * b7;
|
|
884
|
-
t10 += v * b8;
|
|
885
|
-
t11 += v * b9;
|
|
886
|
-
t12 += v * b10;
|
|
887
|
-
t13 += v * b11;
|
|
888
|
-
t14 += v * b12;
|
|
889
|
-
t15 += v * b13;
|
|
890
|
-
t16 += v * b14;
|
|
891
|
-
t17 += v * b15;
|
|
892
|
-
v = a[3];
|
|
893
|
-
t3 += v * b0;
|
|
894
|
-
t4 += v * b1;
|
|
895
|
-
t5 += v * b2;
|
|
896
|
-
t6 += v * b3;
|
|
897
|
-
t7 += v * b4;
|
|
898
|
-
t8 += v * b5;
|
|
899
|
-
t9 += v * b6;
|
|
900
|
-
t10 += v * b7;
|
|
901
|
-
t11 += v * b8;
|
|
902
|
-
t12 += v * b9;
|
|
903
|
-
t13 += v * b10;
|
|
904
|
-
t14 += v * b11;
|
|
905
|
-
t15 += v * b12;
|
|
906
|
-
t16 += v * b13;
|
|
907
|
-
t17 += v * b14;
|
|
908
|
-
t18 += v * b15;
|
|
909
|
-
v = a[4];
|
|
910
|
-
t4 += v * b0;
|
|
911
|
-
t5 += v * b1;
|
|
912
|
-
t6 += v * b2;
|
|
913
|
-
t7 += v * b3;
|
|
914
|
-
t8 += v * b4;
|
|
915
|
-
t9 += v * b5;
|
|
916
|
-
t10 += v * b6;
|
|
917
|
-
t11 += v * b7;
|
|
918
|
-
t12 += v * b8;
|
|
919
|
-
t13 += v * b9;
|
|
920
|
-
t14 += v * b10;
|
|
921
|
-
t15 += v * b11;
|
|
922
|
-
t16 += v * b12;
|
|
923
|
-
t17 += v * b13;
|
|
924
|
-
t18 += v * b14;
|
|
925
|
-
t19 += v * b15;
|
|
926
|
-
v = a[5];
|
|
927
|
-
t5 += v * b0;
|
|
928
|
-
t6 += v * b1;
|
|
929
|
-
t7 += v * b2;
|
|
930
|
-
t8 += v * b3;
|
|
931
|
-
t9 += v * b4;
|
|
932
|
-
t10 += v * b5;
|
|
933
|
-
t11 += v * b6;
|
|
934
|
-
t12 += v * b7;
|
|
935
|
-
t13 += v * b8;
|
|
936
|
-
t14 += v * b9;
|
|
937
|
-
t15 += v * b10;
|
|
938
|
-
t16 += v * b11;
|
|
939
|
-
t17 += v * b12;
|
|
940
|
-
t18 += v * b13;
|
|
941
|
-
t19 += v * b14;
|
|
942
|
-
t20 += v * b15;
|
|
943
|
-
v = a[6];
|
|
944
|
-
t6 += v * b0;
|
|
945
|
-
t7 += v * b1;
|
|
946
|
-
t8 += v * b2;
|
|
947
|
-
t9 += v * b3;
|
|
948
|
-
t10 += v * b4;
|
|
949
|
-
t11 += v * b5;
|
|
950
|
-
t12 += v * b6;
|
|
951
|
-
t13 += v * b7;
|
|
952
|
-
t14 += v * b8;
|
|
953
|
-
t15 += v * b9;
|
|
954
|
-
t16 += v * b10;
|
|
955
|
-
t17 += v * b11;
|
|
956
|
-
t18 += v * b12;
|
|
957
|
-
t19 += v * b13;
|
|
958
|
-
t20 += v * b14;
|
|
959
|
-
t21 += v * b15;
|
|
960
|
-
v = a[7];
|
|
961
|
-
t7 += v * b0;
|
|
962
|
-
t8 += v * b1;
|
|
963
|
-
t9 += v * b2;
|
|
964
|
-
t10 += v * b3;
|
|
965
|
-
t11 += v * b4;
|
|
966
|
-
t12 += v * b5;
|
|
967
|
-
t13 += v * b6;
|
|
968
|
-
t14 += v * b7;
|
|
969
|
-
t15 += v * b8;
|
|
970
|
-
t16 += v * b9;
|
|
971
|
-
t17 += v * b10;
|
|
972
|
-
t18 += v * b11;
|
|
973
|
-
t19 += v * b12;
|
|
974
|
-
t20 += v * b13;
|
|
975
|
-
t21 += v * b14;
|
|
976
|
-
t22 += v * b15;
|
|
977
|
-
v = a[8];
|
|
978
|
-
t8 += v * b0;
|
|
979
|
-
t9 += v * b1;
|
|
980
|
-
t10 += v * b2;
|
|
981
|
-
t11 += v * b3;
|
|
982
|
-
t12 += v * b4;
|
|
983
|
-
t13 += v * b5;
|
|
984
|
-
t14 += v * b6;
|
|
985
|
-
t15 += v * b7;
|
|
986
|
-
t16 += v * b8;
|
|
987
|
-
t17 += v * b9;
|
|
988
|
-
t18 += v * b10;
|
|
989
|
-
t19 += v * b11;
|
|
990
|
-
t20 += v * b12;
|
|
991
|
-
t21 += v * b13;
|
|
992
|
-
t22 += v * b14;
|
|
993
|
-
t23 += v * b15;
|
|
994
|
-
v = a[9];
|
|
995
|
-
t9 += v * b0;
|
|
996
|
-
t10 += v * b1;
|
|
997
|
-
t11 += v * b2;
|
|
998
|
-
t12 += v * b3;
|
|
999
|
-
t13 += v * b4;
|
|
1000
|
-
t14 += v * b5;
|
|
1001
|
-
t15 += v * b6;
|
|
1002
|
-
t16 += v * b7;
|
|
1003
|
-
t17 += v * b8;
|
|
1004
|
-
t18 += v * b9;
|
|
1005
|
-
t19 += v * b10;
|
|
1006
|
-
t20 += v * b11;
|
|
1007
|
-
t21 += v * b12;
|
|
1008
|
-
t22 += v * b13;
|
|
1009
|
-
t23 += v * b14;
|
|
1010
|
-
t24 += v * b15;
|
|
1011
|
-
v = a[10];
|
|
1012
|
-
t10 += v * b0;
|
|
1013
|
-
t11 += v * b1;
|
|
1014
|
-
t12 += v * b2;
|
|
1015
|
-
t13 += v * b3;
|
|
1016
|
-
t14 += v * b4;
|
|
1017
|
-
t15 += v * b5;
|
|
1018
|
-
t16 += v * b6;
|
|
1019
|
-
t17 += v * b7;
|
|
1020
|
-
t18 += v * b8;
|
|
1021
|
-
t19 += v * b9;
|
|
1022
|
-
t20 += v * b10;
|
|
1023
|
-
t21 += v * b11;
|
|
1024
|
-
t22 += v * b12;
|
|
1025
|
-
t23 += v * b13;
|
|
1026
|
-
t24 += v * b14;
|
|
1027
|
-
t25 += v * b15;
|
|
1028
|
-
v = a[11];
|
|
1029
|
-
t11 += v * b0;
|
|
1030
|
-
t12 += v * b1;
|
|
1031
|
-
t13 += v * b2;
|
|
1032
|
-
t14 += v * b3;
|
|
1033
|
-
t15 += v * b4;
|
|
1034
|
-
t16 += v * b5;
|
|
1035
|
-
t17 += v * b6;
|
|
1036
|
-
t18 += v * b7;
|
|
1037
|
-
t19 += v * b8;
|
|
1038
|
-
t20 += v * b9;
|
|
1039
|
-
t21 += v * b10;
|
|
1040
|
-
t22 += v * b11;
|
|
1041
|
-
t23 += v * b12;
|
|
1042
|
-
t24 += v * b13;
|
|
1043
|
-
t25 += v * b14;
|
|
1044
|
-
t26 += v * b15;
|
|
1045
|
-
v = a[12];
|
|
1046
|
-
t12 += v * b0;
|
|
1047
|
-
t13 += v * b1;
|
|
1048
|
-
t14 += v * b2;
|
|
1049
|
-
t15 += v * b3;
|
|
1050
|
-
t16 += v * b4;
|
|
1051
|
-
t17 += v * b5;
|
|
1052
|
-
t18 += v * b6;
|
|
1053
|
-
t19 += v * b7;
|
|
1054
|
-
t20 += v * b8;
|
|
1055
|
-
t21 += v * b9;
|
|
1056
|
-
t22 += v * b10;
|
|
1057
|
-
t23 += v * b11;
|
|
1058
|
-
t24 += v * b12;
|
|
1059
|
-
t25 += v * b13;
|
|
1060
|
-
t26 += v * b14;
|
|
1061
|
-
t27 += v * b15;
|
|
1062
|
-
v = a[13];
|
|
1063
|
-
t13 += v * b0;
|
|
1064
|
-
t14 += v * b1;
|
|
1065
|
-
t15 += v * b2;
|
|
1066
|
-
t16 += v * b3;
|
|
1067
|
-
t17 += v * b4;
|
|
1068
|
-
t18 += v * b5;
|
|
1069
|
-
t19 += v * b6;
|
|
1070
|
-
t20 += v * b7;
|
|
1071
|
-
t21 += v * b8;
|
|
1072
|
-
t22 += v * b9;
|
|
1073
|
-
t23 += v * b10;
|
|
1074
|
-
t24 += v * b11;
|
|
1075
|
-
t25 += v * b12;
|
|
1076
|
-
t26 += v * b13;
|
|
1077
|
-
t27 += v * b14;
|
|
1078
|
-
t28 += v * b15;
|
|
1079
|
-
v = a[14];
|
|
1080
|
-
t14 += v * b0;
|
|
1081
|
-
t15 += v * b1;
|
|
1082
|
-
t16 += v * b2;
|
|
1083
|
-
t17 += v * b3;
|
|
1084
|
-
t18 += v * b4;
|
|
1085
|
-
t19 += v * b5;
|
|
1086
|
-
t20 += v * b6;
|
|
1087
|
-
t21 += v * b7;
|
|
1088
|
-
t22 += v * b8;
|
|
1089
|
-
t23 += v * b9;
|
|
1090
|
-
t24 += v * b10;
|
|
1091
|
-
t25 += v * b11;
|
|
1092
|
-
t26 += v * b12;
|
|
1093
|
-
t27 += v * b13;
|
|
1094
|
-
t28 += v * b14;
|
|
1095
|
-
t29 += v * b15;
|
|
1096
|
-
v = a[15];
|
|
1097
|
-
t15 += v * b0;
|
|
1098
|
-
t16 += v * b1;
|
|
1099
|
-
t17 += v * b2;
|
|
1100
|
-
t18 += v * b3;
|
|
1101
|
-
t19 += v * b4;
|
|
1102
|
-
t20 += v * b5;
|
|
1103
|
-
t21 += v * b6;
|
|
1104
|
-
t22 += v * b7;
|
|
1105
|
-
t23 += v * b8;
|
|
1106
|
-
t24 += v * b9;
|
|
1107
|
-
t25 += v * b10;
|
|
1108
|
-
t26 += v * b11;
|
|
1109
|
-
t27 += v * b12;
|
|
1110
|
-
t28 += v * b13;
|
|
1111
|
-
t29 += v * b14;
|
|
1112
|
-
t30 += v * b15;
|
|
1113
|
-
t0 += 38 * t16;
|
|
1114
|
-
t1 += 38 * t17;
|
|
1115
|
-
t2 += 38 * t18;
|
|
1116
|
-
t3 += 38 * t19;
|
|
1117
|
-
t4 += 38 * t20;
|
|
1118
|
-
t5 += 38 * t21;
|
|
1119
|
-
t6 += 38 * t22;
|
|
1120
|
-
t7 += 38 * t23;
|
|
1121
|
-
t8 += 38 * t24;
|
|
1122
|
-
t9 += 38 * t25;
|
|
1123
|
-
t10 += 38 * t26;
|
|
1124
|
-
t11 += 38 * t27;
|
|
1125
|
-
t12 += 38 * t28;
|
|
1126
|
-
t13 += 38 * t29;
|
|
1127
|
-
t14 += 38 * t30;
|
|
1128
|
-
c = 1;
|
|
1129
|
-
v = t0 + c + 65535;
|
|
1130
|
-
c = Math.floor(v / 65536);
|
|
1131
|
-
t0 = v - c * 65536;
|
|
1132
|
-
v = t1 + c + 65535;
|
|
1133
|
-
c = Math.floor(v / 65536);
|
|
1134
|
-
t1 = v - c * 65536;
|
|
1135
|
-
v = t2 + c + 65535;
|
|
1136
|
-
c = Math.floor(v / 65536);
|
|
1137
|
-
t2 = v - c * 65536;
|
|
1138
|
-
v = t3 + c + 65535;
|
|
1139
|
-
c = Math.floor(v / 65536);
|
|
1140
|
-
t3 = v - c * 65536;
|
|
1141
|
-
v = t4 + c + 65535;
|
|
1142
|
-
c = Math.floor(v / 65536);
|
|
1143
|
-
t4 = v - c * 65536;
|
|
1144
|
-
v = t5 + c + 65535;
|
|
1145
|
-
c = Math.floor(v / 65536);
|
|
1146
|
-
t5 = v - c * 65536;
|
|
1147
|
-
v = t6 + c + 65535;
|
|
1148
|
-
c = Math.floor(v / 65536);
|
|
1149
|
-
t6 = v - c * 65536;
|
|
1150
|
-
v = t7 + c + 65535;
|
|
1151
|
-
c = Math.floor(v / 65536);
|
|
1152
|
-
t7 = v - c * 65536;
|
|
1153
|
-
v = t8 + c + 65535;
|
|
1154
|
-
c = Math.floor(v / 65536);
|
|
1155
|
-
t8 = v - c * 65536;
|
|
1156
|
-
v = t9 + c + 65535;
|
|
1157
|
-
c = Math.floor(v / 65536);
|
|
1158
|
-
t9 = v - c * 65536;
|
|
1159
|
-
v = t10 + c + 65535;
|
|
1160
|
-
c = Math.floor(v / 65536);
|
|
1161
|
-
t10 = v - c * 65536;
|
|
1162
|
-
v = t11 + c + 65535;
|
|
1163
|
-
c = Math.floor(v / 65536);
|
|
1164
|
-
t11 = v - c * 65536;
|
|
1165
|
-
v = t12 + c + 65535;
|
|
1166
|
-
c = Math.floor(v / 65536);
|
|
1167
|
-
t12 = v - c * 65536;
|
|
1168
|
-
v = t13 + c + 65535;
|
|
1169
|
-
c = Math.floor(v / 65536);
|
|
1170
|
-
t13 = v - c * 65536;
|
|
1171
|
-
v = t14 + c + 65535;
|
|
1172
|
-
c = Math.floor(v / 65536);
|
|
1173
|
-
t14 = v - c * 65536;
|
|
1174
|
-
v = t15 + c + 65535;
|
|
1175
|
-
c = Math.floor(v / 65536);
|
|
1176
|
-
t15 = v - c * 65536;
|
|
1177
|
-
t0 += c - 1 + 37 * (c - 1);
|
|
1178
|
-
c = 1;
|
|
1179
|
-
v = t0 + c + 65535;
|
|
1180
|
-
c = Math.floor(v / 65536);
|
|
1181
|
-
t0 = v - c * 65536;
|
|
1182
|
-
v = t1 + c + 65535;
|
|
1183
|
-
c = Math.floor(v / 65536);
|
|
1184
|
-
t1 = v - c * 65536;
|
|
1185
|
-
v = t2 + c + 65535;
|
|
1186
|
-
c = Math.floor(v / 65536);
|
|
1187
|
-
t2 = v - c * 65536;
|
|
1188
|
-
v = t3 + c + 65535;
|
|
1189
|
-
c = Math.floor(v / 65536);
|
|
1190
|
-
t3 = v - c * 65536;
|
|
1191
|
-
v = t4 + c + 65535;
|
|
1192
|
-
c = Math.floor(v / 65536);
|
|
1193
|
-
t4 = v - c * 65536;
|
|
1194
|
-
v = t5 + c + 65535;
|
|
1195
|
-
c = Math.floor(v / 65536);
|
|
1196
|
-
t5 = v - c * 65536;
|
|
1197
|
-
v = t6 + c + 65535;
|
|
1198
|
-
c = Math.floor(v / 65536);
|
|
1199
|
-
t6 = v - c * 65536;
|
|
1200
|
-
v = t7 + c + 65535;
|
|
1201
|
-
c = Math.floor(v / 65536);
|
|
1202
|
-
t7 = v - c * 65536;
|
|
1203
|
-
v = t8 + c + 65535;
|
|
1204
|
-
c = Math.floor(v / 65536);
|
|
1205
|
-
t8 = v - c * 65536;
|
|
1206
|
-
v = t9 + c + 65535;
|
|
1207
|
-
c = Math.floor(v / 65536);
|
|
1208
|
-
t9 = v - c * 65536;
|
|
1209
|
-
v = t10 + c + 65535;
|
|
1210
|
-
c = Math.floor(v / 65536);
|
|
1211
|
-
t10 = v - c * 65536;
|
|
1212
|
-
v = t11 + c + 65535;
|
|
1213
|
-
c = Math.floor(v / 65536);
|
|
1214
|
-
t11 = v - c * 65536;
|
|
1215
|
-
v = t12 + c + 65535;
|
|
1216
|
-
c = Math.floor(v / 65536);
|
|
1217
|
-
t12 = v - c * 65536;
|
|
1218
|
-
v = t13 + c + 65535;
|
|
1219
|
-
c = Math.floor(v / 65536);
|
|
1220
|
-
t13 = v - c * 65536;
|
|
1221
|
-
v = t14 + c + 65535;
|
|
1222
|
-
c = Math.floor(v / 65536);
|
|
1223
|
-
t14 = v - c * 65536;
|
|
1224
|
-
v = t15 + c + 65535;
|
|
1225
|
-
c = Math.floor(v / 65536);
|
|
1226
|
-
t15 = v - c * 65536;
|
|
1227
|
-
t0 += c - 1 + 37 * (c - 1);
|
|
1228
|
-
o[0] = t0;
|
|
1229
|
-
o[1] = t1;
|
|
1230
|
-
o[2] = t2;
|
|
1231
|
-
o[3] = t3;
|
|
1232
|
-
o[4] = t4;
|
|
1233
|
-
o[5] = t5;
|
|
1234
|
-
o[6] = t6;
|
|
1235
|
-
o[7] = t7;
|
|
1236
|
-
o[8] = t8;
|
|
1237
|
-
o[9] = t9;
|
|
1238
|
-
o[10] = t10;
|
|
1239
|
-
o[11] = t11;
|
|
1240
|
-
o[12] = t12;
|
|
1241
|
-
o[13] = t13;
|
|
1242
|
-
o[14] = t14;
|
|
1243
|
-
o[15] = t15;
|
|
1244
|
-
}
|
|
1245
|
-
function S(o, a) {
|
|
1246
|
-
M(o, a, a);
|
|
1247
|
-
}
|
|
1248
|
-
function inv25519(o, i) {
|
|
1249
|
-
var c = gf();
|
|
1250
|
-
var a;
|
|
1251
|
-
for (a = 0; a < 16; a++) c[a] = i[a];
|
|
1252
|
-
for (a = 253; a >= 0; a--) {
|
|
1253
|
-
S(c, c);
|
|
1254
|
-
if (a !== 2 && a !== 4) M(c, c, i);
|
|
1255
|
-
}
|
|
1256
|
-
for (a = 0; a < 16; a++) o[a] = c[a];
|
|
1257
|
-
}
|
|
1258
|
-
function pow2523(o, i) {
|
|
1259
|
-
var c = gf();
|
|
1260
|
-
var a;
|
|
1261
|
-
for (a = 0; a < 16; a++) c[a] = i[a];
|
|
1262
|
-
for (a = 250; a >= 0; a--) {
|
|
1263
|
-
S(c, c);
|
|
1264
|
-
if (a !== 1) M(c, c, i);
|
|
1265
|
-
}
|
|
1266
|
-
for (a = 0; a < 16; a++) o[a] = c[a];
|
|
1267
|
-
}
|
|
1268
|
-
function crypto_scalarmult(q, n, p) {
|
|
1269
|
-
var z4 = new Uint8Array(32);
|
|
1270
|
-
var x = new Float64Array(80), r, i;
|
|
1271
|
-
var a = gf(), b = gf(), c = gf(), d = gf(), e = gf(), f = gf();
|
|
1272
|
-
for (i = 0; i < 31; i++) z4[i] = n[i];
|
|
1273
|
-
z4[31] = n[31] & 127 | 64;
|
|
1274
|
-
z4[0] &= 248;
|
|
1275
|
-
unpack25519(x, p);
|
|
1276
|
-
for (i = 0; i < 16; i++) {
|
|
1277
|
-
b[i] = x[i];
|
|
1278
|
-
d[i] = a[i] = c[i] = 0;
|
|
1279
|
-
}
|
|
1280
|
-
a[0] = d[0] = 1;
|
|
1281
|
-
for (i = 254; i >= 0; --i) {
|
|
1282
|
-
r = z4[i >>> 3] >>> (i & 7) & 1;
|
|
1283
|
-
sel25519(a, b, r);
|
|
1284
|
-
sel25519(c, d, r);
|
|
1285
|
-
A(e, a, c);
|
|
1286
|
-
Z(a, a, c);
|
|
1287
|
-
A(c, b, d);
|
|
1288
|
-
Z(b, b, d);
|
|
1289
|
-
S(d, e);
|
|
1290
|
-
S(f, a);
|
|
1291
|
-
M(a, c, a);
|
|
1292
|
-
M(c, b, e);
|
|
1293
|
-
A(e, a, c);
|
|
1294
|
-
Z(a, a, c);
|
|
1295
|
-
S(b, a);
|
|
1296
|
-
Z(c, d, f);
|
|
1297
|
-
M(a, c, _121665);
|
|
1298
|
-
A(a, a, d);
|
|
1299
|
-
M(c, c, a);
|
|
1300
|
-
M(a, d, f);
|
|
1301
|
-
M(d, b, x);
|
|
1302
|
-
S(b, e);
|
|
1303
|
-
sel25519(a, b, r);
|
|
1304
|
-
sel25519(c, d, r);
|
|
1305
|
-
}
|
|
1306
|
-
for (i = 0; i < 16; i++) {
|
|
1307
|
-
x[i + 16] = a[i];
|
|
1308
|
-
x[i + 32] = c[i];
|
|
1309
|
-
x[i + 48] = b[i];
|
|
1310
|
-
x[i + 64] = d[i];
|
|
1311
|
-
}
|
|
1312
|
-
var x32 = x.subarray(32);
|
|
1313
|
-
var x16 = x.subarray(16);
|
|
1314
|
-
inv25519(x32, x32);
|
|
1315
|
-
M(x16, x16, x32);
|
|
1316
|
-
pack25519(q, x16);
|
|
1317
|
-
return 0;
|
|
1318
|
-
}
|
|
1319
|
-
function crypto_scalarmult_base(q, n) {
|
|
1320
|
-
return crypto_scalarmult(q, n, _9);
|
|
1321
|
-
}
|
|
1322
|
-
function crypto_box_keypair(y, x) {
|
|
1323
|
-
randombytes(x, 32);
|
|
1324
|
-
return crypto_scalarmult_base(y, x);
|
|
1325
|
-
}
|
|
1326
|
-
function crypto_box_beforenm(k, y, x) {
|
|
1327
|
-
var s = new Uint8Array(32);
|
|
1328
|
-
crypto_scalarmult(s, x, y);
|
|
1329
|
-
return crypto_core_hsalsa20(k, _0, s, sigma);
|
|
1330
|
-
}
|
|
1331
|
-
var crypto_box_afternm = crypto_secretbox;
|
|
1332
|
-
var crypto_box_open_afternm = crypto_secretbox_open;
|
|
1333
|
-
function crypto_box(c, m, d, n, y, x) {
|
|
1334
|
-
var k = new Uint8Array(32);
|
|
1335
|
-
crypto_box_beforenm(k, y, x);
|
|
1336
|
-
return crypto_box_afternm(c, m, d, n, k);
|
|
1337
|
-
}
|
|
1338
|
-
function crypto_box_open(m, c, d, n, y, x) {
|
|
1339
|
-
var k = new Uint8Array(32);
|
|
1340
|
-
crypto_box_beforenm(k, y, x);
|
|
1341
|
-
return crypto_box_open_afternm(m, c, d, n, k);
|
|
1342
|
-
}
|
|
1343
|
-
var K = [
|
|
1344
|
-
1116352408,
|
|
1345
|
-
3609767458,
|
|
1346
|
-
1899447441,
|
|
1347
|
-
602891725,
|
|
1348
|
-
3049323471,
|
|
1349
|
-
3964484399,
|
|
1350
|
-
3921009573,
|
|
1351
|
-
2173295548,
|
|
1352
|
-
961987163,
|
|
1353
|
-
4081628472,
|
|
1354
|
-
1508970993,
|
|
1355
|
-
3053834265,
|
|
1356
|
-
2453635748,
|
|
1357
|
-
2937671579,
|
|
1358
|
-
2870763221,
|
|
1359
|
-
3664609560,
|
|
1360
|
-
3624381080,
|
|
1361
|
-
2734883394,
|
|
1362
|
-
310598401,
|
|
1363
|
-
1164996542,
|
|
1364
|
-
607225278,
|
|
1365
|
-
1323610764,
|
|
1366
|
-
1426881987,
|
|
1367
|
-
3590304994,
|
|
1368
|
-
1925078388,
|
|
1369
|
-
4068182383,
|
|
1370
|
-
2162078206,
|
|
1371
|
-
991336113,
|
|
1372
|
-
2614888103,
|
|
1373
|
-
633803317,
|
|
1374
|
-
3248222580,
|
|
1375
|
-
3479774868,
|
|
1376
|
-
3835390401,
|
|
1377
|
-
2666613458,
|
|
1378
|
-
4022224774,
|
|
1379
|
-
944711139,
|
|
1380
|
-
264347078,
|
|
1381
|
-
2341262773,
|
|
1382
|
-
604807628,
|
|
1383
|
-
2007800933,
|
|
1384
|
-
770255983,
|
|
1385
|
-
1495990901,
|
|
1386
|
-
1249150122,
|
|
1387
|
-
1856431235,
|
|
1388
|
-
1555081692,
|
|
1389
|
-
3175218132,
|
|
1390
|
-
1996064986,
|
|
1391
|
-
2198950837,
|
|
1392
|
-
2554220882,
|
|
1393
|
-
3999719339,
|
|
1394
|
-
2821834349,
|
|
1395
|
-
766784016,
|
|
1396
|
-
2952996808,
|
|
1397
|
-
2566594879,
|
|
1398
|
-
3210313671,
|
|
1399
|
-
3203337956,
|
|
1400
|
-
3336571891,
|
|
1401
|
-
1034457026,
|
|
1402
|
-
3584528711,
|
|
1403
|
-
2466948901,
|
|
1404
|
-
113926993,
|
|
1405
|
-
3758326383,
|
|
1406
|
-
338241895,
|
|
1407
|
-
168717936,
|
|
1408
|
-
666307205,
|
|
1409
|
-
1188179964,
|
|
1410
|
-
773529912,
|
|
1411
|
-
1546045734,
|
|
1412
|
-
1294757372,
|
|
1413
|
-
1522805485,
|
|
1414
|
-
1396182291,
|
|
1415
|
-
2643833823,
|
|
1416
|
-
1695183700,
|
|
1417
|
-
2343527390,
|
|
1418
|
-
1986661051,
|
|
1419
|
-
1014477480,
|
|
1420
|
-
2177026350,
|
|
1421
|
-
1206759142,
|
|
1422
|
-
2456956037,
|
|
1423
|
-
344077627,
|
|
1424
|
-
2730485921,
|
|
1425
|
-
1290863460,
|
|
1426
|
-
2820302411,
|
|
1427
|
-
3158454273,
|
|
1428
|
-
3259730800,
|
|
1429
|
-
3505952657,
|
|
1430
|
-
3345764771,
|
|
1431
|
-
106217008,
|
|
1432
|
-
3516065817,
|
|
1433
|
-
3606008344,
|
|
1434
|
-
3600352804,
|
|
1435
|
-
1432725776,
|
|
1436
|
-
4094571909,
|
|
1437
|
-
1467031594,
|
|
1438
|
-
275423344,
|
|
1439
|
-
851169720,
|
|
1440
|
-
430227734,
|
|
1441
|
-
3100823752,
|
|
1442
|
-
506948616,
|
|
1443
|
-
1363258195,
|
|
1444
|
-
659060556,
|
|
1445
|
-
3750685593,
|
|
1446
|
-
883997877,
|
|
1447
|
-
3785050280,
|
|
1448
|
-
958139571,
|
|
1449
|
-
3318307427,
|
|
1450
|
-
1322822218,
|
|
1451
|
-
3812723403,
|
|
1452
|
-
1537002063,
|
|
1453
|
-
2003034995,
|
|
1454
|
-
1747873779,
|
|
1455
|
-
3602036899,
|
|
1456
|
-
1955562222,
|
|
1457
|
-
1575990012,
|
|
1458
|
-
2024104815,
|
|
1459
|
-
1125592928,
|
|
1460
|
-
2227730452,
|
|
1461
|
-
2716904306,
|
|
1462
|
-
2361852424,
|
|
1463
|
-
442776044,
|
|
1464
|
-
2428436474,
|
|
1465
|
-
593698344,
|
|
1466
|
-
2756734187,
|
|
1467
|
-
3733110249,
|
|
1468
|
-
3204031479,
|
|
1469
|
-
2999351573,
|
|
1470
|
-
3329325298,
|
|
1471
|
-
3815920427,
|
|
1472
|
-
3391569614,
|
|
1473
|
-
3928383900,
|
|
1474
|
-
3515267271,
|
|
1475
|
-
566280711,
|
|
1476
|
-
3940187606,
|
|
1477
|
-
3454069534,
|
|
1478
|
-
4118630271,
|
|
1479
|
-
4000239992,
|
|
1480
|
-
116418474,
|
|
1481
|
-
1914138554,
|
|
1482
|
-
174292421,
|
|
1483
|
-
2731055270,
|
|
1484
|
-
289380356,
|
|
1485
|
-
3203993006,
|
|
1486
|
-
460393269,
|
|
1487
|
-
320620315,
|
|
1488
|
-
685471733,
|
|
1489
|
-
587496836,
|
|
1490
|
-
852142971,
|
|
1491
|
-
1086792851,
|
|
1492
|
-
1017036298,
|
|
1493
|
-
365543100,
|
|
1494
|
-
1126000580,
|
|
1495
|
-
2618297676,
|
|
1496
|
-
1288033470,
|
|
1497
|
-
3409855158,
|
|
1498
|
-
1501505948,
|
|
1499
|
-
4234509866,
|
|
1500
|
-
1607167915,
|
|
1501
|
-
987167468,
|
|
1502
|
-
1816402316,
|
|
1503
|
-
1246189591
|
|
1504
|
-
];
|
|
1505
|
-
function crypto_hashblocks_hl(hh, hl, m, n) {
|
|
1506
|
-
var wh = new Int32Array(16), wl = new Int32Array(16), bh0, bh1, bh2, bh3, bh4, bh5, bh6, bh7, bl0, bl1, bl2, bl3, bl4, bl5, bl6, bl7, th, tl, i, j, h, l, a, b, c, d;
|
|
1507
|
-
var ah0 = hh[0], ah1 = hh[1], ah2 = hh[2], ah3 = hh[3], ah4 = hh[4], ah5 = hh[5], ah6 = hh[6], ah7 = hh[7], al0 = hl[0], al1 = hl[1], al2 = hl[2], al3 = hl[3], al4 = hl[4], al5 = hl[5], al6 = hl[6], al7 = hl[7];
|
|
1508
|
-
var pos = 0;
|
|
1509
|
-
while (n >= 128) {
|
|
1510
|
-
for (i = 0; i < 16; i++) {
|
|
1511
|
-
j = 8 * i + pos;
|
|
1512
|
-
wh[i] = m[j + 0] << 24 | m[j + 1] << 16 | m[j + 2] << 8 | m[j + 3];
|
|
1513
|
-
wl[i] = m[j + 4] << 24 | m[j + 5] << 16 | m[j + 6] << 8 | m[j + 7];
|
|
1514
|
-
}
|
|
1515
|
-
for (i = 0; i < 80; i++) {
|
|
1516
|
-
bh0 = ah0;
|
|
1517
|
-
bh1 = ah1;
|
|
1518
|
-
bh2 = ah2;
|
|
1519
|
-
bh3 = ah3;
|
|
1520
|
-
bh4 = ah4;
|
|
1521
|
-
bh5 = ah5;
|
|
1522
|
-
bh6 = ah6;
|
|
1523
|
-
bh7 = ah7;
|
|
1524
|
-
bl0 = al0;
|
|
1525
|
-
bl1 = al1;
|
|
1526
|
-
bl2 = al2;
|
|
1527
|
-
bl3 = al3;
|
|
1528
|
-
bl4 = al4;
|
|
1529
|
-
bl5 = al5;
|
|
1530
|
-
bl6 = al6;
|
|
1531
|
-
bl7 = al7;
|
|
1532
|
-
h = ah7;
|
|
1533
|
-
l = al7;
|
|
1534
|
-
a = l & 65535;
|
|
1535
|
-
b = l >>> 16;
|
|
1536
|
-
c = h & 65535;
|
|
1537
|
-
d = h >>> 16;
|
|
1538
|
-
h = (ah4 >>> 14 | al4 << 32 - 14) ^ (ah4 >>> 18 | al4 << 32 - 18) ^ (al4 >>> 41 - 32 | ah4 << 32 - (41 - 32));
|
|
1539
|
-
l = (al4 >>> 14 | ah4 << 32 - 14) ^ (al4 >>> 18 | ah4 << 32 - 18) ^ (ah4 >>> 41 - 32 | al4 << 32 - (41 - 32));
|
|
1540
|
-
a += l & 65535;
|
|
1541
|
-
b += l >>> 16;
|
|
1542
|
-
c += h & 65535;
|
|
1543
|
-
d += h >>> 16;
|
|
1544
|
-
h = ah4 & ah5 ^ ~ah4 & ah6;
|
|
1545
|
-
l = al4 & al5 ^ ~al4 & al6;
|
|
1546
|
-
a += l & 65535;
|
|
1547
|
-
b += l >>> 16;
|
|
1548
|
-
c += h & 65535;
|
|
1549
|
-
d += h >>> 16;
|
|
1550
|
-
h = K[i * 2];
|
|
1551
|
-
l = K[i * 2 + 1];
|
|
1552
|
-
a += l & 65535;
|
|
1553
|
-
b += l >>> 16;
|
|
1554
|
-
c += h & 65535;
|
|
1555
|
-
d += h >>> 16;
|
|
1556
|
-
h = wh[i % 16];
|
|
1557
|
-
l = wl[i % 16];
|
|
1558
|
-
a += l & 65535;
|
|
1559
|
-
b += l >>> 16;
|
|
1560
|
-
c += h & 65535;
|
|
1561
|
-
d += h >>> 16;
|
|
1562
|
-
b += a >>> 16;
|
|
1563
|
-
c += b >>> 16;
|
|
1564
|
-
d += c >>> 16;
|
|
1565
|
-
th = c & 65535 | d << 16;
|
|
1566
|
-
tl = a & 65535 | b << 16;
|
|
1567
|
-
h = th;
|
|
1568
|
-
l = tl;
|
|
1569
|
-
a = l & 65535;
|
|
1570
|
-
b = l >>> 16;
|
|
1571
|
-
c = h & 65535;
|
|
1572
|
-
d = h >>> 16;
|
|
1573
|
-
h = (ah0 >>> 28 | al0 << 32 - 28) ^ (al0 >>> 34 - 32 | ah0 << 32 - (34 - 32)) ^ (al0 >>> 39 - 32 | ah0 << 32 - (39 - 32));
|
|
1574
|
-
l = (al0 >>> 28 | ah0 << 32 - 28) ^ (ah0 >>> 34 - 32 | al0 << 32 - (34 - 32)) ^ (ah0 >>> 39 - 32 | al0 << 32 - (39 - 32));
|
|
1575
|
-
a += l & 65535;
|
|
1576
|
-
b += l >>> 16;
|
|
1577
|
-
c += h & 65535;
|
|
1578
|
-
d += h >>> 16;
|
|
1579
|
-
h = ah0 & ah1 ^ ah0 & ah2 ^ ah1 & ah2;
|
|
1580
|
-
l = al0 & al1 ^ al0 & al2 ^ al1 & al2;
|
|
1581
|
-
a += l & 65535;
|
|
1582
|
-
b += l >>> 16;
|
|
1583
|
-
c += h & 65535;
|
|
1584
|
-
d += h >>> 16;
|
|
1585
|
-
b += a >>> 16;
|
|
1586
|
-
c += b >>> 16;
|
|
1587
|
-
d += c >>> 16;
|
|
1588
|
-
bh7 = c & 65535 | d << 16;
|
|
1589
|
-
bl7 = a & 65535 | b << 16;
|
|
1590
|
-
h = bh3;
|
|
1591
|
-
l = bl3;
|
|
1592
|
-
a = l & 65535;
|
|
1593
|
-
b = l >>> 16;
|
|
1594
|
-
c = h & 65535;
|
|
1595
|
-
d = h >>> 16;
|
|
1596
|
-
h = th;
|
|
1597
|
-
l = tl;
|
|
1598
|
-
a += l & 65535;
|
|
1599
|
-
b += l >>> 16;
|
|
1600
|
-
c += h & 65535;
|
|
1601
|
-
d += h >>> 16;
|
|
1602
|
-
b += a >>> 16;
|
|
1603
|
-
c += b >>> 16;
|
|
1604
|
-
d += c >>> 16;
|
|
1605
|
-
bh3 = c & 65535 | d << 16;
|
|
1606
|
-
bl3 = a & 65535 | b << 16;
|
|
1607
|
-
ah1 = bh0;
|
|
1608
|
-
ah2 = bh1;
|
|
1609
|
-
ah3 = bh2;
|
|
1610
|
-
ah4 = bh3;
|
|
1611
|
-
ah5 = bh4;
|
|
1612
|
-
ah6 = bh5;
|
|
1613
|
-
ah7 = bh6;
|
|
1614
|
-
ah0 = bh7;
|
|
1615
|
-
al1 = bl0;
|
|
1616
|
-
al2 = bl1;
|
|
1617
|
-
al3 = bl2;
|
|
1618
|
-
al4 = bl3;
|
|
1619
|
-
al5 = bl4;
|
|
1620
|
-
al6 = bl5;
|
|
1621
|
-
al7 = bl6;
|
|
1622
|
-
al0 = bl7;
|
|
1623
|
-
if (i % 16 === 15) {
|
|
1624
|
-
for (j = 0; j < 16; j++) {
|
|
1625
|
-
h = wh[j];
|
|
1626
|
-
l = wl[j];
|
|
1627
|
-
a = l & 65535;
|
|
1628
|
-
b = l >>> 16;
|
|
1629
|
-
c = h & 65535;
|
|
1630
|
-
d = h >>> 16;
|
|
1631
|
-
h = wh[(j + 9) % 16];
|
|
1632
|
-
l = wl[(j + 9) % 16];
|
|
1633
|
-
a += l & 65535;
|
|
1634
|
-
b += l >>> 16;
|
|
1635
|
-
c += h & 65535;
|
|
1636
|
-
d += h >>> 16;
|
|
1637
|
-
th = wh[(j + 1) % 16];
|
|
1638
|
-
tl = wl[(j + 1) % 16];
|
|
1639
|
-
h = (th >>> 1 | tl << 32 - 1) ^ (th >>> 8 | tl << 32 - 8) ^ th >>> 7;
|
|
1640
|
-
l = (tl >>> 1 | th << 32 - 1) ^ (tl >>> 8 | th << 32 - 8) ^ (tl >>> 7 | th << 32 - 7);
|
|
1641
|
-
a += l & 65535;
|
|
1642
|
-
b += l >>> 16;
|
|
1643
|
-
c += h & 65535;
|
|
1644
|
-
d += h >>> 16;
|
|
1645
|
-
th = wh[(j + 14) % 16];
|
|
1646
|
-
tl = wl[(j + 14) % 16];
|
|
1647
|
-
h = (th >>> 19 | tl << 32 - 19) ^ (tl >>> 61 - 32 | th << 32 - (61 - 32)) ^ th >>> 6;
|
|
1648
|
-
l = (tl >>> 19 | th << 32 - 19) ^ (th >>> 61 - 32 | tl << 32 - (61 - 32)) ^ (tl >>> 6 | th << 32 - 6);
|
|
1649
|
-
a += l & 65535;
|
|
1650
|
-
b += l >>> 16;
|
|
1651
|
-
c += h & 65535;
|
|
1652
|
-
d += h >>> 16;
|
|
1653
|
-
b += a >>> 16;
|
|
1654
|
-
c += b >>> 16;
|
|
1655
|
-
d += c >>> 16;
|
|
1656
|
-
wh[j] = c & 65535 | d << 16;
|
|
1657
|
-
wl[j] = a & 65535 | b << 16;
|
|
1658
|
-
}
|
|
1659
|
-
}
|
|
1660
|
-
}
|
|
1661
|
-
h = ah0;
|
|
1662
|
-
l = al0;
|
|
1663
|
-
a = l & 65535;
|
|
1664
|
-
b = l >>> 16;
|
|
1665
|
-
c = h & 65535;
|
|
1666
|
-
d = h >>> 16;
|
|
1667
|
-
h = hh[0];
|
|
1668
|
-
l = hl[0];
|
|
1669
|
-
a += l & 65535;
|
|
1670
|
-
b += l >>> 16;
|
|
1671
|
-
c += h & 65535;
|
|
1672
|
-
d += h >>> 16;
|
|
1673
|
-
b += a >>> 16;
|
|
1674
|
-
c += b >>> 16;
|
|
1675
|
-
d += c >>> 16;
|
|
1676
|
-
hh[0] = ah0 = c & 65535 | d << 16;
|
|
1677
|
-
hl[0] = al0 = a & 65535 | b << 16;
|
|
1678
|
-
h = ah1;
|
|
1679
|
-
l = al1;
|
|
1680
|
-
a = l & 65535;
|
|
1681
|
-
b = l >>> 16;
|
|
1682
|
-
c = h & 65535;
|
|
1683
|
-
d = h >>> 16;
|
|
1684
|
-
h = hh[1];
|
|
1685
|
-
l = hl[1];
|
|
1686
|
-
a += l & 65535;
|
|
1687
|
-
b += l >>> 16;
|
|
1688
|
-
c += h & 65535;
|
|
1689
|
-
d += h >>> 16;
|
|
1690
|
-
b += a >>> 16;
|
|
1691
|
-
c += b >>> 16;
|
|
1692
|
-
d += c >>> 16;
|
|
1693
|
-
hh[1] = ah1 = c & 65535 | d << 16;
|
|
1694
|
-
hl[1] = al1 = a & 65535 | b << 16;
|
|
1695
|
-
h = ah2;
|
|
1696
|
-
l = al2;
|
|
1697
|
-
a = l & 65535;
|
|
1698
|
-
b = l >>> 16;
|
|
1699
|
-
c = h & 65535;
|
|
1700
|
-
d = h >>> 16;
|
|
1701
|
-
h = hh[2];
|
|
1702
|
-
l = hl[2];
|
|
1703
|
-
a += l & 65535;
|
|
1704
|
-
b += l >>> 16;
|
|
1705
|
-
c += h & 65535;
|
|
1706
|
-
d += h >>> 16;
|
|
1707
|
-
b += a >>> 16;
|
|
1708
|
-
c += b >>> 16;
|
|
1709
|
-
d += c >>> 16;
|
|
1710
|
-
hh[2] = ah2 = c & 65535 | d << 16;
|
|
1711
|
-
hl[2] = al2 = a & 65535 | b << 16;
|
|
1712
|
-
h = ah3;
|
|
1713
|
-
l = al3;
|
|
1714
|
-
a = l & 65535;
|
|
1715
|
-
b = l >>> 16;
|
|
1716
|
-
c = h & 65535;
|
|
1717
|
-
d = h >>> 16;
|
|
1718
|
-
h = hh[3];
|
|
1719
|
-
l = hl[3];
|
|
1720
|
-
a += l & 65535;
|
|
1721
|
-
b += l >>> 16;
|
|
1722
|
-
c += h & 65535;
|
|
1723
|
-
d += h >>> 16;
|
|
1724
|
-
b += a >>> 16;
|
|
1725
|
-
c += b >>> 16;
|
|
1726
|
-
d += c >>> 16;
|
|
1727
|
-
hh[3] = ah3 = c & 65535 | d << 16;
|
|
1728
|
-
hl[3] = al3 = a & 65535 | b << 16;
|
|
1729
|
-
h = ah4;
|
|
1730
|
-
l = al4;
|
|
1731
|
-
a = l & 65535;
|
|
1732
|
-
b = l >>> 16;
|
|
1733
|
-
c = h & 65535;
|
|
1734
|
-
d = h >>> 16;
|
|
1735
|
-
h = hh[4];
|
|
1736
|
-
l = hl[4];
|
|
1737
|
-
a += l & 65535;
|
|
1738
|
-
b += l >>> 16;
|
|
1739
|
-
c += h & 65535;
|
|
1740
|
-
d += h >>> 16;
|
|
1741
|
-
b += a >>> 16;
|
|
1742
|
-
c += b >>> 16;
|
|
1743
|
-
d += c >>> 16;
|
|
1744
|
-
hh[4] = ah4 = c & 65535 | d << 16;
|
|
1745
|
-
hl[4] = al4 = a & 65535 | b << 16;
|
|
1746
|
-
h = ah5;
|
|
1747
|
-
l = al5;
|
|
1748
|
-
a = l & 65535;
|
|
1749
|
-
b = l >>> 16;
|
|
1750
|
-
c = h & 65535;
|
|
1751
|
-
d = h >>> 16;
|
|
1752
|
-
h = hh[5];
|
|
1753
|
-
l = hl[5];
|
|
1754
|
-
a += l & 65535;
|
|
1755
|
-
b += l >>> 16;
|
|
1756
|
-
c += h & 65535;
|
|
1757
|
-
d += h >>> 16;
|
|
1758
|
-
b += a >>> 16;
|
|
1759
|
-
c += b >>> 16;
|
|
1760
|
-
d += c >>> 16;
|
|
1761
|
-
hh[5] = ah5 = c & 65535 | d << 16;
|
|
1762
|
-
hl[5] = al5 = a & 65535 | b << 16;
|
|
1763
|
-
h = ah6;
|
|
1764
|
-
l = al6;
|
|
1765
|
-
a = l & 65535;
|
|
1766
|
-
b = l >>> 16;
|
|
1767
|
-
c = h & 65535;
|
|
1768
|
-
d = h >>> 16;
|
|
1769
|
-
h = hh[6];
|
|
1770
|
-
l = hl[6];
|
|
1771
|
-
a += l & 65535;
|
|
1772
|
-
b += l >>> 16;
|
|
1773
|
-
c += h & 65535;
|
|
1774
|
-
d += h >>> 16;
|
|
1775
|
-
b += a >>> 16;
|
|
1776
|
-
c += b >>> 16;
|
|
1777
|
-
d += c >>> 16;
|
|
1778
|
-
hh[6] = ah6 = c & 65535 | d << 16;
|
|
1779
|
-
hl[6] = al6 = a & 65535 | b << 16;
|
|
1780
|
-
h = ah7;
|
|
1781
|
-
l = al7;
|
|
1782
|
-
a = l & 65535;
|
|
1783
|
-
b = l >>> 16;
|
|
1784
|
-
c = h & 65535;
|
|
1785
|
-
d = h >>> 16;
|
|
1786
|
-
h = hh[7];
|
|
1787
|
-
l = hl[7];
|
|
1788
|
-
a += l & 65535;
|
|
1789
|
-
b += l >>> 16;
|
|
1790
|
-
c += h & 65535;
|
|
1791
|
-
d += h >>> 16;
|
|
1792
|
-
b += a >>> 16;
|
|
1793
|
-
c += b >>> 16;
|
|
1794
|
-
d += c >>> 16;
|
|
1795
|
-
hh[7] = ah7 = c & 65535 | d << 16;
|
|
1796
|
-
hl[7] = al7 = a & 65535 | b << 16;
|
|
1797
|
-
pos += 128;
|
|
1798
|
-
n -= 128;
|
|
1799
|
-
}
|
|
1800
|
-
return n;
|
|
1801
|
-
}
|
|
1802
|
-
function crypto_hash(out, m, n) {
|
|
1803
|
-
var hh = new Int32Array(8), hl = new Int32Array(8), x = new Uint8Array(256), i, b = n;
|
|
1804
|
-
hh[0] = 1779033703;
|
|
1805
|
-
hh[1] = 3144134277;
|
|
1806
|
-
hh[2] = 1013904242;
|
|
1807
|
-
hh[3] = 2773480762;
|
|
1808
|
-
hh[4] = 1359893119;
|
|
1809
|
-
hh[5] = 2600822924;
|
|
1810
|
-
hh[6] = 528734635;
|
|
1811
|
-
hh[7] = 1541459225;
|
|
1812
|
-
hl[0] = 4089235720;
|
|
1813
|
-
hl[1] = 2227873595;
|
|
1814
|
-
hl[2] = 4271175723;
|
|
1815
|
-
hl[3] = 1595750129;
|
|
1816
|
-
hl[4] = 2917565137;
|
|
1817
|
-
hl[5] = 725511199;
|
|
1818
|
-
hl[6] = 4215389547;
|
|
1819
|
-
hl[7] = 327033209;
|
|
1820
|
-
crypto_hashblocks_hl(hh, hl, m, n);
|
|
1821
|
-
n %= 128;
|
|
1822
|
-
for (i = 0; i < n; i++) x[i] = m[b - n + i];
|
|
1823
|
-
x[n] = 128;
|
|
1824
|
-
n = 256 - 128 * (n < 112 ? 1 : 0);
|
|
1825
|
-
x[n - 9] = 0;
|
|
1826
|
-
ts64(x, n - 8, b / 536870912 | 0, b << 3);
|
|
1827
|
-
crypto_hashblocks_hl(hh, hl, x, n);
|
|
1828
|
-
for (i = 0; i < 8; i++) ts64(out, 8 * i, hh[i], hl[i]);
|
|
1829
|
-
return 0;
|
|
1830
|
-
}
|
|
1831
|
-
function add(p, q) {
|
|
1832
|
-
var a = gf(), b = gf(), c = gf(), d = gf(), e = gf(), f = gf(), g = gf(), h = gf(), t = gf();
|
|
1833
|
-
Z(a, p[1], p[0]);
|
|
1834
|
-
Z(t, q[1], q[0]);
|
|
1835
|
-
M(a, a, t);
|
|
1836
|
-
A(b, p[0], p[1]);
|
|
1837
|
-
A(t, q[0], q[1]);
|
|
1838
|
-
M(b, b, t);
|
|
1839
|
-
M(c, p[3], q[3]);
|
|
1840
|
-
M(c, c, D2);
|
|
1841
|
-
M(d, p[2], q[2]);
|
|
1842
|
-
A(d, d, d);
|
|
1843
|
-
Z(e, b, a);
|
|
1844
|
-
Z(f, d, c);
|
|
1845
|
-
A(g, d, c);
|
|
1846
|
-
A(h, b, a);
|
|
1847
|
-
M(p[0], e, f);
|
|
1848
|
-
M(p[1], h, g);
|
|
1849
|
-
M(p[2], g, f);
|
|
1850
|
-
M(p[3], e, h);
|
|
1851
|
-
}
|
|
1852
|
-
function cswap(p, q, b) {
|
|
1853
|
-
var i;
|
|
1854
|
-
for (i = 0; i < 4; i++) {
|
|
1855
|
-
sel25519(p[i], q[i], b);
|
|
1856
|
-
}
|
|
1857
|
-
}
|
|
1858
|
-
function pack(r, p) {
|
|
1859
|
-
var tx = gf(), ty = gf(), zi = gf();
|
|
1860
|
-
inv25519(zi, p[2]);
|
|
1861
|
-
M(tx, p[0], zi);
|
|
1862
|
-
M(ty, p[1], zi);
|
|
1863
|
-
pack25519(r, ty);
|
|
1864
|
-
r[31] ^= par25519(tx) << 7;
|
|
1865
|
-
}
|
|
1866
|
-
function scalarmult(p, q, s) {
|
|
1867
|
-
var b, i;
|
|
1868
|
-
set25519(p[0], gf0);
|
|
1869
|
-
set25519(p[1], gf1);
|
|
1870
|
-
set25519(p[2], gf1);
|
|
1871
|
-
set25519(p[3], gf0);
|
|
1872
|
-
for (i = 255; i >= 0; --i) {
|
|
1873
|
-
b = s[i / 8 | 0] >> (i & 7) & 1;
|
|
1874
|
-
cswap(p, q, b);
|
|
1875
|
-
add(q, p);
|
|
1876
|
-
add(p, p);
|
|
1877
|
-
cswap(p, q, b);
|
|
1878
|
-
}
|
|
1879
|
-
}
|
|
1880
|
-
function scalarbase(p, s) {
|
|
1881
|
-
var q = [gf(), gf(), gf(), gf()];
|
|
1882
|
-
set25519(q[0], X);
|
|
1883
|
-
set25519(q[1], Y);
|
|
1884
|
-
set25519(q[2], gf1);
|
|
1885
|
-
M(q[3], X, Y);
|
|
1886
|
-
scalarmult(p, q, s);
|
|
1887
|
-
}
|
|
1888
|
-
function crypto_sign_keypair(pk, sk, seeded) {
|
|
1889
|
-
var d = new Uint8Array(64);
|
|
1890
|
-
var p = [gf(), gf(), gf(), gf()];
|
|
1891
|
-
var i;
|
|
1892
|
-
if (!seeded) randombytes(sk, 32);
|
|
1893
|
-
crypto_hash(d, sk, 32);
|
|
1894
|
-
d[0] &= 248;
|
|
1895
|
-
d[31] &= 127;
|
|
1896
|
-
d[31] |= 64;
|
|
1897
|
-
scalarbase(p, d);
|
|
1898
|
-
pack(pk, p);
|
|
1899
|
-
for (i = 0; i < 32; i++) sk[i + 32] = pk[i];
|
|
1900
|
-
return 0;
|
|
1901
|
-
}
|
|
1902
|
-
var L = new Float64Array([237, 211, 245, 92, 26, 99, 18, 88, 214, 156, 247, 162, 222, 249, 222, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16]);
|
|
1903
|
-
function modL(r, x) {
|
|
1904
|
-
var carry, i, j, k;
|
|
1905
|
-
for (i = 63; i >= 32; --i) {
|
|
1906
|
-
carry = 0;
|
|
1907
|
-
for (j = i - 32, k = i - 12; j < k; ++j) {
|
|
1908
|
-
x[j] += carry - 16 * x[i] * L[j - (i - 32)];
|
|
1909
|
-
carry = Math.floor((x[j] + 128) / 256);
|
|
1910
|
-
x[j] -= carry * 256;
|
|
1911
|
-
}
|
|
1912
|
-
x[j] += carry;
|
|
1913
|
-
x[i] = 0;
|
|
1914
|
-
}
|
|
1915
|
-
carry = 0;
|
|
1916
|
-
for (j = 0; j < 32; j++) {
|
|
1917
|
-
x[j] += carry - (x[31] >> 4) * L[j];
|
|
1918
|
-
carry = x[j] >> 8;
|
|
1919
|
-
x[j] &= 255;
|
|
1920
|
-
}
|
|
1921
|
-
for (j = 0; j < 32; j++) x[j] -= carry * L[j];
|
|
1922
|
-
for (i = 0; i < 32; i++) {
|
|
1923
|
-
x[i + 1] += x[i] >> 8;
|
|
1924
|
-
r[i] = x[i] & 255;
|
|
1925
|
-
}
|
|
1926
|
-
}
|
|
1927
|
-
function reduce(r) {
|
|
1928
|
-
var x = new Float64Array(64), i;
|
|
1929
|
-
for (i = 0; i < 64; i++) x[i] = r[i];
|
|
1930
|
-
for (i = 0; i < 64; i++) r[i] = 0;
|
|
1931
|
-
modL(r, x);
|
|
1932
|
-
}
|
|
1933
|
-
function crypto_sign(sm, m, n, sk) {
|
|
1934
|
-
var d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64);
|
|
1935
|
-
var i, j, x = new Float64Array(64);
|
|
1936
|
-
var p = [gf(), gf(), gf(), gf()];
|
|
1937
|
-
crypto_hash(d, sk, 32);
|
|
1938
|
-
d[0] &= 248;
|
|
1939
|
-
d[31] &= 127;
|
|
1940
|
-
d[31] |= 64;
|
|
1941
|
-
var smlen = n + 64;
|
|
1942
|
-
for (i = 0; i < n; i++) sm[64 + i] = m[i];
|
|
1943
|
-
for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i];
|
|
1944
|
-
crypto_hash(r, sm.subarray(32), n + 32);
|
|
1945
|
-
reduce(r);
|
|
1946
|
-
scalarbase(p, r);
|
|
1947
|
-
pack(sm, p);
|
|
1948
|
-
for (i = 32; i < 64; i++) sm[i] = sk[i];
|
|
1949
|
-
crypto_hash(h, sm, n + 64);
|
|
1950
|
-
reduce(h);
|
|
1951
|
-
for (i = 0; i < 64; i++) x[i] = 0;
|
|
1952
|
-
for (i = 0; i < 32; i++) x[i] = r[i];
|
|
1953
|
-
for (i = 0; i < 32; i++) {
|
|
1954
|
-
for (j = 0; j < 32; j++) {
|
|
1955
|
-
x[i + j] += h[i] * d[j];
|
|
1956
|
-
}
|
|
1957
|
-
}
|
|
1958
|
-
modL(sm.subarray(32), x);
|
|
1959
|
-
return smlen;
|
|
1960
|
-
}
|
|
1961
|
-
function unpackneg(r, p) {
|
|
1962
|
-
var t = gf(), chk = gf(), num = gf(), den = gf(), den2 = gf(), den4 = gf(), den6 = gf();
|
|
1963
|
-
set25519(r[2], gf1);
|
|
1964
|
-
unpack25519(r[1], p);
|
|
1965
|
-
S(num, r[1]);
|
|
1966
|
-
M(den, num, D);
|
|
1967
|
-
Z(num, num, r[2]);
|
|
1968
|
-
A(den, r[2], den);
|
|
1969
|
-
S(den2, den);
|
|
1970
|
-
S(den4, den2);
|
|
1971
|
-
M(den6, den4, den2);
|
|
1972
|
-
M(t, den6, num);
|
|
1973
|
-
M(t, t, den);
|
|
1974
|
-
pow2523(t, t);
|
|
1975
|
-
M(t, t, num);
|
|
1976
|
-
M(t, t, den);
|
|
1977
|
-
M(t, t, den);
|
|
1978
|
-
M(r[0], t, den);
|
|
1979
|
-
S(chk, r[0]);
|
|
1980
|
-
M(chk, chk, den);
|
|
1981
|
-
if (neq25519(chk, num)) M(r[0], r[0], I);
|
|
1982
|
-
S(chk, r[0]);
|
|
1983
|
-
M(chk, chk, den);
|
|
1984
|
-
if (neq25519(chk, num)) return -1;
|
|
1985
|
-
if (par25519(r[0]) === p[31] >> 7) Z(r[0], gf0, r[0]);
|
|
1986
|
-
M(r[3], r[0], r[1]);
|
|
1987
|
-
return 0;
|
|
1988
|
-
}
|
|
1989
|
-
function crypto_sign_open(m, sm, n, pk) {
|
|
1990
|
-
var i;
|
|
1991
|
-
var t = new Uint8Array(32), h = new Uint8Array(64);
|
|
1992
|
-
var p = [gf(), gf(), gf(), gf()], q = [gf(), gf(), gf(), gf()];
|
|
1993
|
-
if (n < 64) return -1;
|
|
1994
|
-
if (unpackneg(q, pk)) return -1;
|
|
1995
|
-
for (i = 0; i < n; i++) m[i] = sm[i];
|
|
1996
|
-
for (i = 0; i < 32; i++) m[i + 32] = pk[i];
|
|
1997
|
-
crypto_hash(h, m, n);
|
|
1998
|
-
reduce(h);
|
|
1999
|
-
scalarmult(p, q, h);
|
|
2000
|
-
scalarbase(q, sm.subarray(32));
|
|
2001
|
-
add(p, q);
|
|
2002
|
-
pack(t, p);
|
|
2003
|
-
n -= 64;
|
|
2004
|
-
if (crypto_verify_32(sm, 0, t, 0)) {
|
|
2005
|
-
for (i = 0; i < n; i++) m[i] = 0;
|
|
2006
|
-
return -1;
|
|
2007
|
-
}
|
|
2008
|
-
for (i = 0; i < n; i++) m[i] = sm[i + 64];
|
|
2009
|
-
return n;
|
|
2010
|
-
}
|
|
2011
|
-
var crypto_secretbox_KEYBYTES = 32, crypto_secretbox_NONCEBYTES = 24, crypto_secretbox_ZEROBYTES = 32, crypto_secretbox_BOXZEROBYTES = 16, crypto_scalarmult_BYTES = 32, crypto_scalarmult_SCALARBYTES = 32, crypto_box_PUBLICKEYBYTES = 32, crypto_box_SECRETKEYBYTES = 32, crypto_box_BEFORENMBYTES = 32, crypto_box_NONCEBYTES = crypto_secretbox_NONCEBYTES, crypto_box_ZEROBYTES = crypto_secretbox_ZEROBYTES, crypto_box_BOXZEROBYTES = crypto_secretbox_BOXZEROBYTES, crypto_sign_BYTES = 64, crypto_sign_PUBLICKEYBYTES = 32, crypto_sign_SECRETKEYBYTES = 64, crypto_sign_SEEDBYTES = 32, crypto_hash_BYTES = 64;
|
|
2012
|
-
nacl6.lowlevel = {
|
|
2013
|
-
crypto_core_hsalsa20,
|
|
2014
|
-
crypto_stream_xor,
|
|
2015
|
-
crypto_stream,
|
|
2016
|
-
crypto_stream_salsa20_xor,
|
|
2017
|
-
crypto_stream_salsa20,
|
|
2018
|
-
crypto_onetimeauth,
|
|
2019
|
-
crypto_onetimeauth_verify,
|
|
2020
|
-
crypto_verify_16,
|
|
2021
|
-
crypto_verify_32,
|
|
2022
|
-
crypto_secretbox,
|
|
2023
|
-
crypto_secretbox_open,
|
|
2024
|
-
crypto_scalarmult,
|
|
2025
|
-
crypto_scalarmult_base,
|
|
2026
|
-
crypto_box_beforenm,
|
|
2027
|
-
crypto_box_afternm,
|
|
2028
|
-
crypto_box,
|
|
2029
|
-
crypto_box_open,
|
|
2030
|
-
crypto_box_keypair,
|
|
2031
|
-
crypto_hash,
|
|
2032
|
-
crypto_sign,
|
|
2033
|
-
crypto_sign_keypair,
|
|
2034
|
-
crypto_sign_open,
|
|
2035
|
-
crypto_secretbox_KEYBYTES,
|
|
2036
|
-
crypto_secretbox_NONCEBYTES,
|
|
2037
|
-
crypto_secretbox_ZEROBYTES,
|
|
2038
|
-
crypto_secretbox_BOXZEROBYTES,
|
|
2039
|
-
crypto_scalarmult_BYTES,
|
|
2040
|
-
crypto_scalarmult_SCALARBYTES,
|
|
2041
|
-
crypto_box_PUBLICKEYBYTES,
|
|
2042
|
-
crypto_box_SECRETKEYBYTES,
|
|
2043
|
-
crypto_box_BEFORENMBYTES,
|
|
2044
|
-
crypto_box_NONCEBYTES,
|
|
2045
|
-
crypto_box_ZEROBYTES,
|
|
2046
|
-
crypto_box_BOXZEROBYTES,
|
|
2047
|
-
crypto_sign_BYTES,
|
|
2048
|
-
crypto_sign_PUBLICKEYBYTES,
|
|
2049
|
-
crypto_sign_SECRETKEYBYTES,
|
|
2050
|
-
crypto_sign_SEEDBYTES,
|
|
2051
|
-
crypto_hash_BYTES,
|
|
2052
|
-
gf,
|
|
2053
|
-
D,
|
|
2054
|
-
L,
|
|
2055
|
-
pack25519,
|
|
2056
|
-
unpack25519,
|
|
2057
|
-
M,
|
|
2058
|
-
A,
|
|
2059
|
-
S,
|
|
2060
|
-
Z,
|
|
2061
|
-
pow2523,
|
|
2062
|
-
add,
|
|
2063
|
-
set25519,
|
|
2064
|
-
modL,
|
|
2065
|
-
scalarmult,
|
|
2066
|
-
scalarbase
|
|
2067
|
-
};
|
|
2068
|
-
function checkLengths(k, n) {
|
|
2069
|
-
if (k.length !== crypto_secretbox_KEYBYTES) throw new Error("bad key size");
|
|
2070
|
-
if (n.length !== crypto_secretbox_NONCEBYTES) throw new Error("bad nonce size");
|
|
2071
|
-
}
|
|
2072
|
-
function checkBoxLengths(pk, sk) {
|
|
2073
|
-
if (pk.length !== crypto_box_PUBLICKEYBYTES) throw new Error("bad public key size");
|
|
2074
|
-
if (sk.length !== crypto_box_SECRETKEYBYTES) throw new Error("bad secret key size");
|
|
2075
|
-
}
|
|
2076
|
-
function checkArrayTypes() {
|
|
2077
|
-
for (var i = 0; i < arguments.length; i++) {
|
|
2078
|
-
if (!(arguments[i] instanceof Uint8Array))
|
|
2079
|
-
throw new TypeError("unexpected type, use Uint8Array");
|
|
2080
|
-
}
|
|
2081
|
-
}
|
|
2082
|
-
function cleanup(arr) {
|
|
2083
|
-
for (var i = 0; i < arr.length; i++) arr[i] = 0;
|
|
2084
|
-
}
|
|
2085
|
-
nacl6.randomBytes = function(n) {
|
|
2086
|
-
var b = new Uint8Array(n);
|
|
2087
|
-
randombytes(b, n);
|
|
2088
|
-
return b;
|
|
2089
|
-
};
|
|
2090
|
-
nacl6.secretbox = function(msg, nonce, key) {
|
|
2091
|
-
checkArrayTypes(msg, nonce, key);
|
|
2092
|
-
checkLengths(key, nonce);
|
|
2093
|
-
var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length);
|
|
2094
|
-
var c = new Uint8Array(m.length);
|
|
2095
|
-
for (var i = 0; i < msg.length; i++) m[i + crypto_secretbox_ZEROBYTES] = msg[i];
|
|
2096
|
-
crypto_secretbox(c, m, m.length, nonce, key);
|
|
2097
|
-
return c.subarray(crypto_secretbox_BOXZEROBYTES);
|
|
2098
|
-
};
|
|
2099
|
-
nacl6.secretbox.open = function(box, nonce, key) {
|
|
2100
|
-
checkArrayTypes(box, nonce, key);
|
|
2101
|
-
checkLengths(key, nonce);
|
|
2102
|
-
var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length);
|
|
2103
|
-
var m = new Uint8Array(c.length);
|
|
2104
|
-
for (var i = 0; i < box.length; i++) c[i + crypto_secretbox_BOXZEROBYTES] = box[i];
|
|
2105
|
-
if (c.length < 32) return null;
|
|
2106
|
-
if (crypto_secretbox_open(m, c, c.length, nonce, key) !== 0) return null;
|
|
2107
|
-
return m.subarray(crypto_secretbox_ZEROBYTES);
|
|
2108
|
-
};
|
|
2109
|
-
nacl6.secretbox.keyLength = crypto_secretbox_KEYBYTES;
|
|
2110
|
-
nacl6.secretbox.nonceLength = crypto_secretbox_NONCEBYTES;
|
|
2111
|
-
nacl6.secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES;
|
|
2112
|
-
nacl6.scalarMult = function(n, p) {
|
|
2113
|
-
checkArrayTypes(n, p);
|
|
2114
|
-
if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error("bad n size");
|
|
2115
|
-
if (p.length !== crypto_scalarmult_BYTES) throw new Error("bad p size");
|
|
2116
|
-
var q = new Uint8Array(crypto_scalarmult_BYTES);
|
|
2117
|
-
crypto_scalarmult(q, n, p);
|
|
2118
|
-
return q;
|
|
2119
|
-
};
|
|
2120
|
-
nacl6.scalarMult.base = function(n) {
|
|
2121
|
-
checkArrayTypes(n);
|
|
2122
|
-
if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error("bad n size");
|
|
2123
|
-
var q = new Uint8Array(crypto_scalarmult_BYTES);
|
|
2124
|
-
crypto_scalarmult_base(q, n);
|
|
2125
|
-
return q;
|
|
2126
|
-
};
|
|
2127
|
-
nacl6.scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES;
|
|
2128
|
-
nacl6.scalarMult.groupElementLength = crypto_scalarmult_BYTES;
|
|
2129
|
-
nacl6.box = function(msg, nonce, publicKey, secretKey) {
|
|
2130
|
-
var k = nacl6.box.before(publicKey, secretKey);
|
|
2131
|
-
return nacl6.secretbox(msg, nonce, k);
|
|
2132
|
-
};
|
|
2133
|
-
nacl6.box.before = function(publicKey, secretKey) {
|
|
2134
|
-
checkArrayTypes(publicKey, secretKey);
|
|
2135
|
-
checkBoxLengths(publicKey, secretKey);
|
|
2136
|
-
var k = new Uint8Array(crypto_box_BEFORENMBYTES);
|
|
2137
|
-
crypto_box_beforenm(k, publicKey, secretKey);
|
|
2138
|
-
return k;
|
|
2139
|
-
};
|
|
2140
|
-
nacl6.box.after = nacl6.secretbox;
|
|
2141
|
-
nacl6.box.open = function(msg, nonce, publicKey, secretKey) {
|
|
2142
|
-
var k = nacl6.box.before(publicKey, secretKey);
|
|
2143
|
-
return nacl6.secretbox.open(msg, nonce, k);
|
|
2144
|
-
};
|
|
2145
|
-
nacl6.box.open.after = nacl6.secretbox.open;
|
|
2146
|
-
nacl6.box.keyPair = function() {
|
|
2147
|
-
var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
|
|
2148
|
-
var sk = new Uint8Array(crypto_box_SECRETKEYBYTES);
|
|
2149
|
-
crypto_box_keypair(pk, sk);
|
|
2150
|
-
return { publicKey: pk, secretKey: sk };
|
|
2151
|
-
};
|
|
2152
|
-
nacl6.box.keyPair.fromSecretKey = function(secretKey) {
|
|
2153
|
-
checkArrayTypes(secretKey);
|
|
2154
|
-
if (secretKey.length !== crypto_box_SECRETKEYBYTES)
|
|
2155
|
-
throw new Error("bad secret key size");
|
|
2156
|
-
var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
|
|
2157
|
-
crypto_scalarmult_base(pk, secretKey);
|
|
2158
|
-
return { publicKey: pk, secretKey: new Uint8Array(secretKey) };
|
|
2159
|
-
};
|
|
2160
|
-
nacl6.box.publicKeyLength = crypto_box_PUBLICKEYBYTES;
|
|
2161
|
-
nacl6.box.secretKeyLength = crypto_box_SECRETKEYBYTES;
|
|
2162
|
-
nacl6.box.sharedKeyLength = crypto_box_BEFORENMBYTES;
|
|
2163
|
-
nacl6.box.nonceLength = crypto_box_NONCEBYTES;
|
|
2164
|
-
nacl6.box.overheadLength = nacl6.secretbox.overheadLength;
|
|
2165
|
-
nacl6.sign = function(msg, secretKey) {
|
|
2166
|
-
checkArrayTypes(msg, secretKey);
|
|
2167
|
-
if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
|
|
2168
|
-
throw new Error("bad secret key size");
|
|
2169
|
-
var signedMsg = new Uint8Array(crypto_sign_BYTES + msg.length);
|
|
2170
|
-
crypto_sign(signedMsg, msg, msg.length, secretKey);
|
|
2171
|
-
return signedMsg;
|
|
2172
|
-
};
|
|
2173
|
-
nacl6.sign.open = function(signedMsg, publicKey) {
|
|
2174
|
-
checkArrayTypes(signedMsg, publicKey);
|
|
2175
|
-
if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
|
|
2176
|
-
throw new Error("bad public key size");
|
|
2177
|
-
var tmp = new Uint8Array(signedMsg.length);
|
|
2178
|
-
var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey);
|
|
2179
|
-
if (mlen < 0) return null;
|
|
2180
|
-
var m = new Uint8Array(mlen);
|
|
2181
|
-
for (var i = 0; i < m.length; i++) m[i] = tmp[i];
|
|
2182
|
-
return m;
|
|
2183
|
-
};
|
|
2184
|
-
nacl6.sign.detached = function(msg, secretKey) {
|
|
2185
|
-
var signedMsg = nacl6.sign(msg, secretKey);
|
|
2186
|
-
var sig = new Uint8Array(crypto_sign_BYTES);
|
|
2187
|
-
for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i];
|
|
2188
|
-
return sig;
|
|
2189
|
-
};
|
|
2190
|
-
nacl6.sign.detached.verify = function(msg, sig, publicKey) {
|
|
2191
|
-
checkArrayTypes(msg, sig, publicKey);
|
|
2192
|
-
if (sig.length !== crypto_sign_BYTES)
|
|
2193
|
-
throw new Error("bad signature size");
|
|
2194
|
-
if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
|
|
2195
|
-
throw new Error("bad public key size");
|
|
2196
|
-
var sm = new Uint8Array(crypto_sign_BYTES + msg.length);
|
|
2197
|
-
var m = new Uint8Array(crypto_sign_BYTES + msg.length);
|
|
2198
|
-
var i;
|
|
2199
|
-
for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i];
|
|
2200
|
-
for (i = 0; i < msg.length; i++) sm[i + crypto_sign_BYTES] = msg[i];
|
|
2201
|
-
return crypto_sign_open(m, sm, sm.length, publicKey) >= 0;
|
|
2202
|
-
};
|
|
2203
|
-
nacl6.sign.keyPair = function() {
|
|
2204
|
-
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
|
2205
|
-
var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
|
|
2206
|
-
crypto_sign_keypair(pk, sk);
|
|
2207
|
-
return { publicKey: pk, secretKey: sk };
|
|
2208
|
-
};
|
|
2209
|
-
nacl6.sign.keyPair.fromSecretKey = function(secretKey) {
|
|
2210
|
-
checkArrayTypes(secretKey);
|
|
2211
|
-
if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
|
|
2212
|
-
throw new Error("bad secret key size");
|
|
2213
|
-
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
|
2214
|
-
for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32 + i];
|
|
2215
|
-
return { publicKey: pk, secretKey: new Uint8Array(secretKey) };
|
|
2216
|
-
};
|
|
2217
|
-
nacl6.sign.keyPair.fromSeed = function(seed) {
|
|
2218
|
-
checkArrayTypes(seed);
|
|
2219
|
-
if (seed.length !== crypto_sign_SEEDBYTES)
|
|
2220
|
-
throw new Error("bad seed size");
|
|
2221
|
-
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
|
2222
|
-
var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
|
|
2223
|
-
for (var i = 0; i < 32; i++) sk[i] = seed[i];
|
|
2224
|
-
crypto_sign_keypair(pk, sk, true);
|
|
2225
|
-
return { publicKey: pk, secretKey: sk };
|
|
2226
|
-
};
|
|
2227
|
-
nacl6.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES;
|
|
2228
|
-
nacl6.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES;
|
|
2229
|
-
nacl6.sign.seedLength = crypto_sign_SEEDBYTES;
|
|
2230
|
-
nacl6.sign.signatureLength = crypto_sign_BYTES;
|
|
2231
|
-
nacl6.hash = function(msg) {
|
|
2232
|
-
checkArrayTypes(msg);
|
|
2233
|
-
var h = new Uint8Array(crypto_hash_BYTES);
|
|
2234
|
-
crypto_hash(h, msg, msg.length);
|
|
2235
|
-
return h;
|
|
2236
|
-
};
|
|
2237
|
-
nacl6.hash.hashLength = crypto_hash_BYTES;
|
|
2238
|
-
nacl6.verify = function(x, y) {
|
|
2239
|
-
checkArrayTypes(x, y);
|
|
2240
|
-
if (x.length === 0 || y.length === 0) return false;
|
|
2241
|
-
if (x.length !== y.length) return false;
|
|
2242
|
-
return vn(x, 0, y, 0, x.length) === 0 ? true : false;
|
|
2243
|
-
};
|
|
2244
|
-
nacl6.setPRNG = function(fn) {
|
|
2245
|
-
randombytes = fn;
|
|
2246
|
-
};
|
|
2247
|
-
(function() {
|
|
2248
|
-
var crypto = typeof self !== "undefined" ? self.crypto || self.msCrypto : null;
|
|
2249
|
-
if (crypto && crypto.getRandomValues) {
|
|
2250
|
-
var QUOTA = 65536;
|
|
2251
|
-
nacl6.setPRNG(function(x, n) {
|
|
2252
|
-
var i, v = new Uint8Array(n);
|
|
2253
|
-
for (i = 0; i < n; i += QUOTA) {
|
|
2254
|
-
crypto.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA)));
|
|
2255
|
-
}
|
|
2256
|
-
for (i = 0; i < n; i++) x[i] = v[i];
|
|
2257
|
-
cleanup(v);
|
|
2258
|
-
});
|
|
2259
|
-
} else if (typeof __require !== "undefined") {
|
|
2260
|
-
crypto = __require("crypto");
|
|
2261
|
-
if (crypto && crypto.randomBytes) {
|
|
2262
|
-
nacl6.setPRNG(function(x, n) {
|
|
2263
|
-
var i, v = crypto.randomBytes(n);
|
|
2264
|
-
for (i = 0; i < n; i++) x[i] = v[i];
|
|
2265
|
-
cleanup(v);
|
|
2266
|
-
});
|
|
2267
|
-
}
|
|
2268
|
-
}
|
|
2269
|
-
})();
|
|
2270
|
-
})(typeof module !== "undefined" && module.exports ? module.exports : self.nacl = self.nacl || {});
|
|
2271
|
-
}
|
|
2272
|
-
});
|
|
2273
23
|
var BACKEND_URL = process.env.PAIGY_BACKEND_URL ?? "https://paigy.ai";
|
|
2274
24
|
var NETWORK_MSG = `Can't reach ${BACKEND_URL} \u2014 the connection was blocked or dropped before an HTTP response. If this agent runs in a sandboxed environment with a network allowlist (e.g. Claude Code on the web, CI), ask the user to add the Paigy domain (paigy.ai) to the environment's allowed domains, then retry.`;
|
|
2275
25
|
var PROXY_ENV = ["HTTPS_PROXY", "https_proxy", "HTTP_PROXY", "http_proxy"];
|
|
@@ -2290,15 +40,42 @@ var envSession = (key) => {
|
|
|
2290
40
|
const v = process.env[key];
|
|
2291
41
|
return v && v.trim() ? v : void 0;
|
|
2292
42
|
};
|
|
2293
|
-
|
|
43
|
+
function parentOf(pid) {
|
|
44
|
+
try {
|
|
45
|
+
if (process.platform === "win32") return void 0;
|
|
46
|
+
const ppid = process.platform === "linux" ? readFileSync(`/proc/${pid}/stat`, "utf8").split(") ")[1]?.split(" ")[1] : execFileSync("ps", ["-o", "ppid=", "-p", String(pid)], { encoding: "utf8", timeout: 1e3 });
|
|
47
|
+
return Number(ppid?.trim()) || void 0;
|
|
48
|
+
} catch {
|
|
49
|
+
return void 0;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
var lineage;
|
|
53
|
+
function ancestors() {
|
|
54
|
+
if (lineage) return lineage;
|
|
55
|
+
lineage = [];
|
|
56
|
+
for (let pid = process.ppid; pid && pid > 1 && lineage.length < 5; pid = parentOf(pid)) lineage.push(pid);
|
|
57
|
+
return lineage;
|
|
58
|
+
}
|
|
59
|
+
function claudeConversation() {
|
|
60
|
+
if (!envSession("CLAUDE_CODE_SESSION_ID") || process.env.CLAUDE_CODE_CHILD_SESSION) return void 0;
|
|
61
|
+
const dir = envSession("CLAUDE_CONFIG_DIR") ?? join(homedir(), ".claude");
|
|
62
|
+
for (const pid of ancestors()) {
|
|
63
|
+
try {
|
|
64
|
+
const { sessionId: sessionId2 } = JSON.parse(readFileSync(join(dir, "sessions", `${pid}.json`), "utf8"));
|
|
65
|
+
return typeof sessionId2 === "string" && sessionId2.trim() ? sessionId2 : void 0;
|
|
66
|
+
} catch {
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return void 0;
|
|
70
|
+
}
|
|
2294
71
|
function sessionId() {
|
|
2295
|
-
return
|
|
72
|
+
return envSession("PAIGY_SESSION_ID") ?? claudeConversation() ?? envSession("CLAUDE_CODE_SESSION_ID") ?? envSession("CODEX_THREAD_ID") ?? envSession("CODEX_SESSION_ID") ?? WORKSPACE_ID;
|
|
2296
73
|
}
|
|
2297
74
|
function isNetworkError(e) {
|
|
2298
75
|
return e instanceof Error && e.message.startsWith(NETWORK_MSG);
|
|
2299
76
|
}
|
|
2300
77
|
async function reach(url, init) {
|
|
2301
|
-
return send(url, init,
|
|
78
|
+
return send(url, init, sessionId());
|
|
2302
79
|
}
|
|
2303
80
|
async function send(url, init, session) {
|
|
2304
81
|
try {
|
|
@@ -3553,32 +1330,28 @@ function mcpInputSchema(s) {
|
|
|
3553
1330
|
delete schema.$schema;
|
|
3554
1331
|
return draft2020(schema);
|
|
3555
1332
|
}
|
|
3556
|
-
var
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
|
|
3560
|
-
// A DecisionNeed is settled only by an answer in the shape THIS ask declares. Bundle news,
|
|
3561
|
-
// findings and a decision into one, and the person answers whichever part engaged them —
|
|
3562
|
-
// which settles nothing, leaves the need open, and gets them asked again. On call 619c5a92
|
|
3563
|
-
// one ask carried a briefing, a side question ("the ring should show the agent's name now —
|
|
3564
|
-
// what did you actually see?") and a one-of-four about how far an erase reaches. The owner
|
|
3565
|
-
// answered the side question. The need stayed open; the card asked again. Of the 45 call
|
|
3566
|
-
// asks carrying a decision, 27 are over 600 characters.
|
|
3567
|
-
//
|
|
3568
|
-
// Sending them separately costs nothing, because a CALL contact joins the call already
|
|
3569
|
-
// happening (`goal/store.ts`, JOIN BEFORE MINTING) — several contacts on one Goal arrive as
|
|
3570
|
-
// one call, planned as its turns, and each keeps its own settleable need.
|
|
1333
|
+
var AskInputSchema = z.object({
|
|
1334
|
+
id: z.string().optional().describe("Optional idempotency key or client-side ID for this specific ask."),
|
|
1335
|
+
parentId: z.string().uuid().optional().describe("Optional explicit parent Goal ID. If omitted, the platform's semantic router will auto-cluster it."),
|
|
1336
|
+
repo: z.string().optional().describe("Optional repository context."),
|
|
3571
1337
|
ask: z.string().trim().min(1).max(1e4).describe(
|
|
3572
1338
|
"The question, and only what is needed to answer it. News, progress and findings are their own contact \u2014 a call contact JOINS a call already happening, so several arrive as one call. Do not bundle: a DecisionNeed is settled only by an answer in the shape this ask declares, so someone who answers the part that interested them settles nothing and is asked again."
|
|
3573
1339
|
),
|
|
1340
|
+
options: z.array(z.object({
|
|
1341
|
+
label: z.string().trim().min(1).max(1e3),
|
|
1342
|
+
hint: z.string().trim().max(500).describe("Optional short projection of consequence or action if this option is chosen.").optional(),
|
|
1343
|
+
image: z.string().url().optional(),
|
|
1344
|
+
html: z.string().max(16384).describe("Optional sandboxed HTML/CSS preview. No JavaScript or network; inline CSS and data: URIs only. It renders edge-to-edge in a responsive card 200pt tall (about 320pt wide on a phone, with the next option peeking beside it), so fit the HTML to that viewport.").optional()
|
|
1345
|
+
}).strict()).min(2).max(6).optional()
|
|
1346
|
+
}).strict();
|
|
1347
|
+
var StartContactSchema = z.object({
|
|
1348
|
+
asks: z.array(AskInputSchema).min(1).describe("The list of asks/questions to pose. They will be semantically clustered by the API."),
|
|
3574
1349
|
waiting: z.enum(["none", "hard"]).default("none"),
|
|
3575
|
-
channel: z.enum(["notification", "call"]).default("notification")
|
|
3576
|
-
options: z.array(z.object({ label: z.string().trim().min(1).max(1e3), image: z.string().url().optional(), html: z.string().max(16384).optional() }).strict()).min(2).max(6).optional(),
|
|
3577
|
-
threadId: z.string().uuid().optional().describe("Continue an existing Thread: the threadId a prior Delivery returned. Omit to start a new Thread.")
|
|
1350
|
+
channel: z.enum(["notification", "call"]).default("notification")
|
|
3578
1351
|
}).strict();
|
|
3579
1352
|
var ContactSchema = z.union([StartContactSchema, z.object({ deliveryId: z.string().uuid() }).strict()]);
|
|
3580
1353
|
var CONTACT_SCHEMA = { type: "object", ...mcpInputSchema(ContactSchema) };
|
|
3581
|
-
var CONTACT_DESCRIPTION = "Contact the user
|
|
1354
|
+
var CONTACT_DESCRIPTION = "Contact the user with one or more asks/questions. Pass an array of asks (each with 'ask', optional 'options', 'id', 'parentId', 'repo'), plus channel:'notification'|'call', and waiting:'none'|'hard'. The platform will semantically cluster your asks under the correct Goals automatically. Notification returns immediately; collect durable answers with check_replies. On stdio, a Call holds one cancellable ~45s window; continue with ONLY {deliveryId}. Never bundle multiple questions into a single 'ask' string; pass them as separate objects in the 'asks' array.";
|
|
3582
1355
|
var CreateGoalSchema = z2.object({
|
|
3583
1356
|
outcome: z2.string().trim().min(1).max(1e4),
|
|
3584
1357
|
/** The work's NAME (#2115) — one to five words, how a person refers to it out loud ("the night
|
|
@@ -3590,7 +1363,6 @@ var CreateGoalSchema = z2.object({
|
|
|
3590
1363
|
* (owner, on the call of 2026-09-14: "let's do the reference with the threading"). A
|
|
3591
1364
|
* reference only: the owner reads it through `get_thread`, which does its own scoping, and
|
|
3592
1365
|
* the writer refuses a thread belonging to another account. */
|
|
3593
|
-
contextThreadId: z2.string().uuid().optional(),
|
|
3594
1366
|
/** THE GOAL THIS ONE BELONGS UNDER (owner, 2026-09-15: "the ask I gave for the design doc
|
|
3595
1367
|
* didn't get created as a child goal of the voice UI goal, which is how it should've
|
|
3596
1368
|
* worked"). It could not have been: this door took no parent, so the only route was
|
|
@@ -3598,12 +1370,15 @@ var CreateGoalSchema = z2.object({
|
|
|
3598
1370
|
* took the short one. The hierarchy has been modelled since Goals existed and had been used
|
|
3599
1371
|
* ZERO times in 2,031 of them. Absent, the server judges it against the caller's open Goals
|
|
3600
1372
|
* (`apps/api/src/goal/intake.ts`). The writer refuses a Goal belonging to another account. */
|
|
3601
|
-
parentGoalId: z2.string().uuid().optional()
|
|
1373
|
+
parentGoalId: z2.string().uuid().optional(),
|
|
1374
|
+
/** The repository or project identifier this Goal belongs to (#2280) — e.g. "owner/repo" or
|
|
1375
|
+
* repo name. Delegated work inherits this from its parent Goal when omitted. */
|
|
1376
|
+
repo: z2.string().trim().min(1).max(200).optional()
|
|
3602
1377
|
});
|
|
3603
1378
|
var CreateGoalToolSchema = CreateGoalSchema.extend({
|
|
3604
1379
|
idempotencyKey: CreateGoalSchema.shape.idempotencyKey.optional().describe("Optional. One is minted per call; pass your own only so a retry lands on the same Goal.")
|
|
3605
1380
|
}).strict();
|
|
3606
|
-
var CREATE_GOAL_DESCRIPTION = 'Create a durable Goal for an outcome. Without parentGoalId it is placed against your open Goals: if one already IS this work, that Goal comes back (existing: true) and nothing new is created \u2014 continue it; if the work belongs under one, it is created there (parentGoalId in the receipt); otherwise it is a root. Pass parentGoalId yourself to put it under a specific Goal. Pass title to name it in one to five words, as a person would refer to it out loud ("the night rings") \u2014 it heads every list and is spoken on a call; without one the brain writes it. Admission only: the owner must claim it before doing work, then update it as it advances. Returns an admission receipt with goalId, current state, revision, ownerParticipant, and the next step; no Goal content or execution lease.';
|
|
1381
|
+
var CREATE_GOAL_DESCRIPTION = 'Create a durable Goal for an outcome. Without parentGoalId it is placed against your open Goals: if one already IS this work, that Goal comes back (existing: true) and nothing new is created \u2014 continue it; if the work belongs under one, it is created there (parentGoalId in the receipt); otherwise it is a root. Pass parentGoalId yourself to put it under a specific Goal. Pass repo to anchor the work to a specific repository ("owner/repo" or repo name); delegated children inherit it. Pass title to name it in one to five words, as a person would refer to it out loud ("the night rings") \u2014 it heads every list and is spoken on a call; without one the brain writes it. Admission only: the owner must claim it before doing work, then update it as it advances. Returns an admission receipt with goalId, current state, revision, ownerParticipant, and the next step; no Goal content or execution lease.';
|
|
3607
1382
|
var UpdateGoalSchema = z2.object({
|
|
3608
1383
|
revision: z2.number().int().positive(),
|
|
3609
1384
|
changes: z2.object({
|
|
@@ -3695,10 +1470,11 @@ var TransformSchema = z3.enum([
|
|
|
3695
1470
|
var OptionSchema = z3.object({
|
|
3696
1471
|
id: z3.string(),
|
|
3697
1472
|
label: z3.string(),
|
|
1473
|
+
hint: z3.string().max(500).describe("Optional short projection of consequence or action if this option is chosen (e.g. 'Reruns test suite', 'Merges to main').").optional(),
|
|
3698
1474
|
// .describe() flows into the MCP contact JSON schema (zodToJsonSchema), so
|
|
3699
1475
|
// the constraints below are what an agent reads when deciding to use these.
|
|
3700
1476
|
html: z3.string().max(16384).describe(
|
|
3701
|
-
"Optional sandboxed HTML/CSS preview for a visual 'pick one' (shown in the option card). Untrusted-sandboxed: NO JavaScript, NO external network or images \u2014 inline CSS and data: URIs only; <=16KB. Use for layout/CSS mockups, tables, diffs. For a hosted image use `image` instead."
|
|
1477
|
+
"Optional sandboxed HTML/CSS preview for a visual 'pick one' (shown in the option card). Untrusted-sandboxed: NO JavaScript, NO external network or images \u2014 inline CSS and data: URIs only; <=16KB. Rendered edge-to-edge in a responsive card that is 200pt tall (about 320pt wide on a phone, with the next option peeking beside it); make your HTML fit that viewport. Use for layout/CSS mockups, tables, diffs. For a hosted image use `image` instead."
|
|
3702
1478
|
).optional(),
|
|
3703
1479
|
image: z3.string().url().describe(
|
|
3704
1480
|
"Optional image URL rendered as the option's preview (plain image, not sandboxed). For agent-generated HTML/CSS mockups, use `html` instead."
|
|
@@ -3789,23 +1565,6 @@ var NotifyRequestFields = z3.object({
|
|
|
3789
1565
|
* when `parentId` became the conversation handle: `parentId` says WHERE, this
|
|
3790
1566
|
* says HOW. */
|
|
3791
1567
|
clarifies: z3.string().optional(),
|
|
3792
|
-
/** E2EE (text lane): when the pairing is E2EE, the sealed replacements for the
|
|
3793
|
-
* plaintext content fields, keyed by field name. FINALIZED wire shape (was
|
|
3794
|
-
* provisional in the storage PR): a per-field map `{ context?, options?,
|
|
3795
|
-
* visuals? }` of opaque Envelopes — one seal per present content field, so a
|
|
3796
|
-
* message with no options/visuals seals only `context`. It COEXISTS with the
|
|
3797
|
-
* plaintext fields by mutual exclusion: the superRefine below requires that
|
|
3798
|
-
* when `envelope` is present the plaintext `context`/`options`/`visuals` are
|
|
3799
|
-
* ABSENT (and vice-versa), so a row is either fully plaintext or fully sealed —
|
|
3800
|
-
* never a readable half. The server persists this OPAQUELY into
|
|
3801
|
-
* notifications.envelope and relays it blindly; it never decrypts. Absent =
|
|
3802
|
-
* today's plaintext path (context/options/visuals carry the cleartext).
|
|
3803
|
-
* z.lazy because EnvelopeSchema is declared further down (E2EE section). */
|
|
3804
|
-
envelope: z3.object({
|
|
3805
|
-
context: z3.lazy(() => EnvelopeSchema).optional(),
|
|
3806
|
-
options: z3.lazy(() => EnvelopeSchema).optional(),
|
|
3807
|
-
visuals: z3.lazy(() => EnvelopeSchema).optional()
|
|
3808
|
-
}).optional(),
|
|
3809
1568
|
select: SelectShapeSchema.optional().describe(
|
|
3810
1569
|
"How the user answers \u2014 required on the fully-shaped form, pick the shape that fits the question: 'one' = pick one option, 'many' = pick several, 'rank' = pick & order (each needs `options`); 'confirm' = yes/no or approve/deny; 'text' = free-form reply only (status updates, open questions). 'confirm' and 'text' take no options. Omit only when sending the simplified `ask` form \u2014 the broker picks the shape."
|
|
3811
1570
|
),
|
|
@@ -3859,22 +1618,6 @@ var NotifyRequestFields = z3.object({
|
|
|
3859
1618
|
});
|
|
3860
1619
|
var NotifyRequestSchema = NotifyRequestFields.superRefine((r, ctx) => {
|
|
3861
1620
|
if (r.workId && r.goalId) ctx.addIssue({ code: z3.ZodIssueCode.custom, path: ["goalId"], message: "pass goalId or workId, not both" });
|
|
3862
|
-
const sealed = !!r.envelope;
|
|
3863
|
-
if (sealed) {
|
|
3864
|
-
if (!r.envelope?.context)
|
|
3865
|
-
ctx.addIssue({ code: z3.ZodIssueCode.custom, path: ["envelope", "context"], message: "sealed request must include envelope.context" });
|
|
3866
|
-
for (const f of ["context", "options", "visuals"]) {
|
|
3867
|
-
if (r[f] !== void 0)
|
|
3868
|
-
ctx.addIssue({ code: z3.ZodIssueCode.custom, path: [f], message: `E2EE request must not carry plaintext ${f} \u2014 it's sealed in envelope.${f}` });
|
|
3869
|
-
}
|
|
3870
|
-
if (r.points !== void 0)
|
|
3871
|
-
ctx.addIssue({ code: z3.ZodIssueCode.custom, path: ["points"], message: "E2EE request must not carry plaintext points" });
|
|
3872
|
-
if (r.ask !== void 0)
|
|
3873
|
-
ctx.addIssue({ code: z3.ZodIssueCode.custom, path: ["ask"], message: "E2EE request must not carry a plaintext ask \u2014 derive the shape agent-side and seal it" });
|
|
3874
|
-
if (r.needs !== void 0)
|
|
3875
|
-
ctx.addIssue({ code: z3.ZodIssueCode.custom, path: ["needs"], message: "E2EE request must not carry plaintext needs" });
|
|
3876
|
-
return;
|
|
3877
|
-
}
|
|
3878
1621
|
if (r.ask !== void 0) {
|
|
3879
1622
|
for (const f of ["context", "select", "points"]) {
|
|
3880
1623
|
if (r[f] !== void 0)
|
|
@@ -3894,61 +1637,6 @@ var NotifyRequestSchema = NotifyRequestFields.superRefine((r, ctx) => {
|
|
|
3894
1637
|
if (!needsOptions && r.options?.length)
|
|
3895
1638
|
ctx.addIssue({ code: z3.ZodIssueCode.custom, path: ["options"], message: `select:'${r.select}' takes no options` });
|
|
3896
1639
|
});
|
|
3897
|
-
function normalizeWaiting(req) {
|
|
3898
|
-
if (!req.waiting) return req;
|
|
3899
|
-
const { waiting, ...rest } = req;
|
|
3900
|
-
return {
|
|
3901
|
-
...rest,
|
|
3902
|
-
urgencyHint: req.urgencyHint ?? { none: "whenever", soft: "soon", hard: "now" }[waiting],
|
|
3903
|
-
blocking: req.blocking || waiting === "hard"
|
|
3904
|
-
};
|
|
3905
|
-
}
|
|
3906
|
-
function unitsOf(text) {
|
|
3907
|
-
const spans = [];
|
|
3908
|
-
const re = /\n\s*\n+/g;
|
|
3909
|
-
let cursor = 0;
|
|
3910
|
-
const push = (from, to) => {
|
|
3911
|
-
const slice = text.slice(from, to);
|
|
3912
|
-
const lead = slice.length - slice.trimStart().length;
|
|
3913
|
-
const tail = slice.length - slice.trimEnd().length;
|
|
3914
|
-
if (from + lead < to - tail) spans.push({ start: from + lead, end: to - tail });
|
|
3915
|
-
};
|
|
3916
|
-
for (let m = re.exec(text); m; m = re.exec(text)) {
|
|
3917
|
-
push(cursor, m.index);
|
|
3918
|
-
cursor = m.index + m[0].length;
|
|
3919
|
-
}
|
|
3920
|
-
push(cursor, text.length);
|
|
3921
|
-
return spans;
|
|
3922
|
-
}
|
|
3923
|
-
function headline(text) {
|
|
3924
|
-
const line = text.split("\n").map((l) => l.trim()).filter((l) => l && !/^`{3,}/.test(l)).map((l) => l.replace(/^(?:#{1,6}|[-*>]|\d{1,3}\.)\s+/, "")).find(Boolean) ?? "";
|
|
3925
|
-
return (/^[^.!?\n]+[.!?]?/.exec(line)?.[0] ?? line).trim();
|
|
3926
|
-
}
|
|
3927
|
-
function bodyAfterHeadline(text) {
|
|
3928
|
-
const body = text.trim();
|
|
3929
|
-
const title = headline(body);
|
|
3930
|
-
const rest = body.slice(title.length).replace(/^[\s.!?—–-]+/, "").trim();
|
|
3931
|
-
if (!rest) return { title, description: [] };
|
|
3932
|
-
const chunks = unitsOf(rest).map((u) => rest.slice(u.start, u.end)).filter(Boolean);
|
|
3933
|
-
return { title, description: chunks.length ? chunks : [rest] };
|
|
3934
|
-
}
|
|
3935
|
-
function deriveAsk(req) {
|
|
3936
|
-
req = normalizeWaiting(req);
|
|
3937
|
-
if (!req.ask) return req;
|
|
3938
|
-
const text = req.ask.trim();
|
|
3939
|
-
const hinted = req.urgencyHint === "now" ? "call" : req.urgencyHint === "soon" ? "banner" : req.urgencyHint === "whenever" ? "inbox" : req.urgency;
|
|
3940
|
-
const urgency = req.channel === "call" ? "call" : req.channel === "message" && hinted === "call" ? "banner" : hinted;
|
|
3941
|
-
const { ask: _ask, needs, urgencyHint: _hint, channel: _channel, ...rest } = req;
|
|
3942
|
-
return {
|
|
3943
|
-
...rest,
|
|
3944
|
-
context: bodyAfterHeadline(text),
|
|
3945
|
-
// Options riding alongside the ask (#575: pixels can't be prose) floor to a
|
|
3946
|
-
// single pick — the model broker may upgrade to many/rank from the wording.
|
|
3947
|
-
select: req.options?.length ? "one" : "text",
|
|
3948
|
-
urgency,
|
|
3949
|
-
...needs?.length ? { points: needs } : {}
|
|
3950
|
-
};
|
|
3951
|
-
}
|
|
3952
1640
|
var NotifyStatusSchema = z3.enum(["pending", "answered", "ignored"]);
|
|
3953
1641
|
var AgentStateSchema = z3.enum(["idle", "in_progress", "completed", "needs_input"]);
|
|
3954
1642
|
var TurnSchema = z3.object({
|
|
@@ -4004,13 +1692,6 @@ var AwaitItemSchema = z3.discriminatedUnion("type", [
|
|
|
4004
1692
|
workId: z3.string().uuid().optional(),
|
|
4005
1693
|
decisionId: z3.string().uuid().optional(),
|
|
4006
1694
|
answer: UserAnswerSchema,
|
|
4007
|
-
/** E2EE: present when the answer is sealed. The server relays the opaque answer
|
|
4008
|
-
* envelope + the plaintext `ignored` status hint; the receiving agent OPENS it
|
|
4009
|
-
* with its device key and re-derives the real UserAnswer, treating a mismatch
|
|
4010
|
-
* against `ignored` as tampering. Absent = today's plaintext answer (in `answer`).
|
|
4011
|
-
* On a sealed reply the plaintext `answer` is a placeholder (kind reflects only
|
|
4012
|
-
* the `ignored` bit) — never the real content, which stays sealed. */
|
|
4013
|
-
sealed: z3.lazy(() => SealedAnswerSchema).optional(),
|
|
4014
1695
|
/** WHAT THE AGENT CANNOT KNOW FROM THE FIELDS BESIDE IT (owner, 2026-09-04, issue
|
|
4015
1696
|
* #1537). One line, built from the record: the ask and the caller's reply VERBATIM,
|
|
4016
1697
|
* the notification they belong to, and the `contact` call that reaches the person
|
|
@@ -4232,21 +1913,6 @@ var InboxItemSchema = z3.object({
|
|
|
4232
1913
|
blocking: z3.boolean().default(false),
|
|
4233
1914
|
/** The user's locked-in answer; present only for replied items (GET /api/replied/:id). */
|
|
4234
1915
|
answer: UserAnswerSchema.optional(),
|
|
4235
|
-
/** E2EE (text lane): the sealed content this item carries when the pairing is E2EE, in
|
|
4236
|
-
* place of the plaintext `context`/`options`/`visuals` (which the operator would
|
|
4237
|
-
* otherwise read). A per-field map of opaque Envelopes — the SAME shape as
|
|
4238
|
-
* NotifyRequest.envelope. The native app decrypts it locally via openNotification;
|
|
4239
|
-
* web / an un-enrolled device can't and renders a locked placeholder. Absent = today's
|
|
4240
|
-
* plaintext item (context carries the cleartext), so plaintext items are unchanged. */
|
|
4241
|
-
envelope: z3.object({
|
|
4242
|
-
context: z3.lazy(() => EnvelopeSchema).optional(),
|
|
4243
|
-
options: z3.lazy(() => EnvelopeSchema).optional(),
|
|
4244
|
-
visuals: z3.lazy(() => EnvelopeSchema).optional()
|
|
4245
|
-
}).optional(),
|
|
4246
|
-
/** E2EE: the agent's device X25519 public key to seal the user's answer BACK to (the
|
|
4247
|
-
* sender the phone replies to). Sourced server-side from this item's pairing credential.
|
|
4248
|
-
* Present only alongside `envelope`; the phone seals via sealAnswer(answer, this, id). */
|
|
4249
|
-
agentX25519: z3.string().optional(),
|
|
4250
1916
|
/** THE TARGET FACTS A CARD RENDERS (#1796 point 5, 2026-09-11): the Delivery it is a view of,
|
|
4251
1917
|
* that Delivery's kind, the request Entry, the Goals it answers for, the exact DecisionNeed (none
|
|
4252
1918
|
* for a request that asks nothing), whether its content is sealed, and that Goal's state. The
|
|
@@ -4344,13 +2010,6 @@ var UserSettingsSchema = z3.object({
|
|
|
4344
2010
|
* setting. Absent = a spoken time can't be landed, so the reminder rides the next
|
|
4345
2011
|
* call — honest about what we know. */
|
|
4346
2012
|
timezone: z3.string().min(1).max(64).optional(),
|
|
4347
|
-
/** Account E2EE state (text lane): 'off' (default) = today's plaintext; 'on' =
|
|
4348
|
-
* content is sealed end-to-end between the local agent and the phone. Like
|
|
4349
|
-
* voiceMode, OPTIONAL and NOT defaulted so a stale client PATCHing the full
|
|
4350
|
-
* settings object without it can't silently flip the account's E2EE state.
|
|
4351
|
-
* Absent = leave unchanged on write, 'off' on read (see store.ts). The demo
|
|
4352
|
-
* account is plaintext by construction and refuses any non-'off' value. */
|
|
4353
|
-
e2eeMode: z3.enum(["off", "on"]).optional(),
|
|
4354
2013
|
/** Rung-2 broker tuning (#381). Optional and NOT defaulted, same stale-client
|
|
4355
2014
|
* clobber guard as voiceMode: absent = leave unchanged on write. */
|
|
4356
2015
|
broker: BrokerTuningSchema.optional()
|
|
@@ -4540,6 +2199,8 @@ var QueueItemSchema = z3.object({
|
|
|
4540
2199
|
blocked: z3.boolean().default(false),
|
|
4541
2200
|
/** Every decision need on it, open or settled — the page decides which to show. */
|
|
4542
2201
|
questions: z3.array(QueueQuestionSchema).default([]),
|
|
2202
|
+
/** The repository or project identifier this Goal belongs to (#2280), null if untracked. */
|
|
2203
|
+
repo: z3.string().nullable().optional(),
|
|
4543
2204
|
createdAt: z3.string(),
|
|
4544
2205
|
updatedAt: z3.string().nullable().default(null)
|
|
4545
2206
|
});
|
|
@@ -4653,54 +2314,12 @@ var DeliveryConfigSchema = z3.object({
|
|
|
4653
2314
|
* carries credentials; only a `poll` registration can come back with null here. */
|
|
4654
2315
|
realtime: z3.object({ url: z3.string(), anonKey: z3.string() }).nullable()
|
|
4655
2316
|
});
|
|
4656
|
-
var EnvelopeRecipientSchema = z3.object({
|
|
4657
|
-
keyId: z3.string(),
|
|
4658
|
-
epk: z3.string(),
|
|
4659
|
-
wnonce: z3.string(),
|
|
4660
|
-
wrap: z3.string()
|
|
4661
|
-
});
|
|
4662
|
-
var EnvelopeHeaderSchema = z3.object({
|
|
4663
|
-
field: z3.enum(["context", "options", "visuals", "answer"]),
|
|
4664
|
-
kind: z3.string(),
|
|
4665
|
-
senderRole: z3.enum(["agent", "user"]),
|
|
4666
|
-
recipientKeyIds: z3.array(z3.string()),
|
|
4667
|
-
seq: z3.number().int().nonnegative()
|
|
4668
|
-
});
|
|
4669
|
-
var EnvelopeSchema = z3.object({
|
|
4670
|
-
v: z3.literal(1),
|
|
4671
|
-
alg: z3.literal("x25519-xsalsa20poly1305"),
|
|
4672
|
-
msgId: z3.string(),
|
|
4673
|
-
hdr: EnvelopeHeaderSchema,
|
|
4674
|
-
recipients: z3.array(EnvelopeRecipientSchema).min(1),
|
|
4675
|
-
nonce: z3.string(),
|
|
4676
|
-
ct: z3.string()
|
|
4677
|
-
});
|
|
4678
|
-
var SealedAnswerSchema = z3.object({
|
|
4679
|
-
ignored: z3.boolean(),
|
|
4680
|
-
envelope: EnvelopeSchema
|
|
4681
|
-
});
|
|
4682
|
-
var DeviceCredentialSchema = z3.object({
|
|
4683
|
-
deviceId: z3.string(),
|
|
4684
|
-
kind: z3.enum(["phone", "web", "agent"]),
|
|
4685
|
-
x25519Pub: z3.string(),
|
|
4686
|
-
ed25519Pub: z3.string(),
|
|
4687
|
-
sig: z3.string()
|
|
4688
|
-
});
|
|
4689
|
-
var DeviceRosterSchema = z3.object({
|
|
4690
|
-
uikPub: z3.string(),
|
|
4691
|
-
devices: z3.array(DeviceCredentialSchema)
|
|
4692
|
-
});
|
|
4693
2317
|
var WakeNudgeSchema = z3.object({
|
|
4694
2318
|
kind: z3.enum(["reply", "request", "callback"]),
|
|
4695
2319
|
notificationId: z3.string().optional(),
|
|
4696
2320
|
parentId: z3.string()
|
|
4697
2321
|
});
|
|
4698
2322
|
var PairingStatusSchema = z3.enum(["pending", "approved", "denied", "expired"]);
|
|
4699
|
-
var PairingRevealSchema = z3.object({
|
|
4700
|
-
x25519: z3.string(),
|
|
4701
|
-
ed25519: z3.string(),
|
|
4702
|
-
nonce: z3.string()
|
|
4703
|
-
});
|
|
4704
2323
|
var DeviceCodeSchema = z3.object({
|
|
4705
2324
|
device_code: z3.string(),
|
|
4706
2325
|
user_code: z3.string(),
|
|
@@ -4720,19 +2339,7 @@ var DeviceInfoSchema = z3.object({
|
|
|
4720
2339
|
* (seen live: PAIGY-5T, 2026-07-21). Remove once a newer binary is the floor. */
|
|
4721
2340
|
agent: z3.string().optional(),
|
|
4722
2341
|
device: z3.string().nullable(),
|
|
4723
|
-
status: PairingStatusSchema
|
|
4724
|
-
proto: z3.string().nullable().optional(),
|
|
4725
|
-
agent_commitment: z3.string().nullable().optional(),
|
|
4726
|
-
// Ca
|
|
4727
|
-
agent_reveal: PairingRevealSchema.nullable().optional(),
|
|
4728
|
-
// present once the agent reveals
|
|
4729
|
-
agent_credential: DeviceCredentialSchema.nullable().optional(),
|
|
4730
|
-
// the phone's UIK-signed cred over the agent's keys — the agent fetches it here to finalizeE2ee
|
|
4731
|
-
// The phone's reveal + identity key, exposed here so a GATED agent (e2ee_mode='on', token
|
|
4732
|
-
// withheld until e2ee=true) can compute the SAS WITHOUT a token. Public keys — same safety
|
|
4733
|
-
// class as agent_reveal above. Present only once the phone reveals; null otherwise.
|
|
4734
|
-
phone_reveal: PairingRevealSchema.nullable().optional(),
|
|
4735
|
-
uik_pub: z3.string().nullable().optional()
|
|
2342
|
+
status: PairingStatusSchema
|
|
4736
2343
|
});
|
|
4737
2344
|
var DeviceTokenSchema = z3.object({
|
|
4738
2345
|
access_token: z3.string(),
|
|
@@ -4751,8 +2358,6 @@ var DeviceTokenSchema = z3.object({
|
|
|
4751
2358
|
* landed in the FIRST granted workspace and the agent rediscovered its own repo from
|
|
4752
2359
|
* the thread each time (host.ts, live catch 2026-08-06 — prompt-papered until now). */
|
|
4753
2360
|
workspace: z3.string().nullable().optional(),
|
|
4754
|
-
phone_reveal: PairingRevealSchema.nullable().optional(),
|
|
4755
|
-
// present once the phone reveals
|
|
4756
2361
|
uik_pub: z3.string().nullable().optional()
|
|
4757
2362
|
});
|
|
4758
2363
|
var SupportRequestSchema = z3.object({
|
|
@@ -4774,188 +2379,19 @@ var NotificationFeedbackKindSchema = z3.enum([
|
|
|
4774
2379
|
"other"
|
|
4775
2380
|
// anything else — the note carries it.
|
|
4776
2381
|
]);
|
|
4777
|
-
var FeedbackResolutionSchema = z3.enum(["broker_fixed", "sent_to_agent"]);
|
|
4778
|
-
var FeedbackOutcomeSchema = z3.object({
|
|
4779
|
-
resolution: FeedbackResolutionSchema,
|
|
4780
|
-
transform: TransformSchema,
|
|
4781
|
-
message: z3.string(),
|
|
4782
|
-
childIds: z3.array(z3.string()).optional()
|
|
4783
|
-
});
|
|
4784
|
-
var import_tweetnacl = __toESM(require_nacl_fast(), 1);
|
|
4785
|
-
var import_tweetnacl2 = __toESM(require_nacl_fast(), 1);
|
|
4786
|
-
var import_tweetnacl3 = __toESM(require_nacl_fast(), 1);
|
|
4787
|
-
var import_tweetnacl4 = __toESM(require_nacl_fast(), 1);
|
|
4788
|
-
var import_tweetnacl5 = __toESM(require_nacl_fast(), 1);
|
|
4789
|
-
function utf8ToBytes(s) {
|
|
4790
|
-
const out = [];
|
|
4791
|
-
for (let i = 0; i < s.length; i++) {
|
|
4792
|
-
const c = s.charCodeAt(i);
|
|
4793
|
-
if (c < 128) out.push(c);
|
|
4794
|
-
else if (c < 2048) out.push(192 | c >> 6, 128 | c & 63);
|
|
4795
|
-
else if (c >= 55296 && c <= 56319) {
|
|
4796
|
-
const c2 = s.charCodeAt(i + 1);
|
|
4797
|
-
if (c2 >= 56320 && c2 <= 57343) {
|
|
4798
|
-
i++;
|
|
4799
|
-
const cp = 65536 + ((c & 1023) << 10) + (c2 & 1023);
|
|
4800
|
-
out.push(240 | cp >> 18, 128 | cp >> 12 & 63, 128 | cp >> 6 & 63, 128 | cp & 63);
|
|
4801
|
-
} else out.push(239, 191, 189);
|
|
4802
|
-
} else if (c >= 56320 && c <= 57343) out.push(239, 191, 189);
|
|
4803
|
-
else out.push(224 | c >> 12, 128 | c >> 6 & 63, 128 | c & 63);
|
|
4804
|
-
}
|
|
4805
|
-
return Uint8Array.from(out);
|
|
4806
|
-
}
|
|
4807
|
-
var B64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
4808
|
-
function toB64(bytes) {
|
|
4809
|
-
let out = "";
|
|
4810
|
-
for (let i = 0; i < bytes.length; i += 3) {
|
|
4811
|
-
const b0 = bytes[i];
|
|
4812
|
-
const has1 = i + 1 < bytes.length;
|
|
4813
|
-
const has2 = i + 2 < bytes.length;
|
|
4814
|
-
const b1 = has1 ? bytes[i + 1] : 0;
|
|
4815
|
-
const b2 = has2 ? bytes[i + 2] : 0;
|
|
4816
|
-
out += B64[b0 >> 2] + B64[(b0 & 3) << 4 | b1 >> 4];
|
|
4817
|
-
out += has1 ? B64[(b1 & 15) << 2 | b2 >> 6] : "=";
|
|
4818
|
-
out += has2 ? B64[b2 & 63] : "=";
|
|
4819
|
-
}
|
|
4820
|
-
return out;
|
|
4821
|
-
}
|
|
4822
|
-
function fromB64Lenient(s) {
|
|
4823
|
-
const clean = s.replace(/[^A-Za-z0-9+/]/g, "");
|
|
4824
|
-
const out = [];
|
|
4825
|
-
for (let i = 0; i < clean.length; i += 4) {
|
|
4826
|
-
const c0 = B64.indexOf(clean[i]);
|
|
4827
|
-
const c1 = B64.indexOf(clean[i + 1] ?? "A");
|
|
4828
|
-
const c2 = clean[i + 2] !== void 0 ? B64.indexOf(clean[i + 2]) : -1;
|
|
4829
|
-
const c3 = clean[i + 3] !== void 0 ? B64.indexOf(clean[i + 3]) : -1;
|
|
4830
|
-
out.push(c0 << 2 | c1 >> 4);
|
|
4831
|
-
if (c2 >= 0) out.push((c1 & 15) << 4 | c2 >> 2);
|
|
4832
|
-
if (c3 >= 0) out.push((c2 & 3) << 6 | c3);
|
|
4833
|
-
}
|
|
4834
|
-
return Uint8Array.from(out);
|
|
4835
|
-
}
|
|
4836
|
-
function fromB64(s) {
|
|
4837
|
-
const bytes = fromB64Lenient(s);
|
|
4838
|
-
if (toB64(bytes) !== s) throw new Error("non-canonical base64");
|
|
4839
|
-
return bytes;
|
|
4840
|
-
}
|
|
4841
|
-
function concat(parts) {
|
|
4842
|
-
let n = 0;
|
|
4843
|
-
for (const p of parts) n += p.length;
|
|
4844
|
-
const out = new Uint8Array(n);
|
|
4845
|
-
let o = 0;
|
|
4846
|
-
for (const p of parts) {
|
|
4847
|
-
out.set(p, o);
|
|
4848
|
-
o += p.length;
|
|
4849
|
-
}
|
|
4850
|
-
return out;
|
|
4851
|
-
}
|
|
4852
|
-
function u32be(n) {
|
|
4853
|
-
return Uint8Array.of(n >>> 24 & 255, n >>> 16 & 255, n >>> 8 & 255, n & 255);
|
|
4854
|
-
}
|
|
4855
|
-
function lp(b) {
|
|
4856
|
-
return concat([u32be(b.length), b]);
|
|
4857
|
-
}
|
|
4858
|
-
function eqCt(a, b) {
|
|
4859
|
-
if (a.length !== b.length) return false;
|
|
4860
|
-
let d = 0;
|
|
4861
|
-
for (let i = 0; i < a.length; i++) d |= a[i] ^ b[i];
|
|
4862
|
-
return d === 0;
|
|
4863
|
-
}
|
|
4864
|
-
var ok = false;
|
|
4865
|
-
function ensureCsprng() {
|
|
4866
|
-
if (ok) return;
|
|
4867
|
-
let a;
|
|
4868
|
-
let b;
|
|
4869
|
-
try {
|
|
4870
|
-
a = import_tweetnacl.default.randomBytes(32);
|
|
4871
|
-
b = import_tweetnacl.default.randomBytes(32);
|
|
4872
|
-
} catch {
|
|
4873
|
-
throw new Error("paigy-crypto: no secure RNG available \u2014 refusing to generate keys (fail-closed)");
|
|
4874
|
-
}
|
|
4875
|
-
if (a.every((x) => x === 0) || eqCt(a, b)) {
|
|
4876
|
-
throw new Error("paigy-crypto: RNG self-test failed (constant/low-entropy output)");
|
|
4877
|
-
}
|
|
4878
|
-
ok = true;
|
|
4879
|
-
}
|
|
4880
|
-
function randomBytes(n) {
|
|
4881
|
-
ensureCsprng();
|
|
4882
|
-
return import_tweetnacl.default.randomBytes(n);
|
|
4883
|
-
}
|
|
4884
|
-
function kp(k) {
|
|
4885
|
-
return { publicKey: toB64(k.publicKey), secretKey: toB64(k.secretKey) };
|
|
4886
|
-
}
|
|
4887
|
-
function genDeviceKeypair() {
|
|
4888
|
-
ensureCsprng();
|
|
4889
|
-
return { x25519: kp(import_tweetnacl2.default.box.keyPair()), ed25519: kp(import_tweetnacl2.default.sign.keyPair()) };
|
|
4890
|
-
}
|
|
4891
|
-
function sharedSecret(peerX25519PubB64, mySecretB64) {
|
|
4892
|
-
const raw = import_tweetnacl2.default.scalarMult(fromB64(mySecretB64), fromB64(peerX25519PubB64));
|
|
4893
|
-
if (raw.every((b) => b === 0)) throw new Error("low-order X25519 point \u2014 shared secret rejected");
|
|
4894
|
-
return toB64(raw);
|
|
4895
|
-
}
|
|
4896
|
-
function credentialBody(c) {
|
|
4897
|
-
return concat([
|
|
4898
|
-
lp(utf8ToBytes("paigy-device-credential-v1")),
|
|
4899
|
-
lp(utf8ToBytes(c.deviceId)),
|
|
4900
|
-
lp(utf8ToBytes(c.kind)),
|
|
4901
|
-
lp(fromB64(c.x25519Pub)),
|
|
4902
|
-
lp(fromB64(c.ed25519Pub))
|
|
4903
|
-
]);
|
|
4904
|
-
}
|
|
4905
|
-
function verifyDeviceCredential(cred, uikPublicB64) {
|
|
4906
|
-
const { sig, ...fields } = cred;
|
|
4907
|
-
try {
|
|
4908
|
-
return import_tweetnacl2.default.sign.detached.verify(credentialBody(fields), fromB64(sig), fromB64(uikPublicB64));
|
|
4909
|
-
} catch {
|
|
4910
|
-
return false;
|
|
4911
|
-
}
|
|
4912
|
-
}
|
|
4913
|
-
var SAS_DOMAIN = "paigy-sas-v2";
|
|
4914
|
-
function deriveSAS(input, bits = 24) {
|
|
4915
|
-
const bundle = concat([
|
|
4916
|
-
lp(utf8ToBytes(SAS_DOMAIN)),
|
|
4917
|
-
lp(utf8ToBytes(input.proto)),
|
|
4918
|
-
lp(fromB64(input.ss)),
|
|
4919
|
-
lp(fromB64(input.ca)),
|
|
4920
|
-
lp(fromB64(input.cb))
|
|
4921
|
-
]);
|
|
4922
|
-
const d = import_tweetnacl4.default.hash(bundle);
|
|
4923
|
-
const nbytes = Math.ceil(bits / 8);
|
|
4924
|
-
let n = 0n;
|
|
4925
|
-
for (let i = 0; i < nbytes; i++) n = n << 8n | BigInt(d[i]);
|
|
4926
|
-
n &= (1n << BigInt(bits)) - 1n;
|
|
4927
|
-
const digits = (2n ** BigInt(bits) - 1n).toString().length;
|
|
4928
|
-
return n.toString().padStart(digits, "0").replace(/(\d{3})(?=\d)/g, "$1 ");
|
|
4929
|
-
}
|
|
4930
|
-
var COMMIT_DOMAIN = "paigy-commit-v1";
|
|
4931
|
-
function commit(valuesB64) {
|
|
4932
|
-
return toB64(import_tweetnacl5.default.hash(concat([lp(utf8ToBytes(COMMIT_DOMAIN)), ...valuesB64.map((v) => lp(fromB64(v)))])).slice(0, 32));
|
|
4933
|
-
}
|
|
4934
|
-
function commitPairing(proto, role, x25519Pub, ed25519Pub, nonce, uikPub) {
|
|
4935
|
-
const vals = [toB64(utf8ToBytes(proto)), toB64(utf8ToBytes(role)), x25519Pub, ed25519Pub, nonce];
|
|
4936
|
-
if (uikPub !== void 0) vals.push(uikPub);
|
|
4937
|
-
return commit(vals);
|
|
4938
|
-
}
|
|
4939
|
-
function verifyPairingCommit(commitment, proto, role, x25519Pub, ed25519Pub, nonce, uikPub) {
|
|
4940
|
-
try {
|
|
4941
|
-
return eqCt(fromB64(commitment), fromB64(commitPairing(proto, role, x25519Pub, ed25519Pub, nonce, uikPub)));
|
|
4942
|
-
} catch {
|
|
4943
|
-
return false;
|
|
4944
|
-
}
|
|
4945
|
-
}
|
|
4946
2382
|
function sessionSlot(sessionId2) {
|
|
4947
2383
|
const id = sessionId2 ?? sessionId();
|
|
4948
2384
|
return `session:${id.slice(0, 8)}`;
|
|
4949
2385
|
}
|
|
4950
|
-
|
|
4951
|
-
|
|
4952
|
-
|
|
4953
|
-
var TOKEN_PATH =
|
|
4954
|
-
var KEY_PATH =
|
|
2386
|
+
function agentName() {
|
|
2387
|
+
return process.env.PAIGY_AGENT || sessionSlot();
|
|
2388
|
+
}
|
|
2389
|
+
var TOKEN_PATH = join2(homedir2(), ".paigy", "token.json");
|
|
2390
|
+
var KEY_PATH = join2(homedir2(), ".paigy", "key.json");
|
|
4955
2391
|
function readTokenFile() {
|
|
4956
2392
|
if (!existsSync(TOKEN_PATH)) return {};
|
|
4957
2393
|
try {
|
|
4958
|
-
const parsed = JSON.parse(
|
|
2394
|
+
const parsed = JSON.parse(readFileSync2(TOKEN_PATH, "utf8"));
|
|
4959
2395
|
if (typeof parsed.access_token === "string") return {};
|
|
4960
2396
|
const slots = parsed;
|
|
4961
2397
|
delete slots["*"];
|
|
@@ -4967,7 +2403,7 @@ function readTokenFile() {
|
|
|
4967
2403
|
function withTokenLock(mutate) {
|
|
4968
2404
|
const lock = TOKEN_PATH + ".lock";
|
|
4969
2405
|
const spin = new Int32Array(new SharedArrayBuffer(4));
|
|
4970
|
-
mkdirSync(
|
|
2406
|
+
mkdirSync(join2(homedir2(), ".paigy"), { recursive: true });
|
|
4971
2407
|
for (const deadline = Date.now() + 5e3; Date.now() < deadline; ) {
|
|
4972
2408
|
try {
|
|
4973
2409
|
closeSync(openSync(lock, "wx"));
|
|
@@ -4984,14 +2420,14 @@ function withTokenLock(mutate) {
|
|
|
4984
2420
|
rmSync(lock, { force: true });
|
|
4985
2421
|
}
|
|
4986
2422
|
}
|
|
4987
|
-
function saveToken(token, agent2 =
|
|
2423
|
+
function saveToken(token, agent2 = agentName()) {
|
|
4988
2424
|
withTokenLock(() => {
|
|
4989
2425
|
const slots = { ...readTokenFile(), [agent2]: token };
|
|
4990
2426
|
writeFileSync(TOKEN_PATH, JSON.stringify(slots, null, 2) + "\n", { mode: 384 });
|
|
4991
2427
|
});
|
|
4992
2428
|
}
|
|
4993
2429
|
var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
4994
|
-
function readToken(agent2 =
|
|
2430
|
+
function readToken(agent2 = agentName()) {
|
|
4995
2431
|
if (process.env.PAIGY_TOKEN) return process.env.PAIGY_TOKEN;
|
|
4996
2432
|
return readTokenFile()[agent2]?.access_token ?? "";
|
|
4997
2433
|
}
|
|
@@ -5001,7 +2437,7 @@ function listSlots() {
|
|
|
5001
2437
|
function slotName(agent2) {
|
|
5002
2438
|
return readTokenFile()[agent2]?.name ?? null;
|
|
5003
2439
|
}
|
|
5004
|
-
function deleteToken(agent2 =
|
|
2440
|
+
function deleteToken(agent2 = agentName()) {
|
|
5005
2441
|
return withTokenLock(() => {
|
|
5006
2442
|
const slots = readTokenFile();
|
|
5007
2443
|
if (!(agent2 in slots)) return false;
|
|
@@ -5018,24 +2454,23 @@ async function revokeToken(token) {
|
|
|
5018
2454
|
});
|
|
5019
2455
|
return res.ok;
|
|
5020
2456
|
}
|
|
5021
|
-
async function requestCode(suggestedName =
|
|
2457
|
+
async function requestCode(suggestedName = agentName(), device) {
|
|
5022
2458
|
const res = await reach(`${BACKEND_URL}/api/device/code`, {
|
|
5023
2459
|
method: "POST",
|
|
5024
2460
|
headers: { "content-type": "application/json" },
|
|
5025
2461
|
body: JSON.stringify({
|
|
5026
2462
|
suggestedName,
|
|
5027
|
-
...device ? { device } : {}
|
|
5028
|
-
...e2ee ? { proto: e2ee.proto, commitment: e2ee.commitment } : {}
|
|
2463
|
+
...device ? { device } : {}
|
|
5029
2464
|
})
|
|
5030
2465
|
});
|
|
5031
2466
|
if (!res.ok) throw new Error(`/api/device/code failed: ${res.status} ${await res.text()}`);
|
|
5032
2467
|
return await res.json();
|
|
5033
2468
|
}
|
|
5034
|
-
async function pollToken(deviceCode
|
|
2469
|
+
async function pollToken(deviceCode) {
|
|
5035
2470
|
const res = await reach(`${BACKEND_URL}/api/device/token`, {
|
|
5036
2471
|
method: "POST",
|
|
5037
2472
|
headers: { "content-type": "application/json" },
|
|
5038
|
-
body: JSON.stringify(
|
|
2473
|
+
body: JSON.stringify({ device_code: deviceCode })
|
|
5039
2474
|
});
|
|
5040
2475
|
if (res.ok) return await res.json();
|
|
5041
2476
|
const body = await res.json().catch(() => ({ error: "unknown" }));
|
|
@@ -5047,96 +2482,6 @@ async function pollToken(deviceCode, reveal) {
|
|
|
5047
2482
|
if (err === "access_denied") throw new Error("Access denied by user. Pairing cancelled.");
|
|
5048
2483
|
throw new Error(`Unexpected error from /api/device/token: ${err}`);
|
|
5049
2484
|
}
|
|
5050
|
-
function saveKeyFile(kf) {
|
|
5051
|
-
mkdirSync(join(homedir(), ".paigy"), { recursive: true });
|
|
5052
|
-
writeFileSync(KEY_PATH, JSON.stringify(kf, null, 2) + "\n", { mode: 384 });
|
|
5053
|
-
}
|
|
5054
|
-
function readKeyFile() {
|
|
5055
|
-
if (!existsSync(KEY_PATH)) return null;
|
|
5056
|
-
try {
|
|
5057
|
-
return JSON.parse(readFileSync(KEY_PATH, "utf8"));
|
|
5058
|
-
} catch {
|
|
5059
|
-
return null;
|
|
5060
|
-
}
|
|
5061
|
-
}
|
|
5062
|
-
function deleteKeyFile() {
|
|
5063
|
-
if (!existsSync(KEY_PATH)) return false;
|
|
5064
|
-
rmSync(KEY_PATH);
|
|
5065
|
-
return true;
|
|
5066
|
-
}
|
|
5067
|
-
function startE2ee() {
|
|
5068
|
-
const keypair = genDeviceKeypair();
|
|
5069
|
-
const nonce = toB64(randomBytes(32));
|
|
5070
|
-
const ca = commitPairing(PROTO, "A", keypair.x25519.publicKey, keypair.ed25519.publicKey, nonce);
|
|
5071
|
-
const keyFile = { proto: PROTO, keypair, nonce, ca, e2ee: false };
|
|
5072
|
-
saveKeyFile(keyFile);
|
|
5073
|
-
return { keyFile, offer: { proto: PROTO, commitment: ca } };
|
|
5074
|
-
}
|
|
5075
|
-
async function fetchPeerCommit(deviceCode) {
|
|
5076
|
-
const res = await reach(`${BACKEND_URL}/api/device/peer-commit?device_code=${encodeURIComponent(deviceCode)}`);
|
|
5077
|
-
if (!res.ok) return null;
|
|
5078
|
-
const body = await res.json().catch(() => ({}));
|
|
5079
|
-
return body.commitment ?? null;
|
|
5080
|
-
}
|
|
5081
|
-
function agentReveal(kf) {
|
|
5082
|
-
return { x25519: kf.keypair.x25519.publicKey, ed25519: kf.keypair.ed25519.publicKey, nonce: kf.nonce };
|
|
5083
|
-
}
|
|
5084
|
-
function computeSAS(kf, cb, phoneReveal, uikPub) {
|
|
5085
|
-
const opens = verifyPairingCommit(cb, PROTO, "P", phoneReveal.x25519, phoneReveal.ed25519, phoneReveal.nonce, uikPub);
|
|
5086
|
-
if (!opens) throw new Error("phone reveal does not open its commitment \u2014 aborting E2EE");
|
|
5087
|
-
const ss = sharedSecret(phoneReveal.x25519, kf.keypair.x25519.secretKey);
|
|
5088
|
-
return deriveSAS({ proto: PROTO, ss, ca: kf.ca, cb }, SAS_BITS);
|
|
5089
|
-
}
|
|
5090
|
-
function finalizeE2ee(kf, credential, uikPub) {
|
|
5091
|
-
if (!verifyDeviceCredential(credential, uikPub)) return false;
|
|
5092
|
-
if (credential.x25519Pub !== kf.keypair.x25519.publicKey || credential.ed25519Pub !== kf.keypair.ed25519.publicKey) {
|
|
5093
|
-
return false;
|
|
5094
|
-
}
|
|
5095
|
-
saveKeyFile({ ...kf, e2ee: true, uikPub });
|
|
5096
|
-
return true;
|
|
5097
|
-
}
|
|
5098
|
-
async function fetchCredential(userCode) {
|
|
5099
|
-
const res = await reach(`${BACKEND_URL}/api/device/info?code=${encodeURIComponent(userCode)}`);
|
|
5100
|
-
if (!res.ok) return null;
|
|
5101
|
-
const body = await res.json().catch(() => ({}));
|
|
5102
|
-
return body.agent_credential ?? null;
|
|
5103
|
-
}
|
|
5104
|
-
async function fetchPhoneReveal(userCode) {
|
|
5105
|
-
const res = await reach(`${BACKEND_URL}/api/device/info?code=${encodeURIComponent(userCode)}`);
|
|
5106
|
-
if (!res.ok) return null;
|
|
5107
|
-
const body = await res.json().catch(() => ({}));
|
|
5108
|
-
if (!body.phone_reveal || !body.uik_pub) return null;
|
|
5109
|
-
return { phone_reveal: body.phone_reveal, uik_pub: body.uik_pub };
|
|
5110
|
-
}
|
|
5111
|
-
async function pairStep(deviceCode, keyFile) {
|
|
5112
|
-
if (!keyFile) {
|
|
5113
|
-
const token2 = await pollToken(deviceCode);
|
|
5114
|
-
return token2 ? { kind: "paired", token: token2 } : { kind: "pending" };
|
|
5115
|
-
}
|
|
5116
|
-
const cb = await fetchPeerCommit(deviceCode);
|
|
5117
|
-
if (!cb) {
|
|
5118
|
-
const token2 = await pollToken(deviceCode);
|
|
5119
|
-
return token2 ? { kind: "paired", token: token2 } : { kind: "pending" };
|
|
5120
|
-
}
|
|
5121
|
-
const token = await pollToken(deviceCode, agentReveal(keyFile));
|
|
5122
|
-
if (!token) {
|
|
5123
|
-
const gated = keyFile.userCode ? await fetchPhoneReveal(keyFile.userCode) : null;
|
|
5124
|
-
if (!gated) return { kind: "pending" };
|
|
5125
|
-
try {
|
|
5126
|
-
const sas = computeSAS(keyFile, cb, gated.phone_reveal, gated.uik_pub);
|
|
5127
|
-
return { kind: "awaiting_confirm", sas, uikPub: gated.uik_pub };
|
|
5128
|
-
} catch (e) {
|
|
5129
|
-
return { kind: "e2ee_aborted", warning: e.message };
|
|
5130
|
-
}
|
|
5131
|
-
}
|
|
5132
|
-
if (!token.phone_reveal || !token.uik_pub) return { kind: "paired", token };
|
|
5133
|
-
try {
|
|
5134
|
-
const sas = computeSAS(keyFile, cb, token.phone_reveal, token.uik_pub);
|
|
5135
|
-
return { kind: "paired", token, sas, uikPub: token.uik_pub };
|
|
5136
|
-
} catch (e) {
|
|
5137
|
-
return { kind: "e2ee_aborted", warning: e.message };
|
|
5138
|
-
}
|
|
5139
|
-
}
|
|
5140
2485
|
var UnpairedError = class extends Error {
|
|
5141
2486
|
constructor() {
|
|
5142
2487
|
super("Not paired with Paigy \u2014 no valid token (the API answered 401). Run the pairing flow, then retry.");
|
|
@@ -5272,20 +2617,34 @@ async function contact(input, opts = {}) {
|
|
|
5272
2617
|
const send2 = opts.reach ?? reach;
|
|
5273
2618
|
const headers = { "content-type": "application/json", authorization: `Bearer ${authToken(opts.token) ?? ""}`, "x-paigy-model": "goal-entry-v1" };
|
|
5274
2619
|
let deliveryId;
|
|
5275
|
-
|
|
5276
|
-
|
|
5277
|
-
|
|
5278
|
-
|
|
5279
|
-
const
|
|
2620
|
+
let deliveries = [];
|
|
2621
|
+
if ("deliveryId" in parsed) {
|
|
2622
|
+
deliveryId = parsed.deliveryId;
|
|
2623
|
+
} else {
|
|
2624
|
+
const reqAsks = parsed.asks.map((a) => ({
|
|
2625
|
+
id: a.id,
|
|
2626
|
+
parentId: a.parentId,
|
|
2627
|
+
repo: a.repo,
|
|
2628
|
+
ask: a.ask,
|
|
2629
|
+
options: a.options ?? []
|
|
2630
|
+
}));
|
|
2631
|
+
const res = ensureAuthed(await send2(`${BACKEND_URL}/api/goals/contact`, {
|
|
5280
2632
|
method: "POST",
|
|
5281
2633
|
headers,
|
|
5282
2634
|
signal: opts.signal,
|
|
5283
|
-
body: JSON.stringify({
|
|
2635
|
+
body: JSON.stringify({
|
|
2636
|
+
operationId: opts.operationId ?? randomUUID3(),
|
|
2637
|
+
asks: reqAsks,
|
|
2638
|
+
waiting: parsed.waiting,
|
|
2639
|
+
channel: parsed.channel === "call" ? "call" : "message"
|
|
2640
|
+
})
|
|
5284
2641
|
}));
|
|
5285
|
-
if (!res.ok) await fail("
|
|
2642
|
+
if (!res.ok) await fail("batch contact", res);
|
|
5286
2643
|
const receipt = await res.json();
|
|
5287
|
-
|
|
5288
|
-
if (
|
|
2644
|
+
deliveries = receipt.deliveries ?? [];
|
|
2645
|
+
if (deliveries.length === 0) throw new Error("Goal contact returned no Delivery identities");
|
|
2646
|
+
deliveryId = deliveries[0]?.deliveryId ?? "";
|
|
2647
|
+
if (!deliveryId) throw new Error("Goal contact returned no valid Delivery identity");
|
|
5289
2648
|
}
|
|
5290
2649
|
const read = async (signal2) => {
|
|
5291
2650
|
const res = ensureAuthed(await send2(`${BACKEND_URL}/api/deliveries/${encodeURIComponent(deliveryId)}`, { headers, signal: signal2 }));
|
|
@@ -5375,7 +2734,6 @@ function goalView(g) {
|
|
|
5375
2734
|
blockedBy: g.blockedDependencyGoalIds,
|
|
5376
2735
|
dueAt: g.dueAt,
|
|
5377
2736
|
leaseExpiresAt: g.leaseExpiresAt,
|
|
5378
|
-
contextThreadId: g.contextThreadId,
|
|
5379
2737
|
conversation: conversation(g),
|
|
5380
2738
|
next: g.message
|
|
5381
2739
|
});
|
|
@@ -5386,7 +2744,6 @@ function deliveryView(d) {
|
|
|
5386
2744
|
kind: d.kind,
|
|
5387
2745
|
state: d.state,
|
|
5388
2746
|
goalIds: d.goalIds,
|
|
5389
|
-
threadId: d.threadId,
|
|
5390
2747
|
conversation: conversation(d),
|
|
5391
2748
|
next: d.kind === "notification" ? "Answers land on the Goal: read them with claim_goal or get_goal. Do not poll this notification." : d.message
|
|
5392
2749
|
});
|
|
@@ -5552,7 +2909,7 @@ async function subscribeWake(onNudge, opts = {}) {
|
|
|
5552
2909
|
export {
|
|
5553
2910
|
isNetworkError,
|
|
5554
2911
|
sessionSlot,
|
|
5555
|
-
|
|
2912
|
+
agentName,
|
|
5556
2913
|
TOKEN_PATH,
|
|
5557
2914
|
saveToken,
|
|
5558
2915
|
sleep,
|
|
@@ -5562,13 +2919,7 @@ export {
|
|
|
5562
2919
|
deleteToken,
|
|
5563
2920
|
revokeToken,
|
|
5564
2921
|
requestCode,
|
|
5565
|
-
|
|
5566
|
-
readKeyFile,
|
|
5567
|
-
deleteKeyFile,
|
|
5568
|
-
startE2ee,
|
|
5569
|
-
finalizeE2ee,
|
|
5570
|
-
fetchCredential,
|
|
5571
|
-
pairStep,
|
|
2922
|
+
pollToken,
|
|
5572
2923
|
UnpairedError,
|
|
5573
2924
|
getGoal,
|
|
5574
2925
|
overrideToken,
|