@esseyonsui/sui-mcp-v3 0.1.8 → 0.1.9

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,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/init.d.ts CHANGED
@@ -8,4 +8,10 @@ export type InitResult = {
8
8
  error: string;
9
9
  };
10
10
  export declare function init(dir: string, configUrl?: string): InitResult;
11
+ /** PRV-14: the client starts this exact release, never whatever the registry serves that day. */
12
+ export declare function serverEntry(env: Record<string, string>, version?: string): {
13
+ command: string;
14
+ args: string[];
15
+ env: Record<string, string>;
16
+ };
11
17
  //# sourceMappingURL=init.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":";AASA,eAAO,MAAM,kBAAkB,yDAAyD,CAAC;AAEzF,MAAM,MAAM,UAAU,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAElG,wBAAgB,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,SAAqB,GAAG,UAAU,CAkB5E"}
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":";AASA,eAAO,MAAM,kBAAkB,yDAAyD,CAAC;AAEzF,MAAM,MAAM,UAAU,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAElG,wBAAgB,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,SAAqB,GAAG,UAAU,CAkB5E;AAKD,iGAAiG;AACjG,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,SAAU;;;;EAEzE"}
package/dist/init.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { randomBytes } from "node:crypto";
3
- import { chmodSync, existsSync, mkdirSync, realpathSync, writeFileSync } from "node:fs";
3
+ import { chmodSync, existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
4
4
  import { homedir } from "node:os";
5
5
  import { resolve } from "node:path";
6
6
  import { fileURLToPath } from "node:url";
@@ -26,6 +26,12 @@ export function init(dir, configUrl = DEFAULT_CONFIG_URL) {
26
26
  },
27
27
  };
28
28
  }
29
+ const VERSION = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"))
30
+ .version;
31
+ /** PRV-14: the client starts this exact release, never whatever the registry serves that day. */
32
+ export function serverEntry(env, version = VERSION) {
33
+ return { command: "npx", args: ["-y", "-p", `@esseyonsui/sui-mcp-v3@${version}`, "essey-sui-mcp-v3"], env };
34
+ }
29
35
  function main() {
30
36
  const dir = resolve(process.argv[2] ?? `${homedir()}/.essey-v3`);
31
37
  const r = init(dir, process.env.ESSEY_V3_CONFIG ?? DEFAULT_CONFIG_URL);
@@ -33,11 +39,7 @@ function main() {
33
39
  console.error(r.error);
34
40
  process.exit(1);
35
41
  }
36
- const server = {
37
- command: "npx",
38
- args: ["-y", "-p", "@esseyonsui/sui-mcp-v3", "essey-sui-mcp-v3"],
39
- env: r.env,
40
- };
42
+ const server = serverEntry(r.env);
41
43
  console.log(`Wrote mode-600 key files in ${dir}. Add this server to your MCP client:\n`);
42
44
  console.log(JSON.stringify({ mcpServers: { "essey-v3": server } }, null, 2));
43
45
  }
package/dist/io.d.ts CHANGED
@@ -14,6 +14,8 @@ export type ChainIoOptions = {
14
14
  wasm: string;
15
15
  zkey: string;
16
16
  }>;
17
+ /** PRV-05: where every circuit's files are kept, fetched once; without it each is fetched on first use. */
18
+ artifactDir?: string;
17
19
  /** Test only: seal random bytes of the same length for the plaintexts it picks. */
18
20
  garble?: (data: Uint8Array) => boolean;
19
21
  fundDeposit?: EsseyIo["fundDeposit"];
@@ -49,6 +51,7 @@ type SealRequest = {
49
51
  signer?: Signer;
50
52
  };
