@ledgerhq/coin-canton 0.5.0-nightly.5 → 0.5.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 (261) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +32 -47
  3. package/lib/api/getBalance.integ.test.js +5 -9
  4. package/lib/api/getBalance.integ.test.js.map +1 -1
  5. package/lib/api/index.d.ts.map +1 -1
  6. package/lib/api/index.js +25 -20
  7. package/lib/api/index.js.map +1 -1
  8. package/lib/api/lastBlock.integ.test.js +1 -1
  9. package/lib/api/lastBlock.integ.test.js.map +1 -1
  10. package/lib/api/listOperations.integ.test.js +1 -1
  11. package/lib/api/listOperations.integ.test.js.map +1 -1
  12. package/lib/bridge/broadcast.d.ts.map +1 -1
  13. package/lib/bridge/broadcast.js +2 -3
  14. package/lib/bridge/broadcast.js.map +1 -1
  15. package/lib/bridge/broadcast.test.js +0 -9
  16. package/lib/bridge/broadcast.test.js.map +1 -1
  17. package/lib/bridge/createTransaction.js +1 -1
  18. package/lib/bridge/createTransaction.js.map +1 -1
  19. package/lib/bridge/getTransactionStatus.js +1 -1
  20. package/lib/bridge/getTransactionStatus.js.map +1 -1
  21. package/lib/bridge/index.d.ts.map +1 -1
  22. package/lib/bridge/index.js +0 -3
  23. package/lib/bridge/index.js.map +1 -1
  24. package/lib/bridge/onboard.d.ts +5 -7
  25. package/lib/bridge/onboard.d.ts.map +1 -1
  26. package/lib/bridge/onboard.integ.test.js +11 -14
  27. package/lib/bridge/onboard.integ.test.js.map +1 -1
  28. package/lib/bridge/onboard.js +42 -110
  29. package/lib/bridge/onboard.js.map +1 -1
  30. package/lib/bridge/prepareTransaction.d.ts.map +1 -1
  31. package/lib/bridge/prepareTransaction.js +7 -5
  32. package/lib/bridge/prepareTransaction.js.map +1 -1
  33. package/lib/bridge/signOperation.d.ts.map +1 -1
  34. package/lib/bridge/signOperation.js +11 -14
  35. package/lib/bridge/signOperation.js.map +1 -1
  36. package/lib/bridge/sync.d.ts +1 -2
  37. package/lib/bridge/sync.d.ts.map +1 -1
  38. package/lib/bridge/sync.js +21 -41
  39. package/lib/bridge/sync.js.map +1 -1
  40. package/lib/bridge/updateTransaction.d.ts.map +1 -1
  41. package/lib/bridge/updateTransaction.js +4 -0
  42. package/lib/bridge/updateTransaction.js.map +1 -1
  43. package/lib/common-logic/account/getBalance.d.ts +1 -2
  44. package/lib/common-logic/account/getBalance.d.ts.map +1 -1
  45. package/lib/common-logic/account/getBalance.js +7 -7
  46. package/lib/common-logic/account/getBalance.js.map +1 -1
  47. package/lib/common-logic/account/getBalance.unit.test.js +3 -6
  48. package/lib/common-logic/account/getBalance.unit.test.js.map +1 -1
  49. package/lib/common-logic/history/lastBlock.d.ts +1 -2
  50. package/lib/common-logic/history/lastBlock.d.ts.map +1 -1
  51. package/lib/common-logic/history/lastBlock.js +3 -3
  52. package/lib/common-logic/history/lastBlock.js.map +1 -1
  53. package/lib/common-logic/history/lastBlock.test.js +2 -5
  54. package/lib/common-logic/history/lastBlock.test.js.map +1 -1
  55. package/lib/common-logic/history/listOperations.d.ts +1 -2
  56. package/lib/common-logic/history/listOperations.d.ts.map +1 -1
  57. package/lib/common-logic/history/listOperations.js +2 -2
  58. package/lib/common-logic/history/listOperations.js.map +1 -1
  59. package/lib/common-logic/transaction/broadcast.d.ts +1 -2
  60. package/lib/common-logic/transaction/broadcast.d.ts.map +1 -1
  61. package/lib/common-logic/transaction/broadcast.js +4 -5
  62. package/lib/common-logic/transaction/broadcast.js.map +1 -1
  63. package/lib/common-logic/transaction/broadcast.test.js +5 -8
  64. package/lib/common-logic/transaction/broadcast.test.js.map +1 -1
  65. package/lib/common-logic/transaction/combine.d.ts +1 -1
  66. package/lib/common-logic/transaction/combine.d.ts.map +1 -1
  67. package/lib/common-logic/transaction/combine.js +3 -2
  68. package/lib/common-logic/transaction/combine.js.map +1 -1
  69. package/lib/common-logic/transaction/combine.test.js +13 -3
  70. package/lib/common-logic/transaction/combine.test.js.map +1 -1
  71. package/lib/common-logic/transaction/craftTransaction.d.ts +4 -8
  72. package/lib/common-logic/transaction/craftTransaction.d.ts.map +1 -1
  73. package/lib/common-logic/transaction/craftTransaction.js +12 -15
  74. package/lib/common-logic/transaction/craftTransaction.js.map +1 -1
  75. package/lib/common-logic/transaction/estimateFees.d.ts +1 -2
  76. package/lib/common-logic/transaction/estimateFees.d.ts.map +1 -1
  77. package/lib/common-logic/transaction/estimateFees.js +3 -7
  78. package/lib/common-logic/transaction/estimateFees.js.map +1 -1
  79. package/lib/config.d.ts +0 -1
  80. package/lib/config.d.ts.map +1 -1
  81. package/lib/config.js.map +1 -1
  82. package/lib/network/gateway.d.ts +17 -41
  83. package/lib/network/gateway.d.ts.map +1 -1
  84. package/lib/network/gateway.integ.test.js +15 -19
  85. package/lib/network/gateway.integ.test.js.map +1 -1
  86. package/lib/network/gateway.js +48 -74
  87. package/lib/network/gateway.js.map +1 -1
  88. package/lib/network/node.d.ts +2 -2
  89. package/lib/network/node.d.ts.map +1 -1
  90. package/lib/network/node.js.map +1 -1
  91. package/lib/network/types.d.ts +1 -1
  92. package/lib/network/types.d.ts.map +1 -1
  93. package/lib/signer/getAddress.d.ts.map +1 -1
  94. package/lib/signer/getAddress.js +2 -2
  95. package/lib/signer/getAddress.js.map +1 -1
  96. package/lib/types/bridge.d.ts +3 -18
  97. package/lib/types/bridge.d.ts.map +1 -1
  98. package/lib/types/index.d.ts +10 -0
  99. package/lib/types/index.d.ts.map +1 -1
  100. package/lib/types/onboard.d.ts +0 -2
  101. package/lib/types/onboard.d.ts.map +1 -1
  102. package/lib/types/onboard.js.map +1 -1
  103. package/lib/types/signer.d.ts +1 -2
  104. package/lib/types/signer.d.ts.map +1 -1
  105. package/lib-es/api/getBalance.integ.test.js +5 -9
  106. package/lib-es/api/getBalance.integ.test.js.map +1 -1
  107. package/lib-es/api/index.d.ts.map +1 -1
  108. package/lib-es/api/index.js +24 -19
  109. package/lib-es/api/index.js.map +1 -1
  110. package/lib-es/api/lastBlock.integ.test.js +1 -1
  111. package/lib-es/api/lastBlock.integ.test.js.map +1 -1
  112. package/lib-es/api/listOperations.integ.test.js +1 -1
  113. package/lib-es/api/listOperations.integ.test.js.map +1 -1
  114. package/lib-es/bridge/broadcast.d.ts.map +1 -1
  115. package/lib-es/bridge/broadcast.js +2 -3
  116. package/lib-es/bridge/broadcast.js.map +1 -1
  117. package/lib-es/bridge/broadcast.test.js +0 -9
  118. package/lib-es/bridge/broadcast.test.js.map +1 -1
  119. package/lib-es/bridge/createTransaction.js +1 -1
  120. package/lib-es/bridge/createTransaction.js.map +1 -1
  121. package/lib-es/bridge/getTransactionStatus.js +1 -1
  122. package/lib-es/bridge/getTransactionStatus.js.map +1 -1
  123. package/lib-es/bridge/index.d.ts.map +1 -1
  124. package/lib-es/bridge/index.js +0 -3
  125. package/lib-es/bridge/index.js.map +1 -1
  126. package/lib-es/bridge/onboard.d.ts +5 -7
  127. package/lib-es/bridge/onboard.d.ts.map +1 -1
  128. package/lib-es/bridge/onboard.integ.test.js +11 -14
  129. package/lib-es/bridge/onboard.integ.test.js.map +1 -1
  130. package/lib-es/bridge/onboard.js +42 -107
  131. package/lib-es/bridge/onboard.js.map +1 -1
  132. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
  133. package/lib-es/bridge/prepareTransaction.js +8 -6
  134. package/lib-es/bridge/prepareTransaction.js.map +1 -1
  135. package/lib-es/bridge/signOperation.d.ts.map +1 -1
  136. package/lib-es/bridge/signOperation.js +12 -15
  137. package/lib-es/bridge/signOperation.js.map +1 -1
  138. package/lib-es/bridge/sync.d.ts +1 -2
  139. package/lib-es/bridge/sync.d.ts.map +1 -1
  140. package/lib-es/bridge/sync.js +22 -42
  141. package/lib-es/bridge/sync.js.map +1 -1
  142. package/lib-es/bridge/updateTransaction.d.ts.map +1 -1
  143. package/lib-es/bridge/updateTransaction.js +4 -0
  144. package/lib-es/bridge/updateTransaction.js.map +1 -1
  145. package/lib-es/common-logic/account/getBalance.d.ts +1 -2
  146. package/lib-es/common-logic/account/getBalance.d.ts.map +1 -1
  147. package/lib-es/common-logic/account/getBalance.js +7 -7
  148. package/lib-es/common-logic/account/getBalance.js.map +1 -1
  149. package/lib-es/common-logic/account/getBalance.unit.test.js +3 -6
  150. package/lib-es/common-logic/account/getBalance.unit.test.js.map +1 -1
  151. package/lib-es/common-logic/history/lastBlock.d.ts +1 -2
  152. package/lib-es/common-logic/history/lastBlock.d.ts.map +1 -1
  153. package/lib-es/common-logic/history/lastBlock.js +3 -3
  154. package/lib-es/common-logic/history/lastBlock.js.map +1 -1
  155. package/lib-es/common-logic/history/lastBlock.test.js +2 -5
  156. package/lib-es/common-logic/history/lastBlock.test.js.map +1 -1
  157. package/lib-es/common-logic/history/listOperations.d.ts +1 -2
  158. package/lib-es/common-logic/history/listOperations.d.ts.map +1 -1
  159. package/lib-es/common-logic/history/listOperations.js +2 -2
  160. package/lib-es/common-logic/history/listOperations.js.map +1 -1
  161. package/lib-es/common-logic/transaction/broadcast.d.ts +1 -2
  162. package/lib-es/common-logic/transaction/broadcast.d.ts.map +1 -1
  163. package/lib-es/common-logic/transaction/broadcast.js +4 -5
  164. package/lib-es/common-logic/transaction/broadcast.js.map +1 -1
  165. package/lib-es/common-logic/transaction/broadcast.test.js +5 -8
  166. package/lib-es/common-logic/transaction/broadcast.test.js.map +1 -1
  167. package/lib-es/common-logic/transaction/combine.d.ts +1 -1
  168. package/lib-es/common-logic/transaction/combine.d.ts.map +1 -1
  169. package/lib-es/common-logic/transaction/combine.js +3 -2
  170. package/lib-es/common-logic/transaction/combine.js.map +1 -1
  171. package/lib-es/common-logic/transaction/combine.test.js +13 -3
  172. package/lib-es/common-logic/transaction/combine.test.js.map +1 -1
  173. package/lib-es/common-logic/transaction/craftTransaction.d.ts +4 -8
  174. package/lib-es/common-logic/transaction/craftTransaction.d.ts.map +1 -1
  175. package/lib-es/common-logic/transaction/craftTransaction.js +12 -15
  176. package/lib-es/common-logic/transaction/craftTransaction.js.map +1 -1
  177. package/lib-es/common-logic/transaction/estimateFees.d.ts +1 -2
  178. package/lib-es/common-logic/transaction/estimateFees.d.ts.map +1 -1
  179. package/lib-es/common-logic/transaction/estimateFees.js +3 -4
  180. package/lib-es/common-logic/transaction/estimateFees.js.map +1 -1
  181. package/lib-es/config.d.ts +0 -1
  182. package/lib-es/config.d.ts.map +1 -1
  183. package/lib-es/config.js.map +1 -1
  184. package/lib-es/network/gateway.d.ts +17 -41
  185. package/lib-es/network/gateway.d.ts.map +1 -1
  186. package/lib-es/network/gateway.integ.test.js +15 -19
  187. package/lib-es/network/gateway.integ.test.js.map +1 -1
  188. package/lib-es/network/gateway.js +48 -73
  189. package/lib-es/network/gateway.js.map +1 -1
  190. package/lib-es/network/node.d.ts +2 -2
  191. package/lib-es/network/node.d.ts.map +1 -1
  192. package/lib-es/network/node.js.map +1 -1
  193. package/lib-es/network/types.d.ts +1 -1
  194. package/lib-es/network/types.d.ts.map +1 -1
  195. package/lib-es/signer/getAddress.d.ts.map +1 -1
  196. package/lib-es/signer/getAddress.js +2 -2
  197. package/lib-es/signer/getAddress.js.map +1 -1
  198. package/lib-es/types/bridge.d.ts +3 -18
  199. package/lib-es/types/bridge.d.ts.map +1 -1
  200. package/lib-es/types/index.d.ts +10 -0
  201. package/lib-es/types/index.d.ts.map +1 -1
  202. package/lib-es/types/onboard.d.ts +0 -2
  203. package/lib-es/types/onboard.d.ts.map +1 -1
  204. package/lib-es/types/onboard.js.map +1 -1
  205. package/lib-es/types/signer.d.ts +1 -2
  206. package/lib-es/types/signer.d.ts.map +1 -1
  207. package/package.json +7 -7
  208. package/src/api/getBalance.integ.test.ts +6 -9
  209. package/src/api/index.ts +44 -22
  210. package/src/api/lastBlock.integ.test.ts +1 -1
  211. package/src/api/listOperations.integ.test.ts +1 -1
  212. package/src/bridge/broadcast.test.ts +0 -11
  213. package/src/bridge/broadcast.ts +2 -4
  214. package/src/bridge/createTransaction.ts +1 -1
  215. package/src/bridge/getTransactionStatus.ts +1 -1
  216. package/src/bridge/index.ts +0 -3
  217. package/src/bridge/onboard.integ.test.ts +13 -25
  218. package/src/bridge/onboard.ts +51 -143
  219. package/src/bridge/prepareTransaction.ts +15 -6
  220. package/src/bridge/signOperation.ts +20 -26
  221. package/src/bridge/sync.ts +27 -53
  222. package/src/bridge/updateTransaction.ts +5 -0
  223. package/src/common-logic/account/getBalance.ts +7 -12
  224. package/src/common-logic/account/getBalance.unit.test.ts +3 -8
  225. package/src/common-logic/history/lastBlock.test.ts +2 -7
  226. package/src/common-logic/history/lastBlock.ts +3 -5
  227. package/src/common-logic/history/listOperations.ts +2 -3
  228. package/src/common-logic/transaction/broadcast.test.ts +5 -10
  229. package/src/common-logic/transaction/broadcast.ts +3 -7
  230. package/src/common-logic/transaction/combine.test.ts +13 -3
  231. package/src/common-logic/transaction/combine.ts +4 -2
  232. package/src/common-logic/transaction/craftTransaction.ts +15 -30
  233. package/src/common-logic/transaction/estimateFees.ts +3 -7
  234. package/src/config.ts +0 -1
  235. package/src/network/gateway.integ.test.ts +12 -31
  236. package/src/network/gateway.ts +62 -141
  237. package/src/network/node.ts +3 -3
  238. package/src/network/types.ts +1 -1
  239. package/src/signer/getAddress.ts +4 -6
  240. package/src/types/bridge.ts +0 -21
  241. package/src/types/index.ts +11 -0
  242. package/src/types/onboard.ts +0 -3
  243. package/src/types/signer.ts +1 -2
  244. package/lib/bridge/serialization.d.ts +0 -4
  245. package/lib/bridge/serialization.d.ts.map +0 -1
  246. package/lib/bridge/serialization.js +0 -31
  247. package/lib/bridge/serialization.js.map +0 -1
  248. package/lib/bridge/sync.integ.test.d.ts +0 -2
  249. package/lib/bridge/sync.integ.test.d.ts.map +0 -1
  250. package/lib/bridge/sync.integ.test.js +0 -175
  251. package/lib/bridge/sync.integ.test.js.map +0 -1
  252. package/lib-es/bridge/serialization.d.ts +0 -4
  253. package/lib-es/bridge/serialization.d.ts.map +0 -1
  254. package/lib-es/bridge/serialization.js +0 -27
  255. package/lib-es/bridge/serialization.js.map +0 -1
  256. package/lib-es/bridge/sync.integ.test.d.ts +0 -2
  257. package/lib-es/bridge/sync.integ.test.d.ts.map +0 -1
  258. package/lib-es/bridge/sync.integ.test.js +0 -137
  259. package/lib-es/bridge/sync.integ.test.js.map +0 -1
  260. package/src/bridge/serialization.ts +0 -36
  261. package/src/bridge/sync.integ.test.ts +0 -180
