@opendatalabs/vana-sdk 0.1.0-alpha.b390e7f → 0.1.0-alpha.cb72de2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -32
- package/dist/index.browser.d.ts +5111 -4311
- package/dist/index.browser.js +825 -330
- package/dist/index.browser.js.map +1 -1
- package/dist/index.node.cjs +897 -372
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.d.cts +5139 -4311
- package/dist/index.node.d.ts +5139 -4311
- package/dist/index.node.js +853 -330
- package/dist/index.node.js.map +1 -1
- package/dist/platform.browser.d.ts +69 -0
- package/dist/platform.browser.js +48 -1
- package/dist/platform.browser.js.map +1 -1
- package/dist/platform.cjs +76 -1
- package/dist/platform.cjs.map +1 -1
- package/dist/platform.js +76 -1
- package/dist/platform.js.map +1 -1
- package/dist/platform.node.cjs +76 -1
- package/dist/platform.node.cjs.map +1 -1
- package/dist/platform.node.d.cts +70 -0
- package/dist/platform.node.d.ts +70 -0
- package/dist/platform.node.js +76 -1
- package/dist/platform.node.js.map +1 -1
- package/package.json +1 -1
package/dist/index.browser.js
CHANGED
|
@@ -29,6 +29,28 @@ function parseEncryptedDataBuffer(encryptedBuffer) {
|
|
|
29
29
|
mac: encryptedBuffer.slice(-32)
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
+
function toBase64(str) {
|
|
33
|
+
if (typeof Buffer !== "undefined") {
|
|
34
|
+
return Buffer.from(str, "utf8").toString("base64");
|
|
35
|
+
} else if (typeof btoa !== "undefined") {
|
|
36
|
+
return btoa(str);
|
|
37
|
+
} else {
|
|
38
|
+
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
39
|
+
let result = "";
|
|
40
|
+
let i = 0;
|
|
41
|
+
while (i < str.length) {
|
|
42
|
+
const a = str.charCodeAt(i++);
|
|
43
|
+
const b = i < str.length ? str.charCodeAt(i++) : 0;
|
|
44
|
+
const c = i < str.length ? str.charCodeAt(i++) : 0;
|
|
45
|
+
const bitmap = a << 16 | b << 8 | c;
|
|
46
|
+
result += chars.charAt(bitmap >> 18 & 63);
|
|
47
|
+
result += chars.charAt(bitmap >> 12 & 63);
|
|
48
|
+
result += i - 2 < str.length ? chars.charAt(bitmap >> 6 & 63) : "=";
|
|
49
|
+
result += i - 1 < str.length ? chars.charAt(bitmap & 63) : "=";
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
32
54
|
var init_crypto_utils = __esm({
|
|
33
55
|
"src/platform/shared/crypto-utils.ts"() {
|
|
34
56
|
"use strict";
|
|
@@ -79,7 +101,7 @@ var init_error_utils = __esm({
|
|
|
79
101
|
|
|
80
102
|
// src/platform/browser.ts
|
|
81
103
|
import * as openpgp from "openpgp";
|
|
82
|
-
var BrowserCryptoAdapter, BrowserPGPAdapter, BrowserHttpAdapter, BrowserPlatformAdapter, browserPlatformAdapter;
|
|
104
|
+
var BrowserCryptoAdapter, BrowserPGPAdapter, BrowserHttpAdapter, BrowserCacheAdapter, BrowserPlatformAdapter, browserPlatformAdapter;
|
|
83
105
|
var init_browser = __esm({
|
|
84
106
|
"src/platform/browser.ts"() {
|
|
85
107
|
"use strict";
|
|
@@ -258,15 +280,62 @@ var init_browser = __esm({
|
|
|
258
280
|
return fetch(url, options);
|
|
259
281
|
}
|
|
260
282
|
};
|
|
283
|
+
BrowserCacheAdapter = class {
|
|
284
|
+
constructor() {
|
|
285
|
+
__publicField(this, "prefix", "vana_cache_");
|
|
286
|
+
}
|
|
287
|
+
get(key) {
|
|
288
|
+
try {
|
|
289
|
+
if (typeof sessionStorage === "undefined") {
|
|
290
|
+
return null;
|
|
291
|
+
}
|
|
292
|
+
return sessionStorage.getItem(this.prefix + key);
|
|
293
|
+
} catch {
|
|
294
|
+
return null;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
set(key, value) {
|
|
298
|
+
try {
|
|
299
|
+
if (typeof sessionStorage !== "undefined") {
|
|
300
|
+
sessionStorage.setItem(this.prefix + key, value);
|
|
301
|
+
}
|
|
302
|
+
} catch {
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
delete(key) {
|
|
306
|
+
try {
|
|
307
|
+
if (typeof sessionStorage !== "undefined") {
|
|
308
|
+
sessionStorage.removeItem(this.prefix + key);
|
|
309
|
+
}
|
|
310
|
+
} catch {
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
clear() {
|
|
314
|
+
try {
|
|
315
|
+
if (typeof sessionStorage === "undefined") {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
const keys = Object.keys(sessionStorage);
|
|
319
|
+
for (const key of keys) {
|
|
320
|
+
if (key.startsWith(this.prefix)) {
|
|
321
|
+
sessionStorage.removeItem(key);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
} catch {
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
};
|
|
261
328
|
BrowserPlatformAdapter = class {
|
|
262
329
|
constructor() {
|
|
263
330
|
__publicField(this, "crypto");
|
|
264
331
|
__publicField(this, "pgp");
|
|
265
332
|
__publicField(this, "http");
|
|
333
|
+
__publicField(this, "cache");
|
|
266
334
|
__publicField(this, "platform", "browser");
|
|
267
335
|
this.crypto = new BrowserCryptoAdapter();
|
|
268
336
|
this.pgp = new BrowserPGPAdapter();
|
|
269
337
|
this.http = new BrowserHttpAdapter();
|
|
338
|
+
this.cache = new BrowserCacheAdapter();
|
|
270
339
|
}
|
|
271
340
|
};
|
|
272
341
|
browserPlatformAdapter = new BrowserPlatformAdapter();
|
|
@@ -800,276 +869,45 @@ var PermissionError = class extends VanaError {
|
|
|
800
869
|
}
|
|
801
870
|
};
|
|
802
871
|
|
|
803
|
-
// src/
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
},
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
}
|
|
842
|
-
},
|
|
843
|
-
VanaTreasury: {
|
|
844
|
-
addresses: {
|
|
845
|
-
14800: "0x94a1E56e555ac48d092f490fB10CDFaB434915eD",
|
|
846
|
-
1480: "0x94a1E56e555ac48d092f490fB10CDFaB434915eD"
|
|
847
|
-
}
|
|
848
|
-
},
|
|
849
|
-
ComputeInstructionRegistry: {
|
|
850
|
-
addresses: {
|
|
851
|
-
14800: "0x5786B12b4c6Ba2bFAF0e77Ed30Bf6d32805563A5",
|
|
852
|
-
1480: "0x5786B12b4c6Ba2bFAF0e77Ed30Bf6d32805563A5"
|
|
853
|
-
}
|
|
854
|
-
},
|
|
855
|
-
// TEE Pool Variants
|
|
856
|
-
TeePoolEphemeralStandard: {
|
|
857
|
-
addresses: {
|
|
858
|
-
14800: "0xe124bae846D5ec157f75Bd9e68ca87C4d2AB835A",
|
|
859
|
-
1480: "0xe124bae846D5ec157f75Bd9e68ca87C4d2AB835A"
|
|
860
|
-
}
|
|
861
|
-
},
|
|
862
|
-
TeePoolPersistentStandard: {
|
|
863
|
-
addresses: {
|
|
864
|
-
14800: "0xe8bB8d0629651Cf33e0845d743976Dc1f0971d76",
|
|
865
|
-
1480: "0xe8bB8d0629651Cf33e0845d743976Dc1f0971d76"
|
|
866
|
-
}
|
|
867
|
-
},
|
|
868
|
-
TeePoolPersistentGpu: {
|
|
869
|
-
addresses: {
|
|
870
|
-
14800: "0x1c346Cd74f8551f8fa13f3F4b6b8dAE22338E6a9",
|
|
871
|
-
1480: "0x1c346Cd74f8551f8fa13f3F4b6b8dAE22338E6a9"
|
|
872
|
-
}
|
|
873
|
-
},
|
|
874
|
-
TeePoolDedicatedStandard: {
|
|
875
|
-
addresses: {
|
|
876
|
-
14800: "0xf024b7ac5E8417416f53B41ecfa58C8e9396687d",
|
|
877
|
-
1480: "0xf024b7ac5E8417416f53B41ecfa58C8e9396687d"
|
|
878
|
-
}
|
|
879
|
-
},
|
|
880
|
-
TeePoolDedicatedGpu: {
|
|
881
|
-
addresses: {
|
|
882
|
-
14800: "0xB1686FA9620bBf851714d1cB47b8a4Bf4664644E",
|
|
883
|
-
1480: "0xB1686FA9620bBf851714d1cB47b8a4Bf4664644E"
|
|
884
|
-
}
|
|
885
|
-
},
|
|
886
|
-
// DLP Reward System
|
|
887
|
-
VanaEpoch: {
|
|
888
|
-
addresses: {
|
|
889
|
-
14800: "0x2063cFF0609D59bCCc196E20Eb58A8696a6b15A0",
|
|
890
|
-
1480: "0x2063cFF0609D59bCCc196E20Eb58A8696a6b15A0"
|
|
891
|
-
}
|
|
892
|
-
},
|
|
893
|
-
DLPRegistry: {
|
|
894
|
-
addresses: {
|
|
895
|
-
14800: "0x4D59880a924526d1dD33260552Ff4328b1E18a43",
|
|
896
|
-
1480: "0x4D59880a924526d1dD33260552Ff4328b1E18a43"
|
|
897
|
-
}
|
|
898
|
-
},
|
|
899
|
-
DLPRegistryTreasury: {
|
|
900
|
-
addresses: {
|
|
901
|
-
14800: "0xb12ce1d27bEeFe39b6F0110b1AB77C21Aa0c9F9a",
|
|
902
|
-
1480: "0xb12ce1d27bEeFe39b6F0110b1AB77C21Aa0c9F9a"
|
|
903
|
-
}
|
|
904
|
-
},
|
|
905
|
-
DLPPerformance: {
|
|
906
|
-
addresses: {
|
|
907
|
-
14800: "0x847715C7DB37cF286611182Be0bD333cbfa29cc1",
|
|
908
|
-
1480: "0x847715C7DB37cF286611182Be0bD333cbfa29cc1"
|
|
909
|
-
}
|
|
910
|
-
},
|
|
911
|
-
DLPRewardDeployer: {
|
|
912
|
-
addresses: {
|
|
913
|
-
14800: "0xEFD0F9Ba9De70586b7c4189971cF754adC923B04",
|
|
914
|
-
1480: "0xEFD0F9Ba9De70586b7c4189971cF754adC923B04"
|
|
915
|
-
}
|
|
916
|
-
},
|
|
917
|
-
DLPRewardDeployerTreasury: {
|
|
918
|
-
addresses: {
|
|
919
|
-
14800: "0xb547ca8Fe4990fe330FeAeb1C2EBb42F925Af5b8",
|
|
920
|
-
1480: "0xb547ca8Fe4990fe330FeAeb1C2EBb42F925Af5b8"
|
|
921
|
-
}
|
|
922
|
-
},
|
|
923
|
-
DLPRewardSwap: {
|
|
924
|
-
addresses: {
|
|
925
|
-
14800: "0x7c6862C46830F0fc3bF3FF509EA1bD0EE7267fB0",
|
|
926
|
-
1480: "0x7c6862C46830F0fc3bF3FF509EA1bD0EE7267fB0"
|
|
927
|
-
}
|
|
928
|
-
},
|
|
929
|
-
SwapHelper: {
|
|
930
|
-
addresses: {
|
|
931
|
-
14800: "0x55D5e6F73326315bF2E091e97F04f0770e5C54e2",
|
|
932
|
-
1480: "0x55D5e6F73326315bF2E091e97F04f0770e5C54e2"
|
|
933
|
-
}
|
|
934
|
-
},
|
|
935
|
-
// VanaPool (Staking)
|
|
936
|
-
VanaPoolStaking: {
|
|
937
|
-
addresses: {
|
|
938
|
-
14800: "0x641C18E2F286c86f96CE95C8ec1EB9fC0415Ca0e",
|
|
939
|
-
1480: "0x641C18E2F286c86f96CE95C8ec1EB9fC0415Ca0e"
|
|
940
|
-
}
|
|
941
|
-
},
|
|
942
|
-
VanaPoolEntity: {
|
|
943
|
-
addresses: {
|
|
944
|
-
14800: "0x44f20490A82e1f1F1cC25Dd3BA8647034eDdce30",
|
|
945
|
-
1480: "0x44f20490A82e1f1F1cC25Dd3BA8647034eDdce30"
|
|
946
|
-
}
|
|
947
|
-
},
|
|
948
|
-
VanaPoolTreasury: {
|
|
949
|
-
addresses: {
|
|
950
|
-
14800: "0x143BE72CF2541604A7691933CAccd6D9cC17c003",
|
|
951
|
-
1480: "0x143BE72CF2541604A7691933CAccd6D9cC17c003"
|
|
952
|
-
}
|
|
953
|
-
},
|
|
954
|
-
// DLP Deployment Contracts
|
|
955
|
-
DAT: {
|
|
956
|
-
addresses: {
|
|
957
|
-
14800: "0xA706b93ccED89f13340673889e29F0a5cd84212d",
|
|
958
|
-
1480: "0xA706b93ccED89f13340673889e29F0a5cd84212d"
|
|
959
|
-
}
|
|
960
|
-
},
|
|
961
|
-
DATFactory: {
|
|
962
|
-
addresses: {
|
|
963
|
-
14800: "0x40f8bccF35a75ecef63BC3B1B3E06ffEB9220644",
|
|
964
|
-
1480: "0x40f8bccF35a75ecef63BC3B1B3E06ffEB9220644"
|
|
965
|
-
}
|
|
966
|
-
},
|
|
967
|
-
DATPausable: {
|
|
968
|
-
addresses: {
|
|
969
|
-
14800: "0xe69FE86f0B95cC2f8416Fe22815c85DC8887e76e",
|
|
970
|
-
1480: "0xe69FE86f0B95cC2f8416Fe22815c85DC8887e76e"
|
|
971
|
-
}
|
|
972
|
-
},
|
|
973
|
-
DATVotes: {
|
|
974
|
-
addresses: {
|
|
975
|
-
14800: "0xaE04c8A77E9B27869eb563720524A9aE0baf1831",
|
|
976
|
-
1480: "0xaE04c8A77E9B27869eb563720524A9aE0baf1831"
|
|
977
|
-
}
|
|
978
|
-
},
|
|
979
|
-
// Utility Contracts (no ABIs in SDK)
|
|
980
|
-
Multicall3: {
|
|
981
|
-
addresses: {
|
|
982
|
-
14800: "0xD8d2dFca27E8797fd779F8547166A2d3B29d360E",
|
|
983
|
-
1480: "0xD8d2dFca27E8797fd779F8547166A2d3B29d360E"
|
|
984
|
-
}
|
|
985
|
-
},
|
|
986
|
-
Multisend: {
|
|
987
|
-
addresses: {
|
|
988
|
-
14800: "0x8807e8BCDFbaA8c2761760f3FBA37F6f7F2C5b2d",
|
|
989
|
-
1480: "0x8807e8BCDFbaA8c2761760f3FBA37F6f7F2C5b2d"
|
|
990
|
-
}
|
|
991
|
-
}
|
|
992
|
-
};
|
|
993
|
-
var LEGACY_CONTRACTS = {
|
|
994
|
-
// DEPRECATED: Original Intel SGX TeePool (PRO-347)
|
|
995
|
-
TeePool: {
|
|
996
|
-
addresses: {
|
|
997
|
-
14800: "0x3c92fD91639b41f13338CE62f19131e7d19eaa0D",
|
|
998
|
-
1480: "0x3c92fD91639b41f13338CE62f19131e7d19eaa0D"
|
|
999
|
-
}
|
|
1000
|
-
},
|
|
1001
|
-
// DEPRECATED: DLPRoot system (replaced by VanaPool + DLPRewards)
|
|
1002
|
-
DLPRootEpoch: {
|
|
1003
|
-
addresses: {
|
|
1004
|
-
14800: "0xc3d176cF6BccFCB9225b53B87a95147218e1537F",
|
|
1005
|
-
1480: "0xc3d176cF6BccFCB9225b53B87a95147218e1537F"
|
|
1006
|
-
}
|
|
1007
|
-
},
|
|
1008
|
-
DLPRootCore: {
|
|
1009
|
-
addresses: {
|
|
1010
|
-
14800: "0x0aBa5e28228c323A67712101d61a54d4ff5720FD",
|
|
1011
|
-
1480: "0x0aBa5e28228c323A67712101d61a54d4ff5720FD"
|
|
1012
|
-
}
|
|
1013
|
-
},
|
|
1014
|
-
DLPRoot: {
|
|
1015
|
-
addresses: {
|
|
1016
|
-
14800: "0xff14346dF2B8Fd0c95BF34f1c92e49417b508AD5",
|
|
1017
|
-
1480: "0xff14346dF2B8Fd0c95BF34f1c92e49417b508AD5"
|
|
1018
|
-
}
|
|
1019
|
-
},
|
|
1020
|
-
DLPRootMetrics: {
|
|
1021
|
-
addresses: {
|
|
1022
|
-
14800: "0xbb532917B6407c060Afd9Cb7d53527eCb91d6662",
|
|
1023
|
-
1480: "0xbb532917B6407c060Afd9Cb7d53527eCb91d6662"
|
|
1024
|
-
}
|
|
1025
|
-
},
|
|
1026
|
-
DLPRootStakesTreasury: {
|
|
1027
|
-
addresses: {
|
|
1028
|
-
14800: "0x52c3260ED5C235fcA43524CF508e29c897318775",
|
|
1029
|
-
1480: "0x52c3260ED5C235fcA43524CF508e29c897318775"
|
|
1030
|
-
}
|
|
1031
|
-
},
|
|
1032
|
-
DLPRootRewardsTreasury: {
|
|
1033
|
-
addresses: {
|
|
1034
|
-
14800: "0xDBFb6B8b9E2eCAEbdE64d665cD553dB81e524479",
|
|
1035
|
-
1480: "0xDBFb6B8b9E2eCAEbdE64d665cD553dB81e524479"
|
|
1036
|
-
}
|
|
1037
|
-
}
|
|
1038
|
-
};
|
|
1039
|
-
var CONTRACT_ADDRESSES = {
|
|
1040
|
-
14800: Object.fromEntries(
|
|
1041
|
-
Object.entries(CONTRACTS).map(([name, info]) => [name, info.addresses[14800]]).filter(([, addr]) => addr)
|
|
1042
|
-
),
|
|
1043
|
-
1480: Object.fromEntries(
|
|
1044
|
-
Object.entries(CONTRACTS).map(([name, info]) => [name, info.addresses[1480]]).filter(([, addr]) => addr)
|
|
1045
|
-
)
|
|
1046
|
-
};
|
|
1047
|
-
var UTILITY_ADDRESSES = {
|
|
1048
|
-
14800: {
|
|
1049
|
-
Multicall3: CONTRACTS.Multicall3.addresses[14800],
|
|
1050
|
-
Multisend: CONTRACTS.Multisend.addresses[14800]
|
|
1051
|
-
},
|
|
1052
|
-
1480: {
|
|
1053
|
-
Multicall3: CONTRACTS.Multicall3.addresses[1480],
|
|
1054
|
-
Multisend: CONTRACTS.Multisend.addresses[1480]
|
|
1055
|
-
}
|
|
1056
|
-
};
|
|
1057
|
-
var LEGACY_ADDRESSES = {
|
|
1058
|
-
14800: Object.fromEntries(
|
|
1059
|
-
Object.entries(LEGACY_CONTRACTS).map(([name, info]) => [name, info.addresses[14800]]).filter(([, addr]) => addr)
|
|
1060
|
-
),
|
|
1061
|
-
1480: Object.fromEntries(
|
|
1062
|
-
Object.entries(LEGACY_CONTRACTS).map(([name, info]) => [name, info.addresses[1480]]).filter(([, addr]) => addr)
|
|
1063
|
-
)
|
|
1064
|
-
};
|
|
1065
|
-
var getContractAddress = (chainId, contract) => {
|
|
1066
|
-
const contractAddress = CONTRACT_ADDRESSES[chainId]?.[contract];
|
|
1067
|
-
if (!contractAddress) {
|
|
1068
|
-
throw new Error(
|
|
1069
|
-
`Contract address not found for ${contract} on chain ${chainId}`
|
|
1070
|
-
);
|
|
872
|
+
// src/utils/transactionParsing.ts
|
|
873
|
+
import { parseEventLogs } from "viem";
|
|
874
|
+
|
|
875
|
+
// src/config/eventMappings.ts
|
|
876
|
+
var EVENT_MAPPINGS = {
|
|
877
|
+
// Permission operations
|
|
878
|
+
grant: {
|
|
879
|
+
contract: "DataPermissions",
|
|
880
|
+
event: "PermissionAdded"
|
|
881
|
+
},
|
|
882
|
+
revoke: {
|
|
883
|
+
contract: "DataPermissions",
|
|
884
|
+
event: "PermissionRevoked"
|
|
885
|
+
},
|
|
886
|
+
trustServer: {
|
|
887
|
+
contract: "DataPermissions",
|
|
888
|
+
event: "ServerTrusted"
|
|
889
|
+
},
|
|
890
|
+
untrustServer: {
|
|
891
|
+
contract: "DataPermissions",
|
|
892
|
+
event: "ServerUntrusted"
|
|
893
|
+
},
|
|
894
|
+
// Data registry operations
|
|
895
|
+
addFile: {
|
|
896
|
+
contract: "DataRegistry",
|
|
897
|
+
event: "FileAdded"
|
|
898
|
+
},
|
|
899
|
+
addRefinement: {
|
|
900
|
+
contract: "DataRegistry",
|
|
901
|
+
event: "RefinementAdded"
|
|
902
|
+
},
|
|
903
|
+
updateRefinement: {
|
|
904
|
+
contract: "DataRegistry",
|
|
905
|
+
event: "RefinementUpdated"
|
|
906
|
+
},
|
|
907
|
+
addFilePermission: {
|
|
908
|
+
contract: "DataRegistry",
|
|
909
|
+
event: "PermissionGranted"
|
|
1071
910
|
}
|
|
1072
|
-
return contractAddress;
|
|
1073
911
|
};
|
|
1074
912
|
|
|
1075
913
|
// src/abi/ComputeEngineImplementation.ts
|
|
@@ -33276,6 +33114,332 @@ function getAbi(contract) {
|
|
|
33276
33114
|
return abi;
|
|
33277
33115
|
}
|
|
33278
33116
|
|
|
33117
|
+
// src/utils/transactionParsing.ts
|
|
33118
|
+
async function parseTransactionResult(context, hash, operation) {
|
|
33119
|
+
const mapping = EVENT_MAPPINGS[operation];
|
|
33120
|
+
try {
|
|
33121
|
+
console.debug(`\u{1F50D} Parsing ${operation} transaction: ${hash}`);
|
|
33122
|
+
const receipt = await context.publicClient.waitForTransactionReceipt({
|
|
33123
|
+
hash,
|
|
33124
|
+
timeout: 3e4
|
|
33125
|
+
// 30 second timeout
|
|
33126
|
+
});
|
|
33127
|
+
console.debug(`\u2705 Transaction confirmed in block ${receipt.blockNumber}`);
|
|
33128
|
+
const abi = getAbi(mapping.contract);
|
|
33129
|
+
const events = parseEventLogs({
|
|
33130
|
+
logs: receipt.logs,
|
|
33131
|
+
abi,
|
|
33132
|
+
eventName: mapping.event,
|
|
33133
|
+
strict: true
|
|
33134
|
+
// Only return logs that conform to the ABI
|
|
33135
|
+
});
|
|
33136
|
+
if (events.length === 0) {
|
|
33137
|
+
throw new BlockchainError(
|
|
33138
|
+
`No ${mapping.event} event found in transaction ${hash}. Transaction may have failed or reverted.`
|
|
33139
|
+
);
|
|
33140
|
+
}
|
|
33141
|
+
if (events.length > 1) {
|
|
33142
|
+
console.warn(
|
|
33143
|
+
`\u26A0\uFE0F Multiple ${mapping.event} events found in transaction ${hash}. Using the first one.`
|
|
33144
|
+
);
|
|
33145
|
+
}
|
|
33146
|
+
const event = events[0];
|
|
33147
|
+
console.debug(`\u{1F389} Found ${mapping.event} event with args:`, event.args);
|
|
33148
|
+
return {
|
|
33149
|
+
...event.args,
|
|
33150
|
+
transactionHash: hash,
|
|
33151
|
+
blockNumber: receipt.blockNumber,
|
|
33152
|
+
gasUsed: receipt.gasUsed
|
|
33153
|
+
};
|
|
33154
|
+
} catch (error) {
|
|
33155
|
+
if (error instanceof BlockchainError || error instanceof NetworkError) {
|
|
33156
|
+
throw error;
|
|
33157
|
+
}
|
|
33158
|
+
if (error instanceof Error && error.message.includes("timeout")) {
|
|
33159
|
+
throw new NetworkError(
|
|
33160
|
+
`Transaction ${hash} confirmation timeout after 30 seconds. The transaction may still be pending.`,
|
|
33161
|
+
error
|
|
33162
|
+
);
|
|
33163
|
+
}
|
|
33164
|
+
throw new BlockchainError(
|
|
33165
|
+
`Failed to parse ${operation} transaction ${hash}: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
33166
|
+
error
|
|
33167
|
+
);
|
|
33168
|
+
}
|
|
33169
|
+
}
|
|
33170
|
+
|
|
33171
|
+
// src/config/addresses.ts
|
|
33172
|
+
var CONTRACTS = {
|
|
33173
|
+
// Core Platform Contracts
|
|
33174
|
+
DataPermissions: {
|
|
33175
|
+
addresses: {
|
|
33176
|
+
14800: "0x31fb1D48f6B2265A4cAD516BC39E96a18fb7c8de",
|
|
33177
|
+
1480: "0x31fb1D48f6B2265A4cAD516BC39E96a18fb7c8de"
|
|
33178
|
+
}
|
|
33179
|
+
},
|
|
33180
|
+
DataRegistry: {
|
|
33181
|
+
addresses: {
|
|
33182
|
+
14800: "0x8C8788f98385F6ba1adD4234e551ABba0f82Cb7C",
|
|
33183
|
+
1480: "0x8C8788f98385F6ba1adD4234e551ABba0f82Cb7C"
|
|
33184
|
+
}
|
|
33185
|
+
},
|
|
33186
|
+
TeePoolPhala: {
|
|
33187
|
+
addresses: {
|
|
33188
|
+
14800: "0xE8EC6BD73b23Ad40E6B9a6f4bD343FAc411bD99A",
|
|
33189
|
+
1480: "0xE8EC6BD73b23Ad40E6B9a6f4bD343FAc411bD99A"
|
|
33190
|
+
}
|
|
33191
|
+
},
|
|
33192
|
+
ComputeEngine: {
|
|
33193
|
+
addresses: {
|
|
33194
|
+
14800: "0xb2BFe33FA420c45F1Cf1287542ad81ae935447bd",
|
|
33195
|
+
1480: "0xb2BFe33FA420c45F1Cf1287542ad81ae935447bd"
|
|
33196
|
+
}
|
|
33197
|
+
},
|
|
33198
|
+
// Data Access Infrastructure
|
|
33199
|
+
DataRefinerRegistry: {
|
|
33200
|
+
addresses: {
|
|
33201
|
+
14800: "0x93c3EF89369fDcf08Be159D9DeF0F18AB6Be008c",
|
|
33202
|
+
1480: "0x93c3EF89369fDcf08Be159D9DeF0F18AB6Be008c"
|
|
33203
|
+
}
|
|
33204
|
+
},
|
|
33205
|
+
QueryEngine: {
|
|
33206
|
+
addresses: {
|
|
33207
|
+
14800: "0xd25Eb66EA2452cf3238A2eC6C1FD1B7F5B320490",
|
|
33208
|
+
1480: "0xd25Eb66EA2452cf3238A2eC6C1FD1B7F5B320490"
|
|
33209
|
+
}
|
|
33210
|
+
},
|
|
33211
|
+
VanaTreasury: {
|
|
33212
|
+
addresses: {
|
|
33213
|
+
14800: "0x94a1E56e555ac48d092f490fB10CDFaB434915eD",
|
|
33214
|
+
1480: "0x94a1E56e555ac48d092f490fB10CDFaB434915eD"
|
|
33215
|
+
}
|
|
33216
|
+
},
|
|
33217
|
+
ComputeInstructionRegistry: {
|
|
33218
|
+
addresses: {
|
|
33219
|
+
14800: "0x5786B12b4c6Ba2bFAF0e77Ed30Bf6d32805563A5",
|
|
33220
|
+
1480: "0x5786B12b4c6Ba2bFAF0e77Ed30Bf6d32805563A5"
|
|
33221
|
+
}
|
|
33222
|
+
},
|
|
33223
|
+
// TEE Pool Variants
|
|
33224
|
+
TeePoolEphemeralStandard: {
|
|
33225
|
+
addresses: {
|
|
33226
|
+
14800: "0xe124bae846D5ec157f75Bd9e68ca87C4d2AB835A",
|
|
33227
|
+
1480: "0xe124bae846D5ec157f75Bd9e68ca87C4d2AB835A"
|
|
33228
|
+
}
|
|
33229
|
+
},
|
|
33230
|
+
TeePoolPersistentStandard: {
|
|
33231
|
+
addresses: {
|
|
33232
|
+
14800: "0xe8bB8d0629651Cf33e0845d743976Dc1f0971d76",
|
|
33233
|
+
1480: "0xe8bB8d0629651Cf33e0845d743976Dc1f0971d76"
|
|
33234
|
+
}
|
|
33235
|
+
},
|
|
33236
|
+
TeePoolPersistentGpu: {
|
|
33237
|
+
addresses: {
|
|
33238
|
+
14800: "0x1c346Cd74f8551f8fa13f3F4b6b8dAE22338E6a9",
|
|
33239
|
+
1480: "0x1c346Cd74f8551f8fa13f3F4b6b8dAE22338E6a9"
|
|
33240
|
+
}
|
|
33241
|
+
},
|
|
33242
|
+
TeePoolDedicatedStandard: {
|
|
33243
|
+
addresses: {
|
|
33244
|
+
14800: "0xf024b7ac5E8417416f53B41ecfa58C8e9396687d",
|
|
33245
|
+
1480: "0xf024b7ac5E8417416f53B41ecfa58C8e9396687d"
|
|
33246
|
+
}
|
|
33247
|
+
},
|
|
33248
|
+
TeePoolDedicatedGpu: {
|
|
33249
|
+
addresses: {
|
|
33250
|
+
14800: "0xB1686FA9620bBf851714d1cB47b8a4Bf4664644E",
|
|
33251
|
+
1480: "0xB1686FA9620bBf851714d1cB47b8a4Bf4664644E"
|
|
33252
|
+
}
|
|
33253
|
+
},
|
|
33254
|
+
// DLP Reward System
|
|
33255
|
+
VanaEpoch: {
|
|
33256
|
+
addresses: {
|
|
33257
|
+
14800: "0x2063cFF0609D59bCCc196E20Eb58A8696a6b15A0",
|
|
33258
|
+
1480: "0x2063cFF0609D59bCCc196E20Eb58A8696a6b15A0"
|
|
33259
|
+
}
|
|
33260
|
+
},
|
|
33261
|
+
DLPRegistry: {
|
|
33262
|
+
addresses: {
|
|
33263
|
+
14800: "0x4D59880a924526d1dD33260552Ff4328b1E18a43",
|
|
33264
|
+
1480: "0x4D59880a924526d1dD33260552Ff4328b1E18a43"
|
|
33265
|
+
}
|
|
33266
|
+
},
|
|
33267
|
+
DLPRegistryTreasury: {
|
|
33268
|
+
addresses: {
|
|
33269
|
+
14800: "0xb12ce1d27bEeFe39b6F0110b1AB77C21Aa0c9F9a",
|
|
33270
|
+
1480: "0xb12ce1d27bEeFe39b6F0110b1AB77C21Aa0c9F9a"
|
|
33271
|
+
}
|
|
33272
|
+
},
|
|
33273
|
+
DLPPerformance: {
|
|
33274
|
+
addresses: {
|
|
33275
|
+
14800: "0x847715C7DB37cF286611182Be0bD333cbfa29cc1",
|
|
33276
|
+
1480: "0x847715C7DB37cF286611182Be0bD333cbfa29cc1"
|
|
33277
|
+
}
|
|
33278
|
+
},
|
|
33279
|
+
DLPRewardDeployer: {
|
|
33280
|
+
addresses: {
|
|
33281
|
+
14800: "0xEFD0F9Ba9De70586b7c4189971cF754adC923B04",
|
|
33282
|
+
1480: "0xEFD0F9Ba9De70586b7c4189971cF754adC923B04"
|
|
33283
|
+
}
|
|
33284
|
+
},
|
|
33285
|
+
DLPRewardDeployerTreasury: {
|
|
33286
|
+
addresses: {
|
|
33287
|
+
14800: "0xb547ca8Fe4990fe330FeAeb1C2EBb42F925Af5b8",
|
|
33288
|
+
1480: "0xb547ca8Fe4990fe330FeAeb1C2EBb42F925Af5b8"
|
|
33289
|
+
}
|
|
33290
|
+
},
|
|
33291
|
+
DLPRewardSwap: {
|
|
33292
|
+
addresses: {
|
|
33293
|
+
14800: "0x7c6862C46830F0fc3bF3FF509EA1bD0EE7267fB0",
|
|
33294
|
+
1480: "0x7c6862C46830F0fc3bF3FF509EA1bD0EE7267fB0"
|
|
33295
|
+
}
|
|
33296
|
+
},
|
|
33297
|
+
SwapHelper: {
|
|
33298
|
+
addresses: {
|
|
33299
|
+
14800: "0x55D5e6F73326315bF2E091e97F04f0770e5C54e2",
|
|
33300
|
+
1480: "0x55D5e6F73326315bF2E091e97F04f0770e5C54e2"
|
|
33301
|
+
}
|
|
33302
|
+
},
|
|
33303
|
+
// VanaPool (Staking)
|
|
33304
|
+
VanaPoolStaking: {
|
|
33305
|
+
addresses: {
|
|
33306
|
+
14800: "0x641C18E2F286c86f96CE95C8ec1EB9fC0415Ca0e",
|
|
33307
|
+
1480: "0x641C18E2F286c86f96CE95C8ec1EB9fC0415Ca0e"
|
|
33308
|
+
}
|
|
33309
|
+
},
|
|
33310
|
+
VanaPoolEntity: {
|
|
33311
|
+
addresses: {
|
|
33312
|
+
14800: "0x44f20490A82e1f1F1cC25Dd3BA8647034eDdce30",
|
|
33313
|
+
1480: "0x44f20490A82e1f1F1cC25Dd3BA8647034eDdce30"
|
|
33314
|
+
}
|
|
33315
|
+
},
|
|
33316
|
+
VanaPoolTreasury: {
|
|
33317
|
+
addresses: {
|
|
33318
|
+
14800: "0x143BE72CF2541604A7691933CAccd6D9cC17c003",
|
|
33319
|
+
1480: "0x143BE72CF2541604A7691933CAccd6D9cC17c003"
|
|
33320
|
+
}
|
|
33321
|
+
},
|
|
33322
|
+
// DLP Deployment Contracts
|
|
33323
|
+
DAT: {
|
|
33324
|
+
addresses: {
|
|
33325
|
+
14800: "0xA706b93ccED89f13340673889e29F0a5cd84212d",
|
|
33326
|
+
1480: "0xA706b93ccED89f13340673889e29F0a5cd84212d"
|
|
33327
|
+
}
|
|
33328
|
+
},
|
|
33329
|
+
DATFactory: {
|
|
33330
|
+
addresses: {
|
|
33331
|
+
14800: "0x40f8bccF35a75ecef63BC3B1B3E06ffEB9220644",
|
|
33332
|
+
1480: "0x40f8bccF35a75ecef63BC3B1B3E06ffEB9220644"
|
|
33333
|
+
}
|
|
33334
|
+
},
|
|
33335
|
+
DATPausable: {
|
|
33336
|
+
addresses: {
|
|
33337
|
+
14800: "0xe69FE86f0B95cC2f8416Fe22815c85DC8887e76e",
|
|
33338
|
+
1480: "0xe69FE86f0B95cC2f8416Fe22815c85DC8887e76e"
|
|
33339
|
+
}
|
|
33340
|
+
},
|
|
33341
|
+
DATVotes: {
|
|
33342
|
+
addresses: {
|
|
33343
|
+
14800: "0xaE04c8A77E9B27869eb563720524A9aE0baf1831",
|
|
33344
|
+
1480: "0xaE04c8A77E9B27869eb563720524A9aE0baf1831"
|
|
33345
|
+
}
|
|
33346
|
+
},
|
|
33347
|
+
// Utility Contracts (no ABIs in SDK)
|
|
33348
|
+
Multicall3: {
|
|
33349
|
+
addresses: {
|
|
33350
|
+
14800: "0xD8d2dFca27E8797fd779F8547166A2d3B29d360E",
|
|
33351
|
+
1480: "0xD8d2dFca27E8797fd779F8547166A2d3B29d360E"
|
|
33352
|
+
}
|
|
33353
|
+
},
|
|
33354
|
+
Multisend: {
|
|
33355
|
+
addresses: {
|
|
33356
|
+
14800: "0x8807e8BCDFbaA8c2761760f3FBA37F6f7F2C5b2d",
|
|
33357
|
+
1480: "0x8807e8BCDFbaA8c2761760f3FBA37F6f7F2C5b2d"
|
|
33358
|
+
}
|
|
33359
|
+
}
|
|
33360
|
+
};
|
|
33361
|
+
var LEGACY_CONTRACTS = {
|
|
33362
|
+
// DEPRECATED: Original Intel SGX TeePool (PRO-347)
|
|
33363
|
+
TeePool: {
|
|
33364
|
+
addresses: {
|
|
33365
|
+
14800: "0x3c92fD91639b41f13338CE62f19131e7d19eaa0D",
|
|
33366
|
+
1480: "0x3c92fD91639b41f13338CE62f19131e7d19eaa0D"
|
|
33367
|
+
}
|
|
33368
|
+
},
|
|
33369
|
+
// DEPRECATED: DLPRoot system (replaced by VanaPool + DLPRewards)
|
|
33370
|
+
DLPRootEpoch: {
|
|
33371
|
+
addresses: {
|
|
33372
|
+
14800: "0xc3d176cF6BccFCB9225b53B87a95147218e1537F",
|
|
33373
|
+
1480: "0xc3d176cF6BccFCB9225b53B87a95147218e1537F"
|
|
33374
|
+
}
|
|
33375
|
+
},
|
|
33376
|
+
DLPRootCore: {
|
|
33377
|
+
addresses: {
|
|
33378
|
+
14800: "0x0aBa5e28228c323A67712101d61a54d4ff5720FD",
|
|
33379
|
+
1480: "0x0aBa5e28228c323A67712101d61a54d4ff5720FD"
|
|
33380
|
+
}
|
|
33381
|
+
},
|
|
33382
|
+
DLPRoot: {
|
|
33383
|
+
addresses: {
|
|
33384
|
+
14800: "0xff14346dF2B8Fd0c95BF34f1c92e49417b508AD5",
|
|
33385
|
+
1480: "0xff14346dF2B8Fd0c95BF34f1c92e49417b508AD5"
|
|
33386
|
+
}
|
|
33387
|
+
},
|
|
33388
|
+
DLPRootMetrics: {
|
|
33389
|
+
addresses: {
|
|
33390
|
+
14800: "0xbb532917B6407c060Afd9Cb7d53527eCb91d6662",
|
|
33391
|
+
1480: "0xbb532917B6407c060Afd9Cb7d53527eCb91d6662"
|
|
33392
|
+
}
|
|
33393
|
+
},
|
|
33394
|
+
DLPRootStakesTreasury: {
|
|
33395
|
+
addresses: {
|
|
33396
|
+
14800: "0x52c3260ED5C235fcA43524CF508e29c897318775",
|
|
33397
|
+
1480: "0x52c3260ED5C235fcA43524CF508e29c897318775"
|
|
33398
|
+
}
|
|
33399
|
+
},
|
|
33400
|
+
DLPRootRewardsTreasury: {
|
|
33401
|
+
addresses: {
|
|
33402
|
+
14800: "0xDBFb6B8b9E2eCAEbdE64d665cD553dB81e524479",
|
|
33403
|
+
1480: "0xDBFb6B8b9E2eCAEbdE64d665cD553dB81e524479"
|
|
33404
|
+
}
|
|
33405
|
+
}
|
|
33406
|
+
};
|
|
33407
|
+
var CONTRACT_ADDRESSES = {
|
|
33408
|
+
14800: Object.fromEntries(
|
|
33409
|
+
Object.entries(CONTRACTS).map(([name, info]) => [name, info.addresses[14800]]).filter(([, addr]) => addr)
|
|
33410
|
+
),
|
|
33411
|
+
1480: Object.fromEntries(
|
|
33412
|
+
Object.entries(CONTRACTS).map(([name, info]) => [name, info.addresses[1480]]).filter(([, addr]) => addr)
|
|
33413
|
+
)
|
|
33414
|
+
};
|
|
33415
|
+
var UTILITY_ADDRESSES = {
|
|
33416
|
+
14800: {
|
|
33417
|
+
Multicall3: CONTRACTS.Multicall3.addresses[14800],
|
|
33418
|
+
Multisend: CONTRACTS.Multisend.addresses[14800]
|
|
33419
|
+
},
|
|
33420
|
+
1480: {
|
|
33421
|
+
Multicall3: CONTRACTS.Multicall3.addresses[1480],
|
|
33422
|
+
Multisend: CONTRACTS.Multisend.addresses[1480]
|
|
33423
|
+
}
|
|
33424
|
+
};
|
|
33425
|
+
var LEGACY_ADDRESSES = {
|
|
33426
|
+
14800: Object.fromEntries(
|
|
33427
|
+
Object.entries(LEGACY_CONTRACTS).map(([name, info]) => [name, info.addresses[14800]]).filter(([, addr]) => addr)
|
|
33428
|
+
),
|
|
33429
|
+
1480: Object.fromEntries(
|
|
33430
|
+
Object.entries(LEGACY_CONTRACTS).map(([name, info]) => [name, info.addresses[1480]]).filter(([, addr]) => addr)
|
|
33431
|
+
)
|
|
33432
|
+
};
|
|
33433
|
+
var getContractAddress = (chainId, contract) => {
|
|
33434
|
+
const contractAddress = CONTRACT_ADDRESSES[chainId]?.[contract];
|
|
33435
|
+
if (!contractAddress) {
|
|
33436
|
+
throw new Error(
|
|
33437
|
+
`Contract address not found for ${contract} on chain ${chainId}`
|
|
33438
|
+
);
|
|
33439
|
+
}
|
|
33440
|
+
return contractAddress;
|
|
33441
|
+
};
|
|
33442
|
+
|
|
33279
33443
|
// src/utils/grantFiles.ts
|
|
33280
33444
|
import { keccak256, toHex } from "viem";
|
|
33281
33445
|
function createGrantFile(params) {
|
|
@@ -33677,6 +33841,91 @@ function validateOperationAccess(grantFile, requestedOperation) {
|
|
|
33677
33841
|
}
|
|
33678
33842
|
}
|
|
33679
33843
|
|
|
33844
|
+
// src/utils/signatureCache.ts
|
|
33845
|
+
init_crypto_utils();
|
|
33846
|
+
var SignatureCache = class {
|
|
33847
|
+
/**
|
|
33848
|
+
* Get a cached signature if it exists and hasn't expired
|
|
33849
|
+
*/
|
|
33850
|
+
static get(cache, walletAddress, messageHash) {
|
|
33851
|
+
const key = this.getCacheKey(walletAddress, messageHash);
|
|
33852
|
+
try {
|
|
33853
|
+
const stored = cache.get(key);
|
|
33854
|
+
if (!stored) return null;
|
|
33855
|
+
const cached = JSON.parse(stored);
|
|
33856
|
+
if (Date.now() > cached.expires) {
|
|
33857
|
+
cache.delete(key);
|
|
33858
|
+
return null;
|
|
33859
|
+
}
|
|
33860
|
+
return cached.signature;
|
|
33861
|
+
} catch {
|
|
33862
|
+
try {
|
|
33863
|
+
cache.delete(key);
|
|
33864
|
+
} catch {
|
|
33865
|
+
}
|
|
33866
|
+
return null;
|
|
33867
|
+
}
|
|
33868
|
+
}
|
|
33869
|
+
/**
|
|
33870
|
+
* Store a signature in the cache
|
|
33871
|
+
*/
|
|
33872
|
+
static set(cache, walletAddress, messageHash, signature, ttlHours = this.DEFAULT_TTL_HOURS) {
|
|
33873
|
+
const key = this.getCacheKey(walletAddress, messageHash);
|
|
33874
|
+
const cached = {
|
|
33875
|
+
signature,
|
|
33876
|
+
expires: Date.now() + ttlHours * 36e5
|
|
33877
|
+
// Convert hours to milliseconds
|
|
33878
|
+
};
|
|
33879
|
+
try {
|
|
33880
|
+
cache.set(key, JSON.stringify(cached));
|
|
33881
|
+
} catch {
|
|
33882
|
+
}
|
|
33883
|
+
}
|
|
33884
|
+
/**
|
|
33885
|
+
* Clear all cached signatures (useful for testing or explicit cleanup)
|
|
33886
|
+
*/
|
|
33887
|
+
static clear(cache) {
|
|
33888
|
+
try {
|
|
33889
|
+
cache.clear();
|
|
33890
|
+
} catch {
|
|
33891
|
+
}
|
|
33892
|
+
}
|
|
33893
|
+
static getCacheKey(walletAddress, messageHash) {
|
|
33894
|
+
return `${this.PREFIX}${walletAddress.toLowerCase()}:${messageHash}`;
|
|
33895
|
+
}
|
|
33896
|
+
static hashMessage(message) {
|
|
33897
|
+
const jsonString = JSON.stringify(message, this.bigIntReplacer);
|
|
33898
|
+
const base64Hash = toBase64(jsonString);
|
|
33899
|
+
const cleaned = base64Hash.replace(/[^a-zA-Z0-9]/g, "");
|
|
33900
|
+
if (cleaned.length > 32) {
|
|
33901
|
+
return cleaned.substring(0, 16) + cleaned.substring(cleaned.length - 16);
|
|
33902
|
+
}
|
|
33903
|
+
return cleaned.substring(0, 32);
|
|
33904
|
+
}
|
|
33905
|
+
/**
|
|
33906
|
+
* Custom JSON replacer that converts BigInt values to strings for serialization
|
|
33907
|
+
* This ensures deterministic cache key generation for EIP-712 typed data
|
|
33908
|
+
*/
|
|
33909
|
+
static bigIntReplacer(key, value) {
|
|
33910
|
+
if (typeof value === "bigint") {
|
|
33911
|
+
return `__BIGINT__${value.toString()}`;
|
|
33912
|
+
}
|
|
33913
|
+
return value;
|
|
33914
|
+
}
|
|
33915
|
+
};
|
|
33916
|
+
__publicField(SignatureCache, "PREFIX", "vana_sig_");
|
|
33917
|
+
__publicField(SignatureCache, "DEFAULT_TTL_HOURS", 2);
|
|
33918
|
+
async function withSignatureCache(cache, walletAddress, typedData, signFn, ttlHours) {
|
|
33919
|
+
const messageHash = SignatureCache.hashMessage(typedData);
|
|
33920
|
+
const cached = SignatureCache.get(cache, walletAddress, messageHash);
|
|
33921
|
+
if (cached) {
|
|
33922
|
+
return cached;
|
|
33923
|
+
}
|
|
33924
|
+
const signature = await signFn();
|
|
33925
|
+
SignatureCache.set(cache, walletAddress, messageHash, signature, ttlHours);
|
|
33926
|
+
return signature;
|
|
33927
|
+
}
|
|
33928
|
+
|
|
33680
33929
|
// src/controllers/permissions.ts
|
|
33681
33930
|
var PermissionsController = class {
|
|
33682
33931
|
constructor(context) {
|
|
@@ -33684,22 +33933,22 @@ var PermissionsController = class {
|
|
|
33684
33933
|
}
|
|
33685
33934
|
/**
|
|
33686
33935
|
* Grants permission for an application to access user data with gasless transactions.
|
|
33936
|
+
*
|
|
33937
|
+
* This method provides a complete end-to-end permission grant flow that returns
|
|
33938
|
+
* the permission ID and other relevant data immediately after successful submission.
|
|
33939
|
+
* For advanced users who need more control over the transaction lifecycle, use
|
|
33940
|
+
* `submitPermissionGrant()` instead.
|
|
33687
33941
|
*
|
|
33688
|
-
* @remarks
|
|
33689
|
-
* This method combines signature creation and gasless submission for a complete
|
|
33690
|
-
* end-to-end permission grant flow. It creates the grant file, stores it on IPFS,
|
|
33691
|
-
* generates an EIP-712 signature, and submits via relayer. The grant file contains
|
|
33692
|
-
* detailed parameters while the blockchain stores only a reference to enable
|
|
33693
|
-
* efficient permission queries.
|
|
33694
33942
|
* @param params - The permission grant configuration object
|
|
33695
|
-
* @returns
|
|
33943
|
+
* @returns Promise resolving to permission data from the PermissionAdded event
|
|
33696
33944
|
* @throws {RelayerError} When gasless transaction submission fails
|
|
33697
33945
|
* @throws {SignatureError} When user rejects the signature request
|
|
33698
33946
|
* @throws {SerializationError} When grant data cannot be serialized
|
|
33699
|
-
* @throws {BlockchainError} When permission grant
|
|
33947
|
+
* @throws {BlockchainError} When permission grant fails or event parsing fails
|
|
33948
|
+
* @throws {NetworkError} When transaction confirmation times out
|
|
33700
33949
|
* @example
|
|
33701
33950
|
* ```typescript
|
|
33702
|
-
* const
|
|
33951
|
+
* const result = await vana.permissions.grant({
|
|
33703
33952
|
* grantee: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36",
|
|
33704
33953
|
* operation: "llm_inference",
|
|
33705
33954
|
* parameters: {
|
|
@@ -33709,10 +33958,42 @@ var PermissionsController = class {
|
|
|
33709
33958
|
* },
|
|
33710
33959
|
* });
|
|
33711
33960
|
*
|
|
33712
|
-
* console.log(`Permission granted
|
|
33961
|
+
* console.log(`Permission ${result.permissionId} granted to ${result.user}`);
|
|
33962
|
+
* console.log(`Transaction: ${result.transactionHash}`);
|
|
33963
|
+
*
|
|
33964
|
+
* // Can immediately use the permission ID for other operations
|
|
33965
|
+
* await vana.permissions.revoke({ permissionId: result.permissionId });
|
|
33713
33966
|
* ```
|
|
33714
33967
|
*/
|
|
33715
33968
|
async grant(params) {
|
|
33969
|
+
const txHash = await this.submitPermissionGrant(params);
|
|
33970
|
+
return parseTransactionResult(this.context, txHash, "grant");
|
|
33971
|
+
}
|
|
33972
|
+
/**
|
|
33973
|
+
* Submits a permission grant transaction and returns the transaction hash immediately.
|
|
33974
|
+
*
|
|
33975
|
+
* This is the lower-level method that provides maximum control over transaction timing.
|
|
33976
|
+
* Use this when you want to handle transaction confirmation and event parsing separately,
|
|
33977
|
+
* or when submitting multiple transactions in batch.
|
|
33978
|
+
*
|
|
33979
|
+
* @param params - The permission grant configuration object
|
|
33980
|
+
* @returns Promise that resolves to the transaction hash when successfully submitted
|
|
33981
|
+
* @throws {RelayerError} When gasless transaction submission fails
|
|
33982
|
+
* @throws {SignatureError} When user rejects the signature request
|
|
33983
|
+
* @throws {SerializationError} When grant data cannot be serialized
|
|
33984
|
+
* @throws {BlockchainError} When permission grant preparation fails
|
|
33985
|
+
* @example
|
|
33986
|
+
* ```typescript
|
|
33987
|
+
* // Submit transaction and handle confirmation later
|
|
33988
|
+
* const txHash = await vana.permissions.submitPermissionGrant(params);
|
|
33989
|
+
* console.log(`Transaction submitted: ${txHash}`);
|
|
33990
|
+
*
|
|
33991
|
+
* // Later, when you need the permission data:
|
|
33992
|
+
* const result = await parseTransactionResult(context, txHash, 'grant');
|
|
33993
|
+
* console.log(`Permission ID: ${result.permissionId}`);
|
|
33994
|
+
* ```
|
|
33995
|
+
*/
|
|
33996
|
+
async submitPermissionGrant(params) {
|
|
33716
33997
|
const { typedData, signature } = await this.createAndSign(params);
|
|
33717
33998
|
return await this.submitSignedGrant(typedData, signature);
|
|
33718
33999
|
}
|
|
@@ -34129,23 +34410,52 @@ var PermissionsController = class {
|
|
|
34129
34410
|
}
|
|
34130
34411
|
/**
|
|
34131
34412
|
* Revokes a previously granted permission.
|
|
34413
|
+
*
|
|
34414
|
+
* This method provides complete revocation with automatic event parsing to confirm
|
|
34415
|
+
* the permission was successfully revoked. For advanced users who need more control,
|
|
34416
|
+
* use `submitPermissionRevoke()` instead.
|
|
34132
34417
|
*
|
|
34133
34418
|
* @param params - Parameters for revoking the permission
|
|
34134
|
-
* @
|
|
34419
|
+
* @param params.permissionId - Permission identifier as bigint for contract compatibility.
|
|
34420
|
+
* Obtain from permission grants via `getUserPermissionGrantsOnChain()`.
|
|
34421
|
+
* @returns Promise resolving to revocation data from PermissionRevoked event
|
|
34422
|
+
* @throws {BlockchainError} When revocation fails or event parsing fails
|
|
34423
|
+
* @throws {UserRejectedRequestError} When user rejects the transaction
|
|
34424
|
+
* @throws {NetworkError} When transaction confirmation times out
|
|
34135
34425
|
* @example
|
|
34136
34426
|
* ```typescript
|
|
34137
|
-
* // Revoke a permission
|
|
34138
|
-
* const
|
|
34427
|
+
* // Revoke a permission and get confirmation
|
|
34428
|
+
* const result = await vana.permissions.revoke({
|
|
34139
34429
|
* permissionId: 123n
|
|
34140
34430
|
* });
|
|
34141
|
-
* console.log(
|
|
34142
|
-
*
|
|
34143
|
-
* // Wait for confirmation if needed
|
|
34144
|
-
* const receipt = await vana.core.waitForTransaction(txHash);
|
|
34145
|
-
* console.log('Revocation confirmed in block:', receipt.blockNumber);
|
|
34431
|
+
* console.log(`Permission ${result.permissionId} revoked in transaction ${result.transactionHash}`);
|
|
34432
|
+
* console.log(`Revoked in block ${result.blockNumber}`);
|
|
34146
34433
|
* ```
|
|
34147
34434
|
*/
|
|
34148
34435
|
async revoke(params) {
|
|
34436
|
+
const txHash = await this.submitPermissionRevoke(params);
|
|
34437
|
+
return parseTransactionResult(this.context, txHash, "revoke");
|
|
34438
|
+
}
|
|
34439
|
+
/**
|
|
34440
|
+
* Submits a permission revocation transaction and returns the transaction hash immediately.
|
|
34441
|
+
*
|
|
34442
|
+
* This is the lower-level method that provides maximum control over transaction timing.
|
|
34443
|
+
* Use this when you want to handle transaction confirmation and event parsing separately.
|
|
34444
|
+
*
|
|
34445
|
+
* @param params - Parameters for revoking the permission
|
|
34446
|
+
* @returns Promise resolving to the transaction hash when successfully submitted
|
|
34447
|
+
* @throws {BlockchainError} When revocation transaction fails
|
|
34448
|
+
* @throws {UserRejectedRequestError} When user rejects the transaction
|
|
34449
|
+
* @example
|
|
34450
|
+
* ```typescript
|
|
34451
|
+
* // Submit revocation and handle confirmation later
|
|
34452
|
+
* const txHash = await vana.permissions.submitPermissionRevoke({
|
|
34453
|
+
* permissionId: 123n
|
|
34454
|
+
* });
|
|
34455
|
+
* console.log(`Revocation submitted: ${txHash}`);
|
|
34456
|
+
* ```
|
|
34457
|
+
*/
|
|
34458
|
+
async submitPermissionRevoke(params) {
|
|
34149
34459
|
try {
|
|
34150
34460
|
if (!this.context.walletClient.chain?.id) {
|
|
34151
34461
|
throw new BlockchainError("Chain ID not available");
|
|
@@ -34311,17 +34621,24 @@ var PermissionsController = class {
|
|
|
34311
34621
|
};
|
|
34312
34622
|
}
|
|
34313
34623
|
/**
|
|
34314
|
-
* Signs typed data using the wallet client.
|
|
34624
|
+
* Signs typed data using the wallet client with signature caching.
|
|
34315
34625
|
*
|
|
34316
34626
|
* @param typedData - The EIP-712 typed data structure to sign
|
|
34317
34627
|
* @returns Promise resolving to the cryptographic signature
|
|
34318
34628
|
*/
|
|
34319
34629
|
async signTypedData(typedData) {
|
|
34320
34630
|
try {
|
|
34321
|
-
const
|
|
34322
|
-
|
|
34631
|
+
const walletAddress = this.context.walletClient.account?.address || await this.getUserAddress();
|
|
34632
|
+
return await withSignatureCache(
|
|
34633
|
+
this.context.platform.cache,
|
|
34634
|
+
walletAddress,
|
|
34635
|
+
typedData,
|
|
34636
|
+
async () => {
|
|
34637
|
+
return await this.context.walletClient.signTypedData(
|
|
34638
|
+
typedData
|
|
34639
|
+
);
|
|
34640
|
+
}
|
|
34323
34641
|
);
|
|
34324
|
-
return signature;
|
|
34325
34642
|
} catch (error) {
|
|
34326
34643
|
if (error instanceof Error && error.message.includes("rejected")) {
|
|
34327
34644
|
throw new UserRejectedRequestError();
|
|
@@ -35155,15 +35472,22 @@ import { getContract, decodeEventLog } from "viem";
|
|
|
35155
35472
|
|
|
35156
35473
|
// src/utils/encryption.ts
|
|
35157
35474
|
var DEFAULT_ENCRYPTION_SEED = "Please sign to retrieve your encryption key";
|
|
35158
|
-
async function generateEncryptionKey(wallet, seed = DEFAULT_ENCRYPTION_SEED) {
|
|
35475
|
+
async function generateEncryptionKey(wallet, platformAdapter, seed = DEFAULT_ENCRYPTION_SEED) {
|
|
35159
35476
|
if (!wallet.account) {
|
|
35160
35477
|
throw new Error("Wallet account is required for encryption key generation");
|
|
35161
35478
|
}
|
|
35162
|
-
const
|
|
35163
|
-
|
|
35164
|
-
|
|
35165
|
-
|
|
35166
|
-
|
|
35479
|
+
const messageData = { message: seed };
|
|
35480
|
+
return await withSignatureCache(
|
|
35481
|
+
platformAdapter.cache,
|
|
35482
|
+
wallet.account.address,
|
|
35483
|
+
messageData,
|
|
35484
|
+
async () => {
|
|
35485
|
+
return await wallet.signMessage({
|
|
35486
|
+
account: wallet.account,
|
|
35487
|
+
message: seed
|
|
35488
|
+
});
|
|
35489
|
+
}
|
|
35490
|
+
);
|
|
35167
35491
|
}
|
|
35168
35492
|
async function encryptWithWalletPublicKey(data, publicKey, platformAdapter) {
|
|
35169
35493
|
try {
|
|
@@ -35272,7 +35596,8 @@ var DataController = class {
|
|
|
35272
35596
|
schemaId,
|
|
35273
35597
|
permissions = [],
|
|
35274
35598
|
encrypt: encrypt2 = true,
|
|
35275
|
-
providerName
|
|
35599
|
+
providerName,
|
|
35600
|
+
owner
|
|
35276
35601
|
} = params;
|
|
35277
35602
|
try {
|
|
35278
35603
|
let blob;
|
|
@@ -35327,6 +35652,7 @@ var DataController = class {
|
|
|
35327
35652
|
if (encrypt2) {
|
|
35328
35653
|
const encryptionKey = await generateEncryptionKey(
|
|
35329
35654
|
this.context.walletClient,
|
|
35655
|
+
this.context.platform,
|
|
35330
35656
|
DEFAULT_ENCRYPTION_SEED
|
|
35331
35657
|
);
|
|
35332
35658
|
finalBlob = await encryptBlobWithSignedKey(
|
|
@@ -35350,28 +35676,23 @@ var DataController = class {
|
|
|
35350
35676
|
filename,
|
|
35351
35677
|
providerName
|
|
35352
35678
|
);
|
|
35353
|
-
const userAddress = await this.getUserAddress();
|
|
35679
|
+
const userAddress = owner || await this.getUserAddress();
|
|
35354
35680
|
let encryptedPermissions = [];
|
|
35355
|
-
if (permissions.length > 0
|
|
35681
|
+
if (permissions.length > 0) {
|
|
35356
35682
|
const userEncryptionKey = await generateEncryptionKey(
|
|
35357
35683
|
this.context.walletClient,
|
|
35684
|
+
this.context.platform,
|
|
35358
35685
|
DEFAULT_ENCRYPTION_SEED
|
|
35359
35686
|
);
|
|
35360
35687
|
encryptedPermissions = await Promise.all(
|
|
35361
35688
|
permissions.map(async (permission) => {
|
|
35362
|
-
const publicKey = permission.publicKey;
|
|
35363
|
-
if (!publicKey) {
|
|
35364
|
-
throw new Error(
|
|
35365
|
-
`Public key required for permission to ${permission.grantee} when encryption is enabled`
|
|
35366
|
-
);
|
|
35367
|
-
}
|
|
35368
35689
|
const encryptedKey = await encryptWithWalletPublicKey(
|
|
35369
35690
|
userEncryptionKey,
|
|
35370
|
-
publicKey,
|
|
35691
|
+
permission.publicKey,
|
|
35371
35692
|
this.context.platform
|
|
35372
35693
|
);
|
|
35373
35694
|
return {
|
|
35374
|
-
account: permission.
|
|
35695
|
+
account: permission.account,
|
|
35375
35696
|
key: encryptedKey
|
|
35376
35697
|
};
|
|
35377
35698
|
})
|
|
@@ -35384,7 +35705,8 @@ var DataController = class {
|
|
|
35384
35705
|
url: uploadResult.url,
|
|
35385
35706
|
userAddress,
|
|
35386
35707
|
permissions: encryptedPermissions,
|
|
35387
|
-
schemaId: schemaId || 0
|
|
35708
|
+
schemaId: schemaId || 0,
|
|
35709
|
+
ownerAddress: owner
|
|
35388
35710
|
}
|
|
35389
35711
|
);
|
|
35390
35712
|
} else if (this.context.relayerCallbacks?.submitFileAddition) {
|
|
@@ -35474,6 +35796,7 @@ var DataController = class {
|
|
|
35474
35796
|
try {
|
|
35475
35797
|
const encryptionKey = await generateEncryptionKey(
|
|
35476
35798
|
this.context.walletClient,
|
|
35799
|
+
this.context.platform,
|
|
35477
35800
|
encryptionSeed || DEFAULT_ENCRYPTION_SEED
|
|
35478
35801
|
);
|
|
35479
35802
|
let encryptedBlob;
|
|
@@ -36857,6 +37180,7 @@ var DataController = class {
|
|
|
36857
37180
|
try {
|
|
36858
37181
|
const userEncryptionKey = await generateEncryptionKey(
|
|
36859
37182
|
this.context.walletClient,
|
|
37183
|
+
this.context.platform,
|
|
36860
37184
|
DEFAULT_ENCRYPTION_SEED
|
|
36861
37185
|
);
|
|
36862
37186
|
const encryptedData = await encryptBlobWithSignedKey(
|
|
@@ -36922,16 +37246,47 @@ var DataController = class {
|
|
|
36922
37246
|
* 1. Gets the user's encryption key
|
|
36923
37247
|
* 2. Encrypts the user's encryption key with the provided public key
|
|
36924
37248
|
* 3. Adds the permission to the file
|
|
37249
|
+
* 4. Returns the permission data from the blockchain event
|
|
37250
|
+
*
|
|
37251
|
+
* For advanced users who need more control over transaction timing,
|
|
37252
|
+
* use `submitFilePermission()` instead.
|
|
36925
37253
|
*
|
|
36926
37254
|
* @param fileId - The ID of the file to add permissions for
|
|
36927
37255
|
* @param account - The address of the account to grant permission to
|
|
36928
37256
|
* @param publicKey - The public key to encrypt the user's encryption key with
|
|
36929
|
-
* @returns Promise resolving to
|
|
37257
|
+
* @returns Promise resolving to permission data from PermissionGranted event
|
|
37258
|
+
* @example
|
|
37259
|
+
* ```typescript
|
|
37260
|
+
* const result = await vana.data.addPermissionToFile(fileId, account, publicKey);
|
|
37261
|
+
* console.log(`Permission granted to ${result.account} for file ${result.fileId}`);
|
|
37262
|
+
* console.log(`Transaction: ${result.transactionHash}`);
|
|
37263
|
+
* ```
|
|
36930
37264
|
*/
|
|
36931
37265
|
async addPermissionToFile(fileId, account, publicKey) {
|
|
37266
|
+
const txHash = await this.submitFilePermission(fileId, account, publicKey);
|
|
37267
|
+
return parseTransactionResult(this.context, txHash, "addFilePermission");
|
|
37268
|
+
}
|
|
37269
|
+
/**
|
|
37270
|
+
* Submits a file permission transaction and returns the transaction hash immediately.
|
|
37271
|
+
*
|
|
37272
|
+
* This is the lower-level method that provides maximum control over transaction timing.
|
|
37273
|
+
* Use this when you want to handle transaction confirmation and event parsing separately.
|
|
37274
|
+
*
|
|
37275
|
+
* @param fileId - The ID of the file to add permissions for
|
|
37276
|
+
* @param account - The address of the account to grant permission to
|
|
37277
|
+
* @param publicKey - The public key to encrypt the user's encryption key with
|
|
37278
|
+
* @returns Promise resolving to the transaction hash
|
|
37279
|
+
* @example
|
|
37280
|
+
* ```typescript
|
|
37281
|
+
* const txHash = await vana.data.submitFilePermission(fileId, account, publicKey);
|
|
37282
|
+
* console.log(`Transaction submitted: ${txHash}`);
|
|
37283
|
+
* ```
|
|
37284
|
+
*/
|
|
37285
|
+
async submitFilePermission(fileId, account, publicKey) {
|
|
36932
37286
|
try {
|
|
36933
37287
|
const userEncryptionKey = await generateEncryptionKey(
|
|
36934
37288
|
this.context.walletClient,
|
|
37289
|
+
this.context.platform,
|
|
36935
37290
|
DEFAULT_ENCRYPTION_SEED
|
|
36936
37291
|
);
|
|
36937
37292
|
const encryptedKey = await encryptWithWalletPublicKey(
|
|
@@ -37645,6 +38000,39 @@ var ServerController = class {
|
|
|
37645
38000
|
this.context = context;
|
|
37646
38001
|
__publicField(this, "PERSONAL_SERVER_BASE_URL", process.env.NEXT_PUBLIC_PERSONAL_SERVER_BASE_URL);
|
|
37647
38002
|
}
|
|
38003
|
+
/**
|
|
38004
|
+
* Retrieves the cryptographic identity of a personal server.
|
|
38005
|
+
*
|
|
38006
|
+
* @remarks
|
|
38007
|
+
* This method fetches the public key and metadata for a personal server,
|
|
38008
|
+
* which is required for encrypting data before sharing with the server.
|
|
38009
|
+
* The identity includes the server's public key, address, and operational
|
|
38010
|
+
* details needed for secure communication. This information is cached
|
|
38011
|
+
* by identity servers to enable offline key retrieval.
|
|
38012
|
+
*
|
|
38013
|
+
* @param request - Parameters containing the user address
|
|
38014
|
+
* @param request.userAddress - The wallet address associated with the personal server
|
|
38015
|
+
* @returns Promise resolving to the server's identity information
|
|
38016
|
+
* @throws {NetworkError} When the identity service is unavailable or returns invalid data
|
|
38017
|
+
* @throws {PersonalServerError} When server identity cannot be retrieved
|
|
38018
|
+
* @example
|
|
38019
|
+
* ```typescript
|
|
38020
|
+
* // Get server identity for data encryption
|
|
38021
|
+
* const identity = await vana.server.getIdentity({
|
|
38022
|
+
* userAddress: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36"
|
|
38023
|
+
* });
|
|
38024
|
+
*
|
|
38025
|
+
* console.log(`Server: ${identity.name}`);
|
|
38026
|
+
* console.log(`Address: ${identity.address}`);
|
|
38027
|
+
* console.log(`Public Key: ${identity.public_key}`);
|
|
38028
|
+
*
|
|
38029
|
+
* // Use the public key for encrypting data to share with this server
|
|
38030
|
+
* const encryptedData = await encryptWithWalletPublicKey(
|
|
38031
|
+
* userData,
|
|
38032
|
+
* identity.public_key
|
|
38033
|
+
* );
|
|
38034
|
+
* ```
|
|
38035
|
+
*/
|
|
37648
38036
|
async getIdentity(request) {
|
|
37649
38037
|
try {
|
|
37650
38038
|
const response = await fetch(
|
|
@@ -37687,10 +38075,13 @@ var ServerController = class {
|
|
|
37687
38075
|
* This method submits a computation request to the personal server API.
|
|
37688
38076
|
* The response includes the operation ID.
|
|
37689
38077
|
* @param params - The request parameters object
|
|
37690
|
-
* @param params.permissionId - The permission ID authorizing this operation
|
|
38078
|
+
* @param params.permissionId - The permission ID authorizing this operation.
|
|
38079
|
+
* Obtain from granted permissions via `vana.permissions.getUserPermissionGrantsOnChain()`.
|
|
37691
38080
|
* @returns A Promise that resolves to an operation response with status and control URLs
|
|
37692
|
-
* @throws {PersonalServerError} When server request fails or parameters are invalid
|
|
37693
|
-
*
|
|
38081
|
+
* @throws {PersonalServerError} When server request fails or parameters are invalid.
|
|
38082
|
+
* Verify permissionId exists and is active for the target server.
|
|
38083
|
+
* @throws {NetworkError} When personal server API communication fails.
|
|
38084
|
+
* Check server URL configuration and network connectivity.
|
|
37694
38085
|
* @example
|
|
37695
38086
|
* ```typescript
|
|
37696
38087
|
* const response = await vana.server.createOperation({
|
|
@@ -37792,6 +38183,50 @@ var ServerController = class {
|
|
|
37792
38183
|
);
|
|
37793
38184
|
}
|
|
37794
38185
|
}
|
|
38186
|
+
/**
|
|
38187
|
+
* Cancels a running operation on the personal server.
|
|
38188
|
+
*
|
|
38189
|
+
* @remarks
|
|
38190
|
+
* This method attempts to cancel an operation that is currently processing
|
|
38191
|
+
* on the personal server. The operation must be in a cancellable state
|
|
38192
|
+
* (typically `starting` or `processing`). Not all operations support
|
|
38193
|
+
* cancellation, and cancellation may not be immediate. The server will
|
|
38194
|
+
* attempt to stop the operation and update its status to `canceled`.
|
|
38195
|
+
*
|
|
38196
|
+
* **Cancellation Behavior:**
|
|
38197
|
+
* - Operations in `succeeded` or `failed` states cannot be canceled
|
|
38198
|
+
* - Some long-running operations may take time to respond to cancellation
|
|
38199
|
+
* - Always verify cancellation by polling the operation status afterward
|
|
38200
|
+
*
|
|
38201
|
+
* @param operationId - The unique identifier of the operation to cancel,
|
|
38202
|
+
* obtained from `createOperation()` response
|
|
38203
|
+
* @returns Promise that resolves when the cancellation request is accepted
|
|
38204
|
+
* @throws {PersonalServerError} When the operation cannot be canceled or doesn't exist.
|
|
38205
|
+
* Check operation status - it may already be completed or failed.
|
|
38206
|
+
* @throws {NetworkError} When unable to reach the personal server API.
|
|
38207
|
+
* Verify server URL and network connectivity.
|
|
38208
|
+
* @example
|
|
38209
|
+
* ```typescript
|
|
38210
|
+
* // Start a long-running operation
|
|
38211
|
+
* const operation = await vana.server.createOperation({
|
|
38212
|
+
* permissionId: 123
|
|
38213
|
+
* });
|
|
38214
|
+
*
|
|
38215
|
+
* // Cancel if needed
|
|
38216
|
+
* try {
|
|
38217
|
+
* await vana.server.cancelOperation(operation.id);
|
|
38218
|
+
* console.log("Cancellation requested");
|
|
38219
|
+
*
|
|
38220
|
+
* // Verify cancellation
|
|
38221
|
+
* const status = await vana.server.getOperation(operation.id);
|
|
38222
|
+
* if (status.status === "canceled") {
|
|
38223
|
+
* console.log("Operation successfully canceled");
|
|
38224
|
+
* }
|
|
38225
|
+
* } catch (error) {
|
|
38226
|
+
* console.error("Failed to cancel:", error);
|
|
38227
|
+
* }
|
|
38228
|
+
* ```
|
|
38229
|
+
*/
|
|
37795
38230
|
async cancelOperation(operationId) {
|
|
37796
38231
|
try {
|
|
37797
38232
|
const response = await fetch(
|
|
@@ -38095,7 +38530,8 @@ var ProtocolController = class {
|
|
|
38095
38530
|
* are actually deployed on the current network.
|
|
38096
38531
|
* @param contractName - The name of the Vana contract to retrieve (use const assertion for full typing)
|
|
38097
38532
|
* @returns An object containing the contract's address and fully typed ABI
|
|
38098
|
-
* @throws {ContractNotFoundError} When the contract is not deployed on the current chain
|
|
38533
|
+
* @throws {ContractNotFoundError} When the contract is not deployed on the current chain.
|
|
38534
|
+
* Verify contract name spelling and check current network with `getChainId()`.
|
|
38099
38535
|
* @example
|
|
38100
38536
|
* ```typescript
|
|
38101
38537
|
* // Get contract info with full type inference
|
|
@@ -38716,6 +39152,7 @@ var GoogleDriveStorage = class {
|
|
|
38716
39152
|
};
|
|
38717
39153
|
|
|
38718
39154
|
// src/storage/providers/ipfs.ts
|
|
39155
|
+
init_crypto_utils();
|
|
38719
39156
|
var IpfsStorage = class _IpfsStorage {
|
|
38720
39157
|
constructor(config) {
|
|
38721
39158
|
this.config = config;
|
|
@@ -38755,7 +39192,7 @@ var IpfsStorage = class _IpfsStorage {
|
|
|
38755
39192
|
* ```
|
|
38756
39193
|
*/
|
|
38757
39194
|
static forInfura(credentials) {
|
|
38758
|
-
const auth =
|
|
39195
|
+
const auth = toBase64(`${credentials.projectId}:${credentials.projectSecret}`);
|
|
38759
39196
|
return new _IpfsStorage({
|
|
38760
39197
|
apiEndpoint: "https://ipfs.infura.io:5001/api/v0/add",
|
|
38761
39198
|
gatewayUrl: "https://ipfs.infura.io/ipfs",
|
|
@@ -40047,15 +40484,35 @@ var VanaCore = class {
|
|
|
40047
40484
|
}
|
|
40048
40485
|
/**
|
|
40049
40486
|
* Encrypts data using the Vana protocol standard encryption.
|
|
40050
|
-
*
|
|
40487
|
+
*
|
|
40488
|
+
* @remarks
|
|
40489
|
+
* This method implements the Vana network's standard encryption protocol using
|
|
40490
|
+
* platform-appropriate cryptographic libraries. It automatically handles different
|
|
40491
|
+
* input types (string or Blob) and produces encrypted output suitable for secure
|
|
40492
|
+
* storage or transmission. The encryption is compatible with the network's
|
|
40493
|
+
* decryption protocols and can be decrypted by authorized parties.
|
|
40051
40494
|
*
|
|
40052
|
-
* @param data The data to encrypt (string or Blob)
|
|
40053
|
-
* @param key The key
|
|
40054
|
-
* @returns The encrypted data as Blob
|
|
40495
|
+
* @param data - The data to encrypt (string or Blob)
|
|
40496
|
+
* @param key - The encryption key (typically generated via `generateEncryptionKey`)
|
|
40497
|
+
* @returns The encrypted data as a Blob
|
|
40498
|
+
* @throws {Error} When encryption fails due to invalid key or data format
|
|
40055
40499
|
* @example
|
|
40056
40500
|
* ```typescript
|
|
40057
|
-
*
|
|
40058
|
-
*
|
|
40501
|
+
* import { generateEncryptionKey } from '@opendatalabs/vana-sdk/node';
|
|
40502
|
+
*
|
|
40503
|
+
* // Generate encryption key from wallet signature
|
|
40504
|
+
* const encryptionKey = await generateEncryptionKey(vana.walletClient);
|
|
40505
|
+
*
|
|
40506
|
+
* // Encrypt string data
|
|
40507
|
+
* const sensitiveData = "User's private information";
|
|
40508
|
+
* const encrypted = await vana.encryptBlob(sensitiveData, encryptionKey);
|
|
40509
|
+
*
|
|
40510
|
+
* // Encrypt file data
|
|
40511
|
+
* const fileBlob = new Blob([fileContent], { type: 'application/json' });
|
|
40512
|
+
* const encryptedFile = await vana.encryptBlob(fileBlob, encryptionKey);
|
|
40513
|
+
*
|
|
40514
|
+
* // Store encrypted data safely
|
|
40515
|
+
* await storageProvider.upload(encrypted, 'encrypted-data.bin');
|
|
40059
40516
|
* ```
|
|
40060
40517
|
*/
|
|
40061
40518
|
async encryptBlob(data, key) {
|
|
@@ -40063,16 +40520,52 @@ var VanaCore = class {
|
|
|
40063
40520
|
}
|
|
40064
40521
|
/**
|
|
40065
40522
|
* Decrypts data that was encrypted using the Vana protocol.
|
|
40066
|
-
*
|
|
40523
|
+
*
|
|
40524
|
+
* @remarks
|
|
40525
|
+
* This method decrypts data that was previously encrypted using the Vana network's
|
|
40526
|
+
* standard encryption protocol. It requires the same wallet signature that was used
|
|
40527
|
+
* for encryption and automatically uses the appropriate platform adapter for
|
|
40528
|
+
* cryptographic operations. The decrypted output maintains the original data format.
|
|
40067
40529
|
*
|
|
40068
|
-
* @param encryptedData The encrypted data (string or Blob)
|
|
40069
|
-
* @param walletSignature The wallet signature
|
|
40070
|
-
* @returns The decrypted data as Blob
|
|
40530
|
+
* @param encryptedData - The encrypted data (string or Blob)
|
|
40531
|
+
* @param walletSignature - The wallet signature used as decryption key
|
|
40532
|
+
* @returns The decrypted data as a Blob
|
|
40533
|
+
* @throws {Error} When decryption fails due to invalid signature or corrupted data
|
|
40071
40534
|
* @example
|
|
40072
40535
|
* ```typescript
|
|
40073
|
-
*
|
|
40074
|
-
*
|
|
40075
|
-
*
|
|
40536
|
+
* import { generateEncryptionKey } from '@opendatalabs/vana-sdk/node';
|
|
40537
|
+
*
|
|
40538
|
+
* // Retrieve encrypted data from storage
|
|
40539
|
+
* const encryptedBlob = await storageProvider.download('encrypted-data.bin');
|
|
40540
|
+
*
|
|
40541
|
+
* // Generate the same key used for encryption
|
|
40542
|
+
* const decryptionKey = await generateEncryptionKey(vana.walletClient);
|
|
40543
|
+
*
|
|
40544
|
+
* // Decrypt the data
|
|
40545
|
+
* const decrypted = await vana.decryptBlob(encryptedBlob, decryptionKey);
|
|
40546
|
+
*
|
|
40547
|
+
* // Convert back to original format
|
|
40548
|
+
* const originalText = await decrypted.text();
|
|
40549
|
+
* const originalJson = JSON.parse(originalText);
|
|
40550
|
+
*
|
|
40551
|
+
* console.log('Decrypted data:', originalJson);
|
|
40552
|
+
* ```
|
|
40553
|
+
*
|
|
40554
|
+
* @example
|
|
40555
|
+
* ```typescript
|
|
40556
|
+
* // Decrypt file downloaded from Vana network
|
|
40557
|
+
* const userFiles = await vana.data.getUserFiles();
|
|
40558
|
+
* const file = userFiles[0];
|
|
40559
|
+
*
|
|
40560
|
+
* // Download encrypted content
|
|
40561
|
+
* const encrypted = await fetch(file.url).then(r => r.blob());
|
|
40562
|
+
*
|
|
40563
|
+
* // Decrypt with user's key
|
|
40564
|
+
* const decryptionKey = await generateEncryptionKey(vana.walletClient);
|
|
40565
|
+
* const decrypted = await vana.decryptBlob(encrypted, decryptionKey);
|
|
40566
|
+
*
|
|
40567
|
+
* // Process original data
|
|
40568
|
+
* const fileContent = await decrypted.arrayBuffer();
|
|
40076
40569
|
* ```
|
|
40077
40570
|
*/
|
|
40078
40571
|
async decryptBlob(encryptedData, walletSignature) {
|
|
@@ -40917,6 +41410,7 @@ export {
|
|
|
40917
41410
|
SerializationError,
|
|
40918
41411
|
ServerController,
|
|
40919
41412
|
ServerUrlMismatchError,
|
|
41413
|
+
SignatureCache,
|
|
40920
41414
|
SignatureError,
|
|
40921
41415
|
StorageError,
|
|
40922
41416
|
StorageManager,
|
|
@@ -40987,6 +41481,7 @@ export {
|
|
|
40987
41481
|
validateGrantFile,
|
|
40988
41482
|
validateGranteeAccess,
|
|
40989
41483
|
validateOperationAccess,
|
|
40990
|
-
vanaMainnet2 as vanaMainnet
|
|
41484
|
+
vanaMainnet2 as vanaMainnet,
|
|
41485
|
+
withSignatureCache
|
|
40991
41486
|
};
|
|
40992
41487
|
//# sourceMappingURL=index.browser.js.map
|