@opendatalabs/vana-sdk 3.3.0 → 3.4.1-canary.ba2cfd7
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 +5 -3
- package/dist/index.browser.js +359 -75
- package/dist/index.browser.js.map +3 -3
- package/dist/index.node.cjs +375 -76
- package/dist/index.node.cjs.map +4 -4
- package/dist/index.node.d.ts +5 -3
- package/dist/index.node.js +359 -75
- package/dist/index.node.js.map +3 -3
- package/dist/protocol/eip712.cjs +58 -3
- package/dist/protocol/eip712.cjs.map +1 -1
- package/dist/protocol/eip712.d.ts +98 -6
- package/dist/protocol/eip712.js +52 -3
- 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 +136 -9
- package/dist/protocol/gateway.cjs.map +1 -1
- package/dist/protocol/gateway.d.ts +227 -17
- package/dist/protocol/gateway.js +136 -9
- 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.cjs
CHANGED
|
@@ -1174,6 +1174,7 @@ var init_browser2 = __esm({
|
|
|
1174
1174
|
var index_node_exports = {};
|
|
1175
1175
|
__export(index_node_exports, {
|
|
1176
1176
|
ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT: () => ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
|
|
1177
|
+
ADD_DATA_TYPES: () => ADD_DATA_TYPES,
|
|
1177
1178
|
AccountPersonalServerLiteOwnerBindingError: () => AccountPersonalServerLiteOwnerBindingError,
|
|
1178
1179
|
AccountPersonalServerRegistrationError: () => AccountPersonalServerRegistrationError,
|
|
1179
1180
|
BUILDER_REGISTRATION_TYPES: () => BUILDER_REGISTRATION_TYPES,
|
|
@@ -1186,9 +1187,12 @@ __export(index_node_exports, {
|
|
|
1186
1187
|
DataFileEnvelopeSchema: () => DataFileEnvelopeSchema,
|
|
1187
1188
|
DropboxStorage: () => DropboxStorage,
|
|
1188
1189
|
ECIESError: () => ECIESError,
|
|
1190
|
+
ESCROW_DEPOSIT_ABI: () => ESCROW_DEPOSIT_ABI,
|
|
1189
1191
|
ExpiredTokenError: () => ExpiredTokenError,
|
|
1192
|
+
FEE_REGISTRY_ABI: () => FEE_REGISTRY_ABI,
|
|
1190
1193
|
FILE_DELETION_TYPES: () => FILE_DELETION_TYPES,
|
|
1191
1194
|
FILE_REGISTRATION_TYPES: () => FILE_REGISTRATION_TYPES,
|
|
1195
|
+
GENERIC_PAYMENT_TYPES: () => GENERIC_PAYMENT_TYPES,
|
|
1192
1196
|
GRANT_REGISTRATION_TYPES: () => GRANT_REGISTRATION_TYPES,
|
|
1193
1197
|
GRANT_REVOCATION_TYPES: () => GRANT_REVOCATION_TYPES,
|
|
1194
1198
|
GoogleDriveStorage: () => GoogleDriveStorage,
|
|
@@ -1199,6 +1203,7 @@ __export(index_node_exports, {
|
|
|
1199
1203
|
IpfsStorage: () => IpfsStorage,
|
|
1200
1204
|
MASTER_KEY_MESSAGE: () => MASTER_KEY_MESSAGE,
|
|
1201
1205
|
MissingAuthError: () => MissingAuthError,
|
|
1206
|
+
NATIVE_VANA_ASSET: () => NATIVE_VANA_ASSET,
|
|
1202
1207
|
NetworkError: () => NetworkError,
|
|
1203
1208
|
NodeECIESProvider: () => NodeECIESUint8Provider,
|
|
1204
1209
|
NodePlatformAdapter: () => NodePlatformAdapter,
|
|
@@ -1216,6 +1221,8 @@ __export(index_node_exports, {
|
|
|
1216
1221
|
PersonalServerError: () => PersonalServerError,
|
|
1217
1222
|
PinataStorage: () => PinataStorage,
|
|
1218
1223
|
R2Storage: () => R2Storage,
|
|
1224
|
+
RECORD_DATA_ACCESS_TYPES: () => RECORD_DATA_ACCESS_TYPES,
|
|
1225
|
+
REGISTRATION_KIND_FOR_OP: () => REGISTRATION_KIND_FOR_OP,
|
|
1219
1226
|
ReadOnlyError: () => ReadOnlyError,
|
|
1220
1227
|
RelayerError: () => RelayerError,
|
|
1221
1228
|
SERVER_REGISTRATION_TYPES: () => SERVER_REGISTRATION_TYPES,
|
|
@@ -1230,6 +1237,8 @@ __export(index_node_exports, {
|
|
|
1230
1237
|
VanaError: () => VanaError,
|
|
1231
1238
|
VanaStorage: () => VanaStorage,
|
|
1232
1239
|
assertValidPkceVerifier: () => assertValidPkceVerifier,
|
|
1240
|
+
buildDepositNativeRequest: () => buildDepositNativeRequest,
|
|
1241
|
+
buildDepositTokenRequest: () => buildDepositTokenRequest,
|
|
1233
1242
|
buildPersonalServerLiteOwnerBindingMessage: () => buildPersonalServerLiteOwnerBindingMessage,
|
|
1234
1243
|
buildPersonalServerLiteOwnerBindingSignature: () => buildPersonalServerLiteOwnerBindingSignature,
|
|
1235
1244
|
buildPersonalServerRegistrationSignature: () => buildPersonalServerRegistrationSignature,
|
|
@@ -1251,12 +1260,17 @@ __export(index_node_exports, {
|
|
|
1251
1260
|
createVanaStorageProvider: () => createVanaStorageProvider,
|
|
1252
1261
|
createViemPersonalServerLiteOwnerBindingSigner: () => createViemPersonalServerLiteOwnerBindingSigner,
|
|
1253
1262
|
createViemPersonalServerRegistrationSigner: () => createViemPersonalServerRegistrationSigner,
|
|
1263
|
+
dataRegistryDomain: () => dataRegistryDomain,
|
|
1254
1264
|
decryptWithPassword: () => decryptWithPassword,
|
|
1255
1265
|
deriveMasterKey: () => deriveMasterKey,
|
|
1256
1266
|
deriveScopeKey: () => deriveScopeKey,
|
|
1257
1267
|
deserializeECIES: () => deserializeECIES,
|
|
1258
1268
|
detectPlatform: () => detectPlatform,
|
|
1269
|
+
encodeDepositNativeData: () => encodeDepositNativeData,
|
|
1270
|
+
encodeDepositTokenData: () => encodeDepositTokenData,
|
|
1259
1271
|
encryptWithPassword: () => encryptWithPassword,
|
|
1272
|
+
escrowContractAddress: () => escrowContractAddress,
|
|
1273
|
+
escrowPaymentDomain: () => escrowPaymentDomain,
|
|
1260
1274
|
fileDeletionDomain: () => fileDeletionDomain,
|
|
1261
1275
|
fileRegistrationDomain: () => fileRegistrationDomain,
|
|
1262
1276
|
generatePkceVerifier: () => generatePkceVerifier,
|
|
@@ -1266,6 +1280,8 @@ __export(index_node_exports, {
|
|
|
1266
1280
|
getContractAddress: () => getContractAddress,
|
|
1267
1281
|
getContractController: () => getContractController,
|
|
1268
1282
|
getContractInfo: () => getContractInfo,
|
|
1283
|
+
getFee: () => getFee,
|
|
1284
|
+
getOpFee: () => getOpFee,
|
|
1269
1285
|
getPlatformCapabilities: () => getPlatformCapabilities,
|
|
1270
1286
|
getServiceEndpoints: () => getServiceEndpoints,
|
|
1271
1287
|
grantRegistrationDomain: () => grantRegistrationDomain,
|
|
@@ -1277,7 +1293,6 @@ __export(index_node_exports, {
|
|
|
1277
1293
|
moksha: () => moksha,
|
|
1278
1294
|
mokshaServices: () => mokshaServices,
|
|
1279
1295
|
mokshaTestnet: () => mokshaTestnet2,
|
|
1280
|
-
parseGrantRegistrationPayload: () => parseGrantRegistrationPayload,
|
|
1281
1296
|
parsePSError: () => parsePSError,
|
|
1282
1297
|
parseScope: () => parseScope,
|
|
1283
1298
|
parseWeb3SignedHeader: () => parseWeb3SignedHeader,
|
|
@@ -32649,6 +32664,7 @@ function formatOAuthError(body, status) {
|
|
|
32649
32664
|
// src/protocol/eip712.ts
|
|
32650
32665
|
var DOMAIN_NAME = "Vana Data Portability";
|
|
32651
32666
|
var DOMAIN_VERSION = "1";
|
|
32667
|
+
var NATIVE_VANA_ASSET = "0x0000000000000000000000000000000000000000";
|
|
32652
32668
|
function buildDomain(chainId, verifyingContract) {
|
|
32653
32669
|
return {
|
|
32654
32670
|
name: DOMAIN_NAME,
|
|
@@ -32663,6 +32679,12 @@ function fileRegistrationDomain(config) {
|
|
|
32663
32679
|
config.contracts.dataRegistry
|
|
32664
32680
|
);
|
|
32665
32681
|
}
|
|
32682
|
+
function dataRegistryDomain(config) {
|
|
32683
|
+
return buildDomain(
|
|
32684
|
+
config.chainId,
|
|
32685
|
+
config.contracts.dataRegistry
|
|
32686
|
+
);
|
|
32687
|
+
}
|
|
32666
32688
|
function fileDeletionDomain(config) {
|
|
32667
32689
|
return buildDomain(
|
|
32668
32690
|
config.chainId,
|
|
@@ -32693,6 +32715,12 @@ function builderRegistrationDomain(config) {
|
|
|
32693
32715
|
config.contracts.dataPortabilityGrantees
|
|
32694
32716
|
);
|
|
32695
32717
|
}
|
|
32718
|
+
function escrowPaymentDomain(config) {
|
|
32719
|
+
return buildDomain(
|
|
32720
|
+
config.chainId,
|
|
32721
|
+
config.contracts.dataPortabilityEscrow
|
|
32722
|
+
);
|
|
32723
|
+
}
|
|
32696
32724
|
var FILE_REGISTRATION_TYPES = {
|
|
32697
32725
|
FileRegistration: [
|
|
32698
32726
|
{ name: "ownerAddress", type: "address" },
|
|
@@ -32710,14 +32738,16 @@ var GRANT_REGISTRATION_TYPES = {
|
|
|
32710
32738
|
GrantRegistration: [
|
|
32711
32739
|
{ name: "grantorAddress", type: "address" },
|
|
32712
32740
|
{ name: "granteeId", type: "bytes32" },
|
|
32713
|
-
{ name: "
|
|
32714
|
-
{ name: "
|
|
32741
|
+
{ name: "scopes", type: "string[]" },
|
|
32742
|
+
{ name: "grantVersion", type: "uint256" },
|
|
32743
|
+
{ name: "expiresAt", type: "uint256" }
|
|
32715
32744
|
]
|
|
32716
32745
|
};
|
|
32717
32746
|
var GRANT_REVOCATION_TYPES = {
|
|
32718
32747
|
GrantRevocation: [
|
|
32719
32748
|
{ name: "grantorAddress", type: "address" },
|
|
32720
|
-
{ name: "grantId", type: "bytes32" }
|
|
32749
|
+
{ name: "grantId", type: "bytes32" },
|
|
32750
|
+
{ name: "grantVersion", type: "uint256" }
|
|
32721
32751
|
]
|
|
32722
32752
|
};
|
|
32723
32753
|
var SERVER_REGISTRATION_TYPES = {
|
|
@@ -32736,6 +32766,34 @@ var BUILDER_REGISTRATION_TYPES = {
|
|
|
32736
32766
|
{ name: "appUrl", type: "string" }
|
|
32737
32767
|
]
|
|
32738
32768
|
};
|
|
32769
|
+
var GENERIC_PAYMENT_TYPES = {
|
|
32770
|
+
GenericPayment: [
|
|
32771
|
+
{ name: "payerAddress", type: "address" },
|
|
32772
|
+
{ name: "opType", type: "string" },
|
|
32773
|
+
{ name: "opId", type: "bytes32" },
|
|
32774
|
+
{ name: "asset", type: "address" },
|
|
32775
|
+
{ name: "amount", type: "uint256" },
|
|
32776
|
+
{ name: "paymentNonce", type: "uint256" }
|
|
32777
|
+
]
|
|
32778
|
+
};
|
|
32779
|
+
var ADD_DATA_TYPES = {
|
|
32780
|
+
AddData: [
|
|
32781
|
+
{ name: "ownerAddress", type: "address" },
|
|
32782
|
+
{ name: "scope", type: "string" },
|
|
32783
|
+
{ name: "dataHash", type: "bytes32" },
|
|
32784
|
+
{ name: "metadataHash", type: "bytes32" },
|
|
32785
|
+
{ name: "expectedVersion", type: "uint256" }
|
|
32786
|
+
]
|
|
32787
|
+
};
|
|
32788
|
+
var RECORD_DATA_ACCESS_TYPES = {
|
|
32789
|
+
RecordDataAccess: [
|
|
32790
|
+
{ name: "ownerAddress", type: "address" },
|
|
32791
|
+
{ name: "scope", type: "string" },
|
|
32792
|
+
{ name: "version", type: "uint256" },
|
|
32793
|
+
{ name: "accessor", type: "address" },
|
|
32794
|
+
{ name: "recordId", type: "bytes32" }
|
|
32795
|
+
]
|
|
32796
|
+
};
|
|
32739
32797
|
|
|
32740
32798
|
// src/protocol/personal-server-registration.ts
|
|
32741
32799
|
var import_viem14 = require("viem");
|
|
@@ -33173,67 +33231,31 @@ function isDataPortabilityGatewayConfig(value) {
|
|
|
33173
33231
|
return false;
|
|
33174
33232
|
}
|
|
33175
33233
|
const c = contracts;
|
|
33176
|
-
return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]);
|
|
33177
|
-
}
|
|
33178
|
-
function parseGrantRegistrationPayload(grant) {
|
|
33179
|
-
let parsed;
|
|
33180
|
-
try {
|
|
33181
|
-
parsed = JSON.parse(grant);
|
|
33182
|
-
} catch {
|
|
33183
|
-
return null;
|
|
33184
|
-
}
|
|
33185
|
-
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
33186
|
-
return null;
|
|
33187
|
-
}
|
|
33188
|
-
const value = parsed;
|
|
33189
|
-
if (!Array.isArray(value["scopes"]) || value["scopes"].length === 0) {
|
|
33190
|
-
return null;
|
|
33191
|
-
}
|
|
33192
|
-
if (!value["scopes"].every((scope) => typeof scope === "string")) {
|
|
33193
|
-
return null;
|
|
33194
|
-
}
|
|
33195
|
-
if (typeof value["expiresAt"] !== "number" || !Number.isFinite(value["expiresAt"])) {
|
|
33196
|
-
return null;
|
|
33197
|
-
}
|
|
33198
|
-
if (value["user"] !== void 0 && !isHexString(value["user"])) {
|
|
33199
|
-
return null;
|
|
33200
|
-
}
|
|
33201
|
-
if (value["builder"] !== void 0 && !isHexString(value["builder"])) {
|
|
33202
|
-
return null;
|
|
33203
|
-
}
|
|
33204
|
-
if (value["nonce"] !== void 0 && (typeof value["nonce"] !== "number" || !Number.isFinite(value["nonce"]))) {
|
|
33205
|
-
return null;
|
|
33206
|
-
}
|
|
33207
|
-
return {
|
|
33208
|
-
user: value["user"],
|
|
33209
|
-
builder: value["builder"],
|
|
33210
|
-
scopes: value["scopes"],
|
|
33211
|
-
expiresAt: value["expiresAt"],
|
|
33212
|
-
nonce: value["nonce"]
|
|
33213
|
-
};
|
|
33234
|
+
return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]) && isHexString(c["dataPortabilityEscrow"]) && isHexString(c["feeRegistry"]);
|
|
33214
33235
|
}
|
|
33215
|
-
function
|
|
33236
|
+
function toUint256(value) {
|
|
33216
33237
|
try {
|
|
33217
|
-
const
|
|
33218
|
-
return
|
|
33219
|
-
|
|
33220
|
-
display: values.map((fileId) => fileId.toString())
|
|
33221
|
-
};
|
|
33238
|
+
const big = typeof value === "bigint" ? value : BigInt(value);
|
|
33239
|
+
if (big < 0n) return null;
|
|
33240
|
+
return big;
|
|
33222
33241
|
} catch {
|
|
33223
33242
|
return null;
|
|
33224
33243
|
}
|
|
33225
33244
|
}
|
|
33226
33245
|
async function verifyGrantRegistration(input) {
|
|
33227
|
-
|
|
33228
|
-
|
|
33229
|
-
|
|
33230
|
-
|
|
33231
|
-
|
|
33232
|
-
};
|
|
33246
|
+
if (!Array.isArray(input.scopes) || input.scopes.length === 0) {
|
|
33247
|
+
return { valid: false, error: "scopes must be a non-empty array" };
|
|
33248
|
+
}
|
|
33249
|
+
if (!input.scopes.every((scope) => typeof scope === "string")) {
|
|
33250
|
+
return { valid: false, error: "scopes must contain only strings" };
|
|
33233
33251
|
}
|
|
33234
|
-
const
|
|
33235
|
-
if (
|
|
33236
|
-
return { valid: false, error: "
|
|
33252
|
+
const grantVersion = toUint256(input.grantVersion);
|
|
33253
|
+
if (grantVersion === null || grantVersion < 1n) {
|
|
33254
|
+
return { valid: false, error: "grantVersion must be a uint256 >= 1" };
|
|
33255
|
+
}
|
|
33256
|
+
const expiresAt = toUint256(input.expiresAt);
|
|
33257
|
+
if (expiresAt === null) {
|
|
33258
|
+
return { valid: false, error: "expiresAt must be a non-negative uint256" };
|
|
33237
33259
|
}
|
|
33238
33260
|
let valid;
|
|
33239
33261
|
try {
|
|
@@ -33245,8 +33267,9 @@ async function verifyGrantRegistration(input) {
|
|
|
33245
33267
|
message: {
|
|
33246
33268
|
grantorAddress: input.grantorAddress,
|
|
33247
33269
|
granteeId: input.granteeId,
|
|
33248
|
-
|
|
33249
|
-
|
|
33270
|
+
scopes: input.scopes,
|
|
33271
|
+
grantVersion,
|
|
33272
|
+
expiresAt
|
|
33250
33273
|
},
|
|
33251
33274
|
signature: input.signature
|
|
33252
33275
|
});
|
|
@@ -33257,19 +33280,153 @@ async function verifyGrantRegistration(input) {
|
|
|
33257
33280
|
return { valid: false, error: "Grant signature does not match grantor" };
|
|
33258
33281
|
}
|
|
33259
33282
|
const nowSeconds = input.nowSeconds ?? Math.floor(Date.now() / 1e3);
|
|
33260
|
-
if (
|
|
33283
|
+
if (expiresAt > 0n && expiresAt < BigInt(nowSeconds)) {
|
|
33261
33284
|
return { valid: false, error: "Grant has expired" };
|
|
33262
33285
|
}
|
|
33263
|
-
if (payload.user !== void 0 && payload.user.toLowerCase() !== input.grantorAddress.toLowerCase()) {
|
|
33264
|
-
return { valid: false, error: "Grant user does not match grantorAddress" };
|
|
33265
|
-
}
|
|
33266
33286
|
return {
|
|
33267
33287
|
valid: true,
|
|
33268
33288
|
grantorAddress: input.grantorAddress,
|
|
33269
33289
|
granteeId: input.granteeId,
|
|
33270
|
-
|
|
33271
|
-
|
|
33272
|
-
|
|
33290
|
+
scopes: input.scopes,
|
|
33291
|
+
grantVersion: grantVersion.toString(),
|
|
33292
|
+
expiresAt: expiresAt.toString()
|
|
33293
|
+
};
|
|
33294
|
+
}
|
|
33295
|
+
|
|
33296
|
+
// src/protocol/escrow-deposit.ts
|
|
33297
|
+
var import_viem18 = require("viem");
|
|
33298
|
+
var ESCROW_DEPOSIT_ABI = [
|
|
33299
|
+
{
|
|
33300
|
+
type: "function",
|
|
33301
|
+
name: "depositNative",
|
|
33302
|
+
stateMutability: "payable",
|
|
33303
|
+
inputs: [{ name: "account", type: "address" }],
|
|
33304
|
+
outputs: []
|
|
33305
|
+
},
|
|
33306
|
+
{
|
|
33307
|
+
type: "function",
|
|
33308
|
+
name: "depositToken",
|
|
33309
|
+
stateMutability: "nonpayable",
|
|
33310
|
+
inputs: [
|
|
33311
|
+
{ name: "account", type: "address" },
|
|
33312
|
+
{ name: "token", type: "address" },
|
|
33313
|
+
{ name: "amount", type: "uint256" }
|
|
33314
|
+
],
|
|
33315
|
+
outputs: []
|
|
33316
|
+
}
|
|
33317
|
+
];
|
|
33318
|
+
function escrowContractAddress(config) {
|
|
33319
|
+
return config.contracts.dataPortabilityEscrow;
|
|
33320
|
+
}
|
|
33321
|
+
function encodeDepositNativeData(input) {
|
|
33322
|
+
return (0, import_viem18.encodeFunctionData)({
|
|
33323
|
+
abi: ESCROW_DEPOSIT_ABI,
|
|
33324
|
+
functionName: "depositNative",
|
|
33325
|
+
args: [input.account]
|
|
33326
|
+
});
|
|
33327
|
+
}
|
|
33328
|
+
function encodeDepositTokenData(input) {
|
|
33329
|
+
return (0, import_viem18.encodeFunctionData)({
|
|
33330
|
+
abi: ESCROW_DEPOSIT_ABI,
|
|
33331
|
+
functionName: "depositToken",
|
|
33332
|
+
args: [input.account, input.token, input.amount]
|
|
33333
|
+
});
|
|
33334
|
+
}
|
|
33335
|
+
function buildDepositNativeRequest(config, input) {
|
|
33336
|
+
return {
|
|
33337
|
+
to: escrowContractAddress(config),
|
|
33338
|
+
data: encodeDepositNativeData({ account: input.account }),
|
|
33339
|
+
value: input.amount
|
|
33340
|
+
};
|
|
33341
|
+
}
|
|
33342
|
+
function buildDepositTokenRequest(config, input) {
|
|
33343
|
+
return {
|
|
33344
|
+
to: escrowContractAddress(config),
|
|
33345
|
+
data: encodeDepositTokenData(input)
|
|
33346
|
+
};
|
|
33347
|
+
}
|
|
33348
|
+
|
|
33349
|
+
// src/protocol/fee-registry.ts
|
|
33350
|
+
var import_viem19 = require("viem");
|
|
33351
|
+
var FEE_REGISTRY_ABI = (0, import_viem19.parseAbi)([
|
|
33352
|
+
"struct Fee { uint256 amount; address asset; address payee; bool enabled; }",
|
|
33353
|
+
"function fees(bytes32 operation) view returns (Fee)",
|
|
33354
|
+
"function operationKey(string name) pure returns (bytes32)"
|
|
33355
|
+
]);
|
|
33356
|
+
var REGISTRATION_KIND_FOR_OP = {
|
|
33357
|
+
grant: "grant_registration",
|
|
33358
|
+
data: "data_registration",
|
|
33359
|
+
server: "server_registration",
|
|
33360
|
+
builder: "builder_registration"
|
|
33361
|
+
};
|
|
33362
|
+
function operationNameFor(kind, opts) {
|
|
33363
|
+
switch (kind) {
|
|
33364
|
+
case "grant_registration":
|
|
33365
|
+
return opts?.grantRegistrationOpName ?? "grant_registration";
|
|
33366
|
+
case "data_access":
|
|
33367
|
+
return opts?.dataAccessOpName ?? "data_access";
|
|
33368
|
+
case "data_registration":
|
|
33369
|
+
return opts?.dataRegistrationOpName ?? "data_registration";
|
|
33370
|
+
case "server_registration":
|
|
33371
|
+
return opts?.serverRegistrationOpName ?? "server_registration";
|
|
33372
|
+
case "builder_registration":
|
|
33373
|
+
return opts?.builderRegistrationOpName ?? "builder_registration";
|
|
33374
|
+
}
|
|
33375
|
+
}
|
|
33376
|
+
var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
33377
|
+
async function getFee(client, config, kind, opts) {
|
|
33378
|
+
const address = config.contracts.feeRegistry;
|
|
33379
|
+
const opName = operationNameFor(kind, opts);
|
|
33380
|
+
const opKey = await client.readContract({
|
|
33381
|
+
address,
|
|
33382
|
+
abi: FEE_REGISTRY_ABI,
|
|
33383
|
+
functionName: "operationKey",
|
|
33384
|
+
args: [opName]
|
|
33385
|
+
});
|
|
33386
|
+
const fee = await client.readContract({
|
|
33387
|
+
address,
|
|
33388
|
+
abi: FEE_REGISTRY_ABI,
|
|
33389
|
+
functionName: "fees",
|
|
33390
|
+
args: [opKey]
|
|
33391
|
+
});
|
|
33392
|
+
if (fee.enabled && fee.payee === ZERO_ADDRESS) {
|
|
33393
|
+
throw new Error(
|
|
33394
|
+
`FeeRegistry: enabled operation "${opName}" has zero-address payee \u2014 contract pre-flight rejects payouts to 0x0`
|
|
33395
|
+
);
|
|
33396
|
+
}
|
|
33397
|
+
return fee;
|
|
33398
|
+
}
|
|
33399
|
+
async function getOpFee(client, config, opType, opts) {
|
|
33400
|
+
const registrationKind = REGISTRATION_KIND_FOR_OP[opType];
|
|
33401
|
+
if (!registrationKind) {
|
|
33402
|
+
throw new Error(
|
|
33403
|
+
`getOpFee: unknown opType "${opType}" \u2014 supported types are ${Object.keys(REGISTRATION_KIND_FOR_OP).join(", ")}`
|
|
33404
|
+
);
|
|
33405
|
+
}
|
|
33406
|
+
const includeDataAccess = opType === "grant";
|
|
33407
|
+
const [registration, dataAccess] = await Promise.all([
|
|
33408
|
+
getFee(client, config, registrationKind, opts),
|
|
33409
|
+
includeDataAccess ? getFee(client, config, "data_access", opts) : Promise.resolve({
|
|
33410
|
+
amount: 0n,
|
|
33411
|
+
asset: ZERO_ADDRESS,
|
|
33412
|
+
payee: ZERO_ADDRESS,
|
|
33413
|
+
enabled: false
|
|
33414
|
+
})
|
|
33415
|
+
]);
|
|
33416
|
+
if (registration.enabled && dataAccess.enabled && registration.asset.toLowerCase() !== dataAccess.asset.toLowerCase()) {
|
|
33417
|
+
throw new Error(
|
|
33418
|
+
`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.`
|
|
33419
|
+
);
|
|
33420
|
+
}
|
|
33421
|
+
const asset = registration.enabled ? registration.asset : dataAccess.enabled ? dataAccess.asset : ZERO_ADDRESS;
|
|
33422
|
+
return {
|
|
33423
|
+
asset,
|
|
33424
|
+
registrationFee: registration.enabled ? registration.amount : 0n,
|
|
33425
|
+
dataAccessFee: dataAccess.enabled ? dataAccess.amount : 0n,
|
|
33426
|
+
registrationEnabled: registration.enabled,
|
|
33427
|
+
dataAccessEnabled: dataAccess.enabled,
|
|
33428
|
+
registrationPayee: registration.enabled ? registration.payee : ZERO_ADDRESS,
|
|
33429
|
+
dataAccessPayee: dataAccess.enabled ? dataAccess.payee : ZERO_ADDRESS
|
|
33273
33430
|
};
|
|
33274
33431
|
}
|
|
33275
33432
|
|
|
@@ -33356,7 +33513,8 @@ function createGatewayClient(baseUrl) {
|
|
|
33356
33513
|
owner: record.owner ?? record.ownerAddress ?? "",
|
|
33357
33514
|
url: record.url,
|
|
33358
33515
|
schemaId: record.schemaId,
|
|
33359
|
-
createdAt: record.createdAt ?? record.addedAt ?? ""
|
|
33516
|
+
createdAt: record.createdAt ?? record.addedAt ?? "",
|
|
33517
|
+
deletedAt: record.deletedAt ?? null
|
|
33360
33518
|
};
|
|
33361
33519
|
}
|
|
33362
33520
|
function getMutationId(body, key) {
|
|
@@ -33416,19 +33574,24 @@ function createGatewayClient(baseUrl) {
|
|
|
33416
33574
|
}
|
|
33417
33575
|
return normalizeFileRecord(await unwrapEnvelope(res));
|
|
33418
33576
|
},
|
|
33419
|
-
async listFilesSince(owner, cursor) {
|
|
33577
|
+
async listFilesSince(owner, cursor, options) {
|
|
33420
33578
|
const params = new URLSearchParams({ user: owner });
|
|
33421
33579
|
if (cursor !== null) {
|
|
33422
|
-
params.set("
|
|
33580
|
+
params.set("cursor", cursor);
|
|
33581
|
+
}
|
|
33582
|
+
if (options?.includeDeleted) {
|
|
33583
|
+
params.set("includeDeleted", "true");
|
|
33423
33584
|
}
|
|
33424
33585
|
const res = await fetch(`${base}/v1/files?${params.toString()}`);
|
|
33425
33586
|
if (!res.ok) {
|
|
33426
33587
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33427
33588
|
}
|
|
33428
|
-
const
|
|
33589
|
+
const envelope = await res.json();
|
|
33590
|
+
const { pagination } = envelope;
|
|
33591
|
+
const nextCursor = pagination?.hasMore === false ? null : pagination?.nextCursor ?? envelope.data.cursor ?? null;
|
|
33429
33592
|
return {
|
|
33430
|
-
files: data.files.map(normalizeFileRecord),
|
|
33431
|
-
cursor:
|
|
33593
|
+
files: envelope.data.files.map(normalizeFileRecord),
|
|
33594
|
+
cursor: nextCursor
|
|
33432
33595
|
};
|
|
33433
33596
|
},
|
|
33434
33597
|
async getSchema(schemaId) {
|
|
@@ -33469,6 +33632,68 @@ function createGatewayClient(baseUrl) {
|
|
|
33469
33632
|
alreadyRegistered: false
|
|
33470
33633
|
};
|
|
33471
33634
|
},
|
|
33635
|
+
async registerBuilder(params) {
|
|
33636
|
+
const res = await fetch(`${base}/v1/builders`, {
|
|
33637
|
+
method: "POST",
|
|
33638
|
+
headers: {
|
|
33639
|
+
"Content-Type": "application/json",
|
|
33640
|
+
Authorization: `Web3Signed ${params.signature}`
|
|
33641
|
+
},
|
|
33642
|
+
body: JSON.stringify({
|
|
33643
|
+
ownerAddress: params.ownerAddress,
|
|
33644
|
+
granteeAddress: params.granteeAddress,
|
|
33645
|
+
publicKey: params.publicKey,
|
|
33646
|
+
appUrl: params.appUrl
|
|
33647
|
+
})
|
|
33648
|
+
});
|
|
33649
|
+
if (res.status === 409) {
|
|
33650
|
+
const body2 = await res.json().catch(() => ({}));
|
|
33651
|
+
return {
|
|
33652
|
+
builderId: getMutationId(
|
|
33653
|
+
body2,
|
|
33654
|
+
"builderId"
|
|
33655
|
+
),
|
|
33656
|
+
alreadyRegistered: true
|
|
33657
|
+
};
|
|
33658
|
+
}
|
|
33659
|
+
if (!res.ok) {
|
|
33660
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33661
|
+
}
|
|
33662
|
+
const body = await res.json().catch(() => ({}));
|
|
33663
|
+
return {
|
|
33664
|
+
builderId: getMutationId(body, "builderId"),
|
|
33665
|
+
alreadyRegistered: false
|
|
33666
|
+
};
|
|
33667
|
+
},
|
|
33668
|
+
async registerDataPoint(params) {
|
|
33669
|
+
const res = await fetch(`${base}/v1/data`, {
|
|
33670
|
+
method: "POST",
|
|
33671
|
+
headers: {
|
|
33672
|
+
"Content-Type": "application/json",
|
|
33673
|
+
Authorization: `Web3Signed ${params.signature}`
|
|
33674
|
+
},
|
|
33675
|
+
body: JSON.stringify({
|
|
33676
|
+
ownerAddress: params.ownerAddress,
|
|
33677
|
+
scope: params.scope,
|
|
33678
|
+
dataHash: params.dataHash,
|
|
33679
|
+
metadataHash: params.metadataHash,
|
|
33680
|
+
expectedVersion: params.expectedVersion
|
|
33681
|
+
})
|
|
33682
|
+
});
|
|
33683
|
+
if (!res.ok) {
|
|
33684
|
+
const body2 = await res.json().catch(() => ({}));
|
|
33685
|
+
const detail = body2.error ?? res.statusText;
|
|
33686
|
+
throw new Error(`Gateway error: ${res.status} ${detail}`);
|
|
33687
|
+
}
|
|
33688
|
+
const body = await res.json().catch(() => ({}));
|
|
33689
|
+
return {
|
|
33690
|
+
dataPointId: getMutationId(
|
|
33691
|
+
body,
|
|
33692
|
+
"dataPointId"
|
|
33693
|
+
),
|
|
33694
|
+
expectedVersion: body.expectedVersion
|
|
33695
|
+
};
|
|
33696
|
+
},
|
|
33472
33697
|
async registerFile(params) {
|
|
33473
33698
|
const res = await fetch(`${base}/v1/files`, {
|
|
33474
33699
|
method: "POST",
|
|
@@ -33506,8 +33731,9 @@ function createGatewayClient(baseUrl) {
|
|
|
33506
33731
|
body: JSON.stringify({
|
|
33507
33732
|
grantorAddress: params.grantorAddress,
|
|
33508
33733
|
granteeId: params.granteeId,
|
|
33509
|
-
|
|
33510
|
-
|
|
33734
|
+
scopes: params.scopes,
|
|
33735
|
+
grantVersion: params.grantVersion,
|
|
33736
|
+
expiresAt: params.expiresAt
|
|
33511
33737
|
})
|
|
33512
33738
|
});
|
|
33513
33739
|
if (res.status === 409) {
|
|
@@ -33532,7 +33758,8 @@ function createGatewayClient(baseUrl) {
|
|
|
33532
33758
|
Authorization: `Web3Signed ${params.signature}`
|
|
33533
33759
|
},
|
|
33534
33760
|
body: JSON.stringify({
|
|
33535
|
-
grantorAddress: params.grantorAddress
|
|
33761
|
+
grantorAddress: params.grantorAddress,
|
|
33762
|
+
grantVersion: params.grantVersion
|
|
33536
33763
|
})
|
|
33537
33764
|
});
|
|
33538
33765
|
if (res.status === 409) return;
|
|
@@ -33540,6 +33767,63 @@ function createGatewayClient(baseUrl) {
|
|
|
33540
33767
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33541
33768
|
}
|
|
33542
33769
|
},
|
|
33770
|
+
async getEscrowBalance(account) {
|
|
33771
|
+
const res = await fetch(`${base}/v1/escrow/balance?account=${account}`);
|
|
33772
|
+
if (!res.ok) {
|
|
33773
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33774
|
+
}
|
|
33775
|
+
return await res.json();
|
|
33776
|
+
},
|
|
33777
|
+
async submitEscrowDeposit(params) {
|
|
33778
|
+
const res = await fetch(`${base}/v1/escrow/deposit`, {
|
|
33779
|
+
method: "POST",
|
|
33780
|
+
headers: { "Content-Type": "application/json" },
|
|
33781
|
+
body: JSON.stringify({ txHash: params.txHash })
|
|
33782
|
+
});
|
|
33783
|
+
if (res.status !== 200 && res.status !== 202) {
|
|
33784
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33785
|
+
}
|
|
33786
|
+
return await res.json();
|
|
33787
|
+
},
|
|
33788
|
+
async payForOperation(params) {
|
|
33789
|
+
const body = {
|
|
33790
|
+
payerAddress: params.payerAddress,
|
|
33791
|
+
opType: params.opType,
|
|
33792
|
+
opId: params.opId,
|
|
33793
|
+
asset: params.asset,
|
|
33794
|
+
amount: params.amount,
|
|
33795
|
+
paymentNonce: params.paymentNonce
|
|
33796
|
+
};
|
|
33797
|
+
if (params.accessRecord) {
|
|
33798
|
+
body["accessRecord"] = params.accessRecord;
|
|
33799
|
+
}
|
|
33800
|
+
const res = await fetch(`${base}/v1/escrow/pay`, {
|
|
33801
|
+
method: "POST",
|
|
33802
|
+
headers: {
|
|
33803
|
+
"Content-Type": "application/json",
|
|
33804
|
+
Authorization: `Web3Signed ${params.signature}`
|
|
33805
|
+
},
|
|
33806
|
+
body: JSON.stringify(body)
|
|
33807
|
+
});
|
|
33808
|
+
if (!res.ok) {
|
|
33809
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33810
|
+
}
|
|
33811
|
+
return await res.json();
|
|
33812
|
+
},
|
|
33813
|
+
async settle(params) {
|
|
33814
|
+
const res = await fetch(`${base}/v1/settle`, {
|
|
33815
|
+
method: "POST",
|
|
33816
|
+
headers: { "Content-Type": "application/json" },
|
|
33817
|
+
// The gateway accepts an empty body; only `limit` is recognised.
|
|
33818
|
+
// Always send a JSON body so the gateway's req.body shape parse
|
|
33819
|
+
// doesn't have to deal with an undefined.
|
|
33820
|
+
body: JSON.stringify(params ?? {})
|
|
33821
|
+
});
|
|
33822
|
+
if (!res.ok) {
|
|
33823
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33824
|
+
}
|
|
33825
|
+
return await res.json();
|
|
33826
|
+
},
|
|
33543
33827
|
async deleteFile(params) {
|
|
33544
33828
|
const res = await fetch(`${base}/v1/files/${params.fileId}`, {
|
|
33545
33829
|
method: "DELETE",
|
|
@@ -33624,6 +33908,7 @@ async function parsePSError(response) {
|
|
|
33624
33908
|
// Annotate the CommonJS export names for ESM import in node:
|
|
33625
33909
|
0 && (module.exports = {
|
|
33626
33910
|
ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
|
|
33911
|
+
ADD_DATA_TYPES,
|
|
33627
33912
|
AccountPersonalServerLiteOwnerBindingError,
|
|
33628
33913
|
AccountPersonalServerRegistrationError,
|
|
33629
33914
|
BUILDER_REGISTRATION_TYPES,
|
|
@@ -33636,9 +33921,12 @@ async function parsePSError(response) {
|
|
|
33636
33921
|
DataFileEnvelopeSchema,
|
|
33637
33922
|
DropboxStorage,
|
|
33638
33923
|
ECIESError,
|
|
33924
|
+
ESCROW_DEPOSIT_ABI,
|
|
33639
33925
|
ExpiredTokenError,
|
|
33926
|
+
FEE_REGISTRY_ABI,
|
|
33640
33927
|
FILE_DELETION_TYPES,
|
|
33641
33928
|
FILE_REGISTRATION_TYPES,
|
|
33929
|
+
GENERIC_PAYMENT_TYPES,
|
|
33642
33930
|
GRANT_REGISTRATION_TYPES,
|
|
33643
33931
|
GRANT_REVOCATION_TYPES,
|
|
33644
33932
|
GoogleDriveStorage,
|
|
@@ -33649,6 +33937,7 @@ async function parsePSError(response) {
|
|
|
33649
33937
|
IpfsStorage,
|
|
33650
33938
|
MASTER_KEY_MESSAGE,
|
|
33651
33939
|
MissingAuthError,
|
|
33940
|
+
NATIVE_VANA_ASSET,
|
|
33652
33941
|
NetworkError,
|
|
33653
33942
|
NodeECIESProvider,
|
|
33654
33943
|
NodePlatformAdapter,
|
|
@@ -33666,6 +33955,8 @@ async function parsePSError(response) {
|
|
|
33666
33955
|
PersonalServerError,
|
|
33667
33956
|
PinataStorage,
|
|
33668
33957
|
R2Storage,
|
|
33958
|
+
RECORD_DATA_ACCESS_TYPES,
|
|
33959
|
+
REGISTRATION_KIND_FOR_OP,
|
|
33669
33960
|
ReadOnlyError,
|
|
33670
33961
|
RelayerError,
|
|
33671
33962
|
SERVER_REGISTRATION_TYPES,
|
|
@@ -33680,6 +33971,8 @@ async function parsePSError(response) {
|
|
|
33680
33971
|
VanaError,
|
|
33681
33972
|
VanaStorage,
|
|
33682
33973
|
assertValidPkceVerifier,
|
|
33974
|
+
buildDepositNativeRequest,
|
|
33975
|
+
buildDepositTokenRequest,
|
|
33683
33976
|
buildPersonalServerLiteOwnerBindingMessage,
|
|
33684
33977
|
buildPersonalServerLiteOwnerBindingSignature,
|
|
33685
33978
|
buildPersonalServerRegistrationSignature,
|
|
@@ -33701,12 +33994,17 @@ async function parsePSError(response) {
|
|
|
33701
33994
|
createVanaStorageProvider,
|
|
33702
33995
|
createViemPersonalServerLiteOwnerBindingSigner,
|
|
33703
33996
|
createViemPersonalServerRegistrationSigner,
|
|
33997
|
+
dataRegistryDomain,
|
|
33704
33998
|
decryptWithPassword,
|
|
33705
33999
|
deriveMasterKey,
|
|
33706
34000
|
deriveScopeKey,
|
|
33707
34001
|
deserializeECIES,
|
|
33708
34002
|
detectPlatform,
|
|
34003
|
+
encodeDepositNativeData,
|
|
34004
|
+
encodeDepositTokenData,
|
|
33709
34005
|
encryptWithPassword,
|
|
34006
|
+
escrowContractAddress,
|
|
34007
|
+
escrowPaymentDomain,
|
|
33710
34008
|
fileDeletionDomain,
|
|
33711
34009
|
fileRegistrationDomain,
|
|
33712
34010
|
generatePkceVerifier,
|
|
@@ -33716,6 +34014,8 @@ async function parsePSError(response) {
|
|
|
33716
34014
|
getContractAddress,
|
|
33717
34015
|
getContractController,
|
|
33718
34016
|
getContractInfo,
|
|
34017
|
+
getFee,
|
|
34018
|
+
getOpFee,
|
|
33719
34019
|
getPlatformCapabilities,
|
|
33720
34020
|
getServiceEndpoints,
|
|
33721
34021
|
grantRegistrationDomain,
|
|
@@ -33727,7 +34027,6 @@ async function parsePSError(response) {
|
|
|
33727
34027
|
moksha,
|
|
33728
34028
|
mokshaServices,
|
|
33729
34029
|
mokshaTestnet,
|
|
33730
|
-
parseGrantRegistrationPayload,
|
|
33731
34030
|
parsePSError,
|
|
33732
34031
|
parseScope,
|
|
33733
34032
|
parseWeb3SignedHeader,
|