@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.browser.d.ts
CHANGED
|
@@ -35,13 +35,15 @@ export { encryptWithPassword, decryptWithPassword, } from "./crypto/envelope/ope
|
|
|
35
35
|
export { parseWeb3SignedHeader, verifyWeb3Signed, type Web3SignedPayload, type VerifiedAuth, } from "./auth/web3-signed";
|
|
36
36
|
export { buildWeb3SignedHeader, computeBodyHash, type Web3SignedSignFn, } from "./auth/web3-signed-builder";
|
|
37
37
|
export { MissingAuthError, InvalidSignatureError, ExpiredTokenError, } from "./auth/errors";
|
|
38
|
-
export { fileRegistrationDomain, fileDeletionDomain, grantRegistrationDomain, grantRevocationDomain, serverRegistrationDomain, builderRegistrationDomain, FILE_REGISTRATION_TYPES, FILE_DELETION_TYPES, GRANT_REGISTRATION_TYPES, GRANT_REVOCATION_TYPES, SERVER_REGISTRATION_TYPES, BUILDER_REGISTRATION_TYPES, type DataPortabilityContracts, type DataPortabilityGatewayConfig, type FileRegistrationMessage, type FileDeletionMessage, type GrantRegistrationMessage, type GrantRevocationMessage, type ServerRegistrationMessage, type BuilderRegistrationMessage, } from "./protocol/eip712";
|
|
38
|
+
export { fileRegistrationDomain, fileDeletionDomain, grantRegistrationDomain, grantRevocationDomain, serverRegistrationDomain, builderRegistrationDomain, escrowPaymentDomain, dataRegistryDomain, FILE_REGISTRATION_TYPES, FILE_DELETION_TYPES, GRANT_REGISTRATION_TYPES, GRANT_REVOCATION_TYPES, SERVER_REGISTRATION_TYPES, BUILDER_REGISTRATION_TYPES, GENERIC_PAYMENT_TYPES, ADD_DATA_TYPES, RECORD_DATA_ACCESS_TYPES, NATIVE_VANA_ASSET, type DataPortabilityContracts, type DataPortabilityGatewayConfig, type FileRegistrationMessage, type FileDeletionMessage, type GrantRegistrationMessage, type GrantRevocationMessage, type ServerRegistrationMessage, type BuilderRegistrationMessage, type GenericPaymentMessage, type AddDataMessage, type RecordDataAccessMessage, } from "./protocol/eip712";
|
|
39
39
|
export { PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID, PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT, personalServerRegistrationDomain, createViemPersonalServerRegistrationSigner, buildPersonalServerRegistrationTypedData, buildPersonalServerRegistrationSignature, registerPersonalServerSignature, type PersonalServerRegistrationTypedData, type PersonalServerRegistrationSigner, type PersonalServerRegistrationDomainInput, type ViemPersonalServerRegistrationWalletClient, type ViemPersonalServerRegistrationSignerSource, type BuildPersonalServerRegistrationTypedDataInput, type BuildPersonalServerRegistrationSignatureInput, type PersonalServerRegistrationSignature, } from "./protocol/personal-server-registration";
|
|
40
40
|
export { PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION, PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE, PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX, buildPersonalServerLiteOwnerBindingMessage, createViemPersonalServerLiteOwnerBindingSigner, buildPersonalServerLiteOwnerBindingSignature, signPersonalServerLiteOwnerBinding, type PersonalServerLiteOwnerBindingPurpose, type PersonalServerLiteOwnerBindingMessage, type PersonalServerLiteOwnerBindingSigner, type ViemPersonalServerLiteOwnerBindingWalletClient, type ViemPersonalServerLiteOwnerBindingSignerSource, type BuildPersonalServerLiteOwnerBindingSignatureInput, type PersonalServerLiteOwnerBindingSignature, } from "./protocol/personal-server-lite-owner-binding";
|
|
41
41
|
export { ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT, AccountPersonalServerRegistrationError, signPersonalServerRegistrationWithAccount, type AccountPersonalServerRegistrationIntent, type AccountPersonalServerRegistrationSignature, type AccountPersonalServerRegistrationStatus, type AccountPersonalServerRegistrationRequest, type AccountPersonalServerRegistrationConfig, type AccountSignedPersonalServerRegistration, type AccountConfirmationRequiredPersonalServerRegistration, type AccountFallbackSignedPersonalServerRegistration, type AccountPersonalServerRegistrationResult, } from "./account/personal-server-registration";
|
|
42
42
|
export { AccountPersonalServerLiteOwnerBindingError, signPersonalServerLiteOwnerBindingWithAccountClient, type AccountPersonalServerLiteOwnerBindingClient, type SignPersonalServerLiteOwnerBindingWithAccountClientConfig, } from "./account/personal-server-lite-owner-binding";
|
|
43
|
-
export { isDataPortabilityGatewayConfig,
|
|
43
|
+
export { isDataPortabilityGatewayConfig, verifyGrantRegistration, type VerifyGrantRegistrationInput, type VerifyGrantRegistrationResult, } from "./protocol/grants";
|
|
44
|
+
export { ESCROW_DEPOSIT_ABI, escrowContractAddress, encodeDepositNativeData, encodeDepositTokenData, buildDepositNativeRequest, buildDepositTokenRequest, type DepositNativeInput, type DepositTokenInput, type DepositTransactionRequest, } from "./protocol/escrow-deposit";
|
|
45
|
+
export { FEE_REGISTRY_ABI, REGISTRATION_KIND_FOR_OP, getFee, getOpFee, type FeeKind, type FeeEntry, type OpFee, type FeeRegistryOptions, } from "./protocol/fee-registry";
|
|
44
46
|
export { ScopeSchema, parseScope, scopeToPathSegments, scopeMatchesPattern, scopeCoveredByGrant, type Scope, type ParsedScope, } from "./protocol/scopes";
|
|
45
47
|
export { DataFileEnvelopeSchema, createDataFileEnvelope, IngestResponseSchema, type DataFileEnvelope, type IngestResponse, } from "./protocol/data-file";
|
|
46
|
-
export { createGatewayClient, type GatewayEnvelope, type GatewayProof, type Builder, type Schema, type ServerInfo, type GatewayGrantResponse, type GrantListItem, type FileRecord, type FileListResult, type RegisterServerParams, type RegisterServerResult, type RegisterFileParams, type CreateGrantParams, type RevokeGrantParams, type DeleteFileParams, type GatewayClient, } from "./protocol/gateway";
|
|
48
|
+
export { createGatewayClient, type GatewayEnvelope, type GatewayProof, type Builder, type Schema, type ServerInfo, type GatewayGrantResponse, type GatewayGrantStatus, type GatewayGrantFee, type GrantListItem, type FileRecord, type FileListResult, type ListFilesOptions, type RegisterServerParams, type RegisterServerResult, type RegisterFileParams, type RegisterBuilderParams, type RegisterBuilderResult, type RegisterDataPointParams, type RegisterDataPointResult, type CreateGrantParams, type RevokeGrantParams, type PayForOperationParams, type PayForOperationResult, type AccessRecord, type SettleOpType, type SettleItem, type SettlePromoteResult, type SettleReconcileItem, type SettleParams, type SettleResult, type SubmitDepositParams, type DepositState, type EscrowBalance, type EscrowBalanceEntry, type EscrowDepositSubmitted, type EscrowDepositFinalized, type EscrowDepositFailed, type DeleteFileParams, type GatewayClient, } from "./protocol/gateway";
|
|
47
49
|
export { PSError, parsePSError, type PSErrorCode } from "./types/ps-errors";
|
package/dist/index.browser.js
CHANGED
|
@@ -31882,6 +31882,7 @@ async function verifyWeb3Signed(params) {
|
|
|
31882
31882
|
// src/protocol/eip712.ts
|
|
31883
31883
|
var DOMAIN_NAME = "Vana Data Portability";
|
|
31884
31884
|
var DOMAIN_VERSION = "1";
|
|
31885
|
+
var NATIVE_VANA_ASSET = "0x0000000000000000000000000000000000000000";
|
|
31885
31886
|
function buildDomain(chainId, verifyingContract) {
|
|
31886
31887
|
return {
|
|
31887
31888
|
name: DOMAIN_NAME,
|
|
@@ -31896,6 +31897,12 @@ function fileRegistrationDomain(config) {
|
|
|
31896
31897
|
config.contracts.dataRegistry
|
|
31897
31898
|
);
|
|
31898
31899
|
}
|
|
31900
|
+
function dataRegistryDomain(config) {
|
|
31901
|
+
return buildDomain(
|
|
31902
|
+
config.chainId,
|
|
31903
|
+
config.contracts.dataRegistry
|
|
31904
|
+
);
|
|
31905
|
+
}
|
|
31899
31906
|
function fileDeletionDomain(config) {
|
|
31900
31907
|
return buildDomain(
|
|
31901
31908
|
config.chainId,
|
|
@@ -31926,6 +31933,12 @@ function builderRegistrationDomain(config) {
|
|
|
31926
31933
|
config.contracts.dataPortabilityGrantees
|
|
31927
31934
|
);
|
|
31928
31935
|
}
|
|
31936
|
+
function escrowPaymentDomain(config) {
|
|
31937
|
+
return buildDomain(
|
|
31938
|
+
config.chainId,
|
|
31939
|
+
config.contracts.dataPortabilityEscrow
|
|
31940
|
+
);
|
|
31941
|
+
}
|
|
31929
31942
|
var FILE_REGISTRATION_TYPES = {
|
|
31930
31943
|
FileRegistration: [
|
|
31931
31944
|
{ name: "ownerAddress", type: "address" },
|
|
@@ -31943,14 +31956,16 @@ var GRANT_REGISTRATION_TYPES = {
|
|
|
31943
31956
|
GrantRegistration: [
|
|
31944
31957
|
{ name: "grantorAddress", type: "address" },
|
|
31945
31958
|
{ name: "granteeId", type: "bytes32" },
|
|
31946
|
-
{ name: "
|
|
31947
|
-
{ name: "
|
|
31959
|
+
{ name: "scopes", type: "string[]" },
|
|
31960
|
+
{ name: "grantVersion", type: "uint256" },
|
|
31961
|
+
{ name: "expiresAt", type: "uint256" }
|
|
31948
31962
|
]
|
|
31949
31963
|
};
|
|
31950
31964
|
var GRANT_REVOCATION_TYPES = {
|
|
31951
31965
|
GrantRevocation: [
|
|
31952
31966
|
{ name: "grantorAddress", type: "address" },
|
|
31953
|
-
{ name: "grantId", type: "bytes32" }
|
|
31967
|
+
{ name: "grantId", type: "bytes32" },
|
|
31968
|
+
{ name: "grantVersion", type: "uint256" }
|
|
31954
31969
|
]
|
|
31955
31970
|
};
|
|
31956
31971
|
var SERVER_REGISTRATION_TYPES = {
|
|
@@ -31969,6 +31984,34 @@ var BUILDER_REGISTRATION_TYPES = {
|
|
|
31969
31984
|
{ name: "appUrl", type: "string" }
|
|
31970
31985
|
]
|
|
31971
31986
|
};
|
|
31987
|
+
var GENERIC_PAYMENT_TYPES = {
|
|
31988
|
+
GenericPayment: [
|
|
31989
|
+
{ name: "payerAddress", type: "address" },
|
|
31990
|
+
{ name: "opType", type: "string" },
|
|
31991
|
+
{ name: "opId", type: "bytes32" },
|
|
31992
|
+
{ name: "asset", type: "address" },
|
|
31993
|
+
{ name: "amount", type: "uint256" },
|
|
31994
|
+
{ name: "paymentNonce", type: "uint256" }
|
|
31995
|
+
]
|
|
31996
|
+
};
|
|
31997
|
+
var ADD_DATA_TYPES = {
|
|
31998
|
+
AddData: [
|
|
31999
|
+
{ name: "ownerAddress", type: "address" },
|
|
32000
|
+
{ name: "scope", type: "string" },
|
|
32001
|
+
{ name: "dataHash", type: "bytes32" },
|
|
32002
|
+
{ name: "metadataHash", type: "bytes32" },
|
|
32003
|
+
{ name: "expectedVersion", type: "uint256" }
|
|
32004
|
+
]
|
|
32005
|
+
};
|
|
32006
|
+
var RECORD_DATA_ACCESS_TYPES = {
|
|
32007
|
+
RecordDataAccess: [
|
|
32008
|
+
{ name: "ownerAddress", type: "address" },
|
|
32009
|
+
{ name: "scope", type: "string" },
|
|
32010
|
+
{ name: "version", type: "uint256" },
|
|
32011
|
+
{ name: "accessor", type: "address" },
|
|
32012
|
+
{ name: "recordId", type: "bytes32" }
|
|
32013
|
+
]
|
|
32014
|
+
};
|
|
31972
32015
|
|
|
31973
32016
|
// src/protocol/personal-server-registration.ts
|
|
31974
32017
|
import {
|
|
@@ -32410,67 +32453,31 @@ function isDataPortabilityGatewayConfig(value) {
|
|
|
32410
32453
|
return false;
|
|
32411
32454
|
}
|
|
32412
32455
|
const c = contracts;
|
|
32413
|
-
return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]);
|
|
32414
|
-
}
|
|
32415
|
-
function parseGrantRegistrationPayload(grant) {
|
|
32416
|
-
let parsed;
|
|
32417
|
-
try {
|
|
32418
|
-
parsed = JSON.parse(grant);
|
|
32419
|
-
} catch {
|
|
32420
|
-
return null;
|
|
32421
|
-
}
|
|
32422
|
-
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
32423
|
-
return null;
|
|
32424
|
-
}
|
|
32425
|
-
const value = parsed;
|
|
32426
|
-
if (!Array.isArray(value["scopes"]) || value["scopes"].length === 0) {
|
|
32427
|
-
return null;
|
|
32428
|
-
}
|
|
32429
|
-
if (!value["scopes"].every((scope) => typeof scope === "string")) {
|
|
32430
|
-
return null;
|
|
32431
|
-
}
|
|
32432
|
-
if (typeof value["expiresAt"] !== "number" || !Number.isFinite(value["expiresAt"])) {
|
|
32433
|
-
return null;
|
|
32434
|
-
}
|
|
32435
|
-
if (value["user"] !== void 0 && !isHexString(value["user"])) {
|
|
32436
|
-
return null;
|
|
32437
|
-
}
|
|
32438
|
-
if (value["builder"] !== void 0 && !isHexString(value["builder"])) {
|
|
32439
|
-
return null;
|
|
32440
|
-
}
|
|
32441
|
-
if (value["nonce"] !== void 0 && (typeof value["nonce"] !== "number" || !Number.isFinite(value["nonce"]))) {
|
|
32442
|
-
return null;
|
|
32443
|
-
}
|
|
32444
|
-
return {
|
|
32445
|
-
user: value["user"],
|
|
32446
|
-
builder: value["builder"],
|
|
32447
|
-
scopes: value["scopes"],
|
|
32448
|
-
expiresAt: value["expiresAt"],
|
|
32449
|
-
nonce: value["nonce"]
|
|
32450
|
-
};
|
|
32456
|
+
return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]) && isHexString(c["dataPortabilityEscrow"]) && isHexString(c["feeRegistry"]);
|
|
32451
32457
|
}
|
|
32452
|
-
function
|
|
32458
|
+
function toUint256(value) {
|
|
32453
32459
|
try {
|
|
32454
|
-
const
|
|
32455
|
-
return
|
|
32456
|
-
|
|
32457
|
-
display: values.map((fileId) => fileId.toString())
|
|
32458
|
-
};
|
|
32460
|
+
const big = typeof value === "bigint" ? value : BigInt(value);
|
|
32461
|
+
if (big < 0n) return null;
|
|
32462
|
+
return big;
|
|
32459
32463
|
} catch {
|
|
32460
32464
|
return null;
|
|
32461
32465
|
}
|
|
32462
32466
|
}
|
|
32463
32467
|
async function verifyGrantRegistration(input) {
|
|
32464
|
-
|
|
32465
|
-
|
|
32466
|
-
|
|
32467
|
-
|
|
32468
|
-
|
|
32469
|
-
};
|
|
32468
|
+
if (!Array.isArray(input.scopes) || input.scopes.length === 0) {
|
|
32469
|
+
return { valid: false, error: "scopes must be a non-empty array" };
|
|
32470
|
+
}
|
|
32471
|
+
if (!input.scopes.every((scope) => typeof scope === "string")) {
|
|
32472
|
+
return { valid: false, error: "scopes must contain only strings" };
|
|
32470
32473
|
}
|
|
32471
|
-
const
|
|
32472
|
-
if (
|
|
32473
|
-
return { valid: false, error: "
|
|
32474
|
+
const grantVersion = toUint256(input.grantVersion);
|
|
32475
|
+
if (grantVersion === null || grantVersion < 1n) {
|
|
32476
|
+
return { valid: false, error: "grantVersion must be a uint256 >= 1" };
|
|
32477
|
+
}
|
|
32478
|
+
const expiresAt = toUint256(input.expiresAt);
|
|
32479
|
+
if (expiresAt === null) {
|
|
32480
|
+
return { valid: false, error: "expiresAt must be a non-negative uint256" };
|
|
32474
32481
|
}
|
|
32475
32482
|
let valid;
|
|
32476
32483
|
try {
|
|
@@ -32482,8 +32489,9 @@ async function verifyGrantRegistration(input) {
|
|
|
32482
32489
|
message: {
|
|
32483
32490
|
grantorAddress: input.grantorAddress,
|
|
32484
32491
|
granteeId: input.granteeId,
|
|
32485
|
-
|
|
32486
|
-
|
|
32492
|
+
scopes: input.scopes,
|
|
32493
|
+
grantVersion,
|
|
32494
|
+
expiresAt
|
|
32487
32495
|
},
|
|
32488
32496
|
signature: input.signature
|
|
32489
32497
|
});
|
|
@@ -32494,19 +32502,153 @@ async function verifyGrantRegistration(input) {
|
|
|
32494
32502
|
return { valid: false, error: "Grant signature does not match grantor" };
|
|
32495
32503
|
}
|
|
32496
32504
|
const nowSeconds = input.nowSeconds ?? Math.floor(Date.now() / 1e3);
|
|
32497
|
-
if (
|
|
32505
|
+
if (expiresAt > 0n && expiresAt < BigInt(nowSeconds)) {
|
|
32498
32506
|
return { valid: false, error: "Grant has expired" };
|
|
32499
32507
|
}
|
|
32500
|
-
if (payload.user !== void 0 && payload.user.toLowerCase() !== input.grantorAddress.toLowerCase()) {
|
|
32501
|
-
return { valid: false, error: "Grant user does not match grantorAddress" };
|
|
32502
|
-
}
|
|
32503
32508
|
return {
|
|
32504
32509
|
valid: true,
|
|
32505
32510
|
grantorAddress: input.grantorAddress,
|
|
32506
32511
|
granteeId: input.granteeId,
|
|
32507
|
-
|
|
32508
|
-
|
|
32509
|
-
|
|
32512
|
+
scopes: input.scopes,
|
|
32513
|
+
grantVersion: grantVersion.toString(),
|
|
32514
|
+
expiresAt: expiresAt.toString()
|
|
32515
|
+
};
|
|
32516
|
+
}
|
|
32517
|
+
|
|
32518
|
+
// src/protocol/escrow-deposit.ts
|
|
32519
|
+
import { encodeFunctionData } from "viem";
|
|
32520
|
+
var ESCROW_DEPOSIT_ABI = [
|
|
32521
|
+
{
|
|
32522
|
+
type: "function",
|
|
32523
|
+
name: "depositNative",
|
|
32524
|
+
stateMutability: "payable",
|
|
32525
|
+
inputs: [{ name: "account", type: "address" }],
|
|
32526
|
+
outputs: []
|
|
32527
|
+
},
|
|
32528
|
+
{
|
|
32529
|
+
type: "function",
|
|
32530
|
+
name: "depositToken",
|
|
32531
|
+
stateMutability: "nonpayable",
|
|
32532
|
+
inputs: [
|
|
32533
|
+
{ name: "account", type: "address" },
|
|
32534
|
+
{ name: "token", type: "address" },
|
|
32535
|
+
{ name: "amount", type: "uint256" }
|
|
32536
|
+
],
|
|
32537
|
+
outputs: []
|
|
32538
|
+
}
|
|
32539
|
+
];
|
|
32540
|
+
function escrowContractAddress(config) {
|
|
32541
|
+
return config.contracts.dataPortabilityEscrow;
|
|
32542
|
+
}
|
|
32543
|
+
function encodeDepositNativeData(input) {
|
|
32544
|
+
return encodeFunctionData({
|
|
32545
|
+
abi: ESCROW_DEPOSIT_ABI,
|
|
32546
|
+
functionName: "depositNative",
|
|
32547
|
+
args: [input.account]
|
|
32548
|
+
});
|
|
32549
|
+
}
|
|
32550
|
+
function encodeDepositTokenData(input) {
|
|
32551
|
+
return encodeFunctionData({
|
|
32552
|
+
abi: ESCROW_DEPOSIT_ABI,
|
|
32553
|
+
functionName: "depositToken",
|
|
32554
|
+
args: [input.account, input.token, input.amount]
|
|
32555
|
+
});
|
|
32556
|
+
}
|
|
32557
|
+
function buildDepositNativeRequest(config, input) {
|
|
32558
|
+
return {
|
|
32559
|
+
to: escrowContractAddress(config),
|
|
32560
|
+
data: encodeDepositNativeData({ account: input.account }),
|
|
32561
|
+
value: input.amount
|
|
32562
|
+
};
|
|
32563
|
+
}
|
|
32564
|
+
function buildDepositTokenRequest(config, input) {
|
|
32565
|
+
return {
|
|
32566
|
+
to: escrowContractAddress(config),
|
|
32567
|
+
data: encodeDepositTokenData(input)
|
|
32568
|
+
};
|
|
32569
|
+
}
|
|
32570
|
+
|
|
32571
|
+
// src/protocol/fee-registry.ts
|
|
32572
|
+
import { parseAbi } from "viem";
|
|
32573
|
+
var FEE_REGISTRY_ABI = parseAbi([
|
|
32574
|
+
"struct Fee { uint256 amount; address asset; address payee; bool enabled; }",
|
|
32575
|
+
"function fees(bytes32 operation) view returns (Fee)",
|
|
32576
|
+
"function operationKey(string name) pure returns (bytes32)"
|
|
32577
|
+
]);
|
|
32578
|
+
var REGISTRATION_KIND_FOR_OP = {
|
|
32579
|
+
grant: "grant_registration",
|
|
32580
|
+
data: "data_registration",
|
|
32581
|
+
server: "server_registration",
|
|
32582
|
+
builder: "builder_registration"
|
|
32583
|
+
};
|
|
32584
|
+
function operationNameFor(kind, opts) {
|
|
32585
|
+
switch (kind) {
|
|
32586
|
+
case "grant_registration":
|
|
32587
|
+
return opts?.grantRegistrationOpName ?? "grant_registration";
|
|
32588
|
+
case "data_access":
|
|
32589
|
+
return opts?.dataAccessOpName ?? "data_access";
|
|
32590
|
+
case "data_registration":
|
|
32591
|
+
return opts?.dataRegistrationOpName ?? "data_registration";
|
|
32592
|
+
case "server_registration":
|
|
32593
|
+
return opts?.serverRegistrationOpName ?? "server_registration";
|
|
32594
|
+
case "builder_registration":
|
|
32595
|
+
return opts?.builderRegistrationOpName ?? "builder_registration";
|
|
32596
|
+
}
|
|
32597
|
+
}
|
|
32598
|
+
var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
32599
|
+
async function getFee(client, config, kind, opts) {
|
|
32600
|
+
const address = config.contracts.feeRegistry;
|
|
32601
|
+
const opName = operationNameFor(kind, opts);
|
|
32602
|
+
const opKey = await client.readContract({
|
|
32603
|
+
address,
|
|
32604
|
+
abi: FEE_REGISTRY_ABI,
|
|
32605
|
+
functionName: "operationKey",
|
|
32606
|
+
args: [opName]
|
|
32607
|
+
});
|
|
32608
|
+
const fee = await client.readContract({
|
|
32609
|
+
address,
|
|
32610
|
+
abi: FEE_REGISTRY_ABI,
|
|
32611
|
+
functionName: "fees",
|
|
32612
|
+
args: [opKey]
|
|
32613
|
+
});
|
|
32614
|
+
if (fee.enabled && fee.payee === ZERO_ADDRESS) {
|
|
32615
|
+
throw new Error(
|
|
32616
|
+
`FeeRegistry: enabled operation "${opName}" has zero-address payee \u2014 contract pre-flight rejects payouts to 0x0`
|
|
32617
|
+
);
|
|
32618
|
+
}
|
|
32619
|
+
return fee;
|
|
32620
|
+
}
|
|
32621
|
+
async function getOpFee(client, config, opType, opts) {
|
|
32622
|
+
const registrationKind = REGISTRATION_KIND_FOR_OP[opType];
|
|
32623
|
+
if (!registrationKind) {
|
|
32624
|
+
throw new Error(
|
|
32625
|
+
`getOpFee: unknown opType "${opType}" \u2014 supported types are ${Object.keys(REGISTRATION_KIND_FOR_OP).join(", ")}`
|
|
32626
|
+
);
|
|
32627
|
+
}
|
|
32628
|
+
const includeDataAccess = opType === "grant";
|
|
32629
|
+
const [registration, dataAccess] = await Promise.all([
|
|
32630
|
+
getFee(client, config, registrationKind, opts),
|
|
32631
|
+
includeDataAccess ? getFee(client, config, "data_access", opts) : Promise.resolve({
|
|
32632
|
+
amount: 0n,
|
|
32633
|
+
asset: ZERO_ADDRESS,
|
|
32634
|
+
payee: ZERO_ADDRESS,
|
|
32635
|
+
enabled: false
|
|
32636
|
+
})
|
|
32637
|
+
]);
|
|
32638
|
+
if (registration.enabled && dataAccess.enabled && registration.asset.toLowerCase() !== dataAccess.asset.toLowerCase()) {
|
|
32639
|
+
throw new Error(
|
|
32640
|
+
`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.`
|
|
32641
|
+
);
|
|
32642
|
+
}
|
|
32643
|
+
const asset = registration.enabled ? registration.asset : dataAccess.enabled ? dataAccess.asset : ZERO_ADDRESS;
|
|
32644
|
+
return {
|
|
32645
|
+
asset,
|
|
32646
|
+
registrationFee: registration.enabled ? registration.amount : 0n,
|
|
32647
|
+
dataAccessFee: dataAccess.enabled ? dataAccess.amount : 0n,
|
|
32648
|
+
registrationEnabled: registration.enabled,
|
|
32649
|
+
dataAccessEnabled: dataAccess.enabled,
|
|
32650
|
+
registrationPayee: registration.enabled ? registration.payee : ZERO_ADDRESS,
|
|
32651
|
+
dataAccessPayee: dataAccess.enabled ? dataAccess.payee : ZERO_ADDRESS
|
|
32510
32652
|
};
|
|
32511
32653
|
}
|
|
32512
32654
|
|
|
@@ -32593,7 +32735,8 @@ function createGatewayClient(baseUrl) {
|
|
|
32593
32735
|
owner: record.owner ?? record.ownerAddress ?? "",
|
|
32594
32736
|
url: record.url,
|
|
32595
32737
|
schemaId: record.schemaId,
|
|
32596
|
-
createdAt: record.createdAt ?? record.addedAt ?? ""
|
|
32738
|
+
createdAt: record.createdAt ?? record.addedAt ?? "",
|
|
32739
|
+
deletedAt: record.deletedAt ?? null
|
|
32597
32740
|
};
|
|
32598
32741
|
}
|
|
32599
32742
|
function getMutationId(body, key) {
|
|
@@ -32653,19 +32796,24 @@ function createGatewayClient(baseUrl) {
|
|
|
32653
32796
|
}
|
|
32654
32797
|
return normalizeFileRecord(await unwrapEnvelope(res));
|
|
32655
32798
|
},
|
|
32656
|
-
async listFilesSince(owner, cursor) {
|
|
32799
|
+
async listFilesSince(owner, cursor, options) {
|
|
32657
32800
|
const params = new URLSearchParams({ user: owner });
|
|
32658
32801
|
if (cursor !== null) {
|
|
32659
|
-
params.set("
|
|
32802
|
+
params.set("cursor", cursor);
|
|
32803
|
+
}
|
|
32804
|
+
if (options?.includeDeleted) {
|
|
32805
|
+
params.set("includeDeleted", "true");
|
|
32660
32806
|
}
|
|
32661
32807
|
const res = await fetch(`${base}/v1/files?${params.toString()}`);
|
|
32662
32808
|
if (!res.ok) {
|
|
32663
32809
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
32664
32810
|
}
|
|
32665
|
-
const
|
|
32811
|
+
const envelope = await res.json();
|
|
32812
|
+
const { pagination } = envelope;
|
|
32813
|
+
const nextCursor = pagination?.hasMore === false ? null : pagination?.nextCursor ?? envelope.data.cursor ?? null;
|
|
32666
32814
|
return {
|
|
32667
|
-
files: data.files.map(normalizeFileRecord),
|
|
32668
|
-
cursor:
|
|
32815
|
+
files: envelope.data.files.map(normalizeFileRecord),
|
|
32816
|
+
cursor: nextCursor
|
|
32669
32817
|
};
|
|
32670
32818
|
},
|
|
32671
32819
|
async getSchema(schemaId) {
|
|
@@ -32706,6 +32854,68 @@ function createGatewayClient(baseUrl) {
|
|
|
32706
32854
|
alreadyRegistered: false
|
|
32707
32855
|
};
|
|
32708
32856
|
},
|
|
32857
|
+
async registerBuilder(params) {
|
|
32858
|
+
const res = await fetch(`${base}/v1/builders`, {
|
|
32859
|
+
method: "POST",
|
|
32860
|
+
headers: {
|
|
32861
|
+
"Content-Type": "application/json",
|
|
32862
|
+
Authorization: `Web3Signed ${params.signature}`
|
|
32863
|
+
},
|
|
32864
|
+
body: JSON.stringify({
|
|
32865
|
+
ownerAddress: params.ownerAddress,
|
|
32866
|
+
granteeAddress: params.granteeAddress,
|
|
32867
|
+
publicKey: params.publicKey,
|
|
32868
|
+
appUrl: params.appUrl
|
|
32869
|
+
})
|
|
32870
|
+
});
|
|
32871
|
+
if (res.status === 409) {
|
|
32872
|
+
const body2 = await res.json().catch(() => ({}));
|
|
32873
|
+
return {
|
|
32874
|
+
builderId: getMutationId(
|
|
32875
|
+
body2,
|
|
32876
|
+
"builderId"
|
|
32877
|
+
),
|
|
32878
|
+
alreadyRegistered: true
|
|
32879
|
+
};
|
|
32880
|
+
}
|
|
32881
|
+
if (!res.ok) {
|
|
32882
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
32883
|
+
}
|
|
32884
|
+
const body = await res.json().catch(() => ({}));
|
|
32885
|
+
return {
|
|
32886
|
+
builderId: getMutationId(body, "builderId"),
|
|
32887
|
+
alreadyRegistered: false
|
|
32888
|
+
};
|
|
32889
|
+
},
|
|
32890
|
+
async registerDataPoint(params) {
|
|
32891
|
+
const res = await fetch(`${base}/v1/data`, {
|
|
32892
|
+
method: "POST",
|
|
32893
|
+
headers: {
|
|
32894
|
+
"Content-Type": "application/json",
|
|
32895
|
+
Authorization: `Web3Signed ${params.signature}`
|
|
32896
|
+
},
|
|
32897
|
+
body: JSON.stringify({
|
|
32898
|
+
ownerAddress: params.ownerAddress,
|
|
32899
|
+
scope: params.scope,
|
|
32900
|
+
dataHash: params.dataHash,
|
|
32901
|
+
metadataHash: params.metadataHash,
|
|
32902
|
+
expectedVersion: params.expectedVersion
|
|
32903
|
+
})
|
|
32904
|
+
});
|
|
32905
|
+
if (!res.ok) {
|
|
32906
|
+
const body2 = await res.json().catch(() => ({}));
|
|
32907
|
+
const detail = body2.error ?? res.statusText;
|
|
32908
|
+
throw new Error(`Gateway error: ${res.status} ${detail}`);
|
|
32909
|
+
}
|
|
32910
|
+
const body = await res.json().catch(() => ({}));
|
|
32911
|
+
return {
|
|
32912
|
+
dataPointId: getMutationId(
|
|
32913
|
+
body,
|
|
32914
|
+
"dataPointId"
|
|
32915
|
+
),
|
|
32916
|
+
expectedVersion: body.expectedVersion
|
|
32917
|
+
};
|
|
32918
|
+
},
|
|
32709
32919
|
async registerFile(params) {
|
|
32710
32920
|
const res = await fetch(`${base}/v1/files`, {
|
|
32711
32921
|
method: "POST",
|
|
@@ -32743,8 +32953,9 @@ function createGatewayClient(baseUrl) {
|
|
|
32743
32953
|
body: JSON.stringify({
|
|
32744
32954
|
grantorAddress: params.grantorAddress,
|
|
32745
32955
|
granteeId: params.granteeId,
|
|
32746
|
-
|
|
32747
|
-
|
|
32956
|
+
scopes: params.scopes,
|
|
32957
|
+
grantVersion: params.grantVersion,
|
|
32958
|
+
expiresAt: params.expiresAt
|
|
32748
32959
|
})
|
|
32749
32960
|
});
|
|
32750
32961
|
if (res.status === 409) {
|
|
@@ -32769,7 +32980,8 @@ function createGatewayClient(baseUrl) {
|
|
|
32769
32980
|
Authorization: `Web3Signed ${params.signature}`
|
|
32770
32981
|
},
|
|
32771
32982
|
body: JSON.stringify({
|
|
32772
|
-
grantorAddress: params.grantorAddress
|
|
32983
|
+
grantorAddress: params.grantorAddress,
|
|
32984
|
+
grantVersion: params.grantVersion
|
|
32773
32985
|
})
|
|
32774
32986
|
});
|
|
32775
32987
|
if (res.status === 409) return;
|
|
@@ -32777,6 +32989,63 @@ function createGatewayClient(baseUrl) {
|
|
|
32777
32989
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
32778
32990
|
}
|
|
32779
32991
|
},
|
|
32992
|
+
async getEscrowBalance(account) {
|
|
32993
|
+
const res = await fetch(`${base}/v1/escrow/balance?account=${account}`);
|
|
32994
|
+
if (!res.ok) {
|
|
32995
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
32996
|
+
}
|
|
32997
|
+
return await res.json();
|
|
32998
|
+
},
|
|
32999
|
+
async submitEscrowDeposit(params) {
|
|
33000
|
+
const res = await fetch(`${base}/v1/escrow/deposit`, {
|
|
33001
|
+
method: "POST",
|
|
33002
|
+
headers: { "Content-Type": "application/json" },
|
|
33003
|
+
body: JSON.stringify({ txHash: params.txHash })
|
|
33004
|
+
});
|
|
33005
|
+
if (res.status !== 200 && res.status !== 202) {
|
|
33006
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33007
|
+
}
|
|
33008
|
+
return await res.json();
|
|
33009
|
+
},
|
|
33010
|
+
async payForOperation(params) {
|
|
33011
|
+
const body = {
|
|
33012
|
+
payerAddress: params.payerAddress,
|
|
33013
|
+
opType: params.opType,
|
|
33014
|
+
opId: params.opId,
|
|
33015
|
+
asset: params.asset,
|
|
33016
|
+
amount: params.amount,
|
|
33017
|
+
paymentNonce: params.paymentNonce
|
|
33018
|
+
};
|
|
33019
|
+
if (params.accessRecord) {
|
|
33020
|
+
body["accessRecord"] = params.accessRecord;
|
|
33021
|
+
}
|
|
33022
|
+
const res = await fetch(`${base}/v1/escrow/pay`, {
|
|
33023
|
+
method: "POST",
|
|
33024
|
+
headers: {
|
|
33025
|
+
"Content-Type": "application/json",
|
|
33026
|
+
Authorization: `Web3Signed ${params.signature}`
|
|
33027
|
+
},
|
|
33028
|
+
body: JSON.stringify(body)
|
|
33029
|
+
});
|
|
33030
|
+
if (!res.ok) {
|
|
33031
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33032
|
+
}
|
|
33033
|
+
return await res.json();
|
|
33034
|
+
},
|
|
33035
|
+
async settle(params) {
|
|
33036
|
+
const res = await fetch(`${base}/v1/settle`, {
|
|
33037
|
+
method: "POST",
|
|
33038
|
+
headers: { "Content-Type": "application/json" },
|
|
33039
|
+
// The gateway accepts an empty body; only `limit` is recognised.
|
|
33040
|
+
// Always send a JSON body so the gateway's req.body shape parse
|
|
33041
|
+
// doesn't have to deal with an undefined.
|
|
33042
|
+
body: JSON.stringify(params ?? {})
|
|
33043
|
+
});
|
|
33044
|
+
if (!res.ok) {
|
|
33045
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33046
|
+
}
|
|
33047
|
+
return await res.json();
|
|
33048
|
+
},
|
|
32780
33049
|
async deleteFile(params) {
|
|
32781
33050
|
const res = await fetch(`${base}/v1/files/${params.fileId}`, {
|
|
32782
33051
|
method: "DELETE",
|
|
@@ -32860,6 +33129,7 @@ async function parsePSError(response) {
|
|
|
32860
33129
|
}
|
|
32861
33130
|
export {
|
|
32862
33131
|
ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
|
|
33132
|
+
ADD_DATA_TYPES,
|
|
32863
33133
|
AccountPersonalServerLiteOwnerBindingError,
|
|
32864
33134
|
AccountPersonalServerRegistrationError,
|
|
32865
33135
|
BUILDER_REGISTRATION_TYPES,
|
|
@@ -32873,9 +33143,12 @@ export {
|
|
|
32873
33143
|
DataFileEnvelopeSchema,
|
|
32874
33144
|
DropboxStorage,
|
|
32875
33145
|
ECIESError,
|
|
33146
|
+
ESCROW_DEPOSIT_ABI,
|
|
32876
33147
|
ExpiredTokenError,
|
|
33148
|
+
FEE_REGISTRY_ABI,
|
|
32877
33149
|
FILE_DELETION_TYPES,
|
|
32878
33150
|
FILE_REGISTRATION_TYPES,
|
|
33151
|
+
GENERIC_PAYMENT_TYPES,
|
|
32879
33152
|
GRANT_REGISTRATION_TYPES,
|
|
32880
33153
|
GRANT_REVOCATION_TYPES,
|
|
32881
33154
|
GoogleDriveStorage,
|
|
@@ -32886,6 +33159,7 @@ export {
|
|
|
32886
33159
|
IpfsStorage,
|
|
32887
33160
|
MASTER_KEY_MESSAGE,
|
|
32888
33161
|
MissingAuthError,
|
|
33162
|
+
NATIVE_VANA_ASSET,
|
|
32889
33163
|
NetworkError,
|
|
32890
33164
|
NonceError,
|
|
32891
33165
|
OAuthClient,
|
|
@@ -32901,6 +33175,8 @@ export {
|
|
|
32901
33175
|
PersonalServerError,
|
|
32902
33176
|
PinataStorage,
|
|
32903
33177
|
R2Storage,
|
|
33178
|
+
RECORD_DATA_ACCESS_TYPES,
|
|
33179
|
+
REGISTRATION_KIND_FOR_OP,
|
|
32904
33180
|
ReadOnlyError,
|
|
32905
33181
|
RelayerError,
|
|
32906
33182
|
SERVER_REGISTRATION_TYPES,
|
|
@@ -32915,6 +33191,8 @@ export {
|
|
|
32915
33191
|
VanaError,
|
|
32916
33192
|
VanaStorage,
|
|
32917
33193
|
assertValidPkceVerifier,
|
|
33194
|
+
buildDepositNativeRequest,
|
|
33195
|
+
buildDepositTokenRequest,
|
|
32918
33196
|
buildPersonalServerLiteOwnerBindingMessage,
|
|
32919
33197
|
buildPersonalServerLiteOwnerBindingSignature,
|
|
32920
33198
|
buildPersonalServerRegistrationSignature,
|
|
@@ -32933,12 +33211,17 @@ export {
|
|
|
32933
33211
|
createVanaStorageProvider,
|
|
32934
33212
|
createViemPersonalServerLiteOwnerBindingSigner,
|
|
32935
33213
|
createViemPersonalServerRegistrationSigner,
|
|
33214
|
+
dataRegistryDomain,
|
|
32936
33215
|
decryptWithPassword,
|
|
32937
33216
|
deriveMasterKey,
|
|
32938
33217
|
deriveScopeKey,
|
|
32939
33218
|
deserializeECIES,
|
|
32940
33219
|
detectPlatform,
|
|
33220
|
+
encodeDepositNativeData,
|
|
33221
|
+
encodeDepositTokenData,
|
|
32941
33222
|
encryptWithPassword,
|
|
33223
|
+
escrowContractAddress,
|
|
33224
|
+
escrowPaymentDomain,
|
|
32942
33225
|
fileDeletionDomain,
|
|
32943
33226
|
fileRegistrationDomain,
|
|
32944
33227
|
generatePkceVerifier,
|
|
@@ -32948,6 +33231,8 @@ export {
|
|
|
32948
33231
|
getContractAddress,
|
|
32949
33232
|
getContractController,
|
|
32950
33233
|
getContractInfo,
|
|
33234
|
+
getFee,
|
|
33235
|
+
getOpFee,
|
|
32951
33236
|
getPlatformCapabilities,
|
|
32952
33237
|
getServiceEndpoints,
|
|
32953
33238
|
grantRegistrationDomain,
|
|
@@ -32959,7 +33244,6 @@ export {
|
|
|
32959
33244
|
moksha,
|
|
32960
33245
|
mokshaServices,
|
|
32961
33246
|
mokshaTestnet2 as mokshaTestnet,
|
|
32962
|
-
parseGrantRegistrationPayload,
|
|
32963
33247
|
parsePSError,
|
|
32964
33248
|
parseScope,
|
|
32965
33249
|
parseWeb3SignedHeader,
|