@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.
- package/README.md +37 -7
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +2 -2
- package/dist/args.d.ts +11 -2
- package/dist/args.d.ts.map +1 -1
- package/dist/args.js +37 -10
- package/dist/artifact-cache.d.ts +14 -0
- package/dist/artifact-cache.d.ts.map +1 -0
- package/dist/artifact-cache.js +48 -0
- package/dist/client.d.ts +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +5 -3
- package/dist/config.d.ts +2 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +5 -0
- package/dist/fund.d.ts.map +1 -1
- package/dist/fund.js +2 -2
- package/dist/handles.d.ts +23 -0
- package/dist/handles.d.ts.map +1 -0
- package/dist/handles.js +142 -0
- package/dist/http.d.ts +6 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +5 -0
- package/dist/init.d.ts +7 -0
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +18 -11
- package/dist/io.d.ts +22 -12
- package/dist/io.d.ts.map +1 -1
- package/dist/io.js +194 -142
- package/dist/keys.d.ts +2 -0
- package/dist/keys.d.ts.map +1 -1
- package/dist/keys.js +14 -1
- package/dist/main.js +21 -9
- package/dist/records.d.ts +21 -4
- package/dist/records.d.ts.map +1 -1
- package/dist/records.js +74 -21
- package/dist/reveal.d.ts +7 -0
- package/dist/reveal.d.ts.map +1 -0
- package/dist/reveal.js +40 -0
- package/dist/snapshot.d.ts +13 -0
- package/dist/snapshot.d.ts.map +1 -0
- package/dist/snapshot.js +29 -0
- package/dist/tools-badge.js +3 -3
- package/dist/tools-more.d.ts +9 -5
- package/dist/tools-more.d.ts.map +1 -1
- package/dist/tools-more.js +56 -12
- package/dist/tools-sales.d.ts.map +1 -1
- package/dist/tools-sales.js +34 -24
- package/dist/tools.d.ts +3 -0
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +64 -30
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -9,7 +9,8 @@ transport. Testnet only.
|
|
|
9
9
|
npx -y -p @esseyonsui/sui-mcp-v3 essey-sui-mcp-v3-init ~/.essey-v3
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
-
That writes a mode-600 note key and agent key into `~/.essey-v3
|
|
12
|
+
That writes a mode-600 note key and agent key into `~/.essey-v3/keys`, points the state file at
|
|
13
|
+
`~/.essey-v3/state/state.json` (it never overwrites one), and prints the
|
|
13
14
|
`mcpServers` entry to paste into your MCP client. Give each agent its own directory. Then ask the agent to obtain
|
|
14
15
|
a credential, take faucet notes, and open or fund a loan. Node 22.13 or later.
|
|
15
16
|
|
|
@@ -23,9 +24,11 @@ The server speaks the same hand-written stdio subset as `packages/mcp`: `initial
|
|
|
23
24
|
`ESSEY_NOTE_KEY_FILE` and `ESSEY_AGENT_KEY_FILE` are mode-600 paths. The note file is 32 raw bytes or 64 hex
|
|
24
25
|
digits; the server passes it to `Essey.connect` and does not put it on the tool context. The agent key file holds
|
|
25
26
|
the `suiprivkey` text `essey-sui-mcp-v3-init` writes (or 64 hex digits, as 0.1.x wallets hold); the server loads
|
|
26
|
-
it at startup (`src/keys.ts`) and signs two kinds of transaction with it. Inside `essey_sale_open`,
|
|
27
|
-
the
|
|
28
|
-
the room while the relayer pays (`src/agent.ts`); no tool argument names the recipient.
|
|
27
|
+
it at startup (`src/keys.ts`) and signs two kinds of transaction with it. Inside `essey_sale_open`, for an item
|
|
28
|
+
placed at the agent address only, a transfer of the item to the fresh sender the SDK derives from the note key,
|
|
29
|
+
which then opens the room while the relayer pays (`src/agent.ts`); no tool argument names the recipient. An item at
|
|
30
|
+
an `essey_item_address` (where `essey_badge_grant` mints and `essey_sale_claim` sends by default) needs no
|
|
31
|
+
hand-over: that single-use address opens the sale itself, so no two sales share an address. Inside
|
|
29
32
|
`essey_notes_deposit`, `0x2::coin::send_funds` of each deposit piece's value from the agent's own wallet to that
|
|
30
33
|
piece's fresh deposit sender (`src/fund.ts`), which reads the file again for each piece and returns a fixed error
|
|
31
34
|
with no key text when funding fails. The agent address pays the gas of both, so fund it with the coin and some SUI
|
|
@@ -36,6 +39,18 @@ invite gate for `essey_credential_obtain`. Results drop secret names (`borrowerS
|
|
|
36
39
|
not the SDK's message; a service refusal adds the service's own all-capitals code as `reason` (`RATE_LIMITED`,
|
|
37
40
|
`E_INSOLVENT`). A refusal while starting prints that code on stderr and not the message.
|
|
38
41
|
|
|
42
|
+
### Keep the keys apart from the state
|
|
43
|
+
|
|
44
|
+
The state directory (the folder of `ESSEY_STATE_FILE`) holds the SDK state and the per-loan and per-sale records.
|
|
45
|
+
Both are sealed under keys derived from the note key: the SDK state as one XChaCha20-Poly1305 box (the SDK's
|
|
46
|
+
`stateKey` option), the records file by file. So a copy of the state directory alone opens nothing, as long as
|
|
47
|
+
`ESSEY_NOTE_KEY_FILE` lives outside it, which is the layout `essey-sui-mcp-v3-init` writes (`keys/` beside
|
|
48
|
+
`state/`). The server warns on stderr when the note key sits inside the state directory; move it out and update
|
|
49
|
+
`ESSEY_NOTE_KEY_FILE`. A plain state file from an older server is sealed the first time this one starts.
|
|
50
|
+
|
|
51
|
+
`essey-sui-mcp-v3-reveal` prints every record, and the value behind each `h_` handle a tool returned, to your own
|
|
52
|
+
terminal, with `ESSEY_STATE_FILE` and `ESSEY_NOTE_KEY_FILE` set as for the server. It is a local command for the operator; no tool returns its output.
|
|
53
|
+
|
|
39
54
|
## Tools
|
|
40
55
|
|
|
41
56
|
Credential: `essey_credential_obtain`, `essey_credential_status`, `essey_credential_renew`.
|
|
@@ -70,14 +85,15 @@ needs and no chain read gives back (the borrower's terms, key and locked amount;
|
|
|
70
85
|
written to `loan-<id>.json` and `offer-<id>.json`, mode 600, in the state file's directory, the same files
|
|
71
86
|
`scripts/v3/live/run.mts` writes. No tool returns them. Give each server its own state directory.
|
|
72
87
|
|
|
73
|
-
Seller: `
|
|
88
|
+
Seller: `essey_item_address` (a fresh single-use address to send one item to), `essey_agent_address` (the
|
|
89
|
+
wallet that funds deposits), `essey_sale_open` (item id and
|
|
74
90
|
struct tag, coin, sealed min and max price, bid window, finish window, max bids), `essey_sale_finish`,
|
|
75
91
|
`essey_sale_slash` (a bid `essey_sale_finish` names as not opening), `essey_sale_cancel` (before any bid),
|
|
76
92
|
`essey_sale_expire` (anyone, after the finish window).
|
|
77
93
|
|
|
78
94
|
Bidder: `essey_sale_list`, `essey_sale_view`, `essey_sale_bid` (room, sealed price, deposit),
|
|
79
95
|
`essey_sale_reclaim` (the deposit, or with `residual` the winner's change), `essey_sale_claim` (as `bidder` when
|
|
80
|
-
the bid won, or as `seller` after a cancel or expiry; `to` defaults to
|
|
96
|
+
the bid won, or as `seller` after a cancel or expiry; `to` defaults to a fresh `essey_item_address`).
|
|
81
97
|
|
|
82
98
|
The seller's keys and price bounds and the bidder's bid record go to `sale-<room>.json` and `bid-<room>.json`,
|
|
83
99
|
mode 600, beside the loan records. Every record file is sealed (XChaCha20-Poly1305) under a key derived from the
|
|
@@ -85,13 +101,26 @@ note key; a plaintext file `scripts/v3/live/run.mts` wrote is still read, and se
|
|
|
85
101
|
returns them. `essey_records_export` copies them all into one sealed mode-600 file at an absolute path, and
|
|
86
102
|
`essey_records_import` reads it back under the same note key, keeping any record already held. The item vault is found on chain by its room. The sellable item type on testnet is the demo
|
|
87
103
|
`0x48db0307be9b6aadbf9f29c28561e1b450348ab2786ea4853a8d7249c22979a1::demo::Badge`, which anyone can mint with
|
|
88
|
-
its public `demo::mint` and transfer to
|
|
104
|
+
its public `demo::mint` and transfer to an `essey_item_address`.
|
|
89
105
|
|
|
90
106
|
`essey_loan_status` reads one loan's public fields from chain. `essey_loan_view` runs the SDK's `localHealth`
|
|
91
107
|
and `covered` on the public fields in its arguments and reads nothing.
|
|
92
108
|
|
|
93
109
|
Amounts are whole-number strings in the coin's smallest unit.
|
|
94
110
|
|
|
111
|
+
## Handles
|
|
112
|
+
|
|
113
|
+
Every tool result reaches the model, so by default the server keeps the member's ledger out of it. Results name
|
|
114
|
+
loan and room ids, digests, item ids and types, payee addresses and amounts (balances, principals, amounts owed,
|
|
115
|
+
collateral, collected values, payouts, the settled rate) by handles such as `h_3f9c0a12b4d5e6f7`. Each tool takes a
|
|
116
|
+
handle wherever it takes that value: settle with the loan handle `essey_loan_open` returned, withdraw the balance
|
|
117
|
+
handle from `essey_notes_balance`, or retry a split withdraw with the handle its refusal names for the largest sum
|
|
118
|
+
below. An id keeps one handle across calls; each amount gets a fresh one. The receive address and the agent
|
|
119
|
+
address are shown as they are, since a payer and a funder need them. Rates to bid against, terms, close times and
|
|
120
|
+
counts are shown too. The handle table is sealed under the records key in `handles.json`, mode 600, beside the
|
|
121
|
+
records. `ESSEY_MCP_OUTPUT=clear` returns ids, digests, tickets and amounts as they are. The model provider still
|
|
122
|
+
sees what the model sends, including an amount the user types; use a zero-retention or local model for that.
|
|
123
|
+
|
|
95
124
|
## Waits
|
|
96
125
|
|
|
97
126
|
So a loan's closing steps do not land seconds apart, each proved action first waits a random time drawn by its
|
|
@@ -118,6 +147,7 @@ restart draws new ones. `ESSEY_SUBMIT_DELAY=off` sends at once.
|
|
|
118
147
|
| `ESSEY_RELAYER` | `clear` (default) or `onion` |
|
|
119
148
|
| `ESSEY_GRAPHQL` | Sui GraphQL URL, `https` or `http` on localhost (default `https://graphql.testnet.sui.io/graphql`) |
|
|
120
149
|
| `ESSEY_SUBMIT_DELAY` | `default` (default) or `off`: the SDK's `delays` option, a random wait before each proved action (see Waits) |
|
|
150
|
+
| `ESSEY_MCP_OUTPUT` | `handles` (default) or `clear`: whether results name ids, digests and amounts by handles (see Handles) |
|
|
121
151
|
|
|
122
152
|
Any other `ESSEY_*` variable stops the server, and so does a name containing `OWNER` or a value holding a private key.
|
|
123
153
|
|
package/dist/agent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAGvD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAMtD,MAAM,MAAM,eAAe,GAAG,WAAW,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC;AAEtE,mEAAmE;AACnE,MAAM,MAAM,OAAO,GAAG,CAAC,EAAE,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAEzD,MAAM,MAAM,QAAQ,GAAG;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,EAAE,WAAW,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC;IACrD,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACtC,CAAC;AAEF,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAMnE;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,IAAY,EAAE,EAAE,QAAQ,GAAG,eAAe,CAcxG"}
|
package/dist/agent.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { SuiGraphQLClient } from "@mysten/sui/graphql";
|
|
2
1
|
import { Transaction } from "@mysten/sui/transactions";
|
|
3
2
|
import { normalizeSuiAddress } from "@mysten/sui/utils";
|
|
3
|
+
import { graphqlClient } from "./http.js";
|
|
4
4
|
const INDEX_RETRIES = 15;
|
|
5
5
|
export function graphqlExecute(url, signer) {
|
|
6
|
-
const client =
|
|
6
|
+
const client = graphqlClient(url);
|
|
7
7
|
return async (tx) => {
|
|
8
8
|
const r = await signer.signAndExecuteTransaction({ transaction: tx, client });
|
|
9
9
|
if (r.$kind !== "Transaction")
|
package/dist/args.d.ts
CHANGED
|
@@ -3,8 +3,11 @@ import type { OpenParams } from "./client.ts";
|
|
|
3
3
|
import type { PublicLoan } from "./loan-view.ts";
|
|
4
4
|
type Rec = Record<string, unknown>;
|
|
5
5
|
export type JsonSchema = Record<string, unknown>;
|
|
6
|
+
/** A tool result's handle stands in for the value (`handles.ts`), so every such pattern also takes one. */
|
|
7
|
+
export declare const orHandle: (pattern: string) => string;
|
|
6
8
|
export declare const AMOUNT: JsonSchema;
|
|
7
9
|
export declare const FORCE: JsonSchema;
|
|
10
|
+
export declare const ALLOW_REUSE: JsonSchema;
|
|
8
11
|
export declare const COIN: JsonSchema;
|
|
9
12
|
export declare const ADDRESS: JsonSchema;
|
|
10
13
|
export declare const MS: JsonSchema;
|
|
@@ -12,8 +15,9 @@ export declare const objectSchema: (properties: Record<string, JsonSchema>, requ
|
|
|
12
15
|
export declare function address(a: Rec, k: string): string;
|
|
13
16
|
export declare function payee(a: Rec, k: string): string;
|
|
14
17
|
export declare function optBool(a: Rec, k: string): boolean | undefined;
|
|
15
|
-
export declare function
|
|
16
|
-
force
|
|
18
|
+
export declare function parseSpend(args: Rec): {
|
|
19
|
+
force?: boolean;
|
|
20
|
+
allowReuse?: boolean;
|
|
17
21
|
} | undefined;
|
|
18
22
|
export declare function int(a: Rec, k: string, min: number, max: number): number;
|
|
19
23
|
export declare function parseRole(args: Rec): "member" | "keeper" | undefined;
|
|
@@ -24,6 +28,11 @@ export declare const PAYEES: JsonSchema;
|
|
|
24
28
|
export declare function parsePayees(args: Rec): string[];
|
|
25
29
|
export declare const parseLoanId: (args: Rec) => string;
|
|
26
30
|
export declare const LOAN_SCHEMA: JsonSchema;
|
|
31
|
+
export declare const COLLECT_SCHEMA: JsonSchema;
|
|
32
|
+
export declare function parseCollect(args: Rec): {
|
|
33
|
+
loan: string;
|
|
34
|
+
sweep?: true;
|
|
35
|
+
};
|
|
27
36
|
export declare const TRANSFER_SCHEMA: JsonSchema;
|
|
28
37
|
export declare function parseReceiver(args: Rec): string;
|
|
29
38
|
export declare const OPEN_SCHEMA: JsonSchema;
|
package/dist/args.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"args.d.ts","sourceRoot":"","sources":["../src/args.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEjE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"args.d.ts","sourceRoot":"","sources":["../src/args.ts"],"names":[],"mappings":"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"}
|
package/dist/args.js
CHANGED
|
@@ -1,30 +1,37 @@
|
|
|
1
1
|
import { COINS, v3 } from "@esseyonsui/sui-sdk-v3";
|
|
2
2
|
import { ToolRefusal } from "./failure.js";
|
|
3
|
+
import { HANDLE } from "./handles.js";
|
|
3
4
|
const U64 = 1n << 64n;
|
|
4
5
|
const MAX_BPS = 10_000;
|
|
5
6
|
const { HEARTBEAT_KS } = v3.collateral;
|
|
6
7
|
function bad(msg) {
|
|
7
8
|
throw new ToolRefusal(msg);
|
|
8
9
|
}
|
|
10
|
+
/** A tool result's handle stands in for the value (`handles.ts`), so every such pattern also takes one. */
|
|
11
|
+
export const orHandle = (pattern) => `${pattern}|^${HANDLE}$`;
|
|
9
12
|
const U64S = {
|
|
10
13
|
type: "string",
|
|
11
|
-
pattern: "^(0|[1-9][0-9]*)$",
|
|
14
|
+
pattern: orHandle("^(0|[1-9][0-9]*)$"),
|
|
12
15
|
description: "canonical decimal u64",
|
|
13
16
|
};
|
|
14
17
|
export const AMOUNT = {
|
|
15
18
|
type: "string",
|
|
16
|
-
pattern: "^[1-9][0-9]*$",
|
|
17
|
-
description: "whole-number string in the coin's smallest unit",
|
|
19
|
+
pattern: orHandle("^[1-9][0-9]*$"),
|
|
20
|
+
description: "whole-number string in the coin's smallest unit, or a handle",
|
|
18
21
|
};
|
|
19
22
|
export const FORCE = {
|
|
20
23
|
type: "boolean",
|
|
21
24
|
description: "one exact withdraw to one address, not split into denominations, sent even when the amount equals a faucet grant or an own note's exact value or deposit, which links them on chain; default false",
|
|
22
25
|
};
|
|
26
|
+
export const ALLOW_REUSE = {
|
|
27
|
+
type: "boolean",
|
|
28
|
+
description: "pay an address this server's note key already paid, which links the two payouts on chain; default false, which refuses it",
|
|
29
|
+
};
|
|
23
30
|
export const COIN = { type: "string", enum: [...COINS], description: "tusdsui, usdc or sui" };
|
|
24
31
|
export const ADDRESS = {
|
|
25
32
|
type: "string",
|
|
26
|
-
pattern: "^0x[0-9a-fA-F]{1,64}$",
|
|
27
|
-
description: "0x object id",
|
|
33
|
+
pattern: orHandle("^0x[0-9a-fA-F]{1,64}$"),
|
|
34
|
+
description: "0x object id, or a handle",
|
|
28
35
|
};
|
|
29
36
|
const LOAN = {
|
|
30
37
|
...ADDRESS,
|
|
@@ -85,9 +92,15 @@ export function optBool(a, k) {
|
|
|
85
92
|
bad(`${k} must be true or false`);
|
|
86
93
|
return a[k];
|
|
87
94
|
}
|
|
88
|
-
export function
|
|
95
|
+
export function parseSpend(args) {
|
|
89
96
|
const force = optBool(args, "force");
|
|
90
|
-
|
|
97
|
+
const allowReuse = optBool(args, "allowReuse");
|
|
98
|
+
if (force === undefined && allowReuse === undefined)
|
|
99
|
+
return undefined;
|
|
100
|
+
return {
|
|
101
|
+
...(force === undefined ? {} : { force }),
|
|
102
|
+
...(allowReuse === undefined ? {} : { allowReuse }),
|
|
103
|
+
};
|
|
91
104
|
}
|
|
92
105
|
export function int(a, k, min, max) {
|
|
93
106
|
const v = a[k];
|
|
@@ -114,7 +127,7 @@ export function parseAmount(args, k = "amount") {
|
|
|
114
127
|
export function parseDenominations(args) {
|
|
115
128
|
return optBool(args, "denominations");
|
|
116
129
|
}
|
|
117
|
-
const PAYEE = { type: "string", pattern: "^0x[0-9a-fA-F]{64}$" };
|
|
130
|
+
const PAYEE = { type: "string", pattern: orHandle("^0x[0-9a-fA-F]{64}$") };
|
|
118
131
|
export const PAYEES = {
|
|
119
132
|
anyOf: [PAYEE, { type: "array", items: PAYEE, minItems: 1, maxItems: v3.notes.MAX_SPLIT_PIECES }],
|
|
120
133
|
description: "0x addresses of 64 hex digits, all different, one per denomination piece; force: true or a coin without denominations takes one",
|
|
@@ -129,6 +142,17 @@ export function parsePayees(args) {
|
|
|
129
142
|
}
|
|
130
143
|
export const parseLoanId = (args) => address(args, "loan");
|
|
131
144
|
export const LOAN_SCHEMA = objectSchema({ loan: LOAN }, ["loan"]);
|
|
145
|
+
export const COLLECT_SCHEMA = objectSchema({
|
|
146
|
+
loan: LOAN,
|
|
147
|
+
sweep: {
|
|
148
|
+
type: "boolean",
|
|
149
|
+
description: "move the note now with a paced self-transfer instead of holding it for the next spend",
|
|
150
|
+
},
|
|
151
|
+
}, ["loan"]);
|
|
152
|
+
export function parseCollect(args) {
|
|
153
|
+
const loan = parseLoanId(args);
|
|
154
|
+
return optBool(args, "sweep") === true ? { loan, sweep: true } : { loan };
|
|
155
|
+
}
|
|
132
156
|
export const TRANSFER_SCHEMA = objectSchema({
|
|
133
157
|
coin: COIN,
|
|
134
158
|
amount: AMOUNT,
|
|
@@ -150,10 +174,13 @@ export const OPEN_SCHEMA = objectSchema({
|
|
|
150
174
|
loanCoin: COIN,
|
|
151
175
|
principal: { ...AMOUNT, description: "principal to borrow, in the loan coin's smallest unit" },
|
|
152
176
|
maxRateBps: { ...BPS, description: "highest rate accepted, basis points" },
|
|
153
|
-
termMs: {
|
|
177
|
+
termMs: {
|
|
178
|
+
...MS,
|
|
179
|
+
description: "loan term after settle, milliseconds: 1, 24, 168, 720 or 2160 close steps (1 h, 1 d, 7 d, 30 d or 90 d at the default hour step; 5 min, 2 h, 14 h, 60 h or 180 h at a 5-minute closeStepMs, as on testnet); any other term is refused",
|
|
180
|
+
},
|
|
154
181
|
offerWindowMs: {
|
|
155
182
|
...MS,
|
|
156
|
-
description: "how long lenders may offer, milliseconds; the close rounds up to the
|
|
183
|
+
description: "how long lenders may offer, 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",
|
|
157
184
|
},
|
|
158
185
|
}, ["collateralCoin", "collateral", "loanCoin", "principal", "maxRateBps", "termMs", "offerWindowMs"]);
|
|
159
186
|
export function parseOpen(args) {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
type Fetch = (url: string, init?: RequestInit) => Promise<Response>;
|
|
2
|
+
/**
|
|
3
|
+
* PRV-05: every circuit's files are fetched once, in the deployment's order, into `dir` named by sha256, so no
|
|
4
|
+
* request names the circuit an action is about to prove. Each read checks the pin again.
|
|
5
|
+
*/
|
|
6
|
+
export declare function artifactCache(fetch: Fetch, circuits: Record<string, unknown>, dir: string): {
|
|
7
|
+
prefetch: () => Promise<void>;
|
|
8
|
+
load(circuit: string): Promise<{
|
|
9
|
+
wasm: Uint8Array;
|
|
10
|
+
zkey: Uint8Array;
|
|
11
|
+
}>;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=artifact-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"artifact-cache.d.ts","sourceRoot":"","sources":["../src/artifact-cache.ts"],"names":[],"mappings":"AAKA,KAAK,KAAK,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAGpE;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,MAAM;;kBA6BlE,MAAM;cAMA,UAAU;cAAQ,UAAU;;EAGzD"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { EsseyError, v3 } from "@esseyonsui/sui-sdk-v3";
|
|
4
|
+
/**
|
|
5
|
+
* PRV-05: every circuit's files are fetched once, in the deployment's order, into `dir` named by sha256, so no
|
|
6
|
+
* request names the circuit an action is about to prove. Each read checks the pin again.
|
|
7
|
+
*/
|
|
8
|
+
export function artifactCache(fetch, circuits, dir) {
|
|
9
|
+
const fileOf = (pin) => join(dir, pin.sha256);
|
|
10
|
+
const cached = (pin) => {
|
|
11
|
+
if (!existsSync(fileOf(pin)))
|
|
12
|
+
return undefined;
|
|
13
|
+
const bytes = new Uint8Array(readFileSync(fileOf(pin)));
|
|
14
|
+
return v3.sha256Hex(bytes) === pin.sha256 ? bytes : undefined;
|
|
15
|
+
};
|
|
16
|
+
const pins = (circuit) => v3.circuitPins(circuits, circuit);
|
|
17
|
+
const fill = async () => {
|
|
18
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
19
|
+
for (const circuit of Object.keys(circuits))
|
|
20
|
+
for (const pin of [pins(circuit).wasm, pins(circuit).zkey]) {
|
|
21
|
+
if (cached(pin))
|
|
22
|
+
continue;
|
|
23
|
+
const bytes = await v3.fetchPinned(fetch, pin.url, pin.sha256);
|
|
24
|
+
const tmp = `${fileOf(pin)}.tmp`;
|
|
25
|
+
writeFileSync(tmp, bytes, { mode: 0o600 });
|
|
26
|
+
renameSync(tmp, fileOf(pin));
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
let all;
|
|
30
|
+
const prefetch = () => {
|
|
31
|
+
all ??= fill().catch((error) => {
|
|
32
|
+
all = undefined;
|
|
33
|
+
throw error;
|
|
34
|
+
});
|
|
35
|
+
return all;
|
|
36
|
+
};
|
|
37
|
+
return {
|
|
38
|
+
prefetch,
|
|
39
|
+
async load(circuit) {
|
|
40
|
+
await prefetch();
|
|
41
|
+
const { wasm, zkey } = pins(circuit);
|
|
42
|
+
const files = { wasm: cached(wasm), zkey: cached(zkey) };
|
|
43
|
+
if (!files.wasm || !files.zkey)
|
|
44
|
+
throw new EsseyError("ARTIFACT_MISMATCH", "refused: a cached artifact no longer matches its pin");
|
|
45
|
+
return files;
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
package/dist/client.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export type OpenParams = Extract<Parameters<Loans["open"]>[0], {
|
|
|
11
11
|
*/
|
|
12
12
|
export type DemoClient = {
|
|
13
13
|
credential: Essey["credential"];
|
|
14
|
-
notes: Pick<Essey["notes"], "faucet" | "deposit" | "scan" | "
|
|
14
|
+
notes: Pick<Essey["notes"], "faucet" | "deposit" | "scan" | "withdrawFirst" | "payNext" | "transfer" | "receiveAddress" | "exitFirst" | "recoverStranded">;
|
|
15
15
|
loans: Pick<Loans, "request" | "lend" | "accept" | "payBack" | "release" | "collect" | "cancelOwn" | "reclaimCollateral" | "recover" | "reclaimOffer" | "collectSeized" | "collectSurplus" | "heartbeat" | "topup" | "list" | "view" | "openRefi" | "settleRefi" | "cancelRefi" | "slash" | "fault" | "liquidate" | "seizeDefault" | "faultLiquidate" | "keeperLiquidate"> & {
|
|
16
16
|
open(p: OpenParams): Promise<{
|
|
17
17
|
id: string;
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAEpD,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAG7D,KAAK,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC;AAC5B,KAAK,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AACpD,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;IAAE,QAAQ,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC;AAEtF;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,UAAU,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;IAChC,KAAK,EAAE,IAAI,CACT,KAAK,CAAC,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAEpD,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAG7D,KAAK,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC;AAC5B,KAAK,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AACpD,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;IAAE,QAAQ,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC;AAEtF;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,UAAU,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;IAChC,KAAK,EAAE,IAAI,CACT,KAAK,CAAC,OAAO,CAAC,EACZ,QAAQ,GACR,SAAS,GACT,MAAM,GACN,eAAe,GACf,SAAS,GACT,UAAU,GACV,gBAAgB,GAChB,WAAW,GACX,iBAAiB,CACpB,CAAC;IACF,KAAK,EAAE,IAAI,CACT,KAAK,EACH,SAAS,GACT,MAAM,GACN,QAAQ,GACR,SAAS,GACT,SAAS,GACT,SAAS,GACT,WAAW,GACX,mBAAmB,GACnB,SAAS,GACT,cAAc,GACd,eAAe,GACf,gBAAgB,GAChB,WAAW,GACX,OAAO,GACP,MAAM,GACN,MAAM,GACN,UAAU,GACV,YAAY,GACZ,YAAY,GACZ,OAAO,GACP,OAAO,GACP,WAAW,GACX,cAAc,GACd,gBAAgB,GAChB,iBAAiB,CACpB,GAAG;QACF,IAAI,CAAC,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC;YAAE,EAAE,EAAE,MAAM,CAAA;SAAE,GAAG,MAAM,CAAC,CAAC;QACtD,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;KAC/C,CAAC;IACF,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IAClC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,WAAW,GAAG,OAAO,GAAG,OAAO,CAAC,CAAC;CAChE,CAAC;AAEF,+FAA+F;AAC/F,MAAM,MAAM,SAAS,GAAG;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;CAAE,CAAC;AASzF,wBAAgB,QAAQ,CACtB,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE,SAAS,EAChB,MAAM,GAAE,UAAU,CAAC,OAAO,CAAC,CAAC,QAAQ,CAA6C,GAChF,UAAU,CAkEZ;AAED,gGAAgG;AAChG,wBAAgB,UAAU,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,UAAU,CAShF"}
|
package/dist/client.js
CHANGED
|
@@ -14,17 +14,18 @@ export function clientOf(essey, chain, health = (loan) => Promise.resolve(status
|
|
|
14
14
|
faucet: (coin) => notes.faucet(coin),
|
|
15
15
|
deposit: (coin, amount, o) => notes.deposit(coin, amount, o),
|
|
16
16
|
scan: (coin) => notes.scan(coin),
|
|
17
|
-
|
|
17
|
+
withdrawFirst: (coin, amount, to, o) => notes.withdrawFirst(coin, amount, to, o),
|
|
18
|
+
payNext: (pending) => notes.payNext(pending),
|
|
18
19
|
transfer: (coin, amount, to) => notes.transfer(coin, amount, to),
|
|
19
20
|
receiveAddress: () => notes.receiveAddress(),
|
|
20
|
-
|
|
21
|
+
exitFirst: (coin, to, o) => notes.exitFirst(coin, to, o),
|
|
21
22
|
recoverStranded: () => notes.recoverStranded(),
|
|
22
23
|
},
|
|
23
24
|
loans: {
|
|
24
25
|
open: (p) => openPlanned(essey, p),
|
|
25
26
|
request: (id) => loans.request(id),
|
|
26
27
|
lend: (p) => loans.lend(p),
|
|
27
|
-
accept: (
|
|
28
|
+
accept: (p) => loans.accept(p),
|
|
28
29
|
payBack: (p) => loans.payBack(p),
|
|
29
30
|
release: (p) => loans.release(p),
|
|
30
31
|
collect: (p) => loans.collect(p),
|
|
@@ -59,6 +60,7 @@ export function clientOf(essey, chain, health = (loan) => Promise.resolve(status
|
|
|
59
60
|
expire: (p) => sales.expire(p),
|
|
60
61
|
reclaim: (p) => sales.reclaim(p),
|
|
61
62
|
claim: (p) => sales.claim(p),
|
|
63
|
+
itemAddress: () => sales.itemAddress(),
|
|
62
64
|
cancel: (p) => sales.cancel(p),
|
|
63
65
|
badgeGrant: (to) => sales.badgeGrant(to),
|
|
64
66
|
agentAddress: chain.agentAddress,
|
package/dist/config.d.ts
CHANGED
|
@@ -21,6 +21,8 @@ export type McpConfig = {
|
|
|
21
21
|
relayer: "clear" | "onion";
|
|
22
22
|
/** The SDK's `delays` option: "default" waits a drawn time before each proved action, "off" sends at once. */
|
|
23
23
|
delays: "default" | "off";
|
|
24
|
+
/** `handles` (default): results name ids, digests and amounts by handles (`handles.ts`); `clear` shows them. */
|
|
25
|
+
output: "handles" | "clear";
|
|
24
26
|
};
|
|
25
27
|
export declare const TESTNET_GRAPHQL = "https://graphql.testnet.sui.io/graphql";
|
|
26
28
|
export declare class ConfigError extends Error {
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG;IACtB,OAAO,EAAE,SAAS,CAAC;IACnB,4EAA4E;IAC5E,MAAM,EAAE;QAAE,IAAI,EAAE,KAAK,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACtE,iHAAiH;IACjH,SAAS,EAAE,MAAM,CAAC;IAClB,2DAA2D;IAC3D,OAAO,EAAE,MAAM,CAAC;IAChB,wGAAwG;IACxG,WAAW,EAAE,MAAM,CAAC;IACpB,+IAA+I;IAC/I,YAAY,EAAE,MAAM,CAAC;IACrB,2GAA2G;IAC3G,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC;IAC3B,8GAA8G;IAC9G,MAAM,EAAE,SAAS,GAAG,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG;IACtB,OAAO,EAAE,SAAS,CAAC;IACnB,4EAA4E;IAC5E,MAAM,EAAE;QAAE,IAAI,EAAE,KAAK,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACtE,iHAAiH;IACjH,SAAS,EAAE,MAAM,CAAC;IAClB,2DAA2D;IAC3D,OAAO,EAAE,MAAM,CAAC;IAChB,wGAAwG;IACxG,WAAW,EAAE,MAAM,CAAC;IACpB,+IAA+I;IAC/I,YAAY,EAAE,MAAM,CAAC;IACrB,2GAA2G;IAC3G,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC;IAC3B,8GAA8G;IAC9G,MAAM,EAAE,SAAS,GAAG,KAAK,CAAC;IAC1B,gHAAgH;IAChH,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC;CAC7B,CAAC;AAEF,eAAO,MAAM,eAAe,2CAA2C,CAAC;AAexE,qBAAa,WAAY,SAAQ,KAAK;IACpC,QAAQ,CAAC,IAAI,oBAAoB;CAClC;AAWD;;;GAGG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,GAAG,SAAS,CAgC7D"}
|
package/dist/config.js
CHANGED
|
@@ -9,6 +9,7 @@ const KNOWN = [
|
|
|
9
9
|
"ESSEY_RELAYER",
|
|
10
10
|
"ESSEY_GRAPHQL",
|
|
11
11
|
"ESSEY_SUBMIT_DELAY",
|
|
12
|
+
"ESSEY_MCP_OUTPUT",
|
|
12
13
|
];
|
|
13
14
|
export class ConfigError extends Error {
|
|
14
15
|
code = "INVALID_CONFIG";
|
|
@@ -45,6 +46,9 @@ export function parseConfig(env) {
|
|
|
45
46
|
const delays = env.ESSEY_SUBMIT_DELAY || "default";
|
|
46
47
|
if (delays !== "default" && delays !== "off")
|
|
47
48
|
fail("ESSEY_SUBMIT_DELAY must be default or off");
|
|
49
|
+
const output = env.ESSEY_MCP_OUTPUT || "handles";
|
|
50
|
+
if (output !== "handles" && output !== "clear")
|
|
51
|
+
fail("ESSEY_MCP_OUTPUT must be handles or clear");
|
|
48
52
|
const noteKeyFile = need("ESSEY_NOTE_KEY_FILE");
|
|
49
53
|
const agentKeyFile = need("ESSEY_AGENT_KEY_FILE");
|
|
50
54
|
if (/^[0-9a-fA-F]{64}$/.test(noteKeyFile) || /^[0-9a-fA-F]{64}$/.test(agentKeyFile))
|
|
@@ -59,6 +63,7 @@ export function parseConfig(env) {
|
|
|
59
63
|
invite: inviteOf(env.ESSEY_INVITE),
|
|
60
64
|
relayer,
|
|
61
65
|
delays,
|
|
66
|
+
output,
|
|
62
67
|
};
|
|
63
68
|
}
|
|
64
69
|
function configOf(v) {
|
package/dist/fund.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fund.d.ts","sourceRoot":"","sources":["../src/fund.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fund.d.ts","sourceRoot":"","sources":["../src/fund.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAmB,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAExE,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAK/D,4GAA4G;AAC5G,eAAO,MAAM,WAAW,8CAA8C,CAAC;AAEvE,uFAAuF;AACvF,MAAM,MAAM,IAAI,GAAG,CAAC,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAE9E,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAO3C;AAED;;;GAGG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,MAAM,GAAG,SAAS,EAC/C,IAAI,EAAE,IAAI,GACT,WAAW,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAmBrC;AAID,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,GAAE,IAAqB;;;;;;EAGrG"}
|
package/dist/fund.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { SuiGraphQLClient } from "@mysten/sui/graphql";
|
|
2
1
|
import { coinWithBalance, Transaction } from "@mysten/sui/transactions";
|
|
2
|
+
import { graphqlClient } from "./http.js";
|
|
3
3
|
import { loadAgentKey } from "./keys.js";
|
|
4
4
|
/** Fixed text: whatever the signing or the chain threw is dropped, so no failure can carry the key file. */
|
|
5
5
|
export const FUND_FAILED = "the agent wallet did not fund the deposit";
|
|
6
6
|
export function chainSend(url) {
|
|
7
|
-
const client =
|
|
7
|
+
const client = graphqlClient(url);
|
|
8
8
|
return async (transaction, signer) => {
|
|
9
9
|
const r = await client.signAndExecuteTransaction({ transaction, signer });
|
|
10
10
|
if (r.$kind !== "Transaction")
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { McpConfig } from "./config.ts";
|
|
2
|
+
/** No `0x`, no 64-hex run and no 7-digit run, so neither `redactText` nor `failure.ts` LONG_TOKEN touches it. */
|
|
3
|
+
export declare const HANDLE = "h_[0-9a-f]{16}";
|
|
4
|
+
type Kind = "amount" | "ref";
|
|
5
|
+
type Args = Record<string, unknown>;
|
|
6
|
+
export type Handles = {
|
|
7
|
+
/** Every handle in the arguments, top level or in an array, replaced by its value. */
|
|
8
|
+
resolve(args: Args): Args;
|
|
9
|
+
hide(result: unknown): unknown;
|
|
10
|
+
hideMessage(text: string): string;
|
|
11
|
+
};
|
|
12
|
+
/** Handles kept sealed under the records key in mode-600 `handles.json` in `dir`. */
|
|
13
|
+
export declare function handleTable(dir: string, key: Uint8Array): Handles;
|
|
14
|
+
/** `clear` is today's output: no table. */
|
|
15
|
+
export declare const handlesFor: (output: McpConfig["output"], dir: string, key: Uint8Array) => Handles | undefined;
|
|
16
|
+
/** Every issued handle and its value, for the operator's reveal CLI only; no tool returns this. */
|
|
17
|
+
export declare const handleRows: (dir: string, key: Uint8Array) => {
|
|
18
|
+
handle: string;
|
|
19
|
+
kind: Kind;
|
|
20
|
+
value: string;
|
|
21
|
+
}[];
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=handles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handles.d.ts","sourceRoot":"","sources":["../src/handles.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAI7C,iHAAiH;AACjH,eAAO,MAAM,MAAM,mBAAmB,CAAC;AAIvC,KAAK,IAAI,GAAG,QAAQ,GAAG,KAAK,CAAC;AAC7B,KAAK,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAmDpC,MAAM,MAAM,OAAO,GAAG;IACpB,sFAAsF;IACtF,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAC1B,IAAI,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC;IAC/B,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;CACnC,CAAC;AAiBF,qFAAqF;AACrF,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,GAAG,OAAO,CA8DjE;AAED,2CAA2C;AAC3C,eAAO,MAAM,UAAU,GAAI,QAAQ,SAAS,CAAC,QAAQ,CAAC,EAAE,KAAK,MAAM,EAAE,KAAK,UAAU,wBAC5B,CAAC;AAEzD,mGAAmG;AACnG,eAAO,MAAM,UAAU,GAAI,KAAK,MAAM,EAAE,KAAK,UAAU;;;;GAC+B,CAAC"}
|
package/dist/handles.js
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { mkdirSync, readFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { ToolRefusal } from "./failure.js";
|
|
5
|
+
import { seal, unseal, writePrivate } from "./records.js";
|
|
6
|
+
/** No `0x`, no 64-hex run and no 7-digit run, so neither `redactText` nor `failure.ts` LONG_TOKEN touches it. */
|
|
7
|
+
export const HANDLE = "h_[0-9a-f]{16}";
|
|
8
|
+
const IS_HANDLE = new RegExp(`^${HANDLE}$`);
|
|
9
|
+
const FILE = "handles.json";
|
|
10
|
+
/** Field names, in results and arguments, whose value is an amount or a private rate. */
|
|
11
|
+
const AMOUNTS = new Set([
|
|
12
|
+
"add",
|
|
13
|
+
"amount",
|
|
14
|
+
"balance",
|
|
15
|
+
"collateral",
|
|
16
|
+
"deposit",
|
|
17
|
+
"kept",
|
|
18
|
+
"maxPrice",
|
|
19
|
+
"minPrice",
|
|
20
|
+
"owed",
|
|
21
|
+
"price",
|
|
22
|
+
"principal",
|
|
23
|
+
"rateBps",
|
|
24
|
+
"value",
|
|
25
|
+
]);
|
|
26
|
+
/** Result strings shown as they are. Every other string becomes a ref handle. */
|
|
27
|
+
const SHOWN = new Set([
|
|
28
|
+
"action",
|
|
29
|
+
"address",
|
|
30
|
+
"atMs",
|
|
31
|
+
"closeMs",
|
|
32
|
+
"coin",
|
|
33
|
+
"collateralCoin",
|
|
34
|
+
"epoch",
|
|
35
|
+
"error",
|
|
36
|
+
"expiresMs",
|
|
37
|
+
"expiryMs",
|
|
38
|
+
"finishByMs",
|
|
39
|
+
"hint",
|
|
40
|
+
"lifecycle",
|
|
41
|
+
"liquidationPrice",
|
|
42
|
+
"loanCoin",
|
|
43
|
+
"ltvBps",
|
|
44
|
+
"maturityS",
|
|
45
|
+
"maxRateBps",
|
|
46
|
+
"message",
|
|
47
|
+
"outcome",
|
|
48
|
+
"reason",
|
|
49
|
+
"role",
|
|
50
|
+
"round",
|
|
51
|
+
"state",
|
|
52
|
+
"termMs",
|
|
53
|
+
]);
|
|
54
|
+
const DROPPED = new Set(["ticket"]);
|
|
55
|
+
/** The SDK quotes amounts in `_` groups (`sdk-v3/src/v3/notes/withdraw.ts:90`); `:105` also quotes one below 1000. */
|
|
56
|
+
const QUOTED_AMOUNT = /(?<=^refused: )[0-9][0-9_]*(?= is not a sum)|(?<=the largest below it is )[0-9][0-9_]*|\b[0-9]{1,3}(?:_[0-9]{3})+\b/g;
|
|
57
|
+
function bad(msg) {
|
|
58
|
+
throw new ToolRefusal(msg);
|
|
59
|
+
}
|
|
60
|
+
function load(path, key) {
|
|
61
|
+
let text;
|
|
62
|
+
try {
|
|
63
|
+
text = readFileSync(path, "utf8");
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
if (err.code === "ENOENT")
|
|
67
|
+
return [];
|
|
68
|
+
throw err;
|
|
69
|
+
}
|
|
70
|
+
return unseal(key, FILE, JSON.parse(text).sealed).rows;
|
|
71
|
+
}
|
|
72
|
+
/** Handles kept sealed under the records key in mode-600 `handles.json` in `dir`. */
|
|
73
|
+
export function handleTable(dir, key) {
|
|
74
|
+
const path = join(dir, FILE);
|
|
75
|
+
const rows = new Map();
|
|
76
|
+
const refs = new Map();
|
|
77
|
+
for (const [h, kind, value] of load(path, key)) {
|
|
78
|
+
rows.set(h, { kind, value });
|
|
79
|
+
if (kind === "ref")
|
|
80
|
+
refs.set(value, h);
|
|
81
|
+
}
|
|
82
|
+
let dirty = false;
|
|
83
|
+
const issue = (kind, value) => {
|
|
84
|
+
const known = kind === "ref" ? refs.get(value) : undefined;
|
|
85
|
+
if (known)
|
|
86
|
+
return known;
|
|
87
|
+
const h = `h_${randomBytes(8).toString("hex")}`;
|
|
88
|
+
rows.set(h, { kind, value });
|
|
89
|
+
if (kind === "ref")
|
|
90
|
+
refs.set(value, h);
|
|
91
|
+
dirty = true;
|
|
92
|
+
return h;
|
|
93
|
+
};
|
|
94
|
+
const save = () => {
|
|
95
|
+
if (!dirty)
|
|
96
|
+
return;
|
|
97
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
98
|
+
writePrivate(path, seal(key, FILE, { rows: [...rows].map(([h, r]) => [h, r.kind, r.value]) }));
|
|
99
|
+
dirty = false;
|
|
100
|
+
};
|
|
101
|
+
const valueOf = (name, v) => {
|
|
102
|
+
if (typeof v !== "string" || !IS_HANDLE.test(v))
|
|
103
|
+
return v;
|
|
104
|
+
const row = rows.get(v) ?? bad("a handle is not one this server issued");
|
|
105
|
+
if (row.kind !== (AMOUNTS.has(name) ? "amount" : "ref"))
|
|
106
|
+
bad(`${name} does not take that kind of handle`);
|
|
107
|
+
return row.value;
|
|
108
|
+
};
|
|
109
|
+
const hidden = (name, v) => {
|
|
110
|
+
if (Array.isArray(v))
|
|
111
|
+
return v.map((item) => hidden(name, item));
|
|
112
|
+
if (v !== null && typeof v === "object")
|
|
113
|
+
return Object.fromEntries(Object.entries(v)
|
|
114
|
+
.filter(([k]) => !DROPPED.has(k))
|
|
115
|
+
.map(([k, inner]) => [k, hidden(k, inner)]));
|
|
116
|
+
if (AMOUNTS.has(name) && (typeof v === "string" || typeof v === "number"))
|
|
117
|
+
return issue("amount", String(v));
|
|
118
|
+
if (typeof v !== "string" || SHOWN.has(name))
|
|
119
|
+
return v;
|
|
120
|
+
return issue("ref", v);
|
|
121
|
+
};
|
|
122
|
+
return {
|
|
123
|
+
resolve: (args) => Object.fromEntries(Object.entries(args).map(([k, v]) => [
|
|
124
|
+
k,
|
|
125
|
+
Array.isArray(v) ? v.map((item) => valueOf(k, item)) : valueOf(k, v),
|
|
126
|
+
])),
|
|
127
|
+
hide: (result) => {
|
|
128
|
+
const out = hidden("", result);
|
|
129
|
+
save();
|
|
130
|
+
return out;
|
|
131
|
+
},
|
|
132
|
+
hideMessage: (text) => {
|
|
133
|
+
const out = text.replace(QUOTED_AMOUNT, (n) => issue("amount", n.replaceAll("_", "")));
|
|
134
|
+
save();
|
|
135
|
+
return out;
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/** `clear` is today's output: no table. */
|
|
140
|
+
export const handlesFor = (output, dir, key) => output === "clear" ? undefined : handleTable(dir, key);
|
|
141
|
+
/** Every issued handle and its value, for the operator's reveal CLI only; no tool returns this. */
|
|
142
|
+
export const handleRows = (dir, key) => load(join(dir, FILE), key).map(([handle, kind, value]) => ({ handle, kind, value }));
|
package/dist/http.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { SuiGraphQLClient } from "@mysten/sui/graphql";
|
|
2
|
+
export type Fetch = (url: string, init?: RequestInit) => Promise<Response>;
|
|
3
|
+
/** PRV-32: every request this server sends goes out with the SDK's fixed headers. */
|
|
4
|
+
export declare const plainFetch: Fetch;
|
|
5
|
+
export declare const graphqlClient: (url: string, fetch?: Fetch) => SuiGraphQLClient<{}>;
|
|
6
|
+
//# sourceMappingURL=http.d.ts.map
|