@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.d.ts
CHANGED
|
@@ -35,13 +35,15 @@ export { MissingAuthError, InvalidSignatureError, ExpiredTokenError, } from "./a
|
|
|
35
35
|
export { generatePkceVerifier, computePkceChallenge, verifyPkceChallenge, assertValidPkceVerifier, PKCE_VERIFIER_PATTERN, PKCE_CHALLENGE_PATTERN, } from "./auth/pkce";
|
|
36
36
|
export { InMemoryTokenStore, type TokenStore, type TokenRecord, } from "./auth/token-store";
|
|
37
37
|
export { OAuthClient, type OAuthClientConfig, type AuthorizationUrlResult, } from "./auth/oauth-client";
|
|
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.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,
|
|
@@ -32523,6 +32524,12 @@ function fileRegistrationDomain(config) {
|
|
|
32523
32524
|
config.contracts.dataRegistry
|
|
32524
32525
|
);
|
|
32525
32526
|
}
|
|
32527
|
+
function dataRegistryDomain(config) {
|
|
32528
|
+
return buildDomain(
|
|
32529
|
+
config.chainId,
|
|
32530
|
+
config.contracts.dataRegistry
|
|
32531
|
+
);
|
|
32532
|
+
}
|
|
32526
32533
|
function fileDeletionDomain(config) {
|
|
32527
32534
|
return buildDomain(
|
|
32528
32535
|
config.chainId,
|
|
@@ -32553,6 +32560,12 @@ function builderRegistrationDomain(config) {
|
|
|
32553
32560
|
config.contracts.dataPortabilityGrantees
|
|
32554
32561
|
);
|
|
32555
32562
|
}
|
|
32563
|
+
function escrowPaymentDomain(config) {
|
|
32564
|
+
return buildDomain(
|
|
32565
|
+
config.chainId,
|
|
32566
|
+
config.contracts.dataPortabilityEscrow
|
|
32567
|
+
);
|
|
32568
|
+
}
|
|
32556
32569
|
var FILE_REGISTRATION_TYPES = {
|
|
32557
32570
|
FileRegistration: [
|
|
32558
32571
|
{ name: "ownerAddress", type: "address" },
|
|
@@ -32570,14 +32583,16 @@ var GRANT_REGISTRATION_TYPES = {
|
|
|
32570
32583
|
GrantRegistration: [
|
|
32571
32584
|
{ name: "grantorAddress", type: "address" },
|
|
32572
32585
|
{ name: "granteeId", type: "bytes32" },
|
|
32573
|
-
{ name: "
|
|
32574
|
-
{ name: "
|
|
32586
|
+
{ name: "scopes", type: "string[]" },
|
|
32587
|
+
{ name: "grantVersion", type: "uint256" },
|
|
32588
|
+
{ name: "expiresAt", type: "uint256" }
|
|
32575
32589
|
]
|
|
32576
32590
|
};
|
|
32577
32591
|
var GRANT_REVOCATION_TYPES = {
|
|
32578
32592
|
GrantRevocation: [
|
|
32579
32593
|
{ name: "grantorAddress", type: "address" },
|
|
32580
|
-
{ name: "grantId", type: "bytes32" }
|
|
32594
|
+
{ name: "grantId", type: "bytes32" },
|
|
32595
|
+
{ name: "grantVersion", type: "uint256" }
|
|
32581
32596
|
]
|
|
32582
32597
|
};
|
|
32583
32598
|
var SERVER_REGISTRATION_TYPES = {
|
|
@@ -32596,6 +32611,34 @@ var BUILDER_REGISTRATION_TYPES = {
|
|
|
32596
32611
|
{ name: "appUrl", type: "string" }
|
|
32597
32612
|
]
|
|
32598
32613
|
};
|
|
32614
|
+
var GENERIC_PAYMENT_TYPES = {
|
|
32615
|
+
GenericPayment: [
|
|
32616
|
+
{ name: "payerAddress", type: "address" },
|
|
32617
|
+
{ name: "opType", type: "string" },
|
|
32618
|
+
{ name: "opId", type: "bytes32" },
|
|
32619
|
+
{ name: "asset", type: "address" },
|
|
32620
|
+
{ name: "amount", type: "uint256" },
|
|
32621
|
+
{ name: "paymentNonce", type: "uint256" }
|
|
32622
|
+
]
|
|
32623
|
+
};
|
|
32624
|
+
var ADD_DATA_TYPES = {
|
|
32625
|
+
AddData: [
|
|
32626
|
+
{ name: "ownerAddress", type: "address" },
|
|
32627
|
+
{ name: "scope", type: "string" },
|
|
32628
|
+
{ name: "dataHash", type: "bytes32" },
|
|
32629
|
+
{ name: "metadataHash", type: "bytes32" },
|
|
32630
|
+
{ name: "expectedVersion", type: "uint256" }
|
|
32631
|
+
]
|
|
32632
|
+
};
|
|
32633
|
+
var RECORD_DATA_ACCESS_TYPES = {
|
|
32634
|
+
RecordDataAccess: [
|
|
32635
|
+
{ name: "ownerAddress", type: "address" },
|
|
32636
|
+
{ name: "scope", type: "string" },
|
|
32637
|
+
{ name: "version", type: "uint256" },
|
|
32638
|
+
{ name: "accessor", type: "address" },
|
|
32639
|
+
{ name: "recordId", type: "bytes32" }
|
|
32640
|
+
]
|
|
32641
|
+
};
|
|
32599
32642
|
|
|
32600
32643
|
// src/protocol/personal-server-registration.ts
|
|
32601
32644
|
import {
|
|
@@ -33037,67 +33080,31 @@ function isDataPortabilityGatewayConfig(value) {
|
|
|
33037
33080
|
return false;
|
|
33038
33081
|
}
|
|
33039
33082
|
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
|
-
};
|
|
33083
|
+
return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]) && isHexString(c["dataPortabilityEscrow"]) && isHexString(c["feeRegistry"]);
|
|
33078
33084
|
}
|
|
33079
|
-
function
|
|
33085
|
+
function toUint256(value) {
|
|
33080
33086
|
try {
|
|
33081
|
-
const
|
|
33082
|
-
return
|
|
33083
|
-
|
|
33084
|
-
display: values.map((fileId) => fileId.toString())
|
|
33085
|
-
};
|
|
33087
|
+
const big = typeof value === "bigint" ? value : BigInt(value);
|
|
33088
|
+
if (big < 0n) return null;
|
|
33089
|
+
return big;
|
|
33086
33090
|
} catch {
|
|
33087
33091
|
return null;
|
|
33088
33092
|
}
|
|
33089
33093
|
}
|
|
33090
33094
|
async function verifyGrantRegistration(input) {
|
|
33091
|
-
|
|
33092
|
-
|
|
33093
|
-
|
|
33094
|
-
|
|
33095
|
-
|
|
33096
|
-
};
|
|
33095
|
+
if (!Array.isArray(input.scopes) || input.scopes.length === 0) {
|
|
33096
|
+
return { valid: false, error: "scopes must be a non-empty array" };
|
|
33097
|
+
}
|
|
33098
|
+
if (!input.scopes.every((scope) => typeof scope === "string")) {
|
|
33099
|
+
return { valid: false, error: "scopes must contain only strings" };
|
|
33097
33100
|
}
|
|
33098
|
-
const
|
|
33099
|
-
if (
|
|
33100
|
-
return { valid: false, error: "
|
|
33101
|
+
const grantVersion = toUint256(input.grantVersion);
|
|
33102
|
+
if (grantVersion === null || grantVersion < 1n) {
|
|
33103
|
+
return { valid: false, error: "grantVersion must be a uint256 >= 1" };
|
|
33104
|
+
}
|
|
33105
|
+
const expiresAt = toUint256(input.expiresAt);
|
|
33106
|
+
if (expiresAt === null) {
|
|
33107
|
+
return { valid: false, error: "expiresAt must be a non-negative uint256" };
|
|
33101
33108
|
}
|
|
33102
33109
|
let valid;
|
|
33103
33110
|
try {
|
|
@@ -33109,8 +33116,9 @@ async function verifyGrantRegistration(input) {
|
|
|
33109
33116
|
message: {
|
|
33110
33117
|
grantorAddress: input.grantorAddress,
|
|
33111
33118
|
granteeId: input.granteeId,
|
|
33112
|
-
|
|
33113
|
-
|
|
33119
|
+
scopes: input.scopes,
|
|
33120
|
+
grantVersion,
|
|
33121
|
+
expiresAt
|
|
33114
33122
|
},
|
|
33115
33123
|
signature: input.signature
|
|
33116
33124
|
});
|
|
@@ -33121,19 +33129,153 @@ async function verifyGrantRegistration(input) {
|
|
|
33121
33129
|
return { valid: false, error: "Grant signature does not match grantor" };
|
|
33122
33130
|
}
|
|
33123
33131
|
const nowSeconds = input.nowSeconds ?? Math.floor(Date.now() / 1e3);
|
|
33124
|
-
if (
|
|
33132
|
+
if (expiresAt > 0n && expiresAt < BigInt(nowSeconds)) {
|
|
33125
33133
|
return { valid: false, error: "Grant has expired" };
|
|
33126
33134
|
}
|
|
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
33135
|
return {
|
|
33131
33136
|
valid: true,
|
|
33132
33137
|
grantorAddress: input.grantorAddress,
|
|
33133
33138
|
granteeId: input.granteeId,
|
|
33134
|
-
|
|
33135
|
-
|
|
33136
|
-
|
|
33139
|
+
scopes: input.scopes,
|
|
33140
|
+
grantVersion: grantVersion.toString(),
|
|
33141
|
+
expiresAt: expiresAt.toString()
|
|
33142
|
+
};
|
|
33143
|
+
}
|
|
33144
|
+
|
|
33145
|
+
// src/protocol/escrow-deposit.ts
|
|
33146
|
+
import { encodeFunctionData } from "viem";
|
|
33147
|
+
var ESCROW_DEPOSIT_ABI = [
|
|
33148
|
+
{
|
|
33149
|
+
type: "function",
|
|
33150
|
+
name: "depositNative",
|
|
33151
|
+
stateMutability: "payable",
|
|
33152
|
+
inputs: [{ name: "account", type: "address" }],
|
|
33153
|
+
outputs: []
|
|
33154
|
+
},
|
|
33155
|
+
{
|
|
33156
|
+
type: "function",
|
|
33157
|
+
name: "depositToken",
|
|
33158
|
+
stateMutability: "nonpayable",
|
|
33159
|
+
inputs: [
|
|
33160
|
+
{ name: "account", type: "address" },
|
|
33161
|
+
{ name: "token", type: "address" },
|
|
33162
|
+
{ name: "amount", type: "uint256" }
|
|
33163
|
+
],
|
|
33164
|
+
outputs: []
|
|
33165
|
+
}
|
|
33166
|
+
];
|
|
33167
|
+
function escrowContractAddress(config) {
|
|
33168
|
+
return config.contracts.dataPortabilityEscrow;
|
|
33169
|
+
}
|
|
33170
|
+
function encodeDepositNativeData(input) {
|
|
33171
|
+
return encodeFunctionData({
|
|
33172
|
+
abi: ESCROW_DEPOSIT_ABI,
|
|
33173
|
+
functionName: "depositNative",
|
|
33174
|
+
args: [input.account]
|
|
33175
|
+
});
|
|
33176
|
+
}
|
|
33177
|
+
function encodeDepositTokenData(input) {
|
|
33178
|
+
return encodeFunctionData({
|
|
33179
|
+
abi: ESCROW_DEPOSIT_ABI,
|
|
33180
|
+
functionName: "depositToken",
|
|
33181
|
+
args: [input.account, input.token, input.amount]
|
|
33182
|
+
});
|
|
33183
|
+
}
|
|
33184
|
+
function buildDepositNativeRequest(config, input) {
|
|
33185
|
+
return {
|
|
33186
|
+
to: escrowContractAddress(config),
|
|
33187
|
+
data: encodeDepositNativeData({ account: input.account }),
|
|
33188
|
+
value: input.amount
|
|
33189
|
+
};
|
|
33190
|
+
}
|
|
33191
|
+
function buildDepositTokenRequest(config, input) {
|
|
33192
|
+
return {
|
|
33193
|
+
to: escrowContractAddress(config),
|
|
33194
|
+
data: encodeDepositTokenData(input)
|
|
33195
|
+
};
|
|
33196
|
+
}
|
|
33197
|
+
|
|
33198
|
+
// src/protocol/fee-registry.ts
|
|
33199
|
+
import { parseAbi } from "viem";
|
|
33200
|
+
var FEE_REGISTRY_ABI = parseAbi([
|
|
33201
|
+
"struct Fee { uint256 amount; address asset; address payee; bool enabled; }",
|
|
33202
|
+
"function fees(bytes32 operation) view returns (Fee)",
|
|
33203
|
+
"function operationKey(string name) pure returns (bytes32)"
|
|
33204
|
+
]);
|
|
33205
|
+
var REGISTRATION_KIND_FOR_OP = {
|
|
33206
|
+
grant: "grant_registration",
|
|
33207
|
+
data: "data_registration",
|
|
33208
|
+
server: "server_registration",
|
|
33209
|
+
builder: "builder_registration"
|
|
33210
|
+
};
|
|
33211
|
+
function operationNameFor(kind, opts) {
|
|
33212
|
+
switch (kind) {
|
|
33213
|
+
case "grant_registration":
|
|
33214
|
+
return opts?.grantRegistrationOpName ?? "grant_registration";
|
|
33215
|
+
case "data_access":
|
|
33216
|
+
return opts?.dataAccessOpName ?? "data_access";
|
|
33217
|
+
case "data_registration":
|
|
33218
|
+
return opts?.dataRegistrationOpName ?? "data_registration";
|
|
33219
|
+
case "server_registration":
|
|
33220
|
+
return opts?.serverRegistrationOpName ?? "server_registration";
|
|
33221
|
+
case "builder_registration":
|
|
33222
|
+
return opts?.builderRegistrationOpName ?? "builder_registration";
|
|
33223
|
+
}
|
|
33224
|
+
}
|
|
33225
|
+
var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
33226
|
+
async function getFee(client, config, kind, opts) {
|
|
33227
|
+
const address = config.contracts.feeRegistry;
|
|
33228
|
+
const opName = operationNameFor(kind, opts);
|
|
33229
|
+
const opKey = await client.readContract({
|
|
33230
|
+
address,
|
|
33231
|
+
abi: FEE_REGISTRY_ABI,
|
|
33232
|
+
functionName: "operationKey",
|
|
33233
|
+
args: [opName]
|
|
33234
|
+
});
|
|
33235
|
+
const fee = await client.readContract({
|
|
33236
|
+
address,
|
|
33237
|
+
abi: FEE_REGISTRY_ABI,
|
|
33238
|
+
functionName: "fees",
|
|
33239
|
+
args: [opKey]
|
|
33240
|
+
});
|
|
33241
|
+
if (fee.enabled && fee.payee === ZERO_ADDRESS) {
|
|
33242
|
+
throw new Error(
|
|
33243
|
+
`FeeRegistry: enabled operation "${opName}" has zero-address payee \u2014 contract pre-flight rejects payouts to 0x0`
|
|
33244
|
+
);
|
|
33245
|
+
}
|
|
33246
|
+
return fee;
|
|
33247
|
+
}
|
|
33248
|
+
async function getOpFee(client, config, opType, opts) {
|
|
33249
|
+
const registrationKind = REGISTRATION_KIND_FOR_OP[opType];
|
|
33250
|
+
if (!registrationKind) {
|
|
33251
|
+
throw new Error(
|
|
33252
|
+
`getOpFee: unknown opType "${opType}" \u2014 supported types are ${Object.keys(REGISTRATION_KIND_FOR_OP).join(", ")}`
|
|
33253
|
+
);
|
|
33254
|
+
}
|
|
33255
|
+
const includeDataAccess = opType === "grant";
|
|
33256
|
+
const [registration, dataAccess] = await Promise.all([
|
|
33257
|
+
getFee(client, config, registrationKind, opts),
|
|
33258
|
+
includeDataAccess ? getFee(client, config, "data_access", opts) : Promise.resolve({
|
|
33259
|
+
amount: 0n,
|
|
33260
|
+
asset: ZERO_ADDRESS,
|
|
33261
|
+
payee: ZERO_ADDRESS,
|
|
33262
|
+
enabled: false
|
|
33263
|
+
})
|
|
33264
|
+
]);
|
|
33265
|
+
if (registration.enabled && dataAccess.enabled && registration.asset.toLowerCase() !== dataAccess.asset.toLowerCase()) {
|
|
33266
|
+
throw new Error(
|
|
33267
|
+
`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.`
|
|
33268
|
+
);
|
|
33269
|
+
}
|
|
33270
|
+
const asset = registration.enabled ? registration.asset : dataAccess.enabled ? dataAccess.asset : ZERO_ADDRESS;
|
|
33271
|
+
return {
|
|
33272
|
+
asset,
|
|
33273
|
+
registrationFee: registration.enabled ? registration.amount : 0n,
|
|
33274
|
+
dataAccessFee: dataAccess.enabled ? dataAccess.amount : 0n,
|
|
33275
|
+
registrationEnabled: registration.enabled,
|
|
33276
|
+
dataAccessEnabled: dataAccess.enabled,
|
|
33277
|
+
registrationPayee: registration.enabled ? registration.payee : ZERO_ADDRESS,
|
|
33278
|
+
dataAccessPayee: dataAccess.enabled ? dataAccess.payee : ZERO_ADDRESS
|
|
33137
33279
|
};
|
|
33138
33280
|
}
|
|
33139
33281
|
|
|
@@ -33220,7 +33362,8 @@ function createGatewayClient(baseUrl) {
|
|
|
33220
33362
|
owner: record.owner ?? record.ownerAddress ?? "",
|
|
33221
33363
|
url: record.url,
|
|
33222
33364
|
schemaId: record.schemaId,
|
|
33223
|
-
createdAt: record.createdAt ?? record.addedAt ?? ""
|
|
33365
|
+
createdAt: record.createdAt ?? record.addedAt ?? "",
|
|
33366
|
+
deletedAt: record.deletedAt ?? null
|
|
33224
33367
|
};
|
|
33225
33368
|
}
|
|
33226
33369
|
function getMutationId(body, key) {
|
|
@@ -33280,19 +33423,24 @@ function createGatewayClient(baseUrl) {
|
|
|
33280
33423
|
}
|
|
33281
33424
|
return normalizeFileRecord(await unwrapEnvelope(res));
|
|
33282
33425
|
},
|
|
33283
|
-
async listFilesSince(owner, cursor) {
|
|
33426
|
+
async listFilesSince(owner, cursor, options) {
|
|
33284
33427
|
const params = new URLSearchParams({ user: owner });
|
|
33285
33428
|
if (cursor !== null) {
|
|
33286
|
-
params.set("
|
|
33429
|
+
params.set("cursor", cursor);
|
|
33430
|
+
}
|
|
33431
|
+
if (options?.includeDeleted) {
|
|
33432
|
+
params.set("includeDeleted", "true");
|
|
33287
33433
|
}
|
|
33288
33434
|
const res = await fetch(`${base}/v1/files?${params.toString()}`);
|
|
33289
33435
|
if (!res.ok) {
|
|
33290
33436
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33291
33437
|
}
|
|
33292
|
-
const
|
|
33438
|
+
const envelope = await res.json();
|
|
33439
|
+
const { pagination } = envelope;
|
|
33440
|
+
const nextCursor = pagination?.hasMore === false ? null : pagination?.nextCursor ?? envelope.data.cursor ?? null;
|
|
33293
33441
|
return {
|
|
33294
|
-
files: data.files.map(normalizeFileRecord),
|
|
33295
|
-
cursor:
|
|
33442
|
+
files: envelope.data.files.map(normalizeFileRecord),
|
|
33443
|
+
cursor: nextCursor
|
|
33296
33444
|
};
|
|
33297
33445
|
},
|
|
33298
33446
|
async getSchema(schemaId) {
|
|
@@ -33333,6 +33481,68 @@ function createGatewayClient(baseUrl) {
|
|
|
33333
33481
|
alreadyRegistered: false
|
|
33334
33482
|
};
|
|
33335
33483
|
},
|
|
33484
|
+
async registerBuilder(params) {
|
|
33485
|
+
const res = await fetch(`${base}/v1/builders`, {
|
|
33486
|
+
method: "POST",
|
|
33487
|
+
headers: {
|
|
33488
|
+
"Content-Type": "application/json",
|
|
33489
|
+
Authorization: `Web3Signed ${params.signature}`
|
|
33490
|
+
},
|
|
33491
|
+
body: JSON.stringify({
|
|
33492
|
+
ownerAddress: params.ownerAddress,
|
|
33493
|
+
granteeAddress: params.granteeAddress,
|
|
33494
|
+
publicKey: params.publicKey,
|
|
33495
|
+
appUrl: params.appUrl
|
|
33496
|
+
})
|
|
33497
|
+
});
|
|
33498
|
+
if (res.status === 409) {
|
|
33499
|
+
const body2 = await res.json().catch(() => ({}));
|
|
33500
|
+
return {
|
|
33501
|
+
builderId: getMutationId(
|
|
33502
|
+
body2,
|
|
33503
|
+
"builderId"
|
|
33504
|
+
),
|
|
33505
|
+
alreadyRegistered: true
|
|
33506
|
+
};
|
|
33507
|
+
}
|
|
33508
|
+
if (!res.ok) {
|
|
33509
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33510
|
+
}
|
|
33511
|
+
const body = await res.json().catch(() => ({}));
|
|
33512
|
+
return {
|
|
33513
|
+
builderId: getMutationId(body, "builderId"),
|
|
33514
|
+
alreadyRegistered: false
|
|
33515
|
+
};
|
|
33516
|
+
},
|
|
33517
|
+
async registerDataPoint(params) {
|
|
33518
|
+
const res = await fetch(`${base}/v1/data`, {
|
|
33519
|
+
method: "POST",
|
|
33520
|
+
headers: {
|
|
33521
|
+
"Content-Type": "application/json",
|
|
33522
|
+
Authorization: `Web3Signed ${params.signature}`
|
|
33523
|
+
},
|
|
33524
|
+
body: JSON.stringify({
|
|
33525
|
+
ownerAddress: params.ownerAddress,
|
|
33526
|
+
scope: params.scope,
|
|
33527
|
+
dataHash: params.dataHash,
|
|
33528
|
+
metadataHash: params.metadataHash,
|
|
33529
|
+
expectedVersion: params.expectedVersion
|
|
33530
|
+
})
|
|
33531
|
+
});
|
|
33532
|
+
if (!res.ok) {
|
|
33533
|
+
const body2 = await res.json().catch(() => ({}));
|
|
33534
|
+
const detail = body2.error ?? res.statusText;
|
|
33535
|
+
throw new Error(`Gateway error: ${res.status} ${detail}`);
|
|
33536
|
+
}
|
|
33537
|
+
const body = await res.json().catch(() => ({}));
|
|
33538
|
+
return {
|
|
33539
|
+
dataPointId: getMutationId(
|
|
33540
|
+
body,
|
|
33541
|
+
"dataPointId"
|
|
33542
|
+
),
|
|
33543
|
+
expectedVersion: body.expectedVersion
|
|
33544
|
+
};
|
|
33545
|
+
},
|
|
33336
33546
|
async registerFile(params) {
|
|
33337
33547
|
const res = await fetch(`${base}/v1/files`, {
|
|
33338
33548
|
method: "POST",
|
|
@@ -33370,8 +33580,9 @@ function createGatewayClient(baseUrl) {
|
|
|
33370
33580
|
body: JSON.stringify({
|
|
33371
33581
|
grantorAddress: params.grantorAddress,
|
|
33372
33582
|
granteeId: params.granteeId,
|
|
33373
|
-
|
|
33374
|
-
|
|
33583
|
+
scopes: params.scopes,
|
|
33584
|
+
grantVersion: params.grantVersion,
|
|
33585
|
+
expiresAt: params.expiresAt
|
|
33375
33586
|
})
|
|
33376
33587
|
});
|
|
33377
33588
|
if (res.status === 409) {
|
|
@@ -33396,7 +33607,8 @@ function createGatewayClient(baseUrl) {
|
|
|
33396
33607
|
Authorization: `Web3Signed ${params.signature}`
|
|
33397
33608
|
},
|
|
33398
33609
|
body: JSON.stringify({
|
|
33399
|
-
grantorAddress: params.grantorAddress
|
|
33610
|
+
grantorAddress: params.grantorAddress,
|
|
33611
|
+
grantVersion: params.grantVersion
|
|
33400
33612
|
})
|
|
33401
33613
|
});
|
|
33402
33614
|
if (res.status === 409) return;
|
|
@@ -33404,6 +33616,63 @@ function createGatewayClient(baseUrl) {
|
|
|
33404
33616
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33405
33617
|
}
|
|
33406
33618
|
},
|
|
33619
|
+
async getEscrowBalance(account) {
|
|
33620
|
+
const res = await fetch(`${base}/v1/escrow/balance?account=${account}`);
|
|
33621
|
+
if (!res.ok) {
|
|
33622
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33623
|
+
}
|
|
33624
|
+
return await res.json();
|
|
33625
|
+
},
|
|
33626
|
+
async submitEscrowDeposit(params) {
|
|
33627
|
+
const res = await fetch(`${base}/v1/escrow/deposit`, {
|
|
33628
|
+
method: "POST",
|
|
33629
|
+
headers: { "Content-Type": "application/json" },
|
|
33630
|
+
body: JSON.stringify({ txHash: params.txHash })
|
|
33631
|
+
});
|
|
33632
|
+
if (res.status !== 200 && res.status !== 202) {
|
|
33633
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33634
|
+
}
|
|
33635
|
+
return await res.json();
|
|
33636
|
+
},
|
|
33637
|
+
async payForOperation(params) {
|
|
33638
|
+
const body = {
|
|
33639
|
+
payerAddress: params.payerAddress,
|
|
33640
|
+
opType: params.opType,
|
|
33641
|
+
opId: params.opId,
|
|
33642
|
+
asset: params.asset,
|
|
33643
|
+
amount: params.amount,
|
|
33644
|
+
paymentNonce: params.paymentNonce
|
|
33645
|
+
};
|
|
33646
|
+
if (params.accessRecord) {
|
|
33647
|
+
body["accessRecord"] = params.accessRecord;
|
|
33648
|
+
}
|
|
33649
|
+
const res = await fetch(`${base}/v1/escrow/pay`, {
|
|
33650
|
+
method: "POST",
|
|
33651
|
+
headers: {
|
|
33652
|
+
"Content-Type": "application/json",
|
|
33653
|
+
Authorization: `Web3Signed ${params.signature}`
|
|
33654
|
+
},
|
|
33655
|
+
body: JSON.stringify(body)
|
|
33656
|
+
});
|
|
33657
|
+
if (!res.ok) {
|
|
33658
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33659
|
+
}
|
|
33660
|
+
return await res.json();
|
|
33661
|
+
},
|
|
33662
|
+
async settle(params) {
|
|
33663
|
+
const res = await fetch(`${base}/v1/settle`, {
|
|
33664
|
+
method: "POST",
|
|
33665
|
+
headers: { "Content-Type": "application/json" },
|
|
33666
|
+
// The gateway accepts an empty body; only `limit` is recognised.
|
|
33667
|
+
// Always send a JSON body so the gateway's req.body shape parse
|
|
33668
|
+
// doesn't have to deal with an undefined.
|
|
33669
|
+
body: JSON.stringify(params ?? {})
|
|
33670
|
+
});
|
|
33671
|
+
if (!res.ok) {
|
|
33672
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33673
|
+
}
|
|
33674
|
+
return await res.json();
|
|
33675
|
+
},
|
|
33407
33676
|
async deleteFile(params) {
|
|
33408
33677
|
const res = await fetch(`${base}/v1/files/${params.fileId}`, {
|
|
33409
33678
|
method: "DELETE",
|
|
@@ -33487,6 +33756,7 @@ async function parsePSError(response) {
|
|
|
33487
33756
|
}
|
|
33488
33757
|
export {
|
|
33489
33758
|
ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
|
|
33759
|
+
ADD_DATA_TYPES,
|
|
33490
33760
|
AccountPersonalServerLiteOwnerBindingError,
|
|
33491
33761
|
AccountPersonalServerRegistrationError,
|
|
33492
33762
|
BUILDER_REGISTRATION_TYPES,
|
|
@@ -33499,9 +33769,12 @@ export {
|
|
|
33499
33769
|
DataFileEnvelopeSchema,
|
|
33500
33770
|
DropboxStorage,
|
|
33501
33771
|
ECIESError,
|
|
33772
|
+
ESCROW_DEPOSIT_ABI,
|
|
33502
33773
|
ExpiredTokenError,
|
|
33774
|
+
FEE_REGISTRY_ABI,
|
|
33503
33775
|
FILE_DELETION_TYPES,
|
|
33504
33776
|
FILE_REGISTRATION_TYPES,
|
|
33777
|
+
GENERIC_PAYMENT_TYPES,
|
|
33505
33778
|
GRANT_REGISTRATION_TYPES,
|
|
33506
33779
|
GRANT_REVOCATION_TYPES,
|
|
33507
33780
|
GoogleDriveStorage,
|
|
@@ -33512,6 +33785,7 @@ export {
|
|
|
33512
33785
|
IpfsStorage,
|
|
33513
33786
|
MASTER_KEY_MESSAGE,
|
|
33514
33787
|
MissingAuthError,
|
|
33788
|
+
NATIVE_VANA_ASSET,
|
|
33515
33789
|
NetworkError,
|
|
33516
33790
|
NodeECIESUint8Provider as NodeECIESProvider,
|
|
33517
33791
|
NodePlatformAdapter,
|
|
@@ -33529,6 +33803,8 @@ export {
|
|
|
33529
33803
|
PersonalServerError,
|
|
33530
33804
|
PinataStorage,
|
|
33531
33805
|
R2Storage,
|
|
33806
|
+
RECORD_DATA_ACCESS_TYPES,
|
|
33807
|
+
REGISTRATION_KIND_FOR_OP,
|
|
33532
33808
|
ReadOnlyError,
|
|
33533
33809
|
RelayerError,
|
|
33534
33810
|
SERVER_REGISTRATION_TYPES,
|
|
@@ -33543,6 +33819,8 @@ export {
|
|
|
33543
33819
|
VanaError,
|
|
33544
33820
|
VanaStorage,
|
|
33545
33821
|
assertValidPkceVerifier,
|
|
33822
|
+
buildDepositNativeRequest,
|
|
33823
|
+
buildDepositTokenRequest,
|
|
33546
33824
|
buildPersonalServerLiteOwnerBindingMessage,
|
|
33547
33825
|
buildPersonalServerLiteOwnerBindingSignature,
|
|
33548
33826
|
buildPersonalServerRegistrationSignature,
|
|
@@ -33564,12 +33842,17 @@ export {
|
|
|
33564
33842
|
createVanaStorageProvider,
|
|
33565
33843
|
createViemPersonalServerLiteOwnerBindingSigner,
|
|
33566
33844
|
createViemPersonalServerRegistrationSigner,
|
|
33845
|
+
dataRegistryDomain,
|
|
33567
33846
|
decryptWithPassword,
|
|
33568
33847
|
deriveMasterKey,
|
|
33569
33848
|
deriveScopeKey,
|
|
33570
33849
|
deserializeECIES,
|
|
33571
33850
|
detectPlatform,
|
|
33851
|
+
encodeDepositNativeData,
|
|
33852
|
+
encodeDepositTokenData,
|
|
33572
33853
|
encryptWithPassword,
|
|
33854
|
+
escrowContractAddress,
|
|
33855
|
+
escrowPaymentDomain,
|
|
33573
33856
|
fileDeletionDomain,
|
|
33574
33857
|
fileRegistrationDomain,
|
|
33575
33858
|
generatePkceVerifier,
|
|
@@ -33579,6 +33862,8 @@ export {
|
|
|
33579
33862
|
getContractAddress,
|
|
33580
33863
|
getContractController,
|
|
33581
33864
|
getContractInfo,
|
|
33865
|
+
getFee,
|
|
33866
|
+
getOpFee,
|
|
33582
33867
|
getPlatformCapabilities,
|
|
33583
33868
|
getServiceEndpoints,
|
|
33584
33869
|
grantRegistrationDomain,
|
|
@@ -33590,7 +33875,6 @@ export {
|
|
|
33590
33875
|
moksha,
|
|
33591
33876
|
mokshaServices,
|
|
33592
33877
|
mokshaTestnet2 as mokshaTestnet,
|
|
33593
|
-
parseGrantRegistrationPayload,
|
|
33594
33878
|
parsePSError,
|
|
33595
33879
|
parseScope,
|
|
33596
33880
|
parseWeb3SignedHeader,
|