@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.node.js
CHANGED
|
@@ -32509,6 +32509,7 @@ function formatOAuthError(body, status) {
|
|
|
32509
32509
|
// src/protocol/eip712.ts
|
|
32510
32510
|
var DOMAIN_NAME = "Vana Data Portability";
|
|
32511
32511
|
var DOMAIN_VERSION = "1";
|
|
32512
|
+
var NATIVE_VANA_ASSET = "0x0000000000000000000000000000000000000000";
|
|
32512
32513
|
function buildDomain(chainId, verifyingContract) {
|
|
32513
32514
|
return {
|
|
32514
32515
|
name: DOMAIN_NAME,
|
|
@@ -32517,13 +32518,7 @@ function buildDomain(chainId, verifyingContract) {
|
|
|
32517
32518
|
verifyingContract
|
|
32518
32519
|
};
|
|
32519
32520
|
}
|
|
32520
|
-
function
|
|
32521
|
-
return buildDomain(
|
|
32522
|
-
config.chainId,
|
|
32523
|
-
config.contracts.dataRegistry
|
|
32524
|
-
);
|
|
32525
|
-
}
|
|
32526
|
-
function fileDeletionDomain(config) {
|
|
32521
|
+
function dataRegistryDomain(config) {
|
|
32527
32522
|
return buildDomain(
|
|
32528
32523
|
config.chainId,
|
|
32529
32524
|
config.contracts.dataRegistry
|
|
@@ -32553,31 +32548,26 @@ function builderRegistrationDomain(config) {
|
|
|
32553
32548
|
config.contracts.dataPortabilityGrantees
|
|
32554
32549
|
);
|
|
32555
32550
|
}
|
|
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
|
-
};
|
|
32551
|
+
function escrowPaymentDomain(config) {
|
|
32552
|
+
return buildDomain(
|
|
32553
|
+
config.chainId,
|
|
32554
|
+
config.contracts.dataPortabilityEscrow
|
|
32555
|
+
);
|
|
32556
|
+
}
|
|
32569
32557
|
var GRANT_REGISTRATION_TYPES = {
|
|
32570
32558
|
GrantRegistration: [
|
|
32571
32559
|
{ name: "grantorAddress", type: "address" },
|
|
32572
32560
|
{ name: "granteeId", type: "bytes32" },
|
|
32573
|
-
{ name: "
|
|
32574
|
-
{ name: "
|
|
32561
|
+
{ name: "scopes", type: "string[]" },
|
|
32562
|
+
{ name: "grantVersion", type: "uint256" },
|
|
32563
|
+
{ name: "expiresAt", type: "uint256" }
|
|
32575
32564
|
]
|
|
32576
32565
|
};
|
|
32577
32566
|
var GRANT_REVOCATION_TYPES = {
|
|
32578
32567
|
GrantRevocation: [
|
|
32579
32568
|
{ name: "grantorAddress", type: "address" },
|
|
32580
|
-
{ name: "grantId", type: "bytes32" }
|
|
32569
|
+
{ name: "grantId", type: "bytes32" },
|
|
32570
|
+
{ name: "grantVersion", type: "uint256" }
|
|
32581
32571
|
]
|
|
32582
32572
|
};
|
|
32583
32573
|
var SERVER_REGISTRATION_TYPES = {
|
|
@@ -32596,6 +32586,34 @@ var BUILDER_REGISTRATION_TYPES = {
|
|
|
32596
32586
|
{ name: "appUrl", type: "string" }
|
|
32597
32587
|
]
|
|
32598
32588
|
};
|
|
32589
|
+
var GENERIC_PAYMENT_TYPES = {
|
|
32590
|
+
GenericPayment: [
|
|
32591
|
+
{ name: "payerAddress", type: "address" },
|
|
32592
|
+
{ name: "opType", type: "string" },
|
|
32593
|
+
{ name: "opId", type: "bytes32" },
|
|
32594
|
+
{ name: "asset", type: "address" },
|
|
32595
|
+
{ name: "amount", type: "uint256" },
|
|
32596
|
+
{ name: "paymentNonce", type: "uint256" }
|
|
32597
|
+
]
|
|
32598
|
+
};
|
|
32599
|
+
var ADD_DATA_TYPES = {
|
|
32600
|
+
AddData: [
|
|
32601
|
+
{ name: "ownerAddress", type: "address" },
|
|
32602
|
+
{ name: "scope", type: "string" },
|
|
32603
|
+
{ name: "dataHash", type: "bytes32" },
|
|
32604
|
+
{ name: "metadataHash", type: "bytes32" },
|
|
32605
|
+
{ name: "expectedVersion", type: "uint256" }
|
|
32606
|
+
]
|
|
32607
|
+
};
|
|
32608
|
+
var RECORD_DATA_ACCESS_TYPES = {
|
|
32609
|
+
RecordDataAccess: [
|
|
32610
|
+
{ name: "ownerAddress", type: "address" },
|
|
32611
|
+
{ name: "scope", type: "string" },
|
|
32612
|
+
{ name: "version", type: "uint256" },
|
|
32613
|
+
{ name: "accessor", type: "address" },
|
|
32614
|
+
{ name: "recordId", type: "bytes32" }
|
|
32615
|
+
]
|
|
32616
|
+
};
|
|
32599
32617
|
|
|
32600
32618
|
// src/protocol/personal-server-registration.ts
|
|
32601
32619
|
import {
|
|
@@ -33037,67 +33055,34 @@ function isDataPortabilityGatewayConfig(value) {
|
|
|
33037
33055
|
return false;
|
|
33038
33056
|
}
|
|
33039
33057
|
const c = contracts;
|
|
33040
|
-
return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]);
|
|
33041
|
-
}
|
|
33042
|
-
function parseGrantRegistrationPayload(grant) {
|
|
33043
|
-
let parsed;
|
|
33044
|
-
try {
|
|
33045
|
-
parsed = JSON.parse(grant);
|
|
33046
|
-
} catch {
|
|
33047
|
-
return null;
|
|
33048
|
-
}
|
|
33049
|
-
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
33050
|
-
return null;
|
|
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
|
-
};
|
|
33058
|
+
return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]) && isHexString(c["dataPortabilityEscrow"]) && isHexString(c["feeRegistry"]);
|
|
33078
33059
|
}
|
|
33079
|
-
function
|
|
33060
|
+
function toUint256(value) {
|
|
33080
33061
|
try {
|
|
33081
|
-
|
|
33082
|
-
|
|
33083
|
-
|
|
33084
|
-
|
|
33085
|
-
|
|
33062
|
+
if (typeof value === "number" && !Number.isSafeInteger(value)) {
|
|
33063
|
+
return null;
|
|
33064
|
+
}
|
|
33065
|
+
const big = typeof value === "bigint" ? value : BigInt(value);
|
|
33066
|
+
if (big < 0n) return null;
|
|
33067
|
+
return big;
|
|
33086
33068
|
} catch {
|
|
33087
33069
|
return null;
|
|
33088
33070
|
}
|
|
33089
33071
|
}
|
|
33090
33072
|
async function verifyGrantRegistration(input) {
|
|
33091
|
-
|
|
33092
|
-
|
|
33093
|
-
return {
|
|
33094
|
-
valid: false,
|
|
33095
|
-
error: "Grant must be JSON with scopes and expiresAt"
|
|
33096
|
-
};
|
|
33073
|
+
if (!Array.isArray(input.scopes) || input.scopes.length === 0) {
|
|
33074
|
+
return { valid: false, error: "scopes must be a non-empty array" };
|
|
33097
33075
|
}
|
|
33098
|
-
|
|
33099
|
-
|
|
33100
|
-
|
|
33076
|
+
if (!input.scopes.every((scope) => typeof scope === "string")) {
|
|
33077
|
+
return { valid: false, error: "scopes must contain only strings" };
|
|
33078
|
+
}
|
|
33079
|
+
const grantVersion = toUint256(input.grantVersion);
|
|
33080
|
+
if (grantVersion === null || grantVersion < 1n) {
|
|
33081
|
+
return { valid: false, error: "grantVersion must be a uint256 >= 1" };
|
|
33082
|
+
}
|
|
33083
|
+
const expiresAt = toUint256(input.expiresAt);
|
|
33084
|
+
if (expiresAt === null) {
|
|
33085
|
+
return { valid: false, error: "expiresAt must be a non-negative uint256" };
|
|
33101
33086
|
}
|
|
33102
33087
|
let valid;
|
|
33103
33088
|
try {
|
|
@@ -33109,8 +33094,9 @@ async function verifyGrantRegistration(input) {
|
|
|
33109
33094
|
message: {
|
|
33110
33095
|
grantorAddress: input.grantorAddress,
|
|
33111
33096
|
granteeId: input.granteeId,
|
|
33112
|
-
|
|
33113
|
-
|
|
33097
|
+
scopes: input.scopes,
|
|
33098
|
+
grantVersion,
|
|
33099
|
+
expiresAt
|
|
33114
33100
|
},
|
|
33115
33101
|
signature: input.signature
|
|
33116
33102
|
});
|
|
@@ -33121,19 +33107,197 @@ async function verifyGrantRegistration(input) {
|
|
|
33121
33107
|
return { valid: false, error: "Grant signature does not match grantor" };
|
|
33122
33108
|
}
|
|
33123
33109
|
const nowSeconds = input.nowSeconds ?? Math.floor(Date.now() / 1e3);
|
|
33124
|
-
if (
|
|
33110
|
+
if (expiresAt > 0n && expiresAt < BigInt(nowSeconds)) {
|
|
33125
33111
|
return { valid: false, error: "Grant has expired" };
|
|
33126
33112
|
}
|
|
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
33113
|
return {
|
|
33131
33114
|
valid: true,
|
|
33132
33115
|
grantorAddress: input.grantorAddress,
|
|
33133
33116
|
granteeId: input.granteeId,
|
|
33134
|
-
|
|
33135
|
-
|
|
33136
|
-
|
|
33117
|
+
scopes: input.scopes,
|
|
33118
|
+
grantVersion: grantVersion.toString(),
|
|
33119
|
+
expiresAt: expiresAt.toString()
|
|
33120
|
+
};
|
|
33121
|
+
}
|
|
33122
|
+
|
|
33123
|
+
// src/protocol/escrow-deposit.ts
|
|
33124
|
+
import { encodeFunctionData } from "viem";
|
|
33125
|
+
var ESCROW_DEPOSIT_ABI = [
|
|
33126
|
+
{
|
|
33127
|
+
type: "function",
|
|
33128
|
+
name: "depositNative",
|
|
33129
|
+
stateMutability: "payable",
|
|
33130
|
+
inputs: [{ name: "account", type: "address" }],
|
|
33131
|
+
outputs: []
|
|
33132
|
+
},
|
|
33133
|
+
{
|
|
33134
|
+
type: "function",
|
|
33135
|
+
name: "depositToken",
|
|
33136
|
+
stateMutability: "nonpayable",
|
|
33137
|
+
inputs: [
|
|
33138
|
+
{ name: "account", type: "address" },
|
|
33139
|
+
{ name: "token", type: "address" },
|
|
33140
|
+
{ name: "amount", type: "uint256" }
|
|
33141
|
+
],
|
|
33142
|
+
outputs: []
|
|
33143
|
+
}
|
|
33144
|
+
];
|
|
33145
|
+
function escrowContractAddress(config) {
|
|
33146
|
+
return config.contracts.dataPortabilityEscrow;
|
|
33147
|
+
}
|
|
33148
|
+
function encodeDepositNativeData(input) {
|
|
33149
|
+
return encodeFunctionData({
|
|
33150
|
+
abi: ESCROW_DEPOSIT_ABI,
|
|
33151
|
+
functionName: "depositNative",
|
|
33152
|
+
args: [input.account]
|
|
33153
|
+
});
|
|
33154
|
+
}
|
|
33155
|
+
function encodeDepositTokenData(input) {
|
|
33156
|
+
return encodeFunctionData({
|
|
33157
|
+
abi: ESCROW_DEPOSIT_ABI,
|
|
33158
|
+
functionName: "depositToken",
|
|
33159
|
+
args: [input.account, input.token, input.amount]
|
|
33160
|
+
});
|
|
33161
|
+
}
|
|
33162
|
+
function buildDepositNativeRequest(config, input) {
|
|
33163
|
+
return {
|
|
33164
|
+
to: escrowContractAddress(config),
|
|
33165
|
+
data: encodeDepositNativeData({ account: input.account }),
|
|
33166
|
+
value: input.amount
|
|
33167
|
+
};
|
|
33168
|
+
}
|
|
33169
|
+
function buildDepositTokenRequest(config, input) {
|
|
33170
|
+
return {
|
|
33171
|
+
to: escrowContractAddress(config),
|
|
33172
|
+
data: encodeDepositTokenData(input)
|
|
33173
|
+
};
|
|
33174
|
+
}
|
|
33175
|
+
|
|
33176
|
+
// src/protocol/data-point-status.ts
|
|
33177
|
+
import { encodeFunctionData as encodeFunctionData2 } from "viem";
|
|
33178
|
+
var DataPointStatus = /* @__PURE__ */ ((DataPointStatus2) => {
|
|
33179
|
+
DataPointStatus2[DataPointStatus2["None"] = 0] = "None";
|
|
33180
|
+
DataPointStatus2[DataPointStatus2["Active"] = 1] = "Active";
|
|
33181
|
+
DataPointStatus2[DataPointStatus2["Inactive"] = 2] = "Inactive";
|
|
33182
|
+
DataPointStatus2[DataPointStatus2["Unavailable"] = 3] = "Unavailable";
|
|
33183
|
+
return DataPointStatus2;
|
|
33184
|
+
})(DataPointStatus || {});
|
|
33185
|
+
var DATA_REGISTRY_STATUS_ABI = [
|
|
33186
|
+
{
|
|
33187
|
+
type: "function",
|
|
33188
|
+
name: "setStatus",
|
|
33189
|
+
stateMutability: "nonpayable",
|
|
33190
|
+
inputs: [
|
|
33191
|
+
{ name: "scope", type: "string" },
|
|
33192
|
+
{ name: "newStatus", type: "uint8" }
|
|
33193
|
+
],
|
|
33194
|
+
outputs: []
|
|
33195
|
+
}
|
|
33196
|
+
];
|
|
33197
|
+
function dataRegistryContractAddress(config) {
|
|
33198
|
+
return config.contracts.dataRegistry;
|
|
33199
|
+
}
|
|
33200
|
+
function encodeSetDataPointStatusData(input) {
|
|
33201
|
+
return encodeFunctionData2({
|
|
33202
|
+
abi: DATA_REGISTRY_STATUS_ABI,
|
|
33203
|
+
functionName: "setStatus",
|
|
33204
|
+
args: [input.scope, input.status]
|
|
33205
|
+
});
|
|
33206
|
+
}
|
|
33207
|
+
function buildSetDataPointStatusRequest(config, input) {
|
|
33208
|
+
return {
|
|
33209
|
+
to: dataRegistryContractAddress(config),
|
|
33210
|
+
data: encodeSetDataPointStatusData(input)
|
|
33211
|
+
};
|
|
33212
|
+
}
|
|
33213
|
+
function buildMarkDataPointUnavailableRequest(config, input) {
|
|
33214
|
+
return buildSetDataPointStatusRequest(config, {
|
|
33215
|
+
scope: input.scope,
|
|
33216
|
+
status: 3 /* Unavailable */
|
|
33217
|
+
});
|
|
33218
|
+
}
|
|
33219
|
+
|
|
33220
|
+
// src/protocol/fee-registry.ts
|
|
33221
|
+
import { parseAbi } from "viem";
|
|
33222
|
+
var FEE_REGISTRY_ABI = parseAbi([
|
|
33223
|
+
"struct Fee { uint256 amount; address asset; address payee; bool enabled; }",
|
|
33224
|
+
"function fees(bytes32 operation) view returns (Fee)",
|
|
33225
|
+
"function operationKey(string name) pure returns (bytes32)"
|
|
33226
|
+
]);
|
|
33227
|
+
var REGISTRATION_KIND_FOR_OP = {
|
|
33228
|
+
grant: "grant_registration",
|
|
33229
|
+
data: "data_registration",
|
|
33230
|
+
server: "server_registration",
|
|
33231
|
+
builder: "builder_registration"
|
|
33232
|
+
};
|
|
33233
|
+
function operationNameFor(kind, opts) {
|
|
33234
|
+
switch (kind) {
|
|
33235
|
+
case "grant_registration":
|
|
33236
|
+
return opts?.grantRegistrationOpName ?? "grant_registration";
|
|
33237
|
+
case "data_access":
|
|
33238
|
+
return opts?.dataAccessOpName ?? "data_access";
|
|
33239
|
+
case "data_registration":
|
|
33240
|
+
return opts?.dataRegistrationOpName ?? "data_registration";
|
|
33241
|
+
case "server_registration":
|
|
33242
|
+
return opts?.serverRegistrationOpName ?? "server_registration";
|
|
33243
|
+
case "builder_registration":
|
|
33244
|
+
return opts?.builderRegistrationOpName ?? "builder_registration";
|
|
33245
|
+
}
|
|
33246
|
+
}
|
|
33247
|
+
var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
33248
|
+
async function getFee(client, config, kind, opts) {
|
|
33249
|
+
const address = config.contracts.feeRegistry;
|
|
33250
|
+
const opName = operationNameFor(kind, opts);
|
|
33251
|
+
const opKey = await client.readContract({
|
|
33252
|
+
address,
|
|
33253
|
+
abi: FEE_REGISTRY_ABI,
|
|
33254
|
+
functionName: "operationKey",
|
|
33255
|
+
args: [opName]
|
|
33256
|
+
});
|
|
33257
|
+
const fee = await client.readContract({
|
|
33258
|
+
address,
|
|
33259
|
+
abi: FEE_REGISTRY_ABI,
|
|
33260
|
+
functionName: "fees",
|
|
33261
|
+
args: [opKey]
|
|
33262
|
+
});
|
|
33263
|
+
if (fee.enabled && fee.payee === ZERO_ADDRESS) {
|
|
33264
|
+
throw new Error(
|
|
33265
|
+
`FeeRegistry: enabled operation "${opName}" has zero-address payee \u2014 contract pre-flight rejects payouts to 0x0`
|
|
33266
|
+
);
|
|
33267
|
+
}
|
|
33268
|
+
return fee;
|
|
33269
|
+
}
|
|
33270
|
+
async function getOpFee(client, config, opType, opts) {
|
|
33271
|
+
const registrationKind = REGISTRATION_KIND_FOR_OP[opType];
|
|
33272
|
+
if (!registrationKind) {
|
|
33273
|
+
throw new Error(
|
|
33274
|
+
`getOpFee: unknown opType "${opType}" \u2014 supported types are ${Object.keys(REGISTRATION_KIND_FOR_OP).join(", ")}`
|
|
33275
|
+
);
|
|
33276
|
+
}
|
|
33277
|
+
const includeDataAccess = opType === "grant";
|
|
33278
|
+
const [registration, dataAccess] = await Promise.all([
|
|
33279
|
+
getFee(client, config, registrationKind, opts),
|
|
33280
|
+
includeDataAccess ? getFee(client, config, "data_access", opts) : Promise.resolve({
|
|
33281
|
+
amount: 0n,
|
|
33282
|
+
asset: ZERO_ADDRESS,
|
|
33283
|
+
payee: ZERO_ADDRESS,
|
|
33284
|
+
enabled: false
|
|
33285
|
+
})
|
|
33286
|
+
]);
|
|
33287
|
+
if (registration.enabled && dataAccess.enabled && registration.asset.toLowerCase() !== dataAccess.asset.toLowerCase()) {
|
|
33288
|
+
throw new Error(
|
|
33289
|
+
`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.`
|
|
33290
|
+
);
|
|
33291
|
+
}
|
|
33292
|
+
const asset = registration.enabled ? registration.asset : dataAccess.enabled ? dataAccess.asset : ZERO_ADDRESS;
|
|
33293
|
+
return {
|
|
33294
|
+
asset,
|
|
33295
|
+
registrationFee: registration.enabled ? registration.amount : 0n,
|
|
33296
|
+
dataAccessFee: dataAccess.enabled ? dataAccess.amount : 0n,
|
|
33297
|
+
registrationEnabled: registration.enabled,
|
|
33298
|
+
dataAccessEnabled: dataAccess.enabled,
|
|
33299
|
+
registrationPayee: registration.enabled ? registration.payee : ZERO_ADDRESS,
|
|
33300
|
+
dataAccessPayee: dataAccess.enabled ? dataAccess.payee : ZERO_ADDRESS
|
|
33137
33301
|
};
|
|
33138
33302
|
}
|
|
33139
33303
|
|
|
@@ -33207,6 +33371,45 @@ var IngestResponseSchema = z2.object({
|
|
|
33207
33371
|
status: z2.enum(["stored", "syncing"])
|
|
33208
33372
|
});
|
|
33209
33373
|
|
|
33374
|
+
// src/protocol/personal-server-data.ts
|
|
33375
|
+
function personalServerDataReadPath(scope) {
|
|
33376
|
+
return `/v1/data/${encodeURIComponent(scope)}`;
|
|
33377
|
+
}
|
|
33378
|
+
async function buildPersonalServerDataReadRequest(params) {
|
|
33379
|
+
const path = personalServerDataReadPath(params.scope);
|
|
33380
|
+
const baseUrl = params.personalServerUrl.replace(/\/+$/, "");
|
|
33381
|
+
const audience = params.audience ?? baseUrl;
|
|
33382
|
+
const headers = new Headers(params.headers);
|
|
33383
|
+
headers.set(
|
|
33384
|
+
"Authorization",
|
|
33385
|
+
await buildWeb3SignedHeader({
|
|
33386
|
+
aud: audience,
|
|
33387
|
+
grantId: params.grantId,
|
|
33388
|
+
method: "GET",
|
|
33389
|
+
signMessage: params.signMessage,
|
|
33390
|
+
uri: path
|
|
33391
|
+
})
|
|
33392
|
+
);
|
|
33393
|
+
return new Request(`${baseUrl}${path}`, {
|
|
33394
|
+
headers,
|
|
33395
|
+
method: "GET"
|
|
33396
|
+
});
|
|
33397
|
+
}
|
|
33398
|
+
async function readPersonalServerData(params) {
|
|
33399
|
+
const fetchFn = params.fetch ?? globalThis.fetch;
|
|
33400
|
+
if (fetchFn === void 0) {
|
|
33401
|
+
throw new Error("No fetch implementation available");
|
|
33402
|
+
}
|
|
33403
|
+
const request = await buildPersonalServerDataReadRequest(params);
|
|
33404
|
+
const response = await fetchFn(request);
|
|
33405
|
+
if (!response.ok) {
|
|
33406
|
+
throw new Error(
|
|
33407
|
+
`Personal Server data read failed: ${response.status} ${response.statusText}`
|
|
33408
|
+
);
|
|
33409
|
+
}
|
|
33410
|
+
return DataFileEnvelopeSchema.parse(await response.json());
|
|
33411
|
+
}
|
|
33412
|
+
|
|
33210
33413
|
// src/protocol/gateway.ts
|
|
33211
33414
|
function createGatewayClient(baseUrl) {
|
|
33212
33415
|
const base = baseUrl.replace(/\/+$/, "");
|
|
@@ -33214,16 +33417,6 @@ function createGatewayClient(baseUrl) {
|
|
|
33214
33417
|
const envelope = await res.json();
|
|
33215
33418
|
return envelope.data;
|
|
33216
33419
|
}
|
|
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
33420
|
function getMutationId(body, key) {
|
|
33228
33421
|
const value = body[key] ?? body["id"];
|
|
33229
33422
|
return typeof value === "string" ? value : void 0;
|
|
@@ -33273,30 +33466,34 @@ function createGatewayClient(baseUrl) {
|
|
|
33273
33466
|
}
|
|
33274
33467
|
return unwrapEnvelope(res);
|
|
33275
33468
|
},
|
|
33276
|
-
async
|
|
33277
|
-
const res = await fetch(`${base}/v1/
|
|
33469
|
+
async getDataPoint(dataPointId) {
|
|
33470
|
+
const res = await fetch(`${base}/v1/data/${dataPointId}`);
|
|
33278
33471
|
if (res.status === 404) return null;
|
|
33279
33472
|
if (!res.ok) {
|
|
33280
33473
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33281
33474
|
}
|
|
33282
|
-
return
|
|
33475
|
+
return unwrapEnvelope(res);
|
|
33283
33476
|
},
|
|
33284
|
-
async
|
|
33477
|
+
async listDataPointsByOwner(owner, cursor, options) {
|
|
33285
33478
|
const params = new URLSearchParams({ user: owner });
|
|
33286
33479
|
if (cursor !== null) {
|
|
33287
|
-
params.set("
|
|
33480
|
+
params.set("cursor", cursor);
|
|
33288
33481
|
}
|
|
33289
|
-
if (options?.
|
|
33290
|
-
params.set("
|
|
33482
|
+
if (options?.since) {
|
|
33483
|
+
params.set("since", options.since);
|
|
33291
33484
|
}
|
|
33292
|
-
|
|
33485
|
+
if (options?.limit !== void 0) {
|
|
33486
|
+
params.set("limit", String(options.limit));
|
|
33487
|
+
}
|
|
33488
|
+
const res = await fetch(`${base}/v1/data?${params.toString()}`);
|
|
33293
33489
|
if (!res.ok) {
|
|
33294
33490
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33295
33491
|
}
|
|
33296
|
-
const
|
|
33492
|
+
const envelope = await res.json();
|
|
33493
|
+
const nextCursor = envelope.pagination?.hasMore === false ? null : envelope.pagination?.nextCursor ?? null;
|
|
33297
33494
|
return {
|
|
33298
|
-
|
|
33299
|
-
cursor:
|
|
33495
|
+
dataPoints: envelope.data.dataPoints,
|
|
33496
|
+
cursor: nextCursor
|
|
33300
33497
|
};
|
|
33301
33498
|
},
|
|
33302
33499
|
async getSchema(schemaId) {
|
|
@@ -33337,8 +33534,8 @@ function createGatewayClient(baseUrl) {
|
|
|
33337
33534
|
alreadyRegistered: false
|
|
33338
33535
|
};
|
|
33339
33536
|
},
|
|
33340
|
-
async
|
|
33341
|
-
const res = await fetch(`${base}/v1/
|
|
33537
|
+
async registerBuilder(params) {
|
|
33538
|
+
const res = await fetch(`${base}/v1/builders`, {
|
|
33342
33539
|
method: "POST",
|
|
33343
33540
|
headers: {
|
|
33344
33541
|
"Content-Type": "application/json",
|
|
@@ -33346,22 +33543,57 @@ function createGatewayClient(baseUrl) {
|
|
|
33346
33543
|
},
|
|
33347
33544
|
body: JSON.stringify({
|
|
33348
33545
|
ownerAddress: params.ownerAddress,
|
|
33349
|
-
|
|
33350
|
-
|
|
33546
|
+
granteeAddress: params.granteeAddress,
|
|
33547
|
+
publicKey: params.publicKey,
|
|
33548
|
+
appUrl: params.appUrl
|
|
33351
33549
|
})
|
|
33352
33550
|
});
|
|
33353
33551
|
if (res.status === 409) {
|
|
33354
33552
|
const body2 = await res.json().catch(() => ({}));
|
|
33355
33553
|
return {
|
|
33356
|
-
|
|
33554
|
+
builderId: getMutationId(
|
|
33555
|
+
body2,
|
|
33556
|
+
"builderId"
|
|
33557
|
+
),
|
|
33558
|
+
alreadyRegistered: true
|
|
33357
33559
|
};
|
|
33358
33560
|
}
|
|
33359
33561
|
if (!res.ok) {
|
|
33360
33562
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33361
33563
|
}
|
|
33362
|
-
const body = await res.json();
|
|
33564
|
+
const body = await res.json().catch(() => ({}));
|
|
33565
|
+
return {
|
|
33566
|
+
builderId: getMutationId(body, "builderId"),
|
|
33567
|
+
alreadyRegistered: false
|
|
33568
|
+
};
|
|
33569
|
+
},
|
|
33570
|
+
async registerDataPoint(params) {
|
|
33571
|
+
const res = await fetch(`${base}/v1/data`, {
|
|
33572
|
+
method: "POST",
|
|
33573
|
+
headers: {
|
|
33574
|
+
"Content-Type": "application/json",
|
|
33575
|
+
Authorization: `Web3Signed ${params.signature}`
|
|
33576
|
+
},
|
|
33577
|
+
body: JSON.stringify({
|
|
33578
|
+
ownerAddress: params.ownerAddress,
|
|
33579
|
+
scope: params.scope,
|
|
33580
|
+
dataHash: params.dataHash,
|
|
33581
|
+
metadataHash: params.metadataHash,
|
|
33582
|
+
expectedVersion: params.expectedVersion
|
|
33583
|
+
})
|
|
33584
|
+
});
|
|
33585
|
+
if (!res.ok) {
|
|
33586
|
+
const body2 = await res.json().catch(() => ({}));
|
|
33587
|
+
const detail = body2.error ?? res.statusText;
|
|
33588
|
+
throw new Error(`Gateway error: ${res.status} ${detail}`);
|
|
33589
|
+
}
|
|
33590
|
+
const body = await res.json().catch(() => ({}));
|
|
33363
33591
|
return {
|
|
33364
|
-
|
|
33592
|
+
dataPointId: getMutationId(
|
|
33593
|
+
body,
|
|
33594
|
+
"dataPointId"
|
|
33595
|
+
),
|
|
33596
|
+
expectedVersion: body.expectedVersion
|
|
33365
33597
|
};
|
|
33366
33598
|
},
|
|
33367
33599
|
async createGrant(params) {
|
|
@@ -33374,8 +33606,9 @@ function createGatewayClient(baseUrl) {
|
|
|
33374
33606
|
body: JSON.stringify({
|
|
33375
33607
|
grantorAddress: params.grantorAddress,
|
|
33376
33608
|
granteeId: params.granteeId,
|
|
33377
|
-
|
|
33378
|
-
|
|
33609
|
+
scopes: params.scopes,
|
|
33610
|
+
grantVersion: params.grantVersion,
|
|
33611
|
+
expiresAt: params.expiresAt
|
|
33379
33612
|
})
|
|
33380
33613
|
});
|
|
33381
33614
|
if (res.status === 409) {
|
|
@@ -33400,7 +33633,8 @@ function createGatewayClient(baseUrl) {
|
|
|
33400
33633
|
Authorization: `Web3Signed ${params.signature}`
|
|
33401
33634
|
},
|
|
33402
33635
|
body: JSON.stringify({
|
|
33403
|
-
grantorAddress: params.grantorAddress
|
|
33636
|
+
grantorAddress: params.grantorAddress,
|
|
33637
|
+
grantVersion: params.grantVersion
|
|
33404
33638
|
})
|
|
33405
33639
|
});
|
|
33406
33640
|
if (res.status === 409) return;
|
|
@@ -33408,21 +33642,62 @@ function createGatewayClient(baseUrl) {
|
|
|
33408
33642
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33409
33643
|
}
|
|
33410
33644
|
},
|
|
33411
|
-
async
|
|
33412
|
-
const res = await fetch(`${base}/v1/
|
|
33413
|
-
|
|
33645
|
+
async getEscrowBalance(account) {
|
|
33646
|
+
const res = await fetch(`${base}/v1/escrow/balance?account=${account}`);
|
|
33647
|
+
if (!res.ok) {
|
|
33648
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33649
|
+
}
|
|
33650
|
+
return await res.json();
|
|
33651
|
+
},
|
|
33652
|
+
async submitEscrowDeposit(params) {
|
|
33653
|
+
const res = await fetch(`${base}/v1/escrow/deposit`, {
|
|
33654
|
+
method: "POST",
|
|
33655
|
+
headers: { "Content-Type": "application/json" },
|
|
33656
|
+
body: JSON.stringify({ txHash: params.txHash })
|
|
33657
|
+
});
|
|
33658
|
+
if (res.status !== 200 && res.status !== 202) {
|
|
33659
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33660
|
+
}
|
|
33661
|
+
return await res.json();
|
|
33662
|
+
},
|
|
33663
|
+
async payForOperation(params) {
|
|
33664
|
+
const body = {
|
|
33665
|
+
payerAddress: params.payerAddress,
|
|
33666
|
+
opType: params.opType,
|
|
33667
|
+
opId: params.opId,
|
|
33668
|
+
asset: params.asset,
|
|
33669
|
+
amount: params.amount,
|
|
33670
|
+
paymentNonce: params.paymentNonce
|
|
33671
|
+
};
|
|
33672
|
+
if (params.accessRecord) {
|
|
33673
|
+
body["accessRecord"] = params.accessRecord;
|
|
33674
|
+
}
|
|
33675
|
+
const res = await fetch(`${base}/v1/escrow/pay`, {
|
|
33676
|
+
method: "POST",
|
|
33414
33677
|
headers: {
|
|
33415
33678
|
"Content-Type": "application/json",
|
|
33416
33679
|
Authorization: `Web3Signed ${params.signature}`
|
|
33417
33680
|
},
|
|
33418
|
-
body: JSON.stringify(
|
|
33419
|
-
|
|
33420
|
-
|
|
33681
|
+
body: JSON.stringify(body)
|
|
33682
|
+
});
|
|
33683
|
+
if (!res.ok) {
|
|
33684
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33685
|
+
}
|
|
33686
|
+
return await res.json();
|
|
33687
|
+
},
|
|
33688
|
+
async settle(params) {
|
|
33689
|
+
const res = await fetch(`${base}/v1/settle`, {
|
|
33690
|
+
method: "POST",
|
|
33691
|
+
headers: { "Content-Type": "application/json" },
|
|
33692
|
+
// The gateway accepts an empty body; only `limit` is recognised.
|
|
33693
|
+
// Always send a JSON body so the gateway's req.body shape parse
|
|
33694
|
+
// doesn't have to deal with an undefined.
|
|
33695
|
+
body: JSON.stringify(params ?? {})
|
|
33421
33696
|
});
|
|
33422
|
-
if (res.status === 409) return;
|
|
33423
33697
|
if (!res.ok) {
|
|
33424
33698
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33425
33699
|
}
|
|
33700
|
+
return await res.json();
|
|
33426
33701
|
}
|
|
33427
33702
|
};
|
|
33428
33703
|
}
|
|
@@ -33491,6 +33766,7 @@ async function parsePSError(response) {
|
|
|
33491
33766
|
}
|
|
33492
33767
|
export {
|
|
33493
33768
|
ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
|
|
33769
|
+
ADD_DATA_TYPES,
|
|
33494
33770
|
AccountPersonalServerLiteOwnerBindingError,
|
|
33495
33771
|
AccountPersonalServerRegistrationError,
|
|
33496
33772
|
BUILDER_REGISTRATION_TYPES,
|
|
@@ -33500,12 +33776,15 @@ export {
|
|
|
33500
33776
|
CallbackStorage,
|
|
33501
33777
|
ContractFactory,
|
|
33502
33778
|
ContractNotFoundError,
|
|
33779
|
+
DATA_REGISTRY_STATUS_ABI,
|
|
33503
33780
|
DataFileEnvelopeSchema,
|
|
33781
|
+
DataPointStatus,
|
|
33504
33782
|
DropboxStorage,
|
|
33505
33783
|
ECIESError,
|
|
33784
|
+
ESCROW_DEPOSIT_ABI,
|
|
33506
33785
|
ExpiredTokenError,
|
|
33507
|
-
|
|
33508
|
-
|
|
33786
|
+
FEE_REGISTRY_ABI,
|
|
33787
|
+
GENERIC_PAYMENT_TYPES,
|
|
33509
33788
|
GRANT_REGISTRATION_TYPES,
|
|
33510
33789
|
GRANT_REVOCATION_TYPES,
|
|
33511
33790
|
GoogleDriveStorage,
|
|
@@ -33516,6 +33795,7 @@ export {
|
|
|
33516
33795
|
IpfsStorage,
|
|
33517
33796
|
MASTER_KEY_MESSAGE,
|
|
33518
33797
|
MissingAuthError,
|
|
33798
|
+
NATIVE_VANA_ASSET,
|
|
33519
33799
|
NetworkError,
|
|
33520
33800
|
NodeECIESUint8Provider as NodeECIESProvider,
|
|
33521
33801
|
NodePlatformAdapter,
|
|
@@ -33533,6 +33813,8 @@ export {
|
|
|
33533
33813
|
PersonalServerError,
|
|
33534
33814
|
PinataStorage,
|
|
33535
33815
|
R2Storage,
|
|
33816
|
+
RECORD_DATA_ACCESS_TYPES,
|
|
33817
|
+
REGISTRATION_KIND_FOR_OP,
|
|
33536
33818
|
ReadOnlyError,
|
|
33537
33819
|
RelayerError,
|
|
33538
33820
|
SERVER_REGISTRATION_TYPES,
|
|
@@ -33547,10 +33829,15 @@ export {
|
|
|
33547
33829
|
VanaError,
|
|
33548
33830
|
VanaStorage,
|
|
33549
33831
|
assertValidPkceVerifier,
|
|
33832
|
+
buildDepositNativeRequest,
|
|
33833
|
+
buildDepositTokenRequest,
|
|
33834
|
+
buildMarkDataPointUnavailableRequest,
|
|
33835
|
+
buildPersonalServerDataReadRequest,
|
|
33550
33836
|
buildPersonalServerLiteOwnerBindingMessage,
|
|
33551
33837
|
buildPersonalServerLiteOwnerBindingSignature,
|
|
33552
33838
|
buildPersonalServerRegistrationSignature,
|
|
33553
33839
|
buildPersonalServerRegistrationTypedData,
|
|
33840
|
+
buildSetDataPointStatusRequest,
|
|
33554
33841
|
buildWeb3SignedHeader,
|
|
33555
33842
|
builderRegistrationDomain,
|
|
33556
33843
|
chains,
|
|
@@ -33568,14 +33855,19 @@ export {
|
|
|
33568
33855
|
createVanaStorageProvider,
|
|
33569
33856
|
createViemPersonalServerLiteOwnerBindingSigner,
|
|
33570
33857
|
createViemPersonalServerRegistrationSigner,
|
|
33858
|
+
dataRegistryContractAddress,
|
|
33859
|
+
dataRegistryDomain,
|
|
33571
33860
|
decryptWithPassword,
|
|
33572
33861
|
deriveMasterKey,
|
|
33573
33862
|
deriveScopeKey,
|
|
33574
33863
|
deserializeECIES,
|
|
33575
33864
|
detectPlatform,
|
|
33865
|
+
encodeDepositNativeData,
|
|
33866
|
+
encodeDepositTokenData,
|
|
33867
|
+
encodeSetDataPointStatusData,
|
|
33576
33868
|
encryptWithPassword,
|
|
33577
|
-
|
|
33578
|
-
|
|
33869
|
+
escrowContractAddress,
|
|
33870
|
+
escrowPaymentDomain,
|
|
33579
33871
|
generatePkceVerifier,
|
|
33580
33872
|
getAbi,
|
|
33581
33873
|
getAllChains,
|
|
@@ -33583,6 +33875,8 @@ export {
|
|
|
33583
33875
|
getContractAddress,
|
|
33584
33876
|
getContractController,
|
|
33585
33877
|
getContractInfo,
|
|
33878
|
+
getFee,
|
|
33879
|
+
getOpFee,
|
|
33586
33880
|
getPlatformCapabilities,
|
|
33587
33881
|
getServiceEndpoints,
|
|
33588
33882
|
grantRegistrationDomain,
|
|
@@ -33594,11 +33888,12 @@ export {
|
|
|
33594
33888
|
moksha,
|
|
33595
33889
|
mokshaServices,
|
|
33596
33890
|
mokshaTestnet2 as mokshaTestnet,
|
|
33597
|
-
parseGrantRegistrationPayload,
|
|
33598
33891
|
parsePSError,
|
|
33599
33892
|
parseScope,
|
|
33600
33893
|
parseWeb3SignedHeader,
|
|
33894
|
+
personalServerDataReadPath,
|
|
33601
33895
|
personalServerRegistrationDomain,
|
|
33896
|
+
readPersonalServerData,
|
|
33602
33897
|
recoverServerOwner,
|
|
33603
33898
|
registerPersonalServerSignature,
|
|
33604
33899
|
scopeCoveredByGrant,
|