@openzeppelin/relayer-plugin-channels 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/LICENSE +661 -21
  2. package/README.md +239 -60
  3. package/dist/client/channels-client.d.ts +142 -0
  4. package/dist/client/channels-client.d.ts.map +1 -0
  5. package/dist/client/channels-client.js +245 -0
  6. package/dist/client/errors.d.ts +47 -0
  7. package/dist/client/errors.d.ts.map +1 -0
  8. package/dist/client/errors.js +61 -0
  9. package/dist/client/index.d.ts +10 -0
  10. package/dist/client/index.d.ts.map +1 -0
  11. package/dist/client/index.js +16 -0
  12. package/dist/client/types.d.ts +119 -0
  13. package/dist/client/types.d.ts.map +1 -0
  14. package/dist/client/types.js +2 -0
  15. package/dist/index.d.ts +4 -4
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +20 -109
  18. package/dist/plugin/build.d.ts.map +1 -0
  19. package/dist/plugin/config.d.ts.map +1 -0
  20. package/dist/plugin/constants.d.ts.map +1 -0
  21. package/dist/plugin/fee.d.ts.map +1 -0
  22. package/dist/plugin/handler.d.ts +12 -0
  23. package/dist/plugin/handler.d.ts.map +1 -0
  24. package/dist/plugin/handler.js +117 -0
  25. package/dist/plugin/index.d.ts +7 -0
  26. package/dist/plugin/index.d.ts.map +1 -0
  27. package/dist/plugin/index.js +10 -0
  28. package/dist/plugin/management.d.ts.map +1 -0
  29. package/dist/plugin/pool.d.ts.map +1 -0
  30. package/dist/plugin/simulation.d.ts.map +1 -0
  31. package/dist/plugin/submit.d.ts.map +1 -0
  32. package/dist/plugin/tx.d.ts.map +1 -0
  33. package/dist/plugin/types.d.ts.map +1 -0
  34. package/dist/plugin/validation.d.ts.map +1 -0
  35. package/package.json +3 -2
  36. package/dist/build.d.ts.map +0 -1
  37. package/dist/config.d.ts.map +0 -1
  38. package/dist/constants.d.ts.map +0 -1
  39. package/dist/fee.d.ts.map +0 -1
  40. package/dist/management.d.ts.map +0 -1
  41. package/dist/pool.d.ts.map +0 -1
  42. package/dist/simulation.d.ts.map +0 -1
  43. package/dist/submit.d.ts.map +0 -1
  44. package/dist/test/config.test.d.ts +0 -2
  45. package/dist/test/config.test.d.ts.map +0 -1
  46. package/dist/test/config.test.js +0 -43
  47. package/dist/test/fee.test.d.ts +0 -2
  48. package/dist/test/fee.test.d.ts.map +0 -1
  49. package/dist/test/fee.test.js +0 -34
  50. package/dist/test/helpers/fakeKV.d.ts +0 -17
  51. package/dist/test/helpers/fakeKV.d.ts.map +0 -1
  52. package/dist/test/helpers/fakeKV.js +0 -60
  53. package/dist/test/management.test.d.ts +0 -2
  54. package/dist/test/management.test.d.ts.map +0 -1
  55. package/dist/test/management.test.js +0 -66
  56. package/dist/test/pool.busy.test.d.ts +0 -2
  57. package/dist/test/pool.busy.test.d.ts.map +0 -1
  58. package/dist/test/pool.busy.test.js +0 -23
  59. package/dist/test/pool.test.d.ts +0 -2
  60. package/dist/test/pool.test.d.ts.map +0 -1
  61. package/dist/test/pool.test.js +0 -29
  62. package/dist/test/tx.test.d.ts +0 -2
  63. package/dist/test/tx.test.d.ts.map +0 -1
  64. package/dist/test/tx.test.js +0 -29
  65. package/dist/test/validation.test.d.ts +0 -2
  66. package/dist/test/validation.test.d.ts.map +0 -1
  67. package/dist/test/validation.test.js +0 -31
  68. package/dist/tx.d.ts.map +0 -1
  69. package/dist/types.d.ts.map +0 -1
  70. package/dist/validation.d.ts.map +0 -1
  71. /package/dist/{build.d.ts → plugin/build.d.ts} +0 -0
  72. /package/dist/{build.js → plugin/build.js} +0 -0
  73. /package/dist/{config.d.ts → plugin/config.d.ts} +0 -0
  74. /package/dist/{config.js → plugin/config.js} +0 -0
  75. /package/dist/{constants.d.ts → plugin/constants.d.ts} +0 -0
  76. /package/dist/{constants.js → plugin/constants.js} +0 -0
  77. /package/dist/{fee.d.ts → plugin/fee.d.ts} +0 -0
  78. /package/dist/{fee.js → plugin/fee.js} +0 -0
  79. /package/dist/{management.d.ts → plugin/management.d.ts} +0 -0
  80. /package/dist/{management.js → plugin/management.js} +0 -0
  81. /package/dist/{pool.d.ts → plugin/pool.d.ts} +0 -0
  82. /package/dist/{pool.js → plugin/pool.js} +0 -0
  83. /package/dist/{simulation.d.ts → plugin/simulation.d.ts} +0 -0
  84. /package/dist/{simulation.js → plugin/simulation.js} +0 -0
  85. /package/dist/{submit.d.ts → plugin/submit.d.ts} +0 -0
  86. /package/dist/{submit.js → plugin/submit.js} +0 -0
  87. /package/dist/{tx.d.ts → plugin/tx.d.ts} +0 -0
  88. /package/dist/{tx.js → plugin/tx.js} +0 -0
  89. /package/dist/{types.d.ts → plugin/types.d.ts} +0 -0
  90. /package/dist/{types.js → plugin/types.js} +0 -0
  91. /package/dist/{validation.d.ts → plugin/validation.d.ts} +0 -0
  92. /package/dist/{validation.js → plugin/validation.js} +0 -0
