@ledgerhq/coin-stellar 6.26.0 → 6.26.1

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 (271) hide show
  1. package/.oxlintrc.json +7 -0
  2. package/CHANGELOG.md +6 -0
  3. package/LICENSE +194 -0
  4. package/knip.json +12 -0
  5. package/lib/api/index.d.ts +5 -5
  6. package/lib/api/index.d.ts.map +1 -1
  7. package/lib/api/index.js +12 -10
  8. package/lib/api/index.js.map +1 -1
  9. package/lib/config.d.ts +1 -1
  10. package/lib/config.d.ts.map +1 -1
  11. package/lib/config.js +2 -0
  12. package/lib/config.js.map +1 -1
  13. package/lib/constants.d.ts.map +1 -1
  14. package/lib/constants.js +3 -1
  15. package/lib/constants.js.map +1 -1
  16. package/lib/logic/broadcast.d.ts.map +1 -1
  17. package/lib/logic/broadcast.js +2 -0
  18. package/lib/logic/broadcast.js.map +1 -1
  19. package/lib/logic/combine.d.ts +1 -1
  20. package/lib/logic/combine.d.ts.map +1 -1
  21. package/lib/logic/combine.js +2 -0
  22. package/lib/logic/combine.js.map +1 -1
  23. package/lib/logic/common.d.ts +1 -1
  24. package/lib/logic/common.d.ts.map +1 -1
  25. package/lib/logic/common.js +4 -2
  26. package/lib/logic/common.js.map +1 -1
  27. package/lib/logic/craftTransaction.d.ts +1 -1
  28. package/lib/logic/craftTransaction.d.ts.map +1 -1
  29. package/lib/logic/craftTransaction.js +10 -8
  30. package/lib/logic/craftTransaction.js.map +1 -1
  31. package/lib/logic/estimateFees.d.ts.map +1 -1
  32. package/lib/logic/estimateFees.js +2 -0
  33. package/lib/logic/estimateFees.js.map +1 -1
  34. package/lib/logic/getBalance.d.ts +1 -1
  35. package/lib/logic/getBalance.d.ts.map +1 -1
  36. package/lib/logic/getBalance.js +4 -2
  37. package/lib/logic/getBalance.js.map +1 -1
  38. package/lib/logic/getBlock.d.ts +1 -1
  39. package/lib/logic/getBlock.d.ts.map +1 -1
  40. package/lib/logic/getBlock.js +39 -34
  41. package/lib/logic/getBlock.js.map +1 -1
  42. package/lib/logic/getBlockInfo.d.ts +1 -1
  43. package/lib/logic/getBlockInfo.d.ts.map +1 -1
  44. package/lib/logic/getBlockInfo.js +2 -0
  45. package/lib/logic/getBlockInfo.js.map +1 -1
  46. package/lib/logic/index.d.ts +12 -12
  47. package/lib/logic/index.d.ts.map +1 -1
  48. package/lib/logic/index.js +2 -0
  49. package/lib/logic/index.js.map +1 -1
  50. package/lib/logic/lastBlock.d.ts +1 -1
  51. package/lib/logic/lastBlock.d.ts.map +1 -1
  52. package/lib/logic/lastBlock.js +2 -0
  53. package/lib/logic/lastBlock.js.map +1 -1
  54. package/lib/logic/listOperations.d.ts +1 -1
  55. package/lib/logic/listOperations.d.ts.map +1 -1
  56. package/lib/logic/listOperations.js +6 -4
  57. package/lib/logic/listOperations.js.map +1 -1
  58. package/lib/logic/sdkWrapper.d.ts +1 -1
  59. package/lib/logic/sdkWrapper.d.ts.map +1 -1
  60. package/lib/logic/sdkWrapper.js +2 -0
  61. package/lib/logic/sdkWrapper.js.map +1 -1
  62. package/lib/logic/utils.d.ts.map +1 -1
  63. package/lib/logic/utils.js +4 -2
  64. package/lib/logic/utils.js.map +1 -1
  65. package/lib/logic/validateAddress.d.ts +1 -1
  66. package/lib/logic/validateAddress.d.ts.map +1 -1
  67. package/lib/logic/validateAddress.js +2 -0
  68. package/lib/logic/validateAddress.js.map +1 -1
  69. package/lib/logic/validateIntent.d.ts +2 -2
  70. package/lib/logic/validateIntent.d.ts.map +1 -1
  71. package/lib/logic/validateIntent.js +21 -19
  72. package/lib/logic/validateIntent.js.map +1 -1
  73. package/lib/logic/validateMemo.d.ts +1 -1
  74. package/lib/logic/validateMemo.d.ts.map +1 -1
  75. package/lib/logic/validateMemo.js +7 -5
  76. package/lib/logic/validateMemo.js.map +1 -1
  77. package/lib/network/horizon.d.ts +6 -7
  78. package/lib/network/horizon.d.ts.map +1 -1
  79. package/lib/network/horizon.js +71 -68
  80. package/lib/network/horizon.js.map +1 -1
  81. package/lib/network/horizonLedgerErrors.d.ts.map +1 -1
  82. package/lib/network/horizonLedgerErrors.js +5 -3
  83. package/lib/network/horizonLedgerErrors.js.map +1 -1
  84. package/lib/network/index.d.ts +1 -1
  85. package/lib/network/index.d.ts.map +1 -1
  86. package/lib/network/index.js +2 -0
  87. package/lib/network/index.js.map +1 -1
  88. package/lib/network/serialization.d.ts +6 -4
  89. package/lib/network/serialization.d.ts.map +1 -1
  90. package/lib/network/serialization.js +95 -91
  91. package/lib/network/serialization.js.map +1 -1
  92. package/lib/polyfill.d.ts.map +1 -1
  93. package/lib/polyfill.js +6 -4
  94. package/lib/polyfill.js.map +1 -1
  95. package/lib/supportedFeatures.d.ts +1 -1
  96. package/lib/supportedFeatures.d.ts.map +1 -1
  97. package/lib/supportedFeatures.js +3 -1
  98. package/lib/supportedFeatures.js.map +1 -1
  99. package/lib/types/errors.d.ts.map +1 -1
  100. package/lib/types/errors.js +14 -12
  101. package/lib/types/errors.js.map +1 -1
  102. package/lib/types/index.d.ts +2 -2
  103. package/lib/types/index.d.ts.map +1 -1
  104. package/lib/types/index.js +2 -0
  105. package/lib/types/index.js.map +1 -1
  106. package/lib/types/model.d.ts +6 -6
  107. package/lib/types/model.d.ts.map +1 -1
  108. package/lib/types/model.js +7 -5
  109. package/lib/types/model.js.map +1 -1
  110. package/lib-es/api/index.d.ts +5 -5
  111. package/lib-es/api/index.d.ts.map +1 -1
  112. package/lib-es/api/index.js +20 -18
  113. package/lib-es/api/index.js.map +1 -1
  114. package/lib-es/config.d.ts +1 -1
  115. package/lib-es/config.d.ts.map +1 -1
  116. package/lib-es/config.js +3 -1
  117. package/lib-es/config.js.map +1 -1
  118. package/lib-es/constants.d.ts.map +1 -1
  119. package/lib-es/constants.js +3 -1
  120. package/lib-es/constants.js.map +1 -1
  121. package/lib-es/logic/broadcast.d.ts.map +1 -1
  122. package/lib-es/logic/broadcast.js +3 -1
  123. package/lib-es/logic/broadcast.js.map +1 -1
  124. package/lib-es/logic/combine.d.ts +1 -1
  125. package/lib-es/logic/combine.d.ts.map +1 -1
  126. package/lib-es/logic/combine.js +3 -1
  127. package/lib-es/logic/combine.js.map +1 -1
  128. package/lib-es/logic/common.d.ts +1 -1
  129. package/lib-es/logic/common.d.ts.map +1 -1
  130. package/lib-es/logic/common.js +5 -3
  131. package/lib-es/logic/common.js.map +1 -1
  132. package/lib-es/logic/craftTransaction.d.ts +1 -1
  133. package/lib-es/logic/craftTransaction.d.ts.map +1 -1
  134. package/lib-es/logic/craftTransaction.js +15 -13
  135. package/lib-es/logic/craftTransaction.js.map +1 -1
  136. package/lib-es/logic/estimateFees.d.ts.map +1 -1
  137. package/lib-es/logic/estimateFees.js +3 -1
  138. package/lib-es/logic/estimateFees.js.map +1 -1
  139. package/lib-es/logic/getBalance.d.ts +1 -1
  140. package/lib-es/logic/getBalance.d.ts.map +1 -1
  141. package/lib-es/logic/getBalance.js +5 -3
  142. package/lib-es/logic/getBalance.js.map +1 -1
  143. package/lib-es/logic/getBlock.d.ts +1 -1
  144. package/lib-es/logic/getBlock.d.ts.map +1 -1
  145. package/lib-es/logic/getBlock.js +42 -37
  146. package/lib-es/logic/getBlock.js.map +1 -1
  147. package/lib-es/logic/getBlockInfo.d.ts +1 -1
  148. package/lib-es/logic/getBlockInfo.d.ts.map +1 -1
  149. package/lib-es/logic/getBlockInfo.js +3 -1
  150. package/lib-es/logic/getBlockInfo.js.map +1 -1
  151. package/lib-es/logic/index.d.ts +12 -12
  152. package/lib-es/logic/index.d.ts.map +1 -1
  153. package/lib-es/logic/index.js +14 -12
  154. package/lib-es/logic/index.js.map +1 -1
  155. package/lib-es/logic/lastBlock.d.ts +1 -1
  156. package/lib-es/logic/lastBlock.d.ts.map +1 -1
  157. package/lib-es/logic/lastBlock.js +3 -1
  158. package/lib-es/logic/lastBlock.js.map +1 -1
  159. package/lib-es/logic/listOperations.d.ts +1 -1
  160. package/lib-es/logic/listOperations.d.ts.map +1 -1
  161. package/lib-es/logic/listOperations.js +7 -5
  162. package/lib-es/logic/listOperations.js.map +1 -1
  163. package/lib-es/logic/sdkWrapper.d.ts +1 -1
  164. package/lib-es/logic/sdkWrapper.d.ts.map +1 -1
  165. package/lib-es/logic/sdkWrapper.js +4 -2
  166. package/lib-es/logic/sdkWrapper.js.map +1 -1
  167. package/lib-es/logic/utils.d.ts.map +1 -1
  168. package/lib-es/logic/utils.js +6 -4
  169. package/lib-es/logic/utils.js.map +1 -1
  170. package/lib-es/logic/validateAddress.d.ts +1 -1
  171. package/lib-es/logic/validateAddress.d.ts.map +1 -1
  172. package/lib-es/logic/validateAddress.js +3 -1
  173. package/lib-es/logic/validateAddress.js.map +1 -1
  174. package/lib-es/logic/validateIntent.d.ts +2 -2
  175. package/lib-es/logic/validateIntent.d.ts.map +1 -1
  176. package/lib-es/logic/validateIntent.js +30 -28
  177. package/lib-es/logic/validateIntent.js.map +1 -1
  178. package/lib-es/logic/validateMemo.d.ts +1 -1
  179. package/lib-es/logic/validateMemo.d.ts.map +1 -1
  180. package/lib-es/logic/validateMemo.js +8 -6
  181. package/lib-es/logic/validateMemo.js.map +1 -1
  182. package/lib-es/network/horizon.d.ts +6 -7
  183. package/lib-es/network/horizon.d.ts.map +1 -1
  184. package/lib-es/network/horizon.js +80 -77
  185. package/lib-es/network/horizon.js.map +1 -1
  186. package/lib-es/network/horizonLedgerErrors.d.ts.map +1 -1
  187. package/lib-es/network/horizonLedgerErrors.js +7 -5
  188. package/lib-es/network/horizonLedgerErrors.js.map +1 -1
  189. package/lib-es/network/index.d.ts +1 -1
  190. package/lib-es/network/index.d.ts.map +1 -1
  191. package/lib-es/network/index.js +3 -1
  192. package/lib-es/network/index.js.map +1 -1
  193. package/lib-es/network/serialization.d.ts +6 -4
  194. package/lib-es/network/serialization.d.ts.map +1 -1
  195. package/lib-es/network/serialization.js +97 -95
  196. package/lib-es/network/serialization.js.map +1 -1
  197. package/lib-es/polyfill.d.ts.map +1 -1
  198. package/lib-es/polyfill.js +7 -5
  199. package/lib-es/polyfill.js.map +1 -1
  200. package/lib-es/supportedFeatures.d.ts +1 -1
  201. package/lib-es/supportedFeatures.d.ts.map +1 -1
  202. package/lib-es/supportedFeatures.js +3 -1
  203. package/lib-es/supportedFeatures.js.map +1 -1
  204. package/lib-es/types/errors.d.ts.map +1 -1
  205. package/lib-es/types/errors.js +15 -13
  206. package/lib-es/types/errors.js.map +1 -1
  207. package/lib-es/types/index.d.ts +2 -2
  208. package/lib-es/types/index.d.ts.map +1 -1
  209. package/lib-es/types/index.js +4 -2
  210. package/lib-es/types/index.js.map +1 -1
  211. package/lib-es/types/model.d.ts +6 -6
  212. package/lib-es/types/model.d.ts.map +1 -1
  213. package/lib-es/types/model.js +7 -5
  214. package/lib-es/types/model.js.map +1 -1
  215. package/package.json +13 -16
  216. package/src/api/index.integ.test.ts +165 -162
  217. package/src/api/index.test.ts +106 -103
  218. package/src/api/index.ts +49 -46
  219. package/src/api/index_error.test.ts +48 -25
  220. package/src/config.ts +15 -12
  221. package/src/constants.ts +4 -1
  222. package/src/globals.d.ts +7 -5
  223. package/src/logic/broadcast.integ.test.ts +22 -19
  224. package/src/logic/broadcast.ts +5 -2
  225. package/src/logic/combine.test.ts +18 -15
  226. package/src/logic/combine.ts +8 -5
  227. package/src/logic/common.ts +9 -6
  228. package/src/logic/craftTransaction.test.ts +76 -75
  229. package/src/logic/craftTransaction.ts +46 -43
  230. package/src/logic/estimateFees.ts +6 -3
  231. package/src/logic/getBalance.test.ts +31 -28
  232. package/src/logic/getBalance.ts +13 -10
  233. package/src/logic/getBlock.integ.test.ts +40 -39
  234. package/src/logic/getBlock.test.ts +462 -415
  235. package/src/logic/getBlock.ts +142 -127
  236. package/src/logic/getBlockInfo.test.ts +72 -69
  237. package/src/logic/getBlockInfo.ts +15 -12
  238. package/src/logic/index.ts +15 -12
  239. package/src/logic/lastBlock.ts +6 -3
  240. package/src/logic/listOperations.ts +14 -11
  241. package/src/logic/listOperations.unit.test.ts +212 -209
  242. package/src/logic/networkWrappers.test.ts +32 -29
  243. package/src/logic/sdkWrapper.ts +19 -16
  244. package/src/logic/utils.ts +13 -10
  245. package/src/logic/validateAddress.test.ts +21 -18
  246. package/src/logic/validateAddress.ts +7 -4
  247. package/src/logic/validateIntent.test.ts +62 -59
  248. package/src/logic/validateIntent.ts +87 -84
  249. package/src/logic/validateMemo.test.ts +50 -47
  250. package/src/logic/validateMemo.ts +16 -13
  251. package/src/network/broadcastTransaction.test.ts +60 -60
  252. package/src/network/fetchLedgerOperations.unit.test.ts +155 -0
  253. package/src/network/horizon.integ.test.ts +45 -42
  254. package/src/network/horizon.test.ts +17 -14
  255. package/src/network/horizon.ts +279 -281
  256. package/src/network/horizon.unit.test.ts +238 -237
  257. package/src/network/horizonLedgerErrors.test.ts +81 -78
  258. package/src/network/horizonLedgerErrors.ts +22 -19
  259. package/src/network/index.ts +4 -1
  260. package/src/network/registerHorizonInterceptors.test.ts +163 -160
  261. package/src/network/serialization.ts +232 -227
  262. package/src/network/serialization.unit.test.ts +801 -798
  263. package/src/polyfill.ts +18 -15
  264. package/src/supportedFeatures.ts +6 -3
  265. package/src/types/errors.ts +33 -32
  266. package/src/types/index.ts +5 -2
  267. package/src/types/model.ts +55 -52
  268. package/tsconfig.json +1 -1
  269. package/.unimportedrc.json +0 -17
  270. package/LICENSE.txt +0 -21
  271. package/src/network/fetchLedgerOperations.nock.unit.test.ts +0 -156
