@altiuslabs/tx-sdk 0.1.11 → 0.1.12
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/package.json +1 -2
- package/src/transaction.js +29 -25
- package/src/utils.js +43 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@altiuslabs/tx-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
4
4
|
"description": "SDK for signing and sending Altius USD multi-token transactions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -19,7 +19,6 @@
|
|
|
19
19
|
"signer"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@altiuslabs/tx-sdk": "^0.1.10",
|
|
23
22
|
"js-sha3": "^0.9.3",
|
|
24
23
|
"noble-secp256k1": "^1.2.14",
|
|
25
24
|
"rlp": "^3.0.0"
|
package/src/transaction.js
CHANGED
|
@@ -180,27 +180,30 @@ export class TxBuilder {
|
|
|
180
180
|
signature_hash() {
|
|
181
181
|
const tx = this.build();
|
|
182
182
|
|
|
183
|
-
// For 0x7a transaction,
|
|
184
|
-
// [chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value,
|
|
183
|
+
// For 0x7a transaction, encode fields WITHOUT fee_payer_signature (matches node's encode_for_signing)
|
|
184
|
+
// Format: [chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, input, accessList, feeToken, feePayer, maxFeePerGasUsdAttodollars]
|
|
185
185
|
const list = [
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
186
|
+
tx.chain_id,
|
|
187
|
+
tx.nonce,
|
|
188
|
+
tx.max_priority_fee_per_gas,
|
|
189
|
+
tx.max_fee_per_gas,
|
|
190
|
+
tx.gas_limit,
|
|
191
191
|
tx.to,
|
|
192
|
-
|
|
192
|
+
tx.value,
|
|
193
193
|
tx.data,
|
|
194
194
|
// Empty access list
|
|
195
|
-
|
|
195
|
+
[],
|
|
196
196
|
tx.fee_token,
|
|
197
197
|
tx.fee_payer,
|
|
198
|
-
|
|
199
|
-
tx.fee_payer_signature,
|
|
198
|
+
tx.max_fee_per_gas_usd_attodollars,
|
|
200
199
|
];
|
|
201
200
|
|
|
201
|
+
// Encode with type byte 0x7a prefix (matches node's encode_for_signing)
|
|
202
|
+
const type_byte = '0x7a';
|
|
202
203
|
const encoded = rlp_encode(list);
|
|
203
|
-
|
|
204
|
+
const with_type = type_byte + encoded.slice(2);
|
|
205
|
+
|
|
206
|
+
return keccak256(with_type);
|
|
204
207
|
}
|
|
205
208
|
|
|
206
209
|
/**
|
|
@@ -218,22 +221,23 @@ export class TxBuilder {
|
|
|
218
221
|
const tx = this.build();
|
|
219
222
|
|
|
220
223
|
// Build signed transaction list (for EIP-2718 encoding)
|
|
224
|
+
// Format matches node's rlp_encode_fields: [chainId, nonce, ..., feePayerSignature, signature]
|
|
221
225
|
const signed_fields = [
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
226
|
+
tx.chain_id,
|
|
227
|
+
tx.nonce,
|
|
228
|
+
tx.max_priority_fee_per_gas,
|
|
229
|
+
tx.max_fee_per_gas,
|
|
230
|
+
tx.gas_limit,
|
|
227
231
|
tx.to,
|
|
228
|
-
|
|
232
|
+
tx.value,
|
|
229
233
|
tx.data,
|
|
230
|
-
|
|
234
|
+
[], // empty access list
|
|
231
235
|
tx.fee_token,
|
|
232
236
|
tx.fee_payer,
|
|
233
|
-
|
|
237
|
+
tx.max_fee_per_gas_usd_attodollars,
|
|
234
238
|
tx.fee_payer_signature,
|
|
235
239
|
// Signature: y_parity (1 byte), r (32 bytes), s (32 bytes)
|
|
236
|
-
|
|
240
|
+
y_parity,
|
|
237
241
|
sig.r,
|
|
238
242
|
sig.s,
|
|
239
243
|
];
|
|
@@ -281,12 +285,12 @@ export function fee_payer_signature_hash(tx, sender) {
|
|
|
281
285
|
// RLP encode the fields as a list
|
|
282
286
|
// [chain_id, nonce, gas_limit, fee_token, fee_payer, max_fee_per_gas_usd_attodollars, sender]
|
|
283
287
|
const list = [
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
288
|
+
tx.chain_id,
|
|
289
|
+
tx.nonce,
|
|
290
|
+
tx.gas_limit,
|
|
287
291
|
tx.fee_token,
|
|
288
292
|
tx.fee_payer,
|
|
289
|
-
|
|
293
|
+
tx.max_fee_per_gas_usd_attodollars,
|
|
290
294
|
sender,
|
|
291
295
|
];
|
|
292
296
|
|
package/src/utils.js
CHANGED
|
@@ -39,12 +39,53 @@ export function num_to_hex(num, bytes = 32) {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
|
-
*
|
|
42
|
+
* Convert a value to RLP-compatible Buffer
|
|
43
|
+
* @param {any} value - Value to convert
|
|
44
|
+
* @returns {Buffer} RLP-compatible buffer
|
|
45
|
+
*/
|
|
46
|
+
function toRlpBytes(value) {
|
|
47
|
+
if (Buffer.isBuffer(value)) {
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
if (typeof value === 'string') {
|
|
51
|
+
// Hex string
|
|
52
|
+
if (value.startsWith('0x')) {
|
|
53
|
+
return Buffer.from(value.slice(2), 'hex');
|
|
54
|
+
}
|
|
55
|
+
return Buffer.from(value);
|
|
56
|
+
}
|
|
57
|
+
if (typeof value === 'number' || typeof value === 'bigint') {
|
|
58
|
+
// Convert number/bigint to big-endian bytes
|
|
59
|
+
const bigIntValue = BigInt(value);
|
|
60
|
+
if (bigIntValue === 0n) {
|
|
61
|
+
return Buffer.from([]);
|
|
62
|
+
}
|
|
63
|
+
const hex = bigIntValue.toString(16);
|
|
64
|
+
// RLP encodes integers as big-endian without leading zeros (except for zero itself)
|
|
65
|
+
return Buffer.from(hex, 'hex');
|
|
66
|
+
}
|
|
67
|
+
if (Array.isArray(value)) {
|
|
68
|
+
// For empty arrays, return empty buffer
|
|
69
|
+
if (value.length === 0) {
|
|
70
|
+
return Buffer.from([]);
|
|
71
|
+
}
|
|
72
|
+
// Recursively encode array items
|
|
73
|
+
const encodedItems = value.map(item => toRlpBytes(item));
|
|
74
|
+
return Buffer.concat(encodedItems);
|
|
75
|
+
}
|
|
76
|
+
// Default: stringify
|
|
77
|
+
return Buffer.from(String(value));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* RLP encoding (for 0x7a transactions)
|
|
43
82
|
* @param {Array} items - Array of items to encode
|
|
44
83
|
* @returns {string} RLP encoded data as 0x-prefixed hex
|
|
45
84
|
*/
|
|
46
85
|
export function rlp_encode(items) {
|
|
47
|
-
|
|
86
|
+
// Convert all items to RLP-compatible buffers first
|
|
87
|
+
const buffers = items.map(item => toRlpBytes(item));
|
|
88
|
+
const encoded = RLP.encode(buffers);
|
|
48
89
|
return '0x' + Buffer.from(encoded).toString('hex');
|
|
49
90
|
}
|
|
50
91
|
|