@opendatalabs/vana-sdk 0.1.0-alpha.f2de4f7 → 0.1.0-alpha.f35bb9c
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/dist/browser.cjs.map +1 -1
- package/dist/browser.d.ts +33 -1
- package/dist/browser.js.map +1 -1
- package/dist/chains/index.cjs.map +1 -1
- package/dist/chains/index.d.ts +30 -1
- package/dist/chains/index.js.map +1 -1
- package/dist/config/chains.cjs.map +1 -1
- package/dist/config/chains.d.ts +99 -0
- package/dist/config/chains.js.map +1 -1
- package/dist/contracts/contractController.cjs.map +1 -1
- package/dist/contracts/contractController.d.ts +66 -10
- package/dist/contracts/contractController.js.map +1 -1
- package/dist/controllers/data.cjs +173 -141
- package/dist/controllers/data.cjs.map +1 -1
- package/dist/controllers/data.d.ts +213 -175
- package/dist/controllers/data.js +173 -141
- package/dist/controllers/data.js.map +1 -1
- package/dist/controllers/permissions.cjs +185 -191
- package/dist/controllers/permissions.cjs.map +1 -1
- package/dist/controllers/permissions.d.ts +29 -73
- package/dist/controllers/permissions.js +185 -191
- package/dist/controllers/permissions.js.map +1 -1
- package/dist/controllers/protocol.cjs.map +1 -1
- package/dist/controllers/protocol.d.ts +27 -28
- package/dist/controllers/protocol.js.map +1 -1
- package/dist/controllers/schemas.cjs +23 -21
- package/dist/controllers/schemas.cjs.map +1 -1
- package/dist/controllers/schemas.d.ts +47 -40
- package/dist/controllers/schemas.js +23 -21
- package/dist/controllers/schemas.js.map +1 -1
- package/dist/controllers/server.cjs +17 -15
- package/dist/controllers/server.cjs.map +1 -1
- package/dist/controllers/server.d.ts +46 -38
- package/dist/controllers/server.js +17 -15
- package/dist/controllers/server.js.map +1 -1
- package/dist/core/apiClient.cjs +53 -3
- package/dist/core/apiClient.cjs.map +1 -1
- package/dist/core/apiClient.d.ts +132 -7
- package/dist/core/apiClient.js +53 -3
- package/dist/core/apiClient.js.map +1 -1
- package/dist/core/generics.cjs +30 -3
- package/dist/core/generics.cjs.map +1 -1
- package/dist/core/generics.d.ts +95 -6
- package/dist/core/generics.js +30 -3
- package/dist/core/generics.js.map +1 -1
- package/dist/core.cjs +29 -12
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.ts +2 -1
- package/dist/core.js +29 -12
- package/dist/core.js.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.node.cjs +3 -3
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.d.ts +8 -9
- package/dist/index.node.js +2 -2
- package/dist/index.node.js.map +1 -1
- package/dist/node.cjs.map +1 -1
- package/dist/node.d.ts +39 -1
- package/dist/node.js.map +1 -1
- package/dist/platform/browser.cjs +160 -2
- package/dist/platform/browser.cjs.map +1 -1
- package/dist/platform/browser.d.ts +232 -12
- package/dist/platform/browser.js +160 -2
- package/dist/platform/browser.js.map +1 -1
- package/dist/platform/interface.cjs.map +1 -1
- package/dist/platform/interface.d.ts +283 -90
- package/dist/platform/node.cjs +163 -2
- package/dist/platform/node.cjs.map +1 -1
- package/dist/platform/node.d.ts +69 -6
- package/dist/platform/node.js +163 -2
- package/dist/platform/node.js.map +1 -1
- package/dist/server/relayerHandler.cjs +214 -0
- package/dist/server/relayerHandler.cjs.map +1 -0
- package/dist/server/relayerHandler.d.ts +36 -0
- package/dist/server/relayerHandler.js +190 -0
- package/dist/server/relayerHandler.js.map +1 -0
- package/dist/storage/manager.cjs +108 -25
- package/dist/storage/manager.cjs.map +1 -1
- package/dist/storage/manager.d.ts +119 -25
- package/dist/storage/manager.js +108 -25
- package/dist/storage/manager.js.map +1 -1
- package/dist/storage/providers/callback-storage.cjs +86 -15
- package/dist/storage/providers/callback-storage.cjs.map +1 -1
- package/dist/storage/providers/callback-storage.d.ts +109 -20
- package/dist/storage/providers/callback-storage.js +86 -15
- package/dist/storage/providers/callback-storage.js.map +1 -1
- package/dist/storage/providers/pinata.cjs.map +1 -1
- package/dist/storage/providers/pinata.d.ts +12 -14
- package/dist/storage/providers/pinata.js.map +1 -1
- package/dist/tests/factories/mockFactory.d.ts +2 -2
- package/dist/tests/relayer-integration.test.d.ts +1 -0
- package/dist/tests/relayer-unified.test.d.ts +1 -0
- package/dist/tests/server-relayer-handler.test.d.ts +1 -0
- package/dist/types/blockchain.cjs.map +1 -1
- package/dist/types/blockchain.d.ts +39 -11
- package/dist/types/chains.cjs.map +1 -1
- package/dist/types/chains.d.ts +74 -7
- package/dist/types/chains.js.map +1 -1
- package/dist/types/config.cjs.map +1 -1
- package/dist/types/config.d.ts +46 -191
- package/dist/types/config.js.map +1 -1
- package/dist/types/contracts.cjs.map +1 -1
- package/dist/types/contracts.d.ts +71 -7
- package/dist/types/controller-context.cjs.map +1 -1
- package/dist/types/controller-context.d.ts +3 -2
- package/dist/types/data.cjs.map +1 -1
- package/dist/types/data.d.ts +4 -6
- package/dist/types/generics.cjs.map +1 -1
- package/dist/types/generics.d.ts +80 -9
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.ts +27 -2
- package/dist/types/index.js.map +1 -1
- package/dist/types/operations.cjs.map +1 -1
- package/dist/types/operations.d.ts +132 -15
- package/dist/types/operations.js.map +1 -1
- package/dist/types/permissions.cjs.map +1 -1
- package/dist/types/permissions.d.ts +15 -20
- package/dist/types/personal.cjs.map +1 -1
- package/dist/types/personal.d.ts +131 -14
- package/dist/types/relayer.cjs.map +1 -1
- package/dist/types/relayer.d.ts +262 -35
- package/dist/types/storage.cjs.map +1 -1
- package/dist/types/storage.d.ts +9 -21
- package/dist/types/storage.js.map +1 -1
- package/dist/utils/grantFiles.cjs.map +1 -1
- package/dist/utils/grantFiles.d.ts +10 -20
- package/dist/utils/grantFiles.js.map +1 -1
- package/dist/utils/grantValidation.cjs.map +1 -1
- package/dist/utils/grantValidation.d.ts +95 -16
- package/dist/utils/grantValidation.js.map +1 -1
- package/dist/utils/grants.cjs.map +1 -1
- package/dist/utils/grants.d.ts +93 -12
- package/dist/utils/grants.js.map +1 -1
- package/dist/utils/lazy-import.cjs.map +1 -1
- package/dist/utils/lazy-import.d.ts +32 -7
- package/dist/utils/lazy-import.js.map +1 -1
- package/dist/utils/signatureCache.cjs +8 -2
- package/dist/utils/signatureCache.cjs.map +1 -1
- package/dist/utils/signatureCache.d.ts +49 -8
- package/dist/utils/signatureCache.js +8 -2
- package/dist/utils/signatureCache.js.map +1 -1
- package/dist/utils/transactionHelpers.cjs.map +1 -1
- package/dist/utils/transactionHelpers.d.ts +12 -12
- package/dist/utils/transactionHelpers.js.map +1 -1
- package/dist/utils/typedDataConverter.cjs.map +1 -1
- package/dist/utils/typedDataConverter.d.ts +39 -3
- package/dist/utils/typedDataConverter.js.map +1 -1
- package/dist/utils/urlResolver.cjs +7 -0
- package/dist/utils/urlResolver.cjs.map +1 -1
- package/dist/utils/urlResolver.d.ts +22 -4
- package/dist/utils/urlResolver.js +7 -0
- package/dist/utils/urlResolver.js.map +1 -1
- package/dist/utils/wallet.cjs +2 -1
- package/dist/utils/wallet.cjs.map +1 -1
- package/dist/utils/wallet.d.ts +78 -16
- package/dist/utils/wallet.js +2 -1
- package/dist/utils/wallet.js.map +1 -1
- package/package.json +1 -1
- package/dist/server/handler.cjs +0 -101
- package/dist/server/handler.cjs.map +0 -1
- package/dist/server/handler.d.ts +0 -87
- package/dist/server/handler.js +0 -77
- package/dist/server/handler.js.map +0 -1
- /package/dist/tests/{server-handler.test.d.ts → permissions-revoke-relayer.test.d.ts} +0 -0
|
@@ -186,17 +186,31 @@ class PermissionsController extends import_base.BaseController {
|
|
|
186
186
|
let { grantUrl } = params;
|
|
187
187
|
console.debug("\u{1F50D} Debug - Grant URL from params:", grantUrl);
|
|
188
188
|
if (!grantUrl) {
|
|
189
|
-
|
|
189
|
+
const canStoreViaRelayer = this.context.relayer !== void 0;
|
|
190
|
+
if (!canStoreViaRelayer && !this.context.storageManager) {
|
|
190
191
|
if (this.context.validateStorageRequired) {
|
|
191
192
|
this.context.validateStorageRequired();
|
|
192
193
|
} else {
|
|
193
194
|
throw new Error(
|
|
194
|
-
"No storage available. Provide a grantUrl, configure
|
|
195
|
+
"No storage available. Provide a grantUrl, configure relayer, or storageManager."
|
|
195
196
|
);
|
|
196
197
|
}
|
|
197
198
|
}
|
|
198
|
-
if (this.context.
|
|
199
|
-
|
|
199
|
+
if (canStoreViaRelayer && this.context.relayer) {
|
|
200
|
+
const request = {
|
|
201
|
+
type: "direct",
|
|
202
|
+
operation: "storeGrantFile",
|
|
203
|
+
params: grantFile
|
|
204
|
+
};
|
|
205
|
+
const response = await this.context.relayer(request);
|
|
206
|
+
if (response.type === "error") {
|
|
207
|
+
throw new Error(response.error);
|
|
208
|
+
}
|
|
209
|
+
if (response.type === "direct" && typeof response.result === "object" && "url" in response.result) {
|
|
210
|
+
grantUrl = response.result.url;
|
|
211
|
+
} else {
|
|
212
|
+
throw new Error("Invalid response from relayer for grant storage");
|
|
213
|
+
}
|
|
200
214
|
} else if (this.context.storageManager) {
|
|
201
215
|
const blob = new Blob([JSON.stringify(grantFile)], {
|
|
202
216
|
type: "application/json"
|
|
@@ -280,17 +294,31 @@ class PermissionsController extends import_base.BaseController {
|
|
|
280
294
|
let { grantUrl } = params;
|
|
281
295
|
console.debug("\u{1F50D} Debug - Grant URL from params:", grantUrl);
|
|
282
296
|
if (!grantUrl) {
|
|
283
|
-
|
|
297
|
+
const canStoreViaRelayer = this.context.relayer !== void 0;
|
|
298
|
+
if (!canStoreViaRelayer && !this.context.storageManager) {
|
|
284
299
|
if (this.context.validateStorageRequired) {
|
|
285
300
|
this.context.validateStorageRequired();
|
|
286
301
|
} else {
|
|
287
302
|
throw new Error(
|
|
288
|
-
"No storage available. Provide a grantUrl, configure
|
|
303
|
+
"No storage available. Provide a grantUrl, configure relayer, or storageManager."
|
|
289
304
|
);
|
|
290
305
|
}
|
|
291
306
|
}
|
|
292
|
-
if (this.context.
|
|
293
|
-
|
|
307
|
+
if (canStoreViaRelayer && this.context.relayer) {
|
|
308
|
+
const request = {
|
|
309
|
+
type: "direct",
|
|
310
|
+
operation: "storeGrantFile",
|
|
311
|
+
params: grantFile
|
|
312
|
+
};
|
|
313
|
+
const response = await this.context.relayer(request);
|
|
314
|
+
if (response.type === "error") {
|
|
315
|
+
throw new Error(response.error);
|
|
316
|
+
}
|
|
317
|
+
if (response.type === "direct" && typeof response.result === "object" && "url" in response.result) {
|
|
318
|
+
grantUrl = response.result.url;
|
|
319
|
+
} else {
|
|
320
|
+
throw new Error("Invalid response from relayer for grant storage");
|
|
321
|
+
}
|
|
294
322
|
} else if (this.context.storageManager) {
|
|
295
323
|
const blob = new Blob([JSON.stringify(grantFile)], {
|
|
296
324
|
type: "application/json"
|
|
@@ -369,11 +397,24 @@ class PermissionsController extends import_base.BaseController {
|
|
|
369
397
|
2
|
|
370
398
|
)
|
|
371
399
|
);
|
|
372
|
-
if (this.context.
|
|
373
|
-
const
|
|
400
|
+
if (this.context.relayer) {
|
|
401
|
+
const response = await this.context.relayer({
|
|
402
|
+
type: "signed",
|
|
403
|
+
operation: "submitAddPermission",
|
|
374
404
|
typedData,
|
|
375
|
-
signature
|
|
376
|
-
|
|
405
|
+
signature,
|
|
406
|
+
expectedUserAddress: this.context.userAddress
|
|
407
|
+
});
|
|
408
|
+
let hash;
|
|
409
|
+
if (response.type === "signed") {
|
|
410
|
+
hash = response.hash;
|
|
411
|
+
} else if (response.type === "error") {
|
|
412
|
+
throw new Error(`Relayer error: ${response.error}`);
|
|
413
|
+
} else {
|
|
414
|
+
throw new Error(
|
|
415
|
+
"Invalid response from relayer: expected signed transaction"
|
|
416
|
+
);
|
|
417
|
+
}
|
|
377
418
|
const account = this.context.walletClient?.account ?? this.context.userAddress;
|
|
378
419
|
const { tx } = await import("../utils/transactionHelpers");
|
|
379
420
|
return tx({
|
|
@@ -599,11 +640,23 @@ class PermissionsController extends import_base.BaseController {
|
|
|
599
640
|
async submitSignedRevoke(typedData, signature) {
|
|
600
641
|
try {
|
|
601
642
|
let hash;
|
|
602
|
-
if (this.context.
|
|
603
|
-
|
|
643
|
+
if (this.context.relayer) {
|
|
644
|
+
const response = await this.context.relayer({
|
|
645
|
+
type: "signed",
|
|
646
|
+
operation: "submitPermissionRevoke",
|
|
604
647
|
typedData,
|
|
605
|
-
signature
|
|
606
|
-
|
|
648
|
+
signature,
|
|
649
|
+
expectedUserAddress: this.context.userAddress
|
|
650
|
+
});
|
|
651
|
+
if (response.type === "signed") {
|
|
652
|
+
hash = response.hash;
|
|
653
|
+
} else if (response.type === "error") {
|
|
654
|
+
throw new Error(`Relayer error: ${response.error}`);
|
|
655
|
+
} else {
|
|
656
|
+
throw new Error(
|
|
657
|
+
"Invalid response from relayer: expected signed transaction"
|
|
658
|
+
);
|
|
659
|
+
}
|
|
607
660
|
} else {
|
|
608
661
|
hash = await this.submitDirectRevokeTransaction(
|
|
609
662
|
typedData,
|
|
@@ -652,11 +705,23 @@ class PermissionsController extends import_base.BaseController {
|
|
|
652
705
|
async submitSignedUntrustServer(typedData, signature) {
|
|
653
706
|
try {
|
|
654
707
|
let hash;
|
|
655
|
-
if (this.context.
|
|
656
|
-
|
|
708
|
+
if (this.context.relayer) {
|
|
709
|
+
const response = await this.context.relayer({
|
|
710
|
+
type: "signed",
|
|
711
|
+
operation: "submitUntrustServer",
|
|
657
712
|
typedData,
|
|
658
|
-
signature
|
|
659
|
-
|
|
713
|
+
signature,
|
|
714
|
+
expectedUserAddress: this.context.userAddress
|
|
715
|
+
});
|
|
716
|
+
if (response.type === "signed") {
|
|
717
|
+
hash = response.hash;
|
|
718
|
+
} else if (response.type === "error") {
|
|
719
|
+
throw new Error(`Relayer error: ${response.error}`);
|
|
720
|
+
} else {
|
|
721
|
+
throw new Error(
|
|
722
|
+
"Invalid response from relayer: expected signed transaction"
|
|
723
|
+
);
|
|
724
|
+
}
|
|
660
725
|
} else {
|
|
661
726
|
hash = await this.submitSignedUntrustTransaction(
|
|
662
727
|
typedData,
|
|
@@ -905,11 +970,23 @@ class PermissionsController extends import_base.BaseController {
|
|
|
905
970
|
};
|
|
906
971
|
const signature = await this.signTypedData(typedData);
|
|
907
972
|
let hash;
|
|
908
|
-
if (this.context.
|
|
909
|
-
|
|
973
|
+
if (this.context.relayer) {
|
|
974
|
+
const response = await this.context.relayer({
|
|
975
|
+
type: "signed",
|
|
976
|
+
operation: "submitPermissionRevoke",
|
|
910
977
|
typedData,
|
|
911
|
-
signature
|
|
912
|
-
|
|
978
|
+
signature,
|
|
979
|
+
expectedUserAddress: this.context.userAddress
|
|
980
|
+
});
|
|
981
|
+
if (response.type === "signed") {
|
|
982
|
+
hash = response.hash;
|
|
983
|
+
} else if (response.type === "error") {
|
|
984
|
+
throw new Error(`Relayer error: ${response.error}`);
|
|
985
|
+
} else {
|
|
986
|
+
throw new Error(
|
|
987
|
+
"Invalid response from relayer: expected signed transaction"
|
|
988
|
+
);
|
|
989
|
+
}
|
|
913
990
|
} else {
|
|
914
991
|
hash = await this.submitDirectRevokeTransaction(
|
|
915
992
|
typedData,
|
|
@@ -1503,11 +1580,22 @@ class PermissionsController extends import_base.BaseController {
|
|
|
1503
1580
|
const signature = await this.signTypedData(typedData);
|
|
1504
1581
|
console.debug("\u{1F50D} Generated signature:", signature);
|
|
1505
1582
|
let hash;
|
|
1506
|
-
if (this.context.
|
|
1507
|
-
|
|
1583
|
+
if (this.context.relayer) {
|
|
1584
|
+
const request = {
|
|
1585
|
+
type: "signed",
|
|
1586
|
+
operation: "submitAddAndTrustServer",
|
|
1508
1587
|
typedData,
|
|
1509
1588
|
signature
|
|
1510
|
-
|
|
1589
|
+
};
|
|
1590
|
+
const response = await this.context.relayer(request);
|
|
1591
|
+
if (response.type === "error") {
|
|
1592
|
+
throw new import_errors.RelayerError(response.error);
|
|
1593
|
+
}
|
|
1594
|
+
if (response.type === "signed") {
|
|
1595
|
+
hash = response.hash;
|
|
1596
|
+
} else {
|
|
1597
|
+
throw new Error("Unexpected response type from relayer");
|
|
1598
|
+
}
|
|
1511
1599
|
} else {
|
|
1512
1600
|
hash = await this.submitAddAndTrustServerTransaction(
|
|
1513
1601
|
addAndTrustServerInput,
|
|
@@ -1561,11 +1649,22 @@ class PermissionsController extends import_base.BaseController {
|
|
|
1561
1649
|
const typedData = await this.composeTrustServerMessage(trustServerInput);
|
|
1562
1650
|
const signature = await this.signTypedData(typedData);
|
|
1563
1651
|
let hash;
|
|
1564
|
-
if (this.context.
|
|
1565
|
-
|
|
1652
|
+
if (this.context.relayer) {
|
|
1653
|
+
const request = {
|
|
1654
|
+
type: "signed",
|
|
1655
|
+
operation: "submitTrustServer",
|
|
1566
1656
|
typedData,
|
|
1567
1657
|
signature
|
|
1568
|
-
|
|
1658
|
+
};
|
|
1659
|
+
const response = await this.context.relayer(request);
|
|
1660
|
+
if (response.type === "error") {
|
|
1661
|
+
throw new import_errors.RelayerError(response.error);
|
|
1662
|
+
}
|
|
1663
|
+
if (response.type === "signed") {
|
|
1664
|
+
hash = response.hash;
|
|
1665
|
+
} else {
|
|
1666
|
+
throw new Error("Unexpected response type from relayer");
|
|
1667
|
+
}
|
|
1569
1668
|
} else {
|
|
1570
1669
|
hash = await this.submitTrustServerTransaction(
|
|
1571
1670
|
trustServerInput,
|
|
@@ -1720,11 +1819,22 @@ class PermissionsController extends import_base.BaseController {
|
|
|
1720
1819
|
const typedData = await this.composeUntrustServerMessage(untrustServerInput);
|
|
1721
1820
|
const signature = await this.signTypedData(typedData);
|
|
1722
1821
|
let hash;
|
|
1723
|
-
if (this.context.
|
|
1724
|
-
|
|
1822
|
+
if (this.context.relayer) {
|
|
1823
|
+
const request = {
|
|
1824
|
+
type: "signed",
|
|
1825
|
+
operation: "submitUntrustServer",
|
|
1725
1826
|
typedData,
|
|
1726
1827
|
signature
|
|
1727
|
-
|
|
1828
|
+
};
|
|
1829
|
+
const response = await this.context.relayer(request);
|
|
1830
|
+
if (response.type === "error") {
|
|
1831
|
+
throw new import_errors.RelayerError(response.error);
|
|
1832
|
+
}
|
|
1833
|
+
if (response.type === "signed") {
|
|
1834
|
+
hash = response.hash;
|
|
1835
|
+
} else {
|
|
1836
|
+
throw new Error("Unexpected response type from relayer");
|
|
1837
|
+
}
|
|
1728
1838
|
} else {
|
|
1729
1839
|
hash = await this.submitSignedUntrustTransaction(typedData, signature);
|
|
1730
1840
|
}
|
|
@@ -2357,73 +2467,9 @@ class PermissionsController extends import_base.BaseController {
|
|
|
2357
2467
|
fn: "registerGrantee"
|
|
2358
2468
|
});
|
|
2359
2469
|
}
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
* @param params - Parameters for registering the grantee
|
|
2364
|
-
* @returns Promise resolving to the transaction hash
|
|
2365
|
-
*
|
|
2366
|
-
* @example
|
|
2367
|
-
* ```typescript
|
|
2368
|
-
* const txHash = await vana.permissions.registerGranteeWithSignature({
|
|
2369
|
-
* owner: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36",
|
|
2370
|
-
* granteeAddress: "0xApp1234567890123456789012345678901234567890",
|
|
2371
|
-
* publicKey: "0x1234567890abcdef..."
|
|
2372
|
-
* });
|
|
2373
|
-
* ```
|
|
2374
|
-
*/
|
|
2375
|
-
async submitRegisterGranteeWithSignature(params) {
|
|
2376
|
-
this.assertWallet();
|
|
2377
|
-
const nonce = await this.getServersUserNonce();
|
|
2378
|
-
const owner = (0, import_viem.getAddress)(params.owner);
|
|
2379
|
-
const granteeAddress = (0, import_viem.getAddress)(params.granteeAddress);
|
|
2380
|
-
const registerGranteeInput = {
|
|
2381
|
-
nonce,
|
|
2382
|
-
owner,
|
|
2383
|
-
granteeAddress,
|
|
2384
|
-
publicKey: params.publicKey
|
|
2385
|
-
};
|
|
2386
|
-
const typedData = await this.buildRegisterGranteeTypedData(registerGranteeInput);
|
|
2387
|
-
const signature = await this.signTypedData(typedData);
|
|
2388
|
-
const hash = await this.submitSignedRegisterGranteeTransaction(
|
|
2389
|
-
typedData,
|
|
2390
|
-
signature
|
|
2391
|
-
);
|
|
2392
|
-
const account = this.context.walletClient?.account ?? this.context.userAddress;
|
|
2393
|
-
const { tx } = await import("../utils/transactionHelpers");
|
|
2394
|
-
return tx({
|
|
2395
|
-
hash,
|
|
2396
|
-
from: typeof account === "string" ? account : account.address,
|
|
2397
|
-
contract: "DataPortabilityGrantees",
|
|
2398
|
-
fn: "registerGrantee"
|
|
2399
|
-
});
|
|
2400
|
-
}
|
|
2401
|
-
/**
|
|
2402
|
-
* Submits a signed register grantee transaction via relayer
|
|
2403
|
-
*
|
|
2404
|
-
* @param typedData - The EIP-712 typed data for register grantee
|
|
2405
|
-
* @param signature - The cryptographic signature
|
|
2406
|
-
* @returns Promise resolving to the transaction hash
|
|
2407
|
-
*
|
|
2408
|
-
* @example
|
|
2409
|
-
* ```typescript
|
|
2410
|
-
* const result = await vana.permissions.submitSignedRegisterGrantee(typedData, signature);
|
|
2411
|
-
* ```
|
|
2412
|
-
*/
|
|
2413
|
-
async submitSignedRegisterGrantee(typedData, signature) {
|
|
2414
|
-
const hash = await this.submitSignedRegisterGranteeTransaction(
|
|
2415
|
-
typedData,
|
|
2416
|
-
signature
|
|
2417
|
-
);
|
|
2418
|
-
const account = this.context.walletClient?.account ?? this.context.userAddress;
|
|
2419
|
-
const { tx } = await import("../utils/transactionHelpers");
|
|
2420
|
-
return tx({
|
|
2421
|
-
hash,
|
|
2422
|
-
from: typeof account === "string" ? account : account.address,
|
|
2423
|
-
contract: "DataPortabilityGrantees",
|
|
2424
|
-
fn: "registerGrantee"
|
|
2425
|
-
});
|
|
2426
|
-
}
|
|
2470
|
+
// TODO: When DataPortabilityGrantees contract adds registerGranteeWithSignature function,
|
|
2471
|
+
// implement submitRegisterGranteeWithSignature and submitSignedRegisterGrantee methods
|
|
2472
|
+
// to support gasless transactions via relayer
|
|
2427
2473
|
/**
|
|
2428
2474
|
* Retrieves all registered grantees from the DataPortabilityGrantees contract.
|
|
2429
2475
|
*
|
|
@@ -2610,68 +2656,6 @@ class PermissionsController extends import_base.BaseController {
|
|
|
2610
2656
|
return null;
|
|
2611
2657
|
}
|
|
2612
2658
|
}
|
|
2613
|
-
/**
|
|
2614
|
-
* Builds EIP-712 typed data for grantee registration
|
|
2615
|
-
*
|
|
2616
|
-
* @param input - The register grantee input
|
|
2617
|
-
* @returns Promise resolving to the typed data structure
|
|
2618
|
-
* @private
|
|
2619
|
-
*/
|
|
2620
|
-
async buildRegisterGranteeTypedData(input) {
|
|
2621
|
-
const chainId = await this.context.publicClient.getChainId();
|
|
2622
|
-
const verifyingContract = (0, import_addresses.getContractAddress)(
|
|
2623
|
-
chainId,
|
|
2624
|
-
"DataPortabilityGrantees"
|
|
2625
|
-
);
|
|
2626
|
-
return {
|
|
2627
|
-
domain: {
|
|
2628
|
-
name: "DataPortabilityGrantees",
|
|
2629
|
-
version: "1",
|
|
2630
|
-
chainId,
|
|
2631
|
-
verifyingContract
|
|
2632
|
-
},
|
|
2633
|
-
types: {
|
|
2634
|
-
RegisterGrantee: [
|
|
2635
|
-
{ name: "nonce", type: "uint256" },
|
|
2636
|
-
{ name: "owner", type: "address" },
|
|
2637
|
-
{ name: "granteeAddress", type: "address" },
|
|
2638
|
-
{ name: "publicKey", type: "string" }
|
|
2639
|
-
]
|
|
2640
|
-
},
|
|
2641
|
-
primaryType: "RegisterGrantee",
|
|
2642
|
-
message: input
|
|
2643
|
-
};
|
|
2644
|
-
}
|
|
2645
|
-
/**
|
|
2646
|
-
* Submits a register grantee transaction with signature.
|
|
2647
|
-
*
|
|
2648
|
-
* @param typedData - The EIP-712 typed data structure for the registration
|
|
2649
|
-
* @param _signature - The cryptographic signature authorizing the registration (currently unused)
|
|
2650
|
-
* @returns Promise resolving to the transaction hash
|
|
2651
|
-
* @private
|
|
2652
|
-
*/
|
|
2653
|
-
async submitSignedRegisterGranteeTransaction(typedData, _signature) {
|
|
2654
|
-
this.assertWallet();
|
|
2655
|
-
const chainId = await this.context.walletClient.getChainId();
|
|
2656
|
-
const DataPortabilityGranteesAddress = (0, import_addresses.getContractAddress)(
|
|
2657
|
-
chainId,
|
|
2658
|
-
"DataPortabilityGrantees"
|
|
2659
|
-
);
|
|
2660
|
-
const DataPortabilityGranteesAbi = (0, import_abi.getAbi)("DataPortabilityGrantees");
|
|
2661
|
-
const txHash = await this.context.walletClient.writeContract({
|
|
2662
|
-
address: DataPortabilityGranteesAddress,
|
|
2663
|
-
abi: DataPortabilityGranteesAbi,
|
|
2664
|
-
functionName: "registerGrantee",
|
|
2665
|
-
args: [
|
|
2666
|
-
typedData.message.owner,
|
|
2667
|
-
typedData.message.granteeAddress,
|
|
2668
|
-
typedData.message.publicKey
|
|
2669
|
-
],
|
|
2670
|
-
account: this.context.walletClient?.account ?? this.context.userAddress,
|
|
2671
|
-
chain: this.context.walletClient?.chain ?? null
|
|
2672
|
-
});
|
|
2673
|
-
return txHash;
|
|
2674
|
-
}
|
|
2675
2659
|
// ===========================
|
|
2676
2660
|
// DATA PORTABILITY SERVERS HELPER METHODS
|
|
2677
2661
|
// ===========================
|
|
@@ -3621,11 +3605,22 @@ class PermissionsController extends import_base.BaseController {
|
|
|
3621
3605
|
this.assertWallet();
|
|
3622
3606
|
try {
|
|
3623
3607
|
let hash;
|
|
3624
|
-
if (this.context.
|
|
3625
|
-
|
|
3608
|
+
if (this.context.relayer) {
|
|
3609
|
+
const request = {
|
|
3610
|
+
type: "signed",
|
|
3611
|
+
operation: "submitAddPermission",
|
|
3626
3612
|
typedData,
|
|
3627
3613
|
signature
|
|
3628
|
-
|
|
3614
|
+
};
|
|
3615
|
+
const response = await this.context.relayer(request);
|
|
3616
|
+
if (response.type === "error") {
|
|
3617
|
+
throw new import_errors.RelayerError(response.error);
|
|
3618
|
+
}
|
|
3619
|
+
if (response.type === "signed") {
|
|
3620
|
+
hash = response.hash;
|
|
3621
|
+
} else {
|
|
3622
|
+
throw new Error("Unexpected response type from relayer");
|
|
3623
|
+
}
|
|
3629
3624
|
} else {
|
|
3630
3625
|
hash = await this.submitDirectAddPermissionTransaction(
|
|
3631
3626
|
typedData,
|
|
@@ -3783,45 +3778,44 @@ class PermissionsController extends import_base.BaseController {
|
|
|
3783
3778
|
async submitSignedAddServerFilesAndPermissions(typedData, signature, options) {
|
|
3784
3779
|
this.assertWallet();
|
|
3785
3780
|
try {
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
hasSubmitMethod: !!this.context.relayerCallbacks?.submitAddServerFilesAndPermissions,
|
|
3789
|
-
availableRelayerMethods: this.context.relayerCallbacks ? Object.keys(this.context.relayerCallbacks) : []
|
|
3790
|
-
});
|
|
3791
|
-
if (this.context.relayerCallbacks?.submitAddServerFilesAndPermissions) {
|
|
3781
|
+
let hash;
|
|
3782
|
+
if (this.context.relayer) {
|
|
3792
3783
|
console.debug(
|
|
3793
3784
|
"\u{1F680} Using relayer for submitAddServerFilesAndPermissions"
|
|
3794
3785
|
);
|
|
3795
|
-
const
|
|
3786
|
+
const request = {
|
|
3787
|
+
type: "signed",
|
|
3788
|
+
operation: "submitAddServerFilesAndPermissions",
|
|
3796
3789
|
typedData,
|
|
3797
3790
|
signature
|
|
3798
|
-
|
|
3799
|
-
const
|
|
3800
|
-
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
|
-
|
|
3805
|
-
|
|
3806
|
-
|
|
3791
|
+
};
|
|
3792
|
+
const response = await this.context.relayer(request);
|
|
3793
|
+
if (response.type === "error") {
|
|
3794
|
+
throw new import_errors.RelayerError(response.error);
|
|
3795
|
+
}
|
|
3796
|
+
if (response.type === "signed") {
|
|
3797
|
+
hash = response.hash;
|
|
3798
|
+
} else {
|
|
3799
|
+
throw new Error("Unexpected response type from relayer");
|
|
3800
|
+
}
|
|
3807
3801
|
} else {
|
|
3808
3802
|
console.debug(
|
|
3809
3803
|
"\u{1F4DD} Using direct transaction for submitAddServerFilesAndPermissions"
|
|
3810
3804
|
);
|
|
3811
|
-
|
|
3805
|
+
hash = await this.submitDirectAddServerFilesAndPermissionsTransaction(
|
|
3812
3806
|
typedData,
|
|
3813
3807
|
signature,
|
|
3814
3808
|
options
|
|
3815
3809
|
);
|
|
3816
|
-
const account = this.context.userAddress;
|
|
3817
|
-
const { tx } = await import("../utils/transactionHelpers");
|
|
3818
|
-
return tx({
|
|
3819
|
-
hash,
|
|
3820
|
-
from: account,
|
|
3821
|
-
contract: "DataPortabilityPermissions",
|
|
3822
|
-
fn: "addServerFilesAndPermissions"
|
|
3823
|
-
});
|
|
3824
3810
|
}
|
|
3811
|
+
const account = this.context.walletClient?.account ?? this.context.userAddress;
|
|
3812
|
+
const { tx } = await import("../utils/transactionHelpers");
|
|
3813
|
+
return tx({
|
|
3814
|
+
hash,
|
|
3815
|
+
from: typeof account === "string" ? account : account.address,
|
|
3816
|
+
contract: "DataPortabilityPermissions",
|
|
3817
|
+
fn: "addServerFilesAndPermissions"
|
|
3818
|
+
});
|
|
3825
3819
|
} catch (error) {
|
|
3826
3820
|
if (error instanceof import_errors.RelayerError || error instanceof import_errors.NetworkError || error instanceof import_errors.UserRejectedRequestError || error instanceof import_errors.SignatureError || error instanceof import_errors.NonceError) {
|
|
3827
3821
|
throw error;
|
|
@@ -3952,7 +3946,7 @@ class PermissionsController extends import_base.BaseController {
|
|
|
3952
3946
|
functionName: "addServerFilesAndPermissions",
|
|
3953
3947
|
// @ts-expect-error - Viem's type inference for nested Permission[][] arrays is incompatible with our Permission type
|
|
3954
3948
|
args: [serverFilesAndPermissionInput, formattedSignature],
|
|
3955
|
-
account: this.context.userAddress,
|
|
3949
|
+
account: this.context.walletClient?.account ?? this.context.userAddress,
|
|
3956
3950
|
chain: this.context.walletClient?.chain ?? null,
|
|
3957
3951
|
...options?.gasLimit && { gas: options.gasLimit },
|
|
3958
3952
|
...options?.nonce && { nonce: options.nonce },
|