@@ -1,3 +1,6 @@
1
+ // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
1
4
  import {
2
5
  Keypair,
3
6
  TransactionBuilder,
@@ -6,24 +9,24 @@ import {
6
9
  BASE_FEE,
7
10
  Asset,
8
11
  Account,
9
- } from "@stellar/stellar-sdk";
10
- import { broadcast } from "./broadcast";
11
- import coinConfig from "../config";
12
- import { StellarBroadcastFailedError } from "../types";
12
+ } from '@stellar/stellar-sdk'
13
+ import coinConfig from '../config'
14
+ import { StellarBroadcastFailedError } from '../types'
15
+ import { broadcast } from './broadcast'
13
16
 
14
- describe("Broadcast", () => {
17
+ describe('Broadcast', () => {
15
18
  beforeAll(() => {
16
19
  coinConfig.setCoinConfig(() => ({
17
- status: { type: "active" },
20
+ status: { type: 'active' },
18
21
  explorer: {
19
- url: "https://stellar.coin.ledger.com",
22
+ url: 'https://stellar.coin.ledger.com',
20
23
  },
21
- }));
22
- });
24
+ }))
25
+ })
23
26
 
24
- it("throws on insufficient funds", async () => {
25
- const source = Keypair.random();
26
- const account = new Account(source.publicKey(), "0");
27
+ it('throws on insufficient funds', async () => {
28
+ const source = Keypair.random()
29
+ const account = new Account(source.publicKey(), '0')
27
30
 
28
31
  const tx = new TransactionBuilder(account, {
29
32
  fee: BASE_FEE,
@@ -33,13 +36,13 @@ describe("Broadcast", () => {
33
36
  Operation.payment({
34
37
  destination: source.publicKey(),
35
38
  asset: Asset.native(),
36
- amount: "1",
37
- }),
39
+ amount: '1',
40
+ })
38
41
  )
39
42
  .setTimeout(0)
40
- .build();
41
- tx.sign(source);
43
+ .build()
44
+ tx.sign(source)
42
45
 
43
- await expect(broadcast(tx.toXDR())).rejects.toThrow(StellarBroadcastFailedError);
44
- });
45
- });
46
+ await expect(broadcast(tx.toXDR())).rejects.toThrow(StellarBroadcastFailedError)
47
+ })
48
+ })
@@ -1,5 +1,8 @@
1
- import { broadcastTransaction } from "../network";
1
+ // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { broadcastTransaction } from '../network'
2
5
 
