@opendatalabs/vana-sdk 0.1.0-alpha.376e2fd → 0.1.0-alpha.52b50da

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.
@@ -49,6 +49,28 @@ function parseEncryptedDataBuffer(encryptedBuffer) {
49
49
  mac: encryptedBuffer.slice(-32)
50
50
  };
51
51
  }
52
+ function toBase64(str) {
53
+ if (typeof Buffer !== "undefined") {
54
+ return Buffer.from(str, "utf8").toString("base64");
55
+ } else if (typeof btoa !== "undefined") {
56
+ return btoa(str);
57
+ } else {
58
+ const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
59
+ let result = "";
60
+ let i = 0;
61
+ while (i < str.length) {
62
+ const a = str.charCodeAt(i++);
63
+ const b = i < str.length ? str.charCodeAt(i++) : 0;
64
+ const c = i < str.length ? str.charCodeAt(i++) : 0;
65
+ const bitmap = a << 16 | b << 8 | c;
66
+ result += chars.charAt(bitmap >> 18 & 63);
67
+ result += chars.charAt(bitmap >> 12 & 63);
68
+ result += i - 2 < str.length ? chars.charAt(bitmap >> 6 & 63) : "=";
69
+ result += i - 1 < str.length ? chars.charAt(bitmap & 63) : "=";
70
+ }
71
+ return result;
72
+ }
73
+ }
52
74
  var init_crypto_utils = __esm({
53
75
  "src/platform/shared/crypto-utils.ts"() {
54
76
  "use strict";
@@ -210,7 +232,7 @@ __export(browser_exports, {
210
232
  BrowserPlatformAdapter: () => BrowserPlatformAdapter,
211
233
  browserPlatformAdapter: () => browserPlatformAdapter
212
234
  });
213
- var openpgp2, BrowserCryptoAdapter, BrowserPGPAdapter, BrowserHttpAdapter, BrowserPlatformAdapter, browserPlatformAdapter;
235
+ var openpgp2, BrowserCryptoAdapter, BrowserPGPAdapter, BrowserHttpAdapter, BrowserCacheAdapter, BrowserPlatformAdapter, browserPlatformAdapter;
214
236
  var init_browser = __esm({
215
237
  "src/platform/browser.ts"() {
216
238
  "use strict";
@@ -390,15 +412,60 @@ var init_browser = __esm({
390
412
  return fetch(url, options);
391
413
  }
392
414
  };
415
+ BrowserCacheAdapter = class {
416
+ prefix = "vana_cache_";
417
+ get(key) {
418
+ try {
419
+ if (typeof sessionStorage === "undefined") {
420
+ return null;
421
+ }
422
+ return sessionStorage.getItem(this.prefix + key);
423
+ } catch {
424
+ return null;
425
+ }
426
+ }
427
+ set(key, value) {
428
+ try {
429
+ if (typeof sessionStorage !== "undefined") {
430
+ sessionStorage.setItem(this.prefix + key, value);
431
+ }
432
+ } catch {
433
+ }
434
+ }
435
+ delete(key) {
436
+ try {
437
+ if (typeof sessionStorage !== "undefined") {
438
+ sessionStorage.removeItem(this.prefix + key);
439
+ }
440
+ } catch {
441
+ }
442
+ }
443
+ clear() {
444
+ try {
445
+ if (typeof sessionStorage === "undefined") {
446
+ return;
447
+ }
448
+ const keys = Object.keys(sessionStorage);
449
+ for (const key of keys) {
450
+ if (key.startsWith(this.prefix)) {
451
+ sessionStorage.removeItem(key);
452
+ }
453
+ }
454
+ } catch {
455
+ }
456
+ }
457
+ };
393
458
  BrowserPlatformAdapter = class {
394
459
  crypto;
395
460
  pgp;
396
461
  http;
462
+ cache;
397
463
  platform = "browser";
398
464
  constructor() {
399
465
  this.crypto = new BrowserCryptoAdapter();
400
466
  this.pgp = new BrowserPGPAdapter();
401
467
  this.http = new BrowserHttpAdapter();
468
+ this.cache = new BrowserCacheAdapter();
402
469
  }
403
470
  };
404
471
  browserPlatformAdapter = new BrowserPlatformAdapter();
@@ -413,6 +480,7 @@ __export(index_node_exports, {
413
480
  BaseController: () => BaseController,
414
481
  BlockchainError: () => BlockchainError,
415
482
  BrowserPlatformAdapter: () => BrowserPlatformAdapter,
483
+ CallbackStorage: () => CallbackStorage,
416
484
  CircuitBreaker: () => CircuitBreaker,
417
485
  ContractFactory: () => ContractFactory,
418
486
  ContractNotFoundError: () => ContractNotFoundError,
@@ -447,8 +515,8 @@ __export(index_node_exports, {
447
515
  SchemaValidator: () => SchemaValidator,
448
516
  SerializationError: () => SerializationError,
449
517
  ServerController: () => ServerController,
450
- ServerProxyStorage: () => ServerProxyStorage,
451
518
  ServerUrlMismatchError: () => ServerUrlMismatchError,
519
+ SignatureCache: () => SignatureCache,
452
520
  SignatureError: () => SignatureError,
453
521
  StorageError: () => StorageError,
454
522
  StorageManager: () => StorageManager,
@@ -523,7 +591,8 @@ __export(index_node_exports, {
523
591
  validateGrantFile: () => validateGrantFile,
524
592
  validateGranteeAccess: () => validateGranteeAccess,
525
593
  validateOperationAccess: () => validateOperationAccess,
526
- vanaMainnet: () => vanaMainnet2
594
+ vanaMainnet: () => vanaMainnet2,
595
+ withSignatureCache: () => withSignatureCache
527
596
  });
528
597
  module.exports = __toCommonJS(index_node_exports);
529
598
 
@@ -746,15 +815,45 @@ var NodeHttpAdapter = class {
746
815
  throw new Error("No fetch implementation available in Node.js environment");
747
816
  }
748
817
  };
818
+ var NodeCacheAdapter = class {
819
+ cache = /* @__PURE__ */ new Map();
820
+ defaultTtl = 2 * 60 * 60 * 1e3;
821
+ // 2 hours in milliseconds
822
+ get(key) {
823
+ const entry = this.cache.get(key);
824
+ if (!entry) {
825
+ return null;
826
+ }
827
+ if (Date.now() > entry.expires) {
828
+ this.cache.delete(key);
829
+ return null;
830
+ }
831
+ return entry.value;
832
+ }
833
+ set(key, value) {
834
+ this.cache.set(key, {
835
+ value,
836
+ expires: Date.now() + this.defaultTtl
837
+ });
838
+ }
839
+ delete(key) {
840
+ this.cache.delete(key);
841
+ }
842
+ clear() {
843
+ this.cache.clear();
844
+ }
845
+ };
749
846
  var NodePlatformAdapter = class {
750
847
  crypto;
751
848
  pgp;
752
849
  http;
850
+ cache;
753
851
  platform = "node";
754
852
  constructor() {
755
853
  this.crypto = new NodeCryptoAdapter();
756
854
  this.pgp = new NodePGPAdapter();
757
855
  this.http = new NodeHttpAdapter();
856
+ this.cache = new NodeCacheAdapter();
758
857
  }
759
858
  };
760
859
  var nodePlatformAdapter = new NodePlatformAdapter();
@@ -1176,276 +1275,45 @@ var PermissionError = class extends VanaError {
1176
1275
  }
1177
1276
  };
1178
1277
 
1179
- // src/config/addresses.ts
1180
- var CONTRACTS = {
1181
- // Core Platform Contracts
1182
- DataPermissions: {
1183
- addresses: {
1184
- 14800: "0x31fb1D48f6B2265A4cAD516BC39E96a18fb7c8de",
1185
- 1480: "0x31fb1D48f6B2265A4cAD516BC39E96a18fb7c8de"
1186
- }
1187
- },
1188
- DataRegistry: {
1189
- addresses: {
1190
- 14800: "0x8C8788f98385F6ba1adD4234e551ABba0f82Cb7C",
1191
- 1480: "0x8C8788f98385F6ba1adD4234e551ABba0f82Cb7C"
1192
- }
1193
- },
1194
- TeePoolPhala: {
1195
- addresses: {
1196
- 14800: "0xE8EC6BD73b23Ad40E6B9a6f4bD343FAc411bD99A",
1197
- 1480: "0xE8EC6BD73b23Ad40E6B9a6f4bD343FAc411bD99A"
1198
- }
1199
- },
1200
- ComputeEngine: {
1201
- addresses: {
1202
- 14800: "0xb2BFe33FA420c45F1Cf1287542ad81ae935447bd",
1203
- 1480: "0xb2BFe33FA420c45F1Cf1287542ad81ae935447bd"
1204
- }
1205
- },
1206
- // Data Access Infrastructure
1207
- DataRefinerRegistry: {
1208
- addresses: {
1209
- 14800: "0x93c3EF89369fDcf08Be159D9DeF0F18AB6Be008c",
1210
- 1480: "0x93c3EF89369fDcf08Be159D9DeF0F18AB6Be008c"
1211
- }
1212
- },
1213
- QueryEngine: {
1214
- addresses: {
1215
- 14800: "0xd25Eb66EA2452cf3238A2eC6C1FD1B7F5B320490",
1216
- 1480: "0xd25Eb66EA2452cf3238A2eC6C1FD1B7F5B320490"
1217
- }
1218
- },
1219
- VanaTreasury: {
1220
- addresses: {
1221
- 14800: "0x94a1E56e555ac48d092f490fB10CDFaB434915eD",
1222
- 1480: "0x94a1E56e555ac48d092f490fB10CDFaB434915eD"
1223
- }
1224
- },
1225
- ComputeInstructionRegistry: {
1226
- addresses: {
1227
- 14800: "0x5786B12b4c6Ba2bFAF0e77Ed30Bf6d32805563A5",
1228
- 1480: "0x5786B12b4c6Ba2bFAF0e77Ed30Bf6d32805563A5"
1229
- }
1230
- },
1231
- // TEE Pool Variants
1232
- TeePoolEphemeralStandard: {
1233
- addresses: {
1234
- 14800: "0xe124bae846D5ec157f75Bd9e68ca87C4d2AB835A",
1235
- 1480: "0xe124bae846D5ec157f75Bd9e68ca87C4d2AB835A"
1236
- }
1237
- },
1238
- TeePoolPersistentStandard: {
1239
- addresses: {
1240
- 14800: "0xe8bB8d0629651Cf33e0845d743976Dc1f0971d76",
1241
- 1480: "0xe8bB8d0629651Cf33e0845d743976Dc1f0971d76"
1242
- }
1243
- },
1244
- TeePoolPersistentGpu: {
1245
- addresses: {
1246
- 14800: "0x1c346Cd74f8551f8fa13f3F4b6b8dAE22338E6a9",
1247
- 1480: "0x1c346Cd74f8551f8fa13f3F4b6b8dAE22338E6a9"
1248
- }
1249
- },
1250
- TeePoolDedicatedStandard: {
1251
- addresses: {
1252
- 14800: "0xf024b7ac5E8417416f53B41ecfa58C8e9396687d",
1253
- 1480: "0xf024b7ac5E8417416f53B41ecfa58C8e9396687d"
1254
- }
1255
- },
1256
- TeePoolDedicatedGpu: {
1257
- addresses: {
1258
- 14800: "0xB1686FA9620bBf851714d1cB47b8a4Bf4664644E",
1259
- 1480: "0xB1686FA9620bBf851714d1cB47b8a4Bf4664644E"
1260
- }
1261
- },
1262
- // DLP Reward System
1263
- VanaEpoch: {
1264
- addresses: {
1265
- 14800: "0x2063cFF0609D59bCCc196E20Eb58A8696a6b15A0",
1266
- 1480: "0x2063cFF0609D59bCCc196E20Eb58A8696a6b15A0"
1267
- }
1268
- },
1269
- DLPRegistry: {
1270
- addresses: {
1271
- 14800: "0x4D59880a924526d1dD33260552Ff4328b1E18a43",
1272
- 1480: "0x4D59880a924526d1dD33260552Ff4328b1E18a43"
1273
- }
1274
- },
1275
- DLPRegistryTreasury: {
1276
- addresses: {
1277
- 14800: "0xb12ce1d27bEeFe39b6F0110b1AB77C21Aa0c9F9a",
1278
- 1480: "0xb12ce1d27bEeFe39b6F0110b1AB77C21Aa0c9F9a"
1279
- }
1280
- },
1281
- DLPPerformance: {
1282
- addresses: {
1283
- 14800: "0x847715C7DB37cF286611182Be0bD333cbfa29cc1",
1284
- 1480: "0x847715C7DB37cF286611182Be0bD333cbfa29cc1"
1285
- }
1286
- },
1287
- DLPRewardDeployer: {
1288
- addresses: {
1289
- 14800: "0xEFD0F9Ba9De70586b7c4189971cF754adC923B04",
1290
- 1480: "0xEFD0F9Ba9De70586b7c4189971cF754adC923B04"
1291
- }
1292
- },
1293
- DLPRewardDeployerTreasury: {
1294
- addresses: {
1295
- 14800: "0xb547ca8Fe4990fe330FeAeb1C2EBb42F925Af5b8",
1296
- 1480: "0xb547ca8Fe4990fe330FeAeb1C2EBb42F925Af5b8"
1297
- }
1298
- },
1299
- DLPRewardSwap: {
1300
- addresses: {
1301
- 14800: "0x7c6862C46830F0fc3bF3FF509EA1bD0EE7267fB0",
1302
- 1480: "0x7c6862C46830F0fc3bF3FF509EA1bD0EE7267fB0"
1303
- }
1304
- },
1305
- SwapHelper: {
1306
- addresses: {
1307
- 14800: "0x55D5e6F73326315bF2E091e97F04f0770e5C54e2",
1308
- 1480: "0x55D5e6F73326315bF2E091e97F04f0770e5C54e2"
1309
- }
1310
- },
1311
- // VanaPool (Staking)
1312
- VanaPoolStaking: {
1313
- addresses: {
1314
- 14800: "0x641C18E2F286c86f96CE95C8ec1EB9fC0415Ca0e",
1315
- 1480: "0x641C18E2F286c86f96CE95C8ec1EB9fC0415Ca0e"
1316
- }
1317
- },
1318
- VanaPoolEntity: {
1319
- addresses: {
1320
- 14800: "0x44f20490A82e1f1F1cC25Dd3BA8647034eDdce30",
1321
- 1480: "0x44f20490A82e1f1F1cC25Dd3BA8647034eDdce30"
1322
- }
1323
- },
1324
- VanaPoolTreasury: {
1325
- addresses: {
1326
- 14800: "0x143BE72CF2541604A7691933CAccd6D9cC17c003",
1327
- 1480: "0x143BE72CF2541604A7691933CAccd6D9cC17c003"
1328
- }
1329
- },
1330
- // DLP Deployment Contracts
1331
- DAT: {
1332
- addresses: {
1333
- 14800: "0xA706b93ccED89f13340673889e29F0a5cd84212d",
1334
- 1480: "0xA706b93ccED89f13340673889e29F0a5cd84212d"
1335
- }
1336
- },
1337
- DATFactory: {
1338
- addresses: {
1339
- 14800: "0x40f8bccF35a75ecef63BC3B1B3E06ffEB9220644",
1340
- 1480: "0x40f8bccF35a75ecef63BC3B1B3E06ffEB9220644"
1341
- }
1342
- },
1343
- DATPausable: {
1344
- addresses: {
1345
- 14800: "0xe69FE86f0B95cC2f8416Fe22815c85DC8887e76e",
1346
- 1480: "0xe69FE86f0B95cC2f8416Fe22815c85DC8887e76e"
1347
- }
1348
- },
1349
- DATVotes: {
1350
- addresses: {
1351
- 14800: "0xaE04c8A77E9B27869eb563720524A9aE0baf1831",
1352
- 1480: "0xaE04c8A77E9B27869eb563720524A9aE0baf1831"
1353
- }
1354
- },
1355
- // Utility Contracts (no ABIs in SDK)
1356
- Multicall3: {
1357
- addresses: {
1358
- 14800: "0xD8d2dFca27E8797fd779F8547166A2d3B29d360E",
1359
- 1480: "0xD8d2dFca27E8797fd779F8547166A2d3B29d360E"
1360
- }
1361
- },
1362
- Multisend: {
1363
- addresses: {
1364
- 14800: "0x8807e8BCDFbaA8c2761760f3FBA37F6f7F2C5b2d",
1365
- 1480: "0x8807e8BCDFbaA8c2761760f3FBA37F6f7F2C5b2d"
1366
- }
1367
- }
1368
- };
1369
- var LEGACY_CONTRACTS = {
1370
- // DEPRECATED: Original Intel SGX TeePool (PRO-347)
1371
- TeePool: {
1372
- addresses: {
1373
- 14800: "0x3c92fD91639b41f13338CE62f19131e7d19eaa0D",
1374
- 1480: "0x3c92fD91639b41f13338CE62f19131e7d19eaa0D"
1375
- }
1376
- },
1377
- // DEPRECATED: DLPRoot system (replaced by VanaPool + DLPRewards)
1378
- DLPRootEpoch: {
1379
- addresses: {
1380
- 14800: "0xc3d176cF6BccFCB9225b53B87a95147218e1537F",
1381
- 1480: "0xc3d176cF6BccFCB9225b53B87a95147218e1537F"
1382
- }
1383
- },
1384
- DLPRootCore: {
1385
- addresses: {
1386
- 14800: "0x0aBa5e28228c323A67712101d61a54d4ff5720FD",
1387
- 1480: "0x0aBa5e28228c323A67712101d61a54d4ff5720FD"
1388
- }
1389
- },
1390
- DLPRoot: {
1391
- addresses: {
1392
- 14800: "0xff14346dF2B8Fd0c95BF34f1c92e49417b508AD5",
1393
- 1480: "0xff14346dF2B8Fd0c95BF34f1c92e49417b508AD5"
1394
- }
1395
- },
1396
- DLPRootMetrics: {
1397
- addresses: {
1398
- 14800: "0xbb532917B6407c060Afd9Cb7d53527eCb91d6662",
1399
- 1480: "0xbb532917B6407c060Afd9Cb7d53527eCb91d6662"
1400
- }
1401
- },
1402
- DLPRootStakesTreasury: {
1403
- addresses: {
1404
- 14800: "0x52c3260ED5C235fcA43524CF508e29c897318775",
1405
- 1480: "0x52c3260ED5C235fcA43524CF508e29c897318775"
1406
- }
1407
- },
1408
- DLPRootRewardsTreasury: {
1409
- addresses: {
1410
- 14800: "0xDBFb6B8b9E2eCAEbdE64d665cD553dB81e524479",
1411
- 1480: "0xDBFb6B8b9E2eCAEbdE64d665cD553dB81e524479"
1412
- }
1413
- }
1414
- };
1415
- var CONTRACT_ADDRESSES = {
1416
- 14800: Object.fromEntries(
1417
- Object.entries(CONTRACTS).map(([name, info]) => [name, info.addresses[14800]]).filter(([, addr]) => addr)
1418
- ),
1419
- 1480: Object.fromEntries(
1420
- Object.entries(CONTRACTS).map(([name, info]) => [name, info.addresses[1480]]).filter(([, addr]) => addr)
1421
- )
1422
- };
1423
- var UTILITY_ADDRESSES = {
1424
- 14800: {
1425
- Multicall3: CONTRACTS.Multicall3.addresses[14800],
1426
- Multisend: CONTRACTS.Multisend.addresses[14800]
1427
- },
1428
- 1480: {
1429
- Multicall3: CONTRACTS.Multicall3.addresses[1480],
1430
- Multisend: CONTRACTS.Multisend.addresses[1480]
1431
- }
1432
- };
1433
- var LEGACY_ADDRESSES = {
1434
- 14800: Object.fromEntries(
1435
- Object.entries(LEGACY_CONTRACTS).map(([name, info]) => [name, info.addresses[14800]]).filter(([, addr]) => addr)
1436
- ),
1437
- 1480: Object.fromEntries(
1438
- Object.entries(LEGACY_CONTRACTS).map(([name, info]) => [name, info.addresses[1480]]).filter(([, addr]) => addr)
1439
- )
1440
- };
1441
- var getContractAddress = (chainId, contract) => {
1442
- const contractAddress = CONTRACT_ADDRESSES[chainId]?.[contract];
1443
- if (!contractAddress) {
1444
- throw new Error(
1445
- `Contract address not found for ${contract} on chain ${chainId}`
1446
- );
1278
+ // src/utils/transactionParsing.ts
1279
+ var import_viem = require("viem");
1280
+
1281
+ // src/config/eventMappings.ts
1282
+ var EVENT_MAPPINGS = {
1283
+ // Permission operations
1284
+ grant: {
1285
+ contract: "DataPermissions",
1286
+ event: "PermissionAdded"
1287
+ },
1288
+ revoke: {
1289
+ contract: "DataPermissions",
1290
+ event: "PermissionRevoked"
1291
+ },
1292
+ trustServer: {
1293
+ contract: "DataPermissions",
1294
+ event: "ServerTrusted"
1295
+ },
1296
+ untrustServer: {
1297
+ contract: "DataPermissions",
1298
+ event: "ServerUntrusted"
1299
+ },
1300
+ // Data registry operations
1301
+ addFile: {
1302
+ contract: "DataRegistry",
1303
+ event: "FileAdded"
1304
+ },
1305
+ addRefinement: {
1306
+ contract: "DataRegistry",
1307
+ event: "RefinementAdded"
1308
+ },
1309
+ updateRefinement: {
1310
+ contract: "DataRegistry",
1311
+ event: "RefinementUpdated"
1312
+ },
1313
+ addFilePermission: {
1314
+ contract: "DataRegistry",
1315
+ event: "PermissionGranted"
1447
1316
  }
1448
- return contractAddress;
1449
1317
  };
1450
1318
 
1451
1319
  // src/abi/ComputeEngineImplementation.ts
@@ -33652,8 +33520,334 @@ function getAbi(contract) {
33652
33520
  return abi;
33653
33521
  }
33654
33522
 
33523
+ // src/utils/transactionParsing.ts
33524
+ async function parseTransactionResult(context, hash, operation) {
33525
+ const mapping = EVENT_MAPPINGS[operation];
33526
+ try {
33527
+ console.debug(`\u{1F50D} Parsing ${operation} transaction: ${hash}`);
33528
+ const receipt = await context.publicClient.waitForTransactionReceipt({
33529
+ hash,
33530
+ timeout: 3e4
33531
+ // 30 second timeout
33532
+ });
33533
+ console.debug(`\u2705 Transaction confirmed in block ${receipt.blockNumber}`);
33534
+ const abi = getAbi(mapping.contract);
33535
+ const events = (0, import_viem.parseEventLogs)({
33536
+ logs: receipt.logs,
33537
+ abi,
33538
+ eventName: mapping.event,
33539
+ strict: true
33540
+ // Only return logs that conform to the ABI
33541
+ });
33542
+ if (events.length === 0) {
33543
+ throw new BlockchainError(
33544
+ `No ${mapping.event} event found in transaction ${hash}. Transaction may have failed or reverted.`
33545
+ );
33546
+ }
33547
+ if (events.length > 1) {
33548
+ console.warn(
33549
+ `\u26A0\uFE0F Multiple ${mapping.event} events found in transaction ${hash}. Using the first one.`
33550
+ );
33551
+ }
33552
+ const event = events[0];
33553
+ console.debug(`\u{1F389} Found ${mapping.event} event with args:`, event.args);
33554
+ return {
33555
+ ...event.args,
33556
+ transactionHash: hash,
33557
+ blockNumber: receipt.blockNumber,
33558
+ gasUsed: receipt.gasUsed
33559
+ };
33560
+ } catch (error) {
33561
+ if (error instanceof BlockchainError || error instanceof NetworkError) {
33562
+ throw error;
33563
+ }
33564
+ if (error instanceof Error && error.message.includes("timeout")) {
33565
+ throw new NetworkError(
33566
+ `Transaction ${hash} confirmation timeout after 30 seconds. The transaction may still be pending.`,
33567
+ error
33568
+ );
33569
+ }
33570
+ throw new BlockchainError(
33571
+ `Failed to parse ${operation} transaction ${hash}: ${error instanceof Error ? error.message : "Unknown error"}`,
33572
+ error
33573
+ );
33574
+ }
33575
+ }
33576
+
33577
+ // src/config/addresses.ts
33578
+ var CONTRACTS = {
33579
+ // Core Platform Contracts
33580
+ DataPermissions: {
33581
+ addresses: {
33582
+ 14800: "0x31fb1D48f6B2265A4cAD516BC39E96a18fb7c8de",
33583
+ 1480: "0x31fb1D48f6B2265A4cAD516BC39E96a18fb7c8de"
33584
+ }
33585
+ },
33586
+ DataRegistry: {
33587
+ addresses: {
33588
+ 14800: "0x8C8788f98385F6ba1adD4234e551ABba0f82Cb7C",
33589
+ 1480: "0x8C8788f98385F6ba1adD4234e551ABba0f82Cb7C"
33590
+ }
33591
+ },
33592
+ TeePoolPhala: {
33593
+ addresses: {
33594
+ 14800: "0xE8EC6BD73b23Ad40E6B9a6f4bD343FAc411bD99A",
33595
+ 1480: "0xE8EC6BD73b23Ad40E6B9a6f4bD343FAc411bD99A"
33596
+ }
33597
+ },
33598
+ ComputeEngine: {
33599
+ addresses: {
33600
+ 14800: "0xb2BFe33FA420c45F1Cf1287542ad81ae935447bd",
33601
+ 1480: "0xb2BFe33FA420c45F1Cf1287542ad81ae935447bd"
33602
+ }
33603
+ },
33604
+ // Data Access Infrastructure
33605
+ DataRefinerRegistry: {
33606
+ addresses: {
33607
+ 14800: "0x93c3EF89369fDcf08Be159D9DeF0F18AB6Be008c",
33608
+ 1480: "0x93c3EF89369fDcf08Be159D9DeF0F18AB6Be008c"
33609
+ }
33610
+ },
33611
+ QueryEngine: {
33612
+ addresses: {
33613
+ 14800: "0xd25Eb66EA2452cf3238A2eC6C1FD1B7F5B320490",
33614
+ 1480: "0xd25Eb66EA2452cf3238A2eC6C1FD1B7F5B320490"
33615
+ }
33616
+ },
33617
+ VanaTreasury: {
33618
+ addresses: {
33619
+ 14800: "0x94a1E56e555ac48d092f490fB10CDFaB434915eD",
33620
+ 1480: "0x94a1E56e555ac48d092f490fB10CDFaB434915eD"
33621
+ }
33622
+ },
33623
+ ComputeInstructionRegistry: {
33624
+ addresses: {
33625
+ 14800: "0x5786B12b4c6Ba2bFAF0e77Ed30Bf6d32805563A5",
33626
+ 1480: "0x5786B12b4c6Ba2bFAF0e77Ed30Bf6d32805563A5"
33627
+ }
33628
+ },
33629
+ // TEE Pool Variants
33630
+ TeePoolEphemeralStandard: {
33631
+ addresses: {
33632
+ 14800: "0xe124bae846D5ec157f75Bd9e68ca87C4d2AB835A",
33633
+ 1480: "0xe124bae846D5ec157f75Bd9e68ca87C4d2AB835A"
33634
+ }
33635
+ },
33636
+ TeePoolPersistentStandard: {
33637
+ addresses: {
33638
+ 14800: "0xe8bB8d0629651Cf33e0845d743976Dc1f0971d76",
33639
+ 1480: "0xe8bB8d0629651Cf33e0845d743976Dc1f0971d76"
33640
+ }
33641
+ },
33642
+ TeePoolPersistentGpu: {
33643
+ addresses: {
33644
+ 14800: "0x1c346Cd74f8551f8fa13f3F4b6b8dAE22338E6a9",
33645
+ 1480: "0x1c346Cd74f8551f8fa13f3F4b6b8dAE22338E6a9"
33646
+ }
33647
+ },
33648
+ TeePoolDedicatedStandard: {
33649
+ addresses: {
33650
+ 14800: "0xf024b7ac5E8417416f53B41ecfa58C8e9396687d",
33651
+ 1480: "0xf024b7ac5E8417416f53B41ecfa58C8e9396687d"
33652
+ }
33653
+ },
33654
+ TeePoolDedicatedGpu: {
33655
+ addresses: {
33656
+ 14800: "0xB1686FA9620bBf851714d1cB47b8a4Bf4664644E",
33657
+ 1480: "0xB1686FA9620bBf851714d1cB47b8a4Bf4664644E"
33658
+ }
33659
+ },
33660
+ // DLP Reward System
33661
+ VanaEpoch: {
33662
+ addresses: {
33663
+ 14800: "0x2063cFF0609D59bCCc196E20Eb58A8696a6b15A0",
33664
+ 1480: "0x2063cFF0609D59bCCc196E20Eb58A8696a6b15A0"
33665
+ }
33666
+ },
33667
+ DLPRegistry: {
33668
+ addresses: {
33669
+ 14800: "0x4D59880a924526d1dD33260552Ff4328b1E18a43",
33670
+ 1480: "0x4D59880a924526d1dD33260552Ff4328b1E18a43"
33671
+ }
33672
+ },
33673
+ DLPRegistryTreasury: {
33674
+ addresses: {
33675
+ 14800: "0xb12ce1d27bEeFe39b6F0110b1AB77C21Aa0c9F9a",
33676
+ 1480: "0xb12ce1d27bEeFe39b6F0110b1AB77C21Aa0c9F9a"
33677
+ }
33678
+ },
33679
+ DLPPerformance: {
33680
+ addresses: {
33681
+ 14800: "0x847715C7DB37cF286611182Be0bD333cbfa29cc1",
33682
+ 1480: "0x847715C7DB37cF286611182Be0bD333cbfa29cc1"
33683
+ }
33684
+ },
33685
+ DLPRewardDeployer: {
33686
+ addresses: {
33687
+ 14800: "0xEFD0F9Ba9De70586b7c4189971cF754adC923B04",
33688
+ 1480: "0xEFD0F9Ba9De70586b7c4189971cF754adC923B04"
33689
+ }
33690
+ },
33691
+ DLPRewardDeployerTreasury: {
33692
+ addresses: {
33693
+ 14800: "0xb547ca8Fe4990fe330FeAeb1C2EBb42F925Af5b8",
33694
+ 1480: "0xb547ca8Fe4990fe330FeAeb1C2EBb42F925Af5b8"
33695
+ }
33696
+ },
33697
+ DLPRewardSwap: {
33698
+ addresses: {
33699
+ 14800: "0x7c6862C46830F0fc3bF3FF509EA1bD0EE7267fB0",
33700
+ 1480: "0x7c6862C46830F0fc3bF3FF509EA1bD0EE7267fB0"
33701
+ }
33702
+ },
33703
+ SwapHelper: {
33704
+ addresses: {
33705
+ 14800: "0x55D5e6F73326315bF2E091e97F04f0770e5C54e2",
33706
+ 1480: "0x55D5e6F73326315bF2E091e97F04f0770e5C54e2"
33707
+ }
33708
+ },
33709
+ // VanaPool (Staking)
33710
+ VanaPoolStaking: {
33711
+ addresses: {
33712
+ 14800: "0x641C18E2F286c86f96CE95C8ec1EB9fC0415Ca0e",
33713
+ 1480: "0x641C18E2F286c86f96CE95C8ec1EB9fC0415Ca0e"
33714
+ }
33715
+ },
33716
+ VanaPoolEntity: {
33717
+ addresses: {
33718
+ 14800: "0x44f20490A82e1f1F1cC25Dd3BA8647034eDdce30",
33719
+ 1480: "0x44f20490A82e1f1F1cC25Dd3BA8647034eDdce30"
33720
+ }
33721
+ },
33722
+ VanaPoolTreasury: {
33723
+ addresses: {
33724
+ 14800: "0x143BE72CF2541604A7691933CAccd6D9cC17c003",
33725
+ 1480: "0x143BE72CF2541604A7691933CAccd6D9cC17c003"
33726
+ }
33727
+ },
33728
+ // DLP Deployment Contracts
33729
+ DAT: {
33730
+ addresses: {
33731
+ 14800: "0xA706b93ccED89f13340673889e29F0a5cd84212d",
33732
+ 1480: "0xA706b93ccED89f13340673889e29F0a5cd84212d"
33733
+ }
33734
+ },
33735
+ DATFactory: {
33736
+ addresses: {
33737
+ 14800: "0x40f8bccF35a75ecef63BC3B1B3E06ffEB9220644",
33738
+ 1480: "0x40f8bccF35a75ecef63BC3B1B3E06ffEB9220644"
33739
+ }
33740
+ },
33741
+ DATPausable: {
33742
+ addresses: {
33743
+ 14800: "0xe69FE86f0B95cC2f8416Fe22815c85DC8887e76e",
33744
+ 1480: "0xe69FE86f0B95cC2f8416Fe22815c85DC8887e76e"
33745
+ }
33746
+ },
33747
+ DATVotes: {
33748
+ addresses: {
33749
+ 14800: "0xaE04c8A77E9B27869eb563720524A9aE0baf1831",
33750
+ 1480: "0xaE04c8A77E9B27869eb563720524A9aE0baf1831"
33751
+ }
33752
+ },
33753
+ // Utility Contracts (no ABIs in SDK)
33754
+ Multicall3: {
33755
+ addresses: {
33756
+ 14800: "0xD8d2dFca27E8797fd779F8547166A2d3B29d360E",
33757
+ 1480: "0xD8d2dFca27E8797fd779F8547166A2d3B29d360E"
33758
+ }
33759
+ },
33760
+ Multisend: {
33761
+ addresses: {
33762
+ 14800: "0x8807e8BCDFbaA8c2761760f3FBA37F6f7F2C5b2d",
33763
+ 1480: "0x8807e8BCDFbaA8c2761760f3FBA37F6f7F2C5b2d"
33764
+ }
33765
+ }
33766
+ };
33767
+ var LEGACY_CONTRACTS = {
33768
+ // DEPRECATED: Original Intel SGX TeePool (PRO-347)
33769
+ TeePool: {
33770
+ addresses: {
33771
+ 14800: "0x3c92fD91639b41f13338CE62f19131e7d19eaa0D",
33772
+ 1480: "0x3c92fD91639b41f13338CE62f19131e7d19eaa0D"
33773
+ }
33774
+ },
33775
+ // DEPRECATED: DLPRoot system (replaced by VanaPool + DLPRewards)
33776
+ DLPRootEpoch: {
33777
+ addresses: {
33778
+ 14800: "0xc3d176cF6BccFCB9225b53B87a95147218e1537F",
33779
+ 1480: "0xc3d176cF6BccFCB9225b53B87a95147218e1537F"
33780
+ }
33781
+ },
33782
+ DLPRootCore: {
33783
+ addresses: {
33784
+ 14800: "0x0aBa5e28228c323A67712101d61a54d4ff5720FD",
33785
+ 1480: "0x0aBa5e28228c323A67712101d61a54d4ff5720FD"
33786
+ }
33787
+ },
33788
+ DLPRoot: {
33789
+ addresses: {
33790
+ 14800: "0xff14346dF2B8Fd0c95BF34f1c92e49417b508AD5",
33791
+ 1480: "0xff14346dF2B8Fd0c95BF34f1c92e49417b508AD5"
33792
+ }
33793
+ },
33794
+ DLPRootMetrics: {
33795
+ addresses: {
33796
+ 14800: "0xbb532917B6407c060Afd9Cb7d53527eCb91d6662",
33797
+ 1480: "0xbb532917B6407c060Afd9Cb7d53527eCb91d6662"
33798
+ }
33799
+ },
33800
+ DLPRootStakesTreasury: {
33801
+ addresses: {
33802
+ 14800: "0x52c3260ED5C235fcA43524CF508e29c897318775",
33803
+ 1480: "0x52c3260ED5C235fcA43524CF508e29c897318775"
33804
+ }
33805
+ },
33806
+ DLPRootRewardsTreasury: {
33807
+ addresses: {
33808
+ 14800: "0xDBFb6B8b9E2eCAEbdE64d665cD553dB81e524479",
33809
+ 1480: "0xDBFb6B8b9E2eCAEbdE64d665cD553dB81e524479"
33810
+ }
33811
+ }
33812
+ };
33813
+ var CONTRACT_ADDRESSES = {
33814
+ 14800: Object.fromEntries(
33815
+ Object.entries(CONTRACTS).map(([name, info]) => [name, info.addresses[14800]]).filter(([, addr]) => addr)
33816
+ ),
33817
+ 1480: Object.fromEntries(
33818
+ Object.entries(CONTRACTS).map(([name, info]) => [name, info.addresses[1480]]).filter(([, addr]) => addr)
33819
+ )
33820
+ };
33821
+ var UTILITY_ADDRESSES = {
33822
+ 14800: {
33823
+ Multicall3: CONTRACTS.Multicall3.addresses[14800],
33824
+ Multisend: CONTRACTS.Multisend.addresses[14800]
33825
+ },
33826
+ 1480: {
33827
+ Multicall3: CONTRACTS.Multicall3.addresses[1480],
33828
+ Multisend: CONTRACTS.Multisend.addresses[1480]
33829
+ }
33830
+ };
33831
+ var LEGACY_ADDRESSES = {
33832
+ 14800: Object.fromEntries(
33833
+ Object.entries(LEGACY_CONTRACTS).map(([name, info]) => [name, info.addresses[14800]]).filter(([, addr]) => addr)
33834
+ ),
33835
+ 1480: Object.fromEntries(
33836
+ Object.entries(LEGACY_CONTRACTS).map(([name, info]) => [name, info.addresses[1480]]).filter(([, addr]) => addr)
33837
+ )
33838
+ };
33839
+ var getContractAddress = (chainId, contract) => {
33840
+ const contractAddress = CONTRACT_ADDRESSES[chainId]?.[contract];
33841
+ if (!contractAddress) {
33842
+ throw new Error(
33843
+ `Contract address not found for ${contract} on chain ${chainId}`
33844
+ );
33845
+ }
33846
+ return contractAddress;
33847
+ };
33848
+
33655
33849
  // src/utils/grantFiles.ts
33656
- var import_viem = require("viem");
33850
+ var import_viem2 = require("viem");
33657
33851
  function createGrantFile(params) {
33658
33852
  const grantFile = {
33659
33853
  grantee: params.grantee,
@@ -33776,8 +33970,8 @@ function getGrantFileHash(grantFile) {
33776
33970
  sortedFile.expires = grantFile.expires;
33777
33971
  }
33778
33972
  const jsonString = JSON.stringify(sortedFile);
33779
- console.info(`Hash: ${(0, import_viem.keccak256)((0, import_viem.toHex)(jsonString))}`);
33780
- return (0, import_viem.keccak256)((0, import_viem.toHex)(jsonString));
33973
+ console.info(`Hash: ${(0, import_viem2.keccak256)((0, import_viem2.toHex)(jsonString))}`);
33974
+ return (0, import_viem2.keccak256)((0, import_viem2.toHex)(jsonString));
33781
33975
  } catch (error) {
33782
33976
  throw new SerializationError(
33783
33977
  `Failed to generate grant file hash: ${error instanceof Error ? error.message : "Unknown error"}`
@@ -34053,6 +34247,91 @@ function validateOperationAccess(grantFile, requestedOperation) {
34053
34247
  }
34054
34248
  }
34055
34249
 
34250
+ // src/utils/signatureCache.ts
34251
+ init_crypto_utils();
34252
+ var SignatureCache = class {
34253
+ static PREFIX = "vana_sig_";
34254
+ static DEFAULT_TTL_HOURS = 2;
34255
+ /**
34256
+ * Get a cached signature if it exists and hasn't expired
34257
+ */
34258
+ static get(cache, walletAddress, messageHash) {
34259
+ const key = this.getCacheKey(walletAddress, messageHash);
34260
+ try {
34261
+ const stored = cache.get(key);
34262
+ if (!stored) return null;
34263
+ const cached = JSON.parse(stored);
34264
+ if (Date.now() > cached.expires) {
34265
+ cache.delete(key);
34266
+ return null;
34267
+ }
34268
+ return cached.signature;
34269
+ } catch {
34270
+ try {
34271
+ cache.delete(key);
34272
+ } catch {
34273
+ }
34274
+ return null;
34275
+ }
34276
+ }
34277
+ /**
34278
+ * Store a signature in the cache
34279
+ */
34280
+ static set(cache, walletAddress, messageHash, signature, ttlHours = this.DEFAULT_TTL_HOURS) {
34281
+ const key = this.getCacheKey(walletAddress, messageHash);
34282
+ const cached = {
34283
+ signature,
34284
+ expires: Date.now() + ttlHours * 36e5
34285
+ // Convert hours to milliseconds
34286
+ };
34287
+ try {
34288
+ cache.set(key, JSON.stringify(cached));
34289
+ } catch {
34290
+ }
34291
+ }
34292
+ /**
34293
+ * Clear all cached signatures (useful for testing or explicit cleanup)
34294
+ */
34295
+ static clear(cache) {
34296
+ try {
34297
+ cache.clear();
34298
+ } catch {
34299
+ }
34300
+ }
34301
+ static getCacheKey(walletAddress, messageHash) {
34302
+ return `${this.PREFIX}${walletAddress.toLowerCase()}:${messageHash}`;
34303
+ }
34304
+ static hashMessage(message) {
34305
+ const jsonString = JSON.stringify(message, this.bigIntReplacer);
34306
+ const base64Hash = toBase64(jsonString);
34307
+ const cleaned = base64Hash.replace(/[^a-zA-Z0-9]/g, "");
34308
+ if (cleaned.length > 32) {
34309
+ return cleaned.substring(0, 16) + cleaned.substring(cleaned.length - 16);
34310
+ }
34311
+ return cleaned.substring(0, 32);
34312
+ }
34313
+ /**
34314
+ * Custom JSON replacer that converts BigInt values to strings for serialization
34315
+ * This ensures deterministic cache key generation for EIP-712 typed data
34316
+ */
34317
+ static bigIntReplacer(key, value) {
34318
+ if (typeof value === "bigint") {
34319
+ return `__BIGINT__${value.toString()}`;
34320
+ }
34321
+ return value;
34322
+ }
34323
+ };
34324
+ async function withSignatureCache(cache, walletAddress, typedData, signFn, ttlHours) {
34325
+ const messageHash = SignatureCache.hashMessage(typedData);
34326
+ const cached = SignatureCache.get(cache, walletAddress, messageHash);
34327
+ if (cached) {
34328
+ return cached;
34329
+ }
34330
+ const signature = await signFn();
34331
+ SignatureCache.set(cache, walletAddress, messageHash, signature, ttlHours);
34332
+ return signature;
34333
+ }
34334
+
34056
34335
  // src/controllers/permissions.ts
34057
34336
  var PermissionsController = class {
34058
34337
  constructor(context) {
@@ -34060,22 +34339,22 @@ var PermissionsController = class {
34060
34339
  }
34061
34340
  /**
34062
34341
  * Grants permission for an application to access user data with gasless transactions.
34342
+ *
34343
+ * This method provides a complete end-to-end permission grant flow that returns
34344
+ * the permission ID and other relevant data immediately after successful submission.
34345
+ * For advanced users who need more control over the transaction lifecycle, use
34346
+ * `submitPermissionGrant()` instead.
34063
34347
  *
34064
- * @remarks
34065
- * This method combines signature creation and gasless submission for a complete
34066
- * end-to-end permission grant flow. It creates the grant file, stores it on IPFS,
34067
- * generates an EIP-712 signature, and submits via relayer. The grant file contains
34068
- * detailed parameters while the blockchain stores only a reference to enable
34069
- * efficient permission queries.
34070
34348
  * @param params - The permission grant configuration object
34071
- * @returns A Promise that resolves to the transaction hash when successfully submitted
34349
+ * @returns Promise resolving to permission data from the PermissionAdded event
34072
34350
  * @throws {RelayerError} When gasless transaction submission fails
34073
34351
  * @throws {SignatureError} When user rejects the signature request
34074
34352
  * @throws {SerializationError} When grant data cannot be serialized
34075
- * @throws {BlockchainError} When permission grant preparation fails
34353
+ * @throws {BlockchainError} When permission grant fails or event parsing fails
34354
+ * @throws {NetworkError} When transaction confirmation times out
34076
34355
  * @example
34077
34356
  * ```typescript
34078
- * const txHash = await vana.permissions.grant({
34357
+ * const result = await vana.permissions.grant({
34079
34358
  * grantee: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36",
34080
34359
  * operation: "llm_inference",
34081
34360
  * parameters: {
@@ -34085,10 +34364,42 @@ var PermissionsController = class {
34085
34364
  * },
34086
34365
  * });
34087
34366
  *
34088
- * console.log(`Permission granted: ${txHash}`);
34367
+ * console.log(`Permission ${result.permissionId} granted to ${result.user}`);
34368
+ * console.log(`Transaction: ${result.transactionHash}`);
34369
+ *
34370
+ * // Can immediately use the permission ID for other operations
34371
+ * await vana.permissions.revoke({ permissionId: result.permissionId });
34089
34372
  * ```
34090
34373
  */
34091
34374
  async grant(params) {
34375
+ const txHash = await this.submitPermissionGrant(params);
34376
+ return parseTransactionResult(this.context, txHash, "grant");
34377
+ }
34378
+ /**
34379
+ * Submits a permission grant transaction and returns the transaction hash immediately.
34380
+ *
34381
+ * This is the lower-level method that provides maximum control over transaction timing.
34382
+ * Use this when you want to handle transaction confirmation and event parsing separately,
34383
+ * or when submitting multiple transactions in batch.
34384
+ *
34385
+ * @param params - The permission grant configuration object
34386
+ * @returns Promise that resolves to the transaction hash when successfully submitted
34387
+ * @throws {RelayerError} When gasless transaction submission fails
34388
+ * @throws {SignatureError} When user rejects the signature request
34389
+ * @throws {SerializationError} When grant data cannot be serialized
34390
+ * @throws {BlockchainError} When permission grant preparation fails
34391
+ * @example
34392
+ * ```typescript
34393
+ * // Submit transaction and handle confirmation later
34394
+ * const txHash = await vana.permissions.submitPermissionGrant(params);
34395
+ * console.log(`Transaction submitted: ${txHash}`);
34396
+ *
34397
+ * // Later, when you need the permission data:
34398
+ * const result = await parseTransactionResult(context, txHash, 'grant');
34399
+ * console.log(`Permission ID: ${result.permissionId}`);
34400
+ * ```
34401
+ */
34402
+ async submitPermissionGrant(params) {
34092
34403
  const { typedData, signature } = await this.createAndSign(params);
34093
34404
  return await this.submitSignedGrant(typedData, signature);
34094
34405
  }
@@ -34505,23 +34816,52 @@ var PermissionsController = class {
34505
34816
  }
34506
34817
  /**
34507
34818
  * Revokes a previously granted permission.
34819
+ *
34820
+ * This method provides complete revocation with automatic event parsing to confirm
34821
+ * the permission was successfully revoked. For advanced users who need more control,
34822
+ * use `submitPermissionRevoke()` instead.
34508
34823
  *
34509
34824
  * @param params - Parameters for revoking the permission
34510
- * @returns Promise resolving to transaction hash
34825
+ * @param params.permissionId - Permission identifier as bigint for contract compatibility.
34826
+ * Obtain from permission grants via `getUserPermissionGrantsOnChain()`.
34827
+ * @returns Promise resolving to revocation data from PermissionRevoked event
34828
+ * @throws {BlockchainError} When revocation fails or event parsing fails
34829
+ * @throws {UserRejectedRequestError} When user rejects the transaction
34830
+ * @throws {NetworkError} When transaction confirmation times out
34511
34831
  * @example
34512
34832
  * ```typescript
34513
- * // Revoke a permission by its ID
34514
- * const txHash = await vana.permissions.revoke({
34833
+ * // Revoke a permission and get confirmation
34834
+ * const result = await vana.permissions.revoke({
34515
34835
  * permissionId: 123n
34516
34836
  * });
34517
- * console.log('Permission revoked in transaction:', txHash);
34518
- *
34519
- * // Wait for confirmation if needed
34520
- * const receipt = await vana.core.waitForTransaction(txHash);
34521
- * console.log('Revocation confirmed in block:', receipt.blockNumber);
34837
+ * console.log(`Permission ${result.permissionId} revoked in transaction ${result.transactionHash}`);
34838
+ * console.log(`Revoked in block ${result.blockNumber}`);
34522
34839
  * ```
34523
34840
  */
34524
34841
  async revoke(params) {
34842
+ const txHash = await this.submitPermissionRevoke(params);
34843
+ return parseTransactionResult(this.context, txHash, "revoke");
34844
+ }
34845
+ /**
34846
+ * Submits a permission revocation transaction and returns the transaction hash immediately.
34847
+ *
34848
+ * This is the lower-level method that provides maximum control over transaction timing.
34849
+ * Use this when you want to handle transaction confirmation and event parsing separately.
34850
+ *
34851
+ * @param params - Parameters for revoking the permission
34852
+ * @returns Promise resolving to the transaction hash when successfully submitted
34853
+ * @throws {BlockchainError} When revocation transaction fails
34854
+ * @throws {UserRejectedRequestError} When user rejects the transaction
34855
+ * @example
34856
+ * ```typescript
34857
+ * // Submit revocation and handle confirmation later
34858
+ * const txHash = await vana.permissions.submitPermissionRevoke({
34859
+ * permissionId: 123n
34860
+ * });
34861
+ * console.log(`Revocation submitted: ${txHash}`);
34862
+ * ```
34863
+ */
34864
+ async submitPermissionRevoke(params) {
34525
34865
  try {
34526
34866
  if (!this.context.walletClient.chain?.id) {
34527
34867
  throw new BlockchainError("Chain ID not available");
@@ -34687,17 +35027,24 @@ var PermissionsController = class {
34687
35027
  };
34688
35028
  }
34689
35029
  /**
34690
- * Signs typed data using the wallet client.
35030
+ * Signs typed data using the wallet client with signature caching.
34691
35031
  *
34692
35032
  * @param typedData - The EIP-712 typed data structure to sign
34693
35033
  * @returns Promise resolving to the cryptographic signature
34694
35034
  */
34695
35035
  async signTypedData(typedData) {
34696
35036
  try {
34697
- const signature = await this.context.walletClient.signTypedData(
34698
- typedData
35037
+ const walletAddress = this.context.walletClient.account?.address || await this.getUserAddress();
35038
+ return await withSignatureCache(
35039
+ this.context.platform.cache,
35040
+ walletAddress,
35041
+ typedData,
35042
+ async () => {
35043
+ return await this.context.walletClient.signTypedData(
35044
+ typedData
35045
+ );
35046
+ }
34699
35047
  );
34700
- return signature;
34701
35048
  } catch (error) {
34702
35049
  if (error instanceof Error && error.message.includes("rejected")) {
34703
35050
  throw new UserRejectedRequestError();
@@ -35527,19 +35874,26 @@ var PermissionsController = class {
35527
35874
  };
35528
35875
 
35529
35876
  // src/controllers/data.ts
35530
- var import_viem2 = require("viem");
35877
+ var import_viem3 = require("viem");
35531
35878
 
35532
35879
  // src/utils/encryption.ts
35533
35880
  var DEFAULT_ENCRYPTION_SEED = "Please sign to retrieve your encryption key";
35534
- async function generateEncryptionKey(wallet, seed = DEFAULT_ENCRYPTION_SEED) {
35881
+ async function generateEncryptionKey(wallet, platformAdapter, seed = DEFAULT_ENCRYPTION_SEED) {
35535
35882
  if (!wallet.account) {
35536
35883
  throw new Error("Wallet account is required for encryption key generation");
35537
35884
  }
35538
- const signature = await wallet.signMessage({
35539
- account: wallet.account,
35540
- message: seed
35541
- });
35542
- return signature;
35885
+ const messageData = { message: seed };
35886
+ return await withSignatureCache(
35887
+ platformAdapter.cache,
35888
+ wallet.account.address,
35889
+ messageData,
35890
+ async () => {
35891
+ return await wallet.signMessage({
35892
+ account: wallet.account,
35893
+ message: seed
35894
+ });
35895
+ }
35896
+ );
35543
35897
  }
35544
35898
  async function encryptWithWalletPublicKey(data, publicKey, platformAdapter) {
35545
35899
  try {
@@ -35648,7 +36002,8 @@ var DataController = class {
35648
36002
  schemaId,
35649
36003
  permissions = [],
35650
36004
  encrypt: encrypt3 = true,
35651
- providerName
36005
+ providerName,
36006
+ owner
35652
36007
  } = params;
35653
36008
  try {
35654
36009
  let blob;
@@ -35703,6 +36058,7 @@ var DataController = class {
35703
36058
  if (encrypt3) {
35704
36059
  const encryptionKey = await generateEncryptionKey(
35705
36060
  this.context.walletClient,
36061
+ this.context.platform,
35706
36062
  DEFAULT_ENCRYPTION_SEED
35707
36063
  );
35708
36064
  finalBlob = await encryptBlobWithSignedKey(
@@ -35726,28 +36082,23 @@ var DataController = class {
35726
36082
  filename,
35727
36083
  providerName
35728
36084
  );
35729
- const userAddress = await this.getUserAddress();
36085
+ const userAddress = owner || await this.getUserAddress();
35730
36086
  let encryptedPermissions = [];
35731
36087
  if (permissions.length > 0 && encrypt3) {
35732
36088
  const userEncryptionKey = await generateEncryptionKey(
35733
36089
  this.context.walletClient,
36090
+ this.context.platform,
35734
36091
  DEFAULT_ENCRYPTION_SEED
35735
36092
  );
35736
36093
  encryptedPermissions = await Promise.all(
35737
36094
  permissions.map(async (permission) => {
35738
- const publicKey = permission.publicKey;
35739
- if (!publicKey) {
35740
- throw new Error(
35741
- `Public key required for permission to ${permission.grantee} when encryption is enabled`
35742
- );
35743
- }
35744
36095
  const encryptedKey = await encryptWithWalletPublicKey(
35745
36096
  userEncryptionKey,
35746
- publicKey,
36097
+ permission.publicKey,
35747
36098
  this.context.platform
35748
36099
  );
35749
36100
  return {
35750
- account: permission.grantee,
36101
+ account: permission.account,
35751
36102
  key: encryptedKey
35752
36103
  };
35753
36104
  })
@@ -35760,7 +36111,8 @@ var DataController = class {
35760
36111
  url: uploadResult.url,
35761
36112
  userAddress,
35762
36113
  permissions: encryptedPermissions,
35763
- schemaId: schemaId || 0
36114
+ schemaId: schemaId || 0,
36115
+ ownerAddress: owner
35764
36116
  }
35765
36117
  );
35766
36118
  } else if (this.context.relayerCallbacks?.submitFileAddition) {
@@ -35850,6 +36202,7 @@ var DataController = class {
35850
36202
  try {
35851
36203
  const encryptionKey = await generateEncryptionKey(
35852
36204
  this.context.walletClient,
36205
+ this.context.platform,
35853
36206
  encryptionSeed || DEFAULT_ENCRYPTION_SEED
35854
36207
  );
35855
36208
  let encryptedBlob;
@@ -36426,7 +36779,7 @@ var DataController = class {
36426
36779
  }
36427
36780
  const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
36428
36781
  const dataRegistryAbi = getAbi("DataRegistry");
36429
- const dataRegistry = (0, import_viem2.getContract)({
36782
+ const dataRegistry = (0, import_viem3.getContract)({
36430
36783
  address: dataRegistryAddress,
36431
36784
  abi: dataRegistryAbi,
36432
36785
  client: this.context.walletClient
@@ -36474,7 +36827,7 @@ var DataController = class {
36474
36827
  }
36475
36828
  const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
36476
36829
  const dataRegistryAbi = getAbi("DataRegistry");
36477
- const dataRegistry = (0, import_viem2.getContract)({
36830
+ const dataRegistry = (0, import_viem3.getContract)({
36478
36831
  address: dataRegistryAddress,
36479
36832
  abi: dataRegistryAbi,
36480
36833
  client: this.context.walletClient
@@ -36573,7 +36926,7 @@ var DataController = class {
36573
36926
  let fileId = 0;
36574
36927
  for (const log of receipt.logs) {
36575
36928
  try {
36576
- const decoded = (0, import_viem2.decodeEventLog)({
36929
+ const decoded = (0, import_viem3.decodeEventLog)({
36577
36930
  abi: dataRegistryAbi,
36578
36931
  data: log.data,
36579
36932
  topics: log.topics
@@ -36655,7 +37008,7 @@ var DataController = class {
36655
37008
  let fileId = 0;
36656
37009
  for (const log of receipt.logs) {
36657
37010
  try {
36658
- const decoded = (0, import_viem2.decodeEventLog)({
37011
+ const decoded = (0, import_viem3.decodeEventLog)({
36659
37012
  abi: dataRegistryAbi,
36660
37013
  data: log.data,
36661
37014
  topics: log.topics
@@ -36718,7 +37071,7 @@ var DataController = class {
36718
37071
  let fileId = 0;
36719
37072
  for (const log of receipt.logs) {
36720
37073
  try {
36721
- const decoded = (0, import_viem2.decodeEventLog)({
37074
+ const decoded = (0, import_viem3.decodeEventLog)({
36722
37075
  abi: dataRegistryAbi,
36723
37076
  data: log.data,
36724
37077
  topics: log.topics
@@ -36792,7 +37145,7 @@ var DataController = class {
36792
37145
  let fileId = 0;
36793
37146
  for (const log of receipt.logs) {
36794
37147
  try {
36795
- const decoded = (0, import_viem2.decodeEventLog)({
37148
+ const decoded = (0, import_viem3.decodeEventLog)({
36796
37149
  abi: dataRegistryAbi,
36797
37150
  data: log.data,
36798
37151
  topics: log.topics
@@ -36852,7 +37205,7 @@ var DataController = class {
36852
37205
  let fileId = 0;
36853
37206
  for (const log of receipt.logs) {
36854
37207
  try {
36855
- const decoded = (0, import_viem2.decodeEventLog)({
37208
+ const decoded = (0, import_viem3.decodeEventLog)({
36856
37209
  abi: dataRegistryAbi,
36857
37210
  data: log.data,
36858
37211
  topics: log.topics
@@ -36911,7 +37264,7 @@ var DataController = class {
36911
37264
  let schemaId = 0;
36912
37265
  for (const log of receipt.logs) {
36913
37266
  try {
36914
- const decoded = (0, import_viem2.decodeEventLog)({
37267
+ const decoded = (0, import_viem3.decodeEventLog)({
36915
37268
  abi: dataRefinerRegistryAbi,
36916
37269
  data: log.data,
36917
37270
  topics: log.topics
@@ -36953,7 +37306,7 @@ var DataController = class {
36953
37306
  "DataRefinerRegistry"
36954
37307
  );
36955
37308
  const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
36956
- const dataRefinerRegistry = (0, import_viem2.getContract)({
37309
+ const dataRefinerRegistry = (0, import_viem3.getContract)({
36957
37310
  address: dataRefinerRegistryAddress,
36958
37311
  abi: dataRefinerRegistryAbi,
36959
37312
  client: this.context.walletClient
@@ -36998,7 +37351,7 @@ var DataController = class {
36998
37351
  "DataRefinerRegistry"
36999
37352
  );
37000
37353
  const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
37001
- const dataRefinerRegistry = (0, import_viem2.getContract)({
37354
+ const dataRefinerRegistry = (0, import_viem3.getContract)({
37002
37355
  address: dataRefinerRegistryAddress,
37003
37356
  abi: dataRefinerRegistryAbi,
37004
37357
  client: this.context.walletClient
@@ -37049,7 +37402,7 @@ var DataController = class {
37049
37402
  let refinerId = 0;
37050
37403
  for (const log of receipt.logs) {
37051
37404
  try {
37052
- const decoded = (0, import_viem2.decodeEventLog)({
37405
+ const decoded = (0, import_viem3.decodeEventLog)({
37053
37406
  abi: dataRefinerRegistryAbi,
37054
37407
  data: log.data,
37055
37408
  topics: log.topics
@@ -37090,7 +37443,7 @@ var DataController = class {
37090
37443
  "DataRefinerRegistry"
37091
37444
  );
37092
37445
  const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
37093
- const dataRefinerRegistry = (0, import_viem2.getContract)({
37446
+ const dataRefinerRegistry = (0, import_viem3.getContract)({
37094
37447
  address: dataRefinerRegistryAddress,
37095
37448
  abi: dataRefinerRegistryAbi,
37096
37449
  client: this.context.walletClient
@@ -37133,7 +37486,7 @@ var DataController = class {
37133
37486
  "DataRefinerRegistry"
37134
37487
  );
37135
37488
  const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
37136
- const dataRefinerRegistry = (0, import_viem2.getContract)({
37489
+ const dataRefinerRegistry = (0, import_viem3.getContract)({
37137
37490
  address: dataRefinerRegistryAddress,
37138
37491
  abi: dataRefinerRegistryAbi,
37139
37492
  client: this.context.walletClient
@@ -37163,7 +37516,7 @@ var DataController = class {
37163
37516
  "DataRefinerRegistry"
37164
37517
  );
37165
37518
  const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
37166
- const dataRefinerRegistry = (0, import_viem2.getContract)({
37519
+ const dataRefinerRegistry = (0, import_viem3.getContract)({
37167
37520
  address: dataRefinerRegistryAddress,
37168
37521
  abi: dataRefinerRegistryAbi,
37169
37522
  client: this.context.walletClient
@@ -37233,6 +37586,7 @@ var DataController = class {
37233
37586
  try {
37234
37587
  const userEncryptionKey = await generateEncryptionKey(
37235
37588
  this.context.walletClient,
37589
+ this.context.platform,
37236
37590
  DEFAULT_ENCRYPTION_SEED
37237
37591
  );
37238
37592
  const encryptedData = await encryptBlobWithSignedKey(
@@ -37298,16 +37652,47 @@ var DataController = class {
37298
37652
  * 1. Gets the user's encryption key
37299
37653
  * 2. Encrypts the user's encryption key with the provided public key
37300
37654
  * 3. Adds the permission to the file
37655
+ * 4. Returns the permission data from the blockchain event
37656
+ *
37657
+ * For advanced users who need more control over transaction timing,
37658
+ * use `submitFilePermission()` instead.
37301
37659
  *
37302
37660
  * @param fileId - The ID of the file to add permissions for
37303
37661
  * @param account - The address of the account to grant permission to
37304
37662
  * @param publicKey - The public key to encrypt the user's encryption key with
37305
- * @returns Promise resolving to the transaction hash
37663
+ * @returns Promise resolving to permission data from PermissionGranted event
37664
+ * @example
37665
+ * ```typescript
37666
+ * const result = await vana.data.addPermissionToFile(fileId, account, publicKey);
37667
+ * console.log(`Permission granted to ${result.account} for file ${result.fileId}`);
37668
+ * console.log(`Transaction: ${result.transactionHash}`);
37669
+ * ```
37306
37670
  */
37307
37671
  async addPermissionToFile(fileId, account, publicKey) {
37672
+ const txHash = await this.submitFilePermission(fileId, account, publicKey);
37673
+ return parseTransactionResult(this.context, txHash, "addFilePermission");
37674
+ }
37675
+ /**
37676
+ * Submits a file permission transaction and returns the transaction hash immediately.
37677
+ *
37678
+ * This is the lower-level method that provides maximum control over transaction timing.
37679
+ * Use this when you want to handle transaction confirmation and event parsing separately.
37680
+ *
37681
+ * @param fileId - The ID of the file to add permissions for
37682
+ * @param account - The address of the account to grant permission to
37683
+ * @param publicKey - The public key to encrypt the user's encryption key with
37684
+ * @returns Promise resolving to the transaction hash
37685
+ * @example
37686
+ * ```typescript
37687
+ * const txHash = await vana.data.submitFilePermission(fileId, account, publicKey);
37688
+ * console.log(`Transaction submitted: ${txHash}`);
37689
+ * ```
37690
+ */
37691
+ async submitFilePermission(fileId, account, publicKey) {
37308
37692
  try {
37309
37693
  const userEncryptionKey = await generateEncryptionKey(
37310
37694
  this.context.walletClient,
37695
+ this.context.platform,
37311
37696
  DEFAULT_ENCRYPTION_SEED
37312
37697
  );
37313
37698
  const encryptedKey = await encryptWithWalletPublicKey(
@@ -37352,7 +37737,7 @@ var DataController = class {
37352
37737
  }
37353
37738
  const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
37354
37739
  const dataRegistryAbi = getAbi("DataRegistry");
37355
- const dataRegistry = (0, import_viem2.getContract)({
37740
+ const dataRegistry = (0, import_viem3.getContract)({
37356
37741
  address: dataRegistryAddress,
37357
37742
  abi: dataRegistryAbi,
37358
37743
  client: this.context.walletClient
@@ -37696,7 +38081,7 @@ var DataController = class {
37696
38081
  };
37697
38082
 
37698
38083
  // src/controllers/schemas.ts
37699
- var import_viem3 = require("viem");
38084
+ var import_viem4 = require("viem");
37700
38085
  var SchemaController = class {
37701
38086
  constructor(context) {
37702
38087
  this.context = context;
@@ -37808,7 +38193,7 @@ var SchemaController = class {
37808
38193
  let schemaId = 0;
37809
38194
  for (const log of receipt.logs) {
37810
38195
  try {
37811
- const decoded = (0, import_viem3.decodeEventLog)({
38196
+ const decoded = (0, import_viem4.decodeEventLog)({
37812
38197
  abi: dataRefinerRegistryAbi,
37813
38198
  data: log.data,
37814
38199
  topics: log.topics
@@ -37857,7 +38242,7 @@ var SchemaController = class {
37857
38242
  "DataRefinerRegistry"
37858
38243
  );
37859
38244
  const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
37860
- const dataRefinerRegistry = (0, import_viem3.getContract)({
38245
+ const dataRefinerRegistry = (0, import_viem4.getContract)({
37861
38246
  address: dataRefinerRegistryAddress,
37862
38247
  abi: dataRefinerRegistryAbi,
37863
38248
  client: this.context.publicClient
@@ -37906,7 +38291,7 @@ var SchemaController = class {
37906
38291
  "DataRefinerRegistry"
37907
38292
  );
37908
38293
  const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
37909
- const dataRefinerRegistry = (0, import_viem3.getContract)({
38294
+ const dataRefinerRegistry = (0, import_viem4.getContract)({
37910
38295
  address: dataRefinerRegistryAddress,
37911
38296
  abi: dataRefinerRegistryAbi,
37912
38297
  client: this.context.publicClient
@@ -38021,6 +38406,39 @@ var ServerController = class {
38021
38406
  this.context = context;
38022
38407
  }
38023
38408
  PERSONAL_SERVER_BASE_URL = process.env.NEXT_PUBLIC_PERSONAL_SERVER_BASE_URL;
38409
+ /**
38410
+ * Retrieves the cryptographic identity of a personal server.
38411
+ *
38412
+ * @remarks
38413
+ * This method fetches the public key and metadata for a personal server,
38414
+ * which is required for encrypting data before sharing with the server.
38415
+ * The identity includes the server's public key, address, and operational
38416
+ * details needed for secure communication. This information is cached
38417
+ * by identity servers to enable offline key retrieval.
38418
+ *
38419
+ * @param request - Parameters containing the user address
38420
+ * @param request.userAddress - The wallet address associated with the personal server
38421
+ * @returns Promise resolving to the server's identity information
38422
+ * @throws {NetworkError} When the identity service is unavailable or returns invalid data
38423
+ * @throws {PersonalServerError} When server identity cannot be retrieved
38424
+ * @example
38425
+ * ```typescript
38426
+ * // Get server identity for data encryption
38427
+ * const identity = await vana.server.getIdentity({
38428
+ * userAddress: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36"
38429
+ * });
38430
+ *
38431
+ * console.log(`Server: ${identity.name}`);
38432
+ * console.log(`Address: ${identity.address}`);
38433
+ * console.log(`Public Key: ${identity.public_key}`);
38434
+ *
38435
+ * // Use the public key for encrypting data to share with this server
38436
+ * const encryptedData = await encryptWithWalletPublicKey(
38437
+ * userData,
38438
+ * identity.public_key
38439
+ * );
38440
+ * ```
38441
+ */
38024
38442
  async getIdentity(request) {
38025
38443
  try {
38026
38444
  const response = await fetch(
@@ -38063,10 +38481,13 @@ var ServerController = class {
38063
38481
  * This method submits a computation request to the personal server API.
38064
38482
  * The response includes the operation ID.
38065
38483
  * @param params - The request parameters object
38066
- * @param params.permissionId - The permission ID authorizing this operation
38484
+ * @param params.permissionId - The permission ID authorizing this operation.
38485
+ * Obtain from granted permissions via `vana.permissions.getUserPermissionGrantsOnChain()`.
38067
38486
  * @returns A Promise that resolves to an operation response with status and control URLs
38068
- * @throws {PersonalServerError} When server request fails or parameters are invalid
38069
- * @throws {NetworkError} When personal server API communication fails
38487
+ * @throws {PersonalServerError} When server request fails or parameters are invalid.
38488
+ * Verify permissionId exists and is active for the target server.
38489
+ * @throws {NetworkError} When personal server API communication fails.
38490
+ * Check server URL configuration and network connectivity.
38070
38491
  * @example
38071
38492
  * ```typescript
38072
38493
  * const response = await vana.server.createOperation({
@@ -38168,6 +38589,50 @@ var ServerController = class {
38168
38589
  );
38169
38590
  }
38170
38591
  }
38592
+ /**
38593
+ * Cancels a running operation on the personal server.
38594
+ *
38595
+ * @remarks
38596
+ * This method attempts to cancel an operation that is currently processing
38597
+ * on the personal server. The operation must be in a cancellable state
38598
+ * (typically `starting` or `processing`). Not all operations support
38599
+ * cancellation, and cancellation may not be immediate. The server will
38600
+ * attempt to stop the operation and update its status to `canceled`.
38601
+ *
38602
+ * **Cancellation Behavior:**
38603
+ * - Operations in `succeeded` or `failed` states cannot be canceled
38604
+ * - Some long-running operations may take time to respond to cancellation
38605
+ * - Always verify cancellation by polling the operation status afterward
38606
+ *
38607
+ * @param operationId - The unique identifier of the operation to cancel,
38608
+ * obtained from `createOperation()` response
38609
+ * @returns Promise that resolves when the cancellation request is accepted
38610
+ * @throws {PersonalServerError} When the operation cannot be canceled or doesn't exist.
38611
+ * Check operation status - it may already be completed or failed.
38612
+ * @throws {NetworkError} When unable to reach the personal server API.
38613
+ * Verify server URL and network connectivity.
38614
+ * @example
38615
+ * ```typescript
38616
+ * // Start a long-running operation
38617
+ * const operation = await vana.server.createOperation({
38618
+ * permissionId: 123
38619
+ * });
38620
+ *
38621
+ * // Cancel if needed
38622
+ * try {
38623
+ * await vana.server.cancelOperation(operation.id);
38624
+ * console.log("Cancellation requested");
38625
+ *
38626
+ * // Verify cancellation
38627
+ * const status = await vana.server.getOperation(operation.id);
38628
+ * if (status.status === "canceled") {
38629
+ * console.log("Operation successfully canceled");
38630
+ * }
38631
+ * } catch (error) {
38632
+ * console.error("Failed to cancel:", error);
38633
+ * }
38634
+ * ```
38635
+ */
38171
38636
  async cancelOperation(operationId) {
38172
38637
  try {
38173
38638
  const response = await fetch(
@@ -38276,14 +38741,14 @@ var ServerController = class {
38276
38741
  };
38277
38742
 
38278
38743
  // src/contracts/contractController.ts
38279
- var import_viem6 = require("viem");
38744
+ var import_viem7 = require("viem");
38280
38745
 
38281
38746
  // src/core/client.ts
38282
- var import_viem5 = require("viem");
38747
+ var import_viem6 = require("viem");
38283
38748
 
38284
38749
  // src/config/chains.ts
38285
- var import_viem4 = require("viem");
38286
- var mokshaTestnet = (0, import_viem4.defineChain)({
38750
+ var import_viem5 = require("viem");
38751
+ var mokshaTestnet = (0, import_viem5.defineChain)({
38287
38752
  id: 14800,
38288
38753
  caipNetworkId: "eip155:14800",
38289
38754
  chainNamespace: "eip155",
@@ -38311,7 +38776,7 @@ var mokshaTestnet = (0, import_viem4.defineChain)({
38311
38776
  contracts: {},
38312
38777
  abis: {}
38313
38778
  });
38314
- var vanaMainnet = (0, import_viem4.defineChain)({
38779
+ var vanaMainnet = (0, import_viem5.defineChain)({
38315
38780
  id: 1480,
38316
38781
  caipNetworkId: "eip155:1480",
38317
38782
  chainNamespace: "eip155",
@@ -38353,9 +38818,9 @@ var createClient = (chainId = mokshaTestnet.id) => {
38353
38818
  if (!chain) {
38354
38819
  throw new Error(`Chain ${chainId} not found`);
38355
38820
  }
38356
- _client = (0, import_viem5.createPublicClient)({
38821
+ _client = (0, import_viem6.createPublicClient)({
38357
38822
  chain,
38358
- transport: (0, import_viem5.http)()
38823
+ transport: (0, import_viem6.http)()
38359
38824
  });
38360
38825
  }
38361
38826
  return _client;
@@ -38372,7 +38837,7 @@ function getContractController(contract, client = createClient()) {
38372
38837
  const cacheKey = createCacheKey(contract, chainId);
38373
38838
  let controller = contractCache.get(cacheKey);
38374
38839
  if (!controller) {
38375
- controller = (0, import_viem6.getContract)({
38840
+ controller = (0, import_viem7.getContract)({
38376
38841
  address: getContractAddress(chainId, contract),
38377
38842
  abi: getAbi(contract),
38378
38843
  client
@@ -38465,7 +38930,8 @@ var ProtocolController = class {
38465
38930
  * are actually deployed on the current network.
38466
38931
  * @param contractName - The name of the Vana contract to retrieve (use const assertion for full typing)
38467
38932
  * @returns An object containing the contract's address and fully typed ABI
38468
- * @throws {ContractNotFoundError} When the contract is not deployed on the current chain
38933
+ * @throws {ContractNotFoundError} When the contract is not deployed on the current chain.
38934
+ * Verify contract name spelling and check current network with `getChainId()`.
38469
38935
  * @example
38470
38936
  * ```typescript
38471
38937
  * // Get contract info with full type inference
@@ -39086,6 +39552,7 @@ var GoogleDriveStorage = class {
39086
39552
  };
39087
39553
 
39088
39554
  // src/storage/providers/ipfs.ts
39555
+ init_crypto_utils();
39089
39556
  var IpfsStorage = class _IpfsStorage {
39090
39557
  constructor(config) {
39091
39558
  this.config = config;
@@ -39125,7 +39592,7 @@ var IpfsStorage = class _IpfsStorage {
39125
39592
  * ```
39126
39593
  */
39127
39594
  static forInfura(credentials) {
39128
- const auth = btoa(`${credentials.projectId}:${credentials.projectSecret}`);
39595
+ const auth = toBase64(`${credentials.projectId}:${credentials.projectSecret}`);
39129
39596
  return new _IpfsStorage({
39130
39597
  apiEndpoint: "https://ipfs.infura.io:5001/api/v0/add",
39131
39598
  gatewayUrl: "https://ipfs.infura.io/ipfs",
@@ -39649,175 +40116,151 @@ var PinataStorage = class {
39649
40116
  }
39650
40117
  };
39651
40118
 
39652
- // src/storage/providers/server-proxy.ts
39653
- var ServerProxyStorage = class {
39654
- constructor(config) {
39655
- this.config = config;
39656
- if (!config.uploadUrl) {
39657
- throw new StorageError(
39658
- "Upload URL is required",
39659
- "MISSING_UPLOAD_URL",
39660
- "server-proxy"
39661
- );
39662
- }
39663
- if (!config.downloadUrl) {
39664
- throw new StorageError(
39665
- "Download URL is required",
39666
- "MISSING_DOWNLOAD_URL",
39667
- "server-proxy"
40119
+ // src/storage/providers/callback-storage.ts
40120
+ var CallbackStorage = class {
40121
+ constructor(callbacks) {
40122
+ this.callbacks = callbacks;
40123
+ if (!callbacks.upload || !callbacks.download) {
40124
+ throw new Error(
40125
+ "CallbackStorage requires both upload and download callbacks"
39668
40126
  );
39669
40127
  }
39670
40128
  }
39671
40129
  /**
39672
- * Uploads a file through your server endpoint
39673
- *
39674
- * @remarks
39675
- * This method sends the file to your configured upload endpoint via FormData.
39676
- * Your server is responsible for handling the actual storage implementation
39677
- * and must return a JSON response with `success: true` and an `identifier` field.
39678
- *
39679
- * @param file - The file to upload
39680
- * @param filename - Optional custom filename
39681
- * @returns Promise that resolves to the server-provided identifier
39682
- * @throws {StorageError} When the upload fails or server returns an error
40130
+ * Upload a file using the provided callback
39683
40131
  *
39684
- * @example
39685
- * ```typescript
39686
- * const identifier = await serverStorage.upload(fileBlob, { name: "report.pdf" });
39687
- * console.log("File uploaded with identifier:", identifier);
39688
- * ```
40132
+ * @param file - The blob to upload
40133
+ * @param filename - Optional filename for the upload
40134
+ * @returns The upload result with URL and metadata
39689
40135
  */
39690
40136
  async upload(file, filename) {
39691
40137
  try {
39692
- const formData = new FormData();
39693
- formData.append("file", file);
39694
- if (filename) {
39695
- formData.append("name", filename);
39696
- }
39697
- const response = await fetch(this.config.uploadUrl, {
39698
- method: "POST",
39699
- body: formData
39700
- });
39701
- if (!response.ok) {
39702
- const _errorText = await response.text();
40138
+ const result = await this.callbacks.upload(file, filename);
40139
+ if (!result.url || result.url.trim() === "") {
39703
40140
  throw new StorageError(
39704
- `Server upload failed: ${response.status} ${response.statusText}`,
39705
- "UPLOAD_FAILED",
39706
- "server-proxy"
40141
+ "Upload callback returned invalid result: missing or empty url",
40142
+ "INVALID_UPLOAD_RESULT",
40143
+ "callback-storage"
39707
40144
  );
39708
40145
  }
39709
- const result = await response.json();
39710
- if (!result.success) {
39711
- throw new StorageError(
39712
- `Upload failed: ${result.error || "Unknown server error"}`,
39713
- "UPLOAD_FAILED",
39714
- "server-proxy"
39715
- );
39716
- }
39717
- if (!result.identifier) {
39718
- throw new StorageError(
39719
- "Server upload succeeded but no identifier returned",
39720
- "NO_IDENTIFIER_RETURNED",
39721
- "server-proxy"
39722
- );
39723
- }
39724
- return {
39725
- url: result.url || result.identifier,
39726
- size: file.size,
39727
- contentType: file.type || "application/octet-stream"
39728
- };
40146
+ return result;
39729
40147
  } catch (error) {
39730
40148
  if (error instanceof StorageError) {
39731
40149
  throw error;
39732
40150
  }
39733
40151
  throw new StorageError(
39734
- `Server proxy upload error: ${error instanceof Error ? error.message : "Unknown error"}`,
40152
+ `Upload failed: ${error instanceof Error ? error.message : String(error)}`,
39735
40153
  "UPLOAD_ERROR",
39736
- "server-proxy"
40154
+ "callback-storage",
40155
+ { cause: error instanceof Error ? error : void 0 }
39737
40156
  );
39738
40157
  }
39739
40158
  }
39740
40159
  /**
39741
- * Downloads a file through your server endpoint
40160
+ * Download a file using the provided callback
39742
40161
  *
39743
- * @remarks
39744
- * This method sends the identifier to your configured download endpoint via POST request.
39745
- * Your server is responsible for retrieving the file from your storage backend
39746
- * and returning the file content as a blob response.
39747
- *
39748
- * @param url - The server-provided URL or identifier from upload
39749
- * @returns Promise that resolves to the downloaded file content
39750
- * @throws {StorageError} When the download fails or file is not found
39751
- *
39752
- * @example
39753
- * ```typescript
39754
- * const fileBlob = await serverStorage.download("file-123");
39755
- * const url = URL.createObjectURL(fileBlob);
39756
- * ```
40162
+ * @param url - The URL or identifier to download
40163
+ * @returns The downloaded blob
39757
40164
  */
39758
40165
  async download(url) {
39759
40166
  try {
39760
- const identifier = this.extractIdentifierFromUrl(url);
39761
- const response = await fetch(this.config.downloadUrl, {
39762
- method: "POST",
39763
- headers: {
39764
- "Content-Type": "application/json"
39765
- },
39766
- body: JSON.stringify({ identifier })
39767
- });
39768
- if (!response.ok) {
39769
- const _errorText = await response.text();
40167
+ const identifier = this.callbacks.extractIdentifier ? this.callbacks.extractIdentifier(url) : url;
40168
+ const blob = await this.callbacks.download(identifier);
40169
+ if (!(blob instanceof Blob)) {
39770
40170
  throw new StorageError(
39771
- `Server download failed: ${response.status} ${response.statusText}`,
39772
- "DOWNLOAD_FAILED",
39773
- "server-proxy"
40171
+ "Download callback returned invalid result: expected Blob",
40172
+ "INVALID_DOWNLOAD_RESULT",
40173
+ "callback-storage"
39774
40174
  );
39775
40175
  }
39776
- return await response.blob();
40176
+ return blob;
39777
40177
  } catch (error) {
39778
40178
  if (error instanceof StorageError) {
39779
40179
  throw error;
39780
40180
  }
39781
40181
  throw new StorageError(
39782
- `Server proxy download error: ${error instanceof Error ? error.message : "Unknown error"}`,
40182
+ `Download failed: ${error instanceof Error ? error.message : String(error)}`,
39783
40183
  "DOWNLOAD_ERROR",
39784
- "server-proxy"
40184
+ "callback-storage",
40185
+ { cause: error instanceof Error ? error : void 0 }
39785
40186
  );
39786
40187
  }
39787
40188
  }
39788
- async list(_options) {
39789
- throw new StorageError(
39790
- "List operation is not supported by server proxy storage",
39791
- "LIST_NOT_SUPPORTED",
39792
- "server-proxy"
39793
- );
39794
- }
39795
- async delete(_url) {
39796
- throw new StorageError(
39797
- "Delete operation is not supported by server proxy storage",
39798
- "DELETE_NOT_SUPPORTED",
39799
- "server-proxy"
39800
- );
40189
+ /**
40190
+ * List files using the provided callback (if available)
40191
+ *
40192
+ * @param options - Optional list options including filters and pagination
40193
+ * @returns Array of storage files
40194
+ */
40195
+ async list(options) {
40196
+ if (!this.callbacks.list) {
40197
+ throw new StorageError(
40198
+ "List operation not supported - no list callback provided",
40199
+ "NOT_SUPPORTED",
40200
+ "callback-storage"
40201
+ );
40202
+ }
40203
+ try {
40204
+ const result = await this.callbacks.list(options?.namePattern, options);
40205
+ return result.items.map((item, index) => ({
40206
+ id: item.identifier,
40207
+ name: item.identifier.split("/").pop() || `file-${index}`,
40208
+ url: item.identifier,
40209
+ size: item.size || 0,
40210
+ contentType: "application/octet-stream",
40211
+ createdAt: item.lastModified || /* @__PURE__ */ new Date(),
40212
+ metadata: item.metadata
40213
+ }));
40214
+ } catch (error) {
40215
+ throw new StorageError(
40216
+ `List failed: ${error instanceof Error ? error.message : String(error)}`,
40217
+ "LIST_ERROR",
40218
+ "callback-storage",
40219
+ { cause: error instanceof Error ? error : void 0 }
40220
+ );
40221
+ }
39801
40222
  }
39802
40223
  /**
39803
- * Extract identifier from URL or return as-is
40224
+ * Delete a file using the provided callback (if available)
39804
40225
  *
39805
- * @param url - URL or identifier string
39806
- * @returns identifier string
40226
+ * @param url - The URL or identifier to delete
40227
+ * @returns True if deletion succeeded
39807
40228
  */
39808
- extractIdentifierFromUrl(url) {
39809
- return url;
40229
+ async delete(url) {
40230
+ if (!this.callbacks.delete) {
40231
+ throw new StorageError(
40232
+ "Delete operation not supported - no delete callback provided",
40233
+ "NOT_SUPPORTED",
40234
+ "callback-storage"
40235
+ );
40236
+ }
40237
+ try {
40238
+ const identifier = this.callbacks.extractIdentifier ? this.callbacks.extractIdentifier(url) : url;
40239
+ return await this.callbacks.delete(identifier);
40240
+ } catch (error) {
40241
+ throw new StorageError(
40242
+ `Delete failed: ${error instanceof Error ? error.message : String(error)}`,
40243
+ "DELETE_ERROR",
40244
+ "callback-storage",
40245
+ { cause: error instanceof Error ? error : void 0 }
40246
+ );
40247
+ }
39810
40248
  }
40249
+ /**
40250
+ * Get provider configuration
40251
+ *
40252
+ * @returns Provider configuration metadata
40253
+ */
39811
40254
  getConfig() {
39812
40255
  return {
39813
- name: "Server Proxy",
39814
- type: "server-proxy",
40256
+ name: "callback-storage",
40257
+ type: "callback",
39815
40258
  requiresAuth: false,
39816
40259
  features: {
39817
40260
  upload: true,
39818
40261
  download: true,
39819
- list: false,
39820
- delete: false
40262
+ list: !!this.callbacks.list,
40263
+ delete: !!this.callbacks.delete
39821
40264
  }
39822
40265
  };
39823
40266
  }
@@ -39986,7 +40429,7 @@ var StorageManager = class {
39986
40429
  };
39987
40430
 
39988
40431
  // src/core.ts
39989
- var import_viem7 = require("viem");
40432
+ var import_viem8 = require("viem");
39990
40433
 
39991
40434
  // src/chains/definitions.ts
39992
40435
  var vanaMainnet2 = {
@@ -40162,9 +40605,9 @@ var VanaCore = class {
40162
40605
  `Unsupported chain ID: ${config.chainId}`
40163
40606
  );
40164
40607
  }
40165
- walletClient = (0, import_viem7.createWalletClient)({
40608
+ walletClient = (0, import_viem8.createWalletClient)({
40166
40609
  chain,
40167
- transport: (0, import_viem7.http)(config.rpcUrl || chain.rpcUrls.default.http[0]),
40610
+ transport: (0, import_viem8.http)(config.rpcUrl || chain.rpcUrls.default.http[0]),
40168
40611
  account: config.account
40169
40612
  });
40170
40613
  } else {
@@ -40172,9 +40615,9 @@ var VanaCore = class {
40172
40615
  "Invalid configuration: must be either WalletConfig or ChainConfig"
40173
40616
  );
40174
40617
  }
40175
- const publicClient = (0, import_viem7.createPublicClient)({
40618
+ const publicClient = (0, import_viem8.createPublicClient)({
40176
40619
  chain: walletClient.chain,
40177
- transport: (0, import_viem7.http)()
40620
+ transport: (0, import_viem8.http)()
40178
40621
  });
40179
40622
  const chainConfig = getChainConfig(walletClient.chain.id);
40180
40623
  const subgraphUrl = config.subgraphUrl || chainConfig?.subgraphUrl;
@@ -40439,15 +40882,35 @@ var VanaCore = class {
40439
40882
  }
40440
40883
  /**
40441
40884
  * Encrypts data using the Vana protocol standard encryption.
40442
- * This method automatically uses the correct platform adapter for the current environment.
40885
+ *
40886
+ * @remarks
40887
+ * This method implements the Vana network's standard encryption protocol using
40888
+ * platform-appropriate cryptographic libraries. It automatically handles different
40889
+ * input types (string or Blob) and produces encrypted output suitable for secure
40890
+ * storage or transmission. The encryption is compatible with the network's
40891
+ * decryption protocols and can be decrypted by authorized parties.
40443
40892
  *
40444
- * @param data The data to encrypt (string or Blob)
40445
- * @param key The key to use as encryption key
40446
- * @returns The encrypted data as Blob
40893
+ * @param data - The data to encrypt (string or Blob)
40894
+ * @param key - The encryption key (typically generated via `generateEncryptionKey`)
40895
+ * @returns The encrypted data as a Blob
40896
+ * @throws {Error} When encryption fails due to invalid key or data format
40447
40897
  * @example
40448
40898
  * ```typescript
40449
- * const encryptionKey = await generateEncryptionKey(walletClient);
40450
- * const encrypted = await vana.encryptBlob("sensitive data", encryptionKey);
40899
+ * import { generateEncryptionKey } from '@opendatalabs/vana-sdk/node';
40900
+ *
40901
+ * // Generate encryption key from wallet signature
40902
+ * const encryptionKey = await generateEncryptionKey(vana.walletClient);
40903
+ *
40904
+ * // Encrypt string data
40905
+ * const sensitiveData = "User's private information";
40906
+ * const encrypted = await vana.encryptBlob(sensitiveData, encryptionKey);
40907
+ *
40908
+ * // Encrypt file data
40909
+ * const fileBlob = new Blob([fileContent], { type: 'application/json' });
40910
+ * const encryptedFile = await vana.encryptBlob(fileBlob, encryptionKey);
40911
+ *
40912
+ * // Store encrypted data safely
40913
+ * await storageProvider.upload(encrypted, 'encrypted-data.bin');
40451
40914
  * ```
40452
40915
  */
40453
40916
  async encryptBlob(data, key) {
@@ -40455,16 +40918,52 @@ var VanaCore = class {
40455
40918
  }
40456
40919
  /**
40457
40920
  * Decrypts data that was encrypted using the Vana protocol.
40458
- * This method automatically uses the correct platform adapter for the current environment.
40921
+ *
40922
+ * @remarks
40923
+ * This method decrypts data that was previously encrypted using the Vana network's
40924
+ * standard encryption protocol. It requires the same wallet signature that was used
40925
+ * for encryption and automatically uses the appropriate platform adapter for
40926
+ * cryptographic operations. The decrypted output maintains the original data format.
40459
40927
  *
40460
- * @param encryptedData The encrypted data (string or Blob)
40461
- * @param walletSignature The wallet signature to use as decryption key
40462
- * @returns The decrypted data as Blob
40928
+ * @param encryptedData - The encrypted data (string or Blob)
40929
+ * @param walletSignature - The wallet signature used as decryption key
40930
+ * @returns The decrypted data as a Blob
40931
+ * @throws {Error} When decryption fails due to invalid signature or corrupted data
40463
40932
  * @example
40464
40933
  * ```typescript
40465
- * const encryptionKey = await generateEncryptionKey(walletClient);
40466
- * const decrypted = await vana.decryptBlob(encryptedData, encryptionKey);
40467
- * const text = await decrypted.text();
40934
+ * import { generateEncryptionKey } from '@opendatalabs/vana-sdk/node';
40935
+ *
40936
+ * // Retrieve encrypted data from storage
40937
+ * const encryptedBlob = await storageProvider.download('encrypted-data.bin');
40938
+ *
40939
+ * // Generate the same key used for encryption
40940
+ * const decryptionKey = await generateEncryptionKey(vana.walletClient);
40941
+ *
40942
+ * // Decrypt the data
40943
+ * const decrypted = await vana.decryptBlob(encryptedBlob, decryptionKey);
40944
+ *
40945
+ * // Convert back to original format
40946
+ * const originalText = await decrypted.text();
40947
+ * const originalJson = JSON.parse(originalText);
40948
+ *
40949
+ * console.log('Decrypted data:', originalJson);
40950
+ * ```
40951
+ *
40952
+ * @example
40953
+ * ```typescript
40954
+ * // Decrypt file downloaded from Vana network
40955
+ * const userFiles = await vana.data.getUserFiles();
40956
+ * const file = userFiles[0];
40957
+ *
40958
+ * // Download encrypted content
40959
+ * const encrypted = await fetch(file.url).then(r => r.blob());
40960
+ *
40961
+ * // Decrypt with user's key
40962
+ * const decryptionKey = await generateEncryptionKey(vana.walletClient);
40963
+ * const decrypted = await vana.decryptBlob(encrypted, decryptionKey);
40964
+ *
40965
+ * // Process original data
40966
+ * const fileContent = await decrypted.arrayBuffer();
40468
40967
  * ```
40469
40968
  */
40470
40969
  async decryptBlob(encryptedData, walletSignature) {
@@ -40477,15 +40976,15 @@ var VanaCore = class {
40477
40976
  };
40478
40977
 
40479
40978
  // src/utils/formatters.ts
40480
- var import_viem8 = require("viem");
40979
+ var import_viem9 = require("viem");
40481
40980
  function formatNumber(value) {
40482
40981
  return Number(value);
40483
40982
  }
40484
40983
  function formatEth(wei, decimals = 4) {
40485
- return (0, import_viem8.formatEther)(BigInt(wei.toString())).slice(0, decimals + 2);
40984
+ return (0, import_viem9.formatEther)(BigInt(wei.toString())).slice(0, decimals + 2);
40486
40985
  }
40487
40986
  function formatToken(amount, decimals = 18, displayDecimals = 4) {
40488
- const value = (0, import_viem8.formatUnits)(BigInt(amount.toString()), decimals);
40987
+ const value = (0, import_viem9.formatUnits)(BigInt(amount.toString()), decimals);
40489
40988
  const parts = value.split(".");
40490
40989
  if (parts.length === 1) {
40491
40990
  return parts[0];
@@ -40917,10 +41416,10 @@ var CircuitBreaker = class {
40917
41416
  };
40918
41417
 
40919
41418
  // src/server/handler.ts
40920
- var import_viem9 = require("viem");
41419
+ var import_viem10 = require("viem");
40921
41420
  async function handleRelayerRequest(sdk, payload) {
40922
41421
  const { typedData, signature, expectedUserAddress } = payload;
40923
- const signerAddress = await (0, import_viem9.recoverTypedDataAddress)({
41422
+ const signerAddress = await (0, import_viem10.recoverTypedDataAddress)({
40924
41423
  domain: typedData.domain,
40925
41424
  types: typedData.types,
40926
41425
  primaryType: typedData.primaryType,
@@ -41382,6 +41881,7 @@ var index_node_default = Vana;
41382
41881
  BaseController,
41383
41882
  BlockchainError,
41384
41883
  BrowserPlatformAdapter,
41884
+ CallbackStorage,
41385
41885
  CircuitBreaker,
41386
41886
  ContractFactory,
41387
41887
  ContractNotFoundError,
@@ -41416,8 +41916,8 @@ var index_node_default = Vana;
41416
41916
  SchemaValidator,
41417
41917
  SerializationError,
41418
41918
  ServerController,
41419
- ServerProxyStorage,
41420
41919
  ServerUrlMismatchError,
41920
+ SignatureCache,
41421
41921
  SignatureError,
41422
41922
  StorageError,
41423
41923
  StorageManager,
@@ -41491,6 +41991,7 @@ var index_node_default = Vana;
41491
41991
  validateGrantFile,
41492
41992
  validateGranteeAccess,
41493
41993
  validateOperationAccess,
41494
- vanaMainnet
41994
+ vanaMainnet,
41995
+ withSignatureCache
41495
41996
  });
41496
41997
  //# sourceMappingURL=index.node.cjs.map