@bitpay-labs/crypto-wallet-core 11.10.9 → 11.10.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.
Files changed (47) hide show
  1. package/package.json +6 -6
  2. package/src/transactions/bch/index.ts +12 -12
  3. package/src/transactions/btc/index.ts +140 -51
  4. package/src/transactions/doge/index.ts +12 -12
  5. package/src/transactions/eth/index.ts +9 -0
  6. package/src/transactions/ltc/index.ts +12 -12
  7. package/src/transactions/sol/index.ts +14 -0
  8. package/src/transactions/xrp/index.ts +9 -0
  9. package/src/utils/index.ts +9 -0
  10. package/test/transactions.test.ts +215 -2
  11. package/test/utils.test.ts +39 -0
  12. package/ts_build/src/transactions/bch/index.d.ts +11 -8
  13. package/ts_build/src/transactions/bch/index.d.ts.map +1 -1
  14. package/ts_build/src/transactions/bch/index.js +5 -11
  15. package/ts_build/src/transactions/bch/index.js.map +1 -1
  16. package/ts_build/src/transactions/btc/index.d.ts +66 -47
  17. package/ts_build/src/transactions/btc/index.d.ts.map +1 -1
  18. package/ts_build/src/transactions/btc/index.js +46 -34
  19. package/ts_build/src/transactions/btc/index.js.map +1 -1
  20. package/ts_build/src/transactions/doge/index.d.ts +11 -8
  21. package/ts_build/src/transactions/doge/index.d.ts.map +1 -1
  22. package/ts_build/src/transactions/doge/index.js +5 -11
  23. package/ts_build/src/transactions/doge/index.js.map +1 -1
  24. package/ts_build/src/transactions/eth/index.d.ts +3 -0
  25. package/ts_build/src/transactions/eth/index.d.ts.map +1 -1
  26. package/ts_build/src/transactions/eth/index.js +4 -0
  27. package/ts_build/src/transactions/eth/index.js.map +1 -1
  28. package/ts_build/src/transactions/ltc/index.d.ts +11 -8
  29. package/ts_build/src/transactions/ltc/index.d.ts.map +1 -1
  30. package/ts_build/src/transactions/ltc/index.js +5 -11
  31. package/ts_build/src/transactions/ltc/index.js.map +1 -1
  32. package/ts_build/src/transactions/sol/index.d.ts +3 -0
  33. package/ts_build/src/transactions/sol/index.d.ts.map +1 -1
  34. package/ts_build/src/transactions/sol/index.js +5 -0
  35. package/ts_build/src/transactions/sol/index.js.map +1 -1
  36. package/ts_build/src/transactions/xrp/index.d.ts +4 -1
  37. package/ts_build/src/transactions/xrp/index.d.ts.map +1 -1
  38. package/ts_build/src/transactions/xrp/index.js +4 -0
  39. package/ts_build/src/transactions/xrp/index.js.map +1 -1
  40. package/ts_build/src/utils/index.d.ts +1 -0
  41. package/ts_build/src/utils/index.d.ts.map +1 -1
  42. package/ts_build/src/utils/index.js +11 -0
  43. package/ts_build/src/utils/index.js.map +1 -1
  44. package/ts_build/test/transactions.test.js +198 -0
  45. package/ts_build/test/transactions.test.js.map +1 -1
  46. package/ts_build/test/utils.test.js +33 -0
  47. package/ts_build/test/utils.test.js.map +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bitpay-labs/crypto-wallet-core",
3
- "version": "11.10.9",
3
+ "version": "11.10.12",
4
4
  "description": "A multi-currency support library for address derivation, private key creation, and transaction creation",
5
5
  "main": "./ts_build/src/index.js",
6
6
  "types": "./ts_build/src/index.d.ts",
@@ -28,10 +28,10 @@
28
28
  "author": "Micah Riggan",
29
29
  "license": "MIT",
