@opendatalabs/vana-sdk 3.5.1 → 3.6.1

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 (116) hide show
  1. package/README.md +116 -0
  2. package/dist/direct/access-request-client.cjs +149 -0
  3. package/dist/direct/access-request-client.cjs.map +1 -0
  4. package/dist/direct/access-request-client.d.ts +66 -0
  5. package/dist/direct/access-request-client.js +123 -0
  6. package/dist/direct/access-request-client.js.map +1 -0
  7. package/dist/direct/access-request-client.test.d.ts +1 -0
  8. package/dist/direct/connect-flow.cjs +152 -0
  9. package/dist/direct/connect-flow.cjs.map +1 -0
  10. package/dist/direct/connect-flow.d.ts +85 -0
  11. package/dist/direct/connect-flow.js +128 -0
  12. package/dist/direct/connect-flow.js.map +1 -0
  13. package/dist/direct/connect-flow.test.d.ts +1 -0
  14. package/dist/direct/controller.cjs +131 -0
  15. package/dist/direct/controller.cjs.map +1 -0
  16. package/dist/direct/controller.d.ts +152 -0
  17. package/dist/direct/controller.js +111 -0
  18. package/dist/direct/controller.js.map +1 -0
  19. package/dist/direct/controller.test.d.ts +1 -0
  20. package/dist/direct/endpoints.cjs +45 -0
  21. package/dist/direct/endpoints.cjs.map +1 -0
  22. package/dist/direct/endpoints.d.ts +22 -0
  23. package/dist/direct/endpoints.js +19 -0
  24. package/dist/direct/endpoints.js.map +1 -0
  25. package/dist/direct/errors.cjs +65 -0
  26. package/dist/direct/errors.cjs.map +1 -0
  27. package/dist/direct/errors.d.ts +44 -0
  28. package/dist/direct/errors.js +38 -0
  29. package/dist/direct/errors.js.map +1 -0
  30. package/dist/direct/escrow-payment.cjs +96 -0
  31. package/dist/direct/escrow-payment.cjs.map +1 -0
  32. package/dist/direct/escrow-payment.d.ts +81 -0
  33. package/dist/direct/escrow-payment.js +72 -0
  34. package/dist/direct/escrow-payment.js.map +1 -0
  35. package/dist/direct/escrow-payment.test.d.ts +1 -0
  36. package/dist/direct/personal-server-read.cjs +149 -0
  37. package/dist/direct/personal-server-read.cjs.map +1 -0
  38. package/dist/direct/personal-server-read.d.ts +103 -0
  39. package/dist/direct/personal-server-read.js +124 -0
  40. package/dist/direct/personal-server-read.js.map +1 -0
  41. package/dist/direct/personal-server-read.test.d.ts +1 -0
  42. package/dist/direct/types.cjs +35 -0
  43. package/dist/direct/types.cjs.map +1 -0
  44. package/dist/direct/types.d.ts +205 -0
  45. package/dist/direct/types.js +11 -0
  46. package/dist/direct/types.js.map +1 -0
  47. package/dist/direct/use-direct-vana-connect.cjs +68 -0
  48. package/dist/direct/use-direct-vana-connect.cjs.map +1 -0
  49. package/dist/direct/use-direct-vana-connect.d.ts +45 -0
  50. package/dist/direct/use-direct-vana-connect.js +46 -0
  51. package/dist/direct/use-direct-vana-connect.js.map +1 -0
  52. package/dist/index.browser.d.ts +7 -3
  53. package/dist/index.browser.js +438 -157
  54. package/dist/index.browser.js.map +4 -4
  55. package/dist/index.node.cjs +461 -162
  56. package/dist/index.node.cjs.map +4 -4
  57. package/dist/index.node.d.ts +7 -3
  58. package/dist/index.node.js +438 -157
  59. package/dist/index.node.js.map +4 -4
  60. package/dist/protocol/data-point-status.cjs +80 -0
  61. package/dist/protocol/data-point-status.cjs.map +1 -0
  62. package/dist/protocol/data-point-status.d.ts +34 -0
  63. package/dist/protocol/data-point-status.js +51 -0
  64. package/dist/protocol/data-point-status.js.map +1 -0
  65. package/dist/protocol/data-point-status.test.d.ts +1 -0
  66. package/dist/protocol/eip712.cjs +53 -31
  67. package/dist/protocol/eip712.cjs.map +1 -1
  68. package/dist/protocol/eip712.d.ts +98 -43
  69. package/dist/protocol/eip712.js +47 -27
  70. package/dist/protocol/eip712.js.map +1 -1
  71. package/dist/protocol/escrow-deposit.cjs +89 -0
  72. package/dist/protocol/escrow-deposit.cjs.map +1 -0
  73. package/dist/protocol/escrow-deposit.d.ts +47 -0
  74. package/dist/protocol/escrow-deposit.js +60 -0
  75. package/dist/protocol/escrow-deposit.js.map +1 -0
  76. package/dist/protocol/escrow-deposit.test.d.ts +1 -0
  77. package/dist/protocol/escrow-flow.test.d.ts +21 -0
  78. package/dist/protocol/fee-registry.cjs +116 -0
  79. package/dist/protocol/fee-registry.cjs.map +1 -0
  80. package/dist/protocol/fee-registry.d.ts +151 -0
  81. package/dist/protocol/fee-registry.js +89 -0
  82. package/dist/protocol/fee-registry.js.map +1 -0
  83. package/dist/protocol/fee-registry.test.d.ts +1 -0
  84. package/dist/protocol/gateway.cjs +107 -37
  85. package/dist/protocol/gateway.cjs.map +1 -1
  86. package/dist/protocol/gateway.d.ts +223 -57
  87. package/dist/protocol/gateway.js +107 -37
  88. package/dist/protocol/gateway.js.map +1 -1
  89. package/dist/protocol/grants.cjs +27 -64
  90. package/dist/protocol/grants.cjs.map +1 -1
  91. package/dist/protocol/grants.d.ts +6 -13
  92. package/dist/protocol/grants.js +27 -63
  93. package/dist/protocol/grants.js.map +1 -1
  94. package/dist/protocol/personal-server-data.cjs +71 -0
  95. package/dist/protocol/personal-server-data.cjs.map +1 -0
  96. package/dist/protocol/personal-server-data.d.ts +16 -0
  97. package/dist/protocol/personal-server-data.js +47 -0
  98. package/dist/protocol/personal-server-data.js.map +1 -0
  99. package/dist/protocol/personal-server-data.test.d.ts +1 -0
  100. package/dist/protocol/personal-server-lite-owner-binding.cjs +93 -0
  101. package/dist/protocol/personal-server-lite-owner-binding.cjs.map +1 -0
  102. package/dist/protocol/personal-server-lite-owner-binding.d.ts +44 -0
  103. package/dist/protocol/personal-server-lite-owner-binding.js +65 -0
  104. package/dist/protocol/personal-server-lite-owner-binding.js.map +1 -0
  105. package/dist/protocol/personal-server-lite-owner-binding.test.d.ts +1 -0
  106. package/dist/react.cjs +32 -0
  107. package/dist/react.cjs.map +1 -0
  108. package/dist/react.d.ts +33 -0
  109. package/dist/react.js +11 -0
  110. package/dist/react.js.map +1 -0
  111. package/dist/server.cjs +73 -0
  112. package/dist/server.cjs.map +1 -0
  113. package/dist/server.d.ts +32 -0
  114. package/dist/server.js +55 -0
  115. package/dist/server.js.map +1 -0
  116. package/package.json +20 -1