@@ -3,14 +3,15 @@ import { createApi } from ".";
3
3
 
4
4
  let api: AlpacaApi;
5
5
 
6
- describe.skip("devnet", () => {
6
+ describe("devnet", () => {
7
7
  beforeAll(() => {
8
8
  api = createApi({
9
9
  nodeUrl: "https://wallet-validator-devnet-canton.ledger-test.com/v2",
10
10
  networkType: "devnet",
11
11
  gatewayUrl: "https://canton-gateway.api.live.ledger-test.com",
12
12
  useGateway: true,
13
- nativeInstrumentId: "Amulet",
13
+ nativeInstrumentId:
14
+ "6e9fc50fb94e56751b49f09ba2dc84da53a9d7cff08115ebb4f6b7a12d0c990c:Splice.Amulet:Amulet",
14
15
  });
15
16
  });
16
17
 
@@ -19,13 +20,9 @@ describe.skip("devnet", () => {
19
20
  const balance = await api.getBalance(
20
21
  "party-4f2e1485107adf5f::122027c6dbbbdbffe0fa3122ae05175f3b9328e879e9ce96b670354deb64a45683c1",
21
22
  );
22
- expect(balance.length).toBeGreaterThanOrEqual(0);
23
- if (balance.length > 0) {
24
- const nativeBalance = balance.find(b => b.asset.type === "native");
25
- if (nativeBalance) {
26
- expect(nativeBalance.value).toBeGreaterThanOrEqual(BigInt(0));
27
- }
28
- }
23
+ expect(balance.length).toBeGreaterThanOrEqual(1);
24
+ const nativeBalance = balance.find(b => b.asset.type === "native");
25
+ expect(nativeBalance?.value).toBeGreaterThanOrEqual(0);
29
26
  });
30
27
  });
31
28
  });
