@bitpay-labs/crypto-wallet-core 11.9.0 → 11.10.3

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 (62) hide show
  1. package/package.json +8 -9
  2. package/src/constants/chains.ts +6 -2
  3. package/src/constants/units.ts +11 -0
  4. package/src/derivation/index.ts +1 -0
  5. package/src/derivation/paths.ts +3 -0
  6. package/src/transactions/index.ts +2 -0
  7. package/src/transactions/spl/index.ts +2 -2
  8. package/src/transactions/xrp/index.ts +39 -10
  9. package/src/utils/index.ts +86 -1
  10. package/src/validation/arc/index.ts +8 -0
  11. package/src/validation/index.ts +2 -0
  12. package/test/address.test.ts +12 -0
  13. package/test/transactions.test.ts +114 -1
  14. package/test/utils.test.ts +296 -10
  15. package/test/validation.test.ts +21 -0
  16. package/ts_build/src/constants/chains.d.ts +5 -2
  17. package/ts_build/src/constants/chains.d.ts.map +1 -1
  18. package/ts_build/src/constants/chains.js +5 -2
  19. package/ts_build/src/constants/chains.js.map +1 -1
  20. package/ts_build/src/constants/index.d.ts +14 -1
  21. package/ts_build/src/constants/index.d.ts.map +1 -1
  22. package/ts_build/src/constants/units.d.ts +11 -0
  23. package/ts_build/src/constants/units.d.ts.map +1 -1
  24. package/ts_build/src/constants/units.js +11 -0
  25. package/ts_build/src/constants/units.js.map +1 -1
  26. package/ts_build/src/derivation/index.d.ts.map +1 -1
  27. package/ts_build/src/derivation/index.js +1 -0
  28. package/ts_build/src/derivation/index.js.map +1 -1
  29. package/ts_build/src/derivation/paths.d.ts +3 -0
  30. package/ts_build/src/derivation/paths.d.ts.map +1 -1
  31. package/ts_build/src/derivation/paths.js +3 -0
  32. package/ts_build/src/derivation/paths.js.map +1 -1
  33. package/ts_build/src/transactions/index.d.ts.map +1 -1
  34. package/ts_build/src/transactions/index.js +2 -0
  35. package/ts_build/src/transactions/index.js.map +1 -1
  36. package/ts_build/src/transactions/spl/index.d.ts +1 -1
  37. package/ts_build/src/transactions/spl/index.d.ts.map +1 -1
  38. package/ts_build/src/transactions/spl/index.js +1 -1
  39. package/ts_build/src/transactions/spl/index.js.map +1 -1
  40. package/ts_build/src/transactions/xrp/index.d.ts +3 -2
  41. package/ts_build/src/transactions/xrp/index.d.ts.map +1 -1
  42. package/ts_build/src/transactions/xrp/index.js +21 -7
  43. package/ts_build/src/transactions/xrp/index.js.map +1 -1
  44. package/ts_build/src/utils/index.d.ts +4 -0
  45. package/ts_build/src/utils/index.d.ts.map +1 -1
  46. package/ts_build/src/utils/index.js +88 -1
  47. package/ts_build/src/utils/index.js.map +1 -1
  48. package/ts_build/src/validation/arc/index.d.ts +5 -0
  49. package/ts_build/src/validation/arc/index.d.ts.map +1 -0
  50. package/ts_build/src/validation/arc/index.js +12 -0
  51. package/ts_build/src/validation/arc/index.js.map +1 -0
  52. package/ts_build/src/validation/index.d.ts.map +1 -1
  53. package/ts_build/src/validation/index.js +2 -0
  54. package/ts_build/src/validation/index.js.map +1 -1
  55. package/ts_build/test/address.test.js +8 -0
  56. package/ts_build/test/address.test.js.map +1 -1
  57. package/ts_build/test/transactions.test.js +102 -0
  58. package/ts_build/test/transactions.test.js.map +1 -1
  59. package/ts_build/test/utils.test.js +244 -10
  60. package/ts_build/test/utils.test.js.map +1 -1
  61. package/ts_build/test/validation.test.js +17 -0
  62. package/ts_build/test/validation.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.9.0",
3
+ "version": "11.10.3",
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",
@@ -12,13 +12,12 @@
12
12
  "build": "tsc",
13
13
  "clean": "rm -rf ts_build && tsc --version",
14
14
  "compile": "npm run clean && npm run build",