@@ -0,0 +1,111 @@
1
+ import { privateKeyToAccount } from "viem/accounts";
2
+ import { parseScope } from "../protocol/scopes.js";
3
+ import {
4
+ createDefaultAccessRequestClient
5
+ } from "./access-request-client.js";
6
+ import { getDirectEndpoints } from "./endpoints.js";
7
+ import { AccessNotApprovedError, DirectConfigError } from "./errors.js";
8
+ import {
9
+ readPersonalServerData
10
+ } from "./personal-server-read.js";
11
+ function isHexPrivateKey(value) {
12
+ return /^0x[0-9a-fA-F]{64}$/.test(value);
13
+ }
14
+ function createDirectDataController(config) {
15
+ const privateKey = config.appPrivateKey ?? config.builderPrivateKey;
16
+ if (!privateKey || !isHexPrivateKey(privateKey)) {
17
+ throw new DirectConfigError(
18
+ "appPrivateKey must be a 0x-prefixed 32-byte hex string"
19
+ );
20
+ }
21
+ if (!config.scopes || config.scopes.length === 0) {
22
+ throw new DirectConfigError("At least one scope is required");
23
+ }
24
+ for (const scope of config.scopes) {
25
+ parseScope(scope);
26
+ }
27
+ const env = config.env ?? "production";
28
+ const endpoints = {
29
+ ...getDirectEndpoints(env),
30
+ ...config.endpoints
31
+ };
32
+ const account = privateKeyToAccount(privateKey);
33
+ const signMessage = (message) => account.signMessage({ message });
34
+ const signTypedData = account.signTypedData;
35
+ const chainId = endpoints.chainId;
36
+ const accessRequestClient = config.accessRequestClient ?? createDefaultAccessRequestClient({
37
+ baseUrl: endpoints.accessRequestBaseUrl,
38
+ approvalBaseUrl: endpoints.approvalAppBaseUrl,
39
+ fetchFn: config.fetchFn,
40
+ appAddress: account.address,
41
+ signMessage
42
+ });
43
+ const escrow = config.escrow ? {
44
+ client: config.escrow.client,
45
+ escrowContract: config.escrow.escrowContract,
46
+ chainId: config.escrow.chainId ?? chainId,
47
+ nonceSource: config.escrow.nonceSource,
48
+ signTypedData
49
+ } : void 0;
50
+ return {
51
+ appAddress: account.address,
52
+ getAppAddress() {
53
+ return account.address;
54
+ },
55
+ getAppIdentity() {
56
+ return {
57
+ id: config.app.id,
58
+ name: config.app.name,
59
+ homepageUrl: config.app.homepageUrl,
60
+ address: account.address
61
+ };
62
+ },
63
+ async createAccessRequest(input) {
64
+ return accessRequestClient.createAccessRequest({
65
+ appAddress: account.address,
66
+ app: config.app,
67
+ source: config.source,
68
+ scopes: config.scopes,
69
+ returnUrl: input.returnUrl
70
+ });
71
+ },
72
+ async getAccessRequestStatus(requestId) {
73
+ return accessRequestClient.getAccessRequestStatus(requestId);
74
+ },
75
+ async readApprovedData(input) {
76
+ const status = await accessRequestClient.getAccessRequestStatus(
77
+ input.requestId
78
+ );
79
+ if (status.status !== "approved" || !status.personalServerUrl || !status.grantId || !status.scope) {
80
+ throw new AccessNotApprovedError(
81
+ "Request is not approved or is missing grantId/scope/personalServerUrl",
82
+ {
83
+ requestId: input.requestId,
84
+ status: status.status,
85
+ hasPersonalServerUrl: Boolean(status.personalServerUrl),
86
+ hasGrantId: Boolean(status.grantId),
87
+ hasScope: Boolean(status.scope)
88
+ }
89
+ );
90
+ }
91
+ const result = await readPersonalServerData({
92
+ personalServerUrl: status.personalServerUrl,
93
+ scope: status.scope,
94
+ grantId: status.grantId,
95
+ payerAddress: account.address,
96
+ signMessage,
97
+ escrow,
98
+ fetchFn: config.personalServerFetch
99
+ });
100
+ return {
101
+ scope: status.scope,
102
+ data: result.data,
103
+ payment: result.payment
104
+ };
105
+ }
106
+ };
107
+ }
108
+ export {
109
+ createDirectDataController
110
+ };
111
+ //# sourceMappingURL=controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/direct/controller.ts"],"sourcesContent":["/**\n * Direct Data Controller — the server-side facade for the two-tab Data\n * Portability flow.\n *\n * @remarks\n * One controller owns an app's private key, source, scopes, app identity, and\n * payment flow. It exposes the three methods the builder guide documents:\n *\n * - {@link DirectDataController.createAccessRequest} — start an approval request.\n * - {@link DirectDataController.getAccessRequestStatus} — poll while the Vana tab is open.\n * - {@link DirectDataController.readApprovedData} — read from the Personal Server,\n * handling 402 Payment Required.\n *\n * Access requests are created through the Vana Account access-request API; the\n * Personal Server read uses Web3Signed auth; and payment uses the DPv2 escrow\n * surface (`protocol/escrow`) — when a read returns `402`, the controller signs\n * a `GenericPayment` with the app key, settles it through the escrow gateway,\n * and retries.\n *\n * @category Direct\n * @module direct/controller\n */\n\nimport { privateKeyToAccount } from \"viem/accounts\";\nimport type { Hex } from \"viem\";\nimport type { Web3SignedSignFn } from \"../auth/web3-signed-builder\";\nimport { parseScope } from \"../protocol/scopes\";\nimport {\n createDefaultAccessRequestClient,\n type FetchLike,\n} from \"./access-request-client\";\nimport { getDirectEndpoints } from \"./endpoints\";\nimport { AccessNotApprovedError, DirectConfigError } from \"./errors\";\nimport {\n type EscrowPaymentConfig,\n type SignTypedDataFn,\n} from \"./escrow-payment\";\nimport {\n readPersonalServerData,\n type PersonalServerFetch,\n} from \"./personal-server-read\";\nimport type {\n AccessRequest,\n AccessRequestClient,\n AccessRequestStatus,\n ApprovedDataResult,\n AppIdentity,\n DirectAppConfig,\n DirectEnv,\n DirectServiceEndpoints,\n} from \"./types\";\n\n/** Configuration for {@link createDirectDataController}. */\nexport interface DirectDataControllerConfig {\n /** Target environment. Defaults to `\"production\"`. */\n env?: DirectEnv;\n /**\n * The app private key (`0x`-prefixed, 32 bytes). Server-side only — this key\n * is the app's on-chain identity and is never exposed to the browser.\n */\n appPrivateKey?: string;\n /**\n * @deprecated Use {@link DirectDataControllerConfig.appPrivateKey}. Accepted as\n * a backwards-compatible alias; if both are set, `appPrivateKey` wins.\n */\n builderPrivateKey?: string;\n /** App identity advertised during approval. */\n app: DirectAppConfig;\n /** Data source key (e.g. `\"icloud_notes\"`). */\n source: string;\n /** Scopes to request (e.g. `[\"icloud_notes.notes\"]`). At least one required. */\n scopes: string[];\n /**\n * Override the resolved service endpoints (partial). Useful for pointing at a\n * non-standard deployment.\n */\n endpoints?: Partial<DirectServiceEndpoints>;\n /**\n * Client for the Vana Account access-request API. Defaults to a client against\n * the resolved Vana Account endpoints; inject your own to point at a custom\n * deployment or to supply a test double.\n */\n accessRequestClient?: AccessRequestClient;\n /**\n * Escrow settlement config used when a Personal Server read returns `402`.\n *\n * @remarks\n * Wires the DPv2 escrow gateway (`protocol/escrow`). The controller supplies\n * the EIP-712 `signTypedData` from the app key automatically, so you provide\n * the gateway `client`, the `escrowContract` address, and (optionally) the\n * `chainId` and a durable `nonceSource`. If omitted, a `402` from the Personal\n * Server throws {@link PaymentRequiredError} carrying the amount/asset owed.\n */\n escrow?: DirectEscrowConfig;\n /** `fetch` used by the default access-request client. Defaults to `globalThis.fetch`. */\n fetchFn?: FetchLike;\n /** `fetch` used for the Personal Server read. Defaults to `globalThis.fetch`. */\n personalServerFetch?: PersonalServerFetch;\n}\n\n/**\n * Controller-level escrow config — the {@link EscrowPaymentConfig} minus the\n * `signTypedData` and `chainId` the controller injects itself.\n */\nexport interface DirectEscrowConfig extends Omit<\n EscrowPaymentConfig,\n \"signTypedData\" | \"chainId\"\n> {\n /**\n * Chain id for the EIP-712 domain. Defaults to the controller's environment\n * (1480 for production, 14800 for dev).\n */\n chainId?: number;\n}\n\n/**\n * Server-side controller for the direct Data Portability flow.\n *\n * @typeParam T - Shape of the data returned by {@link DirectDataController.readApprovedData}.\n */\nexport interface DirectDataController {\n /** The on-chain address of the app, derived from `appPrivateKey`. */\n readonly appAddress: string;\n\n /**\n * The app's on-chain address — the address to fund and inspect in the Builder\n * activity report. Equivalent to {@link DirectDataController.appAddress}.\n *\n * @returns The app's `0x`-prefixed address.\n */\n getAppAddress(): string;\n\n /**\n * The app's full identity: its configured id/name/homepage plus the derived\n * on-chain address. Useful for telling builders which app address to fund or\n * look up.\n *\n * @returns `{ id, name, homepageUrl, address }`.\n */\n getAppIdentity(): AppIdentity;\n\n /**\n * Create an access request the user can approve.\n *\n * @param input - The post-approval return URL.\n * @returns `{ requestId, approvalUrl, appAddress }`.\n */\n createAccessRequest(input: { returnUrl: string }): Promise<AccessRequest>;\n\n /**\n * Fetch the current status of an access request.\n *\n * @param requestId - The `dcr_*` id from {@link DirectDataController.createAccessRequest}.\n * @returns `{ status, personalServerUrl?, grantId?, scope? }`.\n */\n getAccessRequestStatus(requestId: string): Promise<AccessRequestStatus>;\n\n /**\n * Read the approved data from the user's Personal Server.\n *\n * @remarks\n * Resolves the request to its grant + Personal Server and performs a Web3Signed\n * read. Hides the `402 Payment Required` flow by default: if a read needs\n * payment and `escrow` is configured, it settles the grant via the escrow\n * gateway and retries, attaching a {@link DirectPaymentReceipt} under\n * `payment` so callers can inspect amount/asset/fee breakdown. If `escrow` is\n * not configured, it throws {@link PaymentRequiredError} carrying the\n * amount/asset owed.\n *\n * @param input - The `dcr_*` request id to read.\n * @returns `{ scope, data, payment? }`.\n * @throws {@link AccessNotApprovedError} if the request is not approved.\n * @throws {@link PaymentRequiredError} if payment is required but unsettled.\n */\n readApprovedData<T = unknown>(input: {\n requestId: string;\n }): Promise<ApprovedDataResult<T>>;\n}\n\nfunction isHexPrivateKey(value: string): value is Hex {\n return /^0x[0-9a-fA-F]{64}$/.test(value);\n}\n\n/**\n * Create a {@link DirectDataController}.\n *\n * @param config - Controller configuration (env, key, app identity, source, scopes).\n * @returns A ready-to-use controller.\n * @throws {@link DirectConfigError} when the key or scopes are invalid.\n */\nexport function createDirectDataController(\n config: DirectDataControllerConfig,\n): DirectDataController {\n // `appPrivateKey` is the documented field; `builderPrivateKey` is a\n // deprecated alias kept for backwards compatibility.\n const privateKey = config.appPrivateKey ?? config.builderPrivateKey;\n if (!privateKey || !isHexPrivateKey(privateKey)) {\n throw new DirectConfigError(\n \"appPrivateKey must be a 0x-prefixed 32-byte hex string\",\n );\n }\n if (!config.scopes || config.scopes.length === 0) {\n throw new DirectConfigError(\"At least one scope is required\");\n }\n // Validate scopes eagerly so misconfiguration fails at construction.\n for (const scope of config.scopes) {\n parseScope(scope);\n }\n\n const env: DirectEnv = config.env ?? \"production\";\n const endpoints: DirectServiceEndpoints = {\n ...getDirectEndpoints(env),\n ...config.endpoints,\n };\n\n const account = privateKeyToAccount(privateKey as Hex);\n const signMessage: Web3SignedSignFn = (message: string) =>\n account.signMessage({ message });\n // viem's account.signTypedData satisfies the structural SignTypedDataFn used\n // by the escrow GenericPayment signer.\n const signTypedData = account.signTypedData as unknown as SignTypedDataFn;\n const chainId = endpoints.chainId;\n\n const accessRequestClient: AccessRequestClient =\n config.accessRequestClient ??\n createDefaultAccessRequestClient({\n baseUrl: endpoints.accessRequestBaseUrl,\n approvalBaseUrl: endpoints.approvalAppBaseUrl,\n fetchFn: config.fetchFn,\n appAddress: account.address,\n signMessage,\n });\n\n const escrow: EscrowPaymentConfig | undefined = config.escrow\n ? {\n client: config.escrow.client,\n escrowContract: config.escrow.escrowContract,\n chainId: config.escrow.chainId ?? chainId,\n nonceSource: config.escrow.nonceSource,\n signTypedData,\n }\n : undefined;\n\n return {\n appAddress: account.address,\n\n getAppAddress(): string {\n return account.address;\n },\n\n getAppIdentity(): AppIdentity {\n return {\n id: config.app.id,\n name: config.app.name,\n homepageUrl: config.app.homepageUrl,\n address: account.address,\n };\n },\n\n async createAccessRequest(input): Promise<AccessRequest> {\n return accessRequestClient.createAccessRequest({\n appAddress: account.address,\n app: config.app,\n source: config.source,\n scopes: config.scopes,\n returnUrl: input.returnUrl,\n });\n },\n\n async getAccessRequestStatus(\n requestId: string,\n ): Promise<AccessRequestStatus> {\n return accessRequestClient.getAccessRequestStatus(requestId);\n },\n\n async readApprovedData<T = unknown>(input: {\n requestId: string;\n }): Promise<ApprovedDataResult<T>> {\n const status = await accessRequestClient.getAccessRequestStatus(\n input.requestId,\n );\n if (\n status.status !== \"approved\" ||\n !status.personalServerUrl ||\n !status.grantId ||\n !status.scope\n ) {\n throw new AccessNotApprovedError(\n \"Request is not approved or is missing grantId/scope/personalServerUrl\",\n {\n requestId: input.requestId,\n status: status.status,\n hasPersonalServerUrl: Boolean(status.personalServerUrl),\n hasGrantId: Boolean(status.grantId),\n hasScope: Boolean(status.scope),\n },\n );\n }\n\n const result = await readPersonalServerData({\n personalServerUrl: status.personalServerUrl,\n scope: status.scope,\n grantId: status.grantId,\n payerAddress: account.address,\n signMessage,\n escrow,\n fetchFn: config.personalServerFetch,\n });\n\n return {\n scope: status.scope,\n data: result.data as T,\n payment: result.payment,\n };\n },\n };\n}\n"],"mappings":"AAuBA,SAAS,2BAA2B;AAGpC,SAAS,kBAAkB;AAC3B;AAAA,EACE;AAAA,OAEK;AACP,SAAS,0BAA0B;AACnC,SAAS,wBAAwB,yBAAyB;AAK1D;AAAA,EACE;AAAA,OAEK;AA2IP,SAAS,gBAAgB,OAA6B;AACpD,SAAO,sBAAsB,KAAK,KAAK;AACzC;AASO,SAAS,2BACd,QACsB;AAGtB,QAAM,aAAa,OAAO,iBAAiB,OAAO;AAClD,MAAI,CAAC,cAAc,CAAC,gBAAgB,UAAU,GAAG;AAC/C,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,MAAI,CAAC,OAAO,UAAU,OAAO,OAAO,WAAW,GAAG;AAChD,UAAM,IAAI,kBAAkB,gCAAgC;AAAA,EAC9D;AAEA,aAAW,SAAS,OAAO,QAAQ;AACjC,eAAW,KAAK;AAAA,EAClB;AAEA,QAAM,MAAiB,OAAO,OAAO;AACrC,QAAM,YAAoC;AAAA,IACxC,GAAG,mBAAmB,GAAG;AAAA,IACzB,GAAG,OAAO;AAAA,EACZ;AAEA,QAAM,UAAU,oBAAoB,UAAiB;AACrD,QAAM,cAAgC,CAAC,YACrC,QAAQ,YAAY,EAAE,QAAQ,CAAC;AAGjC,QAAM,gBAAgB,QAAQ;AAC9B,QAAM,UAAU,UAAU;AAE1B,QAAM,sBACJ,OAAO,uBACP,iCAAiC;AAAA,IAC/B,SAAS,UAAU;AAAA,IACnB,iBAAiB,UAAU;AAAA,IAC3B,SAAS,OAAO;AAAA,IAChB,YAAY,QAAQ;AAAA,IACpB;AAAA,EACF,CAAC;AAEH,QAAM,SAA0C,OAAO,SACnD;AAAA,IACE,QAAQ,OAAO,OAAO;AAAA,IACtB,gBAAgB,OAAO,OAAO;AAAA,IAC9B,SAAS,OAAO,OAAO,WAAW;AAAA,IAClC,aAAa,OAAO,OAAO;AAAA,IAC3B;AAAA,EACF,IACA;AAEJ,SAAO;AAAA,IACL,YAAY,QAAQ;AAAA,IAEpB,gBAAwB;AACtB,aAAO,QAAQ;AAAA,IACjB;AAAA,IAEA,iBAA8B;AAC5B,aAAO;AAAA,QACL,IAAI,OAAO,IAAI;AAAA,QACf,MAAM,OAAO,IAAI;AAAA,QACjB,aAAa,OAAO,IAAI;AAAA,QACxB,SAAS,QAAQ;AAAA,MACnB;AAAA,IACF;AAAA,IAEA,MAAM,oBAAoB,OAA+B;AACvD,aAAO,oBAAoB,oBAAoB;AAAA,QAC7C,YAAY,QAAQ;AAAA,QACpB,KAAK,OAAO;AAAA,QACZ,QAAQ,OAAO;AAAA,QACf,QAAQ,OAAO;AAAA,QACf,WAAW,MAAM;AAAA,MACnB,CAAC;AAAA,IACH;AAAA,IAEA,MAAM,uBACJ,WAC8B;AAC9B,aAAO,oBAAoB,uBAAuB,SAAS;AAAA,IAC7D;AAAA,IAEA,MAAM,iBAA8B,OAED;AACjC,YAAM,SAAS,MAAM,oBAAoB;AAAA,QACvC,MAAM;AAAA,MACR;AACA,UACE,OAAO,WAAW,cAClB,CAAC,OAAO,qBACR,CAAC,OAAO,WACR,CAAC,OAAO,OACR;AACA,cAAM,IAAI;AAAA,UACR;AAAA,UACA;AAAA,YACE,WAAW,MAAM;AAAA,YACjB,QAAQ,OAAO;AAAA,YACf,sBAAsB,QAAQ,OAAO,iBAAiB;AAAA,YACtD,YAAY,QAAQ,OAAO,OAAO;AAAA,YAClC,UAAU,QAAQ,OAAO,KAAK;AAAA,UAChC;AAAA,QACF;AAAA,MACF;AAEA,YAAM,SAAS,MAAM,uBAAuB;AAAA,QAC1C,mBAAmB,OAAO;AAAA,QAC1B,OAAO,OAAO;AAAA,QACd,SAAS,OAAO;AAAA,QAChB,cAAc,QAAQ;AAAA,QACtB;AAAA,QACA;AAAA,QACA,SAAS,OAAO;AAAA,MAClB,CAAC;AAED,aAAO;AAAA,QACL,OAAO,OAAO;AAAA,QACd,MAAM,OAAO;AAAA,QACb,SAAS,OAAO;AAAA,MAClB;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var endpoints_exports = {};
20
+ __export(endpoints_exports, {
21
+ DEV_ENDPOINTS: () => DEV_ENDPOINTS,
22
+ PRODUCTION_ENDPOINTS: () => PRODUCTION_ENDPOINTS,
23
+ getDirectEndpoints: () => getDirectEndpoints
24
+ });
25
+ module.exports = __toCommonJS(endpoints_exports);
26
+ const PRODUCTION_ENDPOINTS = {
27
+ chainId: 1480,
28
+ accessRequestBaseUrl: "https://app.vana.org",
29
+ approvalAppBaseUrl: "https://app.vana.org"
30
+ };
31
+ const DEV_ENDPOINTS = {
32
+ chainId: 14800,
33
+ accessRequestBaseUrl: "https://app-dev.vana.org",
34
+ approvalAppBaseUrl: "https://app-dev.vana.org"
35
+ };
36
+ function getDirectEndpoints(env) {
37
+ return env === "dev" ? DEV_ENDPOINTS : PRODUCTION_ENDPOINTS;
38
+ }
39
+ // Annotate the CommonJS export names for ESM import in node:
40
+ 0 && (module.exports = {
41
+ DEV_ENDPOINTS,
42
+ PRODUCTION_ENDPOINTS,
43
+ getDirectEndpoints
44
+ });
45
+ //# sourceMappingURL=endpoints.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/direct/endpoints.ts"],"sourcesContent":["/**\n * Per-environment service URLs for the Direct Data Controller.\n *\n * @remarks\n * The SDK ships production defaults; pass `env: \"dev\"` only when testing against\n * Vana's dev stack. This module is the single source of truth for those URLs.\n *\n * @category Direct\n * @module direct/endpoints\n */\n\nimport type { DirectEnv, DirectServiceEndpoints } from \"./types\";\n\n/** Production (mainnet) service URLs. */\nexport const PRODUCTION_ENDPOINTS: DirectServiceEndpoints = {\n chainId: 1480,\n accessRequestBaseUrl: \"https://app.vana.org\",\n approvalAppBaseUrl: \"https://app.vana.org\",\n} as const;\n\n/** Dev/testnet (moksha) service URLs. */\nexport const DEV_ENDPOINTS: DirectServiceEndpoints = {\n chainId: 14800,\n accessRequestBaseUrl: \"https://app-dev.vana.org\",\n approvalAppBaseUrl: \"https://app-dev.vana.org\",\n} as const;\n\n/**\n * Resolve the default {@link DirectServiceEndpoints} for an environment.\n *\n * @param env - Target environment.\n * @returns The default endpoints for that environment.\n */\nexport function getDirectEndpoints(env: DirectEnv): DirectServiceEndpoints {\n return env === \"dev\" ? DEV_ENDPOINTS : PRODUCTION_ENDPOINTS;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAcO,MAAM,uBAA+C;AAAA,EAC1D,SAAS;AAAA,EACT,sBAAsB;AAAA,EACtB,oBAAoB;AACtB;AAGO,MAAM,gBAAwC;AAAA,EACnD,SAAS;AAAA,EACT,sBAAsB;AAAA,EACtB,oBAAoB;AACtB;AAQO,SAAS,mBAAmB,KAAwC;AACzE,SAAO,QAAQ,QAAQ,gBAAgB;AACzC;","names":[]}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Per-environment service URLs for the Direct Data Controller.
3
+ *
4
+ * @remarks
5
+ * The SDK ships production defaults; pass `env: "dev"` only when testing against
6
+ * Vana's dev stack. This module is the single source of truth for those URLs.
7
+ *
8
+ * @category Direct
9
+ * @module direct/endpoints
10
+ */
11
+ import type { DirectEnv, DirectServiceEndpoints } from "./types";
12
+ /** Production (mainnet) service URLs. */
13
+ export declare const PRODUCTION_ENDPOINTS: DirectServiceEndpoints;
14
+ /** Dev/testnet (moksha) service URLs. */
15
+ export declare const DEV_ENDPOINTS: DirectServiceEndpoints;
16
+ /**
17
+ * Resolve the default {@link DirectServiceEndpoints} for an environment.
18
+ *
19
+ * @param env - Target environment.
20
+ * @returns The default endpoints for that environment.
21
+ */
22
+ export declare function getDirectEndpoints(env: DirectEnv): DirectServiceEndpoints;
@@ -0,0 +1,19 @@
1
+ const PRODUCTION_ENDPOINTS = {
2
+ chainId: 1480,
3
+ accessRequestBaseUrl: "https://app.vana.org",
4
+ approvalAppBaseUrl: "https://app.vana.org"
5
+ };
6
+ const DEV_ENDPOINTS = {
7
+ chainId: 14800,
8
+ accessRequestBaseUrl: "https://app-dev.vana.org",
9
+ approvalAppBaseUrl: "https://app-dev.vana.org"
10
+ };
11
+ function getDirectEndpoints(env) {
12
+ return env === "dev" ? DEV_ENDPOINTS : PRODUCTION_ENDPOINTS;
13
+ }
14
+ export {
15
+ DEV_ENDPOINTS,
16
+ PRODUCTION_ENDPOINTS,
17
+ getDirectEndpoints
18
+ };
19
+ //# sourceMappingURL=endpoints.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/direct/endpoints.ts"],"sourcesContent":["/**\n * Per-environment service URLs for the Direct Data Controller.\n *\n * @remarks\n * The SDK ships production defaults; pass `env: \"dev\"` only when testing against\n * Vana's dev stack. This module is the single source of truth for those URLs.\n *\n * @category Direct\n * @module direct/endpoints\n */\n\nimport type { DirectEnv, DirectServiceEndpoints } from \"./types\";\n\n/** Production (mainnet) service URLs. */\nexport const PRODUCTION_ENDPOINTS: DirectServiceEndpoints = {\n chainId: 1480,\n accessRequestBaseUrl: \"https://app.vana.org\",\n approvalAppBaseUrl: \"https://app.vana.org\",\n} as const;\n\n/** Dev/testnet (moksha) service URLs. */\nexport const DEV_ENDPOINTS: DirectServiceEndpoints = {\n chainId: 14800,\n accessRequestBaseUrl: \"https://app-dev.vana.org\",\n approvalAppBaseUrl: \"https://app-dev.vana.org\",\n} as const;\n\n/**\n * Resolve the default {@link DirectServiceEndpoints} for an environment.\n *\n * @param env - Target environment.\n * @returns The default endpoints for that environment.\n */\nexport function getDirectEndpoints(env: DirectEnv): DirectServiceEndpoints {\n return env === \"dev\" ? DEV_ENDPOINTS : PRODUCTION_ENDPOINTS;\n}\n"],"mappings":"AAcO,MAAM,uBAA+C;AAAA,EAC1D,SAAS;AAAA,EACT,sBAAsB;AAAA,EACtB,oBAAoB;AACtB;AAGO,MAAM,gBAAwC;AAAA,EACnD,SAAS;AAAA,EACT,sBAAsB;AAAA,EACtB,oBAAoB;AACtB;AAQO,SAAS,mBAAmB,KAAwC;AACzE,SAAO,QAAQ,QAAQ,gBAAgB;AACzC;","names":[]}
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var errors_exports = {};
20
+ __export(errors_exports, {
21
+ AccessNotApprovedError: () => AccessNotApprovedError,
22
+ DirectConfigError: () => DirectConfigError,
23
+ PaymentRequiredError: () => PaymentRequiredError,
24
+ PersonalServerReadError: () => PersonalServerReadError
25
+ });
26
+ module.exports = __toCommonJS(errors_exports);
27
+ var import_errors = require("../errors");
28
+ class DirectConfigError extends import_errors.VanaError {
29
+ constructor(message, details) {
30
+ super(message, "DIRECT_CONFIG_ERROR");
31
+ this.details = details;
32
+ }
33
+ details;
34
+ }
35
+ class AccessNotApprovedError extends import_errors.VanaError {
36
+ constructor(message = "Access request is not approved yet", details) {
37
+ super(message, "DIRECT_ACCESS_NOT_APPROVED");
38
+ this.details = details;
39
+ }
40
+ details;
41
+ }
42
+ class PersonalServerReadError extends import_errors.VanaError {
43
+ constructor(message, status, details) {
44
+ super(message, "DIRECT_PERSONAL_SERVER_READ_ERROR");
45
+ this.status = status;
46
+ this.details = details;
47
+ }
48
+ status;
49
+ details;
50
+ }
51
+ class PaymentRequiredError extends import_errors.VanaError {
52
+ constructor(message, details) {
53
+ super(message, "DIRECT_PAYMENT_REQUIRED");
54
+ this.details = details;
55
+ }
56
+ details;
57
+ }
58
+ // Annotate the CommonJS export names for ESM import in node:
59
+ 0 && (module.exports = {
60
+ AccessNotApprovedError,
61
+ DirectConfigError,
62
+ PaymentRequiredError,
63
+ PersonalServerReadError
64
+ });
65
+ //# sourceMappingURL=errors.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/direct/errors.ts"],"sourcesContent":["/**\n * Typed errors for the Direct Data Controller flow.\n *\n * @remarks\n * These extend {@link VanaError} so direct-controller callers can branch on the\n * structured `code` field. The messages map to the failure modes documented in\n * the builder guide (\"Common Errors\").\n *\n * @category Direct\n * @module direct/errors\n */\n\nimport { VanaError } from \"../errors\";\n\n/** Thrown when configuration passed to {@link createDirectDataController} is invalid. */\nexport class DirectConfigError extends VanaError {\n constructor(\n message: string,\n public readonly details?: Record<string, unknown>,\n ) {\n super(message, \"DIRECT_CONFIG_ERROR\");\n }\n}\n\n/**\n * Thrown when {@link DirectDataController.readApprovedData} is called for a\n * request that is not yet approved (missing grantId, scope, or personalServerUrl).\n */\nexport class AccessNotApprovedError extends VanaError {\n constructor(\n message = \"Access request is not approved yet\",\n public readonly details?: Record<string, unknown>,\n ) {\n super(message, \"DIRECT_ACCESS_NOT_APPROVED\");\n }\n}\n\n/** Thrown when the Personal Server cannot be reached or returns an error. */\nexport class PersonalServerReadError extends VanaError {\n constructor(\n message: string,\n public readonly status?: number,\n public readonly details?: Record<string, unknown>,\n ) {\n super(message, \"DIRECT_PERSONAL_SERVER_READ_ERROR\");\n }\n}\n\n/**\n * Thrown when a Personal Server requires payment (HTTP 402) but no escrow config\n * is set, or the read still requires payment after escrow settlement.\n *\n * @remarks\n * `details` carries structured debug data (`scope`, `grantId`, `asset`,\n * `amount`, and — after a settlement attempt — the `payment` receipt) so callers\n * can see exactly what was owed.\n */\nexport class PaymentRequiredError extends VanaError {\n constructor(\n message: string,\n public readonly details?: Record<string, unknown>,\n ) {\n super(message, \"DIRECT_PAYMENT_REQUIRED\");\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYA,oBAA0B;AAGnB,MAAM,0BAA0B,wBAAU;AAAA,EAC/C,YACE,SACgB,SAChB;AACA,UAAM,SAAS,qBAAqB;AAFpB;AAAA,EAGlB;AAAA,EAHkB;AAIpB;AAMO,MAAM,+BAA+B,wBAAU;AAAA,EACpD,YACE,UAAU,sCACM,SAChB;AACA,UAAM,SAAS,4BAA4B;AAF3B;AAAA,EAGlB;AAAA,EAHkB;AAIpB;AAGO,MAAM,gCAAgC,wBAAU;AAAA,EACrD,YACE,SACgB,QACA,SAChB;AACA,UAAM,SAAS,mCAAmC;AAHlC;AACA;AAAA,EAGlB;AAAA,EAJkB;AAAA,EACA;AAIpB;AAWO,MAAM,6BAA6B,wBAAU;AAAA,EAClD,YACE,SACgB,SAChB;AACA,UAAM,SAAS,yBAAyB;AAFxB;AAAA,EAGlB;AAAA,EAHkB;AAIpB;","names":[]}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Typed errors for the Direct Data Controller flow.
3
+ *
4
+ * @remarks
5
+ * These extend {@link VanaError} so direct-controller callers can branch on the
6
+ * structured `code` field. The messages map to the failure modes documented in
7
+ * the builder guide ("Common Errors").
8
+ *
9
+ * @category Direct
10
+ * @module direct/errors
11
+ */
12
+ import { VanaError } from "../errors";
13
+ /** Thrown when configuration passed to {@link createDirectDataController} is invalid. */
14
+ export declare class DirectConfigError extends VanaError {
15
+ readonly details?: Record<string, unknown> | undefined;
16
+ constructor(message: string, details?: Record<string, unknown> | undefined);
17
+ }
18
+ /**
19
+ * Thrown when {@link DirectDataController.readApprovedData} is called for a
20
+ * request that is not yet approved (missing grantId, scope, or personalServerUrl).
21
+ */
22
+ export declare class AccessNotApprovedError extends VanaError {
23
+ readonly details?: Record<string, unknown> | undefined;
24
+ constructor(message?: string, details?: Record<string, unknown> | undefined);
25
+ }
26
+ /** Thrown when the Personal Server cannot be reached or returns an error. */
27
+ export declare class PersonalServerReadError extends VanaError {
28
+ readonly status?: number | undefined;
29
+ readonly details?: Record<string, unknown> | undefined;
30
+ constructor(message: string, status?: number | undefined, details?: Record<string, unknown> | undefined);
31
+ }
32
+ /**
33
+ * Thrown when a Personal Server requires payment (HTTP 402) but no escrow config
34
+ * is set, or the read still requires payment after escrow settlement.
35
+ *
36
+ * @remarks
37
+ * `details` carries structured debug data (`scope`, `grantId`, `asset`,
38
+ * `amount`, and — after a settlement attempt — the `payment` receipt) so callers
39
+ * can see exactly what was owed.
40
+ */
41
+ export declare class PaymentRequiredError extends VanaError {
42
+ readonly details?: Record<string, unknown> | undefined;
43
+ constructor(message: string, details?: Record<string, unknown> | undefined);
44
+ }
@@ -0,0 +1,38 @@
1
+ import { VanaError } from "../errors.js";
2
+ class DirectConfigError extends VanaError {
3
+ constructor(message, details) {
4
+ super(message, "DIRECT_CONFIG_ERROR");
5
+ this.details = details;
6
+ }
7
+ details;
8
+ }
9
+ class AccessNotApprovedError extends VanaError {
10
+ constructor(message = "Access request is not approved yet", details) {
11
+ super(message, "DIRECT_ACCESS_NOT_APPROVED");
12
+ this.details = details;
13
+ }
14
+ details;
15
+ }
16
+ class PersonalServerReadError extends VanaError {
17
+ constructor(message, status, details) {
18
+ super(message, "DIRECT_PERSONAL_SERVER_READ_ERROR");
19
+ this.status = status;
20
+ this.details = details;
21
+ }
22
+ status;
23
+ details;
24
+ }
25
+ class PaymentRequiredError extends VanaError {
26
+ constructor(message, details) {
27
+ super(message, "DIRECT_PAYMENT_REQUIRED");
28
+ this.details = details;
29
+ }
30
+ details;
31
+ }
32
+ export {
33
+ AccessNotApprovedError,
34
+ DirectConfigError,
35
+ PaymentRequiredError,
36
+ PersonalServerReadError
37
+ };
38
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/direct/errors.ts"],"sourcesContent":["/**\n * Typed errors for the Direct Data Controller flow.\n *\n * @remarks\n * These extend {@link VanaError} so direct-controller callers can branch on the\n * structured `code` field. The messages map to the failure modes documented in\n * the builder guide (\"Common Errors\").\n *\n * @category Direct\n * @module direct/errors\n */\n\nimport { VanaError } from \"../errors\";\n\n/** Thrown when configuration passed to {@link createDirectDataController} is invalid. */\nexport class DirectConfigError extends VanaError {\n constructor(\n message: string,\n public readonly details?: Record<string, unknown>,\n ) {\n super(message, \"DIRECT_CONFIG_ERROR\");\n }\n}\n\n/**\n * Thrown when {@link DirectDataController.readApprovedData} is called for a\n * request that is not yet approved (missing grantId, scope, or personalServerUrl).\n */\nexport class AccessNotApprovedError extends VanaError {\n constructor(\n message = \"Access request is not approved yet\",\n public readonly details?: Record<string, unknown>,\n ) {\n super(message, \"DIRECT_ACCESS_NOT_APPROVED\");\n }\n}\n\n/** Thrown when the Personal Server cannot be reached or returns an error. */\nexport class PersonalServerReadError extends VanaError {\n constructor(\n message: string,\n public readonly status?: number,\n public readonly details?: Record<string, unknown>,\n ) {\n super(message, \"DIRECT_PERSONAL_SERVER_READ_ERROR\");\n }\n}\n\n/**\n * Thrown when a Personal Server requires payment (HTTP 402) but no escrow config\n * is set, or the read still requires payment after escrow settlement.\n *\n * @remarks\n * `details` carries structured debug data (`scope`, `grantId`, `asset`,\n * `amount`, and — after a settlement attempt — the `payment` receipt) so callers\n * can see exactly what was owed.\n */\nexport class PaymentRequiredError extends VanaError {\n constructor(\n message: string,\n public readonly details?: Record<string, unknown>,\n ) {\n super(message, \"DIRECT_PAYMENT_REQUIRED\");\n }\n}\n"],"mappings":"AAYA,SAAS,iBAAiB;AAGnB,MAAM,0BAA0B,UAAU;AAAA,EAC/C,YACE,SACgB,SAChB;AACA,UAAM,SAAS,qBAAqB;AAFpB;AAAA,EAGlB;AAAA,EAHkB;AAIpB;AAMO,MAAM,+BAA+B,UAAU;AAAA,EACpD,YACE,UAAU,sCACM,SAChB;AACA,UAAM,SAAS,4BAA4B;AAF3B;AAAA,EAGlB;AAAA,EAHkB;AAIpB;AAGO,MAAM,gCAAgC,UAAU;AAAA,EACrD,YACE,SACgB,QACA,SAChB;AACA,UAAM,SAAS,mCAAmC;AAHlC;AACA;AAAA,EAGlB;AAAA,EAJkB;AAAA,EACA;AAIpB;AAWO,MAAM,6BAA6B,UAAU;AAAA,EAClD,YACE,SACgB,SAChB;AACA,UAAM,SAAS,yBAAyB;AAFxB;AAAA,EAGlB;AAAA,EAHkB;AAIpB;","names":[]}
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var escrow_payment_exports = {};
20
+ __export(escrow_payment_exports, {
21
+ GRANT_OP_TYPE: () => GRANT_OP_TYPE,
22
+ authorizeGrantPayment: () => authorizeGrantPayment,
23
+ createDefaultNonceSource: () => createDefaultNonceSource,
24
+ toDirectFeeBreakdown: () => toDirectFeeBreakdown,
25
+ toDirectPaymentReceipt: () => toDirectPaymentReceipt
26
+ });
27
+ module.exports = __toCommonJS(escrow_payment_exports);
28
+ var import_escrow = require("../protocol/escrow");
29
+ const GRANT_OP_TYPE = "grant";
30
+ function toDirectFeeBreakdown(breakdown) {
31
+ return {
32
+ registrationFee: breakdown.registrationFee,
33
+ dataAccessFee: breakdown.dataAccessFee,
34
+ registrationPaid: breakdown.registrationPaid
35
+ };
36
+ }
37
+ function toDirectPaymentReceipt(result) {
38
+ return {
39
+ opType: result.opType,
40
+ opId: result.opId,
41
+ asset: result.asset,
42
+ amount: result.amount,
43
+ paymentNonce: result.paymentNonce,
44
+ breakdown: toDirectFeeBreakdown(result.breakdown),
45
+ paidAt: result.paidAt
46
+ };
47
+ }
48
+ function createDefaultNonceSource() {
49
+ const counters = /* @__PURE__ */ new Map();
50
+ return (payerAddress) => {
51
+ const key = payerAddress.toLowerCase();
52
+ const next = (counters.get(key) ?? 0n) + 1n;
53
+ counters.set(key, next);
54
+ return next;
55
+ };
56
+ }
57
+ async function authorizeGrantPayment(params) {
58
+ const { payerAddress, required, config } = params;
59
+ const nonceSource = config.nonceSource ?? createDefaultNonceSource();
60
+ const paymentNonce = BigInt(await nonceSource(payerAddress));
61
+ const asset = required.asset || import_escrow.NATIVE_ASSET_ADDRESS;
62
+ const opId = required.grantId;
63
+ const amount = BigInt(required.amount);
64
+ const signature = await config.signTypedData({
65
+ domain: (0, import_escrow.genericPaymentDomain)(config.chainId, config.escrowContract),
66
+ types: import_escrow.GENERIC_PAYMENT_TYPES,
67
+ primaryType: "GenericPayment",
68
+ message: {
69
+ payerAddress,
70
+ opType: GRANT_OP_TYPE,
71
+ opId,
72
+ asset,
73
+ amount,
74
+ paymentNonce
75
+ }
76
+ });
77
+ const result = await config.client.payForOp({
78
+ payerAddress,
79
+ opType: GRANT_OP_TYPE,
80
+ opId,
81
+ asset,
82
+ amount: amount.toString(),
83
+ paymentNonce: paymentNonce.toString(),
84
+ signature
85
+ });
86
+ return toDirectPaymentReceipt(result);
87
+ }
88
+ // Annotate the CommonJS export names for ESM import in node:
89
+ 0 && (module.exports = {
90
+ GRANT_OP_TYPE,
91
+ authorizeGrantPayment,
92
+ createDefaultNonceSource,
93
+ toDirectFeeBreakdown,
94
+ toDirectPaymentReceipt
95
+ });
96
+ //# sourceMappingURL=escrow-payment.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/direct/escrow-payment.ts"],"sourcesContent":["/**\n * Escrow-backed payment authorization for the Direct Data Controller.\n *\n * @remarks\n * Builds on the DPv2 escrow surface added in `protocol/escrow`. When a Personal\n * Server read returns `402 Payment Required`, the controller settles the\n * grant's data-access fee through the escrow gateway:\n *\n * 1. Sign a `GenericPayment` EIP-712 message (op `\"grant\"`, opId = grantId)\n * with the app key.\n * 2. POST it to the gateway's `/v1/escrow/pay` via {@link EscrowGatewayClient}.\n * 3. Map the gateway's {@link EscrowPayResult} into a typed\n * {@link DirectPaymentReceipt} for the caller to inspect.\n *\n * This module adapts the escrow `payForOp` flow to the direct-read use case; it\n * does not define its own payment scheme.\n *\n * @category Direct\n * @module direct/escrow-payment\n */\n\nimport {\n GENERIC_PAYMENT_TYPES,\n NATIVE_ASSET_ADDRESS,\n genericPaymentDomain,\n type EscrowGatewayClient,\n type EscrowPayResult,\n type PaymentBreakdown,\n} from \"../protocol/escrow\";\nimport type {\n DirectFeeBreakdown,\n DirectPaymentReceipt,\n PersonalServerPaymentRequired,\n} from \"./types\";\n\n/** The escrow `GenericPayment.opType` used for grant-lifecycle payments. */\nexport const GRANT_OP_TYPE = \"grant\" as const;\n\n/**\n * EIP-712 typed-data signer (e.g. viem `account.signTypedData`).\n *\n * @remarks\n * Kept structurally minimal so any viem account/wallet client satisfies it\n * without the SDK depending on viem's exact `signTypedData` overload set.\n */\nexport type SignTypedDataFn = (args: {\n domain: ReturnType<typeof genericPaymentDomain>;\n types: typeof GENERIC_PAYMENT_TYPES;\n primaryType: \"GenericPayment\";\n message: {\n payerAddress: `0x${string}`;\n opType: string;\n opId: `0x${string}`;\n asset: `0x${string}`;\n amount: bigint;\n paymentNonce: bigint;\n };\n}) => Promise<`0x${string}`>;\n\n/** Supplies a monotonically-increasing payment nonce per payer. */\nexport type PaymentNonceSource = (\n payerAddress: string,\n) => Promise<bigint> | bigint;\n\n/** Escrow settlement configuration for the controller. */\nexport interface EscrowPaymentConfig {\n /** Client for the gateway escrow endpoints (`/v1/escrow/*`). */\n client: EscrowGatewayClient;\n /** Deployed `DataPortabilityEscrow` contract address. */\n escrowContract: `0x${string}`;\n /** Chain id for the EIP-712 domain (1480 mainnet, 14800 moksha). */\n chainId: number;\n /** App EIP-712 signer. */\n signTypedData: SignTypedDataFn;\n /**\n * Supplies the next payment nonce for a payer. Defaults to a process-local\n * monotonic counter seeded at 1. Provide a durable source in production so\n * nonces survive restarts (the gateway rejects reused (payer, nonce) pairs).\n */\n nonceSource?: PaymentNonceSource;\n}\n\n/** Map the gateway {@link PaymentBreakdown} into the public {@link DirectFeeBreakdown}. */\nexport function toDirectFeeBreakdown(\n breakdown: PaymentBreakdown,\n): DirectFeeBreakdown {\n return {\n registrationFee: breakdown.registrationFee,\n dataAccessFee: breakdown.dataAccessFee,\n registrationPaid: breakdown.registrationPaid,\n };\n}\n\n/** Map a gateway {@link EscrowPayResult} into the public {@link DirectPaymentReceipt}. */\nexport function toDirectPaymentReceipt(\n result: EscrowPayResult,\n): DirectPaymentReceipt {\n return {\n opType: result.opType,\n opId: result.opId,\n asset: result.asset,\n amount: result.amount,\n paymentNonce: result.paymentNonce,\n breakdown: toDirectFeeBreakdown(result.breakdown),\n paidAt: result.paidAt,\n };\n}\n\n/** Default in-process monotonic nonce counter (seeded at 1 per payer). */\nexport function createDefaultNonceSource(): PaymentNonceSource {\n const counters = new Map<string, bigint>();\n return (payerAddress: string): bigint => {\n const key = payerAddress.toLowerCase();\n const next = (counters.get(key) ?? 0n) + 1n;\n counters.set(key, next);\n return next;\n };\n}\n\n/**\n * Authorize an escrow payment for a grant data-access fee.\n *\n * @param params - The payment requirement, the payer address, and escrow config.\n * @returns The gateway's {@link EscrowPayResult} as a typed\n * {@link DirectPaymentReceipt}.\n */\nexport async function authorizeGrantPayment(params: {\n payerAddress: `0x${string}`;\n required: PersonalServerPaymentRequired;\n config: EscrowPaymentConfig;\n}): Promise<DirectPaymentReceipt> {\n const { payerAddress, required, config } = params;\n const nonceSource = config.nonceSource ?? createDefaultNonceSource();\n const paymentNonce = BigInt(await nonceSource(payerAddress));\n const asset = (required.asset || NATIVE_ASSET_ADDRESS) as `0x${string}`;\n const opId = required.grantId as `0x${string}`;\n const amount = BigInt(required.amount);\n\n const signature = await config.signTypedData({\n domain: genericPaymentDomain(config.chainId, config.escrowContract),\n types: GENERIC_PAYMENT_TYPES,\n primaryType: \"GenericPayment\",\n message: {\n payerAddress,\n opType: GRANT_OP_TYPE,\n opId,\n asset,\n amount,\n paymentNonce,\n },\n });\n\n const result = await config.client.payForOp({\n payerAddress,\n opType: GRANT_OP_TYPE,\n opId,\n asset,\n amount: amount.toString(),\n paymentNonce: paymentNonce.toString(),\n signature,\n });\n\n return toDirectPaymentReceipt(result);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAqBA,oBAOO;AAQA,MAAM,gBAAgB;AA+CtB,SAAS,qBACd,WACoB;AACpB,SAAO;AAAA,IACL,iBAAiB,UAAU;AAAA,IAC3B,eAAe,UAAU;AAAA,IACzB,kBAAkB,UAAU;AAAA,EAC9B;AACF;AAGO,SAAS,uBACd,QACsB;AACtB,SAAO;AAAA,IACL,QAAQ,OAAO;AAAA,IACf,MAAM,OAAO;AAAA,IACb,OAAO,OAAO;AAAA,IACd,QAAQ,OAAO;AAAA,IACf,cAAc,OAAO;AAAA,IACrB,WAAW,qBAAqB,OAAO,SAAS;AAAA,IAChD,QAAQ,OAAO;AAAA,EACjB;AACF;AAGO,SAAS,2BAA+C;AAC7D,QAAM,WAAW,oBAAI,IAAoB;AACzC,SAAO,CAAC,iBAAiC;AACvC,UAAM,MAAM,aAAa,YAAY;AACrC,UAAM,QAAQ,SAAS,IAAI,GAAG,KAAK,MAAM;AACzC,aAAS,IAAI,KAAK,IAAI;AACtB,WAAO;AAAA,EACT;AACF;AASA,eAAsB,sBAAsB,QAIV;AAChC,QAAM,EAAE,cAAc,UAAU,OAAO,IAAI;AAC3C,QAAM,cAAc,OAAO,eAAe,yBAAyB;AACnE,QAAM,eAAe,OAAO,MAAM,YAAY,YAAY,CAAC;AAC3D,QAAM,QAAS,SAAS,SAAS;AACjC,QAAM,OAAO,SAAS;AACtB,QAAM,SAAS,OAAO,SAAS,MAAM;AAErC,QAAM,YAAY,MAAM,OAAO,cAAc;AAAA,IAC3C,YAAQ,oCAAqB,OAAO,SAAS,OAAO,cAAc;AAAA,IAClE,OAAO;AAAA,IACP,aAAa;AAAA,IACb,SAAS;AAAA,MACP;AAAA,MACA,QAAQ;AAAA,MACR;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF,CAAC;AAED,QAAM,SAAS,MAAM,OAAO,OAAO,SAAS;AAAA,IAC1C;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,IACA,QAAQ,OAAO,SAAS;AAAA,IACxB,cAAc,aAAa,SAAS;AAAA,IACpC;AAAA,EACF,CAAC;AAED,SAAO,uBAAuB,MAAM;AACtC;","names":[]}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Escrow-backed payment authorization for the Direct Data Controller.
3
+ *
4
+ * @remarks
5
+ * Builds on the DPv2 escrow surface added in `protocol/escrow`. When a Personal
6
+ * Server read returns `402 Payment Required`, the controller settles the
7
+ * grant's data-access fee through the escrow gateway:
8
+ *
9
+ * 1. Sign a `GenericPayment` EIP-712 message (op `"grant"`, opId = grantId)
10
+ * with the app key.
11
+ * 2. POST it to the gateway's `/v1/escrow/pay` via {@link EscrowGatewayClient}.
12
+ * 3. Map the gateway's {@link EscrowPayResult} into a typed
13
+ * {@link DirectPaymentReceipt} for the caller to inspect.
14
+ *
15
+ * This module adapts the escrow `payForOp` flow to the direct-read use case; it
16
+ * does not define its own payment scheme.
17
+ *
18
+ * @category Direct
19
+ * @module direct/escrow-payment
20
+ */
21
+ import { GENERIC_PAYMENT_TYPES, genericPaymentDomain, type EscrowGatewayClient, type EscrowPayResult, type PaymentBreakdown } from "../protocol/escrow";
22
+ import type { DirectFeeBreakdown, DirectPaymentReceipt, PersonalServerPaymentRequired } from "./types";
23
+ /** The escrow `GenericPayment.opType` used for grant-lifecycle payments. */
24
+ export declare const GRANT_OP_TYPE: "grant";
25
+ /**
26
+ * EIP-712 typed-data signer (e.g. viem `account.signTypedData`).
27
+ *
28
+ * @remarks
29
+ * Kept structurally minimal so any viem account/wallet client satisfies it
30
+ * without the SDK depending on viem's exact `signTypedData` overload set.
31
+ */
32
+ export type SignTypedDataFn = (args: {
33
+ domain: ReturnType<typeof genericPaymentDomain>;
34
+ types: typeof GENERIC_PAYMENT_TYPES;
35
+ primaryType: "GenericPayment";
36
+ message: {
37
+ payerAddress: `0x${string}`;
38
+ opType: string;
39
+ opId: `0x${string}`;
40
+ asset: `0x${string}`;
41
+ amount: bigint;
42
+ paymentNonce: bigint;
43
+ };
44
+ }) => Promise<`0x${string}`>;
45
+ /** Supplies a monotonically-increasing payment nonce per payer. */
46
+ export type PaymentNonceSource = (payerAddress: string) => Promise<bigint> | bigint;
47
+ /** Escrow settlement configuration for the controller. */
48
+ export interface EscrowPaymentConfig {
49
+ /** Client for the gateway escrow endpoints (`/v1/escrow/*`). */
50
+ client: EscrowGatewayClient;
51
+ /** Deployed `DataPortabilityEscrow` contract address. */
52
+ escrowContract: `0x${string}`;
53
+ /** Chain id for the EIP-712 domain (1480 mainnet, 14800 moksha). */
54
+ chainId: number;
55
+ /** App EIP-712 signer. */
56
+ signTypedData: SignTypedDataFn;
57
+ /**
58
+ * Supplies the next payment nonce for a payer. Defaults to a process-local
59
+ * monotonic counter seeded at 1. Provide a durable source in production so
60
+ * nonces survive restarts (the gateway rejects reused (payer, nonce) pairs).
61
+ */
62
+ nonceSource?: PaymentNonceSource;
63
+ }
64
+ /** Map the gateway {@link PaymentBreakdown} into the public {@link DirectFeeBreakdown}. */
65
+ export declare function toDirectFeeBreakdown(breakdown: PaymentBreakdown): DirectFeeBreakdown;
66
+ /** Map a gateway {@link EscrowPayResult} into the public {@link DirectPaymentReceipt}. */
67
+ export declare function toDirectPaymentReceipt(result: EscrowPayResult): DirectPaymentReceipt;
68
+ /** Default in-process monotonic nonce counter (seeded at 1 per payer). */
69
+ export declare function createDefaultNonceSource(): PaymentNonceSource;
70
+ /**
71
+ * Authorize an escrow payment for a grant data-access fee.
72
+ *
73
+ * @param params - The payment requirement, the payer address, and escrow config.
74
+ * @returns The gateway's {@link EscrowPayResult} as a typed
75
+ * {@link DirectPaymentReceipt}.
76
+ */
77
+ export declare function authorizeGrantPayment(params: {
78
+ payerAddress: `0x${string}`;
79
+ required: PersonalServerPaymentRequired;
80
+ config: EscrowPaymentConfig;
81
+ }): Promise<DirectPaymentReceipt>;