@openzeppelin/relayer-plugin-channels 0.19.0 → 0.21.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.
@@ -1,101 +0,0 @@
1
- "use strict";
2
- /**
3
- * build.ts
4
- *
5
- * Transaction rebuild logic to use channel account as source.
6
- */
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.rebuildWithChannel = rebuildWithChannel;
9
- const stellar_sdk_1 = require("@stellar/stellar-sdk");
10
- const relayer_sdk_1 = require("@openzeppelin/relayer-sdk");
11
- const constants_1 = require("./constants");
12
- /**
13
- * Rebuild transaction with channel account as source
14
- * - Set transaction source to channel account with current sequence
15
- * - Preserve memo, timeBounds, etc.
16
- * - Copy operations ensuring their source equals the fund address
17
- */
18
- function rebuildWithChannel(params) {
19
- const { inputXdr, channelAddress, channelSequence, fundAddress, networkPassphrase } = params;
20
- // Parse input transaction
21
- let inputTx;
22
- try {
23
- const envelope = stellar_sdk_1.xdr.TransactionEnvelope.fromXDR(inputXdr, 'base64');
24
- // Ensure it's a regular transaction envelope (not fee bump)
25
- if (envelope.switch() !== stellar_sdk_1.xdr.EnvelopeType.envelopeTypeTx()) {
26
- throw (0, relayer_sdk_1.pluginError)('Input must be a regular transaction envelope (not fee bump)', {
27
- code: 'INVALID_ENVELOPE_TYPE',
28
- status: constants_1.HTTP_STATUS.BAD_REQUEST,
29
- });
30
- }
31
- inputTx = new stellar_sdk_1.Transaction(envelope, networkPassphrase);
32
- }
33
- catch (error) {
34
- if (error.code === 'INVALID_ENVELOPE_TYPE') {
35
- throw error;
36
- }
37
- throw (0, relayer_sdk_1.pluginError)('Failed to parse input transaction XDR', {
38
- code: 'INVALID_XDR',
39
- status: constants_1.HTTP_STATUS.BAD_REQUEST,
40
- details: { message: error instanceof Error ? error.message : String(error) },
41
- });
42
- }
43
- // Validate timeBounds
44
- if (inputTx.timeBounds) {
45
- const now = Math.floor(Date.now() / 1000);
46
- const maxTime = Number(inputTx.timeBounds.maxTime);
47
- if (maxTime > 0) {
48
- if (maxTime < now) {
49
- throw (0, relayer_sdk_1.pluginError)('Transaction has expired: maxTime is in the past', {
50
- code: 'TIMEBOUNDS_EXPIRED',
51
- status: constants_1.HTTP_STATUS.BAD_REQUEST,
52
- details: { maxTime, now },
53
- });
54
- }
55
- const maxAllowedTime = now + constants_1.TIME.MAX_TIME_BOUND_OFFSET_SECONDS;
56
- if (maxTime > maxAllowedTime) {
57
- throw (0, relayer_sdk_1.pluginError)(`Transaction maxTime is too far in the future. Max allowed: ${constants_1.TIME.MAX_TIME_BOUND_OFFSET_SECONDS} seconds from now`, {
58
- code: 'INVALID_TIME_BOUNDS',
59
- status: constants_1.HTTP_STATUS.BAD_REQUEST,
60
- details: { maxTime, maxAllowedTime },
61
- });
62
- }
63
- }
64
- }
65
- // Validate operations: all operation sources must be fund address or missing
66
- for (let i = 0; i < inputTx.operations.length; i++) {
67
- const op = inputTx.operations[i];
68
- if (op.source && op.source !== fundAddress) {
69
- throw (0, relayer_sdk_1.pluginError)(`Operation ${i} has source ${op.source} but must be ${fundAddress} or omitted`, {
70
- code: 'INVALID_OPERATION_SOURCE',
71
- status: constants_1.HTTP_STATUS.BAD_REQUEST,
72
- details: { operationIndex: i, operationSource: op.source, expectedSource: fundAddress },
73
- });
74
- }
75
- }
76
- // Manipulate the transaction envelope XDR directly to change source and sequence
77
- // This is the most reliable approach that preserves all transaction details
78
- const envelope = inputTx.toEnvelope();
79
- const txBody = envelope.v1().tx();
80
- // Update source account to channel address
81
- const channelAccountId = stellar_sdk_1.StrKey.decodeEd25519PublicKey(channelAddress);
82
- const channelMuxed = stellar_sdk_1.xdr.MuxedAccount.keyTypeEd25519(channelAccountId);
83
- txBody.sourceAccount(channelMuxed);
84
- // Update sequence number
85
- // Sequence numbers in Stellar are represented as Int64 in XDR
86
- const seqNum = stellar_sdk_1.xdr.Int64.fromString(channelSequence);
87
- txBody.seqNum(seqNum);
88
- // Update operation sources to fund address if not set
89
- const fundAccountId = stellar_sdk_1.StrKey.decodeEd25519PublicKey(fundAddress);
90
- const fundMuxed = stellar_sdk_1.xdr.MuxedAccount.keyTypeEd25519(fundAccountId);
91
- const operations = txBody.operations();
92
- for (let i = 0; i < operations.length; i++) {
93
- const op = operations[i];
94
- // If operation doesn't have a source, set it to fund address
95
- if (!op.sourceAccount()) {
96
- op.sourceAccount(fundMuxed);
97
- }
98
- }
99
- // Create new transaction from modified envelope
100
- return new stellar_sdk_1.Transaction(envelope, networkPassphrase);
101
- }