15
- "precommit": "npm run lint",
16
15
  "lint": "eslint .",
17
16
  "fix:errors": "eslint --fix --quiet .",
18
17
  "fix:all": "eslint --fix .",
19
18
  "fix": "npm run fix:errors",
20
- "test": "npm run compile && mocha 'ts_build/test/**/*.test.js'",
21
- "coverage": "npm run compile && nyc mocha 'ts_build/test/**/*.test.js'",
19
+ "test": "npm run compile && mocha -n enable-source-maps 'ts_build/test/**/*.test.js'",
20
+ "coverage": "npm run compile && nyc mocha -n enable-source-maps 'ts_build/test/**/*.test.js'",
22
21
  "pub": "npm run compile && npm publish"
23
22
  },
24
23
  "keywords": [
@@ -45,10 +44,10 @@
45
44
  "author": "Micah Riggan",
46
45
  "license": "MIT",
47
46
  "dependencies": {
48
- "@bitpay-labs/bitcore-lib": "^11.9.0",
49
- "@bitpay-labs/bitcore-lib-cash": "^11.9.0",
50
- "@bitpay-labs/bitcore-lib-doge": "^11.8.1",
51
- "@bitpay-labs/bitcore-lib-ltc": "^11.9.0",
47
+ "@bitpay-labs/bitcore-lib": "^11.10.3",
48
+ "@bitpay-labs/bitcore-lib-cash": "^11.10.3",
49
+ "@bitpay-labs/bitcore-lib-doge": "^11.10.3",
50
+ "@bitpay-labs/bitcore-lib-ltc": "^11.10.3",
52
51
  "@solana-program/compute-budget": "0.7.0",
53
52
  "@solana-program/memo": "0.7.0",
54
53
  "@solana-program/system": "0.7.0",
@@ -70,5 +69,5 @@
70
69
  "nyc": "^17.1.0",
71
70
  "typescript": "5.7.3"
72
71
  },
73
- "gitHead": "3491bf1216d3c6b103c591564726333d55ad8c6d"
72
+ "gitHead": "70298eedd1e458b23139e275125a07c577219bac"
74
73
  }
@@ -1,6 +1,6 @@
1
1
 
2
2
  export const UTXO_CHAINS = ['btc', 'bch', 'doge', 'ltc'];
3
- export const EVM_CHAINS = ['eth', 'matic', 'arb', 'base', 'op'];
3
+ export const EVM_CHAINS = ['eth', 'matic', 'arb', 'base', 'op', 'arc'];
4
4
  export const SVM_CHAINS = ['sol'];
5
5
  export const RIPPLE_CHAINS = ['xrp'];
6
6
  export const CHAINS = [...UTXO_CHAINS, ...EVM_CHAINS, ...SVM_CHAINS, ...RIPPLE_CHAINS];
@@ -12,7 +12,8 @@ export const EVM_CHAIN_DEFAULT_TESTNET = {
12
12
  MATIC: 'amoy',
13
13
  ARB: 'sepolia',
14
14
  BASE: 'sepolia',
15
- OP: 'sepolia'
15
+ OP: 'sepolia',
16
+ ARC: 'testnet'
16
17
  };
17
18
 
