@opendatalabs/vana-sdk 3.4.1 → 3.5.1-pr.159.12a6f39
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 +116 -0
- package/dist/account/personal-server-lite-owner-binding.cjs +3 -3
- package/dist/account/personal-server-lite-owner-binding.cjs.map +1 -1
- package/dist/account/personal-server-lite-owner-binding.d.ts +2 -2
- package/dist/account/personal-server-lite-owner-binding.js +1 -1
- package/dist/account/personal-server-lite-owner-binding.js.map +1 -1
- package/dist/direct/access-request-client.cjs +104 -0
- package/dist/direct/access-request-client.cjs.map +1 -0
- package/dist/direct/access-request-client.d.ts +51 -0
- package/dist/direct/access-request-client.js +79 -0
- package/dist/direct/access-request-client.js.map +1 -0
- package/dist/direct/access-request-client.test.d.ts +1 -0
- package/dist/direct/connect-flow.cjs +152 -0
- package/dist/direct/connect-flow.cjs.map +1 -0
- package/dist/direct/connect-flow.d.ts +85 -0
- package/dist/direct/connect-flow.js +128 -0
- package/dist/direct/connect-flow.js.map +1 -0
- package/dist/direct/connect-flow.test.d.ts +1 -0
- package/dist/direct/controller.cjs +129 -0
- package/dist/direct/controller.cjs.map +1 -0
- package/dist/direct/controller.d.ts +152 -0
- package/dist/direct/controller.js +109 -0
- package/dist/direct/controller.js.map +1 -0
- package/dist/direct/controller.test.d.ts +1 -0
- package/dist/direct/endpoints.cjs +45 -0
- package/dist/direct/endpoints.cjs.map +1 -0
- package/dist/direct/endpoints.d.ts +22 -0
- package/dist/direct/endpoints.js +19 -0
- package/dist/direct/endpoints.js.map +1 -0
- package/dist/direct/errors.cjs +65 -0
- package/dist/direct/errors.cjs.map +1 -0
- package/dist/direct/errors.d.ts +44 -0
- package/dist/direct/errors.js +38 -0
- package/dist/direct/errors.js.map +1 -0
- package/dist/direct/escrow-payment.cjs +96 -0
- package/dist/direct/escrow-payment.cjs.map +1 -0
- package/dist/direct/escrow-payment.d.ts +81 -0
- package/dist/direct/escrow-payment.js +72 -0
- package/dist/direct/escrow-payment.js.map +1 -0
- package/dist/direct/escrow-payment.test.d.ts +1 -0
- package/dist/direct/personal-server-read.cjs +149 -0
- package/dist/direct/personal-server-read.cjs.map +1 -0
- package/dist/direct/personal-server-read.d.ts +103 -0
- package/dist/direct/personal-server-read.js +124 -0
- package/dist/direct/personal-server-read.js.map +1 -0
- package/dist/direct/personal-server-read.test.d.ts +1 -0
- package/dist/direct/types.cjs +35 -0
- package/dist/direct/types.cjs.map +1 -0
- package/dist/direct/types.d.ts +205 -0
- package/dist/direct/types.js +11 -0
- package/dist/direct/types.js.map +1 -0
- package/dist/direct/use-direct-vana-connect.cjs +68 -0
- package/dist/direct/use-direct-vana-connect.cjs.map +1 -0
- package/dist/direct/use-direct-vana-connect.d.ts +45 -0
- package/dist/direct/use-direct-vana-connect.js +46 -0
- package/dist/direct/use-direct-vana-connect.js.map +1 -0
- package/dist/index.browser.d.ts +9 -4
- package/dist/index.browser.js +644 -178
- package/dist/index.browser.js.map +4 -4
- package/dist/index.node.cjs +672 -183
- package/dist/index.node.cjs.map +4 -4
- package/dist/index.node.d.ts +9 -4
- package/dist/index.node.js +644 -178
- package/dist/index.node.js.map +4 -4
- package/dist/personal-server-lite/owner-binding.cjs +93 -0
- package/dist/personal-server-lite/owner-binding.cjs.map +1 -0
- package/dist/personal-server-lite/owner-binding.d.ts +44 -0
- package/dist/personal-server-lite/owner-binding.js +65 -0
- package/dist/personal-server-lite/owner-binding.js.map +1 -0
- package/dist/personal-server-lite/owner-binding.test.d.ts +1 -0
- package/dist/protocol/data-point-status.cjs +80 -0
- package/dist/protocol/data-point-status.cjs.map +1 -0
- package/dist/protocol/data-point-status.d.ts +34 -0
- package/dist/protocol/data-point-status.js +51 -0
- package/dist/protocol/data-point-status.js.map +1 -0
- package/dist/protocol/data-point-status.test.d.ts +1 -0
- package/dist/protocol/eip712.cjs +53 -31
- package/dist/protocol/eip712.cjs.map +1 -1
- package/dist/protocol/eip712.d.ts +98 -43
- package/dist/protocol/eip712.js +47 -27
- 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/escrow.cjs +146 -0
- package/dist/protocol/escrow.cjs.map +1 -0
- package/dist/protocol/escrow.d.ts +336 -0
- package/dist/protocol/escrow.js +118 -0
- package/dist/protocol/escrow.js.map +1 -0
- package/dist/protocol/escrow.test.d.ts +1 -0
- package/dist/protocol/fee-registry.cjs +116 -0
- package/dist/protocol/fee-registry.cjs.map +1 -0
- package/dist/protocol/fee-registry.d.ts +151 -0
- package/dist/protocol/fee-registry.js +89 -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 +107 -37
- package/dist/protocol/gateway.cjs.map +1 -1
- package/dist/protocol/gateway.d.ts +223 -57
- package/dist/protocol/gateway.js +107 -37
- package/dist/protocol/gateway.js.map +1 -1
- package/dist/protocol/grants.cjs +27 -64
- package/dist/protocol/grants.cjs.map +1 -1
- package/dist/protocol/grants.d.ts +6 -13
- package/dist/protocol/grants.js +27 -63
- package/dist/protocol/grants.js.map +1 -1
- package/dist/protocol/personal-server-data.cjs +71 -0
- package/dist/protocol/personal-server-data.cjs.map +1 -0
- package/dist/protocol/personal-server-data.d.ts +16 -0
- package/dist/protocol/personal-server-data.js +47 -0
- package/dist/protocol/personal-server-data.js.map +1 -0
- package/dist/protocol/personal-server-data.test.d.ts +1 -0
- package/dist/protocol/personal-server-registration.cjs +16 -4
- package/dist/protocol/personal-server-registration.cjs.map +1 -1
- package/dist/protocol/personal-server-registration.d.ts +5 -2
- package/dist/protocol/personal-server-registration.js +16 -4
- package/dist/protocol/personal-server-registration.js.map +1 -1
- package/dist/react.cjs +32 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.ts +33 -0
- package/dist/react.js +11 -0
- package/dist/react.js.map +1 -0
- package/dist/server.cjs +73 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.ts +32 -0
- package/dist/server.js +55 -0
- package/dist/server.js.map +1 -0
- package/dist/storage/providers/vana-storage.cjs +75 -17
- package/dist/storage/providers/vana-storage.cjs.map +1 -1
- package/dist/storage/providers/vana-storage.js +75 -17
- package/dist/storage/providers/vana-storage.js.map +1 -1
- package/package.json +20 -1
package/dist/index.browser.js
CHANGED
|
@@ -29009,6 +29009,8 @@ async function buildWeb3SignedHeader(params) {
|
|
|
29009
29009
|
var DEFAULT_ENDPOINT = "https://storage.vana.org";
|
|
29010
29010
|
var BLOB_PATH_PREFIX = "/v1/blobs";
|
|
29011
29011
|
var DEFAULT_TOKEN_TTL_SECONDS = 300;
|
|
29012
|
+
var MAX_UPLOAD_ATTEMPTS = 4;
|
|
29013
|
+
var MAX_RATE_LIMIT_DELAY_MS = 3e4;
|
|
29012
29014
|
var VanaStorage = class {
|
|
29013
29015
|
endpoint;
|
|
29014
29016
|
signer;
|
|
@@ -29047,27 +29049,46 @@ var VanaStorage = class {
|
|
|
29047
29049
|
const body = new Uint8Array(await file.arrayBuffer());
|
|
29048
29050
|
const contentType = file.type !== "" ? file.type : "application/octet-stream";
|
|
29049
29051
|
const header = await this.signRequest("PUT", path, body);
|
|
29050
|
-
let response;
|
|
29051
|
-
|
|
29052
|
-
|
|
29053
|
-
|
|
29054
|
-
|
|
29055
|
-
|
|
29056
|
-
|
|
29057
|
-
|
|
29058
|
-
|
|
29059
|
-
|
|
29060
|
-
|
|
29052
|
+
let response = null;
|
|
29053
|
+
let responseText = "";
|
|
29054
|
+
for (let attempt = 1; attempt <= MAX_UPLOAD_ATTEMPTS; attempt++) {
|
|
29055
|
+
try {
|
|
29056
|
+
response = await this.fetchImpl(`${this.endpoint}${path}`, {
|
|
29057
|
+
method: "PUT",
|
|
29058
|
+
headers: {
|
|
29059
|
+
authorization: header,
|
|
29060
|
+
"content-type": contentType
|
|
29061
|
+
},
|
|
29062
|
+
body
|
|
29063
|
+
});
|
|
29064
|
+
} catch (cause) {
|
|
29065
|
+
throw new StorageError(
|
|
29066
|
+
`vana-storage upload network error: ${describe(cause)}`,
|
|
29067
|
+
"UPLOAD_ERROR",
|
|
29068
|
+
"vana-storage",
|
|
29069
|
+
{ cause: cause instanceof Error ? cause : void 0 }
|
|
29070
|
+
);
|
|
29071
|
+
}
|
|
29072
|
+
if (response.ok) {
|
|
29073
|
+
break;
|
|
29074
|
+
}
|
|
29075
|
+
responseText = await safeText(response);
|
|
29076
|
+
if (response.status === 429 && attempt < MAX_UPLOAD_ATTEMPTS) {
|
|
29077
|
+
const delayMs = retryDelayMs(response, responseText);
|
|
29078
|
+
if (delayMs > 0) {
|
|
29079
|
+
await sleep(delayMs);
|
|
29080
|
+
}
|
|
29081
|
+
continue;
|
|
29082
|
+
}
|
|
29061
29083
|
throw new StorageError(
|
|
29062
|
-
`vana-storage upload
|
|
29063
|
-
"
|
|
29064
|
-
"vana-storage"
|
|
29065
|
-
{ cause: cause instanceof Error ? cause : void 0 }
|
|
29084
|
+
`vana-storage upload failed: ${response.status} ${response.statusText} - ${responseText}`,
|
|
29085
|
+
"UPLOAD_FAILED",
|
|
29086
|
+
"vana-storage"
|
|
29066
29087
|
);
|
|
29067
29088
|
}
|
|
29068
|
-
if (!response
|
|
29089
|
+
if (!response?.ok) {
|
|
29069
29090
|
throw new StorageError(
|
|
29070
|
-
`vana-storage upload failed
|
|
29091
|
+
`vana-storage upload failed after ${MAX_UPLOAD_ATTEMPTS} attempts - ${responseText}`,
|
|
29071
29092
|
"UPLOAD_FAILED",
|
|
29072
29093
|
"vana-storage"
|
|
29073
29094
|
);
|
|
@@ -29220,6 +29241,43 @@ function describe(value) {
|
|
|
29220
29241
|
if (value instanceof Error) return value.message;
|
|
29221
29242
|
return String(value);
|
|
29222
29243
|
}
|
|
29244
|
+
function retryDelayMs(response, responseText) {
|
|
29245
|
+
const headerDelayMs = parseRetryAfterHeaderMs(
|
|
29246
|
+
response.headers.get("retry-after")
|
|
29247
|
+
);
|
|
29248
|
+
if (headerDelayMs !== null) {
|
|
29249
|
+
return clampRateLimitDelay(headerDelayMs);
|
|
29250
|
+
}
|
|
29251
|
+
return clampRateLimitDelay(parseRetryAfterBodyMs(responseText) ?? 0);
|
|
29252
|
+
}
|
|
29253
|
+
function parseRetryAfterHeaderMs(value) {
|
|
29254
|
+
if (!value) return null;
|
|
29255
|
+
const seconds = Number(value);
|
|
29256
|
+
if (Number.isFinite(seconds)) {
|
|
29257
|
+
return seconds * 1e3;
|
|
29258
|
+
}
|
|
29259
|
+
const dateMs = Date.parse(value);
|
|
29260
|
+
if (Number.isFinite(dateMs)) {
|
|
29261
|
+
return Math.max(0, dateMs - Date.now());
|
|
29262
|
+
}
|
|
29263
|
+
return null;
|
|
29264
|
+
}
|
|
29265
|
+
function parseRetryAfterBodyMs(responseText) {
|
|
29266
|
+
if (!responseText) return null;
|
|
29267
|
+
try {
|
|
29268
|
+
const parsed = JSON.parse(responseText);
|
|
29269
|
+
const seconds = Number(parsed.retryAfter);
|
|
29270
|
+
return Number.isFinite(seconds) ? seconds * 1e3 : null;
|
|
29271
|
+
} catch {
|
|
29272
|
+
return null;
|
|
29273
|
+
}
|
|
29274
|
+
}
|
|
29275
|
+
function clampRateLimitDelay(delayMs) {
|
|
29276
|
+
return Math.min(Math.max(0, delayMs), MAX_RATE_LIMIT_DELAY_MS);
|
|
29277
|
+
}
|
|
29278
|
+
function sleep(ms) {
|
|
29279
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
29280
|
+
}
|
|
29223
29281
|
async function safeText(response) {
|
|
29224
29282
|
try {
|
|
29225
29283
|
return await response.text();
|
|
@@ -31882,6 +31940,7 @@ async function verifyWeb3Signed(params) {
|
|
|
31882
31940
|
// src/protocol/eip712.ts
|
|
31883
31941
|
var DOMAIN_NAME = "Vana Data Portability";
|
|
31884
31942
|
var DOMAIN_VERSION = "1";
|
|
31943
|
+
var NATIVE_VANA_ASSET = "0x0000000000000000000000000000000000000000";
|
|
31885
31944
|
function buildDomain(chainId, verifyingContract) {
|
|
31886
31945
|
return {
|
|
31887
31946
|
name: DOMAIN_NAME,
|
|
@@ -31890,13 +31949,7 @@ function buildDomain(chainId, verifyingContract) {
|
|
|
31890
31949
|
verifyingContract
|
|
31891
31950
|
};
|
|
31892
31951
|
}
|
|
31893
|
-
function
|
|
31894
|
-
return buildDomain(
|
|
31895
|
-
config.chainId,
|
|
31896
|
-
config.contracts.dataRegistry
|
|
31897
|
-
);
|
|
31898
|
-
}
|
|
31899
|
-
function fileDeletionDomain(config) {
|
|
31952
|
+
function dataRegistryDomain(config) {
|
|
31900
31953
|
return buildDomain(
|
|
31901
31954
|
config.chainId,
|
|
31902
31955
|
config.contracts.dataRegistry
|
|
@@ -31926,31 +31979,26 @@ function builderRegistrationDomain(config) {
|
|
|
31926
31979
|
config.contracts.dataPortabilityGrantees
|
|
31927
31980
|
);
|
|
31928
31981
|
}
|
|
31929
|
-
|
|
31930
|
-
|
|
31931
|
-
|
|
31932
|
-
|
|
31933
|
-
|
|
31934
|
-
|
|
31935
|
-
};
|
|
31936
|
-
var FILE_DELETION_TYPES = {
|
|
31937
|
-
FileDeletion: [
|
|
31938
|
-
{ name: "ownerAddress", type: "address" },
|
|
31939
|
-
{ name: "fileId", type: "bytes32" }
|
|
31940
|
-
]
|
|
31941
|
-
};
|
|
31982
|
+
function escrowPaymentDomain(config) {
|
|
31983
|
+
return buildDomain(
|
|
31984
|
+
config.chainId,
|
|
31985
|
+
config.contracts.dataPortabilityEscrow
|
|
31986
|
+
);
|
|
31987
|
+
}
|
|
31942
31988
|
var GRANT_REGISTRATION_TYPES = {
|
|
31943
31989
|
GrantRegistration: [
|
|
31944
31990
|
{ name: "grantorAddress", type: "address" },
|
|
31945
31991
|
{ name: "granteeId", type: "bytes32" },
|
|
31946
|
-
{ name: "
|
|
31947
|
-
{ name: "
|
|
31992
|
+
{ name: "scopes", type: "string[]" },
|
|
31993
|
+
{ name: "grantVersion", type: "uint256" },
|
|
31994
|
+
{ name: "expiresAt", type: "uint256" }
|
|
31948
31995
|
]
|
|
31949
31996
|
};
|
|
31950
31997
|
var GRANT_REVOCATION_TYPES = {
|
|
31951
31998
|
GrantRevocation: [
|
|
31952
31999
|
{ name: "grantorAddress", type: "address" },
|
|
31953
|
-
{ name: "grantId", type: "bytes32" }
|
|
32000
|
+
{ name: "grantId", type: "bytes32" },
|
|
32001
|
+
{ name: "grantVersion", type: "uint256" }
|
|
31954
32002
|
]
|
|
31955
32003
|
};
|
|
31956
32004
|
var SERVER_REGISTRATION_TYPES = {
|
|
@@ -31969,13 +32017,34 @@ var BUILDER_REGISTRATION_TYPES = {
|
|
|
31969
32017
|
{ name: "appUrl", type: "string" }
|
|
31970
32018
|
]
|
|
31971
32019
|
};
|
|
32020
|
+
var ADD_DATA_TYPES = {
|
|
32021
|
+
AddData: [
|
|
32022
|
+
{ name: "ownerAddress", type: "address" },
|
|
32023
|
+
{ name: "scope", type: "string" },
|
|
32024
|
+
{ name: "dataHash", type: "bytes32" },
|
|
32025
|
+
{ name: "metadataHash", type: "bytes32" },
|
|
32026
|
+
{ name: "expectedVersion", type: "uint256" }
|
|
32027
|
+
]
|
|
32028
|
+
};
|
|
32029
|
+
var RECORD_DATA_ACCESS_TYPES = {
|
|
32030
|
+
RecordDataAccess: [
|
|
32031
|
+
{ name: "ownerAddress", type: "address" },
|
|
32032
|
+
{ name: "scope", type: "string" },
|
|
32033
|
+
{ name: "version", type: "uint256" },
|
|
32034
|
+
{ name: "accessor", type: "address" },
|
|
32035
|
+
{ name: "recordId", type: "bytes32" }
|
|
32036
|
+
]
|
|
32037
|
+
};
|
|
31972
32038
|
|
|
31973
32039
|
// src/protocol/personal-server-registration.ts
|
|
31974
32040
|
import {
|
|
31975
32041
|
isAddress
|
|
31976
32042
|
} from "viem";
|
|
31977
|
-
var PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID =
|
|
31978
|
-
var PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT =
|
|
32043
|
+
var PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID = vanaMainnet2.id;
|
|
32044
|
+
var PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT = getContractAddress(
|
|
32045
|
+
PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
|
|
32046
|
+
"DataPortabilityServers"
|
|
32047
|
+
);
|
|
31979
32048
|
function assertAddress(value, name) {
|
|
31980
32049
|
if (!isAddress(value)) {
|
|
31981
32050
|
throw new Error(`${name} must be a valid EVM address`);
|
|
@@ -31990,6 +32059,12 @@ function getAccountAddress(account) {
|
|
|
31990
32059
|
function isPersonalServerRegistrationSigner(source) {
|
|
31991
32060
|
return "address" in source && typeof source.signTypedData === "function";
|
|
31992
32061
|
}
|
|
32062
|
+
function getDefaultServerRegistrationContract(chainId) {
|
|
32063
|
+
return getContractAddress(
|
|
32064
|
+
chainId,
|
|
32065
|
+
"DataPortabilityServers"
|
|
32066
|
+
);
|
|
32067
|
+
}
|
|
31993
32068
|
function createViemPersonalServerRegistrationSigner(source, options = {}) {
|
|
31994
32069
|
if (isPersonalServerRegistrationSigner(source)) {
|
|
31995
32070
|
return source;
|
|
@@ -32012,12 +32087,13 @@ function personalServerRegistrationDomain(input = {}) {
|
|
|
32012
32087
|
if (input.config) {
|
|
32013
32088
|
return serverRegistrationDomain(input.config);
|
|
32014
32089
|
}
|
|
32015
|
-
const
|
|
32090
|
+
const chainId = input.chainId ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID;
|
|
32091
|
+
const verifyingContract = input.verifyingContract ?? getDefaultServerRegistrationContract(chainId);
|
|
32016
32092
|
assertAddress(verifyingContract, "verifyingContract");
|
|
32017
32093
|
return {
|
|
32018
32094
|
name: "Vana Data Portability",
|
|
32019
32095
|
version: "1",
|
|
32020
|
-
chainId
|
|
32096
|
+
chainId,
|
|
32021
32097
|
verifyingContract
|
|
32022
32098
|
};
|
|
32023
32099
|
}
|
|
@@ -32055,11 +32131,11 @@ async function buildPersonalServerRegistrationSignature(input) {
|
|
|
32055
32131
|
}
|
|
32056
32132
|
var registerPersonalServerSignature = buildPersonalServerRegistrationSignature;
|
|
32057
32133
|
|
|
32058
|
-
// src/
|
|
32134
|
+
// src/personal-server-lite/owner-binding.ts
|
|
32059
32135
|
import {
|
|
32060
32136
|
isAddress as isAddress2
|
|
32061
32137
|
} from "viem";
|
|
32062
|
-
var PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION = "vana.
|
|
32138
|
+
var PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION = "vana.ps-lite.owner-binding.v1";
|
|
32063
32139
|
var PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE = "ps-lite-owner";
|
|
32064
32140
|
var PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX = `${PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION}:${PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE}:`;
|
|
32065
32141
|
function assertAddress2(value, name) {
|
|
@@ -32410,67 +32486,34 @@ function isDataPortabilityGatewayConfig(value) {
|
|
|
32410
32486
|
return false;
|
|
32411
32487
|
}
|
|
32412
32488
|
const c = contracts;
|
|
32413
|
-
return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]);
|
|
32489
|
+
return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]) && isHexString(c["dataPortabilityEscrow"]) && isHexString(c["feeRegistry"]);
|
|
32414
32490
|
}
|
|
32415
|
-
function
|
|
32416
|
-
let parsed;
|
|
32491
|
+
function toUint256(value) {
|
|
32417
32492
|
try {
|
|
32418
|
-
|
|
32419
|
-
|
|
32420
|
-
|
|
32421
|
-
|
|
32422
|
-
|
|
32423
|
-
return
|
|
32424
|
-
}
|
|
32425
|
-
const value = parsed;
|
|
32426
|
-
if (!Array.isArray(value["scopes"]) || value["scopes"].length === 0) {
|
|
32427
|
-
return null;
|
|
32428
|
-
}
|
|
32429
|
-
if (!value["scopes"].every((scope) => typeof scope === "string")) {
|
|
32430
|
-
return null;
|
|
32431
|
-
}
|
|
32432
|
-
if (typeof value["expiresAt"] !== "number" || !Number.isFinite(value["expiresAt"])) {
|
|
32433
|
-
return null;
|
|
32434
|
-
}
|
|
32435
|
-
if (value["user"] !== void 0 && !isHexString(value["user"])) {
|
|
32436
|
-
return null;
|
|
32437
|
-
}
|
|
32438
|
-
if (value["builder"] !== void 0 && !isHexString(value["builder"])) {
|
|
32439
|
-
return null;
|
|
32440
|
-
}
|
|
32441
|
-
if (value["nonce"] !== void 0 && (typeof value["nonce"] !== "number" || !Number.isFinite(value["nonce"]))) {
|
|
32442
|
-
return null;
|
|
32443
|
-
}
|
|
32444
|
-
return {
|
|
32445
|
-
user: value["user"],
|
|
32446
|
-
builder: value["builder"],
|
|
32447
|
-
scopes: value["scopes"],
|
|
32448
|
-
expiresAt: value["expiresAt"],
|
|
32449
|
-
nonce: value["nonce"]
|
|
32450
|
-
};
|
|
32451
|
-
}
|
|
32452
|
-
function parseFileIds(fileIds) {
|
|
32453
|
-
try {
|
|
32454
|
-
const values = (fileIds ?? []).map((fileId) => BigInt(fileId));
|
|
32455
|
-
return {
|
|
32456
|
-
values,
|
|
32457
|
-
display: values.map((fileId) => fileId.toString())
|
|
32458
|
-
};
|
|
32493
|
+
if (typeof value === "number" && !Number.isSafeInteger(value)) {
|
|
32494
|
+
return null;
|
|
32495
|
+
}
|
|
32496
|
+
const big = typeof value === "bigint" ? value : BigInt(value);
|
|
32497
|
+
if (big < 0n) return null;
|
|
32498
|
+
return big;
|
|
32459
32499
|
} catch {
|
|
32460
32500
|
return null;
|
|
32461
32501
|
}
|
|
32462
32502
|
}
|
|
32463
32503
|
async function verifyGrantRegistration(input) {
|
|
32464
|
-
|
|
32465
|
-
|
|
32466
|
-
|
|
32467
|
-
|
|
32468
|
-
|
|
32469
|
-
};
|
|
32504
|
+
if (!Array.isArray(input.scopes) || input.scopes.length === 0) {
|
|
32505
|
+
return { valid: false, error: "scopes must be a non-empty array" };
|
|
32506
|
+
}
|
|
32507
|
+
if (!input.scopes.every((scope) => typeof scope === "string")) {
|
|
32508
|
+
return { valid: false, error: "scopes must contain only strings" };
|
|
32470
32509
|
}
|
|
32471
|
-
const
|
|
32472
|
-
if (
|
|
32473
|
-
return { valid: false, error: "
|
|
32510
|
+
const grantVersion = toUint256(input.grantVersion);
|
|
32511
|
+
if (grantVersion === null || grantVersion < 1n) {
|
|
32512
|
+
return { valid: false, error: "grantVersion must be a uint256 >= 1" };
|
|
32513
|
+
}
|
|
32514
|
+
const expiresAt = toUint256(input.expiresAt);
|
|
32515
|
+
if (expiresAt === null) {
|
|
32516
|
+
return { valid: false, error: "expiresAt must be a non-negative uint256" };
|
|
32474
32517
|
}
|
|
32475
32518
|
let valid;
|
|
32476
32519
|
try {
|
|
@@ -32482,8 +32525,9 @@ async function verifyGrantRegistration(input) {
|
|
|
32482
32525
|
message: {
|
|
32483
32526
|
grantorAddress: input.grantorAddress,
|
|
32484
32527
|
granteeId: input.granteeId,
|
|
32485
|
-
|
|
32486
|
-
|
|
32528
|
+
scopes: input.scopes,
|
|
32529
|
+
grantVersion,
|
|
32530
|
+
expiresAt
|
|
32487
32531
|
},
|
|
32488
32532
|
signature: input.signature
|
|
32489
32533
|
});
|
|
@@ -32494,26 +32538,269 @@ async function verifyGrantRegistration(input) {
|
|
|
32494
32538
|
return { valid: false, error: "Grant signature does not match grantor" };
|
|
32495
32539
|
}
|
|
32496
32540
|
const nowSeconds = input.nowSeconds ?? Math.floor(Date.now() / 1e3);
|
|
32497
|
-
if (
|
|
32541
|
+
if (expiresAt > 0n && expiresAt < BigInt(nowSeconds)) {
|
|
32498
32542
|
return { valid: false, error: "Grant has expired" };
|
|
32499
32543
|
}
|
|
32500
|
-
if (payload.user !== void 0 && payload.user.toLowerCase() !== input.grantorAddress.toLowerCase()) {
|
|
32501
|
-
return { valid: false, error: "Grant user does not match grantorAddress" };
|
|
32502
|
-
}
|
|
32503
32544
|
return {
|
|
32504
32545
|
valid: true,
|
|
32505
32546
|
grantorAddress: input.grantorAddress,
|
|
32506
32547
|
granteeId: input.granteeId,
|
|
32507
|
-
|
|
32508
|
-
|
|
32509
|
-
|
|
32548
|
+
scopes: input.scopes,
|
|
32549
|
+
grantVersion: grantVersion.toString(),
|
|
32550
|
+
expiresAt: expiresAt.toString()
|
|
32510
32551
|
};
|
|
32511
32552
|
}
|
|
32512
32553
|
|
|
32513
|
-
// src/protocol/
|
|
32554
|
+
// src/protocol/fee-registry.ts
|
|
32555
|
+
import { parseAbi } from "viem";
|
|
32556
|
+
var FEE_REGISTRY_ABI = parseAbi([
|
|
32557
|
+
"struct Fee { uint256 amount; address asset; address payee; bool enabled; }",
|
|
32558
|
+
"function fees(bytes32 operation) view returns (Fee)",
|
|
32559
|
+
"function operationKey(string name) pure returns (bytes32)"
|
|
32560
|
+
]);
|
|
32561
|
+
var REGISTRATION_KIND_FOR_OP = {
|
|
32562
|
+
grant: "grant_registration",
|
|
32563
|
+
data: "data_registration",
|
|
32564
|
+
server: "server_registration",
|
|
32565
|
+
builder: "builder_registration"
|
|
32566
|
+
};
|
|
32567
|
+
function operationNameFor(kind, opts) {
|
|
32568
|
+
switch (kind) {
|
|
32569
|
+
case "grant_registration":
|
|
32570
|
+
return opts?.grantRegistrationOpName ?? "grant_registration";
|
|
32571
|
+
case "data_access":
|
|
32572
|
+
return opts?.dataAccessOpName ?? "data_access";
|
|
32573
|
+
case "data_registration":
|
|
32574
|
+
return opts?.dataRegistrationOpName ?? "data_registration";
|
|
32575
|
+
case "server_registration":
|
|
32576
|
+
return opts?.serverRegistrationOpName ?? "server_registration";
|
|
32577
|
+
case "builder_registration":
|
|
32578
|
+
return opts?.builderRegistrationOpName ?? "builder_registration";
|
|
32579
|
+
}
|
|
32580
|
+
}
|
|
32581
|
+
var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
32582
|
+
async function getFee(client, config, kind, opts) {
|
|
32583
|
+
const address = config.contracts.feeRegistry;
|
|
32584
|
+
const opName = operationNameFor(kind, opts);
|
|
32585
|
+
const opKey = await client.readContract({
|
|
32586
|
+
address,
|
|
32587
|
+
abi: FEE_REGISTRY_ABI,
|
|
32588
|
+
functionName: "operationKey",
|
|
32589
|
+
args: [opName]
|
|
32590
|
+
});
|
|
32591
|
+
const fee = await client.readContract({
|
|
32592
|
+
address,
|
|
32593
|
+
abi: FEE_REGISTRY_ABI,
|
|
32594
|
+
functionName: "fees",
|
|
32595
|
+
args: [opKey]
|
|
32596
|
+
});
|
|
32597
|
+
if (fee.enabled && fee.payee === ZERO_ADDRESS) {
|
|
32598
|
+
throw new Error(
|
|
32599
|
+
`FeeRegistry: enabled operation "${opName}" has zero-address payee \u2014 contract pre-flight rejects payouts to 0x0`
|
|
32600
|
+
);
|
|
32601
|
+
}
|
|
32602
|
+
return fee;
|
|
32603
|
+
}
|
|
32604
|
+
async function getOpFee(client, config, opType, opts) {
|
|
32605
|
+
const registrationKind = REGISTRATION_KIND_FOR_OP[opType];
|
|
32606
|
+
if (!registrationKind) {
|
|
32607
|
+
throw new Error(
|
|
32608
|
+
`getOpFee: unknown opType "${opType}" \u2014 supported types are ${Object.keys(REGISTRATION_KIND_FOR_OP).join(", ")}`
|
|
32609
|
+
);
|
|
32610
|
+
}
|
|
32611
|
+
const includeDataAccess = opType === "grant";
|
|
32612
|
+
const [registration, dataAccess] = await Promise.all([
|
|
32613
|
+
getFee(client, config, registrationKind, opts),
|
|
32614
|
+
includeDataAccess ? getFee(client, config, "data_access", opts) : Promise.resolve({
|
|
32615
|
+
amount: 0n,
|
|
32616
|
+
asset: ZERO_ADDRESS,
|
|
32617
|
+
payee: ZERO_ADDRESS,
|
|
32618
|
+
enabled: false
|
|
32619
|
+
})
|
|
32620
|
+
]);
|
|
32621
|
+
if (registration.enabled && dataAccess.enabled && registration.asset.toLowerCase() !== dataAccess.asset.toLowerCase()) {
|
|
32622
|
+
throw new Error(
|
|
32623
|
+
`FeeRegistry asset mismatch for "${opType}": registration=${registration.asset} vs data_access=${dataAccess.asset}. The gateway requires both kinds to settle in the same asset when both are enabled.`
|
|
32624
|
+
);
|
|
32625
|
+
}
|
|
32626
|
+
const asset = registration.enabled ? registration.asset : dataAccess.enabled ? dataAccess.asset : ZERO_ADDRESS;
|
|
32627
|
+
return {
|
|
32628
|
+
asset,
|
|
32629
|
+
registrationFee: registration.enabled ? registration.amount : 0n,
|
|
32630
|
+
dataAccessFee: dataAccess.enabled ? dataAccess.amount : 0n,
|
|
32631
|
+
registrationEnabled: registration.enabled,
|
|
32632
|
+
dataAccessEnabled: dataAccess.enabled,
|
|
32633
|
+
registrationPayee: registration.enabled ? registration.payee : ZERO_ADDRESS,
|
|
32634
|
+
dataAccessPayee: dataAccess.enabled ? dataAccess.payee : ZERO_ADDRESS
|
|
32635
|
+
};
|
|
32636
|
+
}
|
|
32637
|
+
|
|
32638
|
+
// src/protocol/escrow-deposit.ts
|
|
32639
|
+
import { encodeFunctionData } from "viem";
|
|
32640
|
+
var ESCROW_DEPOSIT_ABI = [
|
|
32641
|
+
{
|
|
32642
|
+
type: "function",
|
|
32643
|
+
name: "depositNative",
|
|
32644
|
+
stateMutability: "payable",
|
|
32645
|
+
inputs: [{ name: "account", type: "address" }],
|
|
32646
|
+
outputs: []
|
|
32647
|
+
},
|
|
32648
|
+
{
|
|
32649
|
+
type: "function",
|
|
32650
|
+
name: "depositToken",
|
|
32651
|
+
stateMutability: "nonpayable",
|
|
32652
|
+
inputs: [
|
|
32653
|
+
{ name: "account", type: "address" },
|
|
32654
|
+
{ name: "token", type: "address" },
|
|
32655
|
+
{ name: "amount", type: "uint256" }
|
|
32656
|
+
],
|
|
32657
|
+
outputs: []
|
|
32658
|
+
}
|
|
32659
|
+
];
|
|
32660
|
+
function escrowContractAddress(config) {
|
|
32661
|
+
return config.contracts.dataPortabilityEscrow;
|
|
32662
|
+
}
|
|
32663
|
+
function encodeDepositNativeData(input) {
|
|
32664
|
+
return encodeFunctionData({
|
|
32665
|
+
abi: ESCROW_DEPOSIT_ABI,
|
|
32666
|
+
functionName: "depositNative",
|
|
32667
|
+
args: [input.account]
|
|
32668
|
+
});
|
|
32669
|
+
}
|
|
32670
|
+
function encodeDepositTokenData(input) {
|
|
32671
|
+
return encodeFunctionData({
|
|
32672
|
+
abi: ESCROW_DEPOSIT_ABI,
|
|
32673
|
+
functionName: "depositToken",
|
|
32674
|
+
args: [input.account, input.token, input.amount]
|
|
32675
|
+
});
|
|
32676
|
+
}
|
|
32677
|
+
function buildDepositNativeRequest(config, input) {
|
|
32678
|
+
return {
|
|
32679
|
+
to: escrowContractAddress(config),
|
|
32680
|
+
data: encodeDepositNativeData({ account: input.account }),
|
|
32681
|
+
value: input.amount
|
|
32682
|
+
};
|
|
32683
|
+
}
|
|
32684
|
+
function buildDepositTokenRequest(config, input) {
|
|
32685
|
+
return {
|
|
32686
|
+
to: escrowContractAddress(config),
|
|
32687
|
+
data: encodeDepositTokenData(input)
|
|
32688
|
+
};
|
|
32689
|
+
}
|
|
32690
|
+
|
|
32691
|
+
// src/protocol/data-point-status.ts
|
|
32692
|
+
import { encodeFunctionData as encodeFunctionData2 } from "viem";
|
|
32693
|
+
var DataPointStatus = /* @__PURE__ */ ((DataPointStatus2) => {
|
|
32694
|
+
DataPointStatus2[DataPointStatus2["None"] = 0] = "None";
|
|
32695
|
+
DataPointStatus2[DataPointStatus2["Active"] = 1] = "Active";
|
|
32696
|
+
DataPointStatus2[DataPointStatus2["Inactive"] = 2] = "Inactive";
|
|
32697
|
+
DataPointStatus2[DataPointStatus2["Unavailable"] = 3] = "Unavailable";
|
|
32698
|
+
return DataPointStatus2;
|
|
32699
|
+
})(DataPointStatus || {});
|
|
32700
|
+
var DATA_REGISTRY_STATUS_ABI = [
|
|
32701
|
+
{
|
|
32702
|
+
type: "function",
|
|
32703
|
+
name: "setStatus",
|
|
32704
|
+
stateMutability: "nonpayable",
|
|
32705
|
+
inputs: [
|
|
32706
|
+
{ name: "scope", type: "string" },
|
|
32707
|
+
{ name: "newStatus", type: "uint8" }
|
|
32708
|
+
],
|
|
32709
|
+
outputs: []
|
|
32710
|
+
}
|
|
32711
|
+
];
|
|
32712
|
+
function dataRegistryContractAddress(config) {
|
|
32713
|
+
return config.contracts.dataRegistry;
|
|
32714
|
+
}
|
|
32715
|
+
function encodeSetDataPointStatusData(input) {
|
|
32716
|
+
return encodeFunctionData2({
|
|
32717
|
+
abi: DATA_REGISTRY_STATUS_ABI,
|
|
32718
|
+
functionName: "setStatus",
|
|
32719
|
+
args: [input.scope, input.status]
|
|
32720
|
+
});
|
|
32721
|
+
}
|
|
32722
|
+
function buildSetDataPointStatusRequest(config, input) {
|
|
32723
|
+
return {
|
|
32724
|
+
to: dataRegistryContractAddress(config),
|
|
32725
|
+
data: encodeSetDataPointStatusData(input)
|
|
32726
|
+
};
|
|
32727
|
+
}
|
|
32728
|
+
function buildMarkDataPointUnavailableRequest(config, input) {
|
|
32729
|
+
return buildSetDataPointStatusRequest(config, {
|
|
32730
|
+
scope: input.scope,
|
|
32731
|
+
status: 3 /* Unavailable */
|
|
32732
|
+
});
|
|
32733
|
+
}
|
|
32734
|
+
|
|
32735
|
+
// src/protocol/data-file.ts
|
|
32514
32736
|
import { z } from "zod";
|
|
32737
|
+
var DataFileEnvelopeSchema = z.object({
|
|
32738
|
+
$schema: z.string().url().optional(),
|
|
32739
|
+
version: z.literal("1.0"),
|
|
32740
|
+
scope: z.string(),
|
|
32741
|
+
schemaId: z.string().optional(),
|
|
32742
|
+
collectedAt: z.string().datetime(),
|
|
32743
|
+
data: z.record(z.string(), z.unknown())
|
|
32744
|
+
});
|
|
32745
|
+
function createDataFileEnvelope(scope, collectedAt, data, schemaUrl, schemaId) {
|
|
32746
|
+
return {
|
|
32747
|
+
...schemaUrl !== void 0 && { $schema: schemaUrl },
|
|
32748
|
+
...schemaId !== void 0 && { schemaId },
|
|
32749
|
+
version: "1.0",
|
|
32750
|
+
scope,
|
|
32751
|
+
collectedAt,
|
|
32752
|
+
data
|
|
32753
|
+
};
|
|
32754
|
+
}
|
|
32755
|
+
var IngestResponseSchema = z.object({
|
|
32756
|
+
scope: z.string(),
|
|
32757
|
+
collectedAt: z.string().datetime(),
|
|
32758
|
+
status: z.enum(["stored", "syncing"])
|
|
32759
|
+
});
|
|
32760
|
+
|
|
32761
|
+
// src/protocol/personal-server-data.ts
|
|
32762
|
+
function personalServerDataReadPath(scope) {
|
|
32763
|
+
return `/v1/data/${encodeURIComponent(scope)}`;
|
|
32764
|
+
}
|
|
32765
|
+
async function buildPersonalServerDataReadRequest(params) {
|
|
32766
|
+
const path = personalServerDataReadPath(params.scope);
|
|
32767
|
+
const baseUrl = params.personalServerUrl.replace(/\/+$/, "");
|
|
32768
|
+
const audience = params.audience ?? baseUrl;
|
|
32769
|
+
const headers = new Headers(params.headers);
|
|
32770
|
+
headers.set(
|
|
32771
|
+
"Authorization",
|
|
32772
|
+
await buildWeb3SignedHeader({
|
|
32773
|
+
aud: audience,
|
|
32774
|
+
grantId: params.grantId,
|
|
32775
|
+
method: "GET",
|
|
32776
|
+
signMessage: params.signMessage,
|
|
32777
|
+
uri: path
|
|
32778
|
+
})
|
|
32779
|
+
);
|
|
32780
|
+
return new Request(`${baseUrl}${path}`, {
|
|
32781
|
+
headers,
|
|
32782
|
+
method: "GET"
|
|
32783
|
+
});
|
|
32784
|
+
}
|
|
32785
|
+
async function readPersonalServerData(params) {
|
|
32786
|
+
const fetchFn = params.fetch ?? globalThis.fetch;
|
|
32787
|
+
if (fetchFn === void 0) {
|
|
32788
|
+
throw new Error("No fetch implementation available");
|
|
32789
|
+
}
|
|
32790
|
+
const request = await buildPersonalServerDataReadRequest(params);
|
|
32791
|
+
const response = await fetchFn(request);
|
|
32792
|
+
if (!response.ok) {
|
|
32793
|
+
throw new Error(
|
|
32794
|
+
`Personal Server data read failed: ${response.status} ${response.statusText}`
|
|
32795
|
+
);
|
|
32796
|
+
}
|
|
32797
|
+
return DataFileEnvelopeSchema.parse(await response.json());
|
|
32798
|
+
}
|
|
32799
|
+
|
|
32800
|
+
// src/protocol/scopes.ts
|
|
32801
|
+
import { z as z2 } from "zod";
|
|
32515
32802
|
var SEGMENT_RE = /^[a-z0-9][a-z0-9_]*$/;
|
|
32516
|
-
var ScopeSchema =
|
|
32803
|
+
var ScopeSchema = z2.string().refine(
|
|
32517
32804
|
(scope) => {
|
|
32518
32805
|
const parts = scope.split(".");
|
|
32519
32806
|
return parts.length >= 2 && parts.length <= 3 && parts.every((part) => SEGMENT_RE.test(part));
|
|
@@ -32554,32 +32841,6 @@ function scopeCoveredByGrant(requestedScope, grantedScopes) {
|
|
|
32554
32841
|
);
|
|
32555
32842
|
}
|
|
32556
32843
|
|
|
32557
|
-
// src/protocol/data-file.ts
|
|
32558
|
-
import { z as z2 } from "zod";
|
|
32559
|
-
var DataFileEnvelopeSchema = z2.object({
|
|
32560
|
-
$schema: z2.string().url().optional(),
|
|
32561
|
-
version: z2.literal("1.0"),
|
|
32562
|
-
scope: z2.string(),
|
|
32563
|
-
schemaId: z2.string().optional(),
|
|
32564
|
-
collectedAt: z2.string().datetime(),
|
|
32565
|
-
data: z2.record(z2.string(), z2.unknown())
|
|
32566
|
-
});
|
|
32567
|
-
function createDataFileEnvelope(scope, collectedAt, data, schemaUrl, schemaId) {
|
|
32568
|
-
return {
|
|
32569
|
-
...schemaUrl !== void 0 && { $schema: schemaUrl },
|
|
32570
|
-
...schemaId !== void 0 && { schemaId },
|
|
32571
|
-
version: "1.0",
|
|
32572
|
-
scope,
|
|
32573
|
-
collectedAt,
|
|
32574
|
-
data
|
|
32575
|
-
};
|
|
32576
|
-
}
|
|
32577
|
-
var IngestResponseSchema = z2.object({
|
|
32578
|
-
scope: z2.string(),
|
|
32579
|
-
collectedAt: z2.string().datetime(),
|
|
32580
|
-
status: z2.enum(["stored", "syncing"])
|
|
32581
|
-
});
|
|
32582
|
-
|
|
32583
32844
|
// src/protocol/gateway.ts
|
|
32584
32845
|
function createGatewayClient(baseUrl) {
|
|
32585
32846
|
const base = baseUrl.replace(/\/+$/, "");
|
|
@@ -32587,16 +32848,6 @@ function createGatewayClient(baseUrl) {
|
|
|
32587
32848
|
const envelope = await res.json();
|
|
32588
32849
|
return envelope.data;
|
|
32589
32850
|
}
|
|
32590
|
-
function normalizeFileRecord(record) {
|
|
32591
|
-
return {
|
|
32592
|
-
fileId: record.fileId ?? record.id ?? "",
|
|
32593
|
-
owner: record.owner ?? record.ownerAddress ?? "",
|
|
32594
|
-
url: record.url,
|
|
32595
|
-
schemaId: record.schemaId,
|
|
32596
|
-
createdAt: record.createdAt ?? record.addedAt ?? "",
|
|
32597
|
-
deletedAt: record.deletedAt ?? null
|
|
32598
|
-
};
|
|
32599
|
-
}
|
|
32600
32851
|
function getMutationId(body, key) {
|
|
32601
32852
|
const value = body[key] ?? body["id"];
|
|
32602
32853
|
return typeof value === "string" ? value : void 0;
|
|
@@ -32646,31 +32897,33 @@ function createGatewayClient(baseUrl) {
|
|
|
32646
32897
|
}
|
|
32647
32898
|
return unwrapEnvelope(res);
|
|
32648
32899
|
},
|
|
32649
|
-
async
|
|
32650
|
-
const res = await fetch(`${base}/v1/
|
|
32900
|
+
async getDataPoint(dataPointId) {
|
|
32901
|
+
const res = await fetch(`${base}/v1/data/${dataPointId}`);
|
|
32651
32902
|
if (res.status === 404) return null;
|
|
32652
32903
|
if (!res.ok) {
|
|
32653
32904
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
32654
32905
|
}
|
|
32655
|
-
return
|
|
32906
|
+
return unwrapEnvelope(res);
|
|
32656
32907
|
},
|
|
32657
|
-
async
|
|
32908
|
+
async listDataPointsByOwner(owner, cursor, options) {
|
|
32658
32909
|
const params = new URLSearchParams({ user: owner });
|
|
32659
32910
|
if (cursor !== null) {
|
|
32660
32911
|
params.set("cursor", cursor);
|
|
32661
32912
|
}
|
|
32662
|
-
if (options?.
|
|
32663
|
-
params.set("
|
|
32913
|
+
if (options?.since) {
|
|
32914
|
+
params.set("since", options.since);
|
|
32664
32915
|
}
|
|
32665
|
-
|
|
32916
|
+
if (options?.limit !== void 0) {
|
|
32917
|
+
params.set("limit", String(options.limit));
|
|
32918
|
+
}
|
|
32919
|
+
const res = await fetch(`${base}/v1/data?${params.toString()}`);
|
|
32666
32920
|
if (!res.ok) {
|
|
32667
32921
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
32668
32922
|
}
|
|
32669
32923
|
const envelope = await res.json();
|
|
32670
|
-
const
|
|
32671
|
-
const nextCursor = pagination?.hasMore === false ? null : pagination?.nextCursor ?? envelope.data.cursor ?? null;
|
|
32924
|
+
const nextCursor = envelope.pagination?.hasMore === false ? null : envelope.pagination?.nextCursor ?? null;
|
|
32672
32925
|
return {
|
|
32673
|
-
|
|
32926
|
+
dataPoints: envelope.data.dataPoints,
|
|
32674
32927
|
cursor: nextCursor
|
|
32675
32928
|
};
|
|
32676
32929
|
},
|
|
@@ -32712,8 +32965,8 @@ function createGatewayClient(baseUrl) {
|
|
|
32712
32965
|
alreadyRegistered: false
|
|
32713
32966
|
};
|
|
32714
32967
|
},
|
|
32715
|
-
async
|
|
32716
|
-
const res = await fetch(`${base}/v1/
|
|
32968
|
+
async registerBuilder(params) {
|
|
32969
|
+
const res = await fetch(`${base}/v1/builders`, {
|
|
32717
32970
|
method: "POST",
|
|
32718
32971
|
headers: {
|
|
32719
32972
|
"Content-Type": "application/json",
|
|
@@ -32721,22 +32974,57 @@ function createGatewayClient(baseUrl) {
|
|
|
32721
32974
|
},
|
|
32722
32975
|
body: JSON.stringify({
|
|
32723
32976
|
ownerAddress: params.ownerAddress,
|
|
32724
|
-
|
|
32725
|
-
|
|
32977
|
+
granteeAddress: params.granteeAddress,
|
|
32978
|
+
publicKey: params.publicKey,
|
|
32979
|
+
appUrl: params.appUrl
|
|
32726
32980
|
})
|
|
32727
32981
|
});
|
|
32728
32982
|
if (res.status === 409) {
|
|
32729
32983
|
const body2 = await res.json().catch(() => ({}));
|
|
32730
32984
|
return {
|
|
32731
|
-
|
|
32985
|
+
builderId: getMutationId(
|
|
32986
|
+
body2,
|
|
32987
|
+
"builderId"
|
|
32988
|
+
),
|
|
32989
|
+
alreadyRegistered: true
|
|
32732
32990
|
};
|
|
32733
32991
|
}
|
|
32734
32992
|
if (!res.ok) {
|
|
32735
32993
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
32736
32994
|
}
|
|
32737
|
-
const body = await res.json();
|
|
32995
|
+
const body = await res.json().catch(() => ({}));
|
|
32996
|
+
return {
|
|
32997
|
+
builderId: getMutationId(body, "builderId"),
|
|
32998
|
+
alreadyRegistered: false
|
|
32999
|
+
};
|
|
33000
|
+
},
|
|
33001
|
+
async registerDataPoint(params) {
|
|
33002
|
+
const res = await fetch(`${base}/v1/data`, {
|
|
33003
|
+
method: "POST",
|
|
33004
|
+
headers: {
|
|
33005
|
+
"Content-Type": "application/json",
|
|
33006
|
+
Authorization: `Web3Signed ${params.signature}`
|
|
33007
|
+
},
|
|
33008
|
+
body: JSON.stringify({
|
|
33009
|
+
ownerAddress: params.ownerAddress,
|
|
33010
|
+
scope: params.scope,
|
|
33011
|
+
dataHash: params.dataHash,
|
|
33012
|
+
metadataHash: params.metadataHash,
|
|
33013
|
+
expectedVersion: params.expectedVersion
|
|
33014
|
+
})
|
|
33015
|
+
});
|
|
33016
|
+
if (!res.ok) {
|
|
33017
|
+
const body2 = await res.json().catch(() => ({}));
|
|
33018
|
+
const detail = body2.error ?? res.statusText;
|
|
33019
|
+
throw new Error(`Gateway error: ${res.status} ${detail}`);
|
|
33020
|
+
}
|
|
33021
|
+
const body = await res.json().catch(() => ({}));
|
|
32738
33022
|
return {
|
|
32739
|
-
|
|
33023
|
+
dataPointId: getMutationId(
|
|
33024
|
+
body,
|
|
33025
|
+
"dataPointId"
|
|
33026
|
+
),
|
|
33027
|
+
expectedVersion: body.expectedVersion
|
|
32740
33028
|
};
|
|
32741
33029
|
},
|
|
32742
33030
|
async createGrant(params) {
|
|
@@ -32749,8 +33037,9 @@ function createGatewayClient(baseUrl) {
|
|
|
32749
33037
|
body: JSON.stringify({
|
|
32750
33038
|
grantorAddress: params.grantorAddress,
|
|
32751
33039
|
granteeId: params.granteeId,
|
|
32752
|
-
|
|
32753
|
-
|
|
33040
|
+
scopes: params.scopes,
|
|
33041
|
+
grantVersion: params.grantVersion,
|
|
33042
|
+
expiresAt: params.expiresAt
|
|
32754
33043
|
})
|
|
32755
33044
|
});
|
|
32756
33045
|
if (res.status === 409) {
|
|
@@ -32775,7 +33064,8 @@ function createGatewayClient(baseUrl) {
|
|
|
32775
33064
|
Authorization: `Web3Signed ${params.signature}`
|
|
32776
33065
|
},
|
|
32777
33066
|
body: JSON.stringify({
|
|
32778
|
-
grantorAddress: params.grantorAddress
|
|
33067
|
+
grantorAddress: params.grantorAddress,
|
|
33068
|
+
grantVersion: params.grantVersion
|
|
32779
33069
|
})
|
|
32780
33070
|
});
|
|
32781
33071
|
if (res.status === 409) return;
|
|
@@ -32783,21 +33073,174 @@ function createGatewayClient(baseUrl) {
|
|
|
32783
33073
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
32784
33074
|
}
|
|
32785
33075
|
},
|
|
32786
|
-
async
|
|
32787
|
-
const res = await fetch(`${base}/v1/
|
|
32788
|
-
|
|
33076
|
+
async getEscrowBalance(account) {
|
|
33077
|
+
const res = await fetch(`${base}/v1/escrow/balance?account=${account}`);
|
|
33078
|
+
if (!res.ok) {
|
|
33079
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33080
|
+
}
|
|
33081
|
+
return await res.json();
|
|
33082
|
+
},
|
|
33083
|
+
async submitEscrowDeposit(params) {
|
|
33084
|
+
const res = await fetch(`${base}/v1/escrow/deposit`, {
|
|
33085
|
+
method: "POST",
|
|
33086
|
+
headers: { "Content-Type": "application/json" },
|
|
33087
|
+
body: JSON.stringify({ txHash: params.txHash })
|
|
33088
|
+
});
|
|
33089
|
+
if (res.status !== 200 && res.status !== 202) {
|
|
33090
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33091
|
+
}
|
|
33092
|
+
return await res.json();
|
|
33093
|
+
},
|
|
33094
|
+
async payForOperation(params) {
|
|
33095
|
+
const body = {
|
|
33096
|
+
payerAddress: params.payerAddress,
|
|
33097
|
+
opType: params.opType,
|
|
33098
|
+
opId: params.opId,
|
|
33099
|
+
asset: params.asset,
|
|
33100
|
+
amount: params.amount,
|
|
33101
|
+
paymentNonce: params.paymentNonce
|
|
33102
|
+
};
|
|
33103
|
+
if (params.accessRecord) {
|
|
33104
|
+
body["accessRecord"] = params.accessRecord;
|
|
33105
|
+
}
|
|
33106
|
+
const res = await fetch(`${base}/v1/escrow/pay`, {
|
|
33107
|
+
method: "POST",
|
|
32789
33108
|
headers: {
|
|
32790
33109
|
"Content-Type": "application/json",
|
|
32791
33110
|
Authorization: `Web3Signed ${params.signature}`
|
|
32792
33111
|
},
|
|
32793
|
-
body: JSON.stringify(
|
|
32794
|
-
|
|
32795
|
-
|
|
33112
|
+
body: JSON.stringify(body)
|
|
33113
|
+
});
|
|
33114
|
+
if (!res.ok) {
|
|
33115
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33116
|
+
}
|
|
33117
|
+
return await res.json();
|
|
33118
|
+
},
|
|
33119
|
+
async settle(params) {
|
|
33120
|
+
const res = await fetch(`${base}/v1/settle`, {
|
|
33121
|
+
method: "POST",
|
|
33122
|
+
headers: { "Content-Type": "application/json" },
|
|
33123
|
+
// The gateway accepts an empty body; only `limit` is recognised.
|
|
33124
|
+
// Always send a JSON body so the gateway's req.body shape parse
|
|
33125
|
+
// doesn't have to deal with an undefined.
|
|
33126
|
+
body: JSON.stringify(params ?? {})
|
|
32796
33127
|
});
|
|
32797
|
-
if (res.status === 409) return;
|
|
32798
33128
|
if (!res.ok) {
|
|
32799
33129
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
32800
33130
|
}
|
|
33131
|
+
return await res.json();
|
|
33132
|
+
}
|
|
33133
|
+
};
|
|
33134
|
+
}
|
|
33135
|
+
|
|
33136
|
+
// src/protocol/escrow.ts
|
|
33137
|
+
var GENERIC_PAYMENT_TYPES = {
|
|
33138
|
+
GenericPayment: [
|
|
33139
|
+
{ name: "payerAddress", type: "address" },
|
|
33140
|
+
{ name: "opType", type: "string" },
|
|
33141
|
+
{ name: "opId", type: "bytes32" },
|
|
33142
|
+
{ name: "asset", type: "address" },
|
|
33143
|
+
{ name: "amount", type: "uint256" },
|
|
33144
|
+
{ name: "paymentNonce", type: "uint256" }
|
|
33145
|
+
]
|
|
33146
|
+
};
|
|
33147
|
+
function genericPaymentDomain(chainId, escrowContract) {
|
|
33148
|
+
return {
|
|
33149
|
+
name: "Vana Data Portability",
|
|
33150
|
+
version: "1",
|
|
33151
|
+
chainId,
|
|
33152
|
+
verifyingContract: escrowContract
|
|
33153
|
+
};
|
|
33154
|
+
}
|
|
33155
|
+
var ESCROW_DEPOSIT_ABI2 = [
|
|
33156
|
+
{
|
|
33157
|
+
type: "function",
|
|
33158
|
+
name: "depositNative",
|
|
33159
|
+
stateMutability: "payable",
|
|
33160
|
+
inputs: [{ name: "account", type: "address" }],
|
|
33161
|
+
outputs: []
|
|
33162
|
+
},
|
|
33163
|
+
{
|
|
33164
|
+
type: "function",
|
|
33165
|
+
name: "depositToken",
|
|
33166
|
+
stateMutability: "nonpayable",
|
|
33167
|
+
inputs: [
|
|
33168
|
+
{ name: "account", type: "address" },
|
|
33169
|
+
{ name: "token", type: "address" },
|
|
33170
|
+
{ name: "amount", type: "uint256" }
|
|
33171
|
+
],
|
|
33172
|
+
outputs: []
|
|
33173
|
+
}
|
|
33174
|
+
];
|
|
33175
|
+
var NATIVE_ASSET_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
33176
|
+
function createEscrowGatewayClient(baseUrl) {
|
|
33177
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
33178
|
+
async function throwOnError(res, context) {
|
|
33179
|
+
if (!res.ok) {
|
|
33180
|
+
let detail = "";
|
|
33181
|
+
try {
|
|
33182
|
+
const body = await res.json();
|
|
33183
|
+
if (body.error) detail = `: ${body.error}`;
|
|
33184
|
+
} catch {
|
|
33185
|
+
}
|
|
33186
|
+
throw new Error(
|
|
33187
|
+
`Escrow gateway error (${context}): ${res.status} ${res.statusText}${detail}`
|
|
33188
|
+
);
|
|
33189
|
+
}
|
|
33190
|
+
}
|
|
33191
|
+
return {
|
|
33192
|
+
async submitDeposit({ txHash }) {
|
|
33193
|
+
const res = await fetch(`${base}/v1/escrow/deposit`, {
|
|
33194
|
+
method: "POST",
|
|
33195
|
+
headers: { "Content-Type": "application/json" },
|
|
33196
|
+
body: JSON.stringify({ txHash })
|
|
33197
|
+
});
|
|
33198
|
+
if (res.status !== 200 && res.status !== 202) {
|
|
33199
|
+
await throwOnError(res, "POST /v1/escrow/deposit");
|
|
33200
|
+
}
|
|
33201
|
+
return res.json();
|
|
33202
|
+
},
|
|
33203
|
+
async getEscrowBalance(account) {
|
|
33204
|
+
const res = await fetch(
|
|
33205
|
+
`${base}/v1/escrow/balance?account=${encodeURIComponent(account)}`
|
|
33206
|
+
);
|
|
33207
|
+
await throwOnError(res, "GET /v1/escrow/balance");
|
|
33208
|
+
return res.json();
|
|
33209
|
+
},
|
|
33210
|
+
async syncEscrowBalance(account) {
|
|
33211
|
+
const res = await fetch(
|
|
33212
|
+
`${base}/v1/escrow/balance/sync?account=${encodeURIComponent(account)}`,
|
|
33213
|
+
{ method: "POST" }
|
|
33214
|
+
);
|
|
33215
|
+
await throwOnError(res, "POST /v1/escrow/balance/sync");
|
|
33216
|
+
return res.json();
|
|
33217
|
+
},
|
|
33218
|
+
async payForOp({
|
|
33219
|
+
payerAddress,
|
|
33220
|
+
opType,
|
|
33221
|
+
opId,
|
|
33222
|
+
asset,
|
|
33223
|
+
amount,
|
|
33224
|
+
paymentNonce,
|
|
33225
|
+
signature
|
|
33226
|
+
}) {
|
|
33227
|
+
const res = await fetch(`${base}/v1/escrow/pay`, {
|
|
33228
|
+
method: "POST",
|
|
33229
|
+
headers: {
|
|
33230
|
+
"Content-Type": "application/json",
|
|
33231
|
+
Authorization: `Web3Signed ${signature}`
|
|
33232
|
+
},
|
|
33233
|
+
body: JSON.stringify({
|
|
33234
|
+
payerAddress,
|
|
33235
|
+
opType,
|
|
33236
|
+
opId,
|
|
33237
|
+
asset,
|
|
33238
|
+
amount,
|
|
33239
|
+
paymentNonce
|
|
33240
|
+
})
|
|
33241
|
+
});
|
|
33242
|
+
await throwOnError(res, "POST /v1/escrow/pay");
|
|
33243
|
+
return res.json();
|
|
32801
33244
|
}
|
|
32802
33245
|
};
|
|
32803
33246
|
}
|
|
@@ -32866,6 +33309,7 @@ async function parsePSError(response) {
|
|
|
32866
33309
|
}
|
|
32867
33310
|
export {
|
|
32868
33311
|
ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
|
|
33312
|
+
ADD_DATA_TYPES,
|
|
32869
33313
|
AccountPersonalServerLiteOwnerBindingError,
|
|
32870
33314
|
AccountPersonalServerRegistrationError,
|
|
32871
33315
|
BUILDER_REGISTRATION_TYPES,
|
|
@@ -32876,12 +33320,15 @@ export {
|
|
|
32876
33320
|
CallbackStorage,
|
|
32877
33321
|
ContractFactory,
|
|
32878
33322
|
ContractNotFoundError,
|
|
33323
|
+
DATA_REGISTRY_STATUS_ABI,
|
|
32879
33324
|
DataFileEnvelopeSchema,
|
|
33325
|
+
DataPointStatus,
|
|
32880
33326
|
DropboxStorage,
|
|
32881
33327
|
ECIESError,
|
|
33328
|
+
ESCROW_DEPOSIT_ABI2 as ESCROW_DEPOSIT_ABI,
|
|
32882
33329
|
ExpiredTokenError,
|
|
32883
|
-
|
|
32884
|
-
|
|
33330
|
+
FEE_REGISTRY_ABI,
|
|
33331
|
+
GENERIC_PAYMENT_TYPES,
|
|
32885
33332
|
GRANT_REGISTRATION_TYPES,
|
|
32886
33333
|
GRANT_REVOCATION_TYPES,
|
|
32887
33334
|
GoogleDriveStorage,
|
|
@@ -32892,6 +33339,8 @@ export {
|
|
|
32892
33339
|
IpfsStorage,
|
|
32893
33340
|
MASTER_KEY_MESSAGE,
|
|
32894
33341
|
MissingAuthError,
|
|
33342
|
+
NATIVE_ASSET_ADDRESS,
|
|
33343
|
+
NATIVE_VANA_ASSET,
|
|
32895
33344
|
NetworkError,
|
|
32896
33345
|
NonceError,
|
|
32897
33346
|
OAuthClient,
|
|
@@ -32907,6 +33356,8 @@ export {
|
|
|
32907
33356
|
PersonalServerError,
|
|
32908
33357
|
PinataStorage,
|
|
32909
33358
|
R2Storage,
|
|
33359
|
+
RECORD_DATA_ACCESS_TYPES,
|
|
33360
|
+
REGISTRATION_KIND_FOR_OP,
|
|
32910
33361
|
ReadOnlyError,
|
|
32911
33362
|
RelayerError,
|
|
32912
33363
|
SERVER_REGISTRATION_TYPES,
|
|
@@ -32921,10 +33372,15 @@ export {
|
|
|
32921
33372
|
VanaError,
|
|
32922
33373
|
VanaStorage,
|
|
32923
33374
|
assertValidPkceVerifier,
|
|
33375
|
+
buildDepositNativeRequest,
|
|
33376
|
+
buildDepositTokenRequest,
|
|
33377
|
+
buildMarkDataPointUnavailableRequest,
|
|
33378
|
+
buildPersonalServerDataReadRequest,
|
|
32924
33379
|
buildPersonalServerLiteOwnerBindingMessage,
|
|
32925
33380
|
buildPersonalServerLiteOwnerBindingSignature,
|
|
32926
33381
|
buildPersonalServerRegistrationSignature,
|
|
32927
33382
|
buildPersonalServerRegistrationTypedData,
|
|
33383
|
+
buildSetDataPointStatusRequest,
|
|
32928
33384
|
buildWeb3SignedHeader,
|
|
32929
33385
|
builderRegistrationDomain,
|
|
32930
33386
|
chains,
|
|
@@ -32934,26 +33390,35 @@ export {
|
|
|
32934
33390
|
contractCacheForTesting,
|
|
32935
33391
|
createBrowserPlatformAdapter,
|
|
32936
33392
|
createDataFileEnvelope,
|
|
33393
|
+
createEscrowGatewayClient,
|
|
32937
33394
|
createGatewayClient,
|
|
32938
33395
|
createPlatformAdapterSafe,
|
|
32939
33396
|
createVanaStorageProvider,
|
|
32940
33397
|
createViemPersonalServerLiteOwnerBindingSigner,
|
|
32941
33398
|
createViemPersonalServerRegistrationSigner,
|
|
33399
|
+
dataRegistryContractAddress,
|
|
33400
|
+
dataRegistryDomain,
|
|
32942
33401
|
decryptWithPassword,
|
|
32943
33402
|
deriveMasterKey,
|
|
32944
33403
|
deriveScopeKey,
|
|
32945
33404
|
deserializeECIES,
|
|
32946
33405
|
detectPlatform,
|
|
33406
|
+
encodeDepositNativeData,
|
|
33407
|
+
encodeDepositTokenData,
|
|
33408
|
+
encodeSetDataPointStatusData,
|
|
32947
33409
|
encryptWithPassword,
|
|
32948
|
-
|
|
32949
|
-
|
|
33410
|
+
escrowContractAddress,
|
|
33411
|
+
escrowPaymentDomain,
|
|
32950
33412
|
generatePkceVerifier,
|
|
33413
|
+
genericPaymentDomain,
|
|
32951
33414
|
getAbi,
|
|
32952
33415
|
getAllChains,
|
|
32953
33416
|
getChainConfig,
|
|
32954
33417
|
getContractAddress,
|
|
32955
33418
|
getContractController,
|
|
32956
33419
|
getContractInfo,
|
|
33420
|
+
getFee,
|
|
33421
|
+
getOpFee,
|
|
32957
33422
|
getPlatformCapabilities,
|
|
32958
33423
|
getServiceEndpoints,
|
|
32959
33424
|
grantRegistrationDomain,
|
|
@@ -32965,11 +33430,12 @@ export {
|
|
|
32965
33430
|
moksha,
|
|
32966
33431
|
mokshaServices,
|
|
32967
33432
|
mokshaTestnet2 as mokshaTestnet,
|
|
32968
|
-
parseGrantRegistrationPayload,
|
|
32969
33433
|
parsePSError,
|
|
32970
33434
|
parseScope,
|
|
32971
33435
|
parseWeb3SignedHeader,
|
|
33436
|
+
personalServerDataReadPath,
|
|
32972
33437
|
personalServerRegistrationDomain,
|
|
33438
|
+
readPersonalServerData,
|
|
32973
33439
|
recoverServerOwner,
|
|
32974
33440
|
registerPersonalServerSignature,
|
|
32975
33441
|
scopeCoveredByGrant,
|