3
6
  export async function broadcast(signature: string): Promise<string> {
4
- return broadcastTransaction(signature);
7
+ return broadcastTransaction(signature)
5
8
  }
@@ -1,24 +1,27 @@
1
- import { Networks, Transaction as StellarSdkTransaction } from "@stellar/stellar-sdk";
2
- import { combine } from "./combine";
1
+ // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
+ // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- jest.mock("@stellar/stellar-sdk", () => ({
4
+ import { Networks, Transaction as StellarSdkTransaction } from '@stellar/stellar-sdk'
5
+ import { combine } from './combine'
6
+
7
+ jest.mock('@stellar/stellar-sdk', () => ({
5
8
  Networks: {
6
- PUBLIC: "PUBLIC",
9
+ PUBLIC: 'PUBLIC',
7
10
  },
8
11
  Transaction: jest.fn().mockImplementation(() => ({
9
12
  addSignature: jest.fn(),
10
- toXDR: jest.fn().mockReturnValue("signed-xdr"),
13
+ toXDR: jest.fn().mockReturnValue('signed-xdr'),
11
14
  })),
12
- }));
15
+ }))
13
16
 
14
- describe("combine", () => {
15
- it("creates a transaction, adds signature and returns xdr", () => {
16
- const result = combine("unsigned-xdr", "signature", "public-key");
17
+ describe('combine', () => {
18
+ it('creates a transaction, adds signature and returns xdr', () => {
19
+ const result = combine('unsigned-xdr', 'signature', 'public-key')
17
20
 
18
- expect(StellarSdkTransaction).toHaveBeenCalledWith("unsigned-xdr", Networks.PUBLIC);
21
+ expect(StellarSdkTransaction).toHaveBeenCalledWith('unsigned-xdr', Networks.PUBLIC)
19
22
 
20
- const txInstance = (StellarSdkTransaction as unknown as jest.Mock).mock.results[0].value;
21
- expect(txInstance.addSignature).toHaveBeenCalledWith("public-key", "signature");
22
- expect(result).toBe("signed-xdr");
23
- });
24
- });
23
+ const txInstance = (StellarSdkTransaction as unknown as jest.Mock).mock.results[0].value
24
+ expect(txInstance.addSignature).toHaveBeenCalledWith('public-key', 'signature')
25
+ expect(result).toBe('signed-xdr')
26
+ })
27
+ })
@@ -1,11 +1,14 @@
1
- import { Networks, Transaction as StellarSdkTransaction, xdr } from "@stellar/stellar-sdk";
1
+ // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { Networks, Transaction as StellarSdkTransaction, xdr } from '@stellar/stellar-sdk'
2
5
 
