@silvana-one/coordination 1.0.15

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 (118) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +1 -0
  3. package/dist/node/agent.d.ts +93 -0
  4. package/dist/node/agent.js +278 -0
  5. package/dist/node/agent.js.map +1 -0
  6. package/dist/node/base58/base58.d.ts +5 -0
  7. package/dist/node/base58/base58.js +108 -0
  8. package/dist/node/base58/base58.js.map +1 -0
  9. package/dist/node/base58/bigint-helpers.d.ts +24 -0
  10. package/dist/node/base58/bigint-helpers.js +214 -0
  11. package/dist/node/base58/bigint-helpers.js.map +1 -0
  12. package/dist/node/base58/index.d.ts +2 -0
  13. package/dist/node/base58/index.js +3 -0
  14. package/dist/node/base58/index.js.map +1 -0
  15. package/dist/node/base58/public-key.d.ts +4 -0
  16. package/dist/node/base58/public-key.js +7 -0
  17. package/dist/node/base58/public-key.js.map +1 -0
  18. package/dist/node/base58/signature.d.ts +3 -0
  19. package/dist/node/base58/signature.js +65 -0
  20. package/dist/node/base58/signature.js.map +1 -0
  21. package/dist/node/base58/versions.d.ts +11 -0
  22. package/dist/node/base58/versions.js +12 -0
  23. package/dist/node/base58/versions.js.map +1 -0
  24. package/dist/node/execute.d.ts +16 -0
  25. package/dist/node/execute.js +142 -0
  26. package/dist/node/execute.js.map +1 -0
  27. package/dist/node/fetch.d.ts +8 -0
  28. package/dist/node/fetch.js +41 -0
  29. package/dist/node/fetch.js.map +1 -0
  30. package/dist/node/index.cjs +878 -0
  31. package/dist/node/index.d.ts +9 -0
  32. package/dist/node/index.js +10 -0
  33. package/dist/node/index.js.map +1 -0
  34. package/dist/node/mvr.d.ts +14 -0
  35. package/dist/node/mvr.js +70 -0
  36. package/dist/node/mvr.js.map +1 -0
  37. package/dist/node/publish.d.ts +9 -0
  38. package/dist/node/publish.js +40 -0
  39. package/dist/node/publish.js.map +1 -0
  40. package/dist/node/sleep.d.ts +1 -0
  41. package/dist/node/sleep.js +4 -0
  42. package/dist/node/sleep.js.map +1 -0
  43. package/dist/node/sui-client.d.ts +4 -0
  44. package/dist/node/sui-client.js +39 -0
  45. package/dist/node/sui-client.js.map +1 -0
  46. package/dist/node/types.d.ts +4 -0
  47. package/dist/node/types.js +2 -0
  48. package/dist/node/types.js.map +1 -0
  49. package/dist/node/upgrade.d.ts +13 -0
  50. package/dist/node/upgrade.js +51 -0
  51. package/dist/node/upgrade.js.map +1 -0
  52. package/dist/tsconfig.tsbuildinfo +1 -0
  53. package/dist/tsconfig.web.tsbuildinfo +1 -0
  54. package/dist/web/agent.d.ts +93 -0
  55. package/dist/web/agent.js +278 -0
  56. package/dist/web/agent.js.map +1 -0
  57. package/dist/web/base58/base58.d.ts +5 -0
  58. package/dist/web/base58/base58.js +108 -0
  59. package/dist/web/base58/base58.js.map +1 -0
  60. package/dist/web/base58/bigint-helpers.d.ts +24 -0
  61. package/dist/web/base58/bigint-helpers.js +214 -0
  62. package/dist/web/base58/bigint-helpers.js.map +1 -0
  63. package/dist/web/base58/index.d.ts +2 -0
  64. package/dist/web/base58/index.js +3 -0
  65. package/dist/web/base58/index.js.map +1 -0
  66. package/dist/web/base58/public-key.d.ts +4 -0
  67. package/dist/web/base58/public-key.js +7 -0
  68. package/dist/web/base58/public-key.js.map +1 -0
  69. package/dist/web/base58/signature.d.ts +3 -0
  70. package/dist/web/base58/signature.js +65 -0
  71. package/dist/web/base58/signature.js.map +1 -0
  72. package/dist/web/base58/versions.d.ts +11 -0
  73. package/dist/web/base58/versions.js +12 -0
  74. package/dist/web/base58/versions.js.map +1 -0
  75. package/dist/web/execute.d.ts +16 -0
  76. package/dist/web/execute.js +142 -0
  77. package/dist/web/execute.js.map +1 -0
  78. package/dist/web/fetch.d.ts +8 -0
  79. package/dist/web/fetch.js +41 -0
  80. package/dist/web/fetch.js.map +1 -0
  81. package/dist/web/index.d.ts +9 -0
  82. package/dist/web/index.js +10 -0
  83. package/dist/web/index.js.map +1 -0
  84. package/dist/web/mvr.d.ts +14 -0
  85. package/dist/web/mvr.js +70 -0
  86. package/dist/web/mvr.js.map +1 -0
  87. package/dist/web/publish.d.ts +9 -0
  88. package/dist/web/publish.js +40 -0
  89. package/dist/web/publish.js.map +1 -0
  90. package/dist/web/sleep.d.ts +1 -0
  91. package/dist/web/sleep.js +4 -0
  92. package/dist/web/sleep.js.map +1 -0
  93. package/dist/web/sui-client.d.ts +4 -0
  94. package/dist/web/sui-client.js +39 -0
  95. package/dist/web/sui-client.js.map +1 -0
  96. package/dist/web/types.d.ts +4 -0
  97. package/dist/web/types.js +2 -0
  98. package/dist/web/types.js.map +1 -0
  99. package/dist/web/upgrade.d.ts +13 -0
  100. package/dist/web/upgrade.js +51 -0
  101. package/dist/web/upgrade.js.map +1 -0
  102. package/package.json +59 -0
  103. package/src/agent.ts +437 -0
  104. package/src/base58/base58.ts +121 -0
  105. package/src/base58/bigint-helpers.ts +236 -0
  106. package/src/base58/index.ts +2 -0
  107. package/src/base58/public-key.ts +13 -0
  108. package/src/base58/signature.ts +89 -0
  109. package/src/base58/versions.ts +12 -0
  110. package/src/execute.ts +176 -0
  111. package/src/fetch.ts +54 -0
  112. package/src/index.ts +9 -0
  113. package/src/mvr.ts +99 -0
  114. package/src/publish.ts +54 -0
  115. package/src/sleep.ts +3 -0
  116. package/src/sui-client.ts +42 -0
  117. package/src/types.ts +4 -0
  118. package/src/upgrade.ts +78 -0
