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