3
6
  export function combine(
4
7
  transaction: string | xdr.TransactionEnvelope,
5
8
  signature: string,
6
- publicKey: string,
9
+ publicKey: string
7
10
  ): string {
8
- const unsignedTx = new StellarSdkTransaction(transaction, Networks.PUBLIC);
9
- unsignedTx.addSignature(publicKey, signature);
10
- return unsignedTx.toXDR();
11
+ const unsignedTx = new StellarSdkTransaction(transaction, Networks.PUBLIC)
12
+ unsignedTx.addSignature(publicKey, signature)
13
+ return unsignedTx.toXDR()
11
14
  }
@@ -1,9 +1,12 @@
1
- import { parseCurrencyUnit } from "@ledgerhq/coin-module-framework/currencies";
2
- import BigNumber from "bignumber.js";
1
+ // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { parseCurrencyUnit } from '@ledgerhq/coin-module-framework/currencies'
5
+ import BigNumber from 'bignumber.js'
3
6
 
4
7
  export const stellarUnit = {
5
- name: "Lumen",
6
- code: "XLM",
8
+ name: 'Lumen',
9
+ code: 'XLM',
7
10
  magnitude: 7,
8
- };
9
- export const parseAPIValue = (value: string): BigNumber => parseCurrencyUnit(stellarUnit, value);
11
+ }
12
+ export const parseAPIValue = (value: string): BigNumber => parseCurrencyUnit(stellarUnit, value)
@@ -1,145 +1,146 @@
1
- import { NetworkDown } from "@ledgerhq/errors";
2
- import { Horizon, Memo } from "@stellar/stellar-sdk";
3
- import { getRecipientAccount, loadAccount } from "../network";
4
- import { StellarAssetRequired, StellarMuxedAccountNotExist } from "../types";
5
- import { craftTransaction } from "./craftTransaction";
1
+ // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { NetworkDown } from '@ledgerhq/errors'
5
+ import { Horizon, Memo } from '@stellar/stellar-sdk'
6
+ import { getRecipientAccount, loadAccount } from '../network'
7
+ import { StellarAssetRequired, StellarMuxedAccountNotExist } from '../types'
8
+ import { craftTransaction } from './craftTransaction'
6
9
  import {
7
10
  buildChangeTrustOperation,
8
11
  buildCreateAccountOperation,
9
12
  buildPaymentOperation,
10
13
  buildTransactionBuilder,
11
- } from "./sdkWrapper";
14
+ } from './sdkWrapper'
12
15
 
