@ledgerhq/live-common 21.28.0 → 21.31.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 (324) hide show
  1. package/lib/__tests__/families/bitcoin/wallet-btc/xpub.synced.unit.test.js +1 -1
  2. package/lib/__tests__/families/bitcoin/wallet-btc/xpub.synced.unit.test.js.map +1 -1
  3. package/lib/__tests__/test-helpers/bridge.js +1 -1
  4. package/lib/__tests__/test-helpers/bridge.js.map +1 -1
  5. package/lib/__tests__/test-helpers/setup.js +1 -0
  6. package/lib/__tests__/test-helpers/setup.js.map +1 -1
  7. package/lib/account/support.d.ts.map +1 -1
  8. package/lib/account/support.js.map +1 -1
  9. package/lib/apps/hw.d.ts.map +1 -1
  10. package/lib/apps/hw.js +8 -3
  11. package/lib/apps/hw.js.map +1 -1
  12. package/lib/bot/engine.js +1 -1
  13. package/lib/bot/engine.js.map +1 -1
  14. package/lib/bridge/jsHelpers.js +1 -1
  15. package/lib/data/icons/react/celo.d.ts +8 -0
  16. package/lib/data/icons/react/celo.d.ts.map +1 -0
  17. package/lib/data/icons/react/celo.js +32 -0
  18. package/lib/data/icons/react/celo.js.map +1 -0
  19. package/lib/data/icons/react/index.d.ts +1 -0
  20. package/lib/data/icons/react/index.d.ts.map +1 -1
  21. package/lib/data/icons/react/index.js +11 -8
  22. package/lib/data/icons/react/index.js.map +1 -1
  23. package/lib/data/icons/reactNative/celo.d.ts +8 -0
  24. package/lib/data/icons/reactNative/celo.d.ts.map +1 -0
  25. package/lib/data/icons/reactNative/celo.js +33 -0
  26. package/lib/data/icons/reactNative/celo.js.map +1 -0
  27. package/lib/data/icons/reactNative/index.d.ts +1 -0
  28. package/lib/data/icons/reactNative/index.d.ts.map +1 -1
  29. package/lib/data/icons/reactNative/index.js +11 -8
  30. package/lib/data/icons/reactNative/index.js.map +1 -1
  31. package/lib/env.d.ts +20 -5
  32. package/lib/env.d.ts.map +1 -1
  33. package/lib/env.js +15 -0
  34. package/lib/env.js.map +1 -1
  35. package/lib/env.react.d.ts +1 -1
  36. package/lib/env.react.d.ts.map +1 -1
  37. package/lib/exchange/swap/hooks/usePickDefaultAccount.d.ts.map +1 -1
  38. package/lib/exchange/swap/hooks/usePickDefaultAccount.js +4 -9
  39. package/lib/exchange/swap/hooks/usePickDefaultAccount.js.map +1 -1
  40. package/lib/exchange/swap/utils/index.d.ts +6 -1
  41. package/lib/exchange/swap/utils/index.d.ts.map +1 -1
  42. package/lib/exchange/swap/utils/index.js +8 -1
  43. package/lib/exchange/swap/utils/index.js.map +1 -1
  44. package/lib/exchange/swap/utils/index.test.js +27 -0
  45. package/lib/exchange/swap/utils/index.test.js.map +1 -1
  46. package/lib/families/bitcoin/wallet-btc/crypto/base.d.ts.map +1 -1
  47. package/lib/families/bitcoin/wallet-btc/crypto/base.js +19 -20
  48. package/lib/families/bitcoin/wallet-btc/crypto/base.js.map +1 -1
  49. package/lib/families/bitcoin/wallet-btc/crypto/bitcoin.d.ts.map +1 -1
  50. package/lib/families/bitcoin/wallet-btc/crypto/bitcoin.js +4 -5
  51. package/lib/families/bitcoin/wallet-btc/crypto/bitcoin.js.map +1 -1
  52. package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.d.ts.map +1 -1
  53. package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.js +3 -4
  54. package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.js.map +1 -1
  55. package/lib/families/bitcoin/wallet-btc/crypto/decred.d.ts.map +1 -1
  56. package/lib/families/bitcoin/wallet-btc/crypto/decred.js +3 -4
  57. package/lib/families/bitcoin/wallet-btc/crypto/decred.js.map +1 -1
  58. package/lib/families/bitcoin/wallet-btc/crypto/litecoin.d.ts.map +1 -1
  59. package/lib/families/bitcoin/wallet-btc/crypto/litecoin.js +3 -4
  60. package/lib/families/bitcoin/wallet-btc/crypto/litecoin.js.map +1 -1
  61. package/lib/families/bitcoin/wallet-btc/crypto/zec.d.ts.map +1 -1
  62. package/lib/families/bitcoin/wallet-btc/crypto/zec.js +3 -4
  63. package/lib/families/bitcoin/wallet-btc/crypto/zec.js.map +1 -1
  64. package/lib/families/bitcoin/wallet-btc/crypto/zen.d.ts.map +1 -1
  65. package/lib/families/bitcoin/wallet-btc/crypto/zen.js +3 -4
  66. package/lib/families/bitcoin/wallet-btc/crypto/zen.js.map +1 -1
  67. package/lib/families/bitcoin/wallet-btc/xpub.js +1 -1
  68. package/lib/families/bitcoin/wallet-btc/xpub.js.map +1 -1
  69. package/lib/families/celo/api/hubble.d.ts +8 -0
  70. package/lib/families/celo/api/hubble.d.ts.map +1 -0
  71. package/lib/families/celo/api/hubble.js +144 -0
  72. package/lib/families/celo/api/hubble.js.map +1 -0
  73. package/lib/families/celo/api/index.d.ts +2 -0
  74. package/lib/families/celo/api/index.d.ts.map +1 -0
  75. package/lib/families/celo/api/index.js +13 -0
  76. package/lib/families/celo/api/index.js.map +1 -0
  77. package/lib/families/celo/api/sdk.d.ts +3 -0
  78. package/lib/families/celo/api/sdk.d.ts.map +1 -0
  79. package/lib/families/celo/api/sdk.js +13 -0
  80. package/lib/families/celo/api/sdk.js.map +1 -0
  81. package/lib/families/celo/bridge/js.d.ts +8 -0
  82. package/lib/families/celo/bridge/js.d.ts.map +1 -0
  83. package/lib/families/celo/bridge/js.js +87 -0
  84. package/lib/families/celo/bridge/js.js.map +1 -0
  85. package/lib/families/celo/cli-transaction.d.ts +14 -0
  86. package/lib/families/celo/cli-transaction.d.ts.map +1 -0
  87. package/lib/families/celo/cli-transaction.js +37 -0
  88. package/lib/families/celo/cli-transaction.js.map +1 -0
  89. package/lib/families/celo/datasets/celo.scanAccounts.1.d.ts +5 -0
  90. package/lib/families/celo/datasets/celo.scanAccounts.1.d.ts.map +1 -0
  91. package/lib/families/celo/datasets/celo.scanAccounts.1.js +12 -0
  92. package/lib/families/celo/datasets/celo.scanAccounts.1.js.map +1 -0
  93. package/lib/families/celo/deviceTransactionConfig.d.ts +4 -0
  94. package/lib/families/celo/deviceTransactionConfig.d.ts.map +1 -0
  95. package/lib/families/celo/deviceTransactionConfig.js +16 -0
  96. package/lib/families/celo/deviceTransactionConfig.js.map +1 -0
  97. package/lib/families/celo/hw-app-celo.d.ts +19 -0
  98. package/lib/families/celo/hw-app-celo.d.ts.map +1 -0
  99. package/lib/families/celo/hw-app-celo.js +147 -0
  100. package/lib/families/celo/hw-app-celo.js.map +1 -0
  101. package/lib/families/celo/hw-getAddress.d.ts +2 -0
  102. package/lib/families/celo/hw-getAddress.d.ts.map +1 -0
  103. package/lib/families/celo/hw-getAddress.js +13 -0
  104. package/lib/families/celo/hw-getAddress.js.map +1 -0
  105. package/lib/families/celo/js-broadcast.d.ts +8 -0
  106. package/lib/families/celo/js-broadcast.d.ts.map +1 -0
  107. package/lib/families/celo/js-broadcast.js +58 -0
  108. package/lib/families/celo/js-broadcast.js.map +1 -0
  109. package/lib/families/celo/js-buildTransaction.d.ts +6 -0
  110. package/lib/families/celo/js-buildTransaction.d.ts.map +1 -0
  111. package/lib/families/celo/js-buildTransaction.js +89 -0
  112. package/lib/families/celo/js-buildTransaction.js.map +1 -0
  113. package/lib/families/celo/js-createTransaction.d.ts +4 -0
  114. package/lib/families/celo/js-createTransaction.d.ts.map +1 -0
  115. package/lib/families/celo/js-createTransaction.js +12 -0
  116. package/lib/families/celo/js-createTransaction.js.map +1 -0
  117. package/lib/families/celo/js-estimateMaxSpendable.d.ts +10 -0
  118. package/lib/families/celo/js-estimateMaxSpendable.d.ts.map +1 -0
  119. package/lib/families/celo/js-estimateMaxSpendable.js +77 -0
  120. package/lib/families/celo/js-estimateMaxSpendable.js.map +1 -0
  121. package/lib/families/celo/js-getFeesForTransaction.d.ts +8 -0
  122. package/lib/families/celo/js-getFeesForTransaction.d.ts.map +1 -0
  123. package/lib/families/celo/js-getFeesForTransaction.js +76 -0
  124. package/lib/families/celo/js-getFeesForTransaction.js.map +1 -0
  125. package/lib/families/celo/js-getTransactionStatus.d.ts +5 -0
  126. package/lib/families/celo/js-getTransactionStatus.d.ts.map +1 -0
  127. package/lib/families/celo/js-getTransactionStatus.js +86 -0
  128. package/lib/families/celo/js-getTransactionStatus.js.map +1 -0
  129. package/lib/families/celo/js-prepareTransaction.d.ts +5 -0
  130. package/lib/families/celo/js-prepareTransaction.d.ts.map +1 -0
  131. package/lib/families/celo/js-prepareTransaction.js +76 -0
  132. package/lib/families/celo/js-prepareTransaction.js.map +1 -0
  133. package/lib/families/celo/js-signOperation.d.ts +13 -0
  134. package/lib/families/celo/js-signOperation.d.ts.map +1 -0
  135. package/lib/families/celo/js-signOperation.js +150 -0
  136. package/lib/families/celo/js-signOperation.js.map +1 -0
  137. package/lib/families/celo/js-synchronisation.d.ts +10 -0
  138. package/lib/families/celo/js-synchronisation.d.ts.map +1 -0
  139. package/lib/families/celo/js-synchronisation.js +88 -0
  140. package/lib/families/celo/js-synchronisation.js.map +1 -0
  141. package/lib/families/celo/specs.d.ts +7 -0
  142. package/lib/families/celo/specs.d.ts.map +1 -0
  143. package/lib/families/celo/specs.js +56 -0
  144. package/lib/families/celo/specs.js.map +1 -0
  145. package/lib/families/celo/speculos-deviceActions.d.ts +7 -0
  146. package/lib/families/celo/speculos-deviceActions.d.ts.map +1 -0
  147. package/lib/families/celo/speculos-deviceActions.js +53 -0
  148. package/lib/families/celo/speculos-deviceActions.js.map +1 -0
  149. package/lib/families/celo/transaction.d.ts +11 -0
  150. package/lib/families/celo/transaction.d.ts.map +1 -0
  151. package/lib/families/celo/transaction.js +39 -0
  152. package/lib/families/celo/transaction.js.map +1 -0
  153. package/lib/families/celo/types.d.ts +16 -0
  154. package/lib/families/celo/types.d.ts.map +1 -0
  155. package/lib/families/celo/types.js +6 -0
  156. package/lib/families/celo/types.js.map +1 -0
  157. package/lib/families/ethereum/datasets/ethereum.scanAccounts.1.d.ts +1 -0
  158. package/lib/families/ethereum/datasets/ethereum.scanAccounts.1.d.ts.map +1 -1
  159. package/lib/families/ethereum/datasets/ethereum.scanAccounts.1.js +1 -0
  160. package/lib/families/ethereum/datasets/ethereum.scanAccounts.1.js.map +1 -1
  161. package/lib/families/ethereum/modules/erc1155.d.ts.map +1 -1
  162. package/lib/families/ethereum/modules/erc1155.js +8 -2
  163. package/lib/families/ethereum/modules/erc1155.js.map +1 -1
  164. package/lib/families/polkadot/cache.d.ts +1 -1
  165. package/lib/families/polkadot/cache.js +1 -1
  166. package/lib/families/solana/api/chain/index.d.ts +2 -2
  167. package/lib/families/solana/api/chain/index.d.ts.map +1 -1
  168. package/lib/families/solana/api/chain/index.js +4 -4
  169. package/lib/families/solana/api/chain/index.js.map +1 -1
  170. package/lib/families/solana/bridge/bridge.js +5 -5
  171. package/lib/families/solana/bridge/bridge.js.map +1 -1
  172. package/lib/families/solana/bridge/js.js +3 -3
  173. package/lib/families/solana/bridge/js.js.map +1 -1
  174. package/lib/families/solana/bridge/mock.js +1 -1
  175. package/lib/families/solana/bridge/mock.js.map +1 -1
  176. package/lib/families/solana/test-dataset.d.ts.map +1 -1
  177. package/lib/families/solana/test-dataset.js +211 -209
  178. package/lib/families/solana/test-dataset.js.map +1 -1
  179. package/lib/families/solana/utils.d.ts +1 -2
  180. package/lib/families/solana/utils.d.ts.map +1 -1
  181. package/lib/families/solana/utils.js +11 -9
  182. package/lib/families/solana/utils.js.map +1 -1
  183. package/lib/families/tezos/datasets/tezos.scanAccounts.1.js +1 -1
  184. package/lib/families/tezos/datasets/tezos.scanAccounts.1.js.map +1 -1
  185. package/lib/featureFlags/FeatureToggle.d.ts +10 -0
  186. package/lib/featureFlags/FeatureToggle.d.ts.map +1 -0
  187. package/lib/featureFlags/FeatureToggle.js +17 -0
  188. package/lib/featureFlags/FeatureToggle.js.map +1 -0
  189. package/lib/featureFlags/defaultFeatures.d.ts +3 -0
  190. package/lib/featureFlags/defaultFeatures.d.ts.map +1 -0
  191. package/lib/featureFlags/defaultFeatures.js +9 -0
  192. package/lib/featureFlags/defaultFeatures.js.map +1 -0
  193. package/lib/featureFlags/index.d.ts +5 -0
  194. package/lib/featureFlags/index.d.ts.map +1 -0
  195. package/lib/featureFlags/index.js +17 -0
  196. package/lib/featureFlags/index.js.map +1 -0
  197. package/lib/featureFlags/provider.d.ts +13 -0
  198. package/lib/featureFlags/provider.d.ts.map +1 -0
  199. package/lib/featureFlags/provider.js +68 -0
  200. package/lib/featureFlags/provider.js.map +1 -0
  201. package/lib/featureFlags/types.d.ts +8 -0
  202. package/lib/featureFlags/types.d.ts.map +1 -0
  203. package/lib/featureFlags/types.js +3 -0
  204. package/lib/featureFlags/types.js.map +1 -0
  205. package/lib/featureFlags/useFeature.d.ts +3 -0
  206. package/lib/featureFlags/useFeature.d.ts.map +1 -0
  207. package/lib/featureFlags/useFeature.js +9 -0
  208. package/lib/featureFlags/useFeature.js.map +1 -0
  209. package/lib/generated/bridge/js.d.ts +4 -0
  210. package/lib/generated/bridge/js.d.ts.map +1 -1
  211. package/lib/generated/bridge/js.js +24 -22
  212. package/lib/generated/bridge/js.js.map +1 -1
  213. package/lib/generated/cli-transaction.d.ts +9 -0
  214. package/lib/generated/cli-transaction.d.ts.map +1 -1
  215. package/lib/generated/cli-transaction.js +24 -22
  216. package/lib/generated/cli-transaction.js.map +1 -1
  217. package/lib/generated/deviceTransactionConfig.d.ts +2 -0
  218. package/lib/generated/deviceTransactionConfig.d.ts.map +1 -1
  219. package/lib/generated/deviceTransactionConfig.js +22 -20
  220. package/lib/generated/deviceTransactionConfig.js.map +1 -1
  221. package/lib/generated/hw-getAddress.d.ts +1 -0
  222. package/lib/generated/hw-getAddress.d.ts.map +1 -1
  223. package/lib/generated/hw-getAddress.js +26 -24
  224. package/lib/generated/hw-getAddress.js.map +1 -1
  225. package/lib/generated/specs.d.ts +3 -0
  226. package/lib/generated/specs.d.ts.map +1 -1
  227. package/lib/generated/specs.js +24 -22
  228. package/lib/generated/specs.js.map +1 -1
  229. package/lib/generated/speculos-deviceActions.d.ts +3 -0
  230. package/lib/generated/speculos-deviceActions.d.ts.map +1 -1
  231. package/lib/generated/speculos-deviceActions.js +24 -22
  232. package/lib/generated/speculos-deviceActions.js.map +1 -1
  233. package/lib/generated/transaction.d.ts +5 -0
  234. package/lib/generated/transaction.d.ts.map +1 -1
  235. package/lib/generated/transaction.js +26 -24
  236. package/lib/generated/transaction.js.map +1 -1
  237. package/lib/generated/types.d.ts +12 -6
  238. package/lib/generated/types.d.ts.map +1 -1
  239. package/lib/generated/types.js +14 -12
  240. package/lib/generated/types.js.map +1 -1
  241. package/lib/types/index.d.ts +1 -0
  242. package/lib/types/index.d.ts.map +1 -1
  243. package/lib/types/index.js +1 -0
  244. package/lib/types/index.js.map +1 -1
  245. package/lib/types/manager.d.ts +7 -0
  246. package/lib/types/manager.d.ts.map +1 -1
  247. package/lib/types/manager.js +7 -0
  248. package/lib/types/manager.js.map +1 -1
  249. package/package.json +12 -9
  250. package/src/.DS_Store +0 -0
  251. package/src/__tests__/.DS_Store +0 -0
  252. package/src/__tests__/__snapshots__/all.libcore.ts.snap +0 -33226
  253. package/src/__tests__/families/bitcoin/wallet-btc/xpub.synced.unit.test.ts +1 -1
  254. package/src/__tests__/test-helpers/bridge.ts +1 -1
  255. package/src/__tests__/test-helpers/setup.ts +1 -0
  256. package/src/account/support.ts +1 -0
  257. package/src/apps/hw.ts +7 -0
  258. package/src/bot/engine.ts +1 -1
  259. package/src/bridge/jsHelpers.ts +1 -1
  260. package/src/data/icons/react/celo.tsx +12 -0
  261. package/src/data/icons/react/index.tsx +1 -0
  262. package/src/data/icons/reactNative/celo.tsx +13 -0
  263. package/src/data/icons/reactNative/index.tsx +1 -0
  264. package/src/data/icons/svg/CELO.svg +5 -0
  265. package/src/env.ts +15 -0
  266. package/src/exchange/swap/hooks/usePickDefaultAccount.ts +4 -9
  267. package/src/exchange/swap/utils/index.test.ts +44 -1
  268. package/src/exchange/swap/utils/index.ts +12 -1
  269. package/src/families/bitcoin/wallet-btc/crypto/base.ts +41 -20
  270. package/src/families/bitcoin/wallet-btc/crypto/bitcoin.ts +12 -5
  271. package/src/families/bitcoin/wallet-btc/crypto/bitcoincash.ts +11 -4
  272. package/src/families/bitcoin/wallet-btc/crypto/decred.ts +11 -4
  273. package/src/families/bitcoin/wallet-btc/crypto/litecoin.ts +11 -4
  274. package/src/families/bitcoin/wallet-btc/crypto/zec.ts +11 -4
  275. package/src/families/bitcoin/wallet-btc/crypto/zen.ts +11 -4
  276. package/src/families/bitcoin/wallet-btc/xpub.ts +1 -1
  277. package/src/families/celo/api/hubble.ts +93 -0
  278. package/src/families/celo/api/index.ts +1 -0
  279. package/src/families/celo/api/sdk.ts +8 -0
  280. package/src/families/celo/bridge/js.ts +38 -0
  281. package/src/families/celo/cli-transaction.ts +41 -0
  282. package/src/families/celo/datasets/celo.scanAccounts.1.ts +20 -0
  283. package/src/families/celo/deviceTransactionConfig.ts +19 -0
  284. package/src/families/celo/hw-app-celo.ts +108 -0
  285. package/src/families/celo/hw-getAddress.ts +1 -0
  286. package/src/families/celo/js-broadcast.ts +12 -0
  287. package/src/families/celo/js-buildTransaction.ts +32 -0
  288. package/src/families/celo/js-createTransaction.ts +12 -0
  289. package/src/families/celo/js-estimateMaxSpendable.ts +28 -0
  290. package/src/families/celo/js-getFeesForTransaction.ts +38 -0
  291. package/src/families/celo/js-getTransactionStatus.ts +67 -0
  292. package/src/families/celo/js-prepareTransaction.ts +28 -0
  293. package/src/families/celo/js-signOperation.ts +149 -0
  294. package/src/families/celo/js-synchronisation.ts +40 -0
  295. package/src/families/celo/specs.ts +53 -0
  296. package/src/families/celo/speculos-deviceActions.ts +51 -0
  297. package/src/families/celo/transaction.ts +39 -0
  298. package/src/families/celo/types.ts +20 -0
  299. package/src/families/ethereum/datasets/ethereum.scanAccounts.1.ts +1 -0
  300. package/src/families/ethereum/modules/erc1155.ts +9 -0
  301. package/src/families/polkadot/cache.ts +1 -1
  302. package/src/families/solana/api/chain/index.ts +8 -7
  303. package/src/families/solana/bridge/bridge.ts +11 -11
  304. package/src/families/solana/bridge/js.ts +3 -3
  305. package/src/families/solana/bridge/mock.ts +1 -1
  306. package/src/families/solana/test-dataset.ts +340 -337
  307. package/src/families/solana/utils.ts +9 -8
  308. package/src/families/tezos/datasets/tezos.scanAccounts.1.ts +39 -39
  309. package/src/featureFlags/FeatureToggle.tsx +24 -0
  310. package/src/featureFlags/defaultFeatures.ts +7 -0
  311. package/src/featureFlags/index.ts +4 -0
  312. package/src/featureFlags/provider.tsx +48 -0
  313. package/src/featureFlags/types.ts +9 -0
  314. package/src/featureFlags/useFeature.ts +8 -0
  315. package/src/generated/bridge/js.ts +3 -0
  316. package/src/generated/cli-transaction.ts +3 -0
  317. package/src/generated/deviceTransactionConfig.ts +3 -0
  318. package/src/generated/hw-getAddress.ts +3 -0
  319. package/src/generated/specs.ts +3 -0
  320. package/src/generated/speculos-deviceActions.ts +3 -0
  321. package/src/generated/transaction.ts +3 -0
  322. package/src/generated/types.ts +14 -0
  323. package/src/types/index.ts +1 -0
  324. package/src/types/manager.ts +7 -0
