@paigy/harness 0.3.13 → 0.3.14
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/cli.js +293 -2741
- package/dist/main.js +296 -2743
- package/package.json +2 -2
package/dist/main.js
CHANGED
|
@@ -3479,7 +3479,7 @@ var require_sync_inflate = __commonJS({
|
|
|
3479
3479
|
if (typeof asyncCb === "function") {
|
|
3480
3480
|
return zlib.Inflate._processChunk.call(this, chunk, flushFlag, asyncCb);
|
|
3481
3481
|
}
|
|
3482
|
-
let
|
|
3482
|
+
let self = this;
|
|
3483
3483
|
let availInBefore = chunk && chunk.length;
|
|
3484
3484
|
let availOutBefore = this._chunkSize - this._offset;
|
|
3485
3485
|
let leftToInflate = this._maxLength;
|
|
@@ -3491,14 +3491,14 @@ var require_sync_inflate = __commonJS({
|
|
|
3491
3491
|
error = err;
|
|
3492
3492
|
});
|
|
3493
3493
|
function handleChunk(availInAfter, availOutAfter) {
|
|
3494
|
-
if (
|
|
3494
|
+
if (self._hadError) {
|
|
3495
3495
|
return;
|
|
3496
3496
|
}
|
|
3497
3497
|
let have = availOutBefore - availOutAfter;
|
|
3498
3498
|
assert(have >= 0, "have should not go down");
|
|
3499
3499
|
if (have > 0) {
|
|
3500
|
-
let out =
|
|
3501
|
-
|
|
3500
|
+
let out = self._buffer.slice(self._offset, self._offset + have);
|
|
3501
|
+
self._offset += have;
|
|
3502
3502
|
if (out.length > leftToInflate) {
|
|
3503
3503
|
out = out.slice(0, leftToInflate);
|
|
3504
3504
|
}
|
|
@@ -3509,10 +3509,10 @@ var require_sync_inflate = __commonJS({
|
|
|
3509
3509
|
return false;
|
|
3510
3510
|
}
|
|
3511
3511
|
}
|
|
3512
|
-
if (availOutAfter === 0 ||
|
|
3513
|
-
availOutBefore =
|
|
3514
|
-
|
|
3515
|
-
|
|
3512
|
+
if (availOutAfter === 0 || self._offset >= self._chunkSize) {
|
|
3513
|
+
availOutBefore = self._chunkSize;
|
|
3514
|
+
self._offset = 0;
|
|
3515
|
+
self._buffer = Buffer.allocUnsafe(self._chunkSize);
|
|
3516
3516
|
}
|
|
3517
3517
|
if (availOutAfter === 0) {
|
|
3518
3518
|
inOff += availInBefore - availInAfter;
|
|
@@ -4578,13 +4578,17 @@ var require_lib = __commonJS({
|
|
|
4578
4578
|
// src/main.ts
|
|
4579
4579
|
import { app, BrowserWindow, dialog, ipcMain } from "electron";
|
|
4580
4580
|
import { spawn as spawn2 } from "child_process";
|
|
4581
|
-
import { readFileSync as
|
|
4581
|
+
import { readFileSync as readFileSync5 } from "fs";
|
|
4582
4582
|
import { fileURLToPath } from "url";
|
|
4583
|
-
import { dirname as dirname4, join as
|
|
4583
|
+
import { dirname as dirname4, join as join8 } from "path";
|
|
4584
4584
|
|
|
4585
4585
|
// ../../packages/sdk/dist/index.js
|
|
4586
4586
|
import { createRequire as __sdkCreateRequire } from "module";
|
|
4587
|
+
import { execFileSync } from "child_process";
|
|
4587
4588
|
import { createHash, randomUUID } from "crypto";
|
|
4589
|
+
import { readFileSync } from "fs";
|
|
4590
|
+
import { homedir } from "os";
|
|
4591
|
+
import { join } from "path";
|
|
4588
4592
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
4589
4593
|
import { setTimeout as sleep2 } from "timers/promises";
|
|
4590
4594
|
|
|
@@ -8631,2265 +8635,11 @@ var NEVER = INVALID;
|
|
|
8631
8635
|
|
|
8632
8636
|
// ../../packages/sdk/dist/index.js
|
|
8633
8637
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
8634
|
-
import { closeSync, existsSync, mkdirSync, openSync, readFileSync, rmSync, statSync, writeFileSync } from "fs";
|
|
8635
|
-
import { homedir } from "os";
|
|
8636
|
-
import { join } from "path";
|
|
8638
|
+
import { closeSync, existsSync, mkdirSync, openSync, readFileSync as readFileSync2, rmSync, statSync, writeFileSync } from "fs";
|
|
8639
|
+
import { homedir as homedir2 } from "os";
|
|
8640
|
+
import { join as join2 } from "path";
|
|
8637
8641
|
var import_undici = __toESM(require_undici(), 1);
|
|
8638
8642
|
var require2 = __sdkCreateRequire(import.meta.url);
|
|
8639
|
-
var __create = Object.create;
|
|
8640
|
-
var __defProp = Object.defineProperty;
|
|
8641
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
8642
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8643
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8644
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8645
|
-
var __require2 = /* @__PURE__ */ ((x) => typeof require2 !== "undefined" ? require2 : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
8646
|
-
get: (a, b) => (typeof require2 !== "undefined" ? require2 : a)[b]
|
|
8647
|
-
}) : x)(function(x) {
|
|
8648
|
-
if (typeof require2 !== "undefined") return require2.apply(this, arguments);
|
|
8649
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
8650
|
-
});
|
|
8651
|
-
var __commonJS2 = (cb, mod) => function __require22() {
|
|
8652
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
8653
|
-
};
|
|
8654
|
-
var __copyProps = (to, from, except, desc) => {
|
|
8655
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8656
|
-
for (let key of __getOwnPropNames(from))
|
|
8657
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
8658
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
8659
|
-
}
|
|
8660
|
-
return to;
|
|
8661
|
-
};
|
|
8662
|
-
var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
8663
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
8664
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
8665
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
8666
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
8667
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
8668
|
-
mod
|
|
8669
|
-
));
|
|
8670
|
-
var require_nacl_fast = __commonJS2({
|
|
8671
|
-
"../../node_modules/.pnpm/tweetnacl@1.0.3/node_modules/tweetnacl/nacl-fast.js"(exports, module) {
|
|
8672
|
-
"use strict";
|
|
8673
|
-
(function(nacl6) {
|
|
8674
|
-
"use strict";
|
|
8675
|
-
var gf = function(init) {
|
|
8676
|
-
var i, r = new Float64Array(16);
|
|
8677
|
-
if (init) for (i = 0; i < init.length; i++) r[i] = init[i];
|
|
8678
|
-
return r;
|
|
8679
|
-
};
|
|
8680
|
-
var randombytes = function() {
|
|
8681
|
-
throw new Error("no PRNG");
|
|
8682
|
-
};
|
|
8683
|
-
var _0 = new Uint8Array(16);
|
|
8684
|
-
var _9 = new Uint8Array(32);
|
|
8685
|
-
_9[0] = 9;
|
|
8686
|
-
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]);
|
|
8687
|
-
function ts64(x, i, h, l) {
|
|
8688
|
-
x[i] = h >> 24 & 255;
|
|
8689
|
-
x[i + 1] = h >> 16 & 255;
|
|
8690
|
-
x[i + 2] = h >> 8 & 255;
|
|
8691
|
-
x[i + 3] = h & 255;
|
|
8692
|
-
x[i + 4] = l >> 24 & 255;
|
|
8693
|
-
x[i + 5] = l >> 16 & 255;
|
|
8694
|
-
x[i + 6] = l >> 8 & 255;
|
|
8695
|
-
x[i + 7] = l & 255;
|
|
8696
|
-
}
|
|
8697
|
-
function vn(x, xi, y, yi, n) {
|
|
8698
|
-
var i, d = 0;
|
|
8699
|
-
for (i = 0; i < n; i++) d |= x[xi + i] ^ y[yi + i];
|
|
8700
|
-
return (1 & d - 1 >>> 8) - 1;
|
|
8701
|
-
}
|
|
8702
|
-
function crypto_verify_16(x, xi, y, yi) {
|
|
8703
|
-
return vn(x, xi, y, yi, 16);
|
|
8704
|
-
}
|
|
8705
|
-
function crypto_verify_32(x, xi, y, yi) {
|
|
8706
|
-
return vn(x, xi, y, yi, 32);
|
|
8707
|
-
}
|
|
8708
|
-
function core_salsa20(o, p, k, c) {
|
|
8709
|
-
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;
|
|
8710
|
-
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;
|
|
8711
|
-
for (var i = 0; i < 20; i += 2) {
|
|
8712
|
-
u = x0 + x12 | 0;
|
|
8713
|
-
x4 ^= u << 7 | u >>> 32 - 7;
|
|
8714
|
-
u = x4 + x0 | 0;
|
|
8715
|
-
x8 ^= u << 9 | u >>> 32 - 9;
|
|
8716
|
-
u = x8 + x4 | 0;
|
|
8717
|
-
x12 ^= u << 13 | u >>> 32 - 13;
|
|
8718
|
-
u = x12 + x8 | 0;
|
|
8719
|
-
x0 ^= u << 18 | u >>> 32 - 18;
|
|
8720
|
-
u = x5 + x1 | 0;
|
|
8721
|
-
x9 ^= u << 7 | u >>> 32 - 7;
|
|
8722
|
-
u = x9 + x5 | 0;
|
|
8723
|
-
x13 ^= u << 9 | u >>> 32 - 9;
|
|
8724
|
-
u = x13 + x9 | 0;
|
|
8725
|
-
x1 ^= u << 13 | u >>> 32 - 13;
|
|
8726
|
-
u = x1 + x13 | 0;
|
|
8727
|
-
x5 ^= u << 18 | u >>> 32 - 18;
|
|
8728
|
-
u = x10 + x6 | 0;
|
|
8729
|
-
x14 ^= u << 7 | u >>> 32 - 7;
|
|
8730
|
-
u = x14 + x10 | 0;
|
|
8731
|
-
x2 ^= u << 9 | u >>> 32 - 9;
|
|
8732
|
-
u = x2 + x14 | 0;
|
|
8733
|
-
x6 ^= u << 13 | u >>> 32 - 13;
|
|
8734
|
-
u = x6 + x2 | 0;
|
|
8735
|
-
x10 ^= u << 18 | u >>> 32 - 18;
|
|
8736
|
-
u = x15 + x11 | 0;
|
|
8737
|
-
x3 ^= u << 7 | u >>> 32 - 7;
|
|
8738
|
-
u = x3 + x15 | 0;
|
|
8739
|
-
x7 ^= u << 9 | u >>> 32 - 9;
|
|
8740
|
-
u = x7 + x3 | 0;
|
|
8741
|
-
x11 ^= u << 13 | u >>> 32 - 13;
|
|
8742
|
-
u = x11 + x7 | 0;
|
|
8743
|
-
x15 ^= u << 18 | u >>> 32 - 18;
|
|
8744
|
-
u = x0 + x3 | 0;
|
|
8745
|
-
x1 ^= u << 7 | u >>> 32 - 7;
|
|
8746
|
-
u = x1 + x0 | 0;
|
|
8747
|
-
x2 ^= u << 9 | u >>> 32 - 9;
|
|
8748
|
-
u = x2 + x1 | 0;
|
|
8749
|
-
x3 ^= u << 13 | u >>> 32 - 13;
|
|
8750
|
-
u = x3 + x2 | 0;
|
|
8751
|
-
x0 ^= u << 18 | u >>> 32 - 18;
|
|
8752
|
-
u = x5 + x4 | 0;
|
|
8753
|
-
x6 ^= u << 7 | u >>> 32 - 7;
|
|
8754
|
-
u = x6 + x5 | 0;
|
|
8755
|
-
x7 ^= u << 9 | u >>> 32 - 9;
|
|
8756
|
-
u = x7 + x6 | 0;
|
|
8757
|
-
x4 ^= u << 13 | u >>> 32 - 13;
|
|
8758
|
-
u = x4 + x7 | 0;
|
|
8759
|
-
x5 ^= u << 18 | u >>> 32 - 18;
|
|
8760
|
-
u = x10 + x9 | 0;
|
|
8761
|
-
x11 ^= u << 7 | u >>> 32 - 7;
|
|
8762
|
-
u = x11 + x10 | 0;
|
|
8763
|
-
x8 ^= u << 9 | u >>> 32 - 9;
|
|
8764
|
-
u = x8 + x11 | 0;
|
|
8765
|
-
x9 ^= u << 13 | u >>> 32 - 13;
|
|
8766
|
-
u = x9 + x8 | 0;
|
|
8767
|
-
x10 ^= u << 18 | u >>> 32 - 18;
|
|
8768
|
-
u = x15 + x14 | 0;
|
|
8769
|
-
x12 ^= u << 7 | u >>> 32 - 7;
|
|
8770
|
-
u = x12 + x15 | 0;
|
|
8771
|
-
x13 ^= u << 9 | u >>> 32 - 9;
|
|
8772
|
-
u = x13 + x12 | 0;
|
|
8773
|
-
x14 ^= u << 13 | u >>> 32 - 13;
|
|
8774
|
-
u = x14 + x13 | 0;
|
|
8775
|
-
x15 ^= u << 18 | u >>> 32 - 18;
|
|
8776
|
-
}
|
|
8777
|
-
x0 = x0 + j0 | 0;
|
|
8778
|
-
x1 = x1 + j1 | 0;
|
|
8779
|
-
x2 = x2 + j2 | 0;
|
|
8780
|
-
x3 = x3 + j3 | 0;
|
|
8781
|
-
x4 = x4 + j4 | 0;
|
|
8782
|
-
x5 = x5 + j5 | 0;
|
|
8783
|
-
x6 = x6 + j6 | 0;
|
|
8784
|
-
x7 = x7 + j7 | 0;
|
|
8785
|
-
x8 = x8 + j8 | 0;
|
|
8786
|
-
x9 = x9 + j9 | 0;
|
|
8787
|
-
x10 = x10 + j10 | 0;
|
|
8788
|
-
x11 = x11 + j11 | 0;
|
|
8789
|
-
x12 = x12 + j12 | 0;
|
|
8790
|
-
x13 = x13 + j13 | 0;
|
|
8791
|
-
x14 = x14 + j14 | 0;
|
|
8792
|
-
x15 = x15 + j15 | 0;
|
|
8793
|
-
o[0] = x0 >>> 0 & 255;
|
|
8794
|
-
o[1] = x0 >>> 8 & 255;
|
|
8795
|
-
o[2] = x0 >>> 16 & 255;
|
|
8796
|
-
o[3] = x0 >>> 24 & 255;
|
|
8797
|
-
o[4] = x1 >>> 0 & 255;
|
|
8798
|
-
o[5] = x1 >>> 8 & 255;
|
|
8799
|
-
o[6] = x1 >>> 16 & 255;
|
|
8800
|
-
o[7] = x1 >>> 24 & 255;
|
|
8801
|
-
o[8] = x2 >>> 0 & 255;
|
|
8802
|
-
o[9] = x2 >>> 8 & 255;
|
|
8803
|
-
o[10] = x2 >>> 16 & 255;
|
|
8804
|
-
o[11] = x2 >>> 24 & 255;
|
|
8805
|
-
o[12] = x3 >>> 0 & 255;
|
|
8806
|
-
o[13] = x3 >>> 8 & 255;
|
|
8807
|
-
o[14] = x3 >>> 16 & 255;
|
|
8808
|
-
o[15] = x3 >>> 24 & 255;
|
|
8809
|
-
o[16] = x4 >>> 0 & 255;
|
|
8810
|
-
o[17] = x4 >>> 8 & 255;
|
|
8811
|
-
o[18] = x4 >>> 16 & 255;
|
|
8812
|
-
o[19] = x4 >>> 24 & 255;
|
|
8813
|
-
o[20] = x5 >>> 0 & 255;
|
|
8814
|
-
o[21] = x5 >>> 8 & 255;
|
|
8815
|
-
o[22] = x5 >>> 16 & 255;
|
|
8816
|
-
o[23] = x5 >>> 24 & 255;
|
|
8817
|
-
o[24] = x6 >>> 0 & 255;
|
|
8818
|
-
o[25] = x6 >>> 8 & 255;
|
|
8819
|
-
o[26] = x6 >>> 16 & 255;
|
|
8820
|
-
o[27] = x6 >>> 24 & 255;
|
|
8821
|
-
o[28] = x7 >>> 0 & 255;
|
|
8822
|
-
o[29] = x7 >>> 8 & 255;
|
|
8823
|
-
o[30] = x7 >>> 16 & 255;
|
|
8824
|
-
o[31] = x7 >>> 24 & 255;
|
|
8825
|
-
o[32] = x8 >>> 0 & 255;
|
|
8826
|
-
o[33] = x8 >>> 8 & 255;
|
|
8827
|
-
o[34] = x8 >>> 16 & 255;
|
|
8828
|
-
o[35] = x8 >>> 24 & 255;
|
|
8829
|
-
o[36] = x9 >>> 0 & 255;
|
|
8830
|
-
o[37] = x9 >>> 8 & 255;
|
|
8831
|
-
o[38] = x9 >>> 16 & 255;
|
|
8832
|
-
o[39] = x9 >>> 24 & 255;
|
|
8833
|
-
o[40] = x10 >>> 0 & 255;
|
|
8834
|
-
o[41] = x10 >>> 8 & 255;
|
|
8835
|
-
o[42] = x10 >>> 16 & 255;
|
|
8836
|
-
o[43] = x10 >>> 24 & 255;
|
|
8837
|
-
o[44] = x11 >>> 0 & 255;
|
|
8838
|
-
o[45] = x11 >>> 8 & 255;
|
|
8839
|
-
o[46] = x11 >>> 16 & 255;
|
|
8840
|
-
o[47] = x11 >>> 24 & 255;
|
|
8841
|
-
o[48] = x12 >>> 0 & 255;
|
|
8842
|
-
o[49] = x12 >>> 8 & 255;
|
|
8843
|
-
o[50] = x12 >>> 16 & 255;
|
|
8844
|
-
o[51] = x12 >>> 24 & 255;
|
|
8845
|
-
o[52] = x13 >>> 0 & 255;
|
|
8846
|
-
o[53] = x13 >>> 8 & 255;
|
|
8847
|
-
o[54] = x13 >>> 16 & 255;
|
|
8848
|
-
o[55] = x13 >>> 24 & 255;
|
|
8849
|
-
o[56] = x14 >>> 0 & 255;
|
|
8850
|
-
o[57] = x14 >>> 8 & 255;
|
|
8851
|
-
o[58] = x14 >>> 16 & 255;
|
|
8852
|
-
o[59] = x14 >>> 24 & 255;
|
|
8853
|
-
o[60] = x15 >>> 0 & 255;
|
|
8854
|
-
o[61] = x15 >>> 8 & 255;
|
|
8855
|
-
o[62] = x15 >>> 16 & 255;
|
|
8856
|
-
o[63] = x15 >>> 24 & 255;
|
|
8857
|
-
}
|
|
8858
|
-
function core_hsalsa20(o, p, k, c) {
|
|
8859
|
-
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;
|
|
8860
|
-
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;
|
|
8861
|
-
for (var i = 0; i < 20; i += 2) {
|
|
8862
|
-
u = x0 + x12 | 0;
|
|
8863
|
-
x4 ^= u << 7 | u >>> 32 - 7;
|
|
8864
|
-
u = x4 + x0 | 0;
|
|
8865
|
-
x8 ^= u << 9 | u >>> 32 - 9;
|
|
8866
|
-
u = x8 + x4 | 0;
|
|
8867
|
-
x12 ^= u << 13 | u >>> 32 - 13;
|
|
8868
|
-
u = x12 + x8 | 0;
|
|
8869
|
-
x0 ^= u << 18 | u >>> 32 - 18;
|
|
8870
|
-
u = x5 + x1 | 0;
|
|
8871
|
-
x9 ^= u << 7 | u >>> 32 - 7;
|
|
8872
|
-
u = x9 + x5 | 0;
|
|
8873
|
-
x13 ^= u << 9 | u >>> 32 - 9;
|
|
8874
|
-
u = x13 + x9 | 0;
|
|
8875
|
-
x1 ^= u << 13 | u >>> 32 - 13;
|
|
8876
|
-
u = x1 + x13 | 0;
|
|
8877
|
-
x5 ^= u << 18 | u >>> 32 - 18;
|
|
8878
|
-
u = x10 + x6 | 0;
|
|
8879
|
-
x14 ^= u << 7 | u >>> 32 - 7;
|
|
8880
|
-
u = x14 + x10 | 0;
|
|
8881
|
-
x2 ^= u << 9 | u >>> 32 - 9;
|
|
8882
|
-
u = x2 + x14 | 0;
|
|
8883
|
-
x6 ^= u << 13 | u >>> 32 - 13;
|
|
8884
|
-
u = x6 + x2 | 0;
|
|
8885
|
-
x10 ^= u << 18 | u >>> 32 - 18;
|
|
8886
|
-
u = x15 + x11 | 0;
|
|
8887
|
-
x3 ^= u << 7 | u >>> 32 - 7;
|
|
8888
|
-
u = x3 + x15 | 0;
|
|
8889
|
-
x7 ^= u << 9 | u >>> 32 - 9;
|
|
8890
|
-
u = x7 + x3 | 0;
|
|
8891
|
-
x11 ^= u << 13 | u >>> 32 - 13;
|
|
8892
|
-
u = x11 + x7 | 0;
|
|
8893
|
-
x15 ^= u << 18 | u >>> 32 - 18;
|
|
8894
|
-
u = x0 + x3 | 0;
|
|
8895
|
-
x1 ^= u << 7 | u >>> 32 - 7;
|
|
8896
|
-
u = x1 + x0 | 0;
|
|
8897
|
-
x2 ^= u << 9 | u >>> 32 - 9;
|
|
8898
|
-
u = x2 + x1 | 0;
|
|
8899
|
-
x3 ^= u << 13 | u >>> 32 - 13;
|
|
8900
|
-
u = x3 + x2 | 0;
|
|
8901
|
-
x0 ^= u << 18 | u >>> 32 - 18;
|
|
8902
|
-
u = x5 + x4 | 0;
|
|
8903
|
-
x6 ^= u << 7 | u >>> 32 - 7;
|
|
8904
|
-
u = x6 + x5 | 0;
|
|
8905
|
-
x7 ^= u << 9 | u >>> 32 - 9;
|
|
8906
|
-
u = x7 + x6 | 0;
|
|
8907
|
-
x4 ^= u << 13 | u >>> 32 - 13;
|
|
8908
|
-
u = x4 + x7 | 0;
|
|
8909
|
-
x5 ^= u << 18 | u >>> 32 - 18;
|
|
8910
|
-
u = x10 + x9 | 0;
|
|
8911
|
-
x11 ^= u << 7 | u >>> 32 - 7;
|
|
8912
|
-
u = x11 + x10 | 0;
|
|
8913
|
-
x8 ^= u << 9 | u >>> 32 - 9;
|
|
8914
|
-
u = x8 + x11 | 0;
|
|
8915
|
-
x9 ^= u << 13 | u >>> 32 - 13;
|
|
8916
|
-
u = x9 + x8 | 0;
|
|
8917
|
-
x10 ^= u << 18 | u >>> 32 - 18;
|
|
8918
|
-
u = x15 + x14 | 0;
|
|
8919
|
-
x12 ^= u << 7 | u >>> 32 - 7;
|
|
8920
|
-
u = x12 + x15 | 0;
|
|
8921
|
-
x13 ^= u << 9 | u >>> 32 - 9;
|
|
8922
|
-
u = x13 + x12 | 0;
|
|
8923
|
-
x14 ^= u << 13 | u >>> 32 - 13;
|
|
8924
|
-
u = x14 + x13 | 0;
|
|
8925
|
-
x15 ^= u << 18 | u >>> 32 - 18;
|
|
8926
|
-
}
|
|
8927
|
-
o[0] = x0 >>> 0 & 255;
|
|
8928
|
-
o[1] = x0 >>> 8 & 255;
|
|
8929
|
-
o[2] = x0 >>> 16 & 255;
|
|
8930
|
-
o[3] = x0 >>> 24 & 255;
|
|
8931
|
-
o[4] = x5 >>> 0 & 255;
|
|
8932
|
-
o[5] = x5 >>> 8 & 255;
|
|
8933
|
-
o[6] = x5 >>> 16 & 255;
|
|
8934
|
-
o[7] = x5 >>> 24 & 255;
|
|
8935
|
-
o[8] = x10 >>> 0 & 255;
|
|
8936
|
-
o[9] = x10 >>> 8 & 255;
|
|
8937
|
-
o[10] = x10 >>> 16 & 255;
|
|
8938
|
-
o[11] = x10 >>> 24 & 255;
|
|
8939
|
-
o[12] = x15 >>> 0 & 255;
|
|
8940
|
-
o[13] = x15 >>> 8 & 255;
|
|
8941
|
-
o[14] = x15 >>> 16 & 255;
|
|
8942
|
-
o[15] = x15 >>> 24 & 255;
|
|
8943
|
-
o[16] = x6 >>> 0 & 255;
|
|
8944
|
-
o[17] = x6 >>> 8 & 255;
|
|
8945
|
-
o[18] = x6 >>> 16 & 255;
|
|
8946
|
-
o[19] = x6 >>> 24 & 255;
|
|
8947
|
-
o[20] = x7 >>> 0 & 255;
|
|
8948
|
-
o[21] = x7 >>> 8 & 255;
|
|
8949
|
-
o[22] = x7 >>> 16 & 255;
|
|
8950
|
-
o[23] = x7 >>> 24 & 255;
|
|
8951
|
-
o[24] = x8 >>> 0 & 255;
|
|
8952
|
-
o[25] = x8 >>> 8 & 255;
|
|
8953
|
-
o[26] = x8 >>> 16 & 255;
|
|
8954
|
-
o[27] = x8 >>> 24 & 255;
|
|
8955
|
-
o[28] = x9 >>> 0 & 255;
|
|
8956
|
-
o[29] = x9 >>> 8 & 255;
|
|
8957
|
-
o[30] = x9 >>> 16 & 255;
|
|
8958
|
-
o[31] = x9 >>> 24 & 255;
|
|
8959
|
-
}
|
|
8960
|
-
function crypto_core_salsa20(out, inp, k, c) {
|
|
8961
|
-
core_salsa20(out, inp, k, c);
|
|
8962
|
-
}
|
|
8963
|
-
function crypto_core_hsalsa20(out, inp, k, c) {
|
|
8964
|
-
core_hsalsa20(out, inp, k, c);
|
|
8965
|
-
}
|
|
8966
|
-
var sigma = new Uint8Array([101, 120, 112, 97, 110, 100, 32, 51, 50, 45, 98, 121, 116, 101, 32, 107]);
|
|
8967
|
-
function crypto_stream_salsa20_xor(c, cpos, m, mpos, b, n, k) {
|
|
8968
|
-
var z4 = new Uint8Array(16), x = new Uint8Array(64);
|
|
8969
|
-
var u, i;
|
|
8970
|
-
for (i = 0; i < 16; i++) z4[i] = 0;
|
|
8971
|
-
for (i = 0; i < 8; i++) z4[i] = n[i];
|
|
8972
|
-
while (b >= 64) {
|
|
8973
|
-
crypto_core_salsa20(x, z4, k, sigma);
|
|
8974
|
-
for (i = 0; i < 64; i++) c[cpos + i] = m[mpos + i] ^ x[i];
|
|
8975
|
-
u = 1;
|
|
8976
|
-
for (i = 8; i < 16; i++) {
|
|
8977
|
-
u = u + (z4[i] & 255) | 0;
|
|
8978
|
-
z4[i] = u & 255;
|
|
8979
|
-
u >>>= 8;
|
|
8980
|
-
}
|
|
8981
|
-
b -= 64;
|
|
8982
|
-
cpos += 64;
|
|
8983
|
-
mpos += 64;
|
|
8984
|
-
}
|
|
8985
|
-
if (b > 0) {
|
|
8986
|
-
crypto_core_salsa20(x, z4, k, sigma);
|
|
8987
|
-
for (i = 0; i < b; i++) c[cpos + i] = m[mpos + i] ^ x[i];
|
|
8988
|
-
}
|
|
8989
|
-
return 0;
|
|
8990
|
-
}
|
|
8991
|
-
function crypto_stream_salsa20(c, cpos, b, n, k) {
|
|
8992
|
-
var z4 = new Uint8Array(16), x = new Uint8Array(64);
|
|
8993
|
-
var u, i;
|
|
8994
|
-
for (i = 0; i < 16; i++) z4[i] = 0;
|
|
8995
|
-
for (i = 0; i < 8; i++) z4[i] = n[i];
|
|
8996
|
-
while (b >= 64) {
|
|
8997
|
-
crypto_core_salsa20(x, z4, k, sigma);
|
|
8998
|
-
for (i = 0; i < 64; i++) c[cpos + i] = x[i];
|
|
8999
|
-
u = 1;
|
|
9000
|
-
for (i = 8; i < 16; i++) {
|
|
9001
|
-
u = u + (z4[i] & 255) | 0;
|
|
9002
|
-
z4[i] = u & 255;
|
|
9003
|
-
u >>>= 8;
|
|
9004
|
-
}
|
|
9005
|
-
b -= 64;
|
|
9006
|
-
cpos += 64;
|
|
9007
|
-
}
|
|
9008
|
-
if (b > 0) {
|
|
9009
|
-
crypto_core_salsa20(x, z4, k, sigma);
|
|
9010
|
-
for (i = 0; i < b; i++) c[cpos + i] = x[i];
|
|
9011
|
-
}
|
|
9012
|
-
return 0;
|
|
9013
|
-
}
|
|
9014
|
-
function crypto_stream(c, cpos, d, n, k) {
|
|
9015
|
-
var s = new Uint8Array(32);
|
|
9016
|
-
crypto_core_hsalsa20(s, n, k, sigma);
|
|
9017
|
-
var sn = new Uint8Array(8);
|
|
9018
|
-
for (var i = 0; i < 8; i++) sn[i] = n[i + 16];
|
|
9019
|
-
return crypto_stream_salsa20(c, cpos, d, sn, s);
|
|
9020
|
-
}
|
|
9021
|
-
function crypto_stream_xor(c, cpos, m, mpos, d, n, k) {
|
|
9022
|
-
var s = new Uint8Array(32);
|
|
9023
|
-
crypto_core_hsalsa20(s, n, k, sigma);
|
|
9024
|
-
var sn = new Uint8Array(8);
|
|
9025
|
-
for (var i = 0; i < 8; i++) sn[i] = n[i + 16];
|
|
9026
|
-
return crypto_stream_salsa20_xor(c, cpos, m, mpos, d, sn, s);
|
|
9027
|
-
}
|
|
9028
|
-
var poly1305 = function(key) {
|
|
9029
|
-
this.buffer = new Uint8Array(16);
|
|
9030
|
-
this.r = new Uint16Array(10);
|
|
9031
|
-
this.h = new Uint16Array(10);
|
|
9032
|
-
this.pad = new Uint16Array(8);
|
|
9033
|
-
this.leftover = 0;
|
|
9034
|
-
this.fin = 0;
|
|
9035
|
-
var t0, t1, t2, t3, t4, t5, t6, t7;
|
|
9036
|
-
t0 = key[0] & 255 | (key[1] & 255) << 8;
|
|
9037
|
-
this.r[0] = t0 & 8191;
|
|
9038
|
-
t1 = key[2] & 255 | (key[3] & 255) << 8;
|
|
9039
|
-
this.r[1] = (t0 >>> 13 | t1 << 3) & 8191;
|
|
9040
|
-
t2 = key[4] & 255 | (key[5] & 255) << 8;
|
|
9041
|
-
this.r[2] = (t1 >>> 10 | t2 << 6) & 7939;
|
|
9042
|
-
t3 = key[6] & 255 | (key[7] & 255) << 8;
|
|
9043
|
-
this.r[3] = (t2 >>> 7 | t3 << 9) & 8191;
|
|
9044
|
-
t4 = key[8] & 255 | (key[9] & 255) << 8;
|
|
9045
|
-
this.r[4] = (t3 >>> 4 | t4 << 12) & 255;
|
|
9046
|
-
this.r[5] = t4 >>> 1 & 8190;
|
|
9047
|
-
t5 = key[10] & 255 | (key[11] & 255) << 8;
|
|
9048
|
-
this.r[6] = (t4 >>> 14 | t5 << 2) & 8191;
|
|
9049
|
-
t6 = key[12] & 255 | (key[13] & 255) << 8;
|
|
9050
|
-
this.r[7] = (t5 >>> 11 | t6 << 5) & 8065;
|
|
9051
|
-
t7 = key[14] & 255 | (key[15] & 255) << 8;
|
|
9052
|
-
this.r[8] = (t6 >>> 8 | t7 << 8) & 8191;
|
|
9053
|
-
this.r[9] = t7 >>> 5 & 127;
|
|
9054
|
-
this.pad[0] = key[16] & 255 | (key[17] & 255) << 8;
|
|
9055
|
-
this.pad[1] = key[18] & 255 | (key[19] & 255) << 8;
|
|
9056
|
-
this.pad[2] = key[20] & 255 | (key[21] & 255) << 8;
|
|
9057
|
-
this.pad[3] = key[22] & 255 | (key[23] & 255) << 8;
|
|
9058
|
-
this.pad[4] = key[24] & 255 | (key[25] & 255) << 8;
|
|
9059
|
-
this.pad[5] = key[26] & 255 | (key[27] & 255) << 8;
|
|
9060
|
-
this.pad[6] = key[28] & 255 | (key[29] & 255) << 8;
|
|
9061
|
-
this.pad[7] = key[30] & 255 | (key[31] & 255) << 8;
|
|
9062
|
-
};
|
|
9063
|
-
poly1305.prototype.blocks = function(m, mpos, bytes) {
|
|
9064
|
-
var hibit = this.fin ? 0 : 1 << 11;
|
|
9065
|
-
var t0, t1, t2, t3, t4, t5, t6, t7, c;
|
|
9066
|
-
var d0, d1, d2, d3, d4, d5, d6, d7, d8, d9;
|
|
9067
|
-
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];
|
|
9068
|
-
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];
|
|
9069
|
-
while (bytes >= 16) {
|
|
9070
|
-
t0 = m[mpos + 0] & 255 | (m[mpos + 1] & 255) << 8;
|
|
9071
|
-
h0 += t0 & 8191;
|
|
9072
|
-
t1 = m[mpos + 2] & 255 | (m[mpos + 3] & 255) << 8;
|
|
9073
|
-
h1 += (t0 >>> 13 | t1 << 3) & 8191;
|
|
9074
|
-
t2 = m[mpos + 4] & 255 | (m[mpos + 5] & 255) << 8;
|
|
9075
|
-
h2 += (t1 >>> 10 | t2 << 6) & 8191;
|
|
9076
|
-
t3 = m[mpos + 6] & 255 | (m[mpos + 7] & 255) << 8;
|
|
9077
|
-
h3 += (t2 >>> 7 | t3 << 9) & 8191;
|
|
9078
|
-
t4 = m[mpos + 8] & 255 | (m[mpos + 9] & 255) << 8;
|
|
9079
|
-
h4 += (t3 >>> 4 | t4 << 12) & 8191;
|
|
9080
|
-
h5 += t4 >>> 1 & 8191;
|
|
9081
|
-
t5 = m[mpos + 10] & 255 | (m[mpos + 11] & 255) << 8;
|
|
9082
|
-
h6 += (t4 >>> 14 | t5 << 2) & 8191;
|
|
9083
|
-
t6 = m[mpos + 12] & 255 | (m[mpos + 13] & 255) << 8;
|
|
9084
|
-
h7 += (t5 >>> 11 | t6 << 5) & 8191;
|
|
9085
|
-
t7 = m[mpos + 14] & 255 | (m[mpos + 15] & 255) << 8;
|
|
9086
|
-
h8 += (t6 >>> 8 | t7 << 8) & 8191;
|
|
9087
|
-
h9 += t7 >>> 5 | hibit;
|
|
9088
|
-
c = 0;
|
|
9089
|
-
d0 = c;
|
|
9090
|
-
d0 += h0 * r0;
|
|
9091
|
-
d0 += h1 * (5 * r9);
|
|
9092
|
-
d0 += h2 * (5 * r8);
|
|
9093
|
-
d0 += h3 * (5 * r7);
|
|
9094
|
-
d0 += h4 * (5 * r6);
|
|
9095
|
-
c = d0 >>> 13;
|
|
9096
|
-
d0 &= 8191;
|
|
9097
|
-
d0 += h5 * (5 * r5);
|
|
9098
|
-
d0 += h6 * (5 * r4);
|
|
9099
|
-
d0 += h7 * (5 * r3);
|
|
9100
|
-
d0 += h8 * (5 * r2);
|
|
9101
|
-
d0 += h9 * (5 * r1);
|
|
9102
|
-
c += d0 >>> 13;
|
|
9103
|
-
d0 &= 8191;
|
|
9104
|
-
d1 = c;
|
|
9105
|
-
d1 += h0 * r1;
|
|
9106
|
-
d1 += h1 * r0;
|
|
9107
|
-
d1 += h2 * (5 * r9);
|
|
9108
|
-
d1 += h3 * (5 * r8);
|
|
9109
|
-
d1 += h4 * (5 * r7);
|
|
9110
|
-
c = d1 >>> 13;
|
|
9111
|
-
d1 &= 8191;
|
|
9112
|
-
d1 += h5 * (5 * r6);
|
|
9113
|
-
d1 += h6 * (5 * r5);
|
|
9114
|
-
d1 += h7 * (5 * r4);
|
|
9115
|
-
d1 += h8 * (5 * r3);
|
|
9116
|
-
d1 += h9 * (5 * r2);
|
|
9117
|
-
c += d1 >>> 13;
|
|
9118
|
-
d1 &= 8191;
|
|
9119
|
-
d2 = c;
|
|
9120
|
-
d2 += h0 * r2;
|
|
9121
|
-
d2 += h1 * r1;
|
|
9122
|
-
d2 += h2 * r0;
|
|
9123
|
-
d2 += h3 * (5 * r9);
|
|
9124
|
-
d2 += h4 * (5 * r8);
|
|
9125
|
-
c = d2 >>> 13;
|
|
9126
|
-
d2 &= 8191;
|
|
9127
|
-
d2 += h5 * (5 * r7);
|
|
9128
|
-
d2 += h6 * (5 * r6);
|
|
9129
|
-
d2 += h7 * (5 * r5);
|
|
9130
|
-
d2 += h8 * (5 * r4);
|
|
9131
|
-
d2 += h9 * (5 * r3);
|
|
9132
|
-
c += d2 >>> 13;
|
|
9133
|
-
d2 &= 8191;
|
|
9134
|
-
d3 = c;
|
|
9135
|
-
d3 += h0 * r3;
|
|
9136
|
-
d3 += h1 * r2;
|
|
9137
|
-
d3 += h2 * r1;
|
|
9138
|
-
d3 += h3 * r0;
|
|
9139
|
-
d3 += h4 * (5 * r9);
|
|
9140
|
-
c = d3 >>> 13;
|
|
9141
|
-
d3 &= 8191;
|
|
9142
|
-
d3 += h5 * (5 * r8);
|
|
9143
|
-
d3 += h6 * (5 * r7);
|
|
9144
|
-
d3 += h7 * (5 * r6);
|
|
9145
|
-
d3 += h8 * (5 * r5);
|
|
9146
|
-
d3 += h9 * (5 * r4);
|
|
9147
|
-
c += d3 >>> 13;
|
|
9148
|
-
d3 &= 8191;
|
|
9149
|
-
d4 = c;
|
|
9150
|
-
d4 += h0 * r4;
|
|
9151
|
-
d4 += h1 * r3;
|
|
9152
|
-
d4 += h2 * r2;
|
|
9153
|
-
d4 += h3 * r1;
|
|
9154
|
-
d4 += h4 * r0;
|
|
9155
|
-
c = d4 >>> 13;
|
|
9156
|
-
d4 &= 8191;
|
|
9157
|
-
d4 += h5 * (5 * r9);
|
|
9158
|
-
d4 += h6 * (5 * r8);
|
|
9159
|
-
d4 += h7 * (5 * r7);
|
|
9160
|
-
d4 += h8 * (5 * r6);
|
|
9161
|
-
d4 += h9 * (5 * r5);
|
|
9162
|
-
c += d4 >>> 13;
|
|
9163
|
-
d4 &= 8191;
|
|
9164
|
-
d5 = c;
|
|
9165
|
-
d5 += h0 * r5;
|
|
9166
|
-
d5 += h1 * r4;
|
|
9167
|
-
d5 += h2 * r3;
|
|
9168
|
-
d5 += h3 * r2;
|
|
9169
|
-
d5 += h4 * r1;
|
|
9170
|
-
c = d5 >>> 13;
|
|
9171
|
-
d5 &= 8191;
|
|
9172
|
-
d5 += h5 * r0;
|
|
9173
|
-
d5 += h6 * (5 * r9);
|
|
9174
|
-
d5 += h7 * (5 * r8);
|
|
9175
|
-
d5 += h8 * (5 * r7);
|
|
9176
|
-
d5 += h9 * (5 * r6);
|
|
9177
|
-
c += d5 >>> 13;
|
|
9178
|
-
d5 &= 8191;
|
|
9179
|
-
d6 = c;
|
|
9180
|
-
d6 += h0 * r6;
|
|
9181
|
-
d6 += h1 * r5;
|
|
9182
|
-
d6 += h2 * r4;
|
|
9183
|
-
d6 += h3 * r3;
|
|
9184
|
-
d6 += h4 * r2;
|
|
9185
|
-
c = d6 >>> 13;
|
|
9186
|
-
d6 &= 8191;
|
|
9187
|
-
d6 += h5 * r1;
|
|
9188
|
-
d6 += h6 * r0;
|
|
9189
|
-
d6 += h7 * (5 * r9);
|
|
9190
|
-
d6 += h8 * (5 * r8);
|
|
9191
|
-
d6 += h9 * (5 * r7);
|
|
9192
|
-
c += d6 >>> 13;
|
|
9193
|
-
d6 &= 8191;
|
|
9194
|
-
d7 = c;
|
|
9195
|
-
d7 += h0 * r7;
|
|
9196
|
-
d7 += h1 * r6;
|
|
9197
|
-
d7 += h2 * r5;
|
|
9198
|
-
d7 += h3 * r4;
|
|
9199
|
-
d7 += h4 * r3;
|
|
9200
|
-
c = d7 >>> 13;
|
|
9201
|
-
d7 &= 8191;
|
|
9202
|
-
d7 += h5 * r2;
|
|
9203
|
-
d7 += h6 * r1;
|
|
9204
|
-
d7 += h7 * r0;
|
|
9205
|
-
d7 += h8 * (5 * r9);
|
|
9206
|
-
d7 += h9 * (5 * r8);
|
|
9207
|
-
c += d7 >>> 13;
|
|
9208
|
-
d7 &= 8191;
|
|
9209
|
-
d8 = c;
|
|
9210
|
-
d8 += h0 * r8;
|
|
9211
|
-
d8 += h1 * r7;
|
|
9212
|
-
d8 += h2 * r6;
|
|
9213
|
-
d8 += h3 * r5;
|
|
9214
|
-
d8 += h4 * r4;
|
|
9215
|
-
c = d8 >>> 13;
|
|
9216
|
-
d8 &= 8191;
|
|
9217
|
-
d8 += h5 * r3;
|
|
9218
|
-
d8 += h6 * r2;
|
|
9219
|
-
d8 += h7 * r1;
|
|
9220
|
-
d8 += h8 * r0;
|
|
9221
|
-
d8 += h9 * (5 * r9);
|
|
9222
|
-
c += d8 >>> 13;
|
|
9223
|
-
d8 &= 8191;
|
|
9224
|
-
d9 = c;
|
|
9225
|
-
d9 += h0 * r9;
|
|
9226
|
-
d9 += h1 * r8;
|
|
9227
|
-
d9 += h2 * r7;
|
|
9228
|
-
d9 += h3 * r6;
|
|
9229
|
-
d9 += h4 * r5;
|
|
9230
|
-
c = d9 >>> 13;
|
|
9231
|
-
d9 &= 8191;
|
|
9232
|
-
d9 += h5 * r4;
|
|
9233
|
-
d9 += h6 * r3;
|
|
9234
|
-
d9 += h7 * r2;
|
|
9235
|
-
d9 += h8 * r1;
|
|
9236
|
-
d9 += h9 * r0;
|
|
9237
|
-
c += d9 >>> 13;
|
|
9238
|
-
d9 &= 8191;
|
|
9239
|
-
c = (c << 2) + c | 0;
|
|
9240
|
-
c = c + d0 | 0;
|
|
9241
|
-
d0 = c & 8191;
|
|
9242
|
-
c = c >>> 13;
|
|
9243
|
-
d1 += c;
|
|
9244
|
-
h0 = d0;
|
|
9245
|
-
h1 = d1;
|
|
9246
|
-
h2 = d2;
|
|
9247
|
-
h3 = d3;
|
|
9248
|
-
h4 = d4;
|
|
9249
|
-
h5 = d5;
|
|
9250
|
-
h6 = d6;
|
|
9251
|
-
h7 = d7;
|
|
9252
|
-
h8 = d8;
|
|
9253
|
-
h9 = d9;
|
|
9254
|
-
mpos += 16;
|
|
9255
|
-
bytes -= 16;
|
|
9256
|
-
}
|
|
9257
|
-
this.h[0] = h0;
|
|
9258
|
-
this.h[1] = h1;
|
|
9259
|
-
this.h[2] = h2;
|
|
9260
|
-
this.h[3] = h3;
|
|
9261
|
-
this.h[4] = h4;
|
|
9262
|
-
this.h[5] = h5;
|
|
9263
|
-
this.h[6] = h6;
|
|
9264
|
-
this.h[7] = h7;
|
|
9265
|
-
this.h[8] = h8;
|
|
9266
|
-
this.h[9] = h9;
|
|
9267
|
-
};
|
|
9268
|
-
poly1305.prototype.finish = function(mac, macpos) {
|
|
9269
|
-
var g = new Uint16Array(10);
|
|
9270
|
-
var c, mask, f, i;
|
|
9271
|
-
if (this.leftover) {
|
|
9272
|
-
i = this.leftover;
|
|
9273
|
-
this.buffer[i++] = 1;
|
|
9274
|
-
for (; i < 16; i++) this.buffer[i] = 0;
|
|
9275
|
-
this.fin = 1;
|
|
9276
|
-
this.blocks(this.buffer, 0, 16);
|
|
9277
|
-
}
|
|
9278
|
-
c = this.h[1] >>> 13;
|
|
9279
|
-
this.h[1] &= 8191;
|
|
9280
|
-
for (i = 2; i < 10; i++) {
|
|
9281
|
-
this.h[i] += c;
|
|
9282
|
-
c = this.h[i] >>> 13;
|
|
9283
|
-
this.h[i] &= 8191;
|
|
9284
|
-
}
|
|
9285
|
-
this.h[0] += c * 5;
|
|
9286
|
-
c = this.h[0] >>> 13;
|
|
9287
|
-
this.h[0] &= 8191;
|
|
9288
|
-
this.h[1] += c;
|
|
9289
|
-
c = this.h[1] >>> 13;
|
|
9290
|
-
this.h[1] &= 8191;
|
|
9291
|
-
this.h[2] += c;
|
|
9292
|
-
g[0] = this.h[0] + 5;
|
|
9293
|
-
c = g[0] >>> 13;
|
|
9294
|
-
g[0] &= 8191;
|
|
9295
|
-
for (i = 1; i < 10; i++) {
|
|
9296
|
-
g[i] = this.h[i] + c;
|
|
9297
|
-
c = g[i] >>> 13;
|
|
9298
|
-
g[i] &= 8191;
|
|
9299
|
-
}
|
|
9300
|
-
g[9] -= 1 << 13;
|
|
9301
|
-
mask = (c ^ 1) - 1;
|
|
9302
|
-
for (i = 0; i < 10; i++) g[i] &= mask;
|
|
9303
|
-
mask = ~mask;
|
|
9304
|
-
for (i = 0; i < 10; i++) this.h[i] = this.h[i] & mask | g[i];
|
|
9305
|
-
this.h[0] = (this.h[0] | this.h[1] << 13) & 65535;
|
|
9306
|
-
this.h[1] = (this.h[1] >>> 3 | this.h[2] << 10) & 65535;
|
|
9307
|
-
this.h[2] = (this.h[2] >>> 6 | this.h[3] << 7) & 65535;
|
|
9308
|
-
this.h[3] = (this.h[3] >>> 9 | this.h[4] << 4) & 65535;
|
|
9309
|
-
this.h[4] = (this.h[4] >>> 12 | this.h[5] << 1 | this.h[6] << 14) & 65535;
|
|
9310
|
-
this.h[5] = (this.h[6] >>> 2 | this.h[7] << 11) & 65535;
|
|
9311
|
-
this.h[6] = (this.h[7] >>> 5 | this.h[8] << 8) & 65535;
|
|
9312
|
-
this.h[7] = (this.h[8] >>> 8 | this.h[9] << 5) & 65535;
|
|
9313
|
-
f = this.h[0] + this.pad[0];
|
|
9314
|
-
this.h[0] = f & 65535;
|
|
9315
|
-
for (i = 1; i < 8; i++) {
|
|
9316
|
-
f = (this.h[i] + this.pad[i] | 0) + (f >>> 16) | 0;
|
|
9317
|
-
this.h[i] = f & 65535;
|
|
9318
|
-
}
|
|
9319
|
-
mac[macpos + 0] = this.h[0] >>> 0 & 255;
|
|
9320
|
-
mac[macpos + 1] = this.h[0] >>> 8 & 255;
|
|
9321
|
-
mac[macpos + 2] = this.h[1] >>> 0 & 255;
|
|
9322
|
-
mac[macpos + 3] = this.h[1] >>> 8 & 255;
|
|
9323
|
-
mac[macpos + 4] = this.h[2] >>> 0 & 255;
|
|
9324
|
-
mac[macpos + 5] = this.h[2] >>> 8 & 255;
|
|
9325
|
-
mac[macpos + 6] = this.h[3] >>> 0 & 255;
|
|
9326
|
-
mac[macpos + 7] = this.h[3] >>> 8 & 255;
|
|
9327
|
-
mac[macpos + 8] = this.h[4] >>> 0 & 255;
|
|
9328
|
-
mac[macpos + 9] = this.h[4] >>> 8 & 255;
|
|
9329
|
-
mac[macpos + 10] = this.h[5] >>> 0 & 255;
|
|
9330
|
-
mac[macpos + 11] = this.h[5] >>> 8 & 255;
|
|
9331
|
-
mac[macpos + 12] = this.h[6] >>> 0 & 255;
|
|
9332
|
-
mac[macpos + 13] = this.h[6] >>> 8 & 255;
|
|
9333
|
-
mac[macpos + 14] = this.h[7] >>> 0 & 255;
|
|
9334
|
-
mac[macpos + 15] = this.h[7] >>> 8 & 255;
|
|
9335
|
-
};
|
|
9336
|
-
poly1305.prototype.update = function(m, mpos, bytes) {
|
|
9337
|
-
var i, want;
|
|
9338
|
-
if (this.leftover) {
|
|
9339
|
-
want = 16 - this.leftover;
|
|
9340
|
-
if (want > bytes)
|
|
9341
|
-
want = bytes;
|
|
9342
|
-
for (i = 0; i < want; i++)
|
|
9343
|
-
this.buffer[this.leftover + i] = m[mpos + i];
|
|
9344
|
-
bytes -= want;
|
|
9345
|
-
mpos += want;
|
|
9346
|
-
this.leftover += want;
|
|
9347
|
-
if (this.leftover < 16)
|
|
9348
|
-
return;
|
|
9349
|
-
this.blocks(this.buffer, 0, 16);
|
|
9350
|
-
this.leftover = 0;
|
|
9351
|
-
}
|
|
9352
|
-
if (bytes >= 16) {
|
|
9353
|
-
want = bytes - bytes % 16;
|
|
9354
|
-
this.blocks(m, mpos, want);
|
|
9355
|
-
mpos += want;
|
|
9356
|
-
bytes -= want;
|
|
9357
|
-
}
|
|
9358
|
-
if (bytes) {
|
|
9359
|
-
for (i = 0; i < bytes; i++)
|
|
9360
|
-
this.buffer[this.leftover + i] = m[mpos + i];
|
|
9361
|
-
this.leftover += bytes;
|
|
9362
|
-
}
|
|
9363
|
-
};
|
|
9364
|
-
function crypto_onetimeauth(out, outpos, m, mpos, n, k) {
|
|
9365
|
-
var s = new poly1305(k);
|
|
9366
|
-
s.update(m, mpos, n);
|
|
9367
|
-
s.finish(out, outpos);
|
|
9368
|
-
return 0;
|
|
9369
|
-
}
|
|
9370
|
-
function crypto_onetimeauth_verify(h, hpos, m, mpos, n, k) {
|
|
9371
|
-
var x = new Uint8Array(16);
|
|
9372
|
-
crypto_onetimeauth(x, 0, m, mpos, n, k);
|
|
9373
|
-
return crypto_verify_16(h, hpos, x, 0);
|
|
9374
|
-
}
|
|
9375
|
-
function crypto_secretbox(c, m, d, n, k) {
|
|
9376
|
-
var i;
|
|
9377
|
-
if (d < 32) return -1;
|
|
9378
|
-
crypto_stream_xor(c, 0, m, 0, d, n, k);
|
|
9379
|
-
crypto_onetimeauth(c, 16, c, 32, d - 32, c);
|
|
9380
|
-
for (i = 0; i < 16; i++) c[i] = 0;
|
|
9381
|
-
return 0;
|
|
9382
|
-
}
|
|
9383
|
-
function crypto_secretbox_open(m, c, d, n, k) {
|
|
9384
|
-
var i;
|
|
9385
|
-
var x = new Uint8Array(32);
|
|
9386
|
-
if (d < 32) return -1;
|
|
9387
|
-
crypto_stream(x, 0, 32, n, k);
|
|
9388
|
-
if (crypto_onetimeauth_verify(c, 16, c, 32, d - 32, x) !== 0) return -1;
|
|
9389
|
-
crypto_stream_xor(m, 0, c, 0, d, n, k);
|
|
9390
|
-
for (i = 0; i < 32; i++) m[i] = 0;
|
|
9391
|
-
return 0;
|
|
9392
|
-
}
|
|
9393
|
-
function set25519(r, a) {
|
|
9394
|
-
var i;
|
|
9395
|
-
for (i = 0; i < 16; i++) r[i] = a[i] | 0;
|
|
9396
|
-
}
|
|
9397
|
-
function car25519(o) {
|
|
9398
|
-
var i, v, c = 1;
|
|
9399
|
-
for (i = 0; i < 16; i++) {
|
|
9400
|
-
v = o[i] + c + 65535;
|
|
9401
|
-
c = Math.floor(v / 65536);
|
|
9402
|
-
o[i] = v - c * 65536;
|
|
9403
|
-
}
|
|
9404
|
-
o[0] += c - 1 + 37 * (c - 1);
|
|
9405
|
-
}
|
|
9406
|
-
function sel25519(p, q, b) {
|
|
9407
|
-
var t, c = ~(b - 1);
|
|
9408
|
-
for (var i = 0; i < 16; i++) {
|
|
9409
|
-
t = c & (p[i] ^ q[i]);
|
|
9410
|
-
p[i] ^= t;
|
|
9411
|
-
q[i] ^= t;
|
|
9412
|
-
}
|
|
9413
|
-
}
|
|
9414
|
-
function pack25519(o, n) {
|
|
9415
|
-
var i, j, b;
|
|
9416
|
-
var m = gf(), t = gf();
|
|
9417
|
-
for (i = 0; i < 16; i++) t[i] = n[i];
|
|
9418
|
-
car25519(t);
|
|
9419
|
-
car25519(t);
|
|
9420
|
-
car25519(t);
|
|
9421
|
-
for (j = 0; j < 2; j++) {
|
|
9422
|
-
m[0] = t[0] - 65517;
|
|
9423
|
-
for (i = 1; i < 15; i++) {
|
|
9424
|
-
m[i] = t[i] - 65535 - (m[i - 1] >> 16 & 1);
|
|
9425
|
-
m[i - 1] &= 65535;
|
|
9426
|
-
}
|
|
9427
|
-
m[15] = t[15] - 32767 - (m[14] >> 16 & 1);
|
|
9428
|
-
b = m[15] >> 16 & 1;
|
|
9429
|
-
m[14] &= 65535;
|
|
9430
|
-
sel25519(t, m, 1 - b);
|
|
9431
|
-
}
|
|
9432
|
-
for (i = 0; i < 16; i++) {
|
|
9433
|
-
o[2 * i] = t[i] & 255;
|
|
9434
|
-
o[2 * i + 1] = t[i] >> 8;
|
|
9435
|
-
}
|
|
9436
|
-
}
|
|
9437
|
-
function neq25519(a, b) {
|
|
9438
|
-
var c = new Uint8Array(32), d = new Uint8Array(32);
|
|
9439
|
-
pack25519(c, a);
|
|
9440
|
-
pack25519(d, b);
|
|
9441
|
-
return crypto_verify_32(c, 0, d, 0);
|
|
9442
|
-
}
|
|
9443
|
-
function par25519(a) {
|
|
9444
|
-
var d = new Uint8Array(32);
|
|
9445
|
-
pack25519(d, a);
|
|
9446
|
-
return d[0] & 1;
|
|
9447
|
-
}
|
|
9448
|
-
function unpack25519(o, n) {
|
|
9449
|
-
var i;
|
|
9450
|
-
for (i = 0; i < 16; i++) o[i] = n[2 * i] + (n[2 * i + 1] << 8);
|
|
9451
|
-
o[15] &= 32767;
|
|
9452
|
-
}
|
|
9453
|
-
function A(o, a, b) {
|
|
9454
|
-
for (var i = 0; i < 16; i++) o[i] = a[i] + b[i];
|
|
9455
|
-
}
|
|
9456
|
-
function Z(o, a, b) {
|
|
9457
|
-
for (var i = 0; i < 16; i++) o[i] = a[i] - b[i];
|
|
9458
|
-
}
|
|
9459
|
-
function M(o, a, b) {
|
|
9460
|
-
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];
|
|
9461
|
-
v = a[0];
|
|
9462
|
-
t0 += v * b0;
|
|
9463
|
-
t1 += v * b1;
|
|
9464
|
-
t2 += v * b2;
|
|
9465
|
-
t3 += v * b3;
|
|
9466
|
-
t4 += v * b4;
|
|
9467
|
-
t5 += v * b5;
|
|
9468
|
-
t6 += v * b6;
|
|
9469
|
-
t7 += v * b7;
|
|
9470
|
-
t8 += v * b8;
|
|
9471
|
-
t9 += v * b9;
|
|
9472
|
-
t10 += v * b10;
|
|
9473
|
-
t11 += v * b11;
|
|
9474
|
-
t12 += v * b12;
|
|
9475
|
-
t13 += v * b13;
|
|
9476
|
-
t14 += v * b14;
|
|
9477
|
-
t15 += v * b15;
|
|
9478
|
-
v = a[1];
|
|
9479
|
-
t1 += v * b0;
|
|
9480
|
-
t2 += v * b1;
|
|
9481
|
-
t3 += v * b2;
|
|
9482
|
-
t4 += v * b3;
|
|
9483
|
-
t5 += v * b4;
|
|
9484
|
-
t6 += v * b5;
|
|
9485
|
-
t7 += v * b6;
|
|
9486
|
-
t8 += v * b7;
|
|
9487
|
-
t9 += v * b8;
|
|
9488
|
-
t10 += v * b9;
|
|
9489
|
-
t11 += v * b10;
|
|
9490
|
-
t12 += v * b11;
|
|
9491
|
-
t13 += v * b12;
|
|
9492
|
-
t14 += v * b13;
|
|
9493
|
-
t15 += v * b14;
|
|
9494
|
-
t16 += v * b15;
|
|
9495
|
-
v = a[2];
|
|
9496
|
-
t2 += v * b0;
|
|
9497
|
-
t3 += v * b1;
|
|
9498
|
-
t4 += v * b2;
|
|
9499
|
-
t5 += v * b3;
|
|
9500
|
-
t6 += v * b4;
|
|
9501
|
-
t7 += v * b5;
|
|
9502
|
-
t8 += v * b6;
|
|
9503
|
-
t9 += v * b7;
|
|
9504
|
-
t10 += v * b8;
|
|
9505
|
-
t11 += v * b9;
|
|
9506
|
-
t12 += v * b10;
|
|
9507
|
-
t13 += v * b11;
|
|
9508
|
-
t14 += v * b12;
|
|
9509
|
-
t15 += v * b13;
|
|
9510
|
-
t16 += v * b14;
|
|
9511
|
-
t17 += v * b15;
|
|
9512
|
-
v = a[3];
|
|
9513
|
-
t3 += v * b0;
|
|
9514
|
-
t4 += v * b1;
|
|
9515
|
-
t5 += v * b2;
|
|
9516
|
-
t6 += v * b3;
|
|
9517
|
-
t7 += v * b4;
|
|
9518
|
-
t8 += v * b5;
|
|
9519
|
-
t9 += v * b6;
|
|
9520
|
-
t10 += v * b7;
|
|
9521
|
-
t11 += v * b8;
|
|
9522
|
-
t12 += v * b9;
|
|
9523
|
-
t13 += v * b10;
|
|
9524
|
-
t14 += v * b11;
|
|
9525
|
-
t15 += v * b12;
|
|
9526
|
-
t16 += v * b13;
|
|
9527
|
-
t17 += v * b14;
|
|
9528
|
-
t18 += v * b15;
|
|
9529
|
-
v = a[4];
|
|
9530
|
-
t4 += v * b0;
|
|
9531
|
-
t5 += v * b1;
|
|
9532
|
-
t6 += v * b2;
|
|
9533
|
-
t7 += v * b3;
|
|
9534
|
-
t8 += v * b4;
|
|
9535
|
-
t9 += v * b5;
|
|
9536
|
-
t10 += v * b6;
|
|
9537
|
-
t11 += v * b7;
|
|
9538
|
-
t12 += v * b8;
|
|
9539
|
-
t13 += v * b9;
|
|
9540
|
-
t14 += v * b10;
|
|
9541
|
-
t15 += v * b11;
|
|
9542
|
-
t16 += v * b12;
|
|
9543
|
-
t17 += v * b13;
|
|
9544
|
-
t18 += v * b14;
|
|
9545
|
-
t19 += v * b15;
|
|
9546
|
-
v = a[5];
|
|
9547
|
-
t5 += v * b0;
|
|
9548
|
-
t6 += v * b1;
|
|
9549
|
-
t7 += v * b2;
|
|
9550
|
-
t8 += v * b3;
|
|
9551
|
-
t9 += v * b4;
|
|
9552
|
-
t10 += v * b5;
|
|
9553
|
-
t11 += v * b6;
|
|
9554
|
-
t12 += v * b7;
|
|
9555
|
-
t13 += v * b8;
|
|
9556
|
-
t14 += v * b9;
|
|
9557
|
-
t15 += v * b10;
|
|
9558
|
-
t16 += v * b11;
|
|
9559
|
-
t17 += v * b12;
|
|
9560
|
-
t18 += v * b13;
|
|
9561
|
-
t19 += v * b14;
|
|
9562
|
-
t20 += v * b15;
|
|
9563
|
-
v = a[6];
|
|
9564
|
-
t6 += v * b0;
|
|
9565
|
-
t7 += v * b1;
|
|
9566
|
-
t8 += v * b2;
|
|
9567
|
-
t9 += v * b3;
|
|
9568
|
-
t10 += v * b4;
|
|
9569
|
-
t11 += v * b5;
|
|
9570
|
-
t12 += v * b6;
|
|
9571
|
-
t13 += v * b7;
|
|
9572
|
-
t14 += v * b8;
|
|
9573
|
-
t15 += v * b9;
|
|
9574
|
-
t16 += v * b10;
|
|
9575
|
-
t17 += v * b11;
|
|
9576
|
-
t18 += v * b12;
|
|
9577
|
-
t19 += v * b13;
|
|
9578
|
-
t20 += v * b14;
|
|
9579
|
-
t21 += v * b15;
|
|
9580
|
-
v = a[7];
|
|
9581
|
-
t7 += v * b0;
|
|
9582
|
-
t8 += v * b1;
|
|
9583
|
-
t9 += v * b2;
|
|
9584
|
-
t10 += v * b3;
|
|
9585
|
-
t11 += v * b4;
|
|
9586
|
-
t12 += v * b5;
|
|
9587
|
-
t13 += v * b6;
|
|
9588
|
-
t14 += v * b7;
|
|
9589
|
-
t15 += v * b8;
|
|
9590
|
-
t16 += v * b9;
|
|
9591
|
-
t17 += v * b10;
|
|
9592
|
-
t18 += v * b11;
|
|
9593
|
-
t19 += v * b12;
|
|
9594
|
-
t20 += v * b13;
|
|
9595
|
-
t21 += v * b14;
|
|
9596
|
-
t22 += v * b15;
|
|
9597
|
-
v = a[8];
|
|
9598
|
-
t8 += v * b0;
|
|
9599
|
-
t9 += v * b1;
|
|
9600
|
-
t10 += v * b2;
|
|
9601
|
-
t11 += v * b3;
|
|
9602
|
-
t12 += v * b4;
|
|
9603
|
-
t13 += v * b5;
|
|
9604
|
-
t14 += v * b6;
|
|
9605
|
-
t15 += v * b7;
|
|
9606
|
-
t16 += v * b8;
|
|
9607
|
-
t17 += v * b9;
|
|
9608
|
-
t18 += v * b10;
|
|
9609
|
-
t19 += v * b11;
|
|
9610
|
-
t20 += v * b12;
|
|
9611
|
-
t21 += v * b13;
|
|
9612
|
-
t22 += v * b14;
|
|
9613
|
-
t23 += v * b15;
|
|
9614
|
-
v = a[9];
|
|
9615
|
-
t9 += v * b0;
|
|
9616
|
-
t10 += v * b1;
|
|
9617
|
-
t11 += v * b2;
|
|
9618
|
-
t12 += v * b3;
|
|
9619
|
-
t13 += v * b4;
|
|
9620
|
-
t14 += v * b5;
|
|
9621
|
-
t15 += v * b6;
|
|
9622
|
-
t16 += v * b7;
|
|
9623
|
-
t17 += v * b8;
|
|
9624
|
-
t18 += v * b9;
|
|
9625
|
-
t19 += v * b10;
|
|
9626
|
-
t20 += v * b11;
|
|
9627
|
-
t21 += v * b12;
|
|
9628
|
-
t22 += v * b13;
|
|
9629
|
-
t23 += v * b14;
|
|
9630
|
-
t24 += v * b15;
|
|
9631
|
-
v = a[10];
|
|
9632
|
-
t10 += v * b0;
|
|
9633
|
-
t11 += v * b1;
|
|
9634
|
-
t12 += v * b2;
|
|
9635
|
-
t13 += v * b3;
|
|
9636
|
-
t14 += v * b4;
|
|
9637
|
-
t15 += v * b5;
|
|
9638
|
-
t16 += v * b6;
|
|
9639
|
-
t17 += v * b7;
|
|
9640
|
-
t18 += v * b8;
|
|
9641
|
-
t19 += v * b9;
|
|
9642
|
-
t20 += v * b10;
|
|
9643
|
-
t21 += v * b11;
|
|
9644
|
-
t22 += v * b12;
|
|
9645
|
-
t23 += v * b13;
|
|
9646
|
-
t24 += v * b14;
|
|
9647
|
-
t25 += v * b15;
|
|
9648
|
-
v = a[11];
|
|
9649
|
-
t11 += v * b0;
|
|
9650
|
-
t12 += v * b1;
|
|
9651
|
-
t13 += v * b2;
|
|
9652
|
-
t14 += v * b3;
|
|
9653
|
-
t15 += v * b4;
|
|
9654
|
-
t16 += v * b5;
|
|
9655
|
-
t17 += v * b6;
|
|
9656
|
-
t18 += v * b7;
|
|
9657
|
-
t19 += v * b8;
|
|
9658
|
-
t20 += v * b9;
|
|
9659
|
-
t21 += v * b10;
|
|
9660
|
-
t22 += v * b11;
|
|
9661
|
-
t23 += v * b12;
|
|
9662
|
-
t24 += v * b13;
|
|
9663
|
-
t25 += v * b14;
|
|
9664
|
-
t26 += v * b15;
|
|
9665
|
-
v = a[12];
|
|
9666
|
-
t12 += v * b0;
|
|
9667
|
-
t13 += v * b1;
|
|
9668
|
-
t14 += v * b2;
|
|
9669
|
-
t15 += v * b3;
|
|
9670
|
-
t16 += v * b4;
|
|
9671
|
-
t17 += v * b5;
|
|
9672
|
-
t18 += v * b6;
|
|
9673
|
-
t19 += v * b7;
|
|
9674
|
-
t20 += v * b8;
|
|
9675
|
-
t21 += v * b9;
|
|
9676
|
-
t22 += v * b10;
|
|
9677
|
-
t23 += v * b11;
|
|
9678
|
-
t24 += v * b12;
|
|
9679
|
-
t25 += v * b13;
|
|
9680
|
-
t26 += v * b14;
|
|
9681
|
-
t27 += v * b15;
|
|
9682
|
-
v = a[13];
|
|
9683
|
-
t13 += v * b0;
|
|
9684
|
-
t14 += v * b1;
|
|
9685
|
-
t15 += v * b2;
|
|
9686
|
-
t16 += v * b3;
|
|
9687
|
-
t17 += v * b4;
|
|
9688
|
-
t18 += v * b5;
|
|
9689
|
-
t19 += v * b6;
|
|
9690
|
-
t20 += v * b7;
|
|
9691
|
-
t21 += v * b8;
|
|
9692
|
-
t22 += v * b9;
|
|
9693
|
-
t23 += v * b10;
|
|
9694
|
-
t24 += v * b11;
|
|
9695
|
-
t25 += v * b12;
|
|
9696
|
-
t26 += v * b13;
|
|
9697
|
-
t27 += v * b14;
|
|
9698
|
-
t28 += v * b15;
|
|
9699
|
-
v = a[14];
|
|
9700
|
-
t14 += v * b0;
|
|
9701
|
-
t15 += v * b1;
|
|
9702
|
-
t16 += v * b2;
|
|
9703
|
-
t17 += v * b3;
|
|
9704
|
-
t18 += v * b4;
|
|
9705
|
-
t19 += v * b5;
|
|
9706
|
-
t20 += v * b6;
|
|
9707
|
-
t21 += v * b7;
|
|
9708
|
-
t22 += v * b8;
|
|
9709
|
-
t23 += v * b9;
|
|
9710
|
-
t24 += v * b10;
|
|
9711
|
-
t25 += v * b11;
|
|
9712
|
-
t26 += v * b12;
|
|
9713
|
-
t27 += v * b13;
|
|
9714
|
-
t28 += v * b14;
|
|
9715
|
-
t29 += v * b15;
|
|
9716
|
-
v = a[15];
|
|
9717
|
-
t15 += v * b0;
|
|
9718
|
-
t16 += v * b1;
|
|
9719
|
-
t17 += v * b2;
|
|
9720
|
-
t18 += v * b3;
|
|
9721
|
-
t19 += v * b4;
|
|
9722
|
-
t20 += v * b5;
|
|
9723
|
-
t21 += v * b6;
|
|
9724
|
-
t22 += v * b7;
|
|
9725
|
-
t23 += v * b8;
|
|
9726
|
-
t24 += v * b9;
|
|
9727
|
-
t25 += v * b10;
|
|
9728
|
-
t26 += v * b11;
|
|
9729
|
-
t27 += v * b12;
|
|
9730
|
-
t28 += v * b13;
|
|
9731
|
-
t29 += v * b14;
|
|
9732
|
-
t30 += v * b15;
|
|
9733
|
-
t0 += 38 * t16;
|
|
9734
|
-
t1 += 38 * t17;
|
|
9735
|
-
t2 += 38 * t18;
|
|
9736
|
-
t3 += 38 * t19;
|
|
9737
|
-
t4 += 38 * t20;
|
|
9738
|
-
t5 += 38 * t21;
|
|
9739
|
-
t6 += 38 * t22;
|
|
9740
|
-
t7 += 38 * t23;
|
|
9741
|
-
t8 += 38 * t24;
|
|
9742
|
-
t9 += 38 * t25;
|
|
9743
|
-
t10 += 38 * t26;
|
|
9744
|
-
t11 += 38 * t27;
|
|
9745
|
-
t12 += 38 * t28;
|
|
9746
|
-
t13 += 38 * t29;
|
|
9747
|
-
t14 += 38 * t30;
|
|
9748
|
-
c = 1;
|
|
9749
|
-
v = t0 + c + 65535;
|
|
9750
|
-
c = Math.floor(v / 65536);
|
|
9751
|
-
t0 = v - c * 65536;
|
|
9752
|
-
v = t1 + c + 65535;
|
|
9753
|
-
c = Math.floor(v / 65536);
|
|
9754
|
-
t1 = v - c * 65536;
|
|
9755
|
-
v = t2 + c + 65535;
|
|
9756
|
-
c = Math.floor(v / 65536);
|
|
9757
|
-
t2 = v - c * 65536;
|
|
9758
|
-
v = t3 + c + 65535;
|
|
9759
|
-
c = Math.floor(v / 65536);
|
|
9760
|
-
t3 = v - c * 65536;
|
|
9761
|
-
v = t4 + c + 65535;
|
|
9762
|
-
c = Math.floor(v / 65536);
|
|
9763
|
-
t4 = v - c * 65536;
|
|
9764
|
-
v = t5 + c + 65535;
|
|
9765
|
-
c = Math.floor(v / 65536);
|
|
9766
|
-
t5 = v - c * 65536;
|
|
9767
|
-
v = t6 + c + 65535;
|
|
9768
|
-
c = Math.floor(v / 65536);
|
|
9769
|
-
t6 = v - c * 65536;
|
|
9770
|
-
v = t7 + c + 65535;
|
|
9771
|
-
c = Math.floor(v / 65536);
|
|
9772
|
-
t7 = v - c * 65536;
|
|
9773
|
-
v = t8 + c + 65535;
|
|
9774
|
-
c = Math.floor(v / 65536);
|
|
9775
|
-
t8 = v - c * 65536;
|
|
9776
|
-
v = t9 + c + 65535;
|
|
9777
|
-
c = Math.floor(v / 65536);
|
|
9778
|
-
t9 = v - c * 65536;
|
|
9779
|
-
v = t10 + c + 65535;
|
|
9780
|
-
c = Math.floor(v / 65536);
|
|
9781
|
-
t10 = v - c * 65536;
|
|
9782
|
-
v = t11 + c + 65535;
|
|
9783
|
-
c = Math.floor(v / 65536);
|
|
9784
|
-
t11 = v - c * 65536;
|
|
9785
|
-
v = t12 + c + 65535;
|
|
9786
|
-
c = Math.floor(v / 65536);
|
|
9787
|
-
t12 = v - c * 65536;
|
|
9788
|
-
v = t13 + c + 65535;
|
|
9789
|
-
c = Math.floor(v / 65536);
|
|
9790
|
-
t13 = v - c * 65536;
|
|
9791
|
-
v = t14 + c + 65535;
|
|
9792
|
-
c = Math.floor(v / 65536);
|
|
9793
|
-
t14 = v - c * 65536;
|
|
9794
|
-
v = t15 + c + 65535;
|
|
9795
|
-
c = Math.floor(v / 65536);
|
|
9796
|
-
t15 = v - c * 65536;
|
|
9797
|
-
t0 += c - 1 + 37 * (c - 1);
|
|
9798
|
-
c = 1;
|
|
9799
|
-
v = t0 + c + 65535;
|
|
9800
|
-
c = Math.floor(v / 65536);
|
|
9801
|
-
t0 = v - c * 65536;
|
|
9802
|
-
v = t1 + c + 65535;
|
|
9803
|
-
c = Math.floor(v / 65536);
|
|
9804
|
-
t1 = v - c * 65536;
|
|
9805
|
-
v = t2 + c + 65535;
|
|
9806
|
-
c = Math.floor(v / 65536);
|
|
9807
|
-
t2 = v - c * 65536;
|
|
9808
|
-
v = t3 + c + 65535;
|
|
9809
|
-
c = Math.floor(v / 65536);
|
|
9810
|
-
t3 = v - c * 65536;
|
|
9811
|
-
v = t4 + c + 65535;
|
|
9812
|
-
c = Math.floor(v / 65536);
|
|
9813
|
-
t4 = v - c * 65536;
|
|
9814
|
-
v = t5 + c + 65535;
|
|
9815
|
-
c = Math.floor(v / 65536);
|
|
9816
|
-
t5 = v - c * 65536;
|
|
9817
|
-
v = t6 + c + 65535;
|
|
9818
|
-
c = Math.floor(v / 65536);
|
|
9819
|
-
t6 = v - c * 65536;
|
|
9820
|
-
v = t7 + c + 65535;
|
|
9821
|
-
c = Math.floor(v / 65536);
|
|
9822
|
-
t7 = v - c * 65536;
|
|
9823
|
-
v = t8 + c + 65535;
|
|
9824
|
-
c = Math.floor(v / 65536);
|
|
9825
|
-
t8 = v - c * 65536;
|
|
9826
|
-
v = t9 + c + 65535;
|
|
9827
|
-
c = Math.floor(v / 65536);
|
|
9828
|
-
t9 = v - c * 65536;
|
|
9829
|
-
v = t10 + c + 65535;
|
|
9830
|
-
c = Math.floor(v / 65536);
|
|
9831
|
-
t10 = v - c * 65536;
|
|
9832
|
-
v = t11 + c + 65535;
|
|
9833
|
-
c = Math.floor(v / 65536);
|
|
9834
|
-
t11 = v - c * 65536;
|
|
9835
|
-
v = t12 + c + 65535;
|
|
9836
|
-
c = Math.floor(v / 65536);
|
|
9837
|
-
t12 = v - c * 65536;
|
|
9838
|
-
v = t13 + c + 65535;
|
|
9839
|
-
c = Math.floor(v / 65536);
|
|
9840
|
-
t13 = v - c * 65536;
|
|
9841
|
-
v = t14 + c + 65535;
|
|
9842
|
-
c = Math.floor(v / 65536);
|
|
9843
|
-
t14 = v - c * 65536;
|
|
9844
|
-
v = t15 + c + 65535;
|
|
9845
|
-
c = Math.floor(v / 65536);
|
|
9846
|
-
t15 = v - c * 65536;
|
|
9847
|
-
t0 += c - 1 + 37 * (c - 1);
|
|
9848
|
-
o[0] = t0;
|
|
9849
|
-
o[1] = t1;
|
|
9850
|
-
o[2] = t2;
|
|
9851
|
-
o[3] = t3;
|
|
9852
|
-
o[4] = t4;
|
|
9853
|
-
o[5] = t5;
|
|
9854
|
-
o[6] = t6;
|
|
9855
|
-
o[7] = t7;
|
|
9856
|
-
o[8] = t8;
|
|
9857
|
-
o[9] = t9;
|
|
9858
|
-
o[10] = t10;
|
|
9859
|
-
o[11] = t11;
|
|
9860
|
-
o[12] = t12;
|
|
9861
|
-
o[13] = t13;
|
|
9862
|
-
o[14] = t14;
|
|
9863
|
-
o[15] = t15;
|
|
9864
|
-
}
|
|
9865
|
-
function S(o, a) {
|
|
9866
|
-
M(o, a, a);
|
|
9867
|
-
}
|
|
9868
|
-
function inv25519(o, i) {
|
|
9869
|
-
var c = gf();
|
|
9870
|
-
var a;
|
|
9871
|
-
for (a = 0; a < 16; a++) c[a] = i[a];
|
|
9872
|
-
for (a = 253; a >= 0; a--) {
|
|
9873
|
-
S(c, c);
|
|
9874
|
-
if (a !== 2 && a !== 4) M(c, c, i);
|
|
9875
|
-
}
|
|
9876
|
-
for (a = 0; a < 16; a++) o[a] = c[a];
|
|
9877
|
-
}
|
|
9878
|
-
function pow2523(o, i) {
|
|
9879
|
-
var c = gf();
|
|
9880
|
-
var a;
|
|
9881
|
-
for (a = 0; a < 16; a++) c[a] = i[a];
|
|
9882
|
-
for (a = 250; a >= 0; a--) {
|
|
9883
|
-
S(c, c);
|
|
9884
|
-
if (a !== 1) M(c, c, i);
|
|
9885
|
-
}
|
|
9886
|
-
for (a = 0; a < 16; a++) o[a] = c[a];
|
|
9887
|
-
}
|
|
9888
|
-
function crypto_scalarmult(q, n, p) {
|
|
9889
|
-
var z4 = new Uint8Array(32);
|
|
9890
|
-
var x = new Float64Array(80), r, i;
|
|
9891
|
-
var a = gf(), b = gf(), c = gf(), d = gf(), e = gf(), f = gf();
|
|
9892
|
-
for (i = 0; i < 31; i++) z4[i] = n[i];
|
|
9893
|
-
z4[31] = n[31] & 127 | 64;
|
|
9894
|
-
z4[0] &= 248;
|
|
9895
|
-
unpack25519(x, p);
|
|
9896
|
-
for (i = 0; i < 16; i++) {
|
|
9897
|
-
b[i] = x[i];
|
|
9898
|
-
d[i] = a[i] = c[i] = 0;
|
|
9899
|
-
}
|
|
9900
|
-
a[0] = d[0] = 1;
|
|
9901
|
-
for (i = 254; i >= 0; --i) {
|
|
9902
|
-
r = z4[i >>> 3] >>> (i & 7) & 1;
|
|
9903
|
-
sel25519(a, b, r);
|
|
9904
|
-
sel25519(c, d, r);
|
|
9905
|
-
A(e, a, c);
|
|
9906
|
-
Z(a, a, c);
|
|
9907
|
-
A(c, b, d);
|
|
9908
|
-
Z(b, b, d);
|
|
9909
|
-
S(d, e);
|
|
9910
|
-
S(f, a);
|
|
9911
|
-
M(a, c, a);
|
|
9912
|
-
M(c, b, e);
|
|
9913
|
-
A(e, a, c);
|
|
9914
|
-
Z(a, a, c);
|
|
9915
|
-
S(b, a);
|
|
9916
|
-
Z(c, d, f);
|
|
9917
|
-
M(a, c, _121665);
|
|
9918
|
-
A(a, a, d);
|
|
9919
|
-
M(c, c, a);
|
|
9920
|
-
M(a, d, f);
|
|
9921
|
-
M(d, b, x);
|
|
9922
|
-
S(b, e);
|
|
9923
|
-
sel25519(a, b, r);
|
|
9924
|
-
sel25519(c, d, r);
|
|
9925
|
-
}
|
|
9926
|
-
for (i = 0; i < 16; i++) {
|
|
9927
|
-
x[i + 16] = a[i];
|
|
9928
|
-
x[i + 32] = c[i];
|
|
9929
|
-
x[i + 48] = b[i];
|
|
9930
|
-
x[i + 64] = d[i];
|
|
9931
|
-
}
|
|
9932
|
-
var x32 = x.subarray(32);
|
|
9933
|
-
var x16 = x.subarray(16);
|
|
9934
|
-
inv25519(x32, x32);
|
|
9935
|
-
M(x16, x16, x32);
|
|
9936
|
-
pack25519(q, x16);
|
|
9937
|
-
return 0;
|
|
9938
|
-
}
|
|
9939
|
-
function crypto_scalarmult_base(q, n) {
|
|
9940
|
-
return crypto_scalarmult(q, n, _9);
|
|
9941
|
-
}
|
|
9942
|
-
function crypto_box_keypair(y, x) {
|
|
9943
|
-
randombytes(x, 32);
|
|
9944
|
-
return crypto_scalarmult_base(y, x);
|
|
9945
|
-
}
|
|
9946
|
-
function crypto_box_beforenm(k, y, x) {
|
|
9947
|
-
var s = new Uint8Array(32);
|
|
9948
|
-
crypto_scalarmult(s, x, y);
|
|
9949
|
-
return crypto_core_hsalsa20(k, _0, s, sigma);
|
|
9950
|
-
}
|
|
9951
|
-
var crypto_box_afternm = crypto_secretbox;
|
|
9952
|
-
var crypto_box_open_afternm = crypto_secretbox_open;
|
|
9953
|
-
function crypto_box(c, m, d, n, y, x) {
|
|
9954
|
-
var k = new Uint8Array(32);
|
|
9955
|
-
crypto_box_beforenm(k, y, x);
|
|
9956
|
-
return crypto_box_afternm(c, m, d, n, k);
|
|
9957
|
-
}
|
|
9958
|
-
function crypto_box_open(m, c, d, n, y, x) {
|
|
9959
|
-
var k = new Uint8Array(32);
|
|
9960
|
-
crypto_box_beforenm(k, y, x);
|
|
9961
|
-
return crypto_box_open_afternm(m, c, d, n, k);
|
|
9962
|
-
}
|
|
9963
|
-
var K = [
|
|
9964
|
-
1116352408,
|
|
9965
|
-
3609767458,
|
|
9966
|
-
1899447441,
|
|
9967
|
-
602891725,
|
|
9968
|
-
3049323471,
|
|
9969
|
-
3964484399,
|
|
9970
|
-
3921009573,
|
|
9971
|
-
2173295548,
|
|
9972
|
-
961987163,
|
|
9973
|
-
4081628472,
|
|
9974
|
-
1508970993,
|
|
9975
|
-
3053834265,
|
|
9976
|
-
2453635748,
|
|
9977
|
-
2937671579,
|
|
9978
|
-
2870763221,
|
|
9979
|
-
3664609560,
|
|
9980
|
-
3624381080,
|
|
9981
|
-
2734883394,
|
|
9982
|
-
310598401,
|
|
9983
|
-
1164996542,
|
|
9984
|
-
607225278,
|
|
9985
|
-
1323610764,
|
|
9986
|
-
1426881987,
|
|
9987
|
-
3590304994,
|
|
9988
|
-
1925078388,
|
|
9989
|
-
4068182383,
|
|
9990
|
-
2162078206,
|
|
9991
|
-
991336113,
|
|
9992
|
-
2614888103,
|
|
9993
|
-
633803317,
|
|
9994
|
-
3248222580,
|
|
9995
|
-
3479774868,
|
|
9996
|
-
3835390401,
|
|
9997
|
-
2666613458,
|
|
9998
|
-
4022224774,
|
|
9999
|
-
944711139,
|
|
10000
|
-
264347078,
|
|
10001
|
-
2341262773,
|
|
10002
|
-
604807628,
|
|
10003
|
-
2007800933,
|
|
10004
|
-
770255983,
|
|
10005
|
-
1495990901,
|
|
10006
|
-
1249150122,
|
|
10007
|
-
1856431235,
|
|
10008
|
-
1555081692,
|
|
10009
|
-
3175218132,
|
|
10010
|
-
1996064986,
|
|
10011
|
-
2198950837,
|
|
10012
|
-
2554220882,
|
|
10013
|
-
3999719339,
|
|
10014
|
-
2821834349,
|
|
10015
|
-
766784016,
|
|
10016
|
-
2952996808,
|
|
10017
|
-
2566594879,
|
|
10018
|
-
3210313671,
|
|
10019
|
-
3203337956,
|
|
10020
|
-
3336571891,
|
|
10021
|
-
1034457026,
|
|
10022
|
-
3584528711,
|
|
10023
|
-
2466948901,
|
|
10024
|
-
113926993,
|
|
10025
|
-
3758326383,
|
|
10026
|
-
338241895,
|
|
10027
|
-
168717936,
|
|
10028
|
-
666307205,
|
|
10029
|
-
1188179964,
|
|
10030
|
-
773529912,
|
|
10031
|
-
1546045734,
|
|
10032
|
-
1294757372,
|
|
10033
|
-
1522805485,
|
|
10034
|
-
1396182291,
|
|
10035
|
-
2643833823,
|
|
10036
|
-
1695183700,
|
|
10037
|
-
2343527390,
|
|
10038
|
-
1986661051,
|
|
10039
|
-
1014477480,
|
|
10040
|
-
2177026350,
|
|
10041
|
-
1206759142,
|
|
10042
|
-
2456956037,
|
|
10043
|
-
344077627,
|
|
10044
|
-
2730485921,
|
|
10045
|
-
1290863460,
|
|
10046
|
-
2820302411,
|
|
10047
|
-
3158454273,
|
|
10048
|
-
3259730800,
|
|
10049
|
-
3505952657,
|
|
10050
|
-
3345764771,
|
|
10051
|
-
106217008,
|
|
10052
|
-
3516065817,
|
|
10053
|
-
3606008344,
|
|
10054
|
-
3600352804,
|
|
10055
|
-
1432725776,
|
|
10056
|
-
4094571909,
|
|
10057
|
-
1467031594,
|
|
10058
|
-
275423344,
|
|
10059
|
-
851169720,
|
|
10060
|
-
430227734,
|
|
10061
|
-
3100823752,
|
|
10062
|
-
506948616,
|
|
10063
|
-
1363258195,
|
|
10064
|
-
659060556,
|
|
10065
|
-
3750685593,
|
|
10066
|
-
883997877,
|
|
10067
|
-
3785050280,
|
|
10068
|
-
958139571,
|
|
10069
|
-
3318307427,
|
|
10070
|
-
1322822218,
|
|
10071
|
-
3812723403,
|
|
10072
|
-
1537002063,
|
|
10073
|
-
2003034995,
|
|
10074
|
-
1747873779,
|
|
10075
|
-
3602036899,
|
|
10076
|
-
1955562222,
|
|
10077
|
-
1575990012,
|
|
10078
|
-
2024104815,
|
|
10079
|
-
1125592928,
|
|
10080
|
-
2227730452,
|
|
10081
|
-
2716904306,
|
|
10082
|
-
2361852424,
|
|
10083
|
-
442776044,
|
|
10084
|
-
2428436474,
|
|
10085
|
-
593698344,
|
|
10086
|
-
2756734187,
|
|
10087
|
-
3733110249,
|
|
10088
|
-
3204031479,
|
|
10089
|
-
2999351573,
|
|
10090
|
-
3329325298,
|
|
10091
|
-
3815920427,
|
|
10092
|
-
3391569614,
|
|
10093
|
-
3928383900,
|
|
10094
|
-
3515267271,
|
|
10095
|
-
566280711,
|
|
10096
|
-
3940187606,
|
|
10097
|
-
3454069534,
|
|
10098
|
-
4118630271,
|
|
10099
|
-
4000239992,
|
|
10100
|
-
116418474,
|
|
10101
|
-
1914138554,
|
|
10102
|
-
174292421,
|
|
10103
|
-
2731055270,
|
|
10104
|
-
289380356,
|
|
10105
|
-
3203993006,
|
|
10106
|
-
460393269,
|
|
10107
|
-
320620315,
|
|
10108
|
-
685471733,
|
|
10109
|
-
587496836,
|
|
10110
|
-
852142971,
|
|
10111
|
-
1086792851,
|
|
10112
|
-
1017036298,
|
|
10113
|
-
365543100,
|
|
10114
|
-
1126000580,
|
|
10115
|
-
2618297676,
|
|
10116
|
-
1288033470,
|
|
10117
|
-
3409855158,
|
|
10118
|
-
1501505948,
|
|
10119
|
-
4234509866,
|
|
10120
|
-
1607167915,
|
|
10121
|
-
987167468,
|
|
10122
|
-
1816402316,
|
|
10123
|
-
1246189591
|
|
10124
|
-
];
|
|
10125
|
-
function crypto_hashblocks_hl(hh, hl, m, n) {
|
|
10126
|
-
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;
|
|
10127
|
-
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];
|
|
10128
|
-
var pos = 0;
|
|
10129
|
-
while (n >= 128) {
|
|
10130
|
-
for (i = 0; i < 16; i++) {
|
|
10131
|
-
j = 8 * i + pos;
|
|
10132
|
-
wh[i] = m[j + 0] << 24 | m[j + 1] << 16 | m[j + 2] << 8 | m[j + 3];
|
|
10133
|
-
wl[i] = m[j + 4] << 24 | m[j + 5] << 16 | m[j + 6] << 8 | m[j + 7];
|
|
10134
|
-
}
|
|
10135
|
-
for (i = 0; i < 80; i++) {
|
|
10136
|
-
bh0 = ah0;
|
|
10137
|
-
bh1 = ah1;
|
|
10138
|
-
bh2 = ah2;
|
|
10139
|
-
bh3 = ah3;
|
|
10140
|
-
bh4 = ah4;
|
|
10141
|
-
bh5 = ah5;
|
|
10142
|
-
bh6 = ah6;
|
|
10143
|
-
bh7 = ah7;
|
|
10144
|
-
bl0 = al0;
|
|
10145
|
-
bl1 = al1;
|
|
10146
|
-
bl2 = al2;
|
|
10147
|
-
bl3 = al3;
|
|
10148
|
-
bl4 = al4;
|
|
10149
|
-
bl5 = al5;
|
|
10150
|
-
bl6 = al6;
|
|
10151
|
-
bl7 = al7;
|
|
10152
|
-
h = ah7;
|
|
10153
|
-
l = al7;
|
|
10154
|
-
a = l & 65535;
|
|
10155
|
-
b = l >>> 16;
|
|
10156
|
-
c = h & 65535;
|
|
10157
|
-
d = h >>> 16;
|
|
10158
|
-
h = (ah4 >>> 14 | al4 << 32 - 14) ^ (ah4 >>> 18 | al4 << 32 - 18) ^ (al4 >>> 41 - 32 | ah4 << 32 - (41 - 32));
|
|
10159
|
-
l = (al4 >>> 14 | ah4 << 32 - 14) ^ (al4 >>> 18 | ah4 << 32 - 18) ^ (ah4 >>> 41 - 32 | al4 << 32 - (41 - 32));
|
|
10160
|
-
a += l & 65535;
|
|
10161
|
-
b += l >>> 16;
|
|
10162
|
-
c += h & 65535;
|
|
10163
|
-
d += h >>> 16;
|
|
10164
|
-
h = ah4 & ah5 ^ ~ah4 & ah6;
|
|
10165
|
-
l = al4 & al5 ^ ~al4 & al6;
|
|
10166
|
-
a += l & 65535;
|
|
10167
|
-
b += l >>> 16;
|
|
10168
|
-
c += h & 65535;
|
|
10169
|
-
d += h >>> 16;
|
|
10170
|
-
h = K[i * 2];
|
|
10171
|
-
l = K[i * 2 + 1];
|
|
10172
|
-
a += l & 65535;
|
|
10173
|
-
b += l >>> 16;
|
|
10174
|
-
c += h & 65535;
|
|
10175
|
-
d += h >>> 16;
|
|
10176
|
-
h = wh[i % 16];
|
|
10177
|
-
l = wl[i % 16];
|
|
10178
|
-
a += l & 65535;
|
|
10179
|
-
b += l >>> 16;
|
|
10180
|
-
c += h & 65535;
|
|
10181
|
-
d += h >>> 16;
|
|
10182
|
-
b += a >>> 16;
|
|
10183
|
-
c += b >>> 16;
|
|
10184
|
-
d += c >>> 16;
|
|
10185
|
-
th = c & 65535 | d << 16;
|
|
10186
|
-
tl = a & 65535 | b << 16;
|
|
10187
|
-
h = th;
|
|
10188
|
-
l = tl;
|
|
10189
|
-
a = l & 65535;
|
|
10190
|
-
b = l >>> 16;
|
|
10191
|
-
c = h & 65535;
|
|
10192
|
-
d = h >>> 16;
|
|
10193
|
-
h = (ah0 >>> 28 | al0 << 32 - 28) ^ (al0 >>> 34 - 32 | ah0 << 32 - (34 - 32)) ^ (al0 >>> 39 - 32 | ah0 << 32 - (39 - 32));
|
|
10194
|
-
l = (al0 >>> 28 | ah0 << 32 - 28) ^ (ah0 >>> 34 - 32 | al0 << 32 - (34 - 32)) ^ (ah0 >>> 39 - 32 | al0 << 32 - (39 - 32));
|
|
10195
|
-
a += l & 65535;
|
|
10196
|
-
b += l >>> 16;
|
|
10197
|
-
c += h & 65535;
|
|
10198
|
-
d += h >>> 16;
|
|
10199
|
-
h = ah0 & ah1 ^ ah0 & ah2 ^ ah1 & ah2;
|
|
10200
|
-
l = al0 & al1 ^ al0 & al2 ^ al1 & al2;
|
|
10201
|
-
a += l & 65535;
|
|
10202
|
-
b += l >>> 16;
|
|
10203
|
-
c += h & 65535;
|
|
10204
|
-
d += h >>> 16;
|
|
10205
|
-
b += a >>> 16;
|
|
10206
|
-
c += b >>> 16;
|
|
10207
|
-
d += c >>> 16;
|
|
10208
|
-
bh7 = c & 65535 | d << 16;
|
|
10209
|
-
bl7 = a & 65535 | b << 16;
|
|
10210
|
-
h = bh3;
|
|
10211
|
-
l = bl3;
|
|
10212
|
-
a = l & 65535;
|
|
10213
|
-
b = l >>> 16;
|
|
10214
|
-
c = h & 65535;
|
|
10215
|
-
d = h >>> 16;
|
|
10216
|
-
h = th;
|
|
10217
|
-
l = tl;
|
|
10218
|
-
a += l & 65535;
|
|
10219
|
-
b += l >>> 16;
|
|
10220
|
-
c += h & 65535;
|
|
10221
|
-
d += h >>> 16;
|
|
10222
|
-
b += a >>> 16;
|
|
10223
|
-
c += b >>> 16;
|
|
10224
|
-
d += c >>> 16;
|
|
10225
|
-
bh3 = c & 65535 | d << 16;
|
|
10226
|
-
bl3 = a & 65535 | b << 16;
|
|
10227
|
-
ah1 = bh0;
|
|
10228
|
-
ah2 = bh1;
|
|
10229
|
-
ah3 = bh2;
|
|
10230
|
-
ah4 = bh3;
|
|
10231
|
-
ah5 = bh4;
|
|
10232
|
-
ah6 = bh5;
|
|
10233
|
-
ah7 = bh6;
|
|
10234
|
-
ah0 = bh7;
|
|
10235
|
-
al1 = bl0;
|
|
10236
|
-
al2 = bl1;
|
|
10237
|
-
al3 = bl2;
|
|
10238
|
-
al4 = bl3;
|
|
10239
|
-
al5 = bl4;
|
|
10240
|
-
al6 = bl5;
|
|
10241
|
-
al7 = bl6;
|
|
10242
|
-
al0 = bl7;
|
|
10243
|
-
if (i % 16 === 15) {
|
|
10244
|
-
for (j = 0; j < 16; j++) {
|
|
10245
|
-
h = wh[j];
|
|
10246
|
-
l = wl[j];
|
|
10247
|
-
a = l & 65535;
|
|
10248
|
-
b = l >>> 16;
|
|
10249
|
-
c = h & 65535;
|
|
10250
|
-
d = h >>> 16;
|
|
10251
|
-
h = wh[(j + 9) % 16];
|
|
10252
|
-
l = wl[(j + 9) % 16];
|
|
10253
|
-
a += l & 65535;
|
|
10254
|
-
b += l >>> 16;
|
|
10255
|
-
c += h & 65535;
|
|
10256
|
-
d += h >>> 16;
|
|
10257
|
-
th = wh[(j + 1) % 16];
|
|
10258
|
-
tl = wl[(j + 1) % 16];
|
|
10259
|
-
h = (th >>> 1 | tl << 32 - 1) ^ (th >>> 8 | tl << 32 - 8) ^ th >>> 7;
|
|
10260
|
-
l = (tl >>> 1 | th << 32 - 1) ^ (tl >>> 8 | th << 32 - 8) ^ (tl >>> 7 | th << 32 - 7);
|
|
10261
|
-
a += l & 65535;
|
|
10262
|
-
b += l >>> 16;
|
|
10263
|
-
c += h & 65535;
|
|
10264
|
-
d += h >>> 16;
|
|
10265
|
-
th = wh[(j + 14) % 16];
|
|
10266
|
-
tl = wl[(j + 14) % 16];
|
|
10267
|
-
h = (th >>> 19 | tl << 32 - 19) ^ (tl >>> 61 - 32 | th << 32 - (61 - 32)) ^ th >>> 6;
|
|
10268
|
-
l = (tl >>> 19 | th << 32 - 19) ^ (th >>> 61 - 32 | tl << 32 - (61 - 32)) ^ (tl >>> 6 | th << 32 - 6);
|
|
10269
|
-
a += l & 65535;
|
|
10270
|
-
b += l >>> 16;
|
|
10271
|
-
c += h & 65535;
|
|
10272
|
-
d += h >>> 16;
|
|
10273
|
-
b += a >>> 16;
|
|
10274
|
-
c += b >>> 16;
|
|
10275
|
-
d += c >>> 16;
|
|
10276
|
-
wh[j] = c & 65535 | d << 16;
|
|
10277
|
-
wl[j] = a & 65535 | b << 16;
|
|
10278
|
-
}
|
|
10279
|
-
}
|
|
10280
|
-
}
|
|
10281
|
-
h = ah0;
|
|
10282
|
-
l = al0;
|
|
10283
|
-
a = l & 65535;
|
|
10284
|
-
b = l >>> 16;
|
|
10285
|
-
c = h & 65535;
|
|
10286
|
-
d = h >>> 16;
|
|
10287
|
-
h = hh[0];
|
|
10288
|
-
l = hl[0];
|
|
10289
|
-
a += l & 65535;
|
|
10290
|
-
b += l >>> 16;
|
|
10291
|
-
c += h & 65535;
|
|
10292
|
-
d += h >>> 16;
|
|
10293
|
-
b += a >>> 16;
|
|
10294
|
-
c += b >>> 16;
|
|
10295
|
-
d += c >>> 16;
|
|
10296
|
-
hh[0] = ah0 = c & 65535 | d << 16;
|
|
10297
|
-
hl[0] = al0 = a & 65535 | b << 16;
|
|
10298
|
-
h = ah1;
|
|
10299
|
-
l = al1;
|
|
10300
|
-
a = l & 65535;
|
|
10301
|
-
b = l >>> 16;
|
|
10302
|
-
c = h & 65535;
|
|
10303
|
-
d = h >>> 16;
|
|
10304
|
-
h = hh[1];
|
|
10305
|
-
l = hl[1];
|
|
10306
|
-
a += l & 65535;
|
|
10307
|
-
b += l >>> 16;
|
|
10308
|
-
c += h & 65535;
|
|
10309
|
-
d += h >>> 16;
|
|
10310
|
-
b += a >>> 16;
|
|
10311
|
-
c += b >>> 16;
|
|
10312
|
-
d += c >>> 16;
|
|
10313
|
-
hh[1] = ah1 = c & 65535 | d << 16;
|
|
10314
|
-
hl[1] = al1 = a & 65535 | b << 16;
|
|
10315
|
-
h = ah2;
|
|
10316
|
-
l = al2;
|
|
10317
|
-
a = l & 65535;
|
|
10318
|
-
b = l >>> 16;
|
|
10319
|
-
c = h & 65535;
|
|
10320
|
-
d = h >>> 16;
|
|
10321
|
-
h = hh[2];
|
|
10322
|
-
l = hl[2];
|
|
10323
|
-
a += l & 65535;
|
|
10324
|
-
b += l >>> 16;
|
|
10325
|
-
c += h & 65535;
|
|
10326
|
-
d += h >>> 16;
|
|
10327
|
-
b += a >>> 16;
|
|
10328
|
-
c += b >>> 16;
|
|
10329
|
-
d += c >>> 16;
|
|
10330
|
-
hh[2] = ah2 = c & 65535 | d << 16;
|
|
10331
|
-
hl[2] = al2 = a & 65535 | b << 16;
|
|
10332
|
-
h = ah3;
|
|
10333
|
-
l = al3;
|
|
10334
|
-
a = l & 65535;
|
|
10335
|
-
b = l >>> 16;
|
|
10336
|
-
c = h & 65535;
|
|
10337
|
-
d = h >>> 16;
|
|
10338
|
-
h = hh[3];
|
|
10339
|
-
l = hl[3];
|
|
10340
|
-
a += l & 65535;
|
|
10341
|
-
b += l >>> 16;
|
|
10342
|
-
c += h & 65535;
|
|
10343
|
-
d += h >>> 16;
|
|
10344
|
-
b += a >>> 16;
|
|
10345
|
-
c += b >>> 16;
|
|
10346
|
-
d += c >>> 16;
|
|
10347
|
-
hh[3] = ah3 = c & 65535 | d << 16;
|
|
10348
|
-
hl[3] = al3 = a & 65535 | b << 16;
|
|
10349
|
-
h = ah4;
|
|
10350
|
-
l = al4;
|
|
10351
|
-
a = l & 65535;
|
|
10352
|
-
b = l >>> 16;
|
|
10353
|
-
c = h & 65535;
|
|
10354
|
-
d = h >>> 16;
|
|
10355
|
-
h = hh[4];
|
|
10356
|
-
l = hl[4];
|
|
10357
|
-
a += l & 65535;
|
|
10358
|
-
b += l >>> 16;
|
|
10359
|
-
c += h & 65535;
|
|
10360
|
-
d += h >>> 16;
|
|
10361
|
-
b += a >>> 16;
|
|
10362
|
-
c += b >>> 16;
|
|
10363
|
-
d += c >>> 16;
|
|
10364
|
-
hh[4] = ah4 = c & 65535 | d << 16;
|
|
10365
|
-
hl[4] = al4 = a & 65535 | b << 16;
|
|
10366
|
-
h = ah5;
|
|
10367
|
-
l = al5;
|
|
10368
|
-
a = l & 65535;
|
|
10369
|
-
b = l >>> 16;
|
|
10370
|
-
c = h & 65535;
|
|
10371
|
-
d = h >>> 16;
|
|
10372
|
-
h = hh[5];
|
|
10373
|
-
l = hl[5];
|
|
10374
|
-
a += l & 65535;
|
|
10375
|
-
b += l >>> 16;
|
|
10376
|
-
c += h & 65535;
|
|
10377
|
-
d += h >>> 16;
|
|
10378
|
-
b += a >>> 16;
|
|
10379
|
-
c += b >>> 16;
|
|
10380
|
-
d += c >>> 16;
|
|
10381
|
-
hh[5] = ah5 = c & 65535 | d << 16;
|
|
10382
|
-
hl[5] = al5 = a & 65535 | b << 16;
|
|
10383
|
-
h = ah6;
|
|
10384
|
-
l = al6;
|
|
10385
|
-
a = l & 65535;
|
|
10386
|
-
b = l >>> 16;
|
|
10387
|
-
c = h & 65535;
|
|
10388
|
-
d = h >>> 16;
|
|
10389
|
-
h = hh[6];
|
|
10390
|
-
l = hl[6];
|
|
10391
|
-
a += l & 65535;
|
|
10392
|
-
b += l >>> 16;
|
|
10393
|
-
c += h & 65535;
|
|
10394
|
-
d += h >>> 16;
|
|
10395
|
-
b += a >>> 16;
|
|
10396
|
-
c += b >>> 16;
|
|
10397
|
-
d += c >>> 16;
|
|
10398
|
-
hh[6] = ah6 = c & 65535 | d << 16;
|
|
10399
|
-
hl[6] = al6 = a & 65535 | b << 16;
|
|
10400
|
-
h = ah7;
|
|
10401
|
-
l = al7;
|
|
10402
|
-
a = l & 65535;
|
|
10403
|
-
b = l >>> 16;
|
|
10404
|
-
c = h & 65535;
|
|
10405
|
-
d = h >>> 16;
|
|
10406
|
-
h = hh[7];
|
|
10407
|
-
l = hl[7];
|
|
10408
|
-
a += l & 65535;
|
|
10409
|
-
b += l >>> 16;
|
|
10410
|
-
c += h & 65535;
|
|
10411
|
-
d += h >>> 16;
|
|
10412
|
-
b += a >>> 16;
|
|
10413
|
-
c += b >>> 16;
|
|
10414
|
-
d += c >>> 16;
|
|
10415
|
-
hh[7] = ah7 = c & 65535 | d << 16;
|
|
10416
|
-
hl[7] = al7 = a & 65535 | b << 16;
|
|
10417
|
-
pos += 128;
|
|
10418
|
-
n -= 128;
|
|
10419
|
-
}
|
|
10420
|
-
return n;
|
|
10421
|
-
}
|
|
10422
|
-
function crypto_hash(out, m, n) {
|
|
10423
|
-
var hh = new Int32Array(8), hl = new Int32Array(8), x = new Uint8Array(256), i, b = n;
|
|
10424
|
-
hh[0] = 1779033703;
|
|
10425
|
-
hh[1] = 3144134277;
|
|
10426
|
-
hh[2] = 1013904242;
|
|
10427
|
-
hh[3] = 2773480762;
|
|
10428
|
-
hh[4] = 1359893119;
|
|
10429
|
-
hh[5] = 2600822924;
|
|
10430
|
-
hh[6] = 528734635;
|
|
10431
|
-
hh[7] = 1541459225;
|
|
10432
|
-
hl[0] = 4089235720;
|
|
10433
|
-
hl[1] = 2227873595;
|
|
10434
|
-
hl[2] = 4271175723;
|
|
10435
|
-
hl[3] = 1595750129;
|
|
10436
|
-
hl[4] = 2917565137;
|
|
10437
|
-
hl[5] = 725511199;
|
|
10438
|
-
hl[6] = 4215389547;
|
|
10439
|
-
hl[7] = 327033209;
|
|
10440
|
-
crypto_hashblocks_hl(hh, hl, m, n);
|
|
10441
|
-
n %= 128;
|
|
10442
|
-
for (i = 0; i < n; i++) x[i] = m[b - n + i];
|
|
10443
|
-
x[n] = 128;
|
|
10444
|
-
n = 256 - 128 * (n < 112 ? 1 : 0);
|
|
10445
|
-
x[n - 9] = 0;
|
|
10446
|
-
ts64(x, n - 8, b / 536870912 | 0, b << 3);
|
|
10447
|
-
crypto_hashblocks_hl(hh, hl, x, n);
|
|
10448
|
-
for (i = 0; i < 8; i++) ts64(out, 8 * i, hh[i], hl[i]);
|
|
10449
|
-
return 0;
|
|
10450
|
-
}
|
|
10451
|
-
function add(p, q) {
|
|
10452
|
-
var a = gf(), b = gf(), c = gf(), d = gf(), e = gf(), f = gf(), g = gf(), h = gf(), t = gf();
|
|
10453
|
-
Z(a, p[1], p[0]);
|
|
10454
|
-
Z(t, q[1], q[0]);
|
|
10455
|
-
M(a, a, t);
|
|
10456
|
-
A(b, p[0], p[1]);
|
|
10457
|
-
A(t, q[0], q[1]);
|
|
10458
|
-
M(b, b, t);
|
|
10459
|
-
M(c, p[3], q[3]);
|
|
10460
|
-
M(c, c, D2);
|
|
10461
|
-
M(d, p[2], q[2]);
|
|
10462
|
-
A(d, d, d);
|
|
10463
|
-
Z(e, b, a);
|
|
10464
|
-
Z(f, d, c);
|
|
10465
|
-
A(g, d, c);
|
|
10466
|
-
A(h, b, a);
|
|
10467
|
-
M(p[0], e, f);
|
|
10468
|
-
M(p[1], h, g);
|
|
10469
|
-
M(p[2], g, f);
|
|
10470
|
-
M(p[3], e, h);
|
|
10471
|
-
}
|
|
10472
|
-
function cswap(p, q, b) {
|
|
10473
|
-
var i;
|
|
10474
|
-
for (i = 0; i < 4; i++) {
|
|
10475
|
-
sel25519(p[i], q[i], b);
|
|
10476
|
-
}
|
|
10477
|
-
}
|
|
10478
|
-
function pack(r, p) {
|
|
10479
|
-
var tx = gf(), ty = gf(), zi = gf();
|
|
10480
|
-
inv25519(zi, p[2]);
|
|
10481
|
-
M(tx, p[0], zi);
|
|
10482
|
-
M(ty, p[1], zi);
|
|
10483
|
-
pack25519(r, ty);
|
|
10484
|
-
r[31] ^= par25519(tx) << 7;
|
|
10485
|
-
}
|
|
10486
|
-
function scalarmult(p, q, s) {
|
|
10487
|
-
var b, i;
|
|
10488
|
-
set25519(p[0], gf0);
|
|
10489
|
-
set25519(p[1], gf1);
|
|
10490
|
-
set25519(p[2], gf1);
|
|
10491
|
-
set25519(p[3], gf0);
|
|
10492
|
-
for (i = 255; i >= 0; --i) {
|
|
10493
|
-
b = s[i / 8 | 0] >> (i & 7) & 1;
|
|
10494
|
-
cswap(p, q, b);
|
|
10495
|
-
add(q, p);
|
|
10496
|
-
add(p, p);
|
|
10497
|
-
cswap(p, q, b);
|
|
10498
|
-
}
|
|
10499
|
-
}
|
|
10500
|
-
function scalarbase(p, s) {
|
|
10501
|
-
var q = [gf(), gf(), gf(), gf()];
|
|
10502
|
-
set25519(q[0], X);
|
|
10503
|
-
set25519(q[1], Y);
|
|
10504
|
-
set25519(q[2], gf1);
|
|
10505
|
-
M(q[3], X, Y);
|
|
10506
|
-
scalarmult(p, q, s);
|
|
10507
|
-
}
|
|
10508
|
-
function crypto_sign_keypair(pk, sk, seeded) {
|
|
10509
|
-
var d = new Uint8Array(64);
|
|
10510
|
-
var p = [gf(), gf(), gf(), gf()];
|
|
10511
|
-
var i;
|
|
10512
|
-
if (!seeded) randombytes(sk, 32);
|
|
10513
|
-
crypto_hash(d, sk, 32);
|
|
10514
|
-
d[0] &= 248;
|
|
10515
|
-
d[31] &= 127;
|
|
10516
|
-
d[31] |= 64;
|
|
10517
|
-
scalarbase(p, d);
|
|
10518
|
-
pack(pk, p);
|
|
10519
|
-
for (i = 0; i < 32; i++) sk[i + 32] = pk[i];
|
|
10520
|
-
return 0;
|
|
10521
|
-
}
|
|
10522
|
-
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]);
|
|
10523
|
-
function modL(r, x) {
|
|
10524
|
-
var carry, i, j, k;
|
|
10525
|
-
for (i = 63; i >= 32; --i) {
|
|
10526
|
-
carry = 0;
|
|
10527
|
-
for (j = i - 32, k = i - 12; j < k; ++j) {
|
|
10528
|
-
x[j] += carry - 16 * x[i] * L[j - (i - 32)];
|
|
10529
|
-
carry = Math.floor((x[j] + 128) / 256);
|
|
10530
|
-
x[j] -= carry * 256;
|
|
10531
|
-
}
|
|
10532
|
-
x[j] += carry;
|
|
10533
|
-
x[i] = 0;
|
|
10534
|
-
}
|
|
10535
|
-
carry = 0;
|
|
10536
|
-
for (j = 0; j < 32; j++) {
|
|
10537
|
-
x[j] += carry - (x[31] >> 4) * L[j];
|
|
10538
|
-
carry = x[j] >> 8;
|
|
10539
|
-
x[j] &= 255;
|
|
10540
|
-
}
|
|
10541
|
-
for (j = 0; j < 32; j++) x[j] -= carry * L[j];
|
|
10542
|
-
for (i = 0; i < 32; i++) {
|
|
10543
|
-
x[i + 1] += x[i] >> 8;
|
|
10544
|
-
r[i] = x[i] & 255;
|
|
10545
|
-
}
|
|
10546
|
-
}
|
|
10547
|
-
function reduce(r) {
|
|
10548
|
-
var x = new Float64Array(64), i;
|
|
10549
|
-
for (i = 0; i < 64; i++) x[i] = r[i];
|
|
10550
|
-
for (i = 0; i < 64; i++) r[i] = 0;
|
|
10551
|
-
modL(r, x);
|
|
10552
|
-
}
|
|
10553
|
-
function crypto_sign(sm, m, n, sk) {
|
|
10554
|
-
var d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64);
|
|
10555
|
-
var i, j, x = new Float64Array(64);
|
|
10556
|
-
var p = [gf(), gf(), gf(), gf()];
|
|
10557
|
-
crypto_hash(d, sk, 32);
|
|
10558
|
-
d[0] &= 248;
|
|
10559
|
-
d[31] &= 127;
|
|
10560
|
-
d[31] |= 64;
|
|
10561
|
-
var smlen = n + 64;
|
|
10562
|
-
for (i = 0; i < n; i++) sm[64 + i] = m[i];
|
|
10563
|
-
for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i];
|
|
10564
|
-
crypto_hash(r, sm.subarray(32), n + 32);
|
|
10565
|
-
reduce(r);
|
|
10566
|
-
scalarbase(p, r);
|
|
10567
|
-
pack(sm, p);
|
|
10568
|
-
for (i = 32; i < 64; i++) sm[i] = sk[i];
|
|
10569
|
-
crypto_hash(h, sm, n + 64);
|
|
10570
|
-
reduce(h);
|
|
10571
|
-
for (i = 0; i < 64; i++) x[i] = 0;
|
|
10572
|
-
for (i = 0; i < 32; i++) x[i] = r[i];
|
|
10573
|
-
for (i = 0; i < 32; i++) {
|
|
10574
|
-
for (j = 0; j < 32; j++) {
|
|
10575
|
-
x[i + j] += h[i] * d[j];
|
|
10576
|
-
}
|
|
10577
|
-
}
|
|
10578
|
-
modL(sm.subarray(32), x);
|
|
10579
|
-
return smlen;
|
|
10580
|
-
}
|
|
10581
|
-
function unpackneg(r, p) {
|
|
10582
|
-
var t = gf(), chk = gf(), num = gf(), den = gf(), den2 = gf(), den4 = gf(), den6 = gf();
|
|
10583
|
-
set25519(r[2], gf1);
|
|
10584
|
-
unpack25519(r[1], p);
|
|
10585
|
-
S(num, r[1]);
|
|
10586
|
-
M(den, num, D);
|
|
10587
|
-
Z(num, num, r[2]);
|
|
10588
|
-
A(den, r[2], den);
|
|
10589
|
-
S(den2, den);
|
|
10590
|
-
S(den4, den2);
|
|
10591
|
-
M(den6, den4, den2);
|
|
10592
|
-
M(t, den6, num);
|
|
10593
|
-
M(t, t, den);
|
|
10594
|
-
pow2523(t, t);
|
|
10595
|
-
M(t, t, num);
|
|
10596
|
-
M(t, t, den);
|
|
10597
|
-
M(t, t, den);
|
|
10598
|
-
M(r[0], t, den);
|
|
10599
|
-
S(chk, r[0]);
|
|
10600
|
-
M(chk, chk, den);
|
|
10601
|
-
if (neq25519(chk, num)) M(r[0], r[0], I);
|
|
10602
|
-
S(chk, r[0]);
|
|
10603
|
-
M(chk, chk, den);
|
|
10604
|
-
if (neq25519(chk, num)) return -1;
|
|
10605
|
-
if (par25519(r[0]) === p[31] >> 7) Z(r[0], gf0, r[0]);
|
|
10606
|
-
M(r[3], r[0], r[1]);
|
|
10607
|
-
return 0;
|
|
10608
|
-
}
|
|
10609
|
-
function crypto_sign_open(m, sm, n, pk) {
|
|
10610
|
-
var i;
|
|
10611
|
-
var t = new Uint8Array(32), h = new Uint8Array(64);
|
|
10612
|
-
var p = [gf(), gf(), gf(), gf()], q = [gf(), gf(), gf(), gf()];
|
|
10613
|
-
if (n < 64) return -1;
|
|
10614
|
-
if (unpackneg(q, pk)) return -1;
|
|
10615
|
-
for (i = 0; i < n; i++) m[i] = sm[i];
|
|
10616
|
-
for (i = 0; i < 32; i++) m[i + 32] = pk[i];
|
|
10617
|
-
crypto_hash(h, m, n);
|
|
10618
|
-
reduce(h);
|
|
10619
|
-
scalarmult(p, q, h);
|
|
10620
|
-
scalarbase(q, sm.subarray(32));
|
|
10621
|
-
add(p, q);
|
|
10622
|
-
pack(t, p);
|
|
10623
|
-
n -= 64;
|
|
10624
|
-
if (crypto_verify_32(sm, 0, t, 0)) {
|
|
10625
|
-
for (i = 0; i < n; i++) m[i] = 0;
|
|
10626
|
-
return -1;
|
|
10627
|
-
}
|
|
10628
|
-
for (i = 0; i < n; i++) m[i] = sm[i + 64];
|
|
10629
|
-
return n;
|
|
10630
|
-
}
|
|
10631
|
-
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;
|
|
10632
|
-
nacl6.lowlevel = {
|
|
10633
|
-
crypto_core_hsalsa20,
|
|
10634
|
-
crypto_stream_xor,
|
|
10635
|
-
crypto_stream,
|
|
10636
|
-
crypto_stream_salsa20_xor,
|
|
10637
|
-
crypto_stream_salsa20,
|
|
10638
|
-
crypto_onetimeauth,
|
|
10639
|
-
crypto_onetimeauth_verify,
|
|
10640
|
-
crypto_verify_16,
|
|
10641
|
-
crypto_verify_32,
|
|
10642
|
-
crypto_secretbox,
|
|
10643
|
-
crypto_secretbox_open,
|
|
10644
|
-
crypto_scalarmult,
|
|
10645
|
-
crypto_scalarmult_base,
|
|
10646
|
-
crypto_box_beforenm,
|
|
10647
|
-
crypto_box_afternm,
|
|
10648
|
-
crypto_box,
|
|
10649
|
-
crypto_box_open,
|
|
10650
|
-
crypto_box_keypair,
|
|
10651
|
-
crypto_hash,
|
|
10652
|
-
crypto_sign,
|
|
10653
|
-
crypto_sign_keypair,
|
|
10654
|
-
crypto_sign_open,
|
|
10655
|
-
crypto_secretbox_KEYBYTES,
|
|
10656
|
-
crypto_secretbox_NONCEBYTES,
|
|
10657
|
-
crypto_secretbox_ZEROBYTES,
|
|
10658
|
-
crypto_secretbox_BOXZEROBYTES,
|
|
10659
|
-
crypto_scalarmult_BYTES,
|
|
10660
|
-
crypto_scalarmult_SCALARBYTES,
|
|
10661
|
-
crypto_box_PUBLICKEYBYTES,
|
|
10662
|
-
crypto_box_SECRETKEYBYTES,
|
|
10663
|
-
crypto_box_BEFORENMBYTES,
|
|
10664
|
-
crypto_box_NONCEBYTES,
|
|
10665
|
-
crypto_box_ZEROBYTES,
|
|
10666
|
-
crypto_box_BOXZEROBYTES,
|
|
10667
|
-
crypto_sign_BYTES,
|
|
10668
|
-
crypto_sign_PUBLICKEYBYTES,
|
|
10669
|
-
crypto_sign_SECRETKEYBYTES,
|
|
10670
|
-
crypto_sign_SEEDBYTES,
|
|
10671
|
-
crypto_hash_BYTES,
|
|
10672
|
-
gf,
|
|
10673
|
-
D,
|
|
10674
|
-
L,
|
|
10675
|
-
pack25519,
|
|
10676
|
-
unpack25519,
|
|
10677
|
-
M,
|
|
10678
|
-
A,
|
|
10679
|
-
S,
|
|
10680
|
-
Z,
|
|
10681
|
-
pow2523,
|
|
10682
|
-
add,
|
|
10683
|
-
set25519,
|
|
10684
|
-
modL,
|
|
10685
|
-
scalarmult,
|
|
10686
|
-
scalarbase
|
|
10687
|
-
};
|
|
10688
|
-
function checkLengths(k, n) {
|
|
10689
|
-
if (k.length !== crypto_secretbox_KEYBYTES) throw new Error("bad key size");
|
|
10690
|
-
if (n.length !== crypto_secretbox_NONCEBYTES) throw new Error("bad nonce size");
|
|
10691
|
-
}
|
|
10692
|
-
function checkBoxLengths(pk, sk) {
|
|
10693
|
-
if (pk.length !== crypto_box_PUBLICKEYBYTES) throw new Error("bad public key size");
|
|
10694
|
-
if (sk.length !== crypto_box_SECRETKEYBYTES) throw new Error("bad secret key size");
|
|
10695
|
-
}
|
|
10696
|
-
function checkArrayTypes() {
|
|
10697
|
-
for (var i = 0; i < arguments.length; i++) {
|
|
10698
|
-
if (!(arguments[i] instanceof Uint8Array))
|
|
10699
|
-
throw new TypeError("unexpected type, use Uint8Array");
|
|
10700
|
-
}
|
|
10701
|
-
}
|
|
10702
|
-
function cleanup(arr) {
|
|
10703
|
-
for (var i = 0; i < arr.length; i++) arr[i] = 0;
|
|
10704
|
-
}
|
|
10705
|
-
nacl6.randomBytes = function(n) {
|
|
10706
|
-
var b = new Uint8Array(n);
|
|
10707
|
-
randombytes(b, n);
|
|
10708
|
-
return b;
|
|
10709
|
-
};
|
|
10710
|
-
nacl6.secretbox = function(msg, nonce, key) {
|
|
10711
|
-
checkArrayTypes(msg, nonce, key);
|
|
10712
|
-
checkLengths(key, nonce);
|
|
10713
|
-
var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length);
|
|
10714
|
-
var c = new Uint8Array(m.length);
|
|
10715
|
-
for (var i = 0; i < msg.length; i++) m[i + crypto_secretbox_ZEROBYTES] = msg[i];
|
|
10716
|
-
crypto_secretbox(c, m, m.length, nonce, key);
|
|
10717
|
-
return c.subarray(crypto_secretbox_BOXZEROBYTES);
|
|
10718
|
-
};
|
|
10719
|
-
nacl6.secretbox.open = function(box, nonce, key) {
|
|
10720
|
-
checkArrayTypes(box, nonce, key);
|
|
10721
|
-
checkLengths(key, nonce);
|
|
10722
|
-
var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length);
|
|
10723
|
-
var m = new Uint8Array(c.length);
|
|
10724
|
-
for (var i = 0; i < box.length; i++) c[i + crypto_secretbox_BOXZEROBYTES] = box[i];
|
|
10725
|
-
if (c.length < 32) return null;
|
|
10726
|
-
if (crypto_secretbox_open(m, c, c.length, nonce, key) !== 0) return null;
|
|
10727
|
-
return m.subarray(crypto_secretbox_ZEROBYTES);
|
|
10728
|
-
};
|
|
10729
|
-
nacl6.secretbox.keyLength = crypto_secretbox_KEYBYTES;
|
|
10730
|
-
nacl6.secretbox.nonceLength = crypto_secretbox_NONCEBYTES;
|
|
10731
|
-
nacl6.secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES;
|
|
10732
|
-
nacl6.scalarMult = function(n, p) {
|
|
10733
|
-
checkArrayTypes(n, p);
|
|
10734
|
-
if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error("bad n size");
|
|
10735
|
-
if (p.length !== crypto_scalarmult_BYTES) throw new Error("bad p size");
|
|
10736
|
-
var q = new Uint8Array(crypto_scalarmult_BYTES);
|
|
10737
|
-
crypto_scalarmult(q, n, p);
|
|
10738
|
-
return q;
|
|
10739
|
-
};
|
|
10740
|
-
nacl6.scalarMult.base = function(n) {
|
|
10741
|
-
checkArrayTypes(n);
|
|
10742
|
-
if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error("bad n size");
|
|
10743
|
-
var q = new Uint8Array(crypto_scalarmult_BYTES);
|
|
10744
|
-
crypto_scalarmult_base(q, n);
|
|
10745
|
-
return q;
|
|
10746
|
-
};
|
|
10747
|
-
nacl6.scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES;
|
|
10748
|
-
nacl6.scalarMult.groupElementLength = crypto_scalarmult_BYTES;
|
|
10749
|
-
nacl6.box = function(msg, nonce, publicKey, secretKey) {
|
|
10750
|
-
var k = nacl6.box.before(publicKey, secretKey);
|
|
10751
|
-
return nacl6.secretbox(msg, nonce, k);
|
|
10752
|
-
};
|
|
10753
|
-
nacl6.box.before = function(publicKey, secretKey) {
|
|
10754
|
-
checkArrayTypes(publicKey, secretKey);
|
|
10755
|
-
checkBoxLengths(publicKey, secretKey);
|
|
10756
|
-
var k = new Uint8Array(crypto_box_BEFORENMBYTES);
|
|
10757
|
-
crypto_box_beforenm(k, publicKey, secretKey);
|
|
10758
|
-
return k;
|
|
10759
|
-
};
|
|
10760
|
-
nacl6.box.after = nacl6.secretbox;
|
|
10761
|
-
nacl6.box.open = function(msg, nonce, publicKey, secretKey) {
|
|
10762
|
-
var k = nacl6.box.before(publicKey, secretKey);
|
|
10763
|
-
return nacl6.secretbox.open(msg, nonce, k);
|
|
10764
|
-
};
|
|
10765
|
-
nacl6.box.open.after = nacl6.secretbox.open;
|
|
10766
|
-
nacl6.box.keyPair = function() {
|
|
10767
|
-
var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
|
|
10768
|
-
var sk = new Uint8Array(crypto_box_SECRETKEYBYTES);
|
|
10769
|
-
crypto_box_keypair(pk, sk);
|
|
10770
|
-
return { publicKey: pk, secretKey: sk };
|
|
10771
|
-
};
|
|
10772
|
-
nacl6.box.keyPair.fromSecretKey = function(secretKey) {
|
|
10773
|
-
checkArrayTypes(secretKey);
|
|
10774
|
-
if (secretKey.length !== crypto_box_SECRETKEYBYTES)
|
|
10775
|
-
throw new Error("bad secret key size");
|
|
10776
|
-
var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
|
|
10777
|
-
crypto_scalarmult_base(pk, secretKey);
|
|
10778
|
-
return { publicKey: pk, secretKey: new Uint8Array(secretKey) };
|
|
10779
|
-
};
|
|
10780
|
-
nacl6.box.publicKeyLength = crypto_box_PUBLICKEYBYTES;
|
|
10781
|
-
nacl6.box.secretKeyLength = crypto_box_SECRETKEYBYTES;
|
|
10782
|
-
nacl6.box.sharedKeyLength = crypto_box_BEFORENMBYTES;
|
|
10783
|
-
nacl6.box.nonceLength = crypto_box_NONCEBYTES;
|
|
10784
|
-
nacl6.box.overheadLength = nacl6.secretbox.overheadLength;
|
|
10785
|
-
nacl6.sign = function(msg, secretKey) {
|
|
10786
|
-
checkArrayTypes(msg, secretKey);
|
|
10787
|
-
if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
|
|
10788
|
-
throw new Error("bad secret key size");
|
|
10789
|
-
var signedMsg = new Uint8Array(crypto_sign_BYTES + msg.length);
|
|
10790
|
-
crypto_sign(signedMsg, msg, msg.length, secretKey);
|
|
10791
|
-
return signedMsg;
|
|
10792
|
-
};
|
|
10793
|
-
nacl6.sign.open = function(signedMsg, publicKey) {
|
|
10794
|
-
checkArrayTypes(signedMsg, publicKey);
|
|
10795
|
-
if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
|
|
10796
|
-
throw new Error("bad public key size");
|
|
10797
|
-
var tmp = new Uint8Array(signedMsg.length);
|
|
10798
|
-
var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey);
|
|
10799
|
-
if (mlen < 0) return null;
|
|
10800
|
-
var m = new Uint8Array(mlen);
|
|
10801
|
-
for (var i = 0; i < m.length; i++) m[i] = tmp[i];
|
|
10802
|
-
return m;
|
|
10803
|
-
};
|
|
10804
|
-
nacl6.sign.detached = function(msg, secretKey) {
|
|
10805
|
-
var signedMsg = nacl6.sign(msg, secretKey);
|
|
10806
|
-
var sig = new Uint8Array(crypto_sign_BYTES);
|
|
10807
|
-
for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i];
|
|
10808
|
-
return sig;
|
|
10809
|
-
};
|
|
10810
|
-
nacl6.sign.detached.verify = function(msg, sig, publicKey) {
|
|
10811
|
-
checkArrayTypes(msg, sig, publicKey);
|
|
10812
|
-
if (sig.length !== crypto_sign_BYTES)
|
|
10813
|
-
throw new Error("bad signature size");
|
|
10814
|
-
if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
|
|
10815
|
-
throw new Error("bad public key size");
|
|
10816
|
-
var sm = new Uint8Array(crypto_sign_BYTES + msg.length);
|
|
10817
|
-
var m = new Uint8Array(crypto_sign_BYTES + msg.length);
|
|
10818
|
-
var i;
|
|
10819
|
-
for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i];
|
|
10820
|
-
for (i = 0; i < msg.length; i++) sm[i + crypto_sign_BYTES] = msg[i];
|
|
10821
|
-
return crypto_sign_open(m, sm, sm.length, publicKey) >= 0;
|
|
10822
|
-
};
|
|
10823
|
-
nacl6.sign.keyPair = function() {
|
|
10824
|
-
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
|
10825
|
-
var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
|
|
10826
|
-
crypto_sign_keypair(pk, sk);
|
|
10827
|
-
return { publicKey: pk, secretKey: sk };
|
|
10828
|
-
};
|
|
10829
|
-
nacl6.sign.keyPair.fromSecretKey = function(secretKey) {
|
|
10830
|
-
checkArrayTypes(secretKey);
|
|
10831
|
-
if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
|
|
10832
|
-
throw new Error("bad secret key size");
|
|
10833
|
-
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
|
10834
|
-
for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32 + i];
|
|
10835
|
-
return { publicKey: pk, secretKey: new Uint8Array(secretKey) };
|
|
10836
|
-
};
|
|
10837
|
-
nacl6.sign.keyPair.fromSeed = function(seed) {
|
|
10838
|
-
checkArrayTypes(seed);
|
|
10839
|
-
if (seed.length !== crypto_sign_SEEDBYTES)
|
|
10840
|
-
throw new Error("bad seed size");
|
|
10841
|
-
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
|
10842
|
-
var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
|
|
10843
|
-
for (var i = 0; i < 32; i++) sk[i] = seed[i];
|
|
10844
|
-
crypto_sign_keypair(pk, sk, true);
|
|
10845
|
-
return { publicKey: pk, secretKey: sk };
|
|
10846
|
-
};
|
|
10847
|
-
nacl6.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES;
|
|
10848
|
-
nacl6.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES;
|
|
10849
|
-
nacl6.sign.seedLength = crypto_sign_SEEDBYTES;
|
|
10850
|
-
nacl6.sign.signatureLength = crypto_sign_BYTES;
|
|
10851
|
-
nacl6.hash = function(msg) {
|
|
10852
|
-
checkArrayTypes(msg);
|
|
10853
|
-
var h = new Uint8Array(crypto_hash_BYTES);
|
|
10854
|
-
crypto_hash(h, msg, msg.length);
|
|
10855
|
-
return h;
|
|
10856
|
-
};
|
|
10857
|
-
nacl6.hash.hashLength = crypto_hash_BYTES;
|
|
10858
|
-
nacl6.verify = function(x, y) {
|
|
10859
|
-
checkArrayTypes(x, y);
|
|
10860
|
-
if (x.length === 0 || y.length === 0) return false;
|
|
10861
|
-
if (x.length !== y.length) return false;
|
|
10862
|
-
return vn(x, 0, y, 0, x.length) === 0 ? true : false;
|
|
10863
|
-
};
|
|
10864
|
-
nacl6.setPRNG = function(fn) {
|
|
10865
|
-
randombytes = fn;
|
|
10866
|
-
};
|
|
10867
|
-
(function() {
|
|
10868
|
-
var crypto = typeof self !== "undefined" ? self.crypto || self.msCrypto : null;
|
|
10869
|
-
if (crypto && crypto.getRandomValues) {
|
|
10870
|
-
var QUOTA = 65536;
|
|
10871
|
-
nacl6.setPRNG(function(x, n) {
|
|
10872
|
-
var i, v = new Uint8Array(n);
|
|
10873
|
-
for (i = 0; i < n; i += QUOTA) {
|
|
10874
|
-
crypto.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA)));
|
|
10875
|
-
}
|
|
10876
|
-
for (i = 0; i < n; i++) x[i] = v[i];
|
|
10877
|
-
cleanup(v);
|
|
10878
|
-
});
|
|
10879
|
-
} else if (typeof __require2 !== "undefined") {
|
|
10880
|
-
crypto = __require2("crypto");
|
|
10881
|
-
if (crypto && crypto.randomBytes) {
|
|
10882
|
-
nacl6.setPRNG(function(x, n) {
|
|
10883
|
-
var i, v = crypto.randomBytes(n);
|
|
10884
|
-
for (i = 0; i < n; i++) x[i] = v[i];
|
|
10885
|
-
cleanup(v);
|
|
10886
|
-
});
|
|
10887
|
-
}
|
|
10888
|
-
}
|
|
10889
|
-
})();
|
|
10890
|
-
})(typeof module !== "undefined" && module.exports ? module.exports : self.nacl = self.nacl || {});
|
|
10891
|
-
}
|
|
10892
|
-
});
|
|
10893
8643
|
var BACKEND_URL = process.env.PAIGY_BACKEND_URL ?? "https://paigy.ai";
|
|
10894
8644
|
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.`;
|
|
10895
8645
|
var PROXY_ENV = ["HTTPS_PROXY", "https_proxy", "HTTP_PROXY", "http_proxy"];
|
|
@@ -10910,12 +8660,39 @@ var envSession = (key) => {
|
|
|
10910
8660
|
const v = process.env[key];
|
|
10911
8661
|
return v && v.trim() ? v : void 0;
|
|
10912
8662
|
};
|
|
10913
|
-
|
|
8663
|
+
function parentOf(pid) {
|
|
8664
|
+
try {
|
|
8665
|
+
if (process.platform === "win32") return void 0;
|
|
8666
|
+
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 });
|
|
8667
|
+
return Number(ppid?.trim()) || void 0;
|
|
8668
|
+
} catch {
|
|
8669
|
+
return void 0;
|
|
8670
|
+
}
|
|
8671
|
+
}
|
|
8672
|
+
var lineage;
|
|
8673
|
+
function ancestors() {
|
|
8674
|
+
if (lineage) return lineage;
|
|
8675
|
+
lineage = [];
|
|
8676
|
+
for (let pid = process.ppid; pid && pid > 1 && lineage.length < 5; pid = parentOf(pid)) lineage.push(pid);
|
|
8677
|
+
return lineage;
|
|
8678
|
+
}
|
|
8679
|
+
function claudeConversation() {
|
|
8680
|
+
if (!envSession("CLAUDE_CODE_SESSION_ID") || process.env.CLAUDE_CODE_CHILD_SESSION) return void 0;
|
|
8681
|
+
const dir = envSession("CLAUDE_CONFIG_DIR") ?? join(homedir(), ".claude");
|
|
8682
|
+
for (const pid of ancestors()) {
|
|
8683
|
+
try {
|
|
8684
|
+
const { sessionId: sessionId2 } = JSON.parse(readFileSync(join(dir, "sessions", `${pid}.json`), "utf8"));
|
|
8685
|
+
return typeof sessionId2 === "string" && sessionId2.trim() ? sessionId2 : void 0;
|
|
8686
|
+
} catch {
|
|
8687
|
+
}
|
|
8688
|
+
}
|
|
8689
|
+
return void 0;
|
|
8690
|
+
}
|
|
10914
8691
|
function sessionId() {
|
|
10915
|
-
return
|
|
8692
|
+
return envSession("PAIGY_SESSION_ID") ?? claudeConversation() ?? envSession("CLAUDE_CODE_SESSION_ID") ?? envSession("CODEX_THREAD_ID") ?? envSession("CODEX_SESSION_ID") ?? WORKSPACE_ID;
|
|
10916
8693
|
}
|
|
10917
8694
|
async function reach(url, init) {
|
|
10918
|
-
return send(url, init,
|
|
8695
|
+
return send(url, init, sessionId());
|
|
10919
8696
|
}
|
|
10920
8697
|
function reachAs(session) {
|
|
10921
8698
|
return (url, init) => send(url, init, session);
|
|
@@ -12173,32 +9950,28 @@ function mcpInputSchema(s) {
|
|
|
12173
9950
|
delete schema.$schema;
|
|
12174
9951
|
return draft2020(schema);
|
|
12175
9952
|
}
|
|
12176
|
-
var
|
|
12177
|
-
|
|
12178
|
-
|
|
12179
|
-
|
|
12180
|
-
// A DecisionNeed is settled only by an answer in the shape THIS ask declares. Bundle news,
|
|
12181
|
-
// findings and a decision into one, and the person answers whichever part engaged them —
|
|
12182
|
-
// which settles nothing, leaves the need open, and gets them asked again. On call 619c5a92
|
|
12183
|
-
// one ask carried a briefing, a side question ("the ring should show the agent's name now —
|
|
12184
|
-
// what did you actually see?") and a one-of-four about how far an erase reaches. The owner
|
|
12185
|
-
// answered the side question. The need stayed open; the card asked again. Of the 45 call
|
|
12186
|
-
// asks carrying a decision, 27 are over 600 characters.
|
|
12187
|
-
//
|
|
12188
|
-
// Sending them separately costs nothing, because a CALL contact joins the call already
|
|
12189
|
-
// happening (`goal/store.ts`, JOIN BEFORE MINTING) — several contacts on one Goal arrive as
|
|
12190
|
-
// one call, planned as its turns, and each keeps its own settleable need.
|
|
9953
|
+
var AskInputSchema = external_exports.object({
|
|
9954
|
+
id: external_exports.string().optional().describe("Optional idempotency key or client-side ID for this specific ask."),
|
|
9955
|
+
parentId: external_exports.string().uuid().optional().describe("Optional explicit parent Goal ID. If omitted, the platform's semantic router will auto-cluster it."),
|
|
9956
|
+
repo: external_exports.string().optional().describe("Optional repository context."),
|
|
12191
9957
|
ask: external_exports.string().trim().min(1).max(1e4).describe(
|
|
12192
9958
|
"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."
|
|
12193
9959
|
),
|
|
9960
|
+
options: external_exports.array(external_exports.object({
|
|
9961
|
+
label: external_exports.string().trim().min(1).max(1e3),
|
|
9962
|
+
hint: external_exports.string().trim().max(500).describe("Optional short projection of consequence or action if this option is chosen.").optional(),
|
|
9963
|
+
image: external_exports.string().url().optional(),
|
|
9964
|
+
html: external_exports.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()
|
|
9965
|
+
}).strict()).min(2).max(6).optional()
|
|
9966
|
+
}).strict();
|
|
9967
|
+
var StartContactSchema = external_exports.object({
|
|
9968
|
+
asks: external_exports.array(AskInputSchema).min(1).describe("The list of asks/questions to pose. They will be semantically clustered by the API."),
|
|
12194
9969
|
waiting: external_exports.enum(["none", "hard"]).default("none"),
|
|
12195
|
-
channel: external_exports.enum(["notification", "call"]).default("notification")
|
|
12196
|
-
options: external_exports.array(external_exports.object({ label: external_exports.string().trim().min(1).max(1e3), image: external_exports.string().url().optional(), html: external_exports.string().max(16384).optional() }).strict()).min(2).max(6).optional(),
|
|
12197
|
-
threadId: external_exports.string().uuid().optional().describe("Continue an existing Thread: the threadId a prior Delivery returned. Omit to start a new Thread.")
|
|
9970
|
+
channel: external_exports.enum(["notification", "call"]).default("notification")
|
|
12198
9971
|
}).strict();
|
|
12199
9972
|
var ContactSchema = external_exports.union([StartContactSchema, external_exports.object({ deliveryId: external_exports.string().uuid() }).strict()]);
|
|
12200
9973
|
var CONTACT_SCHEMA = { type: "object", ...mcpInputSchema(ContactSchema) };
|
|
12201
|
-
var CONTACT_DESCRIPTION = "Contact the user
|
|
9974
|
+
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.";
|
|
12202
9975
|
var CreateGoalSchema = external_exports.object({
|
|
12203
9976
|
outcome: external_exports.string().trim().min(1).max(1e4),
|
|
12204
9977
|
/** The work's NAME (#2115) — one to five words, how a person refers to it out loud ("the night
|
|
@@ -12210,7 +9983,6 @@ var CreateGoalSchema = external_exports.object({
|
|
|
12210
9983
|
* (owner, on the call of 2026-09-14: "let's do the reference with the threading"). A
|
|
12211
9984
|
* reference only: the owner reads it through `get_thread`, which does its own scoping, and
|
|
12212
9985
|
* the writer refuses a thread belonging to another account. */
|
|
12213
|
-
contextThreadId: external_exports.string().uuid().optional(),
|
|
12214
9986
|
/** THE GOAL THIS ONE BELONGS UNDER (owner, 2026-09-15: "the ask I gave for the design doc
|
|
12215
9987
|
* didn't get created as a child goal of the voice UI goal, which is how it should've
|
|
12216
9988
|
* worked"). It could not have been: this door took no parent, so the only route was
|
|
@@ -12218,12 +9990,15 @@ var CreateGoalSchema = external_exports.object({
|
|
|
12218
9990
|
* took the short one. The hierarchy has been modelled since Goals existed and had been used
|
|
12219
9991
|
* ZERO times in 2,031 of them. Absent, the server judges it against the caller's open Goals
|
|
12220
9992
|
* (`apps/api/src/goal/intake.ts`). The writer refuses a Goal belonging to another account. */
|
|
12221
|
-
parentGoalId: external_exports.string().uuid().optional()
|
|
9993
|
+
parentGoalId: external_exports.string().uuid().optional(),
|
|
9994
|
+
/** The repository or project identifier this Goal belongs to (#2280) — e.g. "owner/repo" or
|
|
9995
|
+
* repo name. Delegated work inherits this from its parent Goal when omitted. */
|
|
9996
|
+
repo: external_exports.string().trim().min(1).max(200).optional()
|
|
12222
9997
|
});
|
|
12223
9998
|
var CreateGoalToolSchema = CreateGoalSchema.extend({
|
|
12224
9999
|
idempotencyKey: CreateGoalSchema.shape.idempotencyKey.optional().describe("Optional. One is minted per call; pass your own only so a retry lands on the same Goal.")
|
|
12225
10000
|
}).strict();
|
|
12226
|
-
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.';
|
|
10001
|
+
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.';
|
|
12227
10002
|
var UpdateGoalSchema = external_exports.object({
|
|
12228
10003
|
revision: external_exports.number().int().positive(),
|
|
12229
10004
|
changes: external_exports.object({
|
|
@@ -12300,10 +10075,11 @@ var TransformSchema = external_exports.enum([
|
|
|
12300
10075
|
var OptionSchema = external_exports.object({
|
|
12301
10076
|
id: external_exports.string(),
|
|
12302
10077
|
label: external_exports.string(),
|
|
10078
|
+
hint: external_exports.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(),
|
|
12303
10079
|
// .describe() flows into the MCP contact JSON schema (zodToJsonSchema), so
|
|
12304
10080
|
// the constraints below are what an agent reads when deciding to use these.
|
|
12305
10081
|
html: external_exports.string().max(16384).describe(
|
|
12306
|
-
"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."
|
|
10082
|
+
"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."
|
|
12307
10083
|
).optional(),
|
|
12308
10084
|
image: external_exports.string().url().describe(
|
|
12309
10085
|
"Optional image URL rendered as the option's preview (plain image, not sandboxed). For agent-generated HTML/CSS mockups, use `html` instead."
|
|
@@ -12394,23 +10170,6 @@ var NotifyRequestFields = external_exports.object({
|
|
|
12394
10170
|
* when `parentId` became the conversation handle: `parentId` says WHERE, this
|
|
12395
10171
|
* says HOW. */
|
|
12396
10172
|
clarifies: external_exports.string().optional(),
|
|
12397
|
-
/** E2EE (text lane): when the pairing is E2EE, the sealed replacements for the
|
|
12398
|
-
* plaintext content fields, keyed by field name. FINALIZED wire shape (was
|
|
12399
|
-
* provisional in the storage PR): a per-field map `{ context?, options?,
|
|
12400
|
-
* visuals? }` of opaque Envelopes — one seal per present content field, so a
|
|
12401
|
-
* message with no options/visuals seals only `context`. It COEXISTS with the
|
|
12402
|
-
* plaintext fields by mutual exclusion: the superRefine below requires that
|
|
12403
|
-
* when `envelope` is present the plaintext `context`/`options`/`visuals` are
|
|
12404
|
-
* ABSENT (and vice-versa), so a row is either fully plaintext or fully sealed —
|
|
12405
|
-
* never a readable half. The server persists this OPAQUELY into
|
|
12406
|
-
* notifications.envelope and relays it blindly; it never decrypts. Absent =
|
|
12407
|
-
* today's plaintext path (context/options/visuals carry the cleartext).
|
|
12408
|
-
* z.lazy because EnvelopeSchema is declared further down (E2EE section). */
|
|
12409
|
-
envelope: external_exports.object({
|
|
12410
|
-
context: external_exports.lazy(() => EnvelopeSchema).optional(),
|
|
12411
|
-
options: external_exports.lazy(() => EnvelopeSchema).optional(),
|
|
12412
|
-
visuals: external_exports.lazy(() => EnvelopeSchema).optional()
|
|
12413
|
-
}).optional(),
|
|
12414
10173
|
select: SelectShapeSchema.optional().describe(
|
|
12415
10174
|
"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."
|
|
12416
10175
|
),
|
|
@@ -12464,22 +10223,6 @@ var NotifyRequestFields = external_exports.object({
|
|
|
12464
10223
|
});
|
|
12465
10224
|
var NotifyRequestSchema = NotifyRequestFields.superRefine((r, ctx) => {
|
|
12466
10225
|
if (r.workId && r.goalId) ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["goalId"], message: "pass goalId or workId, not both" });
|
|
12467
|
-
const sealed = !!r.envelope;
|
|
12468
|
-
if (sealed) {
|
|
12469
|
-
if (!r.envelope?.context)
|
|
12470
|
-
ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["envelope", "context"], message: "sealed request must include envelope.context" });
|
|
12471
|
-
for (const f of ["context", "options", "visuals"]) {
|
|
12472
|
-
if (r[f] !== void 0)
|
|
12473
|
-
ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: [f], message: `E2EE request must not carry plaintext ${f} \u2014 it's sealed in envelope.${f}` });
|
|
12474
|
-
}
|
|
12475
|
-
if (r.points !== void 0)
|
|
12476
|
-
ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["points"], message: "E2EE request must not carry plaintext points" });
|
|
12477
|
-
if (r.ask !== void 0)
|
|
12478
|
-
ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["ask"], message: "E2EE request must not carry a plaintext ask \u2014 derive the shape agent-side and seal it" });
|
|
12479
|
-
if (r.needs !== void 0)
|
|
12480
|
-
ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["needs"], message: "E2EE request must not carry plaintext needs" });
|
|
12481
|
-
return;
|
|
12482
|
-
}
|
|
12483
10226
|
if (r.ask !== void 0) {
|
|
12484
10227
|
for (const f of ["context", "select", "points"]) {
|
|
12485
10228
|
if (r[f] !== void 0)
|
|
@@ -12499,61 +10242,6 @@ var NotifyRequestSchema = NotifyRequestFields.superRefine((r, ctx) => {
|
|
|
12499
10242
|
if (!needsOptions && r.options?.length)
|
|
12500
10243
|
ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["options"], message: `select:'${r.select}' takes no options` });
|
|
12501
10244
|
});
|
|
12502
|
-
function normalizeWaiting(req) {
|
|
12503
|
-
if (!req.waiting) return req;
|
|
12504
|
-
const { waiting, ...rest } = req;
|
|
12505
|
-
return {
|
|
12506
|
-
...rest,
|
|
12507
|
-
urgencyHint: req.urgencyHint ?? { none: "whenever", soft: "soon", hard: "now" }[waiting],
|
|
12508
|
-
blocking: req.blocking || waiting === "hard"
|
|
12509
|
-
};
|
|
12510
|
-
}
|
|
12511
|
-
function unitsOf(text) {
|
|
12512
|
-
const spans = [];
|
|
12513
|
-
const re = /\n\s*\n+/g;
|
|
12514
|
-
let cursor = 0;
|
|
12515
|
-
const push = (from, to) => {
|
|
12516
|
-
const slice = text.slice(from, to);
|
|
12517
|
-
const lead = slice.length - slice.trimStart().length;
|
|
12518
|
-
const tail = slice.length - slice.trimEnd().length;
|
|
12519
|
-
if (from + lead < to - tail) spans.push({ start: from + lead, end: to - tail });
|
|
12520
|
-
};
|
|
12521
|
-
for (let m = re.exec(text); m; m = re.exec(text)) {
|
|
12522
|
-
push(cursor, m.index);
|
|
12523
|
-
cursor = m.index + m[0].length;
|
|
12524
|
-
}
|
|
12525
|
-
push(cursor, text.length);
|
|
12526
|
-
return spans;
|
|
12527
|
-
}
|
|
12528
|
-
function headline(text) {
|
|
12529
|
-
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) ?? "";
|
|
12530
|
-
return (/^[^.!?\n]+[.!?]?/.exec(line)?.[0] ?? line).trim();
|
|
12531
|
-
}
|
|
12532
|
-
function bodyAfterHeadline(text) {
|
|
12533
|
-
const body = text.trim();
|
|
12534
|
-
const title = headline(body);
|
|
12535
|
-
const rest = body.slice(title.length).replace(/^[\s.!?—–-]+/, "").trim();
|
|
12536
|
-
if (!rest) return { title, description: [] };
|
|
12537
|
-
const chunks = unitsOf(rest).map((u) => rest.slice(u.start, u.end)).filter(Boolean);
|
|
12538
|
-
return { title, description: chunks.length ? chunks : [rest] };
|
|
12539
|
-
}
|
|
12540
|
-
function deriveAsk(req) {
|
|
12541
|
-
req = normalizeWaiting(req);
|
|
12542
|
-
if (!req.ask) return req;
|
|
12543
|
-
const text = req.ask.trim();
|
|
12544
|
-
const hinted = req.urgencyHint === "now" ? "call" : req.urgencyHint === "soon" ? "banner" : req.urgencyHint === "whenever" ? "inbox" : req.urgency;
|
|
12545
|
-
const urgency = req.channel === "call" ? "call" : req.channel === "message" && hinted === "call" ? "banner" : hinted;
|
|
12546
|
-
const { ask: _ask, needs, urgencyHint: _hint, channel: _channel, ...rest } = req;
|
|
12547
|
-
return {
|
|
12548
|
-
...rest,
|
|
12549
|
-
context: bodyAfterHeadline(text),
|
|
12550
|
-
// Options riding alongside the ask (#575: pixels can't be prose) floor to a
|
|
12551
|
-
// single pick — the model broker may upgrade to many/rank from the wording.
|
|
12552
|
-
select: req.options?.length ? "one" : "text",
|
|
12553
|
-
urgency,
|
|
12554
|
-
...needs?.length ? { points: needs } : {}
|
|
12555
|
-
};
|
|
12556
|
-
}
|
|
12557
10245
|
var NotifyStatusSchema = external_exports.enum(["pending", "answered", "ignored"]);
|
|
12558
10246
|
var AgentStateSchema = external_exports.enum(["idle", "in_progress", "completed", "needs_input"]);
|
|
12559
10247
|
var TurnSchema = external_exports.object({
|
|
@@ -12609,13 +10297,6 @@ var AwaitItemSchema = external_exports.discriminatedUnion("type", [
|
|
|
12609
10297
|
workId: external_exports.string().uuid().optional(),
|
|
12610
10298
|
decisionId: external_exports.string().uuid().optional(),
|
|
12611
10299
|
answer: UserAnswerSchema,
|
|
12612
|
-
/** E2EE: present when the answer is sealed. The server relays the opaque answer
|
|
12613
|
-
* envelope + the plaintext `ignored` status hint; the receiving agent OPENS it
|
|
12614
|
-
* with its device key and re-derives the real UserAnswer, treating a mismatch
|
|
12615
|
-
* against `ignored` as tampering. Absent = today's plaintext answer (in `answer`).
|
|
12616
|
-
* On a sealed reply the plaintext `answer` is a placeholder (kind reflects only
|
|
12617
|
-
* the `ignored` bit) — never the real content, which stays sealed. */
|
|
12618
|
-
sealed: external_exports.lazy(() => SealedAnswerSchema).optional(),
|
|
12619
10300
|
/** WHAT THE AGENT CANNOT KNOW FROM THE FIELDS BESIDE IT (owner, 2026-09-04, issue
|
|
12620
10301
|
* #1537). One line, built from the record: the ask and the caller's reply VERBATIM,
|
|
12621
10302
|
* the notification they belong to, and the `contact` call that reaches the person
|
|
@@ -12837,21 +10518,6 @@ var InboxItemSchema = external_exports.object({
|
|
|
12837
10518
|
blocking: external_exports.boolean().default(false),
|
|
12838
10519
|
/** The user's locked-in answer; present only for replied items (GET /api/replied/:id). */
|
|
12839
10520
|
answer: UserAnswerSchema.optional(),
|
|
12840
|
-
/** E2EE (text lane): the sealed content this item carries when the pairing is E2EE, in
|
|
12841
|
-
* place of the plaintext `context`/`options`/`visuals` (which the operator would
|
|
12842
|
-
* otherwise read). A per-field map of opaque Envelopes — the SAME shape as
|
|
12843
|
-
* NotifyRequest.envelope. The native app decrypts it locally via openNotification;
|
|
12844
|
-
* web / an un-enrolled device can't and renders a locked placeholder. Absent = today's
|
|
12845
|
-
* plaintext item (context carries the cleartext), so plaintext items are unchanged. */
|
|
12846
|
-
envelope: external_exports.object({
|
|
12847
|
-
context: external_exports.lazy(() => EnvelopeSchema).optional(),
|
|
12848
|
-
options: external_exports.lazy(() => EnvelopeSchema).optional(),
|
|
12849
|
-
visuals: external_exports.lazy(() => EnvelopeSchema).optional()
|
|
12850
|
-
}).optional(),
|
|
12851
|
-
/** E2EE: the agent's device X25519 public key to seal the user's answer BACK to (the
|
|
12852
|
-
* sender the phone replies to). Sourced server-side from this item's pairing credential.
|
|
12853
|
-
* Present only alongside `envelope`; the phone seals via sealAnswer(answer, this, id). */
|
|
12854
|
-
agentX25519: external_exports.string().optional(),
|
|
12855
10521
|
/** THE TARGET FACTS A CARD RENDERS (#1796 point 5, 2026-09-11): the Delivery it is a view of,
|
|
12856
10522
|
* that Delivery's kind, the request Entry, the Goals it answers for, the exact DecisionNeed (none
|
|
12857
10523
|
* for a request that asks nothing), whether its content is sealed, and that Goal's state. The
|
|
@@ -12949,13 +10615,6 @@ var UserSettingsSchema = external_exports.object({
|
|
|
12949
10615
|
* setting. Absent = a spoken time can't be landed, so the reminder rides the next
|
|
12950
10616
|
* call — honest about what we know. */
|
|
12951
10617
|
timezone: external_exports.string().min(1).max(64).optional(),
|
|
12952
|
-
/** Account E2EE state (text lane): 'off' (default) = today's plaintext; 'on' =
|
|
12953
|
-
* content is sealed end-to-end between the local agent and the phone. Like
|
|
12954
|
-
* voiceMode, OPTIONAL and NOT defaulted so a stale client PATCHing the full
|
|
12955
|
-
* settings object without it can't silently flip the account's E2EE state.
|
|
12956
|
-
* Absent = leave unchanged on write, 'off' on read (see store.ts). The demo
|
|
12957
|
-
* account is plaintext by construction and refuses any non-'off' value. */
|
|
12958
|
-
e2eeMode: external_exports.enum(["off", "on"]).optional(),
|
|
12959
10618
|
/** Rung-2 broker tuning (#381). Optional and NOT defaulted, same stale-client
|
|
12960
10619
|
* clobber guard as voiceMode: absent = leave unchanged on write. */
|
|
12961
10620
|
broker: BrokerTuningSchema.optional()
|
|
@@ -13145,6 +10804,8 @@ var QueueItemSchema = external_exports.object({
|
|
|
13145
10804
|
blocked: external_exports.boolean().default(false),
|
|
13146
10805
|
/** Every decision need on it, open or settled — the page decides which to show. */
|
|
13147
10806
|
questions: external_exports.array(QueueQuestionSchema).default([]),
|
|
10807
|
+
/** The repository or project identifier this Goal belongs to (#2280), null if untracked. */
|
|
10808
|
+
repo: external_exports.string().nullable().optional(),
|
|
13148
10809
|
createdAt: external_exports.string(),
|
|
13149
10810
|
updatedAt: external_exports.string().nullable().default(null)
|
|
13150
10811
|
});
|
|
@@ -13258,54 +10919,12 @@ var DeliveryConfigSchema = external_exports.object({
|
|
|
13258
10919
|
* carries credentials; only a `poll` registration can come back with null here. */
|
|
13259
10920
|
realtime: external_exports.object({ url: external_exports.string(), anonKey: external_exports.string() }).nullable()
|
|
13260
10921
|
});
|
|
13261
|
-
var EnvelopeRecipientSchema = external_exports.object({
|
|
13262
|
-
keyId: external_exports.string(),
|
|
13263
|
-
epk: external_exports.string(),
|
|
13264
|
-
wnonce: external_exports.string(),
|
|
13265
|
-
wrap: external_exports.string()
|
|
13266
|
-
});
|
|
13267
|
-
var EnvelopeHeaderSchema = external_exports.object({
|
|
13268
|
-
field: external_exports.enum(["context", "options", "visuals", "answer"]),
|
|
13269
|
-
kind: external_exports.string(),
|
|
13270
|
-
senderRole: external_exports.enum(["agent", "user"]),
|
|
13271
|
-
recipientKeyIds: external_exports.array(external_exports.string()),
|
|
13272
|
-
seq: external_exports.number().int().nonnegative()
|
|
13273
|
-
});
|
|
13274
|
-
var EnvelopeSchema = external_exports.object({
|
|
13275
|
-
v: external_exports.literal(1),
|
|
13276
|
-
alg: external_exports.literal("x25519-xsalsa20poly1305"),
|
|
13277
|
-
msgId: external_exports.string(),
|
|
13278
|
-
hdr: EnvelopeHeaderSchema,
|
|
13279
|
-
recipients: external_exports.array(EnvelopeRecipientSchema).min(1),
|
|
13280
|
-
nonce: external_exports.string(),
|
|
13281
|
-
ct: external_exports.string()
|
|
13282
|
-
});
|
|
13283
|
-
var SealedAnswerSchema = external_exports.object({
|
|
13284
|
-
ignored: external_exports.boolean(),
|
|
13285
|
-
envelope: EnvelopeSchema
|
|
13286
|
-
});
|
|
13287
|
-
var DeviceCredentialSchema = external_exports.object({
|
|
13288
|
-
deviceId: external_exports.string(),
|
|
13289
|
-
kind: external_exports.enum(["phone", "web", "agent"]),
|
|
13290
|
-
x25519Pub: external_exports.string(),
|
|
13291
|
-
ed25519Pub: external_exports.string(),
|
|
13292
|
-
sig: external_exports.string()
|
|
13293
|
-
});
|
|
13294
|
-
var DeviceRosterSchema = external_exports.object({
|
|
13295
|
-
uikPub: external_exports.string(),
|
|
13296
|
-
devices: external_exports.array(DeviceCredentialSchema)
|
|
13297
|
-
});
|
|
13298
10922
|
var WakeNudgeSchema = external_exports.object({
|
|
13299
10923
|
kind: external_exports.enum(["reply", "request", "callback"]),
|
|
13300
10924
|
notificationId: external_exports.string().optional(),
|
|
13301
10925
|
parentId: external_exports.string()
|
|
13302
10926
|
});
|
|
13303
10927
|
var PairingStatusSchema = external_exports.enum(["pending", "approved", "denied", "expired"]);
|
|
13304
|
-
var PairingRevealSchema = external_exports.object({
|
|
13305
|
-
x25519: external_exports.string(),
|
|
13306
|
-
ed25519: external_exports.string(),
|
|
13307
|
-
nonce: external_exports.string()
|
|
13308
|
-
});
|
|
13309
10928
|
var DeviceCodeSchema = external_exports.object({
|
|
13310
10929
|
device_code: external_exports.string(),
|
|
13311
10930
|
user_code: external_exports.string(),
|
|
@@ -13325,19 +10944,7 @@ var DeviceInfoSchema = external_exports.object({
|
|
|
13325
10944
|
* (seen live: PAIGY-5T, 2026-07-21). Remove once a newer binary is the floor. */
|
|
13326
10945
|
agent: external_exports.string().optional(),
|
|
13327
10946
|
device: external_exports.string().nullable(),
|
|
13328
|
-
status: PairingStatusSchema
|
|
13329
|
-
proto: external_exports.string().nullable().optional(),
|
|
13330
|
-
agent_commitment: external_exports.string().nullable().optional(),
|
|
13331
|
-
// Ca
|
|
13332
|
-
agent_reveal: PairingRevealSchema.nullable().optional(),
|
|
13333
|
-
// present once the agent reveals
|
|
13334
|
-
agent_credential: DeviceCredentialSchema.nullable().optional(),
|
|
13335
|
-
// the phone's UIK-signed cred over the agent's keys — the agent fetches it here to finalizeE2ee
|
|
13336
|
-
// The phone's reveal + identity key, exposed here so a GATED agent (e2ee_mode='on', token
|
|
13337
|
-
// withheld until e2ee=true) can compute the SAS WITHOUT a token. Public keys — same safety
|
|
13338
|
-
// class as agent_reveal above. Present only once the phone reveals; null otherwise.
|
|
13339
|
-
phone_reveal: PairingRevealSchema.nullable().optional(),
|
|
13340
|
-
uik_pub: external_exports.string().nullable().optional()
|
|
10947
|
+
status: PairingStatusSchema
|
|
13341
10948
|
});
|
|
13342
10949
|
var DeviceTokenSchema = external_exports.object({
|
|
13343
10950
|
access_token: external_exports.string(),
|
|
@@ -13356,8 +10963,6 @@ var DeviceTokenSchema = external_exports.object({
|
|
|
13356
10963
|
* landed in the FIRST granted workspace and the agent rediscovered its own repo from
|
|
13357
10964
|
* the thread each time (host.ts, live catch 2026-08-06 — prompt-papered until now). */
|
|
13358
10965
|
workspace: external_exports.string().nullable().optional(),
|
|
13359
|
-
phone_reveal: PairingRevealSchema.nullable().optional(),
|
|
13360
|
-
// present once the phone reveals
|
|
13361
10966
|
uik_pub: external_exports.string().nullable().optional()
|
|
13362
10967
|
});
|
|
13363
10968
|
var SupportRequestSchema = external_exports.object({
|
|
@@ -13379,29 +10984,19 @@ var NotificationFeedbackKindSchema = external_exports.enum([
|
|
|
13379
10984
|
"other"
|
|
13380
10985
|
// anything else — the note carries it.
|
|
13381
10986
|
]);
|
|
13382
|
-
var FeedbackResolutionSchema = external_exports.enum(["broker_fixed", "sent_to_agent"]);
|
|
13383
|
-
var FeedbackOutcomeSchema = external_exports.object({
|
|
13384
|
-
resolution: FeedbackResolutionSchema,
|
|
13385
|
-
transform: TransformSchema,
|
|
13386
|
-
message: external_exports.string(),
|
|
13387
|
-
childIds: external_exports.array(external_exports.string()).optional()
|
|
13388
|
-
});
|
|
13389
|
-
var import_tweetnacl = __toESM2(require_nacl_fast(), 1);
|
|
13390
|
-
var import_tweetnacl2 = __toESM2(require_nacl_fast(), 1);
|
|
13391
|
-
var import_tweetnacl3 = __toESM2(require_nacl_fast(), 1);
|
|
13392
|
-
var import_tweetnacl4 = __toESM2(require_nacl_fast(), 1);
|
|
13393
|
-
var import_tweetnacl5 = __toESM2(require_nacl_fast(), 1);
|
|
13394
10987
|
function sessionSlot(sessionId2) {
|
|
13395
10988
|
const id = sessionId2 ?? sessionId();
|
|
13396
10989
|
return `session:${id.slice(0, 8)}`;
|
|
13397
10990
|
}
|
|
13398
|
-
|
|
13399
|
-
|
|
13400
|
-
|
|
10991
|
+
function agentName() {
|
|
10992
|
+
return process.env.PAIGY_AGENT || sessionSlot();
|
|
10993
|
+
}
|
|
10994
|
+
var TOKEN_PATH = join2(homedir2(), ".paigy", "token.json");
|
|
10995
|
+
var KEY_PATH = join2(homedir2(), ".paigy", "key.json");
|
|
13401
10996
|
function readTokenFile() {
|
|
13402
10997
|
if (!existsSync(TOKEN_PATH)) return {};
|
|
13403
10998
|
try {
|
|
13404
|
-
const parsed = JSON.parse(
|
|
10999
|
+
const parsed = JSON.parse(readFileSync2(TOKEN_PATH, "utf8"));
|
|
13405
11000
|
if (typeof parsed.access_token === "string") return {};
|
|
13406
11001
|
const slots = parsed;
|
|
13407
11002
|
delete slots["*"];
|
|
@@ -13413,7 +11008,7 @@ function readTokenFile() {
|
|
|
13413
11008
|
function withTokenLock(mutate) {
|
|
13414
11009
|
const lock = TOKEN_PATH + ".lock";
|
|
13415
11010
|
const spin = new Int32Array(new SharedArrayBuffer(4));
|
|
13416
|
-
mkdirSync(
|
|
11011
|
+
mkdirSync(join2(homedir2(), ".paigy"), { recursive: true });
|
|
13417
11012
|
for (const deadline = Date.now() + 5e3; Date.now() < deadline; ) {
|
|
13418
11013
|
try {
|
|
13419
11014
|
closeSync(openSync(lock, "wx"));
|
|
@@ -13430,7 +11025,7 @@ function withTokenLock(mutate) {
|
|
|
13430
11025
|
rmSync(lock, { force: true });
|
|
13431
11026
|
}
|
|
13432
11027
|
}
|
|
13433
|
-
function saveToken(token, agent2 =
|
|
11028
|
+
function saveToken(token, agent2 = agentName()) {
|
|
13434
11029
|
withTokenLock(() => {
|
|
13435
11030
|
const slots = { ...readTokenFile(), [agent2]: token };
|
|
13436
11031
|
writeFileSync(TOKEN_PATH, JSON.stringify(slots, null, 2) + "\n", { mode: 384 });
|
|
@@ -13451,7 +11046,7 @@ function slotIdentity(agent2) {
|
|
|
13451
11046
|
return { name: t?.name ?? null, voice: t?.voice ?? null, tokenId: t?.token_id ?? null, workspace: t?.workspace ?? null };
|
|
13452
11047
|
}
|
|
13453
11048
|
var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
13454
|
-
function readToken(agent2 =
|
|
11049
|
+
function readToken(agent2 = agentName()) {
|
|
13455
11050
|
if (process.env.PAIGY_TOKEN) return process.env.PAIGY_TOKEN;
|
|
13456
11051
|
return readTokenFile()[agent2]?.access_token ?? "";
|
|
13457
11052
|
}
|
|
@@ -13461,24 +11056,23 @@ function listSlots() {
|
|
|
13461
11056
|
function slotName(agent2) {
|
|
13462
11057
|
return readTokenFile()[agent2]?.name ?? null;
|
|
13463
11058
|
}
|
|
13464
|
-
async function requestCode(suggestedName =
|
|
11059
|
+
async function requestCode(suggestedName = agentName(), device) {
|
|
13465
11060
|
const res = await reach(`${BACKEND_URL}/api/device/code`, {
|
|
13466
11061
|
method: "POST",
|
|
13467
11062
|
headers: { "content-type": "application/json" },
|
|
13468
11063
|
body: JSON.stringify({
|
|
13469
11064
|
suggestedName,
|
|
13470
|
-
...device ? { device } : {}
|
|
13471
|
-
...e2ee ? { proto: e2ee.proto, commitment: e2ee.commitment } : {}
|
|
11065
|
+
...device ? { device } : {}
|
|
13472
11066
|
})
|
|
13473
11067
|
});
|
|
13474
11068
|
if (!res.ok) throw new Error(`/api/device/code failed: ${res.status} ${await res.text()}`);
|
|
13475
11069
|
return await res.json();
|
|
13476
11070
|
}
|
|
13477
|
-
async function pollToken(deviceCode
|
|
11071
|
+
async function pollToken(deviceCode) {
|
|
13478
11072
|
const res = await reach(`${BACKEND_URL}/api/device/token`, {
|
|
13479
11073
|
method: "POST",
|
|
13480
11074
|
headers: { "content-type": "application/json" },
|
|
13481
|
-
body: JSON.stringify(
|
|
11075
|
+
body: JSON.stringify({ device_code: deviceCode })
|
|
13482
11076
|
});
|
|
13483
11077
|
if (res.ok) return await res.json();
|
|
13484
11078
|
const body = await res.json().catch(() => ({ error: "unknown" }));
|
|
@@ -13490,14 +11084,6 @@ async function pollToken(deviceCode, reveal) {
|
|
|
13490
11084
|
if (err === "access_denied") throw new Error("Access denied by user. Pairing cancelled.");
|
|
13491
11085
|
throw new Error(`Unexpected error from /api/device/token: ${err}`);
|
|
13492
11086
|
}
|
|
13493
|
-
function readKeyFile() {
|
|
13494
|
-
if (!existsSync(KEY_PATH)) return null;
|
|
13495
|
-
try {
|
|
13496
|
-
return JSON.parse(readFileSync(KEY_PATH, "utf8"));
|
|
13497
|
-
} catch {
|
|
13498
|
-
return null;
|
|
13499
|
-
}
|
|
13500
|
-
}
|
|
13501
11087
|
var UnpairedError = class extends Error {
|
|
13502
11088
|
constructor() {
|
|
13503
11089
|
super("Not paired with Paigy \u2014 no valid token (the API answered 401). Run the pairing flow, then retry.");
|
|
@@ -13526,6 +11112,16 @@ var ApiError = class extends Error {
|
|
|
13526
11112
|
async function fail(what, res) {
|
|
13527
11113
|
throw new ApiError(what, res.status, await res.text());
|
|
13528
11114
|
}
|
|
11115
|
+
async function createGoal(input, opts = {}) {
|
|
11116
|
+
const token = authToken(opts.token) ?? "";
|
|
11117
|
+
const res = ensureAuthed(await (opts.reach ?? reach)(`${BACKEND_URL}/api/goals`, {
|
|
11118
|
+
method: "POST",
|
|
11119
|
+
headers: { "content-type": "application/json", authorization: `Bearer ${token}`, "x-paigy-model": "goal-entry-v1" },
|
|
11120
|
+
body: JSON.stringify(input)
|
|
11121
|
+
}));
|
|
11122
|
+
if (!res.ok) await fail("create_goal", res);
|
|
11123
|
+
return await res.json();
|
|
11124
|
+
}
|
|
13529
11125
|
async function claimGoal(goalId, opts = {}) {
|
|
13530
11126
|
const token = authToken(opts.token) ?? "";
|
|
13531
11127
|
const res = ensureAuthed(await (opts.reach ?? reach)(`${BACKEND_URL}/api/goals/claim`, { method: "POST", headers: { "content-type": "application/json", authorization: `Bearer ${token}`, "x-paigy-model": "goal-entry-v1" }, body: JSON.stringify(goalId ? { goalId } : {}) }));
|
|
@@ -13643,20 +11239,34 @@ async function contact(input, opts = {}) {
|
|
|
13643
11239
|
const send22 = opts.reach ?? reach;
|
|
13644
11240
|
const headers = { "content-type": "application/json", authorization: `Bearer ${authToken(opts.token) ?? ""}`, "x-paigy-model": "goal-entry-v1" };
|
|
13645
11241
|
let deliveryId;
|
|
13646
|
-
|
|
13647
|
-
|
|
13648
|
-
|
|
13649
|
-
|
|
13650
|
-
const
|
|
11242
|
+
let deliveries = [];
|
|
11243
|
+
if ("deliveryId" in parsed) {
|
|
11244
|
+
deliveryId = parsed.deliveryId;
|
|
11245
|
+
} else {
|
|
11246
|
+
const reqAsks = parsed.asks.map((a) => ({
|
|
11247
|
+
id: a.id,
|
|
11248
|
+
parentId: a.parentId,
|
|
11249
|
+
repo: a.repo,
|
|
11250
|
+
ask: a.ask,
|
|
11251
|
+
options: a.options ?? []
|
|
11252
|
+
}));
|
|
11253
|
+
const res = ensureAuthed(await send22(`${BACKEND_URL}/api/goals/contact`, {
|
|
13651
11254
|
method: "POST",
|
|
13652
11255
|
headers,
|
|
13653
11256
|
signal: opts.signal,
|
|
13654
|
-
body: JSON.stringify({
|
|
11257
|
+
body: JSON.stringify({
|
|
11258
|
+
operationId: opts.operationId ?? randomUUID3(),
|
|
11259
|
+
asks: reqAsks,
|
|
11260
|
+
waiting: parsed.waiting,
|
|
11261
|
+
channel: parsed.channel === "call" ? "call" : "message"
|
|
11262
|
+
})
|
|
13655
11263
|
}));
|
|
13656
|
-
if (!res.ok) await fail("
|
|
11264
|
+
if (!res.ok) await fail("batch contact", res);
|
|
13657
11265
|
const receipt = await res.json();
|
|
13658
|
-
|
|
13659
|
-
if (
|
|
11266
|
+
deliveries = receipt.deliveries ?? [];
|
|
11267
|
+
if (deliveries.length === 0) throw new Error("Goal contact returned no Delivery identities");
|
|
11268
|
+
deliveryId = deliveries[0]?.deliveryId ?? "";
|
|
11269
|
+
if (!deliveryId) throw new Error("Goal contact returned no valid Delivery identity");
|
|
13660
11270
|
}
|
|
13661
11271
|
const read = async (signal2) => {
|
|
13662
11272
|
const res = ensureAuthed(await send22(`${BACKEND_URL}/api/deliveries/${encodeURIComponent(deliveryId)}`, { headers, signal: signal2 }));
|
|
@@ -13788,13 +11398,13 @@ async function subscribeWake(onNudge, opts = {}) {
|
|
|
13788
11398
|
|
|
13789
11399
|
// src/main.ts
|
|
13790
11400
|
var import_qrcode = __toESM(require_lib(), 1);
|
|
13791
|
-
import { homedir as
|
|
11401
|
+
import { homedir as homedir9, hostname } from "os";
|
|
13792
11402
|
|
|
13793
11403
|
// src/harness/catalog.ts
|
|
13794
11404
|
import { spawnSync } from "child_process";
|
|
13795
11405
|
import { existsSync as existsSync2 } from "fs";
|
|
13796
|
-
import { homedir as
|
|
13797
|
-
import { delimiter, dirname, join as
|
|
11406
|
+
import { homedir as homedir3 } from "os";
|
|
11407
|
+
import { delimiter, dirname, join as join3 } from "path";
|
|
13798
11408
|
var CATALOG = [
|
|
13799
11409
|
{
|
|
13800
11410
|
name: "claude",
|
|
@@ -13827,13 +11437,13 @@ var CATALOG = [
|
|
|
13827
11437
|
installCli: "curl -fsSL https://antigravity.dev/install.sh | bash"
|
|
13828
11438
|
}
|
|
13829
11439
|
];
|
|
13830
|
-
function probeDirs(home =
|
|
11440
|
+
function probeDirs(home = homedir3()) {
|
|
13831
11441
|
return [
|
|
13832
11442
|
dirname(process.execPath),
|
|
13833
|
-
|
|
11443
|
+
join3(home, ".local", "bin"),
|
|
13834
11444
|
"/usr/local/bin",
|
|
13835
11445
|
"/opt/homebrew/bin",
|
|
13836
|
-
|
|
11446
|
+
join3(home, ".npm-global", "bin")
|
|
13837
11447
|
];
|
|
13838
11448
|
}
|
|
13839
11449
|
function which(bin) {
|
|
@@ -13841,7 +11451,7 @@ function which(bin) {
|
|
|
13841
11451
|
const fromPath = hit.status === 0 ? hit.stdout.trim() : "";
|
|
13842
11452
|
if (fromPath) return fromPath;
|
|
13843
11453
|
for (const dir of probeDirs()) {
|
|
13844
|
-
const candidate =
|
|
11454
|
+
const candidate = join3(dir, bin);
|
|
13845
11455
|
if (existsSync2(candidate)) return candidate;
|
|
13846
11456
|
}
|
|
13847
11457
|
return null;
|
|
@@ -13881,27 +11491,27 @@ function detectAll(deps = {}) {
|
|
|
13881
11491
|
}
|
|
13882
11492
|
|
|
13883
11493
|
// src/host.ts
|
|
13884
|
-
import { readFileSync as
|
|
13885
|
-
import { homedir as
|
|
13886
|
-
import { join as
|
|
11494
|
+
import { readFileSync as readFileSync4, writeFileSync as writeFileSync3 } from "fs";
|
|
11495
|
+
import { homedir as homedir7 } from "os";
|
|
11496
|
+
import { join as join7 } from "path";
|
|
13887
11497
|
|
|
13888
11498
|
// src/workspaces.ts
|
|
13889
|
-
import { existsSync as existsSync3, mkdirSync as mkdirSync2, readFileSync as
|
|
13890
|
-
import { dirname as dirname2, join as
|
|
13891
|
-
import { homedir as
|
|
11499
|
+
import { existsSync as existsSync3, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "fs";
|
|
11500
|
+
import { dirname as dirname2, join as join4, resolve } from "path";
|
|
11501
|
+
import { homedir as homedir4 } from "os";
|
|
13892
11502
|
function workspacesFile() {
|
|
13893
|
-
return
|
|
11503
|
+
return join4(homedir4(), ".paigy", "workspaces.json");
|
|
13894
11504
|
}
|
|
13895
11505
|
function listWorkspaces(deps) {
|
|
13896
11506
|
try {
|
|
13897
|
-
const parsed = JSON.parse(
|
|
11507
|
+
const parsed = JSON.parse(readFileSync3(deps.file, "utf8"));
|
|
13898
11508
|
return Array.isArray(parsed) ? parsed.filter((w) => typeof w === "string") : [];
|
|
13899
11509
|
} catch {
|
|
13900
11510
|
return [];
|
|
13901
11511
|
}
|
|
13902
11512
|
}
|
|
13903
11513
|
function addWorkspace(dir, deps) {
|
|
13904
|
-
const next = resolve(dir.replace(/^~(?=$|\/)/,
|
|
11514
|
+
const next = resolve(dir.replace(/^~(?=$|\/)/, homedir4()));
|
|
13905
11515
|
const all = listWorkspaces(deps);
|
|
13906
11516
|
if (!all.includes(next)) {
|
|
13907
11517
|
all.push(next);
|
|
@@ -13917,12 +11527,12 @@ function removeWorkspace(dir, deps) {
|
|
|
13917
11527
|
return all;
|
|
13918
11528
|
}
|
|
13919
11529
|
function allowed(cwd, deps) {
|
|
13920
|
-
const target = resolve(cwd.replace(/^~(?=$|\/)/,
|
|
11530
|
+
const target = resolve(cwd.replace(/^~(?=$|\/)/, homedir4()));
|
|
13921
11531
|
return listWorkspaces(deps).some((w) => target === w || target.startsWith(`${w}/`));
|
|
13922
11532
|
}
|
|
13923
11533
|
function resolveWakeDir(pinned, deps) {
|
|
13924
11534
|
if (pinned && allowed(pinned, deps)) {
|
|
13925
|
-
const dir = resolve(pinned.replace(/^~(?=$|\/)/,
|
|
11535
|
+
const dir = resolve(pinned.replace(/^~(?=$|\/)/, homedir4()));
|
|
13926
11536
|
if ((deps.exists ?? existsSync3)(dir)) return dir;
|
|
13927
11537
|
}
|
|
13928
11538
|
return listWorkspaces(deps)[0];
|
|
@@ -13930,8 +11540,8 @@ function resolveWakeDir(pinned, deps) {
|
|
|
13930
11540
|
|
|
13931
11541
|
// src/owner.ts
|
|
13932
11542
|
import { closeSync as closeSync2, openSync as openSync2, readSync, readdirSync } from "fs";
|
|
13933
|
-
import { homedir as
|
|
13934
|
-
import { join as
|
|
11543
|
+
import { homedir as homedir5 } from "os";
|
|
11544
|
+
import { join as join5 } from "path";
|
|
13935
11545
|
var HEAD_BYTES = 64e3;
|
|
13936
11546
|
function readHead(file) {
|
|
13937
11547
|
const fd = openSync2(file, "r");
|
|
@@ -13947,7 +11557,7 @@ function ownerSession(slot, deps = {}) {
|
|
|
13947
11557
|
const m = /^session:([0-9a-f]{8})$/.exec(slot);
|
|
13948
11558
|
if (!m) return null;
|
|
13949
11559
|
const prefix = m[1];
|
|
13950
|
-
const root = deps.projectsDir ??
|
|
11560
|
+
const root = deps.projectsDir ?? join5(homedir5(), ".claude", "projects");
|
|
13951
11561
|
const list = deps.list ?? ((dir) => readdirSync(dir));
|
|
13952
11562
|
const head = deps.head ?? readHead;
|
|
13953
11563
|
let folders;
|
|
@@ -13959,7 +11569,7 @@ function ownerSession(slot, deps = {}) {
|
|
|
13959
11569
|
for (const folder of folders) {
|
|
13960
11570
|
let files;
|
|
13961
11571
|
try {
|
|
13962
|
-
files = list(
|
|
11572
|
+
files = list(join5(root, folder));
|
|
13963
11573
|
} catch {
|
|
13964
11574
|
continue;
|
|
13965
11575
|
}
|
|
@@ -13967,7 +11577,7 @@ function ownerSession(slot, deps = {}) {
|
|
|
13967
11577
|
if (!file) continue;
|
|
13968
11578
|
let text;
|
|
13969
11579
|
try {
|
|
13970
|
-
text = head(
|
|
11580
|
+
text = head(join5(root, folder, file));
|
|
13971
11581
|
} catch {
|
|
13972
11582
|
continue;
|
|
13973
11583
|
}
|
|
@@ -15300,32 +12910,28 @@ function mcpInputSchema2(s) {
|
|
|
15300
12910
|
delete schema.$schema;
|
|
15301
12911
|
return draft20202(schema);
|
|
15302
12912
|
}
|
|
15303
|
-
var
|
|
15304
|
-
|
|
15305
|
-
|
|
15306
|
-
|
|
15307
|
-
// A DecisionNeed is settled only by an answer in the shape THIS ask declares. Bundle news,
|
|
15308
|
-
// findings and a decision into one, and the person answers whichever part engaged them —
|
|
15309
|
-
// which settles nothing, leaves the need open, and gets them asked again. On call 619c5a92
|
|
15310
|
-
// one ask carried a briefing, a side question ("the ring should show the agent's name now —
|
|
15311
|
-
// what did you actually see?") and a one-of-four about how far an erase reaches. The owner
|
|
15312
|
-
// answered the side question. The need stayed open; the card asked again. Of the 45 call
|
|
15313
|
-
// asks carrying a decision, 27 are over 600 characters.
|
|
15314
|
-
//
|
|
15315
|
-
// Sending them separately costs nothing, because a CALL contact joins the call already
|
|
15316
|
-
// happening (`goal/store.ts`, JOIN BEFORE MINTING) — several contacts on one Goal arrive as
|
|
15317
|
-
// one call, planned as its turns, and each keeps its own settleable need.
|
|
12913
|
+
var AskInputSchema2 = external_exports.object({
|
|
12914
|
+
id: external_exports.string().optional().describe("Optional idempotency key or client-side ID for this specific ask."),
|
|
12915
|
+
parentId: external_exports.string().uuid().optional().describe("Optional explicit parent Goal ID. If omitted, the platform's semantic router will auto-cluster it."),
|
|
12916
|
+
repo: external_exports.string().optional().describe("Optional repository context."),
|
|
15318
12917
|
ask: external_exports.string().trim().min(1).max(1e4).describe(
|
|
15319
12918
|
"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."
|
|
15320
12919
|
),
|
|
12920
|
+
options: external_exports.array(external_exports.object({
|
|
12921
|
+
label: external_exports.string().trim().min(1).max(1e3),
|
|
12922
|
+
hint: external_exports.string().trim().max(500).describe("Optional short projection of consequence or action if this option is chosen.").optional(),
|
|
12923
|
+
image: external_exports.string().url().optional(),
|
|
12924
|
+
html: external_exports.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()
|
|
12925
|
+
}).strict()).min(2).max(6).optional()
|
|
12926
|
+
}).strict();
|
|
12927
|
+
var StartContactSchema2 = external_exports.object({
|
|
12928
|
+
asks: external_exports.array(AskInputSchema2).min(1).describe("The list of asks/questions to pose. They will be semantically clustered by the API."),
|
|
15321
12929
|
waiting: external_exports.enum(["none", "hard"]).default("none"),
|
|
15322
|
-
channel: external_exports.enum(["notification", "call"]).default("notification")
|
|
15323
|
-
options: external_exports.array(external_exports.object({ label: external_exports.string().trim().min(1).max(1e3), image: external_exports.string().url().optional(), html: external_exports.string().max(16384).optional() }).strict()).min(2).max(6).optional(),
|
|
15324
|
-
threadId: external_exports.string().uuid().optional().describe("Continue an existing Thread: the threadId a prior Delivery returned. Omit to start a new Thread.")
|
|
12930
|
+
channel: external_exports.enum(["notification", "call"]).default("notification")
|
|
15325
12931
|
}).strict();
|
|
15326
12932
|
var ContactSchema2 = external_exports.union([StartContactSchema2, external_exports.object({ deliveryId: external_exports.string().uuid() }).strict()]);
|
|
15327
12933
|
var CONTACT_SCHEMA2 = { type: "object", ...mcpInputSchema2(ContactSchema2) };
|
|
15328
|
-
var CONTACT_DESCRIPTION2 = "Contact the user
|
|
12934
|
+
var CONTACT_DESCRIPTION2 = "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.";
|
|
15329
12935
|
var CreateGoalSchema2 = external_exports.object({
|
|
15330
12936
|
outcome: external_exports.string().trim().min(1).max(1e4),
|
|
15331
12937
|
/** The work's NAME (#2115) — one to five words, how a person refers to it out loud ("the night
|
|
@@ -15337,7 +12943,6 @@ var CreateGoalSchema2 = external_exports.object({
|
|
|
15337
12943
|
* (owner, on the call of 2026-09-14: "let's do the reference with the threading"). A
|
|
15338
12944
|
* reference only: the owner reads it through `get_thread`, which does its own scoping, and
|
|
15339
12945
|
* the writer refuses a thread belonging to another account. */
|
|
15340
|
-
contextThreadId: external_exports.string().uuid().optional(),
|
|
15341
12946
|
/** THE GOAL THIS ONE BELONGS UNDER (owner, 2026-09-15: "the ask I gave for the design doc
|
|
15342
12947
|
* didn't get created as a child goal of the voice UI goal, which is how it should've
|
|
15343
12948
|
* worked"). It could not have been: this door took no parent, so the only route was
|
|
@@ -15345,12 +12950,15 @@ var CreateGoalSchema2 = external_exports.object({
|
|
|
15345
12950
|
* took the short one. The hierarchy has been modelled since Goals existed and had been used
|
|
15346
12951
|
* ZERO times in 2,031 of them. Absent, the server judges it against the caller's open Goals
|
|
15347
12952
|
* (`apps/api/src/goal/intake.ts`). The writer refuses a Goal belonging to another account. */
|
|
15348
|
-
parentGoalId: external_exports.string().uuid().optional()
|
|
12953
|
+
parentGoalId: external_exports.string().uuid().optional(),
|
|
12954
|
+
/** The repository or project identifier this Goal belongs to (#2280) — e.g. "owner/repo" or
|
|
12955
|
+
* repo name. Delegated work inherits this from its parent Goal when omitted. */
|
|
12956
|
+
repo: external_exports.string().trim().min(1).max(200).optional()
|
|
15349
12957
|
});
|
|
15350
12958
|
var CreateGoalToolSchema2 = CreateGoalSchema2.extend({
|
|
15351
12959
|
idempotencyKey: CreateGoalSchema2.shape.idempotencyKey.optional().describe("Optional. One is minted per call; pass your own only so a retry lands on the same Goal.")
|
|
15352
12960
|
}).strict();
|
|
15353
|
-
var CREATE_GOAL_DESCRIPTION2 = '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.';
|
|
12961
|
+
var CREATE_GOAL_DESCRIPTION2 = '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.';
|
|
15354
12962
|
var UpdateGoalSchema2 = external_exports.object({
|
|
15355
12963
|
revision: external_exports.number().int().positive(),
|
|
15356
12964
|
changes: external_exports.object({
|
|
@@ -15442,10 +13050,11 @@ var TransformSchema2 = external_exports.enum([
|
|
|
15442
13050
|
var OptionSchema2 = external_exports.object({
|
|
15443
13051
|
id: external_exports.string(),
|
|
15444
13052
|
label: external_exports.string(),
|
|
13053
|
+
hint: external_exports.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(),
|
|
15445
13054
|
// .describe() flows into the MCP contact JSON schema (zodToJsonSchema), so
|
|
15446
13055
|
// the constraints below are what an agent reads when deciding to use these.
|
|
15447
13056
|
html: external_exports.string().max(16384).describe(
|
|
15448
|
-
"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."
|
|
13057
|
+
"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."
|
|
15449
13058
|
).optional(),
|
|
15450
13059
|
image: external_exports.string().url().describe(
|
|
15451
13060
|
"Optional image URL rendered as the option's preview (plain image, not sandboxed). For agent-generated HTML/CSS mockups, use `html` instead."
|
|
@@ -15536,23 +13145,6 @@ var NotifyRequestFields2 = external_exports.object({
|
|
|
15536
13145
|
* when `parentId` became the conversation handle: `parentId` says WHERE, this
|
|
15537
13146
|
* says HOW. */
|
|
15538
13147
|
clarifies: external_exports.string().optional(),
|
|
15539
|
-
/** E2EE (text lane): when the pairing is E2EE, the sealed replacements for the
|
|
15540
|
-
* plaintext content fields, keyed by field name. FINALIZED wire shape (was
|
|
15541
|
-
* provisional in the storage PR): a per-field map `{ context?, options?,
|
|
15542
|
-
* visuals? }` of opaque Envelopes — one seal per present content field, so a
|
|
15543
|
-
* message with no options/visuals seals only `context`. It COEXISTS with the
|
|
15544
|
-
* plaintext fields by mutual exclusion: the superRefine below requires that
|
|
15545
|
-
* when `envelope` is present the plaintext `context`/`options`/`visuals` are
|
|
15546
|
-
* ABSENT (and vice-versa), so a row is either fully plaintext or fully sealed —
|
|
15547
|
-
* never a readable half. The server persists this OPAQUELY into
|
|
15548
|
-
* notifications.envelope and relays it blindly; it never decrypts. Absent =
|
|
15549
|
-
* today's plaintext path (context/options/visuals carry the cleartext).
|
|
15550
|
-
* z.lazy because EnvelopeSchema is declared further down (E2EE section). */
|
|
15551
|
-
envelope: external_exports.object({
|
|
15552
|
-
context: external_exports.lazy(() => EnvelopeSchema2).optional(),
|
|
15553
|
-
options: external_exports.lazy(() => EnvelopeSchema2).optional(),
|
|
15554
|
-
visuals: external_exports.lazy(() => EnvelopeSchema2).optional()
|
|
15555
|
-
}).optional(),
|
|
15556
13148
|
select: SelectShapeSchema2.optional().describe(
|
|
15557
13149
|
"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."
|
|
15558
13150
|
),
|
|
@@ -15606,22 +13198,6 @@ var NotifyRequestFields2 = external_exports.object({
|
|
|
15606
13198
|
});
|
|
15607
13199
|
var NotifyRequestSchema2 = NotifyRequestFields2.superRefine((r, ctx) => {
|
|
15608
13200
|
if (r.workId && r.goalId) ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["goalId"], message: "pass goalId or workId, not both" });
|
|
15609
|
-
const sealed = !!r.envelope;
|
|
15610
|
-
if (sealed) {
|
|
15611
|
-
if (!r.envelope?.context)
|
|
15612
|
-
ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["envelope", "context"], message: "sealed request must include envelope.context" });
|
|
15613
|
-
for (const f of ["context", "options", "visuals"]) {
|
|
15614
|
-
if (r[f] !== void 0)
|
|
15615
|
-
ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: [f], message: `E2EE request must not carry plaintext ${f} \u2014 it's sealed in envelope.${f}` });
|
|
15616
|
-
}
|
|
15617
|
-
if (r.points !== void 0)
|
|
15618
|
-
ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["points"], message: "E2EE request must not carry plaintext points" });
|
|
15619
|
-
if (r.ask !== void 0)
|
|
15620
|
-
ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["ask"], message: "E2EE request must not carry a plaintext ask \u2014 derive the shape agent-side and seal it" });
|
|
15621
|
-
if (r.needs !== void 0)
|
|
15622
|
-
ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: ["needs"], message: "E2EE request must not carry plaintext needs" });
|
|
15623
|
-
return;
|
|
15624
|
-
}
|
|
15625
13201
|
if (r.ask !== void 0) {
|
|
15626
13202
|
for (const f of ["context", "select", "points"]) {
|
|
15627
13203
|
if (r[f] !== void 0)
|
|
@@ -15696,13 +13272,6 @@ var AwaitItemSchema2 = external_exports.discriminatedUnion("type", [
|
|
|
15696
13272
|
workId: external_exports.string().uuid().optional(),
|
|
15697
13273
|
decisionId: external_exports.string().uuid().optional(),
|
|
15698
13274
|
answer: UserAnswerSchema2,
|
|
15699
|
-
/** E2EE: present when the answer is sealed. The server relays the opaque answer
|
|
15700
|
-
* envelope + the plaintext `ignored` status hint; the receiving agent OPENS it
|
|
15701
|
-
* with its device key and re-derives the real UserAnswer, treating a mismatch
|
|
15702
|
-
* against `ignored` as tampering. Absent = today's plaintext answer (in `answer`).
|
|
15703
|
-
* On a sealed reply the plaintext `answer` is a placeholder (kind reflects only
|
|
15704
|
-
* the `ignored` bit) — never the real content, which stays sealed. */
|
|
15705
|
-
sealed: external_exports.lazy(() => SealedAnswerSchema2).optional(),
|
|
15706
13275
|
/** WHAT THE AGENT CANNOT KNOW FROM THE FIELDS BESIDE IT (owner, 2026-09-04, issue
|
|
15707
13276
|
* #1537). One line, built from the record: the ask and the caller's reply VERBATIM,
|
|
15708
13277
|
* the notification they belong to, and the `contact` call that reaches the person
|
|
@@ -15924,21 +13493,6 @@ var InboxItemSchema2 = external_exports.object({
|
|
|
15924
13493
|
blocking: external_exports.boolean().default(false),
|
|
15925
13494
|
/** The user's locked-in answer; present only for replied items (GET /api/replied/:id). */
|
|
15926
13495
|
answer: UserAnswerSchema2.optional(),
|
|
15927
|
-
/** E2EE (text lane): the sealed content this item carries when the pairing is E2EE, in
|
|
15928
|
-
* place of the plaintext `context`/`options`/`visuals` (which the operator would
|
|
15929
|
-
* otherwise read). A per-field map of opaque Envelopes — the SAME shape as
|
|
15930
|
-
* NotifyRequest.envelope. The native app decrypts it locally via openNotification;
|
|
15931
|
-
* web / an un-enrolled device can't and renders a locked placeholder. Absent = today's
|
|
15932
|
-
* plaintext item (context carries the cleartext), so plaintext items are unchanged. */
|
|
15933
|
-
envelope: external_exports.object({
|
|
15934
|
-
context: external_exports.lazy(() => EnvelopeSchema2).optional(),
|
|
15935
|
-
options: external_exports.lazy(() => EnvelopeSchema2).optional(),
|
|
15936
|
-
visuals: external_exports.lazy(() => EnvelopeSchema2).optional()
|
|
15937
|
-
}).optional(),
|
|
15938
|
-
/** E2EE: the agent's device X25519 public key to seal the user's answer BACK to (the
|
|
15939
|
-
* sender the phone replies to). Sourced server-side from this item's pairing credential.
|
|
15940
|
-
* Present only alongside `envelope`; the phone seals via sealAnswer(answer, this, id). */
|
|
15941
|
-
agentX25519: external_exports.string().optional(),
|
|
15942
13496
|
/** THE TARGET FACTS A CARD RENDERS (#1796 point 5, 2026-09-11): the Delivery it is a view of,
|
|
15943
13497
|
* that Delivery's kind, the request Entry, the Goals it answers for, the exact DecisionNeed (none
|
|
15944
13498
|
* for a request that asks nothing), whether its content is sealed, and that Goal's state. The
|
|
@@ -16036,13 +13590,6 @@ var UserSettingsSchema2 = external_exports.object({
|
|
|
16036
13590
|
* setting. Absent = a spoken time can't be landed, so the reminder rides the next
|
|
16037
13591
|
* call — honest about what we know. */
|
|
16038
13592
|
timezone: external_exports.string().min(1).max(64).optional(),
|
|
16039
|
-
/** Account E2EE state (text lane): 'off' (default) = today's plaintext; 'on' =
|
|
16040
|
-
* content is sealed end-to-end between the local agent and the phone. Like
|
|
16041
|
-
* voiceMode, OPTIONAL and NOT defaulted so a stale client PATCHing the full
|
|
16042
|
-
* settings object without it can't silently flip the account's E2EE state.
|
|
16043
|
-
* Absent = leave unchanged on write, 'off' on read (see store.ts). The demo
|
|
16044
|
-
* account is plaintext by construction and refuses any non-'off' value. */
|
|
16045
|
-
e2eeMode: external_exports.enum(["off", "on"]).optional(),
|
|
16046
13593
|
/** Rung-2 broker tuning (#381). Optional and NOT defaulted, same stale-client
|
|
16047
13594
|
* clobber guard as voiceMode: absent = leave unchanged on write. */
|
|
16048
13595
|
broker: BrokerTuningSchema2.optional()
|
|
@@ -16232,6 +13779,8 @@ var QueueItemSchema2 = external_exports.object({
|
|
|
16232
13779
|
blocked: external_exports.boolean().default(false),
|
|
16233
13780
|
/** Every decision need on it, open or settled — the page decides which to show. */
|
|
16234
13781
|
questions: external_exports.array(QueueQuestionSchema2).default([]),
|
|
13782
|
+
/** The repository or project identifier this Goal belongs to (#2280), null if untracked. */
|
|
13783
|
+
repo: external_exports.string().nullable().optional(),
|
|
16235
13784
|
createdAt: external_exports.string(),
|
|
16236
13785
|
updatedAt: external_exports.string().nullable().default(null)
|
|
16237
13786
|
});
|
|
@@ -16343,54 +13892,12 @@ var DeliveryConfigSchema2 = external_exports.object({
|
|
|
16343
13892
|
* carries credentials; only a `poll` registration can come back with null here. */
|
|
16344
13893
|
realtime: external_exports.object({ url: external_exports.string(), anonKey: external_exports.string() }).nullable()
|
|
16345
13894
|
});
|
|
16346
|
-
var EnvelopeRecipientSchema2 = external_exports.object({
|
|
16347
|
-
keyId: external_exports.string(),
|
|
16348
|
-
epk: external_exports.string(),
|
|
16349
|
-
wnonce: external_exports.string(),
|
|
16350
|
-
wrap: external_exports.string()
|
|
16351
|
-
});
|
|
16352
|
-
var EnvelopeHeaderSchema2 = external_exports.object({
|
|
16353
|
-
field: external_exports.enum(["context", "options", "visuals", "answer"]),
|
|
16354
|
-
kind: external_exports.string(),
|
|
16355
|
-
senderRole: external_exports.enum(["agent", "user"]),
|
|
16356
|
-
recipientKeyIds: external_exports.array(external_exports.string()),
|
|
16357
|
-
seq: external_exports.number().int().nonnegative()
|
|
16358
|
-
});
|
|
16359
|
-
var EnvelopeSchema2 = external_exports.object({
|
|
16360
|
-
v: external_exports.literal(1),
|
|
16361
|
-
alg: external_exports.literal("x25519-xsalsa20poly1305"),
|
|
16362
|
-
msgId: external_exports.string(),
|
|
16363
|
-
hdr: EnvelopeHeaderSchema2,
|
|
16364
|
-
recipients: external_exports.array(EnvelopeRecipientSchema2).min(1),
|
|
16365
|
-
nonce: external_exports.string(),
|
|
16366
|
-
ct: external_exports.string()
|
|
16367
|
-
});
|
|
16368
|
-
var SealedAnswerSchema2 = external_exports.object({
|
|
16369
|
-
ignored: external_exports.boolean(),
|
|
16370
|
-
envelope: EnvelopeSchema2
|
|
16371
|
-
});
|
|
16372
|
-
var DeviceCredentialSchema2 = external_exports.object({
|
|
16373
|
-
deviceId: external_exports.string(),
|
|
16374
|
-
kind: external_exports.enum(["phone", "web", "agent"]),
|
|
16375
|
-
x25519Pub: external_exports.string(),
|
|
16376
|
-
ed25519Pub: external_exports.string(),
|
|
16377
|
-
sig: external_exports.string()
|
|
16378
|
-
});
|
|
16379
|
-
var DeviceRosterSchema2 = external_exports.object({
|
|
16380
|
-
uikPub: external_exports.string(),
|
|
16381
|
-
devices: external_exports.array(DeviceCredentialSchema2)
|
|
16382
|
-
});
|
|
16383
13895
|
var WakeNudgeSchema2 = external_exports.object({
|
|
16384
13896
|
kind: external_exports.enum(["reply", "request", "callback"]),
|
|
16385
13897
|
notificationId: external_exports.string().optional(),
|
|
16386
13898
|
parentId: external_exports.string()
|
|
16387
13899
|
});
|
|
16388
13900
|
var PairingStatusSchema2 = external_exports.enum(["pending", "approved", "denied", "expired"]);
|
|
16389
|
-
var PairingRevealSchema2 = external_exports.object({
|
|
16390
|
-
x25519: external_exports.string(),
|
|
16391
|
-
ed25519: external_exports.string(),
|
|
16392
|
-
nonce: external_exports.string()
|
|
16393
|
-
});
|
|
16394
13901
|
var DeviceCodeSchema2 = external_exports.object({
|
|
16395
13902
|
device_code: external_exports.string(),
|
|
16396
13903
|
user_code: external_exports.string(),
|
|
@@ -16410,19 +13917,7 @@ var DeviceInfoSchema2 = external_exports.object({
|
|
|
16410
13917
|
* (seen live: PAIGY-5T, 2026-07-21). Remove once a newer binary is the floor. */
|
|
16411
13918
|
agent: external_exports.string().optional(),
|
|
16412
13919
|
device: external_exports.string().nullable(),
|
|
16413
|
-
status: PairingStatusSchema2
|
|
16414
|
-
proto: external_exports.string().nullable().optional(),
|
|
16415
|
-
agent_commitment: external_exports.string().nullable().optional(),
|
|
16416
|
-
// Ca
|
|
16417
|
-
agent_reveal: PairingRevealSchema2.nullable().optional(),
|
|
16418
|
-
// present once the agent reveals
|
|
16419
|
-
agent_credential: DeviceCredentialSchema2.nullable().optional(),
|
|
16420
|
-
// the phone's UIK-signed cred over the agent's keys — the agent fetches it here to finalizeE2ee
|
|
16421
|
-
// The phone's reveal + identity key, exposed here so a GATED agent (e2ee_mode='on', token
|
|
16422
|
-
// withheld until e2ee=true) can compute the SAS WITHOUT a token. Public keys — same safety
|
|
16423
|
-
// class as agent_reveal above. Present only once the phone reveals; null otherwise.
|
|
16424
|
-
phone_reveal: PairingRevealSchema2.nullable().optional(),
|
|
16425
|
-
uik_pub: external_exports.string().nullable().optional()
|
|
13920
|
+
status: PairingStatusSchema2
|
|
16426
13921
|
});
|
|
16427
13922
|
var DeviceTokenSchema2 = external_exports.object({
|
|
16428
13923
|
access_token: external_exports.string(),
|
|
@@ -16441,8 +13936,6 @@ var DeviceTokenSchema2 = external_exports.object({
|
|
|
16441
13936
|
* landed in the FIRST granted workspace and the agent rediscovered its own repo from
|
|
16442
13937
|
* the thread each time (host.ts, live catch 2026-08-06 — prompt-papered until now). */
|
|
16443
13938
|
workspace: external_exports.string().nullable().optional(),
|
|
16444
|
-
phone_reveal: PairingRevealSchema2.nullable().optional(),
|
|
16445
|
-
// present once the phone reveals
|
|
16446
13939
|
uik_pub: external_exports.string().nullable().optional()
|
|
16447
13940
|
});
|
|
16448
13941
|
var SupportRequestSchema2 = external_exports.object({
|
|
@@ -16464,13 +13957,6 @@ var NotificationFeedbackKindSchema2 = external_exports.enum([
|
|
|
16464
13957
|
"other"
|
|
16465
13958
|
// anything else — the note carries it.
|
|
16466
13959
|
]);
|
|
16467
|
-
var FeedbackResolutionSchema2 = external_exports.enum(["broker_fixed", "sent_to_agent"]);
|
|
16468
|
-
var FeedbackOutcomeSchema2 = external_exports.object({
|
|
16469
|
-
resolution: FeedbackResolutionSchema2,
|
|
16470
|
-
transform: TransformSchema2,
|
|
16471
|
-
message: external_exports.string(),
|
|
16472
|
-
childIds: external_exports.array(external_exports.string()).optional()
|
|
16473
|
-
});
|
|
16474
13960
|
|
|
16475
13961
|
// src/paigy/activity.ts
|
|
16476
13962
|
function shortenPaths(s) {
|
|
@@ -16495,7 +13981,7 @@ function sameTail(a, b) {
|
|
|
16495
13981
|
// src/harness/session.ts
|
|
16496
13982
|
import { spawn } from "child_process";
|
|
16497
13983
|
import { existsSync as existsSync4 } from "fs";
|
|
16498
|
-
import { homedir as
|
|
13984
|
+
import { homedir as homedir6 } from "os";
|
|
16499
13985
|
import { resolve as resolve2, delimiter as delimiter2 } from "path";
|
|
16500
13986
|
|
|
16501
13987
|
// src/harness/acp.ts
|
|
@@ -16732,7 +14218,7 @@ function splitLines(buffer, chunk) {
|
|
|
16732
14218
|
return { lines: parts.filter((l) => l.trim()), rest };
|
|
16733
14219
|
}
|
|
16734
14220
|
function startSession(opts) {
|
|
16735
|
-
const cwd = resolve2(opts.cwd.replace(/^~(?=$|\/)/,
|
|
14221
|
+
const cwd = resolve2(opts.cwd.replace(/^~(?=$|\/)/, homedir6()));
|
|
16736
14222
|
if (!existsSync4(cwd)) {
|
|
16737
14223
|
queueMicrotask(() => opts.onEvent({ kind: "error", message: `workspace does not exist: ${cwd}` }));
|
|
16738
14224
|
}
|
|
@@ -16793,14 +14279,32 @@ function startSession(opts) {
|
|
|
16793
14279
|
}
|
|
16794
14280
|
|
|
16795
14281
|
// src/paigy/conversation.ts
|
|
14282
|
+
import { randomUUID as randomUUID4 } from "crypto";
|
|
14283
|
+
var HARNESS_INSTRUCTION = "You are running as an unattended background harness agent connected to your user through Paigy. The user is NOT at the terminal and cannot see text printed here. To ask questions, request approvals, or make decisions, use Paigy tools or end your turn with a clear question for the bridge to relay. When complete, provide a concise summary of what was accomplished.";
|
|
16796
14284
|
function endsWithQuestion(text) {
|
|
16797
14285
|
if (!text) return false;
|
|
16798
|
-
const
|
|
16799
|
-
if (!
|
|
16800
|
-
if (
|
|
14286
|
+
const trimmed = text.trim();
|
|
14287
|
+
if (!trimmed) return false;
|
|
14288
|
+
if (trimmed.endsWith("?")) return true;
|
|
14289
|
+
const lines2 = trimmed.split("\n").map((l) => l.trim()).filter(Boolean);
|
|
14290
|
+
if (lines2.length === 0) return false;
|
|
14291
|
+
let lastNonListIdx = lines2.length - 1;
|
|
14292
|
+
while (lastNonListIdx >= 0) {
|
|
14293
|
+
const line = lines2[lastNonListIdx];
|
|
14294
|
+
if (line && /^[-*•\d.)]\s+/.test(line)) {
|
|
14295
|
+
lastNonListIdx--;
|
|
14296
|
+
} else {
|
|
14297
|
+
break;
|
|
14298
|
+
}
|
|
14299
|
+
}
|
|
14300
|
+
const promptLine = lastNonListIdx >= 0 ? lines2[lastNonListIdx] : lines2[lines2.length - 1];
|
|
14301
|
+
if (promptLine?.endsWith("?")) return true;
|
|
14302
|
+
const tail = lines2.slice(-3).join(" ").toLowerCase();
|
|
16801
14303
|
return [
|
|
16802
14304
|
/\b(let me know|which (one|would|do you)|do you want|should i|shall i)\b/,
|
|
16803
|
-
/\b(want me to|prefer|your call|up to you|confirm whether)\b
|
|
14305
|
+
/\b(want me to|prefer|your call|up to you|confirm whether)\b/,
|
|
14306
|
+
/\b(how would you like|how should we|what would you like|what should we)\b/,
|
|
14307
|
+
/\b(please choose|choose one|select one|how do you want)\b/
|
|
16804
14308
|
].some((re) => re.test(tail));
|
|
16805
14309
|
}
|
|
16806
14310
|
var POLL_MS = 5e3;
|
|
@@ -16818,17 +14322,34 @@ function unheard(brief, state) {
|
|
|
16818
14322
|
}
|
|
16819
14323
|
return words2;
|
|
16820
14324
|
}
|
|
16821
|
-
async function step(session, state, rail) {
|
|
14325
|
+
async function step(session, state, rail, opts) {
|
|
16822
14326
|
if (!state.goal) {
|
|
16823
14327
|
if (!state.resting) return;
|
|
16824
|
-
|
|
16825
|
-
if (!brief2.goalId || brief2.revision === void 0)
|
|
14328
|
+
let brief2 = await rail.claim();
|
|
14329
|
+
if (!brief2.goalId || brief2.revision === void 0) {
|
|
14330
|
+
if (opts?.initialPrompt?.trim()) {
|
|
14331
|
+
const prompt = opts.initialPrompt.trim();
|
|
14332
|
+
opts.initialPrompt = void 0;
|
|
14333
|
+
const admitted = await rail.create({ outcome: prompt, idempotencyKey: randomUUID4() });
|
|
14334
|
+
brief2 = await rail.claim();
|
|
14335
|
+
if (!brief2.goalId || brief2.revision === void 0) {
|
|
14336
|
+
state.goal = { id: admitted.goalId, revision: admitted.revision };
|
|
14337
|
+
if (checkCallOnDone(prompt)) state.callOnDone = true;
|
|
14338
|
+
send2(session, state, [HARNESS_INSTRUCTION, prompt].join("\n\n"));
|
|
14339
|
+
return;
|
|
14340
|
+
}
|
|
14341
|
+
} else {
|
|
14342
|
+
return;
|
|
14343
|
+
}
|
|
14344
|
+
}
|
|
16826
14345
|
unheard(brief2, state);
|
|
16827
14346
|
if (ended(brief2.state)) await rail.update(brief2.goalId, { revision: brief2.revision, changes: { reviewed: true }, reason: "Typed into the session." });
|
|
16828
14347
|
else state.goal = { id: brief2.goalId, revision: brief2.revision };
|
|
16829
14348
|
const outcome = brief2.outcome?.trim() ?? "";
|
|
16830
14349
|
const said = (brief2.entries ?? []).map((e) => entryWords(e).trim()).filter((w) => w && w.toLowerCase() !== outcome.toLowerCase());
|
|
16831
|
-
|
|
14350
|
+
const fullText = [outcome, ...said].filter(Boolean).join("\n\n");
|
|
14351
|
+
if (checkCallOnDone(fullText)) state.callOnDone = true;
|
|
14352
|
+
send2(session, state, [HARNESS_INSTRUCTION, fullText].filter(Boolean).join("\n\n"));
|
|
16832
14353
|
return;
|
|
16833
14354
|
}
|
|
16834
14355
|
const brief = await rail.read(state.goal.id);
|
|
@@ -16847,16 +14368,21 @@ async function step(session, state, rail) {
|
|
|
16847
14368
|
}
|
|
16848
14369
|
if (state.asks?.size || !state.resting) return;
|
|
16849
14370
|
const words2 = unheard(brief, state);
|
|
16850
|
-
if (words2.length)
|
|
14371
|
+
if (words2.length) {
|
|
14372
|
+
const text = words2.join("\n\n");
|
|
14373
|
+
if (checkCallOnDone(text)) state.callOnDone = true;
|
|
14374
|
+
send2(session, state, text);
|
|
14375
|
+
}
|
|
16851
14376
|
}
|
|
16852
14377
|
function send2(session, state, text) {
|
|
16853
14378
|
state.resting = false;
|
|
16854
14379
|
session.send(text);
|
|
16855
14380
|
}
|
|
16856
14381
|
async function pump(session, state, rail, opts) {
|
|
14382
|
+
const promptRef = opts.initialPrompt ? { initialPrompt: opts.initialPrompt } : void 0;
|
|
16857
14383
|
for (; ; ) {
|
|
16858
14384
|
try {
|
|
16859
|
-
await step(session, state, rail);
|
|
14385
|
+
await step(session, state, rail, promptRef);
|
|
16860
14386
|
} catch {
|
|
16861
14387
|
}
|
|
16862
14388
|
if (!await opts.onIdle()) return;
|
|
@@ -16864,25 +14390,6 @@ async function pump(session, state, rail, opts) {
|
|
|
16864
14390
|
}
|
|
16865
14391
|
}
|
|
16866
14392
|
|
|
16867
|
-
// src/paigy/level.ts
|
|
16868
|
-
var DESTRUCTIVE = [
|
|
16869
|
-
/\brm\s+-[a-z]*[rf]/,
|
|
16870
|
-
// rm -rf, rm -f
|
|
16871
|
-
/\bgit\s+push\b.*(--force|-f\b)/,
|
|
16872
|
-
/\bgit\s+reset\s+--hard/,
|
|
16873
|
-
/\bgit\s+clean\s+-[a-z]*f/,
|
|
16874
|
-
/\bdrop\s+(table|database|schema)\b/i,
|
|
16875
|
-
/\btruncate\s+table\b/i,
|
|
16876
|
-
/\bdd\s+if=/,
|
|
16877
|
-
/\bmkfs\b/,
|
|
16878
|
-
/\b(shutdown|reboot)\b/,
|
|
16879
|
-
/:\s*>\s*\/dev\/sd/
|
|
16880
|
-
// writing over a raw device
|
|
16881
|
-
];
|
|
16882
|
-
function isDestructive(summary) {
|
|
16883
|
-
return DESTRUCTIVE.some((re) => re.test(summary));
|
|
16884
|
-
}
|
|
16885
|
-
|
|
16886
14393
|
// src/paigy/bridge.ts
|
|
16887
14394
|
function railFor(opts) {
|
|
16888
14395
|
return {
|
|
@@ -16890,7 +14397,8 @@ function railFor(opts) {
|
|
|
16890
14397
|
read: (goalId) => getGoal(goalId, opts),
|
|
16891
14398
|
update: (goalId, input) => updateGoal(goalId, input, opts),
|
|
16892
14399
|
// One read and back: the pump owns the waiting, so a Call must not hold a window here.
|
|
16893
|
-
contact: (input) => contact(input, { ...opts, waits: false })
|
|
14400
|
+
contact: (input) => contact(input, { ...opts, waits: false }),
|
|
14401
|
+
create: (input) => createGoal(input, opts)
|
|
16894
14402
|
};
|
|
16895
14403
|
}
|
|
16896
14404
|
function cancelAsks(state) {
|
|
@@ -16927,11 +14435,9 @@ async function ask(state, rail, input) {
|
|
|
16927
14435
|
if (!state.goal) return null;
|
|
16928
14436
|
try {
|
|
16929
14437
|
const sent = await rail.contact({
|
|
16930
|
-
|
|
16931
|
-
ask: input.ask,
|
|
14438
|
+
asks: [{ ask: input.ask, parentId: state.goal.id, ...input.options ? { options: input.options } : {} }],
|
|
16932
14439
|
waiting: "hard",
|
|
16933
|
-
channel: input.call ? "call" : "notification"
|
|
16934
|
-
...input.options ? { options: input.options } : {}
|
|
14440
|
+
channel: input.call ? "call" : "notification"
|
|
16935
14441
|
});
|
|
16936
14442
|
const entryId = sent.requestEntryIds[0];
|
|
16937
14443
|
if (!entryId) return null;
|
|
@@ -16941,37 +14447,87 @@ async function ask(state, rail, input) {
|
|
|
16941
14447
|
return null;
|
|
16942
14448
|
}
|
|
16943
14449
|
}
|
|
14450
|
+
function checkCallOnDone(text) {
|
|
14451
|
+
if (!text) return false;
|
|
14452
|
+
return /\b(call|ring|phone)\b.*\b(done|finish(ed)?|complete(d)?)\b/i.test(text) || /\b(when|if|once)\b.*\b(done|finish(ed)?|complete(d)?)\b.*\b(call|ring|phone)\b/i.test(text) || /\bcall\s+(me|us)\b/i.test(text);
|
|
14453
|
+
}
|
|
14454
|
+
function parseQuestionOptions(text) {
|
|
14455
|
+
if (!text) return { question: "" };
|
|
14456
|
+
const trimmed = text.trim();
|
|
14457
|
+
const lines2 = trimmed.split("\n").map((l) => l.trim()).filter(Boolean);
|
|
14458
|
+
const optionLines = [];
|
|
14459
|
+
const questionLines = [];
|
|
14460
|
+
for (const line of lines2) {
|
|
14461
|
+
const bulletMatch = line.match(/^[-*•]\s+(.*)$/) ?? line.match(/^\d+[.)]\s+(.*)$/);
|
|
14462
|
+
if (bulletMatch) {
|
|
14463
|
+
optionLines.push(bulletMatch[1].trim());
|
|
14464
|
+
} else {
|
|
14465
|
+
questionLines.push(line);
|
|
14466
|
+
}
|
|
14467
|
+
}
|
|
14468
|
+
if (optionLines.length >= 2 && optionLines.length <= 6) {
|
|
14469
|
+
return {
|
|
14470
|
+
question: questionLines.join("\n\n").trim() || trimmed,
|
|
14471
|
+
options: optionLines.map((raw) => {
|
|
14472
|
+
const colonSplit = raw.match(/^([^:—–-]+)\s*[:—–-]\s*(.+)$/);
|
|
14473
|
+
const parenSplit = raw.match(/^([^(]+)\s*\(([^)]+)\)$/);
|
|
14474
|
+
if (colonSplit && colonSplit[1] && colonSplit[2]) {
|
|
14475
|
+
return { label: colonSplit[1].trim().slice(0, 100), hint: colonSplit[2].trim().slice(0, 250) };
|
|
14476
|
+
}
|
|
14477
|
+
if (parenSplit && parenSplit[1] && parenSplit[2]) {
|
|
14478
|
+
return { label: parenSplit[1].trim().slice(0, 100), hint: parenSplit[2].trim().slice(0, 250) };
|
|
14479
|
+
}
|
|
14480
|
+
return { label: raw.slice(0, 1e3) };
|
|
14481
|
+
})
|
|
14482
|
+
};
|
|
14483
|
+
}
|
|
14484
|
+
return { question: trimmed };
|
|
14485
|
+
}
|
|
16944
14486
|
async function askPermission(event, state, rail) {
|
|
16945
14487
|
return decisionFrom(await ask(state, rail, {
|
|
16946
14488
|
ask: [`The agent is blocked waiting to run: ${event.summary}`, ...event.reason ? [event.reason] : []].join("\n\n"),
|
|
16947
|
-
options: [
|
|
16948
|
-
|
|
14489
|
+
options: [
|
|
14490
|
+
{ label: ALLOW, hint: "Permits the agent to run this command" },
|
|
14491
|
+
{ label: "Deny", hint: "Blocks execution of this command" }
|
|
14492
|
+
],
|
|
14493
|
+
call: true
|
|
16949
14494
|
}));
|
|
16950
14495
|
}
|
|
16951
|
-
async function askQuestion(question, state, rail) {
|
|
16952
|
-
return wordsOf(await ask(state, rail, {
|
|
14496
|
+
async function askQuestion(question, state, rail, opts) {
|
|
14497
|
+
return wordsOf(await ask(state, rail, {
|
|
14498
|
+
ask: question,
|
|
14499
|
+
call: opts?.call ?? true,
|
|
14500
|
+
options: opts?.options
|
|
14501
|
+
}));
|
|
16953
14502
|
}
|
|
16954
|
-
async function finish(result, state, rail) {
|
|
14503
|
+
async function finish(result, state, rail, opts) {
|
|
16955
14504
|
const goal = state.goal;
|
|
16956
14505
|
if (!goal) return;
|
|
16957
14506
|
state.goal = void 0;
|
|
16958
14507
|
const report = result?.trim() || "Done.";
|
|
14508
|
+
const channel = opts?.call || state.callOnDone ? "call" : "notification";
|
|
16959
14509
|
try {
|
|
16960
|
-
await rail.contact({
|
|
14510
|
+
await rail.contact({ asks: [{ ask: report, parentId: goal.id }], waiting: "none", channel });
|
|
16961
14511
|
const { revision } = await rail.read(goal.id);
|
|
16962
14512
|
await rail.update(goal.id, { revision: revision ?? goal.revision, changes: { state: "done", progress: report.slice(0, 1e4) }, reason: "The agent finished its turn without asking anything." });
|
|
16963
|
-
} catch {
|
|
14513
|
+
} catch (error) {
|
|
14514
|
+
opts?.log?.(`\u26A0 finish contact failed: ${error.message}`);
|
|
16964
14515
|
}
|
|
16965
14516
|
}
|
|
16966
|
-
async function afterTurn(event, state, rail) {
|
|
14517
|
+
async function afterTurn(event, state, rail, opts) {
|
|
16967
14518
|
if (!event.failed && !endsWithQuestion(event.result)) {
|
|
16968
|
-
await finish(event.result, state, rail);
|
|
14519
|
+
await finish(event.result, state, rail, opts);
|
|
16969
14520
|
state.resting = true;
|
|
16970
14521
|
return null;
|
|
16971
14522
|
}
|
|
16972
|
-
const
|
|
14523
|
+
const rawText = event.failed ? `The agent stopped without finishing.
|
|
16973
14524
|
|
|
16974
|
-
${event.result?.trim() || "No result reported."}` : event.result ?? ""
|
|
14525
|
+
${event.result?.trim() || "No result reported."}` : event.result ?? "";
|
|
14526
|
+
const parsed = parseQuestionOptions(rawText);
|
|
14527
|
+
const reply = await askQuestion(parsed.question, state, rail, {
|
|
14528
|
+
call: true,
|
|
14529
|
+
options: parsed.options
|
|
14530
|
+
});
|
|
16975
14531
|
if (!reply) state.resting = true;
|
|
16976
14532
|
return reply;
|
|
16977
14533
|
}
|
|
@@ -17018,7 +14574,7 @@ function runHarness(opts) {
|
|
|
17018
14574
|
return;
|
|
17019
14575
|
}
|
|
17020
14576
|
}
|
|
17021
|
-
const reply = await afterTurn(event, state, rail);
|
|
14577
|
+
const reply = await afterTurn(event, state, rail, { log: opts.log });
|
|
17022
14578
|
if (reply && session && running) {
|
|
17023
14579
|
opts.log(`you: ${reply.split("\n")[0] ?? ""}`);
|
|
17024
14580
|
session.send(reply);
|
|
@@ -17035,11 +14591,7 @@ function runHarness(opts) {
|
|
|
17035
14591
|
...opts.onExit ? { onExit: opts.onExit } : {},
|
|
17036
14592
|
onEvent: (event) => void handle(event).catch((err) => opts.log(`\u26A0 ${err.message}`))
|
|
17037
14593
|
});
|
|
17038
|
-
|
|
17039
|
-
state.resting = false;
|
|
17040
|
-
session.send(opts.prompt);
|
|
17041
|
-
}
|
|
17042
|
-
void pump(session, state, rail, { onIdle: () => running }).catch(
|
|
14594
|
+
void pump(session, state, rail, { onIdle: () => running, initialPrompt: opts.prompt }).catch(
|
|
17043
14595
|
(e) => opts.log(`\u26A0 conversation loop stopped: ${e.message}`)
|
|
17044
14596
|
);
|
|
17045
14597
|
opts.log(`\u25B6 started ${opts.harness} in ${opts.cwd} (${opts.mode} mode)`);
|
|
@@ -17063,7 +14615,7 @@ function runHarness(opts) {
|
|
|
17063
14615
|
// src/update.ts
|
|
17064
14616
|
import { execFile } from "child_process";
|
|
17065
14617
|
import { createRequire } from "module";
|
|
17066
|
-
import { dirname as dirname3, join as
|
|
14618
|
+
import { dirname as dirname3, join as join6 } from "path";
|
|
17067
14619
|
import { promisify } from "util";
|
|
17068
14620
|
var SERVICE_LABEL = "ai.paigy.harness";
|
|
17069
14621
|
var VERSION = createRequire(import.meta.url)("../package.json").version;
|
|
@@ -17090,7 +14642,7 @@ async function latestVersion() {
|
|
|
17090
14642
|
}
|
|
17091
14643
|
async function install(version) {
|
|
17092
14644
|
const bin = dirname3(process.execPath);
|
|
17093
|
-
await promisify(execFile)(
|
|
14645
|
+
await promisify(execFile)(join6(bin, "npm"), ["install", "-g", `@paigy/harness@${version}`], {
|
|
17094
14646
|
env: { ...process.env, PATH: `${bin}:${process.env.PATH ?? ""}`, npm_config_update_notifier: "false" },
|
|
17095
14647
|
timeout: 5 * 6e4
|
|
17096
14648
|
});
|
|
@@ -17141,10 +14693,10 @@ function selfUpdater(deps) {
|
|
|
17141
14693
|
}
|
|
17142
14694
|
|
|
17143
14695
|
// src/host.ts
|
|
17144
|
-
var HOST_FILE =
|
|
14696
|
+
var HOST_FILE = join7(homedir7(), ".paigy", "host.json");
|
|
17145
14697
|
function readHostState() {
|
|
17146
14698
|
try {
|
|
17147
|
-
const s = JSON.parse(
|
|
14699
|
+
const s = JSON.parse(readFileSync4(HOST_FILE, "utf8"));
|
|
17148
14700
|
if (Date.now() - s.at > 2e4) return null;
|
|
17149
14701
|
try {
|
|
17150
14702
|
process.kill(s.pid, 0);
|
|
@@ -17223,6 +14775,7 @@ function startHost(opts) {
|
|
|
17223
14775
|
mode: "bypass",
|
|
17224
14776
|
prompt: "",
|
|
17225
14777
|
token: spec.token,
|
|
14778
|
+
resume: spec.sessionId,
|
|
17226
14779
|
onExit: () => {
|
|
17227
14780
|
runs.delete(key);
|
|
17228
14781
|
opts.log(`\u2716 ${label} ended`);
|
|
@@ -17597,7 +15150,7 @@ function staleWhy(note) {
|
|
|
17597
15150
|
|
|
17598
15151
|
// src/triage/judge.ts
|
|
17599
15152
|
import { spawnSync as spawnSync2 } from "child_process";
|
|
17600
|
-
import { homedir as
|
|
15153
|
+
import { homedir as homedir8 } from "os";
|
|
17601
15154
|
import { delimiter as delimiter3 } from "path";
|
|
17602
15155
|
var PRIVACY = {
|
|
17603
15156
|
ollama: "never leaves this machine",
|
|
@@ -17701,7 +15254,7 @@ async function judgeFor(asked, deps = {}) {
|
|
|
17701
15254
|
const out = spawnSync2(bin, runner.argv(null), {
|
|
17702
15255
|
input: prompt,
|
|
17703
15256
|
encoding: "utf8",
|
|
17704
|
-
cwd:
|
|
15257
|
+
cwd: homedir8(),
|
|
17705
15258
|
timeout: RUN_TIMEOUT_MS,
|
|
17706
15259
|
maxBuffer: 32 * 1024 * 1024,
|
|
17707
15260
|
env: { ...process.env, PATH: [process.env["PATH"], ...probeDirs()].filter(Boolean).join(delimiter3) }
|
|
@@ -17999,7 +15552,7 @@ var win = null;
|
|
|
17999
15552
|
function log(message) {
|
|
18000
15553
|
win?.webContents.send("paigy:log", message);
|
|
18001
15554
|
}
|
|
18002
|
-
var ICON =
|
|
15555
|
+
var ICON = join8(here, "..", "assets", "icon.png");
|
|
18003
15556
|
function createWindow() {
|
|
18004
15557
|
win = new BrowserWindow({
|
|
18005
15558
|
// Sized for the working log, which is now the window's centerpiece; the layout is a
|
|
@@ -18011,9 +15564,9 @@ function createWindow() {
|
|
|
18011
15564
|
minHeight: 520,
|
|
18012
15565
|
icon: ICON,
|
|
18013
15566
|
// Windows/Linux window icon; macOS uses the dock icon below
|
|
18014
|
-
webPreferences: { preload:
|
|
15567
|
+
webPreferences: { preload: join8(here, "preload.cjs"), contextIsolation: true, nodeIntegration: false }
|
|
18015
15568
|
});
|
|
18016
|
-
void win.loadFile(
|
|
15569
|
+
void win.loadFile(join8(here, "..", "renderer", "index.html"));
|
|
18017
15570
|
}
|
|
18018
15571
|
var host = null;
|
|
18019
15572
|
app.whenReady().then(() => {
|
|
@@ -18082,7 +15635,7 @@ ipcMain.handle("paigy:agent", async (_e, name) => {
|
|
|
18082
15635
|
});
|
|
18083
15636
|
ipcMain.handle("paigy:agent-log", (_e, name) => {
|
|
18084
15637
|
try {
|
|
18085
|
-
const all =
|
|
15638
|
+
const all = readFileSync5(join8(homedir9(), ".paigy", "host.log"), "utf8").split("\n");
|
|
18086
15639
|
const mine = all.filter((l) => l.includes(`[${name}]`) || /[▶✖◉⚠]/.test(l) && l.includes(name));
|
|
18087
15640
|
return mine.slice(-500).join("\n");
|
|
18088
15641
|
} catch {
|