@opendatalabs/vana-sdk 3.3.0 → 3.4.1-canary.3957547
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 +424 -125
- package/dist/index.browser.js.map +4 -4
- package/dist/index.node.cjs +449 -130
- package/dist/index.node.cjs.map +4 -4
- package/dist/index.node.d.ts +7 -3
- package/dist/index.node.js +424 -125
- 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 +111 -35
- package/dist/protocol/gateway.cjs.map +1 -1
- package/dist/protocol/gateway.d.ts +240 -45
- package/dist/protocol/gateway.js +111 -35
- 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,15 +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
|
-
};
|
|
32598
|
-
}
|
|
32599
32793
|
function getMutationId(body, key) {
|
|
32600
32794
|
const value = body[key] ?? body["id"];
|
|
32601
32795
|
return typeof value === "string" ? value : void 0;
|
|
@@ -32645,27 +32839,34 @@ function createGatewayClient(baseUrl) {
|
|
|
32645
32839
|
}
|
|
32646
32840
|
return unwrapEnvelope(res);
|
|
32647
32841
|
},
|
|
32648
|
-
async
|
|
32649
|
-
const res = await fetch(`${base}/v1/
|
|
32842
|
+
async getDataPoint(dataPointId) {
|
|
32843
|
+
const res = await fetch(`${base}/v1/data/${dataPointId}`);
|
|
32650
32844
|
if (res.status === 404) return null;
|
|
32651
32845
|
if (!res.ok) {
|
|
32652
32846
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
32653
32847
|
}
|
|
32654
|
-
return
|
|
32848
|
+
return unwrapEnvelope(res);
|
|
32655
32849
|
},
|
|
32656
|
-
async
|
|
32850
|
+
async listDataPointsByOwner(owner, cursor, options) {
|
|
32657
32851
|
const params = new URLSearchParams({ user: owner });
|
|
32658
32852
|
if (cursor !== null) {
|
|
32659
|
-
params.set("
|
|
32853
|
+
params.set("cursor", cursor);
|
|
32854
|
+
}
|
|
32855
|
+
if (options?.since) {
|
|
32856
|
+
params.set("since", options.since);
|
|
32660
32857
|
}
|
|
32661
|
-
|
|
32858
|
+
if (options?.limit !== void 0) {
|
|
32859
|
+
params.set("limit", String(options.limit));
|
|
32860
|
+
}
|
|
32861
|
+
const res = await fetch(`${base}/v1/data?${params.toString()}`);
|
|
32662
32862
|
if (!res.ok) {
|
|
32663
32863
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
32664
32864
|
}
|
|
32665
|
-
const
|
|
32865
|
+
const envelope = await res.json();
|
|
32866
|
+
const nextCursor = envelope.pagination?.hasMore === false ? null : envelope.pagination?.nextCursor ?? null;
|
|
32666
32867
|
return {
|
|
32667
|
-
|
|
32668
|
-
cursor:
|
|
32868
|
+
dataPoints: envelope.data.dataPoints,
|
|
32869
|
+
cursor: nextCursor
|
|
32669
32870
|
};
|
|
32670
32871
|
},
|
|
32671
32872
|
async getSchema(schemaId) {
|
|
@@ -32706,8 +32907,8 @@ function createGatewayClient(baseUrl) {
|
|
|
32706
32907
|
alreadyRegistered: false
|
|
32707
32908
|
};
|
|
32708
32909
|
},
|
|
32709
|
-
async
|
|
32710
|
-
const res = await fetch(`${base}/v1/
|
|
32910
|
+
async registerBuilder(params) {
|
|
32911
|
+
const res = await fetch(`${base}/v1/builders`, {
|
|
32711
32912
|
method: "POST",
|
|
32712
32913
|
headers: {
|
|
32713
32914
|
"Content-Type": "application/json",
|
|
@@ -32715,22 +32916,57 @@ function createGatewayClient(baseUrl) {
|
|
|
32715
32916
|
},
|
|
32716
32917
|
body: JSON.stringify({
|
|
32717
32918
|
ownerAddress: params.ownerAddress,
|
|
32718
|
-
|
|
32719
|
-
|
|
32919
|
+
granteeAddress: params.granteeAddress,
|
|
32920
|
+
publicKey: params.publicKey,
|
|
32921
|
+
appUrl: params.appUrl
|
|
32720
32922
|
})
|
|
32721
32923
|
});
|
|
32722
32924
|
if (res.status === 409) {
|
|
32723
32925
|
const body2 = await res.json().catch(() => ({}));
|
|
32724
32926
|
return {
|
|
32725
|
-
|
|
32927
|
+
builderId: getMutationId(
|
|
32928
|
+
body2,
|
|
32929
|
+
"builderId"
|
|
32930
|
+
),
|
|
32931
|
+
alreadyRegistered: true
|
|
32726
32932
|
};
|
|
32727
32933
|
}
|
|
32728
32934
|
if (!res.ok) {
|
|
32729
32935
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
32730
32936
|
}
|
|
32731
|
-
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(() => ({}));
|
|
32732
32964
|
return {
|
|
32733
|
-
|
|
32965
|
+
dataPointId: getMutationId(
|
|
32966
|
+
body,
|
|
32967
|
+
"dataPointId"
|
|
32968
|
+
),
|
|
32969
|
+
expectedVersion: body.expectedVersion
|
|
32734
32970
|
};
|
|
32735
32971
|
},
|
|
32736
32972
|
async createGrant(params) {
|
|
@@ -32743,8 +32979,9 @@ function createGatewayClient(baseUrl) {
|
|
|
32743
32979
|
body: JSON.stringify({
|
|
32744
32980
|
grantorAddress: params.grantorAddress,
|
|
32745
32981
|
granteeId: params.granteeId,
|
|
32746
|
-
|
|
32747
|
-
|
|
32982
|
+
scopes: params.scopes,
|
|
32983
|
+
grantVersion: params.grantVersion,
|
|
32984
|
+
expiresAt: params.expiresAt
|
|
32748
32985
|
})
|
|
32749
32986
|
});
|
|
32750
32987
|
if (res.status === 409) {
|
|
@@ -32769,7 +33006,8 @@ function createGatewayClient(baseUrl) {
|
|
|
32769
33006
|
Authorization: `Web3Signed ${params.signature}`
|
|
32770
33007
|
},
|
|
32771
33008
|
body: JSON.stringify({
|
|
32772
|
-
grantorAddress: params.grantorAddress
|
|
33009
|
+
grantorAddress: params.grantorAddress,
|
|
33010
|
+
grantVersion: params.grantVersion
|
|
32773
33011
|
})
|
|
32774
33012
|
});
|
|
32775
33013
|
if (res.status === 409) return;
|
|
@@ -32777,21 +33015,62 @@ function createGatewayClient(baseUrl) {
|
|
|
32777
33015
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
32778
33016
|
}
|
|
32779
33017
|
},
|
|
32780
|
-
async
|
|
32781
|
-
const res = await fetch(`${base}/v1/
|
|
32782
|
-
|
|
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",
|
|
32783
33050
|
headers: {
|
|
32784
33051
|
"Content-Type": "application/json",
|
|
32785
33052
|
Authorization: `Web3Signed ${params.signature}`
|
|
32786
33053
|
},
|
|
32787
|
-
body: JSON.stringify(
|
|
32788
|
-
|
|
32789
|
-
|
|
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 ?? {})
|
|
32790
33069
|
});
|
|
32791
|
-
if (res.status === 409) return;
|
|
32792
33070
|
if (!res.ok) {
|
|
32793
33071
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
32794
33072
|
}
|
|
33073
|
+
return await res.json();
|
|
32795
33074
|
}
|
|
32796
33075
|
};
|
|
32797
33076
|
}
|
|
@@ -32860,6 +33139,7 @@ async function parsePSError(response) {
|
|
|
32860
33139
|
}
|
|
32861
33140
|
export {
|
|
32862
33141
|
ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
|
|
33142
|
+
ADD_DATA_TYPES,
|
|
32863
33143
|
AccountPersonalServerLiteOwnerBindingError,
|
|
32864
33144
|
AccountPersonalServerRegistrationError,
|
|
32865
33145
|
BUILDER_REGISTRATION_TYPES,
|
|
@@ -32870,12 +33150,15 @@ export {
|
|
|
32870
33150
|
CallbackStorage,
|
|
32871
33151
|
ContractFactory,
|
|
32872
33152
|
ContractNotFoundError,
|
|
33153
|
+
DATA_REGISTRY_STATUS_ABI,
|
|
32873
33154
|
DataFileEnvelopeSchema,
|
|
33155
|
+
DataPointStatus,
|
|
32874
33156
|
DropboxStorage,
|
|
32875
33157
|
ECIESError,
|
|
33158
|
+
ESCROW_DEPOSIT_ABI,
|
|
32876
33159
|
ExpiredTokenError,
|
|
32877
|
-
|
|
32878
|
-
|
|
33160
|
+
FEE_REGISTRY_ABI,
|
|
33161
|
+
GENERIC_PAYMENT_TYPES,
|
|
32879
33162
|
GRANT_REGISTRATION_TYPES,
|
|
32880
33163
|
GRANT_REVOCATION_TYPES,
|
|
32881
33164
|
GoogleDriveStorage,
|
|
@@ -32886,6 +33169,7 @@ export {
|
|
|
32886
33169
|
IpfsStorage,
|
|
32887
33170
|
MASTER_KEY_MESSAGE,
|
|
32888
33171
|
MissingAuthError,
|
|
33172
|
+
NATIVE_VANA_ASSET,
|
|
32889
33173
|
NetworkError,
|
|
32890
33174
|
NonceError,
|
|
32891
33175
|
OAuthClient,
|
|
@@ -32901,6 +33185,8 @@ export {
|
|
|
32901
33185
|
PersonalServerError,
|
|
32902
33186
|
PinataStorage,
|
|
32903
33187
|
R2Storage,
|
|
33188
|
+
RECORD_DATA_ACCESS_TYPES,
|
|
33189
|
+
REGISTRATION_KIND_FOR_OP,
|
|
32904
33190
|
ReadOnlyError,
|
|
32905
33191
|
RelayerError,
|
|
32906
33192
|
SERVER_REGISTRATION_TYPES,
|
|
@@ -32915,10 +33201,15 @@ export {
|
|
|
32915
33201
|
VanaError,
|
|
32916
33202
|
VanaStorage,
|
|
32917
33203
|
assertValidPkceVerifier,
|
|
33204
|
+
buildDepositNativeRequest,
|
|
33205
|
+
buildDepositTokenRequest,
|
|
33206
|
+
buildMarkDataPointUnavailableRequest,
|
|
33207
|
+
buildPersonalServerDataReadRequest,
|
|
32918
33208
|
buildPersonalServerLiteOwnerBindingMessage,
|
|
32919
33209
|
buildPersonalServerLiteOwnerBindingSignature,
|
|
32920
33210
|
buildPersonalServerRegistrationSignature,
|
|
32921
33211
|
buildPersonalServerRegistrationTypedData,
|
|
33212
|
+
buildSetDataPointStatusRequest,
|
|
32922
33213
|
buildWeb3SignedHeader,
|
|
32923
33214
|
builderRegistrationDomain,
|
|
32924
33215
|
chains,
|
|
@@ -32933,14 +33224,19 @@ export {
|
|
|
32933
33224
|
createVanaStorageProvider,
|
|
32934
33225
|
createViemPersonalServerLiteOwnerBindingSigner,
|
|
32935
33226
|
createViemPersonalServerRegistrationSigner,
|
|
33227
|
+
dataRegistryContractAddress,
|
|
33228
|
+
dataRegistryDomain,
|
|
32936
33229
|
decryptWithPassword,
|
|
32937
33230
|
deriveMasterKey,
|
|
32938
33231
|
deriveScopeKey,
|
|
32939
33232
|
deserializeECIES,
|
|
32940
33233
|
detectPlatform,
|
|
33234
|
+
encodeDepositNativeData,
|
|
33235
|
+
encodeDepositTokenData,
|
|
33236
|
+
encodeSetDataPointStatusData,
|
|
32941
33237
|
encryptWithPassword,
|
|
32942
|
-
|
|
32943
|
-
|
|
33238
|
+
escrowContractAddress,
|
|
33239
|
+
escrowPaymentDomain,
|
|
32944
33240
|
generatePkceVerifier,
|
|
32945
33241
|
getAbi,
|
|
32946
33242
|
getAllChains,
|
|
@@ -32948,6 +33244,8 @@ export {
|
|
|
32948
33244
|
getContractAddress,
|
|
32949
33245
|
getContractController,
|
|
32950
33246
|
getContractInfo,
|
|
33247
|
+
getFee,
|
|
33248
|
+
getOpFee,
|
|
32951
33249
|
getPlatformCapabilities,
|
|
32952
33250
|
getServiceEndpoints,
|
|
32953
33251
|
grantRegistrationDomain,
|
|
@@ -32959,11 +33257,12 @@ export {
|
|
|
32959
33257
|
moksha,
|
|
32960
33258
|
mokshaServices,
|
|
32961
33259
|
mokshaTestnet2 as mokshaTestnet,
|
|
32962
|
-
parseGrantRegistrationPayload,
|
|
32963
33260
|
parsePSError,
|
|
32964
33261
|
parseScope,
|
|
32965
33262
|
parseWeb3SignedHeader,
|
|
33263
|
+
personalServerDataReadPath,
|
|
32966
33264
|
personalServerRegistrationDomain,
|
|
33265
|
+
readPersonalServerData,
|
|
32967
33266
|
recoverServerOwner,
|
|
32968
33267
|
registerPersonalServerSignature,
|
|
32969
33268
|
scopeCoveredByGrant,
|