@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
@@ -1,11 +1,10 @@
1
1
  import { Observable } from "rxjs";
2
- import BigNumber from "bignumber.js";
3
2
  import { FeeNotLoaded } from "@ledgerhq/errors";
4
3
  import { AccountBridge, Operation } from "@ledgerhq/types-live";
5
4
  import { SignerContext } from "@ledgerhq/coin-framework/signer";
6
5
  import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
7
- import { combine, craftTransaction } from "../common-logic";
8
- import { Transaction, CantonSigner } from "../types";
6
+ import { combine, craftTransaction, getNextValidSequence } from "../common-logic";
7
+ import { Transaction, CantonSigner, BoilerplateNativeTransaction } from "../types";
9
8
 
10
9
  export const buildSignOperation =
11
10
  (signerContext: SignerContext<CantonSigner>): AccountBridge<Transaction>["signOperation"] =>
@@ -21,36 +20,30 @@ export const buildSignOperation =
21
20
  type: "device-signature-requested",
22
21
  });
23
22
 
23
+ const nextSequenceNumber = await getNextValidSequence(account.freshAddress);
24
+
24
25
  const signature = await signerContext(deviceId, async signer => {
25
26
  const { freshAddressPath: derivationPath } = account;
26
- const partyId = (account as unknown as { cantonResources: { partyId: string } })
27
- .cantonResources.partyId;
28
- const params: {
29
- recipient?: string;
30
- amount: BigNumber;
31
- tokenId: string;
32
- expireInSeconds: number;
33
- memo?: string;
34
- } = {
35
- recipient: transaction.recipient,
36
- amount: transaction.amount,
37
- expireInSeconds: 60 * 60,
38
- tokenId: "Amulet",
39
- };
40
- if (transaction.memo) {
41
- params.memo = transaction.memo;
42
- }
27
+ const { publicKey } = await signer.getAddress(derivationPath);
43
28
 
44
- const { hash, serializedTransaction } = await craftTransaction(
45
- account.currency,
29
+ const { nativeTransaction, serializedTransaction } = await craftTransaction(
30
+ {
31
+ address: account.freshAddress,
32
+ publicKey,
33
+ },
46
34
  {
47
- address: partyId,
35
+ recipient: transaction.recipient,
36
+ amount: transaction.amount,
37
+ fee: fee,
48
38
  },
49
- params,
50
39
  );
51
- const transactionSignature = await signer.signTransaction(derivationPath, hash);
52
40
 
53
- return combine(serializedTransaction, `${transactionSignature}__PARTY__${partyId}`);
41
+ const transactionSignature = await signer.signTransaction(
42
+ derivationPath,
43
+ serializedTransaction,
44
+ );
45
+
46
+ return combine(serializedTransaction, transactionSignature);
54
47
  });
55
48
 
56
49
  o.next({
@@ -71,6 +64,7 @@ export const buildSignOperation =
71
64
  senders: [account.freshAddress],
72
65
  recipients: [transaction.recipient],
73
66
  date: new Date(),
67
+ transactionSequenceNumber: nextSequenceNumber,
74
68
  extra: {},
75
69
  };
76
70
 
@@ -1,14 +1,14 @@
1
1
  import BigNumber from "bignumber.js";
2
- import { Operation, OperationType } from "@ledgerhq/types-live";
3
- import { decodeAccountId, encodeAccountId } from "@ledgerhq/coin-framework/account/index";
2
+ import { Operation } from "@ledgerhq/types-live";
3
+ import { encodeAccountId } from "@ledgerhq/coin-framework/account/index";
4
4
  import { GetAccountShape, mergeOps } from "@ledgerhq/coin-framework/bridge/jsHelpers";
5
- import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
6
5
  import { getBalance, getLedgerEnd, getOperations, type OperationInfo } from "../network/gateway";
7
- import { CantonAccount } from "../types";
6
+
7
+ import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
8
8
  import coinConfig from "../config";
9
9
 
10
10
  const txInfoToOperationAdapter =
11
- (accountId: string, partyId: string) =>
11
+ (accountId: string, address: string) =>
12
12
  (txInfo: OperationInfo): Operation => {
13
13
  const {
14
14
  transaction_hash,
@@ -18,17 +18,12 @@ const txInfoToOperationAdapter =
18
18
  recipients,
19
19
  transaction_timestamp,
20
20
  fee: { value: fee },
21
- transfers: [{ value: transferValue, details }],
21
+ transfers: [{ value: transferValue }],
22
22
  } = txInfo;
23
- let type: OperationType = "UNKNOWN";
24
- if (txInfo.type === "Send") {
25
- type = senders.includes(partyId) ? "OUT" : "IN";
26
- } else if (txInfo.type === "Receive") {
27
- type = "IN";
28
- }
23
+
24
+ const type = senders.includes(address) ? "OUT" : "IN";
29
25
  const value = new BigNumber(transferValue);
30
26
  const feeValue = new BigNumber(fee);
31
- const memo = details.metadata.reason;
32
27
 
33
28
  const op: Operation = {
34
29
  id: encodeOperationId(accountId, transaction_hash, type),
@@ -45,7 +40,6 @@ const txInfoToOperationAdapter =
45
40
  transactionSequenceNumber: height,
46
41
  extra: {
47
42
  uid,
48
- memo,
49
43
  },
50
44
  };
51
45
 
@@ -55,60 +49,45 @@ const txInfoToOperationAdapter =
55
49
  const filterOperations = (
56
50
  transactions: OperationInfo[],
57
51
  accountId: string,
58
- partyId: string,
52
+ address: string,
59
53
  ): Operation[] => {
60
- return transactions.map(txInfoToOperationAdapter(accountId, partyId));
54
+ return transactions
55
+ .filter(tx => tx.type === "Receive" || tx.type === "Send")
56
+ .map(txInfoToOperationAdapter(accountId, address));
61
57
  };
62
58
 
63
- export const getAccountShape: GetAccountShape<CantonAccount> = async info => {
64
- const { address, initialAccount, currency, derivationMode, derivationPath, rest } = info;
65
-
66
- const xpubOrAddress = (
67
- (initialAccount && initialAccount.id && decodeAccountId(initialAccount.id).xpubOrAddress) ||
68
- ""
69
- ).replace(/:/g, "_");
70
- const partyId =
71
- rest?.cantonResources?.partyId ||
72
- initialAccount?.cantonResources?.partyId ||
73
- xpubOrAddress.replace(/_/g, ":");
59
+ export const getAccountShape: GetAccountShape = async info => {
60
+ const { address, initialAccount, currency, derivationMode } = info;
61
+ // TODO: we need better solution ?
62
+ const xpubOrAddress = address?.replace(/:/g, "_") || "";
74
63
 
75
64
  const accountId = encodeAccountId({
76
65
  type: "js",
77
66
  version: "2",
78
67
  currencyId: currency.id,
79
68
  xpubOrAddress,
80
- derivationMode,
69
+ derivationMode: "",
81
70
  });
82
71
 
72
+ // blockheight retrieval
73
+ const blockHeight = await getLedgerEnd();
74
+
83
75
  // Account info retrieval + spendable balance calculation
84
76
  // const accountInfo = await getAccountInfo(address);
85
- const balances = await getBalance(currency, partyId);
86
-
87
- const balanceData = balances.find(balance => balance.instrument_id === "Amulet") || {
88
- instrument_id: "Amulet",
89
- amount: 0,
90
- locked: false,
91
- };
92
-
93
- const balance = new BigNumber(balanceData.amount);
94
- const reserveMin = coinConfig.getCoinConfig(currency).minReserve || 0;
95
- const lockedAmount = balanceData.locked ? balance : new BigNumber(0);
96
- const spendableBalance = BigNumber.max(
97
- 0,
98
- balance.minus(lockedAmount).minus(BigNumber(reserveMin)),
99
- );
77
+ const balanceData = await getBalance(address);
78
+ const balance = new BigNumber(balanceData[0]?.amount || "0");
79
+ const reserveMin = coinConfig.getCoinConfig().minReserve || 0;
80
+ const spendableBalance = balance.minus(BigNumber(reserveMin));
100
81
 
101
82
  // Tx history fetching
102
83
  const oldOperations = initialAccount?.operations || [];
103
84
  const startAt = oldOperations.length ? (oldOperations[0].blockHeight || 0) + 1 : 0;
104
- const transactionData = await getOperations(currency, partyId, {
105
- cursor: startAt,
85
+ const transactionData = await getOperations(address, {
86
+ cursor: 0,
106
87
  limit: 100,
107
88
  });
108
- // blockheight retrieval
109
- const blockHeight = await getLedgerEnd(currency);
110
89
 
111
- const newOperations = filterOperations(transactionData.operations, accountId, partyId);
90
+ const newOperations = filterOperations(transactionData.operations, accountId, address);
112
91
  const operations = mergeOps(oldOperations, newOperations);
113
92
 
114
93
  // We return the new account shape
@@ -120,11 +99,6 @@ export const getAccountShape: GetAccountShape<CantonAccount> = async info => {
120
99
  spendableBalance,
121
100
  operations,
122
101
  operationsCount: operations.length,
123
- freshAddress: address,
124
- freshAddressPath: derivationPath,
125
- cantonResources: {
126
- partyId,
127
- },
128
102
  };
129
103
 
130
104
  return shape;
@@ -8,5 +8,10 @@ import type { Transaction } from "../types";
8
8
  // NOTE: here is an example transaction updater function
9
9
  // in this case, it resets fee to null depending on the patch content
10
10
  export const updateTransaction: AccountBridge<Transaction>["updateTransaction"] = (tx, patch) => {
11
+ // eslint-disable-next-line no-constant-condition
12
+ if (patch.recipient === "boilerplate1" || true) {
13
+ patch = { ...patch, fee: null };
14
+ }
15
+
11
16
  return defaultUpdateTransaction(tx, patch);
12
17
  };
@@ -1,28 +1,23 @@
1
1
  import { Balance } from "@ledgerhq/coin-framework/api/types";
2
2
  import { getBalance as gatewayGetBalance, type InstrumentBalance } from "../../network/gateway";
3
3
  import coinConfig from "../../config";
4
- import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
5
4
 
6
- const useGateway = (currency: CryptoCurrency) =>
7
- coinConfig.getCoinConfig(currency).useGateway === true;
8
- const getNativeId = (currency: CryptoCurrency) =>
9
- coinConfig.getCoinConfig(currency).nativeInstrumentId;
5
+ const useGateway = () => coinConfig.getCoinConfig().useGateway === true;
6
+ const getNativeId = () => coinConfig.getCoinConfig().nativeInstrumentId;
10
7
 
11
- function adaptInstrument(currency: CryptoCurrency, instrument: InstrumentBalance): Balance {
8
+ function adaptInstrument(instrument: InstrumentBalance): Balance {
12
9
  return {
13
10
  value: BigInt(instrument.amount),
14
11
  locked: instrument.locked === true ? BigInt(instrument.amount) : BigInt(0),
15
12
  asset:
16
- getNativeId(currency) === instrument.instrument_id
13
+ getNativeId() === instrument.instrument_id
17
14
  ? { type: "native" }
18
15
  : { type: "token", assetReference: instrument.instrument_id },
19
16
  };
20
17
  }
21
18
 
22
- export async function getBalance(currency: CryptoCurrency, partyId: string): Promise<Balance[]> {
23
- if (useGateway(currency))
24
- return (await gatewayGetBalance(currency, partyId)).map(instrument =>
25
- adaptInstrument(currency, instrument),
26
- );
19
+ export async function getBalance(partyId: string): Promise<Balance[]> {
20
+ if (useGateway())
21
+ return (await gatewayGetBalance(partyId)).map(instrument => adaptInstrument(instrument));
27
22
  else throw new Error("Not implemented");
28
23
  }
@@ -2,11 +2,6 @@ import { getBalance as getBalanceFromNetwork } from "../../network/gateway";
2
2
  import * as coinConfigModule from "../../config";
3
3
  import { getBalance } from "./getBalance";
4
4
  import { Balance } from "@ledgerhq/coin-framework/api/types";
5
- import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
6
-
7
- const mockCurrency = {
8
- id: "canton_network",
9
- } as unknown as CryptoCurrency;
10
5
 
11
6
  jest.mock("../../network/gateway", () => ({
12
7
  getBalance: jest.fn(),
@@ -40,9 +35,9 @@ describe("getBalance", () => {
40
35
 
41
36
  (getBalanceFromNetwork as jest.Mock).mockResolvedValue(mockInstruments);
42
37
 
43
- const result = await getBalance(mockCurrency, "party-id");
38
+ const result = await getBalance("party-id");
44
39
 
45
- expect(getBalanceFromNetwork).toHaveBeenCalledWith(mockCurrency, "party-id");
40
+ expect(getBalanceFromNetwork).toHaveBeenCalledWith("party-id");
46
41
  expect(result).toEqual<Balance[]>([
47
42
  {
48
43
  value: BigInt(1000),
@@ -62,7 +57,7 @@ describe("getBalance", () => {
62
57
  useGateway: false,
63
58
  } as any);
64
59
 
65
- await expect(getBalance(mockCurrency, "party-id")).rejects.toThrow("Not implemented");
60
+ await expect(getBalance("party-id")).rejects.toThrow("Not implemented");
66
61
  expect(getBalanceFromNetwork).not.toHaveBeenCalled();
67
62
  });
68
63
  });
@@ -1,7 +1,6 @@
1
1
  import { lastBlock } from "./lastBlock";
2
2
  import { getLedgerEnd as gatewayGetLedgerEnd } from "../../network/gateway";
3
3
  import { getLedgerEnd as nodeGetLedgerEnd } from "../../network/node";
4
- import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
5
4
 
6
5
  jest.mock("../../network/gateway", () => ({
7
6
  getLedgerEnd: jest.fn(),
@@ -19,10 +18,6 @@ jest.mock("../../config", () => ({
19
18
 
20
19
  import coinConfig from "../../config";
21
20
 
22
- const mockCurrency = {
23
- id: "canton_network",
24
- } as unknown as CryptoCurrency;
25
-
26
21
  describe("lastBlock", () => {
27
22
  beforeEach(() => {
28
23
  jest.clearAllMocks();
@@ -32,7 +27,7 @@ describe("lastBlock", () => {
32
27
  (coinConfig.getCoinConfig as jest.Mock).mockReturnValue({ useGateway: true });
33
28
  (gatewayGetLedgerEnd as jest.Mock).mockResolvedValue(100);
34
29
 
35
- const result = await lastBlock(mockCurrency);
30
+ const result = await lastBlock();
36
31
 
37
32
  expect(result).toEqual({ height: 100 });
38
33
  expect(gatewayGetLedgerEnd).toHaveBeenCalledTimes(1);
@@ -43,7 +38,7 @@ describe("lastBlock", () => {
43
38
  (coinConfig.getCoinConfig as jest.Mock).mockReturnValue({ useGateway: false });
44
39
  (nodeGetLedgerEnd as jest.Mock).mockResolvedValue(200);
45
40
 
46
- const result = await lastBlock(mockCurrency);
41
+ const result = await lastBlock();
47
42
 
48
43
  expect(result).toEqual({ height: 200 });
49
44
  expect(nodeGetLedgerEnd).toHaveBeenCalledTimes(1);
@@ -2,13 +2,11 @@ import type { BlockInfo } from "@ledgerhq/coin-framework/api/index";
2
2
  import { getLedgerEnd as nodeGetLedgerEnd } from "../../network/node";
3
3
  import { getLedgerEnd } from "../../network/gateway";
4
4
  import coinConfig from "../../config";
5
- import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
6
5
 
7
- const useGateway = (currency: CryptoCurrency) =>
8
- coinConfig.getCoinConfig(currency).useGateway === true;
6
+ const useGateway = () => coinConfig.getCoinConfig().useGateway === true;
9
7
 
10
- export async function lastBlock(currency: CryptoCurrency): Promise<BlockInfo> {
8
+ export async function lastBlock(): Promise<BlockInfo> {
11
9
  return {
12
- height: useGateway(currency) ? await getLedgerEnd(currency) : await nodeGetLedgerEnd(),
10
+ height: useGateway() ? await getLedgerEnd() : await nodeGetLedgerEnd(),
13
11
  };
14
12
  }
@@ -1,6 +1,6 @@
1
1
  import type { Operation, Pagination } from "@ledgerhq/coin-framework/api/index";
2
2
  import { getOperations } from "../../network/gateway";
3
- import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
3
+ import coinConfig from "../../config";
4
4
 
5
5
  /**
6
6
  * Returns list of operations associated to an account.
@@ -10,11 +10,10 @@ import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
10
10
  * Impl to finalize when backend is ready
11
11
  */
12
12
  export async function listOperations(
13
- currency: CryptoCurrency,
14
13
  partyId: string,
15
14
  page: Pagination,
16
15
  ): Promise<[Operation[], string]> {
17
- const { operations, next } = await getOperations(currency, partyId, {
16
+ const { operations, next } = await getOperations(partyId, {
18
17
  cursor: page.pagingToken !== undefined ? parseInt(page.pagingToken) : undefined,
19
18
  minOffset: page.minHeight,
20
19
  limit: page.limit,
@@ -1,7 +1,6 @@
1
1
  import { submit } from "../../network/gateway";
2
2
  import * as coinConfigModule from "../../config";
3
3
  import { broadcast } from "./broadcast";
4
- import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
5
4
 
6
5
  jest.mock("../../network/gateway", () => ({
7
6
  submit: jest.fn(),
@@ -9,13 +8,9 @@ jest.mock("../../network/gateway", () => ({
9
8
 
10
9
  const mockSerialized = JSON.stringify({
11
10
  serialized: "serialized-tx",
12
- signature: "signature__PARTY__alice:123",
11
+ signature: "signature",
13
12
  });
14
13
 
15
- const mockCurrency = {
16
- id: "canton_network",
17
- } as unknown as CryptoCurrency;
18
-
19
14
  describe("broadcast", () => {
20
15
  const mockGetCoinConfig = jest.spyOn(coinConfigModule.default, "getCoinConfig");
21
16
 
@@ -28,11 +23,11 @@ describe("broadcast", () => {
28
23
  useGateway: true,
29
24
  } as any);
30
25
 
31
- (submit as jest.Mock).mockResolvedValue({ update_id: "my-update-id" });
26
+ (submit as jest.Mock).mockResolvedValue({ updateId: "my-update-id" });
32
27
 
33
- const result = await broadcast(mockCurrency, mockSerialized);
28
+ const result = await broadcast(mockSerialized);
34
29
 
35
- expect(submit).toHaveBeenCalledWith(mockCurrency, "alice:123", "serialized-tx", "signature");
30
+ expect(submit).toHaveBeenCalledWith("serialized-tx", "signature");
36
31
  expect(result).toEqual("my-update-id");
37
32
  });
38
33
 
@@ -41,7 +36,7 @@ describe("broadcast", () => {
41
36
  useGateway: false,
42
37
  } as any);
43
38
 
44
- await expect(broadcast(mockCurrency, mockSerialized)).rejects.toThrow("Not implemented");
39
+ await expect(broadcast(mockSerialized)).rejects.toThrow("Not implemented");
45
40
  expect(submit).not.toHaveBeenCalled();
46
41
  });
47
42
  });
@@ -1,14 +1,10 @@
1
1
  import coinConfig from "../../config";
2
2
  import { submit } from "../../network/gateway";
3
- import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
4
3
 
5
- const useGateway = (currency: CryptoCurrency) =>
6
- coinConfig.getCoinConfig(currency).useGateway === true;
4
+ const useGateway = () => coinConfig.getCoinConfig().useGateway === true;
7
5
 
8
- export async function broadcast(currency: CryptoCurrency, signedTx: string): Promise<string> {
6
+ export async function broadcast(signedTx: string): Promise<string> {
9
7
  const parsed: { serialized: string; signature: string } = JSON.parse(signedTx);
10
- const [sig, party] = parsed.signature.split("__PARTY__");
11
- if (useGateway(currency))
12
- return (await submit(currency, party, parsed.serialized, sig)).update_id;
8
+ if (useGateway()) return (await submit(parsed.serialized, parsed.signature)).updateId;
13
9
  else throw new Error("Not implemented");
14
10
  }
@@ -3,15 +3,25 @@ import { combine } from "./combine";
3
3
  describe("combine", () => {
4
4
  it("responds with a Stringify version of the payload to broadcast", () => {
5
5
  // GIVEN
6
- const transaction = "0x000000001";
6
+ const transaction = {
7
+ transaction: {
8
+ serialized: "SERIALIZED",
9
+ json: "JSON",
10
+ hash: "HASH",
11
+ },
12
+ };
7
13
  const signature = "SIGNATURE";
8
14
 
9
15
  // WHEN
10
- const result = combine(transaction, signature);
16
+ const result = combine(JSON.stringify(transaction), signature);
11
17
 
12
18
  // THEN
13
19
  expect(JSON.parse(result)).toEqual({
14
- serialized: "0x000000001",
20
+ transaction: {
21
+ serialized: "SERIALIZED",
22
+ json: "JSON",
23
+ hash: "HASH",
24
+ },
15
25
  signature: "SIGNATURE",
16
26
  });
17
27
  });
@@ -1,7 +1,9 @@
1
1
  // Combines signature with raw transaction
2
- export function combine(serialized: string, signature: string): string {
2
+ export function combine(transaction: string, signature: string): string {
3
+ const tx = JSON.parse(transaction);
4
+
3
5
  return JSON.stringify({
4
- serialized,
6
+ ...tx,
5
7
  signature,
6
8
  });
7
9
  }
@@ -1,13 +1,9 @@
1
1
  import BigNumber from "bignumber.js";
2
- import {
3
- PrepareTransferRequest,
4
- prepareTransferRequest,
5
- PrepareTransferResponse,
6
- } from "../../network/gateway";
7
- import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
2
+ import { BoilerplateNativeTransaction } from "../../types";
3
+
4
+ const encodeNativeTx = (nativeTx: BoilerplateNativeTransaction) => JSON.stringify(nativeTx);
8
5
 
9
6
  export async function craftTransaction(
10
- currency: CryptoCurrency,
11
7
  account: {
12
8
  address: string;
13
9
  nextSequenceNumber?: number;
@@ -16,36 +12,25 @@ export async function craftTransaction(
16
12
  transaction: {
17
13
  recipient?: string;
18
14
  amount: BigNumber;
19
- tokenId: string;
20
- expireInSeconds: number;
21
- memo?: string;
15
+ fee?: BigNumber;
22
16
  },
23
17
  ): Promise<{
24
- nativeTransaction: PrepareTransferResponse;
18
+ nativeTransaction: BoilerplateNativeTransaction;
25
19
  serializedTransaction: string;
26
- hash: string;
27
20
  }> {
28
- const params: PrepareTransferRequest = {
29
- recipient: transaction.recipient || "",
30
- amount: transaction.amount.toString(),
31
- type: "token-transfer-request" as const,
32
- execute_before_secs: transaction.expireInSeconds,
33
- instrument_id: transaction.tokenId,
21
+ const nativeTransaction: BoilerplateNativeTransaction = {
22
+ TransactionType: "Payment",
23
+ Account: account.address,
24
+ Amount: transaction.amount.toString(),
25
+ Destination: transaction.recipient || "",
26
+ Fee: transaction.fee?.toString() || "0",
27
+ Sequence: account.nextSequenceNumber || 0,
34
28
  };
35
29
 
36
- if (transaction.memo) {
37
- params.reason = transaction.memo;
38
- }
39
-
40
- const { serialized, json, hash } = await prepareTransferRequest(
41
- currency,
42
- account.address,
43
- params,
44
- );
30
+ const serializedTransaction = encodeNativeTx(nativeTransaction);
45
31
 
46
32
  return {
47
- nativeTransaction: json,
48
- serializedTransaction: serialized,
49
- hash,
33
+ nativeTransaction,
34
+ serializedTransaction,
50
35
  };
51
36
  }
@@ -1,8 +1,4 @@
1
- import coinConfig from "../../config";
2
- import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
3
-
4
- const feeValue = (currency: CryptoCurrency) => coinConfig.getCoinConfig(currency).fee ?? 1;
5
-
6
- export async function estimateFees(currency: CryptoCurrency): Promise<bigint> {
7
- return Promise.resolve(BigInt(feeValue(currency)));
1
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2
+ export async function estimateFees(serializedTransaction: string): Promise<bigint> {
3
+ return Promise.resolve(BigInt(10_000)); // TODO replace with real implementation
8
4
  }
package/src/config.ts CHANGED
@@ -10,7 +10,6 @@ export type CantonConfig = {
10
10
  networkType: "mainnet" | "devnet" | "localnet";
11
11
  useGateway?: boolean;
12
12
  nativeInstrumentId?: string;
13
- fee?: number;
14
13
  };
15
14
 
16
15
  export type CantonCoinConfig = CurrencyConfig & CantonConfig;