@opendatalabs/vana-sdk 3.5.0 → 3.5.1-pr.159.12a6f39

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 (120) hide show
  1. package/README.md +116 -0
  2. package/dist/direct/access-request-client.cjs +104 -0
  3. package/dist/direct/access-request-client.cjs.map +1 -0
  4. package/dist/direct/access-request-client.d.ts +51 -0
  5. package/dist/direct/access-request-client.js +79 -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 +129 -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 +109 -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 +513 -174
  54. package/dist/index.browser.js.map +4 -4
  55. package/dist/index.node.cjs +536 -179
  56. package/dist/index.node.cjs.map +4 -4
  57. package/dist/index.node.d.ts +7 -3
  58. package/dist/index.node.js +513 -174
  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/dist/storage/providers/vana-storage.cjs +75 -17
  117. package/dist/storage/providers/vana-storage.cjs.map +1 -1
  118. package/dist/storage/providers/vana-storage.js +75 -17
  119. package/dist/storage/providers/vana-storage.js.map +1 -1
  120. package/package.json +20 -1
@@ -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>;
@@ -0,0 +1,72 @@
1
+ import {
2
+ GENERIC_PAYMENT_TYPES,
3
+ NATIVE_ASSET_ADDRESS,
4
+ genericPaymentDomain
5
+ } from "../protocol/escrow.js";
6
+ const GRANT_OP_TYPE = "grant";
7
+ function toDirectFeeBreakdown(breakdown) {
8
+ return {
9
+ registrationFee: breakdown.registrationFee,
10
+ dataAccessFee: breakdown.dataAccessFee,
11
+ registrationPaid: breakdown.registrationPaid
12
+ };
13
+ }
14
+ function toDirectPaymentReceipt(result) {
15
+ return {
16
+ opType: result.opType,
17
+ opId: result.opId,
18
+ asset: result.asset,
19
+ amount: result.amount,
20
+ paymentNonce: result.paymentNonce,
21
+ breakdown: toDirectFeeBreakdown(result.breakdown),
22
+ paidAt: result.paidAt
23
+ };
24
+ }
25
+ function createDefaultNonceSource() {
26
+ const counters = /* @__PURE__ */ new Map();
27
+ return (payerAddress) => {
28
+ const key = payerAddress.toLowerCase();
29
+ const next = (counters.get(key) ?? 0n) + 1n;
30
+ counters.set(key, next);
31
+ return next;
32
+ };
33
+ }
34
+ async function authorizeGrantPayment(params) {
35
+ const { payerAddress, required, config } = params;
36
+ const nonceSource = config.nonceSource ?? createDefaultNonceSource();
37
+ const paymentNonce = BigInt(await nonceSource(payerAddress));
38
+ const asset = required.asset || NATIVE_ASSET_ADDRESS;
39
+ const opId = required.grantId;
40
+ const amount = BigInt(required.amount);
41
+ const signature = await config.signTypedData({
42
+ domain: genericPaymentDomain(config.chainId, config.escrowContract),
43
+ types: GENERIC_PAYMENT_TYPES,
44
+ primaryType: "GenericPayment",
45
+ message: {
46
+ payerAddress,
47
+ opType: GRANT_OP_TYPE,
48
+ opId,
49
+ asset,
50
+ amount,
51
+ paymentNonce
52
+ }
53
+ });
54
+ const result = await config.client.payForOp({
55
+ payerAddress,
56
+ opType: GRANT_OP_TYPE,
57
+ opId,
58
+ asset,
59
+ amount: amount.toString(),
60
+ paymentNonce: paymentNonce.toString(),
61
+ signature
62
+ });
63
+ return toDirectPaymentReceipt(result);
64
+ }
65
+ export {
66
+ GRANT_OP_TYPE,
67
+ authorizeGrantPayment,
68
+ createDefaultNonceSource,
69
+ toDirectFeeBreakdown,
70
+ toDirectPaymentReceipt
71
+ };
72
+ //# sourceMappingURL=escrow-payment.js.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":"AAqBA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAIK;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,QAAQ,qBAAqB,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 @@
1
+ export {};
@@ -0,0 +1,149 @@
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 personal_server_read_exports = {};
20
+ __export(personal_server_read_exports, {
21
+ buildPersonalServerDataReadRequest: () => buildPersonalServerDataReadRequest,
22
+ dataPathForScope: () => dataPathForScope,
23
+ parsePersonalServerPaymentRequired: () => parsePersonalServerPaymentRequired,
24
+ readPersonalServerData: () => readPersonalServerData
25
+ });
26
+ module.exports = __toCommonJS(personal_server_read_exports);
27
+ var import_web3_signed_builder = require("../auth/web3-signed-builder");
28
+ var import_escrow = require("../protocol/escrow");
29
+ var import_escrow_payment = require("./escrow-payment");
30
+ var import_errors = require("./errors");
31
+ function stripTrailingSlash(url) {
32
+ return url.replace(/\/+$/, "");
33
+ }
34
+ function dataPathForScope(scope) {
35
+ return `/v1/data/${encodeURIComponent(scope)}`;
36
+ }
37
+ async function buildPersonalServerDataReadRequest(params) {
38
+ const base = stripTrailingSlash(params.personalServerUrl);
39
+ const path = dataPathForScope(params.scope);
40
+ const authorization = await (0, import_web3_signed_builder.buildWeb3SignedHeader)({
41
+ signMessage: params.signMessage,
42
+ aud: base,
43
+ method: "GET",
44
+ uri: path,
45
+ grantId: params.grantId
46
+ });
47
+ const headers = {
48
+ Authorization: authorization,
49
+ Accept: "application/json"
50
+ };
51
+ return { url: `${base}${path}`, method: "GET", path, headers };
52
+ }
53
+ async function parsePersonalServerPaymentRequired(res, grantId) {
54
+ let raw = void 0;
55
+ try {
56
+ raw = await res.json();
57
+ } catch {
58
+ raw = void 0;
59
+ }
60
+ const body = raw ?? {};
61
+ const resolvedGrantId = typeof body.grantId === "string" ? body.grantId : typeof body.opId === "string" ? body.opId : grantId;
62
+ const amountValue = typeof body.amount === "string" ? body.amount : typeof body.maxAmountRequired === "string" ? body.maxAmountRequired : "0";
63
+ return {
64
+ grantId: resolvedGrantId,
65
+ asset: typeof body.asset === "string" ? body.asset : import_escrow.NATIVE_ASSET_ADDRESS,
66
+ amount: amountValue,
67
+ raw
68
+ };
69
+ }
70
+ async function readPersonalServerData(params) {
71
+ const fetchFn = params.fetchFn ?? globalThis.fetch;
72
+ if (!fetchFn) {
73
+ throw new import_errors.PersonalServerReadError(
74
+ "No fetch implementation available for Personal Server read"
75
+ );
76
+ }
77
+ const initial = await buildPersonalServerDataReadRequest({
78
+ personalServerUrl: params.personalServerUrl,
79
+ scope: params.scope,
80
+ grantId: params.grantId,
81
+ signMessage: params.signMessage
82
+ });
83
+ let res = await fetchFn(initial.url, {
84
+ method: initial.method,
85
+ headers: initial.headers
86
+ });
87
+ let payment;
88
+ if (res.status === 402) {
89
+ const required = await parsePersonalServerPaymentRequired(
90
+ res,
91
+ params.grantId
92
+ );
93
+ if (!params.escrow) {
94
+ throw new import_errors.PaymentRequiredError(
95
+ "Personal Server requires payment but no escrow config is set",
96
+ {
97
+ scope: params.scope,
98
+ grantId: required.grantId,
99
+ asset: required.asset,
100
+ amount: required.amount
101
+ }
102
+ );
103
+ }
104
+ payment = await (0, import_escrow_payment.authorizeGrantPayment)({
105
+ payerAddress: params.payerAddress,
106
+ required,
107
+ config: params.escrow
108
+ });
109
+ const retry = await buildPersonalServerDataReadRequest({
110
+ personalServerUrl: params.personalServerUrl,
111
+ scope: params.scope,
112
+ grantId: params.grantId,
113
+ signMessage: params.signMessage
114
+ });
115
+ res = await fetchFn(retry.url, {
116
+ method: retry.method,
117
+ headers: retry.headers
118
+ });
119
+ if (res.status === 402) {
120
+ throw new import_errors.PaymentRequiredError(
121
+ "Personal Server still requires payment after escrow settlement",
122
+ {
123
+ scope: params.scope,
124
+ grantId: required.grantId,
125
+ asset: required.asset,
126
+ amount: required.amount,
127
+ payment
128
+ }
129
+ );
130
+ }
131
+ }
132
+ if (!res.ok) {
133
+ const detail = await res.text().catch(() => "");
134
+ throw new import_errors.PersonalServerReadError(
135
+ `Personal Server read failed: ${res.status} ${res.statusText}`,
136
+ res.status,
137
+ { scope: params.scope, body: detail.slice(0, 500) }
138
+ );
139
+ }
140
+ return { data: await res.json(), payment };
141
+ }
142
+ // Annotate the CommonJS export names for ESM import in node:
143
+ 0 && (module.exports = {
144
+ buildPersonalServerDataReadRequest,
145
+ dataPathForScope,
146
+ parsePersonalServerPaymentRequired,
147
+ readPersonalServerData
148
+ });
149
+ //# sourceMappingURL=personal-server-read.cjs.map