@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,68 @@
1
+ import {
2
+ contractAddressEqual,
3
+ decodeBureauEvent,
4
+ decodeConfigResult,
5
+ decodeLineOfResult,
6
+ decodeStandingOfResult,
7
+ decodeTabOfResult,
8
+ encodeLineOfParams,
9
+ encodeStandingOfParams,
10
+ encodeTabOfParams
11
+ } from "./chunk-D3C7KAMJ.js";
12
+
13
+ // packages/cli/src/verify/common.ts
14
+ var HASH_RE = /^[0-9a-f]{64}$/;
15
+ async function finalizedTx(ctx, hash, rb, label = "transaction") {
16
+ if (!rb.check(`${label} hash is well formed`, HASH_RE.test(hash), hash)) return null;
17
+ const found = await ctx.chain.transaction(hash);
18
+ if (!rb.check(`${label} is finalized`, found.status === "finalized", found.status)) return null;
19
+ if (found.status !== "finalized") return null;
20
+ const tx = found.tx;
21
+ rb.check(`${label} succeeded`, tx.ok, tx.ok ? `block ${tx.blockHeight}` : `${tx.rejectReason ?? "rejected"}${tx.rejectCode === null ? "" : ` (code ${tx.rejectCode})`}`);
22
+ return tx.ok ? tx : null;
23
+ }
24
+ function bureauCall(ctx, tx, entrypoint) {
25
+ return tx.calls.findLast((c) => contractAddressEqual(c.contract, ctx.bureau) && c.receiveName === `tab_bureau.${entrypoint}`);
26
+ }
27
+ function bureauEvents(ctx, tx) {
28
+ const logs = [...tx.calls, ...tx.interruptedEvents].filter((c) => contractAddressEqual(c.contract, ctx.bureau));
29
+ return logs.flatMap((c) => c.events.map((e) => decodeBureauEvent(e)));
30
+ }
31
+ async function tabOf(ctx, tabId, blockHash) {
32
+ return decodeTabOfResult(await ctx.chain.bureauView("tabOf", encodeTabOfParams(tabId), blockHash));
33
+ }
34
+ async function lineOf(ctx, lineId, blockHash) {
35
+ return decodeLineOfResult(await ctx.chain.bureauView("lineOf", encodeLineOfParams(lineId), blockHash));
36
+ }
37
+ async function standingOf(ctx, key, blockHash) {
38
+ return decodeStandingOfResult(await ctx.chain.bureauView("standingOf", encodeStandingOfParams(key), blockHash));
39
+ }
40
+ async function bureauConfig(ctx, blockHash) {
41
+ return decodeConfigResult(await ctx.chain.bureauView("config", new Uint8Array(), blockHash));
42
+ }
43
+ function attempt(rb, name, f) {
44
+ try {
45
+ return f();
46
+ } catch (err) {
47
+ rb.check(name, false, err instanceof Error ? err.message : String(err));
48
+ return null;
49
+ }
50
+ }
51
+ function ccd(micro) {
52
+ const whole = micro / 1000000n;
53
+ const frac = (micro % 1000000n).toString().padStart(6, "0");
54
+ return `${whole}.${frac} CCD`;
55
+ }
56
+
57
+ export {
58
+ HASH_RE,
59
+ finalizedTx,
60
+ bureauCall,
61
+ bureauEvents,
62
+ tabOf,
63
+ lineOf,
64
+ standingOf,
65
+ bureauConfig,
66
+ attempt,
67
+ ccd
68
+ };
@@ -0,0 +1,84 @@
1
+ // packages/registry/src/constants.ts
2
+ var TESTNET_GENESIS = "4221332d34e1694168c2a0c0b3fd0f273809612cb13d000d5c2e00e85f50f796";
3
+ var TESTNET_CAIP2 = `ccd:${TESTNET_GENESIS.slice(0, 32)}`;
4
+ var TESTNET_GRPC_HOST = "grpc.testnet.concordium.com";
5
+ var TESTNET_GRPC_PORT = 2e4;
6
+ var CIS8004 = Object.freeze({
7
+ label: "cis8004",
8
+ address: Object.freeze({ index: 12802n, subindex: 0n }),
9
+ contractName: "CIS-8004",
10
+ moduleRef: "0e57473715d1c2a364fa626b8783688db32b7fac9d0e2fc97043da91e1a7d3eb"
11
+ });
12
+ var CIS8 = Object.freeze({
13
+ label: "cis8",
14
+ address: Object.freeze({ index: 12801n, subindex: 0n }),
15
+ contractName: "CIS-8",
16
+ moduleRef: "3236c12fade1b559935906df2e0e43a372234eac5d40599d6e6cb12cdd6b9afd"
17
+ });
18
+ var HOSTED_MCP_URL = "https://agent-registry-mcp.concordium.com/mcp";
19
+ var HOSTED_REST_BASE = "https://agent-registry-mcp.concordium.com";
20
+ var HOSTED_NETWORK = "testnet";
21
+ var BADGE_EXTENSION_URI = "https://docs.concordium.com/a2a-extensions/concordium-badge/v1";
22
+
23
+ // packages/registry/src/errors.ts
24
+ var RegistryParseError = class extends Error {
25
+ name = "RegistryParseError";
26
+ /** Byte offset at which parsing failed, when known. */
27
+ offset;
28
+ constructor(message, offset) {
29
+ super(offset === void 0 ? message : `${message} (at byte ${offset})`);
30
+ this.offset = offset;
31
+ }
32
+ };
33
+ var RegistryChangedError = class extends Error {
34
+ name = "RegistryChangedError";
35
+ mismatches;
36
+ constructor(mismatches) {
37
+ super(
38
+ `registry module changed: ${mismatches.map((m) => `${m.contract} expected ${m.expected}, found ${m.actual}`).join("; ")}`
39
+ );
40
+ this.mismatches = mismatches;
41
+ }
42
+ };
43
+ var RegistryInvokeError = class extends Error {
44
+ name = "RegistryInvokeError";
45
+ /** The contract's reject code, when the contract itself rejected. */
46
+ rejectCode;
47
+ entrypoint;
48
+ constructor(entrypoint, message, rejectCode) {
49
+ super(`${entrypoint}: ${message}`);
50
+ this.entrypoint = entrypoint;
51
+ this.rejectCode = rejectCode;
52
+ }
53
+ };
54
+ var WrongNetworkError = class extends Error {
55
+ name = "WrongNetworkError";
56
+ expected;
57
+ actual;
58
+ constructor(expected, actual) {
59
+ super(`connected to the wrong network: genesis ${actual}, expected ${expected}`);
60
+ this.expected = expected;
61
+ this.actual = actual;
62
+ }
63
+ };
64
+ var InvalidInputError = class extends Error {
65
+ name = "InvalidInputError";
66
+ };
67
+
68
+ export {
69
+ TESTNET_GENESIS,
70
+ TESTNET_CAIP2,
71
+ TESTNET_GRPC_HOST,
72
+ TESTNET_GRPC_PORT,
73
+ CIS8004,
74
+ CIS8,
75
+ HOSTED_MCP_URL,
76
+ HOSTED_REST_BASE,
77
+ HOSTED_NETWORK,
78
+ BADGE_EXTENSION_URI,
79
+ RegistryParseError,
80
+ RegistryChangedError,
81
+ RegistryInvokeError,
82
+ WrongNetworkError,
83
+ InvalidInputError
84
+ };
@@ -0,0 +1,73 @@
1
+ import {
2
+ TESTNET_DRP_ANCHOR_ACCOUNTS
3
+ } from "./chunk-HTU7QRDF.js";
4
+ import "./chunk-QTI2WM44.js";
5
+ import "./chunk-GOEFQ62Z.js";
6
+ import {
7
+ CliError
8
+ } from "./chunk-MOZ4BFSB.js";
9
+ import {
10
+ contractAddress,
11
+ parseContractAddress
12
+ } from "./chunk-D3C7KAMJ.js";
13
+
14
+ // packages/cli/src/config.ts
15
+ import { homedir } from "node:os";
16
+ import { join } from "node:path";
17
+ var TESTNET_BUREAU = contractAddress(13064n, 0n);
18
+ var TESTNET_ANCHOR_ACCOUNT = "4HT2tWdvyiZ4TcZ6WnCWJhs8Vid8PTREVvTh597b9aTaYXMGeo";
19
+ function optionalUrl(env, name) {
20
+ const v = env[name];
21
+ if (v === void 0 || v === "") return null;
22
+ let u;
23
+ try {
24
+ u = new URL(v);
25
+ } catch {
26
+ throw new CliError("bad_config", `${name} is not a URL`);
27
+ }
28
+ if (u.protocol !== "https:" && !(u.protocol === "http:" && (u.hostname === "localhost" || u.hostname === "127.0.0.1"))) {
29
+ throw new CliError("bad_config", `${name} must be https (http only for localhost)`);
30
+ }
31
+ return v.replace(/\/+$/, "");
32
+ }
33
+ var ACCOUNT_RE = /^[1-9A-HJ-NP-Za-km-z]{50}$/;
34
+ function accountList(env, name) {
35
+ const raw = env[name];
36
+ if (raw === void 0 || raw.trim() === "") return null;
37
+ const list = raw.split(",").map((s) => s.trim()).filter((s) => s !== "");
38
+ if (list.length === 0 || !list.every((a) => ACCOUNT_RE.test(a))) {
39
+ throw new CliError("bad_config", `${name} must be a comma-separated list of account addresses`);
40
+ }
41
+ return list;
42
+ }
43
+ function cliConfig(env) {
44
+ const port = Number(env.OPENTAB_GRPC_PORT ?? "20000");
45
+ if (!Number.isInteger(port) || port < 1 || port > 65535) throw new CliError("bad_config", "OPENTAB_GRPC_PORT must be a port number");
46
+ let bureau = TESTNET_BUREAU;
47
+ if (env.OPENTAB_BUREAU !== void 0 && env.OPENTAB_BUREAU !== "") {
48
+ try {
49
+ bureau = parseContractAddress(env.OPENTAB_BUREAU);
50
+ } catch {
51
+ throw new CliError("bad_config", "OPENTAB_BUREAU must be `index,subindex`");
52
+ }
53
+ }
54
+ const home = env.HOME ?? homedir();
55
+ return {
56
+ grpcHost: env.OPENTAB_GRPC_HOST ?? "grpc.testnet.concordium.com",
57
+ grpcPort: port,
58
+ bureau,
59
+ anchorAccount: env.OPENTAB_ANCHOR_ACCOUNT ?? TESTNET_ANCHOR_ACCOUNT,
60
+ drpAnchorAccounts: accountList(env, "OPENTAB_DRP_ANCHOR_ACCOUNTS") ?? TESTNET_DRP_ANCHOR_ACCOUNTS,
61
+ indexerUrl: optionalUrl(env, "INDEXER_URL"),
62
+ publicBaseUrl: optionalUrl(env, "PUBLIC_BASE_URL"),
63
+ notaryUrl: optionalUrl(env, "NOTARY_URL"),
64
+ facilitatorUrl: optionalUrl(env, "FACILITATOR_URL"),
65
+ keydSocket: env.KEYD_SOCKET ?? join(home, ".opentab", "run", "keyd.sock"),
66
+ keysDir: env.OPENTAB_KEYS_DIR ?? join(home, "opentab-keys")
67
+ };
68
+ }
69
+ export {
70
+ TESTNET_ANCHOR_ACCOUNT,
71
+ TESTNET_BUREAU,
72
+ cliConfig
73
+ };
@@ -0,0 +1,74 @@
1
+ import {
2
+ ReportBuilder
3
+ } from "./chunk-GOEFQ62Z.js";
4
+ import {
5
+ CliError
6
+ } from "./chunk-MOZ4BFSB.js";
7
+ import {
8
+ formatContractAddress
9
+ } from "./chunk-D3C7KAMJ.js";
10
+
11
+ // packages/cli/src/commands/gate.ts
12
+ import { z } from "zod";
13
+ var pricesSchema = z.record(z.string().regex(/^([A-Z]+ )?\/\S*$/).max(256), z.string().regex(/^[1-9][0-9]{0,19}$/)).refine((p) => Object.keys(p).length > 0, "at least one priced route");
14
+ function url(v, name, httpsOnly) {
15
+ if (v === void 0) throw new CliError("usage", `gate up needs ${name}`);
16
+ let u;
17
+ try {
18
+ u = new URL(v);
19
+ } catch {
20
+ throw new CliError("usage", `${name} is not a URL`);
21
+ }
22
+ if (httpsOnly ? u.protocol !== "https:" : u.protocol !== "https:" && u.protocol !== "http:") throw new CliError("usage", `${name} must be ${httpsOnly ? "https" : "http(s)"}`);
23
+ return v.replace(/\/+$/, "");
24
+ }
25
+ function gateUp(env, a) {
26
+ if (a.sellerToken === void 0 || !/^(0|[1-9][0-9]{0,19})$/.test(a.sellerToken)) throw new CliError("usage", "gate up needs --seller-token <CIS-8004 token id>");
27
+ const publicUrl = url(a.publicUrl ?? env.config.publicBaseUrl ?? void 0, "--public-url", true);
28
+ const upstream = url(a.upstream, "--upstream", false);
29
+ const facilitator = env.config.facilitatorUrl;
30
+ if (facilitator === null) throw new CliError("usage", "set FACILITATOR_URL");
31
+ let prices;
32
+ try {
33
+ prices = pricesSchema.parse(JSON.parse(a.prices));
34
+ } catch {
35
+ throw new CliError("usage", '--prices must be JSON mapping "[METHOD ]PATH" to microCCD, e.g. {"GET /v1/*":"1000000"}');
36
+ }
37
+ if (a.mode !== "full" && a.mode !== "passthrough") throw new CliError("usage", "--mode must be full or passthrough");
38
+ if (a.exactPrice !== void 0 && !/^[1-9][0-9]{0,19}$/.test(a.exactPrice)) throw new CliError("usage", "--exact-price must be microCCD");
39
+ const vars = [
40
+ ["PUBLIC_URL", publicUrl],
41
+ ["UPSTREAM_URL", upstream],
42
+ ["SELLER_TOKEN", a.sellerToken],
43
+ ["BUREAU", formatContractAddress(env.config.bureau).replace(/[<>]/g, "")],
44
+ ["PRICES", JSON.stringify(prices)],
45
+ ["FACILITATOR_URL", facilitator],
46
+ ["KEYD_SOCKET", "/run/opentab/keyd.sock"],
47
+ ["KEYD_SELLER_KEY", a.keydKey],
48
+ ["MODE", a.mode],
49
+ ["STORE_PATH", "/data/tab-gate.sqlite"]
50
+ ];
51
+ if (a.mode === "passthrough") vars.push(["PASSTHROUGH_SECRET_FILE", "/run/secrets/tab-gate-upstream"]);
52
+ if (a.exactPrice !== void 0) vars.push(["EXACT_PRICE_MICROCCD", a.exactPrice]);
53
+ const envFile = vars.map(([k, v]) => `${k}=${k === "PRICES" ? `'${v}'` : v}`).join("\n");
54
+ const run = [
55
+ "docker run -d --name tab-gate -p 8403:8403",
56
+ "--env-file tab-gate.env",
57
+ `-v ${env.config.keydSocket}:/run/opentab/keyd.sock`,
58
+ "-v tab-gate-data:/data",
59
+ ...a.mode === "passthrough" ? ["-v ./tab-gate-upstream.secret:/run/secrets/tab-gate-upstream:ro"] : [],
60
+ a.image
61
+ ].join(" \\\n ");
62
+ const rb = new ReportBuilder(`tab-gate for seller ${a.sellerToken}`);
63
+ rb.check("configuration is complete", true, "save the env file as tab-gate.env, then run the docker line");
64
+ rb.fact("tab-gate.env", `
65
+ ${envFile}`);
66
+ rb.fact("docker", `
67
+ ${run}`);
68
+ rb.fact("build the image", "docker build -f services/tab-gate/Dockerfile -t opentab-tab-gate . (from the repository root)");
69
+ rb.fact("needs", "the seller registered with tab_bureau.registerSeller (opentab init --role seller) and keyd serving the seller key");
70
+ return rb.build();
71
+ }
72
+ export {
73
+ gateUp
74
+ };