@opendatalabs/vana-sdk 3.23.0 → 4.0.0

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.
Files changed (84) hide show
  1. package/README.md +57 -0
  2. package/dist/auth/errors.cjs +1 -1
  3. package/dist/auth/web3-signed.cjs +1 -1
  4. package/dist/crypto/envelope/job-stream.test.d.ts +1 -0
  5. package/dist/crypto/envelope/job.cjs +593 -38
  6. package/dist/crypto/envelope/job.cjs.map +1 -1
  7. package/dist/crypto/envelope/job.d.ts +44 -27
  8. package/dist/crypto/envelope/job.js +589 -37
  9. package/dist/crypto/envelope/job.js.map +1 -1
  10. package/dist/direct/access-request-client.cjs +1 -1
  11. package/dist/direct/connect-flow.cjs +43 -1
  12. package/dist/direct/connect-flow.cjs.map +1 -1
  13. package/dist/direct/connect-flow.d.ts +12 -0
  14. package/dist/direct/connect-flow.js +43 -1
  15. package/dist/direct/connect-flow.js.map +1 -1
  16. package/dist/direct/controller.cjs +1 -1
  17. package/dist/direct/errors.cjs +1 -1
  18. package/dist/direct/escrow-payment.cjs.map +1 -1
  19. package/dist/direct/escrow-payment.d.ts +2 -2
  20. package/dist/direct/escrow-payment.js.map +1 -1
  21. package/dist/direct/personal-server-read.cjs +2 -2
  22. package/dist/direct/use-direct-vana-connect.cjs +2 -1
  23. package/dist/direct/use-direct-vana-connect.cjs.map +1 -1
  24. package/dist/direct/use-direct-vana-connect.d.ts +3 -1
  25. package/dist/direct/use-direct-vana-connect.js +2 -1
  26. package/dist/direct/use-direct-vana-connect.js.map +1 -1
  27. package/dist/error-entry-points.test.d.ts +1 -0
  28. package/dist/errors.cjs +7 -0
  29. package/dist/errors.cjs.map +1 -1
  30. package/dist/errors.d.ts +10 -0
  31. package/dist/errors.js +6 -0
  32. package/dist/errors.js.map +1 -1
  33. package/dist/index.browser.d.ts +4 -4
  34. package/dist/index.browser.js +882 -518
  35. package/dist/index.browser.js.map +4 -4
  36. package/dist/index.node.cjs +1035 -705
  37. package/dist/index.node.cjs.map +4 -4
  38. package/dist/index.node.d.ts +4 -4
  39. package/dist/index.node.js +989 -567
  40. package/dist/index.node.js.map +4 -4
  41. package/dist/protocol/data-point-deletion.cjs +1 -1
  42. package/dist/protocol/derivative-questions.cjs +1 -1
  43. package/dist/protocol/derivative-status.cjs +1 -1
  44. package/dist/protocol/eip712.cjs +28 -2
  45. package/dist/protocol/eip712.cjs.map +1 -1
  46. package/dist/protocol/eip712.d.ts +70 -0
  47. package/dist/protocol/eip712.js +24 -1
  48. package/dist/protocol/eip712.js.map +1 -1
  49. package/dist/protocol/escrow.cjs +154 -2
  50. package/dist/protocol/escrow.cjs.map +1 -1
  51. package/dist/protocol/escrow.d.ts +145 -2
  52. package/dist/protocol/escrow.js +152 -1
  53. package/dist/protocol/escrow.js.map +1 -1
  54. package/dist/protocol/fixtures/moksha-identity.json +20 -0
  55. package/dist/protocol/gateway.cjs +1 -1
  56. package/dist/protocol/gateway.cjs.map +1 -1
  57. package/dist/protocol/gateway.d.ts +8 -38
  58. package/dist/protocol/gateway.js.map +1 -1
  59. package/dist/protocol/identity.cjs +7 -2
  60. package/dist/protocol/identity.cjs.map +1 -1
  61. package/dist/protocol/identity.js +7 -2
  62. package/dist/protocol/identity.js.map +1 -1
  63. package/dist/protocol/jobs-client.cjs +73 -21
  64. package/dist/protocol/jobs-client.cjs.map +1 -1
  65. package/dist/protocol/jobs-client.d.ts +7 -5
  66. package/dist/protocol/jobs-client.js +74 -21
  67. package/dist/protocol/jobs-client.js.map +1 -1
  68. package/dist/protocol/jobs.cjs +0 -3
  69. package/dist/protocol/jobs.cjs.map +1 -1
  70. package/dist/protocol/jobs.d.ts +21 -13
  71. package/dist/protocol/jobs.js +0 -2
  72. package/dist/protocol/jobs.js.map +1 -1
  73. package/dist/protocol/lineage.cjs +1 -1
  74. package/dist/protocol/personal-server-data.cjs +1 -1
  75. package/dist/protocol/personal-server-write.cjs +1 -1
  76. package/dist/protocol/write-request.cjs +1 -1
  77. package/dist/protocol/write-signer.cjs +1 -1
  78. package/dist/react.cjs.map +1 -1
  79. package/dist/react.d.ts +1 -1
  80. package/dist/react.js.map +1 -1
  81. package/dist/session-relay/client.cjs +1 -1
  82. package/dist/session-relay/errors.cjs +1 -1
  83. package/dist/session-relay/index.cjs +1 -1
  84. package/package.json +1 -1
