@esseyonsui/sui-mcp-v3 0.1.8 → 0.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.
Files changed (52) hide show
  1. package/README.md +37 -7
  2. package/dist/agent.d.ts.map +1 -1
  3. package/dist/agent.js +2 -2
  4. package/dist/args.d.ts +11 -2
  5. package/dist/args.d.ts.map +1 -1
  6. package/dist/args.js +37 -10
  7. package/dist/artifact-cache.d.ts +14 -0
  8. package/dist/artifact-cache.d.ts.map +1 -0
  9. package/dist/artifact-cache.js +48 -0
  10. package/dist/client.d.ts +1 -1
  11. package/dist/client.d.ts.map +1 -1
  12. package/dist/client.js +5 -3
  13. package/dist/config.d.ts +2 -0
  14. package/dist/config.d.ts.map +1 -1
  15. package/dist/config.js +5 -0
  16. package/dist/fund.d.ts.map +1 -1
  17. package/dist/fund.js +2 -2
  18. package/dist/handles.d.ts +23 -0
  19. package/dist/handles.d.ts.map +1 -0
  20. package/dist/handles.js +142 -0
  21. package/dist/http.d.ts +6 -0
  22. package/dist/http.d.ts.map +1 -0
  23. package/dist/http.js +5 -0
  24. package/dist/init.d.ts +7 -0
  25. package/dist/init.d.ts.map +1 -1
  26. package/dist/init.js +18 -11
  27. package/dist/io.d.ts +22 -12
  28. package/dist/io.d.ts.map +1 -1
  29. package/dist/io.js +194 -142
  30. package/dist/keys.d.ts +2 -0
  31. package/dist/keys.d.ts.map +1 -1
  32. package/dist/keys.js +14 -1
  33. package/dist/main.js +21 -9
  34. package/dist/records.d.ts +21 -4
  35. package/dist/records.d.ts.map +1 -1
  36. package/dist/records.js +74 -21
  37. package/dist/reveal.d.ts +7 -0
  38. package/dist/reveal.d.ts.map +1 -0
  39. package/dist/reveal.js +40 -0
  40. package/dist/snapshot.d.ts +13 -0
  41. package/dist/snapshot.d.ts.map +1 -0
  42. package/dist/snapshot.js +29 -0
  43. package/dist/tools-badge.js +3 -3
  44. package/dist/tools-more.d.ts +9 -5
  45. package/dist/tools-more.d.ts.map +1 -1
  46. package/dist/tools-more.js +56 -12
  47. package/dist/tools-sales.d.ts.map +1 -1
  48. package/dist/tools-sales.js +34 -24
  49. package/dist/tools.d.ts +3 -0
  50. package/dist/tools.d.ts.map +1 -1
  51. package/dist/tools.js +64 -30
  52. package/package.json +4 -3
package/dist/records.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Essey, SaleRecord } from "@esseyonsui/sui-sdk-v3";
1
+ import type { Essey, Pending, SaleRecord } from "@esseyonsui/sui-sdk-v3";
2
2
  export type Terms = Parameters<Essey["loans"]["payBack"]>[0]["terms"];
3
3
  export type OfferRecord = Awaited<ReturnType<Essey["loans"]["lend"]>>["offer"];
4
4
  export type BidRecord = Awaited<ReturnType<Essey["sales"]["bid"]>>["bid"];
@@ -10,9 +10,10 @@ export type LoanRecord = {
10
10
  borrowerPk?: bigint;
11
11
  };
12
12
  /**
13
- * What a cycle step needs from an earlier one and no chain read gives back: `loan-<id>.json`, `offer-<id>.json`,
14
- * `sale-<room>.json`, `bid-<room>.json`, mode 600 beside the state file, sealed under `recordKey`. A file written
15
- * before sealing (the JSON `scripts/v3/live/run.mts` writes) is still read, and sealed on its next save.
13
+ * What a cycle step needs from an earlier one and no chain read gives back, mode 600 beside the state file, sealed
14
+ * under `recordKey`. PRV-10: each file is `r-<hmac of kind and id>.json`, so a listing names no loan or room; the
15
+ * kind and id are inside the seal. A `loan-<id>.json`-style file (older servers, or the plain JSON
16
+ * `scripts/v3/live/run.mts` writes) is moved to its blind name when the store opens.
16
17
  */