30
30
  "dependencies": {
31
- "@bitpay-labs/bitcore-lib": "^11.10.9",
32
- "@bitpay-labs/bitcore-lib-cash": "^11.10.9",
33
- "@bitpay-labs/bitcore-lib-doge": "^11.10.9",
34
- "@bitpay-labs/bitcore-lib-ltc": "^11.10.9",
31
+ "@bitpay-labs/bitcore-lib": "^11.10.12",
32
+ "@bitpay-labs/bitcore-lib-cash": "^11.10.12",
33
+ "@bitpay-labs/bitcore-lib-doge": "^11.10.12",
34
+ "@bitpay-labs/bitcore-lib-ltc": "^11.10.12",
35
35
  "@solana-program/compute-budget": "0.7.0",
36
36
  "@solana-program/memo": "0.7.0",
37
37
  "@solana-program/system": "0.7.0",
@@ -51,5 +51,5 @@
51
51
  "chai": "5.1.2",
52
52
  "typescript": "5.7.3"
53
53
  },
54
- "gitHead": "9fa63bb66aeab5024220c14c428345f8ae946f7c"
54
+ "gitHead": "d1992fd744501a1b69b8cb97f07b0896df7223fd"
55
55
  }
@@ -1,24 +1,24 @@
1
1
  import BitcoreLibCash from '@bitpay-labs/bitcore-lib-cash';
2
- import { BTCTxProvider } from '../btc';
2
+ import { BTCTxProvider, EveryUtxoType } from '../btc';
3
3
 
