@useopentab/cli 0.0.0-stage → 0.1.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.
@@ -0,0 +1,2221 @@
1
+ // packages/codec/src/bytes.ts
2
+ var CodecError = class extends Error {
3
+ name = "CodecError";
4
+ };
5
+ var U8_MAX = 255;
6
+ var U16_MAX = 65535;
7
+ var U32_MAX = 4294967295;
8
+ var U64_MAX = (1n << 64n) - 1n;
9
+ var HEX_RE = /^[0-9a-fA-F]*$/;
10
+ function toHex(bytes) {
11
+ let out = "";
12
+ for (const b of bytes) out += b.toString(16).padStart(2, "0");
13
+ return out;
14
+ }
15
+ function fromHex(hex, expectedLength) {
16
+ const clean = hex.startsWith("0x") || hex.startsWith("0X") ? hex.slice(2) : hex;
17
+ if (clean.length % 2 !== 0 || !HEX_RE.test(clean)) {
18
+ throw new CodecError(`invalid hex string (length ${clean.length})`);
19
+ }
20
+ const out = new Uint8Array(clean.length / 2);
21
+ for (let i = 0; i < out.length; i++) {
22
+ out[i] = Number.parseInt(clean.slice(2 * i, 2 * i + 2), 16);
23
+ }
24
+ if (expectedLength !== void 0 && out.length !== expectedLength) {
25
+ throw new CodecError(`expected ${expectedLength} bytes of hex, got ${out.length}`);
26
+ }
27
+ return out;
28
+ }
29
+ var LONE_SURROGATE = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/;
30
+ var encoder = new TextEncoder();
31
+ var decoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
32
+ function utf8(text) {
33
+ if (LONE_SURROGATE.test(text)) throw new CodecError("string contains a lone surrogate");
34
+ return encoder.encode(text);
35
+ }
36
+ function fromUtf8(bytes) {
37
+ try {
38
+ return decoder.decode(bytes);
39
+ } catch {
40
+ throw new CodecError("invalid UTF-8");
41
+ }
42
+ }
43
+ function ascii(text) {
44
+ const out = new Uint8Array(text.length);
45
+ for (let i = 0; i < text.length; i++) {
46
+ const c = text.charCodeAt(i);
47
+ if (c > 127) throw new CodecError(`non-ASCII character in tag ${JSON.stringify(text)}`);
48
+ out[i] = c;
49
+ }
50
+ return out;
51
+ }
52
+ function concatBytes(...parts) {
53
+ let len = 0;
54
+ for (const p of parts) len += p.length;
55
+ const out = new Uint8Array(len);
56
+ let off = 0;
57
+ for (const p of parts) {
58
+ out.set(p, off);
59
+ off += p.length;
60
+ }
61
+ return out;
62
+ }
63
+ function bytesEqual(a, b) {
64
+ if (a.length !== b.length) return false;
65
+ for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
66
+ return true;
67
+ }
68
+ function checkInt(value, max, what) {
69
+ if (!Number.isInteger(value) || value < 0 || value > max) {
70
+ throw new CodecError(`${what} out of range: ${value}`);
71
+ }
72
+ return value;
73
+ }
74
+ function toU64(value, what = "u64") {
75
+ let v;
76
+ if (typeof value === "number") {
77
+ if (!Number.isSafeInteger(value)) throw new CodecError(`${what} is not a safe integer: ${value}`);
78
+ v = BigInt(value);
79
+ } else if (typeof value === "bigint") {
80
+ v = value;
81
+ } else {
82
+ throw new CodecError(`${what} must be a bigint or number`);
83
+ }
84
+ if (v < 0n || v > U64_MAX) throw new CodecError(`${what} out of range: ${v}`);
85
+ return v;
86
+ }
87
+ var Writer = class {
88
+ #buf = new Uint8Array(256);
89
+ #view = new DataView(this.#buf.buffer);
90
+ #len = 0;
91
+ get length() {
92
+ return this.#len;
93
+ }
94
+ #reserve(n) {
95
+ const need = this.#len + n;
96
+ if (need > this.#buf.length) {
97
+ let cap = this.#buf.length * 2;
98
+ while (cap < need) cap *= 2;
99
+ const next = new Uint8Array(cap);
100
+ next.set(this.#buf.subarray(0, this.#len));
101
+ this.#buf = next;
102
+ this.#view = new DataView(next.buffer);
103
+ }
104
+ const at = this.#len;
105
+ this.#len = need;
106
+ return at;
107
+ }
108
+ /** Raw bytes, no length prefix. */
109
+ raw(bytes) {
110
+ const at = this.#reserve(bytes.length);
111
+ this.#buf.set(bytes, at);
112
+ return this;
113
+ }
114
+ /** Raw bytes that must have exactly `length` bytes. */
115
+ fixed(bytes, length, what) {
116
+ if (!(bytes instanceof Uint8Array)) throw new CodecError(`${what} must be a Uint8Array`);
117
+ if (bytes.length !== length) {
118
+ throw new CodecError(`${what} must be ${length} bytes, got ${bytes.length}`);
119
+ }
120
+ return this.raw(bytes);
121
+ }
122
+ // Each writer reserves space BEFORE touching #view: #reserve may replace the buffer and
123
+ // the view, so `this.#view.setX(this.#reserve(n), ...)` would write into the stale view.
124
+ u8(value, what = "u8") {
125
+ const v = checkInt(value, U8_MAX, what);
126
+ const at = this.#reserve(1);
127
+ this.#view.setUint8(at, v);
128
+ return this;
129
+ }
130
+ u16(value, what = "u16") {
131
+ const v = checkInt(value, U16_MAX, what);
132
+ const at = this.#reserve(2);
133
+ this.#view.setUint16(at, v, true);
134
+ return this;
135
+ }
136
+ u32(value, what = "u32") {
137
+ const v = checkInt(value, U32_MAX, what);
138
+ const at = this.#reserve(4);
139
+ this.#view.setUint32(at, v, true);
140
+ return this;
141
+ }
142
+ u64(value, what = "u64") {
143
+ const v = toU64(value, what);
144
+ const at = this.#reserve(8);
145
+ this.#view.setBigUint64(at, v, true);
146
+ return this;
147
+ }
148
+ /** `u32` byte length, then the bytes. */
149
+ bytestring(bytes, what = "bytestring") {
150
+ if (!(bytes instanceof Uint8Array)) throw new CodecError(`${what} must be a Uint8Array`);
151
+ this.u32(bytes.length, `${what} length`);
152
+ return this.raw(bytes);
153
+ }
154
+ /** `u32` byte length, then UTF-8. */
155
+ string(text, what = "string") {
156
+ if (typeof text !== "string") throw new CodecError(`${what} must be a string`);
157
+ return this.bytestring(utf8(text), what);
158
+ }
159
+ /** A copy of the bytes written so far. */
160
+ toBytes() {
161
+ return this.#buf.slice(0, this.#len);
162
+ }
163
+ };
164
+ var Reader = class {
165
+ #bytes;
166
+ #view;
167
+ #pos = 0;
168
+ constructor(bytes) {
169
+ if (!(bytes instanceof Uint8Array)) throw new CodecError("Reader expects a Uint8Array");
170
+ this.#bytes = bytes;
171
+ this.#view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
172
+ }
173
+ get offset() {
174
+ return this.#pos;
175
+ }
176
+ get remaining() {
177
+ return this.#bytes.length - this.#pos;
178
+ }
179
+ #advance(n, what) {
180
+ if (n > this.remaining) {
181
+ throw new CodecError(
182
+ `unexpected end of input reading ${what}: need ${n} bytes at offset ${this.#pos}, have ${this.remaining}`
183
+ );
184
+ }
185
+ const at = this.#pos;
186
+ this.#pos += n;
187
+ return at;
188
+ }
189
+ /** A copy of the next `n` bytes. */
190
+ raw(n, what = "bytes") {
191
+ const at = this.#advance(n, what);
192
+ return this.#bytes.slice(at, at + n);
193
+ }
194
+ u8(what = "u8") {
195
+ return this.#view.getUint8(this.#advance(1, what));
196
+ }
197
+ u16(what = "u16") {
198
+ return this.#view.getUint16(this.#advance(2, what), true);
199
+ }
200
+ u32(what = "u32") {
201
+ return this.#view.getUint32(this.#advance(4, what), true);
202
+ }
203
+ u64(what = "u64") {
204
+ return this.#view.getBigUint64(this.#advance(8, what), true);
205
+ }
206
+ bytestring(what = "bytestring") {
207
+ const n = this.u32(`${what} length`);
208
+ return this.raw(n, what);
209
+ }
210
+ string(what = "string") {
211
+ return fromUtf8(this.bytestring(what));
212
+ }
213
+ /** Consumes `expected` exactly or throws. */
214
+ expect(expected, what) {
215
+ const got = this.raw(expected.length, what);
216
+ if (!bytesEqual(got, expected)) throw new CodecError(`${what} mismatch`);
217
+ }
218
+ /** Throws if any bytes are left. */
219
+ end(what = "input") {
220
+ if (this.remaining !== 0) {
221
+ throw new CodecError(`${this.remaining} trailing byte(s) after ${what}`);
222
+ }
223
+ }
224
+ };
225
+
226
+ // packages/codec/src/crypto.ts
227
+ import * as ed from "@noble/ed25519";
228
+ import { hmac } from "@noble/hashes/hmac.js";
229
+ import { sha256 as nobleSha256, sha512 } from "@noble/hashes/sha2.js";
230
+ if (ed.hashes.sha512 === void 0) {
231
+ ed.hashes.sha512 = (message) => sha512(message);
232
+ }
233
+ var ED25519_PUBLIC_KEY_LENGTH = 32;
234
+ var ED25519_SEED_LENGTH = 32;
235
+ var ED25519_SIGNATURE_LENGTH = 64;
236
+ var HASH_LENGTH = 32;
237
+ function sha256(...parts) {
238
+ const h = nobleSha256.create();
239
+ for (const p of parts) h.update(p);
240
+ return h.digest();
241
+ }
242
+ function hmacSha256(key, message) {
243
+ return hmac(nobleSha256, key, message);
244
+ }
245
+ function checkSeed(seed) {
246
+ if (!(seed instanceof Uint8Array) || seed.length !== ED25519_SEED_LENGTH) {
247
+ throw new CodecError(`ed25519 secret seed must be ${ED25519_SEED_LENGTH} bytes`);
248
+ }
249
+ }
250
+ function ed25519PublicKey(seed) {
251
+ checkSeed(seed);
252
+ return ed.getPublicKey(seed);
253
+ }
254
+ function ed25519Sign(message, seed) {
255
+ checkSeed(seed);
256
+ return ed.sign(message, seed);
257
+ }
258
+ function ed25519Verify(signature, message, publicKey, options = {}) {
259
+ if (!(signature instanceof Uint8Array) || !(message instanceof Uint8Array) || !(publicKey instanceof Uint8Array) || signature.length !== ED25519_SIGNATURE_LENGTH || publicKey.length !== ED25519_PUBLIC_KEY_LENGTH) {
260
+ return false;
261
+ }
262
+ try {
263
+ return ed.verify(signature, message, publicKey, { zip215: options.strict !== true });
264
+ } catch {
265
+ return false;
266
+ }
267
+ }
268
+ async function ed25519PublicKeyAsync(seed) {
269
+ checkSeed(seed);
270
+ return ed.getPublicKeyAsync(seed);
271
+ }
272
+ async function ed25519SignAsync(message, seed) {
273
+ checkSeed(seed);
274
+ return ed.signAsync(message, seed);
275
+ }
276
+ async function ed25519VerifyAsync(signature, message, publicKey, options = {}) {
277
+ if (!(signature instanceof Uint8Array) || !(message instanceof Uint8Array) || !(publicKey instanceof Uint8Array) || signature.length !== ED25519_SIGNATURE_LENGTH || publicKey.length !== ED25519_PUBLIC_KEY_LENGTH) {
278
+ return false;
279
+ }
280
+ try {
281
+ return await ed.verifyAsync(signature, message, publicKey, { zip215: options.strict !== true });
282
+ } catch {
283
+ return false;
284
+ }
285
+ }
286
+
287
+ // packages/codec/src/address.ts
288
+ var ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
289
+ var ALPHABET_INDEX = new Map([...ALPHABET].map((c, i) => [c, i]));
290
+ function base58Encode(bytes) {
291
+ let zeros = 0;
292
+ while (zeros < bytes.length && bytes[zeros] === 0) zeros++;
293
+ let n = 0n;
294
+ for (const b of bytes) n = n << 8n | BigInt(b);
295
+ let out = "";
296
+ while (n > 0n) {
297
+ out = ALPHABET.charAt(Number(n % 58n)) + out;
298
+ n /= 58n;
299
+ }
300
+ return "1".repeat(zeros) + out;
301
+ }
302
+ function base58Decode(text) {
303
+ if (typeof text !== "string") throw new CodecError("base58 input must be a string");
304
+ let zeros = 0;
305
+ while (zeros < text.length && text[zeros] === "1") zeros++;
306
+ let n = 0n;
307
+ for (const c of text) {
308
+ const v = ALPHABET_INDEX.get(c);
309
+ if (v === void 0) throw new CodecError(`invalid base58 character ${JSON.stringify(c)}`);
310
+ n = n * 58n + BigInt(v);
311
+ }
312
+ const body = [];
313
+ while (n > 0n) {
314
+ body.push(Number(n & 0xffn));
315
+ n >>= 8n;
316
+ }
317
+ body.reverse();
318
+ const out = new Uint8Array(zeros + body.length);
319
+ out.set(body, zeros);
320
+ return out;
321
+ }
322
+ function checksum(payload) {
323
+ return sha256(sha256(payload)).subarray(0, 4);
324
+ }
325
+ function base58CheckEncode(version, data) {
326
+ if (!Number.isInteger(version) || version < 0 || version > 255) {
327
+ throw new CodecError(`invalid Base58Check version ${version}`);
328
+ }
329
+ const payload = concatBytes(Uint8Array.of(version), data);
330
+ return base58Encode(concatBytes(payload, checksum(payload)));
331
+ }
332
+ function base58CheckDecode(text) {
333
+ const raw = base58Decode(text);
334
+ if (raw.length < 5) throw new CodecError("Base58Check input too short");
335
+ const payload = raw.subarray(0, raw.length - 4);
336
+ const sum = raw.subarray(raw.length - 4);
337
+ const expected = checksum(payload);
338
+ for (let i = 0; i < 4; i++) {
339
+ if (sum[i] !== expected[i]) throw new CodecError("Base58Check checksum mismatch");
340
+ }
341
+ return { version: payload[0], data: payload.slice(1) };
342
+ }
343
+ var ACCOUNT_ADDRESS_LENGTH = 32;
344
+ var ACCOUNT_ADDRESS_VERSION = 1;
345
+ function accountAddressFromBase58(address) {
346
+ const { version, data } = base58CheckDecode(address);
347
+ if (version !== ACCOUNT_ADDRESS_VERSION) {
348
+ throw new CodecError(`account address must use version byte 1, got ${version}`);
349
+ }
350
+ if (data.length !== ACCOUNT_ADDRESS_LENGTH) {
351
+ throw new CodecError(`account address must decode to 32 bytes, got ${data.length}`);
352
+ }
353
+ return data;
354
+ }
355
+ function accountAddressToBase58(bytes) {
356
+ if (!(bytes instanceof Uint8Array) || bytes.length !== ACCOUNT_ADDRESS_LENGTH) {
357
+ throw new CodecError("account address must be 32 bytes");
358
+ }
359
+ return base58CheckEncode(ACCOUNT_ADDRESS_VERSION, bytes);
360
+ }
361
+ function isAccountAddress(address) {
362
+ try {
363
+ accountAddressFromBase58(address);
364
+ return true;
365
+ } catch {
366
+ return false;
367
+ }
368
+ }
369
+ function contractAddress(index, subindex = 0n) {
370
+ return Object.freeze({ index: toU64(index, "contract index"), subindex: toU64(subindex, "contract subindex") });
371
+ }
372
+ function formatContractAddress(address) {
373
+ return `<${address.index},${address.subindex}>`;
374
+ }
375
+ function parseContractAddress(text) {
376
+ const m = /^<?\s*(\d+)\s*,\s*(\d+)\s*>?$/.exec(text.trim());
377
+ if (!m) throw new CodecError(`invalid contract address ${JSON.stringify(text)}`);
378
+ return contractAddress(BigInt(m[1]), BigInt(m[2]));
379
+ }
380
+ function contractAddressEqual(a, b) {
381
+ return a.index === b.index && a.subindex === b.subindex;
382
+ }
383
+ function uleb128Encode(value) {
384
+ let v = toU64(value, "ULEB128 value");
385
+ const out = [];
386
+ do {
387
+ let byte = Number(v & 0x7fn);
388
+ v >>= 7n;
389
+ if (v !== 0n) byte |= 128;
390
+ out.push(byte);
391
+ } while (v !== 0n);
392
+ return Uint8Array.from(out);
393
+ }
394
+ function uleb128Decode(bytes, offset = 0) {
395
+ let value = 0n;
396
+ let shift = 0n;
397
+ for (let i = offset; i < bytes.length; i++) {
398
+ const byte = bytes[i];
399
+ value |= BigInt(byte & 127) << shift;
400
+ if (value > U64_MAX) throw new CodecError("ULEB128 value exceeds u64");
401
+ if ((byte & 128) === 0) {
402
+ if (byte === 0 && i > offset) throw new CodecError("overlong ULEB128 encoding");
403
+ return { value, next: i + 1 };
404
+ }
405
+ shift += 7n;
406
+ if (shift >= 70n) throw new CodecError("ULEB128 encoding too long");
407
+ }
408
+ throw new CodecError("unterminated ULEB128 value");
409
+ }
410
+ var TOKEN_ADDRESS_VERSION = 2;
411
+ function tokenIdU64Bytes(tokenId) {
412
+ const out = new Uint8Array(8);
413
+ new DataView(out.buffer).setBigUint64(0, toU64(tokenId, "token id"), true);
414
+ return out;
415
+ }
416
+ function tokenAddress(contract, tokenIdBytes) {
417
+ if (tokenIdBytes.length > 255) throw new CodecError("CIS-2 token ids are at most 255 bytes");
418
+ return base58CheckEncode(
419
+ TOKEN_ADDRESS_VERSION,
420
+ concatBytes(uleb128Encode(contract.index), uleb128Encode(contract.subindex), tokenIdBytes)
421
+ );
422
+ }
423
+ function agentTokenAddress(contract, tokenId) {
424
+ return tokenAddress(contract, tokenIdU64Bytes(tokenId));
425
+ }
426
+ function parseTokenAddress(address) {
427
+ const { version, data } = base58CheckDecode(address);
428
+ if (version !== TOKEN_ADDRESS_VERSION) {
429
+ throw new CodecError(`token address must use version byte 2, got ${version}`);
430
+ }
431
+ const idx = uleb128Decode(data, 0);
432
+ const sub = uleb128Decode(data, idx.next);
433
+ const tokenIdBytes = data.slice(sub.next);
434
+ const tokenId = tokenIdBytes.length === 8 ? new DataView(tokenIdBytes.buffer, tokenIdBytes.byteOffset, 8).getBigUint64(0, true) : null;
435
+ return { contract: contractAddress(idx.value, sub.value), tokenIdBytes, tokenId };
436
+ }
437
+ function caip2FromGenesis(genesis) {
438
+ if (genesis.length !== 32) throw new CodecError("genesis hash must be 32 bytes");
439
+ return `ccd:${toHex(genesis.subarray(0, 16))}`;
440
+ }
441
+ function agentCaip19(caip2, contract, tokenId) {
442
+ if (!/^ccd:[0-9a-f]{32}$/.test(caip2)) throw new CodecError(`invalid ccd CAIP-2 id ${JSON.stringify(caip2)}`);
443
+ return `${caip2}/cis-2:${agentTokenAddress(contract, tokenId)}`;
444
+ }
445
+ function parseCaip19(id) {
446
+ const m = /^(ccd:[0-9a-f]{32})\/cis-2:([1-9A-HJ-NP-Za-km-z]+)$/.exec(id);
447
+ if (!m) throw new CodecError(`invalid ccd CAIP-19 id ${JSON.stringify(id)}`);
448
+ return { caip2: m[1], token: parseTokenAddress(m[2]) };
449
+ }
450
+ var ED25519_MULTICODEC = Uint8Array.of(237, 1);
451
+ function ed25519DidKey(publicKey) {
452
+ if (publicKey.length !== 32) throw new CodecError("ed25519 public key must be 32 bytes");
453
+ return `did:key:z${base58Encode(concatBytes(ED25519_MULTICODEC, publicKey))}`;
454
+ }
455
+ function ed25519FromDidKey(did) {
456
+ if (!did.startsWith("did:key:z")) throw new CodecError("not a base58btc did:key");
457
+ const raw = base58Decode(did.slice("did:key:z".length));
458
+ if (raw.length !== 34 || raw[0] !== 237 || raw[1] !== 1) {
459
+ throw new CodecError("did:key is not an ed25519 key");
460
+ }
461
+ return raw.slice(2);
462
+ }
463
+
464
+ // packages/codec/src/codec.ts
465
+ var u8 = {
466
+ desc: { kind: "u8" },
467
+ size: 1,
468
+ write: (w, v, what) => void w.u8(v, what),
469
+ read: (r, what) => r.u8(what)
470
+ };
471
+ var u16 = {
472
+ desc: { kind: "u16" },
473
+ size: 2,
474
+ write: (w, v, what) => void w.u16(v, what),
475
+ read: (r, what) => r.u16(what)
476
+ };
477
+ var u32 = {
478
+ desc: { kind: "u32" },
479
+ size: 4,
480
+ write: (w, v, what) => void w.u32(v, what),
481
+ read: (r, what) => r.u32(what)
482
+ };
483
+ var u64 = {
484
+ desc: { kind: "u64" },
485
+ size: 8,
486
+ write: (w, v, what) => void w.u64(v, what),
487
+ read: (r, what) => r.u64(what)
488
+ };
489
+ var amount = u64;
490
+ var timestamp = u64;
491
+ var bool = {
492
+ desc: { kind: "bool" },
493
+ size: 1,
494
+ write: (w, v, what) => {
495
+ if (typeof v !== "boolean") throw new CodecError(`${what} must be a boolean`);
496
+ w.u8(v ? 1 : 0, what);
497
+ },
498
+ read: (r, what) => {
499
+ const b = r.u8(what);
500
+ if (b > 1) throw new CodecError(`${what}: invalid boolean byte ${b}`);
501
+ return b === 1;
502
+ }
503
+ };
504
+ function fixedBytes(length, role) {
505
+ return {
506
+ desc: { kind: "bytes", length, role },
507
+ size: length,
508
+ write: (w, v, what) => void w.fixed(v, length, what),
509
+ read: (r, what) => r.raw(length, what)
510
+ };
511
+ }
512
+ var hash = fixedBytes(32, "hash");
513
+ var accountAddress = fixedBytes(32, "account");
514
+ var publicKeyEd25519 = fixedBytes(32, "publicKey");
515
+ var signatureEd25519 = fixedBytes(64, "signature");
516
+ var moduleRef = fixedBytes(32, "moduleRef");
517
+ var contractAddressCodec = {
518
+ desc: { kind: "contractAddress" },
519
+ size: 16,
520
+ write: (w, v, what) => {
521
+ if (v === null || typeof v !== "object") throw new CodecError(`${what} must be a ContractAddress`);
522
+ w.u64(v.index, `${what}.index`).u64(v.subindex, `${what}.subindex`);
523
+ },
524
+ read: (r, what) => contractAddress(r.u64(`${what}.index`), r.u64(`${what}.subindex`))
525
+ };
526
+ var TOKEN_ID_U64_PREFIX = 8;
527
+ var agentTokenId = {
528
+ desc: { kind: "agentTokenId" },
529
+ size: 9,
530
+ write: (w, v, what) => void w.u8(TOKEN_ID_U64_PREFIX).u64(v, what),
531
+ read: (r, what) => {
532
+ const len = r.u8(`${what} length`);
533
+ if (len !== TOKEN_ID_U64_PREFIX) {
534
+ throw new CodecError(`${what}: expected TokenIdU64 length byte 8, got ${len}`);
535
+ }
536
+ return r.u64(what);
537
+ }
538
+ };
539
+ var string = {
540
+ desc: { kind: "string" },
541
+ size: null,
542
+ write: (w, v, what) => void w.string(v, what),
543
+ read: (r, what) => r.string(what)
544
+ };
545
+ var bytestring = {
546
+ desc: { kind: "bytestring" },
547
+ size: null,
548
+ write: (w, v, what) => void w.bytestring(v, what),
549
+ read: (r, what) => r.bytestring(what)
550
+ };
551
+ var string16 = {
552
+ desc: { kind: "string" },
553
+ size: null,
554
+ write: (w, v, what) => {
555
+ if (typeof v !== "string") throw new CodecError(`${what} must be a string`);
556
+ const bytes = utf8(v);
557
+ w.u16(bytes.length, `${what} length`).raw(bytes);
558
+ },
559
+ read: (r, what) => fromUtf8(r.raw(r.u16(`${what} length`), what))
560
+ };
561
+ var bytes16 = {
562
+ desc: { kind: "bytestring" },
563
+ size: null,
564
+ write: (w, v, what) => {
565
+ if (!(v instanceof Uint8Array)) throw new CodecError(`${what} must be a Uint8Array`);
566
+ w.u16(v.length, `${what} length`).raw(v);
567
+ },
568
+ read: (r, what) => r.raw(r.u16(`${what} length`), what)
569
+ };
570
+ function option(inner) {
571
+ return {
572
+ desc: { kind: "option", inner },
573
+ size: null,
574
+ write: (w, v, what) => {
575
+ if (v === void 0) throw new CodecError(`${what} must be null (absent) or a value`);
576
+ if (v === null) {
577
+ w.u8(0);
578
+ } else {
579
+ w.u8(1);
580
+ inner.write(w, v, what);
581
+ }
582
+ },
583
+ read: (r, what) => {
584
+ const t = r.u8(`${what} option tag`);
585
+ if (t === 0) return null;
586
+ if (t !== 1) throw new CodecError(`${what}: invalid option tag ${t}`);
587
+ return inner.read(r, what);
588
+ }
589
+ };
590
+ }
591
+ function vec(inner, countBytes = 2, maxCount) {
592
+ return {
593
+ desc: { kind: "vec", inner, countBytes },
594
+ size: null,
595
+ write: (w, v, what) => {
596
+ if (!Array.isArray(v)) throw new CodecError(`${what} must be an array`);
597
+ if (maxCount !== void 0 && v.length > maxCount) {
598
+ throw new CodecError(`${what}: at most ${maxCount} elements, got ${v.length}`);
599
+ }
600
+ if (countBytes === 2) w.u16(v.length, `${what} count`);
601
+ else w.u32(v.length, `${what} count`);
602
+ v.forEach((item, i) => inner.write(w, item, `${what}[${i}]`));
603
+ },
604
+ read: (r, what) => {
605
+ const n = countBytes === 2 ? r.u16(`${what} count`) : r.u32(`${what} count`);
606
+ if (maxCount !== void 0 && n > maxCount) {
607
+ throw new CodecError(`${what}: at most ${maxCount} elements, got ${n}`);
608
+ }
609
+ if (n > r.remaining || inner.size !== null && n * inner.size > r.remaining) {
610
+ throw new CodecError(`${what}: count ${n} exceeds the remaining input`);
611
+ }
612
+ const out = [];
613
+ for (let i = 0; i < n; i++) out.push(inner.read(r, `${what}[${i}]`));
614
+ return out;
615
+ }
616
+ };
617
+ }
618
+ function array3(inner) {
619
+ return {
620
+ desc: { kind: "array", inner, length: 3 },
621
+ size: inner.size === null ? null : inner.size * 3,
622
+ write: (w, v, what) => {
623
+ if (!Array.isArray(v) || v.length !== 3) throw new CodecError(`${what} must have exactly 3 elements`);
624
+ v.forEach((item, i) => inner.write(w, item, `${what}[${i}]`));
625
+ },
626
+ read: (r, what) => [inner.read(r, `${what}[0]`), inner.read(r, `${what}[1]`), inner.read(r, `${what}[2]`)]
627
+ };
628
+ }
629
+ function struct(name, fields) {
630
+ let size = 0;
631
+ for (const [, c] of fields) size = size === null || c.size === null ? null : size + c.size;
632
+ const list = fields;
633
+ return {
634
+ desc: { kind: "struct", name, fields: list },
635
+ size,
636
+ write: (w, value, what) => {
637
+ if (value === null || typeof value !== "object") throw new CodecError(`${what} must be an object`);
638
+ const rec = value;
639
+ for (const [key, c] of list) c.write(w, rec[key], `${what}.${key}`);
640
+ },
641
+ read: (r, what) => {
642
+ const out = {};
643
+ for (const [key, c] of list) out[key] = c.read(r, `${what}.${key}`);
644
+ return out;
645
+ }
646
+ };
647
+ }
648
+ function u8Enum(name, names) {
649
+ return {
650
+ desc: { kind: "enum", name, variants: names.map((n, tag) => ({ tag, name: n, payload: null })) },
651
+ size: 1,
652
+ write: (w, v, what) => {
653
+ const tag = names.indexOf(v);
654
+ if (tag < 0) throw new CodecError(`${what}: unknown ${name} ${JSON.stringify(v)}`);
655
+ w.u8(tag, what);
656
+ },
657
+ read: (r, what) => {
658
+ const tag = r.u8(what);
659
+ const v = names[tag];
660
+ if (v === void 0) throw new CodecError(`${what}: unknown ${name} tag ${tag}`);
661
+ return v;
662
+ }
663
+ };
664
+ }
665
+ function encodeWith(codec, value, what = "value") {
666
+ const w = new Writer();
667
+ codec.write(w, value, what);
668
+ return w.toBytes();
669
+ }
670
+ function decodeWith(codec, bytes, what = "value") {
671
+ const r = new Reader(bytes);
672
+ const v = codec.read(r, what);
673
+ r.end(what);
674
+ return v;
675
+ }
676
+ var externalKeyId = struct("ExternalKeyId", [
677
+ ["namespace", string],
678
+ ["keyType", string],
679
+ ["publicKey", bytestring]
680
+ ]);
681
+ function encodeExternalKeyId(key) {
682
+ return encodeWith(externalKeyId, key, "ExternalKeyId");
683
+ }
684
+ function decodeExternalKeyId(bytes) {
685
+ return decodeWith(externalKeyId, bytes, "ExternalKeyId");
686
+ }
687
+ var wire = Object.freeze({
688
+ u8,
689
+ u16,
690
+ u32,
691
+ u64,
692
+ amount,
693
+ timestamp,
694
+ bool,
695
+ hash,
696
+ accountAddress,
697
+ publicKeyEd25519,
698
+ signatureEd25519,
699
+ moduleRef,
700
+ contractAddress: contractAddressCodec,
701
+ agentTokenId,
702
+ string,
703
+ bytestring,
704
+ string16,
705
+ bytes16,
706
+ externalKeyId,
707
+ option,
708
+ vec,
709
+ array3,
710
+ struct,
711
+ u8Enum
712
+ });
713
+ function defineMessage(name, tag, fields) {
714
+ const tagBytes = ascii(tag);
715
+ const body = struct(name, fields);
716
+ const encode = (value) => {
717
+ const w = new Writer();
718
+ w.raw(tagBytes);
719
+ body.write(w, value, name);
720
+ return w.toBytes();
721
+ };
722
+ return {
723
+ name,
724
+ tag,
725
+ body,
726
+ size: body.size === null ? null : tagBytes.length + body.size,
727
+ encode,
728
+ decode: (bytes) => {
729
+ const r = new Reader(bytes);
730
+ r.expect(tagBytes, `${name} domain tag`);
731
+ const v = body.read(r, name);
732
+ r.end(name);
733
+ return v;
734
+ },
735
+ encodeBody: (value) => encodeWith(body, value, name),
736
+ decodeBody: (bytes) => decodeWith(body, bytes, name),
737
+ hash: (value) => sha256(encode(value)),
738
+ sign: (value, seed) => ed25519Sign(encode(value), seed),
739
+ verify: (value, signature, publicKey, options) => ed25519Verify(signature, encode(value), publicKey, options)
740
+ };
741
+ }
742
+
743
+ // packages/codec/src/constants.ts
744
+ var TESTNET_GENESIS_HEX = "4221332d34e1694168c2a0c0b3fd0f273809612cb13d000d5c2e00e85f50f796";
745
+ var TESTNET_CAIP2 = "ccd:4221332d34e1694168c2a0c0b3fd0f27";
746
+ var TESTNET_CIS8004 = contractAddress(12802n, 0n);
747
+ var TESTNET_CIS8004_MODULE_HEX = "0e57473715d1c2a364fa626b8783688db32b7fac9d0e2fc97043da91e1a7d3eb";
748
+ var TESTNET_CIS8 = contractAddress(12801n, 0n);
749
+ var TESTNET_CIS8_MODULE_HEX = "3236c12fade1b559935906df2e0e43a372234eac5d40599d6e6cb12cdd6b9afd";
750
+ function testnetGenesis() {
751
+ return fromHex(TESTNET_GENESIS_HEX, 32);
752
+ }
753
+ var CIS8004_CONTRACT_NAME = "CIS-8004";
754
+ var CIS8_CONTRACT_NAME = "CIS-8";
755
+ var BUREAU_CONTRACT_NAME = "tab_bureau";
756
+ var DOMAIN_TAGS = Object.freeze({
757
+ lineTerms: "CCD-TAB/v1/line",
758
+ consent: "CCD-TAB/v1/consent",
759
+ tabAgreement: "CCD-TAB/v1/tab",
760
+ voucher: "CCD-TAB/v1/voucher",
761
+ receipt: "CCD-TAB/v1/receipt",
762
+ close: "CCD-TAB/v1/close",
763
+ closeAck: "CCD-TAB/v1/close-ack",
764
+ report: "CCD-TAB/v1/report",
765
+ limit: "CCD-TAB/v1/limit",
766
+ hello: "CCD-TAB/v1/hello",
767
+ accept: "CCD-TAB/v1/accept"
768
+ });
769
+ var SESSION_KEY_NAMESPACE = "ccdtab:session-v1";
770
+ var ATTESTOR_KEY_NAMESPACE = "ccdtab:attestor-v1";
771
+ var KEY_TYPE_ED25519 = "ed25519";
772
+ var PROOF_SCHEME_SOLANA_ED25519 = "solana-ed25519";
773
+ var MAX_LANES = 16;
774
+ var MAX_REPORT_VOUCHERS = 16;
775
+ var TIER = Object.freeze({ T0: 0, T1: 1, T2: 2 });
776
+
777
+ // packages/codec/src/events.ts
778
+ function def(tag, type, fields) {
779
+ return { tag, type, body: struct(type, fields) };
780
+ }
781
+ var EVENT_DEFS = [
782
+ def(1, "SellerRegistered", [
783
+ ["tokenId", u64],
784
+ ["policyHash", hash]
785
+ ]),
786
+ def(2, "LineOpened", [
787
+ ["lineId", u64],
788
+ ["commitment", hash]
789
+ ]),
790
+ def(3, "TabOpened", [
791
+ ["tabId", u64],
792
+ ["lineId", u64],
793
+ ["sellerToken", u64]
794
+ ]),
795
+ def(4, "TabSettled", [
796
+ ["tabId", u64],
797
+ ["cycle", u32],
798
+ ["onTime", bool],
799
+ ["acked", bool]
800
+ ]),
801
+ def(5, "CapStepped", [
802
+ ["lineId", u64],
803
+ ["k", u8]
804
+ ]),
805
+ def(6, "DefaultReported", [
806
+ ["tabId", u64],
807
+ ["evidenceHash", hash]
808
+ ]),
809
+ def(7, "DefaultCured", [["tabId", u64]]),
810
+ def(8, "TabClosed", [["tabId", u64]]),
811
+ def(9, "LineClosed", [["lineId", u64]]),
812
+ def(10, "FlagCleared", [["evidenceHash", hash]]),
813
+ def(11, "ParamsChanged", [["what", u8]])
814
+ ];
815
+ var PARAMS_CHANGED_WHAT = Object.freeze({
816
+ setParams: 1,
817
+ setAllowLists: 2,
818
+ repinRegistry: 3,
819
+ upgrade: 4,
820
+ /** The admin proposed by setParams accepted the role. */
821
+ acceptAdmin: 5
822
+ });
823
+ var BUREAU_EVENT_TAGS = Object.freeze(
824
+ Object.fromEntries(EVENT_DEFS.map((d) => [d.type, d.tag]))
825
+ );
826
+ var BY_TAG = new Map(EVENT_DEFS.map((d) => [d.tag, d]));
827
+ var BY_TYPE = new Map(EVENT_DEFS.map((d) => [d.type, d]));
828
+ var bureauEvent = {
829
+ desc: {
830
+ kind: "enum",
831
+ name: "Event",
832
+ variants: EVENT_DEFS.map((d) => ({ tag: d.tag, name: d.type, payload: d.body }))
833
+ },
834
+ size: null,
835
+ write: (w, event, what) => {
836
+ const d = event === null || typeof event !== "object" ? void 0 : BY_TYPE.get(event.type);
837
+ if (!d) throw new CodecError(`${what}: unknown event type ${String(event?.type)}`);
838
+ w.u8(d.tag);
839
+ const { type: _type, ...payload } = event;
840
+ d.body.write(w, payload, event.type);
841
+ },
842
+ read: (r, what) => {
843
+ const tag = r.u8(`${what} tag`);
844
+ const d = BY_TAG.get(tag);
845
+ if (!d) throw new CodecError(`unknown tab_bureau event tag ${tag}`);
846
+ return { type: d.type, ...d.body.read(r, d.type) };
847
+ }
848
+ };
849
+ function encodeBureauEvent(event) {
850
+ return encodeWith(bureauEvent, event, "Event");
851
+ }
852
+ function decodeBureauEvent(bytes) {
853
+ return decodeWith(bureauEvent, bytes, "Event");
854
+ }
855
+ var BUREAU_ERRORS = Object.freeze({
856
+ [-7300]: "ParseParams",
857
+ [-7301]: "Unauthorized",
858
+ [-7302]: "WrongDomain",
859
+ [-7303]: "Expired",
860
+ [-7304]: "Replay",
861
+ [-7305]: "RegistryChanged",
862
+ [-7306]: "RegistryParse",
863
+ [-7307]: "AgentNotActive",
864
+ [-7308]: "NotAgentOwner",
865
+ [-7309]: "NoAgentWallet",
866
+ [-7310]: "KeyNotBound",
867
+ [-7311]: "BadSignature",
868
+ [-7312]: "UnknownAttestor",
869
+ [-7313]: "PolicyIdp",
870
+ [-7314]: "PolicyValidity",
871
+ [-7315]: "PolicyAge",
872
+ [-7316]: "Flagged",
873
+ [-7317]: "UnknownSeller",
874
+ [-7318]: "SellerPolicy",
875
+ [-7319]: "DailyBudget",
876
+ [-7320]: "OverLimit",
877
+ [-7321]: "CycleOutOfRange",
878
+ [-7322]: "LaneOutOfRange",
879
+ [-7323]: "LaneRegressed",
880
+ [-7324]: "TotalMismatch",
881
+ [-7325]: "AmountMismatch",
882
+ [-7326]: "TooEarly",
883
+ [-7327]: "NoDebt",
884
+ [-7328]: "TabNotActive",
885
+ [-7329]: "LineNotActive",
886
+ [-7330]: "NonZeroAmount",
887
+ [-7331]: "TransferFailed",
888
+ [-7332]: "SameOwner",
889
+ [-7333]: "NotFound",
890
+ [-7334]: "Overflow",
891
+ [-7335]: "WalletChanged"
892
+ });
893
+ function bureauErrorName(code) {
894
+ return BUREAU_ERRORS[code] ?? null;
895
+ }
896
+ function bureauErrorCode(name) {
897
+ for (const [code, n] of Object.entries(BUREAU_ERRORS)) if (n === name) return Number(code);
898
+ throw new CodecError(`unknown tab_bureau error ${name}`);
899
+ }
900
+
901
+ // packages/codec/src/handshake.ts
902
+ import canonicalize from "canonicalize";
903
+ function assertJson(value, path) {
904
+ switch (typeof value) {
905
+ case "string":
906
+ case "boolean":
907
+ return;
908
+ case "number":
909
+ if (!Number.isFinite(value)) throw new CodecError(`${path}: JSON numbers must be finite`);
910
+ return;
911
+ case "bigint":
912
+ throw new CodecError(`${path}: bigint is not JSON; encode u64 values as decimal strings`);
913
+ case "object":
914
+ if (value === null) return;
915
+ if (Array.isArray(value)) {
916
+ value.forEach((v, i) => assertJson(v, `${path}[${i}]`));
917
+ return;
918
+ }
919
+ if (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) {
920
+ throw new CodecError(`${path}: only plain objects are allowed`);
921
+ }
922
+ for (const [k, v] of Object.entries(value)) {
923
+ if (v !== void 0) assertJson(v, `${path}.${k}`);
924
+ }
925
+ return;
926
+ default:
927
+ throw new CodecError(`${path}: ${typeof value} is not JSON`);
928
+ }
929
+ }
930
+ function jcsString(value) {
931
+ assertJson(value, "$");
932
+ const out = canonicalize(value);
933
+ if (out === void 0) throw new CodecError("value has no JSON representation");
934
+ return out;
935
+ }
936
+ function jcs(value) {
937
+ return utf8(jcsString(value));
938
+ }
939
+ function statementsHash(statements) {
940
+ return sha256(jcs(statements));
941
+ }
942
+ function helloSigningBytes(hello) {
943
+ return concatBytes(ascii(DOMAIN_TAGS.hello), jcs(hello));
944
+ }
945
+ function acceptSigningBytes(accept) {
946
+ return concatBytes(ascii(DOMAIN_TAGS.accept), jcs(accept));
947
+ }
948
+ function signHello(hello, seed) {
949
+ return ed25519Sign(helloSigningBytes(hello), seed);
950
+ }
951
+ function verifyHello(hello, signature, publicKey, options) {
952
+ return ed25519Verify(signature, helloSigningBytes(hello), publicKey, options);
953
+ }
954
+ function signAccept(accept, seed) {
955
+ return ed25519Sign(acceptSigningBytes(accept), seed);
956
+ }
957
+ function verifyAccept(accept, signature, publicKey, options) {
958
+ return ed25519Verify(signature, acceptSigningBytes(accept), publicKey, options);
959
+ }
960
+ function helloHash(hello) {
961
+ return sha256(jcs(hello));
962
+ }
963
+ function acceptTranscriptPart(accept) {
964
+ const { agreement: _agreement, sellerSig: _sellerSig, ...rest } = accept;
965
+ return rest;
966
+ }
967
+ function handshakeHash(hello, accept) {
968
+ return sha256(jcs(hello), jcs(acceptTranscriptPart(accept)));
969
+ }
970
+
971
+ // packages/codec/src/messages.ts
972
+ function zeroHash() {
973
+ return new Uint8Array(32);
974
+ }
975
+ var LineTermsV1Codec = defineMessage(
976
+ "LineTermsV1",
977
+ DOMAIN_TAGS.lineTerms,
978
+ [
979
+ ["genesis", hash],
980
+ ["bureau", contractAddressCodec],
981
+ ["buyerToken", agentTokenId],
982
+ ["owner", accountAddress],
983
+ ["sessionKeyHash", hash],
984
+ ["lineLimit", amount],
985
+ ["perSellerMax", amount],
986
+ ["maxCycleMs", u64],
987
+ ["validUntil", timestamp],
988
+ ["nonce", u64],
989
+ ["expiry", timestamp]
990
+ ]
991
+ );
992
+ var ConsentAttestationV1Codec = defineMessage(
993
+ "ConsentAttestationV1",
994
+ DOMAIN_TAGS.consent,
995
+ [
996
+ ["genesis", hash],
997
+ ["bureau", contractAddressCodec],
998
+ ["owner", accountAddress],
999
+ ["termsHash", hash],
1000
+ ["vraTx", hash],
1001
+ ["vaaTx", hash],
1002
+ ["statementsHash", hash],
1003
+ ["tier", u8],
1004
+ ["subjectKey", hash],
1005
+ ["validUntil", timestamp]
1006
+ ]
1007
+ );
1008
+ var TabAgreementV1Codec = defineMessage(
1009
+ "TabAgreementV1",
1010
+ DOMAIN_TAGS.tabAgreement,
1011
+ [
1012
+ ["genesis", hash],
1013
+ ["bureau", contractAddressCodec],
1014
+ ["lineId", u64],
1015
+ ["sellerToken", agentTokenId],
1016
+ ["sellerWallet", accountAddress],
1017
+ ["limit", amount],
1018
+ ["cycleMs", u64],
1019
+ ["graceMs", u64],
1020
+ ["maxLanes", u16],
1021
+ ["priceScheduleHash", hash],
1022
+ ["termsHash", hash],
1023
+ ["handshakeHash", hash],
1024
+ ["nonce", u64],
1025
+ ["expiry", timestamp]
1026
+ ]
1027
+ );
1028
+ var VoucherV1Codec = defineMessage("VoucherV1", DOMAIN_TAGS.voucher, [
1029
+ ["genesis", hash],
1030
+ ["bureau", contractAddressCodec],
1031
+ ["tabId", u64],
1032
+ ["lane", u16],
1033
+ ["seq", u64],
1034
+ ["ackedCumulative", amount],
1035
+ ["maxPrice", amount],
1036
+ ["requestHash", hash],
1037
+ ["prevReceiptHash", hash],
1038
+ ["issuedAt", timestamp]
1039
+ ]);
1040
+ var ReceiptV1Codec = defineMessage("ReceiptV1", DOMAIN_TAGS.receipt, [
1041
+ ["genesis", hash],
1042
+ ["bureau", contractAddressCodec],
1043
+ ["tabId", u64],
1044
+ ["lane", u16],
1045
+ ["seq", u64],
1046
+ ["voucherHash", hash],
1047
+ ["responseHash", hash],
1048
+ ["charged", amount],
1049
+ ["chargedCumulative", amount],
1050
+ ["issuedAt", timestamp]
1051
+ ]);
1052
+ var laneState = struct("LaneState", [
1053
+ ["lane", u16],
1054
+ ["seq", u64],
1055
+ ["chargedCumulative", amount],
1056
+ ["lastReceiptHash", hash]
1057
+ ]);
1058
+ var CloseVoucherV1Codec = defineMessage(
1059
+ "CloseVoucherV1",
1060
+ DOMAIN_TAGS.close,
1061
+ [
1062
+ ["genesis", hash],
1063
+ ["bureau", contractAddressCodec],
1064
+ ["tabId", u64],
1065
+ ["cycle", u32],
1066
+ ["lanes", vec(laneState, 2)],
1067
+ ["total", amount],
1068
+ ["issuedAt", timestamp]
1069
+ ]
1070
+ );
1071
+ var CloseAckV1Codec = defineMessage("CloseAckV1", DOMAIN_TAGS.closeAck, [
1072
+ ["genesis", hash],
1073
+ ["bureau", contractAddressCodec],
1074
+ ["tabId", u64],
1075
+ ["cycle", u32],
1076
+ ["closeHash", hash],
1077
+ ["issuedAt", timestamp]
1078
+ ]);
1079
+ var ReportV1Codec = defineMessage("ReportV1", DOMAIN_TAGS.report, [
1080
+ ["genesis", hash],
1081
+ ["bureau", contractAddressCodec],
1082
+ ["tabId", u64],
1083
+ ["cycle", u32],
1084
+ ["vouchersHash", hash],
1085
+ ["issuedAt", timestamp]
1086
+ ]);
1087
+ var LimitV1Codec = defineMessage("LimitV1", DOMAIN_TAGS.limit, [
1088
+ ["genesis", hash],
1089
+ ["bureau", contractAddressCodec],
1090
+ ["tabId", u64],
1091
+ ["newLimit", amount],
1092
+ ["nonce", u64],
1093
+ ["expiry", timestamp]
1094
+ ]);
1095
+ var MESSAGE_CODECS = Object.freeze({
1096
+ LineTermsV1: LineTermsV1Codec,
1097
+ ConsentAttestationV1: ConsentAttestationV1Codec,
1098
+ TabAgreementV1: TabAgreementV1Codec,
1099
+ VoucherV1: VoucherV1Codec,
1100
+ ReceiptV1: ReceiptV1Codec,
1101
+ CloseVoucherV1: CloseVoucherV1Codec,
1102
+ CloseAckV1: CloseAckV1Codec,
1103
+ ReportV1: ReportV1Codec,
1104
+ LimitV1: LimitV1Codec
1105
+ });
1106
+ var encodeLineTermsV1 = (v) => LineTermsV1Codec.encode(v);
1107
+ var decodeLineTermsV1 = (b) => LineTermsV1Codec.decode(b);
1108
+ var termsHash = (v) => LineTermsV1Codec.hash(v);
1109
+ var encodeConsentAttestationV1 = (v) => ConsentAttestationV1Codec.encode(v);
1110
+ var decodeConsentAttestationV1 = (b) => ConsentAttestationV1Codec.decode(b);
1111
+ var attestationHash = (v) => ConsentAttestationV1Codec.hash(v);
1112
+ var encodeTabAgreementV1 = (v) => TabAgreementV1Codec.encode(v);
1113
+ var decodeTabAgreementV1 = (b) => TabAgreementV1Codec.decode(b);
1114
+ var agreementHash = (v) => TabAgreementV1Codec.hash(v);
1115
+ var encodeVoucherV1 = (v) => VoucherV1Codec.encode(v);
1116
+ var decodeVoucherV1 = (b) => VoucherV1Codec.decode(b);
1117
+ var commitmentId = (v) => VoucherV1Codec.hash(v);
1118
+ var encodeReceiptV1 = (v) => ReceiptV1Codec.encode(v);
1119
+ var decodeReceiptV1 = (b) => ReceiptV1Codec.decode(b);
1120
+ var receiptHash = (v) => ReceiptV1Codec.hash(v);
1121
+ var encodeCloseVoucherV1 = (v) => CloseVoucherV1Codec.encode(v);
1122
+ var decodeCloseVoucherV1 = (b) => CloseVoucherV1Codec.decode(b);
1123
+ var closeHash = (v) => CloseVoucherV1Codec.hash(v);
1124
+ var encodeCloseAckV1 = (v) => CloseAckV1Codec.encode(v);
1125
+ var decodeCloseAckV1 = (b) => CloseAckV1Codec.decode(b);
1126
+ var encodeReportV1 = (v) => ReportV1Codec.encode(v);
1127
+ var decodeReportV1 = (b) => ReportV1Codec.decode(b);
1128
+ var encodeLimitV1 = (v) => LimitV1Codec.encode(v);
1129
+ var decodeLimitV1 = (b) => LimitV1Codec.decode(b);
1130
+ function sessionKeyHash(key) {
1131
+ return sha256(encodeExternalKeyId(key));
1132
+ }
1133
+ function requestHash(method, pathAndQuery, body = new Uint8Array()) {
1134
+ const bodyBytes = typeof body === "string" ? utf8(body) : body;
1135
+ return sha256(utf8(method), utf8(" "), utf8(pathAndQuery), utf8("\n"), bodyBytes);
1136
+ }
1137
+ function responseHash(body) {
1138
+ return sha256(typeof body === "string" ? utf8(body) : body);
1139
+ }
1140
+ function lineCommitment(termsHashBytes, attestationHashBytes) {
1141
+ return sha256(concatBytes(termsHashBytes, attestationHashBytes));
1142
+ }
1143
+ var signedVoucher = struct("SignedVoucher", [
1144
+ ["voucher", VoucherV1Codec.body],
1145
+ ["sig", signatureEd25519]
1146
+ ]);
1147
+ var signedVoucherVec = vec(signedVoucher, 2, 16);
1148
+ function encodeSignedVouchers(vouchers) {
1149
+ const w = new Writer();
1150
+ signedVoucherVec.write(w, vouchers, "vouchers");
1151
+ return w.toBytes();
1152
+ }
1153
+ function vouchersHash(vouchers) {
1154
+ return sha256(encodeSignedVouchers(vouchers));
1155
+ }
1156
+ function cycleEnd(openedAt, cycle, cycleMs) {
1157
+ return openedAt + BigInt(cycle + 1) * cycleMs;
1158
+ }
1159
+ function closeAckFor(close) {
1160
+ return {
1161
+ genesis: close.genesis,
1162
+ bureau: close.bureau,
1163
+ tabId: close.tabId,
1164
+ cycle: close.cycle,
1165
+ closeHash: CloseVoucherV1Codec.hash(close),
1166
+ issuedAt: close.issuedAt
1167
+ };
1168
+ }
1169
+ function reportFor(input) {
1170
+ return {
1171
+ genesis: input.genesis,
1172
+ bureau: input.bureau,
1173
+ tabId: input.tabId,
1174
+ cycle: input.cycle,
1175
+ vouchersHash: vouchersHash(input.vouchers),
1176
+ issuedAt: cycleEnd(input.openedAt, input.cycle, input.cycleMs)
1177
+ };
1178
+ }
1179
+
1180
+ // packages/codec/src/params.ts
1181
+ var standingKey = {
1182
+ desc: {
1183
+ kind: "enum",
1184
+ name: "StandingKey",
1185
+ variants: [
1186
+ { tag: 0, name: "account", payload: accountAddress },
1187
+ { tag: 1, name: "subject", payload: hash }
1188
+ ]
1189
+ },
1190
+ size: 33,
1191
+ write: (w, v, what) => {
1192
+ if (v?.kind === "account") {
1193
+ w.u8(0);
1194
+ accountAddress.write(w, v.account, `${what}.account`);
1195
+ } else if (v?.kind === "subject") {
1196
+ w.u8(1);
1197
+ hash.write(w, v.subjectKey, `${what}.subjectKey`);
1198
+ } else {
1199
+ throw new CodecError(`${what} must be a StandingKey`);
1200
+ }
1201
+ },
1202
+ read: (r, what) => {
1203
+ const tag = r.u8(`${what} tag`);
1204
+ if (tag === 0) return { kind: "account", account: accountAddress.read(r, `${what}.account`) };
1205
+ if (tag === 1) return { kind: "subject", subjectKey: hash.read(r, `${what}.subjectKey`) };
1206
+ throw new CodecError(`${what}: unknown StandingKey tag ${tag}`);
1207
+ }
1208
+ };
1209
+ function standingKeyFor(tier, owner, subjectKey) {
1210
+ return tier === 0 ? { kind: "account", account: owner } : { kind: "subject", subjectKey };
1211
+ }
1212
+ var encodeStandingKey = (key) => encodeWith(standingKey, key, "StandingKey");
1213
+ var decodeStandingKey = (bytes) => decodeWith(standingKey, bytes, "StandingKey");
1214
+ var bureauConfig = struct("Config", [
1215
+ ["genesis", hash],
1216
+ ["cis8004", contractAddressCodec],
1217
+ ["cis8004Module", moduleRef],
1218
+ ["cis8", contractAddressCodec],
1219
+ ["cis8Module", moduleRef],
1220
+ ["admin", accountAddress],
1221
+ ["allowedIdps", vec(u32, 2)],
1222
+ ["attestors", vec(publicKeyEd25519, 2)],
1223
+ ["ciAttestors", vec(publicKeyEd25519, 2)],
1224
+ ["tierBase", array3(amount)],
1225
+ ["maxSteps", u8],
1226
+ ["minStep", amount],
1227
+ ["maxLanes", u16],
1228
+ ["settleWindowMs", u64],
1229
+ ["flagTtlMs", u64],
1230
+ ["minIdentityAgeMs", array3(u64)]
1231
+ ]);
1232
+ var encodeInitParams = (config) => encodeWith(bureauConfig, config, "Config");
1233
+ var decodeConfig = (bytes) => decodeWith(bureauConfig, bytes, "Config");
1234
+ function ladderCap(tierBase, maxSteps, tier, k) {
1235
+ const base = tierBase[tier];
1236
+ if (base === void 0) throw new CodecError(`unknown tier ${tier}`);
1237
+ for (const [name, v] of [["k", k], ["maxSteps", maxSteps]]) {
1238
+ if (!Number.isInteger(v) || v < 0 || v > 255) throw new CodecError(`${name} must be a u8, got ${v}`);
1239
+ }
1240
+ const cap = base * (1n << BigInt(Math.min(k, maxSteps)));
1241
+ return cap > U64_MAX ? U64_MAX : cap;
1242
+ }
1243
+ var sellerPolicy = struct("SellerPolicy", [
1244
+ ["maxTabLimit", amount],
1245
+ ["minBuyerTier", u8],
1246
+ ["minBuyerK", u8],
1247
+ ["minCycleMs", u64],
1248
+ ["maxCycleMs", u64],
1249
+ ["maxNewTabsPerDay", u32],
1250
+ ["priceScheduleHash", hash],
1251
+ ["admitBadgeInvalid", bool]
1252
+ ]);
1253
+ var encodeSellerPolicy = (p) => encodeWith(sellerPolicy, p, "SellerPolicy");
1254
+ var decodeSellerPolicy = (b) => decodeWith(sellerPolicy, b, "SellerPolicy");
1255
+ var policyHash = (p) => sha256(encodeSellerPolicy(p));
1256
+ var registerSellerParams = struct("RegisterSellerParams", [
1257
+ ["sellerToken", agentTokenId],
1258
+ ["sessionKey", externalKeyId],
1259
+ ["policy", sellerPolicy]
1260
+ ]);
1261
+ var encodeRegisterSellerParams = (p) => encodeWith(registerSellerParams, p, "RegisterSellerParams");
1262
+ var decodeRegisterSellerParams = (b) => decodeWith(registerSellerParams, b, "RegisterSellerParams");
1263
+ var openLineParams = struct("OpenLineParams", [
1264
+ ["terms", LineTermsV1Codec.body],
1265
+ ["sessionKey", externalKeyId],
1266
+ ["attestation", ConsentAttestationV1Codec.body],
1267
+ ["attestorKey", publicKeyEd25519],
1268
+ ["attestationSig", signatureEd25519]
1269
+ ]);
1270
+ var encodeOpenLineParams = (p) => encodeWith(openLineParams, p, "OpenLineParams");
1271
+ var decodeOpenLineParams = (b) => decodeWith(openLineParams, b, "OpenLineParams");
1272
+ var openTabParams = struct("OpenTabParams", [
1273
+ ["agreement", TabAgreementV1Codec.body],
1274
+ ["buyerSig", signatureEd25519],
1275
+ ["sellerSig", signatureEd25519]
1276
+ ]);
1277
+ var encodeOpenTabParams = (p) => encodeWith(openTabParams, p, "OpenTabParams");
1278
+ var decodeOpenTabParams = (b) => decodeWith(openTabParams, b, "OpenTabParams");
1279
+ var settleTabParams = struct("SettleTabParams", [
1280
+ ["close", CloseVoucherV1Codec.body],
1281
+ ["buyerSig", signatureEd25519],
1282
+ ["ackSig", option(signatureEd25519)]
1283
+ ]);
1284
+ var encodeSettleTabParams = (p) => encodeWith(settleTabParams, p, "SettleTabParams");
1285
+ var decodeSettleTabParams = (b) => decodeWith(settleTabParams, b, "SettleTabParams");
1286
+ var reportDefaultParams = struct("ReportDefaultParams", [
1287
+ ["tabId", u64],
1288
+ ["cycle", u32],
1289
+ ["vouchers", vec(signedVoucher, 2, MAX_REPORT_VOUCHERS)],
1290
+ ["reportSig", option(signatureEd25519)]
1291
+ ]);
1292
+ var encodeReportDefaultParams = (p) => encodeWith(reportDefaultParams, p, "ReportDefaultParams");
1293
+ var decodeReportDefaultParams = (b) => decodeWith(reportDefaultParams, b, "ReportDefaultParams");
1294
+ var encodeCloseTabParams = (tabId) => encodeWith(u64, tabId, "tab_id");
1295
+ var encodeCloseLineParams = (lineId) => encodeWith(u64, lineId, "line_id");
1296
+ var decodeIdParams = (b) => decodeWith(u64, b, "id");
1297
+ var clearFlagParams = struct("ClearFlagParams", [
1298
+ ["key", standingKey],
1299
+ ["evidenceHash", hash]
1300
+ ]);
1301
+ var encodeClearFlagParams = (p) => encodeWith(clearFlagParams, p, "ClearFlagParams");
1302
+ var decodeClearFlagParams = (b) => decodeWith(clearFlagParams, b, "ClearFlagParams");
1303
+ var resolveDefaultParams = struct("ResolveDefaultParams", [
1304
+ ["tabId", u64],
1305
+ ["evidenceHash", hash]
1306
+ ]);
1307
+ var encodeResolveDefaultParams = (p) => encodeWith(resolveDefaultParams, p, "ResolveDefaultParams");
1308
+ var decodeResolveDefaultParams = (b) => decodeWith(resolveDefaultParams, b, "ResolveDefaultParams");
1309
+ var pruneExpiredParams = vec(standingKey, 2);
1310
+ var encodePruneExpiredParams = (keys) => encodeWith(pruneExpiredParams, keys, "pruneExpired");
1311
+ var decodePruneExpiredParams = (b) => decodeWith(pruneExpiredParams, b, "pruneExpired");
1312
+ var raiseLimitParams = struct("RaiseLimitParams", [
1313
+ ["tabId", u64],
1314
+ ["limit", LimitV1Codec.body],
1315
+ ["sellerSig", signatureEd25519]
1316
+ ]);
1317
+ var encodeRaiseLimitParams = (p) => encodeWith(raiseLimitParams, p, "RaiseLimitParams");
1318
+ var decodeRaiseLimitParams = (b) => decodeWith(raiseLimitParams, b, "RaiseLimitParams");
1319
+ var setParamsParams = struct("SetParamsParams", [
1320
+ ["tierBase", array3(amount)],
1321
+ ["maxSteps", u8],
1322
+ ["minStep", amount],
1323
+ ["maxLanes", u16],
1324
+ ["settleWindowMs", u64],
1325
+ ["flagTtlMs", u64],
1326
+ ["minIdentityAgeMs", array3(u64)],
1327
+ ["admin", accountAddress]
1328
+ ]);
1329
+ var encodeSetParamsParams = (p) => encodeWith(setParamsParams, p, "SetParamsParams");
1330
+ var decodeSetParamsParams = (b) => decodeWith(setParamsParams, b, "SetParamsParams");
1331
+ var setAllowListsParams = struct("SetAllowListsParams", [
1332
+ ["allowedIdps", vec(u32, 2)],
1333
+ ["attestors", vec(publicKeyEd25519, 2)],
1334
+ ["ciAttestors", vec(publicKeyEd25519, 2)]
1335
+ ]);
1336
+ var encodeSetAllowListsParams = (p) => encodeWith(setAllowListsParams, p, "SetAllowListsParams");
1337
+ var decodeSetAllowListsParams = (b) => decodeWith(setAllowListsParams, b, "SetAllowListsParams");
1338
+ var repinRegistryParams = struct("RepinRegistryParams", [
1339
+ ["cis8004Module", moduleRef],
1340
+ ["cis8Module", moduleRef]
1341
+ ]);
1342
+ var encodeRepinRegistryParams = (p) => encodeWith(repinRegistryParams, p, "RepinRegistryParams");
1343
+ var decodeRepinRegistryParams = (b) => decodeWith(repinRegistryParams, b, "RepinRegistryParams");
1344
+ var MAX_ENTRYPOINT_NAME_BYTES = 100;
1345
+ var ENTRYPOINT_NAME_RE = /^[\x21-\x7e]*$/;
1346
+ function checkEntrypointName(name, what) {
1347
+ if (typeof name !== "string") throw new CodecError(`${what} must be a string`);
1348
+ if (name.length >= MAX_ENTRYPOINT_NAME_BYTES) {
1349
+ throw new CodecError(`${what}: entrypoint names have fewer than ${MAX_ENTRYPOINT_NAME_BYTES} bytes`);
1350
+ }
1351
+ if (!ENTRYPOINT_NAME_RE.test(name)) {
1352
+ throw new CodecError(`${what}: entrypoint names are ASCII letters, digits and punctuation only`);
1353
+ }
1354
+ }
1355
+ var entrypointName = {
1356
+ desc: string16.desc,
1357
+ size: null,
1358
+ write: (w, v, what) => {
1359
+ checkEntrypointName(v, what);
1360
+ string16.write(w, v, what);
1361
+ },
1362
+ read: (r, what) => {
1363
+ const v = string16.read(r, what);
1364
+ checkEntrypointName(v, what);
1365
+ return v;
1366
+ }
1367
+ };
1368
+ var upgradeParams = struct("UpgradeParams", [
1369
+ ["module", moduleRef],
1370
+ [
1371
+ "migrate",
1372
+ option(
1373
+ struct("Migrate", [
1374
+ ["entrypoint", entrypointName],
1375
+ ["parameter", bytes16]
1376
+ ])
1377
+ )
1378
+ ]
1379
+ ]);
1380
+ var encodeUpgradeParams = (p) => encodeWith(upgradeParams, p, "UpgradeParams");
1381
+ var decodeUpgradeParams = (b) => decodeWith(upgradeParams, b, "UpgradeParams");
1382
+ var BUREAU_ENTRYPOINTS = Object.freeze({
1383
+ registerSeller: "registerSeller",
1384
+ openLine: "openLine",
1385
+ openTab: "openTab",
1386
+ settleTab: "settleTab",
1387
+ reportDefault: "reportDefault",
1388
+ closeTab: "closeTab",
1389
+ closeLine: "closeLine",
1390
+ clearFlag: "clearFlag",
1391
+ resolveDefault: "resolveDefault",
1392
+ pruneExpired: "pruneExpired",
1393
+ raiseLimit: "raiseLimit",
1394
+ setParams: "setParams",
1395
+ /** Takes no parameter: the account proposed by setParams accepts the admin role. */
1396
+ acceptAdmin: "acceptAdmin",
1397
+ setAllowLists: "setAllowLists",
1398
+ repinRegistry: "repinRegistry",
1399
+ upgrade: "upgrade",
1400
+ checkSpend: "check_spend",
1401
+ lineOf: "lineOf",
1402
+ tabOf: "tabOf",
1403
+ sellerOf: "sellerOf",
1404
+ standingOf: "standingOf",
1405
+ capOf: "capOf",
1406
+ config: "config"
1407
+ });
1408
+
1409
+ // packages/codec/src/registry.ts
1410
+ function ed25519KeyId(publicKey, namespace = SESSION_KEY_NAMESPACE) {
1411
+ if (publicKey.length !== 32) throw new CodecError("ed25519 public key must be 32 bytes");
1412
+ return { namespace, keyType: KEY_TYPE_ED25519, publicKey };
1413
+ }
1414
+ function externalKeyIdEqual(a, b) {
1415
+ const ea = encodeExternalKeyId(a);
1416
+ const eb = encodeExternalKeyId(b);
1417
+ return ea.length === eb.length && ea.every((x, i) => x === eb[i]);
1418
+ }
1419
+ var externalReference = struct("ExternalReference", [
1420
+ ["contract", contractAddressCodec],
1421
+ ["kind", u8Enum("ExternalRefKind", ["Cis8"])],
1422
+ ["key", externalKeyId]
1423
+ ]);
1424
+ var agentMetadataEntry = struct("MetadataEntry", [
1425
+ ["key", string],
1426
+ ["value", bytestring]
1427
+ ]);
1428
+ var agentView = struct("AgentView", [
1429
+ ["tokenId", agentTokenId],
1430
+ ["ownerAccount", accountAddress],
1431
+ ["agentUri", option(string)],
1432
+ ["metadataHash", option(hash)],
1433
+ ["externalReference", option(externalReference)],
1434
+ ["agentWallet", option(accountAddress)],
1435
+ ["status", u8Enum("AgentStatus", ["Active", "Revoked"])],
1436
+ ["registeredAt", timestamp],
1437
+ ["revokedAt", option(timestamp)],
1438
+ ["revocationReason", option(string)],
1439
+ ["onChainMetadata", vec(agentMetadataEntry, 4)]
1440
+ ]);
1441
+ var encodeAgentOfParams = (tokenId) => encodeWith(agentTokenId, tokenId, "token_id");
1442
+ function decodeAgentOfResult(bytes, expectedTokenId) {
1443
+ const view = decodeWith(option(agentView), bytes, "agentOf result");
1444
+ if (view !== null && expectedTokenId !== void 0 && view.tokenId !== expectedTokenId) {
1445
+ throw new CodecError(`agentOf result is for token ${view.tokenId}, not ${expectedTokenId}`);
1446
+ }
1447
+ return view;
1448
+ }
1449
+ var encodeAgentOfResult = (view) => encodeWith(option(agentView), view, "agentOf result");
1450
+ var decodeAgentWalletResult = (bytes) => decodeWith(option(accountAddress), bytes, "getAgentWallet result");
1451
+ var decodeAgentWalletNonceResult = (bytes) => decodeWith(option(u64), bytes, "getAgentWalletNonce result");
1452
+ var cis8MetadataEntry = struct("MetadataEntry", [
1453
+ ["key", string],
1454
+ ["value", string]
1455
+ ]);
1456
+ var registration = struct("Registration", [
1457
+ ["owner", accountAddress],
1458
+ ["externalKey", externalKeyId],
1459
+ ["proofScheme", string],
1460
+ ["metadata", vec(cis8MetadataEntry, 4)],
1461
+ ["status", u8Enum("RegistrationStatus", ["Active", "Revoked"])],
1462
+ ["lastUpdated", timestamp]
1463
+ ]);
1464
+ var encodeOwnerOfKeyParams = (key) => encodeExternalKeyId(key);
1465
+ var decodeOwnerOfKeyResult = (bytes) => decodeWith(option(registration), bytes, "ownerOfKey result");
1466
+ var encodeOwnerOfKeyResult = (reg) => encodeWith(option(registration), reg, "ownerOfKey result");
1467
+ function isKeyBoundTo(reg, owner, pinned) {
1468
+ if (reg === null || reg.status !== "Active") return false;
1469
+ if (reg.owner.length !== owner.length || !reg.owner.every((b, i) => b === owner[i])) return false;
1470
+ return externalKeyIdEqual(reg.externalKey, pinned);
1471
+ }
1472
+ var registerExternalKeyParams = struct("RegisterExternalKeyParam", [
1473
+ ["externalKey", externalKeyId],
1474
+ [
1475
+ "proof",
1476
+ struct("Proof", [
1477
+ ["scheme", string],
1478
+ ["signature", bytestring]
1479
+ ])
1480
+ ],
1481
+ ["metadata", vec(cis8MetadataEntry, 4)]
1482
+ ]);
1483
+ var encodeRegisterExternalKeyParams = (p) => encodeWith(registerExternalKeyParams, p, "RegisterExternalKeyParam");
1484
+ var decodeRegisterExternalKeyParams = (b) => decodeWith(registerExternalKeyParams, b, "RegisterExternalKeyParam");
1485
+ var CIS8_CANONICAL_TAG = "CIS-8/v1/canonical";
1486
+ var Cis8CanonicalMessageCodec = defineMessage(
1487
+ "Cis8CanonicalMessage",
1488
+ CIS8_CANONICAL_TAG,
1489
+ [
1490
+ ["account", accountAddress],
1491
+ ["contract", contractAddressCodec],
1492
+ ["genesis", hash],
1493
+ ["externalNamespace", string],
1494
+ ["externalKey", externalKeyId],
1495
+ ["proofScheme", string]
1496
+ ]
1497
+ );
1498
+ function cis8Message(input) {
1499
+ return {
1500
+ account: input.account,
1501
+ contract: input.contract ?? TESTNET_CIS8,
1502
+ genesis: input.genesis ?? testnetGenesis(),
1503
+ externalNamespace: input.externalNamespace ?? input.externalKey.namespace,
1504
+ externalKey: input.externalKey,
1505
+ proofScheme: input.proofScheme
1506
+ };
1507
+ }
1508
+ function cis8CanonicalMessage(input) {
1509
+ return Cis8CanonicalMessageCodec.encode(cis8Message(input));
1510
+ }
1511
+ function signCis8Canonical(input, seed) {
1512
+ return ed25519Sign(cis8CanonicalMessage(input), seed);
1513
+ }
1514
+ function verifyCis8Canonical(input, signature, options) {
1515
+ return ed25519Verify(signature, cis8CanonicalMessage(input), input.externalKey.publicKey, options);
1516
+ }
1517
+ var SET_AGENT_WALLET_TAG = "CIS-8004/v1/setAgentWallet";
1518
+ var SET_AGENT_WALLET_MESSAGE_LENGTH = 162;
1519
+ var SetAgentWalletMessageCodec = defineMessage(
1520
+ "SetAgentWalletMessage",
1521
+ SET_AGENT_WALLET_TAG,
1522
+ [
1523
+ ["tokenId", u64],
1524
+ ["owner", accountAddress],
1525
+ ["newWallet", accountAddress],
1526
+ ["walletSetNonce", u64],
1527
+ ["deadline", timestamp],
1528
+ ["contract", contractAddressCodec],
1529
+ ["genesis", hash]
1530
+ ]
1531
+ );
1532
+ function setAgentWalletMessage(input) {
1533
+ return SetAgentWalletMessageCodec.encode({
1534
+ tokenId: input.tokenId,
1535
+ owner: input.owner,
1536
+ newWallet: input.newWallet,
1537
+ walletSetNonce: input.walletSetNonce,
1538
+ deadline: input.deadline,
1539
+ contract: input.contract ?? TESTNET_CIS8004,
1540
+ genesis: input.genesis ?? testnetGenesis()
1541
+ });
1542
+ }
1543
+ function decodeSetAgentWalletMessage(bytes) {
1544
+ return SetAgentWalletMessageCodec.decode(bytes);
1545
+ }
1546
+ function encodeAccountSignatures(signatures) {
1547
+ const byCred = /* @__PURE__ */ new Map();
1548
+ for (const s of signatures) {
1549
+ if (s.signature.length !== 64) throw new CodecError("account signature must be 64 bytes");
1550
+ const keys = byCred.get(s.credential) ?? /* @__PURE__ */ new Map();
1551
+ if (keys.has(s.key)) throw new CodecError(`duplicate signature for credential ${s.credential} key ${s.key}`);
1552
+ keys.set(s.key, s.signature);
1553
+ byCred.set(s.credential, keys);
1554
+ }
1555
+ const w = new Writer();
1556
+ w.u8(byCred.size, "credential count");
1557
+ for (const cred of [...byCred.keys()].sort((a, b) => a - b)) {
1558
+ const keys = byCred.get(cred);
1559
+ w.u8(cred, "credential index").u8(keys.size, "key count");
1560
+ for (const key of [...keys.keys()].sort((a, b) => a - b)) {
1561
+ w.u8(key, "key index").u8(0).raw(keys.get(key));
1562
+ }
1563
+ }
1564
+ return w.toBytes();
1565
+ }
1566
+ function singleKeyAccountSignatures(signature) {
1567
+ return encodeAccountSignatures([{ credential: 0, key: 0, signature }]);
1568
+ }
1569
+ var setAgentWalletParams = struct("SetAgentWalletParam", [
1570
+ ["tokenId", agentTokenId],
1571
+ ["newWallet", accountAddress],
1572
+ ["deadline", timestamp],
1573
+ ["signature", bytestring]
1574
+ ]);
1575
+ var encodeSetAgentWalletParams = (p) => encodeWith(setAgentWalletParams, p, "SetAgentWalletParam");
1576
+ var decodeSetAgentWalletParams = (b) => decodeWith(setAgentWalletParams, b, "SetAgentWalletParam");
1577
+ function decodeAccountSignatures(bytes) {
1578
+ const r = new Reader(bytes);
1579
+ const out = [];
1580
+ const creds = r.u8("credential count");
1581
+ for (let i = 0; i < creds; i++) {
1582
+ const credential = r.u8("credential index");
1583
+ const keys = r.u8("key count");
1584
+ for (let k = 0; k < keys; k++) {
1585
+ const key = r.u8("key index");
1586
+ const tag = r.u8("signature tag");
1587
+ if (tag !== 0) throw new CodecError(`unsupported account signature scheme tag ${tag}`);
1588
+ out.push({ credential, key, signature: r.raw(64, "signature") });
1589
+ }
1590
+ }
1591
+ r.end("AccountSignatures");
1592
+ return out;
1593
+ }
1594
+
1595
+ // packages/codec/src/registry-events.ts
1596
+ var cis2Address = {
1597
+ desc: {
1598
+ kind: "enum",
1599
+ name: "Address",
1600
+ variants: [
1601
+ { tag: 0, name: "account", payload: accountAddress },
1602
+ { tag: 1, name: "contract", payload: contractAddressCodec }
1603
+ ]
1604
+ },
1605
+ size: null,
1606
+ write: (w, v, what) => {
1607
+ if (v.kind === "account") {
1608
+ w.u8(0);
1609
+ accountAddress.write(w, v.address, what);
1610
+ } else {
1611
+ w.u8(1);
1612
+ contractAddressCodec.write(w, v.address, what);
1613
+ }
1614
+ },
1615
+ read: (r, what) => {
1616
+ const tag = r.u8(`${what} tag`);
1617
+ if (tag === 0) return { kind: "account", address: accountAddress.read(r, what) };
1618
+ if (tag === 1) return { kind: "contract", address: contractAddressCodec.read(r, what) };
1619
+ throw new CodecError(`${what}: unknown Address tag ${tag}`);
1620
+ }
1621
+ };
1622
+ var cis2Amount = {
1623
+ desc: { kind: "u64" },
1624
+ size: null,
1625
+ write: (w, v, what) => {
1626
+ if (typeof v !== "bigint" || v < 0n || v >= 1n << 256n) throw new CodecError(`${what} out of range`);
1627
+ let x = v;
1628
+ do {
1629
+ let byte = Number(x & 0x7fn);
1630
+ x >>= 7n;
1631
+ if (x !== 0n) byte |= 128;
1632
+ w.u8(byte);
1633
+ } while (x !== 0n);
1634
+ },
1635
+ read: (r, what) => {
1636
+ let value = 0n;
1637
+ for (let i = 0; i < 37; i++) {
1638
+ const byte = r.u8(what);
1639
+ value |= BigInt(byte & 127) << BigInt(7 * i);
1640
+ if ((byte & 128) === 0) {
1641
+ if (byte === 0 && i > 0) throw new CodecError(`${what}: overlong ULEB128`);
1642
+ return value;
1643
+ }
1644
+ }
1645
+ throw new CodecError(`${what}: ULEB128 longer than 37 bytes`);
1646
+ }
1647
+ };
1648
+ function ev(tag, type, fields) {
1649
+ return { tag, type, body: struct(type, fields) };
1650
+ }
1651
+ function encodeTagged(defs, event, standard) {
1652
+ const d = defs.find((x) => x.type === event.type);
1653
+ if (!d) throw new CodecError(`unknown ${standard} event type ${event.type}`);
1654
+ const w = new Writer();
1655
+ w.u8(d.tag);
1656
+ const { type: _type, ...payload } = event;
1657
+ d.body.write(w, payload, d.type);
1658
+ return w.toBytes();
1659
+ }
1660
+ function decodeTagged(defs, bytes, standard) {
1661
+ const r = new Reader(bytes);
1662
+ const tag = r.u8("event tag");
1663
+ const d = defs.find((x) => x.tag === tag);
1664
+ if (!d) throw new CodecError(`unknown ${standard} event tag ${tag}`);
1665
+ const payload = d.body.read(r, d.type);
1666
+ r.end(d.type);
1667
+ return { type: d.type, ...payload };
1668
+ }
1669
+ var CIS8_EVENT_TAGS = Object.freeze({
1670
+ ExternalKeyRegistered: 231,
1671
+ ExternalKeyRevoked: 232,
1672
+ UpdateMetadata: 233,
1673
+ Upgraded: 234,
1674
+ AdminTransferred: 235
1675
+ });
1676
+ var adminTransferred = [
1677
+ ["previous", option(accountAddress)],
1678
+ ["next", option(accountAddress)],
1679
+ ["updatedAt", timestamp]
1680
+ ];
1681
+ var CIS8_EVENTS = [
1682
+ ev(231, "ExternalKeyRegistered", [
1683
+ ["owner", accountAddress],
1684
+ ["externalKey", externalKeyId],
1685
+ ["proofScheme", string],
1686
+ ["metadata", vec(cis8MetadataEntry, 4)]
1687
+ ]),
1688
+ ev(232, "ExternalKeyRevoked", [
1689
+ ["owner", accountAddress],
1690
+ ["externalKey", externalKeyId]
1691
+ ]),
1692
+ ev(233, "UpdateMetadata", [
1693
+ ["externalKey", externalKeyId],
1694
+ ["metadata", vec(cis8MetadataEntry, 4)]
1695
+ ]),
1696
+ ev(234, "Upgraded", [
1697
+ ["newModule", moduleRef],
1698
+ ["upgradedAt", timestamp]
1699
+ ]),
1700
+ ev(235, "AdminTransferred", adminTransferred)
1701
+ ];
1702
+ function decodeCis8Event(bytes) {
1703
+ return decodeTagged(CIS8_EVENTS, bytes, "CIS-8");
1704
+ }
1705
+ function encodeCis8Event(event) {
1706
+ return encodeTagged(CIS8_EVENTS, event, "CIS-8");
1707
+ }
1708
+ var CIS8004_EVENT_TAGS = Object.freeze({
1709
+ Registered: 240,
1710
+ URIUpdated: 241,
1711
+ ExternalReferenceSet: 242,
1712
+ MetadataSet: 243,
1713
+ Revoked: 244,
1714
+ AgentWalletSet: 245,
1715
+ AdminTransferred: 247,
1716
+ ExternalRegistriesUpdated: 248,
1717
+ TokenMetadata: 251,
1718
+ UpdateOperator: 252,
1719
+ Burn: 253,
1720
+ Mint: 254,
1721
+ Transfer: 255
1722
+ });
1723
+ var CIS8004_EVENTS = [
1724
+ ev(240, "Registered", [
1725
+ ["tokenId", agentTokenId],
1726
+ ["ownerAccount", accountAddress],
1727
+ ["agentUri", option(string)],
1728
+ ["metadataHash", option(hash)],
1729
+ ["externalReference", option(externalReference)],
1730
+ ["registeredAt", timestamp]
1731
+ ]),
1732
+ ev(241, "URIUpdated", [
1733
+ ["tokenId", agentTokenId],
1734
+ ["agentUri", option(string)],
1735
+ ["metadataHash", option(hash)],
1736
+ ["updatedAt", timestamp]
1737
+ ]),
1738
+ ev(242, "ExternalReferenceSet", [
1739
+ ["tokenId", agentTokenId],
1740
+ ["externalReference", option(externalReference)],
1741
+ ["updatedAt", timestamp]
1742
+ ]),
1743
+ ev(243, "MetadataSet", [
1744
+ ["tokenId", agentTokenId],
1745
+ ["key", string],
1746
+ ["value", bytestring],
1747
+ ["updatedAt", timestamp]
1748
+ ]),
1749
+ ev(244, "Revoked", [
1750
+ ["tokenId", agentTokenId],
1751
+ ["ownerAccount", accountAddress],
1752
+ ["reason", option(string)],
1753
+ ["revokedAt", timestamp]
1754
+ ]),
1755
+ ev(245, "AgentWalletSet", [
1756
+ ["tokenId", agentTokenId],
1757
+ ["newWallet", option(accountAddress)],
1758
+ ["updatedAt", timestamp]
1759
+ ]),
1760
+ ev(247, "AdminTransferred", adminTransferred),
1761
+ ev(248, "ExternalRegistriesUpdated", [
1762
+ ["previousCis8Contract", contractAddressCodec],
1763
+ ["newCis8Contract", contractAddressCodec]
1764
+ ]),
1765
+ ev(251, "TokenMetadata", [
1766
+ ["tokenId", agentTokenId],
1767
+ ["url", string16],
1768
+ ["hash", option(hash)]
1769
+ ]),
1770
+ ev(252, "UpdateOperator", [
1771
+ ["update", u8Enum("OperatorUpdate", ["Remove", "Add"])],
1772
+ ["owner", cis2Address],
1773
+ ["operator", cis2Address]
1774
+ ]),
1775
+ ev(253, "Burn", [
1776
+ ["tokenId", agentTokenId],
1777
+ ["amount", cis2Amount],
1778
+ ["owner", cis2Address]
1779
+ ]),
1780
+ ev(254, "Mint", [
1781
+ ["tokenId", agentTokenId],
1782
+ ["amount", cis2Amount],
1783
+ ["owner", cis2Address]
1784
+ ]),
1785
+ ev(255, "Transfer", [
1786
+ ["tokenId", agentTokenId],
1787
+ ["amount", cis2Amount],
1788
+ ["from", cis2Address],
1789
+ ["to", cis2Address]
1790
+ ])
1791
+ ];
1792
+ function decodeCis8004Event(bytes) {
1793
+ return decodeTagged(CIS8004_EVENTS, bytes, "CIS-8004");
1794
+ }
1795
+ function encodeCis8004Event(event) {
1796
+ return encodeTagged(CIS8004_EVENTS, event, "CIS-8004");
1797
+ }
1798
+
1799
+ // packages/codec/src/views.ts
1800
+ var checkSpendParams = struct("CheckSpendParams", [
1801
+ ["tabId", u64],
1802
+ ["amountAfter", amount]
1803
+ ]);
1804
+ var encodeCheckSpendParams = (p) => encodeWith(checkSpendParams, p, "CheckSpendParams");
1805
+ var decodeCheckSpendParams = (b) => decodeWith(checkSpendParams, b, "CheckSpendParams");
1806
+ var SPEND_NOGO_REASONS = Object.freeze({
1807
+ 1: "TabNotActive",
1808
+ 2: "LineNotActive",
1809
+ 3: "LineExpired",
1810
+ 4: "OwnerDefaulted",
1811
+ 5: "AgentRevoked",
1812
+ 6: "OwnerChanged",
1813
+ 7: "KeyRevokedOrDisplaced",
1814
+ 8: "SellerNotActive",
1815
+ 9: "OverLimit",
1816
+ 10: "PastDue",
1817
+ 11: "RegistryChanged"
1818
+ });
1819
+ var spendDecision = {
1820
+ desc: {
1821
+ kind: "enum",
1822
+ name: "SpendDecision",
1823
+ variants: [
1824
+ { tag: 0, name: "Go", payload: null },
1825
+ { tag: 1, name: "NoGo", payload: u8 }
1826
+ ]
1827
+ },
1828
+ size: null,
1829
+ write: (w, v, what) => {
1830
+ if (v.go) {
1831
+ w.u8(0);
1832
+ } else {
1833
+ w.u8(1).u8(v.code, `${what}.code`);
1834
+ }
1835
+ },
1836
+ read: (r, what) => {
1837
+ const tag = r.u8(`${what} tag`);
1838
+ if (tag === 0) return { go: true };
1839
+ if (tag !== 1) throw new CodecError(`${what}: unknown SpendDecision tag ${tag}`);
1840
+ const code = r.u8(`${what}.reason`);
1841
+ const reason = SPEND_NOGO_REASONS[code];
1842
+ if (reason === void 0) throw new CodecError(`${what}: unknown NoGo reason ${code}`);
1843
+ return { go: false, code, reason };
1844
+ }
1845
+ };
1846
+ function noGo(reason) {
1847
+ const entry = Object.entries(SPEND_NOGO_REASONS).find(([, name]) => name === reason);
1848
+ if (!entry) throw new CodecError(`unknown NoGo reason ${reason}`);
1849
+ return { go: false, code: Number(entry[0]), reason };
1850
+ }
1851
+ var encodeSpendDecision = (d) => encodeWith(spendDecision, d, "SpendDecision");
1852
+ var decodeSpendDecision = (b) => decodeWith(spendDecision, b, "SpendDecision");
1853
+ var encodeLineOfParams = (lineId) => encodeWith(u64, lineId, "line_id");
1854
+ var encodeTabOfParams = (tabId) => encodeWith(u64, tabId, "tab_id");
1855
+ var encodeSellerOfParams = (tokenId) => encodeWith(u64, tokenId, "token_id");
1856
+ var lineView = struct("LineView", [
1857
+ ["buyerToken", u64],
1858
+ ["owner", accountAddress],
1859
+ ["buyerWallet", option(accountAddress)],
1860
+ ["sessionKey", externalKeyId],
1861
+ ["tier", u8],
1862
+ ["standingKey", standingKey],
1863
+ ["lineLimit", amount],
1864
+ ["perSellerMax", amount],
1865
+ ["maxCycleMs", u64],
1866
+ ["validUntil", timestamp],
1867
+ ["openTotal", amount],
1868
+ ["ci", bool],
1869
+ ["status", u8Enum("LineStatus", ["Active", "Closed"])],
1870
+ ["steppedBy", vec(accountAddress, 2)],
1871
+ ["openTabs", vec(u64, 2)],
1872
+ ["termsHash", hash],
1873
+ ["openedAt", timestamp]
1874
+ ]);
1875
+ var encodeLineOfResult = (v) => encodeWith(option(lineView), v, "lineOf result");
1876
+ var decodeLineOfResult = (b) => decodeWith(option(lineView), b, "lineOf result");
1877
+ var laneRecord = struct("LaneRecord", [
1878
+ ["seq", u64],
1879
+ ["chargedCumulative", amount]
1880
+ ]);
1881
+ var tabView = struct("TabView", [
1882
+ ["lineId", u64],
1883
+ ["sellerToken", u64],
1884
+ ["sellerOwner", accountAddress],
1885
+ ["sellerWallet", accountAddress],
1886
+ ["sellerKey", publicKeyEd25519],
1887
+ ["limit", amount],
1888
+ ["cycleMs", u64],
1889
+ ["graceMs", u64],
1890
+ ["settleWindowMs", u64],
1891
+ ["maxLanes", u16],
1892
+ ["openedAt", timestamp],
1893
+ ["lanes", vec(laneRecord, 2)],
1894
+ ["settledTotal", amount],
1895
+ ["lastSettledCycle", option(u32)],
1896
+ ["lastSettledAt", option(timestamp)],
1897
+ ["lastAcked", bool],
1898
+ ["lastOnTime", bool],
1899
+ ["reportedTotal", amount],
1900
+ ["status", u8Enum("TabStatus", ["Active", "Defaulted", "Closed"])],
1901
+ ["closeRequestedAt", option(timestamp)],
1902
+ ["curedAt", option(timestamp)],
1903
+ ["agreementHash", hash]
1904
+ ]);
1905
+ var encodeTabOfResult = (v) => encodeWith(option(tabView), v, "tabOf result");
1906
+ var decodeTabOfResult = (b) => decodeWith(option(tabView), b, "tabOf result");
1907
+ var sellerView = struct("SellerView", [
1908
+ ["owner", accountAddress],
1909
+ ["wallet", accountAddress],
1910
+ ["idp", u32],
1911
+ ["createdAt", timestamp],
1912
+ ["sessionKey", externalKeyId],
1913
+ ["policy", sellerPolicy],
1914
+ ["registeredAt", timestamp],
1915
+ ["day", u64],
1916
+ ["tabsToday", u32]
1917
+ ]);
1918
+ var encodeSellerOfResult = (v) => encodeWith(option(sellerView), v, "sellerOf result");
1919
+ var decodeSellerOfResult = (b) => decodeWith(option(sellerView), b, "sellerOf result");
1920
+ var standing = struct("Standing", [
1921
+ ["k", u8],
1922
+ ["openLimits", amount],
1923
+ ["openDefaults", u16],
1924
+ ["flagUntil", timestamp],
1925
+ ["defaultsTotal", u32],
1926
+ ["onTimeCycles", u32]
1927
+ ]);
1928
+ var encodeStandingOfParams = (key) => encodeWith(standingKey, key, "StandingKey");
1929
+ var encodeStanding = (s) => encodeWith(standing, s, "Standing");
1930
+ var decodeStandingOfResult = (b) => decodeWith(standing, b, "Standing");
1931
+ function isFlagged(s, nowMs) {
1932
+ return s.openDefaults > 0 && nowMs < s.flagUntil;
1933
+ }
1934
+ var capOfParams = struct("CapOfParams", [
1935
+ ["key", standingKey],
1936
+ ["tier", u8]
1937
+ ]);
1938
+ var encodeCapOfParams = (p) => encodeWith(capOfParams, p, "CapOfParams");
1939
+ var decodeCapOfParams = (b) => decodeWith(capOfParams, b, "CapOfParams");
1940
+ var encodeCapOfResult = (cap) => encodeWith(amount, cap, "capOf result");
1941
+ var decodeCapOfResult = (b) => decodeWith(amount, b, "capOf result");
1942
+ var decodeConfigResult = (b) => decodeConfig(b);
1943
+
1944
+ export {
1945
+ CodecError,
1946
+ U8_MAX,
1947
+ U16_MAX,
1948
+ U32_MAX,
1949
+ U64_MAX,
1950
+ toHex,
1951
+ fromHex,
1952
+ utf8,
1953
+ fromUtf8,
1954
+ ascii,
1955
+ concatBytes,
1956
+ bytesEqual,
1957
+ toU64,
1958
+ Writer,
1959
+ Reader,
1960
+ ED25519_PUBLIC_KEY_LENGTH,
1961
+ ED25519_SEED_LENGTH,
1962
+ ED25519_SIGNATURE_LENGTH,
1963
+ HASH_LENGTH,
1964
+ sha256,
1965
+ hmacSha256,
1966
+ ed25519PublicKey,
1967
+ ed25519Sign,
1968
+ ed25519Verify,
1969
+ ed25519PublicKeyAsync,
1970
+ ed25519SignAsync,
1971
+ ed25519VerifyAsync,
1972
+ base58Encode,
1973
+ base58Decode,
1974
+ base58CheckEncode,
1975
+ base58CheckDecode,
1976
+ ACCOUNT_ADDRESS_LENGTH,
1977
+ ACCOUNT_ADDRESS_VERSION,
1978
+ accountAddressFromBase58,
1979
+ accountAddressToBase58,
1980
+ isAccountAddress,
1981
+ contractAddress,
1982
+ formatContractAddress,
1983
+ parseContractAddress,
1984
+ contractAddressEqual,
1985
+ uleb128Encode,
1986
+ uleb128Decode,
1987
+ TOKEN_ADDRESS_VERSION,
1988
+ tokenIdU64Bytes,
1989
+ tokenAddress,
1990
+ agentTokenAddress,
1991
+ parseTokenAddress,
1992
+ caip2FromGenesis,
1993
+ agentCaip19,
1994
+ parseCaip19,
1995
+ ed25519DidKey,
1996
+ ed25519FromDidKey,
1997
+ TOKEN_ID_U64_PREFIX,
1998
+ encodeWith,
1999
+ decodeWith,
2000
+ encodeExternalKeyId,
2001
+ decodeExternalKeyId,
2002
+ wire,
2003
+ defineMessage,
2004
+ TESTNET_GENESIS_HEX,
2005
+ TESTNET_CAIP2,
2006
+ TESTNET_CIS8004,
2007
+ TESTNET_CIS8004_MODULE_HEX,
2008
+ TESTNET_CIS8,
2009
+ TESTNET_CIS8_MODULE_HEX,
2010
+ testnetGenesis,
2011
+ CIS8004_CONTRACT_NAME,
2012
+ CIS8_CONTRACT_NAME,
2013
+ BUREAU_CONTRACT_NAME,
2014
+ DOMAIN_TAGS,
2015
+ SESSION_KEY_NAMESPACE,
2016
+ ATTESTOR_KEY_NAMESPACE,
2017
+ KEY_TYPE_ED25519,
2018
+ PROOF_SCHEME_SOLANA_ED25519,
2019
+ MAX_LANES,
2020
+ MAX_REPORT_VOUCHERS,
2021
+ TIER,
2022
+ PARAMS_CHANGED_WHAT,
2023
+ BUREAU_EVENT_TAGS,
2024
+ bureauEvent,
2025
+ encodeBureauEvent,
2026
+ decodeBureauEvent,
2027
+ BUREAU_ERRORS,
2028
+ bureauErrorName,
2029
+ bureauErrorCode,
2030
+ jcsString,
2031
+ jcs,
2032
+ statementsHash,
2033
+ helloSigningBytes,
2034
+ acceptSigningBytes,
2035
+ signHello,
2036
+ verifyHello,
2037
+ signAccept,
2038
+ verifyAccept,
2039
+ helloHash,
2040
+ acceptTranscriptPart,
2041
+ handshakeHash,
2042
+ zeroHash,
2043
+ LineTermsV1Codec,
2044
+ ConsentAttestationV1Codec,
2045
+ TabAgreementV1Codec,
2046
+ VoucherV1Codec,
2047
+ ReceiptV1Codec,
2048
+ laneState,
2049
+ CloseVoucherV1Codec,
2050
+ CloseAckV1Codec,
2051
+ ReportV1Codec,
2052
+ LimitV1Codec,
2053
+ MESSAGE_CODECS,
2054
+ encodeLineTermsV1,
2055
+ decodeLineTermsV1,
2056
+ termsHash,
2057
+ encodeConsentAttestationV1,
2058
+ decodeConsentAttestationV1,
2059
+ attestationHash,
2060
+ encodeTabAgreementV1,
2061
+ decodeTabAgreementV1,
2062
+ agreementHash,
2063
+ encodeVoucherV1,
2064
+ decodeVoucherV1,
2065
+ commitmentId,
2066
+ encodeReceiptV1,
2067
+ decodeReceiptV1,
2068
+ receiptHash,
2069
+ encodeCloseVoucherV1,
2070
+ decodeCloseVoucherV1,
2071
+ closeHash,
2072
+ encodeCloseAckV1,
2073
+ decodeCloseAckV1,
2074
+ encodeReportV1,
2075
+ decodeReportV1,
2076
+ encodeLimitV1,
2077
+ decodeLimitV1,
2078
+ sessionKeyHash,
2079
+ requestHash,
2080
+ responseHash,
2081
+ lineCommitment,
2082
+ signedVoucher,
2083
+ signedVoucherVec,
2084
+ encodeSignedVouchers,
2085
+ vouchersHash,
2086
+ cycleEnd,
2087
+ closeAckFor,
2088
+ reportFor,
2089
+ standingKey,
2090
+ standingKeyFor,
2091
+ encodeStandingKey,
2092
+ decodeStandingKey,
2093
+ bureauConfig,
2094
+ encodeInitParams,
2095
+ decodeConfig,
2096
+ ladderCap,
2097
+ sellerPolicy,
2098
+ encodeSellerPolicy,
2099
+ decodeSellerPolicy,
2100
+ policyHash,
2101
+ registerSellerParams,
2102
+ encodeRegisterSellerParams,
2103
+ decodeRegisterSellerParams,
2104
+ openLineParams,
2105
+ encodeOpenLineParams,
2106
+ decodeOpenLineParams,
2107
+ openTabParams,
2108
+ encodeOpenTabParams,
2109
+ decodeOpenTabParams,
2110
+ settleTabParams,
2111
+ encodeSettleTabParams,
2112
+ decodeSettleTabParams,
2113
+ reportDefaultParams,
2114
+ encodeReportDefaultParams,
2115
+ decodeReportDefaultParams,
2116
+ encodeCloseTabParams,
2117
+ encodeCloseLineParams,
2118
+ decodeIdParams,
2119
+ clearFlagParams,
2120
+ encodeClearFlagParams,
2121
+ decodeClearFlagParams,
2122
+ resolveDefaultParams,
2123
+ encodeResolveDefaultParams,
2124
+ decodeResolveDefaultParams,
2125
+ pruneExpiredParams,
2126
+ encodePruneExpiredParams,
2127
+ decodePruneExpiredParams,
2128
+ raiseLimitParams,
2129
+ encodeRaiseLimitParams,
2130
+ decodeRaiseLimitParams,
2131
+ setParamsParams,
2132
+ encodeSetParamsParams,
2133
+ decodeSetParamsParams,
2134
+ setAllowListsParams,
2135
+ encodeSetAllowListsParams,
2136
+ decodeSetAllowListsParams,
2137
+ repinRegistryParams,
2138
+ encodeRepinRegistryParams,
2139
+ decodeRepinRegistryParams,
2140
+ MAX_ENTRYPOINT_NAME_BYTES,
2141
+ entrypointName,
2142
+ upgradeParams,
2143
+ encodeUpgradeParams,
2144
+ decodeUpgradeParams,
2145
+ BUREAU_ENTRYPOINTS,
2146
+ ed25519KeyId,
2147
+ externalKeyIdEqual,
2148
+ externalReference,
2149
+ agentMetadataEntry,
2150
+ agentView,
2151
+ encodeAgentOfParams,
2152
+ decodeAgentOfResult,
2153
+ encodeAgentOfResult,
2154
+ decodeAgentWalletResult,
2155
+ decodeAgentWalletNonceResult,
2156
+ cis8MetadataEntry,
2157
+ registration,
2158
+ encodeOwnerOfKeyParams,
2159
+ decodeOwnerOfKeyResult,
2160
+ encodeOwnerOfKeyResult,
2161
+ isKeyBoundTo,
2162
+ registerExternalKeyParams,
2163
+ encodeRegisterExternalKeyParams,
2164
+ decodeRegisterExternalKeyParams,
2165
+ CIS8_CANONICAL_TAG,
2166
+ Cis8CanonicalMessageCodec,
2167
+ cis8CanonicalMessage,
2168
+ signCis8Canonical,
2169
+ verifyCis8Canonical,
2170
+ SET_AGENT_WALLET_TAG,
2171
+ SET_AGENT_WALLET_MESSAGE_LENGTH,
2172
+ SetAgentWalletMessageCodec,
2173
+ setAgentWalletMessage,
2174
+ decodeSetAgentWalletMessage,
2175
+ encodeAccountSignatures,
2176
+ singleKeyAccountSignatures,
2177
+ setAgentWalletParams,
2178
+ encodeSetAgentWalletParams,
2179
+ decodeSetAgentWalletParams,
2180
+ decodeAccountSignatures,
2181
+ cis2Address,
2182
+ cis2Amount,
2183
+ CIS8_EVENT_TAGS,
2184
+ decodeCis8Event,
2185
+ encodeCis8Event,
2186
+ CIS8004_EVENT_TAGS,
2187
+ decodeCis8004Event,
2188
+ encodeCis8004Event,
2189
+ checkSpendParams,
2190
+ encodeCheckSpendParams,
2191
+ decodeCheckSpendParams,
2192
+ SPEND_NOGO_REASONS,
2193
+ spendDecision,
2194
+ noGo,
2195
+ encodeSpendDecision,
2196
+ decodeSpendDecision,
2197
+ encodeLineOfParams,
2198
+ encodeTabOfParams,
2199
+ encodeSellerOfParams,
2200
+ lineView,
2201
+ encodeLineOfResult,
2202
+ decodeLineOfResult,
2203
+ laneRecord,
2204
+ tabView,
2205
+ encodeTabOfResult,
2206
+ decodeTabOfResult,
2207
+ sellerView,
2208
+ encodeSellerOfResult,
2209
+ decodeSellerOfResult,
2210
+ standing,
2211
+ encodeStandingOfParams,
2212
+ encodeStanding,
2213
+ decodeStandingOfResult,
2214
+ isFlagged,
2215
+ capOfParams,
2216
+ encodeCapOfParams,
2217
+ decodeCapOfParams,
2218
+ encodeCapOfResult,
2219
+ decodeCapOfResult,
2220
+ decodeConfigResult
2221
+ };