package/src/api/index.ts CHANGED
@@ -2,42 +2,38 @@ import {
2
2
  AlpacaApi,
3
3
  Block,
4
4
  BlockInfo,
5
+ CraftedTransaction,
5
6
  Cursor,
6
7
  FeeEstimation,
7
8
  Page,
8
9
  Reward,
9
10
  Stake,
10
11
  TransactionIntent,
11
- Operation,
12
- Balance,
13
- Pagination,
14
12
  } from "@ledgerhq/coin-framework/api/index";
15
13
  import coinConfig, { type CantonConfig } from "../config";
16
- import { combine } from "../common-logic/transaction/combine";
14
+ import {
15
+ broadcast,
16
+ combine,
17
+ craftTransaction,
18
+ estimateFees,
19
+ getBalance,
20
+ getNextValidSequence,
21
+ lastBlock,
22
+ listOperations,
23
+ } from "../common-logic";
24
+ import BigNumber from "bignumber.js";
17
25
 
18
26
  export function createApi(config: CantonConfig): AlpacaApi {
19
27
  coinConfig.setCoinConfig(() => ({ ...config, status: { type: "active" } }));
20
28
 
21
29
  return {
22
- broadcast: (_tx: string): Promise<string> => {
23
- throw new Error("broadcast is not supported");
24
- },
30
+ broadcast,
25
31
  combine,
26
- craftTransaction(_transactionIntent: TransactionIntent, _customFees?: FeeEstimation) {
27
- throw new Error("craftTransaction is not supported");
28
- },
29
- estimateFees(_transactionIntent: TransactionIntent): Promise<FeeEstimation> {
30
- throw new Error("estimateFees is not supported");
31
- },
32
- getBalance(_address: string): Promise<Balance[]> {
33
- throw new Error("getBalance is not supported");
34
- },
35
- lastBlock(): Promise<BlockInfo> {
36
- throw new Error("listOperations is not supported");
37
- },
38
- listOperations(_address: string, _pagination: Pagination): Promise<[Operation[], string]> {
39
- throw new Error("listOperations is not supported");
40
- },
32
+ craftTransaction: craft,
33
+ estimateFees: estimate,
34
+ getBalance,
35
+ lastBlock,
36
+ listOperations,
41
37
  getBlock(_height): Promise<Block> {
42
38
  throw new Error("getBlock is not supported");
43
39
  },
@@ -52,3 +48,29 @@ export function createApi(config: CantonConfig): AlpacaApi {
52
48
  },
53
49
  };
54
50
  }