51
53
  export declare function chainIo(config: Json, o: ChainIoOptions): {
54
+ prefetchArtifacts: () => Promise<void> | undefined;
52
55
  waitIndexed: (landedAtMs: number) => Promise<boolean>;
53
56
  prover: v3.Prover;
54
57
  readPrice: (market: string) => Promise<{
@@ -71,7 +74,6 @@ export declare function chainIo(config: Json, o: ChainIoOptions): {
71
74
  readSettleTime: (loanId: string) => Promise<bigint>;
72
75
  readTopupDelivery: (loanId: string) => Promise<[bigint, bigint, bigint] | null>;
73
76
  readKeeperCt: (loanId: string) => Promise<Uint8Array<ArrayBufferLike>>;
74
- readCreated: (digest: string) => Promise<string | null>;
75
77
  readBadge: (digest: string) => Promise<{
76
78
  id: string;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CAAC;KACnB;qBAgDgB,WAAW,GAAG;QAAE,MAAM,EAAE,UAAU,CAAA;KAAE;yBAOpC,WAAW,GAAG;QAAE,EAAE,EAAE,UAAU,CAAA;KAAE;mBA6ChC,MAAM,UAAU,MAAM;;;;wBACjB,MAAM,GAAG,IAAI;;;;;;;;;;0BAGL,MAAM;4BAEJ,MAAM;qBACb,MAAM;;;;;;;;EAkBhC"}
package/dist/io.js CHANGED
@@ -8,6 +8,7 @@ import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
8
8
  import { Transaction } from "@mysten/sui/transactions";
9
9
  import { normalizeSuiAddress } from "@mysten/sui/utils";
10
10
  import { v3 } from "@esseyonsui/sui-sdk-v3";
11
+ import { artifactCache } from "./artifact-cache.js";
11
12
  export { TESTNET_GRAPHQL } from "./config.js";
12
13
  const require = createRequire(import.meta.url);
13
14
  const snarkjs = require("snarkjs");
@@ -189,10 +190,6 @@ async function createdBy(gql, digest) {
189
190
  }
190
191
  return null;
191
192
  }
192
- async function readCreated(gql, digest) {
193
- const created = await createdBy(gql, digest);
194
- return created?.find((n) => /::loan::ShieldedLoan</.test(n.type))?.address ?? null;
195
- }
196
193
  /** Query shape as `scripts/v3/upgrade-testnet.ts:94` reads an owner. */
197
194
  async function readObjectRef(gql, id) {
198
195
  const d = await gql(`query($id: SuiAddress!) { object(address: $id) { version digest owner { __typename ... on AddressOwner { address { address } } } } }`, { id });
@@ -390,13 +387,15 @@ export function chainIo(config, o) {
390
387
  const gql = graphql(o.graphql, fetch);
391
388
  const pools = config.objects.pools;
392
389
  const pkg = config.packages.pool;
390
+ const cache = o.artifactDir ? artifactCache(fetch, config.circuits, o.artifactDir) : undefined;
393
391
  const artifacts = (circuit) => {
394
392
  const local = o.localArtifacts?.[circuit];
395
393
  if (local)
396
394
  return Promise.resolve({ wasm: readFileSync(local.wasm), zkey: readFileSync(local.zkey) });
397
- return v3.loadCircuitArtifacts(fetch, config.circuits, circuit);
395
+ return cache ? cache.load(circuit) : v3.loadCircuitArtifacts(fetch, config.circuits, circuit);
398
396
  };
399
397
  return {
398
+ prefetchArtifacts: () => cache?.prefetch(),
400
399
  waitIndexed: (landedAtMs) => waitIndexed(gql, landedAtMs, o.indexPauseMs ?? 1500),
401
400
  prover: v3.groth16Prover(snarkjs.groth16, artifacts),
402
401
  readPrice: (market) => readPrice(gql, market),
@@ -405,7 +404,6 @@ export function chainIo(config, o) {
405
404
  readSettleTime: (loanId) => readSettleTime(gql, loanId),
406
405
  readTopupDelivery: (loanId) => readTopupDelivery(gql, loanId),
407
406
  readKeeperCt: (loanId) => readKeeperCt(gql, loanId),
408
- readCreated: (digest) => readCreated(gql, digest),
409
407
  readBadge: (digest) => readBadge(gql, digest),
410
408
  readSaleOpened: (digest) => readSaleOpened(gql, digest),
411
409
  readObjectRef: (id) => readObjectRef(gql, id),
package/dist/main.js CHANGED
@@ -78,7 +78,8 @@ async function start() {
78
78
  const seed = loadNoteSeed(cfg.noteKeyFile);
79
79
  try {
80
80
  const { source, raw } = await deploymentOf(cfg);
81
- const io = chainIo(raw, { graphql: cfg.graphql });
81
+ const io = chainIo(raw, { graphql: cfg.graphql, artifactDir: `${dirname(cfg.stateFile)}/artifacts` });
82
+ io.prefetchArtifacts()?.catch(() => { });
82
83
  const deliverSaleItem = itemHandOver({
83
84
  signer: agent,
84
85
  execute: graphqlExecute(cfg.graphql, agent),
package/dist/records.d.ts CHANGED
@@ -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;
@@ -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,CAAC,CAAC;AAC1E,YAAY,EAAE,UAAU,EAAE,CAAC;AAE3B,sHAAsH;AACtH,MAAM,MAAM,UAAU,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,KAAK,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjF;;;;GAIG;AACH,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,UAAU,CAAC;IAC7B,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;IAC/C,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,WAAW,CAAC;IAC/B,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,IAAI,CAAC;IACjD,IAAI,CAAC,IAAI,EAA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,UAAU,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,KAAK,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjF;;;;;GAKG;AACH,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,UAAU,CAAC;IAC7B,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;IAC/C,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,WAAW,CAAC;IAC/B,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,IAAI,CAAC;IACjD,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAAC;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;IACjD,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,GAAG,IAAI,CAAC;IAC/C,2FAA2F;IAC3F,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,iGAAiG;IACjG,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CAC9D,CAAC;AA0BF,oHAAoH;AACpH,wBAAgB,SAAS,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAEtD;AA2CD,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,GAAG,OAAO,CAgIjE"}
package/dist/records.js CHANGED
@@ -1,12 +1,14 @@
1
1
  import { randomBytes } from "node:crypto";
2
- import { chmodSync, mkdirSync, readdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
2
+ import { chmodSync, mkdirSync, readdirSync, readFileSync, renameSync, 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";
8
9
  const LOAN_ID = /^0x[0-9a-f]{64}$/;
9
- const RECORD_FILE = /^(loan|offer|sale|bid)-(0x[0-9a-f]{64})\.json$/;
10
+ const NAMED_FILE = /^(loan|offer|sale|bid)-(0x[0-9a-f]{64})\.json$/;
11
+ const BLIND_FILE = /^r-[0-9a-f]{32}\.json$/;
10
12
  const KINDS = ["loan", "offer", "sale", "bid"];
11
13
  const EXPORT_LABEL = "export";
12
14
  const NONCE = 24;
@@ -63,43 +65,60 @@ function exportRows(text, key) {
63
65
  });
64
66
  }
65
67
  export function fileRecords(dir, key) {
66
- const path = (kind, id) => {
68
+ const nameKey = hkdf(sha256, key, undefined, utf8("essey-v3-mcp record names v1"), 32);
69
+ const blindName = (kind, id) => {
67
70
  if (!LOAN_ID.test(id))
68
71
  throw new ToolRefusal("loan must be 0x and 64 hex digits");
69
- return join(dir, `${kind}-${id}.json`);
72
+ return `r-${Buffer.from(hmac(sha256, nameKey, utf8(`${kind}-${id}`)))
73
+ .toString("hex")
74
+ .slice(0, 32)}.json`;
70
75
  };
71
- const read = (kind, id) => {
76
+ const opened = (name) => {
72
77
  let v;
73
78
  try {
74
- v = JSON.parse(readFileSync(path(kind, id), "utf8"));
79
+ v = JSON.parse(readFileSync(join(dir, name), "utf8"));
75
80
  }
76
81
  catch (err) {
77
82
  if (err.code === "ENOENT")
78
83
  return null;
79
84
  throw err;
80
85
  }
81
- return typeof v.sealed === "string" ? unseal(key, `${kind}-${id}`, v.sealed) : v;
86
+ return unseal(key, name, String(v.sealed));
87
+ };
88
+ const read = (kind, id) => {
89
+ const row = opened(blindName(kind, id));
90
+ if (row && (row.kind !== kind || row.id !== id))
91
+ throw new ToolRefusal("a record file holds another record");
92
+ return row?.record ?? null;
82
93
  };
83
- const write = (kind, id, v) => {
84
- const target = path(kind, id);
94
+ const write = (kind, id, record) => {
95
+ const name = blindName(kind, id);
85
96
  mkdirSync(dir, { recursive: true, mode: 0o700 });
86
- writePrivate(target, seal(key, `${kind}-${id}`, v));
97
+ writePrivate(join(dir, name), seal(key, name, { kind, id, record }));
87
98
  };
88
- const held = () => {
89
- let names;
99
+ const names = () => {
90
100
  try {
91
- names = readdirSync(dir);
101
+ return readdirSync(dir);
92
102
  }
93
103
  catch (err) {
94
104
  if (err.code === "ENOENT")
95
105
  return [];
96
106
  throw err;
97
107
  }
98
- return names.flatMap((n) => {
99
- const m = RECORD_FILE.exec(n);
100
- return m ? [{ kind: m[1], id: m[2] }] : [];
101
- });
102
108
  };
109
+ const held = () => names().flatMap((n) => {
110
+ const row = BLIND_FILE.test(n) ? opened(n) : null;
111
+ return row ? [{ kind: row.kind, id: row.id }] : [];
112
+ });
113
+ for (const n of names()) {
114
+ const m = NAMED_FILE.exec(n);
115
+ if (!m)
116
+ continue;
117
+ const [kind, id] = [m[1], m[2]];
118
+ const v = JSON.parse(readFileSync(join(dir, n), "utf8"));
119
+ write(kind, id, typeof v.sealed === "string" ? unseal(key, `${kind}-${id}`, v.sealed) : v);
120
+ unlinkSync(join(dir, n));
121
+ }
103
122
  const absolute = (p) => {
104
123
  if (!isAbsolute(p))
105
124
  throw new ToolRefusal("path must be absolute");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@esseyonsui/sui-mcp-v3",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "private": false,
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -29,7 +29,7 @@
29
29
  "typecheck": "tsc --noEmit -p tsconfig.json"
30
30
  },
31
31
  "dependencies": {
32
- "@esseyonsui/sui-sdk-v3": "0.1.8",
32
+ "@esseyonsui/sui-sdk-v3": "0.1.9",
33
33
  "@mysten/seal": "1.5.1",
34
34
  "@mysten/sui": "2.37.0",
35
35
  "@noble/ciphers": "2.4.0",