@opendatalabs/vana-sdk 3.4.1 → 3.5.1-pr.159.2d90789
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.node.js
CHANGED
|
@@ -29018,6 +29018,8 @@ async function buildWeb3SignedHeader(params) {
|
|
|
29018
29018
|
var DEFAULT_ENDPOINT = "https://storage.vana.org";
|
|
29019
29019
|
var BLOB_PATH_PREFIX = "/v1/blobs";
|
|
29020
29020
|
var DEFAULT_TOKEN_TTL_SECONDS = 300;
|
|
29021
|
+
var MAX_UPLOAD_ATTEMPTS = 4;
|
|
29022
|
+
var MAX_RATE_LIMIT_DELAY_MS = 3e4;
|
|
29021
29023
|
var VanaStorage = class {
|
|
29022
29024
|
endpoint;
|
|
29023
29025
|
signer;
|
|
@@ -29056,27 +29058,46 @@ var VanaStorage = class {
|
|
|
29056
29058
|
const body = new Uint8Array(await file.arrayBuffer());
|
|
29057
29059
|
const contentType = file.type !== "" ? file.type : "application/octet-stream";
|
|
29058
29060
|
const header = await this.signRequest("PUT", path, body);
|
|
29059
|
-
let response;
|
|
29060
|
-
|
|
29061
|
-
|
|
29062
|
-
|
|
29063
|
-
|
|
29064
|
-
|
|
29065
|
-
|
|
29066
|
-
|
|
29067
|
-
|
|
29068
|
-
|
|
29069
|
-
|
|
29061
|
+
let response = null;
|
|
29062
|
+
let responseText = "";
|
|
29063
|
+
for (let attempt = 1; attempt <= MAX_UPLOAD_ATTEMPTS; attempt++) {
|
|
29064
|
+
try {
|
|
29065
|
+
response = await this.fetchImpl(`${this.endpoint}${path}`, {
|
|
29066
|
+
method: "PUT",
|
|
29067
|
+
headers: {
|
|
29068
|
+
authorization: header,
|
|
29069
|
+
"content-type": contentType
|
|
29070
|
+
},
|
|
29071
|
+
body
|
|
29072
|
+
});
|
|
29073
|
+
} catch (cause) {
|
|
29074
|
+
throw new StorageError(
|
|
29075
|
+
`vana-storage upload network error: ${describe(cause)}`,
|
|
29076
|
+
"UPLOAD_ERROR",
|
|
29077
|
+
"vana-storage",
|
|
29078
|
+
{ cause: cause instanceof Error ? cause : void 0 }
|
|
29079
|
+
);
|
|
29080
|
+
}
|
|
29081
|
+
if (response.ok) {
|
|
29082
|
+
break;
|
|
29083
|
+
}
|
|
29084
|
+
responseText = await safeText(response);
|
|
29085
|
+
if (response.status === 429 && attempt < MAX_UPLOAD_ATTEMPTS) {
|
|
29086
|
+
const delayMs = retryDelayMs(response, responseText);
|
|
29087
|
+
if (delayMs > 0) {
|
|
29088
|
+
await sleep(delayMs);
|
|
29089
|
+
}
|
|
29090
|
+
continue;
|
|
29091
|
+
}
|
|
29070
29092
|
throw new StorageError(
|
|
29071
|
-
`vana-storage upload
|
|
29072
|
-
"
|
|
29073
|
-
"vana-storage"
|
|
29074
|
-
{ cause: cause instanceof Error ? cause : void 0 }
|
|
29093
|
+
`vana-storage upload failed: ${response.status} ${response.statusText} - ${responseText}`,
|
|
29094
|
+
"UPLOAD_FAILED",
|
|
29095
|
+
"vana-storage"
|
|
29075
29096
|
);
|
|
29076
29097
|
}
|
|
29077
|
-
if (!response
|
|
29098
|
+
if (!response?.ok) {
|
|
29078
29099
|
throw new StorageError(
|
|
29079
|
-
`vana-storage upload failed
|
|
29100
|
+
`vana-storage upload failed after ${MAX_UPLOAD_ATTEMPTS} attempts - ${responseText}`,
|
|
29080
29101
|
"UPLOAD_FAILED",
|
|
29081
29102
|
"vana-storage"
|
|
29082
29103
|
);
|
|
@@ -29229,6 +29250,43 @@ function describe(value) {
|
|
|
29229
29250
|
if (value instanceof Error) return value.message;
|
|
29230
29251
|
return String(value);
|
|
29231
29252
|
}
|
|
29253
|
+
function retryDelayMs(response, responseText) {
|
|
29254
|
+
const headerDelayMs = parseRetryAfterHeaderMs(
|
|
29255
|
+
response.headers.get("retry-after")
|
|
29256
|
+
);
|
|
29257
|
+
if (headerDelayMs !== null) {
|
|
29258
|
+
return clampRateLimitDelay(headerDelayMs);
|
|
29259
|
+
}
|
|
29260
|
+
return clampRateLimitDelay(parseRetryAfterBodyMs(responseText) ?? 0);
|
|
29261
|
+
}
|
|
29262
|
+
function parseRetryAfterHeaderMs(value) {
|
|
29263
|
+
if (!value) return null;
|
|
29264
|
+
const seconds = Number(value);
|
|
29265
|
+
if (Number.isFinite(seconds)) {
|
|
29266
|
+
return seconds * 1e3;
|
|
29267
|
+
}
|
|
29268
|
+
const dateMs = Date.parse(value);
|
|
29269
|
+
if (Number.isFinite(dateMs)) {
|
|
29270
|
+
return Math.max(0, dateMs - Date.now());
|
|
29271
|
+
}
|
|
29272
|
+
return null;
|
|
29273
|
+
}
|
|
29274
|
+
function parseRetryAfterBodyMs(responseText) {
|
|
29275
|
+
if (!responseText) return null;
|
|
29276
|
+
try {
|
|
29277
|
+
const parsed = JSON.parse(responseText);
|
|
29278
|
+
const seconds = Number(parsed.retryAfter);
|
|
29279
|
+
return Number.isFinite(seconds) ? seconds * 1e3 : null;
|
|
29280
|
+
} catch {
|
|
29281
|
+
return null;
|
|
29282
|
+
}
|
|
29283
|
+
}
|
|
29284
|
+
function clampRateLimitDelay(delayMs) {
|
|
29285
|
+
return Math.min(Math.max(0, delayMs), MAX_RATE_LIMIT_DELAY_MS);
|
|
29286
|
+
}
|
|
29287
|
+
function sleep(ms) {
|
|
29288
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
29289
|
+
}
|
|
29232
29290
|
async function safeText(response) {
|
|
29233
29291
|
try {
|
|
29234
29292
|
return await response.text();
|
|
@@ -32509,6 +32567,7 @@ function formatOAuthError(body, status) {
|
|
|
32509
32567
|
// src/protocol/eip712.ts
|
|
32510
32568
|
var DOMAIN_NAME = "Vana Data Portability";
|
|
32511
32569
|
var DOMAIN_VERSION = "1";
|
|
32570
|
+
var NATIVE_VANA_ASSET = "0x0000000000000000000000000000000000000000";
|
|
32512
32571
|
function buildDomain(chainId, verifyingContract) {
|
|
32513
32572
|
return {
|
|
32514
32573
|
name: DOMAIN_NAME,
|
|
@@ -32517,13 +32576,7 @@ function buildDomain(chainId, verifyingContract) {
|
|
|
32517
32576
|
verifyingContract
|
|
32518
32577
|
};
|
|
32519
32578
|
}
|
|
32520
|
-
function
|
|
32521
|
-
return buildDomain(
|
|
32522
|
-
config.chainId,
|
|
32523
|
-
config.contracts.dataRegistry
|
|
32524
|
-
);
|
|
32525
|
-
}
|
|
32526
|
-
function fileDeletionDomain(config) {
|
|
32579
|
+
function dataRegistryDomain(config) {
|
|
32527
32580
|
return buildDomain(
|
|
32528
32581
|
config.chainId,
|
|
32529
32582
|
config.contracts.dataRegistry
|
|
@@ -32553,31 +32606,26 @@ function builderRegistrationDomain(config) {
|
|
|
32553
32606
|
config.contracts.dataPortabilityGrantees
|
|
32554
32607
|
);
|
|
32555
32608
|
}
|
|
32556
|
-
|
|
32557
|
-
|
|
32558
|
-
|
|
32559
|
-
|
|
32560
|
-
|
|
32561
|
-
|
|
32562
|
-
};
|
|
32563
|
-
var FILE_DELETION_TYPES = {
|
|
32564
|
-
FileDeletion: [
|
|
32565
|
-
{ name: "ownerAddress", type: "address" },
|
|
32566
|
-
{ name: "fileId", type: "bytes32" }
|
|
32567
|
-
]
|
|
32568
|
-
};
|
|
32609
|
+
function escrowPaymentDomain(config) {
|
|
32610
|
+
return buildDomain(
|
|
32611
|
+
config.chainId,
|
|
32612
|
+
config.contracts.dataPortabilityEscrow
|
|
32613
|
+
);
|
|
32614
|
+
}
|
|
32569
32615
|
var GRANT_REGISTRATION_TYPES = {
|
|
32570
32616
|
GrantRegistration: [
|
|
32571
32617
|
{ name: "grantorAddress", type: "address" },
|
|
32572
32618
|
{ name: "granteeId", type: "bytes32" },
|
|
32573
|
-
{ name: "
|
|
32574
|
-
{ name: "
|
|
32619
|
+
{ name: "scopes", type: "string[]" },
|
|
32620
|
+
{ name: "grantVersion", type: "uint256" },
|
|
32621
|
+
{ name: "expiresAt", type: "uint256" }
|
|
32575
32622
|
]
|
|
32576
32623
|
};
|
|
32577
32624
|
var GRANT_REVOCATION_TYPES = {
|
|
32578
32625
|
GrantRevocation: [
|
|
32579
32626
|
{ name: "grantorAddress", type: "address" },
|
|
32580
|
-
{ name: "grantId", type: "bytes32" }
|
|
32627
|
+
{ name: "grantId", type: "bytes32" },
|
|
32628
|
+
{ name: "grantVersion", type: "uint256" }
|
|
32581
32629
|
]
|
|
32582
32630
|
};
|
|
32583
32631
|
var SERVER_REGISTRATION_TYPES = {
|
|
@@ -32596,13 +32644,34 @@ var BUILDER_REGISTRATION_TYPES = {
|
|
|
32596
32644
|
{ name: "appUrl", type: "string" }
|
|
32597
32645
|
]
|
|
32598
32646
|
};
|
|
32647
|
+
var ADD_DATA_TYPES = {
|
|
32648
|
+
AddData: [
|
|
32649
|
+
{ name: "ownerAddress", type: "address" },
|
|
32650
|
+
{ name: "scope", type: "string" },
|
|
32651
|
+
{ name: "dataHash", type: "bytes32" },
|
|
32652
|
+
{ name: "metadataHash", type: "bytes32" },
|
|
32653
|
+
{ name: "expectedVersion", type: "uint256" }
|
|
32654
|
+
]
|
|
32655
|
+
};
|
|
32656
|
+
var RECORD_DATA_ACCESS_TYPES = {
|
|
32657
|
+
RecordDataAccess: [
|
|
32658
|
+
{ name: "ownerAddress", type: "address" },
|
|
32659
|
+
{ name: "scope", type: "string" },
|
|
32660
|
+
{ name: "version", type: "uint256" },
|
|
32661
|
+
{ name: "accessor", type: "address" },
|
|
32662
|
+
{ name: "recordId", type: "bytes32" }
|
|
32663
|
+
]
|
|
32664
|
+
};
|
|
32599
32665
|
|
|
32600
32666
|
// src/protocol/personal-server-registration.ts
|
|
32601
32667
|
import {
|
|
32602
32668
|
isAddress
|
|
32603
32669
|
} from "viem";
|
|
32604
|
-
var PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID =
|
|
32605
|
-
var PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT =
|
|
32670
|
+
var PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID = vanaMainnet2.id;
|
|
32671
|
+
var PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT = getContractAddress(
|
|
32672
|
+
PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
|
|
32673
|
+
"DataPortabilityServers"
|
|
32674
|
+
);
|
|
32606
32675
|
function assertAddress(value, name) {
|
|
32607
32676
|
if (!isAddress(value)) {
|
|
32608
32677
|
throw new Error(`${name} must be a valid EVM address`);
|
|
@@ -32617,6 +32686,12 @@ function getAccountAddress(account) {
|
|
|
32617
32686
|
function isPersonalServerRegistrationSigner(source) {
|
|
32618
32687
|
return "address" in source && typeof source.signTypedData === "function";
|
|
32619
32688
|
}
|
|
32689
|
+
function getDefaultServerRegistrationContract(chainId) {
|
|
32690
|
+
return getContractAddress(
|
|
32691
|
+
chainId,
|
|
32692
|
+
"DataPortabilityServers"
|
|
32693
|
+
);
|
|
32694
|
+
}
|
|
32620
32695
|
function createViemPersonalServerRegistrationSigner(source, options = {}) {
|
|
32621
32696
|
if (isPersonalServerRegistrationSigner(source)) {
|
|
32622
32697
|
return source;
|
|
@@ -32639,12 +32714,13 @@ function personalServerRegistrationDomain(input = {}) {
|
|
|
32639
32714
|
if (input.config) {
|
|
32640
32715
|
return serverRegistrationDomain(input.config);
|
|
32641
32716
|
}
|
|
32642
|
-
const
|
|
32717
|
+
const chainId = input.chainId ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID;
|
|
32718
|
+
const verifyingContract = input.verifyingContract ?? getDefaultServerRegistrationContract(chainId);
|
|
32643
32719
|
assertAddress(verifyingContract, "verifyingContract");
|
|
32644
32720
|
return {
|
|
32645
32721
|
name: "Vana Data Portability",
|
|
32646
32722
|
version: "1",
|
|
32647
|
-
chainId
|
|
32723
|
+
chainId,
|
|
32648
32724
|
verifyingContract
|
|
32649
32725
|
};
|
|
32650
32726
|
}
|
|
@@ -32682,11 +32758,11 @@ async function buildPersonalServerRegistrationSignature(input) {
|
|
|
32682
32758
|
}
|
|
32683
32759
|
var registerPersonalServerSignature = buildPersonalServerRegistrationSignature;
|
|
32684
32760
|
|
|
32685
|
-
// src/
|
|
32761
|
+
// src/personal-server-lite/owner-binding.ts
|
|
32686
32762
|
import {
|
|
32687
32763
|
isAddress as isAddress2
|
|
32688
32764
|
} from "viem";
|
|
32689
|
-
var PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION = "vana.
|
|
32765
|
+
var PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION = "vana.ps-lite.owner-binding.v1";
|
|
32690
32766
|
var PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE = "ps-lite-owner";
|
|
32691
32767
|
var PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX = `${PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION}:${PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE}:`;
|
|
32692
32768
|
function assertAddress2(value, name) {
|
|
@@ -33037,67 +33113,34 @@ function isDataPortabilityGatewayConfig(value) {
|
|
|
33037
33113
|
return false;
|
|
33038
33114
|
}
|
|
33039
33115
|
const c = contracts;
|
|
33040
|
-
return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]);
|
|
33116
|
+
return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]) && isHexString(c["dataPortabilityEscrow"]) && isHexString(c["feeRegistry"]);
|
|
33041
33117
|
}
|
|
33042
|
-
function
|
|
33043
|
-
let parsed;
|
|
33118
|
+
function toUint256(value) {
|
|
33044
33119
|
try {
|
|
33045
|
-
|
|
33046
|
-
|
|
33047
|
-
|
|
33048
|
-
|
|
33049
|
-
|
|
33050
|
-
return
|
|
33051
|
-
}
|
|
33052
|
-
const value = parsed;
|
|
33053
|
-
if (!Array.isArray(value["scopes"]) || value["scopes"].length === 0) {
|
|
33054
|
-
return null;
|
|
33055
|
-
}
|
|
33056
|
-
if (!value["scopes"].every((scope) => typeof scope === "string")) {
|
|
33057
|
-
return null;
|
|
33058
|
-
}
|
|
33059
|
-
if (typeof value["expiresAt"] !== "number" || !Number.isFinite(value["expiresAt"])) {
|
|
33060
|
-
return null;
|
|
33061
|
-
}
|
|
33062
|
-
if (value["user"] !== void 0 && !isHexString(value["user"])) {
|
|
33063
|
-
return null;
|
|
33064
|
-
}
|
|
33065
|
-
if (value["builder"] !== void 0 && !isHexString(value["builder"])) {
|
|
33066
|
-
return null;
|
|
33067
|
-
}
|
|
33068
|
-
if (value["nonce"] !== void 0 && (typeof value["nonce"] !== "number" || !Number.isFinite(value["nonce"]))) {
|
|
33069
|
-
return null;
|
|
33070
|
-
}
|
|
33071
|
-
return {
|
|
33072
|
-
user: value["user"],
|
|
33073
|
-
builder: value["builder"],
|
|
33074
|
-
scopes: value["scopes"],
|
|
33075
|
-
expiresAt: value["expiresAt"],
|
|
33076
|
-
nonce: value["nonce"]
|
|
33077
|
-
};
|
|
33078
|
-
}
|
|
33079
|
-
function parseFileIds(fileIds) {
|
|
33080
|
-
try {
|
|
33081
|
-
const values = (fileIds ?? []).map((fileId) => BigInt(fileId));
|
|
33082
|
-
return {
|
|
33083
|
-
values,
|
|
33084
|
-
display: values.map((fileId) => fileId.toString())
|
|
33085
|
-
};
|
|
33120
|
+
if (typeof value === "number" && !Number.isSafeInteger(value)) {
|
|
33121
|
+
return null;
|
|
33122
|
+
}
|
|
33123
|
+
const big = typeof value === "bigint" ? value : BigInt(value);
|
|
33124
|
+
if (big < 0n) return null;
|
|
33125
|
+
return big;
|
|
33086
33126
|
} catch {
|
|
33087
33127
|
return null;
|
|
33088
33128
|
}
|
|
33089
33129
|
}
|
|
33090
33130
|
async function verifyGrantRegistration(input) {
|
|
33091
|
-
|
|
33092
|
-
|
|
33093
|
-
|
|
33094
|
-
|
|
33095
|
-
|
|
33096
|
-
};
|
|
33131
|
+
if (!Array.isArray(input.scopes) || input.scopes.length === 0) {
|
|
33132
|
+
return { valid: false, error: "scopes must be a non-empty array" };
|
|
33133
|
+
}
|
|
33134
|
+
if (!input.scopes.every((scope) => typeof scope === "string")) {
|
|
33135
|
+
return { valid: false, error: "scopes must contain only strings" };
|
|
33097
33136
|
}
|
|
33098
|
-
const
|
|
33099
|
-
if (
|
|
33100
|
-
return { valid: false, error: "
|
|
33137
|
+
const grantVersion = toUint256(input.grantVersion);
|
|
33138
|
+
if (grantVersion === null || grantVersion < 1n) {
|
|
33139
|
+
return { valid: false, error: "grantVersion must be a uint256 >= 1" };
|
|
33140
|
+
}
|
|
33141
|
+
const expiresAt = toUint256(input.expiresAt);
|
|
33142
|
+
if (expiresAt === null) {
|
|
33143
|
+
return { valid: false, error: "expiresAt must be a non-negative uint256" };
|
|
33101
33144
|
}
|
|
33102
33145
|
let valid;
|
|
33103
33146
|
try {
|
|
@@ -33109,8 +33152,9 @@ async function verifyGrantRegistration(input) {
|
|
|
33109
33152
|
message: {
|
|
33110
33153
|
grantorAddress: input.grantorAddress,
|
|
33111
33154
|
granteeId: input.granteeId,
|
|
33112
|
-
|
|
33113
|
-
|
|
33155
|
+
scopes: input.scopes,
|
|
33156
|
+
grantVersion,
|
|
33157
|
+
expiresAt
|
|
33114
33158
|
},
|
|
33115
33159
|
signature: input.signature
|
|
33116
33160
|
});
|
|
@@ -33121,26 +33165,269 @@ async function verifyGrantRegistration(input) {
|
|
|
33121
33165
|
return { valid: false, error: "Grant signature does not match grantor" };
|
|
33122
33166
|
}
|
|
33123
33167
|
const nowSeconds = input.nowSeconds ?? Math.floor(Date.now() / 1e3);
|
|
33124
|
-
if (
|
|
33168
|
+
if (expiresAt > 0n && expiresAt < BigInt(nowSeconds)) {
|
|
33125
33169
|
return { valid: false, error: "Grant has expired" };
|
|
33126
33170
|
}
|
|
33127
|
-
if (payload.user !== void 0 && payload.user.toLowerCase() !== input.grantorAddress.toLowerCase()) {
|
|
33128
|
-
return { valid: false, error: "Grant user does not match grantorAddress" };
|
|
33129
|
-
}
|
|
33130
33171
|
return {
|
|
33131
33172
|
valid: true,
|
|
33132
33173
|
grantorAddress: input.grantorAddress,
|
|
33133
33174
|
granteeId: input.granteeId,
|
|
33134
|
-
|
|
33135
|
-
|
|
33136
|
-
|
|
33175
|
+
scopes: input.scopes,
|
|
33176
|
+
grantVersion: grantVersion.toString(),
|
|
33177
|
+
expiresAt: expiresAt.toString()
|
|
33137
33178
|
};
|
|
33138
33179
|
}
|
|
33139
33180
|
|
|
33140
|
-
// src/protocol/
|
|
33181
|
+
// src/protocol/fee-registry.ts
|
|
33182
|
+
import { parseAbi } from "viem";
|
|
33183
|
+
var FEE_REGISTRY_ABI = parseAbi([
|
|
33184
|
+
"struct Fee { uint256 amount; address asset; address payee; bool enabled; }",
|
|
33185
|
+
"function fees(bytes32 operation) view returns (Fee)",
|
|
33186
|
+
"function operationKey(string name) pure returns (bytes32)"
|
|
33187
|
+
]);
|
|
33188
|
+
var REGISTRATION_KIND_FOR_OP = {
|
|
33189
|
+
grant: "grant_registration",
|
|
33190
|
+
data: "data_registration",
|
|
33191
|
+
server: "server_registration",
|
|
33192
|
+
builder: "builder_registration"
|
|
33193
|
+
};
|
|
33194
|
+
function operationNameFor(kind, opts) {
|
|
33195
|
+
switch (kind) {
|
|
33196
|
+
case "grant_registration":
|
|
33197
|
+
return opts?.grantRegistrationOpName ?? "grant_registration";
|
|
33198
|
+
case "data_access":
|
|
33199
|
+
return opts?.dataAccessOpName ?? "data_access";
|
|
33200
|
+
case "data_registration":
|
|
33201
|
+
return opts?.dataRegistrationOpName ?? "data_registration";
|
|
33202
|
+
case "server_registration":
|
|
33203
|
+
return opts?.serverRegistrationOpName ?? "server_registration";
|
|
33204
|
+
case "builder_registration":
|
|
33205
|
+
return opts?.builderRegistrationOpName ?? "builder_registration";
|
|
33206
|
+
}
|
|
33207
|
+
}
|
|
33208
|
+
var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
33209
|
+
async function getFee(client, config, kind, opts) {
|
|
33210
|
+
const address = config.contracts.feeRegistry;
|
|
33211
|
+
const opName = operationNameFor(kind, opts);
|
|
33212
|
+
const opKey = await client.readContract({
|
|
33213
|
+
address,
|
|
33214
|
+
abi: FEE_REGISTRY_ABI,
|
|
33215
|
+
functionName: "operationKey",
|
|
33216
|
+
args: [opName]
|
|
33217
|
+
});
|
|
33218
|
+
const fee = await client.readContract({
|
|
33219
|
+
address,
|
|
33220
|
+
abi: FEE_REGISTRY_ABI,
|
|
33221
|
+
functionName: "fees",
|
|
33222
|
+
args: [opKey]
|
|
33223
|
+
});
|
|
33224
|
+
if (fee.enabled && fee.payee === ZERO_ADDRESS) {
|
|
33225
|
+
throw new Error(
|
|
33226
|
+
`FeeRegistry: enabled operation "${opName}" has zero-address payee \u2014 contract pre-flight rejects payouts to 0x0`
|
|
33227
|
+
);
|
|
33228
|
+
}
|
|
33229
|
+
return fee;
|
|
33230
|
+
}
|
|
33231
|
+
async function getOpFee(client, config, opType, opts) {
|
|
33232
|
+
const registrationKind = REGISTRATION_KIND_FOR_OP[opType];
|
|
33233
|
+
if (!registrationKind) {
|
|
33234
|
+
throw new Error(
|
|
33235
|
+
`getOpFee: unknown opType "${opType}" \u2014 supported types are ${Object.keys(REGISTRATION_KIND_FOR_OP).join(", ")}`
|
|
33236
|
+
);
|
|
33237
|
+
}
|
|
33238
|
+
const includeDataAccess = opType === "grant";
|
|
33239
|
+
const [registration, dataAccess] = await Promise.all([
|
|
33240
|
+
getFee(client, config, registrationKind, opts),
|
|
33241
|
+
includeDataAccess ? getFee(client, config, "data_access", opts) : Promise.resolve({
|
|
33242
|
+
amount: 0n,
|
|
33243
|
+
asset: ZERO_ADDRESS,
|
|
33244
|
+
payee: ZERO_ADDRESS,
|
|
33245
|
+
enabled: false
|
|
33246
|
+
})
|
|
33247
|
+
]);
|
|
33248
|
+
if (registration.enabled && dataAccess.enabled && registration.asset.toLowerCase() !== dataAccess.asset.toLowerCase()) {
|
|
33249
|
+
throw new Error(
|
|
33250
|
+
`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.`
|
|
33251
|
+
);
|
|
33252
|
+
}
|
|
33253
|
+
const asset = registration.enabled ? registration.asset : dataAccess.enabled ? dataAccess.asset : ZERO_ADDRESS;
|
|
33254
|
+
return {
|
|
33255
|
+
asset,
|
|
33256
|
+
registrationFee: registration.enabled ? registration.amount : 0n,
|
|
33257
|
+
dataAccessFee: dataAccess.enabled ? dataAccess.amount : 0n,
|
|
33258
|
+
registrationEnabled: registration.enabled,
|
|
33259
|
+
dataAccessEnabled: dataAccess.enabled,
|
|
33260
|
+
registrationPayee: registration.enabled ? registration.payee : ZERO_ADDRESS,
|
|
33261
|
+
dataAccessPayee: dataAccess.enabled ? dataAccess.payee : ZERO_ADDRESS
|
|
33262
|
+
};
|
|
33263
|
+
}
|
|
33264
|
+
|
|
33265
|
+
// src/protocol/escrow-deposit.ts
|
|
33266
|
+
import { encodeFunctionData } from "viem";
|
|
33267
|
+
var ESCROW_DEPOSIT_ABI = [
|
|
33268
|
+
{
|
|
33269
|
+
type: "function",
|
|
33270
|
+
name: "depositNative",
|
|
33271
|
+
stateMutability: "payable",
|
|
33272
|
+
inputs: [{ name: "account", type: "address" }],
|
|
33273
|
+
outputs: []
|
|
33274
|
+
},
|
|
33275
|
+
{
|
|
33276
|
+
type: "function",
|
|
33277
|
+
name: "depositToken",
|
|
33278
|
+
stateMutability: "nonpayable",
|
|
33279
|
+
inputs: [
|
|
33280
|
+
{ name: "account", type: "address" },
|
|
33281
|
+
{ name: "token", type: "address" },
|
|
33282
|
+
{ name: "amount", type: "uint256" }
|
|
33283
|
+
],
|
|
33284
|
+
outputs: []
|
|
33285
|
+
}
|
|
33286
|
+
];
|
|
33287
|
+
function escrowContractAddress(config) {
|
|
33288
|
+
return config.contracts.dataPortabilityEscrow;
|
|
33289
|
+
}
|
|
33290
|
+
function encodeDepositNativeData(input) {
|
|
33291
|
+
return encodeFunctionData({
|
|
33292
|
+
abi: ESCROW_DEPOSIT_ABI,
|
|
33293
|
+
functionName: "depositNative",
|
|
33294
|
+
args: [input.account]
|
|
33295
|
+
});
|
|
33296
|
+
}
|
|
33297
|
+
function encodeDepositTokenData(input) {
|
|
33298
|
+
return encodeFunctionData({
|
|
33299
|
+
abi: ESCROW_DEPOSIT_ABI,
|
|
33300
|
+
functionName: "depositToken",
|
|
33301
|
+
args: [input.account, input.token, input.amount]
|
|
33302
|
+
});
|
|
33303
|
+
}
|
|
33304
|
+
function buildDepositNativeRequest(config, input) {
|
|
33305
|
+
return {
|
|
33306
|
+
to: escrowContractAddress(config),
|
|
33307
|
+
data: encodeDepositNativeData({ account: input.account }),
|
|
33308
|
+
value: input.amount
|
|
33309
|
+
};
|
|
33310
|
+
}
|
|
33311
|
+
function buildDepositTokenRequest(config, input) {
|
|
33312
|
+
return {
|
|
33313
|
+
to: escrowContractAddress(config),
|
|
33314
|
+
data: encodeDepositTokenData(input)
|
|
33315
|
+
};
|
|
33316
|
+
}
|
|
33317
|
+
|
|
33318
|
+
// src/protocol/data-point-status.ts
|
|
33319
|
+
import { encodeFunctionData as encodeFunctionData2 } from "viem";
|
|
33320
|
+
var DataPointStatus = /* @__PURE__ */ ((DataPointStatus2) => {
|
|
33321
|
+
DataPointStatus2[DataPointStatus2["None"] = 0] = "None";
|
|
33322
|
+
DataPointStatus2[DataPointStatus2["Active"] = 1] = "Active";
|
|
33323
|
+
DataPointStatus2[DataPointStatus2["Inactive"] = 2] = "Inactive";
|
|
33324
|
+
DataPointStatus2[DataPointStatus2["Unavailable"] = 3] = "Unavailable";
|
|
33325
|
+
return DataPointStatus2;
|
|
33326
|
+
})(DataPointStatus || {});
|
|
33327
|
+
var DATA_REGISTRY_STATUS_ABI = [
|
|
33328
|
+
{
|
|
33329
|
+
type: "function",
|
|
33330
|
+
name: "setStatus",
|
|
33331
|
+
stateMutability: "nonpayable",
|
|
33332
|
+
inputs: [
|
|
33333
|
+
{ name: "scope", type: "string" },
|
|
33334
|
+
{ name: "newStatus", type: "uint8" }
|
|
33335
|
+
],
|
|
33336
|
+
outputs: []
|
|
33337
|
+
}
|
|
33338
|
+
];
|
|
33339
|
+
function dataRegistryContractAddress(config) {
|
|
33340
|
+
return config.contracts.dataRegistry;
|
|
33341
|
+
}
|
|
33342
|
+
function encodeSetDataPointStatusData(input) {
|
|
33343
|
+
return encodeFunctionData2({
|
|
33344
|
+
abi: DATA_REGISTRY_STATUS_ABI,
|
|
33345
|
+
functionName: "setStatus",
|
|
33346
|
+
args: [input.scope, input.status]
|
|
33347
|
+
});
|
|
33348
|
+
}
|
|
33349
|
+
function buildSetDataPointStatusRequest(config, input) {
|
|
33350
|
+
return {
|
|
33351
|
+
to: dataRegistryContractAddress(config),
|
|
33352
|
+
data: encodeSetDataPointStatusData(input)
|
|
33353
|
+
};
|
|
33354
|
+
}
|
|
33355
|
+
function buildMarkDataPointUnavailableRequest(config, input) {
|
|
33356
|
+
return buildSetDataPointStatusRequest(config, {
|
|
33357
|
+
scope: input.scope,
|
|
33358
|
+
status: 3 /* Unavailable */
|
|
33359
|
+
});
|
|
33360
|
+
}
|
|
33361
|
+
|
|
33362
|
+
// src/protocol/data-file.ts
|
|
33141
33363
|
import { z } from "zod";
|
|
33364
|
+
var DataFileEnvelopeSchema = z.object({
|
|
33365
|
+
$schema: z.string().url().optional(),
|
|
33366
|
+
version: z.literal("1.0"),
|
|
33367
|
+
scope: z.string(),
|
|
33368
|
+
schemaId: z.string().optional(),
|
|
33369
|
+
collectedAt: z.string().datetime(),
|
|
33370
|
+
data: z.record(z.string(), z.unknown())
|
|
33371
|
+
});
|
|
33372
|
+
function createDataFileEnvelope(scope, collectedAt, data, schemaUrl, schemaId) {
|
|
33373
|
+
return {
|
|
33374
|
+
...schemaUrl !== void 0 && { $schema: schemaUrl },
|
|
33375
|
+
...schemaId !== void 0 && { schemaId },
|
|
33376
|
+
version: "1.0",
|
|
33377
|
+
scope,
|
|
33378
|
+
collectedAt,
|
|
33379
|
+
data
|
|
33380
|
+
};
|
|
33381
|
+
}
|
|
33382
|
+
var IngestResponseSchema = z.object({
|
|
33383
|
+
scope: z.string(),
|
|
33384
|
+
collectedAt: z.string().datetime(),
|
|
33385
|
+
status: z.enum(["stored", "syncing"])
|
|
33386
|
+
});
|
|
33387
|
+
|
|
33388
|
+
// src/protocol/personal-server-data.ts
|
|
33389
|
+
function personalServerDataReadPath(scope) {
|
|
33390
|
+
return `/v1/data/${encodeURIComponent(scope)}`;
|
|
33391
|
+
}
|
|
33392
|
+
async function buildPersonalServerDataReadRequest(params) {
|
|
33393
|
+
const path = personalServerDataReadPath(params.scope);
|
|
33394
|
+
const baseUrl = params.personalServerUrl.replace(/\/+$/, "");
|
|
33395
|
+
const audience = params.audience ?? baseUrl;
|
|
33396
|
+
const headers = new Headers(params.headers);
|
|
33397
|
+
headers.set(
|
|
33398
|
+
"Authorization",
|
|
33399
|
+
await buildWeb3SignedHeader({
|
|
33400
|
+
aud: audience,
|
|
33401
|
+
grantId: params.grantId,
|
|
33402
|
+
method: "GET",
|
|
33403
|
+
signMessage: params.signMessage,
|
|
33404
|
+
uri: path
|
|
33405
|
+
})
|
|
33406
|
+
);
|
|
33407
|
+
return new Request(`${baseUrl}${path}`, {
|
|
33408
|
+
headers,
|
|
33409
|
+
method: "GET"
|
|
33410
|
+
});
|
|
33411
|
+
}
|
|
33412
|
+
async function readPersonalServerData(params) {
|
|
33413
|
+
const fetchFn = params.fetch ?? globalThis.fetch;
|
|
33414
|
+
if (fetchFn === void 0) {
|
|
33415
|
+
throw new Error("No fetch implementation available");
|
|
33416
|
+
}
|
|
33417
|
+
const request = await buildPersonalServerDataReadRequest(params);
|
|
33418
|
+
const response = await fetchFn(request);
|
|
33419
|
+
if (!response.ok) {
|
|
33420
|
+
throw new Error(
|
|
33421
|
+
`Personal Server data read failed: ${response.status} ${response.statusText}`
|
|
33422
|
+
);
|
|
33423
|
+
}
|
|
33424
|
+
return DataFileEnvelopeSchema.parse(await response.json());
|
|
33425
|
+
}
|
|
33426
|
+
|
|
33427
|
+
// src/protocol/scopes.ts
|
|
33428
|
+
import { z as z2 } from "zod";
|
|
33142
33429
|
var SEGMENT_RE = /^[a-z0-9][a-z0-9_]*$/;
|
|
33143
|
-
var ScopeSchema =
|
|
33430
|
+
var ScopeSchema = z2.string().refine(
|
|
33144
33431
|
(scope) => {
|
|
33145
33432
|
const parts = scope.split(".");
|
|
33146
33433
|
return parts.length >= 2 && parts.length <= 3 && parts.every((part) => SEGMENT_RE.test(part));
|
|
@@ -33181,32 +33468,6 @@ function scopeCoveredByGrant(requestedScope, grantedScopes) {
|
|
|
33181
33468
|
);
|
|
33182
33469
|
}
|
|
33183
33470
|
|
|
33184
|
-
// src/protocol/data-file.ts
|
|
33185
|
-
import { z as z2 } from "zod";
|
|
33186
|
-
var DataFileEnvelopeSchema = z2.object({
|
|
33187
|
-
$schema: z2.string().url().optional(),
|
|
33188
|
-
version: z2.literal("1.0"),
|
|
33189
|
-
scope: z2.string(),
|
|
33190
|
-
schemaId: z2.string().optional(),
|
|
33191
|
-
collectedAt: z2.string().datetime(),
|
|
33192
|
-
data: z2.record(z2.string(), z2.unknown())
|
|
33193
|
-
});
|
|
33194
|
-
function createDataFileEnvelope(scope, collectedAt, data, schemaUrl, schemaId) {
|
|
33195
|
-
return {
|
|
33196
|
-
...schemaUrl !== void 0 && { $schema: schemaUrl },
|
|
33197
|
-
...schemaId !== void 0 && { schemaId },
|
|
33198
|
-
version: "1.0",
|
|
33199
|
-
scope,
|
|
33200
|
-
collectedAt,
|
|
33201
|
-
data
|
|
33202
|
-
};
|
|
33203
|
-
}
|
|
33204
|
-
var IngestResponseSchema = z2.object({
|
|
33205
|
-
scope: z2.string(),
|
|
33206
|
-
collectedAt: z2.string().datetime(),
|
|
33207
|
-
status: z2.enum(["stored", "syncing"])
|
|
33208
|
-
});
|
|
33209
|
-
|
|
33210
33471
|
// src/protocol/gateway.ts
|
|
33211
33472
|
function createGatewayClient(baseUrl) {
|
|
33212
33473
|
const base = baseUrl.replace(/\/+$/, "");
|
|
@@ -33214,16 +33475,6 @@ function createGatewayClient(baseUrl) {
|
|
|
33214
33475
|
const envelope = await res.json();
|
|
33215
33476
|
return envelope.data;
|
|
33216
33477
|
}
|
|
33217
|
-
function normalizeFileRecord(record) {
|
|
33218
|
-
return {
|
|
33219
|
-
fileId: record.fileId ?? record.id ?? "",
|
|
33220
|
-
owner: record.owner ?? record.ownerAddress ?? "",
|
|
33221
|
-
url: record.url,
|
|
33222
|
-
schemaId: record.schemaId,
|
|
33223
|
-
createdAt: record.createdAt ?? record.addedAt ?? "",
|
|
33224
|
-
deletedAt: record.deletedAt ?? null
|
|
33225
|
-
};
|
|
33226
|
-
}
|
|
33227
33478
|
function getMutationId(body, key) {
|
|
33228
33479
|
const value = body[key] ?? body["id"];
|
|
33229
33480
|
return typeof value === "string" ? value : void 0;
|
|
@@ -33273,31 +33524,33 @@ function createGatewayClient(baseUrl) {
|
|
|
33273
33524
|
}
|
|
33274
33525
|
return unwrapEnvelope(res);
|
|
33275
33526
|
},
|
|
33276
|
-
async
|
|
33277
|
-
const res = await fetch(`${base}/v1/
|
|
33527
|
+
async getDataPoint(dataPointId) {
|
|
33528
|
+
const res = await fetch(`${base}/v1/data/${dataPointId}`);
|
|
33278
33529
|
if (res.status === 404) return null;
|
|
33279
33530
|
if (!res.ok) {
|
|
33280
33531
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33281
33532
|
}
|
|
33282
|
-
return
|
|
33533
|
+
return unwrapEnvelope(res);
|
|
33283
33534
|
},
|
|
33284
|
-
async
|
|
33535
|
+
async listDataPointsByOwner(owner, cursor, options) {
|
|
33285
33536
|
const params = new URLSearchParams({ user: owner });
|
|
33286
33537
|
if (cursor !== null) {
|
|
33287
33538
|
params.set("cursor", cursor);
|
|
33288
33539
|
}
|
|
33289
|
-
if (options?.
|
|
33290
|
-
params.set("
|
|
33540
|
+
if (options?.since) {
|
|
33541
|
+
params.set("since", options.since);
|
|
33291
33542
|
}
|
|
33292
|
-
|
|
33543
|
+
if (options?.limit !== void 0) {
|
|
33544
|
+
params.set("limit", String(options.limit));
|
|
33545
|
+
}
|
|
33546
|
+
const res = await fetch(`${base}/v1/data?${params.toString()}`);
|
|
33293
33547
|
if (!res.ok) {
|
|
33294
33548
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33295
33549
|
}
|
|
33296
33550
|
const envelope = await res.json();
|
|
33297
|
-
const
|
|
33298
|
-
const nextCursor = pagination?.hasMore === false ? null : pagination?.nextCursor ?? envelope.data.cursor ?? null;
|
|
33551
|
+
const nextCursor = envelope.pagination?.hasMore === false ? null : envelope.pagination?.nextCursor ?? null;
|
|
33299
33552
|
return {
|
|
33300
|
-
|
|
33553
|
+
dataPoints: envelope.data.dataPoints,
|
|
33301
33554
|
cursor: nextCursor
|
|
33302
33555
|
};
|
|
33303
33556
|
},
|
|
@@ -33339,8 +33592,8 @@ function createGatewayClient(baseUrl) {
|
|
|
33339
33592
|
alreadyRegistered: false
|
|
33340
33593
|
};
|
|
33341
33594
|
},
|
|
33342
|
-
async
|
|
33343
|
-
const res = await fetch(`${base}/v1/
|
|
33595
|
+
async registerBuilder(params) {
|
|
33596
|
+
const res = await fetch(`${base}/v1/builders`, {
|
|
33344
33597
|
method: "POST",
|
|
33345
33598
|
headers: {
|
|
33346
33599
|
"Content-Type": "application/json",
|
|
@@ -33348,22 +33601,57 @@ function createGatewayClient(baseUrl) {
|
|
|
33348
33601
|
},
|
|
33349
33602
|
body: JSON.stringify({
|
|
33350
33603
|
ownerAddress: params.ownerAddress,
|
|
33351
|
-
|
|
33352
|
-
|
|
33604
|
+
granteeAddress: params.granteeAddress,
|
|
33605
|
+
publicKey: params.publicKey,
|
|
33606
|
+
appUrl: params.appUrl
|
|
33353
33607
|
})
|
|
33354
33608
|
});
|
|
33355
33609
|
if (res.status === 409) {
|
|
33356
33610
|
const body2 = await res.json().catch(() => ({}));
|
|
33357
33611
|
return {
|
|
33358
|
-
|
|
33612
|
+
builderId: getMutationId(
|
|
33613
|
+
body2,
|
|
33614
|
+
"builderId"
|
|
33615
|
+
),
|
|
33616
|
+
alreadyRegistered: true
|
|
33359
33617
|
};
|
|
33360
33618
|
}
|
|
33361
33619
|
if (!res.ok) {
|
|
33362
33620
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33363
33621
|
}
|
|
33364
|
-
const body = await res.json();
|
|
33622
|
+
const body = await res.json().catch(() => ({}));
|
|
33623
|
+
return {
|
|
33624
|
+
builderId: getMutationId(body, "builderId"),
|
|
33625
|
+
alreadyRegistered: false
|
|
33626
|
+
};
|
|
33627
|
+
},
|
|
33628
|
+
async registerDataPoint(params) {
|
|
33629
|
+
const res = await fetch(`${base}/v1/data`, {
|
|
33630
|
+
method: "POST",
|
|
33631
|
+
headers: {
|
|
33632
|
+
"Content-Type": "application/json",
|
|
33633
|
+
Authorization: `Web3Signed ${params.signature}`
|
|
33634
|
+
},
|
|
33635
|
+
body: JSON.stringify({
|
|
33636
|
+
ownerAddress: params.ownerAddress,
|
|
33637
|
+
scope: params.scope,
|
|
33638
|
+
dataHash: params.dataHash,
|
|
33639
|
+
metadataHash: params.metadataHash,
|
|
33640
|
+
expectedVersion: params.expectedVersion
|
|
33641
|
+
})
|
|
33642
|
+
});
|
|
33643
|
+
if (!res.ok) {
|
|
33644
|
+
const body2 = await res.json().catch(() => ({}));
|
|
33645
|
+
const detail = body2.error ?? res.statusText;
|
|
33646
|
+
throw new Error(`Gateway error: ${res.status} ${detail}`);
|
|
33647
|
+
}
|
|
33648
|
+
const body = await res.json().catch(() => ({}));
|
|
33365
33649
|
return {
|
|
33366
|
-
|
|
33650
|
+
dataPointId: getMutationId(
|
|
33651
|
+
body,
|
|
33652
|
+
"dataPointId"
|
|
33653
|
+
),
|
|
33654
|
+
expectedVersion: body.expectedVersion
|
|
33367
33655
|
};
|
|
33368
33656
|
},
|
|
33369
33657
|
async createGrant(params) {
|
|
@@ -33376,8 +33664,9 @@ function createGatewayClient(baseUrl) {
|
|
|
33376
33664
|
body: JSON.stringify({
|
|
33377
33665
|
grantorAddress: params.grantorAddress,
|
|
33378
33666
|
granteeId: params.granteeId,
|
|
33379
|
-
|
|
33380
|
-
|
|
33667
|
+
scopes: params.scopes,
|
|
33668
|
+
grantVersion: params.grantVersion,
|
|
33669
|
+
expiresAt: params.expiresAt
|
|
33381
33670
|
})
|
|
33382
33671
|
});
|
|
33383
33672
|
if (res.status === 409) {
|
|
@@ -33402,7 +33691,8 @@ function createGatewayClient(baseUrl) {
|
|
|
33402
33691
|
Authorization: `Web3Signed ${params.signature}`
|
|
33403
33692
|
},
|
|
33404
33693
|
body: JSON.stringify({
|
|
33405
|
-
grantorAddress: params.grantorAddress
|
|
33694
|
+
grantorAddress: params.grantorAddress,
|
|
33695
|
+
grantVersion: params.grantVersion
|
|
33406
33696
|
})
|
|
33407
33697
|
});
|
|
33408
33698
|
if (res.status === 409) return;
|
|
@@ -33410,21 +33700,174 @@ function createGatewayClient(baseUrl) {
|
|
|
33410
33700
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33411
33701
|
}
|
|
33412
33702
|
},
|
|
33413
|
-
async
|
|
33414
|
-
const res = await fetch(`${base}/v1/
|
|
33415
|
-
|
|
33703
|
+
async getEscrowBalance(account) {
|
|
33704
|
+
const res = await fetch(`${base}/v1/escrow/balance?account=${account}`);
|
|
33705
|
+
if (!res.ok) {
|
|
33706
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33707
|
+
}
|
|
33708
|
+
return await res.json();
|
|
33709
|
+
},
|
|
33710
|
+
async submitEscrowDeposit(params) {
|
|
33711
|
+
const res = await fetch(`${base}/v1/escrow/deposit`, {
|
|
33712
|
+
method: "POST",
|
|
33713
|
+
headers: { "Content-Type": "application/json" },
|
|
33714
|
+
body: JSON.stringify({ txHash: params.txHash })
|
|
33715
|
+
});
|
|
33716
|
+
if (res.status !== 200 && res.status !== 202) {
|
|
33717
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33718
|
+
}
|
|
33719
|
+
return await res.json();
|
|
33720
|
+
},
|
|
33721
|
+
async payForOperation(params) {
|
|
33722
|
+
const body = {
|
|
33723
|
+
payerAddress: params.payerAddress,
|
|
33724
|
+
opType: params.opType,
|
|
33725
|
+
opId: params.opId,
|
|
33726
|
+
asset: params.asset,
|
|
33727
|
+
amount: params.amount,
|
|
33728
|
+
paymentNonce: params.paymentNonce
|
|
33729
|
+
};
|
|
33730
|
+
if (params.accessRecord) {
|
|
33731
|
+
body["accessRecord"] = params.accessRecord;
|
|
33732
|
+
}
|
|
33733
|
+
const res = await fetch(`${base}/v1/escrow/pay`, {
|
|
33734
|
+
method: "POST",
|
|
33416
33735
|
headers: {
|
|
33417
33736
|
"Content-Type": "application/json",
|
|
33418
33737
|
Authorization: `Web3Signed ${params.signature}`
|
|
33419
33738
|
},
|
|
33420
|
-
body: JSON.stringify(
|
|
33421
|
-
|
|
33422
|
-
|
|
33739
|
+
body: JSON.stringify(body)
|
|
33740
|
+
});
|
|
33741
|
+
if (!res.ok) {
|
|
33742
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33743
|
+
}
|
|
33744
|
+
return await res.json();
|
|
33745
|
+
},
|
|
33746
|
+
async settle(params) {
|
|
33747
|
+
const res = await fetch(`${base}/v1/settle`, {
|
|
33748
|
+
method: "POST",
|
|
33749
|
+
headers: { "Content-Type": "application/json" },
|
|
33750
|
+
// The gateway accepts an empty body; only `limit` is recognised.
|
|
33751
|
+
// Always send a JSON body so the gateway's req.body shape parse
|
|
33752
|
+
// doesn't have to deal with an undefined.
|
|
33753
|
+
body: JSON.stringify(params ?? {})
|
|
33423
33754
|
});
|
|
33424
|
-
if (res.status === 409) return;
|
|
33425
33755
|
if (!res.ok) {
|
|
33426
33756
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33427
33757
|
}
|
|
33758
|
+
return await res.json();
|
|
33759
|
+
}
|
|
33760
|
+
};
|
|
33761
|
+
}
|
|
33762
|
+
|
|
33763
|
+
// src/protocol/escrow.ts
|
|
33764
|
+
var GENERIC_PAYMENT_TYPES = {
|
|
33765
|
+
GenericPayment: [
|
|
33766
|
+
{ name: "payerAddress", type: "address" },
|
|
33767
|
+
{ name: "opType", type: "string" },
|
|
33768
|
+
{ name: "opId", type: "bytes32" },
|
|
33769
|
+
{ name: "asset", type: "address" },
|
|
33770
|
+
{ name: "amount", type: "uint256" },
|
|
33771
|
+
{ name: "paymentNonce", type: "uint256" }
|
|
33772
|
+
]
|
|
33773
|
+
};
|
|
33774
|
+
function genericPaymentDomain(chainId, escrowContract) {
|
|
33775
|
+
return {
|
|
33776
|
+
name: "Vana Data Portability",
|
|
33777
|
+
version: "1",
|
|
33778
|
+
chainId,
|
|
33779
|
+
verifyingContract: escrowContract
|
|
33780
|
+
};
|
|
33781
|
+
}
|
|
33782
|
+
var ESCROW_DEPOSIT_ABI2 = [
|
|
33783
|
+
{
|
|
33784
|
+
type: "function",
|
|
33785
|
+
name: "depositNative",
|
|
33786
|
+
stateMutability: "payable",
|
|
33787
|
+
inputs: [{ name: "account", type: "address" }],
|
|
33788
|
+
outputs: []
|
|
33789
|
+
},
|
|
33790
|
+
{
|
|
33791
|
+
type: "function",
|
|
33792
|
+
name: "depositToken",
|
|
33793
|
+
stateMutability: "nonpayable",
|
|
33794
|
+
inputs: [
|
|
33795
|
+
{ name: "account", type: "address" },
|
|
33796
|
+
{ name: "token", type: "address" },
|
|
33797
|
+
{ name: "amount", type: "uint256" }
|
|
33798
|
+
],
|
|
33799
|
+
outputs: []
|
|
33800
|
+
}
|
|
33801
|
+
];
|
|
33802
|
+
var NATIVE_ASSET_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
33803
|
+
function createEscrowGatewayClient(baseUrl) {
|
|
33804
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
33805
|
+
async function throwOnError(res, context) {
|
|
33806
|
+
if (!res.ok) {
|
|
33807
|
+
let detail = "";
|
|
33808
|
+
try {
|
|
33809
|
+
const body = await res.json();
|
|
33810
|
+
if (body.error) detail = `: ${body.error}`;
|
|
33811
|
+
} catch {
|
|
33812
|
+
}
|
|
33813
|
+
throw new Error(
|
|
33814
|
+
`Escrow gateway error (${context}): ${res.status} ${res.statusText}${detail}`
|
|
33815
|
+
);
|
|
33816
|
+
}
|
|
33817
|
+
}
|
|
33818
|
+
return {
|
|
33819
|
+
async submitDeposit({ txHash }) {
|
|
33820
|
+
const res = await fetch(`${base}/v1/escrow/deposit`, {
|
|
33821
|
+
method: "POST",
|
|
33822
|
+
headers: { "Content-Type": "application/json" },
|
|
33823
|
+
body: JSON.stringify({ txHash })
|
|
33824
|
+
});
|
|
33825
|
+
if (res.status !== 200 && res.status !== 202) {
|
|
33826
|
+
await throwOnError(res, "POST /v1/escrow/deposit");
|
|
33827
|
+
}
|
|
33828
|
+
return res.json();
|
|
33829
|
+
},
|
|
33830
|
+
async getEscrowBalance(account) {
|
|
33831
|
+
const res = await fetch(
|
|
33832
|
+
`${base}/v1/escrow/balance?account=${encodeURIComponent(account)}`
|
|
33833
|
+
);
|
|
33834
|
+
await throwOnError(res, "GET /v1/escrow/balance");
|
|
33835
|
+
return res.json();
|
|
33836
|
+
},
|
|
33837
|
+
async syncEscrowBalance(account) {
|
|
33838
|
+
const res = await fetch(
|
|
33839
|
+
`${base}/v1/escrow/balance/sync?account=${encodeURIComponent(account)}`,
|
|
33840
|
+
{ method: "POST" }
|
|
33841
|
+
);
|
|
33842
|
+
await throwOnError(res, "POST /v1/escrow/balance/sync");
|
|
33843
|
+
return res.json();
|
|
33844
|
+
},
|
|
33845
|
+
async payForOp({
|
|
33846
|
+
payerAddress,
|
|
33847
|
+
opType,
|
|
33848
|
+
opId,
|
|
33849
|
+
asset,
|
|
33850
|
+
amount,
|
|
33851
|
+
paymentNonce,
|
|
33852
|
+
signature
|
|
33853
|
+
}) {
|
|
33854
|
+
const res = await fetch(`${base}/v1/escrow/pay`, {
|
|
33855
|
+
method: "POST",
|
|
33856
|
+
headers: {
|
|
33857
|
+
"Content-Type": "application/json",
|
|
33858
|
+
Authorization: `Web3Signed ${signature}`
|
|
33859
|
+
},
|
|
33860
|
+
body: JSON.stringify({
|
|
33861
|
+
payerAddress,
|
|
33862
|
+
opType,
|
|
33863
|
+
opId,
|
|
33864
|
+
asset,
|
|
33865
|
+
amount,
|
|
33866
|
+
paymentNonce
|
|
33867
|
+
})
|
|
33868
|
+
});
|
|
33869
|
+
await throwOnError(res, "POST /v1/escrow/pay");
|
|
33870
|
+
return res.json();
|
|
33428
33871
|
}
|
|
33429
33872
|
};
|
|
33430
33873
|
}
|
|
@@ -33493,6 +33936,7 @@ async function parsePSError(response) {
|
|
|
33493
33936
|
}
|
|
33494
33937
|
export {
|
|
33495
33938
|
ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
|
|
33939
|
+
ADD_DATA_TYPES,
|
|
33496
33940
|
AccountPersonalServerLiteOwnerBindingError,
|
|
33497
33941
|
AccountPersonalServerRegistrationError,
|
|
33498
33942
|
BUILDER_REGISTRATION_TYPES,
|
|
@@ -33502,12 +33946,15 @@ export {
|
|
|
33502
33946
|
CallbackStorage,
|
|
33503
33947
|
ContractFactory,
|
|
33504
33948
|
ContractNotFoundError,
|
|
33949
|
+
DATA_REGISTRY_STATUS_ABI,
|
|
33505
33950
|
DataFileEnvelopeSchema,
|
|
33951
|
+
DataPointStatus,
|
|
33506
33952
|
DropboxStorage,
|
|
33507
33953
|
ECIESError,
|
|
33954
|
+
ESCROW_DEPOSIT_ABI2 as ESCROW_DEPOSIT_ABI,
|
|
33508
33955
|
ExpiredTokenError,
|
|
33509
|
-
|
|
33510
|
-
|
|
33956
|
+
FEE_REGISTRY_ABI,
|
|
33957
|
+
GENERIC_PAYMENT_TYPES,
|
|
33511
33958
|
GRANT_REGISTRATION_TYPES,
|
|
33512
33959
|
GRANT_REVOCATION_TYPES,
|
|
33513
33960
|
GoogleDriveStorage,
|
|
@@ -33518,6 +33965,8 @@ export {
|
|
|
33518
33965
|
IpfsStorage,
|
|
33519
33966
|
MASTER_KEY_MESSAGE,
|
|
33520
33967
|
MissingAuthError,
|
|
33968
|
+
NATIVE_ASSET_ADDRESS,
|
|
33969
|
+
NATIVE_VANA_ASSET,
|
|
33521
33970
|
NetworkError,
|
|
33522
33971
|
NodeECIESUint8Provider as NodeECIESProvider,
|
|
33523
33972
|
NodePlatformAdapter,
|
|
@@ -33535,6 +33984,8 @@ export {
|
|
|
33535
33984
|
PersonalServerError,
|
|
33536
33985
|
PinataStorage,
|
|
33537
33986
|
R2Storage,
|
|
33987
|
+
RECORD_DATA_ACCESS_TYPES,
|
|
33988
|
+
REGISTRATION_KIND_FOR_OP,
|
|
33538
33989
|
ReadOnlyError,
|
|
33539
33990
|
RelayerError,
|
|
33540
33991
|
SERVER_REGISTRATION_TYPES,
|
|
@@ -33549,10 +34000,15 @@ export {
|
|
|
33549
34000
|
VanaError,
|
|
33550
34001
|
VanaStorage,
|
|
33551
34002
|
assertValidPkceVerifier,
|
|
34003
|
+
buildDepositNativeRequest,
|
|
34004
|
+
buildDepositTokenRequest,
|
|
34005
|
+
buildMarkDataPointUnavailableRequest,
|
|
34006
|
+
buildPersonalServerDataReadRequest,
|
|
33552
34007
|
buildPersonalServerLiteOwnerBindingMessage,
|
|
33553
34008
|
buildPersonalServerLiteOwnerBindingSignature,
|
|
33554
34009
|
buildPersonalServerRegistrationSignature,
|
|
33555
34010
|
buildPersonalServerRegistrationTypedData,
|
|
34011
|
+
buildSetDataPointStatusRequest,
|
|
33556
34012
|
buildWeb3SignedHeader,
|
|
33557
34013
|
builderRegistrationDomain,
|
|
33558
34014
|
chains,
|
|
@@ -33562,6 +34018,7 @@ export {
|
|
|
33562
34018
|
contractCacheForTesting,
|
|
33563
34019
|
createBrowserPlatformAdapter,
|
|
33564
34020
|
createDataFileEnvelope,
|
|
34021
|
+
createEscrowGatewayClient,
|
|
33565
34022
|
createGatewayClient,
|
|
33566
34023
|
createNodePlatformAdapter,
|
|
33567
34024
|
createPlatformAdapter,
|
|
@@ -33570,21 +34027,29 @@ export {
|
|
|
33570
34027
|
createVanaStorageProvider,
|
|
33571
34028
|
createViemPersonalServerLiteOwnerBindingSigner,
|
|
33572
34029
|
createViemPersonalServerRegistrationSigner,
|
|
34030
|
+
dataRegistryContractAddress,
|
|
34031
|
+
dataRegistryDomain,
|
|
33573
34032
|
decryptWithPassword,
|
|
33574
34033
|
deriveMasterKey,
|
|
33575
34034
|
deriveScopeKey,
|
|
33576
34035
|
deserializeECIES,
|
|
33577
34036
|
detectPlatform,
|
|
34037
|
+
encodeDepositNativeData,
|
|
34038
|
+
encodeDepositTokenData,
|
|
34039
|
+
encodeSetDataPointStatusData,
|
|
33578
34040
|
encryptWithPassword,
|
|
33579
|
-
|
|
33580
|
-
|
|
34041
|
+
escrowContractAddress,
|
|
34042
|
+
escrowPaymentDomain,
|
|
33581
34043
|
generatePkceVerifier,
|
|
34044
|
+
genericPaymentDomain,
|
|
33582
34045
|
getAbi,
|
|
33583
34046
|
getAllChains,
|
|
33584
34047
|
getChainConfig,
|
|
33585
34048
|
getContractAddress,
|
|
33586
34049
|
getContractController,
|
|
33587
34050
|
getContractInfo,
|
|
34051
|
+
getFee,
|
|
34052
|
+
getOpFee,
|
|
33588
34053
|
getPlatformCapabilities,
|
|
33589
34054
|
getServiceEndpoints,
|
|
33590
34055
|
grantRegistrationDomain,
|
|
@@ -33596,11 +34061,12 @@ export {
|
|
|
33596
34061
|
moksha,
|
|
33597
34062
|
mokshaServices,
|
|
33598
34063
|
mokshaTestnet2 as mokshaTestnet,
|
|
33599
|
-
parseGrantRegistrationPayload,
|
|
33600
34064
|
parsePSError,
|
|
33601
34065
|
parseScope,
|
|
33602
34066
|
parseWeb3SignedHeader,
|
|
34067
|
+
personalServerDataReadPath,
|
|
33603
34068
|
personalServerRegistrationDomain,
|
|
34069
|
+
readPersonalServerData,
|
|
33604
34070
|
recoverServerOwner,
|
|
33605
34071
|
registerPersonalServerSignature,
|
|
33606
34072
|
scopeCoveredByGrant,
|