51
+
52
+ async function craft(transactionIntent: TransactionIntent): Promise<CraftedTransaction> {
53
+ const nextSequenceNumber = await getNextValidSequence(transactionIntent.sender);
54
+ const tx = await craftTransaction(
55
+ { address: transactionIntent.sender, nextSequenceNumber },
56
+ {
57
+ recipient: transactionIntent.recipient,
58
+ amount: new BigNumber(transactionIntent.amount.toString()),
59
+ },
60
+ );
61
+ return { transaction: tx.serializedTransaction };
62
+ }
63
+
64
+ async function estimate(transactionIntent: TransactionIntent): Promise<FeeEstimation> {
65
+ const { serializedTransaction } = await craftTransaction(
66
+ { address: transactionIntent.sender },
67
+ {
68
+ recipient: transactionIntent.recipient,
69
+ amount: new BigNumber(transactionIntent.amount.toString()),
70
+ },
71
+ );
72
+
73
+ const value = await estimateFees(serializedTransaction);
74
+
75
+ return { value };
76
+ }
@@ -20,7 +20,7 @@ describe.skip("localnet", () => {
20
20
  });
21
21
  });
22
22
 
23
- describe.skip("devnet", () => {
23
+ describe("devnet", () => {
24
24
  beforeAll(() => {
25
25
  api = createApi({
26
26
  nodeUrl: "https://wallet-validator-devnet-canton.ledger-test.com/v2",
@@ -3,7 +3,7 @@ import { createApi } from ".";
3
3
 
4
4
  let api: AlpacaApi;
5
5
 
6
- describe.skip("devnet", () => {
6
+ describe("devnet", () => {
7
7
  beforeAll(() => {
8
8
  api = createApi({
9
9
  nodeUrl: "https://wallet-validator-devnet-canton.ledger-test.com/v2",
@@ -4,11 +4,6 @@ jest.mock("@ledgerhq/coin-framework/operation");
4
4
  jest.mock("../common-logic");
5
5
  import { patchOperationWithHash } from "@ledgerhq/coin-framework/operation";
6
6
  import { broadcast as broadcastLogic } from "../common-logic";
7
- import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
8
-
9
- const mockCurrency = {
10
- id: "canton_network",
11
- } as unknown as CryptoCurrency;
12
7
 
13
8
  describe("broadcast", () => {
14
9
  let patchOperationSpy: jest.SpyInstance;
@@ -21,9 +16,6 @@ describe("broadcast", () => {
21
16
 
22
17
  it("should broadcast", () => {
23
18
  broadcast({
24
- account: {
25
- currency: mockCurrency,
26
- },
27
19
  signedOperation: {
28
20
  signature: undefined,
29
21
  operation: undefined,
@@ -34,9 +26,6 @@ describe("broadcast", () => {
34
26
 
35
27
  it("should patch operation with hash", () => {
36
28
  broadcast({
37
- account: {
38
- currency: mockCurrency,
39
- },
40
29
  signedOperation: {
41
30
  signature: undefined,
42
31
  operation: undefined,
@@ -4,10 +4,8 @@ import { broadcast as broadcastLogic } from "../common-logic";
4
4
  import { Transaction } from "../types";
5
5
 
6
6
  export const broadcast: AccountBridge<Transaction>["broadcast"] = async ({
7
- account,
8
- signedOperation,
7
+ signedOperation: { signature, operation },
9
8
  }) => {
10
- const { operation, signature } = signedOperation;
11
- const hash = await broadcastLogic(account.currency, signature);
9
+ const hash = await broadcastLogic(signature);
12
10
  return patchOperationWithHash(operation, hash);
13
11
  };
@@ -8,7 +8,7 @@ export const createTransaction: AccountBridge<Transaction>["createTransaction"]
8
8
  amount: new BigNumber(0),
9
9
  recipient: "",
10
10
  fee: null,
11
- memo: "",
11
+ memo: undefined,
12
12
  networkInfo: null,
13
13
  feeCustomUnit: null,
14
14
  });
@@ -25,7 +25,7 @@ export const getTransactionStatus: AccountBridge<
25
25
  const warnings: Record<string, Error> = {};
26
26
 
27
27
  // reserveAmount is the minimum amount of currency that an account must hold in order to stay activated
28
- const reserveAmount = new BigNumber(coinConfig.getCoinConfig(account.currency).minReserve || 0);
28
+ const reserveAmount = new BigNumber(coinConfig.getCoinConfig().minReserve || 0);
29
29
  const estimatedFees = new BigNumber(transaction.fee || 0);
30
30
  const totalSpent = new BigNumber(transaction.amount).plus(estimatedFees);
31
31
  const amount = new BigNumber(transaction.amount);
@@ -21,7 +21,6 @@ import { buildSignOperation } from "./signOperation";
21
21
  import { getAccountShape } from "./sync";
22
22
  import { updateTransaction } from "./updateTransaction";
23
23
  import { buildOnboardAccount, buildAuthorizePreapproval } from "./onboard";
24
- import { assignFromAccountRaw, assignToAccountRaw } from "./serialization";
25
24
 
26
25
  export function createBridges(
27
26
  signerContext: SignerContext<CantonSigner>,
@@ -63,8 +62,6 @@ export function createBridges(
63
62
  sync,
64
63
  receive,
65
64
  signOperation,
66
- assignToAccountRaw,
67
- assignFromAccountRaw,
68
65
  getSerializedAddressParameters,
69
66
  };
70
67
 
@@ -10,14 +10,10 @@ import {
10
10
  CantonPreApprovalResult,
11
11
  } from "../types/onboard";
12
12
  import coinConfig from "../config";
13
- import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
14
13
 
15
- describe("onboard (devnet)", () => {
14
+ describe("onboard integration tests", () => {
16
15
  const mockDeviceId = "test-device-id";
17
16
  const mockDerivationPath = "44'/6767'/0'/0'/0'";
18
- const mockCurrency = {
19
- id: "canton_network",
20
- } as unknown as CryptoCurrency;
21
17
 
22
18
  let onboardedAccount: {
23
19
  keyPair: ReturnType<typeof generateMockKeyPair>;
@@ -57,7 +53,7 @@ describe("onboard (devnet)", () => {
57
53
 
58
54
  const onboardObservable = buildOnboardAccount(mockSignerContext);
59
55
  const onboardValues = await firstValueFrom(
60
- onboardObservable(mockCurrency, mockDeviceId, mockDerivationPath).pipe(toArray()),
56
+ onboardObservable(mockDeviceId, mockDerivationPath).pipe(toArray()),
61
57
  );
62
58
  const onboardResult = onboardValues.find(
63
59
  (value): value is CantonOnboardResult => "partyId" in value,
@@ -76,7 +72,7 @@ describe("onboard (devnet)", () => {
76
72
  };
77
73
 
78
74
  // WHEN
79
- const result = await isAccountOnboarded(mockCurrency, keyPair.publicKeyHex);
75
+ const result = await isAccountOnboarded(keyPair.publicKeyHex);
80
76
 
81
77
  // THEN
82
78
  expect(result).not.toBe(false);
@@ -91,10 +87,10 @@ describe("onboard (devnet)", () => {
91
87
  const keyPair = generateMockKeyPair();
92
88
 
93
89
  // WHEN
94
- const result = await isAccountOnboarded(mockCurrency, keyPair.publicKeyHex);
90
+ const result = await isAccountOnboarded(keyPair.publicKeyHex);
95
91
 
96
92
  // THEN
97
- expect(result).toEqual({ isOnboarded: false });
93
+ expect(result).toBe(false);
98
94
  }, 15000);
99
95
 
100
96
  it("should handle errors gracefully when checking non-existent party", async () => {
@@ -102,10 +98,10 @@ describe("onboard (devnet)", () => {
102
98
  const keyPair = generateMockKeyPair();
103
99
 
104
100
  // WHEN
105
- const result = await isAccountOnboarded(mockCurrency, keyPair.publicKeyHex);
101
+ const result = await isAccountOnboarded(keyPair.publicKeyHex);
106
102
 
107
103
  // THEN
108
- expect(result).toEqual({ isOnboarded: false });
104
+ expect(result).toBe(false);
109
105
  }, 15000);
110
106
  });
111
107
 
@@ -121,7 +117,7 @@ describe("onboard (devnet)", () => {
121
117
 
122
118
  // WHEN
123
119
  const allValues = await firstValueFrom(
124
- onboardObservable(mockCurrency, mockDeviceId, mockDerivationPath).pipe(toArray()),
120
+ onboardObservable(mockDeviceId, mockDerivationPath).pipe(toArray()),
125
121
  );
126
122
  const progressValues = allValues.filter(
127
123
  (value): value is CantonOnboardProgress => "status" in value && !("partyId" in value),
@@ -153,7 +149,7 @@ describe("onboard (devnet)", () => {
153
149
 
154
150
  // WHEN
155
151
  const secondOnboardValues = await firstValueFrom(
156
- secondOnboardObservable(mockCurrency, mockDeviceId, mockDerivationPath).pipe(toArray()),
152
+ secondOnboardObservable(mockDeviceId, mockDerivationPath).pipe(toArray()),
157
153
  );
158
154
  const secondResult = secondOnboardValues.find(
159
155
  (value): value is CantonOnboardResult => "partyId" in value,
@@ -174,12 +170,9 @@ describe("onboard (devnet)", () => {
174
170
 
175
171
  // WHEN
176
172
  const preapprovalValues = await firstValueFrom(
177
- preapprovalObservable(
178
- mockCurrency,
179
- mockDeviceId,
180
- mockDerivationPath,
181
- onboardResult.partyId,
182
- ).pipe(toArray()),
173
+ preapprovalObservable(mockDeviceId, mockDerivationPath, onboardResult.partyId).pipe(
174
+ toArray(),
175
+ ),
183
176
  );
184
177
 
185
178
  const progressValues = preapprovalValues.filter(
@@ -215,12 +208,7 @@ describe("onboard (devnet)", () => {
215
208
  // WHEN & THEN
216
209
  try {
217
210
  await firstValueFrom(
218
- preapprovalObservable(
219
- mockCurrency,
220
- mockDeviceId,
221
- mockDerivationPath,
222
- "invalid-party-id-123",
223
- ),
211
+ preapprovalObservable(mockDeviceId, mockDerivationPath, "invalid-party-id-123"),
224
212
  );
225
213
  expect(true).toBe(true);
226
214
  } catch (error) {
@@ -1,10 +1,6 @@
1
1
  import { Observable } from "rxjs";
2
2
  import { SignerContext } from "@ledgerhq/coin-framework/signer";
3
- import { emptyHistoryCache } from "@ledgerhq/coin-framework/account/index";
4
- import { getDerivationModesForCurrency } from "@ledgerhq/coin-framework/derivation";
5
- import { getAccountShape } from "./sync";
6
- import { CantonAccount, CantonSigner } from "../types";
7
- import type { Account, DerivationMode } from "@ledgerhq/types-live";
3
+ import { CantonSigner } from "../types/signer";
8
4
  import {
9
5
  prepareOnboarding,
10
6
  submitOnboarding,
@@ -23,10 +19,8 @@ import {
23
19
  CantonPreApprovalResult,
24
20
  PrepareTransactionResponse,
25
21
  } from "../types/onboard";
26
- import resolver from "../signer";
27
- import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
28
22
 
29
- async function _getKeypair(
23
+ async function getKeypair(
30
24
  signerContext: SignerContext<CantonSigner>,
31
25
  deviceId: string,
32
26
  derivationPath: string,
@@ -38,27 +32,25 @@ async function _getKeypair(
38
32
  }
39
33
 
40
34
  export const isAccountOnboarded = async (
41
- currency: CryptoCurrency,
42
35
  publicKey: string,
43
- ): Promise<{ isOnboarded: boolean; party_id?: string }> => {
36
+ ): Promise<false | { party_id: string }> => {
44
37
  try {
45
- const { party_id } = await getPartyByPubKey(currency, publicKey);
38
+ const { party_id } = await getPartyByPubKey(publicKey);
46
39
 
47
40
  if (party_id) {
48
- return { isOnboarded: true, party_id };
41
+ return { party_id };
49
42
  } else {
50
- return { isOnboarded: false };
43
+ return false;
51
44
  }
52
45
  } catch (err) {
53
46
  log("[isAccountOnboarded] Error checking party status (likely not onboarded):", err);
54
- return { isOnboarded: false };
47
+ return false;
55
48
  }
56
49
  };
57
50
 
58
51
  export const buildOnboardAccount =
59
52
  (signerContext: SignerContext<CantonSigner>) =>
60
53
  (
61
- currency: CryptoCurrency,
62
54
  deviceId: string,
63
55
  derivationPath: string,
64
56
  ): Observable<CantonOnboardProgress | CantonOnboardResult> =>
@@ -67,36 +59,22 @@ export const buildOnboardAccount =
67
59
  observer.next({
68
60
  status: OnboardStatus.INIT,
69
61
  });
70
- const derivationMode = getDerivationModesForCurrency(currency)[0];
71
- const getAddress = resolver(signerContext);
72
- const { address, publicKey } = await getAddress(deviceId, {
73
- path: derivationPath,
74
- currency,
75
- derivationMode: derivationMode || "",
76
- });
62
+ const keypair = await getKeypair(signerContext, deviceId, derivationPath);
77
63
 
78
64
  observer.next({
79
65
  status: OnboardStatus.PREPARE,
80
66
  });
81
67
 
82
- const { party_id: partyId } = await isAccountOnboarded(currency, publicKey);
83
- if (partyId) {
84
- const account = await createAccount({
85
- address,
86
- derivationPath,
87
- partyId,
88
- currency,
89
- derivationMode,
90
- });
68
+ const isOnboardedResult = await isAccountOnboarded(keypair.publicKey);
69
+ if (isOnboardedResult && isOnboardedResult.party_id) {
91
70
  observer.next({
92
- partyId,
93
- account,
71
+ partyId: isOnboardedResult.party_id,
94
72
  });
95
73
  observer.complete();
96
74
  return;
97
75
  }
98
76
 
99
- const preparedTransaction = await prepareOnboarding(currency, publicKey, "ed25519");
77
+ const preparedTransaction = await prepareOnboarding(keypair.publicKey, "ed25519");
100
78
 
101
79
  observer.next({
102
80
  status: OnboardStatus.SIGN,
@@ -111,44 +89,26 @@ export const buildOnboardAccount =
111
89
  });
112
90
 
113
91
  const result = await submitOnboarding(
114
- currency,
115
- { public_key: publicKey, public_key_type: "ed25519" },
92
+ { public_key: keypair.publicKey, public_key_type: "ed25519" },
116
93
  preparedTransaction,
117
94
  signature,
118
- ).catch(async err => {
95
+ ).catch(err => {
119
96
  if (err.type === "PARTY_ALREADY_EXISTS") {
120
- const account = await createAccount({
121
- address,
122
- derivationPath,
123
- partyId: preparedTransaction.party_id,
124
- currency,
125
- derivationMode,
126
- });
127
97
  observer.next({
128
98
  partyId: preparedTransaction.party_id,
129
- account,
130
99
  });
131
100
  return observer.complete();
132
101
  }
133
102
  throw err;
134
103
  });
135
104
 
136
- if (result) {
137
- observer.next({
138
- status: OnboardStatus.SUCCESS,
139
- });
140
- const account = await createAccount({
141
- address,
142
- derivationPath,
143
- partyId: result.party.party_id,
144
- currency,
145
- derivationMode,
146
- });
147
- observer.next({
148
- partyId: result.party.party_id,
149
- account,
150
- });
151
- }
105
+ observer.next({
106
+ status: OnboardStatus.SUCCESS,
107
+ });
108
+
109
+ observer.next({
110
+ partyId: result?.party?.party_id || "unknown",
111
+ });
152
112
 
153
113
  observer.complete();
154
114
  }
@@ -165,7 +125,6 @@ export const buildOnboardAccount =
165
125
  export const buildAuthorizePreapproval =
166
126
  (signerContext: SignerContext<CantonSigner>) =>
167
127
  (
168
- currency: CryptoCurrency,
169
128
  deviceId: string,
170
129
  derivationPath: string,
171
130
  partyId: string,
@@ -176,10 +135,8 @@ export const buildAuthorizePreapproval =
176
135
  status: PreApprovalStatus.PREPARE,
177
136
  });
178
137
 
179
- const preparedTransaction: PrepareTransactionResponse = await preparePreApprovalTransaction(
180
- currency,
181
- partyId,
182
- );
138
+ const preparedTransaction: PrepareTransactionResponse =
139
+ await preparePreApprovalTransaction(partyId);
183
140
 
184
141
  observer.next({
185
142
  status: PreApprovalStatus.SIGN,
@@ -194,7 +151,6 @@ export const buildAuthorizePreapproval =
194
151
  });
195
152
 
196
153
  const { isApproved } = await submitPreApprovalTransaction(
197
- currency,
198
154
  partyId,
199
155
  preparedTransaction,
200
156
  signature,
@@ -208,35 +164,38 @@ export const buildAuthorizePreapproval =
208
164
  isApproved,
209
165
  });
210
166
 
167
+ // TODO: remove after demo
211
168
  const handleTapRequest = async () => {
212
169
  try {
213
- const { serialized, hash } = await prepareTapRequest(currency, {
170
+ observer.next({
171
+ status: PreApprovalStatus.PREPARE,
172
+ });
173
+
174
+ const { serialized, hash } = await prepareTapRequest({
175
+ partyId,
176
+ });
177
+
178
+ observer.next({
179
+ status: PreApprovalStatus.SIGN,
180
+ });
181
+
182
+ const signature = await signerContext(deviceId, signer =>
183
+ signer.signTransaction(derivationPath, hash),
184
+ );
185
+
186
+ observer.next({
187
+ status: PreApprovalStatus.SUBMIT,
188
+ });
189
+
190
+ await submitTapRequest({
214
191
  partyId,
192
+ serialized,
193
+ signature,
215
194
  });
216
195
 
217
- if (serialized && hash) {
218
- observer.next({
219
- status: PreApprovalStatus.SIGN,
220
- });
221
-
222
- const signature = await signerContext(deviceId, signer =>
223
- signer.signTransaction(derivationPath, hash),
224
- );
225
-
226
- observer.next({
227
- status: PreApprovalStatus.SUBMIT,
228
- });
229
-
230
- await submitTapRequest(currency, {
231
- partyId,
232
- serialized,
233
- signature,
234
- });
235
-
236
- observer.next({
237
- status: PreApprovalStatus.SUCCESS,
238
- });
239
- }
196
+ observer.next({
197
+ status: PreApprovalStatus.SUCCESS,
198
+ });
240
199
  } catch (err) {
241
200
  // Tap request failure should not break the pre-approval flow
242
201
  }
@@ -255,58 +214,7 @@ export const buildAuthorizePreapproval =
255
214
  );
256
215
  });
257
216
 
258
- const createAccount = async ({
259
- address,
260
- partyId,
261
- derivationPath,
262
- currency,
263
- derivationMode,
264
- index = 0,
265
- }: {
266
- address: string;
267
- derivationPath: string;
268
- partyId: string;
269
- currency: CryptoCurrency;
270
- derivationMode: DerivationMode;
271
- index?: number;
272
- }): Promise<Partial<Account>> => {
273
- const accountShape = await getAccountShape(
274
- {
275
- address,
276
- currency,
277
- derivationMode,
278
- derivationPath,
279
- index,
280
- rest: {
281
- cantonResources: {
282
- partyId,
283
- },
284
- },
285
- },
286
- { paginationConfig: {} },
287
- );
288
-
289
- const account: Partial<CantonAccount> = {
290
- ...accountShape,
291
- type: "Account",
292
- xpub: partyId.replace(/:/g, "_"),
293
- index,
294
- // operations: [],
295
- currency,
296
- derivationMode,
297
- lastSyncDate: new Date(),
298
- pendingOperations: [],
299
- seedIdentifier: address,
300
- balanceHistoryCache: emptyHistoryCache,
301
- cantonResources: {
302
- partyId,
303
- },
304
- };
305
-
306
- return account;
307
- };
308
-
309
- const log = (message: string, ...rest: unknown[]) => {
217
+ const log = (message: string, ...rest: any[]) => {
310
218
  // eslint-disable-next-line no-console
311
219
  console.log(message, ...rest);
312
220
  };
@@ -1,16 +1,25 @@
1
1
  import { AccountBridge } from "@ledgerhq/types-live";
2
2
  import { Transaction } from "../types";
3
- import { estimateFees } from "../common-logic";
3
+ import { craftTransaction, estimateFees } from "../common-logic";
4
+ import { getNextSequence } from "../network/node";
4
5
  import BigNumber from "bignumber.js";
5
- import { updateTransaction } from "./updateTransaction";
6
6
 
7
7
  export const prepareTransaction: AccountBridge<Transaction>["prepareTransaction"] = async (
8
8
  account,
9
9
  transaction,
10
10
  ) => {
11
- let fee = transaction.fee;
12
- if (!fee || fee.eq(0)) {
13
- fee = BigNumber((await estimateFees(account.currency)).toString());
11
+ const seq = await getNextSequence(account.freshAddress);
12
+
13
+ const craftedTransaction = await craftTransaction(
14
+ { address: account.freshAddress, nextSequenceNumber: seq },
15
+ { amount: transaction.amount, recipient: transaction.recipient },
16
+ );
17
+
18
+ const fee = await estimateFees(craftedTransaction.serializedTransaction);
19
+
20
+ if (transaction.fee !== new BigNumber(fee.toString())) {
21
+ return { ...transaction, fee: new BigNumber(fee.toString()) };
14
22
  }
15
- return updateTransaction(transaction, { fee });
23
+
24
+ return transaction;
16
25
  };