@covia/covia-sdk 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +478 -49
- package/dist/index.d.mts +760 -87
- package/dist/index.d.ts +760 -87
- package/dist/index.js +1958 -229
- package/dist/index.mjs +1930 -230
- package/package.json +5 -1
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { Resolver } from 'did-resolver';
|
|
2
2
|
import { getResolver } from 'web-did-resolver';
|
|
3
3
|
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
7
|
+
|
|
4
8
|
// src/types.ts
|
|
5
9
|
var RunStatus = /* @__PURE__ */ ((RunStatus2) => {
|
|
6
10
|
RunStatus2["COMPLETE"] = "COMPLETE";
|
|
@@ -15,6 +19,14 @@ var RunStatus = /* @__PURE__ */ ((RunStatus2) => {
|
|
|
15
19
|
RunStatus2["PAUSED"] = "PAUSED";
|
|
16
20
|
return RunStatus2;
|
|
17
21
|
})(RunStatus || {});
|
|
22
|
+
var JobStatus = RunStatus;
|
|
23
|
+
var AgentStatus = /* @__PURE__ */ ((AgentStatus2) => {
|
|
24
|
+
AgentStatus2["SLEEPING"] = "SLEEPING";
|
|
25
|
+
AgentStatus2["RUNNING"] = "RUNNING";
|
|
26
|
+
AgentStatus2["SUSPENDED"] = "SUSPENDED";
|
|
27
|
+
AgentStatus2["TERMINATED"] = "TERMINATED";
|
|
28
|
+
return AgentStatus2;
|
|
29
|
+
})(AgentStatus || {});
|
|
18
30
|
var CoviaError = class extends Error {
|
|
19
31
|
constructor(message, code = null) {
|
|
20
32
|
super(message);
|
|
@@ -23,8 +35,1100 @@ var CoviaError = class extends Error {
|
|
|
23
35
|
this.message = message;
|
|
24
36
|
}
|
|
25
37
|
};
|
|
38
|
+
var GridError = class extends CoviaError {
|
|
39
|
+
constructor(statusCode, message, responseBody = null) {
|
|
40
|
+
super(`HTTP ${statusCode}: ${message}`, statusCode);
|
|
41
|
+
this.name = "GridError";
|
|
42
|
+
this.statusCode = statusCode;
|
|
43
|
+
this.responseBody = responseBody;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
var CoviaConnectionError = class extends CoviaError {
|
|
47
|
+
constructor(message) {
|
|
48
|
+
super(message);
|
|
49
|
+
this.name = "CoviaConnectionError";
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
var CoviaTimeoutError = class extends CoviaError {
|
|
53
|
+
constructor(message) {
|
|
54
|
+
super(message);
|
|
55
|
+
this.name = "CoviaTimeoutError";
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
var JobFailedError = class extends CoviaError {
|
|
59
|
+
constructor(jobData) {
|
|
60
|
+
const id = jobData.id ?? "unknown";
|
|
61
|
+
const status = jobData.status ?? "unknown";
|
|
62
|
+
let msg = `Job ${id} ${status}`;
|
|
63
|
+
if (jobData.output?.error) {
|
|
64
|
+
msg += `: ${jobData.output.error}`;
|
|
65
|
+
}
|
|
66
|
+
super(msg);
|
|
67
|
+
this.name = "JobFailedError";
|
|
68
|
+
this.jobData = jobData;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
var NotFoundError = class extends GridError {
|
|
72
|
+
constructor(message) {
|
|
73
|
+
super(404, message);
|
|
74
|
+
this.name = "NotFoundError";
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
var AssetNotFoundError = class extends NotFoundError {
|
|
78
|
+
constructor(assetId) {
|
|
79
|
+
super(`Asset not found: ${assetId}`);
|
|
80
|
+
this.name = "AssetNotFoundError";
|
|
81
|
+
this.assetId = assetId;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
var JobNotFoundError = class extends NotFoundError {
|
|
85
|
+
constructor(jobId) {
|
|
86
|
+
super(`Job not found: ${jobId}`);
|
|
87
|
+
this.name = "JobNotFoundError";
|
|
88
|
+
this.jobId = jobId;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// node_modules/@noble/ed25519/index.js
|
|
93
|
+
var ed25519_CURVE = {
|
|
94
|
+
p: 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffedn,
|
|
95
|
+
n: 0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3edn,
|
|
96
|
+
a: 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffecn,
|
|
97
|
+
d: 0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3n,
|
|
98
|
+
Gx: 0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an,
|
|
99
|
+
Gy: 0x6666666666666666666666666666666666666666666666666666666666666658n
|
|
100
|
+
};
|
|
101
|
+
var { p: P, n: N, Gx, Gy, a: _a, d: _d } = ed25519_CURVE;
|
|
102
|
+
var h = 8n;
|
|
103
|
+
var L = 32;
|
|
104
|
+
var L2 = 64;
|
|
105
|
+
var err = (m = "") => {
|
|
106
|
+
throw new Error(m);
|
|
107
|
+
};
|
|
108
|
+
var isBig = (n) => typeof n === "bigint";
|
|
109
|
+
var isStr = (s) => typeof s === "string";
|
|
110
|
+
var isBytes = (a) => a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
111
|
+
var abytes = (a, l) => !isBytes(a) || typeof l === "number" && l > 0 && a.length !== l ? err("Uint8Array expected") : a;
|
|
112
|
+
var u8n = (len) => new Uint8Array(len);
|
|
113
|
+
var u8fr = (buf) => Uint8Array.from(buf);
|
|
114
|
+
var padh = (n, pad) => n.toString(16).padStart(pad, "0");
|
|
115
|
+
var bytesToHex = (b) => Array.from(abytes(b)).map((e) => padh(e, 2)).join("");
|
|
116
|
+
var C = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
|
|
117
|
+
var _ch = (ch) => {
|
|
118
|
+
if (ch >= C._0 && ch <= C._9)
|
|
119
|
+
return ch - C._0;
|
|
120
|
+
if (ch >= C.A && ch <= C.F)
|
|
121
|
+
return ch - (C.A - 10);
|
|
122
|
+
if (ch >= C.a && ch <= C.f)
|
|
123
|
+
return ch - (C.a - 10);
|
|
124
|
+
return;
|
|
125
|
+
};
|
|
126
|
+
var hexToBytes = (hex) => {
|
|
127
|
+
const e = "hex invalid";
|
|
128
|
+
if (!isStr(hex))
|
|
129
|
+
return err(e);
|
|
130
|
+
const hl = hex.length;
|
|
131
|
+
const al = hl / 2;
|
|
132
|
+
if (hl % 2)
|
|
133
|
+
return err(e);
|
|
134
|
+
const array = u8n(al);
|
|
135
|
+
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
136
|
+
const n1 = _ch(hex.charCodeAt(hi));
|
|
137
|
+
const n2 = _ch(hex.charCodeAt(hi + 1));
|
|
138
|
+
if (n1 === void 0 || n2 === void 0)
|
|
139
|
+
return err(e);
|
|
140
|
+
array[ai] = n1 * 16 + n2;
|
|
141
|
+
}
|
|
142
|
+
return array;
|
|
143
|
+
};
|
|
144
|
+
var toU8 = (a, len) => abytes(isStr(a) ? hexToBytes(a) : u8fr(abytes(a)), len);
|
|
145
|
+
var cr = () => globalThis?.crypto;
|
|
146
|
+
var subtle = () => cr()?.subtle ?? err("crypto.subtle must be defined");
|
|
147
|
+
var concatBytes = (...arrs) => {
|
|
148
|
+
const r = u8n(arrs.reduce((sum, a) => sum + abytes(a).length, 0));
|
|
149
|
+
let pad = 0;
|
|
150
|
+
arrs.forEach((a) => {
|
|
151
|
+
r.set(a, pad);
|
|
152
|
+
pad += a.length;
|
|
153
|
+
});
|
|
154
|
+
return r;
|
|
155
|
+
};
|
|
156
|
+
var randomBytes = (len = L) => {
|
|
157
|
+
const c = cr();
|
|
158
|
+
return c.getRandomValues(u8n(len));
|
|
159
|
+
};
|
|
160
|
+
var big = BigInt;
|
|
161
|
+
var arange = (n, min, max, msg = "bad number: out of range") => isBig(n) && min <= n && n < max ? n : err(msg);
|
|
162
|
+
var M = (a, b = P) => {
|
|
163
|
+
const r = a % b;
|
|
164
|
+
return r >= 0n ? r : b + r;
|
|
165
|
+
};
|
|
166
|
+
var modN = (a) => M(a, N);
|
|
167
|
+
var invert = (num, md) => {
|
|
168
|
+
if (num === 0n || md <= 0n)
|
|
169
|
+
err("no inverse n=" + num + " mod=" + md);
|
|
170
|
+
let a = M(num, md), b = md, x = 0n, u = 1n;
|
|
171
|
+
while (a !== 0n) {
|
|
172
|
+
const q = b / a, r = b % a;
|
|
173
|
+
const m = x - u * q;
|
|
174
|
+
b = a, a = r, x = u, u = m;
|
|
175
|
+
}
|
|
176
|
+
return b === 1n ? M(x, md) : err("no inverse");
|
|
177
|
+
};
|
|
178
|
+
var callHash = (name) => {
|
|
179
|
+
const fn = etc[name];
|
|
180
|
+
if (typeof fn !== "function")
|
|
181
|
+
err("hashes." + name + " not set");
|
|
182
|
+
return fn;
|
|
183
|
+
};
|
|
184
|
+
var apoint = (p) => p instanceof Point ? p : err("Point expected");
|
|
185
|
+
var B256 = 2n ** 256n;
|
|
186
|
+
var _Point = class _Point {
|
|
187
|
+
constructor(ex, ey, ez, et) {
|
|
188
|
+
__publicField(this, "ex");
|
|
189
|
+
__publicField(this, "ey");
|
|
190
|
+
__publicField(this, "ez");
|
|
191
|
+
__publicField(this, "et");
|
|
192
|
+
const max = B256;
|
|
193
|
+
this.ex = arange(ex, 0n, max);
|
|
194
|
+
this.ey = arange(ey, 0n, max);
|
|
195
|
+
this.ez = arange(ez, 1n, max);
|
|
196
|
+
this.et = arange(et, 0n, max);
|
|
197
|
+
Object.freeze(this);
|
|
198
|
+
}
|
|
199
|
+
static fromAffine(p) {
|
|
200
|
+
return new _Point(p.x, p.y, 1n, M(p.x * p.y));
|
|
201
|
+
}
|
|
202
|
+
/** RFC8032 5.1.3: Uint8Array to Point. */
|
|
203
|
+
static fromBytes(hex, zip215 = false) {
|
|
204
|
+
const d = _d;
|
|
205
|
+
const normed = u8fr(abytes(hex, L));
|
|
206
|
+
const lastByte = hex[31];
|
|
207
|
+
normed[31] = lastByte & -129;
|
|
208
|
+
const y = bytesToNumLE(normed);
|
|
209
|
+
const max = zip215 ? B256 : P;
|
|
210
|
+
arange(y, 0n, max);
|
|
211
|
+
const y2 = M(y * y);
|
|
212
|
+
const u = M(y2 - 1n);
|
|
213
|
+
const v = M(d * y2 + 1n);
|
|
214
|
+
let { isValid, value: x } = uvRatio(u, v);
|
|
215
|
+
if (!isValid)
|
|
216
|
+
err("bad point: y not sqrt");
|
|
217
|
+
const isXOdd = (x & 1n) === 1n;
|
|
218
|
+
const isLastByteOdd = (lastByte & 128) !== 0;
|
|
219
|
+
if (!zip215 && x === 0n && isLastByteOdd)
|
|
220
|
+
err("bad point: x==0, isLastByteOdd");
|
|
221
|
+
if (isLastByteOdd !== isXOdd)
|
|
222
|
+
x = M(-x);
|
|
223
|
+
return new _Point(x, y, 1n, M(x * y));
|
|
224
|
+
}
|
|
225
|
+
/** Checks if the point is valid and on-curve. */
|
|
226
|
+
assertValidity() {
|
|
227
|
+
const a = _a;
|
|
228
|
+
const d = _d;
|
|
229
|
+
const p = this;
|
|
230
|
+
if (p.is0())
|
|
231
|
+
throw new Error("bad point: ZERO");
|
|
232
|
+
const { ex: X, ey: Y, ez: Z, et: T } = p;
|
|
233
|
+
const X2 = M(X * X);
|
|
234
|
+
const Y2 = M(Y * Y);
|
|
235
|
+
const Z2 = M(Z * Z);
|
|
236
|
+
const Z4 = M(Z2 * Z2);
|
|
237
|
+
const aX2 = M(X2 * a);
|
|
238
|
+
const left = M(Z2 * M(aX2 + Y2));
|
|
239
|
+
const right = M(Z4 + M(d * M(X2 * Y2)));
|
|
240
|
+
if (left !== right)
|
|
241
|
+
throw new Error("bad point: equation left != right (1)");
|
|
242
|
+
const XY = M(X * Y);
|
|
243
|
+
const ZT = M(Z * T);
|
|
244
|
+
if (XY !== ZT)
|
|
245
|
+
throw new Error("bad point: equation left != right (2)");
|
|
246
|
+
return this;
|
|
247
|
+
}
|
|
248
|
+
/** Equality check: compare points P&Q. */
|
|
249
|
+
equals(other) {
|
|
250
|
+
const { ex: X1, ey: Y1, ez: Z1 } = this;
|
|
251
|
+
const { ex: X2, ey: Y2, ez: Z2 } = apoint(other);
|
|
252
|
+
const X1Z2 = M(X1 * Z2);
|
|
253
|
+
const X2Z1 = M(X2 * Z1);
|
|
254
|
+
const Y1Z2 = M(Y1 * Z2);
|
|
255
|
+
const Y2Z1 = M(Y2 * Z1);
|
|
256
|
+
return X1Z2 === X2Z1 && Y1Z2 === Y2Z1;
|
|
257
|
+
}
|
|
258
|
+
is0() {
|
|
259
|
+
return this.equals(I);
|
|
260
|
+
}
|
|
261
|
+
/** Flip point over y coordinate. */
|
|
262
|
+
negate() {
|
|
263
|
+
return new _Point(M(-this.ex), this.ey, this.ez, M(-this.et));
|
|
264
|
+
}
|
|
265
|
+
/** Point doubling. Complete formula. Cost: `4M + 4S + 1*a + 6add + 1*2`. */
|
|
266
|
+
double() {
|
|
267
|
+
const { ex: X1, ey: Y1, ez: Z1 } = this;
|
|
268
|
+
const a = _a;
|
|
269
|
+
const A = M(X1 * X1);
|
|
270
|
+
const B = M(Y1 * Y1);
|
|
271
|
+
const C2 = M(2n * M(Z1 * Z1));
|
|
272
|
+
const D = M(a * A);
|
|
273
|
+
const x1y1 = X1 + Y1;
|
|
274
|
+
const E = M(M(x1y1 * x1y1) - A - B);
|
|
275
|
+
const G2 = D + B;
|
|
276
|
+
const F = G2 - C2;
|
|
277
|
+
const H = D - B;
|
|
278
|
+
const X3 = M(E * F);
|
|
279
|
+
const Y3 = M(G2 * H);
|
|
280
|
+
const T3 = M(E * H);
|
|
281
|
+
const Z3 = M(F * G2);
|
|
282
|
+
return new _Point(X3, Y3, Z3, T3);
|
|
283
|
+
}
|
|
284
|
+
/** Point addition. Complete formula. Cost: `8M + 1*k + 8add + 1*2`. */
|
|
285
|
+
add(other) {
|
|
286
|
+
const { ex: X1, ey: Y1, ez: Z1, et: T1 } = this;
|
|
287
|
+
const { ex: X2, ey: Y2, ez: Z2, et: T2 } = apoint(other);
|
|
288
|
+
const a = _a;
|
|
289
|
+
const d = _d;
|
|
290
|
+
const A = M(X1 * X2);
|
|
291
|
+
const B = M(Y1 * Y2);
|
|
292
|
+
const C2 = M(T1 * d * T2);
|
|
293
|
+
const D = M(Z1 * Z2);
|
|
294
|
+
const E = M((X1 + Y1) * (X2 + Y2) - A - B);
|
|
295
|
+
const F = M(D - C2);
|
|
296
|
+
const G2 = M(D + C2);
|
|
297
|
+
const H = M(B - a * A);
|
|
298
|
+
const X3 = M(E * F);
|
|
299
|
+
const Y3 = M(G2 * H);
|
|
300
|
+
const T3 = M(E * H);
|
|
301
|
+
const Z3 = M(F * G2);
|
|
302
|
+
return new _Point(X3, Y3, Z3, T3);
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Point-by-scalar multiplication. Scalar must be in range 1 <= n < CURVE.n.
|
|
306
|
+
* Uses {@link wNAF} for base point.
|
|
307
|
+
* Uses fake point to mitigate side-channel leakage.
|
|
308
|
+
* @param n scalar by which point is multiplied
|
|
309
|
+
* @param safe safe mode guards against timing attacks; unsafe mode is faster
|
|
310
|
+
*/
|
|
311
|
+
multiply(n, safe = true) {
|
|
312
|
+
if (!safe && (n === 0n || this.is0()))
|
|
313
|
+
return I;
|
|
314
|
+
arange(n, 1n, N);
|
|
315
|
+
if (n === 1n)
|
|
316
|
+
return this;
|
|
317
|
+
if (this.equals(G))
|
|
318
|
+
return wNAF(n).p;
|
|
319
|
+
let p = I;
|
|
320
|
+
let f = G;
|
|
321
|
+
for (let d = this; n > 0n; d = d.double(), n >>= 1n) {
|
|
322
|
+
if (n & 1n)
|
|
323
|
+
p = p.add(d);
|
|
324
|
+
else if (safe)
|
|
325
|
+
f = f.add(d);
|
|
326
|
+
}
|
|
327
|
+
return p;
|
|
328
|
+
}
|
|
329
|
+
/** Convert point to 2d xy affine point. (X, Y, Z) ∋ (x=X/Z, y=Y/Z) */
|
|
330
|
+
toAffine() {
|
|
331
|
+
const { ex: x, ey: y, ez: z } = this;
|
|
332
|
+
if (this.equals(I))
|
|
333
|
+
return { x: 0n, y: 1n };
|
|
334
|
+
const iz = invert(z, P);
|
|
335
|
+
if (M(z * iz) !== 1n)
|
|
336
|
+
err("invalid inverse");
|
|
337
|
+
return { x: M(x * iz), y: M(y * iz) };
|
|
338
|
+
}
|
|
339
|
+
toBytes() {
|
|
340
|
+
const { x, y } = this.assertValidity().toAffine();
|
|
341
|
+
const b = numTo32bLE(y);
|
|
342
|
+
b[31] |= x & 1n ? 128 : 0;
|
|
343
|
+
return b;
|
|
344
|
+
}
|
|
345
|
+
toHex() {
|
|
346
|
+
return bytesToHex(this.toBytes());
|
|
347
|
+
}
|
|
348
|
+
// encode to hex string
|
|
349
|
+
clearCofactor() {
|
|
350
|
+
return this.multiply(big(h), false);
|
|
351
|
+
}
|
|
352
|
+
isSmallOrder() {
|
|
353
|
+
return this.clearCofactor().is0();
|
|
354
|
+
}
|
|
355
|
+
isTorsionFree() {
|
|
356
|
+
let p = this.multiply(N / 2n, false).double();
|
|
357
|
+
if (N % 2n)
|
|
358
|
+
p = p.add(this);
|
|
359
|
+
return p.is0();
|
|
360
|
+
}
|
|
361
|
+
static fromHex(hex, zip215) {
|
|
362
|
+
return _Point.fromBytes(toU8(hex), zip215);
|
|
363
|
+
}
|
|
364
|
+
get x() {
|
|
365
|
+
return this.toAffine().x;
|
|
366
|
+
}
|
|
367
|
+
get y() {
|
|
368
|
+
return this.toAffine().y;
|
|
369
|
+
}
|
|
370
|
+
toRawBytes() {
|
|
371
|
+
return this.toBytes();
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
__publicField(_Point, "BASE");
|
|
375
|
+
__publicField(_Point, "ZERO");
|
|
376
|
+
var Point = _Point;
|
|
377
|
+
var G = new Point(Gx, Gy, 1n, M(Gx * Gy));
|
|
378
|
+
var I = new Point(0n, 1n, 1n, 0n);
|
|
379
|
+
Point.BASE = G;
|
|
380
|
+
Point.ZERO = I;
|
|
381
|
+
var numTo32bLE = (num) => hexToBytes(padh(arange(num, 0n, B256), L2)).reverse();
|
|
382
|
+
var bytesToNumLE = (b) => big("0x" + bytesToHex(u8fr(abytes(b)).reverse()));
|
|
383
|
+
var pow2 = (x, power) => {
|
|
384
|
+
let r = x;
|
|
385
|
+
while (power-- > 0n) {
|
|
386
|
+
r *= r;
|
|
387
|
+
r %= P;
|
|
388
|
+
}
|
|
389
|
+
return r;
|
|
390
|
+
};
|
|
391
|
+
var pow_2_252_3 = (x) => {
|
|
392
|
+
const x2 = x * x % P;
|
|
393
|
+
const b2 = x2 * x % P;
|
|
394
|
+
const b4 = pow2(b2, 2n) * b2 % P;
|
|
395
|
+
const b5 = pow2(b4, 1n) * x % P;
|
|
396
|
+
const b10 = pow2(b5, 5n) * b5 % P;
|
|
397
|
+
const b20 = pow2(b10, 10n) * b10 % P;
|
|
398
|
+
const b40 = pow2(b20, 20n) * b20 % P;
|
|
399
|
+
const b80 = pow2(b40, 40n) * b40 % P;
|
|
400
|
+
const b160 = pow2(b80, 80n) * b80 % P;
|
|
401
|
+
const b240 = pow2(b160, 80n) * b80 % P;
|
|
402
|
+
const b250 = pow2(b240, 10n) * b10 % P;
|
|
403
|
+
const pow_p_5_8 = pow2(b250, 2n) * x % P;
|
|
404
|
+
return { pow_p_5_8, b2 };
|
|
405
|
+
};
|
|
406
|
+
var RM1 = 0x2b8324804fc1df0b2b4d00993dfbd7a72f431806ad2fe478c4ee1b274a0ea0b0n;
|
|
407
|
+
var uvRatio = (u, v) => {
|
|
408
|
+
const v3 = M(v * v * v);
|
|
409
|
+
const v7 = M(v3 * v3 * v);
|
|
410
|
+
const pow = pow_2_252_3(u * v7).pow_p_5_8;
|
|
411
|
+
let x = M(u * v3 * pow);
|
|
412
|
+
const vx2 = M(v * x * x);
|
|
413
|
+
const root1 = x;
|
|
414
|
+
const root2 = M(x * RM1);
|
|
415
|
+
const useRoot1 = vx2 === u;
|
|
416
|
+
const useRoot2 = vx2 === M(-u);
|
|
417
|
+
const noRoot = vx2 === M(-u * RM1);
|
|
418
|
+
if (useRoot1)
|
|
419
|
+
x = root1;
|
|
420
|
+
if (useRoot2 || noRoot)
|
|
421
|
+
x = root2;
|
|
422
|
+
if ((M(x) & 1n) === 1n)
|
|
423
|
+
x = M(-x);
|
|
424
|
+
return { isValid: useRoot1 || useRoot2, value: x };
|
|
425
|
+
};
|
|
426
|
+
var modL_LE = (hash) => modN(bytesToNumLE(hash));
|
|
427
|
+
var sha512a = (...m) => etc.sha512Async(...m);
|
|
428
|
+
var sha512s = (...m) => callHash("sha512Sync")(...m);
|
|
429
|
+
var hash2extK = (hashed) => {
|
|
430
|
+
const head = hashed.slice(0, L);
|
|
431
|
+
head[0] &= 248;
|
|
432
|
+
head[31] &= 127;
|
|
433
|
+
head[31] |= 64;
|
|
434
|
+
const prefix = hashed.slice(L, L2);
|
|
435
|
+
const scalar = modL_LE(head);
|
|
436
|
+
const point = G.multiply(scalar);
|
|
437
|
+
const pointBytes = point.toBytes();
|
|
438
|
+
return { head, prefix, scalar, point, pointBytes };
|
|
439
|
+
};
|
|
440
|
+
var getExtendedPublicKeyAsync = (priv) => sha512a(toU8(priv, L)).then(hash2extK);
|
|
441
|
+
var getExtendedPublicKey = (priv) => hash2extK(sha512s(toU8(priv, L)));
|
|
442
|
+
var getPublicKey = (priv) => getExtendedPublicKey(priv).pointBytes;
|
|
443
|
+
var hashFinishS = (res) => res.finish(sha512s(res.hashable));
|
|
444
|
+
var _sign = (e, rBytes, msg) => {
|
|
445
|
+
const { pointBytes: P2, scalar: s } = e;
|
|
446
|
+
const r = modL_LE(rBytes);
|
|
447
|
+
const R = G.multiply(r).toBytes();
|
|
448
|
+
const hashable = concatBytes(R, P2, msg);
|
|
449
|
+
const finish = (hashed) => {
|
|
450
|
+
const S = modN(r + modL_LE(hashed) * s);
|
|
451
|
+
return abytes(concatBytes(R, numTo32bLE(S)), L2);
|
|
452
|
+
};
|
|
453
|
+
return { hashable, finish };
|
|
454
|
+
};
|
|
455
|
+
var sign = (msg, privKey) => {
|
|
456
|
+
const m = toU8(msg);
|
|
457
|
+
const e = getExtendedPublicKey(privKey);
|
|
458
|
+
const rBytes = sha512s(e.prefix, m);
|
|
459
|
+
return hashFinishS(_sign(e, rBytes, m));
|
|
460
|
+
};
|
|
461
|
+
var etc = {
|
|
462
|
+
sha512Async: async (...messages) => {
|
|
463
|
+
const s = subtle();
|
|
464
|
+
const m = concatBytes(...messages);
|
|
465
|
+
return u8n(await s.digest("SHA-512", m.buffer));
|
|
466
|
+
},
|
|
467
|
+
sha512Sync: void 0,
|
|
468
|
+
bytesToHex,
|
|
469
|
+
hexToBytes,
|
|
470
|
+
concatBytes,
|
|
471
|
+
mod: M,
|
|
472
|
+
invert,
|
|
473
|
+
randomBytes
|
|
474
|
+
};
|
|
475
|
+
var utils = {
|
|
476
|
+
getExtendedPublicKeyAsync,
|
|
477
|
+
getExtendedPublicKey,
|
|
478
|
+
randomPrivateKey: () => randomBytes(L),
|
|
479
|
+
precompute: (w = 8, p = G) => {
|
|
480
|
+
p.multiply(3n);
|
|
481
|
+
return p;
|
|
482
|
+
}
|
|
483
|
+
// no-op
|
|
484
|
+
};
|
|
485
|
+
var W = 8;
|
|
486
|
+
var scalarBits = 256;
|
|
487
|
+
var pwindows = Math.ceil(scalarBits / W) + 1;
|
|
488
|
+
var pwindowSize = 2 ** (W - 1);
|
|
489
|
+
var precompute = () => {
|
|
490
|
+
const points = [];
|
|
491
|
+
let p = G;
|
|
492
|
+
let b = p;
|
|
493
|
+
for (let w = 0; w < pwindows; w++) {
|
|
494
|
+
b = p;
|
|
495
|
+
points.push(b);
|
|
496
|
+
for (let i = 1; i < pwindowSize; i++) {
|
|
497
|
+
b = b.add(p);
|
|
498
|
+
points.push(b);
|
|
499
|
+
}
|
|
500
|
+
p = b.double();
|
|
501
|
+
}
|
|
502
|
+
return points;
|
|
503
|
+
};
|
|
504
|
+
var Gpows = void 0;
|
|
505
|
+
var ctneg = (cnd, p) => {
|
|
506
|
+
const n = p.negate();
|
|
507
|
+
return cnd ? n : p;
|
|
508
|
+
};
|
|
509
|
+
var wNAF = (n) => {
|
|
510
|
+
const comp = Gpows || (Gpows = precompute());
|
|
511
|
+
let p = I;
|
|
512
|
+
let f = G;
|
|
513
|
+
const pow_2_w = 2 ** W;
|
|
514
|
+
const maxNum = pow_2_w;
|
|
515
|
+
const mask = big(pow_2_w - 1);
|
|
516
|
+
const shiftBy = big(W);
|
|
517
|
+
for (let w = 0; w < pwindows; w++) {
|
|
518
|
+
let wbits = Number(n & mask);
|
|
519
|
+
n >>= shiftBy;
|
|
520
|
+
if (wbits > pwindowSize) {
|
|
521
|
+
wbits -= maxNum;
|
|
522
|
+
n += 1n;
|
|
523
|
+
}
|
|
524
|
+
const off = w * pwindowSize;
|
|
525
|
+
const offF = off;
|
|
526
|
+
const offP = off + Math.abs(wbits) - 1;
|
|
527
|
+
const isEven = w % 2 !== 0;
|
|
528
|
+
const isNeg = wbits < 0;
|
|
529
|
+
if (wbits === 0) {
|
|
530
|
+
f = f.add(ctneg(isEven, comp[offF]));
|
|
531
|
+
} else {
|
|
532
|
+
p = p.add(ctneg(isNeg, comp[offP]));
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
return { p, f };
|
|
536
|
+
};
|
|
537
|
+
|
|
538
|
+
// node_modules/@noble/hashes/esm/utils.js
|
|
539
|
+
function isBytes2(a) {
|
|
540
|
+
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
541
|
+
}
|
|
542
|
+
function abytes2(b, ...lengths) {
|
|
543
|
+
if (!isBytes2(b))
|
|
544
|
+
throw new Error("Uint8Array expected");
|
|
545
|
+
if (lengths.length > 0 && !lengths.includes(b.length))
|
|
546
|
+
throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
|
|
547
|
+
}
|
|
548
|
+
function aexists(instance, checkFinished = true) {
|
|
549
|
+
if (instance.destroyed)
|
|
550
|
+
throw new Error("Hash instance has been destroyed");
|
|
551
|
+
if (checkFinished && instance.finished)
|
|
552
|
+
throw new Error("Hash#digest() has already been called");
|
|
553
|
+
}
|
|
554
|
+
function aoutput(out, instance) {
|
|
555
|
+
abytes2(out);
|
|
556
|
+
const min = instance.outputLen;
|
|
557
|
+
if (out.length < min) {
|
|
558
|
+
throw new Error("digestInto() expects output buffer of length at least " + min);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
function clean(...arrays) {
|
|
562
|
+
for (let i = 0; i < arrays.length; i++) {
|
|
563
|
+
arrays[i].fill(0);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
function createView(arr) {
|
|
567
|
+
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
568
|
+
}
|
|
569
|
+
function utf8ToBytes(str) {
|
|
570
|
+
if (typeof str !== "string")
|
|
571
|
+
throw new Error("string expected");
|
|
572
|
+
return new Uint8Array(new TextEncoder().encode(str));
|
|
573
|
+
}
|
|
574
|
+
function toBytes(data) {
|
|
575
|
+
if (typeof data === "string")
|
|
576
|
+
data = utf8ToBytes(data);
|
|
577
|
+
abytes2(data);
|
|
578
|
+
return data;
|
|
579
|
+
}
|
|
580
|
+
var Hash = class {
|
|
581
|
+
};
|
|
582
|
+
function createHasher(hashCons) {
|
|
583
|
+
const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
|
|
584
|
+
const tmp = hashCons();
|
|
585
|
+
hashC.outputLen = tmp.outputLen;
|
|
586
|
+
hashC.blockLen = tmp.blockLen;
|
|
587
|
+
hashC.create = () => hashCons();
|
|
588
|
+
return hashC;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
// node_modules/@noble/hashes/esm/_md.js
|
|
592
|
+
function setBigUint64(view, byteOffset, value, isLE) {
|
|
593
|
+
if (typeof view.setBigUint64 === "function")
|
|
594
|
+
return view.setBigUint64(byteOffset, value, isLE);
|
|
595
|
+
const _32n2 = BigInt(32);
|
|
596
|
+
const _u32_max = BigInt(4294967295);
|
|
597
|
+
const wh = Number(value >> _32n2 & _u32_max);
|
|
598
|
+
const wl = Number(value & _u32_max);
|
|
599
|
+
const h2 = isLE ? 4 : 0;
|
|
600
|
+
const l = isLE ? 0 : 4;
|
|
601
|
+
view.setUint32(byteOffset + h2, wh, isLE);
|
|
602
|
+
view.setUint32(byteOffset + l, wl, isLE);
|
|
603
|
+
}
|
|
604
|
+
var HashMD = class extends Hash {
|
|
605
|
+
constructor(blockLen, outputLen, padOffset, isLE) {
|
|
606
|
+
super();
|
|
607
|
+
this.finished = false;
|
|
608
|
+
this.length = 0;
|
|
609
|
+
this.pos = 0;
|
|
610
|
+
this.destroyed = false;
|
|
611
|
+
this.blockLen = blockLen;
|
|
612
|
+
this.outputLen = outputLen;
|
|
613
|
+
this.padOffset = padOffset;
|
|
614
|
+
this.isLE = isLE;
|
|
615
|
+
this.buffer = new Uint8Array(blockLen);
|
|
616
|
+
this.view = createView(this.buffer);
|
|
617
|
+
}
|
|
618
|
+
update(data) {
|
|
619
|
+
aexists(this);
|
|
620
|
+
data = toBytes(data);
|
|
621
|
+
abytes2(data);
|
|
622
|
+
const { view, buffer, blockLen } = this;
|
|
623
|
+
const len = data.length;
|
|
624
|
+
for (let pos = 0; pos < len; ) {
|
|
625
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
626
|
+
if (take === blockLen) {
|
|
627
|
+
const dataView = createView(data);
|
|
628
|
+
for (; blockLen <= len - pos; pos += blockLen)
|
|
629
|
+
this.process(dataView, pos);
|
|
630
|
+
continue;
|
|
631
|
+
}
|
|
632
|
+
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
633
|
+
this.pos += take;
|
|
634
|
+
pos += take;
|
|
635
|
+
if (this.pos === blockLen) {
|
|
636
|
+
this.process(view, 0);
|
|
637
|
+
this.pos = 0;
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
this.length += data.length;
|
|
641
|
+
this.roundClean();
|
|
642
|
+
return this;
|
|
643
|
+
}
|
|
644
|
+
digestInto(out) {
|
|
645
|
+
aexists(this);
|
|
646
|
+
aoutput(out, this);
|
|
647
|
+
this.finished = true;
|
|
648
|
+
const { buffer, view, blockLen, isLE } = this;
|
|
649
|
+
let { pos } = this;
|
|
650
|
+
buffer[pos++] = 128;
|
|
651
|
+
clean(this.buffer.subarray(pos));
|
|
652
|
+
if (this.padOffset > blockLen - pos) {
|
|
653
|
+
this.process(view, 0);
|
|
654
|
+
pos = 0;
|
|
655
|
+
}
|
|
656
|
+
for (let i = pos; i < blockLen; i++)
|
|
657
|
+
buffer[i] = 0;
|
|
658
|
+
setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);
|
|
659
|
+
this.process(view, 0);
|
|
660
|
+
const oview = createView(out);
|
|
661
|
+
const len = this.outputLen;
|
|
662
|
+
if (len % 4)
|
|
663
|
+
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
664
|
+
const outLen = len / 4;
|
|
665
|
+
const state = this.get();
|
|
666
|
+
if (outLen > state.length)
|
|
667
|
+
throw new Error("_sha2: outputLen bigger than state");
|
|
668
|
+
for (let i = 0; i < outLen; i++)
|
|
669
|
+
oview.setUint32(4 * i, state[i], isLE);
|
|
670
|
+
}
|
|
671
|
+
digest() {
|
|
672
|
+
const { buffer, outputLen } = this;
|
|
673
|
+
this.digestInto(buffer);
|
|
674
|
+
const res = buffer.slice(0, outputLen);
|
|
675
|
+
this.destroy();
|
|
676
|
+
return res;
|
|
677
|
+
}
|
|
678
|
+
_cloneInto(to) {
|
|
679
|
+
to || (to = new this.constructor());
|
|
680
|
+
to.set(...this.get());
|
|
681
|
+
const { blockLen, buffer, length, finished, destroyed, pos } = this;
|
|
682
|
+
to.destroyed = destroyed;
|
|
683
|
+
to.finished = finished;
|
|
684
|
+
to.length = length;
|
|
685
|
+
to.pos = pos;
|
|
686
|
+
if (length % blockLen)
|
|
687
|
+
to.buffer.set(buffer);
|
|
688
|
+
return to;
|
|
689
|
+
}
|
|
690
|
+
clone() {
|
|
691
|
+
return this._cloneInto();
|
|
692
|
+
}
|
|
693
|
+
};
|
|
694
|
+
var SHA512_IV = /* @__PURE__ */ Uint32Array.from([
|
|
695
|
+
1779033703,
|
|
696
|
+
4089235720,
|
|
697
|
+
3144134277,
|
|
698
|
+
2227873595,
|
|
699
|
+
1013904242,
|
|
700
|
+
4271175723,
|
|
701
|
+
2773480762,
|
|
702
|
+
1595750129,
|
|
703
|
+
1359893119,
|
|
704
|
+
2917565137,
|
|
705
|
+
2600822924,
|
|
706
|
+
725511199,
|
|
707
|
+
528734635,
|
|
708
|
+
4215389547,
|
|
709
|
+
1541459225,
|
|
710
|
+
327033209
|
|
711
|
+
]);
|
|
712
|
+
|
|
713
|
+
// node_modules/@noble/hashes/esm/_u64.js
|
|
714
|
+
var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
715
|
+
var _32n = /* @__PURE__ */ BigInt(32);
|
|
716
|
+
function fromBig(n, le = false) {
|
|
717
|
+
if (le)
|
|
718
|
+
return { h: Number(n & U32_MASK64), l: Number(n >> _32n & U32_MASK64) };
|
|
719
|
+
return { h: Number(n >> _32n & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
|
|
720
|
+
}
|
|
721
|
+
function split(lst, le = false) {
|
|
722
|
+
const len = lst.length;
|
|
723
|
+
let Ah = new Uint32Array(len);
|
|
724
|
+
let Al = new Uint32Array(len);
|
|
725
|
+
for (let i = 0; i < len; i++) {
|
|
726
|
+
const { h: h2, l } = fromBig(lst[i], le);
|
|
727
|
+
[Ah[i], Al[i]] = [h2, l];
|
|
728
|
+
}
|
|
729
|
+
return [Ah, Al];
|
|
730
|
+
}
|
|
731
|
+
var shrSH = (h2, _l, s) => h2 >>> s;
|
|
732
|
+
var shrSL = (h2, l, s) => h2 << 32 - s | l >>> s;
|
|
733
|
+
var rotrSH = (h2, l, s) => h2 >>> s | l << 32 - s;
|
|
734
|
+
var rotrSL = (h2, l, s) => h2 << 32 - s | l >>> s;
|
|
735
|
+
var rotrBH = (h2, l, s) => h2 << 64 - s | l >>> s - 32;
|
|
736
|
+
var rotrBL = (h2, l, s) => h2 >>> s - 32 | l << 64 - s;
|
|
737
|
+
function add(Ah, Al, Bh, Bl) {
|
|
738
|
+
const l = (Al >>> 0) + (Bl >>> 0);
|
|
739
|
+
return { h: Ah + Bh + (l / 2 ** 32 | 0) | 0, l: l | 0 };
|
|
740
|
+
}
|
|
741
|
+
var add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
|
|
742
|
+
var add3H = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
|
|
743
|
+
var add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
|
|
744
|
+
var add4H = (low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0;
|
|
745
|
+
var add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
|
|
746
|
+
var add5H = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
|
|
747
|
+
|
|
748
|
+
// node_modules/@noble/hashes/esm/sha2.js
|
|
749
|
+
var K512 = /* @__PURE__ */ (() => split([
|
|
750
|
+
"0x428a2f98d728ae22",
|
|
751
|
+
"0x7137449123ef65cd",
|
|
752
|
+
"0xb5c0fbcfec4d3b2f",
|
|
753
|
+
"0xe9b5dba58189dbbc",
|
|
754
|
+
"0x3956c25bf348b538",
|
|
755
|
+
"0x59f111f1b605d019",
|
|
756
|
+
"0x923f82a4af194f9b",
|
|
757
|
+
"0xab1c5ed5da6d8118",
|
|
758
|
+
"0xd807aa98a3030242",
|
|
759
|
+
"0x12835b0145706fbe",
|
|
760
|
+
"0x243185be4ee4b28c",
|
|
761
|
+
"0x550c7dc3d5ffb4e2",
|
|
762
|
+
"0x72be5d74f27b896f",
|
|
763
|
+
"0x80deb1fe3b1696b1",
|
|
764
|
+
"0x9bdc06a725c71235",
|
|
765
|
+
"0xc19bf174cf692694",
|
|
766
|
+
"0xe49b69c19ef14ad2",
|
|
767
|
+
"0xefbe4786384f25e3",
|
|
768
|
+
"0x0fc19dc68b8cd5b5",
|
|
769
|
+
"0x240ca1cc77ac9c65",
|
|
770
|
+
"0x2de92c6f592b0275",
|
|
771
|
+
"0x4a7484aa6ea6e483",
|
|
772
|
+
"0x5cb0a9dcbd41fbd4",
|
|
773
|
+
"0x76f988da831153b5",
|
|
774
|
+
"0x983e5152ee66dfab",
|
|
775
|
+
"0xa831c66d2db43210",
|
|
776
|
+
"0xb00327c898fb213f",
|
|
777
|
+
"0xbf597fc7beef0ee4",
|
|
778
|
+
"0xc6e00bf33da88fc2",
|
|
779
|
+
"0xd5a79147930aa725",
|
|
780
|
+
"0x06ca6351e003826f",
|
|
781
|
+
"0x142929670a0e6e70",
|
|
782
|
+
"0x27b70a8546d22ffc",
|
|
783
|
+
"0x2e1b21385c26c926",
|
|
784
|
+
"0x4d2c6dfc5ac42aed",
|
|
785
|
+
"0x53380d139d95b3df",
|
|
786
|
+
"0x650a73548baf63de",
|
|
787
|
+
"0x766a0abb3c77b2a8",
|
|
788
|
+
"0x81c2c92e47edaee6",
|
|
789
|
+
"0x92722c851482353b",
|
|
790
|
+
"0xa2bfe8a14cf10364",
|
|
791
|
+
"0xa81a664bbc423001",
|
|
792
|
+
"0xc24b8b70d0f89791",
|
|
793
|
+
"0xc76c51a30654be30",
|
|
794
|
+
"0xd192e819d6ef5218",
|
|
795
|
+
"0xd69906245565a910",
|
|
796
|
+
"0xf40e35855771202a",
|
|
797
|
+
"0x106aa07032bbd1b8",
|
|
798
|
+
"0x19a4c116b8d2d0c8",
|
|
799
|
+
"0x1e376c085141ab53",
|
|
800
|
+
"0x2748774cdf8eeb99",
|
|
801
|
+
"0x34b0bcb5e19b48a8",
|
|
802
|
+
"0x391c0cb3c5c95a63",
|
|
803
|
+
"0x4ed8aa4ae3418acb",
|
|
804
|
+
"0x5b9cca4f7763e373",
|
|
805
|
+
"0x682e6ff3d6b2b8a3",
|
|
806
|
+
"0x748f82ee5defb2fc",
|
|
807
|
+
"0x78a5636f43172f60",
|
|
808
|
+
"0x84c87814a1f0ab72",
|
|
809
|
+
"0x8cc702081a6439ec",
|
|
810
|
+
"0x90befffa23631e28",
|
|
811
|
+
"0xa4506cebde82bde9",
|
|
812
|
+
"0xbef9a3f7b2c67915",
|
|
813
|
+
"0xc67178f2e372532b",
|
|
814
|
+
"0xca273eceea26619c",
|
|
815
|
+
"0xd186b8c721c0c207",
|
|
816
|
+
"0xeada7dd6cde0eb1e",
|
|
817
|
+
"0xf57d4f7fee6ed178",
|
|
818
|
+
"0x06f067aa72176fba",
|
|
819
|
+
"0x0a637dc5a2c898a6",
|
|
820
|
+
"0x113f9804bef90dae",
|
|
821
|
+
"0x1b710b35131c471b",
|
|
822
|
+
"0x28db77f523047d84",
|
|
823
|
+
"0x32caab7b40c72493",
|
|
824
|
+
"0x3c9ebe0a15c9bebc",
|
|
825
|
+
"0x431d67c49c100d4c",
|
|
826
|
+
"0x4cc5d4becb3e42b6",
|
|
827
|
+
"0x597f299cfc657e2a",
|
|
828
|
+
"0x5fcb6fab3ad6faec",
|
|
829
|
+
"0x6c44198c4a475817"
|
|
830
|
+
].map((n) => BigInt(n))))();
|
|
831
|
+
var SHA512_Kh = /* @__PURE__ */ (() => K512[0])();
|
|
832
|
+
var SHA512_Kl = /* @__PURE__ */ (() => K512[1])();
|
|
833
|
+
var SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
|
|
834
|
+
var SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
|
|
835
|
+
var SHA512 = class extends HashMD {
|
|
836
|
+
constructor(outputLen = 64) {
|
|
837
|
+
super(128, outputLen, 16, false);
|
|
838
|
+
this.Ah = SHA512_IV[0] | 0;
|
|
839
|
+
this.Al = SHA512_IV[1] | 0;
|
|
840
|
+
this.Bh = SHA512_IV[2] | 0;
|
|
841
|
+
this.Bl = SHA512_IV[3] | 0;
|
|
842
|
+
this.Ch = SHA512_IV[4] | 0;
|
|
843
|
+
this.Cl = SHA512_IV[5] | 0;
|
|
844
|
+
this.Dh = SHA512_IV[6] | 0;
|
|
845
|
+
this.Dl = SHA512_IV[7] | 0;
|
|
846
|
+
this.Eh = SHA512_IV[8] | 0;
|
|
847
|
+
this.El = SHA512_IV[9] | 0;
|
|
848
|
+
this.Fh = SHA512_IV[10] | 0;
|
|
849
|
+
this.Fl = SHA512_IV[11] | 0;
|
|
850
|
+
this.Gh = SHA512_IV[12] | 0;
|
|
851
|
+
this.Gl = SHA512_IV[13] | 0;
|
|
852
|
+
this.Hh = SHA512_IV[14] | 0;
|
|
853
|
+
this.Hl = SHA512_IV[15] | 0;
|
|
854
|
+
}
|
|
855
|
+
// prettier-ignore
|
|
856
|
+
get() {
|
|
857
|
+
const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
|
858
|
+
return [Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl];
|
|
859
|
+
}
|
|
860
|
+
// prettier-ignore
|
|
861
|
+
set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
|
|
862
|
+
this.Ah = Ah | 0;
|
|
863
|
+
this.Al = Al | 0;
|
|
864
|
+
this.Bh = Bh | 0;
|
|
865
|
+
this.Bl = Bl | 0;
|
|
866
|
+
this.Ch = Ch | 0;
|
|
867
|
+
this.Cl = Cl | 0;
|
|
868
|
+
this.Dh = Dh | 0;
|
|
869
|
+
this.Dl = Dl | 0;
|
|
870
|
+
this.Eh = Eh | 0;
|
|
871
|
+
this.El = El | 0;
|
|
872
|
+
this.Fh = Fh | 0;
|
|
873
|
+
this.Fl = Fl | 0;
|
|
874
|
+
this.Gh = Gh | 0;
|
|
875
|
+
this.Gl = Gl | 0;
|
|
876
|
+
this.Hh = Hh | 0;
|
|
877
|
+
this.Hl = Hl | 0;
|
|
878
|
+
}
|
|
879
|
+
process(view, offset) {
|
|
880
|
+
for (let i = 0; i < 16; i++, offset += 4) {
|
|
881
|
+
SHA512_W_H[i] = view.getUint32(offset);
|
|
882
|
+
SHA512_W_L[i] = view.getUint32(offset += 4);
|
|
883
|
+
}
|
|
884
|
+
for (let i = 16; i < 80; i++) {
|
|
885
|
+
const W15h = SHA512_W_H[i - 15] | 0;
|
|
886
|
+
const W15l = SHA512_W_L[i - 15] | 0;
|
|
887
|
+
const s0h = rotrSH(W15h, W15l, 1) ^ rotrSH(W15h, W15l, 8) ^ shrSH(W15h, W15l, 7);
|
|
888
|
+
const s0l = rotrSL(W15h, W15l, 1) ^ rotrSL(W15h, W15l, 8) ^ shrSL(W15h, W15l, 7);
|
|
889
|
+
const W2h = SHA512_W_H[i - 2] | 0;
|
|
890
|
+
const W2l = SHA512_W_L[i - 2] | 0;
|
|
891
|
+
const s1h = rotrSH(W2h, W2l, 19) ^ rotrBH(W2h, W2l, 61) ^ shrSH(W2h, W2l, 6);
|
|
892
|
+
const s1l = rotrSL(W2h, W2l, 19) ^ rotrBL(W2h, W2l, 61) ^ shrSL(W2h, W2l, 6);
|
|
893
|
+
const SUMl = add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
|
|
894
|
+
const SUMh = add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]);
|
|
895
|
+
SHA512_W_H[i] = SUMh | 0;
|
|
896
|
+
SHA512_W_L[i] = SUMl | 0;
|
|
897
|
+
}
|
|
898
|
+
let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
|
899
|
+
for (let i = 0; i < 80; i++) {
|
|
900
|
+
const sigma1h = rotrSH(Eh, El, 14) ^ rotrSH(Eh, El, 18) ^ rotrBH(Eh, El, 41);
|
|
901
|
+
const sigma1l = rotrSL(Eh, El, 14) ^ rotrSL(Eh, El, 18) ^ rotrBL(Eh, El, 41);
|
|
902
|
+
const CHIh = Eh & Fh ^ ~Eh & Gh;
|
|
903
|
+
const CHIl = El & Fl ^ ~El & Gl;
|
|
904
|
+
const T1ll = add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
|
|
905
|
+
const T1h = add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
|
|
906
|
+
const T1l = T1ll | 0;
|
|
907
|
+
const sigma0h = rotrSH(Ah, Al, 28) ^ rotrBH(Ah, Al, 34) ^ rotrBH(Ah, Al, 39);
|
|
908
|
+
const sigma0l = rotrSL(Ah, Al, 28) ^ rotrBL(Ah, Al, 34) ^ rotrBL(Ah, Al, 39);
|
|
909
|
+
const MAJh = Ah & Bh ^ Ah & Ch ^ Bh & Ch;
|
|
910
|
+
const MAJl = Al & Bl ^ Al & Cl ^ Bl & Cl;
|
|
911
|
+
Hh = Gh | 0;
|
|
912
|
+
Hl = Gl | 0;
|
|
913
|
+
Gh = Fh | 0;
|
|
914
|
+
Gl = Fl | 0;
|
|
915
|
+
Fh = Eh | 0;
|
|
916
|
+
Fl = El | 0;
|
|
917
|
+
({ h: Eh, l: El } = add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
|
|
918
|
+
Dh = Ch | 0;
|
|
919
|
+
Dl = Cl | 0;
|
|
920
|
+
Ch = Bh | 0;
|
|
921
|
+
Cl = Bl | 0;
|
|
922
|
+
Bh = Ah | 0;
|
|
923
|
+
Bl = Al | 0;
|
|
924
|
+
const All = add3L(T1l, sigma0l, MAJl);
|
|
925
|
+
Ah = add3H(All, T1h, sigma0h, MAJh);
|
|
926
|
+
Al = All | 0;
|
|
927
|
+
}
|
|
928
|
+
({ h: Ah, l: Al } = add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
|
|
929
|
+
({ h: Bh, l: Bl } = add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
|
|
930
|
+
({ h: Ch, l: Cl } = add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
|
|
931
|
+
({ h: Dh, l: Dl } = add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
|
|
932
|
+
({ h: Eh, l: El } = add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
|
|
933
|
+
({ h: Fh, l: Fl } = add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
|
|
934
|
+
({ h: Gh, l: Gl } = add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
|
|
935
|
+
({ h: Hh, l: Hl } = add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
|
|
936
|
+
this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
|
|
937
|
+
}
|
|
938
|
+
roundClean() {
|
|
939
|
+
clean(SHA512_W_H, SHA512_W_L);
|
|
940
|
+
}
|
|
941
|
+
destroy() {
|
|
942
|
+
clean(this.buffer);
|
|
943
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
944
|
+
}
|
|
945
|
+
};
|
|
946
|
+
var sha512 = /* @__PURE__ */ createHasher(() => new SHA512());
|
|
947
|
+
|
|
948
|
+
// node_modules/@noble/hashes/esm/sha512.js
|
|
949
|
+
var sha5122 = sha512;
|
|
950
|
+
|
|
951
|
+
// src/crypto/keys.ts
|
|
952
|
+
etc.sha512Sync = (...m) => {
|
|
953
|
+
const h2 = sha5122.create();
|
|
954
|
+
for (const msg of m) h2.update(msg);
|
|
955
|
+
return h2.digest();
|
|
956
|
+
};
|
|
957
|
+
function generateKeyPair() {
|
|
958
|
+
const privateKey = utils.randomPrivateKey();
|
|
959
|
+
const publicKey = getPublicKey(privateKey);
|
|
960
|
+
return { privateKey, publicKey };
|
|
961
|
+
}
|
|
962
|
+
function getPublicKey2(privateKey) {
|
|
963
|
+
return getPublicKey(privateKey);
|
|
964
|
+
}
|
|
965
|
+
function privateKeyToHex(key) {
|
|
966
|
+
return Array.from(key).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
967
|
+
}
|
|
968
|
+
function hexToPrivateKey(hex) {
|
|
969
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
970
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
971
|
+
bytes[i] = parseInt(hex.substring(i * 2, i * 2 + 2), 16);
|
|
972
|
+
}
|
|
973
|
+
return bytes;
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
// src/crypto/base58.ts
|
|
977
|
+
var ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
978
|
+
var BASE = 58;
|
|
979
|
+
var ALPHABET_MAP = /* @__PURE__ */ new Map();
|
|
980
|
+
for (let i = 0; i < ALPHABET.length; i++) {
|
|
981
|
+
ALPHABET_MAP.set(ALPHABET[i], i);
|
|
982
|
+
}
|
|
983
|
+
function encode(bytes) {
|
|
984
|
+
if (bytes.length === 0) return "";
|
|
985
|
+
let zeros = 0;
|
|
986
|
+
while (zeros < bytes.length && bytes[zeros] === 0) zeros++;
|
|
987
|
+
const digits = [];
|
|
988
|
+
for (let i = zeros; i < bytes.length; i++) {
|
|
989
|
+
let carry = bytes[i];
|
|
990
|
+
for (let j = 0; j < digits.length; j++) {
|
|
991
|
+
carry += digits[j] << 8;
|
|
992
|
+
digits[j] = carry % BASE;
|
|
993
|
+
carry = carry / BASE | 0;
|
|
994
|
+
}
|
|
995
|
+
while (carry > 0) {
|
|
996
|
+
digits.push(carry % BASE);
|
|
997
|
+
carry = carry / BASE | 0;
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
let result = ALPHABET[0].repeat(zeros);
|
|
1001
|
+
for (let i = digits.length - 1; i >= 0; i--) {
|
|
1002
|
+
result += ALPHABET[digits[i]];
|
|
1003
|
+
}
|
|
1004
|
+
return result;
|
|
1005
|
+
}
|
|
1006
|
+
function decode(str) {
|
|
1007
|
+
if (str.length === 0) return new Uint8Array(0);
|
|
1008
|
+
let zeros = 0;
|
|
1009
|
+
while (zeros < str.length && str[zeros] === ALPHABET[0]) zeros++;
|
|
1010
|
+
const bytes = [];
|
|
1011
|
+
for (let i = zeros; i < str.length; i++) {
|
|
1012
|
+
const val = ALPHABET_MAP.get(str[i]);
|
|
1013
|
+
if (val === void 0) throw new Error(`Invalid base58 character: ${str[i]}`);
|
|
1014
|
+
let carry = val;
|
|
1015
|
+
for (let j = 0; j < bytes.length; j++) {
|
|
1016
|
+
carry += bytes[j] * BASE;
|
|
1017
|
+
bytes[j] = carry & 255;
|
|
1018
|
+
carry >>= 8;
|
|
1019
|
+
}
|
|
1020
|
+
while (carry > 0) {
|
|
1021
|
+
bytes.push(carry & 255);
|
|
1022
|
+
carry >>= 8;
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
const result = new Uint8Array(zeros + bytes.length);
|
|
1026
|
+
for (let i = 0; i < zeros; i++) result[i] = 0;
|
|
1027
|
+
for (let i = 0; i < bytes.length; i++) result[zeros + i] = bytes[bytes.length - 1 - i];
|
|
1028
|
+
return result;
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
// src/crypto/multikey.ts
|
|
1032
|
+
var ED25519_PREFIX = new Uint8Array([237, 1]);
|
|
1033
|
+
function encodePublicKey(publicKey) {
|
|
1034
|
+
const prefixed = new Uint8Array(2 + publicKey.length);
|
|
1035
|
+
prefixed.set(ED25519_PREFIX, 0);
|
|
1036
|
+
prefixed.set(publicKey, 2);
|
|
1037
|
+
return "z" + encode(prefixed);
|
|
1038
|
+
}
|
|
1039
|
+
function decodePublicKey(multikey) {
|
|
1040
|
+
if (!multikey.startsWith("z")) {
|
|
1041
|
+
throw new Error('Multikey must start with "z"');
|
|
1042
|
+
}
|
|
1043
|
+
const decoded = decode(multikey.slice(1));
|
|
1044
|
+
if (decoded[0] !== 237 || decoded[1] !== 1) {
|
|
1045
|
+
throw new Error("Invalid Ed25519 multikey prefix");
|
|
1046
|
+
}
|
|
1047
|
+
return decoded.slice(2);
|
|
1048
|
+
}
|
|
1049
|
+
function didFromPublicKey(publicKey) {
|
|
1050
|
+
return `did:key:${encodePublicKey(publicKey)}`;
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
// src/crypto/jwt.ts
|
|
1054
|
+
var encoder = new TextEncoder();
|
|
1055
|
+
function base64UrlEncode(data) {
|
|
1056
|
+
let binary = "";
|
|
1057
|
+
for (let i = 0; i < data.length; i++) {
|
|
1058
|
+
binary += String.fromCharCode(data[i]);
|
|
1059
|
+
}
|
|
1060
|
+
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
1061
|
+
}
|
|
1062
|
+
function createEdDSAJWT(privateKey, lifetimeSeconds = 300) {
|
|
1063
|
+
const publicKey = getPublicKey2(privateKey);
|
|
1064
|
+
const multikey = encodePublicKey(publicKey);
|
|
1065
|
+
const did = `did:key:${multikey}`;
|
|
1066
|
+
const nowSecs = Math.floor(Date.now() / 1e3);
|
|
1067
|
+
const header = JSON.stringify({ alg: "EdDSA", typ: "JWT", kid: multikey });
|
|
1068
|
+
const payload = JSON.stringify({
|
|
1069
|
+
sub: did,
|
|
1070
|
+
iss: did,
|
|
1071
|
+
iat: nowSecs,
|
|
1072
|
+
exp: nowSecs + lifetimeSeconds
|
|
1073
|
+
});
|
|
1074
|
+
const headerB64 = base64UrlEncode(encoder.encode(header));
|
|
1075
|
+
const payloadB64 = base64UrlEncode(encoder.encode(payload));
|
|
1076
|
+
const signingInput = `${headerB64}.${payloadB64}`;
|
|
1077
|
+
const signature = sign(encoder.encode(signingInput), privateKey);
|
|
1078
|
+
const signatureB64 = base64UrlEncode(signature);
|
|
1079
|
+
return `${signingInput}.${signatureB64}`;
|
|
1080
|
+
}
|
|
26
1081
|
|
|
27
1082
|
// src/Credentials.ts
|
|
1083
|
+
var Auth = class {
|
|
1084
|
+
};
|
|
1085
|
+
var NoAuth = class extends Auth {
|
|
1086
|
+
apply(_headers) {
|
|
1087
|
+
}
|
|
1088
|
+
};
|
|
1089
|
+
var BearerAuth = class extends Auth {
|
|
1090
|
+
constructor(token) {
|
|
1091
|
+
super();
|
|
1092
|
+
this._token = token;
|
|
1093
|
+
}
|
|
1094
|
+
apply(headers) {
|
|
1095
|
+
headers["Authorization"] = `Bearer ${this._token}`;
|
|
1096
|
+
}
|
|
1097
|
+
};
|
|
1098
|
+
var KeyPairAuth = class _KeyPairAuth extends Auth {
|
|
1099
|
+
/**
|
|
1100
|
+
* @param privateKey - 32-byte Ed25519 private key
|
|
1101
|
+
* @param tokenLifetimeSeconds - JWT lifetime in seconds (default 300 = 5 min)
|
|
1102
|
+
*/
|
|
1103
|
+
constructor(privateKey, tokenLifetimeSeconds = 300) {
|
|
1104
|
+
super();
|
|
1105
|
+
this._privateKey = privateKey;
|
|
1106
|
+
this._publicKey = getPublicKey2(privateKey);
|
|
1107
|
+
this._did = didFromPublicKey(this._publicKey);
|
|
1108
|
+
this._lifetime = tokenLifetimeSeconds;
|
|
1109
|
+
}
|
|
1110
|
+
apply(headers) {
|
|
1111
|
+
const jwt = createEdDSAJWT(this._privateKey, this._lifetime);
|
|
1112
|
+
headers["Authorization"] = `Bearer ${jwt}`;
|
|
1113
|
+
}
|
|
1114
|
+
/** The caller's DID derived from the public key. */
|
|
1115
|
+
getDID() {
|
|
1116
|
+
return this._did;
|
|
1117
|
+
}
|
|
1118
|
+
/** The 32-byte Ed25519 public key. */
|
|
1119
|
+
getPublicKey() {
|
|
1120
|
+
return this._publicKey;
|
|
1121
|
+
}
|
|
1122
|
+
/** Generate a new random keypair and return a KeyPairAuth instance. */
|
|
1123
|
+
static generate(tokenLifetimeSeconds = 300) {
|
|
1124
|
+
const { privateKey } = generateKeyPair();
|
|
1125
|
+
return new _KeyPairAuth(privateKey, tokenLifetimeSeconds);
|
|
1126
|
+
}
|
|
1127
|
+
/** Create from a hex-encoded private key string. */
|
|
1128
|
+
static fromHex(privateKeyHex, tokenLifetimeSeconds = 300) {
|
|
1129
|
+
return new _KeyPairAuth(hexToPrivateKey(privateKeyHex), tokenLifetimeSeconds);
|
|
1130
|
+
}
|
|
1131
|
+
};
|
|
28
1132
|
var CredentialsHTTP = class {
|
|
29
1133
|
constructor(venueId, apiKey, userId) {
|
|
30
1134
|
this.venueId = venueId;
|
|
@@ -33,60 +1137,485 @@ var CredentialsHTTP = class {
|
|
|
33
1137
|
}
|
|
34
1138
|
};
|
|
35
1139
|
|
|
1140
|
+
// src/Logger.ts
|
|
1141
|
+
var defaultHandler = (_level, message) => {
|
|
1142
|
+
console.debug(`[covia] ${message}`);
|
|
1143
|
+
};
|
|
1144
|
+
var logger = {
|
|
1145
|
+
level: "none",
|
|
1146
|
+
handler: defaultHandler,
|
|
1147
|
+
debug(message) {
|
|
1148
|
+
if (this.level === "debug") {
|
|
1149
|
+
this.handler("debug", message);
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
};
|
|
1153
|
+
|
|
36
1154
|
// src/Utils.ts
|
|
37
|
-
function
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
1155
|
+
async function parseErrorBody(response) {
|
|
1156
|
+
let body = null;
|
|
1157
|
+
let message = `Request failed with status ${response.status}`;
|
|
1158
|
+
try {
|
|
1159
|
+
body = await response.json();
|
|
1160
|
+
if (body?.error) {
|
|
1161
|
+
message = body.error;
|
|
1162
|
+
}
|
|
1163
|
+
} catch {
|
|
1164
|
+
try {
|
|
1165
|
+
const text = await response.text();
|
|
1166
|
+
if (text) message = text;
|
|
1167
|
+
} catch {
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
return { message, body };
|
|
1171
|
+
}
|
|
1172
|
+
async function throwHttpError(response) {
|
|
1173
|
+
const { message, body } = await parseErrorBody(response);
|
|
1174
|
+
if (response.status === 404) {
|
|
1175
|
+
throw new NotFoundError(message);
|
|
1176
|
+
}
|
|
1177
|
+
throw new GridError(response.status, message, body);
|
|
1178
|
+
}
|
|
1179
|
+
function wrapError(error) {
|
|
1180
|
+
if (error instanceof CoviaError) return error;
|
|
1181
|
+
const msg = error.message ?? String(error);
|
|
1182
|
+
if (error instanceof TypeError) {
|
|
1183
|
+
return new CoviaConnectionError(msg);
|
|
1184
|
+
}
|
|
1185
|
+
return new CoviaError(`Request failed: ${msg}`);
|
|
1186
|
+
}
|
|
1187
|
+
async function fetchWithError(url, options) {
|
|
1188
|
+
const method = options?.method ?? "GET";
|
|
1189
|
+
logger.debug(`${method} ${url}`);
|
|
1190
|
+
let response;
|
|
1191
|
+
try {
|
|
1192
|
+
response = await fetch(url, options);
|
|
1193
|
+
} catch (error) {
|
|
1194
|
+
const msg = error.message ?? String(error);
|
|
1195
|
+
logger.debug(`Connection failed: ${method} ${url} \u2014 ${msg}`);
|
|
1196
|
+
throw wrapError(error);
|
|
1197
|
+
}
|
|
1198
|
+
logger.debug(`${method} ${url} \u2192 ${response.status}`);
|
|
1199
|
+
if (!response.ok) {
|
|
1200
|
+
await throwHttpError(response);
|
|
1201
|
+
}
|
|
1202
|
+
return response.json();
|
|
1203
|
+
}
|
|
1204
|
+
async function fetchStreamWithError(url, options) {
|
|
1205
|
+
const method = options?.method ?? "GET";
|
|
1206
|
+
logger.debug(`${method} ${url}`);
|
|
1207
|
+
let response;
|
|
1208
|
+
try {
|
|
1209
|
+
response = await fetch(url, options);
|
|
1210
|
+
} catch (error) {
|
|
1211
|
+
const msg = error.message ?? String(error);
|
|
1212
|
+
logger.debug(`Connection failed: ${method} ${url} \u2014 ${msg}`);
|
|
1213
|
+
throw wrapError(error);
|
|
1214
|
+
}
|
|
1215
|
+
logger.debug(`${method} ${url} \u2192 ${response.status}`);
|
|
1216
|
+
if (!response.ok) {
|
|
1217
|
+
await throwHttpError(response);
|
|
1218
|
+
}
|
|
1219
|
+
return response;
|
|
1220
|
+
}
|
|
1221
|
+
function isJobComplete(jobStatus) {
|
|
1222
|
+
if (jobStatus == null)
|
|
1223
|
+
return false;
|
|
1224
|
+
return jobStatus == "COMPLETE" /* COMPLETE */ ? true : false;
|
|
1225
|
+
}
|
|
1226
|
+
function isJobPaused(jobStatus) {
|
|
1227
|
+
if (jobStatus == null)
|
|
1228
|
+
return false;
|
|
1229
|
+
return jobStatus == "PAUSED" /* PAUSED */ || jobStatus == "INPUT_REQUIRED" /* INPUT_REQUIRED */ || jobStatus == "AUTH_REQUIRED" /* AUTH_REQUIRED */;
|
|
1230
|
+
}
|
|
1231
|
+
function isJobFinished(jobStatus) {
|
|
1232
|
+
if (jobStatus == null)
|
|
1233
|
+
return false;
|
|
1234
|
+
if (jobStatus == "COMPLETE" /* COMPLETE */) return true;
|
|
1235
|
+
if (jobStatus == "FAILED" /* FAILED */) return true;
|
|
1236
|
+
if (jobStatus == "REJECTED" /* REJECTED */) return true;
|
|
1237
|
+
if (jobStatus == "CANCELLED" /* CANCELLED */) return true;
|
|
1238
|
+
if (jobStatus == "TIMEOUT" /* TIMEOUT */) return true;
|
|
1239
|
+
return false;
|
|
1240
|
+
}
|
|
1241
|
+
function getParsedAssetId(assetId) {
|
|
1242
|
+
if (assetId.startsWith("did:web")) {
|
|
1243
|
+
const parts = assetId.split("/");
|
|
1244
|
+
return parts[parts.length - 1];
|
|
1245
|
+
}
|
|
1246
|
+
return assetId;
|
|
1247
|
+
}
|
|
1248
|
+
function getAssetIdFromPath(assetHex, assetPath) {
|
|
1249
|
+
const venueDid = decodeURIComponent(assetPath.split("/")[4]);
|
|
1250
|
+
return venueDid + "/a/" + assetHex;
|
|
1251
|
+
}
|
|
1252
|
+
function getAssetIdFromVenueId(assetHex, venueId) {
|
|
1253
|
+
return venueId + "/a/" + assetHex;
|
|
46
1254
|
}
|
|
47
|
-
function
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
1255
|
+
function createSSEEvent(fields) {
|
|
1256
|
+
const data = fields.data ?? "";
|
|
1257
|
+
return {
|
|
1258
|
+
event: fields.event || null,
|
|
1259
|
+
data,
|
|
1260
|
+
id: fields.id || null,
|
|
1261
|
+
retry: fields.retry ?? null,
|
|
1262
|
+
json() {
|
|
1263
|
+
return JSON.parse(data);
|
|
1264
|
+
}
|
|
1265
|
+
};
|
|
1266
|
+
}
|
|
1267
|
+
async function* parseSSEStream(response) {
|
|
1268
|
+
const reader = response.body?.getReader();
|
|
1269
|
+
if (!reader) return;
|
|
1270
|
+
const decoder = new TextDecoder();
|
|
1271
|
+
let buffer = "";
|
|
1272
|
+
let event;
|
|
1273
|
+
let data = [];
|
|
1274
|
+
let id;
|
|
1275
|
+
let retry;
|
|
1276
|
+
try {
|
|
1277
|
+
while (true) {
|
|
1278
|
+
const { done, value } = await reader.read();
|
|
1279
|
+
if (done) break;
|
|
1280
|
+
buffer += decoder.decode(value, { stream: true });
|
|
1281
|
+
const lines = buffer.split("\n");
|
|
1282
|
+
buffer = lines.pop() ?? "";
|
|
1283
|
+
for (const line of lines) {
|
|
1284
|
+
if (line === "") {
|
|
1285
|
+
if (data.length > 0 || event !== void 0) {
|
|
1286
|
+
yield createSSEEvent({
|
|
1287
|
+
event,
|
|
1288
|
+
data: data.join("\n"),
|
|
1289
|
+
id,
|
|
1290
|
+
retry
|
|
1291
|
+
});
|
|
1292
|
+
event = void 0;
|
|
1293
|
+
data = [];
|
|
1294
|
+
id = void 0;
|
|
1295
|
+
retry = void 0;
|
|
1296
|
+
}
|
|
1297
|
+
continue;
|
|
1298
|
+
}
|
|
1299
|
+
if (line.startsWith(":")) continue;
|
|
1300
|
+
const colonIdx = line.indexOf(":");
|
|
1301
|
+
let field;
|
|
1302
|
+
let val;
|
|
1303
|
+
if (colonIdx === -1) {
|
|
1304
|
+
field = line;
|
|
1305
|
+
val = "";
|
|
1306
|
+
} else {
|
|
1307
|
+
field = line.slice(0, colonIdx);
|
|
1308
|
+
val = line.slice(colonIdx + 1);
|
|
1309
|
+
if (val.startsWith(" ")) val = val.slice(1);
|
|
1310
|
+
}
|
|
1311
|
+
switch (field) {
|
|
1312
|
+
case "event":
|
|
1313
|
+
event = val;
|
|
1314
|
+
break;
|
|
1315
|
+
case "data":
|
|
1316
|
+
data.push(val);
|
|
1317
|
+
break;
|
|
1318
|
+
case "id":
|
|
1319
|
+
id = val;
|
|
1320
|
+
break;
|
|
1321
|
+
case "retry": {
|
|
1322
|
+
const n = parseInt(val, 10);
|
|
1323
|
+
if (!isNaN(n)) retry = n;
|
|
1324
|
+
break;
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
if (data.length > 0 || event !== void 0) {
|
|
1330
|
+
yield createSSEEvent({ event, data: data.join("\n"), id, retry });
|
|
1331
|
+
}
|
|
1332
|
+
} finally {
|
|
1333
|
+
reader.releaseLock();
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
// src/AgentManager.ts
|
|
1338
|
+
var AgentManager = class {
|
|
1339
|
+
constructor(venue) {
|
|
1340
|
+
this.venue = venue;
|
|
1341
|
+
}
|
|
1342
|
+
async create(input) {
|
|
1343
|
+
return this.venue.operations.run("agent:create", input);
|
|
1344
|
+
}
|
|
1345
|
+
async request(agentId, input, wait) {
|
|
1346
|
+
return this.venue.operations.run("agent:request", { agentId, input, wait });
|
|
1347
|
+
}
|
|
1348
|
+
async message(agentId, message) {
|
|
1349
|
+
return this.venue.operations.run("agent:message", { agentId, message });
|
|
1350
|
+
}
|
|
1351
|
+
async trigger(agentId) {
|
|
1352
|
+
return this.venue.operations.run("agent:trigger", { agentId });
|
|
1353
|
+
}
|
|
1354
|
+
async query(agentId) {
|
|
1355
|
+
return this.venue.operations.run("agent:query", { agentId });
|
|
1356
|
+
}
|
|
1357
|
+
async list(includeTerminated) {
|
|
1358
|
+
return this.venue.operations.run("agent:list", { includeTerminated });
|
|
1359
|
+
}
|
|
1360
|
+
async delete(agentId, remove) {
|
|
1361
|
+
return this.venue.operations.run("agent:delete", { agentId, remove });
|
|
1362
|
+
}
|
|
1363
|
+
async suspend(agentId) {
|
|
1364
|
+
return this.venue.operations.run("agent:suspend", { agentId });
|
|
1365
|
+
}
|
|
1366
|
+
async resume(agentId, autoWake) {
|
|
1367
|
+
return this.venue.operations.run("agent:resume", { agentId, autoWake });
|
|
1368
|
+
}
|
|
1369
|
+
async update(input) {
|
|
1370
|
+
return this.venue.operations.run("agent:update", input);
|
|
1371
|
+
}
|
|
1372
|
+
async cancelTask(agentId, taskId) {
|
|
1373
|
+
return this.venue.operations.run("agent:cancelTask", { agentId, taskId });
|
|
1374
|
+
}
|
|
1375
|
+
};
|
|
1376
|
+
|
|
1377
|
+
// src/Job.ts
|
|
1378
|
+
var INITIAL_POLL_DELAY = 300;
|
|
1379
|
+
var BACKOFF_FACTOR = 1.5;
|
|
1380
|
+
var MAX_POLL_DELAY = 1e4;
|
|
1381
|
+
var Job = class {
|
|
1382
|
+
constructor(id, venue, metadata) {
|
|
1383
|
+
this.id = id;
|
|
1384
|
+
this.venue = venue;
|
|
1385
|
+
this.metadata = metadata;
|
|
1386
|
+
this._jobs = venue.jobs;
|
|
1387
|
+
}
|
|
1388
|
+
/**
|
|
1389
|
+
* Whether the job has reached a terminal state
|
|
1390
|
+
*/
|
|
1391
|
+
get isFinished() {
|
|
1392
|
+
return this.metadata.status != null && isJobFinished(this.metadata.status);
|
|
1393
|
+
}
|
|
1394
|
+
/**
|
|
1395
|
+
* Whether the job completed successfully
|
|
1396
|
+
*/
|
|
1397
|
+
get isComplete() {
|
|
1398
|
+
return this.metadata.status != null && isJobComplete(this.metadata.status);
|
|
1399
|
+
}
|
|
1400
|
+
/**
|
|
1401
|
+
* The job output.
|
|
1402
|
+
* @throws {Error} If the job has not finished yet.
|
|
1403
|
+
* @throws {JobFailedError} If the job finished with a non-COMPLETE status.
|
|
1404
|
+
*/
|
|
1405
|
+
get output() {
|
|
1406
|
+
if (!this.isFinished) {
|
|
1407
|
+
throw new Error(`Job is not finished (status: ${this.metadata.status})`);
|
|
1408
|
+
}
|
|
1409
|
+
if (!this.isComplete) {
|
|
1410
|
+
throw new JobFailedError(this.metadata);
|
|
1411
|
+
}
|
|
1412
|
+
return this.metadata.output;
|
|
1413
|
+
}
|
|
1414
|
+
/**
|
|
1415
|
+
* Poll the venue for the latest job status.
|
|
1416
|
+
* @throws {Error} If the job has no ID.
|
|
1417
|
+
*/
|
|
1418
|
+
async refresh() {
|
|
1419
|
+
if (!this.id) {
|
|
1420
|
+
throw new Error("Cannot refresh a job with no ID");
|
|
1421
|
+
}
|
|
1422
|
+
const job = await this.venue.getJob(this.id);
|
|
1423
|
+
this.metadata = job.metadata;
|
|
1424
|
+
}
|
|
1425
|
+
/**
|
|
1426
|
+
* Wait until the job reaches a terminal state.
|
|
1427
|
+
* Uses exponential backoff polling (initial 300ms, factor 1.5, max 10s).
|
|
1428
|
+
* @param options.timeout - Maximum milliseconds to wait. Undefined waits indefinitely.
|
|
1429
|
+
* @throws {CoviaTimeoutError} If timeout is exceeded.
|
|
1430
|
+
*/
|
|
1431
|
+
async wait(options) {
|
|
1432
|
+
if (this.isFinished) return;
|
|
1433
|
+
let delay = INITIAL_POLL_DELAY;
|
|
1434
|
+
const start = Date.now();
|
|
1435
|
+
logger.debug(`Polling job ${this.id} (status: ${this.metadata.status})`);
|
|
1436
|
+
while (!this.isFinished) {
|
|
1437
|
+
if (options?.timeout !== void 0 && Date.now() - start > options.timeout) {
|
|
1438
|
+
throw new CoviaTimeoutError(`Job ${this.id} did not finish within ${options.timeout}ms`);
|
|
1439
|
+
}
|
|
1440
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
1441
|
+
await this.refresh();
|
|
1442
|
+
logger.debug(`Job ${this.id} polled \u2192 ${this.metadata.status} (delay=${(delay / 1e3).toFixed(1)}s)`);
|
|
1443
|
+
delay = Math.min(delay * BACKOFF_FACTOR, MAX_POLL_DELAY);
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
/**
|
|
1447
|
+
* Wait for the job to complete and return its output.
|
|
1448
|
+
* @param options.timeout - Maximum milliseconds to wait.
|
|
1449
|
+
* @returns The job output.
|
|
1450
|
+
* @throws {JobFailedError} If the job finishes with a non-COMPLETE status.
|
|
1451
|
+
* @throws {CoviaTimeoutError} If timeout is exceeded.
|
|
1452
|
+
*/
|
|
1453
|
+
async result(options) {
|
|
1454
|
+
await this.wait(options);
|
|
1455
|
+
return this.output;
|
|
1456
|
+
}
|
|
1457
|
+
/**
|
|
1458
|
+
* Stream server-sent events for this job.
|
|
1459
|
+
* @returns AsyncGenerator yielding SSEEvent objects
|
|
1460
|
+
*/
|
|
1461
|
+
async *stream() {
|
|
1462
|
+
yield* this._jobs.stream(this.id);
|
|
1463
|
+
}
|
|
1464
|
+
/**
|
|
1465
|
+
* Whether the job is paused (PAUSED, INPUT_REQUIRED, or AUTH_REQUIRED)
|
|
1466
|
+
*/
|
|
1467
|
+
get isPaused() {
|
|
1468
|
+
return this.metadata.status != null && isJobPaused(this.metadata.status);
|
|
1469
|
+
}
|
|
1470
|
+
/**
|
|
1471
|
+
* Whether the job requires user input
|
|
1472
|
+
*/
|
|
1473
|
+
get needsInput() {
|
|
1474
|
+
return this.metadata.status === "INPUT_REQUIRED" /* INPUT_REQUIRED */;
|
|
1475
|
+
}
|
|
1476
|
+
/**
|
|
1477
|
+
* Whether the job requires authentication
|
|
1478
|
+
*/
|
|
1479
|
+
get needsAuth() {
|
|
1480
|
+
return this.metadata.status === "AUTH_REQUIRED" /* AUTH_REQUIRED */;
|
|
1481
|
+
}
|
|
1482
|
+
/**
|
|
1483
|
+
* Send a message to the running job
|
|
1484
|
+
* @param message - Message payload
|
|
1485
|
+
* @returns {Promise<any>}
|
|
1486
|
+
*/
|
|
1487
|
+
async sendMessage(message) {
|
|
1488
|
+
return this._jobs.sendMessage(this.id, message);
|
|
1489
|
+
}
|
|
1490
|
+
/**
|
|
1491
|
+
* Pause the job
|
|
1492
|
+
* @returns {Promise<JobMetadata>} Updated job metadata
|
|
1493
|
+
*/
|
|
1494
|
+
async pause() {
|
|
1495
|
+
this.metadata = await this._jobs.pause(this.id);
|
|
1496
|
+
return this.metadata;
|
|
1497
|
+
}
|
|
1498
|
+
/**
|
|
1499
|
+
* Resume the job
|
|
1500
|
+
* @returns {Promise<JobMetadata>} Updated job metadata
|
|
1501
|
+
*/
|
|
1502
|
+
async resume() {
|
|
1503
|
+
this.metadata = await this._jobs.resume(this.id);
|
|
1504
|
+
return this.metadata;
|
|
1505
|
+
}
|
|
1506
|
+
/**
|
|
1507
|
+
* Cancel the job
|
|
1508
|
+
* @returns {Promise<JobMetadata>} Updated job metadata
|
|
1509
|
+
*/
|
|
1510
|
+
async cancel() {
|
|
1511
|
+
this.metadata = await this._jobs.cancel(this.id);
|
|
1512
|
+
return this.metadata;
|
|
1513
|
+
}
|
|
1514
|
+
/**
|
|
1515
|
+
* Delete the job
|
|
1516
|
+
*/
|
|
1517
|
+
async delete() {
|
|
1518
|
+
return this._jobs.delete(this.id);
|
|
1519
|
+
}
|
|
1520
|
+
};
|
|
1521
|
+
|
|
1522
|
+
// src/JobManager.ts
|
|
1523
|
+
var JobManager = class {
|
|
1524
|
+
constructor(venue) {
|
|
1525
|
+
this.venue = venue;
|
|
1526
|
+
}
|
|
1527
|
+
async list() {
|
|
1528
|
+
return fetchWithError(`${this.venue.baseUrl}/api/v1/jobs`);
|
|
1529
|
+
}
|
|
1530
|
+
async get(jobId) {
|
|
1531
|
+
try {
|
|
1532
|
+
const data = await fetchWithError(`${this.venue.baseUrl}/api/v1/jobs/${jobId}`);
|
|
1533
|
+
return new Job(jobId, this.venue, data);
|
|
1534
|
+
} catch (error) {
|
|
1535
|
+
if (error instanceof NotFoundError) {
|
|
1536
|
+
throw new JobNotFoundError(jobId);
|
|
1537
|
+
}
|
|
1538
|
+
throw error;
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
async cancel(jobId) {
|
|
1542
|
+
try {
|
|
1543
|
+
return await fetchWithError(`${this.venue.baseUrl}/api/v1/jobs/${jobId}/cancel`, {
|
|
1544
|
+
method: "PUT",
|
|
1545
|
+
headers: this._buildHeaders()
|
|
1546
|
+
});
|
|
1547
|
+
} catch (error) {
|
|
1548
|
+
if (error instanceof NotFoundError) {
|
|
1549
|
+
throw new JobNotFoundError(jobId);
|
|
1550
|
+
}
|
|
1551
|
+
throw error;
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
async delete(jobId) {
|
|
1555
|
+
try {
|
|
1556
|
+
await fetchStreamWithError(`${this.venue.baseUrl}/api/v1/jobs/${jobId}/delete`, {
|
|
1557
|
+
method: "PUT",
|
|
1558
|
+
headers: this._buildHeaders()
|
|
1559
|
+
});
|
|
1560
|
+
} catch (error) {
|
|
1561
|
+
if (error instanceof NotFoundError) {
|
|
1562
|
+
throw new JobNotFoundError(jobId);
|
|
1563
|
+
}
|
|
1564
|
+
throw error;
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
async pause(jobId) {
|
|
1568
|
+
try {
|
|
1569
|
+
return await fetchWithError(`${this.venue.baseUrl}/api/v1/jobs/${jobId}/pause`, {
|
|
1570
|
+
method: "PUT",
|
|
1571
|
+
headers: this._buildHeaders()
|
|
1572
|
+
});
|
|
1573
|
+
} catch (error) {
|
|
1574
|
+
if (error instanceof NotFoundError) {
|
|
1575
|
+
throw new JobNotFoundError(jobId);
|
|
1576
|
+
}
|
|
1577
|
+
throw error;
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
async resume(jobId) {
|
|
1581
|
+
try {
|
|
1582
|
+
return await fetchWithError(`${this.venue.baseUrl}/api/v1/jobs/${jobId}/resume`, {
|
|
1583
|
+
method: "PUT",
|
|
1584
|
+
headers: this._buildHeaders()
|
|
1585
|
+
});
|
|
1586
|
+
} catch (error) {
|
|
1587
|
+
if (error instanceof NotFoundError) {
|
|
1588
|
+
throw new JobNotFoundError(jobId);
|
|
1589
|
+
}
|
|
1590
|
+
throw error;
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
async sendMessage(jobId, message) {
|
|
1594
|
+
try {
|
|
1595
|
+
return await fetchWithError(`${this.venue.baseUrl}/api/v1/jobs/${jobId}`, {
|
|
1596
|
+
method: "POST",
|
|
1597
|
+
headers: this._buildHeaders(),
|
|
1598
|
+
body: JSON.stringify(message)
|
|
1599
|
+
});
|
|
1600
|
+
} catch (error) {
|
|
1601
|
+
if (error instanceof NotFoundError) {
|
|
1602
|
+
throw new JobNotFoundError(jobId);
|
|
1603
|
+
}
|
|
1604
|
+
throw error;
|
|
51
1605
|
}
|
|
52
|
-
return response;
|
|
53
|
-
}).catch((error) => {
|
|
54
|
-
throw error instanceof CoviaError ? error : new CoviaError(`Request failed: ${error.message}`);
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
function isJobComplete(jobStatus) {
|
|
58
|
-
if (jobStatus == null)
|
|
59
|
-
return false;
|
|
60
|
-
return jobStatus == "COMPLETE" /* COMPLETE */ ? true : false;
|
|
61
|
-
}
|
|
62
|
-
function isJobPaused(jobStatus) {
|
|
63
|
-
if (jobStatus == null)
|
|
64
|
-
return false;
|
|
65
|
-
return jobStatus == "PAUSED" /* PAUSED */ ? true : false;
|
|
66
|
-
}
|
|
67
|
-
function isJobFinished(jobStatus) {
|
|
68
|
-
if (jobStatus == null)
|
|
69
|
-
return false;
|
|
70
|
-
if (jobStatus == "COMPLETE" /* COMPLETE */) return true;
|
|
71
|
-
if (jobStatus == "FAILED" /* FAILED */) return true;
|
|
72
|
-
if (jobStatus == "REJECTED" /* REJECTED */) return true;
|
|
73
|
-
if (jobStatus == "CANCELLED" /* CANCELLED */) return true;
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
function getParsedAssetId(assetId) {
|
|
77
|
-
if (assetId.startsWith("did:web")) {
|
|
78
|
-
const parts = assetId.split("/");
|
|
79
|
-
return parts[parts.length - 1];
|
|
80
1606
|
}
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
1607
|
+
async *stream(jobId) {
|
|
1608
|
+
const response = await fetchStreamWithError(`${this.venue.baseUrl}/api/v1/jobs/${jobId}/sse`, {
|
|
1609
|
+
headers: { ...this._buildHeaders(), "Accept": "text/event-stream" }
|
|
1610
|
+
});
|
|
1611
|
+
yield* parseSSEStream(response);
|
|
1612
|
+
}
|
|
1613
|
+
_buildHeaders() {
|
|
1614
|
+
const headers = { "Content-Type": "application/json" };
|
|
1615
|
+
this.venue.auth.apply(headers);
|
|
1616
|
+
return headers;
|
|
1617
|
+
}
|
|
1618
|
+
};
|
|
90
1619
|
|
|
91
1620
|
// src/Asset.ts
|
|
92
1621
|
var cache = /* @__PURE__ */ new Map();
|
|
@@ -95,6 +1624,8 @@ var Asset = class {
|
|
|
95
1624
|
this.id = id;
|
|
96
1625
|
this.venue = venue;
|
|
97
1626
|
this.metadata = metadata;
|
|
1627
|
+
this._assets = venue.assets;
|
|
1628
|
+
this._operations = venue.operations;
|
|
98
1629
|
}
|
|
99
1630
|
/**
|
|
100
1631
|
* Get asset metadata
|
|
@@ -104,7 +1635,7 @@ var Asset = class {
|
|
|
104
1635
|
if (cache.has(this.id)) {
|
|
105
1636
|
return Promise.resolve(cache.get(this.id));
|
|
106
1637
|
} else {
|
|
107
|
-
const data = this.
|
|
1638
|
+
const data = this._assets.getMetadata(this.id);
|
|
108
1639
|
if (data) {
|
|
109
1640
|
cache.set(this.id, data);
|
|
110
1641
|
}
|
|
@@ -112,26 +1643,19 @@ var Asset = class {
|
|
|
112
1643
|
}
|
|
113
1644
|
}
|
|
114
1645
|
/**
|
|
115
|
-
*
|
|
116
|
-
* @param reader - ReadableStreamDefaultReader
|
|
117
|
-
*/
|
|
118
|
-
async readStream(reader) {
|
|
119
|
-
return this.readStream(reader);
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Upload content to asset
|
|
1646
|
+
* Put content to asset
|
|
123
1647
|
* @param content - Content to upload
|
|
124
|
-
* @returns {Promise<
|
|
1648
|
+
* @returns {Promise<ContentHashResult>} The content hash returned by the server
|
|
125
1649
|
*/
|
|
126
|
-
|
|
127
|
-
return this.
|
|
1650
|
+
putContent(content) {
|
|
1651
|
+
return this._assets.putContent(this.id, content);
|
|
128
1652
|
}
|
|
129
1653
|
/**
|
|
130
1654
|
* Get asset content
|
|
131
1655
|
* @returns {Promise<ReadableStream<Uint8Array> | null>}
|
|
132
1656
|
*/
|
|
133
1657
|
getContent() {
|
|
134
|
-
return this.
|
|
1658
|
+
return this._assets.getContent(this.id);
|
|
135
1659
|
}
|
|
136
1660
|
/**
|
|
137
1661
|
* Get the URL for downloading asset content
|
|
@@ -146,15 +1670,15 @@ var Asset = class {
|
|
|
146
1670
|
* @returns {Promise<any>}
|
|
147
1671
|
*/
|
|
148
1672
|
run(input) {
|
|
149
|
-
return this.
|
|
1673
|
+
return this._operations.run(this.id, input);
|
|
150
1674
|
}
|
|
151
1675
|
/**
|
|
152
1676
|
* Execute the operation
|
|
153
1677
|
* @param input - Operation input parameters
|
|
154
|
-
* @returns {Promise<
|
|
1678
|
+
* @returns {Promise<Job>}
|
|
155
1679
|
*/
|
|
156
1680
|
invoke(input) {
|
|
157
|
-
return this.
|
|
1681
|
+
return this._operations.invoke(this.id, input);
|
|
158
1682
|
}
|
|
159
1683
|
};
|
|
160
1684
|
|
|
@@ -176,38 +1700,280 @@ var DataAsset = class extends Asset {
|
|
|
176
1700
|
// For now, it inherits all functionality from Asset
|
|
177
1701
|
};
|
|
178
1702
|
|
|
179
|
-
// src/
|
|
180
|
-
var
|
|
181
|
-
|
|
182
|
-
|
|
1703
|
+
// src/AssetManager.ts
|
|
1704
|
+
var cache2 = /* @__PURE__ */ new Map();
|
|
1705
|
+
var AssetManager = class {
|
|
1706
|
+
constructor(venue) {
|
|
183
1707
|
this.venue = venue;
|
|
184
|
-
this.metadata = metadata;
|
|
185
1708
|
}
|
|
186
1709
|
/**
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
1710
|
+
* Get asset by ID
|
|
1711
|
+
* @param assetId - Asset identifier
|
|
1712
|
+
* @returns Returns either an Operation or DataAsset based on the asset's metadata
|
|
1713
|
+
*/
|
|
1714
|
+
async get(assetId) {
|
|
1715
|
+
if (cache2.has(assetId)) {
|
|
1716
|
+
const cachedData = cache2.get(assetId);
|
|
1717
|
+
if (cachedData.metadata?.operation) {
|
|
1718
|
+
return new Operation(assetId, this.venue, cachedData);
|
|
1719
|
+
} else {
|
|
1720
|
+
return new DataAsset(assetId, this.venue, cachedData);
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
try {
|
|
1724
|
+
const data = await fetchWithError(`${this.venue.baseUrl}/api/v1/assets/${assetId}`);
|
|
1725
|
+
cache2.set(assetId, data);
|
|
1726
|
+
if (data.metadata?.operation) {
|
|
1727
|
+
return new Operation(assetId, this.venue, data);
|
|
1728
|
+
} else {
|
|
1729
|
+
return new DataAsset(assetId, this.venue, data);
|
|
1730
|
+
}
|
|
1731
|
+
} catch (error) {
|
|
1732
|
+
if (error instanceof NotFoundError) {
|
|
1733
|
+
throw new AssetNotFoundError(assetId);
|
|
1734
|
+
}
|
|
1735
|
+
throw error;
|
|
1736
|
+
}
|
|
192
1737
|
}
|
|
193
1738
|
/**
|
|
194
|
-
*
|
|
195
|
-
* @
|
|
1739
|
+
* List assets with pagination support
|
|
1740
|
+
* @param options - Pagination options (offset, limit)
|
|
1741
|
+
*/
|
|
1742
|
+
async list(options = {}) {
|
|
1743
|
+
const params = new URLSearchParams();
|
|
1744
|
+
params.set("offset", String(options.offset ?? 0));
|
|
1745
|
+
if (options.limit !== void 0) {
|
|
1746
|
+
params.set("limit", String(options.limit));
|
|
1747
|
+
}
|
|
1748
|
+
return fetchWithError(`${this.venue.baseUrl}/api/v1/assets?${params.toString()}`);
|
|
1749
|
+
}
|
|
1750
|
+
/**
|
|
1751
|
+
* Register a new asset
|
|
1752
|
+
* @param assetData - Asset configuration
|
|
1753
|
+
*/
|
|
1754
|
+
async register(assetData) {
|
|
1755
|
+
return fetchWithError(`${this.venue.baseUrl}/api/v1/assets`, {
|
|
1756
|
+
method: "POST",
|
|
1757
|
+
headers: this._buildHeaders(),
|
|
1758
|
+
body: JSON.stringify(assetData)
|
|
1759
|
+
}).then((response) => this.get(response));
|
|
1760
|
+
}
|
|
1761
|
+
/**
|
|
1762
|
+
* Get asset metadata
|
|
1763
|
+
* @param assetId - Asset identifier
|
|
1764
|
+
*/
|
|
1765
|
+
async getMetadata(assetId) {
|
|
1766
|
+
try {
|
|
1767
|
+
return await fetchWithError(`${this.venue.baseUrl}/api/v1/assets/${assetId}`);
|
|
1768
|
+
} catch (error) {
|
|
1769
|
+
if (error instanceof NotFoundError) {
|
|
1770
|
+
throw new AssetNotFoundError(assetId);
|
|
1771
|
+
}
|
|
1772
|
+
throw error;
|
|
1773
|
+
}
|
|
1774
|
+
}
|
|
1775
|
+
/**
|
|
1776
|
+
* Put content to asset
|
|
1777
|
+
* @param assetId - Asset identifier
|
|
1778
|
+
* @param content - Content to upload
|
|
1779
|
+
* @returns The content hash returned by the server
|
|
1780
|
+
*/
|
|
1781
|
+
async putContent(assetId, content) {
|
|
1782
|
+
try {
|
|
1783
|
+
return await fetchWithError(`${this.venue.baseUrl}/api/v1/assets/${assetId}/content`, {
|
|
1784
|
+
method: "PUT",
|
|
1785
|
+
headers: this._buildHeaders(),
|
|
1786
|
+
body: content
|
|
1787
|
+
});
|
|
1788
|
+
} catch (error) {
|
|
1789
|
+
if (error instanceof NotFoundError) {
|
|
1790
|
+
throw new AssetNotFoundError(assetId);
|
|
1791
|
+
}
|
|
1792
|
+
throw error;
|
|
1793
|
+
}
|
|
1794
|
+
}
|
|
1795
|
+
/**
|
|
1796
|
+
* Get asset content
|
|
1797
|
+
* @param assetId - Asset identifier
|
|
1798
|
+
*/
|
|
1799
|
+
async getContent(assetId) {
|
|
1800
|
+
try {
|
|
1801
|
+
const response = await fetchStreamWithError(`${this.venue.baseUrl}/api/v1/assets/${assetId}/content`);
|
|
1802
|
+
return response.body;
|
|
1803
|
+
} catch (error) {
|
|
1804
|
+
if (error instanceof NotFoundError) {
|
|
1805
|
+
throw new AssetNotFoundError(assetId);
|
|
1806
|
+
}
|
|
1807
|
+
throw error;
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
/**
|
|
1811
|
+
* Clear the asset cache.
|
|
1812
|
+
*/
|
|
1813
|
+
clearCache() {
|
|
1814
|
+
cache2.clear();
|
|
1815
|
+
}
|
|
1816
|
+
_buildHeaders() {
|
|
1817
|
+
const headers = { "Content-Type": "application/json" };
|
|
1818
|
+
this.venue.auth.apply(headers);
|
|
1819
|
+
return headers;
|
|
1820
|
+
}
|
|
1821
|
+
};
|
|
1822
|
+
|
|
1823
|
+
// src/OperationManager.ts
|
|
1824
|
+
var OperationManager = class {
|
|
1825
|
+
constructor(venue) {
|
|
1826
|
+
this.venue = venue;
|
|
1827
|
+
}
|
|
1828
|
+
/**
|
|
1829
|
+
* List all named operations available on this venue
|
|
1830
|
+
*/
|
|
1831
|
+
async list() {
|
|
1832
|
+
return fetchWithError(`${this.venue.baseUrl}/api/v1/operations`);
|
|
1833
|
+
}
|
|
1834
|
+
/**
|
|
1835
|
+
* Get details of a named operation
|
|
1836
|
+
* @param name - Operation name (e.g., "test:echo")
|
|
1837
|
+
*/
|
|
1838
|
+
async get(name) {
|
|
1839
|
+
return fetchWithError(`${this.venue.baseUrl}/api/v1/operations/${name}`);
|
|
1840
|
+
}
|
|
1841
|
+
/**
|
|
1842
|
+
* Execute an operation and wait for the result
|
|
1843
|
+
* @param assetId - Operation asset ID or named operation
|
|
1844
|
+
* @param input - Operation input parameters
|
|
1845
|
+
* @param options - Invoke options (e.g., ucans)
|
|
1846
|
+
*/
|
|
1847
|
+
async run(assetId, input, options) {
|
|
1848
|
+
const job = await this.invoke(assetId, input, options);
|
|
1849
|
+
return job.result();
|
|
1850
|
+
}
|
|
1851
|
+
/**
|
|
1852
|
+
* Execute an operation and return a Job for tracking
|
|
1853
|
+
* @param assetId - Operation asset ID or named operation
|
|
1854
|
+
* @param input - Operation input parameters
|
|
1855
|
+
* @param options - Invoke options (e.g., ucans)
|
|
196
1856
|
*/
|
|
197
|
-
async
|
|
198
|
-
|
|
1857
|
+
async invoke(assetId, input, options) {
|
|
1858
|
+
const payload = {
|
|
1859
|
+
operation: assetId,
|
|
1860
|
+
input
|
|
1861
|
+
};
|
|
1862
|
+
if (options?.ucans) {
|
|
1863
|
+
payload.ucans = options.ucans;
|
|
1864
|
+
}
|
|
1865
|
+
const response = await fetchWithError(`${this.venue.baseUrl}/api/v1/invoke`, {
|
|
1866
|
+
method: "POST",
|
|
1867
|
+
headers: this._buildHeaders(),
|
|
1868
|
+
body: JSON.stringify(payload)
|
|
1869
|
+
});
|
|
1870
|
+
return new Job(response?.id, this.venue, response);
|
|
1871
|
+
}
|
|
1872
|
+
_buildHeaders() {
|
|
1873
|
+
const headers = { "Content-Type": "application/json" };
|
|
1874
|
+
this.venue.auth.apply(headers);
|
|
1875
|
+
return headers;
|
|
1876
|
+
}
|
|
1877
|
+
};
|
|
1878
|
+
|
|
1879
|
+
// src/WorkspaceManager.ts
|
|
1880
|
+
var WorkspaceManager = class {
|
|
1881
|
+
constructor(venue) {
|
|
1882
|
+
this.venue = venue;
|
|
1883
|
+
}
|
|
1884
|
+
async read(path, maxSize) {
|
|
1885
|
+
return this.venue.operations.run("covia:read", { path, maxSize });
|
|
1886
|
+
}
|
|
1887
|
+
async write(path, value) {
|
|
1888
|
+
return this.venue.operations.run("covia:write", { path, value });
|
|
1889
|
+
}
|
|
1890
|
+
async delete(path) {
|
|
1891
|
+
return this.venue.operations.run("covia:delete", { path });
|
|
1892
|
+
}
|
|
1893
|
+
async append(path, value) {
|
|
1894
|
+
return this.venue.operations.run("covia:append", { path, value });
|
|
1895
|
+
}
|
|
1896
|
+
async list(path, limit, offset) {
|
|
1897
|
+
return this.venue.operations.run("covia:list", { path, limit, offset });
|
|
1898
|
+
}
|
|
1899
|
+
async slice(path, offset, limit) {
|
|
1900
|
+
return this.venue.operations.run("covia:slice", { path, offset, limit });
|
|
1901
|
+
}
|
|
1902
|
+
async functions() {
|
|
1903
|
+
return this.venue.operations.run("covia:functions", {});
|
|
1904
|
+
}
|
|
1905
|
+
async describe(name) {
|
|
1906
|
+
return this.venue.operations.run("covia:describe", { name });
|
|
1907
|
+
}
|
|
1908
|
+
async adapters() {
|
|
1909
|
+
return this.venue.operations.run("covia:adapters", {});
|
|
1910
|
+
}
|
|
1911
|
+
};
|
|
1912
|
+
|
|
1913
|
+
// src/UCANManager.ts
|
|
1914
|
+
var UCANManager = class {
|
|
1915
|
+
constructor(venue) {
|
|
1916
|
+
this.venue = venue;
|
|
1917
|
+
}
|
|
1918
|
+
async issue(aud, att, exp) {
|
|
1919
|
+
return this.venue.operations.run("ucan:issue", { aud, att, exp });
|
|
199
1920
|
}
|
|
200
1921
|
};
|
|
201
1922
|
|
|
202
|
-
// src/
|
|
1923
|
+
// src/SecretManager.ts
|
|
1924
|
+
var SecretManager = class {
|
|
1925
|
+
constructor(venue) {
|
|
1926
|
+
this.venue = venue;
|
|
1927
|
+
}
|
|
1928
|
+
async set(name, value) {
|
|
1929
|
+
return this.venue.operations.run("secret:set", { name, value });
|
|
1930
|
+
}
|
|
1931
|
+
/**
|
|
1932
|
+
* Extract a secret value by name.
|
|
1933
|
+
* NOTE: This operation requires a UCAN capability grant. The backend
|
|
1934
|
+
* may reject requests that lack the appropriate capability proof.
|
|
1935
|
+
*/
|
|
1936
|
+
async extract(name) {
|
|
1937
|
+
return this.venue.operations.run("secret:extract", { name });
|
|
1938
|
+
}
|
|
1939
|
+
async list() {
|
|
1940
|
+
return this.venue.listSecrets();
|
|
1941
|
+
}
|
|
1942
|
+
async put(name, value) {
|
|
1943
|
+
return this.venue.putSecret(name, value);
|
|
1944
|
+
}
|
|
1945
|
+
async delete(name) {
|
|
1946
|
+
return this.venue.deleteSecret(name);
|
|
1947
|
+
}
|
|
1948
|
+
};
|
|
203
1949
|
var webResolver = getResolver();
|
|
204
1950
|
var resolver = new Resolver(webResolver);
|
|
205
|
-
var cache2 = /* @__PURE__ */ new Map();
|
|
206
1951
|
var Venue = class _Venue {
|
|
1952
|
+
get agents() {
|
|
1953
|
+
return this._agents ?? (this._agents = new AgentManager(this));
|
|
1954
|
+
}
|
|
1955
|
+
get jobs() {
|
|
1956
|
+
return this._jobs ?? (this._jobs = new JobManager(this));
|
|
1957
|
+
}
|
|
1958
|
+
get assets() {
|
|
1959
|
+
return this._assets ?? (this._assets = new AssetManager(this));
|
|
1960
|
+
}
|
|
1961
|
+
get operations() {
|
|
1962
|
+
return this._operations ?? (this._operations = new OperationManager(this));
|
|
1963
|
+
}
|
|
1964
|
+
get workspace() {
|
|
1965
|
+
return this._workspace ?? (this._workspace = new WorkspaceManager(this));
|
|
1966
|
+
}
|
|
1967
|
+
get ucan() {
|
|
1968
|
+
return this._ucan ?? (this._ucan = new UCANManager(this));
|
|
1969
|
+
}
|
|
1970
|
+
get secrets() {
|
|
1971
|
+
return this._secrets ?? (this._secrets = new SecretManager(this));
|
|
1972
|
+
}
|
|
207
1973
|
constructor(options = {}) {
|
|
208
1974
|
this.baseUrl = options.baseUrl || "";
|
|
209
1975
|
this.venueId = options.venueId || "";
|
|
210
|
-
this.
|
|
1976
|
+
this.auth = options.auth || new NoAuth();
|
|
211
1977
|
this.metadata = {
|
|
212
1978
|
name: options.name || "default",
|
|
213
1979
|
description: options.description || ""
|
|
@@ -219,13 +1985,13 @@ var Venue = class _Venue {
|
|
|
219
1985
|
* @param credentials - Optional credentials for venue authentication
|
|
220
1986
|
* @returns {Promise<Venue>} A new Venue instance configured appropriately
|
|
221
1987
|
*/
|
|
222
|
-
static async connect(venueId,
|
|
1988
|
+
static async connect(venueId, auth) {
|
|
223
1989
|
if (venueId instanceof _Venue) {
|
|
224
1990
|
return new _Venue({
|
|
225
1991
|
baseUrl: venueId.baseUrl,
|
|
226
1992
|
venueId: venueId.venueId,
|
|
227
1993
|
name: venueId.metadata.name,
|
|
228
|
-
|
|
1994
|
+
auth
|
|
229
1995
|
});
|
|
230
1996
|
}
|
|
231
1997
|
if (typeof venueId === "string") {
|
|
@@ -252,77 +2018,33 @@ var Venue = class _Venue {
|
|
|
252
2018
|
baseUrl,
|
|
253
2019
|
venueId: data.did,
|
|
254
2020
|
name: data.name,
|
|
255
|
-
|
|
2021
|
+
auth
|
|
256
2022
|
});
|
|
257
2023
|
}
|
|
258
2024
|
throw new CoviaError("Invalid venue ID parameter. Must be a string (URL/DNS) or Venue instance.");
|
|
259
2025
|
}
|
|
260
2026
|
/**
|
|
261
|
-
*
|
|
262
|
-
* @param assetData - Asset configuration
|
|
263
|
-
* @returns {Promise<Asset>}
|
|
264
|
-
*/
|
|
265
|
-
async createAsset(assetData) {
|
|
266
|
-
return fetchWithError(`${this.baseUrl}/api/v1/assets/`, {
|
|
267
|
-
method: "POST",
|
|
268
|
-
headers: this.setCredentialsInHeader(),
|
|
269
|
-
body: JSON.stringify(assetData)
|
|
270
|
-
}).then((response) => {
|
|
271
|
-
return this.getAsset(response);
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
/**
|
|
275
|
-
* Read stream from asset
|
|
276
|
-
* @param reader - ReadableStreamDefaultReader
|
|
277
|
-
*/
|
|
278
|
-
async readStream(reader) {
|
|
279
|
-
while (true) {
|
|
280
|
-
const { done, value } = await reader.read();
|
|
281
|
-
if (done) {
|
|
282
|
-
break;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
/**
|
|
287
|
-
* Get asset by ID
|
|
2027
|
+
* Get asset by ID (convenience delegate to venue.assets.get)
|
|
288
2028
|
* @param assetId - Asset identifier
|
|
289
2029
|
* @returns {Promise<Asset>} Returns either an Operation or DataAsset based on the asset's metadata
|
|
290
2030
|
*/
|
|
291
2031
|
async getAsset(assetId) {
|
|
292
|
-
|
|
293
|
-
const cachedData = cache2.get(assetId);
|
|
294
|
-
if (cachedData.metadata?.operation) {
|
|
295
|
-
return new Operation(assetId, this, cachedData);
|
|
296
|
-
} else {
|
|
297
|
-
return new DataAsset(assetId, this, cachedData);
|
|
298
|
-
}
|
|
299
|
-
} else {
|
|
300
|
-
return fetchWithError(`${this.baseUrl}/api/v1/assets/${assetId}`).then((data) => {
|
|
301
|
-
cache2.set(assetId, data);
|
|
302
|
-
if (data.metadata?.operation) {
|
|
303
|
-
return new Operation(assetId, this, data);
|
|
304
|
-
} else {
|
|
305
|
-
return new DataAsset(assetId, this, data);
|
|
306
|
-
}
|
|
307
|
-
});
|
|
308
|
-
}
|
|
2032
|
+
return this.assets.get(assetId);
|
|
309
2033
|
}
|
|
310
2034
|
/**
|
|
311
|
-
*
|
|
312
|
-
* @
|
|
2035
|
+
* List assets with pagination support (convenience delegate to venue.assets.list)
|
|
2036
|
+
* @param options - Pagination options (offset, limit)
|
|
2037
|
+
* @returns {Promise<AssetList>} Paginated list of asset IDs with metadata
|
|
313
2038
|
*/
|
|
314
|
-
|
|
315
|
-
return
|
|
316
|
-
const assetPromises = assetIds.items.map((assetId) => this.getAsset(assetId));
|
|
317
|
-
return Promise.all(assetPromises);
|
|
318
|
-
});
|
|
2039
|
+
async listAssets(options = {}) {
|
|
2040
|
+
return this.assets.list(options);
|
|
319
2041
|
}
|
|
320
2042
|
/**
|
|
321
|
-
*
|
|
2043
|
+
* List all jobs
|
|
322
2044
|
* @returns {Promise<string[]>}
|
|
323
2045
|
*/
|
|
324
|
-
async
|
|
325
|
-
return
|
|
2046
|
+
async listJobs() {
|
|
2047
|
+
return this.jobs.list();
|
|
326
2048
|
}
|
|
327
2049
|
/**
|
|
328
2050
|
* Get job by ID
|
|
@@ -330,116 +2052,85 @@ var Venue = class _Venue {
|
|
|
330
2052
|
* @returns {Promise<Job>}
|
|
331
2053
|
*/
|
|
332
2054
|
async getJob(jobId) {
|
|
333
|
-
return
|
|
334
|
-
|
|
2055
|
+
return this.jobs.get(jobId);
|
|
2056
|
+
}
|
|
2057
|
+
/**
|
|
2058
|
+
* List secret names
|
|
2059
|
+
* @returns {Promise<string[]>}
|
|
2060
|
+
*/
|
|
2061
|
+
async listSecrets() {
|
|
2062
|
+
const result = await fetchWithError(`${this.baseUrl}/api/v1/secrets`, {
|
|
2063
|
+
headers: this._buildHeaders()
|
|
335
2064
|
});
|
|
2065
|
+
return result.items;
|
|
336
2066
|
}
|
|
337
2067
|
/**
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
async
|
|
343
|
-
|
|
344
|
-
|
|
2068
|
+
* Store a secret value
|
|
2069
|
+
* @param name - Secret name
|
|
2070
|
+
* @param value - Secret value
|
|
2071
|
+
*/
|
|
2072
|
+
async putSecret(name, value) {
|
|
2073
|
+
await fetchWithError(`${this.baseUrl}/api/v1/secrets/${encodeURIComponent(name)}`, {
|
|
2074
|
+
method: "PUT",
|
|
2075
|
+
headers: this._buildHeaders(),
|
|
2076
|
+
body: JSON.stringify({ value })
|
|
345
2077
|
});
|
|
346
2078
|
}
|
|
347
2079
|
/**
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
2080
|
+
* Delete a secret
|
|
2081
|
+
* @param name - Secret name
|
|
2082
|
+
*/
|
|
2083
|
+
async deleteSecret(name) {
|
|
2084
|
+
await fetchStreamWithError(`${this.baseUrl}/api/v1/secrets/${encodeURIComponent(name)}`, {
|
|
2085
|
+
method: "DELETE",
|
|
2086
|
+
headers: this._buildHeaders()
|
|
355
2087
|
});
|
|
356
2088
|
}
|
|
357
2089
|
/**
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
2090
|
+
* Get venue status
|
|
2091
|
+
* @returns {Promise<StatusData>}
|
|
2092
|
+
*/
|
|
2093
|
+
status() {
|
|
362
2094
|
return fetchWithError(`${this.baseUrl}/api/v1/status`);
|
|
363
2095
|
}
|
|
364
2096
|
/**
|
|
365
|
-
* Get
|
|
366
|
-
* @returns {Promise<
|
|
2097
|
+
* Get the full DID document for this venue
|
|
2098
|
+
* @returns {Promise<DIDDocument>}
|
|
367
2099
|
*/
|
|
368
|
-
async
|
|
369
|
-
return
|
|
2100
|
+
async didDocument() {
|
|
2101
|
+
return fetchWithError(`${this.baseUrl}/.well-known/did.json`);
|
|
370
2102
|
}
|
|
371
2103
|
/**
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
const response = await fetchStreamWithError(`${this.baseUrl}/api/v1/assets/${assetId}/content`, {
|
|
378
|
-
method: "PUT",
|
|
379
|
-
headers: this.setCredentialsInHeader(),
|
|
380
|
-
body: content
|
|
381
|
-
});
|
|
382
|
-
return response.body;
|
|
2104
|
+
* Get MCP (Model Context Protocol) discovery information
|
|
2105
|
+
* @returns {Promise<MCPDiscovery>}
|
|
2106
|
+
*/
|
|
2107
|
+
async mcpDiscovery() {
|
|
2108
|
+
return fetchWithError(`${this.baseUrl}/.well-known/mcp`);
|
|
383
2109
|
}
|
|
384
2110
|
/**
|
|
385
|
-
* Get
|
|
386
|
-
* @returns {Promise<
|
|
2111
|
+
* Get the A2A (Agent-to-Agent) agent card
|
|
2112
|
+
* @returns {Promise<AgentCard>}
|
|
387
2113
|
*/
|
|
388
|
-
async
|
|
389
|
-
|
|
390
|
-
return response.body;
|
|
2114
|
+
async agentCard() {
|
|
2115
|
+
return fetchWithError(`${this.baseUrl}/.well-known/agent-card.json`);
|
|
391
2116
|
}
|
|
392
2117
|
/**
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
const payload = {
|
|
399
|
-
operation: assetId,
|
|
400
|
-
input
|
|
401
|
-
};
|
|
402
|
-
try {
|
|
403
|
-
const response = await fetchWithError(`${this.baseUrl}/api/v1/invoke/`, {
|
|
404
|
-
method: "POST",
|
|
405
|
-
headers: this.setCredentialsInHeader(),
|
|
406
|
-
body: JSON.stringify(payload)
|
|
407
|
-
});
|
|
408
|
-
return response?.output;
|
|
409
|
-
} catch (error) {
|
|
410
|
-
throw error;
|
|
411
|
-
}
|
|
2118
|
+
* Close the venue and release resources.
|
|
2119
|
+
* Clears cached asset data for this venue.
|
|
2120
|
+
*/
|
|
2121
|
+
close() {
|
|
2122
|
+
this.assets.clearCache();
|
|
412
2123
|
}
|
|
413
2124
|
/**
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
async invoke(assetId, input) {
|
|
419
|
-
const payload = {
|
|
420
|
-
operation: assetId,
|
|
421
|
-
input
|
|
422
|
-
};
|
|
423
|
-
try {
|
|
424
|
-
const response = await fetchWithError(`${this.baseUrl}/api/v1/invoke/`, {
|
|
425
|
-
method: "POST",
|
|
426
|
-
headers: this.setCredentialsInHeader(),
|
|
427
|
-
body: JSON.stringify(payload)
|
|
428
|
-
});
|
|
429
|
-
return new Job(response?.id, this, response);
|
|
430
|
-
} catch (error) {
|
|
431
|
-
throw error;
|
|
432
|
-
}
|
|
2125
|
+
* Disposable support — allows `using venue = await Grid.connect(...)` in TS 5.2+.
|
|
2126
|
+
*/
|
|
2127
|
+
[Symbol.dispose]() {
|
|
2128
|
+
this.close();
|
|
433
2129
|
}
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
"X-Covia-User": this.credentials.userId
|
|
439
|
-
};
|
|
440
|
-
} else {
|
|
441
|
-
return { "Content-Type": "application/json" };
|
|
442
|
-
}
|
|
2130
|
+
_buildHeaders() {
|
|
2131
|
+
const headers = { "Content-Type": "application/json" };
|
|
2132
|
+
this.auth.apply(headers);
|
|
2133
|
+
return headers;
|
|
443
2134
|
}
|
|
444
2135
|
};
|
|
445
2136
|
|
|
@@ -449,15 +2140,24 @@ var Grid = class {
|
|
|
449
2140
|
/**
|
|
450
2141
|
* Static method to connect to a venue
|
|
451
2142
|
* @param venueId - Can be a HTTP base URL, DNS name, or existing Venue instance
|
|
2143
|
+
* @param auth - Optional authentication provider (BearerAuth, KeyPairAuth, etc.)
|
|
452
2144
|
* @returns {Promise<Venue>} A new Venue instance configured appropriately
|
|
453
2145
|
*/
|
|
454
|
-
static async connect(venueId,
|
|
2146
|
+
static async connect(venueId, auth) {
|
|
455
2147
|
if (cache3.has(venueId))
|
|
456
2148
|
return Promise.resolve(cache3.get(venueId));
|
|
457
|
-
const connectedVenue = await Venue.connect(venueId,
|
|
2149
|
+
const connectedVenue = await Venue.connect(venueId, auth);
|
|
458
2150
|
cache3.set(venueId, connectedVenue);
|
|
459
2151
|
return Promise.resolve(connectedVenue);
|
|
460
2152
|
}
|
|
461
2153
|
};
|
|
2154
|
+
/*! Bundled license information:
|
|
2155
|
+
|
|
2156
|
+
@noble/ed25519/index.js:
|
|
2157
|
+
(*! noble-ed25519 - MIT License (c) 2019 Paul Miller (paulmillr.com) *)
|
|
2158
|
+
|
|
2159
|
+
@noble/hashes/esm/utils.js:
|
|
2160
|
+
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
2161
|
+
*/
|
|
462
2162
|
|
|
463
|
-
export { Asset, CoviaError, CredentialsHTTP, DataAsset, Grid, Job, Operation, RunStatus, Venue, fetchStreamWithError, fetchWithError, getAssetIdFromPath, getAssetIdFromVenueId, getParsedAssetId, isJobComplete, isJobFinished, isJobPaused };
|
|
2163
|
+
export { AgentManager, AgentStatus, Asset, AssetManager, AssetNotFoundError, Auth, BearerAuth, CoviaConnectionError, CoviaError, CoviaTimeoutError, CredentialsHTTP, DataAsset, Grid, GridError, Job, JobFailedError, JobManager, JobNotFoundError, JobStatus, KeyPairAuth, NoAuth, NotFoundError, Operation, OperationManager, RunStatus, SecretManager, UCANManager, Venue, WorkspaceManager, createSSEEvent, decodePublicKey, didFromPublicKey, encodePublicKey, fetchStreamWithError, fetchWithError, generateKeyPair, getAssetIdFromPath, getAssetIdFromVenueId, getParsedAssetId, hexToPrivateKey, isJobComplete, isJobFinished, isJobPaused, logger, parseSSEStream, privateKeyToHex };
|