13
- jest.mock("../network", () => ({
16
+ jest.mock('../network', () => ({
14
17
  loadAccount: jest.fn(),
15
18
  getRecipientAccount: jest.fn(),
16
- }));
19
+ }))
17
20
 
18
- jest.mock("./sdkWrapper", () => ({
21
+ jest.mock('./sdkWrapper', () => ({
19
22
  buildChangeTrustOperation: jest.fn(),
20
23
  buildCreateAccountOperation: jest.fn(),
21
24
  buildPaymentOperation: jest.fn(),
22
25
  buildTransactionBuilder: jest.fn(),
23
- }));
26
+ }))
24
27
 
25
- describe("craftTransaction", () => {
26
- const account = { address: "GABC" };
28
+ describe('craftTransaction', () => {
29
+ const account = { address: 'GABC' }
27
30
  const transaction = {
28
- type: "payment",
29
- recipient: "GRECIPIENT",
31
+ type: 'payment',
32
+ recipient: 'GRECIPIENT',
30
33
  amount: 10000000n,
31
34
  fee: 100n,
32
- };
35
+ }
33
36
 
34
37
  const craftedTransaction = {
35
- toXDR: jest.fn().mockReturnValue("tx-xdr"),
36
- signatureBase: jest.fn().mockReturnValue(Buffer.from("signature-base")),
37
- };
38
+ toXDR: jest.fn().mockReturnValue('tx-xdr'),
39
+ signatureBase: jest.fn().mockReturnValue(Buffer.from('signature-base')),
40
+ }
38
41
 
39
42
  const txBuilder = {
40
43
  addOperation: jest.fn(),
41
44
  addMemo: jest.fn(),
42
45
  setTimeout: jest.fn(),
43
46
  build: jest.fn().mockReturnValue(craftedTransaction),
44
- };
47
+ }
45
48
 
46
49
  beforeEach(() => {
47
- jest.clearAllMocks();
48
- txBuilder.setTimeout.mockReturnValue(txBuilder);
50
+ jest.clearAllMocks()
51
+ txBuilder.setTimeout.mockReturnValue(txBuilder)
49
52
  jest
50
53
  .mocked(buildTransactionBuilder)
51
- .mockReturnValue(txBuilder as unknown as ReturnType<typeof buildTransactionBuilder>);
52
- jest.mocked(loadAccount).mockResolvedValue({ id: "source-account" } as Horizon.AccountResponse);
54
+ .mockReturnValue(txBuilder as unknown as ReturnType<typeof buildTransactionBuilder>)
55
+ jest.mocked(loadAccount).mockResolvedValue({ id: 'source-account' } as Horizon.AccountResponse)
53
56
  jest.mocked(getRecipientAccount).mockResolvedValue({
54
- id: "GRECIPIENT",
57
+ id: 'GRECIPIENT',
55
58
  isMuxedAccount: false,
56
59
  assetIds: [],
57
- });
60
+ })
58
61
  jest
59
62
  .mocked(buildPaymentOperation)
60
- .mockReturnValue("payment-op" as unknown as ReturnType<typeof buildPaymentOperation>);
63
+ .mockReturnValue('payment-op' as unknown as ReturnType<typeof buildPaymentOperation>)
61
64
  jest
62
65
  .mocked(buildCreateAccountOperation)
63
66
  .mockReturnValue(
64
- "create-account-op" as unknown as ReturnType<typeof buildCreateAccountOperation>,
65
- );
67
+ 'create-account-op' as unknown as ReturnType<typeof buildCreateAccountOperation>
68
+ )
66
69
  jest
