@opendatalabs/vana-sdk 3.22.0-pr.208.e9c19e9 → 3.22.0-pr.209.13d545d
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/crypto/envelope/job.cjs +26 -87
- package/dist/crypto/envelope/job.cjs.map +1 -1
- package/dist/crypto/envelope/job.d.ts +9 -95
- package/dist/crypto/envelope/job.js +27 -91
- package/dist/crypto/envelope/job.js.map +1 -1
- package/dist/direct/escrow-payment.cjs.map +1 -1
- package/dist/direct/escrow-payment.d.ts +2 -2
- package/dist/direct/escrow-payment.js.map +1 -1
- package/dist/index.browser.d.ts +2 -2
- package/dist/index.browser.js +39 -265
- package/dist/index.browser.js.map +3 -3
- package/dist/index.node.cjs +36 -267
- package/dist/index.node.cjs.map +3 -3
- package/dist/index.node.d.ts +2 -2
- package/dist/index.node.js +49 -275
- package/dist/index.node.js.map +3 -3
- package/dist/protocol/eip712.cjs +2 -28
- package/dist/protocol/eip712.cjs.map +1 -1
- package/dist/protocol/eip712.d.ts +0 -70
- package/dist/protocol/eip712.js +1 -24
- package/dist/protocol/eip712.js.map +1 -1
- package/dist/protocol/escrow.cjs +2 -154
- package/dist/protocol/escrow.cjs.map +1 -1
- package/dist/protocol/escrow.d.ts +2 -145
- package/dist/protocol/escrow.js +1 -152
- package/dist/protocol/escrow.js.map +1 -1
- package/dist/protocol/gateway.cjs.map +1 -1
- package/dist/protocol/gateway.d.ts +38 -8
- package/dist/protocol/gateway.js.map +1 -1
- package/dist/protocol/jobs.cjs.map +1 -1
- package/dist/protocol/jobs.d.ts +1 -23
- package/dist/protocol/jobs.js.map +1 -1
- package/package.json +1 -1
package/dist/protocol/eip712.cjs
CHANGED
|
@@ -26,15 +26,12 @@ __export(eip712_exports, {
|
|
|
26
26
|
NATIVE_VANA_ASSET: () => NATIVE_VANA_ASSET,
|
|
27
27
|
RECORD_DATA_ACCESS_TYPES: () => RECORD_DATA_ACCESS_TYPES,
|
|
28
28
|
SERVER_REGISTRATION_TYPES: () => SERVER_REGISTRATION_TYPES,
|
|
29
|
-
WITHDRAW_AUTHORIZATION_TYPES: () => WITHDRAW_AUTHORIZATION_TYPES,
|
|
30
|
-
buildWithdrawAuthorizationTypedData: () => buildWithdrawAuthorizationTypedData,
|
|
31
29
|
builderRegistrationDomain: () => builderRegistrationDomain,
|
|
32
30
|
dataRegistryDomain: () => dataRegistryDomain,
|
|
33
31
|
escrowPaymentDomain: () => escrowPaymentDomain,
|
|
34
32
|
grantRegistrationDomain: () => grantRegistrationDomain,
|
|
35
33
|
grantRevocationDomain: () => grantRevocationDomain,
|
|
36
|
-
serverRegistrationDomain: () => serverRegistrationDomain
|
|
37
|
-
withdrawAuthorizationDomain: () => withdrawAuthorizationDomain
|
|
34
|
+
serverRegistrationDomain: () => serverRegistrationDomain
|
|
38
35
|
});
|
|
39
36
|
module.exports = __toCommonJS(eip712_exports);
|
|
40
37
|
const DOMAIN_NAME = "Vana Data Portability";
|
|
@@ -84,9 +81,6 @@ function escrowPaymentDomain(config) {
|
|
|
84
81
|
config.contracts.dataPortabilityEscrow
|
|
85
82
|
);
|
|
86
83
|
}
|
|
87
|
-
function withdrawAuthorizationDomain(config) {
|
|
88
|
-
return escrowPaymentDomain(config);
|
|
89
|
-
}
|
|
90
84
|
const GRANT_REGISTRATION_TYPES = {
|
|
91
85
|
GrantRegistration: [
|
|
92
86
|
{ name: "grantorAddress", type: "address" },
|
|
@@ -129,15 +123,6 @@ const GENERIC_PAYMENT_TYPES = {
|
|
|
129
123
|
{ name: "paymentNonce", type: "uint256" }
|
|
130
124
|
]
|
|
131
125
|
};
|
|
132
|
-
const WITHDRAW_AUTHORIZATION_TYPES = {
|
|
133
|
-
WithdrawAuthorization: [
|
|
134
|
-
{ name: "account", type: "address" },
|
|
135
|
-
{ name: "asset", type: "address" },
|
|
136
|
-
{ name: "amount", type: "uint256" },
|
|
137
|
-
{ name: "withdrawNonce", type: "uint256" },
|
|
138
|
-
{ name: "deadline", type: "uint256" }
|
|
139
|
-
]
|
|
140
|
-
};
|
|
141
126
|
const ADD_DATA_TYPES = {
|
|
142
127
|
AddData: [
|
|
143
128
|
{ name: "ownerAddress", type: "address" },
|
|
@@ -156,14 +141,6 @@ const RECORD_DATA_ACCESS_TYPES = {
|
|
|
156
141
|
{ name: "recordId", type: "bytes32" }
|
|
157
142
|
]
|
|
158
143
|
};
|
|
159
|
-
function buildWithdrawAuthorizationTypedData(config, message) {
|
|
160
|
-
return {
|
|
161
|
-
domain: withdrawAuthorizationDomain(config),
|
|
162
|
-
types: WITHDRAW_AUTHORIZATION_TYPES,
|
|
163
|
-
primaryType: "WithdrawAuthorization",
|
|
164
|
-
message
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
144
|
// Annotate the CommonJS export names for ESM import in node:
|
|
168
145
|
0 && (module.exports = {
|
|
169
146
|
ADD_DATA_TYPES,
|
|
@@ -174,14 +151,11 @@ function buildWithdrawAuthorizationTypedData(config, message) {
|
|
|
174
151
|
NATIVE_VANA_ASSET,
|
|
175
152
|
RECORD_DATA_ACCESS_TYPES,
|
|
176
153
|
SERVER_REGISTRATION_TYPES,
|
|
177
|
-
WITHDRAW_AUTHORIZATION_TYPES,
|
|
178
|
-
buildWithdrawAuthorizationTypedData,
|
|
179
154
|
builderRegistrationDomain,
|
|
180
155
|
dataRegistryDomain,
|
|
181
156
|
escrowPaymentDomain,
|
|
182
157
|
grantRegistrationDomain,
|
|
183
158
|
grantRevocationDomain,
|
|
184
|
-
serverRegistrationDomain
|
|
185
|
-
withdrawAuthorizationDomain
|
|
159
|
+
serverRegistrationDomain
|
|
186
160
|
});
|
|
187
161
|
//# sourceMappingURL=eip712.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/protocol/eip712.ts"],"sourcesContent":["/**\n * EIP-712 domain and type builders for Data Portability protocol writes.\n *\n * These helpers are shared primitives only. Personal Server runtimes own when\n * to sign and submit these payloads.\n *\n * @category Protocol\n */\n\nimport type { TypedDataDomain } from \"viem\";\n\nconst DOMAIN_NAME = \"Vana Data Portability\";\nconst DOMAIN_VERSION = \"1\";\n\nexport interface DataPortabilityContracts {\n dataRegistry: string;\n dataPortabilityPermissions: string;\n dataPortabilityServer: string;\n dataPortabilityGrantees: string;\n // DataPortabilityEscrow — verifies GENERIC_PAYMENT_TYPES signatures backing\n // /v1/escrow/pay (the data-access payment path).\n dataPortabilityEscrow: string;\n // FeeRegistry — per-operation `{amount, asset, payee, enabled}` records\n // keyed on `keccak256(name)`. The gateway re-resolves fees against this\n // contract on every /v1/escrow/pay so the SDK has to read the same\n // source of truth to size payment amounts.\n feeRegistry: string;\n}\n\n// Native VANA asset sentinel used by /v1/escrow/pay's `asset` field — pay any\n// other ERC-20 by passing its contract address instead.\nexport const NATIVE_VANA_ASSET =\n \"0x0000000000000000000000000000000000000000\" as const;\n\nexport interface DataPortabilityGatewayConfig {\n chainId: number;\n contracts: DataPortabilityContracts;\n}\n\nfunction buildDomain(\n chainId: number,\n verifyingContract: `0x${string}`,\n): TypedDataDomain {\n return {\n name: DOMAIN_NAME,\n version: DOMAIN_VERSION,\n chainId,\n verifyingContract,\n };\n}\n\n// Domain for the DataRegistryV2 contract — verifies the AddData and\n// RecordDataAccess EIP-712 signatures. The v2 contract dropped the file\n// concept entirely in favor of versioned data points keyed on (owner,\n// scope); the primaryType distinguishes the two flows.\nexport function dataRegistryDomain(\n config: DataPortabilityGatewayConfig,\n): TypedDataDomain {\n return buildDomain(\n config.chainId,\n config.contracts.dataRegistry as `0x${string}`,\n );\n}\n\nexport function grantRegistrationDomain(\n config: DataPortabilityGatewayConfig,\n): TypedDataDomain {\n return buildDomain(\n config.chainId,\n config.contracts.dataPortabilityPermissions as `0x${string}`,\n );\n}\n\nexport function grantRevocationDomain(\n config: DataPortabilityGatewayConfig,\n): TypedDataDomain {\n return buildDomain(\n config.chainId,\n config.contracts.dataPortabilityPermissions as `0x${string}`,\n );\n}\n\nexport function serverRegistrationDomain(\n config: DataPortabilityGatewayConfig,\n): TypedDataDomain {\n return buildDomain(\n config.chainId,\n config.contracts.dataPortabilityServer as `0x${string}`,\n );\n}\n\nexport function builderRegistrationDomain(\n config: DataPortabilityGatewayConfig,\n): TypedDataDomain {\n return buildDomain(\n config.chainId,\n config.contracts.dataPortabilityGrantees as `0x${string}`,\n );\n}\n\n// Domain for the generic-payment EIP-712 signature consumed by\n// /v1/escrow/pay. The verifyingContract is the escrow itself (not the per-op\n// contract), so a single signature debits the payer's escrow balance for any\n// supported op — `grant` today; file/builder/schema in the future.\nexport function escrowPaymentDomain(\n config: DataPortabilityGatewayConfig,\n): TypedDataDomain {\n return buildDomain(\n config.chainId,\n config.contracts.dataPortabilityEscrow as `0x${string}`,\n );\n}\n\n/**\n * Domain for a gateway-authorized escrow withdrawal.\n *\n * Withdrawals use the escrow contract as their verifying contract, just like\n * generic payments. The distinct primary type prevents a payment signature\n * from authorizing a withdrawal.\n */\nexport function withdrawAuthorizationDomain(\n config: DataPortabilityGatewayConfig,\n): TypedDataDomain {\n return escrowPaymentDomain(config);\n}\n\n// grantVersion is a monotonic uint256 nonce per (grantor, grantee) pair. The\n// gateway rejects any registration whose version is <= the stored value,\n// which is the replay-attack defence now that re-registering the same pair\n// is a permitted override. expiresAt is unix seconds; 0 = no expiry.\nexport const GRANT_REGISTRATION_TYPES = {\n GrantRegistration: [\n { name: \"grantorAddress\", type: \"address\" },\n { name: \"granteeId\", type: \"bytes32\" },\n { name: \"scopes\", type: \"string[]\" },\n { name: \"grantVersion\", type: \"uint256\" },\n { name: \"expiresAt\", type: \"uint256\" },\n ],\n} as const;\n\n// Revocation shares the (grantor, grantee) monotonic nonce with registration —\n// both events advance the same grantVersion counter so an old revocation sig\n// can't be replayed across a revoke → re-register cycle.\nexport const GRANT_REVOCATION_TYPES = {\n GrantRevocation: [\n { name: \"grantorAddress\", type: \"address\" },\n { name: \"grantId\", type: \"bytes32\" },\n { name: \"grantVersion\", type: \"uint256\" },\n ],\n} as const;\n\nexport const SERVER_REGISTRATION_TYPES = {\n ServerRegistration: [\n { name: \"ownerAddress\", type: \"address\" },\n { name: \"serverAddress\", type: \"address\" },\n { name: \"publicKey\", type: \"string\" },\n { name: \"serverUrl\", type: \"string\" },\n ],\n} as const;\n\nexport const BUILDER_REGISTRATION_TYPES = {\n BuilderRegistration: [\n { name: \"ownerAddress\", type: \"address\" },\n { name: \"granteeAddress\", type: \"address\" },\n { name: \"publicKey\", type: \"string\" },\n { name: \"appUrl\", type: \"string\" },\n ],\n} as const;\n\n// Generic payment for the escrow flow. The (opType, opId) pair routes the\n// debit to the right op-row; paymentNonce is per-payer monotonic so the same\n// signed message can't be replayed after a revoke + re-register cycle.\n//\n// Legacy grant payments bind opId to grantId; standalone data_access payments\n// bind opId to the accompanying accessRecord.recordId.\nexport const GENERIC_PAYMENT_TYPES = {\n GenericPayment: [\n { name: \"payerAddress\", type: \"address\" },\n { name: \"opType\", type: \"string\" },\n { name: \"opId\", type: \"bytes32\" },\n { name: \"asset\", type: \"address\" },\n { name: \"amount\", type: \"uint256\" },\n { name: \"paymentNonce\", type: \"uint256\" },\n ],\n} as const;\n\n/**\n * Authorization consumed by `POST /v1/escrow/withdraw`.\n *\n * The current escrow contract always pays `account` itself. Do not add an\n * unsigned recipient field: a future recipient capability must be introduced\n * as a new, signed protocol type after the contract and gateway support it.\n */\nexport const WITHDRAW_AUTHORIZATION_TYPES = {\n WithdrawAuthorization: [\n { name: \"account\", type: \"address\" },\n { name: \"asset\", type: \"address\" },\n { name: \"amount\", type: \"uint256\" },\n { name: \"withdrawNonce\", type: \"uint256\" },\n { name: \"deadline\", type: \"uint256\" },\n ],\n} as const;\n\n// AddData is signed by the data point's owner — registers (scope, dataHash,\n// metadataHash) on DataRegistryV2. expectedVersion is the version the caller\n// believes is current; the contract rejects with a CAS error if it isn't.\n// Used at POST /v1/data.\nexport const ADD_DATA_TYPES = {\n AddData: [\n { name: \"ownerAddress\", type: \"address\" },\n { name: \"scope\", type: \"string\" },\n { name: \"dataHash\", type: \"bytes32\" },\n { name: \"metadataHash\", type: \"bytes32\" },\n { name: \"expectedVersion\", type: \"uint256\" },\n ],\n} as const;\n\n// RecordDataAccess is signed by a *trusted personal server* of `ownerAddress`\n// — attests that (scope, version) was served to `accessor`. recordId is a\n// per-event bytes32 the contract pins in `_usedRecordIds` to prevent replay.\n// Used as the optional `accessRecord` on POST /v1/escrow/pay.\nexport const RECORD_DATA_ACCESS_TYPES = {\n RecordDataAccess: [\n { name: \"ownerAddress\", type: \"address\" },\n { name: \"scope\", type: \"string\" },\n { name: \"version\", type: \"uint256\" },\n { name: \"accessor\", type: \"address\" },\n { name: \"recordId\", type: \"bytes32\" },\n ],\n} as const;\n\nexport interface GrantRegistrationMessage {\n grantorAddress: `0x${string}`;\n granteeId: `0x${string}`;\n scopes: string[];\n grantVersion: bigint;\n expiresAt: bigint;\n}\n\nexport interface GrantRevocationMessage {\n grantorAddress: `0x${string}`;\n grantId: `0x${string}`;\n grantVersion: bigint;\n}\n\nexport interface ServerRegistrationMessage {\n ownerAddress: `0x${string}`;\n serverAddress: `0x${string}`;\n publicKey: string;\n serverUrl: string;\n}\n\nexport interface BuilderRegistrationMessage {\n ownerAddress: `0x${string}`;\n granteeAddress: `0x${string}`;\n publicKey: string;\n appUrl: string;\n}\n\nexport interface GenericPaymentMessage {\n payerAddress: `0x${string}`;\n // 'grant' today — extensible to 'file' | 'builder' | 'schema' as those\n // op-types become payable. Sent verbatim over the wire and into the\n // typed-data string field, so callers must match the gateway's spelling.\n opType: string;\n opId: `0x${string}`;\n // NATIVE_VANA_ASSET for native VANA; an ERC-20 contract address otherwise.\n asset: `0x${string}`;\n amount: bigint;\n paymentNonce: bigint;\n}\n\n/** EIP-712 message authorizing a withdrawal of an account's escrow balance. */\nexport interface WithdrawAuthorizationMessage {\n /** The escrow account to debit and the withdrawal recipient. */\n account: `0x${string}`;\n /** Native VANA sentinel or the ERC-20 asset contract. */\n asset: `0x${string}`;\n /** Base-unit amount. */\n amount: bigint;\n /** Caller-managed, strictly increasing nonce for newly accepted intents. */\n withdrawNonce: bigint;\n /** Unix seconds. Bounds first acceptance; exact accepted retries remain valid. */\n deadline: bigint;\n}\n\n/** Builds the typed data a wallet must sign before calling the withdraw API. */\nexport function buildWithdrawAuthorizationTypedData(\n config: DataPortabilityGatewayConfig,\n message: WithdrawAuthorizationMessage,\n) {\n return {\n domain: withdrawAuthorizationDomain(config),\n types: WITHDRAW_AUTHORIZATION_TYPES,\n primaryType: \"WithdrawAuthorization\" as const,\n message,\n };\n}\n\nexport interface AddDataMessage {\n ownerAddress: `0x${string}`;\n scope: string;\n dataHash: `0x${string}`;\n metadataHash: `0x${string}`;\n expectedVersion: bigint;\n}\n\nexport interface RecordDataAccessMessage {\n ownerAddress: `0x${string}`;\n scope: string;\n version: bigint;\n accessor: `0x${string}`;\n recordId: `0x${string}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,MAAM,cAAc;AACpB,MAAM,iBAAiB;AAmBhB,MAAM,oBACX;AAOF,SAAS,YACP,SACA,mBACiB;AACjB,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IACT;AAAA,IACA;AAAA,EACF;AACF;AAMO,SAAS,mBACd,QACiB;AACjB,SAAO;AAAA,IACL,OAAO;AAAA,IACP,OAAO,UAAU;AAAA,EACnB;AACF;AAEO,SAAS,wBACd,QACiB;AACjB,SAAO;AAAA,IACL,OAAO;AAAA,IACP,OAAO,UAAU;AAAA,EACnB;AACF;AAEO,SAAS,sBACd,QACiB;AACjB,SAAO;AAAA,IACL,OAAO;AAAA,IACP,OAAO,UAAU;AAAA,EACnB;AACF;AAEO,SAAS,yBACd,QACiB;AACjB,SAAO;AAAA,IACL,OAAO;AAAA,IACP,OAAO,UAAU;AAAA,EACn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"version":3,"sources":["../../src/protocol/eip712.ts"],"sourcesContent":["/**\n * EIP-712 domain and type builders for Data Portability protocol writes.\n *\n * These helpers are shared primitives only. Personal Server runtimes own when\n * to sign and submit these payloads.\n *\n * @category Protocol\n */\n\nimport type { TypedDataDomain } from \"viem\";\n\nconst DOMAIN_NAME = \"Vana Data Portability\";\nconst DOMAIN_VERSION = \"1\";\n\nexport interface DataPortabilityContracts {\n dataRegistry: string;\n dataPortabilityPermissions: string;\n dataPortabilityServer: string;\n dataPortabilityGrantees: string;\n // DataPortabilityEscrow — verifies GENERIC_PAYMENT_TYPES signatures backing\n // /v1/escrow/pay (the data-access payment path).\n dataPortabilityEscrow: string;\n // FeeRegistry — per-operation `{amount, asset, payee, enabled}` records\n // keyed on `keccak256(name)`. The gateway re-resolves fees against this\n // contract on every /v1/escrow/pay so the SDK has to read the same\n // source of truth to size payment amounts.\n feeRegistry: string;\n}\n\n// Native VANA asset sentinel used by /v1/escrow/pay's `asset` field — pay any\n// other ERC-20 by passing its contract address instead.\nexport const NATIVE_VANA_ASSET =\n \"0x0000000000000000000000000000000000000000\" as const;\n\nexport interface DataPortabilityGatewayConfig {\n chainId: number;\n contracts: DataPortabilityContracts;\n}\n\nfunction buildDomain(\n chainId: number,\n verifyingContract: `0x${string}`,\n): TypedDataDomain {\n return {\n name: DOMAIN_NAME,\n version: DOMAIN_VERSION,\n chainId,\n verifyingContract,\n };\n}\n\n// Domain for the DataRegistryV2 contract — verifies the AddData and\n// RecordDataAccess EIP-712 signatures. The v2 contract dropped the file\n// concept entirely in favor of versioned data points keyed on (owner,\n// scope); the primaryType distinguishes the two flows.\nexport function dataRegistryDomain(\n config: DataPortabilityGatewayConfig,\n): TypedDataDomain {\n return buildDomain(\n config.chainId,\n config.contracts.dataRegistry as `0x${string}`,\n );\n}\n\nexport function grantRegistrationDomain(\n config: DataPortabilityGatewayConfig,\n): TypedDataDomain {\n return buildDomain(\n config.chainId,\n config.contracts.dataPortabilityPermissions as `0x${string}`,\n );\n}\n\nexport function grantRevocationDomain(\n config: DataPortabilityGatewayConfig,\n): TypedDataDomain {\n return buildDomain(\n config.chainId,\n config.contracts.dataPortabilityPermissions as `0x${string}`,\n );\n}\n\nexport function serverRegistrationDomain(\n config: DataPortabilityGatewayConfig,\n): TypedDataDomain {\n return buildDomain(\n config.chainId,\n config.contracts.dataPortabilityServer as `0x${string}`,\n );\n}\n\nexport function builderRegistrationDomain(\n config: DataPortabilityGatewayConfig,\n): TypedDataDomain {\n return buildDomain(\n config.chainId,\n config.contracts.dataPortabilityGrantees as `0x${string}`,\n );\n}\n\n// Domain for the generic-payment EIP-712 signature consumed by\n// /v1/escrow/pay. The verifyingContract is the escrow itself (not the per-op\n// contract), so a single signature debits the payer's escrow balance for any\n// supported op — `grant` today; file/builder/schema in the future.\nexport function escrowPaymentDomain(\n config: DataPortabilityGatewayConfig,\n): TypedDataDomain {\n return buildDomain(\n config.chainId,\n config.contracts.dataPortabilityEscrow as `0x${string}`,\n );\n}\n\n// grantVersion is a monotonic uint256 nonce per (grantor, grantee) pair. The\n// gateway rejects any registration whose version is <= the stored value,\n// which is the replay-attack defence now that re-registering the same pair\n// is a permitted override. expiresAt is unix seconds; 0 = no expiry.\nexport const GRANT_REGISTRATION_TYPES = {\n GrantRegistration: [\n { name: \"grantorAddress\", type: \"address\" },\n { name: \"granteeId\", type: \"bytes32\" },\n { name: \"scopes\", type: \"string[]\" },\n { name: \"grantVersion\", type: \"uint256\" },\n { name: \"expiresAt\", type: \"uint256\" },\n ],\n} as const;\n\n// Revocation shares the (grantor, grantee) monotonic nonce with registration —\n// both events advance the same grantVersion counter so an old revocation sig\n// can't be replayed across a revoke → re-register cycle.\nexport const GRANT_REVOCATION_TYPES = {\n GrantRevocation: [\n { name: \"grantorAddress\", type: \"address\" },\n { name: \"grantId\", type: \"bytes32\" },\n { name: \"grantVersion\", type: \"uint256\" },\n ],\n} as const;\n\nexport const SERVER_REGISTRATION_TYPES = {\n ServerRegistration: [\n { name: \"ownerAddress\", type: \"address\" },\n { name: \"serverAddress\", type: \"address\" },\n { name: \"publicKey\", type: \"string\" },\n { name: \"serverUrl\", type: \"string\" },\n ],\n} as const;\n\nexport const BUILDER_REGISTRATION_TYPES = {\n BuilderRegistration: [\n { name: \"ownerAddress\", type: \"address\" },\n { name: \"granteeAddress\", type: \"address\" },\n { name: \"publicKey\", type: \"string\" },\n { name: \"appUrl\", type: \"string\" },\n ],\n} as const;\n\n// Generic payment for the escrow flow. The (opType, opId) pair routes the\n// debit to the right op-row; paymentNonce is per-payer monotonic so the same\n// signed message can't be replayed after a revoke + re-register cycle.\n//\n// Legacy grant payments bind opId to grantId; standalone data_access payments\n// bind opId to the accompanying accessRecord.recordId.\nexport const GENERIC_PAYMENT_TYPES = {\n GenericPayment: [\n { name: \"payerAddress\", type: \"address\" },\n { name: \"opType\", type: \"string\" },\n { name: \"opId\", type: \"bytes32\" },\n { name: \"asset\", type: \"address\" },\n { name: \"amount\", type: \"uint256\" },\n { name: \"paymentNonce\", type: \"uint256\" },\n ],\n} as const;\n\n// AddData is signed by the data point's owner — registers (scope, dataHash,\n// metadataHash) on DataRegistryV2. expectedVersion is the version the caller\n// believes is current; the contract rejects with a CAS error if it isn't.\n// Used at POST /v1/data.\nexport const ADD_DATA_TYPES = {\n AddData: [\n { name: \"ownerAddress\", type: \"address\" },\n { name: \"scope\", type: \"string\" },\n { name: \"dataHash\", type: \"bytes32\" },\n { name: \"metadataHash\", type: \"bytes32\" },\n { name: \"expectedVersion\", type: \"uint256\" },\n ],\n} as const;\n\n// RecordDataAccess is signed by a *trusted personal server* of `ownerAddress`\n// — attests that (scope, version) was served to `accessor`. recordId is a\n// per-event bytes32 the contract pins in `_usedRecordIds` to prevent replay.\n// Used as the optional `accessRecord` on POST /v1/escrow/pay.\nexport const RECORD_DATA_ACCESS_TYPES = {\n RecordDataAccess: [\n { name: \"ownerAddress\", type: \"address\" },\n { name: \"scope\", type: \"string\" },\n { name: \"version\", type: \"uint256\" },\n { name: \"accessor\", type: \"address\" },\n { name: \"recordId\", type: \"bytes32\" },\n ],\n} as const;\n\nexport interface GrantRegistrationMessage {\n grantorAddress: `0x${string}`;\n granteeId: `0x${string}`;\n scopes: string[];\n grantVersion: bigint;\n expiresAt: bigint;\n}\n\nexport interface GrantRevocationMessage {\n grantorAddress: `0x${string}`;\n grantId: `0x${string}`;\n grantVersion: bigint;\n}\n\nexport interface ServerRegistrationMessage {\n ownerAddress: `0x${string}`;\n serverAddress: `0x${string}`;\n publicKey: string;\n serverUrl: string;\n}\n\nexport interface BuilderRegistrationMessage {\n ownerAddress: `0x${string}`;\n granteeAddress: `0x${string}`;\n publicKey: string;\n appUrl: string;\n}\n\nexport interface GenericPaymentMessage {\n payerAddress: `0x${string}`;\n // 'grant' today — extensible to 'file' | 'builder' | 'schema' as those\n // op-types become payable. Sent verbatim over the wire and into the\n // typed-data string field, so callers must match the gateway's spelling.\n opType: string;\n opId: `0x${string}`;\n // NATIVE_VANA_ASSET for native VANA; an ERC-20 contract address otherwise.\n asset: `0x${string}`;\n amount: bigint;\n paymentNonce: bigint;\n}\n\nexport interface AddDataMessage {\n ownerAddress: `0x${string}`;\n scope: string;\n dataHash: `0x${string}`;\n metadataHash: `0x${string}`;\n expectedVersion: bigint;\n}\n\nexport interface RecordDataAccessMessage {\n ownerAddress: `0x${string}`;\n scope: string;\n version: bigint;\n accessor: `0x${string}`;\n recordId: `0x${string}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,MAAM,cAAc;AACpB,MAAM,iBAAiB;AAmBhB,MAAM,oBACX;AAOF,SAAS,YACP,SACA,mBACiB;AACjB,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IACT;AAAA,IACA;AAAA,EACF;AACF;AAMO,SAAS,mBACd,QACiB;AACjB,SAAO;AAAA,I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A,EACxC,qBAAqB;AAAA,IACnB,EAAE,MAAM,gBAAgB,MAAM,UAAU;AAAA,IACxC,EAAE,MAAM,kBAAkB,MAAM,UAAU;AAAA,IAC1C,EAAE,MAAM,aAAa,MAAM,SAAS;AAAA,IACpC,EAAE,MAAM,UAAU,MAAM,SAAS;AAAA,EACnC;AACF;AAQO,MAAM,wBAAwB;AAAA,EACnC,gBAAgB;AAAA,IACd,EAAE,MAAM,gBAAgB,MAAM,UAAU;AAAA,IACxC,EAAE,MAAM,UAAU,MAAM,SAAS;AAAA,IACjC,EAAE,MAAM,QAAQ,MAAM,UAAU;AAAA,IAChC,EAAE,MAAM,SAAS,MAAM,UAAU;AAAA,IACjC,EAAE,MAAM,UAAU,MAAM,UAAU;AAAA,IAClC,EAAE,MAAM,gBAAgB,MAAM,UAAU;AAAA,EAC1C;AACF;AAMO,MAAM,iBAAiB;AAAA,EAC5B,SAAS;AAAA,IACP,EAAE,MAAM,gBAAgB,MAAM,UAAU;AAAA,IACxC,EAAE,MAAM,SAAS,MAAM,SAAS;AAAA,IAChC,EAAE,MAAM,YAAY,MAAM,UAAU;AAAA,IACpC,EAAE,MAAM,gBAAgB,MAAM,UAAU;AAAA,IACxC,EAAE,MAAM,mBAAmB,MAAM,UAAU;AAAA,EAC7C;AACF;AAMO,MAAM,2BAA2B;AAAA,EACtC,kBAAkB;AAAA,IAChB,EAAE,MAAM,gBAAgB,MAAM,UAAU;AAAA,IACxC,EAAE,MAAM,SAAS,MAAM,SAAS;AAAA,IAChC,EAAE,MAAM,WAAW,MAAM,UAAU;AAAA,IACnC,EAAE,MAAM,YAAY,MAAM,UAAU;AAAA,IACpC,EAAE,MAAM,YAAY,MAAM,UAAU;AAAA,EACtC;AACF;","names":[]}
|
|
@@ -26,14 +26,6 @@ export declare function grantRevocationDomain(config: DataPortabilityGatewayConf
|
|
|
26
26
|
export declare function serverRegistrationDomain(config: DataPortabilityGatewayConfig): TypedDataDomain;
|
|
27
27
|
export declare function builderRegistrationDomain(config: DataPortabilityGatewayConfig): TypedDataDomain;
|
|
28
28
|
export declare function escrowPaymentDomain(config: DataPortabilityGatewayConfig): TypedDataDomain;
|
|
29
|
-
/**
|
|
30
|
-
* Domain for a gateway-authorized escrow withdrawal.
|
|
31
|
-
*
|
|
32
|
-
* Withdrawals use the escrow contract as their verifying contract, just like
|
|
33
|
-
* generic payments. The distinct primary type prevents a payment signature
|
|
34
|
-
* from authorizing a withdrawal.
|
|
35
|
-
*/
|
|
36
|
-
export declare function withdrawAuthorizationDomain(config: DataPortabilityGatewayConfig): TypedDataDomain;
|
|
37
29
|
export declare const GRANT_REGISTRATION_TYPES: {
|
|
38
30
|
readonly GrantRegistration: readonly [{
|
|
39
31
|
readonly name: "grantorAddress";
|
|
@@ -115,31 +107,6 @@ export declare const GENERIC_PAYMENT_TYPES: {
|
|
|
115
107
|
readonly type: "uint256";
|
|
116
108
|
}];
|
|
117
109
|
};
|
|
118
|
-
/**
|
|
119
|
-
* Authorization consumed by `POST /v1/escrow/withdraw`.
|
|
120
|
-
*
|
|
121
|
-
* The current escrow contract always pays `account` itself. Do not add an
|
|
122
|
-
* unsigned recipient field: a future recipient capability must be introduced
|
|
123
|
-
* as a new, signed protocol type after the contract and gateway support it.
|
|
124
|
-
*/
|
|
125
|
-
export declare const WITHDRAW_AUTHORIZATION_TYPES: {
|
|
126
|
-
readonly WithdrawAuthorization: readonly [{
|
|
127
|
-
readonly name: "account";
|
|
128
|
-
readonly type: "address";
|
|
129
|
-
}, {
|
|
130
|
-
readonly name: "asset";
|
|
131
|
-
readonly type: "address";
|
|
132
|
-
}, {
|
|
133
|
-
readonly name: "amount";
|
|
134
|
-
readonly type: "uint256";
|
|
135
|
-
}, {
|
|
136
|
-
readonly name: "withdrawNonce";
|
|
137
|
-
readonly type: "uint256";
|
|
138
|
-
}, {
|
|
139
|
-
readonly name: "deadline";
|
|
140
|
-
readonly type: "uint256";
|
|
141
|
-
}];
|
|
142
|
-
};
|
|
143
110
|
export declare const ADD_DATA_TYPES: {
|
|
144
111
|
readonly AddData: readonly [{
|
|
145
112
|
readonly name: "ownerAddress";
|
|
@@ -208,43 +175,6 @@ export interface GenericPaymentMessage {
|
|
|
208
175
|
amount: bigint;
|
|
209
176
|
paymentNonce: bigint;
|
|
210
177
|
}
|
|
211
|
-
/** EIP-712 message authorizing a withdrawal of an account's escrow balance. */
|
|
212
|
-
export interface WithdrawAuthorizationMessage {
|
|
213
|
-
/** The escrow account to debit and the withdrawal recipient. */
|
|
214
|
-
account: `0x${string}`;
|
|
215
|
-
/** Native VANA sentinel or the ERC-20 asset contract. */
|
|
216
|
-
asset: `0x${string}`;
|
|
217
|
-
/** Base-unit amount. */
|
|
218
|
-
amount: bigint;
|
|
219
|
-
/** Caller-managed, strictly increasing nonce for newly accepted intents. */
|
|
220
|
-
withdrawNonce: bigint;
|
|
221
|
-
/** Unix seconds. Bounds first acceptance; exact accepted retries remain valid. */
|
|
222
|
-
deadline: bigint;
|
|
223
|
-
}
|
|
224
|
-
/** Builds the typed data a wallet must sign before calling the withdraw API. */
|
|
225
|
-
export declare function buildWithdrawAuthorizationTypedData(config: DataPortabilityGatewayConfig, message: WithdrawAuthorizationMessage): {
|
|
226
|
-
domain: TypedDataDomain;
|
|
227
|
-
types: {
|
|
228
|
-
readonly WithdrawAuthorization: readonly [{
|
|
229
|
-
readonly name: "account";
|
|
230
|
-
readonly type: "address";
|
|
231
|
-
}, {
|
|
232
|
-
readonly name: "asset";
|
|
233
|
-
readonly type: "address";
|
|
234
|
-
}, {
|
|
235
|
-
readonly name: "amount";
|
|
236
|
-
readonly type: "uint256";
|
|
237
|
-
}, {
|
|
238
|
-
readonly name: "withdrawNonce";
|
|
239
|
-
readonly type: "uint256";
|
|
240
|
-
}, {
|
|
241
|
-
readonly name: "deadline";
|
|
242
|
-
readonly type: "uint256";
|
|
243
|
-
}];
|
|
244
|
-
};
|
|
245
|
-
primaryType: "WithdrawAuthorization";
|
|
246
|
-
message: WithdrawAuthorizationMessage;
|
|
247
|
-
};
|
|
248
178
|
export interface AddDataMessage {
|
|
249
179
|
ownerAddress: `0x${string}`;
|
|
250
180
|
scope: string;
|
package/dist/protocol/eip712.js
CHANGED
|
@@ -45,9 +45,6 @@ function escrowPaymentDomain(config) {
|
|
|
45
45
|
config.contracts.dataPortabilityEscrow
|
|
46
46
|
);
|
|
47
47
|
}
|
|
48
|
-
function withdrawAuthorizationDomain(config) {
|
|
49
|
-
return escrowPaymentDomain(config);
|
|
50
|
-
}
|
|
51
48
|
const GRANT_REGISTRATION_TYPES = {
|
|
52
49
|
GrantRegistration: [
|
|
53
50
|
{ name: "grantorAddress", type: "address" },
|
|
@@ -90,15 +87,6 @@ const GENERIC_PAYMENT_TYPES = {
|
|
|
90
87
|
{ name: "paymentNonce", type: "uint256" }
|
|
91
88
|
]
|
|
92
89
|
};
|
|
93
|
-
const WITHDRAW_AUTHORIZATION_TYPES = {
|
|
94
|
-
WithdrawAuthorization: [
|
|
95
|
-
{ name: "account", type: "address" },
|
|
96
|
-
{ name: "asset", type: "address" },
|
|
97
|
-
{ name: "amount", type: "uint256" },
|
|
98
|
-
{ name: "withdrawNonce", type: "uint256" },
|
|
99
|
-
{ name: "deadline", type: "uint256" }
|
|
100
|
-
]
|
|
101
|
-
};
|
|
102
90
|
const ADD_DATA_TYPES = {
|
|
103
91
|
AddData: [
|
|
104
92
|
{ name: "ownerAddress", type: "address" },
|
|
@@ -117,14 +105,6 @@ const RECORD_DATA_ACCESS_TYPES = {
|
|
|
117
105
|
{ name: "recordId", type: "bytes32" }
|
|
118
106
|
]
|
|
119
107
|
};
|
|
120
|
-
function buildWithdrawAuthorizationTypedData(config, message) {
|
|
121
|
-
return {
|
|
122
|
-
domain: withdrawAuthorizationDomain(config),
|
|
123
|
-
types: WITHDRAW_AUTHORIZATION_TYPES,
|
|
124
|
-
primaryType: "WithdrawAuthorization",
|
|
125
|
-
message
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
108
|
export {
|
|
129
109
|
ADD_DATA_TYPES,
|
|
130
110
|
BUILDER_REGISTRATION_TYPES,
|
|
@@ -134,14 +114,11 @@ export {
|
|
|
134
114
|
NATIVE_VANA_ASSET,
|
|
135
115
|
RECORD_DATA_ACCESS_TYPES,
|
|
136
116
|
SERVER_REGISTRATION_TYPES,
|
|
137
|
-
WITHDRAW_AUTHORIZATION_TYPES,
|
|
138
|
-
buildWithdrawAuthorizationTypedData,
|
|
139
117
|
builderRegistrationDomain,
|
|
140
118
|
dataRegistryDomain,
|
|
141
119
|
escrowPaymentDomain,
|
|
142
120
|
grantRegistrationDomain,
|
|
143
121
|
grantRevocationDomain,
|
|
144
|
-
serverRegistrationDomain
|
|
145
|
-
withdrawAuthorizationDomain
|
|
122
|
+
serverRegistrationDomain
|
|
146
123
|
};
|
|
147
124
|
//# sourceMappingURL=eip712.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/protocol/eip712.ts"],"sourcesContent":["/**\n * EIP-712 domain and type builders for Data Portability protocol writes.\n *\n * These helpers are shared primitives only. Personal Server runtimes own when\n * to sign and submit these payloads.\n *\n * @category Protocol\n */\n\nimport type { TypedDataDomain } from \"viem\";\n\nconst DOMAIN_NAME = \"Vana Data Portability\";\nconst DOMAIN_VERSION = \"1\";\n\nexport interface DataPortabilityContracts {\n dataRegistry: string;\n dataPortabilityPermissions: string;\n dataPortabilityServer: string;\n dataPortabilityGrantees: string;\n // DataPortabilityEscrow — verifies GENERIC_PAYMENT_TYPES signatures backing\n // /v1/escrow/pay (the data-access payment path).\n dataPortabilityEscrow: string;\n // FeeRegistry — per-operation `{amount, asset, payee, enabled}` records\n // keyed on `keccak256(name)`. The gateway re-resolves fees against this\n // contract on every /v1/escrow/pay so the SDK has to read the same\n // source of truth to size payment amounts.\n feeRegistry: string;\n}\n\n// Native VANA asset sentinel used by /v1/escrow/pay's `asset` field — pay any\n// other ERC-20 by passing its contract address instead.\nexport const NATIVE_VANA_ASSET =\n \"0x0000000000000000000000000000000000000000\" as const;\n\nexport interface DataPortabilityGatewayConfig {\n chainId: number;\n contracts: DataPortabilityContracts;\n}\n\nfunction buildDomain(\n chainId: number,\n verifyingContract: `0x${string}`,\n): TypedDataDomain {\n return {\n name: DOMAIN_NAME,\n version: DOMAIN_VERSION,\n chainId,\n verifyingContract,\n };\n}\n\n// Domain for the DataRegistryV2 contract — verifies the AddData and\n// RecordDataAccess EIP-712 signatures. The v2 contract dropped the file\n// concept entirely in favor of versioned data points keyed on (owner,\n// scope); the primaryType distinguishes the two flows.\nexport function dataRegistryDomain(\n config: DataPortabilityGatewayConfig,\n): TypedDataDomain {\n return buildDomain(\n config.chainId,\n config.contracts.dataRegistry as `0x${string}`,\n );\n}\n\nexport function grantRegistrationDomain(\n config: DataPortabilityGatewayConfig,\n): TypedDataDomain {\n return buildDomain(\n config.chainId,\n config.contracts.dataPortabilityPermissions as `0x${string}`,\n );\n}\n\nexport function grantRevocationDomain(\n config: DataPortabilityGatewayConfig,\n): TypedDataDomain {\n return buildDomain(\n config.chainId,\n config.contracts.dataPortabilityPermissions as `0x${string}`,\n );\n}\n\nexport function serverRegistrationDomain(\n config: DataPortabilityGatewayConfig,\n): TypedDataDomain {\n return buildDomain(\n config.chainId,\n config.contracts.dataPortabilityServer as `0x${string}`,\n );\n}\n\nexport function builderRegistrationDomain(\n config: DataPortabilityGatewayConfig,\n): TypedDataDomain {\n return buildDomain(\n config.chainId,\n config.contracts.dataPortabilityGrantees as `0x${string}`,\n );\n}\n\n// Domain for the generic-payment EIP-712 signature consumed by\n// /v1/escrow/pay. The verifyingContract is the escrow itself (not the per-op\n// contract), so a single signature debits the payer's escrow balance for any\n// supported op — `grant` today; file/builder/schema in the future.\nexport function escrowPaymentDomain(\n config: DataPortabilityGatewayConfig,\n): TypedDataDomain {\n return buildDomain(\n config.chainId,\n config.contracts.dataPortabilityEscrow as `0x${string}`,\n );\n}\n\n/**\n * Domain for a gateway-authorized escrow withdrawal.\n *\n * Withdrawals use the escrow contract as their verifying contract, just like\n * generic payments. The distinct primary type prevents a payment signature\n * from authorizing a withdrawal.\n */\nexport function withdrawAuthorizationDomain(\n config: DataPortabilityGatewayConfig,\n): TypedDataDomain {\n return escrowPaymentDomain(config);\n}\n\n// grantVersion is a monotonic uint256 nonce per (grantor, grantee) pair. The\n// gateway rejects any registration whose version is <= the stored value,\n// which is the replay-attack defence now that re-registering the same pair\n// is a permitted override. expiresAt is unix seconds; 0 = no expiry.\nexport const GRANT_REGISTRATION_TYPES = {\n GrantRegistration: [\n { name: \"grantorAddress\", type: \"address\" },\n { name: \"granteeId\", type: \"bytes32\" },\n { name: \"scopes\", type: \"string[]\" },\n { name: \"grantVersion\", type: \"uint256\" },\n { name: \"expiresAt\", type: \"uint256\" },\n ],\n} as const;\n\n// Revocation shares the (grantor, grantee) monotonic nonce with registration —\n// both events advance the same grantVersion counter so an old revocation sig\n// can't be replayed across a revoke → re-register cycle.\nexport const GRANT_REVOCATION_TYPES = {\n GrantRevocation: [\n { name: \"grantorAddress\", type: \"address\" },\n { name: \"grantId\", type: \"bytes32\" },\n { name: \"grantVersion\", type: \"uint256\" },\n ],\n} as const;\n\nexport const SERVER_REGISTRATION_TYPES = {\n ServerRegistration: [\n { name: \"ownerAddress\", type: \"address\" },\n { name: \"serverAddress\", type: \"address\" },\n { name: \"publicKey\", type: \"string\" },\n { name: \"serverUrl\", type: \"string\" },\n ],\n} as const;\n\nexport const BUILDER_REGISTRATION_TYPES = {\n BuilderRegistration: [\n { name: \"ownerAddress\", type: \"address\" },\n { name: \"granteeAddress\", type: \"address\" },\n { name: \"publicKey\", type: \"string\" },\n { name: \"appUrl\", type: \"string\" },\n ],\n} as const;\n\n// Generic payment for the escrow flow. The (opType, opId) pair routes the\n// debit to the right op-row; paymentNonce is per-payer monotonic so the same\n// signed message can't be replayed after a revoke + re-register cycle.\n//\n// Legacy grant payments bind opId to grantId; standalone data_access payments\n// bind opId to the accompanying accessRecord.recordId.\nexport const GENERIC_PAYMENT_TYPES = {\n GenericPayment: [\n { name: \"payerAddress\", type: \"address\" },\n { name: \"opType\", type: \"string\" },\n { name: \"opId\", type: \"bytes32\" },\n { name: \"asset\", type: \"address\" },\n { name: \"amount\", type: \"uint256\" },\n { name: \"paymentNonce\", type: \"uint256\" },\n ],\n} as const;\n\n/**\n * Authorization consumed by `POST /v1/escrow/withdraw`.\n *\n * The current escrow contract always pays `account` itself. Do not add an\n * unsigned recipient field: a future recipient capability must be introduced\n * as a new, signed protocol type after the contract and gateway support it.\n */\nexport const WITHDRAW_AUTHORIZATION_TYPES = {\n WithdrawAuthorization: [\n { name: \"account\", type: \"address\" },\n { name: \"asset\", type: \"address\" },\n { name: \"amount\", type: \"uint256\" },\n { name: \"withdrawNonce\", type: \"uint256\" },\n { name: \"deadline\", type: \"uint256\" },\n ],\n} as const;\n\n// AddData is signed by the data point's owner — registers (scope, dataHash,\n// metadataHash) on DataRegistryV2. expectedVersion is the version the caller\n// believes is current; the contract rejects with a CAS error if it isn't.\n// Used at POST /v1/data.\nexport const ADD_DATA_TYPES = {\n AddData: [\n { name: \"ownerAddress\", type: \"address\" },\n { name: \"scope\", type: \"string\" },\n { name: \"dataHash\", type: \"bytes32\" },\n { name: \"metadataHash\", type: \"bytes32\" },\n { name: \"expectedVersion\", type: \"uint256\" },\n ],\n} as const;\n\n// RecordDataAccess is signed by a *trusted personal server* of `ownerAddress`\n// — attests that (scope, version) was served to `accessor`. recordId is a\n// per-event bytes32 the contract pins in `_usedRecordIds` to prevent replay.\n// Used as the optional `accessRecord` on POST /v1/escrow/pay.\nexport const RECORD_DATA_ACCESS_TYPES = {\n RecordDataAccess: [\n { name: \"ownerAddress\", type: \"address\" },\n { name: \"scope\", type: \"string\" },\n { name: \"version\", type: \"uint256\" },\n { name: \"accessor\", type: \"address\" },\n { name: \"recordId\", type: \"bytes32\" },\n ],\n} as const;\n\nexport interface GrantRegistrationMessage {\n grantorAddress: `0x${string}`;\n granteeId: `0x${string}`;\n scopes: string[];\n grantVersion: bigint;\n expiresAt: bigint;\n}\n\nexport interface GrantRevocationMessage {\n grantorAddress: `0x${string}`;\n grantId: `0x${string}`;\n grantVersion: bigint;\n}\n\nexport interface ServerRegistrationMessage {\n ownerAddress: `0x${string}`;\n serverAddress: `0x${string}`;\n publicKey: string;\n serverUrl: string;\n}\n\nexport interface BuilderRegistrationMessage {\n ownerAddress: `0x${string}`;\n granteeAddress: `0x${string}`;\n publicKey: string;\n appUrl: string;\n}\n\nexport interface GenericPaymentMessage {\n payerAddress: `0x${string}`;\n // 'grant' today — extensible to 'file' | 'builder' | 'schema' as those\n // op-types become payable. Sent verbatim over the wire and into the\n // typed-data string field, so callers must match the gateway's spelling.\n opType: string;\n opId: `0x${string}`;\n // NATIVE_VANA_ASSET for native VANA; an ERC-20 contract address otherwise.\n asset: `0x${string}`;\n amount: bigint;\n paymentNonce: bigint;\n}\n\n/** EIP-712 message authorizing a withdrawal of an account's escrow balance. */\nexport interface WithdrawAuthorizationMessage {\n /** The escrow account to debit and the withdrawal recipient. */\n account: `0x${string}`;\n /** Native VANA sentinel or the ERC-20 asset contract. */\n asset: `0x${string}`;\n /** Base-unit amount. */\n amount: bigint;\n /** Caller-managed, strictly increasing nonce for newly accepted intents. */\n withdrawNonce: bigint;\n /** Unix seconds. Bounds first acceptance; exact accepted retries remain valid. */\n deadline: bigint;\n}\n\n/** Builds the typed data a wallet must sign before calling the withdraw API. */\nexport function buildWithdrawAuthorizationTypedData(\n config: DataPortabilityGatewayConfig,\n message: WithdrawAuthorizationMessage,\n) {\n return {\n domain: withdrawAuthorizationDomain(config),\n types: WITHDRAW_AUTHORIZATION_TYPES,\n primaryType: \"WithdrawAuthorization\" as const,\n message,\n };\n}\n\nexport interface AddDataMessage {\n ownerAddress: `0x${string}`;\n scope: string;\n dataHash: `0x${string}`;\n metadataHash: `0x${string}`;\n expectedVersion: bigint;\n}\n\nexport interface RecordDataAccessMessage {\n ownerAddress: `0x${string}`;\n scope: string;\n version: bigint;\n accessor: `0x${string}`;\n recordId: `0x${string}`;\n}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MAAM,UAAU;AAAA,IACpC,EAAE,MAAM,gBAAgB,MAAM,UAAU;AAAA,IACxC,EAAE,MAAM,mBAAmB,MAAM,UAAU;AAAA,EAC7C;AACF;AAMO,MAAM,2BAA2B;AAAA,EACtC,kBAAkB;AAAA,IAChB,EAAE,MAAM,gBAAgB,MAAM,UAAU;AAAA,IACxC,EAAE,MAAM,SAAS,MAAM,SAAS;AAAA,IAChC,EAAE,MAAM,WAAW,MAAM,UAAU;AAAA,IACnC,EAAE,MAAM,YAAY,MAAM,UAAU;AAAA,IACpC,EAAE,MAAM,YAAY,MAAM,UAAU;AAAA,EACtC;AACF;AA0DO,SAAS,oCACd,QACA,SACA;AACA,SAAO;AAAA,IACL,QAAQ,4BAA4B,MAAM;AAAA,IAC1C,OAAO;AAAA,IACP,aAAa;AAAA,IACb;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/protocol/eip712.ts"],"sourcesContent":["/**\n * EIP-712 domain and type builders for Data Portability protocol writes.\n *\n * These helpers are shared primitives only. Personal Server runtimes own when\n * to sign and submit these payloads.\n *\n * @category Protocol\n */\n\nimport type { TypedDataDomain } from \"viem\";\n\nconst DOMAIN_NAME = \"Vana Data Portability\";\nconst DOMAIN_VERSION = \"1\";\n\nexport interface DataPortabilityContracts {\n dataRegistry: string;\n dataPortabilityPermissions: string;\n dataPortabilityServer: string;\n dataPortabilityGrantees: string;\n // DataPortabilityEscrow — verifies GENERIC_PAYMENT_TYPES signatures backing\n // /v1/escrow/pay (the data-access payment path).\n dataPortabilityEscrow: string;\n // FeeRegistry — per-operation `{amount, asset, payee, enabled}` records\n // keyed on `keccak256(name)`. The gateway re-resolves fees against this\n // contract on every /v1/escrow/pay so the SDK has to read the same\n // source of truth to size payment amounts.\n feeRegistry: string;\n}\n\n// Native VANA asset sentinel used by /v1/escrow/pay's `asset` field — pay any\n// other ERC-20 by passing its contract address instead.\nexport const NATIVE_VANA_ASSET =\n \"0x0000000000000000000000000000000000000000\" as const;\n\nexport interface DataPortabilityGatewayConfig {\n chainId: number;\n contracts: DataPortabilityContracts;\n}\n\nfunction buildDomain(\n chainId: number,\n verifyingContract: `0x${string}`,\n): TypedDataDomain {\n return {\n name: DOMAIN_NAME,\n version: DOMAIN_VERSION,\n chainId,\n verifyingContract,\n };\n}\n\n// Domain for the DataRegistryV2 contract — verifies the AddData and\n// RecordDataAccess EIP-712 signatures. The v2 contract dropped the file\n// concept entirely in favor of versioned data points keyed on (owner,\n// scope); the primaryType distinguishes the two flows.\nexport function dataRegistryDomain(\n config: DataPortabilityGatewayConfig,\n): TypedDataDomain {\n return buildDomain(\n config.chainId,\n config.contracts.dataRegistry as `0x${string}`,\n );\n}\n\nexport function grantRegistrationDomain(\n config: DataPortabilityGatewayConfig,\n): TypedDataDomain {\n return buildDomain(\n config.chainId,\n config.contracts.dataPortabilityPermissions as `0x${string}`,\n );\n}\n\nexport function grantRevocationDomain(\n config: DataPortabilityGatewayConfig,\n): TypedDataDomain {\n return buildDomain(\n config.chainId,\n config.contracts.dataPortabilityPermissions as `0x${string}`,\n );\n}\n\nexport function serverRegistrationDomain(\n config: DataPortabilityGatewayConfig,\n): TypedDataDomain {\n return buildDomain(\n config.chainId,\n config.contracts.dataPortabilityServer as `0x${string}`,\n );\n}\n\nexport function builderRegistrationDomain(\n config: DataPortabilityGatewayConfig,\n): TypedDataDomain {\n return buildDomain(\n config.chainId,\n config.contracts.dataPortabilityGrantees as `0x${string}`,\n );\n}\n\n// Domain for the generic-payment EIP-712 signature consumed by\n// /v1/escrow/pay. The verifyingContract is the escrow itself (not the per-op\n// contract), so a single signature debits the payer's escrow balance for any\n// supported op — `grant` today; file/builder/schema in the future.\nexport function escrowPaymentDomain(\n config: DataPortabilityGatewayConfig,\n): TypedDataDomain {\n return buildDomain(\n config.chainId,\n config.contracts.dataPortabilityEscrow as `0x${string}`,\n );\n}\n\n// grantVersion is a monotonic uint256 nonce per (grantor, grantee) pair. The\n// gateway rejects any registration whose version is <= the stored value,\n// which is the replay-attack defence now that re-registering the same pair\n// is a permitted override. expiresAt is unix seconds; 0 = no expiry.\nexport const GRANT_REGISTRATION_TYPES = {\n GrantRegistration: [\n { name: \"grantorAddress\", type: \"address\" },\n { name: \"granteeId\", type: \"bytes32\" },\n { name: \"scopes\", type: \"string[]\" },\n { name: \"grantVersion\", type: \"uint256\" },\n { name: \"expiresAt\", type: \"uint256\" },\n ],\n} as const;\n\n// Revocation shares the (grantor, grantee) monotonic nonce with registration —\n// both events advance the same grantVersion counter so an old revocation sig\n// can't be replayed across a revoke → re-register cycle.\nexport const GRANT_REVOCATION_TYPES = {\n GrantRevocation: [\n { name: \"grantorAddress\", type: \"address\" },\n { name: \"grantId\", type: \"bytes32\" },\n { name: \"grantVersion\", type: \"uint256\" },\n ],\n} as const;\n\nexport const SERVER_REGISTRATION_TYPES = {\n ServerRegistration: [\n { name: \"ownerAddress\", type: \"address\" },\n { name: \"serverAddress\", type: \"address\" },\n { name: \"publicKey\", type: \"string\" },\n { name: \"serverUrl\", type: \"string\" },\n ],\n} as const;\n\nexport const BUILDER_REGISTRATION_TYPES = {\n BuilderRegistration: [\n { name: \"ownerAddress\", type: \"address\" },\n { name: \"granteeAddress\", type: \"address\" },\n { name: \"publicKey\", type: \"string\" },\n { name: \"appUrl\", type: \"string\" },\n ],\n} as const;\n\n// Generic payment for the escrow flow. The (opType, opId) pair routes the\n// debit to the right op-row; paymentNonce is per-payer monotonic so the same\n// signed message can't be replayed after a revoke + re-register cycle.\n//\n// Legacy grant payments bind opId to grantId; standalone data_access payments\n// bind opId to the accompanying accessRecord.recordId.\nexport const GENERIC_PAYMENT_TYPES = {\n GenericPayment: [\n { name: \"payerAddress\", type: \"address\" },\n { name: \"opType\", type: \"string\" },\n { name: \"opId\", type: \"bytes32\" },\n { name: \"asset\", type: \"address\" },\n { name: \"amount\", type: \"uint256\" },\n { name: \"paymentNonce\", type: \"uint256\" },\n ],\n} as const;\n\n// AddData is signed by the data point's owner — registers (scope, dataHash,\n// metadataHash) on DataRegistryV2. expectedVersion is the version the caller\n// believes is current; the contract rejects with a CAS error if it isn't.\n// Used at POST /v1/data.\nexport const ADD_DATA_TYPES = {\n AddData: [\n { name: \"ownerAddress\", type: \"address\" },\n { name: \"scope\", type: \"string\" },\n { name: \"dataHash\", type: \"bytes32\" },\n { name: \"metadataHash\", type: \"bytes32\" },\n { name: \"expectedVersion\", type: \"uint256\" },\n ],\n} as const;\n\n// RecordDataAccess is signed by a *trusted personal server* of `ownerAddress`\n// — attests that (scope, version) was served to `accessor`. recordId is a\n// per-event bytes32 the contract pins in `_usedRecordIds` to prevent replay.\n// Used as the optional `accessRecord` on POST /v1/escrow/pay.\nexport const RECORD_DATA_ACCESS_TYPES = {\n RecordDataAccess: [\n { name: \"ownerAddress\", type: \"address\" },\n { name: \"scope\", type: \"string\" },\n { name: \"version\", type: \"uint256\" },\n { name: \"accessor\", type: \"address\" },\n { name: \"recordId\", type: \"bytes32\" },\n ],\n} as const;\n\nexport interface GrantRegistrationMessage {\n grantorAddress: `0x${string}`;\n granteeId: `0x${string}`;\n scopes: string[];\n grantVersion: bigint;\n expiresAt: bigint;\n}\n\nexport interface GrantRevocationMessage {\n grantorAddress: `0x${string}`;\n grantId: `0x${string}`;\n grantVersion: bigint;\n}\n\nexport interface ServerRegistrationMessage {\n ownerAddress: `0x${string}`;\n serverAddress: `0x${string}`;\n publicKey: string;\n serverUrl: string;\n}\n\nexport interface BuilderRegistrationMessage {\n ownerAddress: `0x${string}`;\n granteeAddress: `0x${string}`;\n publicKey: string;\n appUrl: string;\n}\n\nexport interface GenericPaymentMessage {\n payerAddress: `0x${string}`;\n // 'grant' today — extensible to 'file' | 'builder' | 'schema' as those\n // op-types become payable. Sent verbatim over the wire and into the\n // typed-data string field, so callers must match the gateway's spelling.\n opType: string;\n opId: `0x${string}`;\n // NATIVE_VANA_ASSET for native VANA; an ERC-20 contract address otherwise.\n asset: `0x${string}`;\n amount: bigint;\n paymentNonce: bigint;\n}\n\nexport interface AddDataMessage {\n ownerAddress: `0x${string}`;\n scope: string;\n dataHash: `0x${string}`;\n metadataHash: `0x${string}`;\n expectedVersion: bigint;\n}\n\nexport interface RecordDataAccessMessage {\n ownerAddress: `0x${string}`;\n scope: string;\n version: bigint;\n accessor: `0x${string}`;\n recordId: `0x${string}`;\n}\n"],"mappings":"AAWA,MAAM,cAAc;AACpB,MAAM,iBAAiB;AAmBhB,MAAM,oBACX;AAOF,SAAS,YACP,SACA,mBACiB;AACjB,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IACT;AAAA,IACA;AAAA,EACF;AACF;AAMO,SAAS,mBACd,QACiB;AACjB,SAAO;AAAA,IACL,OAAO;AAAA,IACP,OAAO,UAAU;AAAA,EACnB;AACF;AAEO,SAAS,wBACd,QACiB;AACjB,SAAO;AAAA,IACL,OAAO;AAAA,IACP,OAAO,UAAU;AAAA,EACnB;AACF;AAEO,SAAS,sBACd,QACiB;AACjB,SAAO;AAAA,IACL,OAAO;AAAA,IACP,OAAO,UAAU;AAAA,EACnB;AACF;AAEO,SAAS,yBACd,QACiB;AACjB,SAAO;AAAA,IACL,OAAO;AAAA,IACP,OAAO,UAAU;AAAA,EACnB;AACF;AAEO,SAAS,0BACd,QACiB;AACjB,SAAO;AAAA,IACL,OAAO;AAAA,IACP,OAAO,UAAU;AAAA,EACnB;AACF;AAMO,SAAS,oBACd,QACiB;AACjB,SAAO;AAAA,IACL,OAAO;AAAA,IACP,OAAO,UAAU;AAAA,EACnB;AACF;AAMO,MAAM,2BAA2B;AAAA,EACtC,mBAAmB;AAAA,IACjB,EAAE,MAAM,kBAAkB,MAAM,UAAU;AAAA,IAC1C,EAAE,MAAM,aAAa,MAAM,UAAU;AAAA,IACrC,EAAE,MAAM,UAAU,MAAM,WAAW;AAAA,IACnC,EAAE,MAAM,gBAAgB,MAAM,UAAU;AAAA,IACxC,EAAE,MAAM,aAAa,MAAM,UAAU;AAAA,EACvC;AACF;AAKO,MAAM,yBAAyB;AAAA,E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A2B;AAAA,EACtC,kBAAkB;AAAA,IAChB,EAAE,MAAM,gBAAgB,MAAM,UAAU;AAAA,IACxC,EAAE,MAAM,SAAS,MAAM,SAAS;AAAA,IAChC,EAAE,MAAM,WAAW,MAAM,UAAU;AAAA,IACnC,EAAE,MAAM,YAAY,MAAM,UAAU;AAAA,IACpC,EAAE,MAAM,YAAY,MAAM,UAAU;AAAA,EACtC;AACF;","names":[]}
|
package/dist/protocol/escrow.cjs
CHANGED
|
@@ -19,19 +19,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var escrow_exports = {};
|
|
20
20
|
__export(escrow_exports, {
|
|
21
21
|
ESCROW_DEPOSIT_ABI: () => ESCROW_DEPOSIT_ABI,
|
|
22
|
-
EscrowWithdrawalLifecycleError: () => EscrowWithdrawalLifecycleError,
|
|
23
|
-
EscrowWithdrawalRejectionError: () => EscrowWithdrawalRejectionError,
|
|
24
22
|
GENERIC_PAYMENT_TYPES: () => GENERIC_PAYMENT_TYPES,
|
|
25
23
|
NATIVE_ASSET_ADDRESS: () => NATIVE_ASSET_ADDRESS,
|
|
26
|
-
WITHDRAW_AUTHORIZATION_TYPES: () => import_eip712.WITHDRAW_AUTHORIZATION_TYPES,
|
|
27
|
-
buildWithdrawAuthorizationTypedData: () => import_eip712.buildWithdrawAuthorizationTypedData,
|
|
28
24
|
createEscrowGatewayClient: () => createEscrowGatewayClient,
|
|
29
|
-
genericPaymentDomain: () => genericPaymentDomain
|
|
30
|
-
withdrawAuthorizationDomain: () => import_eip712.withdrawAuthorizationDomain
|
|
25
|
+
genericPaymentDomain: () => genericPaymentDomain
|
|
31
26
|
});
|
|
32
27
|
module.exports = __toCommonJS(escrow_exports);
|
|
33
|
-
var import_eip712 = require("./eip712");
|
|
34
|
-
var import_viem = require("viem");
|
|
35
28
|
const GENERIC_PAYMENT_TYPES = {
|
|
36
29
|
GenericPayment: [
|
|
37
30
|
{ name: "payerAddress", type: "address" },
|
|
@@ -71,26 +64,6 @@ const ESCROW_DEPOSIT_ABI = [
|
|
|
71
64
|
}
|
|
72
65
|
];
|
|
73
66
|
const NATIVE_ASSET_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
74
|
-
class EscrowWithdrawalLifecycleError extends Error {
|
|
75
|
-
constructor(httpStatus, result) {
|
|
76
|
-
super(result.error);
|
|
77
|
-
this.httpStatus = httpStatus;
|
|
78
|
-
this.result = result;
|
|
79
|
-
}
|
|
80
|
-
httpStatus;
|
|
81
|
-
result;
|
|
82
|
-
name = "EscrowWithdrawalLifecycleError";
|
|
83
|
-
}
|
|
84
|
-
class EscrowWithdrawalRejectionError extends Error {
|
|
85
|
-
constructor(httpStatus, result) {
|
|
86
|
-
super(result.error);
|
|
87
|
-
this.httpStatus = httpStatus;
|
|
88
|
-
this.result = result;
|
|
89
|
-
}
|
|
90
|
-
httpStatus;
|
|
91
|
-
result;
|
|
92
|
-
name = "EscrowWithdrawalRejectionError";
|
|
93
|
-
}
|
|
94
67
|
function createEscrowGatewayClient(baseUrl) {
|
|
95
68
|
const base = baseUrl.replace(/\/+$/, "");
|
|
96
69
|
async function throwOnError(res, context) {
|
|
@@ -106,27 +79,6 @@ function createEscrowGatewayClient(baseUrl) {
|
|
|
106
79
|
);
|
|
107
80
|
}
|
|
108
81
|
}
|
|
109
|
-
async function throwOnWithdrawError(res) {
|
|
110
|
-
if (res.ok) return;
|
|
111
|
-
let body;
|
|
112
|
-
try {
|
|
113
|
-
body = await res.json();
|
|
114
|
-
} catch {
|
|
115
|
-
throw new Error(
|
|
116
|
-
`Escrow gateway error (POST /v1/escrow/withdraw): ${res.status} ${res.statusText}`
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
if (isEscrowWithdrawalFailureResult(body)) {
|
|
120
|
-
throw new EscrowWithdrawalLifecycleError(res.status, body);
|
|
121
|
-
}
|
|
122
|
-
if (isEscrowWithdrawalRejectedResult(body)) {
|
|
123
|
-
throw new EscrowWithdrawalRejectionError(res.status, body);
|
|
124
|
-
}
|
|
125
|
-
const error = getGatewayErrorMessage(body);
|
|
126
|
-
throw new Error(
|
|
127
|
-
`Escrow gateway error (POST /v1/escrow/withdraw): ${res.status} ${res.statusText}${error ? `: ${error}` : ""}`
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
82
|
return {
|
|
131
83
|
async submitDeposit({ txHash }) {
|
|
132
84
|
const res = await fetch(`${base}/v1/escrow/deposit`, {
|
|
@@ -182,119 +134,15 @@ function createEscrowGatewayClient(baseUrl) {
|
|
|
182
134
|
});
|
|
183
135
|
await throwOnError(res, "POST /v1/escrow/pay");
|
|
184
136
|
return res.json();
|
|
185
|
-
},
|
|
186
|
-
async withdraw({
|
|
187
|
-
account,
|
|
188
|
-
asset,
|
|
189
|
-
amount,
|
|
190
|
-
withdrawNonce,
|
|
191
|
-
deadline,
|
|
192
|
-
signature
|
|
193
|
-
}) {
|
|
194
|
-
const res = await fetch(`${base}/v1/escrow/withdraw`, {
|
|
195
|
-
method: "POST",
|
|
196
|
-
headers: {
|
|
197
|
-
"Content-Type": "application/json",
|
|
198
|
-
Authorization: `Web3Signed ${signature}`
|
|
199
|
-
},
|
|
200
|
-
body: JSON.stringify({
|
|
201
|
-
account,
|
|
202
|
-
asset,
|
|
203
|
-
amount,
|
|
204
|
-
withdrawNonce,
|
|
205
|
-
deadline
|
|
206
|
-
})
|
|
207
|
-
});
|
|
208
|
-
await throwOnWithdrawError(res);
|
|
209
|
-
return res.json();
|
|
210
|
-
},
|
|
211
|
-
async getWithdrawNonce(account) {
|
|
212
|
-
const res = await fetch(
|
|
213
|
-
`${base}/v1/escrow/withdraw/nonce?account=${encodeURIComponent(account)}`,
|
|
214
|
-
{ cache: "no-store" }
|
|
215
|
-
);
|
|
216
|
-
await throwOnError(res, "GET /v1/escrow/withdraw/nonce");
|
|
217
|
-
const body = await res.json();
|
|
218
|
-
if (!isWithdrawNonceResponse(body, account)) {
|
|
219
|
-
throw new Error(
|
|
220
|
-
"GET /v1/escrow/withdraw/nonce: invalid response structure"
|
|
221
|
-
);
|
|
222
|
-
}
|
|
223
|
-
return body;
|
|
224
137
|
}
|
|
225
138
|
};
|
|
226
139
|
}
|
|
227
|
-
function getGatewayErrorMessage(body) {
|
|
228
|
-
if (typeof body === "object" && body !== null && "error" in body && typeof body.error === "string") {
|
|
229
|
-
return body.error;
|
|
230
|
-
}
|
|
231
|
-
return void 0;
|
|
232
|
-
}
|
|
233
|
-
function isEscrowWithdrawalFailureResult(body) {
|
|
234
|
-
if (typeof body !== "object" || body === null) return false;
|
|
235
|
-
const value = body;
|
|
236
|
-
return value.success === false && (value.status === "retryable" || value.status === "reorged" || value.status === "failed") && typeof value.error === "string" && isAddressHex(value.account) && isAddressHex(value.asset) && isUint256Decimal(value.amount) && isUint256Decimal(value.withdrawNonce) && isUint256Decimal(value.deadline) && (isHash(value.txHash) || value.txHash === null) && (!("blockNumber" in value) || isBlockNumber(value.blockNumber));
|
|
237
|
-
}
|
|
238
|
-
function isEscrowWithdrawalRejectedResult(body) {
|
|
239
|
-
if (typeof body !== "object" || body === null) return false;
|
|
240
|
-
const value = body;
|
|
241
|
-
return value.success === false && value.status === "rejected" && isWithdrawalRejectionCode(value.code) && typeof value.error === "string" && isAddressHex(value.account) && isAddressHex(value.asset) && isUint256Decimal(value.amount) && isUint256Decimal(value.withdrawNonce) && isUint256Decimal(value.deadline) && optionalUint256Decimal(value.balance) && optionalUint256Decimal(value.authorizedAmount) && optionalUint256Decimal(value.withdrawingAmount) && optionalUint256Decimal(value.availableAmount) && optionalUint256Decimal(value.requestedAmount) && optionalUint256Decimal(value.minimumAmount);
|
|
242
|
-
}
|
|
243
|
-
function isWithdrawalRejectionCode(value) {
|
|
244
|
-
return value === "below_minimum" || value === "deadline_too_far" || value === "expired" || value === "insufficient_available" || value === "stale_nonce";
|
|
245
|
-
}
|
|
246
|
-
function optionalUint256Decimal(value) {
|
|
247
|
-
return value === void 0 || isUint256Decimal(value);
|
|
248
|
-
}
|
|
249
|
-
function isAddressHex(value) {
|
|
250
|
-
return typeof value === "string" && (0, import_viem.isHex)(value, { strict: true }) && value.length === 42;
|
|
251
|
-
}
|
|
252
|
-
function isHash(value) {
|
|
253
|
-
return typeof value === "string" && (0, import_viem.isHex)(value, { strict: true }) && value.length === 66;
|
|
254
|
-
}
|
|
255
|
-
function isUint256Decimal(value) {
|
|
256
|
-
if (typeof value !== "string" || value.length === 0 || value.length > 78) {
|
|
257
|
-
return false;
|
|
258
|
-
}
|
|
259
|
-
if (!/^(0|[1-9]\d*)$/.test(value)) return false;
|
|
260
|
-
return BigInt(value) <= 2n ** 256n - 1n;
|
|
261
|
-
}
|
|
262
|
-
function isBlockNumber(value) {
|
|
263
|
-
return value === null || isUint256Decimal(value);
|
|
264
|
-
}
|
|
265
|
-
function isWithdrawNonceResponse(body, requestedAccount) {
|
|
266
|
-
if (typeof body !== "object" || body === null) return false;
|
|
267
|
-
const value = body;
|
|
268
|
-
if (value.success !== true) return false;
|
|
269
|
-
if (!isAddressHex(value.account)) return false;
|
|
270
|
-
if (value.account.toLowerCase() !== requestedAccount.toLowerCase())
|
|
271
|
-
return false;
|
|
272
|
-
if (typeof value.chainId !== "string") return false;
|
|
273
|
-
if (!/^(0|[1-9]\d*)$/.test(value.chainId)) return false;
|
|
274
|
-
const isLastNull = value.lastWithdrawNonce === null;
|
|
275
|
-
const lastNonceValid = isLastNull || isUint256Decimal(value.lastWithdrawNonce);
|
|
276
|
-
if (!lastNonceValid) return false;
|
|
277
|
-
if (!isUint256Decimal(value.nextWithdrawNonce)) return false;
|
|
278
|
-
if (isLastNull) {
|
|
279
|
-
return value.nextWithdrawNonce === "1";
|
|
280
|
-
}
|
|
281
|
-
const lastNonce = BigInt(value.lastWithdrawNonce);
|
|
282
|
-
const nextNonce = BigInt(value.nextWithdrawNonce);
|
|
283
|
-
const expectedNextNonce = lastNonce + 1n;
|
|
284
|
-
if (expectedNextNonce > 2n ** 256n - 1n) return false;
|
|
285
|
-
return nextNonce === expectedNextNonce;
|
|
286
|
-
}
|
|
287
140
|
// Annotate the CommonJS export names for ESM import in node:
|
|
288
141
|
0 && (module.exports = {
|
|
289
142
|
ESCROW_DEPOSIT_ABI,
|
|
290
|
-
EscrowWithdrawalLifecycleError,
|
|
291
|
-
EscrowWithdrawalRejectionError,
|
|
292
143
|
GENERIC_PAYMENT_TYPES,
|
|
293
144
|
NATIVE_ASSET_ADDRESS,
|
|
294
|
-
WITHDRAW_AUTHORIZATION_TYPES,
|
|
295
|
-
buildWithdrawAuthorizationTypedData,
|
|
296
145
|
createEscrowGatewayClient,
|
|
297
|
-
genericPaymentDomain
|
|
298
|
-
withdrawAuthorizationDomain
|
|
146
|
+
genericPaymentDomain
|
|
299
147
|
});
|
|
300
148
|
//# sourceMappingURL=escrow.cjs.map
|