@opendatalabs/vana-sdk 3.1.0 → 3.2.0-canary.a8087c5
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 +2 -1
- package/dist/account/personal-server-lite-owner-binding.cjs +81 -0
- package/dist/account/personal-server-lite-owner-binding.cjs.map +1 -0
- package/dist/account/personal-server-lite-owner-binding.d.ts +30 -0
- package/dist/account/personal-server-lite-owner-binding.js +59 -0
- package/dist/account/personal-server-lite-owner-binding.js.map +1 -0
- package/dist/account/personal-server-lite-owner-binding.test.d.ts +1 -0
- package/dist/account/personal-server-registration.cjs +263 -0
- package/dist/account/personal-server-registration.cjs.map +1 -0
- package/dist/account/personal-server-registration.d.ts +66 -0
- package/dist/account/personal-server-registration.js +240 -0
- package/dist/account/personal-server-registration.js.map +1 -0
- package/dist/account/personal-server-registration.test.d.ts +1 -0
- package/dist/auth/errors.js +1 -1
- package/dist/auth/oauth-client.js +2 -2
- package/dist/auth/web3-signed-builder.js +1 -1
- package/dist/auth/web3-signed.js +3 -3
- package/dist/browser.js +1 -1
- package/dist/chains/definitions.js +1 -1
- package/dist/chains/index.js +1 -1
- package/dist/chains.browser.js +1 -1
- package/dist/chains.js +1 -1
- package/dist/chains.node.js +1 -1
- package/dist/contracts/contractController.js +4 -4
- package/dist/core/client.js +1 -1
- package/dist/crypto/ecies/base.js +3 -3
- package/dist/crypto/ecies/browser.js +1 -1
- package/dist/crypto/ecies/index.js +1 -1
- package/dist/crypto/ecies/interface.js +1 -1
- package/dist/crypto/ecies/node.js +1 -1
- package/dist/crypto/services/WalletKeyEncryptionService.js +1 -1
- package/dist/generated/abi/index.js +26 -26
- package/dist/index.browser.d.ts +8 -3
- package/dist/index.browser.js +706 -72
- package/dist/index.browser.js.map +4 -4
- package/dist/index.node.cjs +733 -73
- package/dist/index.node.cjs.map +4 -4
- package/dist/index.node.d.ts +8 -3
- package/dist/index.node.js +706 -72
- package/dist/index.node.js.map +4 -4
- package/dist/node.js +1 -1
- package/dist/platform/browser-only.js +1 -1
- package/dist/platform/browser-safe.js +1 -1
- package/dist/platform/browser.js +6 -6
- package/dist/platform/index.js +4 -4
- package/dist/platform/node.js +8 -8
- package/dist/platform/utils.js +2 -2
- package/dist/platform.browser.js +3 -3
- package/dist/platform.js +4 -4
- package/dist/platform.node.js +4 -4
- package/dist/protocol/eip712.cjs +58 -3
- package/dist/protocol/eip712.cjs.map +1 -1
- package/dist/protocol/eip712.d.ts +98 -7
- package/dist/protocol/eip712.js +52 -3
- package/dist/protocol/eip712.js.map +1 -1
- package/dist/protocol/escrow-deposit.cjs +89 -0
- package/dist/protocol/escrow-deposit.cjs.map +1 -0
- package/dist/protocol/escrow-deposit.d.ts +47 -0
- package/dist/protocol/escrow-deposit.js +60 -0
- package/dist/protocol/escrow-deposit.js.map +1 -0
- package/dist/protocol/escrow-deposit.test.d.ts +1 -0
- package/dist/protocol/escrow-flow.test.d.ts +21 -0
- package/dist/protocol/gateway.cjs +124 -3
- package/dist/protocol/gateway.cjs.map +1 -1
- package/dist/protocol/gateway.d.ts +196 -16
- package/dist/protocol/gateway.js +124 -3
- package/dist/protocol/gateway.js.map +1 -1
- package/dist/protocol/grants.cjs +24 -64
- package/dist/protocol/grants.cjs.map +1 -1
- package/dist/protocol/grants.d.ts +6 -13
- package/dist/protocol/grants.js +25 -64
- package/dist/protocol/grants.js.map +1 -1
- package/dist/protocol/personal-server-lite-owner-binding.cjs +93 -0
- package/dist/protocol/personal-server-lite-owner-binding.cjs.map +1 -0
- package/dist/protocol/personal-server-lite-owner-binding.d.ts +44 -0
- package/dist/protocol/personal-server-lite-owner-binding.js +65 -0
- package/dist/protocol/personal-server-lite-owner-binding.js.map +1 -0
- package/dist/protocol/personal-server-lite-owner-binding.test.d.ts +1 -0
- package/dist/protocol/personal-server-registration.cjs +122 -0
- package/dist/protocol/personal-server-registration.cjs.map +1 -0
- package/dist/protocol/personal-server-registration.d.ts +62 -0
- package/dist/protocol/personal-server-registration.js +97 -0
- package/dist/protocol/personal-server-registration.js.map +1 -0
- package/dist/protocol/personal-server-registration.test.d.ts +1 -0
- package/dist/storage/default.js +1 -1
- package/dist/storage/index.js +10 -10
- package/dist/storage/manager.js +1 -1
- package/dist/storage/providers/callback-storage.js +1 -1
- package/dist/storage/providers/dropbox.js +1 -1
- package/dist/storage/providers/google-drive.js +1 -1
- package/dist/storage/providers/ipfs.js +2 -2
- package/dist/storage/providers/pinata.js +1 -1
- package/dist/storage/providers/r2.js +1 -1
- package/dist/storage/providers/vana-storage.js +2 -2
- package/dist/types/index.js +2 -2
- package/dist/types.js +1 -1
- package/package.json +6 -3
package/dist/index.node.cjs
CHANGED
|
@@ -1173,6 +1173,10 @@ var init_browser2 = __esm({
|
|
|
1173
1173
|
// src/index.node.ts
|
|
1174
1174
|
var index_node_exports = {};
|
|
1175
1175
|
__export(index_node_exports, {
|
|
1176
|
+
ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT: () => ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
|
|
1177
|
+
ADD_DATA_TYPES: () => ADD_DATA_TYPES,
|
|
1178
|
+
AccountPersonalServerLiteOwnerBindingError: () => AccountPersonalServerLiteOwnerBindingError,
|
|
1179
|
+
AccountPersonalServerRegistrationError: () => AccountPersonalServerRegistrationError,
|
|
1176
1180
|
BUILDER_REGISTRATION_TYPES: () => BUILDER_REGISTRATION_TYPES,
|
|
1177
1181
|
BlockchainError: () => BlockchainError,
|
|
1178
1182
|
BrowserPlatformAdapter: () => BrowserPlatformAdapter,
|
|
@@ -1183,8 +1187,10 @@ __export(index_node_exports, {
|
|
|
1183
1187
|
DataFileEnvelopeSchema: () => DataFileEnvelopeSchema,
|
|
1184
1188
|
DropboxStorage: () => DropboxStorage,
|
|
1185
1189
|
ECIESError: () => ECIESError,
|
|
1190
|
+
ESCROW_DEPOSIT_ABI: () => ESCROW_DEPOSIT_ABI,
|
|
1186
1191
|
ExpiredTokenError: () => ExpiredTokenError,
|
|
1187
1192
|
FILE_REGISTRATION_TYPES: () => FILE_REGISTRATION_TYPES,
|
|
1193
|
+
GENERIC_PAYMENT_TYPES: () => GENERIC_PAYMENT_TYPES,
|
|
1188
1194
|
GRANT_REGISTRATION_TYPES: () => GRANT_REGISTRATION_TYPES,
|
|
1189
1195
|
GRANT_REVOCATION_TYPES: () => GRANT_REVOCATION_TYPES,
|
|
1190
1196
|
GoogleDriveStorage: () => GoogleDriveStorage,
|
|
@@ -1195,11 +1201,17 @@ __export(index_node_exports, {
|
|
|
1195
1201
|
IpfsStorage: () => IpfsStorage,
|
|
1196
1202
|
MASTER_KEY_MESSAGE: () => MASTER_KEY_MESSAGE,
|
|
1197
1203
|
MissingAuthError: () => MissingAuthError,
|
|
1204
|
+
NATIVE_VANA_ASSET: () => NATIVE_VANA_ASSET,
|
|
1198
1205
|
NetworkError: () => NetworkError,
|
|
1199
1206
|
NodeECIESProvider: () => NodeECIESUint8Provider,
|
|
1200
1207
|
NodePlatformAdapter: () => NodePlatformAdapter,
|
|
1201
1208
|
NonceError: () => NonceError,
|
|
1202
1209
|
OAuthClient: () => OAuthClient,
|
|
1210
|
+
PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX: () => PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX,
|
|
1211
|
+
PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE: () => PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE,
|
|
1212
|
+
PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION: () => PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION,
|
|
1213
|
+
PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID: () => PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
|
|
1214
|
+
PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT: () => PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT,
|
|
1203
1215
|
PKCE_CHALLENGE_PATTERN: () => PKCE_CHALLENGE_PATTERN,
|
|
1204
1216
|
PKCE_VERIFIER_PATTERN: () => PKCE_VERIFIER_PATTERN,
|
|
1205
1217
|
PSError: () => PSError,
|
|
@@ -1207,6 +1219,7 @@ __export(index_node_exports, {
|
|
|
1207
1219
|
PersonalServerError: () => PersonalServerError,
|
|
1208
1220
|
PinataStorage: () => PinataStorage,
|
|
1209
1221
|
R2Storage: () => R2Storage,
|
|
1222
|
+
RECORD_DATA_ACCESS_TYPES: () => RECORD_DATA_ACCESS_TYPES,
|
|
1210
1223
|
ReadOnlyError: () => ReadOnlyError,
|
|
1211
1224
|
RelayerError: () => RelayerError,
|
|
1212
1225
|
SERVER_REGISTRATION_TYPES: () => SERVER_REGISTRATION_TYPES,
|
|
@@ -1221,6 +1234,12 @@ __export(index_node_exports, {
|
|
|
1221
1234
|
VanaError: () => VanaError,
|
|
1222
1235
|
VanaStorage: () => VanaStorage,
|
|
1223
1236
|
assertValidPkceVerifier: () => assertValidPkceVerifier,
|
|
1237
|
+
buildDepositNativeRequest: () => buildDepositNativeRequest,
|
|
1238
|
+
buildDepositTokenRequest: () => buildDepositTokenRequest,
|
|
1239
|
+
buildPersonalServerLiteOwnerBindingMessage: () => buildPersonalServerLiteOwnerBindingMessage,
|
|
1240
|
+
buildPersonalServerLiteOwnerBindingSignature: () => buildPersonalServerLiteOwnerBindingSignature,
|
|
1241
|
+
buildPersonalServerRegistrationSignature: () => buildPersonalServerRegistrationSignature,
|
|
1242
|
+
buildPersonalServerRegistrationTypedData: () => buildPersonalServerRegistrationTypedData,
|
|
1224
1243
|
buildWeb3SignedHeader: () => buildWeb3SignedHeader,
|
|
1225
1244
|
builderRegistrationDomain: () => builderRegistrationDomain,
|
|
1226
1245
|
chains: () => chains,
|
|
@@ -1236,12 +1255,19 @@ __export(index_node_exports, {
|
|
|
1236
1255
|
createPlatformAdapterFor: () => createPlatformAdapterFor,
|
|
1237
1256
|
createPlatformAdapterSafe: () => createPlatformAdapterSafe,
|
|
1238
1257
|
createVanaStorageProvider: () => createVanaStorageProvider,
|
|
1258
|
+
createViemPersonalServerLiteOwnerBindingSigner: () => createViemPersonalServerLiteOwnerBindingSigner,
|
|
1259
|
+
createViemPersonalServerRegistrationSigner: () => createViemPersonalServerRegistrationSigner,
|
|
1260
|
+
dataRegistryDomain: () => dataRegistryDomain,
|
|
1239
1261
|
decryptWithPassword: () => decryptWithPassword,
|
|
1240
1262
|
deriveMasterKey: () => deriveMasterKey,
|
|
1241
1263
|
deriveScopeKey: () => deriveScopeKey,
|
|
1242
1264
|
deserializeECIES: () => deserializeECIES,
|
|
1243
1265
|
detectPlatform: () => detectPlatform,
|
|
1266
|
+
encodeDepositNativeData: () => encodeDepositNativeData,
|
|
1267
|
+
encodeDepositTokenData: () => encodeDepositTokenData,
|
|
1244
1268
|
encryptWithPassword: () => encryptWithPassword,
|
|
1269
|
+
escrowContractAddress: () => escrowContractAddress,
|
|
1270
|
+
escrowPaymentDomain: () => escrowPaymentDomain,
|
|
1245
1271
|
fileRegistrationDomain: () => fileRegistrationDomain,
|
|
1246
1272
|
generatePkceVerifier: () => generatePkceVerifier,
|
|
1247
1273
|
getAbi: () => getAbi,
|
|
@@ -1261,16 +1287,20 @@ __export(index_node_exports, {
|
|
|
1261
1287
|
moksha: () => moksha,
|
|
1262
1288
|
mokshaServices: () => mokshaServices,
|
|
1263
1289
|
mokshaTestnet: () => mokshaTestnet2,
|
|
1264
|
-
parseGrantRegistrationPayload: () => parseGrantRegistrationPayload,
|
|
1265
1290
|
parsePSError: () => parsePSError,
|
|
1266
1291
|
parseScope: () => parseScope,
|
|
1267
1292
|
parseWeb3SignedHeader: () => parseWeb3SignedHeader,
|
|
1293
|
+
personalServerRegistrationDomain: () => personalServerRegistrationDomain,
|
|
1268
1294
|
recoverServerOwner: () => recoverServerOwner,
|
|
1295
|
+
registerPersonalServerSignature: () => registerPersonalServerSignature,
|
|
1269
1296
|
scopeCoveredByGrant: () => scopeCoveredByGrant,
|
|
1270
1297
|
scopeMatchesPattern: () => scopeMatchesPattern,
|
|
1271
1298
|
scopeToPathSegments: () => scopeToPathSegments,
|
|
1272
1299
|
serializeECIES: () => serializeECIES,
|
|
1273
1300
|
serverRegistrationDomain: () => serverRegistrationDomain,
|
|
1301
|
+
signPersonalServerLiteOwnerBinding: () => signPersonalServerLiteOwnerBinding,
|
|
1302
|
+
signPersonalServerLiteOwnerBindingWithAccountClient: () => signPersonalServerLiteOwnerBindingWithAccountClient,
|
|
1303
|
+
signPersonalServerRegistrationWithAccount: () => signPersonalServerRegistrationWithAccount,
|
|
1274
1304
|
vanaMainnet: () => vanaMainnet2,
|
|
1275
1305
|
verifyGrantRegistration: () => verifyGrantRegistration,
|
|
1276
1306
|
verifyPkceChallenge: () => verifyPkceChallenge,
|
|
@@ -32628,6 +32658,7 @@ function formatOAuthError(body, status) {
|
|
|
32628
32658
|
// src/protocol/eip712.ts
|
|
32629
32659
|
var DOMAIN_NAME = "Vana Data Portability";
|
|
32630
32660
|
var DOMAIN_VERSION = "1";
|
|
32661
|
+
var NATIVE_VANA_ASSET = "0x0000000000000000000000000000000000000000";
|
|
32631
32662
|
function buildDomain(chainId, verifyingContract) {
|
|
32632
32663
|
return {
|
|
32633
32664
|
name: DOMAIN_NAME,
|
|
@@ -32642,6 +32673,12 @@ function fileRegistrationDomain(config) {
|
|
|
32642
32673
|
config.contracts.dataRegistry
|
|
32643
32674
|
);
|
|
32644
32675
|
}
|
|
32676
|
+
function dataRegistryDomain(config) {
|
|
32677
|
+
return buildDomain(
|
|
32678
|
+
config.chainId,
|
|
32679
|
+
config.contracts.dataRegistry
|
|
32680
|
+
);
|
|
32681
|
+
}
|
|
32645
32682
|
function grantRegistrationDomain(config) {
|
|
32646
32683
|
return buildDomain(
|
|
32647
32684
|
config.chainId,
|
|
@@ -32666,6 +32703,12 @@ function builderRegistrationDomain(config) {
|
|
|
32666
32703
|
config.contracts.dataPortabilityGrantees
|
|
32667
32704
|
);
|
|
32668
32705
|
}
|
|
32706
|
+
function escrowPaymentDomain(config) {
|
|
32707
|
+
return buildDomain(
|
|
32708
|
+
config.chainId,
|
|
32709
|
+
config.contracts.dataPortabilityEscrow
|
|
32710
|
+
);
|
|
32711
|
+
}
|
|
32669
32712
|
var FILE_REGISTRATION_TYPES = {
|
|
32670
32713
|
FileRegistration: [
|
|
32671
32714
|
{ name: "ownerAddress", type: "address" },
|
|
@@ -32677,14 +32720,16 @@ var GRANT_REGISTRATION_TYPES = {
|
|
|
32677
32720
|
GrantRegistration: [
|
|
32678
32721
|
{ name: "grantorAddress", type: "address" },
|
|
32679
32722
|
{ name: "granteeId", type: "bytes32" },
|
|
32680
|
-
{ name: "
|
|
32681
|
-
{ name: "
|
|
32723
|
+
{ name: "scopes", type: "string[]" },
|
|
32724
|
+
{ name: "grantVersion", type: "uint256" },
|
|
32725
|
+
{ name: "expiresAt", type: "uint256" }
|
|
32682
32726
|
]
|
|
32683
32727
|
};
|
|
32684
32728
|
var GRANT_REVOCATION_TYPES = {
|
|
32685
32729
|
GrantRevocation: [
|
|
32686
32730
|
{ name: "grantorAddress", type: "address" },
|
|
32687
|
-
{ name: "grantId", type: "bytes32" }
|
|
32731
|
+
{ name: "grantId", type: "bytes32" },
|
|
32732
|
+
{ name: "grantVersion", type: "uint256" }
|
|
32688
32733
|
]
|
|
32689
32734
|
};
|
|
32690
32735
|
var SERVER_REGISTRATION_TYPES = {
|
|
@@ -32703,87 +32748,500 @@ var BUILDER_REGISTRATION_TYPES = {
|
|
|
32703
32748
|
{ name: "appUrl", type: "string" }
|
|
32704
32749
|
]
|
|
32705
32750
|
};
|
|
32751
|
+
var GENERIC_PAYMENT_TYPES = {
|
|
32752
|
+
GenericPayment: [
|
|
32753
|
+
{ name: "payerAddress", type: "address" },
|
|
32754
|
+
{ name: "opType", type: "string" },
|
|
32755
|
+
{ name: "opId", type: "bytes32" },
|
|
32756
|
+
{ name: "asset", type: "address" },
|
|
32757
|
+
{ name: "amount", type: "uint256" },
|
|
32758
|
+
{ name: "paymentNonce", type: "uint256" }
|
|
32759
|
+
]
|
|
32760
|
+
};
|
|
32761
|
+
var ADD_DATA_TYPES = {
|
|
32762
|
+
AddData: [
|
|
32763
|
+
{ name: "ownerAddress", type: "address" },
|
|
32764
|
+
{ name: "scope", type: "string" },
|
|
32765
|
+
{ name: "dataHash", type: "bytes32" },
|
|
32766
|
+
{ name: "metadataHash", type: "bytes32" },
|
|
32767
|
+
{ name: "expectedVersion", type: "uint256" }
|
|
32768
|
+
]
|
|
32769
|
+
};
|
|
32770
|
+
var RECORD_DATA_ACCESS_TYPES = {
|
|
32771
|
+
RecordDataAccess: [
|
|
32772
|
+
{ name: "ownerAddress", type: "address" },
|
|
32773
|
+
{ name: "scope", type: "string" },
|
|
32774
|
+
{ name: "version", type: "uint256" },
|
|
32775
|
+
{ name: "accessor", type: "address" },
|
|
32776
|
+
{ name: "recordId", type: "bytes32" }
|
|
32777
|
+
]
|
|
32778
|
+
};
|
|
32706
32779
|
|
|
32707
|
-
// src/protocol/
|
|
32780
|
+
// src/protocol/personal-server-registration.ts
|
|
32708
32781
|
var import_viem14 = require("viem");
|
|
32709
|
-
|
|
32710
|
-
|
|
32782
|
+
var PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID = 1480;
|
|
32783
|
+
var PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT = "0x1483B1F634DBA75AeaE60da7f01A679aabd5ee2c";
|
|
32784
|
+
function assertAddress(value, name) {
|
|
32785
|
+
if (!(0, import_viem14.isAddress)(value)) {
|
|
32786
|
+
throw new Error(`${name} must be a valid EVM address`);
|
|
32787
|
+
}
|
|
32711
32788
|
}
|
|
32712
|
-
function
|
|
32713
|
-
if (
|
|
32714
|
-
return
|
|
32789
|
+
function getAccountAddress(account) {
|
|
32790
|
+
if (!account) {
|
|
32791
|
+
return void 0;
|
|
32715
32792
|
}
|
|
32716
|
-
|
|
32717
|
-
|
|
32718
|
-
|
|
32719
|
-
|
|
32793
|
+
return typeof account === "string" ? account : account.address;
|
|
32794
|
+
}
|
|
32795
|
+
function isPersonalServerRegistrationSigner(source) {
|
|
32796
|
+
return "address" in source && typeof source.signTypedData === "function";
|
|
32797
|
+
}
|
|
32798
|
+
function createViemPersonalServerRegistrationSigner(source, options = {}) {
|
|
32799
|
+
if (isPersonalServerRegistrationSigner(source)) {
|
|
32800
|
+
return source;
|
|
32720
32801
|
}
|
|
32721
|
-
const
|
|
32722
|
-
|
|
32802
|
+
const accountAddress = getAccountAddress(options.account) ?? getAccountAddress(source.account);
|
|
32803
|
+
if (accountAddress) {
|
|
32804
|
+
return {
|
|
32805
|
+
address: accountAddress,
|
|
32806
|
+
signTypedData: (typedData) => source.signTypedData({
|
|
32807
|
+
...typedData,
|
|
32808
|
+
account: options.account ?? source.account ?? accountAddress
|
|
32809
|
+
})
|
|
32810
|
+
};
|
|
32811
|
+
}
|
|
32812
|
+
throw new Error(
|
|
32813
|
+
"Viem wallet client requires an account option or account property"
|
|
32814
|
+
);
|
|
32723
32815
|
}
|
|
32724
|
-
function
|
|
32725
|
-
|
|
32726
|
-
|
|
32727
|
-
parsed = JSON.parse(grant);
|
|
32728
|
-
} catch {
|
|
32729
|
-
return null;
|
|
32816
|
+
function personalServerRegistrationDomain(input = {}) {
|
|
32817
|
+
if (input.config) {
|
|
32818
|
+
return serverRegistrationDomain(input.config);
|
|
32730
32819
|
}
|
|
32731
|
-
|
|
32732
|
-
|
|
32820
|
+
const verifyingContract = input.verifyingContract ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT;
|
|
32821
|
+
assertAddress(verifyingContract, "verifyingContract");
|
|
32822
|
+
return {
|
|
32823
|
+
name: "Vana Data Portability",
|
|
32824
|
+
version: "1",
|
|
32825
|
+
chainId: input.chainId ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
|
|
32826
|
+
verifyingContract
|
|
32827
|
+
};
|
|
32828
|
+
}
|
|
32829
|
+
function buildPersonalServerRegistrationTypedData(input) {
|
|
32830
|
+
assertAddress(input.ownerAddress, "ownerAddress");
|
|
32831
|
+
assertAddress(input.serverAddress, "serverAddress");
|
|
32832
|
+
return {
|
|
32833
|
+
domain: personalServerRegistrationDomain(input),
|
|
32834
|
+
types: SERVER_REGISTRATION_TYPES,
|
|
32835
|
+
primaryType: "ServerRegistration",
|
|
32836
|
+
message: {
|
|
32837
|
+
ownerAddress: input.ownerAddress,
|
|
32838
|
+
serverAddress: input.serverAddress,
|
|
32839
|
+
publicKey: input.serverPublicKey,
|
|
32840
|
+
serverUrl: input.serverUrl
|
|
32841
|
+
}
|
|
32842
|
+
};
|
|
32843
|
+
}
|
|
32844
|
+
async function buildPersonalServerRegistrationSignature(input) {
|
|
32845
|
+
const typedData = buildPersonalServerRegistrationTypedData({
|
|
32846
|
+
ownerAddress: input.signer.address,
|
|
32847
|
+
serverAddress: input.serverAddress,
|
|
32848
|
+
serverPublicKey: input.serverPublicKey,
|
|
32849
|
+
serverUrl: input.serverUrl,
|
|
32850
|
+
config: input.config,
|
|
32851
|
+
chainId: input.chainId,
|
|
32852
|
+
verifyingContract: input.verifyingContract
|
|
32853
|
+
});
|
|
32854
|
+
const signature = await input.signer.signTypedData(typedData);
|
|
32855
|
+
return {
|
|
32856
|
+
signature,
|
|
32857
|
+
signerAddress: input.signer.address,
|
|
32858
|
+
typedData
|
|
32859
|
+
};
|
|
32860
|
+
}
|
|
32861
|
+
var registerPersonalServerSignature = buildPersonalServerRegistrationSignature;
|
|
32862
|
+
|
|
32863
|
+
// src/protocol/personal-server-lite-owner-binding.ts
|
|
32864
|
+
var import_viem15 = require("viem");
|
|
32865
|
+
var PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION = "vana.account.v1";
|
|
32866
|
+
var PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE = "ps-lite-owner";
|
|
32867
|
+
var PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX = `${PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION}:${PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE}:`;
|
|
32868
|
+
function assertAddress2(value, name) {
|
|
32869
|
+
if (!(0, import_viem15.isAddress)(value)) {
|
|
32870
|
+
throw new Error(`${name} must be a valid EVM address`);
|
|
32733
32871
|
}
|
|
32734
|
-
|
|
32735
|
-
|
|
32736
|
-
|
|
32872
|
+
}
|
|
32873
|
+
function getAccountAddress2(account) {
|
|
32874
|
+
if (!account) {
|
|
32875
|
+
return void 0;
|
|
32737
32876
|
}
|
|
32738
|
-
|
|
32739
|
-
|
|
32877
|
+
return typeof account === "string" ? account : account.address;
|
|
32878
|
+
}
|
|
32879
|
+
function isPersonalServerLiteOwnerBindingSigner(source) {
|
|
32880
|
+
return "address" in source && typeof source.signMessage === "function";
|
|
32881
|
+
}
|
|
32882
|
+
function buildPersonalServerLiteOwnerBindingMessage(ownerAddress) {
|
|
32883
|
+
assertAddress2(ownerAddress, "ownerAddress");
|
|
32884
|
+
return `${PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX}${ownerAddress.toLowerCase()}`;
|
|
32885
|
+
}
|
|
32886
|
+
function createViemPersonalServerLiteOwnerBindingSigner(source, options = {}) {
|
|
32887
|
+
if (isPersonalServerLiteOwnerBindingSigner(source)) {
|
|
32888
|
+
return source;
|
|
32740
32889
|
}
|
|
32741
|
-
|
|
32742
|
-
|
|
32890
|
+
const accountAddress = getAccountAddress2(options.account) ?? getAccountAddress2(source.account);
|
|
32891
|
+
if (accountAddress) {
|
|
32892
|
+
return {
|
|
32893
|
+
address: accountAddress,
|
|
32894
|
+
signMessage: ({ message }) => source.signMessage({
|
|
32895
|
+
account: options.account ?? source.account ?? accountAddress,
|
|
32896
|
+
message
|
|
32897
|
+
})
|
|
32898
|
+
};
|
|
32743
32899
|
}
|
|
32744
|
-
|
|
32745
|
-
|
|
32900
|
+
throw new Error(
|
|
32901
|
+
"Viem wallet client requires an account option or account property"
|
|
32902
|
+
);
|
|
32903
|
+
}
|
|
32904
|
+
async function buildPersonalServerLiteOwnerBindingSignature(input) {
|
|
32905
|
+
const message = buildPersonalServerLiteOwnerBindingMessage(
|
|
32906
|
+
input.signer.address
|
|
32907
|
+
);
|
|
32908
|
+
const signature = await input.signer.signMessage({ message });
|
|
32909
|
+
return {
|
|
32910
|
+
signature,
|
|
32911
|
+
signerAddress: input.signer.address,
|
|
32912
|
+
message,
|
|
32913
|
+
purpose: PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE
|
|
32914
|
+
};
|
|
32915
|
+
}
|
|
32916
|
+
var signPersonalServerLiteOwnerBinding = buildPersonalServerLiteOwnerBindingSignature;
|
|
32917
|
+
|
|
32918
|
+
// src/account/personal-server-registration.ts
|
|
32919
|
+
var import_viem16 = require("viem");
|
|
32920
|
+
var ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT = "personal_server.server_registration.v1";
|
|
32921
|
+
var AccountPersonalServerRegistrationError = class extends Error {
|
|
32922
|
+
status;
|
|
32923
|
+
code;
|
|
32924
|
+
details;
|
|
32925
|
+
constructor(input) {
|
|
32926
|
+
super(input.message);
|
|
32927
|
+
this.name = "AccountPersonalServerRegistrationError";
|
|
32928
|
+
this.status = input.status;
|
|
32929
|
+
this.code = input.code;
|
|
32930
|
+
this.details = input.details;
|
|
32746
32931
|
}
|
|
32747
|
-
|
|
32748
|
-
|
|
32932
|
+
};
|
|
32933
|
+
var DEFAULT_ACCOUNT_PS_REGISTRATION_PATH = "/api/v1/intents/personal-server-registration/sign";
|
|
32934
|
+
function trimTrailingSlash(value) {
|
|
32935
|
+
return value.replace(/\/+$/, "");
|
|
32936
|
+
}
|
|
32937
|
+
function assertAddress3(value, name) {
|
|
32938
|
+
if (!(0, import_viem16.isAddress)(value)) {
|
|
32939
|
+
throw new Error(`${name} must be a valid EVM address`);
|
|
32749
32940
|
}
|
|
32750
|
-
|
|
32751
|
-
|
|
32941
|
+
}
|
|
32942
|
+
async function parseAccountResponse(response) {
|
|
32943
|
+
const body = await response.json().catch(() => void 0);
|
|
32944
|
+
if (!response.ok) {
|
|
32945
|
+
throw new AccountPersonalServerRegistrationError({
|
|
32946
|
+
status: response.status,
|
|
32947
|
+
code: accountErrorCode(body),
|
|
32948
|
+
message: accountErrorMessage(response.status, body),
|
|
32949
|
+
details: body
|
|
32950
|
+
});
|
|
32951
|
+
}
|
|
32952
|
+
return body;
|
|
32953
|
+
}
|
|
32954
|
+
function accountErrorMessage(status, body) {
|
|
32955
|
+
const nestedMessage = nestedAccountErrorField(body, "message");
|
|
32956
|
+
if (nestedMessage) {
|
|
32957
|
+
return nestedMessage;
|
|
32958
|
+
}
|
|
32959
|
+
if (isRecord(body) && typeof body.message === "string") {
|
|
32960
|
+
return body.message;
|
|
32961
|
+
}
|
|
32962
|
+
const code = accountErrorCode(body);
|
|
32963
|
+
if (code) {
|
|
32964
|
+
return `Account PS registration signing failed: ${code}`;
|
|
32965
|
+
}
|
|
32966
|
+
return `Account PS registration signing failed: ${status}`;
|
|
32967
|
+
}
|
|
32968
|
+
function accountErrorCode(body) {
|
|
32969
|
+
const nestedCode = nestedAccountErrorField(body, "code");
|
|
32970
|
+
if (nestedCode) {
|
|
32971
|
+
return nestedCode;
|
|
32972
|
+
}
|
|
32973
|
+
if (isRecord(body)) {
|
|
32974
|
+
if (typeof body.code === "string") {
|
|
32975
|
+
return body.code;
|
|
32976
|
+
}
|
|
32977
|
+
if (typeof body.error === "string") {
|
|
32978
|
+
return body.error;
|
|
32979
|
+
}
|
|
32980
|
+
}
|
|
32981
|
+
return void 0;
|
|
32982
|
+
}
|
|
32983
|
+
function nestedAccountErrorField(body, field) {
|
|
32984
|
+
if (!isRecord(body) || !isRecord(body.error)) {
|
|
32985
|
+
return void 0;
|
|
32752
32986
|
}
|
|
32987
|
+
const value = body.error[field];
|
|
32988
|
+
return typeof value === "string" ? value : void 0;
|
|
32989
|
+
}
|
|
32990
|
+
function isRecord(value) {
|
|
32991
|
+
return typeof value === "object" && value !== null;
|
|
32992
|
+
}
|
|
32993
|
+
function normalizeAccountResponse(response) {
|
|
32753
32994
|
return {
|
|
32754
|
-
|
|
32755
|
-
|
|
32756
|
-
|
|
32757
|
-
|
|
32758
|
-
nonce: value["nonce"]
|
|
32995
|
+
...response,
|
|
32996
|
+
status: response.status === "fallback_required" ? "confirmation_required" : response.status,
|
|
32997
|
+
signerAddress: response.signerAddress ?? response.signer?.address,
|
|
32998
|
+
typedData: response.typedData ?? response.typed_data
|
|
32759
32999
|
};
|
|
32760
33000
|
}
|
|
32761
|
-
function
|
|
32762
|
-
|
|
32763
|
-
|
|
33001
|
+
function buildSignedResult(response, request) {
|
|
33002
|
+
assertAddress3(response.signerAddress, "signerAddress");
|
|
33003
|
+
if (response.typedData) {
|
|
33004
|
+
assertTypedDataMatchesRequest(
|
|
33005
|
+
response.typedData,
|
|
33006
|
+
request,
|
|
33007
|
+
response.signerAddress
|
|
33008
|
+
);
|
|
33009
|
+
}
|
|
33010
|
+
return {
|
|
33011
|
+
signature: response.signature,
|
|
33012
|
+
signerAddress: response.signerAddress,
|
|
33013
|
+
typedData: response.typedData ?? buildPersonalServerRegistrationTypedData({
|
|
33014
|
+
ownerAddress: response.signerAddress,
|
|
33015
|
+
...request
|
|
33016
|
+
}),
|
|
33017
|
+
intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT
|
|
33018
|
+
};
|
|
33019
|
+
}
|
|
33020
|
+
function assertTypedDataMatchesRequest(typedData, request, expectedSignerAddress) {
|
|
33021
|
+
assertAddress3(
|
|
33022
|
+
typedData.message.ownerAddress,
|
|
33023
|
+
"typedData.message.ownerAddress"
|
|
33024
|
+
);
|
|
33025
|
+
assertAddress3(
|
|
33026
|
+
typedData.message.serverAddress,
|
|
33027
|
+
"typedData.message.serverAddress"
|
|
33028
|
+
);
|
|
33029
|
+
if (expectedSignerAddress && !sameAddress(typedData.message.ownerAddress, expectedSignerAddress)) {
|
|
33030
|
+
throw new Error(
|
|
33031
|
+
"Account typedData ownerAddress must match the expected signer address"
|
|
33032
|
+
);
|
|
33033
|
+
}
|
|
33034
|
+
if (!sameAddress(typedData.message.serverAddress, request.serverAddress)) {
|
|
33035
|
+
throw new Error(
|
|
33036
|
+
"Account typedData serverAddress must match the requested serverAddress"
|
|
33037
|
+
);
|
|
33038
|
+
}
|
|
33039
|
+
if (typedData.message.publicKey !== request.serverPublicKey) {
|
|
33040
|
+
throw new Error(
|
|
33041
|
+
"Account typedData publicKey must match the requested serverPublicKey"
|
|
33042
|
+
);
|
|
33043
|
+
}
|
|
33044
|
+
if (typedData.message.serverUrl !== request.serverUrl) {
|
|
33045
|
+
throw new Error(
|
|
33046
|
+
"Account typedData serverUrl must match the requested serverUrl"
|
|
33047
|
+
);
|
|
33048
|
+
}
|
|
33049
|
+
if (typedData.primaryType !== "ServerRegistration") {
|
|
33050
|
+
throw new Error("Account typedData primaryType must be ServerRegistration");
|
|
33051
|
+
}
|
|
33052
|
+
if (JSON.stringify(typedData.types) !== JSON.stringify(SERVER_REGISTRATION_TYPES)) {
|
|
33053
|
+
throw new Error("Account typedData types must be ServerRegistration types");
|
|
33054
|
+
}
|
|
33055
|
+
const expectedDomain = personalServerRegistrationDomain({
|
|
33056
|
+
config: request.config,
|
|
33057
|
+
chainId: request.chainId,
|
|
33058
|
+
verifyingContract: request.verifyingContract
|
|
33059
|
+
});
|
|
33060
|
+
if (!domainsEqual(typedData.domain, expectedDomain)) {
|
|
33061
|
+
throw new Error("Account typedData domain must match the requested domain");
|
|
33062
|
+
}
|
|
33063
|
+
}
|
|
33064
|
+
function sameAddress(a, b) {
|
|
33065
|
+
return a.toLowerCase() === b.toLowerCase();
|
|
33066
|
+
}
|
|
33067
|
+
function domainsEqual(a, b) {
|
|
33068
|
+
if (!a || !b) {
|
|
33069
|
+
return false;
|
|
33070
|
+
}
|
|
33071
|
+
return a.name === b.name && a.version === b.version && Number(a.chainId) === Number(b.chainId) && String(a.verifyingContract ?? "").toLowerCase() === String(b.verifyingContract ?? "").toLowerCase() && a.salt === b.salt;
|
|
33072
|
+
}
|
|
33073
|
+
async function signPersonalServerRegistrationWithAccount(config, request) {
|
|
33074
|
+
assertAddress3(request.serverAddress, "serverAddress");
|
|
33075
|
+
const fetchImpl = config.fetchImpl ?? globalThis.fetch.bind(globalThis);
|
|
33076
|
+
const endpoint = new URL(
|
|
33077
|
+
config.endpointPath ?? DEFAULT_ACCOUNT_PS_REGISTRATION_PATH,
|
|
33078
|
+
`${trimTrailingSlash(config.accountOrigin)}/`
|
|
33079
|
+
);
|
|
33080
|
+
const response = await fetchImpl(endpoint, {
|
|
33081
|
+
method: "POST",
|
|
33082
|
+
headers: { "content-type": "application/json" },
|
|
33083
|
+
credentials: "include",
|
|
33084
|
+
body: JSON.stringify({
|
|
33085
|
+
intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
|
|
33086
|
+
serverAddress: request.serverAddress,
|
|
33087
|
+
serverPublicKey: request.serverPublicKey,
|
|
33088
|
+
serverUrl: request.serverUrl,
|
|
33089
|
+
config: request.config,
|
|
33090
|
+
chainId: request.chainId,
|
|
33091
|
+
verifyingContract: request.verifyingContract
|
|
33092
|
+
})
|
|
33093
|
+
});
|
|
33094
|
+
const body = normalizeAccountResponse(await parseAccountResponse(response));
|
|
33095
|
+
if (body.status === "signed") {
|
|
33096
|
+
if (!body.signature || !body.signerAddress) {
|
|
33097
|
+
throw new Error(
|
|
33098
|
+
"Account signed response must include signature and signerAddress"
|
|
33099
|
+
);
|
|
33100
|
+
}
|
|
32764
33101
|
return {
|
|
32765
|
-
|
|
32766
|
-
|
|
33102
|
+
status: "signed",
|
|
33103
|
+
result: buildSignedResult(
|
|
33104
|
+
{
|
|
33105
|
+
signature: body.signature,
|
|
33106
|
+
signerAddress: body.signerAddress,
|
|
33107
|
+
typedData: body.typedData
|
|
33108
|
+
},
|
|
33109
|
+
request
|
|
33110
|
+
)
|
|
32767
33111
|
};
|
|
33112
|
+
}
|
|
33113
|
+
if (body.status === "confirmation_required") {
|
|
33114
|
+
if (!body.typedData) {
|
|
33115
|
+
throw new Error(
|
|
33116
|
+
"Account confirmation_required response must include typedData"
|
|
33117
|
+
);
|
|
33118
|
+
}
|
|
33119
|
+
assertTypedDataMatchesRequest(body.typedData, request, body.signerAddress);
|
|
33120
|
+
if (!config.fallbackSigner) {
|
|
33121
|
+
return {
|
|
33122
|
+
status: "confirmation_required",
|
|
33123
|
+
typedData: body.typedData,
|
|
33124
|
+
signerAddress: body.signerAddress
|
|
33125
|
+
};
|
|
33126
|
+
}
|
|
33127
|
+
assertTypedDataMatchesRequest(
|
|
33128
|
+
body.typedData,
|
|
33129
|
+
request,
|
|
33130
|
+
config.fallbackSigner.address
|
|
33131
|
+
);
|
|
33132
|
+
const signature = await config.fallbackSigner.signTypedData(body.typedData);
|
|
33133
|
+
return {
|
|
33134
|
+
status: "fallback_signed",
|
|
33135
|
+
accountStatus: "confirmation_required",
|
|
33136
|
+
result: {
|
|
33137
|
+
signature,
|
|
33138
|
+
signerAddress: config.fallbackSigner.address,
|
|
33139
|
+
typedData: body.typedData,
|
|
33140
|
+
intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT
|
|
33141
|
+
}
|
|
33142
|
+
};
|
|
33143
|
+
}
|
|
33144
|
+
throw new Error(
|
|
33145
|
+
`Unsupported Account PS registration signing status: ${String(body.status)}`
|
|
33146
|
+
);
|
|
33147
|
+
}
|
|
33148
|
+
|
|
33149
|
+
// src/account/personal-server-lite-owner-binding.ts
|
|
33150
|
+
var AccountPersonalServerLiteOwnerBindingError = class extends Error {
|
|
33151
|
+
code;
|
|
33152
|
+
details;
|
|
33153
|
+
constructor(input) {
|
|
33154
|
+
super(input.message);
|
|
33155
|
+
this.name = "AccountPersonalServerLiteOwnerBindingError";
|
|
33156
|
+
this.code = input.code;
|
|
33157
|
+
this.details = input.details;
|
|
33158
|
+
}
|
|
33159
|
+
};
|
|
33160
|
+
async function signPersonalServerLiteOwnerBindingWithAccountClient(config) {
|
|
33161
|
+
let address;
|
|
33162
|
+
try {
|
|
33163
|
+
address = await config.client.getAddress();
|
|
33164
|
+
} catch (error) {
|
|
33165
|
+
throw accountOwnerBindingError(error);
|
|
33166
|
+
}
|
|
33167
|
+
if (!address) {
|
|
33168
|
+
throw new AccountPersonalServerLiteOwnerBindingError({
|
|
33169
|
+
message: "Account did not return a wallet address",
|
|
33170
|
+
code: "account_address_required"
|
|
33171
|
+
});
|
|
33172
|
+
}
|
|
33173
|
+
const message = buildPersonalServerLiteOwnerBindingMessage(address);
|
|
33174
|
+
let signature;
|
|
33175
|
+
try {
|
|
33176
|
+
signature = await config.client.signMessage({ message });
|
|
33177
|
+
} catch (error) {
|
|
33178
|
+
throw accountOwnerBindingError(error);
|
|
33179
|
+
}
|
|
33180
|
+
return {
|
|
33181
|
+
signature,
|
|
33182
|
+
signerAddress: address,
|
|
33183
|
+
message,
|
|
33184
|
+
purpose: PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE
|
|
33185
|
+
};
|
|
33186
|
+
}
|
|
33187
|
+
function accountOwnerBindingError(error) {
|
|
33188
|
+
if (error instanceof AccountPersonalServerLiteOwnerBindingError) {
|
|
33189
|
+
return error;
|
|
33190
|
+
}
|
|
33191
|
+
const rpcError = error;
|
|
33192
|
+
const code = rpcError?.code;
|
|
33193
|
+
const message = typeof rpcError?.message === "string" && rpcError.message.length > 0 ? rpcError.message : "Account PS Lite owner-binding signature failed";
|
|
33194
|
+
return new AccountPersonalServerLiteOwnerBindingError({
|
|
33195
|
+
message,
|
|
33196
|
+
code,
|
|
33197
|
+
details: error
|
|
33198
|
+
});
|
|
33199
|
+
}
|
|
33200
|
+
|
|
33201
|
+
// src/protocol/grants.ts
|
|
33202
|
+
var import_viem17 = require("viem");
|
|
33203
|
+
function isHexString(value) {
|
|
33204
|
+
return typeof value === "string" && value.startsWith("0x");
|
|
33205
|
+
}
|
|
33206
|
+
function isDataPortabilityGatewayConfig(value) {
|
|
33207
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
33208
|
+
return false;
|
|
33209
|
+
}
|
|
33210
|
+
const config = value;
|
|
33211
|
+
const contracts = config["contracts"];
|
|
33212
|
+
if (typeof config["chainId"] !== "number" || !Number.isInteger(config["chainId"]) || config["chainId"] <= 0 || contracts === null || typeof contracts !== "object" || Array.isArray(contracts)) {
|
|
33213
|
+
return false;
|
|
33214
|
+
}
|
|
33215
|
+
const c = contracts;
|
|
33216
|
+
return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]) && isHexString(c["dataPortabilityEscrow"]);
|
|
33217
|
+
}
|
|
33218
|
+
function toUint256(value) {
|
|
33219
|
+
try {
|
|
33220
|
+
const big = typeof value === "bigint" ? value : BigInt(value);
|
|
33221
|
+
if (big < 0n) return null;
|
|
33222
|
+
return big;
|
|
32768
33223
|
} catch {
|
|
32769
33224
|
return null;
|
|
32770
33225
|
}
|
|
32771
33226
|
}
|
|
32772
33227
|
async function verifyGrantRegistration(input) {
|
|
32773
|
-
|
|
32774
|
-
|
|
32775
|
-
return {
|
|
32776
|
-
valid: false,
|
|
32777
|
-
error: "Grant must be JSON with scopes and expiresAt"
|
|
32778
|
-
};
|
|
33228
|
+
if (!Array.isArray(input.scopes) || input.scopes.length === 0) {
|
|
33229
|
+
return { valid: false, error: "scopes must be a non-empty array" };
|
|
32779
33230
|
}
|
|
32780
|
-
|
|
32781
|
-
|
|
32782
|
-
|
|
33231
|
+
if (!input.scopes.every((scope) => typeof scope === "string")) {
|
|
33232
|
+
return { valid: false, error: "scopes must contain only strings" };
|
|
33233
|
+
}
|
|
33234
|
+
const grantVersion = toUint256(input.grantVersion);
|
|
33235
|
+
if (grantVersion === null || grantVersion < 1n) {
|
|
33236
|
+
return { valid: false, error: "grantVersion must be a uint256 >= 1" };
|
|
33237
|
+
}
|
|
33238
|
+
const expiresAt = toUint256(input.expiresAt);
|
|
33239
|
+
if (expiresAt === null) {
|
|
33240
|
+
return { valid: false, error: "expiresAt must be a non-negative uint256" };
|
|
32783
33241
|
}
|
|
32784
33242
|
let valid;
|
|
32785
33243
|
try {
|
|
32786
|
-
valid = await (0,
|
|
33244
|
+
valid = await (0, import_viem17.verifyTypedData)({
|
|
32787
33245
|
address: input.grantorAddress,
|
|
32788
33246
|
domain: grantRegistrationDomain(input.gatewayConfig),
|
|
32789
33247
|
types: GRANT_REGISTRATION_TYPES,
|
|
@@ -32791,8 +33249,9 @@ async function verifyGrantRegistration(input) {
|
|
|
32791
33249
|
message: {
|
|
32792
33250
|
grantorAddress: input.grantorAddress,
|
|
32793
33251
|
granteeId: input.granteeId,
|
|
32794
|
-
|
|
32795
|
-
|
|
33252
|
+
scopes: input.scopes,
|
|
33253
|
+
grantVersion,
|
|
33254
|
+
expiresAt
|
|
32796
33255
|
},
|
|
32797
33256
|
signature: input.signature
|
|
32798
33257
|
});
|
|
@@ -32803,19 +33262,69 @@ async function verifyGrantRegistration(input) {
|
|
|
32803
33262
|
return { valid: false, error: "Grant signature does not match grantor" };
|
|
32804
33263
|
}
|
|
32805
33264
|
const nowSeconds = input.nowSeconds ?? Math.floor(Date.now() / 1e3);
|
|
32806
|
-
if (
|
|
33265
|
+
if (expiresAt > 0n && expiresAt < BigInt(nowSeconds)) {
|
|
32807
33266
|
return { valid: false, error: "Grant has expired" };
|
|
32808
33267
|
}
|
|
32809
|
-
if (payload.user !== void 0 && payload.user.toLowerCase() !== input.grantorAddress.toLowerCase()) {
|
|
32810
|
-
return { valid: false, error: "Grant user does not match grantorAddress" };
|
|
32811
|
-
}
|
|
32812
33268
|
return {
|
|
32813
33269
|
valid: true,
|
|
32814
33270
|
grantorAddress: input.grantorAddress,
|
|
32815
33271
|
granteeId: input.granteeId,
|
|
32816
|
-
|
|
32817
|
-
|
|
32818
|
-
|
|
33272
|
+
scopes: input.scopes,
|
|
33273
|
+
grantVersion: grantVersion.toString(),
|
|
33274
|
+
expiresAt: expiresAt.toString()
|
|
33275
|
+
};
|
|
33276
|
+
}
|
|
33277
|
+
|
|
33278
|
+
// src/protocol/escrow-deposit.ts
|
|
33279
|
+
var import_viem18 = require("viem");
|
|
33280
|
+
var ESCROW_DEPOSIT_ABI = [
|
|
33281
|
+
{
|
|
33282
|
+
type: "function",
|
|
33283
|
+
name: "depositNative",
|
|
33284
|
+
stateMutability: "payable",
|
|
33285
|
+
inputs: [{ name: "account", type: "address" }],
|
|
33286
|
+
outputs: []
|
|
33287
|
+
},
|
|
33288
|
+
{
|
|
33289
|
+
type: "function",
|
|
33290
|
+
name: "depositToken",
|
|
33291
|
+
stateMutability: "nonpayable",
|
|
33292
|
+
inputs: [
|
|
33293
|
+
{ name: "account", type: "address" },
|
|
33294
|
+
{ name: "token", type: "address" },
|
|
33295
|
+
{ name: "amount", type: "uint256" }
|
|
33296
|
+
],
|
|
33297
|
+
outputs: []
|
|
33298
|
+
}
|
|
33299
|
+
];
|
|
33300
|
+
function escrowContractAddress(config) {
|
|
33301
|
+
return config.contracts.dataPortabilityEscrow;
|
|
33302
|
+
}
|
|
33303
|
+
function encodeDepositNativeData(input) {
|
|
33304
|
+
return (0, import_viem18.encodeFunctionData)({
|
|
33305
|
+
abi: ESCROW_DEPOSIT_ABI,
|
|
33306
|
+
functionName: "depositNative",
|
|
33307
|
+
args: [input.account]
|
|
33308
|
+
});
|
|
33309
|
+
}
|
|
33310
|
+
function encodeDepositTokenData(input) {
|
|
33311
|
+
return (0, import_viem18.encodeFunctionData)({
|
|
33312
|
+
abi: ESCROW_DEPOSIT_ABI,
|
|
33313
|
+
functionName: "depositToken",
|
|
33314
|
+
args: [input.account, input.token, input.amount]
|
|
33315
|
+
});
|
|
33316
|
+
}
|
|
33317
|
+
function buildDepositNativeRequest(config, input) {
|
|
33318
|
+
return {
|
|
33319
|
+
to: escrowContractAddress(config),
|
|
33320
|
+
data: encodeDepositNativeData({ account: input.account }),
|
|
33321
|
+
value: input.amount
|
|
33322
|
+
};
|
|
33323
|
+
}
|
|
33324
|
+
function buildDepositTokenRequest(config, input) {
|
|
33325
|
+
return {
|
|
33326
|
+
to: escrowContractAddress(config),
|
|
33327
|
+
data: encodeDepositTokenData(input)
|
|
32819
33328
|
};
|
|
32820
33329
|
}
|
|
32821
33330
|
|
|
@@ -33015,6 +33524,68 @@ function createGatewayClient(baseUrl) {
|
|
|
33015
33524
|
alreadyRegistered: false
|
|
33016
33525
|
};
|
|
33017
33526
|
},
|
|
33527
|
+
async registerBuilder(params) {
|
|
33528
|
+
const res = await fetch(`${base}/v1/builders`, {
|
|
33529
|
+
method: "POST",
|
|
33530
|
+
headers: {
|
|
33531
|
+
"Content-Type": "application/json",
|
|
33532
|
+
Authorization: `Web3Signed ${params.signature}`
|
|
33533
|
+
},
|
|
33534
|
+
body: JSON.stringify({
|
|
33535
|
+
ownerAddress: params.ownerAddress,
|
|
33536
|
+
granteeAddress: params.granteeAddress,
|
|
33537
|
+
publicKey: params.publicKey,
|
|
33538
|
+
appUrl: params.appUrl
|
|
33539
|
+
})
|
|
33540
|
+
});
|
|
33541
|
+
if (res.status === 409) {
|
|
33542
|
+
const body2 = await res.json().catch(() => ({}));
|
|
33543
|
+
return {
|
|
33544
|
+
builderId: getMutationId(
|
|
33545
|
+
body2,
|
|
33546
|
+
"builderId"
|
|
33547
|
+
),
|
|
33548
|
+
alreadyRegistered: true
|
|
33549
|
+
};
|
|
33550
|
+
}
|
|
33551
|
+
if (!res.ok) {
|
|
33552
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33553
|
+
}
|
|
33554
|
+
const body = await res.json().catch(() => ({}));
|
|
33555
|
+
return {
|
|
33556
|
+
builderId: getMutationId(body, "builderId"),
|
|
33557
|
+
alreadyRegistered: false
|
|
33558
|
+
};
|
|
33559
|
+
},
|
|
33560
|
+
async registerDataPoint(params) {
|
|
33561
|
+
const res = await fetch(`${base}/v1/data`, {
|
|
33562
|
+
method: "POST",
|
|
33563
|
+
headers: {
|
|
33564
|
+
"Content-Type": "application/json",
|
|
33565
|
+
Authorization: `Web3Signed ${params.signature}`
|
|
33566
|
+
},
|
|
33567
|
+
body: JSON.stringify({
|
|
33568
|
+
ownerAddress: params.ownerAddress,
|
|
33569
|
+
scope: params.scope,
|
|
33570
|
+
dataHash: params.dataHash,
|
|
33571
|
+
metadataHash: params.metadataHash,
|
|
33572
|
+
expectedVersion: params.expectedVersion
|
|
33573
|
+
})
|
|
33574
|
+
});
|
|
33575
|
+
if (!res.ok) {
|
|
33576
|
+
const body2 = await res.json().catch(() => ({}));
|
|
33577
|
+
const detail = body2.error ?? res.statusText;
|
|
33578
|
+
throw new Error(`Gateway error: ${res.status} ${detail}`);
|
|
33579
|
+
}
|
|
33580
|
+
const body = await res.json().catch(() => ({}));
|
|
33581
|
+
return {
|
|
33582
|
+
dataPointId: getMutationId(
|
|
33583
|
+
body,
|
|
33584
|
+
"dataPointId"
|
|
33585
|
+
),
|
|
33586
|
+
expectedVersion: body.expectedVersion
|
|
33587
|
+
};
|
|
33588
|
+
},
|
|
33018
33589
|
async registerFile(params) {
|
|
33019
33590
|
const res = await fetch(`${base}/v1/files`, {
|
|
33020
33591
|
method: "POST",
|
|
@@ -33052,8 +33623,9 @@ function createGatewayClient(baseUrl) {
|
|
|
33052
33623
|
body: JSON.stringify({
|
|
33053
33624
|
grantorAddress: params.grantorAddress,
|
|
33054
33625
|
granteeId: params.granteeId,
|
|
33055
|
-
|
|
33056
|
-
|
|
33626
|
+
scopes: params.scopes,
|
|
33627
|
+
grantVersion: params.grantVersion,
|
|
33628
|
+
expiresAt: params.expiresAt
|
|
33057
33629
|
})
|
|
33058
33630
|
});
|
|
33059
33631
|
if (res.status === 409) {
|
|
@@ -33078,13 +33650,71 @@ function createGatewayClient(baseUrl) {
|
|
|
33078
33650
|
Authorization: `Web3Signed ${params.signature}`
|
|
33079
33651
|
},
|
|
33080
33652
|
body: JSON.stringify({
|
|
33081
|
-
grantorAddress: params.grantorAddress
|
|
33653
|
+
grantorAddress: params.grantorAddress,
|
|
33654
|
+
grantVersion: params.grantVersion
|
|
33082
33655
|
})
|
|
33083
33656
|
});
|
|
33084
33657
|
if (res.status === 409) return;
|
|
33085
33658
|
if (!res.ok) {
|
|
33086
33659
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33087
33660
|
}
|
|
33661
|
+
},
|
|
33662
|
+
async getEscrowBalance(account) {
|
|
33663
|
+
const res = await fetch(`${base}/v1/escrow/balance?account=${account}`);
|
|
33664
|
+
if (!res.ok) {
|
|
33665
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33666
|
+
}
|
|
33667
|
+
return await res.json();
|
|
33668
|
+
},
|
|
33669
|
+
async submitEscrowDeposit(params) {
|
|
33670
|
+
const res = await fetch(`${base}/v1/escrow/deposit`, {
|
|
33671
|
+
method: "POST",
|
|
33672
|
+
headers: { "Content-Type": "application/json" },
|
|
33673
|
+
body: JSON.stringify({ txHash: params.txHash })
|
|
33674
|
+
});
|
|
33675
|
+
if (res.status !== 200 && res.status !== 202) {
|
|
33676
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33677
|
+
}
|
|
33678
|
+
return await res.json();
|
|
33679
|
+
},
|
|
33680
|
+
async payForOperation(params) {
|
|
33681
|
+
const body = {
|
|
33682
|
+
payerAddress: params.payerAddress,
|
|
33683
|
+
opType: params.opType,
|
|
33684
|
+
opId: params.opId,
|
|
33685
|
+
asset: params.asset,
|
|
33686
|
+
amount: params.amount,
|
|
33687
|
+
paymentNonce: params.paymentNonce
|
|
33688
|
+
};
|
|
33689
|
+
if (params.accessRecord) {
|
|
33690
|
+
body["accessRecord"] = params.accessRecord;
|
|
33691
|
+
}
|
|
33692
|
+
const res = await fetch(`${base}/v1/escrow/pay`, {
|
|
33693
|
+
method: "POST",
|
|
33694
|
+
headers: {
|
|
33695
|
+
"Content-Type": "application/json",
|
|
33696
|
+
Authorization: `Web3Signed ${params.signature}`
|
|
33697
|
+
},
|
|
33698
|
+
body: JSON.stringify(body)
|
|
33699
|
+
});
|
|
33700
|
+
if (!res.ok) {
|
|
33701
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33702
|
+
}
|
|
33703
|
+
return await res.json();
|
|
33704
|
+
},
|
|
33705
|
+
async settle(params) {
|
|
33706
|
+
const res = await fetch(`${base}/v1/settle`, {
|
|
33707
|
+
method: "POST",
|
|
33708
|
+
headers: { "Content-Type": "application/json" },
|
|
33709
|
+
// The gateway accepts an empty body; only `limit` is recognised.
|
|
33710
|
+
// Always send a JSON body so the gateway's req.body shape parse
|
|
33711
|
+
// doesn't have to deal with an undefined.
|
|
33712
|
+
body: JSON.stringify(params ?? {})
|
|
33713
|
+
});
|
|
33714
|
+
if (!res.ok) {
|
|
33715
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33716
|
+
}
|
|
33717
|
+
return await res.json();
|
|
33088
33718
|
}
|
|
33089
33719
|
};
|
|
33090
33720
|
}
|
|
@@ -33114,7 +33744,7 @@ var KNOWN_CODES = /* @__PURE__ */ new Set([
|
|
|
33114
33744
|
"server_not_configured",
|
|
33115
33745
|
"content_too_large"
|
|
33116
33746
|
]);
|
|
33117
|
-
function
|
|
33747
|
+
function isRecord2(value) {
|
|
33118
33748
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
33119
33749
|
}
|
|
33120
33750
|
function normalizeCode(value) {
|
|
@@ -33125,10 +33755,10 @@ function normalizeCode(value) {
|
|
|
33125
33755
|
return KNOWN_CODES.has(code) ? code : null;
|
|
33126
33756
|
}
|
|
33127
33757
|
function extractPSErrorBody(body) {
|
|
33128
|
-
if (!
|
|
33758
|
+
if (!isRecord2(body)) {
|
|
33129
33759
|
return null;
|
|
33130
33760
|
}
|
|
33131
|
-
const nested =
|
|
33761
|
+
const nested = isRecord2(body.error) ? body.error : null;
|
|
33132
33762
|
const code = normalizeCode(
|
|
33133
33763
|
nested?.errorCode ?? nested?.code ?? body.errorCode ?? body.code
|
|
33134
33764
|
);
|
|
@@ -33153,6 +33783,10 @@ async function parsePSError(response) {
|
|
|
33153
33783
|
}
|
|
33154
33784
|
// Annotate the CommonJS export names for ESM import in node:
|
|
33155
33785
|
0 && (module.exports = {
|
|
33786
|
+
ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
|
|
33787
|
+
ADD_DATA_TYPES,
|
|
33788
|
+
AccountPersonalServerLiteOwnerBindingError,
|
|
33789
|
+
AccountPersonalServerRegistrationError,
|
|
33156
33790
|
BUILDER_REGISTRATION_TYPES,
|
|
33157
33791
|
BlockchainError,
|
|
33158
33792
|
BrowserPlatformAdapter,
|
|
@@ -33163,8 +33797,10 @@ async function parsePSError(response) {
|
|
|
33163
33797
|
DataFileEnvelopeSchema,
|
|
33164
33798
|
DropboxStorage,
|
|
33165
33799
|
ECIESError,
|
|
33800
|
+
ESCROW_DEPOSIT_ABI,
|
|
33166
33801
|
ExpiredTokenError,
|
|
33167
33802
|
FILE_REGISTRATION_TYPES,
|
|
33803
|
+
GENERIC_PAYMENT_TYPES,
|
|
33168
33804
|
GRANT_REGISTRATION_TYPES,
|
|
33169
33805
|
GRANT_REVOCATION_TYPES,
|
|
33170
33806
|
GoogleDriveStorage,
|
|
@@ -33175,11 +33811,17 @@ async function parsePSError(response) {
|
|
|
33175
33811
|
IpfsStorage,
|
|
33176
33812
|
MASTER_KEY_MESSAGE,
|
|
33177
33813
|
MissingAuthError,
|
|
33814
|
+
NATIVE_VANA_ASSET,
|
|
33178
33815
|
NetworkError,
|
|
33179
33816
|
NodeECIESProvider,
|
|
33180
33817
|
NodePlatformAdapter,
|
|
33181
33818
|
NonceError,
|
|
33182
33819
|
OAuthClient,
|
|
33820
|
+
PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX,
|
|
33821
|
+
PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE,
|
|
33822
|
+
PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION,
|
|
33823
|
+
PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
|
|
33824
|
+
PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT,
|
|
33183
33825
|
PKCE_CHALLENGE_PATTERN,
|
|
33184
33826
|
PKCE_VERIFIER_PATTERN,
|
|
33185
33827
|
PSError,
|
|
@@ -33187,6 +33829,7 @@ async function parsePSError(response) {
|
|
|
33187
33829
|
PersonalServerError,
|
|
33188
33830
|
PinataStorage,
|
|
33189
33831
|
R2Storage,
|
|
33832
|
+
RECORD_DATA_ACCESS_TYPES,
|
|
33190
33833
|
ReadOnlyError,
|
|
33191
33834
|
RelayerError,
|
|
33192
33835
|
SERVER_REGISTRATION_TYPES,
|
|
@@ -33201,6 +33844,12 @@ async function parsePSError(response) {
|
|
|
33201
33844
|
VanaError,
|
|
33202
33845
|
VanaStorage,
|
|
33203
33846
|
assertValidPkceVerifier,
|
|
33847
|
+
buildDepositNativeRequest,
|
|
33848
|
+
buildDepositTokenRequest,
|
|
33849
|
+
buildPersonalServerLiteOwnerBindingMessage,
|
|
33850
|
+
buildPersonalServerLiteOwnerBindingSignature,
|
|
33851
|
+
buildPersonalServerRegistrationSignature,
|
|
33852
|
+
buildPersonalServerRegistrationTypedData,
|
|
33204
33853
|
buildWeb3SignedHeader,
|
|
33205
33854
|
builderRegistrationDomain,
|
|
33206
33855
|
chains,
|
|
@@ -33216,12 +33865,19 @@ async function parsePSError(response) {
|
|
|
33216
33865
|
createPlatformAdapterFor,
|
|
33217
33866
|
createPlatformAdapterSafe,
|
|
33218
33867
|
createVanaStorageProvider,
|
|
33868
|
+
createViemPersonalServerLiteOwnerBindingSigner,
|
|
33869
|
+
createViemPersonalServerRegistrationSigner,
|
|
33870
|
+
dataRegistryDomain,
|
|
33219
33871
|
decryptWithPassword,
|
|
33220
33872
|
deriveMasterKey,
|
|
33221
33873
|
deriveScopeKey,
|
|
33222
33874
|
deserializeECIES,
|
|
33223
33875
|
detectPlatform,
|
|
33876
|
+
encodeDepositNativeData,
|
|
33877
|
+
encodeDepositTokenData,
|
|
33224
33878
|
encryptWithPassword,
|
|
33879
|
+
escrowContractAddress,
|
|
33880
|
+
escrowPaymentDomain,
|
|
33225
33881
|
fileRegistrationDomain,
|
|
33226
33882
|
generatePkceVerifier,
|
|
33227
33883
|
getAbi,
|
|
@@ -33241,16 +33897,20 @@ async function parsePSError(response) {
|
|
|
33241
33897
|
moksha,
|
|
33242
33898
|
mokshaServices,
|
|
33243
33899
|
mokshaTestnet,
|
|
33244
|
-
parseGrantRegistrationPayload,
|
|
33245
33900
|
parsePSError,
|
|
33246
33901
|
parseScope,
|
|
33247
33902
|
parseWeb3SignedHeader,
|
|
33903
|
+
personalServerRegistrationDomain,
|
|
33248
33904
|
recoverServerOwner,
|
|
33905
|
+
registerPersonalServerSignature,
|
|
33249
33906
|
scopeCoveredByGrant,
|
|
33250
33907
|
scopeMatchesPattern,
|
|
33251
33908
|
scopeToPathSegments,
|
|
33252
33909
|
serializeECIES,
|
|
33253
33910
|
serverRegistrationDomain,
|
|
33911
|
+
signPersonalServerLiteOwnerBinding,
|
|
33912
|
+
signPersonalServerLiteOwnerBindingWithAccountClient,
|
|
33913
|
+
signPersonalServerRegistrationWithAccount,
|
|
33254
33914
|
vanaMainnet,
|
|
33255
33915
|
verifyGrantRegistration,
|
|
33256
33916
|
verifyPkceChallenge,
|