@@ -0,0 +1,38 @@
1
+ import type { AccountBridge, CurrencyBridge } from "../../../types";
2
+ import type { Transaction } from "../types";
3
+ import { makeAccountBridgeReceive } from "../../../bridge/jsHelpers";
4
+ import { sync, scanAccounts } from "../js-synchronisation";
5
+ import signOperation from "../js-signOperation";
6
+ import getTransactionStatus from "../js-getTransactionStatus";
7
+ import broadcast from "../js-broadcast";
8
+ import estimateMaxSpendable from "../js-estimateMaxSpendable";
9
+ import prepareTransaction from "../js-prepareTransaction";
10
+ import createTransaction from "../js-createTransaction";
11
+
12
+ const updateTransaction = (t, patch) => ({ ...t, ...patch });
13
+
14
+ const receive = makeAccountBridgeReceive();
15
+
16
+ const preload = async () => Promise.resolve({});
17
+ const hydrate = (): void => {};
18
+
19
+ const currencyBridge: CurrencyBridge = {
20
+ preload,
21
+ hydrate,
22
+ scanAccounts,
23
+ };
24
+ const accountBridge: AccountBridge<Transaction> = {
25
+ estimateMaxSpendable,
26
+ createTransaction,
27
+ updateTransaction,
28
+ getTransactionStatus,
29
+ prepareTransaction,
30
+ sync,
31
+ receive,
32
+ signOperation,
33
+ broadcast,
34
+ };
35
+ export default {
36
+ currencyBridge,
37
+ accountBridge,
38
+ };
@@ -0,0 +1,41 @@
1
+ import invariant from "invariant";
2
+ import flatMap from "lodash/flatMap";
3
+
4
+ import type {
5
+ Transaction,
6
+ Account,
7
+ AccountLike,
8
+ AccountLikeArray,
9
+ } from "../../types";
10
+
11
+ const options = [];
12
+
13
+ function inferAccounts(account: Account): AccountLikeArray {
14
+ invariant(account.currency.family === "celo", "celo family");
15
+
16
+ const accounts: Account[] = [account];
17
+ return accounts;
18
+ }
19
+
20
+ function inferTransactions(
21
+ transactions: Array<{
22
+ account: AccountLike;
23
+ transaction: Transaction;
24
+ mainAccount: Account;
25
+ }>
26
+ ): Transaction[] {
27
+ return flatMap(transactions, ({ transaction }) => {
28
+ invariant(transaction.family === "celo", "celo family");
29
+
30
+ return {
31
+ ...transaction,
32
+ family: "celo",
33
+ } as Transaction;
34
+ });
35
+ }
36
+
37
+ export default {
38
+ options,
39
+ inferAccounts,
40
+ inferTransactions,
41
+ };
@@ -0,0 +1,20 @@
1
+ import type { CurrenciesData } from "../../../types";
2
+ import type { Transaction } from "../types";
3
+
4
+ const dataset: CurrenciesData<Transaction> = {
5
+ scanAccounts: [
6
+ {
7
+ name: "celo seed 1",
8
+ apdus: `
9
+ => e002000009028000002c8000ce10
10
+ <= 41040106794f46b69e1ae56dff904510959e59074a37341f8cc740e9ce7a0b24421c42e7023481f5ef03926739baa6bb26cac7bf48f249a24793264711d48499499528433235323935323541463035434134313939633236413838623438393463383342303330433733399000
11
+ => e002000015058000002c8000ce10800000000000000000000000
12
+ <= 41044f4998c3f81966645f25e95082f9fe7d104b1ba4286486a8ecd8fd11f79ef02bd8110f086b390a418ab619a650f3df59a3c84912ce1ea125386d7aa7732fcd0b28393634313334336638346535304143304334434133626644313244433063346231653732363544359000
13
+ => e002000015058000002c8000ce10800000010000000000000000
14
+ <= 4104630b6447b0f690520a5612f1dc57da90b84f6b59dfeb375bed1113fb34a8d0f9181ec63e40f9fde05761084dbd022ba76711eb2b36442cf4b5d2bc19def9156428343435306565646238623532333931354534393639633239646241653944354563303646453837349000
15
+ `,
16
+ },
17
+ ],
18
+ };
19
+
20
+ export default dataset;
@@ -0,0 +1,19 @@
1
+ import type { DeviceTransactionField } from "../../transaction";
2
+
3
+ function getDeviceTransactionConfig(): Array<DeviceTransactionField> {
4
+ const fields: Array<DeviceTransactionField> = [];
5
+
6
+ fields.push({
7
+ type: "amount",
8
+ label: "Amount",
9
+ });
10
+
11
+ fields.push({
12
+ type: "fees",
13
+ label: "Fees",
14
+ });
15
+
16
+ return fields;
17
+ }
18
+
19
+ export default getDeviceTransactionConfig;
@@ -0,0 +1,108 @@
1
+ import type Transport from "@ledgerhq/hw-transport";
2
+ import { decode, encode } from "rlp";
3
+
4
+ /**
5
+ * Heavily inspiried by celo-web-wallet
6
+ * https://github.com/celo-tools/celo-web-wallet/blob/master/src/features/ledger/CeloLedgerApp.ts
7
+ */
8
+ export class CeloApp {
9
+ transport: Transport;
10
+
11
+ constructor(transport: any) {
12
+ this.transport = transport;
13
+ }
14
+
15
+ async signTransaction(
16
+ path: string,
17
+ rawTxHex: string
18
+ ): Promise<{
19
+ s: string;
20
+ v: string;
21
+ r: string;
22
+ }> {
23
+ const paths = splitPath(path);
24
+ const rawTx = Buffer.from(rawTxHex, "hex");
25
+ let offset = 0;
26
+ let response;
27
+
28
+ const rlpTx = decode(rawTx);
29
+ let rlpOffset = 0;
30
+ if (rlpTx.length > 6) {
31
+ const rlpVrs = encode(rlpTx.slice(-3));
32
+ rlpOffset = rawTx.length - (rlpVrs.length - 1);
33
+ }
34
+
35
+ while (offset !== rawTx.length) {
36
+ const first = offset === 0;
37
+ const maxChunkSize = first ? 150 - 1 - paths.length * 4 : 150;
38
+ let chunkSize =
39
+ offset + maxChunkSize > rawTx.length
40
+ ? rawTx.length - offset
41
+ : maxChunkSize;
42
+ if (rlpOffset != 0 && offset + chunkSize == rlpOffset) {
43
+ // Make sure that the chunk doesn't end right on the EIP 155 marker if set
44
+ chunkSize--;
45
+ }
46
+ const buffer = Buffer.alloc(
47
+ first ? 1 + paths.length * 4 + chunkSize : chunkSize
48
+ );
49
+ if (first) {
50
+ buffer[0] = paths.length;
51
+ paths.forEach((element, index) => {
52
+ buffer.writeUInt32BE(element, 1 + 4 * index);
53
+ });
54
+ rawTx.copy(buffer, 1 + 4 * paths.length, offset, offset + chunkSize);
55
+ } else {
56
+ rawTx.copy(buffer, 0, offset, offset + chunkSize);
57
+ }
58
+
59
+ response = await this.transport
60
+ .send(0xe0, 0x04, first ? 0x00 : 0x80, 0x00, buffer)
61
+ .catch((e) => {
62
+ throw e;
63
+ });
64
+
65
+ offset += chunkSize;
66
+ }
67
+
68
+ const v = response.slice(0, 1).toString("hex");
69
+ const r = response.slice(1, 1 + 32).toString("hex");
70
+ const s = response.slice(1 + 32, 1 + 32 + 32).toString("hex");
71
+ return { v, r, s };
72
+ }
73
+
74
+ provideERC20TokenInformation({ data }: { data: Buffer }): Promise<boolean> {
75
+ return provideERC20TokenInformation(this.transport, data);
76
+ }
77
+ }
78
+
79
+ function splitPath(path: string): number[] {
80
+ const result: number[] = [];
81
+ const components = path.split("/");
82
+ components.forEach((element) => {
83
+ let number = parseInt(element, 10);
84
+ if (isNaN(number)) {
85
+ return; // FIXME shouldn't it throws instead?
86
+ }
87
+ if (element.length > 1 && element[element.length - 1] === "'") {
88
+ number += 0x80000000;
89
+ }
90
+ result.push(number);
91
+ });
92
+ return result;
93
+ }
94
+
95
+ function provideERC20TokenInformation(
96
+ transport: Transport,
97
+ data: Buffer
98
+ ): Promise<boolean> {
99
+ return transport.send(0xe0, 0x0a, 0x00, 0x00, data).then(
100
+ () => true,
101
+ (e) => {
102
+ if (e && e.statusCode === 0x6d00) {
103
+ return false;
104
+ }
105
+ throw e;
106
+ }
107
+ );
108
+ }
@@ -0,0 +1 @@
1
+ export { default } from "../ethereum/hw-getAddress";
@@ -0,0 +1,12 @@
1
+ import { patchOperationWithHash } from "../../operation";
2
+ import { celoKit } from "./api/sdk";
3
+
4
+ const broadcast = async ({ signedOperation: { operation, signature } }) => {
5
+ const kit = celoKit();
6
+ const { transactionHash } = await kit.web3.eth.sendSignedTransaction(
7
+ signature
8
+ );
9
+ return patchOperationWithHash(operation, transactionHash);
10
+ };
11
+
12
+ export default broadcast;
@@ -0,0 +1,32 @@
1
+ import type { Transaction } from "./types";
2
+ import type { Account } from "../../types";
3
+ import { CeloTx } from "@celo/connect";
4
+ import { celoKit } from "./api/sdk";
5
+
6
+ const buildTransaction = async (account: Account, transaction: Transaction) => {
7
+ const kit = celoKit();
8
+ const { amount } = transaction;
9
+ const value = transaction.useAllAmount
10
+ ? account.spendableBalance.minus(transaction.fees || 0)
11
+ : amount;
12
+
13
+ const celoToken = await kit.contracts.getGoldToken();
14
+
15
+ const celoTransaction = {
16
+ from: account.freshAddress,
17
+ to: celoToken.address,
18
+ data: celoToken
19
+ .transfer(transaction.recipient, value.toFixed())
20
+ .txo.encodeABI(),
21
+ };
22
+
23
+ return {
24
+ ...celoTransaction,
25
+ chainId: await kit.connection.chainId(),
26
+ nonce: await kit.connection.nonce(account.freshAddress),
27
+ gas: await kit.connection.estimateGasWithInflationFactor(celoTransaction),
28
+ gasPrice: await kit.connection.gasPrice(),
29
+ } as CeloTx;
30
+ };
31
+
32
+ export default buildTransaction;
@@ -0,0 +1,12 @@
1
+ import { Transaction } from "./types";
2
+ import { BigNumber } from "bignumber.js";
3
+
4
+ const createTransaction = (): Transaction => ({
5
+ family: "celo",
6
+ amount: new BigNumber(0),
7
+ recipient: "",
8
+ useAllAmount: false,
9
+ fees: null,
10
+ });
11
+
12
+ export default createTransaction;
@@ -0,0 +1,28 @@
1
+ import { Account, AccountLike } from "../../types";
2
+ import { Transaction } from "./types";
3
+ import { BigNumber } from "bignumber.js";
4
+ import { getMainAccount } from "../../account";
5
+ import getTransactionStatus from "./js-getTransactionStatus";
6
+ import prepareTransaction from "./js-prepareTransaction";
7
+ import createTransaction from "./js-createTransaction";
8
+
9
+ const estimateMaxSpendable = async ({
10
+ account,
11
+ parentAccount,
12
+ transaction,
13
+ }: {
14
+ account: AccountLike;
15
+ parentAccount: Account;
16
+ transaction: Transaction;
17
+ }): Promise<BigNumber> => {
18
+ const mainAccount = getMainAccount(account, parentAccount);
19
+ const t = await prepareTransaction(mainAccount, {
20
+ ...createTransaction(),
21
+ ...transaction,
22
+ useAllAmount: true,
23
+ });
24
+ const s = await getTransactionStatus(mainAccount, t);
25
+ return s.amount;
26
+ };
27
+
28
+ export default estimateMaxSpendable;
@@ -0,0 +1,38 @@
1
+ import { BigNumber } from "bignumber.js";
2
+ import { Account, Transaction } from "../../types";
3
+ import { celoKit } from "./api/sdk";
4
+
5
+ const getFeesForTransaction = async ({
6
+ account,
7
+ transaction,
8
+ }: {
9
+ account: Account;
10
+ transaction: Transaction;
11
+ }): Promise<BigNumber> => {
12
+ const { amount } = transaction;
13
+ const kit = celoKit();
14
+
15
+ // A workaround - estimating gas throws an error if value > funds
16
+ const value = transaction.useAllAmount
17
+ ? account.spendableBalance
18
+ : BigNumber.minimum(amount, account.spendableBalance);
19
+
20
+ const celoToken = await kit.contracts.getGoldToken();
21
+
22
+ const celoTransaction = {
23
+ from: account.freshAddress,
24
+ to: celoToken.address,
25
+ data: celoToken
26
+ .transfer(transaction.recipient, value.toFixed())
27
+ .txo.encodeABI(),
28
+ };
29
+
30
+ const gasPrice = new BigNumber(await kit.connection.gasPrice());
31
+ const gas = await kit.connection.estimateGasWithInflationFactor(
32
+ celoTransaction
33
+ );
34
+
35
+ return gasPrice.times(gas);
36
+ };
37
+
38
+ export default getFeesForTransaction;
@@ -0,0 +1,67 @@
1
+ import { Account, TransactionStatus } from "../../types";
2
+ import { Transaction } from "./types";
3
+ import {
4
+ AmountRequired,
5
+ FeeNotLoaded,
6
+ InvalidAddress,
7
+ InvalidAddressBecauseDestinationIsAlsoSource,
8
+ NotEnoughBalance,
9
+ RecipientRequired,
10
+ } from "@ledgerhq/errors";
11
+ import { BigNumber } from "bignumber.js";
12
+ import { isValidAddress } from "@celo/utils/lib/address";
13
+
14
+ const getTransactionStatus = async (
15
+ account: Account,
16
+ transaction: Transaction
17
+ ): Promise<TransactionStatus> => {
18
+ const errors: any = {};
19
+ const warnings: any = {};
20
+ const useAllAmount = !!transaction.useAllAmount;
21
+
22
+ if (account.freshAddress === transaction.recipient) {
23
+ errors.recipient = new InvalidAddressBecauseDestinationIsAlsoSource();
24
+ }
25
+
26
+ if (!transaction.fees || !transaction.fees.gt(0)) {
27
+ errors.fees = new FeeNotLoaded();
28
+ }
29
+
30
+ const estimatedFees = transaction.fees || new BigNumber(0);
31
+
32
+ const amount = useAllAmount
33
+ ? account.spendableBalance.minus(estimatedFees)
34
+ : new BigNumber(transaction.amount);
35
+
36
+ if (amount.lte(0) && !transaction.useAllAmount) {
37
+ errors.amount = new AmountRequired();
38
+ }
39
+
40
+ const totalSpent = amount.plus(estimatedFees);
41
+
42
+ if (totalSpent.gt(account.spendableBalance)) {
43
+ errors.amount = new NotEnoughBalance();
44
+ }
45
+
46
+ if (!errors.amount && account.spendableBalance.lt(estimatedFees)) {
47
+ errors.amount = new NotEnoughBalance();
48
+ }
49
+
50
+ if (!transaction.recipient) {
51
+ errors.recipient = new RecipientRequired();
52
+ } else if (!isValidAddress(transaction.recipient)) {
53
+ errors.recipient = new InvalidAddress("", {
54
+ currencyName: account.currency.name,
55
+ });
56
+ }
57
+
58
+ return Promise.resolve({
59
+ errors,
60
+ warnings,
61
+ estimatedFees,
62
+ amount,
63
+ totalSpent,
64
+ });
65
+ };
66
+
67
+ export default getTransactionStatus;
@@ -0,0 +1,28 @@
1
+ import { Account } from "../../types";
2
+ import { Transaction } from "./types";
3
+ import getFeesForTransaction from "./js-getFeesForTransaction";
4
+ import { isValidAddress } from "@celo/utils/lib/address";
5
+
6
+ const sameFees = (a, b) => (!a || !b ? a === b : a.eq(b));
7
+
8
+ const prepareTransaction = async (
9
+ account: Account,
10
+ transaction: Transaction
11
+ ) => {
12
+ if (
13
+ !transaction.recipient ||
14
+ (transaction.recipient && !isValidAddress(transaction.recipient))
15
+ ) {
16
+ return transaction;
17
+ }
18
+
19
+ const fees = await getFeesForTransaction({ account, transaction });
20
+
21
+ if (!sameFees(transaction.fees, fees)) {
22
+ return { ...transaction, fees };
23
+ }
24
+
25
+ return transaction;
26
+ };
27
+
28
+ export default prepareTransaction;
@@ -0,0 +1,149 @@
1
+ import { BigNumber } from "bignumber.js";
2
+ import { Observable } from "rxjs";
3
+ import { FeeNotLoaded } from "@ledgerhq/errors";
4
+ import type { Transaction } from "./types";
5
+ import type { Account, Operation, SignOperationEvent } from "../../types";
6
+ import { encodeOperationId } from "../../operation";
7
+ import { CeloApp } from "./hw-app-celo";
8
+ import buildTransaction from "./js-buildTransaction";
9
+ import { rlpEncodedTx, encodeTransaction } from "@celo/wallet-base";
10
+ import { tokenInfoByAddressAndChainId } from "@celo/wallet-ledger/lib/tokens";
11
+ import { withDevice } from "../../hw/deviceAccess";
12
+
13
+ const buildOptimisticOperation = (
14
+ account: Account,
15
+ transaction: Transaction,
16
+ fee: BigNumber
17
+ ): Operation => {
18
+ const type = "OUT";
19
+
20
+ const value = new BigNumber(transaction.amount).plus(fee);
21
+
22
+ const operation: Operation = {
23
+ id: encodeOperationId(account.id, "", type),
24
+ hash: "",
25
+ type,
26
+ value,
27
+ fee,
28
+ blockHash: null,
29
+ blockHeight: null,
30
+ senders: [account.freshAddress],
31
+ recipients: [transaction.recipient].filter(Boolean),
32
+ accountId: account.id,
33
+ date: new Date(),
34
+ extra: { additionalField: transaction.amount },
35
+ };
36
+
37
+ return operation;
38
+ };
39
+
40
+ const trimLeading0x = (input: string) =>
41
+ input.startsWith("0x") ? input.slice(2) : input;
42
+
43
+ const parseSigningResponse = (
44
+ response: {
45
+ s: string;
46
+ v: string;
47
+ r: string;
48
+ },
49
+ chainId: number
50
+ ): {
51
+ s: Buffer;
52
+ v: number;
53
+ r: Buffer;
54
+ } => {
55
+ // EIP155
56
+ const sigV = parseInt(response.v, 16);
57
+ let eip155V = chainId * 2 + 35;
58
+ if (sigV !== eip155V && (sigV & eip155V) !== sigV) {
59
+ eip155V += 1;
60
+ }
61
+
62
+ return {
63
+ s: Buffer.from(response.s, "hex"),
64
+ v: eip155V,
65
+ r: Buffer.from(response.r, "hex"),
66
+ };
67
+ };
68
+
69
+ /**
70
+ * Sign Transaction with Ledger hardware
71
+ */
72
+ const signOperation = ({
73
+ account,
74
+ deviceId,
75
+ transaction,
76
+ }: {
77
+ account: Account;
78
+ deviceId: any;
79
+ transaction: Transaction;
80
+ }): Observable<SignOperationEvent> =>
81
+ withDevice(deviceId)(
82
+ (transport) =>
83
+ new Observable((o) => {
84
+ let cancelled;
85
+
86
+ async function main() {
87
+ if (!transaction.fees) {
88
+ throw new FeeNotLoaded();
89
+ }
90
+
91
+ const celo = new CeloApp(transport);
92
+ const unsignedTransaction = await buildTransaction(
93
+ account,
94
+ transaction
95
+ );
96
+ const { chainId, to } = unsignedTransaction;
97
+ const rlpEncodedTransaction = rlpEncodedTx(unsignedTransaction);
98
+
99
+ const tokenInfo = tokenInfoByAddressAndChainId(to!, chainId!);
100
+ if (tokenInfo) {
101
+ await celo.provideERC20TokenInformation(tokenInfo);
102
+ }
103
+
104
+ o.next({ type: "device-signature-requested" });
105
+
106
+ const response = await celo.signTransaction(
107
+ account.freshAddressPath,
108
+ trimLeading0x(rlpEncodedTransaction.rlpEncode)
109
+ );
110
+
111
+ if (cancelled) return;
112
+
113
+ const signature = parseSigningResponse(response, chainId!);
114
+
115
+ o.next({ type: "device-signature-granted" });
116
+
117
+ const encodedTransaction = await encodeTransaction(
118
+ rlpEncodedTransaction,
119
+ signature
120
+ );
121
+
122
+ const operation = buildOptimisticOperation(
123
+ account,
124
+ transaction,
125
+ transaction.fees ?? new BigNumber(0)
126
+ );
127
+
128
+ o.next({
129
+ type: "signed",
130
+ signedOperation: {
131
+ operation,
132
+ signature: encodedTransaction.raw,
133
+ expirationDate: null,
134
+ },
135
+ });
136
+ }
137
+
138
+ main().then(
139
+ () => o.complete(),
140
+ (e) => o.error(e)
141
+ );
142
+
143
+ return () => {
144
+ cancelled = true;
145
+ };
146
+ })
147
+ );
148
+
149
+ export default signOperation;
@@ -0,0 +1,40 @@
1
+ import type { Account } from "../../types";
2
+ import { encodeAccountId } from "../../account";
3
+ import type { GetAccountShape } from "../../bridge/jsHelpers";
4
+ import { makeSync, makeScanAccounts, mergeOps } from "../../bridge/jsHelpers";
5
+ import { getAccountDetails } from "./api";
6
+
7
+ const getAccountShape: GetAccountShape = async (info) => {
8
+ const { address, currency, initialAccount, derivationMode } = info;
9
+ const oldOperations = initialAccount?.operations || [];
10
+
11
+ const accountId = encodeAccountId({
12
+ type: "js",
13
+ version: "2",
14
+ currencyId: currency.id,
15
+ xpubOrAddress: address,
16
+ derivationMode,
17
+ });
18
+ const {
19
+ blockHeight,
20
+ balance,
21
+ spendableBalance,
22
+ operations: newOperations,
23
+ } = await getAccountDetails(address, accountId);
24
+ const operations = mergeOps(oldOperations, newOperations);
25
+ const shape = {
26
+ id: accountId,
27
+ balance,
28
+ spendableBalance,
29
+ operationsCount: operations.length,
30
+ blockHeight,
31
+ };
32
+ return { ...shape, operations };
33
+ };
34
+
35
+ const postSync = (_initial: Account, parent: Account) => {
36
+ return parent;
37
+ };
38
+
39
+ export const scanAccounts = makeScanAccounts(getAccountShape);
40
+ export const sync = makeSync(getAccountShape, postSync);