@@ -0,0 +1,245 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ChannelsClient = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const relayer_sdk_1 = require("@openzeppelin/relayer-sdk");
9
+ const errors_1 = require("./errors");
10
+ /**
11
+ * Client for interacting with the Channels plugin
12
+ *
13
+ * @example
14
+ * // Connecting to OpenZeppelin's managed Channels service
15
+ * const client = new ChannelsClient({
16
+ * baseUrl: 'https://channels.openzeppelin.com',
17
+ * apiKey: 'your-api-key',
18
+ * adminSecret: 'your-admin-secret', // Optional, for management operations
19
+ * });
20
+ *
21
+ * @example
22
+ * // Connecting to your own Relayer with Channels plugin
23
+ * const client = new ChannelsClient({
24
+ * baseUrl: 'http://localhost:8080',
25
+ * pluginId: 'channels',
26
+ * apiKey: 'your-relayer-api-key',
27
+ * adminSecret: 'your-admin-secret', // Optional, for management operations
28
+ * });
29
+ */
30
+ class ChannelsClient {
31
+ constructor(config) {
32
+ this.adminSecret = config.adminSecret;
33
+ // Route through Relayer plugin system if pluginId provided, otherwise connect directly
34
+ if ("pluginId" in config && config.pluginId) {
35
+ this.pluginId = config.pluginId;
36
+ const relayerConfig = new relayer_sdk_1.Configuration({
37
+ basePath: config.baseUrl,
38
+ accessToken: config.apiKey,
39
+ });
40
+ this.pluginsApi = new relayer_sdk_1.PluginsApi(relayerConfig);
41
+ }
42
+ else {
43
+ if (!("baseUrl" in config) || !config.baseUrl) {
44
+ throw new Error("baseUrl is required when pluginId is not provided");
45
+ }
46
+ this.axiosClient = axios_1.default.create({
47
+ baseURL: config.baseUrl,
48
+ timeout: config.timeout || 30000,
49
+ headers: {
50
+ "Content-Type": "application/json",
51
+ Authorization: `Bearer ${config.apiKey}`,
52
+ },
53
+ });
54
+ }
55
+ }
56
+ /**
57
+ * Submit a signed XDR transaction to the channel accounts service
58
+ *
59
+ * @param request Transaction request with signed XDR
60
+ * @returns Transaction result with ID, hash, and status
61
+ * @throws {PluginTransportError} Network/HTTP failures
62
+ * @throws {PluginExecutionError} Plugin rejected the request
63
+ * @throws {PluginUnexpectedError} Malformed response or client-side errors
64
+ *
65
+ * @example
66
+ * const result = await client.submitTransaction({
67
+ * xdr: 'AAAAAgAAAAC...',
68
+ * });
69
+ */
70
+ async submitTransaction(request) {
71
+ return this.call(request);
72
+ }
73
+ /**
74
+ * Submit a Soroban transaction using function and authorization entries
75
+ * This path uses channel accounts and includes automatic simulation
76
+ *
77
+ * @param request Transaction request with func and auth
78
+ * @returns Transaction result with ID, hash, and status
79
+ * @throws {PluginTransportError} Network/HTTP failures
80
+ * @throws {PluginExecutionError} Plugin rejected the request
81
+ * @throws {PluginUnexpectedError} Malformed response or client-side errors
82
+ *
83
+ * @example
84
+ * const result = await client.submitSorobanTransaction({
85
+ * func: 'AAAABgAAAA...',
86
+ * auth: ['AAAABwAAAA...', 'AAAABwAAAA...'],
87
+ * });
88
+ */
89
+ async submitSorobanTransaction(request) {
90
+ return this.call(request);
91
+ }
92
+ /**
93
+ * List currently configured channel accounts (requires adminSecret)
94
+ *
95
+ * @returns List of channel account relayer IDs
96
+ * @throws {Error} If adminSecret not provided in config
97
+ * @throws {PluginTransportError} Network/HTTP failures
98
+ * @throws {PluginExecutionError} Plugin rejected the request
99
+ * @throws {PluginUnexpectedError} Malformed response or client-side errors
100
+ *
101
+ * @example
102
+ * const accounts = await client.listChannelAccounts();
103
+ * console.log(accounts.relayerIds);
104
+ */
105
+ async listChannelAccounts() {
106
+ return this.call({
107
+ management: {
108
+ action: "listChannelAccounts",
109
+ adminSecret: this.requireAdminSecret(),
110
+ },
111
+ });
112
+ }
113
+ /**
114
+ * Configure channel accounts for the service (requires adminSecret)
115
+ *
116
+ * @param relayerIds Array of relayer IDs to use as channel accounts
117
+ * @returns Confirmation with applied relayer IDs
118
+ * @throws {Error} If adminSecret not provided in config
119
+ * @throws {PluginTransportError} Network/HTTP failures
120
+ * @throws {PluginExecutionError} Plugin rejected the request
121
+ * @throws {PluginUnexpectedError} Malformed response or client-side errors
122
+ *
123
+ * @example
124
+ * const result = await client.setChannelAccounts([
125
+ * 'relayer-id-1',
126
+ * 'relayer-id-2',
127
+ * ]);
128
+ */
129
+ async setChannelAccounts(relayerIds) {
130
+ return this.call({
131
+ management: {
132
+ action: "setChannelAccounts",
133
+ adminSecret: this.requireAdminSecret(),
134
+ relayerIds,
135
+ },
136
+ });
137
+ }
138
+ /**
139
+ * Ensures adminSecret is configured
140
+ *
141
+ * @returns The admin secret value
142
+ * @throws {Error} If adminSecret not provided in config
143
+ */
144
+ requireAdminSecret() {
145
+ if (!this.adminSecret) {
146
+ throw new Error("adminSecret required for management operations. Provide it in client config.");
147
+ }
148
+ return this.adminSecret;
149
+ }
150
+ /**
151
+ * Parses axios errors and extracts response body if available
152
+ *
153
+ * @param error The caught error from axios
154
+ * @returns Plugin response if available in error
155
+ * @throws {PluginTransportError} For network/transport errors
156
+ * @throws {PluginUnexpectedError} For unknown error types
157
+ */
158
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
159
+ parseAxiosError(error) {
160
+ if (axios_1.default.isAxiosError(error)) {
161
+ if (error.response?.data) {
162
+ // HTTP error with response body - return it for further processing
163
+ return error.response.data;
164
+ }
165
+ // Network/transport error without response body
166
+ throw new errors_1.PluginTransportError(`Network error: ${error.message}`, error.response?.status, error);
167
+ }
168
+ // Unknown error type
169
+ throw new errors_1.PluginUnexpectedError(`Unexpected error: ${error instanceof Error ? error.message : String(error)}`, error);
170
+ }
171
+ /**
172
+ * Validates that response has the expected plugin response structure
173
+ *
174
+ * @param responseBody The raw response body to validate
175
+ * @returns Validated plugin response
176
+ * @throws {PluginUnexpectedError} For invalid/malformed responses
177
+ */
178
+ validateResponse(responseBody) {
179
+ if (!responseBody || typeof responseBody !== "object") {
180
+ throw new errors_1.PluginUnexpectedError("Empty or invalid response from plugin");
181
+ }
182
+ const response = responseBody;
183
+ if (response.success === undefined) {
184
+ throw new errors_1.PluginUnexpectedError("Malformed response: missing success field");
185
+ }
186
+ return response;
187
+ }
188
+ /**
189
+ * Merges metadata into the response data if present
190
+ *
191
+ * @param data The response data
192
+ * @param metadata Optional metadata (logs and traces)
193
+ * @returns Data with metadata merged if present
194
+ */
195
+ mergeMetadata(data, metadata) {
196
+ if (!metadata || (!metadata.logs && !metadata.traces)) {
197
+ return data;
198
+ }
199
+ return { ...data, metadata };
200
+ }
201
+ /**
202
+ * Internal method to make a plugin call with automatic payload wrapping and response parsing
203
+ *
204
+ * @param params Request parameters
205
+ * @returns Parsed response data with optional metadata
206
+ * @throws {PluginTransportError} Network/HTTP failures
207
+ * @throws {PluginExecutionError} Plugin rejected the request
208
+ * @throws {PluginUnexpectedError} Malformed response or client-side errors
209
+ */
210
+ async call(params) {
211
+ const payload = { params };
212
+ // Send request and handle transport errors
213
+ let responseBody;
214
+ try {
215
+ responseBody = await this.sendCall(payload);
216
+ }
217
+ catch (error) {
218
+ responseBody = this.parseAxiosError(error);
219
+ }
220
+ // Validate response structure
221
+ const response = this.validateResponse(responseBody);
222
+ // Handle execution errors
223
+ if (!response.success) {
224
+ throw new errors_1.PluginExecutionError(response.error || "Plugin execution failed", response.data);
225
+ }
226
+ // Return data with metadata if present
227
+ return this.mergeMetadata(response.data, response.metadata);
228
+ }
229
+ /**
230
+ * Internal method to send the actual HTTP request
231
+ * Routes to either axios (direct HTTP) or PluginsApi (relayer) based on configuration
232
+ *
233
+ * @param payload The complete payload (already wrapped in {params})
234
+ * @returns Raw response from the service/relayer
235
+ */
236
+ async sendCall(payload) {
237
+ if (this.pluginsApi) {
238
+ const response = await this.pluginsApi.callPlugin(this.pluginId, payload);
239
+ return response.data;
240
+ }
241
+ const response = await this.axiosClient.post("/", payload);
242
+ return response.data;
243
+ }
244
+ }
245
+ exports.ChannelsClient = ChannelsClient;
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Base class for all plugin-related errors
3
+ */
4
+ export declare abstract class PluginClientError extends Error {
5
+ abstract readonly category: "transport" | "execution" | "client";
6
+ }
7
+ /**
8
+ * HTTP/Network transport failures
9
+ *
10
+ * Thrown when communication with the service fails:
11
+ * - Network errors (connection refused, timeout, DNS failures)
12
+ * - HTTP errors (500, 502, 503, 504)
13
+ * - Invalid responses (malformed JSON)
14
+ */
15
+ export declare class PluginTransportError extends PluginClientError {
16
+ readonly statusCode?: number | undefined;
17
+ readonly errorDetails?: any | undefined;
18
+ readonly category = "transport";
19
+ constructor(message: string, statusCode?: number | undefined, errorDetails?: any | undefined);
20
+ }
21
+ /**
22
+ * Plugin execution/validation errors
23
+ *
24
+ * Thrown when the plugin processes the request but returns an error:
25
+ * - Validation failures (invalid parameters, missing auth)
26
+ * - Business logic errors (insufficient balance, rate limits)
27
+ * - On-chain failures (transaction reverted)
28
+ */
29
+ export declare class PluginExecutionError extends PluginClientError {
30
+ readonly errorDetails?: any | undefined;
31
+ readonly category = "execution";
32
+ constructor(message: string, errorDetails?: any | undefined);
33
+ }
34
+ /**
35
+ * Client-side parsing/validation errors
36
+ *
37
+ * Thrown when the client encounters unexpected issues:
38
+ * - Empty or malformed responses
39
+ * - Missing required fields in response
40
+ * - Unexpected response structure
41
+ */
42
+ export declare class PluginUnexpectedError extends PluginClientError {
43
+ readonly errorDetails?: any | undefined;
44
+ readonly category = "client";
45
+ constructor(message: string, errorDetails?: any | undefined);
46
+ }
47
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/client/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,8BAAsB,iBAAkB,SAAQ,KAAK;IACnD,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,WAAW,GAAG,WAAW,GAAG,QAAQ,CAAC;CAClE;AAED;;;;;;;GAOG;AACH,qBAAa,oBAAqB,SAAQ,iBAAiB;aAKvC,UAAU,CAAC,EAAE,MAAM;aACnB,YAAY,CAAC,EAAE,GAAG;IALpC,QAAQ,CAAC,QAAQ,eAAe;gBAG9B,OAAO,EAAE,MAAM,EACC,UAAU,CAAC,EAAE,MAAM,YAAA,EACnB,YAAY,CAAC,EAAE,GAAG,YAAA;CAKrC;AAED;;;;;;;GAOG;AACH,qBAAa,oBAAqB,SAAQ,iBAAiB;aAKvC,YAAY,CAAC,EAAE,GAAG;IAJpC,QAAQ,CAAC,QAAQ,eAAe;gBAG9B,OAAO,EAAE,MAAM,EACC,YAAY,CAAC,EAAE,GAAG,YAAA;CAKrC;AAED;;;;;;;GAOG;AACH,qBAAa,qBAAsB,SAAQ,iBAAiB;aAKxC,YAAY,CAAC,EAAE,GAAG;IAJpC,QAAQ,CAAC,QAAQ,YAAY;gBAG3B,OAAO,EAAE,MAAM,EACC,YAAY,CAAC,EAAE,GAAG,YAAA;CAKrC"}
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PluginUnexpectedError = exports.PluginExecutionError = exports.PluginTransportError = exports.PluginClientError = void 0;
4
+ /**
5
+ * Base class for all plugin-related errors
6
+ */
7
+ class PluginClientError extends Error {
8
+ }
9
+ exports.PluginClientError = PluginClientError;
10
+ /**
11
+ * HTTP/Network transport failures
12
+ *
13
+ * Thrown when communication with the service fails:
14
+ * - Network errors (connection refused, timeout, DNS failures)
15
+ * - HTTP errors (500, 502, 503, 504)
16
+ * - Invalid responses (malformed JSON)
17
+ */
18
+ class PluginTransportError extends PluginClientError {
19
+ constructor(message, statusCode, errorDetails) {
20
+ super(message);
21
+ this.statusCode = statusCode;
22
+ this.errorDetails = errorDetails;
23
+ this.category = "transport";
24
+ this.name = "PluginTransportError";
25
+ }
26
+ }
27
+ exports.PluginTransportError = PluginTransportError;
28
+ /**
29
+ * Plugin execution/validation errors
30
+ *
31
+ * Thrown when the plugin processes the request but returns an error:
32
+ * - Validation failures (invalid parameters, missing auth)
33
+ * - Business logic errors (insufficient balance, rate limits)
34
+ * - On-chain failures (transaction reverted)
35
+ */
36
+ class PluginExecutionError extends PluginClientError {
37
+ constructor(message, errorDetails) {
38
+ super(message);
39
+ this.errorDetails = errorDetails;
40
+ this.category = "execution";
41
+ this.name = "PluginExecutionError";
42
+ }
43
+ }
44
+ exports.PluginExecutionError = PluginExecutionError;
45
+ /**
46
+ * Client-side parsing/validation errors
47
+ *
48
+ * Thrown when the client encounters unexpected issues:
49
+ * - Empty or malformed responses
50
+ * - Missing required fields in response
51
+ * - Unexpected response structure
52
+ */
53
+ class PluginUnexpectedError extends PluginClientError {
54
+ constructor(message, errorDetails) {
55
+ super(message);
56
+ this.errorDetails = errorDetails;
57
+ this.category = "client";
58
+ this.name = "PluginUnexpectedError";
59
+ }
60
+ }
61
+ exports.PluginUnexpectedError = PluginUnexpectedError;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Channels Plugin Client
3
+ *
4
+ * Unified client for interacting with the channels plugin
5
+ * in both direct HTTP mode and OpenZeppelin Relayer mode.
6
+ */
7
+ export { ChannelsClient } from "./channels-client";
8
+ export { ChannelsClientConfig, DirectHttpConfig, RelayerConfig, ChannelsXdrRequest, ChannelsFuncAuthRequest, ChannelsTransactionResponse, ListChannelAccountsResponse, SetChannelAccountsResponse, } from "./types";
9
+ export { PluginClientError, PluginTransportError, PluginExecutionError, PluginUnexpectedError, } from "./errors";
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,uBAAuB,EACvB,2BAA2B,EAC3B,2BAA2B,EAC3B,0BAA0B,GAC3B,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,UAAU,CAAC"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ /**
3
+ * Channels Plugin Client
4
+ *
5
+ * Unified client for interacting with the channels plugin
6
+ * in both direct HTTP mode and OpenZeppelin Relayer mode.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.PluginUnexpectedError = exports.PluginExecutionError = exports.PluginTransportError = exports.PluginClientError = exports.ChannelsClient = void 0;
10
+ var channels_client_1 = require("./channels-client");
11
+ Object.defineProperty(exports, "ChannelsClient", { enumerable: true, get: function () { return channels_client_1.ChannelsClient; } });
12
+ var errors_1 = require("./errors");
13
+ Object.defineProperty(exports, "PluginClientError", { enumerable: true, get: function () { return errors_1.PluginClientError; } });
14
+ Object.defineProperty(exports, "PluginTransportError", { enumerable: true, get: function () { return errors_1.PluginTransportError; } });
15
+ Object.defineProperty(exports, "PluginExecutionError", { enumerable: true, get: function () { return errors_1.PluginExecutionError; } });
16
+ Object.defineProperty(exports, "PluginUnexpectedError", { enumerable: true, get: function () { return errors_1.PluginUnexpectedError; } });
@@ -0,0 +1,119 @@
1
+ import type { LogEntry } from "@openzeppelin/relayer-sdk";
2
+ /**
3
+ * Configuration for ChannelsClient in direct HTTP mode
4
+ */
5
+ export interface DirectHttpConfig {
6
+ /** Base URL for channel accounts service */
7
+ baseUrl: string;
8
+ /** API key for channel accounts service */
9
+ apiKey: string;
10
+ /** Optional admin secret for management operations */
11
+ adminSecret?: string;
12
+ /** Optional request timeout in milliseconds (default: 30000) */
13
+ timeout?: number;
14
+ }
15
+ /**
16
+ * Configuration for ChannelsClient in relayer mode
17
+ */
18
+ export interface RelayerConfig {
19
+ /** Plugin ID in the OpenZeppelin Relayer */
20
+ pluginId: string;
21
+ /** API key for OpenZeppelin Relayer */
22
+ apiKey: string;
23
+ /** Base URL for OpenZeppelin Relayer */
24
+ baseUrl: string;
25
+ /** Optional admin secret for management operations */
26
+ adminSecret?: string;
27
+ /** Optional request timeout in milliseconds (default: 30000) */
28
+ timeout?: number;
29
+ }
30
+ /**
31
+ * Configuration for ChannelsClient
32
+ * The client automatically detects the mode:
33
+ * - If pluginId is provided → relayer mode
34
+ * - Otherwise → direct HTTP mode
35
+ */
36
+ export type ChannelsClientConfig = DirectHttpConfig | RelayerConfig;
37
+ /**
38
+ * Transaction submission request using signed XDR
39
+ */
40
+ export interface ChannelsXdrRequest {
41
+ /** Complete signed transaction envelope XDR */
42
+ xdr: string;
43
+ }
44
+ /**
45
+ * Transaction submission using Soroban function and authorization
46
+ */
47
+ export interface ChannelsFuncAuthRequest {
48
+ /** Soroban host function XDR (base64) */
49
+ func: string;
50
+ /** Array of authorization entry XDRs (base64) */
51
+ auth: string[];
52
+ }
53
+ /**
54
+ * Response from transaction submission
55
+ */
56
+ export interface ChannelsTransactionResponse {
57
+ /** Transaction ID from the relayer */
58
+ transactionId: string | null;
59
+ /** Transaction hash on-chain */
60
+ hash: string | null;
61
+ /** Transaction status */
62
+ status: string | null;
63
+ /** Optional metadata (logs and traces) */
64
+ metadata?: {
65
+ logs?: LogEntry[];
66
+ traces?: any[];
67
+ };
68
+ }
69
+ /**
70
+ * Response from listing channel accounts
71
+ */
72
+ export interface ListChannelAccountsResponse {
73
+ /** Array of relayer IDs currently configured as channel accounts */
74
+ relayerIds: string[];
75
+ /** Optional metadata (logs and traces) */
76
+ metadata?: {
77
+ logs?: LogEntry[];
78
+ traces?: any[];
79
+ };
80
+ }
81
+ /**
82
+ * Response from setting channel accounts
83
+ */
84
+ export interface SetChannelAccountsResponse {
85
+ /** Success indicator */
86
+ ok: boolean;
87
+ /** Array of relayer IDs that were applied */
88
+ appliedRelayerIds: string[];
89
+ /** Optional metadata (logs and traces) */
90
+ metadata?: {
91
+ logs?: LogEntry[];
92
+ traces?: any[];
93
+ };
94
+ }
95
+ /**
96
+ * Plugin response structure for successful operations
97
+ */
98
+ export interface PluginResponseSuccess<T> {
99
+ success: true;
100
+ data: T;
101
+ metadata?: {
102
+ logs?: LogEntry[];
103
+ traces?: any[];
104
+ };
105
+ }
106
+ /**
107
+ * Plugin response structure for failed operations
108
+ */
109
+ export interface PluginResponseError {
110
+ success: false;
111
+ error: string;
112
+ data?: any;
113
+ }
114
+ /**
115
+ * Discriminated union type for all plugin responses
116
+ * Enables type-safe handling of success/error cases
117
+ */
118
+ export type PluginResponse<T> = PluginResponseSuccess<T> | PluginResponseError;
119
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAE1D;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,4CAA4C;IAC5C,OAAO,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,sDAAsD;IACtD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gEAAgE;IAChE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,4CAA4C;IAC5C,QAAQ,EAAE,MAAM,CAAC;IACjB,uCAAuC;IACvC,MAAM,EAAE,MAAM,CAAC;IACf,wCAAwC;IACxC,OAAO,EAAE,MAAM,CAAC;IAChB,sDAAsD;IACtD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gEAAgE;IAChE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;GAKG;AACH,MAAM,MAAM,oBAAoB,GAAG,gBAAgB,GAAG,aAAa,CAAC;AAEpE;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,+CAA+C;IAC/C,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,iDAAiD;IACjD,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C,sCAAsC;IACtC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,gCAAgC;IAChC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,yBAAyB;IACzB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,0CAA0C;IAC1C,QAAQ,CAAC,EAAE;QACT,IAAI,CAAC,EAAE,QAAQ,EAAE,CAAC;QAClB,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC;KAChB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C,oEAAoE;IACpE,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,0CAA0C;IAC1C,QAAQ,CAAC,EAAE;QACT,IAAI,CAAC,EAAE,QAAQ,EAAE,CAAC;QAClB,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC;KAChB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,wBAAwB;IACxB,EAAE,EAAE,OAAO,CAAC;IACZ,6CAA6C;IAC7C,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,0CAA0C;IAC1C,QAAQ,CAAC,EAAE;QACT,IAAI,CAAC,EAAE,QAAQ,EAAE,CAAC;QAClB,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC;KAChB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB,CAAC,CAAC;IACtC,OAAO,EAAE,IAAI,CAAC;IACd,IAAI,EAAE,CAAC,CAAC;IACR,QAAQ,CAAC,EAAE;QACT,IAAI,CAAC,EAAE,QAAQ,EAAE,CAAC;QAClB,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC;KAChB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,KAAK,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,GAAG,CAAC;CACZ;AAED;;;GAGG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI,qBAAqB,CAAC,CAAC,CAAC,GAAG,mBAAmB,CAAC"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * index.ts
3
3
  *
4
- * Main entry point for the channel accounts plugin.
5
- * Orchestrates the transaction processing pipeline using channel accounts with fee bumping.
4
+ * Main entry point for the @openzeppelin/relayer-plugin-channels package
5
+ * Re-exports both the client (for external use) and the plugin handler
6
6
  */
7
- import { PluginContext } from "@openzeppelin/relayer-sdk";
8
- export declare function handler(context: PluginContext): Promise<any>;
7
+ export * from "./client";
8
+ export * from "./plugin";
9
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAe,MAAM,2BAA2B,CAAC;AAiLvE,wBAAsB,OAAO,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,CAGlE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,cAAc,UAAU,CAAC;AAGzB,cAAc,UAAU,CAAC"}