@opendatalabs/vana-sdk 3.4.0 → 3.4.1-canary.7afbfe0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.browser.d.ts +7 -3
- package/dist/index.browser.js +423 -128
- package/dist/index.browser.js.map +4 -4
- package/dist/index.node.cjs +448 -133
- package/dist/index.node.cjs.map +4 -4
- package/dist/index.node.d.ts +7 -3
- package/dist/index.node.js +423 -128
- package/dist/index.node.js.map +4 -4
- 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/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 +110 -38
- package/dist/protocol/gateway.cjs.map +1 -1
- package/dist/protocol/gateway.d.ts +238 -56
- package/dist/protocol/gateway.js +110 -38
- 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/package.json +3 -2
package/dist/index.browser.js
CHANGED
|
@@ -31882,6 +31882,7 @@ async function verifyWeb3Signed(params) {
|
|
|
31882
31882
|
// src/protocol/eip712.ts
|
|
31883
31883
|
var DOMAIN_NAME = "Vana Data Portability";
|
|
31884
31884
|
var DOMAIN_VERSION = "1";
|
|
31885
|
+
var NATIVE_VANA_ASSET = "0x0000000000000000000000000000000000000000";
|
|
31885
31886
|
function buildDomain(chainId, verifyingContract) {
|
|
31886
31887
|
return {
|
|
31887
31888
|
name: DOMAIN_NAME,
|
|
@@ -31890,13 +31891,7 @@ function buildDomain(chainId, verifyingContract) {
|
|
|
31890
31891
|
verifyingContract
|
|
31891
31892
|
};
|
|
31892
31893
|
}
|
|
31893
|
-
function
|
|
31894
|
-
return buildDomain(
|
|
31895
|
-
config.chainId,
|
|
31896
|
-
config.contracts.dataRegistry
|
|
31897
|
-
);
|
|
31898
|
-
}
|
|
31899
|
-
function fileDeletionDomain(config) {
|
|
31894
|
+
function dataRegistryDomain(config) {
|
|
31900
31895
|
return buildDomain(
|
|
31901
31896
|
config.chainId,
|
|
31902
31897
|
config.contracts.dataRegistry
|
|
@@ -31926,31 +31921,26 @@ function builderRegistrationDomain(config) {
|
|
|
31926
31921
|
config.contracts.dataPortabilityGrantees
|
|
31927
31922
|
);
|
|
31928
31923
|
}
|
|
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
|
-
};
|
|
31924
|
+
function escrowPaymentDomain(config) {
|
|
31925
|
+
return buildDomain(
|
|
31926
|
+
config.chainId,
|
|
31927
|
+
config.contracts.dataPortabilityEscrow
|
|
31928
|
+
);
|
|
31929
|
+
}
|
|
31942
31930
|
var GRANT_REGISTRATION_TYPES = {
|
|
31943
31931
|
GrantRegistration: [
|
|
31944
31932
|
{ name: "grantorAddress", type: "address" },
|
|
31945
31933
|
{ name: "granteeId", type: "bytes32" },
|
|
31946
|
-
{ name: "
|
|
31947
|
-
{ name: "
|
|
31934
|
+
{ name: "scopes", type: "string[]" },
|
|
31935
|
+
{ name: "grantVersion", type: "uint256" },
|
|
31936
|
+
{ name: "expiresAt", type: "uint256" }
|
|
31948
31937
|
]
|
|
31949
31938
|
};
|
|
31950
31939
|
var GRANT_REVOCATION_TYPES = {
|
|
31951
31940
|
GrantRevocation: [
|
|
31952
31941
|
{ name: "grantorAddress", type: "address" },
|
|
31953
|
-
{ name: "grantId", type: "bytes32" }
|
|
31942
|
+
{ name: "grantId", type: "bytes32" },
|
|
31943
|
+
{ name: "grantVersion", type: "uint256" }
|
|
31954
31944
|
]
|
|
31955
31945
|
};
|
|
31956
31946
|
var SERVER_REGISTRATION_TYPES = {
|
|
@@ -31969,6 +31959,34 @@ var BUILDER_REGISTRATION_TYPES = {
|
|
|
31969
31959
|
{ name: "appUrl", type: "string" }
|
|
31970
31960
|
]
|
|
31971
31961
|
};
|
|
31962
|
+
var GENERIC_PAYMENT_TYPES = {
|
|
31963
|
+
GenericPayment: [
|
|
31964
|
+
{ name: "payerAddress", type: "address" },
|
|
31965
|
+
{ name: "opType", type: "string" },
|
|
31966
|
+
{ name: "opId", type: "bytes32" },
|
|
31967
|
+
{ name: "asset", type: "address" },
|
|
31968
|
+
{ name: "amount", type: "uint256" },
|
|
31969
|
+
{ name: "paymentNonce", type: "uint256" }
|
|
31970
|
+
]
|
|
31971
|
+
};
|
|
31972
|
+
var ADD_DATA_TYPES = {
|
|
31973
|
+
AddData: [
|
|
31974
|
+
{ name: "ownerAddress", type: "address" },
|
|
31975
|
+
{ name: "scope", type: "string" },
|
|
31976
|
+
{ name: "dataHash", type: "bytes32" },
|
|
31977
|
+
{ name: "metadataHash", type: "bytes32" },
|
|
31978
|
+
{ name: "expectedVersion", type: "uint256" }
|
|
31979
|
+
]
|
|
31980
|
+
};
|
|
31981
|
+
var RECORD_DATA_ACCESS_TYPES = {
|
|
31982
|
+
RecordDataAccess: [
|
|
31983
|
+
{ name: "ownerAddress", type: "address" },
|
|
31984
|
+
{ name: "scope", type: "string" },
|
|
31985
|
+
{ name: "version", type: "uint256" },
|
|
31986
|
+
{ name: "accessor", type: "address" },
|
|
31987
|
+
{ name: "recordId", type: "bytes32" }
|
|
31988
|
+
]
|
|
31989
|
+
};
|
|
31972
31990
|
|
|
31973
31991
|
// src/protocol/personal-server-registration.ts
|
|
31974
31992
|
import {
|
|
@@ -32410,67 +32428,34 @@ function isDataPortabilityGatewayConfig(value) {
|
|
|
32410
32428
|
return false;
|
|
32411
32429
|
}
|
|
32412
32430
|
const c = contracts;
|
|
32413
|
-
return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]);
|
|
32414
|
-
}
|
|
32415
|
-
function parseGrantRegistrationPayload(grant) {
|
|
32416
|
-
let parsed;
|
|
32417
|
-
try {
|
|
32418
|
-
parsed = JSON.parse(grant);
|
|
32419
|
-
} catch {
|
|
32420
|
-
return null;
|
|
32421
|
-
}
|
|
32422
|
-
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
32423
|
-
return null;
|
|
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
|
-
};
|
|
32431
|
+
return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]) && isHexString(c["dataPortabilityEscrow"]) && isHexString(c["feeRegistry"]);
|
|
32451
32432
|
}
|
|
32452
|
-
function
|
|
32433
|
+
function toUint256(value) {
|
|
32453
32434
|
try {
|
|
32454
|
-
|
|
32455
|
-
|
|
32456
|
-
|
|
32457
|
-
|
|
32458
|
-
|
|
32435
|
+
if (typeof value === "number" && !Number.isSafeInteger(value)) {
|
|
32436
|
+
return null;
|
|
32437
|
+
}
|
|
32438
|
+
const big = typeof value === "bigint" ? value : BigInt(value);
|
|
32439
|
+
if (big < 0n) return null;
|
|
32440
|
+
return big;
|
|
32459
32441
|
} catch {
|
|
32460
32442
|
return null;
|
|
32461
32443
|
}
|
|
32462
32444
|
}
|
|
32463
32445
|
async function verifyGrantRegistration(input) {
|
|
32464
|
-
|
|
32465
|
-
|
|
32466
|
-
return {
|
|
32467
|
-
valid: false,
|
|
32468
|
-
error: "Grant must be JSON with scopes and expiresAt"
|
|
32469
|
-
};
|
|
32446
|
+
if (!Array.isArray(input.scopes) || input.scopes.length === 0) {
|
|
32447
|
+
return { valid: false, error: "scopes must be a non-empty array" };
|
|
32470
32448
|
}
|
|
32471
|
-
|
|
32472
|
-
|
|
32473
|
-
|
|
32449
|
+
if (!input.scopes.every((scope) => typeof scope === "string")) {
|
|
32450
|
+
return { valid: false, error: "scopes must contain only strings" };
|
|
32451
|
+
}
|
|
32452
|
+
const grantVersion = toUint256(input.grantVersion);
|
|
32453
|
+
if (grantVersion === null || grantVersion < 1n) {
|
|
32454
|
+
return { valid: false, error: "grantVersion must be a uint256 >= 1" };
|
|
32455
|
+
}
|
|
32456
|
+
const expiresAt = toUint256(input.expiresAt);
|
|
32457
|
+
if (expiresAt === null) {
|
|
32458
|
+
return { valid: false, error: "expiresAt must be a non-negative uint256" };
|
|
32474
32459
|
}
|
|
32475
32460
|
let valid;
|
|
32476
32461
|
try {
|
|
@@ -32482,8 +32467,9 @@ async function verifyGrantRegistration(input) {
|
|
|
32482
32467
|
message: {
|
|
32483
32468
|
grantorAddress: input.grantorAddress,
|
|
32484
32469
|
granteeId: input.granteeId,
|
|
32485
|
-
|
|
32486
|
-
|
|
32470
|
+
scopes: input.scopes,
|
|
32471
|
+
grantVersion,
|
|
32472
|
+
expiresAt
|
|
32487
32473
|
},
|
|
32488
32474
|
signature: input.signature
|
|
32489
32475
|
});
|
|
@@ -32494,19 +32480,197 @@ async function verifyGrantRegistration(input) {
|
|
|
32494
32480
|
return { valid: false, error: "Grant signature does not match grantor" };
|
|
32495
32481
|
}
|
|
32496
32482
|
const nowSeconds = input.nowSeconds ?? Math.floor(Date.now() / 1e3);
|
|
32497
|
-
if (
|
|
32483
|
+
if (expiresAt > 0n && expiresAt < BigInt(nowSeconds)) {
|
|
32498
32484
|
return { valid: false, error: "Grant has expired" };
|
|
32499
32485
|
}
|
|
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
32486
|
return {
|
|
32504
32487
|
valid: true,
|
|
32505
32488
|
grantorAddress: input.grantorAddress,
|
|
32506
32489
|
granteeId: input.granteeId,
|
|
32507
|
-
|
|
32508
|
-
|
|
32509
|
-
|
|
32490
|
+
scopes: input.scopes,
|
|
32491
|
+
grantVersion: grantVersion.toString(),
|
|
32492
|
+
expiresAt: expiresAt.toString()
|
|
32493
|
+
};
|
|
32494
|
+
}
|
|
32495
|
+
|
|
32496
|
+
// src/protocol/escrow-deposit.ts
|
|
32497
|
+
import { encodeFunctionData } from "viem";
|
|
32498
|
+
var ESCROW_DEPOSIT_ABI = [
|
|
32499
|
+
{
|
|
32500
|
+
type: "function",
|
|
32501
|
+
name: "depositNative",
|
|
32502
|
+
stateMutability: "payable",
|
|
32503
|
+
inputs: [{ name: "account", type: "address" }],
|
|
32504
|
+
outputs: []
|
|
32505
|
+
},
|
|
32506
|
+
{
|
|
32507
|
+
type: "function",
|
|
32508
|
+
name: "depositToken",
|
|
32509
|
+
stateMutability: "nonpayable",
|
|
32510
|
+
inputs: [
|
|
32511
|
+
{ name: "account", type: "address" },
|
|
32512
|
+
{ name: "token", type: "address" },
|
|
32513
|
+
{ name: "amount", type: "uint256" }
|
|
32514
|
+
],
|
|
32515
|
+
outputs: []
|
|
32516
|
+
}
|
|
32517
|
+
];
|
|
32518
|
+
function escrowContractAddress(config) {
|
|
32519
|
+
return config.contracts.dataPortabilityEscrow;
|
|
32520
|
+
}
|
|
32521
|
+
function encodeDepositNativeData(input) {
|
|
32522
|
+
return encodeFunctionData({
|
|
32523
|
+
abi: ESCROW_DEPOSIT_ABI,
|
|
32524
|
+
functionName: "depositNative",
|
|
32525
|
+
args: [input.account]
|
|
32526
|
+
});
|
|
32527
|
+
}
|
|
32528
|
+
function encodeDepositTokenData(input) {
|
|
32529
|
+
return encodeFunctionData({
|
|
32530
|
+
abi: ESCROW_DEPOSIT_ABI,
|
|
32531
|
+
functionName: "depositToken",
|
|
32532
|
+
args: [input.account, input.token, input.amount]
|
|
32533
|
+
});
|
|
32534
|
+
}
|
|
32535
|
+
function buildDepositNativeRequest(config, input) {
|
|
32536
|
+
return {
|
|
32537
|
+
to: escrowContractAddress(config),
|
|
32538
|
+
data: encodeDepositNativeData({ account: input.account }),
|
|
32539
|
+
value: input.amount
|
|
32540
|
+
};
|
|
32541
|
+
}
|
|
32542
|
+
function buildDepositTokenRequest(config, input) {
|
|
32543
|
+
return {
|
|
32544
|
+
to: escrowContractAddress(config),
|
|
32545
|
+
data: encodeDepositTokenData(input)
|
|
32546
|
+
};
|
|
32547
|
+
}
|
|
32548
|
+
|
|
32549
|
+
// src/protocol/data-point-status.ts
|
|
32550
|
+
import { encodeFunctionData as encodeFunctionData2 } from "viem";
|
|
32551
|
+
var DataPointStatus = /* @__PURE__ */ ((DataPointStatus2) => {
|
|
32552
|
+
DataPointStatus2[DataPointStatus2["None"] = 0] = "None";
|
|
32553
|
+
DataPointStatus2[DataPointStatus2["Active"] = 1] = "Active";
|
|
32554
|
+
DataPointStatus2[DataPointStatus2["Inactive"] = 2] = "Inactive";
|
|
32555
|
+
DataPointStatus2[DataPointStatus2["Unavailable"] = 3] = "Unavailable";
|
|
32556
|
+
return DataPointStatus2;
|
|
32557
|
+
})(DataPointStatus || {});
|
|
32558
|
+
var DATA_REGISTRY_STATUS_ABI = [
|
|
32559
|
+
{
|
|
32560
|
+
type: "function",
|
|
32561
|
+
name: "setStatus",
|
|
32562
|
+
stateMutability: "nonpayable",
|
|
32563
|
+
inputs: [
|
|
32564
|
+
{ name: "scope", type: "string" },
|
|
32565
|
+
{ name: "newStatus", type: "uint8" }
|
|
32566
|
+
],
|
|
32567
|
+
outputs: []
|
|
32568
|
+
}
|
|
32569
|
+
];
|
|
32570
|
+
function dataRegistryContractAddress(config) {
|
|
32571
|
+
return config.contracts.dataRegistry;
|
|
32572
|
+
}
|
|
32573
|
+
function encodeSetDataPointStatusData(input) {
|
|
32574
|
+
return encodeFunctionData2({
|
|
32575
|
+
abi: DATA_REGISTRY_STATUS_ABI,
|
|
32576
|
+
functionName: "setStatus",
|
|
32577
|
+
args: [input.scope, input.status]
|
|
32578
|
+
});
|
|
32579
|
+
}
|
|
32580
|
+
function buildSetDataPointStatusRequest(config, input) {
|
|
32581
|
+
return {
|
|
32582
|
+
to: dataRegistryContractAddress(config),
|
|
32583
|
+
data: encodeSetDataPointStatusData(input)
|
|
32584
|
+
};
|
|
32585
|
+
}
|
|
32586
|
+
function buildMarkDataPointUnavailableRequest(config, input) {
|
|
32587
|
+
return buildSetDataPointStatusRequest(config, {
|
|
32588
|
+
scope: input.scope,
|
|
32589
|
+
status: 3 /* Unavailable */
|
|
32590
|
+
});
|
|
32591
|
+
}
|
|
32592
|
+
|
|
32593
|
+
// src/protocol/fee-registry.ts
|
|
32594
|
+
import { parseAbi } from "viem";
|
|
32595
|
+
var FEE_REGISTRY_ABI = parseAbi([
|
|
32596
|
+
"struct Fee { uint256 amount; address asset; address payee; bool enabled; }",
|
|
32597
|
+
"function fees(bytes32 operation) view returns (Fee)",
|
|
32598
|
+
"function operationKey(string name) pure returns (bytes32)"
|
|
32599
|
+
]);
|
|
32600
|
+
var REGISTRATION_KIND_FOR_OP = {
|
|
32601
|
+
grant: "grant_registration",
|
|
32602
|
+
data: "data_registration",
|
|
32603
|
+
server: "server_registration",
|
|
32604
|
+
builder: "builder_registration"
|
|
32605
|
+
};
|
|
32606
|
+
function operationNameFor(kind, opts) {
|
|
32607
|
+
switch (kind) {
|
|
32608
|
+
case "grant_registration":
|
|
32609
|
+
return opts?.grantRegistrationOpName ?? "grant_registration";
|
|
32610
|
+
case "data_access":
|
|
32611
|
+
return opts?.dataAccessOpName ?? "data_access";
|
|
32612
|
+
case "data_registration":
|
|
32613
|
+
return opts?.dataRegistrationOpName ?? "data_registration";
|
|
32614
|
+
case "server_registration":
|
|
32615
|
+
return opts?.serverRegistrationOpName ?? "server_registration";
|
|
32616
|
+
case "builder_registration":
|
|
32617
|
+
return opts?.builderRegistrationOpName ?? "builder_registration";
|
|
32618
|
+
}
|
|
32619
|
+
}
|
|
32620
|
+
var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
32621
|
+
async function getFee(client, config, kind, opts) {
|
|
32622
|
+
const address = config.contracts.feeRegistry;
|
|
32623
|
+
const opName = operationNameFor(kind, opts);
|
|
32624
|
+
const opKey = await client.readContract({
|
|
32625
|
+
address,
|
|
32626
|
+
abi: FEE_REGISTRY_ABI,
|
|
32627
|
+
functionName: "operationKey",
|
|
32628
|
+
args: [opName]
|
|
32629
|
+
});
|
|
32630
|
+
const fee = await client.readContract({
|
|
32631
|
+
address,
|
|
32632
|
+
abi: FEE_REGISTRY_ABI,
|
|
32633
|
+
functionName: "fees",
|
|
32634
|
+
args: [opKey]
|
|
32635
|
+
});
|
|
32636
|
+
if (fee.enabled && fee.payee === ZERO_ADDRESS) {
|
|
32637
|
+
throw new Error(
|
|
32638
|
+
`FeeRegistry: enabled operation "${opName}" has zero-address payee \u2014 contract pre-flight rejects payouts to 0x0`
|
|
32639
|
+
);
|
|
32640
|
+
}
|
|
32641
|
+
return fee;
|
|
32642
|
+
}
|
|
32643
|
+
async function getOpFee(client, config, opType, opts) {
|
|
32644
|
+
const registrationKind = REGISTRATION_KIND_FOR_OP[opType];
|
|
32645
|
+
if (!registrationKind) {
|
|
32646
|
+
throw new Error(
|
|
32647
|
+
`getOpFee: unknown opType "${opType}" \u2014 supported types are ${Object.keys(REGISTRATION_KIND_FOR_OP).join(", ")}`
|
|
32648
|
+
);
|
|
32649
|
+
}
|
|
32650
|
+
const includeDataAccess = opType === "grant";
|
|
32651
|
+
const [registration, dataAccess] = await Promise.all([
|
|
32652
|
+
getFee(client, config, registrationKind, opts),
|
|
32653
|
+
includeDataAccess ? getFee(client, config, "data_access", opts) : Promise.resolve({
|
|
32654
|
+
amount: 0n,
|
|
32655
|
+
asset: ZERO_ADDRESS,
|
|
32656
|
+
payee: ZERO_ADDRESS,
|
|
32657
|
+
enabled: false
|
|
32658
|
+
})
|
|
32659
|
+
]);
|
|
32660
|
+
if (registration.enabled && dataAccess.enabled && registration.asset.toLowerCase() !== dataAccess.asset.toLowerCase()) {
|
|
32661
|
+
throw new Error(
|
|
32662
|
+
`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.`
|
|
32663
|
+
);
|
|
32664
|
+
}
|
|
32665
|
+
const asset = registration.enabled ? registration.asset : dataAccess.enabled ? dataAccess.asset : ZERO_ADDRESS;
|
|
32666
|
+
return {
|
|
32667
|
+
asset,
|
|
32668
|
+
registrationFee: registration.enabled ? registration.amount : 0n,
|
|
32669
|
+
dataAccessFee: dataAccess.enabled ? dataAccess.amount : 0n,
|
|
32670
|
+
registrationEnabled: registration.enabled,
|
|
32671
|
+
dataAccessEnabled: dataAccess.enabled,
|
|
32672
|
+
registrationPayee: registration.enabled ? registration.payee : ZERO_ADDRESS,
|
|
32673
|
+
dataAccessPayee: dataAccess.enabled ? dataAccess.payee : ZERO_ADDRESS
|
|
32510
32674
|
};
|
|
32511
32675
|
}
|
|
32512
32676
|
|
|
@@ -32580,6 +32744,45 @@ var IngestResponseSchema = z2.object({
|
|
|
32580
32744
|
status: z2.enum(["stored", "syncing"])
|
|
32581
32745
|
});
|
|
32582
32746
|
|
|
32747
|
+
// src/protocol/personal-server-data.ts
|
|
32748
|
+
function personalServerDataReadPath(scope) {
|
|
32749
|
+
return `/v1/data/${encodeURIComponent(scope)}`;
|
|
32750
|
+
}
|
|
32751
|
+
async function buildPersonalServerDataReadRequest(params) {
|
|
32752
|
+
const path = personalServerDataReadPath(params.scope);
|
|
32753
|
+
const baseUrl = params.personalServerUrl.replace(/\/+$/, "");
|
|
32754
|
+
const audience = params.audience ?? baseUrl;
|
|
32755
|
+
const headers = new Headers(params.headers);
|
|
32756
|
+
headers.set(
|
|
32757
|
+
"Authorization",
|
|
32758
|
+
await buildWeb3SignedHeader({
|
|
32759
|
+
aud: audience,
|
|
32760
|
+
grantId: params.grantId,
|
|
32761
|
+
method: "GET",
|
|
32762
|
+
signMessage: params.signMessage,
|
|
32763
|
+
uri: path
|
|
32764
|
+
})
|
|
32765
|
+
);
|
|
32766
|
+
return new Request(`${baseUrl}${path}`, {
|
|
32767
|
+
headers,
|
|
32768
|
+
method: "GET"
|
|
32769
|
+
});
|
|
32770
|
+
}
|
|
32771
|
+
async function readPersonalServerData(params) {
|
|
32772
|
+
const fetchFn = params.fetch ?? globalThis.fetch;
|
|
32773
|
+
if (fetchFn === void 0) {
|
|
32774
|
+
throw new Error("No fetch implementation available");
|
|
32775
|
+
}
|
|
32776
|
+
const request = await buildPersonalServerDataReadRequest(params);
|
|
32777
|
+
const response = await fetchFn(request);
|
|
32778
|
+
if (!response.ok) {
|
|
32779
|
+
throw new Error(
|
|
32780
|
+
`Personal Server data read failed: ${response.status} ${response.statusText}`
|
|
32781
|
+
);
|
|
32782
|
+
}
|
|
32783
|
+
return DataFileEnvelopeSchema.parse(await response.json());
|
|
32784
|
+
}
|
|
32785
|
+
|
|
32583
32786
|
// src/protocol/gateway.ts
|
|
32584
32787
|
function createGatewayClient(baseUrl) {
|
|
32585
32788
|
const base = baseUrl.replace(/\/+$/, "");
|
|
@@ -32587,16 +32790,6 @@ function createGatewayClient(baseUrl) {
|
|
|
32587
32790
|
const envelope = await res.json();
|
|
32588
32791
|
return envelope.data;
|
|
32589
32792
|
}
|
|
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
32793
|
function getMutationId(body, key) {
|
|
32601
32794
|
const value = body[key] ?? body["id"];
|
|
32602
32795
|
return typeof value === "string" ? value : void 0;
|
|
@@ -32646,30 +32839,34 @@ function createGatewayClient(baseUrl) {
|
|
|
32646
32839
|
}
|
|
32647
32840
|
return unwrapEnvelope(res);
|
|
32648
32841
|
},
|
|
32649
|
-
async
|
|
32650
|
-
const res = await fetch(`${base}/v1/
|
|
32842
|
+
async getDataPoint(dataPointId) {
|
|
32843
|
+
const res = await fetch(`${base}/v1/data/${dataPointId}`);
|
|
32651
32844
|
if (res.status === 404) return null;
|
|
32652
32845
|
if (!res.ok) {
|
|
32653
32846
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
32654
32847
|
}
|
|
32655
|
-
return
|
|
32848
|
+
return unwrapEnvelope(res);
|
|
32656
32849
|
},
|
|
32657
|
-
async
|
|
32850
|
+
async listDataPointsByOwner(owner, cursor, options) {
|
|
32658
32851
|
const params = new URLSearchParams({ user: owner });
|
|
32659
32852
|
if (cursor !== null) {
|
|
32660
|
-
params.set("
|
|
32853
|
+
params.set("cursor", cursor);
|
|
32661
32854
|
}
|
|
32662
|
-
if (options?.
|
|
32663
|
-
params.set("
|
|
32855
|
+
if (options?.since) {
|
|
32856
|
+
params.set("since", options.since);
|
|
32664
32857
|
}
|
|
32665
|
-
|
|
32858
|
+
if (options?.limit !== void 0) {
|
|
32859
|
+
params.set("limit", String(options.limit));
|
|
32860
|
+
}
|
|
32861
|
+
const res = await fetch(`${base}/v1/data?${params.toString()}`);
|
|
32666
32862
|
if (!res.ok) {
|
|
32667
32863
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
32668
32864
|
}
|
|
32669
|
-
const
|
|
32865
|
+
const envelope = await res.json();
|
|
32866
|
+
const nextCursor = envelope.pagination?.hasMore === false ? null : envelope.pagination?.nextCursor ?? null;
|
|
32670
32867
|
return {
|
|
32671
|
-
|
|
32672
|
-
cursor:
|
|
32868
|
+
dataPoints: envelope.data.dataPoints,
|
|
32869
|
+
cursor: nextCursor
|
|
32673
32870
|
};
|
|
32674
32871
|
},
|
|
32675
32872
|
async getSchema(schemaId) {
|
|
@@ -32710,8 +32907,8 @@ function createGatewayClient(baseUrl) {
|
|
|
32710
32907
|
alreadyRegistered: false
|
|
32711
32908
|
};
|
|
32712
32909
|
},
|
|
32713
|
-
async
|
|
32714
|
-
const res = await fetch(`${base}/v1/
|
|
32910
|
+
async registerBuilder(params) {
|
|
32911
|
+
const res = await fetch(`${base}/v1/builders`, {
|
|
32715
32912
|
method: "POST",
|
|
32716
32913
|
headers: {
|
|
32717
32914
|
"Content-Type": "application/json",
|
|
@@ -32719,22 +32916,57 @@ function createGatewayClient(baseUrl) {
|
|
|
32719
32916
|
},
|
|
32720
32917
|
body: JSON.stringify({
|
|
32721
32918
|
ownerAddress: params.ownerAddress,
|
|
32722
|
-
|
|
32723
|
-
|
|
32919
|
+
granteeAddress: params.granteeAddress,
|
|
32920
|
+
publicKey: params.publicKey,
|
|
32921
|
+
appUrl: params.appUrl
|
|
32724
32922
|
})
|
|
32725
32923
|
});
|
|
32726
32924
|
if (res.status === 409) {
|
|
32727
32925
|
const body2 = await res.json().catch(() => ({}));
|
|
32728
32926
|
return {
|
|
32729
|
-
|
|
32927
|
+
builderId: getMutationId(
|
|
32928
|
+
body2,
|
|
32929
|
+
"builderId"
|
|
32930
|
+
),
|
|
32931
|
+
alreadyRegistered: true
|
|
32730
32932
|
};
|
|
32731
32933
|
}
|
|
32732
32934
|
if (!res.ok) {
|
|
32733
32935
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
32734
32936
|
}
|
|
32735
|
-
const body = await res.json();
|
|
32937
|
+
const body = await res.json().catch(() => ({}));
|
|
32938
|
+
return {
|
|
32939
|
+
builderId: getMutationId(body, "builderId"),
|
|
32940
|
+
alreadyRegistered: false
|
|
32941
|
+
};
|
|
32942
|
+
},
|
|
32943
|
+
async registerDataPoint(params) {
|
|
32944
|
+
const res = await fetch(`${base}/v1/data`, {
|
|
32945
|
+
method: "POST",
|
|
32946
|
+
headers: {
|
|
32947
|
+
"Content-Type": "application/json",
|
|
32948
|
+
Authorization: `Web3Signed ${params.signature}`
|
|
32949
|
+
},
|
|
32950
|
+
body: JSON.stringify({
|
|
32951
|
+
ownerAddress: params.ownerAddress,
|
|
32952
|
+
scope: params.scope,
|
|
32953
|
+
dataHash: params.dataHash,
|
|
32954
|
+
metadataHash: params.metadataHash,
|
|
32955
|
+
expectedVersion: params.expectedVersion
|
|
32956
|
+
})
|
|
32957
|
+
});
|
|
32958
|
+
if (!res.ok) {
|
|
32959
|
+
const body2 = await res.json().catch(() => ({}));
|
|
32960
|
+
const detail = body2.error ?? res.statusText;
|
|
32961
|
+
throw new Error(`Gateway error: ${res.status} ${detail}`);
|
|
32962
|
+
}
|
|
32963
|
+
const body = await res.json().catch(() => ({}));
|
|
32736
32964
|
return {
|
|
32737
|
-
|
|
32965
|
+
dataPointId: getMutationId(
|
|
32966
|
+
body,
|
|
32967
|
+
"dataPointId"
|
|
32968
|
+
),
|
|
32969
|
+
expectedVersion: body.expectedVersion
|
|
32738
32970
|
};
|
|
32739
32971
|
},
|
|
32740
32972
|
async createGrant(params) {
|
|
@@ -32747,8 +32979,9 @@ function createGatewayClient(baseUrl) {
|
|
|
32747
32979
|
body: JSON.stringify({
|
|
32748
32980
|
grantorAddress: params.grantorAddress,
|
|
32749
32981
|
granteeId: params.granteeId,
|
|
32750
|
-
|
|
32751
|
-
|
|
32982
|
+
scopes: params.scopes,
|
|
32983
|
+
grantVersion: params.grantVersion,
|
|
32984
|
+
expiresAt: params.expiresAt
|
|
32752
32985
|
})
|
|
32753
32986
|
});
|
|
32754
32987
|
if (res.status === 409) {
|
|
@@ -32773,7 +33006,8 @@ function createGatewayClient(baseUrl) {
|
|
|
32773
33006
|
Authorization: `Web3Signed ${params.signature}`
|
|
32774
33007
|
},
|
|
32775
33008
|
body: JSON.stringify({
|
|
32776
|
-
grantorAddress: params.grantorAddress
|
|
33009
|
+
grantorAddress: params.grantorAddress,
|
|
33010
|
+
grantVersion: params.grantVersion
|
|
32777
33011
|
})
|
|
32778
33012
|
});
|
|
32779
33013
|
if (res.status === 409) return;
|
|
@@ -32781,21 +33015,62 @@ function createGatewayClient(baseUrl) {
|
|
|
32781
33015
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
32782
33016
|
}
|
|
32783
33017
|
},
|
|
32784
|
-
async
|
|
32785
|
-
const res = await fetch(`${base}/v1/
|
|
32786
|
-
|
|
33018
|
+
async getEscrowBalance(account) {
|
|
33019
|
+
const res = await fetch(`${base}/v1/escrow/balance?account=${account}`);
|
|
33020
|
+
if (!res.ok) {
|
|
33021
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33022
|
+
}
|
|
33023
|
+
return await res.json();
|
|
33024
|
+
},
|
|
33025
|
+
async submitEscrowDeposit(params) {
|
|
33026
|
+
const res = await fetch(`${base}/v1/escrow/deposit`, {
|
|
33027
|
+
method: "POST",
|
|
33028
|
+
headers: { "Content-Type": "application/json" },
|
|
33029
|
+
body: JSON.stringify({ txHash: params.txHash })
|
|
33030
|
+
});
|
|
33031
|
+
if (res.status !== 200 && res.status !== 202) {
|
|
33032
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33033
|
+
}
|
|
33034
|
+
return await res.json();
|
|
33035
|
+
},
|
|
33036
|
+
async payForOperation(params) {
|
|
33037
|
+
const body = {
|
|
33038
|
+
payerAddress: params.payerAddress,
|
|
33039
|
+
opType: params.opType,
|
|
33040
|
+
opId: params.opId,
|
|
33041
|
+
asset: params.asset,
|
|
33042
|
+
amount: params.amount,
|
|
33043
|
+
paymentNonce: params.paymentNonce
|
|
33044
|
+
};
|
|
33045
|
+
if (params.accessRecord) {
|
|
33046
|
+
body["accessRecord"] = params.accessRecord;
|
|
33047
|
+
}
|
|
33048
|
+
const res = await fetch(`${base}/v1/escrow/pay`, {
|
|
33049
|
+
method: "POST",
|
|
32787
33050
|
headers: {
|
|
32788
33051
|
"Content-Type": "application/json",
|
|
32789
33052
|
Authorization: `Web3Signed ${params.signature}`
|
|
32790
33053
|
},
|
|
32791
|
-
body: JSON.stringify(
|
|
32792
|
-
|
|
32793
|
-
|
|
33054
|
+
body: JSON.stringify(body)
|
|
33055
|
+
});
|
|
33056
|
+
if (!res.ok) {
|
|
33057
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33058
|
+
}
|
|
33059
|
+
return await res.json();
|
|
33060
|
+
},
|
|
33061
|
+
async settle(params) {
|
|
33062
|
+
const res = await fetch(`${base}/v1/settle`, {
|
|
33063
|
+
method: "POST",
|
|
33064
|
+
headers: { "Content-Type": "application/json" },
|
|
33065
|
+
// The gateway accepts an empty body; only `limit` is recognised.
|
|
33066
|
+
// Always send a JSON body so the gateway's req.body shape parse
|
|
33067
|
+
// doesn't have to deal with an undefined.
|
|
33068
|
+
body: JSON.stringify(params ?? {})
|
|
32794
33069
|
});
|
|
32795
|
-
if (res.status === 409) return;
|
|
32796
33070
|
if (!res.ok) {
|
|
32797
33071
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
32798
33072
|
}
|
|
33073
|
+
return await res.json();
|
|
32799
33074
|
}
|
|
32800
33075
|
};
|
|
32801
33076
|
}
|
|
@@ -32864,6 +33139,7 @@ async function parsePSError(response) {
|
|
|
32864
33139
|
}
|
|
32865
33140
|
export {
|
|
32866
33141
|
ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
|
|
33142
|
+
ADD_DATA_TYPES,
|
|
32867
33143
|
AccountPersonalServerLiteOwnerBindingError,
|
|
32868
33144
|
AccountPersonalServerRegistrationError,
|
|
32869
33145
|
BUILDER_REGISTRATION_TYPES,
|
|
@@ -32874,12 +33150,15 @@ export {
|
|
|
32874
33150
|
CallbackStorage,
|
|
32875
33151
|
ContractFactory,
|
|
32876
33152
|
ContractNotFoundError,
|
|
33153
|
+
DATA_REGISTRY_STATUS_ABI,
|
|
32877
33154
|
DataFileEnvelopeSchema,
|
|
33155
|
+
DataPointStatus,
|
|
32878
33156
|
DropboxStorage,
|
|
32879
33157
|
ECIESError,
|
|
33158
|
+
ESCROW_DEPOSIT_ABI,
|
|
32880
33159
|
ExpiredTokenError,
|
|
32881
|
-
|
|
32882
|
-
|
|
33160
|
+
FEE_REGISTRY_ABI,
|
|
33161
|
+
GENERIC_PAYMENT_TYPES,
|
|
32883
33162
|
GRANT_REGISTRATION_TYPES,
|
|
32884
33163
|
GRANT_REVOCATION_TYPES,
|
|
32885
33164
|
GoogleDriveStorage,
|
|
@@ -32890,6 +33169,7 @@ export {
|
|
|
32890
33169
|
IpfsStorage,
|
|
32891
33170
|
MASTER_KEY_MESSAGE,
|
|
32892
33171
|
MissingAuthError,
|
|
33172
|
+
NATIVE_VANA_ASSET,
|
|
32893
33173
|
NetworkError,
|
|
32894
33174
|
NonceError,
|
|
32895
33175
|
OAuthClient,
|
|
@@ -32905,6 +33185,8 @@ export {
|
|
|
32905
33185
|
PersonalServerError,
|
|
32906
33186
|
PinataStorage,
|
|
32907
33187
|
R2Storage,
|
|
33188
|
+
RECORD_DATA_ACCESS_TYPES,
|
|
33189
|
+
REGISTRATION_KIND_FOR_OP,
|
|
32908
33190
|
ReadOnlyError,
|
|
32909
33191
|
RelayerError,
|
|
32910
33192
|
SERVER_REGISTRATION_TYPES,
|
|
@@ -32919,10 +33201,15 @@ export {
|
|
|
32919
33201
|
VanaError,
|
|
32920
33202
|
VanaStorage,
|
|
32921
33203
|
assertValidPkceVerifier,
|
|
33204
|
+
buildDepositNativeRequest,
|
|
33205
|
+
buildDepositTokenRequest,
|
|
33206
|
+
buildMarkDataPointUnavailableRequest,
|
|
33207
|
+
buildPersonalServerDataReadRequest,
|
|
32922
33208
|
buildPersonalServerLiteOwnerBindingMessage,
|
|
32923
33209
|
buildPersonalServerLiteOwnerBindingSignature,
|
|
32924
33210
|
buildPersonalServerRegistrationSignature,
|
|
32925
33211
|
buildPersonalServerRegistrationTypedData,
|
|
33212
|
+
buildSetDataPointStatusRequest,
|
|
32926
33213
|
buildWeb3SignedHeader,
|
|
32927
33214
|
builderRegistrationDomain,
|
|
32928
33215
|
chains,
|
|
@@ -32937,14 +33224,19 @@ export {
|
|
|
32937
33224
|
createVanaStorageProvider,
|
|
32938
33225
|
createViemPersonalServerLiteOwnerBindingSigner,
|
|
32939
33226
|
createViemPersonalServerRegistrationSigner,
|
|
33227
|
+
dataRegistryContractAddress,
|
|
33228
|
+
dataRegistryDomain,
|
|
32940
33229
|
decryptWithPassword,
|
|
32941
33230
|
deriveMasterKey,
|
|
32942
33231
|
deriveScopeKey,
|
|
32943
33232
|
deserializeECIES,
|
|
32944
33233
|
detectPlatform,
|
|
33234
|
+
encodeDepositNativeData,
|
|
33235
|
+
encodeDepositTokenData,
|
|
33236
|
+
encodeSetDataPointStatusData,
|
|
32945
33237
|
encryptWithPassword,
|
|
32946
|
-
|
|
32947
|
-
|
|
33238
|
+
escrowContractAddress,
|
|
33239
|
+
escrowPaymentDomain,
|
|
32948
33240
|
generatePkceVerifier,
|
|
32949
33241
|
getAbi,
|
|
32950
33242
|
getAllChains,
|
|
@@ -32952,6 +33244,8 @@ export {
|
|
|
32952
33244
|
getContractAddress,
|
|
32953
33245
|
getContractController,
|
|
32954
33246
|
getContractInfo,
|
|
33247
|
+
getFee,
|
|
33248
|
+
getOpFee,
|
|
32955
33249
|
getPlatformCapabilities,
|
|
32956
33250
|
getServiceEndpoints,
|
|
32957
33251
|
grantRegistrationDomain,
|
|
@@ -32963,11 +33257,12 @@ export {
|
|
|
32963
33257
|
moksha,
|
|
32964
33258
|
mokshaServices,
|
|
32965
33259
|
mokshaTestnet2 as mokshaTestnet,
|
|
32966
|
-
parseGrantRegistrationPayload,
|
|
32967
33260
|
parsePSError,
|
|
32968
33261
|
parseScope,
|
|
32969
33262
|
parseWeb3SignedHeader,
|
|
33263
|
+
personalServerDataReadPath,
|
|
32970
33264
|
personalServerRegistrationDomain,
|
|
33265
|
+
readPersonalServerData,
|
|
32971
33266
|
recoverServerOwner,
|
|
32972
33267
|
registerPersonalServerSignature,
|
|
32973
33268
|
scopeCoveredByGrant,
|