@opendatalabs/vana-sdk 3.1.0 → 3.2.0-canary.0911ffc
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 +9 -3
- package/dist/index.browser.js +768 -72
- package/dist/index.browser.js.map +4 -4
- package/dist/index.node.cjs +798 -73
- package/dist/index.node.cjs.map +4 -4
- package/dist/index.node.d.ts +9 -3
- package/dist/index.node.js +768 -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 +99 -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/fee-registry.cjs +89 -0
- package/dist/protocol/fee-registry.cjs.map +1 -0
- package/dist/protocol/fee-registry.d.ts +105 -0
- package/dist/protocol/fee-registry.js +63 -0
- package/dist/protocol/fee-registry.js.map +1 -0
- package/dist/protocol/fee-registry.test.d.ts +1 -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.browser.js
CHANGED
|
@@ -31882,6 +31882,7 @@ async function verifyWeb3Signed(params) {
|
|
|
31882
31882
|
// src/protocol/eip712.ts
|
|
31883
31883
|
var DOMAIN_NAME = "Vana Data Portability";
|
|
31884
31884
|
var DOMAIN_VERSION = "1";
|
|
31885
|
+
var NATIVE_VANA_ASSET = "0x0000000000000000000000000000000000000000";
|
|
31885
31886
|
function buildDomain(chainId, verifyingContract) {
|
|
31886
31887
|
return {
|
|
31887
31888
|
name: DOMAIN_NAME,
|
|
@@ -31896,6 +31897,12 @@ function fileRegistrationDomain(config) {
|
|
|
31896
31897
|
config.contracts.dataRegistry
|
|
31897
31898
|
);
|
|
31898
31899
|
}
|
|
31900
|
+
function dataRegistryDomain(config) {
|
|
31901
|
+
return buildDomain(
|
|
31902
|
+
config.chainId,
|
|
31903
|
+
config.contracts.dataRegistry
|
|
31904
|
+
);
|
|
31905
|
+
}
|
|
31899
31906
|
function grantRegistrationDomain(config) {
|
|
31900
31907
|
return buildDomain(
|
|
31901
31908
|
config.chainId,
|
|
@@ -31920,6 +31927,12 @@ function builderRegistrationDomain(config) {
|
|
|
31920
31927
|
config.contracts.dataPortabilityGrantees
|
|
31921
31928
|
);
|
|
31922
31929
|
}
|
|
31930
|
+
function escrowPaymentDomain(config) {
|
|
31931
|
+
return buildDomain(
|
|
31932
|
+
config.chainId,
|
|
31933
|
+
config.contracts.dataPortabilityEscrow
|
|
31934
|
+
);
|
|
31935
|
+
}
|
|
31923
31936
|
var FILE_REGISTRATION_TYPES = {
|
|
31924
31937
|
FileRegistration: [
|
|
31925
31938
|
{ name: "ownerAddress", type: "address" },
|
|
@@ -31931,14 +31944,16 @@ var GRANT_REGISTRATION_TYPES = {
|
|
|
31931
31944
|
GrantRegistration: [
|
|
31932
31945
|
{ name: "grantorAddress", type: "address" },
|
|
31933
31946
|
{ name: "granteeId", type: "bytes32" },
|
|
31934
|
-
{ name: "
|
|
31935
|
-
{ name: "
|
|
31947
|
+
{ name: "scopes", type: "string[]" },
|
|
31948
|
+
{ name: "grantVersion", type: "uint256" },
|
|
31949
|
+
{ name: "expiresAt", type: "uint256" }
|
|
31936
31950
|
]
|
|
31937
31951
|
};
|
|
31938
31952
|
var GRANT_REVOCATION_TYPES = {
|
|
31939
31953
|
GrantRevocation: [
|
|
31940
31954
|
{ name: "grantorAddress", type: "address" },
|
|
31941
|
-
{ name: "grantId", type: "bytes32" }
|
|
31955
|
+
{ name: "grantId", type: "bytes32" },
|
|
31956
|
+
{ name: "grantVersion", type: "uint256" }
|
|
31942
31957
|
]
|
|
31943
31958
|
};
|
|
31944
31959
|
var SERVER_REGISTRATION_TYPES = {
|
|
@@ -31957,83 +31972,500 @@ var BUILDER_REGISTRATION_TYPES = {
|
|
|
31957
31972
|
{ name: "appUrl", type: "string" }
|
|
31958
31973
|
]
|
|
31959
31974
|
};
|
|
31975
|
+
var GENERIC_PAYMENT_TYPES = {
|
|
31976
|
+
GenericPayment: [
|
|
31977
|
+
{ name: "payerAddress", type: "address" },
|
|
31978
|
+
{ name: "opType", type: "string" },
|
|
31979
|
+
{ name: "opId", type: "bytes32" },
|
|
31980
|
+
{ name: "asset", type: "address" },
|
|
31981
|
+
{ name: "amount", type: "uint256" },
|
|
31982
|
+
{ name: "paymentNonce", type: "uint256" }
|
|
31983
|
+
]
|
|
31984
|
+
};
|
|
31985
|
+
var ADD_DATA_TYPES = {
|
|
31986
|
+
AddData: [
|
|
31987
|
+
{ name: "ownerAddress", type: "address" },
|
|
31988
|
+
{ name: "scope", type: "string" },
|
|
31989
|
+
{ name: "dataHash", type: "bytes32" },
|
|
31990
|
+
{ name: "metadataHash", type: "bytes32" },
|
|
31991
|
+
{ name: "expectedVersion", type: "uint256" }
|
|
31992
|
+
]
|
|
31993
|
+
};
|
|
31994
|
+
var RECORD_DATA_ACCESS_TYPES = {
|
|
31995
|
+
RecordDataAccess: [
|
|
31996
|
+
{ name: "ownerAddress", type: "address" },
|
|
31997
|
+
{ name: "scope", type: "string" },
|
|
31998
|
+
{ name: "version", type: "uint256" },
|
|
31999
|
+
{ name: "accessor", type: "address" },
|
|
32000
|
+
{ name: "recordId", type: "bytes32" }
|
|
32001
|
+
]
|
|
32002
|
+
};
|
|
31960
32003
|
|
|
31961
|
-
// src/protocol/
|
|
31962
|
-
import {
|
|
31963
|
-
|
|
31964
|
-
|
|
32004
|
+
// src/protocol/personal-server-registration.ts
|
|
32005
|
+
import {
|
|
32006
|
+
isAddress
|
|
32007
|
+
} from "viem";
|
|
32008
|
+
var PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID = 1480;
|
|
32009
|
+
var PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT = "0x1483B1F634DBA75AeaE60da7f01A679aabd5ee2c";
|
|
32010
|
+
function assertAddress(value, name) {
|
|
32011
|
+
if (!isAddress(value)) {
|
|
32012
|
+
throw new Error(`${name} must be a valid EVM address`);
|
|
32013
|
+
}
|
|
31965
32014
|
}
|
|
31966
|
-
function
|
|
31967
|
-
if (
|
|
31968
|
-
return
|
|
32015
|
+
function getAccountAddress(account) {
|
|
32016
|
+
if (!account) {
|
|
32017
|
+
return void 0;
|
|
31969
32018
|
}
|
|
31970
|
-
|
|
31971
|
-
|
|
31972
|
-
|
|
31973
|
-
|
|
32019
|
+
return typeof account === "string" ? account : account.address;
|
|
32020
|
+
}
|
|
32021
|
+
function isPersonalServerRegistrationSigner(source) {
|
|
32022
|
+
return "address" in source && typeof source.signTypedData === "function";
|
|
32023
|
+
}
|
|
32024
|
+
function createViemPersonalServerRegistrationSigner(source, options = {}) {
|
|
32025
|
+
if (isPersonalServerRegistrationSigner(source)) {
|
|
32026
|
+
return source;
|
|
31974
32027
|
}
|
|
31975
|
-
const
|
|
31976
|
-
|
|
32028
|
+
const accountAddress = getAccountAddress(options.account) ?? getAccountAddress(source.account);
|
|
32029
|
+
if (accountAddress) {
|
|
32030
|
+
return {
|
|
32031
|
+
address: accountAddress,
|
|
32032
|
+
signTypedData: (typedData) => source.signTypedData({
|
|
32033
|
+
...typedData,
|
|
32034
|
+
account: options.account ?? source.account ?? accountAddress
|
|
32035
|
+
})
|
|
32036
|
+
};
|
|
32037
|
+
}
|
|
32038
|
+
throw new Error(
|
|
32039
|
+
"Viem wallet client requires an account option or account property"
|
|
32040
|
+
);
|
|
31977
32041
|
}
|
|
31978
|
-
function
|
|
31979
|
-
|
|
31980
|
-
|
|
31981
|
-
parsed = JSON.parse(grant);
|
|
31982
|
-
} catch {
|
|
31983
|
-
return null;
|
|
32042
|
+
function personalServerRegistrationDomain(input = {}) {
|
|
32043
|
+
if (input.config) {
|
|
32044
|
+
return serverRegistrationDomain(input.config);
|
|
31984
32045
|
}
|
|
31985
|
-
|
|
31986
|
-
|
|
32046
|
+
const verifyingContract = input.verifyingContract ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT;
|
|
32047
|
+
assertAddress(verifyingContract, "verifyingContract");
|
|
32048
|
+
return {
|
|
32049
|
+
name: "Vana Data Portability",
|
|
32050
|
+
version: "1",
|
|
32051
|
+
chainId: input.chainId ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
|
|
32052
|
+
verifyingContract
|
|
32053
|
+
};
|
|
32054
|
+
}
|
|
32055
|
+
function buildPersonalServerRegistrationTypedData(input) {
|
|
32056
|
+
assertAddress(input.ownerAddress, "ownerAddress");
|
|
32057
|
+
assertAddress(input.serverAddress, "serverAddress");
|
|
32058
|
+
return {
|
|
32059
|
+
domain: personalServerRegistrationDomain(input),
|
|
32060
|
+
types: SERVER_REGISTRATION_TYPES,
|
|
32061
|
+
primaryType: "ServerRegistration",
|
|
32062
|
+
message: {
|
|
32063
|
+
ownerAddress: input.ownerAddress,
|
|
32064
|
+
serverAddress: input.serverAddress,
|
|
32065
|
+
publicKey: input.serverPublicKey,
|
|
32066
|
+
serverUrl: input.serverUrl
|
|
32067
|
+
}
|
|
32068
|
+
};
|
|
32069
|
+
}
|
|
32070
|
+
async function buildPersonalServerRegistrationSignature(input) {
|
|
32071
|
+
const typedData = buildPersonalServerRegistrationTypedData({
|
|
32072
|
+
ownerAddress: input.signer.address,
|
|
32073
|
+
serverAddress: input.serverAddress,
|
|
32074
|
+
serverPublicKey: input.serverPublicKey,
|
|
32075
|
+
serverUrl: input.serverUrl,
|
|
32076
|
+
config: input.config,
|
|
32077
|
+
chainId: input.chainId,
|
|
32078
|
+
verifyingContract: input.verifyingContract
|
|
32079
|
+
});
|
|
32080
|
+
const signature = await input.signer.signTypedData(typedData);
|
|
32081
|
+
return {
|
|
32082
|
+
signature,
|
|
32083
|
+
signerAddress: input.signer.address,
|
|
32084
|
+
typedData
|
|
32085
|
+
};
|
|
32086
|
+
}
|
|
32087
|
+
var registerPersonalServerSignature = buildPersonalServerRegistrationSignature;
|
|
32088
|
+
|
|
32089
|
+
// src/protocol/personal-server-lite-owner-binding.ts
|
|
32090
|
+
import {
|
|
32091
|
+
isAddress as isAddress2
|
|
32092
|
+
} from "viem";
|
|
32093
|
+
var PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION = "vana.account.v1";
|
|
32094
|
+
var PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE = "ps-lite-owner";
|
|
32095
|
+
var PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX = `${PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION}:${PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE}:`;
|
|
32096
|
+
function assertAddress2(value, name) {
|
|
32097
|
+
if (!isAddress2(value)) {
|
|
32098
|
+
throw new Error(`${name} must be a valid EVM address`);
|
|
31987
32099
|
}
|
|
31988
|
-
|
|
31989
|
-
|
|
31990
|
-
|
|
32100
|
+
}
|
|
32101
|
+
function getAccountAddress2(account) {
|
|
32102
|
+
if (!account) {
|
|
32103
|
+
return void 0;
|
|
31991
32104
|
}
|
|
31992
|
-
|
|
31993
|
-
|
|
32105
|
+
return typeof account === "string" ? account : account.address;
|
|
32106
|
+
}
|
|
32107
|
+
function isPersonalServerLiteOwnerBindingSigner(source) {
|
|
32108
|
+
return "address" in source && typeof source.signMessage === "function";
|
|
32109
|
+
}
|
|
32110
|
+
function buildPersonalServerLiteOwnerBindingMessage(ownerAddress) {
|
|
32111
|
+
assertAddress2(ownerAddress, "ownerAddress");
|
|
32112
|
+
return `${PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX}${ownerAddress.toLowerCase()}`;
|
|
32113
|
+
}
|
|
32114
|
+
function createViemPersonalServerLiteOwnerBindingSigner(source, options = {}) {
|
|
32115
|
+
if (isPersonalServerLiteOwnerBindingSigner(source)) {
|
|
32116
|
+
return source;
|
|
31994
32117
|
}
|
|
31995
|
-
|
|
31996
|
-
|
|
32118
|
+
const accountAddress = getAccountAddress2(options.account) ?? getAccountAddress2(source.account);
|
|
32119
|
+
if (accountAddress) {
|
|
32120
|
+
return {
|
|
32121
|
+
address: accountAddress,
|
|
32122
|
+
signMessage: ({ message }) => source.signMessage({
|
|
32123
|
+
account: options.account ?? source.account ?? accountAddress,
|
|
32124
|
+
message
|
|
32125
|
+
})
|
|
32126
|
+
};
|
|
31997
32127
|
}
|
|
31998
|
-
|
|
31999
|
-
|
|
32128
|
+
throw new Error(
|
|
32129
|
+
"Viem wallet client requires an account option or account property"
|
|
32130
|
+
);
|
|
32131
|
+
}
|
|
32132
|
+
async function buildPersonalServerLiteOwnerBindingSignature(input) {
|
|
32133
|
+
const message = buildPersonalServerLiteOwnerBindingMessage(
|
|
32134
|
+
input.signer.address
|
|
32135
|
+
);
|
|
32136
|
+
const signature = await input.signer.signMessage({ message });
|
|
32137
|
+
return {
|
|
32138
|
+
signature,
|
|
32139
|
+
signerAddress: input.signer.address,
|
|
32140
|
+
message,
|
|
32141
|
+
purpose: PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE
|
|
32142
|
+
};
|
|
32143
|
+
}
|
|
32144
|
+
var signPersonalServerLiteOwnerBinding = buildPersonalServerLiteOwnerBindingSignature;
|
|
32145
|
+
|
|
32146
|
+
// src/account/personal-server-registration.ts
|
|
32147
|
+
import { isAddress as isAddress3 } from "viem";
|
|
32148
|
+
var ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT = "personal_server.server_registration.v1";
|
|
32149
|
+
var AccountPersonalServerRegistrationError = class extends Error {
|
|
32150
|
+
status;
|
|
32151
|
+
code;
|
|
32152
|
+
details;
|
|
32153
|
+
constructor(input) {
|
|
32154
|
+
super(input.message);
|
|
32155
|
+
this.name = "AccountPersonalServerRegistrationError";
|
|
32156
|
+
this.status = input.status;
|
|
32157
|
+
this.code = input.code;
|
|
32158
|
+
this.details = input.details;
|
|
32000
32159
|
}
|
|
32001
|
-
|
|
32002
|
-
|
|
32160
|
+
};
|
|
32161
|
+
var DEFAULT_ACCOUNT_PS_REGISTRATION_PATH = "/api/v1/intents/personal-server-registration/sign";
|
|
32162
|
+
function trimTrailingSlash(value) {
|
|
32163
|
+
return value.replace(/\/+$/, "");
|
|
32164
|
+
}
|
|
32165
|
+
function assertAddress3(value, name) {
|
|
32166
|
+
if (!isAddress3(value)) {
|
|
32167
|
+
throw new Error(`${name} must be a valid EVM address`);
|
|
32003
32168
|
}
|
|
32004
|
-
|
|
32005
|
-
|
|
32169
|
+
}
|
|
32170
|
+
async function parseAccountResponse(response) {
|
|
32171
|
+
const body = await response.json().catch(() => void 0);
|
|
32172
|
+
if (!response.ok) {
|
|
32173
|
+
throw new AccountPersonalServerRegistrationError({
|
|
32174
|
+
status: response.status,
|
|
32175
|
+
code: accountErrorCode(body),
|
|
32176
|
+
message: accountErrorMessage(response.status, body),
|
|
32177
|
+
details: body
|
|
32178
|
+
});
|
|
32179
|
+
}
|
|
32180
|
+
return body;
|
|
32181
|
+
}
|
|
32182
|
+
function accountErrorMessage(status, body) {
|
|
32183
|
+
const nestedMessage = nestedAccountErrorField(body, "message");
|
|
32184
|
+
if (nestedMessage) {
|
|
32185
|
+
return nestedMessage;
|
|
32186
|
+
}
|
|
32187
|
+
if (isRecord(body) && typeof body.message === "string") {
|
|
32188
|
+
return body.message;
|
|
32189
|
+
}
|
|
32190
|
+
const code = accountErrorCode(body);
|
|
32191
|
+
if (code) {
|
|
32192
|
+
return `Account PS registration signing failed: ${code}`;
|
|
32193
|
+
}
|
|
32194
|
+
return `Account PS registration signing failed: ${status}`;
|
|
32195
|
+
}
|
|
32196
|
+
function accountErrorCode(body) {
|
|
32197
|
+
const nestedCode = nestedAccountErrorField(body, "code");
|
|
32198
|
+
if (nestedCode) {
|
|
32199
|
+
return nestedCode;
|
|
32200
|
+
}
|
|
32201
|
+
if (isRecord(body)) {
|
|
32202
|
+
if (typeof body.code === "string") {
|
|
32203
|
+
return body.code;
|
|
32204
|
+
}
|
|
32205
|
+
if (typeof body.error === "string") {
|
|
32206
|
+
return body.error;
|
|
32207
|
+
}
|
|
32208
|
+
}
|
|
32209
|
+
return void 0;
|
|
32210
|
+
}
|
|
32211
|
+
function nestedAccountErrorField(body, field) {
|
|
32212
|
+
if (!isRecord(body) || !isRecord(body.error)) {
|
|
32213
|
+
return void 0;
|
|
32214
|
+
}
|
|
32215
|
+
const value = body.error[field];
|
|
32216
|
+
return typeof value === "string" ? value : void 0;
|
|
32217
|
+
}
|
|
32218
|
+
function isRecord(value) {
|
|
32219
|
+
return typeof value === "object" && value !== null;
|
|
32220
|
+
}
|
|
32221
|
+
function normalizeAccountResponse(response) {
|
|
32222
|
+
return {
|
|
32223
|
+
...response,
|
|
32224
|
+
status: response.status === "fallback_required" ? "confirmation_required" : response.status,
|
|
32225
|
+
signerAddress: response.signerAddress ?? response.signer?.address,
|
|
32226
|
+
typedData: response.typedData ?? response.typed_data
|
|
32227
|
+
};
|
|
32228
|
+
}
|
|
32229
|
+
function buildSignedResult(response, request) {
|
|
32230
|
+
assertAddress3(response.signerAddress, "signerAddress");
|
|
32231
|
+
if (response.typedData) {
|
|
32232
|
+
assertTypedDataMatchesRequest(
|
|
32233
|
+
response.typedData,
|
|
32234
|
+
request,
|
|
32235
|
+
response.signerAddress
|
|
32236
|
+
);
|
|
32006
32237
|
}
|
|
32007
32238
|
return {
|
|
32008
|
-
|
|
32009
|
-
|
|
32010
|
-
|
|
32011
|
-
|
|
32012
|
-
|
|
32239
|
+
signature: response.signature,
|
|
32240
|
+
signerAddress: response.signerAddress,
|
|
32241
|
+
typedData: response.typedData ?? buildPersonalServerRegistrationTypedData({
|
|
32242
|
+
ownerAddress: response.signerAddress,
|
|
32243
|
+
...request
|
|
32244
|
+
}),
|
|
32245
|
+
intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT
|
|
32013
32246
|
};
|
|
32014
32247
|
}
|
|
32015
|
-
function
|
|
32016
|
-
|
|
32017
|
-
|
|
32248
|
+
function assertTypedDataMatchesRequest(typedData, request, expectedSignerAddress) {
|
|
32249
|
+
assertAddress3(
|
|
32250
|
+
typedData.message.ownerAddress,
|
|
32251
|
+
"typedData.message.ownerAddress"
|
|
32252
|
+
);
|
|
32253
|
+
assertAddress3(
|
|
32254
|
+
typedData.message.serverAddress,
|
|
32255
|
+
"typedData.message.serverAddress"
|
|
32256
|
+
);
|
|
32257
|
+
if (expectedSignerAddress && !sameAddress(typedData.message.ownerAddress, expectedSignerAddress)) {
|
|
32258
|
+
throw new Error(
|
|
32259
|
+
"Account typedData ownerAddress must match the expected signer address"
|
|
32260
|
+
);
|
|
32261
|
+
}
|
|
32262
|
+
if (!sameAddress(typedData.message.serverAddress, request.serverAddress)) {
|
|
32263
|
+
throw new Error(
|
|
32264
|
+
"Account typedData serverAddress must match the requested serverAddress"
|
|
32265
|
+
);
|
|
32266
|
+
}
|
|
32267
|
+
if (typedData.message.publicKey !== request.serverPublicKey) {
|
|
32268
|
+
throw new Error(
|
|
32269
|
+
"Account typedData publicKey must match the requested serverPublicKey"
|
|
32270
|
+
);
|
|
32271
|
+
}
|
|
32272
|
+
if (typedData.message.serverUrl !== request.serverUrl) {
|
|
32273
|
+
throw new Error(
|
|
32274
|
+
"Account typedData serverUrl must match the requested serverUrl"
|
|
32275
|
+
);
|
|
32276
|
+
}
|
|
32277
|
+
if (typedData.primaryType !== "ServerRegistration") {
|
|
32278
|
+
throw new Error("Account typedData primaryType must be ServerRegistration");
|
|
32279
|
+
}
|
|
32280
|
+
if (JSON.stringify(typedData.types) !== JSON.stringify(SERVER_REGISTRATION_TYPES)) {
|
|
32281
|
+
throw new Error("Account typedData types must be ServerRegistration types");
|
|
32282
|
+
}
|
|
32283
|
+
const expectedDomain = personalServerRegistrationDomain({
|
|
32284
|
+
config: request.config,
|
|
32285
|
+
chainId: request.chainId,
|
|
32286
|
+
verifyingContract: request.verifyingContract
|
|
32287
|
+
});
|
|
32288
|
+
if (!domainsEqual(typedData.domain, expectedDomain)) {
|
|
32289
|
+
throw new Error("Account typedData domain must match the requested domain");
|
|
32290
|
+
}
|
|
32291
|
+
}
|
|
32292
|
+
function sameAddress(a, b) {
|
|
32293
|
+
return a.toLowerCase() === b.toLowerCase();
|
|
32294
|
+
}
|
|
32295
|
+
function domainsEqual(a, b) {
|
|
32296
|
+
if (!a || !b) {
|
|
32297
|
+
return false;
|
|
32298
|
+
}
|
|
32299
|
+
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;
|
|
32300
|
+
}
|
|
32301
|
+
async function signPersonalServerRegistrationWithAccount(config, request) {
|
|
32302
|
+
assertAddress3(request.serverAddress, "serverAddress");
|
|
32303
|
+
const fetchImpl = config.fetchImpl ?? globalThis.fetch.bind(globalThis);
|
|
32304
|
+
const endpoint = new URL(
|
|
32305
|
+
config.endpointPath ?? DEFAULT_ACCOUNT_PS_REGISTRATION_PATH,
|
|
32306
|
+
`${trimTrailingSlash(config.accountOrigin)}/`
|
|
32307
|
+
);
|
|
32308
|
+
const response = await fetchImpl(endpoint, {
|
|
32309
|
+
method: "POST",
|
|
32310
|
+
headers: { "content-type": "application/json" },
|
|
32311
|
+
credentials: "include",
|
|
32312
|
+
body: JSON.stringify({
|
|
32313
|
+
intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
|
|
32314
|
+
serverAddress: request.serverAddress,
|
|
32315
|
+
serverPublicKey: request.serverPublicKey,
|
|
32316
|
+
serverUrl: request.serverUrl,
|
|
32317
|
+
config: request.config,
|
|
32318
|
+
chainId: request.chainId,
|
|
32319
|
+
verifyingContract: request.verifyingContract
|
|
32320
|
+
})
|
|
32321
|
+
});
|
|
32322
|
+
const body = normalizeAccountResponse(await parseAccountResponse(response));
|
|
32323
|
+
if (body.status === "signed") {
|
|
32324
|
+
if (!body.signature || !body.signerAddress) {
|
|
32325
|
+
throw new Error(
|
|
32326
|
+
"Account signed response must include signature and signerAddress"
|
|
32327
|
+
);
|
|
32328
|
+
}
|
|
32018
32329
|
return {
|
|
32019
|
-
|
|
32020
|
-
|
|
32330
|
+
status: "signed",
|
|
32331
|
+
result: buildSignedResult(
|
|
32332
|
+
{
|
|
32333
|
+
signature: body.signature,
|
|
32334
|
+
signerAddress: body.signerAddress,
|
|
32335
|
+
typedData: body.typedData
|
|
32336
|
+
},
|
|
32337
|
+
request
|
|
32338
|
+
)
|
|
32021
32339
|
};
|
|
32340
|
+
}
|
|
32341
|
+
if (body.status === "confirmation_required") {
|
|
32342
|
+
if (!body.typedData) {
|
|
32343
|
+
throw new Error(
|
|
32344
|
+
"Account confirmation_required response must include typedData"
|
|
32345
|
+
);
|
|
32346
|
+
}
|
|
32347
|
+
assertTypedDataMatchesRequest(body.typedData, request, body.signerAddress);
|
|
32348
|
+
if (!config.fallbackSigner) {
|
|
32349
|
+
return {
|
|
32350
|
+
status: "confirmation_required",
|
|
32351
|
+
typedData: body.typedData,
|
|
32352
|
+
signerAddress: body.signerAddress
|
|
32353
|
+
};
|
|
32354
|
+
}
|
|
32355
|
+
assertTypedDataMatchesRequest(
|
|
32356
|
+
body.typedData,
|
|
32357
|
+
request,
|
|
32358
|
+
config.fallbackSigner.address
|
|
32359
|
+
);
|
|
32360
|
+
const signature = await config.fallbackSigner.signTypedData(body.typedData);
|
|
32361
|
+
return {
|
|
32362
|
+
status: "fallback_signed",
|
|
32363
|
+
accountStatus: "confirmation_required",
|
|
32364
|
+
result: {
|
|
32365
|
+
signature,
|
|
32366
|
+
signerAddress: config.fallbackSigner.address,
|
|
32367
|
+
typedData: body.typedData,
|
|
32368
|
+
intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT
|
|
32369
|
+
}
|
|
32370
|
+
};
|
|
32371
|
+
}
|
|
32372
|
+
throw new Error(
|
|
32373
|
+
`Unsupported Account PS registration signing status: ${String(body.status)}`
|
|
32374
|
+
);
|
|
32375
|
+
}
|
|
32376
|
+
|
|
32377
|
+
// src/account/personal-server-lite-owner-binding.ts
|
|
32378
|
+
var AccountPersonalServerLiteOwnerBindingError = class extends Error {
|
|
32379
|
+
code;
|
|
32380
|
+
details;
|
|
32381
|
+
constructor(input) {
|
|
32382
|
+
super(input.message);
|
|
32383
|
+
this.name = "AccountPersonalServerLiteOwnerBindingError";
|
|
32384
|
+
this.code = input.code;
|
|
32385
|
+
this.details = input.details;
|
|
32386
|
+
}
|
|
32387
|
+
};
|
|
32388
|
+
async function signPersonalServerLiteOwnerBindingWithAccountClient(config) {
|
|
32389
|
+
let address;
|
|
32390
|
+
try {
|
|
32391
|
+
address = await config.client.getAddress();
|
|
32392
|
+
} catch (error) {
|
|
32393
|
+
throw accountOwnerBindingError(error);
|
|
32394
|
+
}
|
|
32395
|
+
if (!address) {
|
|
32396
|
+
throw new AccountPersonalServerLiteOwnerBindingError({
|
|
32397
|
+
message: "Account did not return a wallet address",
|
|
32398
|
+
code: "account_address_required"
|
|
32399
|
+
});
|
|
32400
|
+
}
|
|
32401
|
+
const message = buildPersonalServerLiteOwnerBindingMessage(address);
|
|
32402
|
+
let signature;
|
|
32403
|
+
try {
|
|
32404
|
+
signature = await config.client.signMessage({ message });
|
|
32405
|
+
} catch (error) {
|
|
32406
|
+
throw accountOwnerBindingError(error);
|
|
32407
|
+
}
|
|
32408
|
+
return {
|
|
32409
|
+
signature,
|
|
32410
|
+
signerAddress: address,
|
|
32411
|
+
message,
|
|
32412
|
+
purpose: PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE
|
|
32413
|
+
};
|
|
32414
|
+
}
|
|
32415
|
+
function accountOwnerBindingError(error) {
|
|
32416
|
+
if (error instanceof AccountPersonalServerLiteOwnerBindingError) {
|
|
32417
|
+
return error;
|
|
32418
|
+
}
|
|
32419
|
+
const rpcError = error;
|
|
32420
|
+
const code = rpcError?.code;
|
|
32421
|
+
const message = typeof rpcError?.message === "string" && rpcError.message.length > 0 ? rpcError.message : "Account PS Lite owner-binding signature failed";
|
|
32422
|
+
return new AccountPersonalServerLiteOwnerBindingError({
|
|
32423
|
+
message,
|
|
32424
|
+
code,
|
|
32425
|
+
details: error
|
|
32426
|
+
});
|
|
32427
|
+
}
|
|
32428
|
+
|
|
32429
|
+
// src/protocol/grants.ts
|
|
32430
|
+
import { verifyTypedData } from "viem";
|
|
32431
|
+
function isHexString(value) {
|
|
32432
|
+
return typeof value === "string" && value.startsWith("0x");
|
|
32433
|
+
}
|
|
32434
|
+
function isDataPortabilityGatewayConfig(value) {
|
|
32435
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
32436
|
+
return false;
|
|
32437
|
+
}
|
|
32438
|
+
const config = value;
|
|
32439
|
+
const contracts = config["contracts"];
|
|
32440
|
+
if (typeof config["chainId"] !== "number" || !Number.isInteger(config["chainId"]) || config["chainId"] <= 0 || contracts === null || typeof contracts !== "object" || Array.isArray(contracts)) {
|
|
32441
|
+
return false;
|
|
32442
|
+
}
|
|
32443
|
+
const c = contracts;
|
|
32444
|
+
return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]) && isHexString(c["dataPortabilityEscrow"]) && isHexString(c["feeRegistry"]);
|
|
32445
|
+
}
|
|
32446
|
+
function toUint256(value) {
|
|
32447
|
+
try {
|
|
32448
|
+
const big = typeof value === "bigint" ? value : BigInt(value);
|
|
32449
|
+
if (big < 0n) return null;
|
|
32450
|
+
return big;
|
|
32022
32451
|
} catch {
|
|
32023
32452
|
return null;
|
|
32024
32453
|
}
|
|
32025
32454
|
}
|
|
32026
32455
|
async function verifyGrantRegistration(input) {
|
|
32027
|
-
|
|
32028
|
-
|
|
32029
|
-
|
|
32030
|
-
|
|
32031
|
-
|
|
32032
|
-
};
|
|
32456
|
+
if (!Array.isArray(input.scopes) || input.scopes.length === 0) {
|
|
32457
|
+
return { valid: false, error: "scopes must be a non-empty array" };
|
|
32458
|
+
}
|
|
32459
|
+
if (!input.scopes.every((scope) => typeof scope === "string")) {
|
|
32460
|
+
return { valid: false, error: "scopes must contain only strings" };
|
|
32033
32461
|
}
|
|
32034
|
-
const
|
|
32035
|
-
if (
|
|
32036
|
-
return { valid: false, error: "
|
|
32462
|
+
const grantVersion = toUint256(input.grantVersion);
|
|
32463
|
+
if (grantVersion === null || grantVersion < 1n) {
|
|
32464
|
+
return { valid: false, error: "grantVersion must be a uint256 >= 1" };
|
|
32465
|
+
}
|
|
32466
|
+
const expiresAt = toUint256(input.expiresAt);
|
|
32467
|
+
if (expiresAt === null) {
|
|
32468
|
+
return { valid: false, error: "expiresAt must be a non-negative uint256" };
|
|
32037
32469
|
}
|
|
32038
32470
|
let valid;
|
|
32039
32471
|
try {
|
|
@@ -32045,8 +32477,9 @@ async function verifyGrantRegistration(input) {
|
|
|
32045
32477
|
message: {
|
|
32046
32478
|
grantorAddress: input.grantorAddress,
|
|
32047
32479
|
granteeId: input.granteeId,
|
|
32048
|
-
|
|
32049
|
-
|
|
32480
|
+
scopes: input.scopes,
|
|
32481
|
+
grantVersion,
|
|
32482
|
+
expiresAt
|
|
32050
32483
|
},
|
|
32051
32484
|
signature: input.signature
|
|
32052
32485
|
});
|
|
@@ -32057,19 +32490,128 @@ async function verifyGrantRegistration(input) {
|
|
|
32057
32490
|
return { valid: false, error: "Grant signature does not match grantor" };
|
|
32058
32491
|
}
|
|
32059
32492
|
const nowSeconds = input.nowSeconds ?? Math.floor(Date.now() / 1e3);
|
|
32060
|
-
if (
|
|
32493
|
+
if (expiresAt > 0n && expiresAt < BigInt(nowSeconds)) {
|
|
32061
32494
|
return { valid: false, error: "Grant has expired" };
|
|
32062
32495
|
}
|
|
32063
|
-
if (payload.user !== void 0 && payload.user.toLowerCase() !== input.grantorAddress.toLowerCase()) {
|
|
32064
|
-
return { valid: false, error: "Grant user does not match grantorAddress" };
|
|
32065
|
-
}
|
|
32066
32496
|
return {
|
|
32067
32497
|
valid: true,
|
|
32068
32498
|
grantorAddress: input.grantorAddress,
|
|
32069
32499
|
granteeId: input.granteeId,
|
|
32070
|
-
|
|
32071
|
-
|
|
32072
|
-
|
|
32500
|
+
scopes: input.scopes,
|
|
32501
|
+
grantVersion: grantVersion.toString(),
|
|
32502
|
+
expiresAt: expiresAt.toString()
|
|
32503
|
+
};
|
|
32504
|
+
}
|
|
32505
|
+
|
|
32506
|
+
// src/protocol/escrow-deposit.ts
|
|
32507
|
+
import { encodeFunctionData } from "viem";
|
|
32508
|
+
var ESCROW_DEPOSIT_ABI = [
|
|
32509
|
+
{
|
|
32510
|
+
type: "function",
|
|
32511
|
+
name: "depositNative",
|
|
32512
|
+
stateMutability: "payable",
|
|
32513
|
+
inputs: [{ name: "account", type: "address" }],
|
|
32514
|
+
outputs: []
|
|
32515
|
+
},
|
|
32516
|
+
{
|
|
32517
|
+
type: "function",
|
|
32518
|
+
name: "depositToken",
|
|
32519
|
+
stateMutability: "nonpayable",
|
|
32520
|
+
inputs: [
|
|
32521
|
+
{ name: "account", type: "address" },
|
|
32522
|
+
{ name: "token", type: "address" },
|
|
32523
|
+
{ name: "amount", type: "uint256" }
|
|
32524
|
+
],
|
|
32525
|
+
outputs: []
|
|
32526
|
+
}
|
|
32527
|
+
];
|
|
32528
|
+
function escrowContractAddress(config) {
|
|
32529
|
+
return config.contracts.dataPortabilityEscrow;
|
|
32530
|
+
}
|
|
32531
|
+
function encodeDepositNativeData(input) {
|
|
32532
|
+
return encodeFunctionData({
|
|
32533
|
+
abi: ESCROW_DEPOSIT_ABI,
|
|
32534
|
+
functionName: "depositNative",
|
|
32535
|
+
args: [input.account]
|
|
32536
|
+
});
|
|
32537
|
+
}
|
|
32538
|
+
function encodeDepositTokenData(input) {
|
|
32539
|
+
return encodeFunctionData({
|
|
32540
|
+
abi: ESCROW_DEPOSIT_ABI,
|
|
32541
|
+
functionName: "depositToken",
|
|
32542
|
+
args: [input.account, input.token, input.amount]
|
|
32543
|
+
});
|
|
32544
|
+
}
|
|
32545
|
+
function buildDepositNativeRequest(config, input) {
|
|
32546
|
+
return {
|
|
32547
|
+
to: escrowContractAddress(config),
|
|
32548
|
+
data: encodeDepositNativeData({ account: input.account }),
|
|
32549
|
+
value: input.amount
|
|
32550
|
+
};
|
|
32551
|
+
}
|
|
32552
|
+
function buildDepositTokenRequest(config, input) {
|
|
32553
|
+
return {
|
|
32554
|
+
to: escrowContractAddress(config),
|
|
32555
|
+
data: encodeDepositTokenData(input)
|
|
32556
|
+
};
|
|
32557
|
+
}
|
|
32558
|
+
|
|
32559
|
+
// src/protocol/fee-registry.ts
|
|
32560
|
+
import { parseAbi } from "viem";
|
|
32561
|
+
var FEE_REGISTRY_ABI = parseAbi([
|
|
32562
|
+
"struct Fee { uint256 amount; address asset; address payee; bool enabled; }",
|
|
32563
|
+
"function fees(bytes32 operation) view returns (Fee)",
|
|
32564
|
+
"function operationKey(string name) pure returns (bytes32)"
|
|
32565
|
+
]);
|
|
32566
|
+
function operationNameFor(kind, opts) {
|
|
32567
|
+
if (kind === "registration") {
|
|
32568
|
+
return opts?.registrationOpName ?? "registration";
|
|
32569
|
+
}
|
|
32570
|
+
return opts?.dataAccessOpName ?? "data_access";
|
|
32571
|
+
}
|
|
32572
|
+
async function getFee(client, config, kind, opts) {
|
|
32573
|
+
const address = config.contracts.feeRegistry;
|
|
32574
|
+
const opName = operationNameFor(kind, opts);
|
|
32575
|
+
const opKey = await client.readContract({
|
|
32576
|
+
address,
|
|
32577
|
+
abi: FEE_REGISTRY_ABI,
|
|
32578
|
+
functionName: "operationKey",
|
|
32579
|
+
args: [opName]
|
|
32580
|
+
});
|
|
32581
|
+
const fee = await client.readContract({
|
|
32582
|
+
address,
|
|
32583
|
+
abi: FEE_REGISTRY_ABI,
|
|
32584
|
+
functionName: "fees",
|
|
32585
|
+
args: [opKey]
|
|
32586
|
+
});
|
|
32587
|
+
if (!fee.enabled) {
|
|
32588
|
+
throw new Error(
|
|
32589
|
+
`FeeRegistry: operation "${opName}" (kind=${kind}) is not enabled \u2014 operator must call setFeeByName before payments will validate`
|
|
32590
|
+
);
|
|
32591
|
+
}
|
|
32592
|
+
if (fee.payee === "0x0000000000000000000000000000000000000000") {
|
|
32593
|
+
throw new Error(
|
|
32594
|
+
`FeeRegistry: operation "${opName}" has zero-address payee \u2014 contract pre-flight rejects payouts to 0x0`
|
|
32595
|
+
);
|
|
32596
|
+
}
|
|
32597
|
+
return fee;
|
|
32598
|
+
}
|
|
32599
|
+
async function getOpFee(client, config, opts) {
|
|
32600
|
+
const [registration, dataAccess] = await Promise.all([
|
|
32601
|
+
getFee(client, config, "registration", opts),
|
|
32602
|
+
getFee(client, config, "data_access", opts)
|
|
32603
|
+
]);
|
|
32604
|
+
if (registration.asset.toLowerCase() !== dataAccess.asset.toLowerCase()) {
|
|
32605
|
+
throw new Error(
|
|
32606
|
+
`FeeRegistry asset mismatch: registration=${registration.asset} vs data_access=${dataAccess.asset}. The gateway requires both fees to settle in the same asset.`
|
|
32607
|
+
);
|
|
32608
|
+
}
|
|
32609
|
+
return {
|
|
32610
|
+
asset: registration.asset,
|
|
32611
|
+
registrationFee: registration.amount,
|
|
32612
|
+
dataAccessFee: dataAccess.amount,
|
|
32613
|
+
registrationPayee: registration.payee,
|
|
32614
|
+
dataAccessPayee: dataAccess.payee
|
|
32073
32615
|
};
|
|
32074
32616
|
}
|
|
32075
32617
|
|
|
@@ -32269,6 +32811,68 @@ function createGatewayClient(baseUrl) {
|
|
|
32269
32811
|
alreadyRegistered: false
|
|
32270
32812
|
};
|
|
32271
32813
|
},
|
|
32814
|
+
async registerBuilder(params) {
|
|
32815
|
+
const res = await fetch(`${base}/v1/builders`, {
|
|
32816
|
+
method: "POST",
|
|
32817
|
+
headers: {
|
|
32818
|
+
"Content-Type": "application/json",
|
|
32819
|
+
Authorization: `Web3Signed ${params.signature}`
|
|
32820
|
+
},
|
|
32821
|
+
body: JSON.stringify({
|
|
32822
|
+
ownerAddress: params.ownerAddress,
|
|
32823
|
+
granteeAddress: params.granteeAddress,
|
|
32824
|
+
publicKey: params.publicKey,
|
|
32825
|
+
appUrl: params.appUrl
|
|
32826
|
+
})
|
|
32827
|
+
});
|
|
32828
|
+
if (res.status === 409) {
|
|
32829
|
+
const body2 = await res.json().catch(() => ({}));
|
|
32830
|
+
return {
|
|
32831
|
+
builderId: getMutationId(
|
|
32832
|
+
body2,
|
|
32833
|
+
"builderId"
|
|
32834
|
+
),
|
|
32835
|
+
alreadyRegistered: true
|
|
32836
|
+
};
|
|
32837
|
+
}
|
|
32838
|
+
if (!res.ok) {
|
|
32839
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
32840
|
+
}
|
|
32841
|
+
const body = await res.json().catch(() => ({}));
|
|
32842
|
+
return {
|
|
32843
|
+
builderId: getMutationId(body, "builderId"),
|
|
32844
|
+
alreadyRegistered: false
|
|
32845
|
+
};
|
|
32846
|
+
},
|
|
32847
|
+
async registerDataPoint(params) {
|
|
32848
|
+
const res = await fetch(`${base}/v1/data`, {
|
|
32849
|
+
method: "POST",
|
|
32850
|
+
headers: {
|
|
32851
|
+
"Content-Type": "application/json",
|
|
32852
|
+
Authorization: `Web3Signed ${params.signature}`
|
|
32853
|
+
},
|
|
32854
|
+
body: JSON.stringify({
|
|
32855
|
+
ownerAddress: params.ownerAddress,
|
|
32856
|
+
scope: params.scope,
|
|
32857
|
+
dataHash: params.dataHash,
|
|
32858
|
+
metadataHash: params.metadataHash,
|
|
32859
|
+
expectedVersion: params.expectedVersion
|
|
32860
|
+
})
|
|
32861
|
+
});
|
|
32862
|
+
if (!res.ok) {
|
|
32863
|
+
const body2 = await res.json().catch(() => ({}));
|
|
32864
|
+
const detail = body2.error ?? res.statusText;
|
|
32865
|
+
throw new Error(`Gateway error: ${res.status} ${detail}`);
|
|
32866
|
+
}
|
|
32867
|
+
const body = await res.json().catch(() => ({}));
|
|
32868
|
+
return {
|
|
32869
|
+
dataPointId: getMutationId(
|
|
32870
|
+
body,
|
|
32871
|
+
"dataPointId"
|
|
32872
|
+
),
|
|
32873
|
+
expectedVersion: body.expectedVersion
|
|
32874
|
+
};
|
|
32875
|
+
},
|
|
32272
32876
|
async registerFile(params) {
|
|
32273
32877
|
const res = await fetch(`${base}/v1/files`, {
|
|
32274
32878
|
method: "POST",
|
|
@@ -32306,8 +32910,9 @@ function createGatewayClient(baseUrl) {
|
|
|
32306
32910
|
body: JSON.stringify({
|
|
32307
32911
|
grantorAddress: params.grantorAddress,
|
|
32308
32912
|
granteeId: params.granteeId,
|
|
32309
|
-
|
|
32310
|
-
|
|
32913
|
+
scopes: params.scopes,
|
|
32914
|
+
grantVersion: params.grantVersion,
|
|
32915
|
+
expiresAt: params.expiresAt
|
|
32311
32916
|
})
|
|
32312
32917
|
});
|
|
32313
32918
|
if (res.status === 409) {
|
|
@@ -32332,13 +32937,71 @@ function createGatewayClient(baseUrl) {
|
|
|
32332
32937
|
Authorization: `Web3Signed ${params.signature}`
|
|
32333
32938
|
},
|
|
32334
32939
|
body: JSON.stringify({
|
|
32335
|
-
grantorAddress: params.grantorAddress
|
|
32940
|
+
grantorAddress: params.grantorAddress,
|
|
32941
|
+
grantVersion: params.grantVersion
|
|
32336
32942
|
})
|
|
32337
32943
|
});
|
|
32338
32944
|
if (res.status === 409) return;
|
|
32339
32945
|
if (!res.ok) {
|
|
32340
32946
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
32341
32947
|
}
|
|
32948
|
+
},
|
|
32949
|
+
async getEscrowBalance(account) {
|
|
32950
|
+
const res = await fetch(`${base}/v1/escrow/balance?account=${account}`);
|
|
32951
|
+
if (!res.ok) {
|
|
32952
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
32953
|
+
}
|
|
32954
|
+
return await res.json();
|
|
32955
|
+
},
|
|
32956
|
+
async submitEscrowDeposit(params) {
|
|
32957
|
+
const res = await fetch(`${base}/v1/escrow/deposit`, {
|
|
32958
|
+
method: "POST",
|
|
32959
|
+
headers: { "Content-Type": "application/json" },
|
|
32960
|
+
body: JSON.stringify({ txHash: params.txHash })
|
|
32961
|
+
});
|
|
32962
|
+
if (res.status !== 200 && res.status !== 202) {
|
|
32963
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
32964
|
+
}
|
|
32965
|
+
return await res.json();
|
|
32966
|
+
},
|
|
32967
|
+
async payForOperation(params) {
|
|
32968
|
+
const body = {
|
|
32969
|
+
payerAddress: params.payerAddress,
|
|
32970
|
+
opType: params.opType,
|
|
32971
|
+
opId: params.opId,
|
|
32972
|
+
asset: params.asset,
|
|
32973
|
+
amount: params.amount,
|
|
32974
|
+
paymentNonce: params.paymentNonce
|
|
32975
|
+
};
|
|
32976
|
+
if (params.accessRecord) {
|
|
32977
|
+
body["accessRecord"] = params.accessRecord;
|
|
32978
|
+
}
|
|
32979
|
+
const res = await fetch(`${base}/v1/escrow/pay`, {
|
|
32980
|
+
method: "POST",
|
|
32981
|
+
headers: {
|
|
32982
|
+
"Content-Type": "application/json",
|
|
32983
|
+
Authorization: `Web3Signed ${params.signature}`
|
|
32984
|
+
},
|
|
32985
|
+
body: JSON.stringify(body)
|
|
32986
|
+
});
|
|
32987
|
+
if (!res.ok) {
|
|
32988
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
32989
|
+
}
|
|
32990
|
+
return await res.json();
|
|
32991
|
+
},
|
|
32992
|
+
async settle(params) {
|
|
32993
|
+
const res = await fetch(`${base}/v1/settle`, {
|
|
32994
|
+
method: "POST",
|
|
32995
|
+
headers: { "Content-Type": "application/json" },
|
|
32996
|
+
// The gateway accepts an empty body; only `limit` is recognised.
|
|
32997
|
+
// Always send a JSON body so the gateway's req.body shape parse
|
|
32998
|
+
// doesn't have to deal with an undefined.
|
|
32999
|
+
body: JSON.stringify(params ?? {})
|
|
33000
|
+
});
|
|
33001
|
+
if (!res.ok) {
|
|
33002
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33003
|
+
}
|
|
33004
|
+
return await res.json();
|
|
32342
33005
|
}
|
|
32343
33006
|
};
|
|
32344
33007
|
}
|
|
@@ -32368,7 +33031,7 @@ var KNOWN_CODES = /* @__PURE__ */ new Set([
|
|
|
32368
33031
|
"server_not_configured",
|
|
32369
33032
|
"content_too_large"
|
|
32370
33033
|
]);
|
|
32371
|
-
function
|
|
33034
|
+
function isRecord2(value) {
|
|
32372
33035
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
32373
33036
|
}
|
|
32374
33037
|
function normalizeCode(value) {
|
|
@@ -32379,10 +33042,10 @@ function normalizeCode(value) {
|
|
|
32379
33042
|
return KNOWN_CODES.has(code) ? code : null;
|
|
32380
33043
|
}
|
|
32381
33044
|
function extractPSErrorBody(body) {
|
|
32382
|
-
if (!
|
|
33045
|
+
if (!isRecord2(body)) {
|
|
32383
33046
|
return null;
|
|
32384
33047
|
}
|
|
32385
|
-
const nested =
|
|
33048
|
+
const nested = isRecord2(body.error) ? body.error : null;
|
|
32386
33049
|
const code = normalizeCode(
|
|
32387
33050
|
nested?.errorCode ?? nested?.code ?? body.errorCode ?? body.code
|
|
32388
33051
|
);
|
|
@@ -32406,6 +33069,10 @@ async function parsePSError(response) {
|
|
|
32406
33069
|
return errorBody ? new PSError(errorBody.code, errorBody.message) : null;
|
|
32407
33070
|
}
|
|
32408
33071
|
export {
|
|
33072
|
+
ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
|
|
33073
|
+
ADD_DATA_TYPES,
|
|
33074
|
+
AccountPersonalServerLiteOwnerBindingError,
|
|
33075
|
+
AccountPersonalServerRegistrationError,
|
|
32409
33076
|
BUILDER_REGISTRATION_TYPES,
|
|
32410
33077
|
BlockchainError,
|
|
32411
33078
|
BrowserECIESUint8Provider as BrowserECIESProvider,
|
|
@@ -32417,8 +33084,11 @@ export {
|
|
|
32417
33084
|
DataFileEnvelopeSchema,
|
|
32418
33085
|
DropboxStorage,
|
|
32419
33086
|
ECIESError,
|
|
33087
|
+
ESCROW_DEPOSIT_ABI,
|
|
32420
33088
|
ExpiredTokenError,
|
|
33089
|
+
FEE_REGISTRY_ABI,
|
|
32421
33090
|
FILE_REGISTRATION_TYPES,
|
|
33091
|
+
GENERIC_PAYMENT_TYPES,
|
|
32422
33092
|
GRANT_REGISTRATION_TYPES,
|
|
32423
33093
|
GRANT_REVOCATION_TYPES,
|
|
32424
33094
|
GoogleDriveStorage,
|
|
@@ -32429,9 +33099,15 @@ export {
|
|
|
32429
33099
|
IpfsStorage,
|
|
32430
33100
|
MASTER_KEY_MESSAGE,
|
|
32431
33101
|
MissingAuthError,
|
|
33102
|
+
NATIVE_VANA_ASSET,
|
|
32432
33103
|
NetworkError,
|
|
32433
33104
|
NonceError,
|
|
32434
33105
|
OAuthClient,
|
|
33106
|
+
PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX,
|
|
33107
|
+
PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE,
|
|
33108
|
+
PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION,
|
|
33109
|
+
PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
|
|
33110
|
+
PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT,
|
|
32435
33111
|
PKCE_CHALLENGE_PATTERN,
|
|
32436
33112
|
PKCE_VERIFIER_PATTERN,
|
|
32437
33113
|
PSError,
|
|
@@ -32439,6 +33115,7 @@ export {
|
|
|
32439
33115
|
PersonalServerError,
|
|
32440
33116
|
PinataStorage,
|
|
32441
33117
|
R2Storage,
|
|
33118
|
+
RECORD_DATA_ACCESS_TYPES,
|
|
32442
33119
|
ReadOnlyError,
|
|
32443
33120
|
RelayerError,
|
|
32444
33121
|
SERVER_REGISTRATION_TYPES,
|
|
@@ -32453,6 +33130,12 @@ export {
|
|
|
32453
33130
|
VanaError,
|
|
32454
33131
|
VanaStorage,
|
|
32455
33132
|
assertValidPkceVerifier,
|
|
33133
|
+
buildDepositNativeRequest,
|
|
33134
|
+
buildDepositTokenRequest,
|
|
33135
|
+
buildPersonalServerLiteOwnerBindingMessage,
|
|
33136
|
+
buildPersonalServerLiteOwnerBindingSignature,
|
|
33137
|
+
buildPersonalServerRegistrationSignature,
|
|
33138
|
+
buildPersonalServerRegistrationTypedData,
|
|
32456
33139
|
buildWeb3SignedHeader,
|
|
32457
33140
|
builderRegistrationDomain,
|
|
32458
33141
|
chains,
|
|
@@ -32465,12 +33148,19 @@ export {
|
|
|
32465
33148
|
createGatewayClient,
|
|
32466
33149
|
createPlatformAdapterSafe,
|
|
32467
33150
|
createVanaStorageProvider,
|
|
33151
|
+
createViemPersonalServerLiteOwnerBindingSigner,
|
|
33152
|
+
createViemPersonalServerRegistrationSigner,
|
|
33153
|
+
dataRegistryDomain,
|
|
32468
33154
|
decryptWithPassword,
|
|
32469
33155
|
deriveMasterKey,
|
|
32470
33156
|
deriveScopeKey,
|
|
32471
33157
|
deserializeECIES,
|
|
32472
33158
|
detectPlatform,
|
|
33159
|
+
encodeDepositNativeData,
|
|
33160
|
+
encodeDepositTokenData,
|
|
32473
33161
|
encryptWithPassword,
|
|
33162
|
+
escrowContractAddress,
|
|
33163
|
+
escrowPaymentDomain,
|
|
32474
33164
|
fileRegistrationDomain,
|
|
32475
33165
|
generatePkceVerifier,
|
|
32476
33166
|
getAbi,
|
|
@@ -32479,6 +33169,8 @@ export {
|
|
|
32479
33169
|
getContractAddress,
|
|
32480
33170
|
getContractController,
|
|
32481
33171
|
getContractInfo,
|
|
33172
|
+
getFee,
|
|
33173
|
+
getOpFee,
|
|
32482
33174
|
getPlatformCapabilities,
|
|
32483
33175
|
getServiceEndpoints,
|
|
32484
33176
|
grantRegistrationDomain,
|
|
@@ -32490,16 +33182,20 @@ export {
|
|
|
32490
33182
|
moksha,
|
|
32491
33183
|
mokshaServices,
|
|
32492
33184
|
mokshaTestnet2 as mokshaTestnet,
|
|
32493
|
-
parseGrantRegistrationPayload,
|
|
32494
33185
|
parsePSError,
|
|
32495
33186
|
parseScope,
|
|
32496
33187
|
parseWeb3SignedHeader,
|
|
33188
|
+
personalServerRegistrationDomain,
|
|
32497
33189
|
recoverServerOwner,
|
|
33190
|
+
registerPersonalServerSignature,
|
|
32498
33191
|
scopeCoveredByGrant,
|
|
32499
33192
|
scopeMatchesPattern,
|
|
32500
33193
|
scopeToPathSegments,
|
|
32501
33194
|
serializeECIES,
|
|
32502
33195
|
serverRegistrationDomain,
|
|
33196
|
+
signPersonalServerLiteOwnerBinding,
|
|
33197
|
+
signPersonalServerLiteOwnerBindingWithAccountClient,
|
|
33198
|
+
signPersonalServerRegistrationWithAccount,
|
|
32503
33199
|
vanaMainnet2 as vanaMainnet,
|
|
32504
33200
|
verifyGrantRegistration,
|
|
32505
33201
|
verifyPkceChallenge,
|