@opendatalabs/vana-sdk 3.4.0 → 3.4.1-canary.5ef490b
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 +6 -3
- package/dist/index.browser.js +378 -128
- package/dist/index.browser.js.map +4 -4
- package/dist/index.node.cjs +400 -133
- package/dist/index.node.cjs.map +4 -4
- package/dist/index.node.d.ts +6 -3
- package/dist/index.node.js +378 -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 +24 -64
- package/dist/protocol/grants.cjs.map +1 -1
- package/dist/protocol/grants.d.ts +6 -13
- package/dist/protocol/grants.js +24 -63
- package/dist/protocol/grants.js.map +1 -1
- 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,31 @@ 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
|
-
const
|
|
33082
|
-
return
|
|
33083
|
-
|
|
33084
|
-
display: values.map((fileId) => fileId.toString())
|
|
33085
|
-
};
|
|
33062
|
+
const big = typeof value === "bigint" ? value : BigInt(value);
|
|
33063
|
+
if (big < 0n) return null;
|
|
33064
|
+
return big;
|
|
33086
33065
|
} catch {
|
|
33087
33066
|
return null;
|
|
33088
33067
|
}
|
|
33089
33068
|
}
|
|
33090
33069
|
async function verifyGrantRegistration(input) {
|
|
33091
|
-
|
|
33092
|
-
|
|
33093
|
-
|
|
33094
|
-
|
|
33095
|
-
|
|
33096
|
-
|
|
33070
|
+
if (!Array.isArray(input.scopes) || input.scopes.length === 0) {
|
|
33071
|
+
return { valid: false, error: "scopes must be a non-empty array" };
|
|
33072
|
+
}
|
|
33073
|
+
if (!input.scopes.every((scope) => typeof scope === "string")) {
|
|
33074
|
+
return { valid: false, error: "scopes must contain only strings" };
|
|
33075
|
+
}
|
|
33076
|
+
const grantVersion = toUint256(input.grantVersion);
|
|
33077
|
+
if (grantVersion === null || grantVersion < 1n) {
|
|
33078
|
+
return { valid: false, error: "grantVersion must be a uint256 >= 1" };
|
|
33097
33079
|
}
|
|
33098
|
-
const
|
|
33099
|
-
if (
|
|
33100
|
-
return { valid: false, error: "
|
|
33080
|
+
const expiresAt = toUint256(input.expiresAt);
|
|
33081
|
+
if (expiresAt === null) {
|
|
33082
|
+
return { valid: false, error: "expiresAt must be a non-negative uint256" };
|
|
33101
33083
|
}
|
|
33102
33084
|
let valid;
|
|
33103
33085
|
try {
|
|
@@ -33109,8 +33091,9 @@ async function verifyGrantRegistration(input) {
|
|
|
33109
33091
|
message: {
|
|
33110
33092
|
grantorAddress: input.grantorAddress,
|
|
33111
33093
|
granteeId: input.granteeId,
|
|
33112
|
-
|
|
33113
|
-
|
|
33094
|
+
scopes: input.scopes,
|
|
33095
|
+
grantVersion,
|
|
33096
|
+
expiresAt
|
|
33114
33097
|
},
|
|
33115
33098
|
signature: input.signature
|
|
33116
33099
|
});
|
|
@@ -33121,19 +33104,197 @@ async function verifyGrantRegistration(input) {
|
|
|
33121
33104
|
return { valid: false, error: "Grant signature does not match grantor" };
|
|
33122
33105
|
}
|
|
33123
33106
|
const nowSeconds = input.nowSeconds ?? Math.floor(Date.now() / 1e3);
|
|
33124
|
-
if (
|
|
33107
|
+
if (expiresAt > 0n && expiresAt < BigInt(nowSeconds)) {
|
|
33125
33108
|
return { valid: false, error: "Grant has expired" };
|
|
33126
33109
|
}
|
|
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
33110
|
return {
|
|
33131
33111
|
valid: true,
|
|
33132
33112
|
grantorAddress: input.grantorAddress,
|
|
33133
33113
|
granteeId: input.granteeId,
|
|
33134
|
-
|
|
33135
|
-
|
|
33136
|
-
|
|
33114
|
+
scopes: input.scopes,
|
|
33115
|
+
grantVersion: grantVersion.toString(),
|
|
33116
|
+
expiresAt: expiresAt.toString()
|
|
33117
|
+
};
|
|
33118
|
+
}
|
|
33119
|
+
|
|
33120
|
+
// src/protocol/escrow-deposit.ts
|
|
33121
|
+
import { encodeFunctionData } from "viem";
|
|
33122
|
+
var ESCROW_DEPOSIT_ABI = [
|
|
33123
|
+
{
|
|
33124
|
+
type: "function",
|
|
33125
|
+
name: "depositNative",
|
|
33126
|
+
stateMutability: "payable",
|
|
33127
|
+
inputs: [{ name: "account", type: "address" }],
|
|
33128
|
+
outputs: []
|
|
33129
|
+
},
|
|
33130
|
+
{
|
|
33131
|
+
type: "function",
|
|
33132
|
+
name: "depositToken",
|
|
33133
|
+
stateMutability: "nonpayable",
|
|
33134
|
+
inputs: [
|
|
33135
|
+
{ name: "account", type: "address" },
|
|
33136
|
+
{ name: "token", type: "address" },
|
|
33137
|
+
{ name: "amount", type: "uint256" }
|
|
33138
|
+
],
|
|
33139
|
+
outputs: []
|
|
33140
|
+
}
|
|
33141
|
+
];
|
|
33142
|
+
function escrowContractAddress(config) {
|
|
33143
|
+
return config.contracts.dataPortabilityEscrow;
|
|
33144
|
+
}
|
|
33145
|
+
function encodeDepositNativeData(input) {
|
|
33146
|
+
return encodeFunctionData({
|
|
33147
|
+
abi: ESCROW_DEPOSIT_ABI,
|
|
33148
|
+
functionName: "depositNative",
|
|
33149
|
+
args: [input.account]
|
|
33150
|
+
});
|
|
33151
|
+
}
|
|
33152
|
+
function encodeDepositTokenData(input) {
|
|
33153
|
+
return encodeFunctionData({
|
|
33154
|
+
abi: ESCROW_DEPOSIT_ABI,
|
|
33155
|
+
functionName: "depositToken",
|
|
33156
|
+
args: [input.account, input.token, input.amount]
|
|
33157
|
+
});
|
|
33158
|
+
}
|
|
33159
|
+
function buildDepositNativeRequest(config, input) {
|
|
33160
|
+
return {
|
|
33161
|
+
to: escrowContractAddress(config),
|
|
33162
|
+
data: encodeDepositNativeData({ account: input.account }),
|
|
33163
|
+
value: input.amount
|
|
33164
|
+
};
|
|
33165
|
+
}
|
|
33166
|
+
function buildDepositTokenRequest(config, input) {
|
|
33167
|
+
return {
|
|
33168
|
+
to: escrowContractAddress(config),
|
|
33169
|
+
data: encodeDepositTokenData(input)
|
|
33170
|
+
};
|
|
33171
|
+
}
|
|
33172
|
+
|
|
33173
|
+
// src/protocol/data-point-status.ts
|
|
33174
|
+
import { encodeFunctionData as encodeFunctionData2 } from "viem";
|
|
33175
|
+
var DataPointStatus = /* @__PURE__ */ ((DataPointStatus2) => {
|
|
33176
|
+
DataPointStatus2[DataPointStatus2["None"] = 0] = "None";
|
|
33177
|
+
DataPointStatus2[DataPointStatus2["Active"] = 1] = "Active";
|
|
33178
|
+
DataPointStatus2[DataPointStatus2["Inactive"] = 2] = "Inactive";
|
|
33179
|
+
DataPointStatus2[DataPointStatus2["Unavailable"] = 3] = "Unavailable";
|
|
33180
|
+
return DataPointStatus2;
|
|
33181
|
+
})(DataPointStatus || {});
|
|
33182
|
+
var DATA_REGISTRY_STATUS_ABI = [
|
|
33183
|
+
{
|
|
33184
|
+
type: "function",
|
|
33185
|
+
name: "setStatus",
|
|
33186
|
+
stateMutability: "nonpayable",
|
|
33187
|
+
inputs: [
|
|
33188
|
+
{ name: "scope", type: "string" },
|
|
33189
|
+
{ name: "newStatus", type: "uint8" }
|
|
33190
|
+
],
|
|
33191
|
+
outputs: []
|
|
33192
|
+
}
|
|
33193
|
+
];
|
|
33194
|
+
function dataRegistryContractAddress(config) {
|
|
33195
|
+
return config.contracts.dataRegistry;
|
|
33196
|
+
}
|
|
33197
|
+
function encodeSetDataPointStatusData(input) {
|
|
33198
|
+
return encodeFunctionData2({
|
|
33199
|
+
abi: DATA_REGISTRY_STATUS_ABI,
|
|
33200
|
+
functionName: "setStatus",
|
|
33201
|
+
args: [input.scope, input.status]
|
|
33202
|
+
});
|
|
33203
|
+
}
|
|
33204
|
+
function buildSetDataPointStatusRequest(config, input) {
|
|
33205
|
+
return {
|
|
33206
|
+
to: dataRegistryContractAddress(config),
|
|
33207
|
+
data: encodeSetDataPointStatusData(input)
|
|
33208
|
+
};
|
|
33209
|
+
}
|
|
33210
|
+
function buildMarkDataPointUnavailableRequest(config, input) {
|
|
33211
|
+
return buildSetDataPointStatusRequest(config, {
|
|
33212
|
+
scope: input.scope,
|
|
33213
|
+
status: 3 /* Unavailable */
|
|
33214
|
+
});
|
|
33215
|
+
}
|
|
33216
|
+
|
|
33217
|
+
// src/protocol/fee-registry.ts
|
|
33218
|
+
import { parseAbi } from "viem";
|
|
33219
|
+
var FEE_REGISTRY_ABI = parseAbi([
|
|
33220
|
+
"struct Fee { uint256 amount; address asset; address payee; bool enabled; }",
|
|
33221
|
+
"function fees(bytes32 operation) view returns (Fee)",
|
|
33222
|
+
"function operationKey(string name) pure returns (bytes32)"
|
|
33223
|
+
]);
|
|
33224
|
+
var REGISTRATION_KIND_FOR_OP = {
|
|
33225
|
+
grant: "grant_registration",
|
|
33226
|
+
data: "data_registration",
|
|
33227
|
+
server: "server_registration",
|
|
33228
|
+
builder: "builder_registration"
|
|
33229
|
+
};
|
|
33230
|
+
function operationNameFor(kind, opts) {
|
|
33231
|
+
switch (kind) {
|
|
33232
|
+
case "grant_registration":
|
|
33233
|
+
return opts?.grantRegistrationOpName ?? "grant_registration";
|
|
33234
|
+
case "data_access":
|
|
33235
|
+
return opts?.dataAccessOpName ?? "data_access";
|
|
33236
|
+
case "data_registration":
|
|
33237
|
+
return opts?.dataRegistrationOpName ?? "data_registration";
|
|
33238
|
+
case "server_registration":
|
|
33239
|
+
return opts?.serverRegistrationOpName ?? "server_registration";
|
|
33240
|
+
case "builder_registration":
|
|
33241
|
+
return opts?.builderRegistrationOpName ?? "builder_registration";
|
|
33242
|
+
}
|
|
33243
|
+
}
|
|
33244
|
+
var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
33245
|
+
async function getFee(client, config, kind, opts) {
|
|
33246
|
+
const address = config.contracts.feeRegistry;
|
|
33247
|
+
const opName = operationNameFor(kind, opts);
|
|
33248
|
+
const opKey = await client.readContract({
|
|
33249
|
+
address,
|
|
33250
|
+
abi: FEE_REGISTRY_ABI,
|
|
33251
|
+
functionName: "operationKey",
|
|
33252
|
+
args: [opName]
|
|
33253
|
+
});
|
|
33254
|
+
const fee = await client.readContract({
|
|
33255
|
+
address,
|
|
33256
|
+
abi: FEE_REGISTRY_ABI,
|
|
33257
|
+
functionName: "fees",
|
|
33258
|
+
args: [opKey]
|
|
33259
|
+
});
|
|
33260
|
+
if (fee.enabled && fee.payee === ZERO_ADDRESS) {
|
|
33261
|
+
throw new Error(
|
|
33262
|
+
`FeeRegistry: enabled operation "${opName}" has zero-address payee \u2014 contract pre-flight rejects payouts to 0x0`
|
|
33263
|
+
);
|
|
33264
|
+
}
|
|
33265
|
+
return fee;
|
|
33266
|
+
}
|
|
33267
|
+
async function getOpFee(client, config, opType, opts) {
|
|
33268
|
+
const registrationKind = REGISTRATION_KIND_FOR_OP[opType];
|
|
33269
|
+
if (!registrationKind) {
|
|
33270
|
+
throw new Error(
|
|
33271
|
+
`getOpFee: unknown opType "${opType}" \u2014 supported types are ${Object.keys(REGISTRATION_KIND_FOR_OP).join(", ")}`
|
|
33272
|
+
);
|
|
33273
|
+
}
|
|
33274
|
+
const includeDataAccess = opType === "grant";
|
|
33275
|
+
const [registration, dataAccess] = await Promise.all([
|
|
33276
|
+
getFee(client, config, registrationKind, opts),
|
|
33277
|
+
includeDataAccess ? getFee(client, config, "data_access", opts) : Promise.resolve({
|
|
33278
|
+
amount: 0n,
|
|
33279
|
+
asset: ZERO_ADDRESS,
|
|
33280
|
+
payee: ZERO_ADDRESS,
|
|
33281
|
+
enabled: false
|
|
33282
|
+
})
|
|
33283
|
+
]);
|
|
33284
|
+
if (registration.enabled && dataAccess.enabled && registration.asset.toLowerCase() !== dataAccess.asset.toLowerCase()) {
|
|
33285
|
+
throw new Error(
|
|
33286
|
+
`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.`
|
|
33287
|
+
);
|
|
33288
|
+
}
|
|
33289
|
+
const asset = registration.enabled ? registration.asset : dataAccess.enabled ? dataAccess.asset : ZERO_ADDRESS;
|
|
33290
|
+
return {
|
|
33291
|
+
asset,
|
|
33292
|
+
registrationFee: registration.enabled ? registration.amount : 0n,
|
|
33293
|
+
dataAccessFee: dataAccess.enabled ? dataAccess.amount : 0n,
|
|
33294
|
+
registrationEnabled: registration.enabled,
|
|
33295
|
+
dataAccessEnabled: dataAccess.enabled,
|
|
33296
|
+
registrationPayee: registration.enabled ? registration.payee : ZERO_ADDRESS,
|
|
33297
|
+
dataAccessPayee: dataAccess.enabled ? dataAccess.payee : ZERO_ADDRESS
|
|
33137
33298
|
};
|
|
33138
33299
|
}
|
|
33139
33300
|
|
|
@@ -33214,16 +33375,6 @@ function createGatewayClient(baseUrl) {
|
|
|
33214
33375
|
const envelope = await res.json();
|
|
33215
33376
|
return envelope.data;
|
|
33216
33377
|
}
|
|
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
33378
|
function getMutationId(body, key) {
|
|
33228
33379
|
const value = body[key] ?? body["id"];
|
|
33229
33380
|
return typeof value === "string" ? value : void 0;
|
|
@@ -33273,30 +33424,34 @@ function createGatewayClient(baseUrl) {
|
|
|
33273
33424
|
}
|
|
33274
33425
|
return unwrapEnvelope(res);
|
|
33275
33426
|
},
|
|
33276
|
-
async
|
|
33277
|
-
const res = await fetch(`${base}/v1/
|
|
33427
|
+
async getDataPoint(dataPointId) {
|
|
33428
|
+
const res = await fetch(`${base}/v1/data/${dataPointId}`);
|
|
33278
33429
|
if (res.status === 404) return null;
|
|
33279
33430
|
if (!res.ok) {
|
|
33280
33431
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33281
33432
|
}
|
|
33282
|
-
return
|
|
33433
|
+
return unwrapEnvelope(res);
|
|
33283
33434
|
},
|
|
33284
|
-
async
|
|
33435
|
+
async listDataPointsByOwner(owner, cursor, options) {
|
|
33285
33436
|
const params = new URLSearchParams({ user: owner });
|
|
33286
33437
|
if (cursor !== null) {
|
|
33287
|
-
params.set("
|
|
33438
|
+
params.set("cursor", cursor);
|
|
33288
33439
|
}
|
|
33289
|
-
if (options?.
|
|
33290
|
-
params.set("
|
|
33440
|
+
if (options?.since) {
|
|
33441
|
+
params.set("since", options.since);
|
|
33442
|
+
}
|
|
33443
|
+
if (options?.limit !== void 0) {
|
|
33444
|
+
params.set("limit", String(options.limit));
|
|
33291
33445
|
}
|
|
33292
|
-
const res = await fetch(`${base}/v1/
|
|
33446
|
+
const res = await fetch(`${base}/v1/data?${params.toString()}`);
|
|
33293
33447
|
if (!res.ok) {
|
|
33294
33448
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33295
33449
|
}
|
|
33296
|
-
const
|
|
33450
|
+
const envelope = await res.json();
|
|
33451
|
+
const nextCursor = envelope.pagination?.hasMore === false ? null : envelope.pagination?.nextCursor ?? null;
|
|
33297
33452
|
return {
|
|
33298
|
-
|
|
33299
|
-
cursor:
|
|
33453
|
+
dataPoints: envelope.data.dataPoints,
|
|
33454
|
+
cursor: nextCursor
|
|
33300
33455
|
};
|
|
33301
33456
|
},
|
|
33302
33457
|
async getSchema(schemaId) {
|
|
@@ -33337,8 +33492,8 @@ function createGatewayClient(baseUrl) {
|
|
|
33337
33492
|
alreadyRegistered: false
|
|
33338
33493
|
};
|
|
33339
33494
|
},
|
|
33340
|
-
async
|
|
33341
|
-
const res = await fetch(`${base}/v1/
|
|
33495
|
+
async registerBuilder(params) {
|
|
33496
|
+
const res = await fetch(`${base}/v1/builders`, {
|
|
33342
33497
|
method: "POST",
|
|
33343
33498
|
headers: {
|
|
33344
33499
|
"Content-Type": "application/json",
|
|
@@ -33346,22 +33501,57 @@ function createGatewayClient(baseUrl) {
|
|
|
33346
33501
|
},
|
|
33347
33502
|
body: JSON.stringify({
|
|
33348
33503
|
ownerAddress: params.ownerAddress,
|
|
33349
|
-
|
|
33350
|
-
|
|
33504
|
+
granteeAddress: params.granteeAddress,
|
|
33505
|
+
publicKey: params.publicKey,
|
|
33506
|
+
appUrl: params.appUrl
|
|
33351
33507
|
})
|
|
33352
33508
|
});
|
|
33353
33509
|
if (res.status === 409) {
|
|
33354
33510
|
const body2 = await res.json().catch(() => ({}));
|
|
33355
33511
|
return {
|
|
33356
|
-
|
|
33512
|
+
builderId: getMutationId(
|
|
33513
|
+
body2,
|
|
33514
|
+
"builderId"
|
|
33515
|
+
),
|
|
33516
|
+
alreadyRegistered: true
|
|
33357
33517
|
};
|
|
33358
33518
|
}
|
|
33359
33519
|
if (!res.ok) {
|
|
33360
33520
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33361
33521
|
}
|
|
33362
|
-
const body = await res.json();
|
|
33522
|
+
const body = await res.json().catch(() => ({}));
|
|
33363
33523
|
return {
|
|
33364
|
-
|
|
33524
|
+
builderId: getMutationId(body, "builderId"),
|
|
33525
|
+
alreadyRegistered: false
|
|
33526
|
+
};
|
|
33527
|
+
},
|
|
33528
|
+
async registerDataPoint(params) {
|
|
33529
|
+
const res = await fetch(`${base}/v1/data`, {
|
|
33530
|
+
method: "POST",
|
|
33531
|
+
headers: {
|
|
33532
|
+
"Content-Type": "application/json",
|
|
33533
|
+
Authorization: `Web3Signed ${params.signature}`
|
|
33534
|
+
},
|
|
33535
|
+
body: JSON.stringify({
|
|
33536
|
+
ownerAddress: params.ownerAddress,
|
|
33537
|
+
scope: params.scope,
|
|
33538
|
+
dataHash: params.dataHash,
|
|
33539
|
+
metadataHash: params.metadataHash,
|
|
33540
|
+
expectedVersion: params.expectedVersion
|
|
33541
|
+
})
|
|
33542
|
+
});
|
|
33543
|
+
if (!res.ok) {
|
|
33544
|
+
const body2 = await res.json().catch(() => ({}));
|
|
33545
|
+
const detail = body2.error ?? res.statusText;
|
|
33546
|
+
throw new Error(`Gateway error: ${res.status} ${detail}`);
|
|
33547
|
+
}
|
|
33548
|
+
const body = await res.json().catch(() => ({}));
|
|
33549
|
+
return {
|
|
33550
|
+
dataPointId: getMutationId(
|
|
33551
|
+
body,
|
|
33552
|
+
"dataPointId"
|
|
33553
|
+
),
|
|
33554
|
+
expectedVersion: body.expectedVersion
|
|
33365
33555
|
};
|
|
33366
33556
|
},
|
|
33367
33557
|
async createGrant(params) {
|
|
@@ -33374,8 +33564,9 @@ function createGatewayClient(baseUrl) {
|
|
|
33374
33564
|
body: JSON.stringify({
|
|
33375
33565
|
grantorAddress: params.grantorAddress,
|
|
33376
33566
|
granteeId: params.granteeId,
|
|
33377
|
-
|
|
33378
|
-
|
|
33567
|
+
scopes: params.scopes,
|
|
33568
|
+
grantVersion: params.grantVersion,
|
|
33569
|
+
expiresAt: params.expiresAt
|
|
33379
33570
|
})
|
|
33380
33571
|
});
|
|
33381
33572
|
if (res.status === 409) {
|
|
@@ -33400,7 +33591,8 @@ function createGatewayClient(baseUrl) {
|
|
|
33400
33591
|
Authorization: `Web3Signed ${params.signature}`
|
|
33401
33592
|
},
|
|
33402
33593
|
body: JSON.stringify({
|
|
33403
|
-
grantorAddress: params.grantorAddress
|
|
33594
|
+
grantorAddress: params.grantorAddress,
|
|
33595
|
+
grantVersion: params.grantVersion
|
|
33404
33596
|
})
|
|
33405
33597
|
});
|
|
33406
33598
|
if (res.status === 409) return;
|
|
@@ -33408,21 +33600,62 @@ function createGatewayClient(baseUrl) {
|
|
|
33408
33600
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33409
33601
|
}
|
|
33410
33602
|
},
|
|
33411
|
-
async
|
|
33412
|
-
const res = await fetch(`${base}/v1/
|
|
33413
|
-
|
|
33603
|
+
async getEscrowBalance(account) {
|
|
33604
|
+
const res = await fetch(`${base}/v1/escrow/balance?account=${account}`);
|
|
33605
|
+
if (!res.ok) {
|
|
33606
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33607
|
+
}
|
|
33608
|
+
return await res.json();
|
|
33609
|
+
},
|
|
33610
|
+
async submitEscrowDeposit(params) {
|
|
33611
|
+
const res = await fetch(`${base}/v1/escrow/deposit`, {
|
|
33612
|
+
method: "POST",
|
|
33613
|
+
headers: { "Content-Type": "application/json" },
|
|
33614
|
+
body: JSON.stringify({ txHash: params.txHash })
|
|
33615
|
+
});
|
|
33616
|
+
if (res.status !== 200 && res.status !== 202) {
|
|
33617
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33618
|
+
}
|
|
33619
|
+
return await res.json();
|
|
33620
|
+
},
|
|
33621
|
+
async payForOperation(params) {
|
|
33622
|
+
const body = {
|
|
33623
|
+
payerAddress: params.payerAddress,
|
|
33624
|
+
opType: params.opType,
|
|
33625
|
+
opId: params.opId,
|
|
33626
|
+
asset: params.asset,
|
|
33627
|
+
amount: params.amount,
|
|
33628
|
+
paymentNonce: params.paymentNonce
|
|
33629
|
+
};
|
|
33630
|
+
if (params.accessRecord) {
|
|
33631
|
+
body["accessRecord"] = params.accessRecord;
|
|
33632
|
+
}
|
|
33633
|
+
const res = await fetch(`${base}/v1/escrow/pay`, {
|
|
33634
|
+
method: "POST",
|
|
33414
33635
|
headers: {
|
|
33415
33636
|
"Content-Type": "application/json",
|
|
33416
33637
|
Authorization: `Web3Signed ${params.signature}`
|
|
33417
33638
|
},
|
|
33418
|
-
body: JSON.stringify(
|
|
33419
|
-
|
|
33420
|
-
|
|
33639
|
+
body: JSON.stringify(body)
|
|
33640
|
+
});
|
|
33641
|
+
if (!res.ok) {
|
|
33642
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33643
|
+
}
|
|
33644
|
+
return await res.json();
|
|
33645
|
+
},
|
|
33646
|
+
async settle(params) {
|
|
33647
|
+
const res = await fetch(`${base}/v1/settle`, {
|
|
33648
|
+
method: "POST",
|
|
33649
|
+
headers: { "Content-Type": "application/json" },
|
|
33650
|
+
// The gateway accepts an empty body; only `limit` is recognised.
|
|
33651
|
+
// Always send a JSON body so the gateway's req.body shape parse
|
|
33652
|
+
// doesn't have to deal with an undefined.
|
|
33653
|
+
body: JSON.stringify(params ?? {})
|
|
33421
33654
|
});
|
|
33422
|
-
if (res.status === 409) return;
|
|
33423
33655
|
if (!res.ok) {
|
|
33424
33656
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33425
33657
|
}
|
|
33658
|
+
return await res.json();
|
|
33426
33659
|
}
|
|
33427
33660
|
};
|
|
33428
33661
|
}
|
|
@@ -33491,6 +33724,7 @@ async function parsePSError(response) {
|
|
|
33491
33724
|
}
|
|
33492
33725
|
export {
|
|
33493
33726
|
ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
|
|
33727
|
+
ADD_DATA_TYPES,
|
|
33494
33728
|
AccountPersonalServerLiteOwnerBindingError,
|
|
33495
33729
|
AccountPersonalServerRegistrationError,
|
|
33496
33730
|
BUILDER_REGISTRATION_TYPES,
|
|
@@ -33500,12 +33734,15 @@ export {
|
|
|
33500
33734
|
CallbackStorage,
|
|
33501
33735
|
ContractFactory,
|
|
33502
33736
|
ContractNotFoundError,
|
|
33737
|
+
DATA_REGISTRY_STATUS_ABI,
|
|
33503
33738
|
DataFileEnvelopeSchema,
|
|
33739
|
+
DataPointStatus,
|
|
33504
33740
|
DropboxStorage,
|
|
33505
33741
|
ECIESError,
|
|
33742
|
+
ESCROW_DEPOSIT_ABI,
|
|
33506
33743
|
ExpiredTokenError,
|
|
33507
|
-
|
|
33508
|
-
|
|
33744
|
+
FEE_REGISTRY_ABI,
|
|
33745
|
+
GENERIC_PAYMENT_TYPES,
|
|
33509
33746
|
GRANT_REGISTRATION_TYPES,
|
|
33510
33747
|
GRANT_REVOCATION_TYPES,
|
|
33511
33748
|
GoogleDriveStorage,
|
|
@@ -33516,6 +33753,7 @@ export {
|
|
|
33516
33753
|
IpfsStorage,
|
|
33517
33754
|
MASTER_KEY_MESSAGE,
|
|
33518
33755
|
MissingAuthError,
|
|
33756
|
+
NATIVE_VANA_ASSET,
|
|
33519
33757
|
NetworkError,
|
|
33520
33758
|
NodeECIESUint8Provider as NodeECIESProvider,
|
|
33521
33759
|
NodePlatformAdapter,
|
|
@@ -33533,6 +33771,8 @@ export {
|
|
|
33533
33771
|
PersonalServerError,
|
|
33534
33772
|
PinataStorage,
|
|
33535
33773
|
R2Storage,
|
|
33774
|
+
RECORD_DATA_ACCESS_TYPES,
|
|
33775
|
+
REGISTRATION_KIND_FOR_OP,
|
|
33536
33776
|
ReadOnlyError,
|
|
33537
33777
|
RelayerError,
|
|
33538
33778
|
SERVER_REGISTRATION_TYPES,
|
|
@@ -33547,10 +33787,14 @@ export {
|
|
|
33547
33787
|
VanaError,
|
|
33548
33788
|
VanaStorage,
|
|
33549
33789
|
assertValidPkceVerifier,
|
|
33790
|
+
buildDepositNativeRequest,
|
|
33791
|
+
buildDepositTokenRequest,
|
|
33792
|
+
buildMarkDataPointUnavailableRequest,
|
|
33550
33793
|
buildPersonalServerLiteOwnerBindingMessage,
|
|
33551
33794
|
buildPersonalServerLiteOwnerBindingSignature,
|
|
33552
33795
|
buildPersonalServerRegistrationSignature,
|
|
33553
33796
|
buildPersonalServerRegistrationTypedData,
|
|
33797
|
+
buildSetDataPointStatusRequest,
|
|
33554
33798
|
buildWeb3SignedHeader,
|
|
33555
33799
|
builderRegistrationDomain,
|
|
33556
33800
|
chains,
|
|
@@ -33568,14 +33812,19 @@ export {
|
|
|
33568
33812
|
createVanaStorageProvider,
|
|
33569
33813
|
createViemPersonalServerLiteOwnerBindingSigner,
|
|
33570
33814
|
createViemPersonalServerRegistrationSigner,
|
|
33815
|
+
dataRegistryContractAddress,
|
|
33816
|
+
dataRegistryDomain,
|
|
33571
33817
|
decryptWithPassword,
|
|
33572
33818
|
deriveMasterKey,
|
|
33573
33819
|
deriveScopeKey,
|
|
33574
33820
|
deserializeECIES,
|
|
33575
33821
|
detectPlatform,
|
|
33822
|
+
encodeDepositNativeData,
|
|
33823
|
+
encodeDepositTokenData,
|
|
33824
|
+
encodeSetDataPointStatusData,
|
|
33576
33825
|
encryptWithPassword,
|
|
33577
|
-
|
|
33578
|
-
|
|
33826
|
+
escrowContractAddress,
|
|
33827
|
+
escrowPaymentDomain,
|
|
33579
33828
|
generatePkceVerifier,
|
|
33580
33829
|
getAbi,
|
|
33581
33830
|
getAllChains,
|
|
@@ -33583,6 +33832,8 @@ export {
|
|
|
33583
33832
|
getContractAddress,
|
|
33584
33833
|
getContractController,
|
|
33585
33834
|
getContractInfo,
|
|
33835
|
+
getFee,
|
|
33836
|
+
getOpFee,
|
|
33586
33837
|
getPlatformCapabilities,
|
|
33587
33838
|
getServiceEndpoints,
|
|
33588
33839
|
grantRegistrationDomain,
|
|
@@ -33594,7 +33845,6 @@ export {
|
|
|
33594
33845
|
moksha,
|
|
33595
33846
|
mokshaServices,
|
|
33596
33847
|
mokshaTestnet2 as mokshaTestnet,
|
|
33597
|
-
parseGrantRegistrationPayload,
|
|
33598
33848
|
parsePSError,
|
|
33599
33849
|
parseScope,
|
|
33600
33850
|
parseWeb3SignedHeader,
|