67
70
  .mocked(buildChangeTrustOperation)
68
- .mockReturnValue(
69
- "change-trust-op" as unknown as ReturnType<typeof buildChangeTrustOperation>,
70
- );
71
- });
71
+ .mockReturnValue('change-trust-op' as unknown as ReturnType<typeof buildChangeTrustOperation>)
72
+ })
72
73
 
73
- it("throws NetworkDown when source account cannot be loaded", async () => {
74
- jest.mocked(loadAccount).mockResolvedValue(null);
74
+ it('throws NetworkDown when source account cannot be loaded', async () => {
75
+ jest.mocked(loadAccount).mockResolvedValue(null)
75
76
 
76
- await expect(craftTransaction(account, transaction)).rejects.toThrow(NetworkDown);
77
- });
77
+ await expect(craftTransaction(account, transaction)).rejects.toThrow(NetworkDown)
78
+ })
78
79
 
79
- it("throws StellarAssetRequired for changeTrust without asset code and issuer", async () => {
80
+ it('throws StellarAssetRequired for changeTrust without asset code and issuer', async () => {
80
81
  await expect(
81
82
  craftTransaction(account, {
82
83
  ...transaction,
83
- type: "changeTrust",
84
+ type: 'changeTrust',
84
85
  assetCode: undefined,
85
86
  assetIssuer: undefined,
86
- }),
87
- ).rejects.toThrow(StellarAssetRequired);
88
- });
87
+ })
88
+ ).rejects.toThrow(StellarAssetRequired)
89
+ })
89
90
 
90
- it("builds a changeTrust operation when type is changeTrust", async () => {
91
+ it('builds a changeTrust operation when type is changeTrust', async () => {
91
92
  const result = await craftTransaction(account, {
92
93
  ...transaction,
93
- type: "changeTrust",
94
- assetCode: "USDC",
95
- assetIssuer: "GISSUER",
96
- });
94
+ type: 'changeTrust',
95
+ assetCode: 'USDC',
96
+ assetIssuer: 'GISSUER',
97
+ })
97
98
 
98
- expect(buildChangeTrustOperation).toHaveBeenCalledWith("USDC", "GISSUER");
99
- expect(txBuilder.addOperation).toHaveBeenCalledWith("change-trust-op");
100
- expect(getRecipientAccount).not.toHaveBeenCalled();
101
- expect(result.xdr).toBe("tx-xdr");
102
- expect(result.signatureBase).toBe("c2lnbmF0dXJlLWJhc2U=");
103
- });
99
+ expect(buildChangeTrustOperation).toHaveBeenCalledWith('USDC', 'GISSUER')
100
+ expect(txBuilder.addOperation).toHaveBeenCalledWith('change-trust-op')
101
+ expect(getRecipientAccount).not.toHaveBeenCalled()
102
+ expect(result.xdr).toBe('tx-xdr')
103
+ expect(result.signatureBase).toBe('c2lnbmF0dXJlLWJhc2U=')
104
+ })
104
105
 
105
- it("builds a payment operation and memo when recipient exists", async () => {
106
- const memoTextSpy = jest.spyOn(Memo, "text");
106
+ it('builds a payment operation and memo when recipient exists', async () => {
107
+ const memoTextSpy = jest.spyOn(Memo, 'text')
107
108
 
108
109
  await craftTransaction(account, {
109
110
  ...transaction,
110
- memoType: "MEMO_TEXT",
111
- memoValue: "hello",
112
- });
111
+ memoType: 'MEMO_TEXT',
112
+ memoValue: 'hello',
113
+ })
113
114
 
114
115
  expect(buildPaymentOperation).toHaveBeenCalledWith({
115
- destination: "GRECIPIENT",
116
+ destination: 'GRECIPIENT',
116
117
  amount: 10000000n,
117
118
  assetCode: undefined,
118
119
  assetIssuer: undefined,
119
- });
120
- expect(txBuilder.addOperation).toHaveBeenCalledWith("payment-op");
121
- expect(memoTextSpy).toHaveBeenCalledWith("hello");
122
- expect(txBuilder.addMemo).toHaveBeenCalledTimes(1);
123
- });
120
+ })
121
+ expect(txBuilder.addOperation).toHaveBeenCalledWith('payment-op')
122
+ expect(memoTextSpy).toHaveBeenCalledWith('hello')
123
+ expect(txBuilder.addMemo).toHaveBeenCalledTimes(1)
124
+ })
124
125
 
125
- it("throws StellarMuxedAccountNotExist when missing muxed recipient account", async () => {
126
+ it('throws StellarMuxedAccountNotExist when missing muxed recipient account', async () => {
126
127
  jest
127
128
  .mocked(getRecipientAccount)
128
- .mockResolvedValue({ id: null, isMuxedAccount: true, assetIds: [] });
129
+ .mockResolvedValue({ id: null, isMuxedAccount: true, assetIds: [] })
129
130
 
130
131
  await expect(craftTransaction(account, transaction)).rejects.toThrow(
131
- StellarMuxedAccountNotExist,
132
- );
133
- });
132
+ StellarMuxedAccountNotExist
133
+ )
134
+ })
134
135
 