@@ -33,7 +33,7 @@ __export(data_point_deletion_exports, {
33
33
  });
34
34
  module.exports = __toCommonJS(data_point_deletion_exports);
35
35
  var import_viem = require("viem");
36
- var import_errors = require("../errors");
36
+ var import_errors = require("../errors.cjs");
37
37
  var import_response_body = require("../utils/response-body");
38
38
  var import_eip712 = require("./eip712");
39
39
  var import_lineage = require("./lineage");
@@ -44,7 +44,7 @@ __export(derivative_questions_exports, {
44
44
  module.exports = __toCommonJS(derivative_questions_exports);
45
45
  var import_zod = require("zod");
46
46
  var import_web3_signed_builder = require("../auth/web3-signed-builder");
47
- var import_errors = require("../errors");
47
+ var import_errors = require("../errors.cjs");
48
48
  var import_lineage = require("./lineage");
49
49
  var import_personal_server_error_body = require("./personal-server-error-body");
50
50
  var import_personal_server_data = require("./personal-server-data");
@@ -32,7 +32,7 @@ __export(derivative_status_exports, {
32
32
  module.exports = __toCommonJS(derivative_status_exports);
33
33
  var import_zod = require("zod");
34
34
  var import_web3_signed_builder = require("../auth/web3-signed-builder");
35
- var import_errors = require("../errors");
35
+ var import_errors = require("../errors.cjs");
36
36
  var import_derivative_questions = require("./derivative-questions");
37
37
  var import_write_signer = require("./write-signer");
38
38
  var import_derivative_questions2 = require("./derivative-questions");
@@ -26,12 +26,15 @@ __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,
29
31
  builderRegistrationDomain: () => builderRegistrationDomain,
30
32
  dataRegistryDomain: () => dataRegistryDomain,
31
33
  escrowPaymentDomain: () => escrowPaymentDomain,
32
34
  grantRegistrationDomain: () => grantRegistrationDomain,
33
35
  grantRevocationDomain: () => grantRevocationDomain,
34
- serverRegistrationDomain: () => serverRegistrationDomain
36
+ serverRegistrationDomain: () => serverRegistrationDomain,
37
+ withdrawAuthorizationDomain: () => withdrawAuthorizationDomain
35
38
  });
36
39
  module.exports = __toCommonJS(eip712_exports);
37
40
  const DOMAIN_NAME = "Vana Data Portability";
@@ -81,6 +84,9 @@ function escrowPaymentDomain(config) {
81
84
  config.contracts.dataPortabilityEscrow
82
85
  );
83
86
  }
87
+ function withdrawAuthorizationDomain(config) {
88
+ return escrowPaymentDomain(config);
89
+ }
84
90
  const GRANT_REGISTRATION_TYPES = {
85
91
  GrantRegistration: [
86
92
  { name: "grantorAddress", type: "address" },
@@ -123,6 +129,15 @@ const GENERIC_PAYMENT_TYPES = {
123
129
  { name: "paymentNonce", type: "uint256" }
124
130
  ]
125
131
  };
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
+ };
126
141
  const ADD_DATA_TYPES = {
127
142
  AddData: [
128
143
  { name: "ownerAddress", type: "address" },
@@ -141,6 +156,14 @@ const RECORD_DATA_ACCESS_TYPES = {
141
156
  { name: "recordId", type: "bytes32" }
142
157
  ]
143
158
  };
159
+ function buildWithdrawAuthorizationTypedData(config, message) {
160
+ return {
161
+ domain: withdrawAuthorizationDomain(config),
162
+ types: WITHDRAW_AUTHORIZATION_TYPES,
163
+ primaryType: "WithdrawAuthorization",
164
+ message
165
+ };
166
+ }
144
167
  // Annotate the CommonJS export names for ESM import in node:
145
168
  0 && (module.exports = {
146
169
  ADD_DATA_TYPES,
@@ -151,11 +174,14 @@ const RECORD_DATA_ACCESS_TYPES = {
151
174
  NATIVE_VANA_ASSET,
152
175
  RECORD_DATA_ACCESS_TYPES,
153
176
  SERVER_REGISTRATION_TYPES,
177
+ WITHDRAW_AUTHORIZATION_TYPES,
178
+ buildWithdrawAuthorizationTypedData,
154
179
  builderRegistrationDomain,
155
180
  dataRegistryDomain,
156
181
  escrowPaymentDomain,
157
182
  grantRegistrationDomain,
158
183
  grantRevocationDomain,
159
- serverRegistrationDomain
184
+ serverRegistrationDomain,
185
+ withdrawAuthorizationDomain
160
186
  });
161
187
  //# 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// 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,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,U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mB,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":[]}
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,SA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,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":[]}
@@ -26,6 +26,14 @@ 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;
29
37
  export declare const GRANT_REGISTRATION_TYPES: {
30
38
  readonly GrantRegistration: readonly [{
31
39
  readonly name: "grantorAddress";
@@ -107,6 +115,31 @@ export declare const GENERIC_PAYMENT_TYPES: {
107
115
  readonly type: "uint256";
108
116
  }];
109
117
  };
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
+ };
110
143
  export declare const ADD_DATA_TYPES: {
111
144
  readonly AddData: readonly [{
112
145
  readonly name: "ownerAddress";
@@ -175,6 +208,43 @@ export interface GenericPaymentMessage {
175
208
  amount: bigint;
176
209
  paymentNonce: bigint;
177
210
  }
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
+ };
178
248
  export interface AddDataMessage {
179
249
  ownerAddress: `0x${string}`;
180
250
  scope: string;
@@ -45,6 +45,9 @@ function escrowPaymentDomain(config) {
45
45
  config.contracts.dataPortabilityEscrow
46
46
  );
47
47
  }
48
+ function withdrawAuthorizationDomain(config) {
49
+ return escrowPaymentDomain(config);
50
+ }
48
51
  const GRANT_REGISTRATION_TYPES = {
49
52
  GrantRegistration: [
50
53
  { name: "grantorAddress", type: "address" },
@@ -87,6 +90,15 @@ const GENERIC_PAYMENT_TYPES = {
87
90
  { name: "paymentNonce", type: "uint256" }
88
91
  ]
89
92
  };
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
+ };
90
102
  const ADD_DATA_TYPES = {
91
103
  AddData: [
92
104
  { name: "ownerAddress", type: "address" },
@@ -105,6 +117,14 @@ const RECORD_DATA_ACCESS_TYPES = {
105
117
  { name: "recordId", type: "bytes32" }
106
118
  ]
107
119
  };
120
+ function buildWithdrawAuthorizationTypedData(config, message) {
121
+ return {
122
+ domain: withdrawAuthorizationDomain(config),
123
+ types: WITHDRAW_AUTHORIZATION_TYPES,
124
+ primaryType: "WithdrawAuthorization",
125
+ message
126
+ };
127
+ }
108
128
  export {
109
129
  ADD_DATA_TYPES,
110
130
  BUILDER_REGISTRATION_TYPES,
@@ -114,11 +134,14 @@ export {
114
134
  NATIVE_VANA_ASSET,
115
135
  RECORD_DATA_ACCESS_TYPES,
116
136
  SERVER_REGISTRATION_TYPES,
137
+ WITHDRAW_AUTHORIZATION_TYPES,
138
+ buildWithdrawAuthorizationTypedData,
117
139
  builderRegistrationDomain,
118
140
  dataRegistryDomain,
119
141
  escrowPaymentDomain,
120
142
  grantRegistrationDomain,
121
143
  grantRevocationDomain,
122
- serverRegistrationDomain
144
+ serverRegistrationDomain,
145
+ withdrawAuthorizationDomain
123
146
  };
124
147
  //# 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// 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,E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,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":[]}
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":"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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AAM,UAAU;AAAA,IAClC,EAAE,MAAM,gBAAgB,MAAM,UAAU;AAAA,EAC1C;AACF;AASO,MAAM,+BAA+B;AAAA,EAC1C,uBAAuB;AAAA,IACrB,EAAE,MAAM,WAAW,MAAM,UAAU;AAAA,IACnC,EAAE,MAAM,SAAS,MAAM,UAAU;AAAA,IACjC,EAAE,MAAM,UAAU,MAAM,UAAU;AAAA,IAClC,EAAE,MAAM,iBAAiB,MAAM,UAAU;AAAA,IACzC,EAAE,MAAM,YAAY,MAAM,UAAU;AAAA,EACtC;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;AA0DO,SAAS,oCACd,QACA,SACA;AACA,SAAO;AAAA,IACL,QAAQ,4BAA4B,MAAM;AAAA,IAC1C,OAAO;AAAA,IACP,aAAa;AAAA,IACb;AAAA,EACF;AACF;","names":[]}
@@ -19,12 +19,19 @@ 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,
22
24
  GENERIC_PAYMENT_TYPES: () => GENERIC_PAYMENT_TYPES,
23
25
  NATIVE_ASSET_ADDRESS: () => NATIVE_ASSET_ADDRESS,
26
+ WITHDRAW_AUTHORIZATION_TYPES: () => import_eip712.WITHDRAW_AUTHORIZATION_TYPES,
27
+ buildWithdrawAuthorizationTypedData: () => import_eip712.buildWithdrawAuthorizationTypedData,
24
28
  createEscrowGatewayClient: () => createEscrowGatewayClient,
25
- genericPaymentDomain: () => genericPaymentDomain
29
+ genericPaymentDomain: () => genericPaymentDomain,
30
+ withdrawAuthorizationDomain: () => import_eip712.withdrawAuthorizationDomain
26
31
  });
27
32
  module.exports = __toCommonJS(escrow_exports);
33
+ var import_eip712 = require("./eip712");
34
+ var import_viem = require("viem");
28
35
  const GENERIC_PAYMENT_TYPES = {
29
36
  GenericPayment: [
30
37
  { name: "payerAddress", type: "address" },
@@ -64,6 +71,26 @@ const ESCROW_DEPOSIT_ABI = [
64
71
  }
65
72
  ];
66
73
  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
+ }
67
94
  function createEscrowGatewayClient(baseUrl) {
68
95
  const base = baseUrl.replace(/\/+$/, "");
69
96
  async function throwOnError(res, context) {
@@ -79,6 +106,27 @@ function createEscrowGatewayClient(baseUrl) {
79
106
  );
80
107
  }
81
108
  }
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
+ }
82
130
  return {
83
131
  async submitDeposit({ txHash }) {
84
132
  const res = await fetch(`${base}/v1/escrow/deposit`, {
@@ -134,15 +182,119 @@ function createEscrowGatewayClient(baseUrl) {
134
182
  });
135
183
  await throwOnError(res, "POST /v1/escrow/pay");
136
184
  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;
137
224
  }
138
225
  };
139
226
  }
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
+ }
140
287
  // Annotate the CommonJS export names for ESM import in node:
141
288
  0 && (module.exports = {
142
289
  ESCROW_DEPOSIT_ABI,
290
+ EscrowWithdrawalLifecycleError,
291
+ EscrowWithdrawalRejectionError,
143
292
  GENERIC_PAYMENT_TYPES,
144
293
  NATIVE_ASSET_ADDRESS,
294
+ WITHDRAW_AUTHORIZATION_TYPES,
295
+ buildWithdrawAuthorizationTypedData,
145
296
  createEscrowGatewayClient,
146
- genericPaymentDomain
297
+ genericPaymentDomain,
298
+ withdrawAuthorizationDomain
147
299
  });
148
300
  //# sourceMappingURL=escrow.cjs.map