17
18
  export type Records = {
18
19
  loan(id: string): LoanRecord;
@@ -23,6 +24,12 @@ export type Records = {
23
24
  saveSale(room: string, record: SaleRecord): void;
24
25
  bid(room: string): BidRecord;
25
26
  saveBid(room: string, record: BidRecord): void;
27
+ /** Every record held, opened. Only the local reveal CLI prints it; no tool returns it. */
28
+ all(): {
29
+ kind: string;
30
+ id: string;
31
+ record: Record<string, unknown> | null;
32
+ }[];
26
33
  /** Every record into one new sealed mode-600 file at `path`. Returns how many it holds. */
27
34
  exportTo(path: string): number;
28
35
  /** The records of an `exportTo` file. One this server already holds is kept, not overwritten. */
@@ -30,8 +37,18 @@ export type Records = {
30
37
  imported: number;
31
38
  kept: number;
32
39
  };
40
+ /** PRV-11: a split payout's unpaid pieces, sealed in `payouts.json`; null when none is pending. */
41
+ payouts(): Pending | null;
42
+ /** null deletes the file. */
43
+ savePayouts(pending: Pending | null): void;
33
44
  };
34
45
  /** The records key: HKDF-SHA256 of the note seed under a fixed label, so the seed itself never leaves `main.ts`. */
35
46
  export declare function recordKey(seed: Uint8Array): Uint8Array;
47
+ /** PRV-36a: the SDK state file's sealing key, under its own label so it never equals the records key. */
48
+ export declare function stateKey(seed: Uint8Array): Uint8Array;
49
+ /** `label` is the AAD: a sealed file opens only under the name it was written for. */
50
+ export declare function seal(key: Uint8Array, label: string, v: unknown): string;
51
+ export declare function unseal(key: Uint8Array, label: string, sealed: string): Record<string, unknown>;
52
+ export declare function writePrivate(target: string, text: string): void;
36
53
  export declare function fileRecords(dir: string, key: Uint8Array): Records;
37
54
  //# sourceMappingURL=records.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"records.d.ts","sourceRoot":"","sources":["../src/records.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAOhE,MAAM,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;AACtE,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;AAC/E,MAAM,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK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node:crypto";
2
- import { chmodSync, mkdirSync, readdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
2
+ import { chmodSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, unlinkSync, writeFileSync, } from "node:fs";
3
3
  import { isAbsolute, join } from "node:path";
4
4
  import { xchacha20poly1305 } from "@noble/ciphers/chacha.js";
5
5
  import { hkdf } from "@noble/hashes/hkdf.js";
6
+ import { hmac } from "@noble/hashes/hmac.js";
6
7
  import { sha256 } from "@noble/hashes/sha2.js";
7
8
  import { ToolRefusal } from "./failure.js";
9
+ const PAYOUTS = "payouts.json";
8
10
  const LOAN_ID = /^0x[0-9a-f]{64}$/;
9
- const RECORD_FILE = /^(loan|offer|sale|bid)-(0x[0-9a-f]{64})\.json$/;
11
+ const NAMED_FILE = /^(loan|offer|sale|bid)-(0x[0-9a-f]{64})\.json$/;
12
+ const BLIND_FILE = /^r-[0-9a-f]{32}\.json$/;
10
13
  const KINDS = ["loan", "offer", "sale", "bid"];
11
14
  const EXPORT_LABEL = "export";
12
15
  const NONCE = 24;
@@ -26,18 +29,22 @@ function noRecord(kind) {
26
29
  export function recordKey(seed) {
27
30
  return hkdf(sha256, seed, undefined, utf8("essey-v3-mcp records v1"), 32);
28
31
  }
32
+ /** PRV-36a: the SDK state file's sealing key, under its own label so it never equals the records key. */
33
+ export function stateKey(seed) {
34
+ return hkdf(sha256, seed, undefined, utf8("essey-v3-mcp state v1"), 32);
35
+ }
29
36
  /** `label` is the AAD: a sealed file opens only under the name it was written for. */
30
- function seal(key, label, v) {
37
+ export function seal(key, label, v) {
31
38
  const nonce = randomBytes(NONCE);
32
39
  const box = xchacha20poly1305(key, nonce, utf8(label)).encrypt(utf8(plain(v)));
33
40
  return JSON.stringify({ sealed: Buffer.concat([nonce, box]).toString("base64") });
34
41
  }
35
- function unseal(key, label, sealed) {
42
+ export function unseal(key, label, sealed) {
36
43
  const bytes = Buffer.from(sealed, "base64");
37
44
  const text = xchacha20poly1305(key, bytes.subarray(0, NONCE), utf8(label)).decrypt(bytes.subarray(NONCE));
38
45
  return JSON.parse(new TextDecoder().decode(text));
39
46
  }
40
- function writePrivate(target, text) {
47
+ export function writePrivate(target, text) {
41
48
  const tmp = `${target}.${randomBytes(6).toString("hex")}.tmp`;
42
49
  writeFileSync(tmp, text, { mode: 0o600, flag: "wx" });
43
50
  chmodSync(tmp, 0o600);
@@ -63,43 +70,61 @@ function exportRows(text, key) {
63
70
  });
64
71
  }
65
72
  export function fileRecords(dir, key) {
66
- const path = (kind, id) => {
73
+ const nameKey = hkdf(sha256, key, undefined, utf8("essey-v3-mcp record names v1"), 32);
74
+ const blindName = (kind, id) => {
67
75
  if (!LOAN_ID.test(id))
68
76
  throw new ToolRefusal("loan must be 0x and 64 hex digits");
69
- return join(dir, `${kind}-${id}.json`);
77
+ return `r-${Buffer.from(hmac(sha256, nameKey, utf8(`${kind}-${id}`)))
78
+ .toString("hex")
79
+ .slice(0, 32)}.json`;
70
80
  };
71
- const read = (kind, id) => {
81
+ const opened = (name) => {
72
82
  let v;
73
83
  try {
74
- v = JSON.parse(readFileSync(path(kind, id), "utf8"));
84
+ v = JSON.parse(readFileSync(join(dir, name), "utf8"));
75
85
  }
76
86
  catch (err) {
77
87
  if (err.code === "ENOENT")
78
88
  return null;
79
89
  throw err;
80
90
  }
81
- return typeof v.sealed === "string" ? unseal(key, `${kind}-${id}`, v.sealed) : v;
91
+ return unseal(key, name, String(v.sealed));
82
92
  };
83
- const write = (kind, id, v) => {
84
- const target = path(kind, id);
93
+ const read = (kind, id) => {
94
+ const row = opened(blindName(kind, id));
95
+ if (row && (row.kind !== kind || row.id !== id))
96
+ throw new ToolRefusal("a record file holds another record");
97
+ return row?.record ?? null;
98
+ };
99
+ const write = (kind, id, record) => {
100
+ const name = blindName(kind, id);
85
101
  mkdirSync(dir, { recursive: true, mode: 0o700 });
86
- writePrivate(target, seal(key, `${kind}-${id}`, v));
102
+ writePrivate(join(dir, name), seal(key, name, { kind, id, record }));
87
103
  };
88
- const held = () => {
89
- let names;
104
+ const names = () => {
90
105
  try {
91
- names = readdirSync(dir);
106
+ return readdirSync(dir);
92
107
  }
93
108
  catch (err) {
94
109
  if (err.code === "ENOENT")
95
110
  return [];
96
111
  throw err;
97
112
  }
98
- return names.flatMap((n) => {
99
- const m = RECORD_FILE.exec(n);
100
- return m ? [{ kind: m[1], id: m[2] }] : [];
101
- });
102
113
  };
114
+ const held = () => names().flatMap((n) => {
115
+ const row = BLIND_FILE.test(n) ? opened(n) : null;
116
+ return row ? [{ kind: row.kind, id: row.id }] : [];
117
+ });
118
+ const all = () => held().map(({ kind, id }) => ({ kind, id, record: read(kind, id) }));
119
+ for (const n of names()) {
120
+ const m = NAMED_FILE.exec(n);
121
+ if (!m)
122
+ continue;
123
+ const [kind, id] = [m[1], m[2]];
124
+ const v = JSON.parse(readFileSync(join(dir, n), "utf8"));
125
+ write(kind, id, typeof v.sealed === "string" ? unseal(key, `${kind}-${id}`, v.sealed) : v);
126
+ unlinkSync(join(dir, n));
127
+ }
103
128
  const absolute = (p) => {
104
129
  if (!isAbsolute(p))
105
130
  throw new ToolRefusal("path must be absolute");
@@ -149,8 +174,9 @@ export function fileRecords(dir, key) {
149
174
  };
150
175
  },
151
176
  saveBid: (room, record) => write("bid", room, record),
177
+ all,
152
178
  exportTo: (target) => {
153
- const records = held().map(({ kind, id }) => ({ kind, id, record: read(kind, id) }));
179
+ const records = all();
154
180
  try {
155
181
  writeFileSync(absolute(target), seal(key, EXPORT_LABEL, { records }), { mode: 0o600, flag: "wx" });
156
182
  }
@@ -182,5 +208,32 @@ export function fileRecords(dir, key) {
182
208
  }
183
209
  return { imported, kept: rows.length - imported };
184
210
  },
211
+ payouts: () => {
212
+ let text;
213
+ try {
214
+ text = readFileSync(join(dir, PAYOUTS), "utf8");
215
+ }
216
+ catch (err) {
217
+ if (err.code === "ENOENT")
218
+ return null;
219
+ throw err;
220
+ }
221
+ const r = unseal(key, PAYOUTS, JSON.parse(text).sealed);
222
+ return {
223
+ coin: r.coin,
224
+ pieces: r.pieces.map((p) => ({
225
+ amount: BigInt(p.amount),
226
+ to: p.to,
227
+ })),
228
+ notBeforeMs: r.notBeforeMs,
229
+ spent: r.spent,
230
+ };
231
+ },
232
+ savePayouts: (pending) => {
233
+ if (pending === null)
234
+ return rmSync(join(dir, PAYOUTS), { force: true });
235
+ mkdirSync(dir, { recursive: true, mode: 0o700 });
236
+ writePrivate(join(dir, PAYOUTS), seal(key, PAYOUTS, pending));
237
+ },
185
238
  };
186
239
  }
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * PRV-36d: the operator's own view of the sealed records and of the PRV-04 handle table (what each `h_` handle a
4
+ * tool returned stands for), printed on this terminal and never through MCP, so the model never sees it.
5
+ */
6
+ export declare function reveal(env: NodeJS.ProcessEnv): string;
7
+ //# sourceMappingURL=reveal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reveal.d.ts","sourceRoot":"","sources":["../src/reveal.ts"],"names":[],"mappings":";AAUA;;;GAGG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,GAAG,MAAM,CAarD"}
package/dist/reveal.js ADDED
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env node
2
+ import { realpathSync } from "node:fs";
3
+ import { dirname } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { ConfigError } from "./config.js";
6
+ import { handleRows } from "./handles.js";
7
+ import { loadNoteSeed } from "./keys.js";
8
+ import { fileRecords, recordKey } from "./records.js";
9
+ /**
10
+ * PRV-36d: the operator's own view of the sealed records and of the PRV-04 handle table (what each `h_` handle a
11
+ * tool returned stands for), printed on this terminal and never through MCP, so the model never sees it.
12
+ */
13
+ export function reveal(env) {
14
+ const stateFile = env.ESSEY_STATE_FILE;
15
+ const keyFile = env.ESSEY_NOTE_KEY_FILE;
16
+ if (!stateFile || !keyFile)
17
+ throw new ConfigError("ESSEY_STATE_FILE and ESSEY_NOTE_KEY_FILE are required");
18
+ const seed = loadNoteSeed(keyFile);
19
+ try {
20
+ const dir = dirname(stateFile);
21
+ const key = recordKey(seed);
22
+ const shown = { records: fileRecords(dir, key).all(), handles: handleRows(dir, key) };
23
+ return JSON.stringify(shown, (_k, v) => (typeof v === "bigint" ? v.toString() : v), 2);
24
+ }
25
+ finally {
26
+ seed.fill(0);
27
+ }
28
+ }
29
+ function main() {
30
+ try {
31
+ process.stdout.write(`${reveal(process.env)}\n`);
32
+ }
33
+ catch (err) {
34
+ const why = err instanceof ConfigError ? err.message : "the records did not open under this note key";
35
+ process.stderr.write(`essey-sui-mcp-v3-reveal: ${why}\n`);
36
+ process.exit(1);
37
+ }
38
+ }
39
+ if (process.argv[1] && realpathSync(process.argv[1]) === fileURLToPath(import.meta.url))
40
+ main();
@@ -0,0 +1,13 @@
1
+ export type Snapshot<T> = {
2
+ /** The held walk while younger than `ttlMs`, otherwise a fresh one. */
3
+ get(): Promise<T>;
4
+ /** `pick` over the held walk; on a miss over an older walk, once more over a fresh one. */
5
+ find<R>(pick: (set: T) => R | undefined): Promise<R | undefined>;
6
+ drop(): void;
7
+ };
8
+ /**
9
+ * PRV-32: one full walk of a public set serves every lookup for `ttlMs`, so no read names the object it wants.
10
+ * A failed walk is not held.
11
+ */
12
+ export declare function snapshot<T>(walk: () => Promise<T>, ttlMs: number, now?: () => number): Snapshot<T>;
13
+ //# sourceMappingURL=snapshot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../src/snapshot.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI;IACxB,uEAAuE;IACvE,GAAG,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC;IAClB,2FAA2F;IAC3F,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,SAAS,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;IACjE,IAAI,IAAI,IAAI,CAAC;CACd,CAAC;AAEF;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EACxB,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACtB,KAAK,EAAE,MAAM,EACb,GAAG,GAAE,MAAM,MAAiB,GAC3B,QAAQ,CAAC,CAAC,CAAC,CAuBb"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * PRV-32: one full walk of a public set serves every lookup for `ttlMs`, so no read names the object it wants.
3
+ * A failed walk is not held.
4
+ */
5
+ export function snapshot(walk, ttlMs, now = Date.now) {
6
+ let held;
7
+ const fresh = () => held !== undefined && now() - held.at < ttlMs;
8
+ const load = () => {
9
+ const set = walk();
10
+ held = { at: now(), set };
11
+ set.catch(() => {
12
+ if (held?.set === set)
13
+ held = undefined;
14
+ });
15
+ return set;
16
+ };
17
+ const get = () => (fresh() ? held.set : load());
18
+ return {
19
+ get,
20
+ async find(pick) {
21
+ const wasHeld = fresh();
22
+ const hit = pick(await get());
23
+ return hit !== undefined || !wasHeld ? hit : pick(await load());
24
+ },
25
+ drop: () => {
26
+ held = undefined;
27
+ },
28
+ };
29
+ }
@@ -5,13 +5,13 @@ export const BADGE_TOOLS = [
5
5
  {
6
6
  name: "essey_badge_grant",
7
7
  kind: "call",
8
- description: "Seller, testnet: ask the service for one demo Badge to sell, minted to essey_agent_address with the gas " +
9
- "SUI its hand-over needs. Needs a credential; one grant per credential per UTC day. The agent address is " +
8
+ description: "Seller, testnet: ask the service for one demo Badge to sell, minted with a little gas SUI to a fresh " +
9
+ "single-use essey_item_address. Needs a credential; one grant per credential per UTC day. The address is " +
10
10
  "public on chain and the service sees it beside this credential's day-tag. Returns the digest and the " +
11
11
  "itemId and itemType to pass to essey_sale_open.",
12
12
  inputSchema: objectSchema({}, []),
13
13
  run: async (ctx) => {
14
- const { digest, badge } = await ctx.client.sales.badgeGrant(ctx.client.sales.agentAddress);
14
+ const { digest, badge } = await ctx.client.sales.badgeGrant();
15
15
  return { ok: true, digest, itemId: badge, itemType: TESTNET_BADGE_TYPE };
16
16
  },
17
17
  },
@@ -1,16 +1,20 @@
1
- import { type Payout } from "@esseyonsui/sui-sdk-v3";
2
- import type { Tool } from "./tools.ts";
3
- /** The top-level digest is the last piece's, the one `bind` waits to see indexed. */
4
- export declare function paidOut(rows: Payout[]): {
1
+ import { type Staged } from "@esseyonsui/sui-sdk-v3";
2
+ import type { Tool, ToolContext } from "./tools.ts";
3
+ export declare const SPLIT: string;
4
+ /** PRV-11: a pending split is saved before the result returns. No piece amount is returned. */
5
+ export declare function staged(ctx: ToolContext, s: Staged): {
6
+ notBeforeMs?: number | undefined;
5
7
  ok: true;
6
8
  digest: string;
7
9
  payouts: {
8
10
  digest: string;
9
11
  ticket: string;
10
- amount: string;
11
12
  to: string;
12
13
  }[];
14
+ left: number;
13
15
  };
16
+ /** A new plan would spend notes the pending pieces were planned against (`refuseUncovered`). */
17
+ export declare function refuseWhilePaying(ctx: ToolContext): void;
14
18
  /** No SDK call behind either, so they sit outside `MORE`. */
15
19
  export declare const RECORD_TOOLS: Tool[];
16
20
  export declare const MORE: Tool[];
@@ -1 +1 @@
1
- {"version":3,"file":"tools-more.d.ts","sourceRoot":"","sources":["../src/tools-more.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,KAAK,MAAM,EAAkB,MAAM,wBAAwB,CAAC;AAgB5F,OAAO,KAAK,EAAE,IAAI,EAAe,MAAM,YAAY,CAAC;AAsCpD,qFAAqF;AACrF,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE;;;;;;;;;EAMrC;AAiPD,6DAA6D;AAC7D,eAAO,MAAM,YAAY,EAAE,IAAI,EAoB9B,CAAC;AAEF,eAAO,MAAM,IAAI,EAAE,IAAI,EAA6C,CAAC"}
1
+ {"version":3,"file":"tools-more.d.ts","sourceRoot":"","sources":["../src/tools-more.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuD,KAAK,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAiB1G,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAsCpD,eAAO,MAAM,KAAK,QAI0B,CAAC;AAE7C,+FAA+F;AAC/F,wBAAgB,MAAM,CAAC,GAAG,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM;;;;;;;;;;EASjD;AAED,gGAAgG;AAChG,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,WAAW,GAAG,IAAI,CAGxD;AAgRD,6DAA6D;AAC7D,eAAO,MAAM,YAAY,EAAE,IAAI,EAoB9B,CAAC;AAEF,eAAO,MAAM,IAAI,EAAE,IAAI,EAA6C,CAAC"}
@@ -1,7 +1,7 @@
1
- import { COINS } from "@esseyonsui/sui-sdk-v3";
2
- import { FORCE, LOAN_SCHEMA, OPEN_SCHEMA, PAYEES, int, parseAmount, parseCoin, parseForce, parseLoanId, parsePayees, } from "./args.js";
1
+ import { COINS, isEsseyError } from "@esseyonsui/sui-sdk-v3";
2
+ import { ALLOW_REUSE, FORCE, LOAN_SCHEMA, OPEN_SCHEMA, PAYEES, int, parseAmount, parseCoin, parseLoanId, parsePayees, parseSpend, } from "./args.js";
3
3
  import { isSdkCode, ToolRefusal } from "./failure.js";
4
- import { WAITS_LONG, WAITS_MEDIUM, WAITS_SHORT } from "./pace.js";
4
+ import { NotBefore, WAITS_LONG, WAITS_MEDIUM, WAITS_SHORT } from "./pace.js";
5
5
  /** `move/v3/loan/sources/loan.move:40` MAX_OFFERS = 16. */
6
6
  const MAX_SEQ = 15;
7
7
  const MAX_MS = Number.MAX_SAFE_INTEGER;
@@ -27,14 +27,46 @@ function bad(msg) {
27
27
  function landed(row) {
28
28
  return { ok: true, digest: row.digest, ticket: row.ticket };
29
29
  }
30
- /** The top-level digest is the last piece's, the one `bind` waits to see indexed. */
31
- export function paidOut(rows) {
30
+ export const SPLIT = " With more than one piece the call pays the first and keeps the rest in a sealed file beside the state file; " +
31
+ "essey_notes_withdraw_continue pays each next one a random 2 to 30 min after the last. A listed address this " +
32
+ "server already paid is refused unless allowReuse is true. Spend each piece from its own address: funding or " +
33
+ "sweeping them together joins them again.";
34
+ /** PRV-11: a pending split is saved before the result returns. No piece amount is returned. */
35
+ export function staged(ctx, s) {
36
+ ctx.records.savePayouts(s.pending);
32
37
  return {
33
38
  ok: true,
34
- digest: rows[rows.length - 1].digest,
35
- payouts: rows.map((r) => ({ digest: r.digest, ticket: r.ticket, amount: r.amount.toString(), to: r.to })),
39
+ digest: s.paid.digest,
40
+ payouts: [{ digest: s.paid.digest, ticket: s.paid.ticket, to: s.paid.to }],
41
+ left: s.pending?.pieces.length ?? 0,
42
+ ...(s.pending ? { notBeforeMs: s.pending.notBeforeMs } : {}),
36
43
  };
37
44
  }
45
+ /** A new plan would spend notes the pending pieces were planned against (`refuseUncovered`). */
46
+ export function refuseWhilePaying(ctx) {
47
+ if (ctx.records.payouts())
48
+ bad("a split withdraw or exit is still paying out: call essey_notes_withdraw_continue until left is 0");
49
+ }
50
+ /**
51
+ * Write-ahead: the next piece leaves the file before it is sent, so a crash never pays it twice. A failure puts it
52
+ * back, except an unknown outcome, which may have landed.
53
+ */
54
+ async function continuePayout(ctx) {
55
+ const due = ctx.records.payouts() ?? bad("no split withdraw or exit is paying out");
56
+ if (Date.now() < due.notBeforeMs)
57
+ throw new NotBefore(due.notBeforeMs);
58
+ ctx.records.savePayouts(due.pieces.length > 1 ? { ...due, pieces: due.pieces.slice(1) } : null);
59
+ let paid;
60
+ try {
61
+ paid = await ctx.client.notes.payNext(due);
62
+ }
63
+ catch (err) {
64
+ if (!isEsseyError(err, "RELAY_OUTCOME_UNKNOWN"))
65
+ ctx.records.savePayouts(due);
66
+ throw err;
67
+ }
68
+ return staged(ctx, paid);
69
+ }
38
70
  function keeperArgs(args) {
39
71
  const loan = parseLoanId(args);
40
72
  if (args.via === undefined)
@@ -65,7 +97,7 @@ const REFI = [
65
97
  kind: "call",
66
98
  description: "Borrower of an active loan settled from this server: open a refinance round for a new principal that pays the " +
67
99
  "current lender what is owed. Lenders offer with essey_loan_request and essey_loan_offer as on a new loan. " +
68
- "Returns the digest, ticket, round and when offers close.",
100
+ "Returns the digest, round and when offers close.",
69
101
  inputSchema: obj({
70
102
  loan: LOAN,
71
103
  principal: {
@@ -97,7 +129,7 @@ const REFI = [
97
129
  name: "essey_loan_refi_settle",
98
130
  kind: "call",
99
131
  description: "Borrower, after the refinance window: take the lowest eligible offer. The old lender is paid and collects with " +
100
- `essey_loan_collect; this server keeps the new terms. Returns the digest, ticket, rate, amount owed and maturity.${WAITS_MEDIUM}`,
132
+ `essey_loan_collect; this server keeps the new terms. Returns the digest, rate, amount owed and maturity.${WAITS_MEDIUM}`,
101
133
  inputSchema: LOAN_SCHEMA,
102
134
  run: async (ctx, args) => {
103
135
  const settled = own(ctx, parseLoanId(args));
@@ -222,17 +254,29 @@ const NOTES = [
222
254
  description: "Withdraw the notes of a coin, at most two. With denominations, the largest denomination sum they cover with " +
223
255
  "every piece's fees goes out as pieces, each to its own address in to, and kept stays in a note; a refusal " +
224
256
  "names how many addresses it needs. force: true, or a coin without denominations: everything less fees to " +
225
- `one address. Returns each piece's digest, ticket, amount and address.${WAITS_LONG}`,
257
+ `one address. Returns the piece's digest and address, left and notBeforeMs.${SPLIT}${WAITS_LONG}`,
226
258
  inputSchema: obj({
227
259
  coin: { type: "string", enum: [...COINS] },
228
260
  to: PAYEES,
229
261
  force: FORCE,
262
+ allowReuse: ALLOW_REUSE,
230
263
  }, ["coin", "to"]),
231
264
  run: async (ctx, args) => {
232
- const out = await ctx.client.notes.exit(parseCoin(args), parsePayees(args), parseForce(args));
233
- return { ...paidOut(out.payouts), kept: out.kept.toString() };
265
+ const [coin, to, o] = [parseCoin(args), parsePayees(args), parseSpend(args)];
266
+ refuseWhilePaying(ctx);
267
+ const out = await ctx.client.notes.exitFirst(coin, to, o);
268
+ return { ...staged(ctx, out), kept: out.kept.toString() };
234
269
  },
235
270
  },
271
+ {
272
+ name: "essey_notes_withdraw_continue",
273
+ kind: "call",
274
+ description: "Pay the next piece of the split withdraw or exit this server is paying out. Before its time it answers " +
275
+ "NOT_BEFORE with notBeforeMs. Returns the piece's digest and address, left (pieces still to pay) and, " +
276
+ "while left is above 0, notBeforeMs for the next. The schedule is a sealed file, so it survives a restart.",
277
+ inputSchema: obj(),
278
+ run: (ctx) => continuePayout(ctx),
279
+ },
236
280
  {
237
281
  name: "essey_notes_recover",
238
282
  kind: "call",
@@ -1 +1 @@
1
- {"version":3,"file":"tools-sales.d.ts","sourceRoot":"","sources":["../src/tools-sales.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,IAAI,EAAe,MAAM,YAAY,CAAC;AAwQpD,eAAO,MAAM,UAAU,EAAE,IAAI,EAA2B,CAAC"}
1
+ {"version":3,"file":"tools-sales.d.ts","sourceRoot":"","sources":["../src/tools-sales.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,IAAI,EAAe,MAAM,YAAY,CAAC;AAqRpD,eAAO,MAAM,UAAU,EAAE,IAAI,EAA2B,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { isEsseyError, v3 } from "@esseyonsui/sui-sdk-v3";
2
- import { ADDRESS, AMOUNT, COIN, MS, address, int, objectSchema, optBool, parseAmount, parseCoin, payee, } from "./args.js";
2
+ import { ADDRESS, AMOUNT, COIN, MS, address, int, objectSchema, optBool, orHandle, parseAmount, parseCoin, payee, } from "./args.js";
3
3
  import { ToolRefusal } from "./failure.js";
4
4
  import { WAITS_LONG, WAITS_MEDIUM } from "./pace.js";
5
5
  const SLOTS = v3.sales.SLOTS;
@@ -22,7 +22,7 @@ function summary(row) {
22
22
  const state = ROOM_STATES[row.state] ?? "unknown";
23
23
  return { id: row.id, coin: row.coin, state, closeMs: row.closeMs, bids: row.bids };
24
24
  }
25
- function parseSaleOpen(args, nowMs) {
25
+ function parseSaleOpen(args) {
26
26
  const minPrice = parseAmount(args, "minPrice");
27
27
  const maxPrice = parseAmount(args, "maxPrice");
28
28
  if (minPrice > maxPrice)
@@ -30,16 +30,13 @@ function parseSaleOpen(args, nowMs) {
30
30
  const itemType = args.itemType;
31
31
  if (typeof itemType !== "string" || !new RegExp(STRUCT_TAG).test(itemType))
32
32
  bad("itemType must be a non-generic struct tag, 0x<package>::<module>::<Type>");
33
- const closeMs = nowMs + int(args, "bidWindowMs", 1, Number.MAX_SAFE_INTEGER);
34
- if (!Number.isSafeInteger(closeMs))
35
- bad("bidWindowMs is too long");
36
33
  return {
37
34
  itemId: address(args, "itemId"),
38
35
  itemType,
39
36
  coin: parseCoin(args),
40
37
  minPrice,
41
38
  maxPrice,
42
- closeMs,
39
+ bidWindowMs: int(args, "bidWindowMs", 1, Number.MAX_SAFE_INTEGER),
43
40
  finishWindowMs: int(args, "finishWindowMs", 1, Number.MAX_SAFE_INTEGER),
44
41
  maxBids: int(args, "maxBids", 1, SLOTS),
45
42
  sponsored: true,
@@ -52,10 +49,10 @@ function parseBid(args) {
52
49
  bad("price must be at most deposit");
53
50
  return { room: parseRoom(args), v, amount };
54
51
  }
55
- function parseClaim(ctx, args) {
52
+ function parseClaim(args) {
56
53
  if (args.as !== "seller" && args.as !== "bidder")
57
54
  bad("as must be seller or bidder");
58
- const to = args.to === undefined ? ctx.client.sales.agentAddress : payee(args, "to");
55
+ const to = args.to === undefined ? undefined : payee(args, "to");
59
56
  return { room: parseRoom(args), as: args.as, to };
60
57
  }
61
58
  async function finish(ctx, room) {
@@ -79,23 +76,32 @@ const SELLER = [
79
76
  {
80
77
  name: "essey_agent_address",
81
78
  kind: "read",
82
- description: "The Sui address of this server's agent key. Send it the item to sell and testnet SUI for gas. The key signs " +
83
- "one kind of transaction: the item hand-over inside essey_sale_open.",
79
+ description: "The Sui address of this server's agent key, which funds deposits. An item to sell goes to " +
80
+ "essey_item_address instead; one sent here is handed over by this key inside essey_sale_open, which links " +
81
+ "the sale to this address.",
84
82
  inputSchema: objectSchema({}, []),
85
83
  run: async (ctx) => ({ ok: true, address: ctx.client.sales.agentAddress }),
86
84
  },
85
+ {
86
+ name: "essey_item_address",
87
+ kind: "call",
88
+ description: "A fresh single-use Sui address derived from the note key. Send one item to sell to it; essey_sale_open " +
89
+ "then opens from that address with no hand-over. Use a new one per item.",
90
+ inputSchema: objectSchema({}, []),
91
+ run: async (ctx) => ({ ok: true, address: ctx.client.sales.itemAddress() }),
92
+ },
87
93
  {
88
94
  name: "essey_sale_open",
89
95
  kind: "call",
90
- description: "Seller: open a sealed sale of an item essey_agent_address holds. The agent key hands the item to a fresh " +
91
- "sender derived from the note key and the relayer pays the open. Bids close bidWindowMs from now; the seller " +
92
- "finishes within finishWindowMs after that. The seller keys and price bounds stay in a mode-600 file. " +
93
- "Returns the room id, digest and ticket.",
96
+ description: "Seller: open a sealed sale of an item at an essey_item_address, which signs the open while the relayer pays. " +
97
+ "An item at essey_agent_address is first handed to a fresh sender by the agent key. Bids close bidWindowMs " +
98
+ "from now; the seller finishes within finishWindowMs after that. The seller keys and price bounds stay in a " +
99
+ "mode-600 file. Returns the room id and digest.",
94
100
  inputSchema: objectSchema({
95
- itemId: { ...ADDRESS, description: "the item's object id, owned by essey_agent_address" },
101
+ itemId: { ...ADDRESS, description: "the item's object id, at an essey_item_address" },
96
102
  itemType: {
97
103
  type: "string",
98
- pattern: STRUCT_TAG,
104
+ pattern: orHandle(STRUCT_TAG),
99
105
  maxLength: 200,
100
106
  description: "the item's struct tag, 0x<package>::<module>::<Type>",
101
107
  },
@@ -104,13 +110,16 @@ const SELLER = [
104
110
  maxPrice: { ...AMOUNT, description: "highest price settled at; sealed, never shown to bidders" },
105
111
  bidWindowMs: {
106
112
  ...MS,
107
- description: "how long bids are taken from now, milliseconds; the close rounds up to the deployment's close step (an hour unless the deployment sets closeStepMs)",
113
+ description: "how long bids are taken from now, milliseconds: 1, 6, 24 or 72 close steps (1 h, 6 h, 24 h or 72 h at the default hour step; 5 min, 30 min, 2 h or 6 h at a 5-minute closeStepMs, as on testnet); the close rounds up to the next step, and any other window is refused",
114
+ },
115
+ finishWindowMs: {
116
+ ...MS,
117
+ description: "how long after close the seller may finish, milliseconds: 6, 24 or 72 close steps (6 h, 24 h or 72 h at the default hour step; 30 min, 2 h or 6 h at a 5-minute closeStepMs); any other window is refused",
108
118
  },
109
- finishWindowMs: { ...MS, description: "how long after close the seller may finish, milliseconds" },
110
119
  maxBids: { type: "integer", minimum: 1, maximum: SLOTS, description: `1 to ${SLOTS}` },
111
120
  }, ["itemId", "itemType", "coin", "minPrice", "maxPrice", "bidWindowMs", "finishWindowMs", "maxBids"]),
112
121
  run: async (ctx, args) => {
113
- const r = await ctx.client.sales.open(parseSaleOpen(args, Date.now()));
122
+ const r = await ctx.client.sales.open(parseSaleOpen(args));
114
123
  ctx.records.saveSale(r.id, r.sale);
115
124
  return { ...landed(r), room: r.id };
116
125
  },
@@ -173,7 +182,7 @@ const BIDDER = [
173
182
  name: "essey_sale_bid",
174
183
  kind: "call",
175
184
  description: "Bidder: lock deposit from own notes of the room's coin behind a sealed bid of price. Only the seller opens " +
176
- `it, after close. The bid record stays in a mode-600 file. Returns the digest and ticket.${WAITS_MEDIUM}`,
185
+ `it, after close. The bid record stays in a mode-600 file. Returns the digest.${WAITS_MEDIUM}`,
177
186
  inputSchema: objectSchema({
178
187
  room: ROOM,
179
188
  price: { ...AMOUNT, description: "the sealed bid, in the room coin's smallest unit" },
@@ -209,17 +218,18 @@ const BIDDER = [
209
218
  name: "essey_sale_claim",
210
219
  kind: "call",
211
220
  description: "Send the room's item to an address: as bidder when this server's bid won, or as seller after a cancel or " +
212
- "expiry. to defaults to essey_agent_address.",
221
+ "expiry. to defaults to a fresh essey_item_address, from which the item can be sold again.",
213
222
  inputSchema: objectSchema({
214
223
  room: ROOM,
215
224
  as: { type: "string", enum: ["seller", "bidder"], description: "which record of this server claims" },
216
- to: { type: "string", pattern: "^0x[0-9a-fA-F]{64}$", description: "recipient address" },
225
+ to: { type: "string", pattern: orHandle("^0x[0-9a-fA-F]{64}$"), description: "recipient address" },
217
226
  }, ["room", "as"]),
218
227
  run: async (ctx, args) => {
219
- const { room, as, to } = parseClaim(ctx, args);
228
+ const { room, as, to } = parseClaim(args);
220
229
  const holder = as === "seller" ? { seller: ctx.records.sale(room).seller } : { bid: ctx.records.bid(room) };
221
230
  const vault = await ctx.client.sales.vaultOf(room);
222
- return { ...landed(await ctx.client.sales.claim({ vault, recipient: to, ...holder })), to };
231
+ const r = await ctx.client.sales.claim({ vault, ...(to ? { recipient: to } : {}), ...holder });
232
+ return { ...landed(r), to: r.to };
223
233
  },
224
234
  },
225
235
  ];