135
- it("builds createAccount operation when recipient does not exist and is not muxed", async () => {
136
+ it('builds createAccount operation when recipient does not exist and is not muxed', async () => {
136
137
  jest
137
138
  .mocked(getRecipientAccount)
138
- .mockResolvedValue({ id: null, isMuxedAccount: false, assetIds: [] });
139
+ .mockResolvedValue({ id: null, isMuxedAccount: false, assetIds: [] })
139
140
 
140
- await craftTransaction(account, transaction);
141
+ await craftTransaction(account, transaction)
141
142
 
142
- expect(buildCreateAccountOperation).toHaveBeenCalledWith("GRECIPIENT", 10000000n);
143
- expect(txBuilder.addOperation).toHaveBeenCalledWith("create-account-op");
144
- });
145
- });
143
+ expect(buildCreateAccountOperation).toHaveBeenCalledWith('GRECIPIENT', 10000000n)
144
+ expect(txBuilder.addOperation).toHaveBeenCalledWith('create-account-op')
145
+ })
146
+ })
@@ -1,55 +1,58 @@
1
- import { NetworkDown } from "@ledgerhq/errors";
1
+ // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { NetworkDown } from '@ledgerhq/errors'
2
5
  import {
3
6
  Memo,
4
7
  Operation as StellarSdkOperation,
5
8
  Transaction as StellarSdkTransaction,
6
9
  xdr,
7
- } from "@stellar/stellar-sdk";
8
- import { getRecipientAccount, loadAccount } from "../network";
9
- import { StellarAssetRequired, StellarMuxedAccountNotExist } from "../types";
10
+ } from '@stellar/stellar-sdk'
11
+ import { getRecipientAccount, loadAccount } from '../network'
12
+ import { StellarAssetRequired, StellarMuxedAccountNotExist } from '../types'
10
13
  import {
11
14
  buildChangeTrustOperation,
12
15
  buildCreateAccountOperation,
13
16
  buildPaymentOperation,
14
17
  buildTransactionBuilder,
15
- } from "./sdkWrapper";
18
+ } from './sdkWrapper'
16
19
 
17
20
  export async function craftTransaction(
18
21
  account: {
19
- address: string;
22
+ address: string
20
23
  },
21
24
  transaction: {
22
- type: string;
23
- recipient: string;
24
- amount: bigint;
25
- fee: bigint;
26
- assetCode?: string | undefined;
27
- assetIssuer?: string | undefined;
28
- memoType?: string | null | undefined;
29
- memoValue?: string | null | undefined;
30
- },
25
+ type: string
26
+ recipient: string
27
+ amount: bigint
28
+ fee: bigint
29
+ assetCode?: string | undefined
30
+ assetIssuer?: string | undefined
31
+ memoType?: string | null | undefined
32
+ memoValue?: string | null | undefined
33
+ }
31
34
  ): Promise<{ transaction: StellarSdkTransaction; xdr: string; signatureBase: string }> {
32
- const { amount, recipient, fee, memoType, memoValue, type, assetCode, assetIssuer } = transaction;
33
- const source = await loadAccount(account.address);
35
+ const { amount, recipient, fee, memoType, memoValue, type, assetCode, assetIssuer } = transaction
36
+ const source = await loadAccount(account.address)
34
37
 
35
38
  if (!source) {
36
- throw new NetworkDown();
39
+ throw new NetworkDown()
37
40
  }
38
41
 
39
- const transactionBuilder = buildTransactionBuilder(source, fee);
40
- let operation: xdr.Operation<StellarSdkOperation.ChangeTrust> | null = null;
42
+ const transactionBuilder = buildTransactionBuilder(source, fee)
43
+ let operation: xdr.Operation<StellarSdkOperation.ChangeTrust> | null = null
41
44
 
42
- if (type === "changeTrust") {
45
+ if (type === 'changeTrust') {
43
46
  if (!assetCode || !assetIssuer) {
44
- throw new StellarAssetRequired("");
47
+ throw new StellarAssetRequired('')
45
48
  }
46
49
 
47
- operation = buildChangeTrustOperation(assetCode, assetIssuer);
50
+ operation = buildChangeTrustOperation(assetCode, assetIssuer)
48
51
  } else {
49
52
  // Payment
50
53
  const recipientAccount = await getRecipientAccount({
51
54
  recipient,
52
- });
55
+ })
53
56
 
54
57
  if (recipientAccount?.id) {
55
58
  operation = buildPaymentOperation({
@@ -57,46 +60,46 @@ export async function craftTransaction(
57
60
  amount,
58
61
  assetCode,
59
62
  assetIssuer,
60
- });
63
+ })
61
64
  } else {
62
65
  if (recipientAccount?.isMuxedAccount) {
63
- throw new StellarMuxedAccountNotExist("");
66
+ throw new StellarMuxedAccountNotExist('')
64
67
  }
65
68
 
66
- operation = buildCreateAccountOperation(recipient, amount);
69
+ operation = buildCreateAccountOperation(recipient, amount)
67
70
  }
68
71
  }
69
72
 
70
- transactionBuilder.addOperation(operation);
73
+ transactionBuilder.addOperation(operation)
71
74
 
