@ledgerhq/live-common 34.37.0-nightly.4 → 34.38.0-next.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.
Files changed (250) hide show
  1. package/lib/__tests__/test-helpers/bridge.d.ts.map +1 -1
  2. package/lib/__tests__/test-helpers/bridge.js +4 -4
  3. package/lib/__tests__/test-helpers/bridge.js.map +1 -1
  4. package/lib/bridge/impl.d.ts.map +1 -1
  5. package/lib/bridge/impl.js +3 -59
  6. package/lib/bridge/impl.js.map +1 -1
  7. package/lib/config/index.d.ts +2 -3
  8. package/lib/config/index.d.ts.map +1 -1
  9. package/lib/config/index.js +1 -9
  10. package/lib/config/index.js.map +1 -1
  11. package/lib/config/sharedConfig.d.ts.map +1 -1
  12. package/lib/config/sharedConfig.js +0 -7
  13. package/lib/config/sharedConfig.js.map +1 -1
  14. package/lib/families/xrp/setup.d.ts +6 -3
  15. package/lib/families/xrp/setup.d.ts.map +1 -1
  16. package/lib/families/xrp/setup.js +7 -1
  17. package/lib/families/xrp/setup.js.map +1 -1
  18. package/lib/featureFlags/stakePrograms/index.d.ts +8 -2
  19. package/lib/featureFlags/stakePrograms/index.d.ts.map +1 -1
  20. package/lib/featureFlags/stakePrograms/index.js +3 -2
  21. package/lib/featureFlags/stakePrograms/index.js.map +1 -1
  22. package/lib/featureFlags/stakePrograms/index.test.js +4 -4
  23. package/lib/featureFlags/stakePrograms/index.test.js.map +1 -1
  24. package/lib/generated/bridge/js.d.ts +1 -0
  25. package/lib/generated/bridge/js.d.ts.map +1 -1
  26. package/lib/generated/bridge/js.js +6 -4
  27. package/lib/generated/bridge/js.js.map +1 -1
  28. package/lib/hw/connectAppEventMapper.d.ts.map +1 -1
  29. package/lib/hw/connectAppEventMapper.js +4 -4
  30. package/lib/hw/connectAppEventMapper.js.map +1 -1
  31. package/lib-es/__tests__/test-helpers/bridge.d.ts.map +1 -1
  32. package/lib-es/__tests__/test-helpers/bridge.js +4 -4
  33. package/lib-es/__tests__/test-helpers/bridge.js.map +1 -1
  34. package/lib-es/bridge/impl.d.ts.map +1 -1
  35. package/lib-es/bridge/impl.js +3 -59
  36. package/lib-es/bridge/impl.js.map +1 -1
  37. package/lib-es/config/index.d.ts +2 -3
  38. package/lib-es/config/index.d.ts.map +1 -1
  39. package/lib-es/config/index.js +1 -8
  40. package/lib-es/config/index.js.map +1 -1
  41. package/lib-es/config/sharedConfig.d.ts.map +1 -1
  42. package/lib-es/config/sharedConfig.js +0 -7
  43. package/lib-es/config/sharedConfig.js.map +1 -1
  44. package/lib-es/families/xrp/setup.d.ts +6 -3
  45. package/lib-es/families/xrp/setup.d.ts.map +1 -1
  46. package/lib-es/families/xrp/setup.js +7 -2
  47. package/lib-es/families/xrp/setup.js.map +1 -1
  48. package/lib-es/featureFlags/stakePrograms/index.d.ts +8 -2
  49. package/lib-es/featureFlags/stakePrograms/index.d.ts.map +1 -1
  50. package/lib-es/featureFlags/stakePrograms/index.js +3 -2
  51. package/lib-es/featureFlags/stakePrograms/index.js.map +1 -1
  52. package/lib-es/featureFlags/stakePrograms/index.test.js +4 -4
  53. package/lib-es/featureFlags/stakePrograms/index.test.js.map +1 -1
  54. package/lib-es/generated/bridge/js.d.ts +1 -0
  55. package/lib-es/generated/bridge/js.d.ts.map +1 -1
  56. package/lib-es/generated/bridge/js.js +2 -0
  57. package/lib-es/generated/bridge/js.js.map +1 -1
  58. package/lib-es/hw/connectAppEventMapper.d.ts.map +1 -1
  59. package/lib-es/hw/connectAppEventMapper.js +5 -5
  60. package/lib-es/hw/connectAppEventMapper.js.map +1 -1
  61. package/package.json +66 -66
  62. package/src/__tests__/test-helpers/bridge.ts +4 -2
  63. package/src/bridge/impl.ts +5 -87
  64. package/src/config/index.ts +2 -11
  65. package/src/config/sharedConfig.ts +0 -8
  66. package/src/families/xrp/setup.ts +15 -2
  67. package/src/featureFlags/stakePrograms/index.test.ts +4 -4
  68. package/src/featureFlags/stakePrograms/index.ts +5 -6
  69. package/src/generated/bridge/js.ts +2 -0
  70. package/src/hw/connectAppEventMapper.ts +4 -4
  71. package/lib/bridge/generic-alpaca/accountBridge.d.ts +0 -3
  72. package/lib/bridge/generic-alpaca/accountBridge.d.ts.map +0 -1
  73. package/lib/bridge/generic-alpaca/accountBridge.js +0 -34
  74. package/lib/bridge/generic-alpaca/accountBridge.js.map +0 -1
  75. package/lib/bridge/generic-alpaca/alpaca/index.d.ts +0 -3
  76. package/lib/bridge/generic-alpaca/alpaca/index.d.ts.map +0 -1
  77. package/lib/bridge/generic-alpaca/alpaca/index.js +0 -20
  78. package/lib/bridge/generic-alpaca/alpaca/index.js.map +0 -1
  79. package/lib/bridge/generic-alpaca/alpaca/network/network-alpaca.d.ts +0 -16
  80. package/lib/bridge/generic-alpaca/alpaca/network/network-alpaca.d.ts.map +0 -1
  81. package/lib/bridge/generic-alpaca/alpaca/network/network-alpaca.js +0 -123
  82. package/lib/bridge/generic-alpaca/alpaca/network/network-alpaca.js.map +0 -1
  83. package/lib/bridge/generic-alpaca/broadcast.d.ts +0 -3
  84. package/lib/bridge/generic-alpaca/broadcast.d.ts.map +0 -1
  85. package/lib/bridge/generic-alpaca/broadcast.js +0 -11
  86. package/lib/bridge/generic-alpaca/broadcast.js.map +0 -1
  87. package/lib/bridge/generic-alpaca/createTransaction.d.ts +0 -16
  88. package/lib/bridge/generic-alpaca/createTransaction.d.ts.map +0 -1
  89. package/lib/bridge/generic-alpaca/createTransaction.js +0 -20
  90. package/lib/bridge/generic-alpaca/createTransaction.js.map +0 -1
  91. package/lib/bridge/generic-alpaca/currencyBridge.d.ts +0 -3
  92. package/lib/bridge/generic-alpaca/currencyBridge.d.ts.map +0 -1
  93. package/lib/bridge/generic-alpaca/currencyBridge.js +0 -20
  94. package/lib/bridge/generic-alpaca/currencyBridge.js.map +0 -1
  95. package/lib/bridge/generic-alpaca/estimateMaxSpendable.d.ts +0 -3
  96. package/lib/bridge/generic-alpaca/estimateMaxSpendable.d.ts.map +0 -1
  97. package/lib/bridge/generic-alpaca/estimateMaxSpendable.js +0 -26
  98. package/lib/bridge/generic-alpaca/estimateMaxSpendable.js.map +0 -1
  99. package/lib/bridge/generic-alpaca/getAccountShape.d.ts +0 -3
  100. package/lib/bridge/generic-alpaca/getAccountShape.d.ts.map +0 -1
  101. package/lib/bridge/generic-alpaca/getAccountShape.js +0 -58
  102. package/lib/bridge/generic-alpaca/getAccountShape.js.map +0 -1
  103. package/lib/bridge/generic-alpaca/getTransactionStatus.d.ts +0 -3
  104. package/lib/bridge/generic-alpaca/getTransactionStatus.d.ts.map +0 -1
  105. package/lib/bridge/generic-alpaca/getTransactionStatus.js +0 -36
  106. package/lib/bridge/generic-alpaca/getTransactionStatus.js.map +0 -1
  107. package/lib/bridge/generic-alpaca/prepareTransaction.d.ts +0 -3
  108. package/lib/bridge/generic-alpaca/prepareTransaction.d.ts.map +0 -1
  109. package/lib/bridge/generic-alpaca/prepareTransaction.js +0 -21
  110. package/lib/bridge/generic-alpaca/prepareTransaction.js.map +0 -1
  111. package/lib/bridge/generic-alpaca/signOperation.d.ts +0 -7
  112. package/lib/bridge/generic-alpaca/signOperation.d.ts.map +0 -1
  113. package/lib/bridge/generic-alpaca/signOperation.js +0 -49
  114. package/lib/bridge/generic-alpaca/signOperation.js.map +0 -1
  115. package/lib/bridge/generic-alpaca/signer/index.d.ts +0 -11
  116. package/lib/bridge/generic-alpaca/signer/index.d.ts.map +0 -1
  117. package/lib/bridge/generic-alpaca/signer/index.js +0 -28
  118. package/lib/bridge/generic-alpaca/signer/index.js.map +0 -1
  119. package/lib/bridge/generic-alpaca/signer/signTransaction.d.ts +0 -5
  120. package/lib/bridge/generic-alpaca/signer/signTransaction.d.ts.map +0 -1
  121. package/lib/bridge/generic-alpaca/signer/signTransaction.js +0 -11
  122. package/lib/bridge/generic-alpaca/signer/signTransaction.js.map +0 -1
  123. package/lib/bridge/generic-alpaca/signer/types.d.ts +0 -5
  124. package/lib/bridge/generic-alpaca/signer/types.d.ts.map +0 -1
  125. package/lib/bridge/generic-alpaca/signer/types.js +0 -3
  126. package/lib/bridge/generic-alpaca/signer/types.js.map +0 -1
  127. package/lib/bridge/generic-alpaca/tests/estimateMaxSpendable.test.d.ts +0 -2
  128. package/lib/bridge/generic-alpaca/tests/estimateMaxSpendable.test.d.ts.map +0 -1
  129. package/lib/bridge/generic-alpaca/tests/estimateMaxSpendable.test.js +0 -90
  130. package/lib/bridge/generic-alpaca/tests/estimateMaxSpendable.test.js.map +0 -1
  131. package/lib/bridge/generic-alpaca/tests/prepareTransaction.test.d.ts +0 -2
  132. package/lib/bridge/generic-alpaca/tests/prepareTransaction.test.d.ts.map +0 -1
  133. package/lib/bridge/generic-alpaca/tests/prepareTransaction.test.js +0 -53
  134. package/lib/bridge/generic-alpaca/tests/prepareTransaction.test.js.map +0 -1
  135. package/lib/bridge/generic-alpaca/tests/signOperation.test.d.ts +0 -2
  136. package/lib/bridge/generic-alpaca/tests/signOperation.test.d.ts.map +0 -1
  137. package/lib/bridge/generic-alpaca/tests/signOperation.test.js +0 -79
  138. package/lib/bridge/generic-alpaca/tests/signOperation.test.js.map +0 -1
  139. package/lib/bridge/generic-alpaca/utils.d.ts +0 -6
  140. package/lib/bridge/generic-alpaca/utils.d.ts.map +0 -1
  141. package/lib/bridge/generic-alpaca/utils.js +0 -55
  142. package/lib/bridge/generic-alpaca/utils.js.map +0 -1
  143. package/lib/sanction/errors.d.ts +0 -13
  144. package/lib/sanction/errors.d.ts.map +0 -1
  145. package/lib/sanction/errors.js +0 -36
  146. package/lib/sanction/errors.js.map +0 -1
  147. package/lib/sanction/index.d.ts +0 -3
  148. package/lib/sanction/index.d.ts.map +0 -1
  149. package/lib/sanction/index.js +0 -51
  150. package/lib/sanction/index.js.map +0 -1
  151. package/lib-es/bridge/generic-alpaca/accountBridge.d.ts +0 -3
  152. package/lib-es/bridge/generic-alpaca/accountBridge.d.ts.map +0 -1
  153. package/lib-es/bridge/generic-alpaca/accountBridge.js +0 -27
  154. package/lib-es/bridge/generic-alpaca/accountBridge.js.map +0 -1
  155. package/lib-es/bridge/generic-alpaca/alpaca/index.d.ts +0 -3
  156. package/lib-es/bridge/generic-alpaca/alpaca/index.d.ts.map +0 -1
  157. package/lib-es/bridge/generic-alpaca/alpaca/index.js +0 -16
  158. package/lib-es/bridge/generic-alpaca/alpaca/index.js.map +0 -1
  159. package/lib-es/bridge/generic-alpaca/alpaca/network/network-alpaca.d.ts +0 -16
  160. package/lib-es/bridge/generic-alpaca/alpaca/network/network-alpaca.d.ts.map +0 -1
  161. package/lib-es/bridge/generic-alpaca/alpaca/network/network-alpaca.js +0 -116
  162. package/lib-es/bridge/generic-alpaca/alpaca/network/network-alpaca.js.map +0 -1
  163. package/lib-es/bridge/generic-alpaca/broadcast.d.ts +0 -3
  164. package/lib-es/bridge/generic-alpaca/broadcast.d.ts.map +0 -1
  165. package/lib-es/bridge/generic-alpaca/broadcast.js +0 -7
  166. package/lib-es/bridge/generic-alpaca/broadcast.js.map +0 -1
  167. package/lib-es/bridge/generic-alpaca/createTransaction.d.ts +0 -16
  168. package/lib-es/bridge/generic-alpaca/createTransaction.d.ts.map +0 -1
  169. package/lib-es/bridge/generic-alpaca/createTransaction.js +0 -13
  170. package/lib-es/bridge/generic-alpaca/createTransaction.js.map +0 -1
  171. package/lib-es/bridge/generic-alpaca/currencyBridge.d.ts +0 -3
  172. package/lib-es/bridge/generic-alpaca/currencyBridge.d.ts.map +0 -1
  173. package/lib-es/bridge/generic-alpaca/currencyBridge.js +0 -16
  174. package/lib-es/bridge/generic-alpaca/currencyBridge.js.map +0 -1
  175. package/lib-es/bridge/generic-alpaca/estimateMaxSpendable.d.ts +0 -3
  176. package/lib-es/bridge/generic-alpaca/estimateMaxSpendable.d.ts.map +0 -1
  177. package/lib-es/bridge/generic-alpaca/estimateMaxSpendable.js +0 -19
  178. package/lib-es/bridge/generic-alpaca/estimateMaxSpendable.js.map +0 -1
  179. package/lib-es/bridge/generic-alpaca/getAccountShape.d.ts +0 -3
  180. package/lib-es/bridge/generic-alpaca/getAccountShape.d.ts.map +0 -1
  181. package/lib-es/bridge/generic-alpaca/getAccountShape.js +0 -51
  182. package/lib-es/bridge/generic-alpaca/getAccountShape.js.map +0 -1
  183. package/lib-es/bridge/generic-alpaca/getTransactionStatus.d.ts +0 -3
  184. package/lib-es/bridge/generic-alpaca/getTransactionStatus.d.ts.map +0 -1
  185. package/lib-es/bridge/generic-alpaca/getTransactionStatus.js +0 -29
  186. package/lib-es/bridge/generic-alpaca/getTransactionStatus.js.map +0 -1
  187. package/lib-es/bridge/generic-alpaca/prepareTransaction.d.ts +0 -3
  188. package/lib-es/bridge/generic-alpaca/prepareTransaction.d.ts.map +0 -1
  189. package/lib-es/bridge/generic-alpaca/prepareTransaction.js +0 -14
  190. package/lib-es/bridge/generic-alpaca/prepareTransaction.js.map +0 -1
  191. package/lib-es/bridge/generic-alpaca/signOperation.d.ts +0 -7
  192. package/lib-es/bridge/generic-alpaca/signOperation.d.ts.map +0 -1
  193. package/lib-es/bridge/generic-alpaca/signOperation.js +0 -45
  194. package/lib-es/bridge/generic-alpaca/signOperation.js.map +0 -1
  195. package/lib-es/bridge/generic-alpaca/signer/index.d.ts +0 -11
  196. package/lib-es/bridge/generic-alpaca/signer/index.d.ts.map +0 -1
  197. package/lib-es/bridge/generic-alpaca/signer/index.js +0 -21
  198. package/lib-es/bridge/generic-alpaca/signer/index.js.map +0 -1
  199. package/lib-es/bridge/generic-alpaca/signer/signTransaction.d.ts +0 -5
  200. package/lib-es/bridge/generic-alpaca/signer/signTransaction.d.ts.map +0 -1
  201. package/lib-es/bridge/generic-alpaca/signer/signTransaction.js +0 -7
  202. package/lib-es/bridge/generic-alpaca/signer/signTransaction.js.map +0 -1
  203. package/lib-es/bridge/generic-alpaca/signer/types.d.ts +0 -5
  204. package/lib-es/bridge/generic-alpaca/signer/types.d.ts.map +0 -1
  205. package/lib-es/bridge/generic-alpaca/signer/types.js +0 -2
  206. package/lib-es/bridge/generic-alpaca/signer/types.js.map +0 -1
  207. package/lib-es/bridge/generic-alpaca/tests/estimateMaxSpendable.test.d.ts +0 -2
  208. package/lib-es/bridge/generic-alpaca/tests/estimateMaxSpendable.test.d.ts.map +0 -1
  209. package/lib-es/bridge/generic-alpaca/tests/estimateMaxSpendable.test.js +0 -62
  210. package/lib-es/bridge/generic-alpaca/tests/estimateMaxSpendable.test.js.map +0 -1
  211. package/lib-es/bridge/generic-alpaca/tests/prepareTransaction.test.d.ts +0 -2
  212. package/lib-es/bridge/generic-alpaca/tests/prepareTransaction.test.d.ts.map +0 -1
  213. package/lib-es/bridge/generic-alpaca/tests/prepareTransaction.test.js +0 -48
  214. package/lib-es/bridge/generic-alpaca/tests/prepareTransaction.test.js.map +0 -1
  215. package/lib-es/bridge/generic-alpaca/tests/signOperation.test.d.ts +0 -2
  216. package/lib-es/bridge/generic-alpaca/tests/signOperation.test.d.ts.map +0 -1
  217. package/lib-es/bridge/generic-alpaca/tests/signOperation.test.js +0 -77
  218. package/lib-es/bridge/generic-alpaca/tests/signOperation.test.js.map +0 -1
  219. package/lib-es/bridge/generic-alpaca/utils.d.ts +0 -6
  220. package/lib-es/bridge/generic-alpaca/utils.d.ts.map +0 -1
  221. package/lib-es/bridge/generic-alpaca/utils.js +0 -46
  222. package/lib-es/bridge/generic-alpaca/utils.js.map +0 -1
  223. package/lib-es/sanction/errors.d.ts +0 -13
  224. package/lib-es/sanction/errors.d.ts.map +0 -1
  225. package/lib-es/sanction/errors.js +0 -29
  226. package/lib-es/sanction/errors.js.map +0 -1
  227. package/lib-es/sanction/index.d.ts +0 -3
  228. package/lib-es/sanction/index.d.ts.map +0 -1
  229. package/lib-es/sanction/index.js +0 -44
  230. package/lib-es/sanction/index.js.map +0 -1
  231. package/src/bridge/generic-alpaca/accountBridge.ts +0 -32
  232. package/src/bridge/generic-alpaca/alpaca/index.ts +0 -20
  233. package/src/bridge/generic-alpaca/alpaca/network/network-alpaca.ts +0 -182
  234. package/src/bridge/generic-alpaca/broadcast.ts +0 -11
  235. package/src/bridge/generic-alpaca/createTransaction.ts +0 -27
  236. package/src/bridge/generic-alpaca/currencyBridge.ts +0 -17
  237. package/src/bridge/generic-alpaca/estimateMaxSpendable.ts +0 -27
  238. package/src/bridge/generic-alpaca/getAccountShape.ts +0 -62
  239. package/src/bridge/generic-alpaca/getTransactionStatus.ts +0 -38
  240. package/src/bridge/generic-alpaca/prepareTransaction.ts +0 -22
  241. package/src/bridge/generic-alpaca/signOperation.ts +0 -83
  242. package/src/bridge/generic-alpaca/signer/index.ts +0 -33
  243. package/src/bridge/generic-alpaca/signer/signTransaction.ts +0 -13
  244. package/src/bridge/generic-alpaca/signer/types.ts +0 -4
  245. package/src/bridge/generic-alpaca/tests/estimateMaxSpendable.test.ts +0 -76
  246. package/src/bridge/generic-alpaca/tests/prepareTransaction.test.ts +0 -66
  247. package/src/bridge/generic-alpaca/tests/signOperation.test.ts +0 -96
  248. package/src/bridge/generic-alpaca/utils.ts +0 -63
  249. package/src/sanction/errors.ts +0 -31
  250. package/src/sanction/index.ts +0 -59