@@ -0,0 +1,878 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // dist/node/index.js
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ AgentRegistry: () => AgentRegistry,
24
+ buildPublishTx: () => buildPublishTx,
25
+ buildUpgradeTx: () => buildUpgradeTx,
26
+ convertFieldsToPublicKey: () => convertFieldsToPublicKey,
27
+ convertMinaSignatureFromBase58: () => convertMinaSignatureFromBase58,
28
+ convertMinaSignatureToBase58: () => convertMinaSignatureToBase58,
29
+ executeTx: () => executeTx,
30
+ fetchSuiDynamicField: () => fetchSuiDynamicField,
31
+ fetchSuiObject: () => fetchSuiObject,
32
+ network: () => network,
33
+ publishCodeToMVR: () => publishCodeToMVR,
34
+ publishToMVR: () => publishToMVR,
35
+ sleep: () => sleep,
36
+ suiClient: () => suiClient,
37
+ waitTx: () => waitTx
38
+ });
39
+ module.exports = __toCommonJS(index_exports);
40
+
41
+ // dist/node/base58/base58.js
42
+ var import_js_sha256 = require("js-sha256");
43
+
44
+ // dist/node/base58/bigint-helpers.js
45
+ var mask64 = (1n << 64n) - 1n;
46
+ var hexToNum = {};
47
+ for (let i = 0; i < 16; i++)
48
+ hexToNum[i.toString(16).charCodeAt(0)] = i;
49
+ var encoder = new TextEncoder();
50
+ var tmpBytes = new Uint8Array(64);
51
+ function changeBase(digits, base, newBase) {
52
+ let x = fromBase(digits, base);
53
+ let newDigits = toBase(x, newBase);
54
+ return newDigits;
55
+ }
56
+ function fromBase(digits, base) {
57
+ if (base <= 0n)
58
+ throw Error("fromBase: base must be positive");
59
+ let basePowers = [];
60
+ for (let power = base, n = 1; n < digits.length; power **= 2n, n *= 2) {
61
+ basePowers.push(power);
62
+ }
63
+ let k = basePowers.length;
64
+ digits = digits.concat(Array(2 ** k - digits.length).fill(0n));
65
+ for (let i = 0; i < k; i++) {
66
+ let newDigits = Array(digits.length >> 1);
67
+ let basePower = basePowers[i];
68
+ for (let j = 0; j < newDigits.length; j++) {
69
+ newDigits[j] = digits[2 * j] + basePower * digits[2 * j + 1];
70
+ }
71
+ digits = newDigits;
72
+ }
73
+ console.assert(digits.length === 1);
74
+ let [digit] = digits;
75
+ return digit;
76
+ }
77
+ function toBase(x, base) {
78
+ if (base <= 0n)
79
+ throw Error("toBase: base must be positive");
80
+ let basePowers = [];
81
+ for (let power = base; power < x; power **= 2n) {
82
+ basePowers.push(power);
83
+ }
84
+ let digits = [x];
85
+ let k = basePowers.length;
86
+ for (let i = 0; i < k; i++) {
87
+ let newDigits = Array(2 * digits.length);
88
+ let basePower = basePowers[k - 1 - i];
89
+ for (let j = 0; j < digits.length; j++) {
90
+ let x2 = digits[j];
91
+ let high = x2 / basePower;
92
+ newDigits[2 * j + 1] = high;
93
+ newDigits[2 * j] = x2 - high * basePower;
94
+ }
95
+ digits = newDigits;
96
+ }
97
+ while (digits[digits.length - 1] === 0n) {
98
+ digits.pop();
99
+ }
100
+ return digits;
101
+ }
102
+
103
+ // dist/node/base58/base58.js
104
+ var alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz".split("");
105
+ var inverseAlphabet = {};
106
+ alphabet.forEach((c, i) => {
107
+ inverseAlphabet[c] = i;
108
+ });
109
+ function toBytesWithVersionNumber(t, versionNumber) {
110
+ let bytes = toBytes(t, versionNumber);
111
+ bytes.unshift(versionNumber);
112
+ return bytes;
113
+ }
114
+ function bigIntToBytes(x, length) {
115
+ if (x < 0n) {
116
+ throw Error(`bigIntToBytes: negative numbers are not supported, got ${x}`);
117
+ }
118
+ let bytes = Array(length);
119
+ for (let i = 0; i < length; i++, x >>= 8n) {
120
+ bytes[i] = Number(x & 0xffn);
121
+ }
122
+ if (x > 0n) {
123
+ throw Error(`bigIntToBytes: input does not fit in ${length} bytes`);
124
+ }
125
+ return bytes;
126
+ }
127
+ function toBytes(t, versionNumber) {
128
+ if (t.length !== 2)
129
+ throw new Error("Expected 2 elements in t");
130
+ let bytes = [];
131
+ let subBytes1 = bigIntToBytes(t[0], 32);
132
+ subBytes1.unshift(versionNumber);
133
+ bytes.push(...subBytes1);
134
+ bytes.push(Number(t[1]));
135
+ return bytes;
136
+ }
137
+ function toBase58Check(input, versionByte) {
138
+ let withVersion = [versionByte, ...input];
139
+ let checksum = computeChecksum(withVersion);
140
+ let withChecksum = withVersion.concat(checksum);
141
+ return toBase58(withChecksum);
142
+ }
143
+ function toBase58(bytes) {
144
+ let z = 0;
145
+ while (bytes[z] === 0)
146
+ z++;
147
+ let digits = [...bytes].map(BigInt).reverse();
148
+ let base58Digits = changeBase(digits, 256n, 58n).reverse();
149
+ base58Digits = Array(z).fill(0n).concat(base58Digits);
150
+ return base58Digits.map((x) => alphabet[Number(x)]).join("");
151
+ }
152
+ function fromBase58Check(base58, versionByte) {
153
+ let bytes = fromBase58(base58);
154
+ let checksum = bytes.slice(-4);
155
+ let originalBytes = bytes.slice(0, -4);
156
+ let actualChecksum = computeChecksum(originalBytes);
157
+ if (!arrayEqual(checksum, actualChecksum))
158
+ throw Error("fromBase58Check: invalid checksum");
159
+ if (originalBytes[0] !== versionByte)
160
+ throw Error(`fromBase58Check: input version byte ${versionByte} does not match encoded version byte ${originalBytes[0]}`);
161
+ return originalBytes.slice(1);
162
+ }
163
+ function fromBase58(base58) {
164
+ let base58Digits = [...base58].map((c) => {
165
+ let digit = inverseAlphabet[c];
166
+ if (digit === void 0)
167
+ throw Error("fromBase58: invalid character");
168
+ return BigInt(digit);
169
+ });
170
+ let z = 0;
171
+ while (base58Digits[z] === 0n)
172
+ z++;
173
+ let digits = changeBase(base58Digits.reverse(), 58n, 256n).reverse();
174
+ digits = Array(z).fill(0n).concat(digits);
175
+ return digits.map(Number);
176
+ }
177
+ function computeChecksum(input) {
178
+ let hash1 = import_js_sha256.sha256.create();
179
+ hash1.update(input);
180
+ let hash2 = import_js_sha256.sha256.create();
181
+ hash2.update(hash1.array());
182
+ return hash2.array().slice(0, 4);
183
+ }
184
+ function arrayEqual(a, b) {
185
+ if (a.length !== b.length)
186
+ return false;
187
+ for (let i = 0; i < a.length; i++) {
188
+ if (a[i] !== b[i])
189
+ return false;
190
+ }
191
+ return true;
192
+ }
193
+
194
+ // dist/node/base58/versions.js
195
+ var versionNumbers = {
196
+ field: 1,
197
+ scalar: 1,
198
+ publicKey: 1,
199
+ signature: 1
200
+ };
201
+ var versionBytes = {
202
+ publicKey: 203,
203
+ privateKey: 90,
204
+ signature: 154
205
+ };
206
+
207
+ // dist/node/base58/signature.js
208
+ function assertNonNegativeInteger(n, message) {
209
+ if (!Number.isInteger(n) || n < 0)
210
+ throw Error(message);
211
+ }
212
+ function bytesToBigInt(bytes) {
213
+ let x = 0n;
214
+ let bitPosition = 0n;
215
+ for (let byte of bytes) {
216
+ x += BigInt(byte) << bitPosition;
217
+ bitPosition += 8n;
218
+ }
219
+ return x;
220
+ }
221
+ function readBytesInternal(bytes, start) {
222
+ const rBytes = bytes.slice(start, start + 32);
223
+ const sBytes = bytes.slice(start + 32, start + 64);
224
+ const r = bytesToBigInt(rBytes);
225
+ const s = bytesToBigInt(sBytes);
226
+ return { r, s };
227
+ }
228
+ function readBytes(bytes, offset, versionNumber) {
229
+ let version = bytes[offset++];
230
+ if (version !== versionNumber) {
231
+ throw Error(`fromBytes: Invalid version byte. Expected ${versionNumber}, got ${version}.`);
232
+ }
233
+ return readBytesInternal(bytes, offset);
234
+ }
235
+ var readBytes_ = (bytes, offset) => {
236
+ assertNonNegativeInteger(offset, "readBytes: offset must be integer >= 0");
237
+ if (offset >= bytes.length)
238
+ throw Error("readBytes: offset must be within bytes length");
239
+ return readBytes(bytes, offset, versionNumbers.signature);
240
+ };
241
+ function fromBytes(bytes) {
242
+ return readBytes_(bytes, 0);
243
+ }
244
+ function toBytes2(signature) {
245
+ const result = new Array(65);
246
+ result[0] = versionNumbers.signature;
247
+ let r = signature.r;
248
+ for (let i = 0; i < 32; i++) {
249
+ result[i + 1] = Number(r & 0xffn);
250
+ r >>= 8n;
251
+ }
252
+ let s = signature.s;
253
+ for (let i = 0; i < 32; i++) {
254
+ result[i + 33] = Number(s & 0xffn);
255
+ s >>= 8n;
256
+ }
257
+ return result;
258
+ }
259
+ function convertMinaSignatureFromBase58(signature) {
260
+ const bytes = fromBase58Check(signature, versionBytes.signature);
261
+ const minaSignature = fromBytes(bytes);
262
+ return minaSignature;
263
+ }
264
+ function convertMinaSignatureToBase58(signature) {
265
+ const bytes = toBytes2(signature);
266
+ return toBase58Check(bytes, versionBytes.signature);
267
+ }
268
+
269
+ // dist/node/base58/public-key.js
270
+ function convertFieldsToPublicKey(fields) {
271
+ let bytes = toBytesWithVersionNumber([fields.x, fields.isOdd ? 1n : 0n], versionNumbers.publicKey);
272
+ return toBase58Check(bytes, versionBytes.publicKey);
273
+ }
274
+
275
+ // dist/node/execute.js
276
+ var import_transactions2 = require("@mysten/sui/transactions");
277
+
278
+ // dist/node/sui-client.js
279
+ var import_client = require("@mysten/sui/client");
280
+ var import_transactions = require("@mysten/sui/transactions");
281
+ var network = process.env.NEXT_PUBLIC_SUI_CHAIN || process.env.SUI_CHAIN || "testnet";
282
+ if (!network) {
283
+ throw new Error("SUI_CHAIN is not set");
284
+ }
285
+ if (network === "testnet") {
286
+ const plugin = (0, import_transactions.namedPackagesPlugin)({
287
+ url: "https://testnet.mvr.mystenlabs.com"
288
+ });
289
+ import_transactions.Transaction.registerGlobalSerializationPlugin("namedPackagesPlugin", plugin);
290
+ }
291
+ if (network === "mainnet") {
292
+ const plugin = (0, import_transactions.namedPackagesPlugin)({
293
+ url: "https://mainnet.mvr.mystenlabs.com"
294
+ });
295
+ import_transactions.Transaction.registerGlobalSerializationPlugin("namedPackagesPlugin", plugin);
296
+ }
297
+ var suiClient = new import_client.SuiClient({
298
+ url: getUrl(network)
299
+ });
300
+ function getUrl(network2) {
301
+ if (network2 === "testnet") {
302
+ return "https://rpc-testnet.suiscan.xyz:443";
303
+ } else if (network2 === "devnet") {
304
+ return "https://rpc-ws-devnet.suiscan.xyz";
305
+ } else if (network2 === "mainnet") {
306
+ return "https://rpc-mainnet.suiscan.xyz:443";
307
+ } else {
308
+ return (0, import_client.getFullnodeUrl)(network2);
309
+ }
310
+ }
311
+
312
+ // dist/node/execute.js
313
+ var import_nanoid = require("nanoid");
314
+
315
+ // dist/node/sleep.js
316
+ function sleep(ms) {
317
+ return new Promise((resolve) => setTimeout(resolve, ms));
318
+ }
319
+
320
+ // dist/node/execute.js
321
+ var executors = {};
322
+ var locks = {};
323
+ var LOCK_TIMEOUT = 1e3 * 60 * 2;
324
+ async function getLock(address) {
325
+ const id = (0, import_nanoid.nanoid)();
326
+ let locked = false;
327
+ const start = Date.now();
328
+ while (!locked && Date.now() - start < LOCK_TIMEOUT) {
329
+ if (locks[address]) {
330
+ await sleep(Math.floor(Math.random() * 10) + 10);
331
+ } else {
332
+ locks[address] = id;
333
+ await sleep(10);
334
+ if (locks[address] === id) {
335
+ locked = true;
336
+ return id;
337
+ }
338
+ }
339
+ }
340
+ return void 0;
341
+ }
342
+ async function releaseLock(params) {
343
+ const { address, id } = params;
344
+ if (locks[address] === id) {
345
+ locks[address] = void 0;
346
+ }
347
+ }
348
+ function getExecutor(keyPair) {
349
+ const keyPairId = keyPair.toSuiAddress();
350
+ if (!executors[keyPairId]) {
351
+ executors[keyPairId] = new import_transactions2.ParallelTransactionExecutor({
352
+ client: suiClient,
353
+ signer: keyPair,
354
+ initialCoinBalance: 500000000n,
355
+ minimumCoinBalance: 300000000n,
356
+ maxPoolSize: 5
357
+ });
358
+ locks[keyPairId] = void 0;
359
+ }
360
+ return executors[keyPairId];
361
+ }
362
+ async function executeTx(params) {
363
+ let lockId;
364
+ let address;
365
+ try {
366
+ const { tx, keyPair, useParallelExecutor = false, showErrors = true } = params;
367
+ let executedTx;
368
+ let start = 0;
369
+ let end = 0;
370
+ if (useParallelExecutor) {
371
+ address = keyPair.toSuiAddress();
372
+ lockId = await getLock(address);
373
+ if (!lockId) {
374
+ throw new Error("Failed to get lock");
375
+ }
376
+ start = Date.now();
377
+ const executor = getExecutor(keyPair);
378
+ executedTx = (await executor.executeTransaction(tx, {
379
+ showEffects: true,
380
+ showObjectChanges: true,
381
+ showInput: true,
382
+ showEvents: true,
383
+ showBalanceChanges: true
384
+ })).data;
385
+ end = Date.now();
386
+ await waitTx(executedTx.digest);
387
+ await sleep(1e3);
388
+ await releaseLock({ address, id: lockId });
389
+ } else {
390
+ address = keyPair.toSuiAddress();
391
+ lockId = await getLock(address);
392
+ if (!lockId) {
393
+ throw new Error("Failed to get lock");
394
+ }
395
+ const signedTx = await tx.sign({
396
+ signer: keyPair,
397
+ client: suiClient
398
+ });
399
+ start = Date.now();
400
+ executedTx = await suiClient.executeTransactionBlock({
401
+ transactionBlock: signedTx.bytes,
402
+ signature: signedTx.signature,
403
+ options: {
404
+ showEffects: true,
405
+ showObjectChanges: true,
406
+ showInput: true,
407
+ showEvents: true,
408
+ showBalanceChanges: true
409
+ }
410
+ });
411
+ end = Date.now();
412
+ await releaseLock({ address, id: lockId });
413
+ }
414
+ if (executedTx?.effects?.status?.status === "failure") {
415
+ if (showErrors) {
416
+ console.log(`Errors for tx ${executedTx.digest}:`, executedTx?.effects?.status?.error);
417
+ throw new Error(`tx execution failed: ${executedTx.digest}`);
418
+ }
419
+ }
420
+ return {
421
+ tx: executedTx,
422
+ digest: executedTx.digest,
423
+ events: executedTx?.events?.[0]?.parsedJson,
424
+ executeTime: end - start
425
+ };
426
+ } catch (error) {
427
+ if (lockId && address) {
428
+ await releaseLock({ address, id: lockId });
429
+ }
430
+ console.error("Error in executeTx", error.message);
431
+ return void 0;
432
+ }
433
+ }
434
+ async function waitTx(digest) {
435
+ console.time(`wait sui tx`);
436
+ const txWaitResult = await suiClient.waitForTransaction({
437
+ digest,
438
+ options: {
439
+ showEffects: true,
440
+ showObjectChanges: true,
441
+ showInput: true,
442
+ showEvents: true,
443
+ showBalanceChanges: true
444
+ }
445
+ });
446
+ console.timeEnd(`wait sui tx`);
447
+ return txWaitResult;
448
+ }
449
+
450
+ // dist/node/publish.js
451
+ var import_transactions3 = require("@mysten/sui/transactions");
452
+ async function buildPublishTx(params) {
453
+ const { modules, dependencies, keypair } = params;
454
+ const address = keypair.toSuiAddress();
455
+ const tx = new import_transactions3.Transaction();
456
+ const { Result: publishedDex } = tx.publish({
457
+ modules,
458
+ dependencies
459
+ });
460
+ const { Result: dex } = tx.transferObjects([
461
+ {
462
+ Result: publishedDex
463
+ }
464
+ ], address);
465
+ tx.setSender(address);
466
+ return { tx };
467
+ }
468
+
469
+ // dist/node/upgrade.js
470
+ var import_transactions4 = require("@mysten/sui/transactions");
471
+ async function buildUpgradeTx(params) {
472
+ const { modules, dependencies, digest, address, keypair, packageID, upgradeCap } = params;
473
+ const tx = new import_transactions4.Transaction();
474
+ const ticket = tx.moveCall({
475
+ target: "0x2::package::authorize_upgrade",
476
+ arguments: [
477
+ tx.object(upgradeCap),
478
+ tx.pure.u8(import_transactions4.UpgradePolicy.COMPATIBLE),
479
+ tx.pure.vector("u8", digest)
480
+ ]
481
+ });
482
+ const upgradeData = tx.upgrade({
483
+ package: packageID,
484
+ ticket,
485
+ modules,
486
+ dependencies
487
+ });
488
+ const commitData = tx.moveCall({
489
+ target: "0x2::package::commit_upgrade",
490
+ arguments: [tx.object(upgradeCap), upgradeData]
491
+ });
492
+ const paginatedCoins = await suiClient.getCoins({
493
+ owner: address
494
+ });
495
+ const coins = paginatedCoins.data.map((coin) => {
496
+ return {
497
+ objectId: coin.coinObjectId,
498
+ version: coin.version,
499
+ digest: coin.digest
500
+ };
501
+ });
502
+ tx.setSender(address);
503
+ tx.setGasOwner(address);
504
+ tx.setGasPayment(coins);
505
+ tx.setGasBudget(3e8);
506
+ console.time("sign");
507
+ console.timeEnd("sign");
508
+ return { tx };
509
+ }
510
+
511
+ // dist/node/mvr.js
512
+ var import_transactions5 = require("@mysten/sui/transactions");
513
+ function publishToMVR(params) {
514
+ const { upgradeCap, packageName, mvrName, safeAddress } = params;
515
+ const transaction = new import_transactions5.Transaction();
516
+ const packageInfo = transaction.moveCall({
517
+ target: `@mvr/metadata::package_info::new`,
518
+ arguments: [transaction.object(upgradeCap)]
519
+ });
520
+ const display = transaction.moveCall({
521
+ target: `@mvr/metadata::display::default`,
522
+ arguments: [transaction.pure.string(packageName)]
523
+ });
524
+ transaction.moveCall({
525
+ target: `@mvr/metadata::package_info::set_display`,
526
+ arguments: [transaction.object(packageInfo), display]
527
+ });
528
+ transaction.moveCall({
529
+ target: "@mvr/metadata::package_info::set_metadata",
530
+ arguments: [
531
+ transaction.object(packageInfo),
532
+ transaction.pure.string("default"),
533
+ transaction.pure.string(mvrName)
534
+ ]
535
+ });
536
+ transaction.moveCall({
537
+ target: `@mvr/metadata::package_info::transfer`,
538
+ arguments: [
539
+ transaction.object(packageInfo),
540
+ transaction.pure.address(safeAddress)
541
+ ]
542
+ });
543
+ return transaction;
544
+ }
545
+ function publishCodeToMVR(params) {
546
+ const { packageInfo, gitRepository, gitSubdirectory, gitCommitHash, version } = params;
547
+ const transaction = new import_transactions5.Transaction();
548
+ const git = transaction.moveCall({
549
+ target: `@mvr/metadata::git::new`,
550
+ arguments: [
551
+ transaction.pure.string(gitRepository),
552
+ transaction.pure.string(gitSubdirectory),
553
+ transaction.pure.string(gitCommitHash)
554
+ ]
555
+ });
556
+ transaction.moveCall({
557
+ target: `@mvr/metadata::package_info::set_git_versioning`,
558
+ arguments: [
559
+ transaction.object(packageInfo),
560
+ transaction.pure.u64(version),
561
+ git
562
+ ]
563
+ });
564
+ return transaction;
565
+ }
566
+
567
+ // dist/node/agent.js
568
+ var import_transactions6 = require("@mysten/sui/transactions");
569
+ var import_utils = require("@mysten/sui/utils");
570
+
571
+ // dist/node/fetch.js
572
+ async function fetchSuiObject(objectID) {
573
+ const data = await suiClient.getObject({
574
+ id: objectID,
575
+ options: {
576
+ showContent: true
577
+ }
578
+ });
579
+ return data;
580
+ }
581
+ async function fetchSuiDynamicField(params) {
582
+ try {
583
+ const { objectID, parentID, fieldName, type, key } = params;
584
+ if (!objectID && !parentID) {
585
+ console.error("objectID or parentID is required");
586
+ return void 0;
587
+ }
588
+ let id = parentID;
589
+ if (objectID && !parentID) {
590
+ const suiObject = await fetchSuiObject(objectID);
591
+ id = suiObject?.data?.content?.fields?.[fieldName]?.fields?.id?.id;
592
+ }
593
+ if (!id) {
594
+ return void 0;
595
+ }
596
+ const field = await suiClient.getDynamicFieldObject({
597
+ parentId: id,
598
+ name: {
599
+ type,
600
+ value: key
601
+ }
602
+ });
603
+ return field.data?.content?.fields;
604
+ } catch (error) {
605
+ console.error("fetchSuiDynamicField: Error fetching dynamic field", error?.message);
606
+ return void 0;
607
+ }
608
+ }
609
+
610
+ // dist/node/agent.js
611
+ var AgentRegistry = class {
612
+ constructor(params) {
613
+ this.registry = params.registry;
614
+ }
615
+ static createAgentRegistry(params) {
616
+ console.log("Creating agent registry", params.name);
617
+ const transaction = new import_transactions6.Transaction();
618
+ transaction.moveCall({
619
+ target: `@silvana/agent::registry::create_registry`,
620
+ arguments: [transaction.pure.string(params.name)]
621
+ });
622
+ return transaction;
623
+ }
624
+ createDeveloper(params) {
625
+ const { name, github, image, description, site } = params;
626
+ const tx = new import_transactions6.Transaction();
627
+ tx.moveCall({
628
+ target: `@silvana/agent::registry::add_developer`,
629
+ arguments: [
630
+ tx.object(this.registry),
631
+ tx.pure.string(name),
632
+ tx.pure.string(github),
633
+ tx.pure.option("string", image ?? null),
634
+ tx.pure.option("string", description ?? null),
635
+ tx.pure.option("string", site ?? null),
636
+ tx.object(import_utils.SUI_CLOCK_OBJECT_ID)
637
+ ]
638
+ });
639
+ return tx;
640
+ }
641
+ updateDeveloper(params) {
642
+ const { name, github, image, description, site } = params;
643
+ const tx = new import_transactions6.Transaction();
644
+ tx.moveCall({
645
+ target: `@silvana/agent::registry::update_developer`,
646
+ arguments: [
647
+ tx.object(this.registry),
648
+ tx.pure.string(name),
649
+ tx.pure.string(github),
650
+ tx.pure.option("string", image ?? null),
651
+ tx.pure.option("string", description ?? null),
652
+ tx.pure.option("string", site ?? null),
653
+ tx.object(import_utils.SUI_CLOCK_OBJECT_ID)
654
+ ]
655
+ });
656
+ return tx;
657
+ }
658
+ removeDeveloper(params) {
659
+ const { name } = params;
660
+ const tx = new import_transactions6.Transaction();
661
+ tx.moveCall({
662
+ target: `@silvana/agent::registry::remove_developer`,
663
+ arguments: [tx.object(this.registry), tx.pure.string(name)]
664
+ });
665
+ return tx;
666
+ }
667
+ createAgent(params) {
668
+ const { developer, name, image, description, site, docker_image, docker_sha256, min_memory_gb, min_cpu_cores, supports_tee } = params;
669
+ const tx = new import_transactions6.Transaction();
670
+ tx.moveCall({
671
+ target: `@silvana/agent::registry::add_agent`,
672
+ arguments: [
673
+ tx.object(this.registry),
674
+ tx.pure.string(developer),
675
+ tx.pure.string(name),
676
+ tx.pure.option("string", image ?? null),
677
+ tx.pure.option("string", description ?? null),
678
+ tx.pure.option("string", site ?? null),
679
+ tx.pure.string(docker_image),
680
+ tx.pure.option("string", docker_sha256 ?? null),
681
+ tx.pure.u16(min_memory_gb),
682
+ tx.pure.u16(min_cpu_cores),
683
+ tx.pure.bool(supports_tee),
684
+ tx.object(import_utils.SUI_CLOCK_OBJECT_ID)
685
+ ]
686
+ });
687
+ return tx;
688
+ }
689
+ updateAgent(params) {
690
+ const { developer, name, image, description, site, docker_image, docker_sha256, min_memory_gb, min_cpu_cores, supports_tee } = params;
691
+ const tx = new import_transactions6.Transaction();
692
+ tx.moveCall({
693
+ target: `@silvana/agent::registry::update_agent`,
694
+ arguments: [
695
+ tx.object(this.registry),
696
+ tx.pure.string(developer),
697
+ tx.pure.string(name),
698
+ tx.pure.option("string", image ?? null),
699
+ tx.pure.option("string", description ?? null),
700
+ tx.pure.option("string", site ?? null),
701
+ tx.pure.string(docker_image),
702
+ tx.pure.option("string", docker_sha256 ?? null),
703
+ tx.pure.u16(min_memory_gb),
704
+ tx.pure.u16(min_cpu_cores),
705
+ tx.pure.bool(supports_tee),
706
+ tx.object(import_utils.SUI_CLOCK_OBJECT_ID)
707
+ ]
708
+ });
709
+ return tx;
710
+ }
711
+ removeAgent(params) {
712
+ const { developer, agent } = params;
713
+ const tx = new import_transactions6.Transaction();
714
+ tx.moveCall({
715
+ target: `@silvana/agent::registry::remove_agent`,
716
+ arguments: [
717
+ tx.object(this.registry),
718
+ tx.pure.string(developer),
719
+ tx.pure.string(agent)
720
+ ]
721
+ });
722
+ return tx;
723
+ }
724
+ async getDeveloper(params) {
725
+ const developerObject = await fetchSuiDynamicField({
726
+ objectID: this.registry,
727
+ fieldName: "developers",
728
+ type: "0x1::string::String",
729
+ key: params.name
730
+ });
731
+ if (!developerObject) {
732
+ return void 0;
733
+ }
734
+ const developer = {
735
+ id: developerObject?.id?.id,
736
+ name: developerObject.name,
737
+ github: developerObject.github,
738
+ image: developerObject?.image ?? void 0,
739
+ description: developerObject?.description ?? void 0,
740
+ site: developerObject?.site ?? void 0,
741
+ owner: developerObject.owner,
742
+ createdAt: Number(developerObject.created_at),
743
+ updatedAt: Number(developerObject.updated_at)
744
+ };
745
+ if (!developer.id || !developer.name || !developer.github || !developer.owner || !developer.createdAt || !developer.updatedAt) {
746
+ return void 0;
747
+ }
748
+ return developer;
749
+ }
750
+ async getAgent(params) {
751
+ const developerObject = await fetchSuiDynamicField({
752
+ objectID: this.registry,
753
+ fieldName: "developers",
754
+ type: "0x1::string::String",
755
+ key: params.developer
756
+ });
757
+ const id = developerObject?.agents?.fields?.id?.id;
758
+ if (!id) {
759
+ return void 0;
760
+ }
761
+ const agentObject = await fetchSuiDynamicField({
762
+ parentID: id,
763
+ fieldName: "agents",
764
+ type: "0x1::string::String",
765
+ key: params.agent
766
+ });
767
+ if (!agentObject) {
768
+ return void 0;
769
+ }
770
+ const agent = {
771
+ id: agentObject?.id?.id,
772
+ name: agentObject.name,
773
+ image: agentObject?.image ?? void 0,
774
+ description: agentObject?.description ?? void 0,
775
+ site: agentObject?.site ?? void 0,
776
+ dockerImage: agentObject.docker_image,
777
+ dockerSha256: agentObject?.docker_sha256 ?? void 0,
778
+ minMemoryGb: Number(agentObject.min_memory_gb),
779
+ minCpuCores: Number(agentObject.min_cpu_cores),
780
+ supportsTEE: Boolean(agentObject.supports_tee),
781
+ createdAt: Number(agentObject.created_at),
782
+ updatedAt: Number(agentObject.updated_at)
783
+ };
784
+ if (!agent.id || !agent.name || !agent.dockerImage || !agent.minMemoryGb || !agent.minCpuCores || !agent.createdAt || !agent.updatedAt) {
785
+ return void 0;
786
+ }
787
+ return agent;
788
+ }
789
+ static async getDockerImageDetails(params) {
790
+ try {
791
+ const { dockerImage } = params;
792
+ const colonPos = dockerImage.lastIndexOf(":");
793
+ const repository = colonPos !== -1 ? dockerImage.slice(0, colonPos) : dockerImage;
794
+ const tag = colonPos !== -1 ? dockerImage.slice(colonPos + 1) : "latest";
795
+ const tokenResponse = await fetch("https://auth.docker.io/token?" + new URLSearchParams({
796
+ service: "registry.docker.io",
797
+ scope: `repository:${repository}:pull`
798
+ }));
799
+ if (!tokenResponse.ok) {
800
+ return void 0;
801
+ }
802
+ const tokenData = await tokenResponse.json();
803
+ const token = tokenData.token;
804
+ if (!token) {
805
+ return void 0;
806
+ }
807
+ const manifestResponse = await fetch(`https://registry-1.docker.io/v2/${repository}/manifests/${tag}`, {
808
+ headers: {
809
+ Authorization: `Bearer ${token}`,
810
+ Accept: "application/vnd.docker.distribution.manifest.list.v2+json, application/vnd.oci.image.index.v1+json, application/vnd.docker.distribution.manifest.v2+json"
811
+ }
812
+ });
813
+ if (!manifestResponse.ok) {
814
+ return void 0;
815
+ }
816
+ const contentType = manifestResponse.headers.get("content-type") || "";
817
+ let digest = manifestResponse.headers.get("docker-content-digest") || "";
818
+ let manifest;
819
+ if (contentType.includes("index") || contentType.includes("list")) {
820
+ const idx = await manifestResponse.json();
821
+ const platformManifest = idx.manifests?.find((m) => m.platform?.architecture === "amd64" && m.platform?.os === "linux");
822
+ if (!platformManifest) {
823
+ return void 0;
824
+ }
825
+ const platformDigest = platformManifest.digest;
826
+ const actualManifestResponse = await fetch(`https://registry-1.docker.io/v2/${repository}/manifests/${platformDigest}`, {
827
+ headers: {
828
+ Authorization: `Bearer ${token}`,
829
+ Accept: "application/vnd.docker.distribution.manifest.v2+json"
830
+ }
831
+ });
832
+ if (!actualManifestResponse.ok) {
833
+ return void 0;
834
+ }
835
+ manifest = await actualManifestResponse.json();
836
+ const actualDigest = actualManifestResponse.headers.get("docker-content-digest");
837
+ if (actualDigest) {
838
+ digest = actualDigest;
839
+ }
840
+ } else {
841
+ manifest = await manifestResponse.json();
842
+ }
843
+ if (!manifest?.layers || !Array.isArray(manifest.layers)) {
844
+ return void 0;
845
+ }
846
+ const numberOfLayers = manifest.layers.length;
847
+ const sha2562 = digest.startsWith("sha256:") ? digest.slice(7) : digest;
848
+ if (!sha2562) {
849
+ return void 0;
850
+ }
851
+ return {
852
+ sha256: sha2562,
853
+ numberOfLayers
854
+ };
855
+ } catch (error) {
856
+ console.error("Error fetching Docker image details:", error);
857
+ return void 0;
858
+ }
859
+ }
860
+ };
861
+ // Annotate the CommonJS export names for ESM import in node:
862
+ 0 && (module.exports = {
863
+ AgentRegistry,
864
+ buildPublishTx,
865
+ buildUpgradeTx,
866
+ convertFieldsToPublicKey,
867
+ convertMinaSignatureFromBase58,
868
+ convertMinaSignatureToBase58,
869
+ executeTx,
870
+ fetchSuiDynamicField,
871
+ fetchSuiObject,
872
+ network,
873
+ publishCodeToMVR,
874
+ publishToMVR,
875
+ sleep,
876
+ suiClient,
877
+ waitTx
878
+ });