@opendatalabs/vana-sdk 0.1.0-alpha.8eb4e46 → 0.1.0-alpha.9a32094

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();
@@ -449,6 +516,7 @@ __export(index_node_exports, {
449
516
  SerializationError: () => SerializationError,
450
517
  ServerController: () => ServerController,
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,158 @@ 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
+ * @param cache - Platform cache adapter instance
34259
+ * @param walletAddress - Wallet address that created the signature
34260
+ * @param messageHash - Hash of the message that was signed
34261
+ * @returns The cached signature if valid, null if expired or not found
34262
+ * @example
34263
+ * ```typescript
34264
+ * const messageHash = SignatureCache.hashMessage(typedData);
34265
+ * const cached = SignatureCache.get(cache, '0x123...', messageHash);
34266
+ * if (cached) {
34267
+ * console.log('Using cached signature:', cached);
34268
+ * }
34269
+ * ```
34270
+ */
34271
+ static get(cache, walletAddress, messageHash) {
34272
+ const key = this.getCacheKey(walletAddress, messageHash);
34273
+ try {
34274
+ const stored = cache.get(key);
34275
+ if (!stored) return null;
34276
+ const cached = JSON.parse(stored);
34277
+ if (Date.now() > cached.expires) {
34278
+ cache.delete(key);
34279
+ return null;
34280
+ }
34281
+ return cached.signature;
34282
+ } catch {
34283
+ try {
34284
+ cache.delete(key);
34285
+ } catch {
34286
+ }
34287
+ return null;
34288
+ }
34289
+ }
34290
+ /**
34291
+ * Store a signature in the cache with configurable TTL
34292
+ *
34293
+ * @param cache - Platform cache adapter instance
34294
+ * @param walletAddress - Wallet address that created the signature
34295
+ * @param messageHash - Hash of the message that was signed
34296
+ * @param signature - The signature to cache
34297
+ * @param ttlHours - Time to live in hours (default: 2)
34298
+ * @example
34299
+ * ```typescript
34300
+ * const signature = await wallet.signTypedData(typedData);
34301
+ * const messageHash = SignatureCache.hashMessage(typedData);
34302
+ *
34303
+ * // Cache for default 2 hours
34304
+ * SignatureCache.set(cache, walletAddress, messageHash, signature);
34305
+ *
34306
+ * // Cache for 24 hours
34307
+ * SignatureCache.set(cache, walletAddress, messageHash, signature, 24);
34308
+ * ```
34309
+ */
34310
+ static set(cache, walletAddress, messageHash, signature, ttlHours = this.DEFAULT_TTL_HOURS) {
34311
+ const key = this.getCacheKey(walletAddress, messageHash);
34312
+ const cached = {
34313
+ signature,
34314
+ expires: Date.now() + ttlHours * 36e5
34315
+ // Convert hours to milliseconds
34316
+ };
34317
+ try {
34318
+ cache.set(key, JSON.stringify(cached));
34319
+ } catch {
34320
+ }
34321
+ }
34322
+ /**
34323
+ * Clear all cached signatures (useful for testing or explicit cleanup)
34324
+ *
34325
+ * @param cache - Platform cache adapter instance
34326
+ * @example
34327
+ * ```typescript
34328
+ * // Clear all signatures when user logs out
34329
+ * SignatureCache.clear(cache);
34330
+ *
34331
+ * // Clear before running tests
34332
+ * beforeEach(() => {
34333
+ * SignatureCache.clear(cache);
34334
+ * });
34335
+ * ```
34336
+ */
34337
+ static clear(cache) {
34338
+ try {
34339
+ cache.clear();
34340
+ } catch {
34341
+ }
34342
+ }
34343
+ static getCacheKey(walletAddress, messageHash) {
34344
+ return `${this.PREFIX}${walletAddress.toLowerCase()}:${messageHash}`;
34345
+ }
34346
+ /**
34347
+ * Generate a deterministic hash of a message object for cache key generation
34348
+ *
34349
+ * @remarks
34350
+ * Creates a consistent hash from complex objects including EIP-712 typed data.
34351
+ * Handles BigInt serialization and produces a 32-character hash that balances
34352
+ * uniqueness with key length constraints.
34353
+ *
34354
+ * @param message - The message object to hash (typically EIP-712 typed data)
34355
+ * @returns A 32-character hash string suitable for cache keys
34356
+ * @example
34357
+ * ```typescript
34358
+ * const typedData = {
34359
+ * domain: { name: 'Vana', version: '1' },
34360
+ * message: { nonce: 123n, grant: '...' }
34361
+ * };
34362
+ *
34363
+ * const hash = SignatureCache.hashMessage(typedData);
34364
+ * // Returns something like: "a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6"
34365
+ * ```
34366
+ */
34367
+ static hashMessage(message) {
34368
+ const jsonString = JSON.stringify(message, this.bigIntReplacer);
34369
+ const base64Hash = toBase64(jsonString);
34370
+ const cleaned = base64Hash.replace(/[^a-zA-Z0-9]/g, "");
34371
+ if (cleaned.length > 32) {
34372
+ return cleaned.substring(0, 16) + cleaned.substring(cleaned.length - 16);
34373
+ }
34374
+ return cleaned.substring(0, 32);
34375
+ }
34376
+ /**
34377
+ * Custom JSON replacer that converts BigInt values to strings for serialization
34378
+ * This ensures deterministic cache key generation for EIP-712 typed data
34379
+ *
34380
+ * @param _key - The object key being serialized (unused)
34381
+ * @param value - The value to serialize
34382
+ * @returns The serialized value
34383
+ */
34384
+ static bigIntReplacer(_key, value) {
34385
+ if (typeof value === "bigint") {
34386
+ return `__BIGINT__${value.toString()}`;
34387
+ }
34388
+ return value;
34389
+ }
34390
+ };
34391
+ async function withSignatureCache(cache, walletAddress, typedData, signFn, ttlHours) {
34392
+ const messageHash = SignatureCache.hashMessage(typedData);
34393
+ const cached = SignatureCache.get(cache, walletAddress, messageHash);
34394
+ if (cached) {
34395
+ return cached;
34396
+ }
34397
+ const signature = await signFn();
34398
+ SignatureCache.set(cache, walletAddress, messageHash, signature, ttlHours);
34399
+ return signature;
34400
+ }
34401
+
34056
34402
  // src/controllers/permissions.ts
34057
34403
  var PermissionsController = class {
34058
34404
  constructor(context) {
@@ -34061,21 +34407,21 @@ var PermissionsController = class {
34061
34407
  /**
34062
34408
  * Grants permission for an application to access user data with gasless transactions.
34063
34409
  *
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.
34410
+ * This method provides a complete end-to-end permission grant flow that returns
34411
+ * the permission ID and other relevant data immediately after successful submission.
34412
+ * For advanced users who need more control over the transaction lifecycle, use
34413
+ * `submitPermissionGrant()` instead.
34414
+ *
34070
34415
  * @param params - The permission grant configuration object
34071
- * @returns A Promise that resolves to the transaction hash when successfully submitted
34416
+ * @returns Promise resolving to permission data from the PermissionAdded event
34072
34417
  * @throws {RelayerError} When gasless transaction submission fails
34073
34418
  * @throws {SignatureError} When user rejects the signature request
34074
34419
  * @throws {SerializationError} When grant data cannot be serialized
34075
- * @throws {BlockchainError} When permission grant preparation fails
34420
+ * @throws {BlockchainError} When permission grant fails or event parsing fails
34421
+ * @throws {NetworkError} When transaction confirmation times out
34076
34422
  * @example
34077
34423
  * ```typescript
34078
- * const txHash = await vana.permissions.grant({
34424
+ * const result = await vana.permissions.grant({
34079
34425
  * grantee: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36",
34080
34426
  * operation: "llm_inference",
34081
34427
  * parameters: {
@@ -34085,10 +34431,42 @@ var PermissionsController = class {
34085
34431
  * },
34086
34432
  * });
34087
34433
  *
34088
- * console.log(`Permission granted: ${txHash}`);
34434
+ * console.log(`Permission ${result.permissionId} granted to ${result.user}`);
34435
+ * console.log(`Transaction: ${result.transactionHash}`);
34436
+ *
34437
+ * // Can immediately use the permission ID for other operations
34438
+ * await vana.permissions.revoke({ permissionId: result.permissionId });
34089
34439
  * ```
34090
34440
  */
34091
34441
  async grant(params) {
34442
+ const txHash = await this.submitPermissionGrant(params);
34443
+ return parseTransactionResult(this.context, txHash, "grant");
34444
+ }
34445
+ /**
34446
+ * Submits a permission grant transaction and returns the transaction hash immediately.
34447
+ *
34448
+ * This is the lower-level method that provides maximum control over transaction timing.
34449
+ * Use this when you want to handle transaction confirmation and event parsing separately,
34450
+ * or when submitting multiple transactions in batch.
34451
+ *
34452
+ * @param params - The permission grant configuration object
34453
+ * @returns Promise that resolves to the transaction hash when successfully submitted
34454
+ * @throws {RelayerError} When gasless transaction submission fails
34455
+ * @throws {SignatureError} When user rejects the signature request
34456
+ * @throws {SerializationError} When grant data cannot be serialized
34457
+ * @throws {BlockchainError} When permission grant preparation fails
34458
+ * @example
34459
+ * ```typescript
34460
+ * // Submit transaction and handle confirmation later
34461
+ * const txHash = await vana.permissions.submitPermissionGrant(params);
34462
+ * console.log(`Transaction submitted: ${txHash}`);
34463
+ *
34464
+ * // Later, when you need the permission data:
34465
+ * const result = await parseTransactionResult(context, txHash, 'grant');
34466
+ * console.log(`Permission ID: ${result.permissionId}`);
34467
+ * ```
34468
+ */
34469
+ async submitPermissionGrant(params) {
34092
34470
  const { typedData, signature } = await this.createAndSign(params);
34093
34471
  return await this.submitSignedGrant(typedData, signature);
34094
34472
  }
@@ -34102,6 +34480,8 @@ var PermissionsController = class {
34102
34480
  * until the returned `confirm()` function is called.
34103
34481
  * @param params - The permission grant parameters
34104
34482
  * @returns A promise resolving to a preview object and confirm function
34483
+ * @throws {SerializationError} When grant parameters are invalid or cannot be serialized
34484
+ * @throws {BlockchainError} When grant validation fails or preparation encounters an error
34105
34485
  * @example
34106
34486
  * ```typescript
34107
34487
  * const { preview, confirm } = await vana.permissions.prepareGrant({
@@ -34506,22 +34886,51 @@ var PermissionsController = class {
34506
34886
  /**
34507
34887
  * Revokes a previously granted permission.
34508
34888
  *
34889
+ * This method provides complete revocation with automatic event parsing to confirm
34890
+ * the permission was successfully revoked. For advanced users who need more control,
34891
+ * use `submitPermissionRevoke()` instead.
34892
+ *
34509
34893
  * @param params - Parameters for revoking the permission
34510
- * @returns Promise resolving to transaction hash
34894
+ * @param params.permissionId - Permission identifier (accepts bigint, number, or string).
34895
+ * Obtain from permission grants via `getUserPermissionGrantsOnChain()`.
34896
+ * @returns Promise resolving to revocation data from PermissionRevoked event
34897
+ * @throws {BlockchainError} When revocation fails or event parsing fails
34898
+ * @throws {UserRejectedRequestError} When user rejects the transaction
34899
+ * @throws {NetworkError} When transaction confirmation times out
34511
34900
  * @example
34512
34901
  * ```typescript
34513
- * // Revoke a permission by its ID
34514
- * const txHash = await vana.permissions.revoke({
34902
+ * // Revoke a permission and get confirmation
34903
+ * const result = await vana.permissions.revoke({
34515
34904
  * permissionId: 123n
34516
34905
  * });
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);
34906
+ * console.log(`Permission ${result.permissionId} revoked in transaction ${result.transactionHash}`);
34907
+ * console.log(`Revoked in block ${result.blockNumber}`);
34522
34908
  * ```
34523
34909
  */
34524
34910
  async revoke(params) {
34911
+ const txHash = await this.submitPermissionRevoke(params);
34912
+ return parseTransactionResult(this.context, txHash, "revoke");
34913
+ }
34914
+ /**
34915
+ * Submits a permission revocation transaction and returns the transaction hash immediately.
34916
+ *
34917
+ * This is the lower-level method that provides maximum control over transaction timing.
34918
+ * Use this when you want to handle transaction confirmation and event parsing separately.
34919
+ *
34920
+ * @param params - Parameters for revoking the permission
34921
+ * @returns Promise resolving to the transaction hash when successfully submitted
34922
+ * @throws {BlockchainError} When revocation transaction fails
34923
+ * @throws {UserRejectedRequestError} When user rejects the transaction
34924
+ * @example
34925
+ * ```typescript
34926
+ * // Submit revocation and handle confirmation later
34927
+ * const txHash = await vana.permissions.submitPermissionRevoke({
34928
+ * permissionId: 123n
34929
+ * });
34930
+ * console.log(`Revocation submitted: ${txHash}`);
34931
+ * ```
34932
+ */
34933
+ async submitPermissionRevoke(params) {
34525
34934
  try {
34526
34935
  if (!this.context.walletClient.chain?.id) {
34527
34936
  throw new BlockchainError("Chain ID not available");
@@ -34559,6 +34968,11 @@ var PermissionsController = class {
34559
34968
  *
34560
34969
  * @param params - Parameters for revoking the permission
34561
34970
  * @returns Promise resolving to transaction hash
34971
+ * @throws {BlockchainError} When chain ID is not available
34972
+ * @throws {NonceError} When retrieving user nonce fails
34973
+ * @throws {SignatureError} When user rejects the signature request
34974
+ * @throws {RelayerError} When gasless submission fails
34975
+ * @throws {PermissionError} When revocation fails for any other reason
34562
34976
  */
34563
34977
  async revokeWithSignature(params) {
34564
34978
  try {
@@ -34601,6 +35015,9 @@ var PermissionsController = class {
34601
35015
  * Retrieves the user's current nonce from the DataPermissions contract.
34602
35016
  *
34603
35017
  * @returns Promise resolving to the user's current nonce value
35018
+ * @throws {Error} When wallet account is not available
35019
+ * @throws {Error} When chain ID is not available
35020
+ * @throws {NonceError} When reading nonce from contract fails
34604
35021
  */
34605
35022
  async getUserNonce() {
34606
35023
  try {
@@ -34687,17 +35104,24 @@ var PermissionsController = class {
34687
35104
  };
34688
35105
  }
34689
35106
  /**
34690
- * Signs typed data using the wallet client.
35107
+ * Signs typed data using the wallet client with signature caching.
34691
35108
  *
34692
35109
  * @param typedData - The EIP-712 typed data structure to sign
34693
35110
  * @returns Promise resolving to the cryptographic signature
34694
35111
  */
34695
35112
  async signTypedData(typedData) {
34696
35113
  try {
34697
- const signature = await this.context.walletClient.signTypedData(
34698
- typedData
35114
+ const walletAddress = this.context.walletClient.account?.address || await this.getUserAddress();
35115
+ return await withSignatureCache(
35116
+ this.context.platform.cache,
35117
+ walletAddress,
35118
+ typedData,
35119
+ async () => {
35120
+ return await this.context.walletClient.signTypedData(
35121
+ typedData
35122
+ );
35123
+ }
34699
35124
  );
34700
- return signature;
34701
35125
  } catch (error) {
34702
35126
  if (error instanceof Error && error.message.includes("rejected")) {
34703
35127
  throw new UserRejectedRequestError();
@@ -34840,6 +35264,7 @@ var PermissionsController = class {
34840
35264
  *
34841
35265
  * @param fileId - The file ID to query permissions for
34842
35266
  * @returns Promise resolving to array of permission IDs
35267
+ * @throws {BlockchainError} When reading from contract fails or chain is unavailable
34843
35268
  */
34844
35269
  async getFilePermissionIds(fileId) {
34845
35270
  try {
@@ -34868,6 +35293,7 @@ var PermissionsController = class {
34868
35293
  *
34869
35294
  * @param permissionId - The permission ID to query files for
34870
35295
  * @returns Promise resolving to array of file IDs
35296
+ * @throws {BlockchainError} When reading from contract fails or chain is unavailable
34871
35297
  */
34872
35298
  async getPermissionFileIds(permissionId) {
34873
35299
  try {
@@ -34896,6 +35322,7 @@ var PermissionsController = class {
34896
35322
  *
34897
35323
  * @param permissionId - The permission ID to check
34898
35324
  * @returns Promise resolving to boolean indicating if permission is active
35325
+ * @throws {BlockchainError} When reading from contract fails or chain is unavailable
34899
35326
  */
34900
35327
  async isActivePermission(permissionId) {
34901
35328
  try {
@@ -34924,6 +35351,7 @@ var PermissionsController = class {
34924
35351
  *
34925
35352
  * @param permissionId - The permission ID to query
34926
35353
  * @returns Promise resolving to permission info
35354
+ * @throws {BlockchainError} When reading from contract fails or chain is unavailable
34927
35355
  */
34928
35356
  async getPermissionInfo(permissionId) {
34929
35357
  try {
@@ -34971,13 +35399,18 @@ var PermissionsController = class {
34971
35399
  * Trusts a server for data processing.
34972
35400
  *
34973
35401
  * @param params - Parameters for trusting the server
35402
+ * @param params.serverId - The server's Ethereum address
35403
+ * @param params.serverUrl - The server's URL endpoint
34974
35404
  * @returns Promise resolving to transaction hash
35405
+ * @throws {UserRejectedRequestError} When user rejects the transaction
35406
+ * @throws {BlockchainError} When chain ID is unavailable or transaction fails
35407
+ * @throws {Error} When wallet account is not available
34975
35408
  * @example
34976
35409
  * ```typescript
34977
35410
  * // Trust a server by providing its ID and URL
34978
35411
  * const txHash = await vana.permissions.trustServer({
34979
35412
  * serverId: '0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6',
34980
- * serverUrl: 'https://myserver.example.com'
35413
+ * serverUrl: 'https://personal-server.vana.org'
34981
35414
  * });
34982
35415
  * console.log('Server trusted in transaction:', txHash);
34983
35416
  *
@@ -35018,6 +35451,12 @@ var PermissionsController = class {
35018
35451
  *
35019
35452
  * @param params - Parameters for trusting the server
35020
35453
  * @returns Promise resolving to transaction hash
35454
+ * @throws {BlockchainError} When chain ID is not available
35455
+ * @throws {NonceError} When retrieving user nonce fails
35456
+ * @throws {SignatureError} When user rejects the signature request
35457
+ * @throws {RelayerError} When gasless submission fails
35458
+ * @throws {ServerUrlMismatchError} When server URL doesn't match existing registration
35459
+ * @throws {BlockchainError} When trust operation fails for any other reason
35021
35460
  */
35022
35461
  async trustServerWithSignature(params) {
35023
35462
  try {
@@ -35092,7 +35531,12 @@ var PermissionsController = class {
35092
35531
  * Untrusts a server.
35093
35532
  *
35094
35533
  * @param params - Parameters for untrusting the server
35534
+ * @param params.serverId - The server's Ethereum address to untrust
35095
35535
  * @returns Promise resolving to transaction hash
35536
+ * @throws {Error} When wallet account is not available
35537
+ * @throws {NonceError} When retrieving user nonce fails
35538
+ * @throws {UserRejectedRequestError} When user rejects the transaction
35539
+ * @throws {BlockchainError} When untrust transaction fails
35096
35540
  */
35097
35541
  async untrustServer(params) {
35098
35542
  const nonce = await this.getUserNonce();
@@ -35106,7 +35550,13 @@ var PermissionsController = class {
35106
35550
  * Untrusts a server using a signature (gasless transaction).
35107
35551
  *
35108
35552
  * @param params - Parameters for untrusting the server
35553
+ * @param params.serverId - The server's Ethereum address to untrust
35109
35554
  * @returns Promise resolving to transaction hash
35555
+ * @throws {Error} When wallet account is not available
35556
+ * @throws {NonceError} When retrieving user nonce fails
35557
+ * @throws {SignatureError} When user rejects the signature request
35558
+ * @throws {RelayerError} When gasless submission fails
35559
+ * @throws {BlockchainError} When untrust transaction fails
35110
35560
  */
35111
35561
  async untrustServerWithSignature(params) {
35112
35562
  try {
@@ -35148,6 +35598,7 @@ var PermissionsController = class {
35148
35598
  *
35149
35599
  * @param userAddress - Optional user address (defaults to current user)
35150
35600
  * @returns Promise resolving to array of trusted server addresses
35601
+ * @throws {BlockchainError} When reading from contract fails or chain is unavailable
35151
35602
  */
35152
35603
  async getTrustedServers(userAddress) {
35153
35604
  try {
@@ -35177,6 +35628,7 @@ var PermissionsController = class {
35177
35628
  *
35178
35629
  * @param serverId - Server address
35179
35630
  * @returns Promise resolving to server information
35631
+ * @throws {BlockchainError} When reading from contract fails or chain is unavailable
35180
35632
  */
35181
35633
  async getServerInfo(serverId) {
35182
35634
  try {
@@ -35205,6 +35657,7 @@ var PermissionsController = class {
35205
35657
  *
35206
35658
  * @param userAddress - Optional user address (defaults to current user)
35207
35659
  * @returns Promise resolving to the number of trusted servers
35660
+ * @throws {BlockchainError} When reading from contract fails or chain is unavailable
35208
35661
  */
35209
35662
  async getTrustedServersCount(userAddress) {
35210
35663
  try {
@@ -35234,6 +35687,7 @@ var PermissionsController = class {
35234
35687
  *
35235
35688
  * @param options - Query options including pagination parameters
35236
35689
  * @returns Promise resolving to paginated trusted servers
35690
+ * @throws {BlockchainError} When reading from contract fails or chain is unavailable
35237
35691
  */
35238
35692
  async getTrustedServersPaginated(options = {}) {
35239
35693
  try {
@@ -35293,6 +35747,7 @@ var PermissionsController = class {
35293
35747
  *
35294
35748
  * @param options - Query options
35295
35749
  * @returns Promise resolving to array of trusted server info
35750
+ * @throws {BlockchainError} When reading from contract fails or chain is unavailable
35296
35751
  */
35297
35752
  async getTrustedServersWithInfo(options = {}) {
35298
35753
  try {
@@ -35330,6 +35785,7 @@ var PermissionsController = class {
35330
35785
  *
35331
35786
  * @param serverIds - Array of server IDs to query
35332
35787
  * @returns Promise resolving to batch result with successes and failures
35788
+ * @throws {BlockchainError} When reading from contract fails or chain is unavailable
35333
35789
  */
35334
35790
  async getServerInfoBatch(serverIds) {
35335
35791
  if (serverIds.length === 0) {
@@ -35527,19 +35983,26 @@ var PermissionsController = class {
35527
35983
  };
35528
35984
 
35529
35985
  // src/controllers/data.ts
35530
- var import_viem2 = require("viem");
35986
+ var import_viem3 = require("viem");
35531
35987
 
35532
35988
  // src/utils/encryption.ts
35533
35989
  var DEFAULT_ENCRYPTION_SEED = "Please sign to retrieve your encryption key";
35534
- async function generateEncryptionKey(wallet, seed = DEFAULT_ENCRYPTION_SEED) {
35990
+ async function generateEncryptionKey(wallet, platformAdapter, seed = DEFAULT_ENCRYPTION_SEED) {
35535
35991
  if (!wallet.account) {
35536
35992
  throw new Error("Wallet account is required for encryption key generation");
35537
35993
  }
35538
- const signature = await wallet.signMessage({
35539
- account: wallet.account,
35540
- message: seed
35541
- });
35542
- return signature;
35994
+ const messageData = { message: seed };
35995
+ return await withSignatureCache(
35996
+ platformAdapter.cache,
35997
+ wallet.account.address,
35998
+ messageData,
35999
+ async () => {
36000
+ return await wallet.signMessage({
36001
+ account: wallet.account,
36002
+ message: seed
36003
+ });
36004
+ }
36005
+ );
35543
36006
  }
35544
36007
  async function encryptWithWalletPublicKey(data, publicKey, platformAdapter) {
35545
36008
  try {
@@ -35704,6 +36167,7 @@ var DataController = class {
35704
36167
  if (encrypt3) {
35705
36168
  const encryptionKey = await generateEncryptionKey(
35706
36169
  this.context.walletClient,
36170
+ this.context.platform,
35707
36171
  DEFAULT_ENCRYPTION_SEED
35708
36172
  );
35709
36173
  finalBlob = await encryptBlobWithSignedKey(
@@ -35729,26 +36193,21 @@ var DataController = class {
35729
36193
  );
35730
36194
  const userAddress = owner || await this.getUserAddress();
35731
36195
  let encryptedPermissions = [];
35732
- if (permissions.length > 0 && encrypt3) {
36196
+ if (permissions.length > 0) {
35733
36197
  const userEncryptionKey = await generateEncryptionKey(
35734
36198
  this.context.walletClient,
36199
+ this.context.platform,
35735
36200
  DEFAULT_ENCRYPTION_SEED
35736
36201
  );
35737
36202
  encryptedPermissions = await Promise.all(
35738
36203
  permissions.map(async (permission) => {
35739
- const publicKey = permission.publicKey;
35740
- if (!publicKey) {
35741
- throw new Error(
35742
- `Public key required for permission to ${permission.grantee} when encryption is enabled`
35743
- );
35744
- }
35745
36204
  const encryptedKey = await encryptWithWalletPublicKey(
35746
36205
  userEncryptionKey,
35747
- publicKey,
36206
+ permission.publicKey,
35748
36207
  this.context.platform
35749
36208
  );
35750
36209
  return {
35751
- account: permission.grantee,
36210
+ account: permission.account,
35752
36211
  key: encryptedKey
35753
36212
  };
35754
36213
  })
@@ -35820,9 +36279,14 @@ var DataController = class {
35820
36279
  * @param file - The user file to decrypt (typically from getUserFiles)
35821
36280
  * @param encryptionSeed - Optional custom encryption seed (defaults to Vana standard)
35822
36281
  * @returns Promise resolving to the decrypted file content as a Blob
35823
- * @throws {Error} When the wallet is not connected
35824
- * @throws {Error} When fetching the encrypted content fails
35825
- * @throws {Error} When decryption fails (wrong key or corrupted data)
36282
+ * @throws {Error} "No addresses available in wallet client" - When wallet is not connected
36283
+ * @throws {Error} "Network error: Cannot access the file URL" - When file URL is inaccessible (CORS, server down)
36284
+ * @throws {Error} "File not found: The encrypted file is no longer available" - When file returns 404
36285
+ * @throws {Error} "Access denied" - When file returns 403 (no permission)
36286
+ * @throws {Error} "File is empty or could not be retrieved" - When file has no content
36287
+ * @throws {Error} "Invalid file format: This file doesn't appear to be encrypted with the Vana protocol" - When file is not properly encrypted
36288
+ * @throws {Error} "Wrong encryption key" - When decryption fails due to incorrect key/seed
36289
+ * @throws {Error} "Failed to decrypt file: {error}" - General decryption failures
35826
36290
  * @example
35827
36291
  * ```typescript
35828
36292
  * // Basic file decryption
@@ -35852,6 +36316,7 @@ var DataController = class {
35852
36316
  try {
35853
36317
  const encryptionKey = await generateEncryptionKey(
35854
36318
  this.context.walletClient,
36319
+ this.context.platform,
35855
36320
  encryptionSeed || DEFAULT_ENCRYPTION_SEED
35856
36321
  );
35857
36322
  let encryptedBlob;
@@ -35941,11 +36406,20 @@ var DataController = class {
35941
36406
  * This method queries the Vana subgraph to find files directly owned by the user.
35942
36407
  * It efficiently handles large datasets by using the File entity's owner field
35943
36408
  * and returns complete file metadata without additional contract calls.
36409
+ *
36410
+ * **Deduplication Behavior:**
36411
+ * The method automatically deduplicates files by ID, keeping only the latest version
36412
+ * (highest timestamp) when duplicate file IDs are found. This handles cases where
36413
+ * the subgraph may contain multiple entries for the same file due to re-indexing
36414
+ * or blockchain reorganizations.
35944
36415
  * @param params - The query parameters object
35945
36416
  * @param params.owner - The wallet address of the file owner to query
35946
36417
  * @param params.subgraphUrl - Optional subgraph URL to override the default endpoint
35947
- * @returns A Promise that resolves to an array of UserFile objects with metadata
35948
- * @throws {Error} When the subgraph is unavailable or returns invalid data
36418
+ * @returns A Promise that resolves to an array of UserFile objects with metadata, sorted by latest timestamp first
36419
+ * @throws {Error} When subgraphUrl is not provided and not configured - "subgraphUrl is required"
36420
+ * @throws {Error} When subgraph request fails - "Subgraph request failed: {status} {statusText}"
36421
+ * @throws {Error} When subgraph returns errors - "Subgraph errors: {error messages}"
36422
+ * @throws {Error} When JSON parsing fails - "Failed to fetch user files from subgraph: {error}"
35949
36423
  * @example
35950
36424
  * ```typescript
35951
36425
  * // Query files for a specific user
@@ -36428,7 +36902,7 @@ var DataController = class {
36428
36902
  }
36429
36903
  const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
36430
36904
  const dataRegistryAbi = getAbi("DataRegistry");
36431
- const dataRegistry = (0, import_viem2.getContract)({
36905
+ const dataRegistry = (0, import_viem3.getContract)({
36432
36906
  address: dataRegistryAddress,
36433
36907
  abi: dataRegistryAbi,
36434
36908
  client: this.context.walletClient
@@ -36448,6 +36922,9 @@ var DataController = class {
36448
36922
  *
36449
36923
  * @param fileId - The file ID to look up
36450
36924
  * @returns Promise resolving to UserFile object
36925
+ * @throws {Error} "Chain ID not available" - When wallet chain is not configured
36926
+ * @throws {Error} "File not found" - When file ID doesn't exist or returns empty data
36927
+ * @throws {Error} "Failed to fetch file {fileId}: {error}" - General contract read failures
36451
36928
  * @example
36452
36929
  * ```typescript
36453
36930
  * try {
@@ -36476,7 +36953,7 @@ var DataController = class {
36476
36953
  }
36477
36954
  const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
36478
36955
  const dataRegistryAbi = getAbi("DataRegistry");
36479
- const dataRegistry = (0, import_viem2.getContract)({
36956
+ const dataRegistry = (0, import_viem3.getContract)({
36480
36957
  address: dataRegistryAddress,
36481
36958
  abi: dataRegistryAbi,
36482
36959
  client: this.context.walletClient
@@ -36517,7 +36994,21 @@ var DataController = class {
36517
36994
  /**
36518
36995
  * Uploads an encrypted file to storage and registers it on the blockchain.
36519
36996
  *
36520
- * @deprecated Use vana.data.upload() instead for the high-level API with automatic encryption
36997
+ * @deprecated Since v2.0.0 - Use vana.data.upload() instead for the high-level API with automatic encryption
36998
+ *
36999
+ * Migration guide:
37000
+ * ```typescript
37001
+ * // Old way (deprecated):
37002
+ * const encrypted = await encryptBlob(data, key);
37003
+ * const result = await vana.data.uploadEncryptedFile(encrypted, filename);
37004
+ *
37005
+ * // New way:
37006
+ * const result = await vana.data.upload({
37007
+ * content: data,
37008
+ * filename: filename,
37009
+ * encrypt: true // Handles encryption automatically
37010
+ * });
37011
+ * ```
36521
37012
  * @param encryptedFile - The encrypted file blob to upload
36522
37013
  * @param filename - Optional filename for the upload
36523
37014
  * @param providerName - Optional storage provider to use
@@ -36575,7 +37066,7 @@ var DataController = class {
36575
37066
  let fileId = 0;
36576
37067
  for (const log of receipt.logs) {
36577
37068
  try {
36578
- const decoded = (0, import_viem2.decodeEventLog)({
37069
+ const decoded = (0, import_viem3.decodeEventLog)({
36579
37070
  abi: dataRegistryAbi,
36580
37071
  data: log.data,
36581
37072
  topics: log.topics
@@ -36605,7 +37096,22 @@ var DataController = class {
36605
37096
  /**
36606
37097
  * Uploads an encrypted file to storage and registers it on the blockchain with a schema.
36607
37098
  *
36608
- * @deprecated Use vana.data.upload() instead for the high-level API with automatic encryption and schema validation
37099
+ * @deprecated Since v2.0.0 - Use vana.data.upload() instead for the high-level API with automatic encryption and schema validation
37100
+ *
37101
+ * Migration guide:
37102
+ * ```typescript
37103
+ * // Old way (deprecated):
37104
+ * const encrypted = await encryptBlob(data, key);
37105
+ * const result = await vana.data.uploadEncryptedFileWithSchema(encrypted, schemaId, filename);
37106
+ *
37107
+ * // New way:
37108
+ * const result = await vana.data.upload({
37109
+ * content: data,
37110
+ * filename: filename,
37111
+ * schemaId: schemaId, // Automatic validation
37112
+ * encrypt: true
37113
+ * });
37114
+ * ```
36609
37115
  * @param encryptedFile - The encrypted file blob to upload
36610
37116
  * @param schemaId - The schema ID to associate with the file
36611
37117
  * @param filename - Optional filename for the upload
@@ -36657,7 +37163,7 @@ var DataController = class {
36657
37163
  let fileId = 0;
36658
37164
  for (const log of receipt.logs) {
36659
37165
  try {
36660
- const decoded = (0, import_viem2.decodeEventLog)({
37166
+ const decoded = (0, import_viem3.decodeEventLog)({
36661
37167
  abi: dataRegistryAbi,
36662
37168
  data: log.data,
36663
37169
  topics: log.topics
@@ -36720,7 +37226,7 @@ var DataController = class {
36720
37226
  let fileId = 0;
36721
37227
  for (const log of receipt.logs) {
36722
37228
  try {
36723
- const decoded = (0, import_viem2.decodeEventLog)({
37229
+ const decoded = (0, import_viem3.decodeEventLog)({
36724
37230
  abi: dataRegistryAbi,
36725
37231
  data: log.data,
36726
37232
  topics: log.topics
@@ -36748,6 +37254,7 @@ var DataController = class {
36748
37254
  * Gets the user's address from the wallet client.
36749
37255
  *
36750
37256
  * @returns Promise resolving to the user's wallet address
37257
+ * @throws {Error} When no addresses are available in wallet client
36751
37258
  */
36752
37259
  async getUserAddress() {
36753
37260
  const addresses = await this.context.walletClient.getAddresses();
@@ -36763,6 +37270,10 @@ var DataController = class {
36763
37270
  * @param ownerAddress - The address of the file owner
36764
37271
  * @param permissions - Array of permissions to set for the file
36765
37272
  * @returns Promise resolving to file ID and transaction hash
37273
+ * @throws {Error} When chain ID is not available
37274
+ * @throws {ContractError} When contract execution fails
37275
+ * @throws {Error} When transaction receipt is not available
37276
+ * @throws {Error} When FileAdded event cannot be parsed
36766
37277
  *
36767
37278
  * This method handles the core logic of registering a file
36768
37279
  * with specific permissions on the DataRegistry contract. It can be used
@@ -36794,7 +37305,7 @@ var DataController = class {
36794
37305
  let fileId = 0;
36795
37306
  for (const log of receipt.logs) {
36796
37307
  try {
36797
- const decoded = (0, import_viem2.decodeEventLog)({
37308
+ const decoded = (0, import_viem3.decodeEventLog)({
36798
37309
  abi: dataRegistryAbi,
36799
37310
  data: log.data,
36800
37311
  topics: log.topics
@@ -36827,6 +37338,10 @@ var DataController = class {
36827
37338
  * @param permissions - Array of permissions to grant (account and encrypted key)
36828
37339
  * @param schemaId - The schema ID to associate with the file (0 for no schema)
36829
37340
  * @returns Promise resolving to object with fileId and transactionHash
37341
+ * @throws {Error} When chain ID is not available
37342
+ * @throws {ContractError} When contract execution fails
37343
+ * @throws {Error} When transaction receipt is not available
37344
+ * @throws {Error} When FileAdded event cannot be parsed
36830
37345
  */
36831
37346
  async addFileWithPermissionsAndSchema(url, ownerAddress, permissions = [], schemaId = 0) {
36832
37347
  try {
@@ -36854,7 +37369,7 @@ var DataController = class {
36854
37369
  let fileId = 0;
36855
37370
  for (const log of receipt.logs) {
36856
37371
  try {
36857
- const decoded = (0, import_viem2.decodeEventLog)({
37372
+ const decoded = (0, import_viem3.decodeEventLog)({
36858
37373
  abi: dataRegistryAbi,
36859
37374
  data: log.data,
36860
37375
  topics: log.topics
@@ -36881,7 +37396,24 @@ var DataController = class {
36881
37396
  /**
36882
37397
  * Adds a new schema to the DataRefinerRegistry.
36883
37398
  *
36884
- * @deprecated Use vana.schemas.create() instead for the high-level API with automatic IPFS upload
37399
+ * @deprecated Since v2.0.0 - Use vana.schemas.create() instead for the high-level API with automatic IPFS upload
37400
+ *
37401
+ * Migration guide:
37402
+ * ```typescript
37403
+ * // Old way (deprecated):
37404
+ * const result = await vana.data.addSchema({
37405
+ * name: "UserProfile",
37406
+ * type: "JSON",
37407
+ * definitionUrl: "ipfs://..."
37408
+ * });
37409
+ *
37410
+ * // New way:
37411
+ * const result = await vana.schemas.create({
37412
+ * name: "UserProfile",
37413
+ * type: "JSON",
37414
+ * definition: schemaObject // Automatically uploads to IPFS
37415
+ * });
37416
+ * ```
36885
37417
  * @param params - Schema parameters including name, type, and definition URL
36886
37418
  * @returns Promise resolving to the new schema ID and transaction hash
36887
37419
  */
@@ -36913,7 +37445,7 @@ var DataController = class {
36913
37445
  let schemaId = 0;
36914
37446
  for (const log of receipt.logs) {
36915
37447
  try {
36916
- const decoded = (0, import_viem2.decodeEventLog)({
37448
+ const decoded = (0, import_viem3.decodeEventLog)({
36917
37449
  abi: dataRefinerRegistryAbi,
36918
37450
  data: log.data,
36919
37451
  topics: log.topics
@@ -36940,7 +37472,16 @@ var DataController = class {
36940
37472
  /**
36941
37473
  * Retrieves a schema by its ID.
36942
37474
  *
36943
- * @deprecated Use vana.schemas.get() instead
37475
+ * @deprecated Since v2.0.0 - Use vana.schemas.get() instead
37476
+ *
37477
+ * Migration guide:
37478
+ * ```typescript
37479
+ * // Old way (deprecated):
37480
+ * const schema = await vana.data.getSchema(schemaId);
37481
+ *
37482
+ * // New way:
37483
+ * const schema = await vana.schemas.get(schemaId);
37484
+ * ```
36944
37485
  * @param schemaId - The schema ID to retrieve
36945
37486
  * @returns Promise resolving to the schema information
36946
37487
  */
@@ -36955,7 +37496,7 @@ var DataController = class {
36955
37496
  "DataRefinerRegistry"
36956
37497
  );
36957
37498
  const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
36958
- const dataRefinerRegistry = (0, import_viem2.getContract)({
37499
+ const dataRefinerRegistry = (0, import_viem3.getContract)({
36959
37500
  address: dataRefinerRegistryAddress,
36960
37501
  abi: dataRefinerRegistryAbi,
36961
37502
  client: this.context.walletClient
@@ -36986,7 +37527,16 @@ var DataController = class {
36986
37527
  /**
36987
37528
  * Gets the total number of schemas in the registry.
36988
37529
  *
36989
- * @deprecated Use vana.schemas.count() instead
37530
+ * @deprecated Since v2.0.0 - Use vana.schemas.count() instead
37531
+ *
37532
+ * Migration guide:
37533
+ * ```typescript
37534
+ * // Old way (deprecated):
37535
+ * const count = await vana.data.getSchemasCount();
37536
+ *
37537
+ * // New way:
37538
+ * const count = await vana.schemas.count();
37539
+ * ```
36990
37540
  * @returns Promise resolving to the total schema count
36991
37541
  */
36992
37542
  async getSchemasCount() {
@@ -37000,7 +37550,7 @@ var DataController = class {
37000
37550
  "DataRefinerRegistry"
37001
37551
  );
37002
37552
  const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
37003
- const dataRefinerRegistry = (0, import_viem2.getContract)({
37553
+ const dataRefinerRegistry = (0, import_viem3.getContract)({
37004
37554
  address: dataRefinerRegistryAddress,
37005
37555
  abi: dataRefinerRegistryAbi,
37006
37556
  client: this.context.walletClient
@@ -37051,7 +37601,7 @@ var DataController = class {
37051
37601
  let refinerId = 0;
37052
37602
  for (const log of receipt.logs) {
37053
37603
  try {
37054
- const decoded = (0, import_viem2.decodeEventLog)({
37604
+ const decoded = (0, import_viem3.decodeEventLog)({
37055
37605
  abi: dataRefinerRegistryAbi,
37056
37606
  data: log.data,
37057
37607
  topics: log.topics
@@ -37092,7 +37642,7 @@ var DataController = class {
37092
37642
  "DataRefinerRegistry"
37093
37643
  );
37094
37644
  const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
37095
- const dataRefinerRegistry = (0, import_viem2.getContract)({
37645
+ const dataRefinerRegistry = (0, import_viem3.getContract)({
37096
37646
  address: dataRefinerRegistryAddress,
37097
37647
  abi: dataRefinerRegistryAbi,
37098
37648
  client: this.context.walletClient
@@ -37135,7 +37685,7 @@ var DataController = class {
37135
37685
  "DataRefinerRegistry"
37136
37686
  );
37137
37687
  const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
37138
- const dataRefinerRegistry = (0, import_viem2.getContract)({
37688
+ const dataRefinerRegistry = (0, import_viem3.getContract)({
37139
37689
  address: dataRefinerRegistryAddress,
37140
37690
  abi: dataRefinerRegistryAbi,
37141
37691
  client: this.context.walletClient
@@ -37165,7 +37715,7 @@ var DataController = class {
37165
37715
  "DataRefinerRegistry"
37166
37716
  );
37167
37717
  const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
37168
- const dataRefinerRegistry = (0, import_viem2.getContract)({
37718
+ const dataRefinerRegistry = (0, import_viem3.getContract)({
37169
37719
  address: dataRefinerRegistryAddress,
37170
37720
  abi: dataRefinerRegistryAbi,
37171
37721
  client: this.context.walletClient
@@ -37235,6 +37785,7 @@ var DataController = class {
37235
37785
  try {
37236
37786
  const userEncryptionKey = await generateEncryptionKey(
37237
37787
  this.context.walletClient,
37788
+ this.context.platform,
37238
37789
  DEFAULT_ENCRYPTION_SEED
37239
37790
  );
37240
37791
  const encryptedData = await encryptBlobWithSignedKey(
@@ -37300,16 +37851,50 @@ var DataController = class {
37300
37851
  * 1. Gets the user's encryption key
37301
37852
  * 2. Encrypts the user's encryption key with the provided public key
37302
37853
  * 3. Adds the permission to the file
37854
+ * 4. Returns the permission data from the blockchain event
37855
+ *
37856
+ * For advanced users who need more control over transaction timing,
37857
+ * use `submitFilePermission()` instead.
37858
+ *
37859
+ * @param fileId - The ID of the file to add permissions for
37860
+ * @param account - The address of the account to grant permission to
37861
+ * @param publicKey - The public key to encrypt the user's encryption key with (hex string with 0x prefix)
37862
+ * @returns Promise resolving to permission data from PermissionGranted event
37863
+ * @throws {Error} "No addresses available in wallet client" - When wallet is not connected
37864
+ * @throws {Error} "Chain ID not available" - When wallet chain is not configured
37865
+ * @throws {Error} "Failed to add permission to file: {error}" - When transaction fails or user doesn't own file
37866
+ * @example
37867
+ * ```typescript
37868
+ * const result = await vana.data.addPermissionToFile(fileId, account, publicKey);
37869
+ * console.log(`Permission granted to ${result.account} for file ${result.fileId}`);
37870
+ * console.log(`Transaction: ${result.transactionHash}`);
37871
+ * ```
37872
+ */
37873
+ async addPermissionToFile(fileId, account, publicKey) {
37874
+ const txHash = await this.submitFilePermission(fileId, account, publicKey);
37875
+ return parseTransactionResult(this.context, txHash, "addFilePermission");
37876
+ }
37877
+ /**
37878
+ * Submits a file permission transaction and returns the transaction hash immediately.
37879
+ *
37880
+ * This is the lower-level method that provides maximum control over transaction timing.
37881
+ * Use this when you want to handle transaction confirmation and event parsing separately.
37303
37882
  *
37304
37883
  * @param fileId - The ID of the file to add permissions for
37305
37884
  * @param account - The address of the account to grant permission to
37306
37885
  * @param publicKey - The public key to encrypt the user's encryption key with
37307
37886
  * @returns Promise resolving to the transaction hash
37887
+ * @example
37888
+ * ```typescript
37889
+ * const txHash = await vana.data.submitFilePermission(fileId, account, publicKey);
37890
+ * console.log(`Transaction submitted: ${txHash}`);
37891
+ * ```
37308
37892
  */
37309
- async addPermissionToFile(fileId, account, publicKey) {
37893
+ async submitFilePermission(fileId, account, publicKey) {
37310
37894
  try {
37311
37895
  const userEncryptionKey = await generateEncryptionKey(
37312
37896
  this.context.walletClient,
37897
+ this.context.platform,
37313
37898
  DEFAULT_ENCRYPTION_SEED
37314
37899
  );
37315
37900
  const encryptedKey = await encryptWithWalletPublicKey(
@@ -37354,7 +37939,7 @@ var DataController = class {
37354
37939
  }
37355
37940
  const dataRegistryAddress = getContractAddress(chainId, "DataRegistry");
37356
37941
  const dataRegistryAbi = getAbi("DataRegistry");
37357
- const dataRegistry = (0, import_viem2.getContract)({
37942
+ const dataRegistry = (0, import_viem3.getContract)({
37358
37943
  address: dataRegistryAddress,
37359
37944
  abi: dataRegistryAbi,
37360
37945
  client: this.context.walletClient
@@ -37430,7 +38015,9 @@ var DataController = class {
37430
38015
  *
37431
38016
  * @param url - The URL to fetch content from
37432
38017
  * @returns Promise resolving to the fetched content as a Blob
37433
- * @throws {Error} When the fetch fails or returns a non-ok response
38018
+ * @throws {Error} "HTTP error! status: {status} {statusText}" - When server returns error status
38019
+ * @throws {Error} "Empty response" - When server returns no content
38020
+ * @throws {Error} "Network error: Failed to fetch from {url}" - When network request fails
37434
38021
  *
37435
38022
  * @example
37436
38023
  * ```typescript
@@ -37482,7 +38069,10 @@ var DataController = class {
37482
38069
  * @param options - Optional configuration
37483
38070
  * @param options.gateways - Array of IPFS gateway URLs to try (must end with /)
37484
38071
  * @returns Promise resolving to the fetched content as a Blob
37485
- * @throws {Error} When all gateways fail to fetch the content
38072
+ * @throws {Error} "Invalid IPFS URL format" - When URL is not ipfs:// or valid CID
38073
+ * @throws {Error} "Empty response" - When gateway returns no content
38074
+ * @throws {Error} "HTTP error! status: {status}" - When gateway returns error status
38075
+ * @throws {Error} "Failed to fetch IPFS content {cid} from all gateways" - When all gateways fail
37486
38076
  *
37487
38077
  * @example
37488
38078
  * ```typescript
@@ -37698,7 +38288,7 @@ var DataController = class {
37698
38288
  };
37699
38289
 
37700
38290
  // src/controllers/schemas.ts
37701
- var import_viem3 = require("viem");
38291
+ var import_viem4 = require("viem");
37702
38292
  var SchemaController = class {
37703
38293
  constructor(context) {
37704
38294
  this.context = context;
@@ -37810,7 +38400,7 @@ var SchemaController = class {
37810
38400
  let schemaId = 0;
37811
38401
  for (const log of receipt.logs) {
37812
38402
  try {
37813
- const decoded = (0, import_viem3.decodeEventLog)({
38403
+ const decoded = (0, import_viem4.decodeEventLog)({
37814
38404
  abi: dataRefinerRegistryAbi,
37815
38405
  data: log.data,
37816
38406
  topics: log.topics
@@ -37859,7 +38449,7 @@ var SchemaController = class {
37859
38449
  "DataRefinerRegistry"
37860
38450
  );
37861
38451
  const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
37862
- const dataRefinerRegistry = (0, import_viem3.getContract)({
38452
+ const dataRefinerRegistry = (0, import_viem4.getContract)({
37863
38453
  address: dataRefinerRegistryAddress,
37864
38454
  abi: dataRefinerRegistryAbi,
37865
38455
  client: this.context.publicClient
@@ -37908,7 +38498,7 @@ var SchemaController = class {
37908
38498
  "DataRefinerRegistry"
37909
38499
  );
37910
38500
  const dataRefinerRegistryAbi = getAbi("DataRefinerRegistry");
37911
- const dataRefinerRegistry = (0, import_viem3.getContract)({
38501
+ const dataRefinerRegistry = (0, import_viem4.getContract)({
37912
38502
  address: dataRefinerRegistryAddress,
37913
38503
  abi: dataRefinerRegistryAbi,
37914
38504
  client: this.context.publicClient
@@ -38023,6 +38613,39 @@ var ServerController = class {
38023
38613
  this.context = context;
38024
38614
  }
38025
38615
  PERSONAL_SERVER_BASE_URL = process.env.NEXT_PUBLIC_PERSONAL_SERVER_BASE_URL;
38616
+ /**
38617
+ * Retrieves the cryptographic identity of a personal server.
38618
+ *
38619
+ * @remarks
38620
+ * This method fetches the public key and metadata for a personal server,
38621
+ * which is required for encrypting data before sharing with the server.
38622
+ * The identity includes the server's public key, address, and operational
38623
+ * details needed for secure communication. This information is cached
38624
+ * by identity servers to enable offline key retrieval.
38625
+ *
38626
+ * @param request - Parameters containing the user address
38627
+ * @param request.userAddress - The wallet address associated with the personal server
38628
+ * @returns Promise resolving to the server's identity information
38629
+ * @throws {NetworkError} When the identity service is unavailable or returns invalid data
38630
+ * @throws {PersonalServerError} When server identity cannot be retrieved
38631
+ * @example
38632
+ * ```typescript
38633
+ * // Get server identity for data encryption
38634
+ * const identity = await vana.server.getIdentity({
38635
+ * userAddress: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36"
38636
+ * });
38637
+ *
38638
+ * console.log(`Server: ${identity.name}`);
38639
+ * console.log(`Address: ${identity.address}`);
38640
+ * console.log(`Public Key: ${identity.public_key}`);
38641
+ *
38642
+ * // Use the public key for encrypting data to share with this server
38643
+ * const encryptedData = await encryptWithWalletPublicKey(
38644
+ * userData,
38645
+ * identity.public_key
38646
+ * );
38647
+ * ```
38648
+ */
38026
38649
  async getIdentity(request) {
38027
38650
  try {
38028
38651
  const response = await fetch(
@@ -38065,10 +38688,13 @@ var ServerController = class {
38065
38688
  * This method submits a computation request to the personal server API.
38066
38689
  * The response includes the operation ID.
38067
38690
  * @param params - The request parameters object
38068
- * @param params.permissionId - The permission ID authorizing this operation
38691
+ * @param params.permissionId - The permission ID authorizing this operation.
38692
+ * Obtain from granted permissions via `vana.permissions.getUserPermissionGrantsOnChain()`.
38069
38693
  * @returns A Promise that resolves to an operation response with status and control URLs
38070
- * @throws {PersonalServerError} When server request fails or parameters are invalid
38071
- * @throws {NetworkError} When personal server API communication fails
38694
+ * @throws {PersonalServerError} When server request fails or parameters are invalid.
38695
+ * Verify permissionId exists and is active for the target server.
38696
+ * @throws {NetworkError} When personal server API communication fails.
38697
+ * Check server URL configuration and network connectivity.
38072
38698
  * @example
38073
38699
  * ```typescript
38074
38700
  * const response = await vana.server.createOperation({
@@ -38170,6 +38796,50 @@ var ServerController = class {
38170
38796
  );
38171
38797
  }
38172
38798
  }
38799
+ /**
38800
+ * Cancels a running operation on the personal server.
38801
+ *
38802
+ * @remarks
38803
+ * This method attempts to cancel an operation that is currently processing
38804
+ * on the personal server. The operation must be in a cancellable state
38805
+ * (typically `starting` or `processing`). Not all operations support
38806
+ * cancellation, and cancellation may not be immediate. The server will
38807
+ * attempt to stop the operation and update its status to `canceled`.
38808
+ *
38809
+ * **Cancellation Behavior:**
38810
+ * - Operations in `succeeded` or `failed` states cannot be canceled
38811
+ * - Some long-running operations may take time to respond to cancellation
38812
+ * - Always verify cancellation by polling the operation status afterward
38813
+ *
38814
+ * @param operationId - The unique identifier of the operation to cancel,
38815
+ * obtained from `createOperation()` response
38816
+ * @returns Promise that resolves when the cancellation request is accepted
38817
+ * @throws {PersonalServerError} When the operation cannot be canceled or doesn't exist.
38818
+ * Check operation status - it may already be completed or failed.
38819
+ * @throws {NetworkError} When unable to reach the personal server API.
38820
+ * Verify server URL and network connectivity.
38821
+ * @example
38822
+ * ```typescript
38823
+ * // Start a long-running operation
38824
+ * const operation = await vana.server.createOperation({
38825
+ * permissionId: 123
38826
+ * });
38827
+ *
38828
+ * // Cancel if needed
38829
+ * try {
38830
+ * await vana.server.cancelOperation(operation.id);
38831
+ * console.log("Cancellation requested");
38832
+ *
38833
+ * // Verify cancellation
38834
+ * const status = await vana.server.getOperation(operation.id);
38835
+ * if (status.status === "canceled") {
38836
+ * console.log("Operation successfully canceled");
38837
+ * }
38838
+ * } catch (error) {
38839
+ * console.error("Failed to cancel:", error);
38840
+ * }
38841
+ * ```
38842
+ */
38173
38843
  async cancelOperation(operationId) {
38174
38844
  try {
38175
38845
  const response = await fetch(
@@ -38278,14 +38948,14 @@ var ServerController = class {
38278
38948
  };
38279
38949
 
38280
38950
  // src/contracts/contractController.ts
38281
- var import_viem6 = require("viem");
38951
+ var import_viem7 = require("viem");
38282
38952
 
38283
38953
  // src/core/client.ts
38284
- var import_viem5 = require("viem");
38954
+ var import_viem6 = require("viem");
38285
38955
 
38286
38956
  // src/config/chains.ts
38287
- var import_viem4 = require("viem");
38288
- var mokshaTestnet = (0, import_viem4.defineChain)({
38957
+ var import_viem5 = require("viem");
38958
+ var mokshaTestnet = (0, import_viem5.defineChain)({
38289
38959
  id: 14800,
38290
38960
  caipNetworkId: "eip155:14800",
38291
38961
  chainNamespace: "eip155",
@@ -38313,7 +38983,7 @@ var mokshaTestnet = (0, import_viem4.defineChain)({
38313
38983
  contracts: {},
38314
38984
  abis: {}
38315
38985
  });
38316
- var vanaMainnet = (0, import_viem4.defineChain)({
38986
+ var vanaMainnet = (0, import_viem5.defineChain)({
38317
38987
  id: 1480,
38318
38988
  caipNetworkId: "eip155:1480",
38319
38989
  chainNamespace: "eip155",
@@ -38355,9 +39025,9 @@ var createClient = (chainId = mokshaTestnet.id) => {
38355
39025
  if (!chain) {
38356
39026
  throw new Error(`Chain ${chainId} not found`);
38357
39027
  }
38358
- _client = (0, import_viem5.createPublicClient)({
39028
+ _client = (0, import_viem6.createPublicClient)({
38359
39029
  chain,
38360
- transport: (0, import_viem5.http)()
39030
+ transport: (0, import_viem6.http)()
38361
39031
  });
38362
39032
  }
38363
39033
  return _client;
@@ -38374,7 +39044,7 @@ function getContractController(contract, client = createClient()) {
38374
39044
  const cacheKey = createCacheKey(contract, chainId);
38375
39045
  let controller = contractCache.get(cacheKey);
38376
39046
  if (!controller) {
38377
- controller = (0, import_viem6.getContract)({
39047
+ controller = (0, import_viem7.getContract)({
38378
39048
  address: getContractAddress(chainId, contract),
38379
39049
  abi: getAbi(contract),
38380
39050
  client
@@ -38467,7 +39137,8 @@ var ProtocolController = class {
38467
39137
  * are actually deployed on the current network.
38468
39138
  * @param contractName - The name of the Vana contract to retrieve (use const assertion for full typing)
38469
39139
  * @returns An object containing the contract's address and fully typed ABI
38470
- * @throws {ContractNotFoundError} When the contract is not deployed on the current chain
39140
+ * @throws {ContractNotFoundError} When the contract is not deployed on the current chain.
39141
+ * Verify contract name spelling and check current network with `getChainId()`.
38471
39142
  * @example
38472
39143
  * ```typescript
38473
39144
  * // Get contract info with full type inference
@@ -38576,6 +39247,7 @@ var ProtocolController = class {
38576
39247
  * Gets the current chain ID from the wallet client.
38577
39248
  *
38578
39249
  * @returns The chain ID
39250
+ * @throws {Error} When chain ID is not available from wallet client
38579
39251
  */
38580
39252
  getChainId() {
38581
39253
  const chainId = this.context.walletClient.chain?.id;
@@ -38588,6 +39260,7 @@ var ProtocolController = class {
38588
39260
  * Gets the current chain name from the wallet client.
38589
39261
  *
38590
39262
  * @returns The chain name
39263
+ * @throws {Error} When chain name is not available from wallet client
38591
39264
  */
38592
39265
  getChainName() {
38593
39266
  const chainName = this.context.walletClient.chain?.name;
@@ -39088,6 +39761,7 @@ var GoogleDriveStorage = class {
39088
39761
  };
39089
39762
 
39090
39763
  // src/storage/providers/ipfs.ts
39764
+ init_crypto_utils();
39091
39765
  var IpfsStorage = class _IpfsStorage {
39092
39766
  constructor(config) {
39093
39767
  this.config = config;
@@ -39127,7 +39801,7 @@ var IpfsStorage = class _IpfsStorage {
39127
39801
  * ```
39128
39802
  */
39129
39803
  static forInfura(credentials) {
39130
- const auth = btoa(`${credentials.projectId}:${credentials.projectSecret}`);
39804
+ const auth = toBase64(`${credentials.projectId}:${credentials.projectSecret}`);
39131
39805
  return new _IpfsStorage({
39132
39806
  apiEndpoint: "https://ipfs.infura.io:5001/api/v0/add",
39133
39807
  gatewayUrl: "https://ipfs.infura.io/ipfs",
@@ -39964,7 +40638,7 @@ var StorageManager = class {
39964
40638
  };
39965
40639
 
39966
40640
  // src/core.ts
39967
- var import_viem7 = require("viem");
40641
+ var import_viem8 = require("viem");
39968
40642
 
39969
40643
  // src/chains/definitions.ts
39970
40644
  var vanaMainnet2 = {
@@ -40140,9 +40814,9 @@ var VanaCore = class {
40140
40814
  `Unsupported chain ID: ${config.chainId}`
40141
40815
  );
40142
40816
  }
40143
- walletClient = (0, import_viem7.createWalletClient)({
40817
+ walletClient = (0, import_viem8.createWalletClient)({
40144
40818
  chain,
40145
- transport: (0, import_viem7.http)(config.rpcUrl || chain.rpcUrls.default.http[0]),
40819
+ transport: (0, import_viem8.http)(config.rpcUrl || chain.rpcUrls.default.http[0]),
40146
40820
  account: config.account
40147
40821
  });
40148
40822
  } else {
@@ -40150,9 +40824,9 @@ var VanaCore = class {
40150
40824
  "Invalid configuration: must be either WalletConfig or ChainConfig"
40151
40825
  );
40152
40826
  }
40153
- const publicClient = (0, import_viem7.createPublicClient)({
40827
+ const publicClient = (0, import_viem8.createPublicClient)({
40154
40828
  chain: walletClient.chain,
40155
- transport: (0, import_viem7.http)()
40829
+ transport: (0, import_viem8.http)()
40156
40830
  });
40157
40831
  const chainConfig = getChainConfig(walletClient.chain.id);
40158
40832
  const subgraphUrl = config.subgraphUrl || chainConfig?.subgraphUrl;
@@ -40417,15 +41091,35 @@ var VanaCore = class {
40417
41091
  }
40418
41092
  /**
40419
41093
  * Encrypts data using the Vana protocol standard encryption.
40420
- * This method automatically uses the correct platform adapter for the current environment.
41094
+ *
41095
+ * @remarks
41096
+ * This method implements the Vana network's standard encryption protocol using
41097
+ * platform-appropriate cryptographic libraries. It automatically handles different
41098
+ * input types (string or Blob) and produces encrypted output suitable for secure
41099
+ * storage or transmission. The encryption is compatible with the network's
41100
+ * decryption protocols and can be decrypted by authorized parties.
40421
41101
  *
40422
- * @param data The data to encrypt (string or Blob)
40423
- * @param key The key to use as encryption key
40424
- * @returns The encrypted data as Blob
41102
+ * @param data - The data to encrypt (string or Blob)
41103
+ * @param key - The encryption key (typically generated via `generateEncryptionKey`)
41104
+ * @returns The encrypted data as a Blob
41105
+ * @throws {Error} When encryption fails due to invalid key or data format
40425
41106
  * @example
40426
41107
  * ```typescript
40427
- * const encryptionKey = await generateEncryptionKey(walletClient);
40428
- * const encrypted = await vana.encryptBlob("sensitive data", encryptionKey);
41108
+ * import { generateEncryptionKey } from '@opendatalabs/vana-sdk/node';
41109
+ *
41110
+ * // Generate encryption key from wallet signature
41111
+ * const encryptionKey = await generateEncryptionKey(vana.walletClient);
41112
+ *
41113
+ * // Encrypt string data
41114
+ * const sensitiveData = "User's private information";
41115
+ * const encrypted = await vana.encryptBlob(sensitiveData, encryptionKey);
41116
+ *
41117
+ * // Encrypt file data
41118
+ * const fileBlob = new Blob([fileContent], { type: 'application/json' });
41119
+ * const encryptedFile = await vana.encryptBlob(fileBlob, encryptionKey);
41120
+ *
41121
+ * // Store encrypted data safely
41122
+ * await storageProvider.upload(encrypted, 'encrypted-data.bin');
40429
41123
  * ```
40430
41124
  */
40431
41125
  async encryptBlob(data, key) {
@@ -40433,16 +41127,52 @@ var VanaCore = class {
40433
41127
  }
40434
41128
  /**
40435
41129
  * Decrypts data that was encrypted using the Vana protocol.
40436
- * This method automatically uses the correct platform adapter for the current environment.
41130
+ *
41131
+ * @remarks
41132
+ * This method decrypts data that was previously encrypted using the Vana network's
41133
+ * standard encryption protocol. It requires the same wallet signature that was used
41134
+ * for encryption and automatically uses the appropriate platform adapter for
41135
+ * cryptographic operations. The decrypted output maintains the original data format.
40437
41136
  *
40438
- * @param encryptedData The encrypted data (string or Blob)
40439
- * @param walletSignature The wallet signature to use as decryption key
40440
- * @returns The decrypted data as Blob
41137
+ * @param encryptedData - The encrypted data (string or Blob)
41138
+ * @param walletSignature - The wallet signature used as decryption key
41139
+ * @returns The decrypted data as a Blob
41140
+ * @throws {Error} When decryption fails due to invalid signature or corrupted data
40441
41141
  * @example
40442
41142
  * ```typescript
40443
- * const encryptionKey = await generateEncryptionKey(walletClient);
40444
- * const decrypted = await vana.decryptBlob(encryptedData, encryptionKey);
40445
- * const text = await decrypted.text();
41143
+ * import { generateEncryptionKey } from '@opendatalabs/vana-sdk/node';
41144
+ *
41145
+ * // Retrieve encrypted data from storage
41146
+ * const encryptedBlob = await storageProvider.download('encrypted-data.bin');
41147
+ *
41148
+ * // Generate the same key used for encryption
41149
+ * const decryptionKey = await generateEncryptionKey(vana.walletClient);
41150
+ *
41151
+ * // Decrypt the data
41152
+ * const decrypted = await vana.decryptBlob(encryptedBlob, decryptionKey);
41153
+ *
41154
+ * // Convert back to original format
41155
+ * const originalText = await decrypted.text();
41156
+ * const originalJson = JSON.parse(originalText);
41157
+ *
41158
+ * console.log('Decrypted data:', originalJson);
41159
+ * ```
41160
+ *
41161
+ * @example
41162
+ * ```typescript
41163
+ * // Decrypt file downloaded from Vana network
41164
+ * const userFiles = await vana.data.getUserFiles();
41165
+ * const file = userFiles[0];
41166
+ *
41167
+ * // Download encrypted content
41168
+ * const encrypted = await fetch(file.url).then(r => r.blob());
41169
+ *
41170
+ * // Decrypt with user's key
41171
+ * const decryptionKey = await generateEncryptionKey(vana.walletClient);
41172
+ * const decrypted = await vana.decryptBlob(encrypted, decryptionKey);
41173
+ *
41174
+ * // Process original data
41175
+ * const fileContent = await decrypted.arrayBuffer();
40446
41176
  * ```
40447
41177
  */
40448
41178
  async decryptBlob(encryptedData, walletSignature) {
@@ -40455,15 +41185,15 @@ var VanaCore = class {
40455
41185
  };
40456
41186
 
40457
41187
  // src/utils/formatters.ts
40458
- var import_viem8 = require("viem");
41188
+ var import_viem9 = require("viem");
40459
41189
  function formatNumber(value) {
40460
41190
  return Number(value);
40461
41191
  }
40462
41192
  function formatEth(wei, decimals = 4) {
40463
- return (0, import_viem8.formatEther)(BigInt(wei.toString())).slice(0, decimals + 2);
41193
+ return (0, import_viem9.formatEther)(BigInt(wei.toString())).slice(0, decimals + 2);
40464
41194
  }
40465
41195
  function formatToken(amount, decimals = 18, displayDecimals = 4) {
40466
- const value = (0, import_viem8.formatUnits)(BigInt(amount.toString()), decimals);
41196
+ const value = (0, import_viem9.formatUnits)(BigInt(amount.toString()), decimals);
40467
41197
  const parts = value.split(".");
40468
41198
  if (parts.length === 1) {
40469
41199
  return parts[0];
@@ -40895,10 +41625,10 @@ var CircuitBreaker = class {
40895
41625
  };
40896
41626
 
40897
41627
  // src/server/handler.ts
40898
- var import_viem9 = require("viem");
41628
+ var import_viem10 = require("viem");
40899
41629
  async function handleRelayerRequest(sdk, payload) {
40900
41630
  const { typedData, signature, expectedUserAddress } = payload;
40901
- const signerAddress = await (0, import_viem9.recoverTypedDataAddress)({
41631
+ const signerAddress = await (0, import_viem10.recoverTypedDataAddress)({
40902
41632
  domain: typedData.domain,
40903
41633
  types: typedData.types,
40904
41634
  primaryType: typedData.primaryType,
@@ -41396,6 +42126,7 @@ var index_node_default = Vana;
41396
42126
  SerializationError,
41397
42127
  ServerController,
41398
42128
  ServerUrlMismatchError,
42129
+ SignatureCache,
41399
42130
  SignatureError,
41400
42131
  StorageError,
41401
42132
  StorageManager,
@@ -41469,6 +42200,7 @@ var index_node_default = Vana;
41469
42200
  validateGrantFile,
41470
42201
  validateGranteeAccess,
41471
42202
  validateOperationAccess,
41472
- vanaMainnet
42203
+ vanaMainnet,
42204
+ withSignatureCache
41473
42205
  });
41474
42206
  //# sourceMappingURL=index.node.cjs.map