@@ -1,27 +0,0 @@
1
- import { AccountBridge } from "@ledgerhq/types-live";
2
- import { getMainAccount } from "../../account";
3
- import { getAlpacaApi } from "./alpaca";
4
- import { createTransaction } from "./createTransaction";
5
- import { transactionToIntent } from "./utils";
6
- import BigNumber from "bignumber.js";
7
-
8
- export function genericEstimateMaxSpendable(
9
- network,
10
- kind,
11
- ): AccountBridge<any>["estimateMaxSpendable"] {
12
- return async ({ account, parentAccount, transaction }) => {
13
- const mainAccount = getMainAccount(account, parentAccount);
14
-
15
- const draftTransaction = {
16
- ...createTransaction(account as any),
17
- ...transaction,
18
- amount: mainAccount.spendableBalance,
19
- };
20
- const fees = await getAlpacaApi(network, kind).estimateFees(
21
- transactionToIntent(mainAccount, draftTransaction),
22
- );
23
-
24
- const bnFee = BigNumber(fees.value.toString());
25
- return BigNumber.max(0, account.spendableBalance.minus(bnFee));
26
- };
27
- }
@@ -1,62 +0,0 @@
1
- import { encodeAccountId } from "@ledgerhq/coin-framework/account/index";
2
- import { GetAccountShape, mergeOps } from "@ledgerhq/coin-framework/bridge/jsHelpers";
3
- import BigNumber from "bignumber.js";
4
- import { getAlpacaApi } from "./alpaca";
5
- import { adaptCoreOperationToLiveOperation } from "./utils";
6
-
7
- export function genericGetAccountShape(network, kind): GetAccountShape {
8
- return async info => {
9
- try {
10
- const { address, initialAccount, currency, derivationMode } = info;
11
- const accountId = encodeAccountId({
12
- type: "js",
13
- version: "2",
14
- currencyId: currency.id,
15
- xpubOrAddress: address,
16
- derivationMode,
17
- });
18
-
19
- const blockInfo = await getAlpacaApi(network, kind).lastBlock();
20
-
21
- const balanceRes = await getAlpacaApi(network, kind).getBalance(address);
22
- // FIXME: fix type Balance -> check "native" balance
23
- // is balance[0] always the native ?
24
- const balance = BigNumber(balanceRes[0].value.toString());
25
-
26
- let spendableBalance: BigNumber;
27
- if (balanceRes[0]?.locked) {
28
- spendableBalance = BigNumber.max(
29
- balance.minus(BigNumber(balanceRes[0].locked.toString())),
30
- BigNumber(0),
31
- );
32
- } else {
33
- spendableBalance = initialAccount?.spendableBalance || balance;
34
- }
35
- const oldOperations = initialAccount?.operations || [];
36
-
37
- const blockHeight = oldOperations.length ? (oldOperations[0].blockHeight ?? 0) + 1 : 0;
38
-
39
- const [newOperations, _] = await getAlpacaApi(network, kind).listOperations(address, {
40
- minHeight: blockHeight,
41
- });
42
-
43
- const operations = mergeOps(
44
- oldOperations,
45
- newOperations.map(op => adaptCoreOperationToLiveOperation(accountId, op)),
46
- );
47
-
48
- return {
49
- id: accountId,
50
- xpub: address,
51
- blockHeight: initialAccount?.blockHeight || blockInfo.height,
52
- balance,
53
- spendableBalance,
54
- operations,
55
- operationsCount: operations.length,
56
- };
57
- } catch (e) {
58
- console.error("Error in getAccountShape", e);
59
- throw e;
60
- }
61
- };
62
- }
@@ -1,38 +0,0 @@
1
- import { AccountBridge, TransactionCommon } from "@ledgerhq/types-live";
2
- import BigNumber from "bignumber.js";
3
- import { getAlpacaApi } from "./alpaca";
4
-
5
- // => alpaca validateIntent
6
- export function genericGetTransactionStatus(
7
- network,
8
- kind,
9
- ): AccountBridge<any>["getTransactionStatus"] {
10
- return async (account, transaction: TransactionCommon & { fees: BigNumber }) => {
11
- const { freshAddress, balance, currency } = account;
12
- const alpacaApi = getAlpacaApi(network, kind);
13
- const { errors, warnings } = await alpacaApi.validateIntent(
14
- {
15
- currencyName: currency.name,
16
- address: freshAddress,
17
- balance: BigInt(balance.toString()),
18
- currencyUnit: currency.units[0],
19
- },
20
- {
21
- type: "PAYMENT", // NOTE: assuming payment by default here
22
- recipient: transaction.recipient,
23
- amount: BigInt(transaction.amount?.toString() ?? "0"),
24
- fee: BigInt(transaction.fees?.toString() ?? "0"),
25
- },
26
- );
27
-
28
- const estimatedFees = transaction.fees || new BigNumber(0);
29
-
30
- return Promise.resolve({
31
- errors,
32
- warnings,
33
- estimatedFees,
34
- amount: transaction.amount,
35
- totalSpent: transaction.amount.plus(transaction.fees),
36
- });
37
- };
38
- }
@@ -1,22 +0,0 @@
1
- import { Account, AccountBridge, TransactionCommon } from "@ledgerhq/types-live";
2
- import { getAlpacaApi } from "./alpaca";
3
- import { transactionToIntent } from "./utils";
4
- import BigNumber from "bignumber.js";
5
-
6
- export function genericPrepareTransaction(
7
- network,
8
- kind,
9
- ): AccountBridge<TransactionCommon, Account, any, any>["prepareTransaction"] {
10
- return async (_account, transaction: TransactionCommon & { fees: BigNumber }) => {
11
- const fees = await getAlpacaApi(network, kind).estimateFees(
12
- transactionToIntent(_account, transaction),
13
- );
14
- const bnFee = BigNumber(fees.value.toString());
15
-
16
- if (transaction.fees !== bnFee) {
17
- return { ...transaction, fees: bnFee };
18
- }
19
-
20
- return transaction;
21
- };
22
- }
@@ -1,83 +0,0 @@
1
- import { Observable } from "rxjs";
2
- import { SignerContext } from "@ledgerhq/coin-framework/signer";
3
- import type {
4
- Account,
5
- DeviceId,
6
- SignOperationEvent,
7
- AccountBridge,
8
- TransactionCommon,
9
- } from "@ledgerhq/types-live";
10
- import { getAlpacaApi } from "./alpaca";
11
- import { buildOptimisticOperation, transactionToIntent } from "./utils";
12
- import { FeeNotLoaded } from "@ledgerhq/errors";
13
- import { Result } from "@ledgerhq/coin-framework/derivation";
14
- import { MapMemo, TransactionIntent } from "@ledgerhq/coin-framework/api/types";
15
-
16
- /**
17
- * Sign Transaction with Ledger hardware
18
- */
19
- export const genericSignOperation =
20
- (network, kind) =>
21
- (signerContext: SignerContext<any>): AccountBridge<TransactionCommon>["signOperation"] =>
22
- ({
23
- account,
24
- transaction,
25
- deviceId,
26
- }: {
27
- account: Account;
28
- transaction: TransactionCommon;
29
- deviceId: DeviceId;
30
- }): Observable<SignOperationEvent> =>
31
- new Observable(o => {
32
- async function main() {
33
- if (!transaction["fees"]) throw new FeeNotLoaded();
34
- o.next({ type: "device-signature-requested" });
35
-
36
- const { publicKey } = (await signerContext(deviceId, signer =>
37
- signer.getAddress(account.freshAddressPath),
38
- )) as Result;
39
-
40
- const transactionIntent = transactionToIntent(account, transaction);
41
- transactionIntent.senderPublicKey = publicKey;
42
- // NOTE: is setting the memo here instead of transactionToIntent sensible?
43
- const txWithMemo = transactionIntent as TransactionIntent<any, MapMemo<string, string>>;
44
- if (transaction["tag"]) {
45
- const txMemo = String(transaction["tag"]);
46
- txWithMemo.memo = {
47
- type: "map",
48
- memos: new Map(),
49
- };
50
- txWithMemo.memo.memos.set("destinationTag", txMemo);
51
- }
52
-
53
- const unsigned = await getAlpacaApi(network, kind).craftTransaction({
54
- ...txWithMemo,
55
- });
56
- const transactionSignature: string = await signerContext(deviceId, signer =>
57
- signer.signTransaction(account.freshAddressPath, unsigned),
58
- );
59
- o.next({ type: "device-signature-granted" });
60
-
61
- const signed = await getAlpacaApi(network, kind).combine(
62
- unsigned,
63
- transactionSignature,
64
- publicKey,
65
- );
66
-
67
- const operation = buildOptimisticOperation(account, transaction);
68
- // NOTE: we set the transactionSequenceNumber before on the operation
69
- // now that we create it in craftTransaction, we might need to return it back from craftTransaction also
70
- o.next({
71
- type: "signed",
72
- signedOperation: {
73
- operation,
74
- signature: signed,
75
- },
76
- });
77
- }
78
-
79
- main().then(
80
- () => o.complete(),
81
- e => o.error(e),
82
- );
83
- });
@@ -1,33 +0,0 @@
1
- import { GetAddressFn } from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
2
- import xrpGetAddress from "@ledgerhq/coin-xrp/signer/getAddress";
3
- import { CreateSigner, executeWithSigner } from "../../setup";
4
- import Xrp from "@ledgerhq/hw-app-xrp";
5
-
6
- import Transport from "@ledgerhq/hw-transport";
7
- import { signTransaction } from "./signTransaction";
8
- import { SignerContext } from "@ledgerhq/coin-framework/signer";
9
- import { SignTransactionOptions } from "./types";
10
-
11
- export type AlpacaSigner = {
12
- getAddress: GetAddressFn;
13
- signTransaction?: (deviceId: string, opts: SignTransactionOptions) => Promise<string>;
14
- signMessage?: (message: string) => Promise<string>;
15
- context: SignerContext<any>;
16
- };
17
-
18
- export function getSigner(network): AlpacaSigner {
19
- switch (network) {
20
- case "ripple":
21
- case "xrp": {
22
- const createSigner: CreateSigner<Xrp> = (transport: Transport) => {
23
- return new Xrp(transport);
24
- };
25
- return {
26
- getAddress: xrpGetAddress(executeWithSigner(createSigner)),
27
- signTransaction: signTransaction(executeWithSigner(createSigner)),
28
- context: executeWithSigner(createSigner),
29
- };
30
- }
31
- }
32
- throw new Error(`signer for ${network} not implemented`);
33
- }
@@ -1,13 +0,0 @@
1
- import { SignerContext } from "@ledgerhq/coin-framework/signer";
2
- import { XrpSigner } from "@ledgerhq/coin-xrp/index";
3
- import { SignTransactionOptions } from "./types";
4
-
5
- export const signTransaction = (signerContext: SignerContext<XrpSigner>) => {
6
- return async (deviceId: string, { path, rawTxHex }: SignTransactionOptions) => {
7
- const signedTx = await signerContext(deviceId, signer =>
8
- signer.signTransaction(path, rawTxHex),
9
- );
10
-
11
- return signedTx;
12
- };
13
- };
@@ -1,4 +0,0 @@
1
- export type SignTransactionOptions = {
2
- rawTxHex: string;
3
- path: string;
4
- };
@@ -1,76 +0,0 @@
1
- import BigNumber from "bignumber.js";
2
- import { genericEstimateMaxSpendable } from "../estimateMaxSpendable";
3
- import * as alpaca from "../alpaca";
4
- import { Account } from "@ledgerhq/types-live";
5
-
6
- // Mock the alpaca API
7
- jest.mock("../alpaca", () => ({
8
- getAlpacaApi: jest.fn(),
9
- }));
10
-
11
- const mockedGetAlpacaApi = alpaca.getAlpacaApi as jest.Mock;
12
-
13
- // Dummy data
14
- const dummyAccount = {
15
- id: "js:2:ripple:r123:",
16
- type: "Account", // <-- this is mandatory for getMainAccount to work
17
- spendableBalance: new BigNumber(50000000),
18
- currency: { id: "ripple", name: "XRP", units: [{ name: "XRP", magnitude: 6 }] },
19
- freshAddress: "r123",
20
- } as unknown as Account;
21
-
22
- describe("genericEstimateMaxSpendable", () => {
23
- afterEach(() => {
24
- jest.clearAllMocks();
25
- });
26
-
27
- it("subtracts estimated fee from spendable balance", async () => {
28
- mockedGetAlpacaApi.mockReturnValue({
29
- estimateFees: jest.fn().mockResolvedValue({ value: 10000n }), // 0.01 XRP
30
- });
31
-
32
- const estimate = genericEstimateMaxSpendable("xrp", "local");
33
- const result = await estimate({
34
- account: dummyAccount,
35
- parentAccount: null,
36
- transaction: {},
37
- });
38
-
39
- expect(result.toString()).toBe("49990000"); // 50_000_000 - 10_000
40
- });
41
-
42
- it("returns 0 if fee is higher than spendable", async () => {
43
- const poorAccount = {
44
- ...dummyAccount,
45
- spendableBalance: new BigNumber(5000), // very low
46
- };
47
-
48
- mockedGetAlpacaApi.mockReturnValue({
49
- estimateFees: jest.fn().mockResolvedValue({ value: 10000n }),
50
- });
51
-
52
- const estimate = genericEstimateMaxSpendable("xrp", "local");
53
- const result = await estimate({
54
- account: poorAccount,
55
- parentAccount: null,
56
- transaction: {},
57
- });
58
-
59
- expect(result.toString()).toBe("0");
60
- });
61
-
62
- it("returns full spendable balance if fee is 0", async () => {
63
- mockedGetAlpacaApi.mockReturnValue({
64
- estimateFees: jest.fn().mockResolvedValue({ value: 0n }),
65
- });
66
-
67
- const estimate = genericEstimateMaxSpendable("xrp", "local");
68
- const result = await estimate({
69
- account: dummyAccount,
70
- parentAccount: null,
71
- transaction: {},
72
- });
73
-
74
- expect(result.toString()).toBe("50000000");
75
- });
76
- });
@@ -1,66 +0,0 @@
1
- import { genericPrepareTransaction } from "../prepareTransaction";
2
- import { getAlpacaApi } from "../alpaca";
3
- import { transactionToIntent } from "../utils";
4
- import BigNumber from "bignumber.js";
5
- import type { TransactionCommon } from "@ledgerhq/types-live";
6
-
7
- jest.mock("../alpaca", () => ({
8
- getAlpacaApi: jest.fn(),
9
- }));
10
-
11
- jest.mock("../utils", () => ({
12
- transactionToIntent: jest.fn(),
13
- }));
14
-
15
- describe("genericPrepareTransaction", () => {
16
- const network = "testnet";
17
- const kind = "local";
18
-
19
- const account = {
20
- id: "test-account",
21
- address: "0xabc",
22
- } as any;
23
-
24
- const baseTransaction: TransactionCommon & { fees: BigNumber } = {
25
- amount: new BigNumber(100_000),
26
- fees: new BigNumber(500),
27
- recipient: "0xrecipient",
28
- };
29
-
30
- const txIntent = { mock: "intent" };
31
-
32
- beforeEach(() => {
33
- jest.clearAllMocks();
34
- (transactionToIntent as jest.Mock).mockReturnValue(txIntent);
35
- });
36
-
37
- it("updates fees if they differ", async () => {
38
- const newFee = new BigNumber(700);
39
-
40
- (getAlpacaApi as jest.Mock).mockReturnValue({
41
- estimateFees: jest.fn().mockResolvedValue({ value: newFee }),
42
- });
43
-
44
- const prepareTransaction = genericPrepareTransaction(network, kind);
45
- const result = await prepareTransaction(account, { ...baseTransaction });
46
-
47
- expect((result as any).fees.toString()).toBe(newFee.toString());
48
- expect(transactionToIntent).toHaveBeenCalledWith(
49
- account,
50
- expect.objectContaining(baseTransaction),
51
- );
52
- });
53
-
54
- it("returns original transaction if fees are the same", async () => {
55
- const sameFee = baseTransaction.fees;
56
-
57
- (getAlpacaApi as jest.Mock).mockReturnValue({
58
- estimateFees: jest.fn().mockResolvedValue({ value: sameFee }),
59
- });
60
-
61
- const prepareTransaction = genericPrepareTransaction(network, kind);
62
- const result = await prepareTransaction(account, { ...baseTransaction });
63
-
64
- expect(result).toStrictEqual(baseTransaction);
65
- });
66
- });
@@ -1,96 +0,0 @@
1
- import { lastValueFrom } from "rxjs";
2
- import { toArray } from "rxjs/operators";
3
- import { genericSignOperation } from "../signOperation";
4
- import { FeeNotLoaded } from "@ledgerhq/errors";
5
- import { getAlpacaApi } from "../alpaca";
6
- import { buildOptimisticOperation, transactionToIntent } from "../utils";
7
-
8
- jest.mock("../alpaca", () => ({
9
- getAlpacaApi: jest.fn(),
10
- }));
11
-
12
- jest.mock("../utils", () => ({
13
- buildOptimisticOperation: jest.fn(),
14
- transactionToIntent: jest.fn(),
15
- }));
16
-
17
- describe("genericSignOperation", () => {
18
- const network = "xrp";
19
- const kind = "local";
20
-
21
- const mockSignerContext = jest.fn();
22
- const mockSigner = {
23
- getAddress: jest.fn(),
24
- signTransaction: jest.fn(),
25
- };
26
-
27
- const account = {
28
- freshAddressPath: "44'/144'/0'/0/0",
29
- address: "rTestAddress",
30
- } as any;
31
-
32
- const transaction = {
33
- amount: 100_000n,
34
- fees: 500n,
35
- tag: 1234,
36
- } as any;
37
-
38
- const deviceId = "mockDevice";
39
-
40
- const txIntent = {
41
- memo: {
42
- type: "map",
43
- memos: new Map(),
44
- },
45
- };
46
-
47
- const unsignedTx = "unsignedTx";
48
- const signedTx = "signedTx";
49
- const pubKey = "pubKey";
50
-
51
- beforeEach(() => {
52
- jest.clearAllMocks();
53
-
54
- (getAlpacaApi as jest.Mock).mockReturnValue({
55
- craftTransaction: jest.fn().mockResolvedValue(unsignedTx),
56
- combine: jest.fn().mockResolvedValue(signedTx),
57
- });
58
-
59
- (transactionToIntent as jest.Mock).mockReturnValue(txIntent);
60
- (buildOptimisticOperation as jest.Mock).mockReturnValue({ id: "mock-op" });
61
-
62
- mockSigner.getAddress.mockResolvedValue({ publicKey: pubKey });
63
- mockSigner.signTransaction.mockResolvedValue("sig");
64
- mockSignerContext.mockImplementation(async (_deviceId, cb) => cb(mockSigner));
65
- });
66
-
67
- it("emits full sign operation flow", async () => {
68
- const signOperation = genericSignOperation(network, kind)(mockSignerContext);
69
- const observable = signOperation({ account, transaction, deviceId });
70
-
71
- const events = await lastValueFrom(observable.pipe(toArray()));
72
-
73
- expect(events[0]).toEqual({ type: "device-signature-requested" });
74
- expect(events[1]).toEqual({ type: "device-signature-granted" });
75
- expect(events[2]).toEqual({
76
- type: "signed",
77
- signedOperation: {
78
- operation: { id: "mock-op" },
79
- signature: signedTx,
80
- },
81
- });
82
-
83
- expect(transactionToIntent).toHaveBeenCalledWith(account, transaction);
84
- expect(txIntent.memo.memos.get("destinationTag")).toBe("1234");
85
- });
86
-
87
- it("throws FeeNotLoaded if fees are missing", async () => {
88
- const txWithoutFees = { ...transaction };
89
- delete txWithoutFees.fees;
90
-
91
- const signOperation = genericSignOperation(network, kind)(mockSignerContext);
92
- const observable = signOperation({ account, transaction: txWithoutFees, deviceId });
93
-
94
- await expect(observable.toPromise()).rejects.toThrow(FeeNotLoaded);
95
- });
96
- });
@@ -1,63 +0,0 @@
1
- import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
2
- import { Account, Operation, OperationType, TransactionCommon } from "@ledgerhq/types-live";
3
- import {
4
- Operation as CoreOperation,
5
- Asset,
6
- TransactionIntent,
7
- } from "@ledgerhq/coin-framework/api/types";
8
- import BigNumber from "bignumber.js";
9
- import { fromBigNumberToBigInt } from "@ledgerhq/coin-framework/utils";
10
-
11
- export function adaptCoreOperationToLiveOperation(
12
- accountId: string,
13
- op: CoreOperation<Asset>,
14
- ): Operation {
15
- return {
16
- id: encodeOperationId(accountId, op.tx.hash, op.type),
17
- hash: op.tx.hash,
18
- accountId,
19
- type: op.type as OperationType,
20
- value: new BigNumber(op.value.toString()),
21
- fee: new BigNumber(op.tx.fees.toString()),
22
- blockHash: op.tx.block.hash,
23
- blockHeight: op.tx.block.height,
24
- senders: op.senders,
25
- recipients: op.recipients,
26
- date: op.tx.date,
27
- transactionSequenceNumber: op.details?.sequence as number,
28
- extra: {},
29
- };
30
- }
31
-
32
- export function transactionToIntent(
33
- _account: Account,
34
- transaction: TransactionCommon,
35
- ): TransactionIntent<any> {
36
- return {
37
- type: "Payment",
38
- sender: _account.freshAddress,
39
- recipient: transaction.recipient,
40
- amount: fromBigNumberToBigInt(transaction.amount, BigInt(0)),
41
- asset: null,
42
- };
43
- }
44
-
45
- export const buildOptimisticOperation = (
46
- account: Account,
47
- transaction: TransactionCommon,
48
- ): Operation => {
49
- return {
50
- id: encodeOperationId(account.id, "", "OUT"),
51
- hash: "",
52
- type: "OUT",
53
- value: transaction.amount,
54
- fee: transaction["fees"] ?? BigNumber(0),
55
- blockHash: null,
56
- blockHeight: null,
57
- senders: [account.freshAddress.toString()],
58
- recipients: [transaction.recipient],
59
- accountId: account.id,
60
- date: new Date(),
61
- extra: {},
62
- };
63
- };
@@ -1,31 +0,0 @@
1
- export class UserAddressSanctionedError extends Error {
2
- constructor() {
3
- super();
4
- this.message = this.constructor.name;
5
- this.name = this.constructor.name;
6
- }
7
- }
8
-
9
- export class UserAddressSanctionedForSendError extends Error {
10
- constructor() {
11
- super();
12
- this.message = this.constructor.name;
13
- this.name = this.constructor.name;
14
- }
15
- }
16
-
17
- export class UserAddressSanctionedForStakingError extends Error {
18
- constructor() {
19
- super();
20
- this.message = this.constructor.name;
21
- this.name = this.constructor.name;
22
- }
23
- }
24
-
25
- export class RecipientAddressSanctionedError extends Error {
26
- constructor() {
27
- super();
28
- this.message = this.constructor.name;
29
- this.name = this.constructor.name;
30
- }
31
- }
@@ -1,59 +0,0 @@
1
- import { LiveConfig } from "@ledgerhq/live-config/LiveConfig";
2
- import axios from "axios";
3
- import { hours, makeLRUCache } from "@ledgerhq/live-network/cache";
4
- import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
5
- import { getCurrencyConfiguration, getSharedConfiguration } from "../config";
6
- import { CurrencyConfig } from "@ledgerhq/coin-framework/config";
7
-
8
- const cache = makeLRUCache(fetchSanctionedAddresses, () => "all_sanctioned_addresses", hours(12));
9
-
10
- async function fetchSanctionedAddresses(): Promise<Record<string, string[]>> {
11
- const { data } = await axios.get(
12
- "https://ofac-compliance.pages.dev/all_sanctioned_addresses.json",
13
- );
14
- return data;
15
- }
16
-
17
- export async function isAddressSanctioned(
18
- currency: CryptoCurrency,
19
- address: string,
20
- ): Promise<boolean> {
21
- if (!isCheckBlacklistAddressEnabled(currency)) {
22
- return false;
23
- }
24
-
25
- // Only for testing, should be deleted after
26
- const temporarySanctionedAddresses: string[] | undefined =
27
- LiveConfig.getValueByKey(`tmp_sanctioned_addresses`);
28
-
29
- const data: Record<string, string[]> = await cache();
30
- const addresses = data[currency.ticker] || [];
31
-
32
- if (temporarySanctionedAddresses) {
33
- return addresses.concat(temporarySanctionedAddresses).includes(address);
34
- }
35
-
36
- return addresses.includes(address);
37
- }
38
-
39
- function isCheckBlacklistAddressEnabled(currency: CryptoCurrency): boolean {
40
- const currencyConfig = tryGetCurrencyConfig(currency);
41
- if (currencyConfig && "checkBlacklistAddress" in currencyConfig) {
42
- return currencyConfig.checkBlacklistAddress === true;
43
- } else {
44
- const sharedConfiguration = getSharedConfiguration();
45
- if ("checkBlacklistAddress" in sharedConfiguration) {
46
- return sharedConfiguration.checkBlacklistAddress === true;
47
- }
48
- }
49
-
50
- return false;
51
- }
52
-
53
- function tryGetCurrencyConfig(currency: CryptoCurrency): CurrencyConfig | undefined {
54
- try {
55
- return getCurrencyConfiguration(currency);
56
- } catch (error) {
57
- return undefined;
58
- }
59
- }