72
- const memo = buildMemo(memoType, memoValue);
75
+ const memo = buildMemo(memoType, memoValue)
73
76
  if (memo) {
74
- transactionBuilder.addMemo(memo);
77
+ transactionBuilder.addMemo(memo)
75
78
  }
76
79
 
77
- const craftedTransaction = transactionBuilder.setTimeout(0).build();
80
+ const craftedTransaction = transactionBuilder.setTimeout(0).build()
78
81
  return {
79
82
  transaction: craftedTransaction,
80
83
  xdr: craftedTransaction.toXDR(),
81
- signatureBase: craftedTransaction.signatureBase().toString("base64"),
82
- };
84
+ signatureBase: craftedTransaction.signatureBase().toString('base64'),
85
+ }
83
86
  }
84
87
 
85
88
  function buildMemo(
86
89
  memoType?: string | null | undefined,
87
- memoValue?: string | null | undefined,
90
+ memoValue?: string | null | undefined
88
91
  ): Memo | null {
89
92
  if (memoType && memoValue) {
90
93
  switch (memoType) {
91
- case "MEMO_TEXT":
92
- return Memo.text(memoValue);
93
- case "MEMO_ID":
94
- return Memo.id(memoValue);
95
- case "MEMO_HASH":
96
- return Memo.hash(memoValue);
97
- case "MEMO_RETURN":
98
- return Memo.return(memoValue);
94
+ case 'MEMO_TEXT':
95
+ return Memo.text(memoValue)
96
+ case 'MEMO_ID':
97
+ return Memo.id(memoValue)
98
+ case 'MEMO_HASH':
99
+ return Memo.hash(memoValue)
100
+ case 'MEMO_RETURN':
101
+ return Memo.return(memoValue)
99
102
  }
100
103
  }
101
- return null;
104
+ return null
102
105
  }
@@ -1,10 +1,13 @@
1
- import { fetchBaseFee } from "../network";
1
+ // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { fetchBaseFee } from '../network'
2
5
 
3
6
  /**
4
7
  * Estimate the fees for one transaction
5
8
  * @see {@link https://developers.stellar.org/docs/learn/fundamentals/fees-resource-limits-metering#inclusion-fee}
6
9
  */
7
10
  export async function estimateFees(): Promise<bigint> {
8
- const baseFee = await fetchBaseFee();
9
- return BigInt(baseFee.recommendedFee);
11
+ const baseFee = await fetchBaseFee()
12
+ return BigInt(baseFee.recommendedFee)
10
13
  }
@@ -1,61 +1,64 @@
1
- import { fetchAccount } from "../network";
2
- import { getBalance } from "./getBalance";
1
+ // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
+ // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- jest.mock("../network", () => ({
4
+ import { fetchAccount } from '../network'
5
+ import { getBalance } from './getBalance'
6
+
7
+ jest.mock('../network', () => ({
5
8
  fetchAccount: jest.fn(),
6
- }));
9
+ }))
7
10
 
8
- describe("getBalance", () => {
9
- it("returns native balance when no assets are present", async () => {
10
- (fetchAccount as jest.Mock).mockResolvedValue({
11
+ describe('getBalance', () => {
12
+ it('returns native balance when no assets are present', async () => {
13
+ ;(fetchAccount as jest.Mock).mockResolvedValue({
11
14
  balance: 100000000,
12
15
  spendableBalance: 99999990,
13
16
  assets: [],
14
- });
17
+ })
15
18
 
16
- const result = await getBalance("test-address");
19
+ const result = await getBalance('test-address')
17
20
 
18
21
  expect(result).toEqual([
19
22
  {
20
23
  value: BigInt(100000000),
21
- asset: { type: "native" },
24
+ asset: { type: 'native' },
22
25
  locked: BigInt(10),
23
26
  },
24
- ]);
25
- });
27
+ ])
28
+ })
26
29
 
27
- it("returns native and asset balances when assets are present", async () => {
28
- (fetchAccount as jest.Mock).mockResolvedValue({
30
+ it('returns native and asset balances when assets are present', async () => {
31
+ ;(fetchAccount as jest.Mock).mockResolvedValue({
29
32
  balance: 100000000,
30
33
  spendableBalance: 99999990,
31
34
  assets: [
32
35
  {
33
- asset_type: "credit_alphanum4",
34
- asset_code: "USDC",
35
- asset_issuer: "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN",
36
- balance: "50.1234567",
36
+ asset_type: 'credit_alphanum4',
37
+ asset_code: 'USDC',
38
+ asset_issuer: 'GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN',
39
+ balance: '50.1234567',
37
40
  },
38
41
  ],
39
- });
42
+ })
40
43
 
41
- const result = await getBalance("test-address");
44
+ const result = await getBalance('test-address')
42
45
 
43
46
  expect(result).toEqual([
44
47
  {
45
48
  value: BigInt(100000000),
46
- asset: { type: "native" },
49
+ asset: { type: 'native' },
47
50
  locked: BigInt(10),
48
51
  },
49
52
  {
50
53
  value: BigInt(501234567),
51
54
  asset: {
52
- type: "credit_alphanum4",
53
- assetReference: "USDC",
54
- assetOwner: "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN",
55
+ type: 'credit_alphanum4',
56
+ assetReference: 'USDC',
57
+ assetOwner: 'GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN',
55
58
  },
56
59
  },
57
- ]);
60
+ ])
58
61
 
59
- expect(fetchAccount).toHaveBeenCalledWith("test-address");
60
- });
61
- });
62
+ expect(fetchAccount).toHaveBeenCalledWith('test-address')
63
+ })
64
+ })