@openzeppelin/relayer-plugin-channels 0.6.0 → 0.8.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.
- package/README.md +79 -43
- package/dist/client/channels-client.d.ts +1 -1
- package/dist/client/channels-client.d.ts.map +1 -1
- package/dist/client/channels-client.js +20 -21
- package/dist/client/errors.d.ts +1 -1
- package/dist/client/errors.js +12 -9
- package/dist/client/index.d.ts +3 -3
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/types.d.ts +5 -1
- package/dist/client/types.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/plugin/build.d.ts +1 -1
- package/dist/plugin/build.d.ts.map +1 -1
- package/dist/plugin/build.js +11 -17
- package/dist/plugin/config.d.ts +4 -2
- package/dist/plugin/config.d.ts.map +1 -1
- package/dist/plugin/config.js +43 -13
- package/dist/plugin/constants.d.ts +1 -0
- package/dist/plugin/constants.d.ts.map +1 -1
- package/dist/plugin/constants.js +2 -1
- package/dist/plugin/fee-tracking.d.ts +2 -2
- package/dist/plugin/fee-tracking.d.ts.map +1 -1
- package/dist/plugin/fee-tracking.js +4 -9
- package/dist/plugin/fee.d.ts +12 -5
- package/dist/plugin/fee.d.ts.map +1 -1
- package/dist/plugin/fee.js +39 -23
- package/dist/plugin/handler.d.ts +2 -2
- package/dist/plugin/handler.d.ts.map +1 -1
- package/dist/plugin/handler.js +52 -34
- package/dist/plugin/index.d.ts +1 -1
- package/dist/plugin/management.d.ts +1 -1
- package/dist/plugin/management.d.ts.map +1 -1
- package/dist/plugin/management.js +53 -79
- package/dist/plugin/pool.d.ts +8 -3
- package/dist/plugin/pool.d.ts.map +1 -1
- package/dist/plugin/pool.js +45 -17
- package/dist/plugin/simulation.d.ts +34 -6
- package/dist/plugin/simulation.d.ts.map +1 -1
- package/dist/plugin/simulation.js +86 -49
- package/dist/plugin/submit.d.ts +5 -5
- package/dist/plugin/submit.d.ts.map +1 -1
- package/dist/plugin/submit.js +11 -14
- package/dist/plugin/tx.d.ts +1 -1
- package/dist/plugin/tx.d.ts.map +1 -1
- package/dist/plugin/tx.js +6 -8
- package/dist/plugin/types.d.ts +8 -4
- package/dist/plugin/types.d.ts.map +1 -1
- package/dist/plugin/validation.d.ts +1 -1
- package/dist/plugin/validation.d.ts.map +1 -1
- package/dist/plugin/validation.js +26 -27
- package/package.json +1 -1
package/dist/plugin/submit.d.ts
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Signing and submission logic for channel account transactions.
|
|
5
5
|
*/
|
|
6
|
-
import { Transaction } from
|
|
7
|
-
import { Relayer, PluginAPI } from
|
|
8
|
-
import { ChannelAccountsResponse } from
|
|
9
|
-
import { FeeTracker } from
|
|
6
|
+
import { Transaction } from '@stellar/stellar-sdk';
|
|
7
|
+
import { Relayer, PluginAPI } from '@openzeppelin/relayer-sdk';
|
|
8
|
+
import { ChannelAccountsResponse } from './types';
|
|
9
|
+
import { FeeTracker } from './fee-tracking';
|
|
10
10
|
/**
|
|
11
11
|
* Sign transaction with both channel and fund relayers
|
|
12
12
|
* - First sign with channel account
|
|
@@ -17,7 +17,7 @@ export declare function signWithChannelAndFund(transaction: Transaction, channel
|
|
|
17
17
|
/**
|
|
18
18
|
* Submit transaction with fee bump and wait for confirmation
|
|
19
19
|
*/
|
|
20
|
-
export declare function submitWithFeeBumpAndWait(fundRelayer: Relayer, signedXdr: string, network:
|
|
20
|
+
export declare function submitWithFeeBumpAndWait(fundRelayer: Relayer, signedXdr: string, network: 'testnet' | 'mainnet', maxFee: number, api: PluginAPI, tracker?: FeeTracker): Promise<ChannelAccountsResponse>;
|
|
21
21
|
/** Strip provider wrapper text, extract last segment (e.g., "TxInsufficientBalance") */
|
|
22
22
|
export declare function sanitizeReason(reason: string): string;
|
|
23
23
|
//# sourceMappingURL=submit.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"submit.d.ts","sourceRoot":"","sources":["../../src/plugin/submit.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAEL,OAAO,EAGP,SAAS,EACV,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAC1C,WAAW,EAAE,WAAW,EACxB,cAAc,EAAE,OAAO,EACvB,YAAY,EAAE,OAAO,EACrB,cAAc,EAAE,MAAM,EACtB,YAAY,EAAE,MAAM,EACpB,iBAAiB,EAAE,MAAM,GACxB,OAAO,CAAC,WAAW,CAAC,
|
|
1
|
+
{"version":3,"file":"submit.d.ts","sourceRoot":"","sources":["../../src/plugin/submit.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAEL,OAAO,EAGP,SAAS,EACV,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAC1C,WAAW,EAAE,WAAW,EACxB,cAAc,EAAE,OAAO,EACvB,YAAY,EAAE,OAAO,EACrB,cAAc,EAAE,MAAM,EACtB,YAAY,EAAE,MAAM,EACpB,iBAAiB,EAAE,MAAM,GACxB,OAAO,CAAC,WAAW,CAAC,CAuBtB;AAED;;GAEG;AACH,wBAAsB,wBAAwB,CAC5C,WAAW,EAAE,OAAO,EACpB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,SAAS,GAAG,SAAS,EAC9B,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,SAAS,EACd,OAAO,CAAC,EAAE,UAAU,GACnB,OAAO,CAAC,uBAAuB,CAAC,CAkElC;AASD,wFAAwF;AACxF,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAOrD"}
|
package/dist/plugin/submit.js
CHANGED
|
@@ -26,8 +26,8 @@ async function signWithChannelAndFund(transaction, channelRelayer, _fundRelayer,
|
|
|
26
26
|
unsigned_xdr: txXdr,
|
|
27
27
|
});
|
|
28
28
|
if (!isSignTransactionResponseStellar(channelSignResult)) {
|
|
29
|
-
throw (0, relayer_sdk_1.pluginError)(
|
|
30
|
-
code:
|
|
29
|
+
throw (0, relayer_sdk_1.pluginError)('Invalid channel signature response', {
|
|
30
|
+
code: 'INVALID_SIGNATURE',
|
|
31
31
|
status: constants_1.HTTP_STATUS.INTERNAL_SERVER_ERROR,
|
|
32
32
|
});
|
|
33
33
|
}
|
|
@@ -58,16 +58,16 @@ async function submitWithFeeBumpAndWait(fundRelayer, signedXdr, network, maxFee,
|
|
|
58
58
|
timeout: 25000,
|
|
59
59
|
}));
|
|
60
60
|
// Check if transaction actually succeeded
|
|
61
|
-
if (final.status ===
|
|
61
|
+
if (final.status === 'failed') {
|
|
62
62
|
// Record fee on on-chain failure (transaction was still submitted and consumed fees)
|
|
63
63
|
if (tracker) {
|
|
64
64
|
await tracker.recordUsage(maxFee);
|
|
65
65
|
}
|
|
66
|
-
const rawReason = final.status_reason ||
|
|
66
|
+
const rawReason = final.status_reason || 'Transaction failed';
|
|
67
67
|
console.error(`[channels] Transaction failed: ${rawReason}`);
|
|
68
68
|
const reason = sanitizeReason(rawReason);
|
|
69
69
|
throw (0, relayer_sdk_1.pluginError)(reason, {
|
|
70
|
-
code:
|
|
70
|
+
code: 'ONCHAIN_FAILED',
|
|
71
71
|
status: constants_1.HTTP_STATUS.BAD_REQUEST,
|
|
72
72
|
details: {
|
|
73
73
|
status: String(final.status),
|
|
@@ -89,12 +89,12 @@ async function submitWithFeeBumpAndWait(fundRelayer, signedXdr, network, maxFee,
|
|
|
89
89
|
}
|
|
90
90
|
catch (error) {
|
|
91
91
|
// If it's already a pluginError with ONCHAIN_FAILED, rethrow it
|
|
92
|
-
if (error.code ===
|
|
92
|
+
if (error.code === 'ONCHAIN_FAILED') {
|
|
93
93
|
throw error;
|
|
94
94
|
}
|
|
95
95
|
// Otherwise, it's a timeout - don't track fees (status unknown)
|
|
96
|
-
throw (0, relayer_sdk_1.pluginError)(
|
|
97
|
-
code:
|
|
96
|
+
throw (0, relayer_sdk_1.pluginError)('Transaction wait timeout. It may still submit.', {
|
|
97
|
+
code: 'WAIT_TIMEOUT',
|
|
98
98
|
status: constants_1.HTTP_STATUS.GATEWAY_TIMEOUT,
|
|
99
99
|
details: {
|
|
100
100
|
id: submission.id,
|
|
@@ -107,17 +107,14 @@ async function submitWithFeeBumpAndWait(fundRelayer, signedXdr, network, maxFee,
|
|
|
107
107
|
* Type guard for SignTransactionResponseStellar
|
|
108
108
|
*/
|
|
109
109
|
function isSignTransactionResponseStellar(data) {
|
|
110
|
-
return
|
|
111
|
-
typeof data === "object" &&
|
|
112
|
-
"signature" in data &&
|
|
113
|
-
"signedXdr" in data);
|
|
110
|
+
return data !== null && typeof data === 'object' && 'signature' in data && 'signedXdr' in data;
|
|
114
111
|
}
|
|
115
112
|
/** Strip provider wrapper text, extract last segment (e.g., "TxInsufficientBalance") */
|
|
116
113
|
function sanitizeReason(reason) {
|
|
117
114
|
const segments = reason.split(/:\s*/);
|
|
118
115
|
const last = segments[segments.length - 1]?.trim();
|
|
119
|
-
if (last && last.length > 2 && !last.toLowerCase().includes(
|
|
116
|
+
if (last && last.length > 2 && !last.toLowerCase().includes('provider')) {
|
|
120
117
|
return last;
|
|
121
118
|
}
|
|
122
|
-
return reason.length > 100 ? reason.slice(0, 100) +
|
|
119
|
+
return reason.length > 100 ? reason.slice(0, 100) + '...' : reason;
|
|
123
120
|
}
|
package/dist/plugin/tx.d.ts
CHANGED
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Transaction validation helpers for the XDR submit-only path.
|
|
5
5
|
*/
|
|
6
|
-
import { Transaction } from
|
|
6
|
+
import { Transaction } from '@stellar/stellar-sdk';
|
|
7
7
|
export declare function validateExistingTransactionForSubmitOnly(tx: Transaction): Transaction;
|
|
8
8
|
//# sourceMappingURL=tx.d.ts.map
|
package/dist/plugin/tx.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tx.d.ts","sourceRoot":"","sources":["../../src/plugin/tx.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAO,MAAM,sBAAsB,CAAC;AAIxD,wBAAgB,wCAAwC,
|
|
1
|
+
{"version":3,"file":"tx.d.ts","sourceRoot":"","sources":["../../src/plugin/tx.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAO,MAAM,sBAAsB,CAAC;AAIxD,wBAAgB,wCAAwC,CAAC,EAAE,EAAE,WAAW,GAAG,WAAW,CAsCrF"}
|
package/dist/plugin/tx.js
CHANGED
|
@@ -15,8 +15,8 @@ function validateExistingTransactionForSubmitOnly(tx) {
|
|
|
15
15
|
const envelope = tx.toEnvelope();
|
|
16
16
|
const kind = envelope.switch();
|
|
17
17
|
if (kind !== stellar_sdk_1.xdr.EnvelopeType.envelopeTypeTx()) {
|
|
18
|
-
throw (0, relayer_sdk_1.pluginError)(
|
|
19
|
-
code:
|
|
18
|
+
throw (0, relayer_sdk_1.pluginError)('Input must be a regular transaction envelope (fee-bump not allowed)', {
|
|
19
|
+
code: 'INVALID_ENVELOPE_TYPE',
|
|
20
20
|
status: constants_1.HTTP_STATUS.BAD_REQUEST,
|
|
21
21
|
});
|
|
22
22
|
}
|
|
@@ -25,19 +25,17 @@ function validateExistingTransactionForSubmitOnly(tx) {
|
|
|
25
25
|
if (sorobanData) {
|
|
26
26
|
const resourceFee = sorobanData.resourceFee().toBigInt();
|
|
27
27
|
if (BigInt(tx.fee) > resourceFee + 201n) {
|
|
28
|
-
throw (0, relayer_sdk_1.pluginError)(
|
|
29
|
-
code:
|
|
28
|
+
throw (0, relayer_sdk_1.pluginError)('Transaction fee must be equal to the resource fee', {
|
|
29
|
+
code: 'FEE_MISMATCH',
|
|
30
30
|
status: constants_1.HTTP_STATUS.BAD_REQUEST,
|
|
31
31
|
details: { fee: tx.fee, resourceFee: resourceFee.toString() },
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
// Time bounds sanity
|
|
36
|
-
if (tx.timeBounds?.maxTime &&
|
|
37
|
-
Number(tx.timeBounds.maxTime) - now >
|
|
38
|
-
constants_1.SIMULATION.MAX_FUTURE_TIME_BOUND_SECONDS) {
|
|
36
|
+
if (tx.timeBounds?.maxTime && Number(tx.timeBounds.maxTime) - now > constants_1.SIMULATION.MAX_FUTURE_TIME_BOUND_SECONDS) {
|
|
39
37
|
throw (0, relayer_sdk_1.pluginError)(`Transaction \`timeBounds.maxTime\` too far into the future. Must be no greater than ${constants_1.SIMULATION.MAX_FUTURE_TIME_BOUND_SECONDS} seconds`, {
|
|
40
|
-
code:
|
|
38
|
+
code: 'TIMEBOUNDS_TOO_FAR',
|
|
41
39
|
status: constants_1.HTTP_STATUS.BAD_REQUEST,
|
|
42
40
|
});
|
|
43
41
|
}
|
package/dist/plugin/types.d.ts
CHANGED
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
* - Submit-only: signed regular transaction XDR
|
|
9
9
|
* - Channel build: func + auth (always simulated)
|
|
10
10
|
*/
|
|
11
|
-
import type { xdr } from
|
|
11
|
+
import type { xdr } from '@stellar/stellar-sdk';
|
|
12
12
|
export type ChannelAccountsRequest = {
|
|
13
|
-
type:
|
|
13
|
+
type: 'xdr';
|
|
14
14
|
xdr: string;
|
|
15
15
|
} | {
|
|
16
|
-
type:
|
|
16
|
+
type: 'func-auth';
|
|
17
17
|
func: xdr.HostFunction;
|
|
18
18
|
auth: xdr.SorobanAuthorizationEntry[];
|
|
19
19
|
};
|
|
@@ -24,6 +24,10 @@ export interface ChannelAccountsResponse {
|
|
|
24
24
|
transactionId: string | null;
|
|
25
25
|
status: string | null;
|
|
26
26
|
hash: string | null;
|
|
27
|
+
/** Present only for read-only calls: the base64-encoded xdr.ScVal return value */
|
|
28
|
+
returnValue?: string;
|
|
29
|
+
/** Present only for read-only calls: the latest ledger at simulation time */
|
|
30
|
+
latestLedger?: number;
|
|
27
31
|
}
|
|
28
32
|
/**
|
|
29
33
|
* Management request structure
|
|
@@ -31,7 +35,7 @@ export interface ChannelAccountsResponse {
|
|
|
31
35
|
export interface ManagementRequest {
|
|
32
36
|
management: {
|
|
33
37
|
adminSecret: string;
|
|
34
|
-
action:
|
|
38
|
+
action: 'listChannelAccounts' | 'setChannelAccounts';
|
|
35
39
|
relayerIds?: string[];
|
|
36
40
|
};
|
|
37
41
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/plugin/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;GAIG;AACH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAEhD,MAAM,MAAM,sBAAsB,GAC9B;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAC5B;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/plugin/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;GAIG;AACH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAEhD,MAAM,MAAM,sBAAsB,GAC9B;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAC5B;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,GAAG,CAAC,YAAY,CAAC;IAAC,IAAI,EAAE,GAAG,CAAC,yBAAyB,EAAE,CAAA;CAAE,CAAC;AAEzF;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,kFAAkF;IAClF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,6EAA6E;IAC7E,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE;QACV,WAAW,EAAE,MAAM,CAAC;QACpB,MAAM,EAAE,qBAAqB,GAAG,oBAAoB,CAAC;QACrD,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;KACvB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,EAAE,EAAE,OAAO,CAAC;IACZ,iBAAiB,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB"}
|
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
* Request validation and parsing for the Channel Accounts plugin.
|
|
5
5
|
* Supports either a signed XDR or func+auth.
|
|
6
6
|
*/
|
|
7
|
-
import { ChannelAccountsRequest } from
|
|
7
|
+
import { ChannelAccountsRequest } from './types';
|
|
8
8
|
export declare function validateAndParseRequest(params: any): ChannelAccountsRequest;
|
|
9
9
|
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/plugin/validation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAEjD,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,GAAG,GAAG,sBAAsB,
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/plugin/validation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAEjD,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,GAAG,GAAG,sBAAsB,CAiF3E"}
|
|
@@ -11,38 +11,38 @@ const stellar_sdk_1 = require("@stellar/stellar-sdk");
|
|
|
11
11
|
const relayer_sdk_1 = require("@openzeppelin/relayer-sdk");
|
|
12
12
|
const constants_1 = require("./constants");
|
|
13
13
|
function validateAndParseRequest(params) {
|
|
14
|
-
if (!params || typeof params !==
|
|
15
|
-
throw (0, relayer_sdk_1.pluginError)(
|
|
16
|
-
code:
|
|
14
|
+
if (!params || typeof params !== 'object') {
|
|
15
|
+
throw (0, relayer_sdk_1.pluginError)('Invalid request: params must be an object', {
|
|
16
|
+
code: 'INVALID_PARAMS',
|
|
17
17
|
status: constants_1.HTTP_STATUS.BAD_REQUEST,
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
// Disallow any management-shaped keys leaking into here; management is handled earlier
|
|
21
21
|
const keys = Object.keys(params);
|
|
22
22
|
// Mode: XDR
|
|
23
|
-
if (
|
|
24
|
-
if (typeof params.xdr !==
|
|
25
|
-
throw (0, relayer_sdk_1.pluginError)(
|
|
26
|
-
code:
|
|
23
|
+
if ('xdr' in params) {
|
|
24
|
+
if (typeof params.xdr !== 'string' || params.xdr.trim() === '') {
|
|
25
|
+
throw (0, relayer_sdk_1.pluginError)('`xdr` must be a non-empty base64 string', {
|
|
26
|
+
code: 'INVALID_PARAMS',
|
|
27
27
|
status: constants_1.HTTP_STATUS.BAD_REQUEST,
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
// Strict: cannot include func/auth when using xdr
|
|
31
|
-
const unknown = keys.filter((k) => ![
|
|
31
|
+
const unknown = keys.filter((k) => !['xdr'].includes(k));
|
|
32
32
|
if (unknown.length > 0) {
|
|
33
|
-
throw (0, relayer_sdk_1.pluginError)(
|
|
34
|
-
code:
|
|
33
|
+
throw (0, relayer_sdk_1.pluginError)('`xdr` request must not include other parameters', {
|
|
34
|
+
code: 'INVALID_PARAMS',
|
|
35
35
|
status: constants_1.HTTP_STATUS.BAD_REQUEST,
|
|
36
36
|
details: { unknown },
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
|
-
return { type:
|
|
39
|
+
return { type: 'xdr', xdr: params.xdr.trim() };
|
|
40
40
|
}
|
|
41
41
|
// Mode: func+auth
|
|
42
|
-
if (
|
|
42
|
+
if ('func' in params || 'auth' in params) {
|
|
43
43
|
if (!params.func || !params.auth) {
|
|
44
|
-
throw (0, relayer_sdk_1.pluginError)(
|
|
45
|
-
code:
|
|
44
|
+
throw (0, relayer_sdk_1.pluginError)('`func` and `auth` are both required when omitting `xdr`', {
|
|
45
|
+
code: 'INVALID_PARAMS',
|
|
46
46
|
status: constants_1.HTTP_STATUS.BAD_REQUEST,
|
|
47
47
|
});
|
|
48
48
|
}
|
|
@@ -50,15 +50,15 @@ function validateAndParseRequest(params) {
|
|
|
50
50
|
let func;
|
|
51
51
|
let auth = [];
|
|
52
52
|
try {
|
|
53
|
-
func = stellar_sdk_1.xdr.HostFunction.fromXDR(params.func,
|
|
53
|
+
func = stellar_sdk_1.xdr.HostFunction.fromXDR(params.func, 'base64');
|
|
54
54
|
if (!Array.isArray(params.auth)) {
|
|
55
|
-
throw new Error(
|
|
55
|
+
throw new Error('auth must be an array of base64 strings');
|
|
56
56
|
}
|
|
57
|
-
auth = params.auth.map((a) => stellar_sdk_1.xdr.SorobanAuthorizationEntry.fromXDR(a,
|
|
57
|
+
auth = params.auth.map((a) => stellar_sdk_1.xdr.SorobanAuthorizationEntry.fromXDR(a, 'base64'));
|
|
58
58
|
}
|
|
59
59
|
catch (e) {
|
|
60
|
-
throw (0, relayer_sdk_1.pluginError)(
|
|
61
|
-
code:
|
|
60
|
+
throw (0, relayer_sdk_1.pluginError)('Invalid `func` or `auth` encoding', {
|
|
61
|
+
code: 'INVALID_PARAMS',
|
|
62
62
|
status: constants_1.HTTP_STATUS.BAD_REQUEST,
|
|
63
63
|
details: { message: e instanceof Error ? e.message : String(e) },
|
|
64
64
|
});
|
|
@@ -66,19 +66,18 @@ function validateAndParseRequest(params) {
|
|
|
66
66
|
// Reject SourceAccount credentials: incompatible with relayer-managed channel source
|
|
67
67
|
for (const entry of auth) {
|
|
68
68
|
const credType = entry.credentials().switch();
|
|
69
|
-
if (credType ===
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
code: "INVALID_PARAMS",
|
|
69
|
+
if (credType === stellar_sdk_1.xdr.SorobanCredentialsType.sorobanCredentialsSourceAccount()) {
|
|
70
|
+
throw (0, relayer_sdk_1.pluginError)('Detached address credentials required: source-account credentials are incompatible with relayer-managed channel accounts', {
|
|
71
|
+
code: 'INVALID_PARAMS',
|
|
73
72
|
status: constants_1.HTTP_STATUS.BAD_REQUEST,
|
|
74
|
-
details: { reason:
|
|
73
|
+
details: { reason: 'source-account credentials not allowed' },
|
|
75
74
|
});
|
|
76
75
|
}
|
|
77
76
|
}
|
|
78
|
-
return { type:
|
|
77
|
+
return { type: 'func-auth', func, auth };
|
|
79
78
|
}
|
|
80
|
-
throw (0, relayer_sdk_1.pluginError)(
|
|
81
|
-
code:
|
|
79
|
+
throw (0, relayer_sdk_1.pluginError)('Must pass either `xdr` or `func` and `auth`', {
|
|
80
|
+
code: 'INVALID_PARAMS',
|
|
82
81
|
status: constants_1.HTTP_STATUS.BAD_REQUEST,
|
|
83
82
|
});
|
|
84
83
|
}
|