18
19
  export const EVM_CHAIN_NETWORK_TO_CHAIN_ID = {
@@ -22,6 +23,7 @@ export const EVM_CHAIN_NETWORK_TO_CHAIN_ID = {
22
23
  ARB_mainnet: 42161,
23
24
  BASE_mainnet: 8453,
24
25
  OP_mainnet: 10,
26
+ ARC_mainnet: 'unsupported',
25
27
  // ETH testnets
26
28
  ETH_holesky: 17000,
27
29
  ETH_sepolia: 11155111,
@@ -41,6 +43,8 @@ export const EVM_CHAIN_NETWORK_TO_CHAIN_ID = {
41
43
  // OP testnets
42
44
  OP_sepolia: 11155420,
43
45
  OP_goerli: 28528,
46
+ // ARC testnets
47
+ ARC_testnet: 5042002,
44
48
  // Regtests
45
49
  ETH_regtest: 1337,
46
50
  MATIC_regtest: 13375,
@@ -87,6 +87,17 @@ export const UNITS = {
87
87
  minDecimals: 2
88
88
  }
89
89
  },
90
+ arc: {
91
+ toSatoshis: 1e18,
92
+ full: {
93
+ maxDecimals: 6,
94
+ minDecimals: 6
95
+ },
96
+ short: {
97
+ maxDecimals: 6,
98
+ minDecimals: 2
99
+ }
100
+ },
90
101
  xrp: {
91
102
  toSatoshis: 1e6,
92
103
  full: {
@@ -23,6 +23,7 @@ const derivers: { [chain: string]: IDeriver } = {
23
23
  ARB: new ArbDeriver(),
24
24
  BASE: new BaseDeriver(),
25
25
  OP: new OpDeriver(),
26
+ ARC: new EthDeriver(),
26
27
  SOL: new SolDeriver()
27
28
  };
28
29
 
@@ -33,6 +33,9 @@ export const Paths = {
33
33
  BASE: {
34
34
  default: "m/44'/60'/",
35
35
  },
36
+ ARC: {
37
+ default: "m/44'/60'/",
38
+ },
36
39
  SOL: {
37
40
  default: "m/44'/501'/",
38
41
  },
@@ -41,6 +41,8 @@ const providers = {
41
41
  BASEERC20: new BASEERC20TxProvider(),
42
42
  OP: new OPTxProvider(),
43
43
  OPERC20: new OPERC20TxProvider(),
44
+ ARC: new ETHTxProvider('ARC'),
45
+ ARCERC20: new ERC20TxProvider('ARC'),
44
46
  SOL: new SOLTxProvider(),
45
47
  SOLSPL: new SPLTxProvider(),
46
48
  };
@@ -28,7 +28,7 @@ export class SPLTxProvider extends SOLTxProvider {
28
28
  mint: SolKit.address(tokenAddress),
29
29
  destination: SolKit.address(recipientAddress), // ATA address
30
30
  amount: BigInt(recipientAmount),
31
- decimals
31
+ decimals: Number(decimals)
32
32
  }));
33
33
  }
34
34
  }
@@ -164,7 +164,7 @@ interface CreateParams {
164
164
  // SPL token transfer fields (required for token transfers)
165
165
  tokenAddress: string; // mint address
166
166
  fromAta?: string;
167
- decimals?: number;
167
+ decimals?: number | string;
168
168
  }
169
169
 
170
170
  interface CreateRecoverNestedAssociatedTokenParams {
@@ -3,6 +3,7 @@ import * as RBC from 'ripple-binary-codec';
3
3
  import * as binary from 'ripple-binary-codec/dist/binary';
4
4
  import { HashPrefix } from 'ripple-binary-codec/dist/hash-prefixes';
5
5
  import * as xrpl from 'xrpl';
6
+ import * as Utils from '../../utils';
6
7
  import { BTCTxProvider } from '../btc';
7
8
  import type { Key } from '../../types/derivation';
8
9
 
@@ -15,12 +16,23 @@ export class XRPTxProvider {
15
16
  fee: number;
16
17
  feeRate: number;
17
18
  nonce: number;
18
- type?: string;
19
- flags?: number;
19
+ txType?: string;
20
+ flags?: number | string;
20
21
  }) {
21
- const { recipients, tag, from, invoiceID, fee, nonce, type, flags } = params;
22
+ const {
23
+ recipients,
24
+ tag,
25
+ from,
26
+ invoiceID,
27
+ fee,
28
+ nonce,
29
+ // `params.type` is an old param to fallback to.
30
+ // Changed to txType to re-use similar property name from other chains (e.g. EVM)
31
+ txType = params['type'],
32
+ flags,
33
+ } = params;
22
34
 
23
- switch (type?.toLowerCase()) {
35
+ switch (txType?.toLowerCase()) {
24
36
  case 'payment':
25
37
  default:
26
38
  const { address, amount } = recipients[0];
@@ -35,7 +47,8 @@ export class XRPTxProvider {
35
47
  Flags: 2147483648 // tfFullyCanonicalSig - DEPRECATED but still here for backward compatibility
36
48
  };
37
49
  if (flags != null) {
38
- paymentTx.Flags = flags;
50
+ paymentTx.Flags = this.transformFlags<xrpl.PaymentFlagsInterface>(flags, 'payment');
51
+ xrpl.setTransactionFlagsToNumber(paymentTx);
39
52
  }
40
53
  if (invoiceID) {
41
54
  paymentTx.InvoiceID = invoiceID;
@@ -45,16 +58,14 @@ export class XRPTxProvider {
45
58
  }
46
59
  return xrpl.encode(paymentTx);
47
60
  case 'accountset':
48
- if (!xrpl.AccountSetTfFlags[flags]) {
49
- throw new Error('Invalid tfAccountSet flag');
50
- }
51
61
  const accountSetTx: xrpl.AccountSet = {
52
62
  TransactionType: 'AccountSet',
53
63
  Account: from,
54
- Flags: (isNaN(flags) ? xrpl.AccountSetTfFlags[flags] : flags) as number, // in testing, only the number values take effect.
64
+ Flags: this.transformFlags<xrpl.AccountSetFlagsInterface>(flags, 'accountset'),
55
65
  Fee: fee.toString(),
56
66
  Sequence: nonce
57
67
  };
68
+ xrpl.setTransactionFlagsToNumber(accountSetTx);
58
69
  return xrpl.encode(accountSetTx);
59
70
  case 'accountdelete':
60
71
  const accountDeleteTx: xrpl.AccountDelete = {
@@ -126,4 +137,22 @@ export class XRPTxProvider {
126
137
  }).toString('hex');
127
138
  return this.sha512Half(encoded);
128
139
  }
129
- }
140
+
141
+ private transformFlags<T extends xrpl.PaymentFlagsInterface>(flags: string | number, txType: 'payment'): T | number
142
+ private transformFlags<T extends xrpl.AccountSetFlagsInterface>(flags: string | number, txType: 'accountset'): T | number
143
+ private transformFlags<T extends xrpl.PaymentFlagsInterface | xrpl.AccountSetFlagsInterface>(flags: string | number, txType: 'payment' | 'accountset'): T | number {
144
+ if (flags == null) {
145
+ throw new Error('No XRP flag(s) provided');
146
+ }
147
+ if (typeof flags === 'number') {
148
+ // Pass through numbers since they may be combined flags
149
+ return flags;
150
+ }
151
+ const flagEnum = txType === 'payment' ? xrpl.PaymentFlags : xrpl.AccountSetTfFlags;
152
+ return flags.split(',').reduce((acc, flag) => {
153
+ const flagValue = Utils.normalizeXrpFlag(flag.trim(), flagEnum);
154
+ acc[flagValue] = true;
155
+ return acc;
156
+ }, {} as T);
157
+ }
158
+ }
@@ -1,4 +1,5 @@
1
1
  import BitcoreLib from '@bitpay-labs/bitcore-lib';
2
+ import * as xrpl from 'xrpl';
2
3
  import { Constants } from '../constants';
3
4
 
4
5
 
@@ -63,7 +64,10 @@ export function isHexString(str: string): boolean {
63
64
  if (typeof str !== 'string' || str === '') {
64
65
  return false;
65
66
  }
66
- const normalizedStr = str.toLowerCase().slice(0, 2) === '0x' ? str.toLowerCase().slice(2) : str.toLowerCase();
67
+ let normalizedStr = str.toLowerCase().slice(0, 2) === '0x' ? str.toLowerCase().slice(2) : str.toLowerCase();
68
+ if (normalizedStr.length % 2) {
69
+ normalizedStr = '0' + normalizedStr; // add leading zero if odd length
70
+ }
67
71
  return Buffer.from(normalizedStr, 'hex').toString('hex') === normalizedStr;
68
72
  }
69
73
 
@@ -91,4 +95,85 @@ export function toHex(input: number | string | bigint): string {
91
95
  }
92
96
  }
93
97
 
98
+ /**
99
+ * Returns the elements that are in arr1 but not in arr2.
100
+ * Note, this does a primitive comparison of elements.
101
+ * @returns An array containing the elements that are in arr1 but not in arr2
102
+ *
103
+ * @example difference([1,2,3], [2,3,4]) => [1]
104
+ * @example difference([{a:1}], [{a:1}]) => [{a:1}]
105
+ * @example const obj = {a:1};
106
+ * difference([obj], [obj]) => []
107
+ */
108
+ export function difference<T>(arr1: T[], arr2: T[]): T[] {
109
+ arr1 = arr1 || [];
110
+ arr2 = arr2 || [];
111
+ const arr2Set = new Set(arr2);
112
+ return arr1.filter(x => !arr2Set.has(x));
113
+ }
114
+
115
+ /**
116
+ * Deeply compares two objects for equality, handling circular references.
117
+ * @returns True if the objects are deeply equal, false otherwise
118
+ */
119
+ export function isEqual(obj1: object, obj2: object): boolean {
120
+ if (obj1 === obj2) return true;
121
+ if (obj1 == null || obj2 == null) return false;
122
+ if (typeof obj1 !== 'object' || typeof obj2 !== 'object') return false;
123
+ const stack = [obj1, obj2];
124
+ // Use a WeakSet to track already compared objects to handle circular references
125
+ const weakRefs = new WeakSet();
126
+ const isWeak = (val) => val !== null && (typeof val === 'object' || typeof val === 'function');
94
127
 
128
+ while (stack.length) {
129
+ const a = stack.pop();
130
+ const b = stack.pop();
131
+ if (a === b) continue;
132
+ if (a == null || b == null) return false;
133
+ if (typeof a !== 'object' || typeof b !== 'object') return false;
134
+ if (Object.getPrototypeOf(a) !== Object.getPrototypeOf(b)) return false;
135
+ if (a instanceof Date) {
136
+ if (!(b instanceof Date) || a.getTime() !== b.getTime()) return false;
137
+ continue;
138
+ }
139
+ if (a instanceof RegExp) {
140
+ if (!(b instanceof RegExp) || a.source !== b.source || a.flags !== b.flags) return false;
141
+ continue;
142
+ }
143
+ for (const key of Object.keys(a)) {
144
+ if (!(key in b)) return false;
145
+ if (isWeak(a[key])) {
146
+ if (weakRefs.has(a[key])) continue;
147
+ try { weakRefs.add(a[key]); } catch { /* ignore TypeError if a[key] is not a valid WeakSet key */ }
148
+ }
149
+
150
+ stack.push(a[key], b[key]);
151
+ }
152
+ const addtlBKeys = difference(Object.keys(b), Object.keys(a));
153
+ for (const key of addtlBKeys) {
154
+ if (!(key in a)) return false;
155
+ if (isWeak(b[key])) {
156
+ if (weakRefs.has(b[key])) continue;
157
+ try { weakRefs.add(b[key]); } catch { /* ignore TypeError if b[key] is not a valid WeakSet key */ }
158
+ }
159
+ stack.push(a[key], b[key]);
160
+ }
161
+ }
162
+ return true;
163
+ }
164
+
165
+ export function normalizeXrpFlag(flag: string | number, flagEnum?: typeof xrpl.AccountSetTfFlags | typeof xrpl.PaymentFlags): string {
166
+ flagEnum = flagEnum || xrpl.AccountSetTfFlags; // default to AccountSet flags if not provided
167
+ const normalizedFlag = isNaN(parseInt(flag as string))
168
+ ? (flag as string) // flag is already a non-numeric string (e.g. 'tfRequireDestTag')
169
+ : (flagEnum[flag as string]);
170
+
171
+ if (!flagEnum[normalizedFlag]) {
172
+ const enumName =
173
+ flagEnum === xrpl.AccountSetTfFlags ? 'AccountSetTfFlags' :
174
+ flagEnum === xrpl.PaymentFlags ? 'PaymentFlags' :
175
+ '<unknown>';
176
+ throw new Error(`Invalid XRP flag: ${flag}. Flag is not in enum ${enumName}`);
177
+ }
178
+ return normalizedFlag;
179
+ }
@@ -0,0 +1,8 @@
1
+ import { EthValidation } from '../eth';
2
+
3
+ export class ArcValidation extends EthValidation {
4
+ constructor() {
5
+ super();
6
+ this.regex = /arc/i;
7
+ }
8
+ }
@@ -1,4 +1,5 @@
1
1
  import { ArbValidation } from './arb';
2
+ import { ArcValidation } from './arc';
2
3
  import { BaseValidation } from './base';
3
4
  import { BchValidation } from './bch';
4
5
  import { BtcValidation } from './btc';
@@ -22,6 +23,7 @@ const validation: { [chain: string]: IValidation } = {
22
23
  ARB: new ArbValidation(),
23
24
  BASE: new BaseValidation(),
24
25
  OP: new OpValidation(),
26
+ ARC: new ArcValidation(),
25
27
  SOL: new SolValidation(),
26
28
  };
27
29
 
@@ -88,6 +88,18 @@ describe('Address Derivation', () => {
88
88
  expect(address).to.equal(expectedAddress);
89
89
  });
90
90
 
91
+ it('should be able to generate a valid ARC address', () => {
92
+ const xPub = 'xpub6D8rChqkgFuaZULuq2n6VrS4zB5Cmv24gcRc889dFRRgYAH1CGQmQZ9kcPfMAfWGPnyMd1X5foBYFmJ5ZPfvwhm6tXjaY13ao1rQHRtkKDv';
93
+ // 'select scout crash enforce riot rival spring whale hollow radar rule sentence';
94
+
95
+ const path = Deriver.pathFor('ARC', 'testnet');
96
+ expect(path).to.equal("m/44'/60'/0'");
97
+
98
+ const address = Deriver.deriveAddress('ARC', 'testnet', xPub, 0, false);
99
+ const expectedAddress = '0x9dbfE221A6EEa27a0e2f52961B339e95426931F9';
100
+ expect(address).to.equal(expectedAddress);
101
+ });
102
+
91
103
  it('should be able to generate a valid ETH address, privKey, pubKey', () => {
92
104
  const privKey = 'xprv9ypBjKErGMqCdzd44hfSdy1Vk6PGtU3si8ogZcow7rA23HTxMi9XfT99EKmiNdLMr9BAZ9S8ZKCYfN1eCmzYSmXYHje1jnYQseV1VJDDfdS';
93
105
 
@@ -4,7 +4,7 @@ import bitcoreLib from '@bitpay-labs/bitcore-lib';
4
4
  import bitcoreLibCash from '@bitpay-labs/bitcore-lib-cash';
5
5
  import bitcoreLibDoge from '@bitpay-labs/bitcore-lib-doge';
6
6
  import bitcoreLibLtc from '@bitpay-labs/bitcore-lib-ltc';
7
- import { Transactions } from '../src';
7
+ import { Constants, Transactions } from '../src';
8
8
 
9
9
  describe('Transaction', function() {
10
10
  describe('create', () => {
@@ -714,6 +714,66 @@ describe('Transaction', function() {
714
714
  }
715
715
  });
716
716
 
717
+ it('should create an AccountSet tx with string flag', () => {
718
+ const xrpParams = {
719
+ chain: 'XRP',
720
+ network: 'testnet',
721
+ from: 'rMmUqMZRzKKnzrTnN3B6Zcz4qQQvmHowt8',
722
+ fee: 10,
723
+ nonce: 11876358,
724
+ txType: 'accountset',
725
+ flags: 'tfRequireDestTag'
726
+ };
727
+ const cryptoTx = Transactions.create(xrpParams);
728
+ const expectedTx = '12000322000100002400B5380668400000000000000A8114E3BEB23E9931CEE681B8CBFDA2F9203EFC18C5BA';
729
+ expect(cryptoTx).to.equal(expectedTx);
730
+ });
731
+
732
+ it('should create an AccountSet tx with comma-delimited string flags', () => {
733
+ const xrpParams = {
734
+ chain: 'XRP',
735
+ network: 'testnet',
736
+ from: 'rMmUqMZRzKKnzrTnN3B6Zcz4qQQvmHowt8',
737
+ fee: 10,
738
+ nonce: 11876358,
739
+ txType: 'accountset',
740
+ flags: 'tfRequireDestTag,tfDisallowXRP'
741
+ };
742
+ const cryptoTx = Transactions.create(xrpParams);
743
+ const expectedTx = '12000322001100002400B5380668400000000000000A8114E3BEB23E9931CEE681B8CBFDA2F9203EFC18C5BA';
744
+ expect(cryptoTx).to.equal(expectedTx);
745
+ });
746
+
747
+ it('should create an AccountSet tx with number flag', () => {
748
+ const xrpParams = {
749
+ chain: 'XRP',
750
+ network: 'testnet',
751
+ from: 'rMmUqMZRzKKnzrTnN3B6Zcz4qQQvmHowt8',
752
+ fee: 10,
753
+ nonce: 11876358,
754
+ txType: 'accountset',
755
+ flags: 65536 // tfRequireDestTag
756
+ };
757
+ const cryptoTx = Transactions.create(xrpParams);
758
+ const expectedTx = '12000322000100002400B5380668400000000000000A8114E3BEB23E9931CEE681B8CBFDA2F9203EFC18C5BA';
759
+ expect(cryptoTx).to.equal(expectedTx);
760
+ });
761
+
762
+ it('should throw on invalid flag(s)', () => {
763
+ const xrpParams = {
764
+ chain: 'XRP',
765
+ network: 'testnet',
766
+ from: 'rMmUqMZRzKKnzrTnN3B6Zcz4qQQvmHowt8',
767
+ fee: 10,
768
+ nonce: 11876358,
769
+ txType: 'accountset'
770
+ };
771
+ expect(() => Transactions.create({ ...xrpParams, flags: undefined })).to.throw('No XRP flag(s) provided');
772
+ expect(() => Transactions.create({ ...xrpParams, flags: null })).to.throw('No XRP flag(s) provided');
773
+ expect(() => Transactions.create({ ...xrpParams, flags: 'tfInvalidFlag' })).to.throw('Invalid XRP flag: tfInvalidFlag');
774
+ expect(() => Transactions.create({ ...xrpParams, flags: 'tfRequireDestTag,tfInvalidFlag' })).to.throw('Invalid XRP flag: tfInvalidFlag');
775
+ });
776
+
717
777
  it('should create a DOGE tx', () => {
718
778
  const recipients = [{ address: 'mpNpzMoprLnSBu8CWDunNCYeJq3Mzdk59V', amount: 1e8 }];
719
779
  const change = 'msnAsQcCdtzDyiSWb4ZnNxFwUy3P9ogQvY';
@@ -1751,6 +1811,59 @@ describe('Transaction', function() {
1751
1811
  });
1752
1812
  });
1753
1813
 
1814
+ describe('ARC EVM support', () => {
1815
+ it('should get the correct testnet chainId', () => {
1816
+ const testnetId = Transactions.get({ chain: 'ARC' }).getChainId('testnet');
1817
+ expect(testnetId).to.equal(5042002);
1818
+ });
1819
+
1820
+ it('should create an ARC native transaction using 18-decimal base units', () => {
1821
+ const tx = Transactions.create({
1822
+ chain: 'ARC',
1823
+ recipients: [{ address: '0x37d7B3bBD88EFdE6a93cF74D2F5b0385D3E3B08A', amount: '1000000000000000000' }],
1824
+ nonce: 0,
1825
+ gasPrice: 1,
1826
+ gasLimit: 21000,
1827
+ network: 'testnet',
1828
+ data: '0x'
1829
+ });
1830
+ const parsed = ethers.Transaction.from(tx);
1831
+ expect(parsed.chainId).to.equal(5042002n);
1832
+ expect(parsed.value).to.equal(1000000000000000000n);
1833
+ });
1834
+
1835
+ it('should create an ARC ERC20 transaction using ARC testnet chainId', () => {
1836
+ const tokenAddress = '0x3600000000000000000000000000000000000000';
1837
+ const recipient = '0x37d7B3bBD88EFdE6a93cF74D2F5b0385D3E3B08A';
1838
+ const amount = '1000000';
1839
+ const tx = Transactions.create({
1840
+ chain: 'ARCERC20',
1841
+ recipients: [{ address: recipient, amount }],
1842
+ nonce: 0,
1843
+ gasPrice: 1,
1844
+ gasLimit: 200000,
1845
+ network: 'testnet',
1846
+ tokenAddress
1847
+ });
1848
+ const parsed = ethers.Transaction.from(tx);
1849
+
1850
+ expect(parsed.chainId).to.equal(5042002n);
1851
+ expect(parsed.to).to.equal(ethers.getAddress(tokenAddress));
1852
+ expect(parsed.value).to.equal(0n);
1853
+ expect(parsed.data).to.equal(
1854
+ '0xa9059cbb' +
1855
+ '00000000000000000000000037d7b3bbd88efde6a93cf74d2f5b0385d3e3b08a' +
1856
+ '00000000000000000000000000000000000000000000000000000000000f4240'
1857
+ );
1858
+ });
1859
+
1860
+ it('should define ARC native units as 18 decimals', () => {
1861
+ expect(Constants.UNITS.arc.toSatoshis).to.equal(1e18);
1862
+ expect(Constants.UNITS.arc.full.maxDecimals).to.equal(6);
1863
+ expect(Constants.UNITS.arc.full.minDecimals).to.equal(6);
1864
+ });
1865
+ });
1866
+
1754
1867
  describe('ETH _toHex', function() {
1755
1868
  it('should convert number to hex string', function() {
1756
1869
  const ETHTxProvider = Transactions.get({ chain: 'ETH' });