4
4
  export class BCHTxProvider extends BTCTxProvider {
5
5
  lib = BitcoreLibCash;
6
- create({ recipients, utxos = [], change, fee = 20000, isSweep }) {
7
- const filteredUtxos = isSweep ? utxos : this.selectCoins(recipients, utxos, fee);
8
- const btcUtxos = filteredUtxos.map(utxo => {
9
- const btcUtxo = Object.assign({}, utxo, {
10
- amount: utxo.value / 1e8,
11
- txid: utxo.mintTxid,
12
- outputIndex: utxo.mintIndex
13
- });
14
- return new this.lib.Transaction.UnspentOutput(btcUtxo);
15
- });
6
+ create(params: {
7
+ recipients: Array<{ address: string; amount: number | string }>;
8
+ utxos?: EveryUtxoType[];
9
+ change?: string;
10
+ fee?: number | string;
11
+ isSweep?: boolean;
12
+ }): string {
13
+ const { recipients, utxos = [], change, fee = 20000, isSweep } = params;
14
+ const filteredUtxos = isSweep ? utxos : this.selectCoins(recipients, utxos, Number(fee));
15
+ const btcUtxos = filteredUtxos.map(utxo => this.standardizeUtxo(utxo));
16
16
  const tx = new this.lib.Transaction().from(btcUtxos).feePerByte(Number(fee) + 2);
17
17
  if (change) {
18
18
  tx.change(change);
19
19
  }
20
20
  for (const recipient of recipients) {
21
- tx.to(recipient.address, parseInt(recipient.amount));
21
+ tx.to(recipient.address, Number(recipient.amount));
22
22
  }
23
23
  return tx.uncheckedSerialize();
24
24
  }
@@ -15,42 +15,71 @@ export class BTCTxProvider {
15
15
  lib = BitcoreLib;
16
16
 
17
17
  selectCoins(
18
- recipients: Array<{ amount: number }>,
19
- utxos: Array<{
20
- value: number;
21
- mintHeight: number;
22
- txid?: string;
23
- mintTxid?: string;
24
- mintIndex?: number;
25
- }>,
26
- fee: number
27
- ) {
28
- utxos = utxos.sort(function(a, b) {
29
- return a.mintHeight - b.mintHeight;
30
- });
18
+ recipients: Array<{ amount: number | string }>,
19
+ utxos: EveryUtxoType[],
20
+ fee?: number
21
+ ): EveryUtxoType[] {
22
+ // Only sort by block height if utxos are bitcore-node style
23
+ if (utxos.length > 0 && utxos.every(utxo => utxo.mintHeight != undefined)) {
24
+ utxos = utxos.sort(function(a, b) {
25
+ return a.mintHeight - b.mintHeight;
26
+ });
27
+ }
31
28
 
32
29
  let index = 0;
33
30
  let utxoSum = 0;
34
31
  const recepientSum = recipients.reduce((sum, cur) => sum + Number(cur.amount), fee || 0);
35
32
  while (utxoSum < recepientSum) {
33
+ assert(index < utxos.length, 'insufficient funds');
36
34
  const utxo = utxos[index];
37
- utxoSum += Number(utxo.value);
35
+ utxoSum += Number(utxo.satoshis ?? utxo.value ?? this.lib.Unit.fromBTC(utxo.amount ?? 0).toSatoshis());
38
36
  index += 1;
39
37
  }
40
38
  const filteredUtxos = utxos.slice(0, index);
41
39
  return filteredUtxos;
42
40
  }
43
41
 
44
- create({ recipients, utxos = [], change, feeRate, fee, isSweep, replaceByFee, lockUntilDate, lockUntilBlock }) {
45
- const filteredUtxos = isSweep ? utxos : this.selectCoins(recipients, utxos, fee);
46
- const btcUtxos = filteredUtxos.map(utxo => {
47
- const btcUtxo = Object.assign({}, utxo, {
48
- amount: utxo.value / 1e8,
49
- txid: utxo.mintTxid,
50
- outputIndex: utxo.mintIndex
51
- });
52
- return new this.lib.Transaction.UnspentOutput(btcUtxo);
53
- });
42
+ /**
43
+ * Standardize utxo for internal functionality.
44
+ * Accepts either a bitcore-node or a lib (bitcore-lib, bitcore-lib-cash, etc.) utxo.
45
+ * Handles both lib style utxos: UnspentOutput properties and UnspentOutput.toObject properties.
46
+ *
47
+ * @param utxo either a bitcore-node or lib utxo
48
+ * @returns utxo in the standard, internally used format
49
+ */
50
+ standardizeUtxo(utxo: EveryUtxoType): UtxoType {
51
+ const outputIndex = utxo.outputIndex ?? utxo.mintIndex ?? utxo.vout;
52
+ const satoshis = utxo.satoshis ?? utxo.value ?? (utxo.amount != undefined ? this.lib.Unit.fromBTC(utxo.amount ?? 0).toSatoshis() : undefined);
53
+ const txId = utxo.txId ?? utxo.mintTxid ?? utxo.txid;
54
+ const script = utxo.script ?? utxo.scriptPubKey;
55
+ $.checkArgument(outputIndex != undefined, 'output index required (outputIndex|mintIndex|vout)');
56
+ $.checkArgument(satoshis != undefined, 'satoshis required (satoshis|value|amount)');
57
+ $.checkArgument(txId, 'txid required (txid|txId|mintTxid)');
58
+ $.checkArgument(script || utxo.address, 'script or address required (script|scriptPubKey|address)');
59
+
60
+ return {
61
+ satoshis: Number(satoshis),
62
+ txId,
63
+ outputIndex: Number(outputIndex),
64
+ script: script != undefined ? new this.lib.Script(script).toHex() : undefined,
65
+ address: utxo.address != undefined ? new this.lib.Address(utxo.address).toString() : undefined
66
+ };
67
+ }
68
+
69
+ create(params: {
70
+ recipients: Array<{ address: string; amount: number | string }>;
71
+ utxos?: EveryUtxoType[];
72
+ change?: string;
73
+ feeRate?: number | string;
74
+ fee?: number | string;
75
+ isSweep?: boolean;
76
+ replaceByFee?: boolean;
77
+ lockUntilDate?: number;
78
+ lockUntilBlock?: number;
79
+ }): string {
80
+ const { recipients, utxos = [], change, feeRate, fee, isSweep, replaceByFee, lockUntilDate, lockUntilBlock } = params;
81
+ const filteredUtxos = isSweep ? utxos : this.selectCoins(recipients, utxos, Number(fee));
82
+ const btcUtxos = filteredUtxos.map(utxo => this.standardizeUtxo(utxo));
54
83
  const tx = new this.lib.Transaction().from(btcUtxos);
55
84
  if (fee) {
56
85
  tx.fee(fee);
@@ -62,7 +91,7 @@ export class BTCTxProvider {
62
91
  tx.change(change);
63
92
  }
64
93
  for (const recipient of recipients) {
65
- tx.to(recipient.address, parseInt(recipient.amount));
94
+ tx.to(recipient.address, Number(recipient.amount));
66
95
  }
67
96
  if (replaceByFee && typeof tx.enableRBF === 'function') {
68
97
  tx.enableRBF();
@@ -79,7 +108,7 @@ export class BTCTxProvider {
79
108
  throw new Error('function getSignature not implemented for UTXO coins');
80
109
  }
81
110
 
82
- transformSignatureObject(params: { obj: any; sigtype?: number }) {
111
+ transformSignatureObject(params: { obj: any; sigtype?: number }): string {
83
112
  const { obj, sigtype } = params;
84
113
  const { v } = obj;
85
114
  let { r, s, i, nhashtype } = obj;
@@ -107,7 +136,12 @@ export class BTCTxProvider {
107
136
  return new this.lib.crypto.Signature({ r, s, i, nhashtype }).toString();
108
137
  }
109
138
 
110
- applySignature(params: { tx: BitcoreLib.Transaction; signature: SignatureType; index: number; sigtype?: number }) {
139
+ applySignature(params: {
140
+ tx: BitcoreLib.Transaction;
141
+ signature: SignatureType;
142
+ index: number;
143
+ sigtype?: number;
144
+ }): BitcoreLib.Transaction {
111
145
  const { index, sigtype, tx } = params;
112
146
  let { signature } = params;
113
147
  assert(tx instanceof this.lib.Transaction, 'tx must be an instance of Transaction');
@@ -128,63 +162,77 @@ export class BTCTxProvider {
128
162
  return tx;
129
163
  }
130
164
 
131
- getHash(params: { tx: string }) {
165
+ getHash(params: { tx: TransactionType }): string {
132
166
  const bitcoreTx = new this.lib.Transaction(params.tx);
133
167
  return bitcoreTx.hash;
134
168
  }
135
169
 
136
- sign(params: { tx: string; keys: Array<Key>; utxos: any[]; pubkeys?: any[]; threshold?: number; opts: any }) {
137
- const { tx, keys, pubkeys, threshold, opts } = params;
170
+ sign(params: {
171
+ tx: TransactionType;
172
+ keys: Key[];
173
+ utxos: EveryUtxoType[];
174
+ sigtype?: number;
175
+ pubkeys?: any[];
176
+ threshold?: number;
177
+ opts?: any;
178
+ }): string {
179
+ const { tx, keys, pubkeys, sigtype, threshold, opts } = params;
180
+ $.checkArgument(keys.every(k => !!k.privKey), 'Keys must contain private key data for signing');
181
+
138
182
  const utxos = params.utxos || [];
139
183
  const bitcoreTx = new this.lib.Transaction(tx);
184
+ const btcUtxos = utxos.map(utxo => this.standardizeUtxo(utxo));
140
185
  const applicableUtxos = this.getRelatedUtxos({
141
186
  outputs: bitcoreTx.inputs,
142
- utxos
187
+ utxos: btcUtxos
143
188
  });
144
- bitcoreTx.associateInputs(applicableUtxos, pubkeys, threshold, opts);
189
+ bitcoreTx.associateInputs(applicableUtxos.map(utxo => new this.lib.Transaction.UnspentOutput(utxo)), pubkeys, threshold, opts);
145
190
  const uniqePrivKeys = Object.values(keys.reduce((map, key) => {
146
191
  // Need to preserve (un)compressed property, so don't use key.privKey.toString();
147
192
  const pk = new this.lib.PrivateKey(key.privKey);
148
193
  map[pk.publicKey.toString()] = pk;
149
194
  return map;
150
195
  }, {}));
151
- const signedTx = bitcoreTx.sign(uniqePrivKeys).toString();
196
+ const signedTx = bitcoreTx.sign(uniqePrivKeys, sigtype).toString();
152
197
  return signedTx;
153
198
  }
154
199
 
155
- getRelatedUtxos({ outputs, utxos }) {
200
+ getRelatedUtxos(params: {
201
+ outputs: BitcoreLib.Transaction.Input[];
202
+ utxos: UtxoType[];
203
+ }): UtxoType[] {
204
+ const { outputs, utxos } = params;
156
205
  const txids = outputs.map(output => output.toObject().prevTxId);
157
- const applicableUtxos = utxos.filter(utxo => txids.includes(utxo.txid || utxo.mintTxid));
158
- return applicableUtxos.map(utxo => {
159
- const btcUtxo = Object.assign({}, utxo, {
160
- amount: utxo.value / Math.pow(10, 8),
161
- txid: utxo.mintTxid,
162
- outputIndex: utxo.mintIndex
163
- });
164
- return new this.lib.Transaction.UnspentOutput(btcUtxo);
165
- });
206
+ return utxos.filter(utxo => txids.includes(utxo.txId));
166
207
  }
167
208
 
168
- getOutputsFromTx({ tx }) {
169
- return tx.outputs.map(({ script, satoshis }) => {
209
+ getOutputsFromTx(params: {
210
+ tx: BitcoreLib.Transaction;
211
+ }): Array<{ address: string | BitcoreLib.Script; satoshis: number }> {
212
+ return params.tx.outputs.map(({ script, satoshis }) => {
170
213
  const address = script;
171
214
  return { address, satoshis };
172
215
  });
173
216
  }
174
217
 
175
- getSigningAddresses({ tx, utxos }): string[] {
218
+ getSigningAddresses(params: {
219
+ tx: TransactionType;
220
+ utxos: EveryUtxoType[];
221
+ }): (string | undefined)[] {
222
+ const { tx, utxos } = params;
176
223
  const bitcoreTx = new this.lib.Transaction(tx);
224
+ const btcUtxos = utxos.map(utxo => this.standardizeUtxo(utxo));
177
225
  const applicableUtxos = this.getRelatedUtxos({
178
226
  outputs: bitcoreTx.inputs,
179
- utxos
227
+ utxos: btcUtxos
180
228
  });
181
229
  return applicableUtxos.map(utxo => utxo.address);
182
230
  }
183
231
 
184
232
  getSighash(params: {
185
- tx: string | BitcoreLib.Transaction;
233
+ tx: TransactionType;
186
234
  index: number;
187
- utxos?: BitcoreLib.Transaction.UnspentOutput[];
235
+ utxos?: EveryUtxoType[];
188
236
  pubKey?: string | BitcoreLib.PublicKey | BitcoreLib.HDPublicKey;
189
237
  path?: string;
190
238
  sigtype?: number;
@@ -204,7 +252,8 @@ export class BTCTxProvider {
204
252
  tx = new this.lib.Transaction(tx);
205
253
  }
206
254
  if (utxos) {
207
- tx.associateInputs(utxos.map(this.lib.Transaction.UnspentOutput), pubKeys, threshold, opts);
255
+ const btcUtxos = utxos.map(utxo => this.standardizeUtxo(utxo));
256
+ tx.associateInputs(btcUtxos.map(utxo => new this.lib.Transaction.UnspentOutput(utxo)), pubKeys, threshold, opts);
208
257
  }
209
258
  $.checkState(tx.inputs[index].output instanceof this.lib.Transaction.Output, 'Input must have all utxo info');
210
259
 
@@ -224,4 +273,44 @@ export class BTCTxProvider {
224
273
  }
225
274
  }
226
275
 
227
- type SignatureType = BitcoreLib.Transaction.Signature | BitcoreLib.crypto.Signature | TssSig;
276
+ type SignatureType = BitcoreLib.Transaction.Signature | BitcoreLib.crypto.Signature | TssSig;
277
+
278
+ /** Transaction data that can be converted into a Transaction via Transaction(tx) */
279
+ type TransactionType = BitcoreLib.Transaction | string | Buffer | object;
280
+
281
+ /**
282
+ * Standard utxo type used for internal processing.
283
+ * Property names are from bitcore-lib's UnspentOutput.
284
+ * Note, UnspentOutput addresses and scripts are Address and Script classes respectively,
285
+ * here they are both strings.
286
+ */
287
+ export type UtxoType = {
288
+ txId: string;
289
+ outputIndex: number;
290
+ satoshis: number;
291
+ script?: string;
292
+ address?: string;
293
+ };
294
+
295
+ /**
296
+ * Utxo type for functions where the received utxo type is unknown.
297
+ * Could either be in the format of UnspentOutput, UnspentOutput.toObject, or from bitcore-node.
298
+ */
299
+ export type EveryUtxoType = Partial<{
300
+ // UnspentOutput properties
301
+ txId: string;
302
+ outputIndex: number | string;
303
+ satoshis: number | string;
304
+ script: string | BitcoreLib.Script;
305
+ address: string | BitcoreLib.Address;
306
+ // bitcore-node specific properties
307
+ mintTxid: string;
308
+ mintIndex: number;
309
+ mintHeight: number;
310
+ value: number;
311
+ // UnspentOutput.toObject specific properties
312
+ txid: string;
313
+ amount: number;
314
+ vout: number;
315
+ scriptPubKey: string;
316
+ }>;
@@ -1,18 +1,18 @@
1
1
  import BitcoreLibDoge from '@bitpay-labs/bitcore-lib-doge';
2
- import { BTCTxProvider } from '../btc';
2
+ import { BTCTxProvider, EveryUtxoType } from '../btc';
3
3
 
4
4
  export class DOGETxProvider extends BTCTxProvider {
5
5
  lib = BitcoreLibDoge;
6
- create({ recipients, utxos = [], change, feeRate, fee = 20000 }) {
7
- const filteredUtxos = this.selectCoins(recipients, utxos, fee);
8
- const btcUtxos = filteredUtxos.map(utxo => {
9
- const btcUtxo = Object.assign({}, utxo, {
10
- amount: utxo.value / 1e8,
11
- txid: utxo.mintTxid,
12
- outputIndex: utxo.mintIndex
13
- });
14
- return new this.lib.Transaction.UnspentOutput(btcUtxo);
15
- });
6
+ create(params: {
7
+ recipients: Array<{ address: string; amount: number | string }>;
8
+ utxos?: EveryUtxoType[];
9
+ change?: string;
10
+ feeRate?: number | string;
11
+ fee?: number | string;
12
+ }): string {
13
+ const { recipients, utxos = [], change, feeRate, fee = 20000 } = params;
14
+ const filteredUtxos = this.selectCoins(recipients, utxos, Number(fee));
15
+ const btcUtxos = filteredUtxos.map(utxo => this.standardizeUtxo(utxo));
16
16
  const tx = new this.lib.Transaction().from(btcUtxos);
17
17
  if (fee) {
18
18
  tx.fee(fee);
@@ -24,7 +24,7 @@ export class DOGETxProvider extends BTCTxProvider {
24
24
  tx.change(change);
25
25
  }
26
26
  for (const recipient of recipients) {
27
- tx.to(recipient.address, parseInt(recipient.amount));
27
+ tx.to(recipient.address, Number(recipient.amount));
28
28
  }
29
29
  return tx.uncheckedSerialize();
30
30
  }
@@ -127,6 +127,15 @@ export class ETHTxProvider {
127
127
  return ethers.Transaction.from(tx).hash;
128
128
  }
129
129
 
130
+ /**
131
+ * Reads the fields BWS may mutate between proposal creation and publish out of a raw tx, to bind
132
+ * txp.prePublishRaw to the proposal. For EVM that is only the account nonce (deferred-nonce proposals).
133
+ */
134
+ getMutableFields(rawTx: string): { nonce?: number } {
135
+ const parsed = ethers.Transaction.from(rawTx);
136
+ return { nonce: parsed.nonce != null ? Number(parsed.nonce) : undefined };
137
+ }
138
+
130
139
  applySignature(params: { tx: string; signature: any }) {
131
140
  const { tx, signature } = params;
132
141
  const parsedTx = ethers.Transaction.from(tx);
@@ -1,18 +1,18 @@
1
1
  import BitcoreLibLtc from '@bitpay-labs/bitcore-lib-ltc';
2
- import { BTCTxProvider } from '../btc';
2
+ import { BTCTxProvider, EveryUtxoType } from '../btc';
3
3
 
4
4
  export class LTCTxProvider extends BTCTxProvider {
5
5
  lib = BitcoreLibLtc;
6
- create({ recipients, utxos = [], change, feeRate, fee = 20000 }) {
7
- const filteredUtxos = this.selectCoins(recipients, utxos, fee);
8
- const btcUtxos = filteredUtxos.map(utxo => {
9
- const btcUtxo = Object.assign({}, utxo, {
10
- amount: utxo.value / 1e8,
11
- txid: utxo.mintTxid,
12
- outputIndex: utxo.mintIndex
13
- });
14
- return new this.lib.Transaction.UnspentOutput(btcUtxo);
15
- });
6
+ create(params: {
7
+ recipients: Array<{ address: string; amount: number | string }>;
8
+ utxos?: EveryUtxoType[];
9
+ change?: string;
10
+ feeRate?: number | string;
11
+ fee?: number | string;
12
+ }): string {
13
+ const { recipients, utxos = [], change, feeRate, fee = 20000 } = params;
14
+ const filteredUtxos = this.selectCoins(recipients, utxos, Number(fee));
15
+ const btcUtxos = filteredUtxos.map(utxo => this.standardizeUtxo(utxo));
16
16
  const tx = new this.lib.Transaction().from(btcUtxos);
17
17
  if (fee) {
18
18
  tx.fee(fee);
@@ -24,7 +24,7 @@ export class LTCTxProvider extends BTCTxProvider {
24
24
  tx.change(change);
25
25
  }
26
26
  for (const recipient of recipients) {
27
- tx.to(recipient.address, parseInt(recipient.amount));
27
+ tx.to(recipient.address, Number(recipient.amount));
28
28
  }
29
29
  return tx.uncheckedSerialize();
30
30
  }
@@ -180,6 +180,20 @@ export class SOLTxProvider {
180
180
  return SolKit.decompileTransactionMessage(compiledTransactionMessage);
181
181
  }
182
182
 
183
+ /**
184
+ * Reads the fields BWS may mutate between proposal creation and publish out of a raw tx, to bind
185
+ * txp.prePublishRaw to the proposal. For Solana that is the recent blockhash (refreshOnPublish), which is
186
+ * the compiled message's `lifetimeToken`. We decode only the compiled message (never decompile) so this
187
+ * stays safe for txs using Address Lookup Tables -- decompilation would need the on-chain table accounts,
188
+ * which a client-side lib cannot fetch. lastValidBlockHeight is not on the wire and does not affect
189
+ * serialization, so it is intentionally not recovered.
190
+ */
191
+ getMutableFields(rawTx: string): { blockHash?: string } {
192
+ const decoded: any = this.decodeRawTransaction({ rawTx, decodeTransactionMessage: false });
193
+ const compiled: any = SolKit.getCompiledTransactionMessageDecoder().decode(decoded.messageBytes);
194
+ return { blockHash: compiled?.lifetimeToken };
195
+ }
196
+
183
197
  async sign(params: { tx: string; key: Key }): Promise<string> {
184
198
  const { tx, key } = params;
185
199
  const decodedTx = this.decodeRawTransaction({ rawTx: tx, decodeTransactionMessage: false });
@@ -99,6 +99,15 @@ export class XRPTxProvider {
99
99
  return this.sha512Half(prefix + tx);
100
100
  }
101
101
 
102
+ /**
103
+ * Reads the fields BWS may mutate between proposal creation and publish out of a raw tx, to bind
104
+ * txp.prePublishRaw to the proposal. For XRP that is only the account sequence/nonce (deferred-nonce).
105
+ */
106
+ getMutableFields(rawTx: string): { nonce?: number } {
107
+ const txJSON = (xrpl.decode(rawTx) as any);
108
+ return { nonce: txJSON?.Sequence != null ? Number(txJSON.Sequence) : undefined };
109
+ }
110
+
102
111
  applySignature(params: { tx: string; signature: string; pubKey: string }): string {
103
112
  const { tx, signature, pubKey } = params;
104
113
  const txJSON = (xrpl.decode(tx) as any) as xrpl.Transaction;
@@ -176,4 +176,13 @@ export function normalizeXrpFlag(flag: string | number, flagEnum?: typeof xrpl.A
176
176
  throw new Error(`Invalid XRP flag: ${flag}. Flag is not in enum ${enumName}`);
177
177
  }
178
178
  return normalizedFlag;
179
+ }
180
+
181
+ export function tryParse(json: unknown, fallback?: any) {
182
+ try {
183
+ if (typeof json !== 'string') return json; // already parsed
184
+ return JSON.parse(json);
185
+ } catch {
186
+ return fallback;
187
+ }
179
188
  }