@ledgerhq/coin-canton 0.5.0-nightly.4 → 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 (195) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +36 -39
  3. package/lib/api/getBalance.integ.test.js +4 -8
  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 +8 -11
  7. package/lib/api/index.js.map +1 -1
  8. package/lib/bridge/broadcast.d.ts.map +1 -1
  9. package/lib/bridge/broadcast.js +1 -2
  10. package/lib/bridge/broadcast.js.map +1 -1
  11. package/lib/bridge/index.d.ts.map +1 -1
  12. package/lib/bridge/index.js +0 -3
  13. package/lib/bridge/index.js.map +1 -1
  14. package/lib/bridge/onboard.d.ts +3 -4
  15. package/lib/bridge/onboard.d.ts.map +1 -1
  16. package/lib/bridge/onboard.integ.test.js +3 -3
  17. package/lib/bridge/onboard.integ.test.js.map +1 -1
  18. package/lib/bridge/onboard.js +35 -95
  19. package/lib/bridge/onboard.js.map +1 -1
  20. package/lib/bridge/prepareTransaction.d.ts.map +1 -1
  21. package/lib/bridge/prepareTransaction.js +7 -5
  22. package/lib/bridge/prepareTransaction.js.map +1 -1
  23. package/lib/bridge/signOperation.d.ts.map +1 -1
  24. package/lib/bridge/signOperation.js +9 -7
  25. package/lib/bridge/signOperation.js.map +1 -1
  26. package/lib/bridge/sync.d.ts +1 -2
  27. package/lib/bridge/sync.d.ts.map +1 -1
  28. package/lib/bridge/sync.js +15 -30
  29. package/lib/bridge/sync.js.map +1 -1
  30. package/lib/bridge/updateTransaction.d.ts.map +1 -1
  31. package/lib/bridge/updateTransaction.js +4 -0
  32. package/lib/bridge/updateTransaction.js.map +1 -1
  33. package/lib/common-logic/transaction/broadcast.d.ts.map +1 -1
  34. package/lib/common-logic/transaction/broadcast.js +1 -2
  35. package/lib/common-logic/transaction/broadcast.js.map +1 -1
  36. package/lib/common-logic/transaction/broadcast.test.js +3 -3
  37. package/lib/common-logic/transaction/broadcast.test.js.map +1 -1
  38. package/lib/common-logic/transaction/combine.d.ts +1 -1
  39. package/lib/common-logic/transaction/combine.d.ts.map +1 -1
  40. package/lib/common-logic/transaction/combine.js +3 -2
  41. package/lib/common-logic/transaction/combine.js.map +1 -1
  42. package/lib/common-logic/transaction/combine.test.js +13 -3
  43. package/lib/common-logic/transaction/combine.test.js.map +1 -1
  44. package/lib/common-logic/transaction/craftTransaction.d.ts +3 -5
  45. package/lib/common-logic/transaction/craftTransaction.d.ts.map +1 -1
  46. package/lib/common-logic/transaction/craftTransaction.js +12 -11
  47. package/lib/common-logic/transaction/craftTransaction.js.map +1 -1
  48. package/lib/common-logic/transaction/estimateFees.d.ts.map +1 -1
  49. package/lib/common-logic/transaction/estimateFees.js +1 -6
  50. package/lib/common-logic/transaction/estimateFees.js.map +1 -1
  51. package/lib/config.d.ts +0 -1
  52. package/lib/config.d.ts.map +1 -1
  53. package/lib/config.js.map +1 -1
  54. package/lib/network/gateway.d.ts +8 -22
  55. package/lib/network/gateway.d.ts.map +1 -1
  56. package/lib/network/gateway.integ.test.js +1 -2
  57. package/lib/network/gateway.integ.test.js.map +1 -1
  58. package/lib/network/gateway.js +24 -50
  59. package/lib/network/gateway.js.map +1 -1
  60. package/lib/network/node.d.ts +2 -2
  61. package/lib/network/node.d.ts.map +1 -1
  62. package/lib/network/node.js.map +1 -1
  63. package/lib/network/types.d.ts +1 -1
  64. package/lib/network/types.d.ts.map +1 -1
  65. package/lib/signer/getAddress.d.ts.map +1 -1
  66. package/lib/signer/getAddress.js +2 -2
  67. package/lib/signer/getAddress.js.map +1 -1
  68. package/lib/types/bridge.d.ts +1 -13
  69. package/lib/types/bridge.d.ts.map +1 -1
  70. package/lib/types/index.d.ts +10 -0
  71. package/lib/types/index.d.ts.map +1 -1
  72. package/lib/types/onboard.d.ts +0 -2
  73. package/lib/types/onboard.d.ts.map +1 -1
  74. package/lib/types/onboard.js.map +1 -1
  75. package/lib/types/signer.d.ts +1 -2
  76. package/lib/types/signer.d.ts.map +1 -1
  77. package/lib-es/api/getBalance.integ.test.js +4 -8
  78. package/lib-es/api/getBalance.integ.test.js.map +1 -1
  79. package/lib-es/api/index.d.ts.map +1 -1
  80. package/lib-es/api/index.js +9 -12
  81. package/lib-es/api/index.js.map +1 -1
  82. package/lib-es/bridge/broadcast.d.ts.map +1 -1
  83. package/lib-es/bridge/broadcast.js +1 -2
  84. package/lib-es/bridge/broadcast.js.map +1 -1
  85. package/lib-es/bridge/index.d.ts.map +1 -1
  86. package/lib-es/bridge/index.js +0 -3
  87. package/lib-es/bridge/index.js.map +1 -1
  88. package/lib-es/bridge/onboard.d.ts +3 -4
  89. package/lib-es/bridge/onboard.d.ts.map +1 -1
  90. package/lib-es/bridge/onboard.integ.test.js +3 -3
  91. package/lib-es/bridge/onboard.integ.test.js.map +1 -1
  92. package/lib-es/bridge/onboard.js +35 -92
  93. package/lib-es/bridge/onboard.js.map +1 -1
  94. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
  95. package/lib-es/bridge/prepareTransaction.js +8 -6
  96. package/lib-es/bridge/prepareTransaction.js.map +1 -1
  97. package/lib-es/bridge/signOperation.d.ts.map +1 -1
  98. package/lib-es/bridge/signOperation.js +10 -8
  99. package/lib-es/bridge/signOperation.js.map +1 -1
  100. package/lib-es/bridge/sync.d.ts +1 -2
  101. package/lib-es/bridge/sync.d.ts.map +1 -1
  102. package/lib-es/bridge/sync.js +16 -31
  103. package/lib-es/bridge/sync.js.map +1 -1
  104. package/lib-es/bridge/updateTransaction.d.ts.map +1 -1
  105. package/lib-es/bridge/updateTransaction.js +4 -0
  106. package/lib-es/bridge/updateTransaction.js.map +1 -1
  107. package/lib-es/common-logic/transaction/broadcast.d.ts.map +1 -1
  108. package/lib-es/common-logic/transaction/broadcast.js +1 -2
  109. package/lib-es/common-logic/transaction/broadcast.js.map +1 -1
  110. package/lib-es/common-logic/transaction/broadcast.test.js +3 -3
  111. package/lib-es/common-logic/transaction/broadcast.test.js.map +1 -1
  112. package/lib-es/common-logic/transaction/combine.d.ts +1 -1
  113. package/lib-es/common-logic/transaction/combine.d.ts.map +1 -1
  114. package/lib-es/common-logic/transaction/combine.js +3 -2
  115. package/lib-es/common-logic/transaction/combine.js.map +1 -1
  116. package/lib-es/common-logic/transaction/combine.test.js +13 -3
  117. package/lib-es/common-logic/transaction/combine.test.js.map +1 -1
  118. package/lib-es/common-logic/transaction/craftTransaction.d.ts +3 -5
  119. package/lib-es/common-logic/transaction/craftTransaction.d.ts.map +1 -1
  120. package/lib-es/common-logic/transaction/craftTransaction.js +12 -11
  121. package/lib-es/common-logic/transaction/craftTransaction.js.map +1 -1
  122. package/lib-es/common-logic/transaction/estimateFees.d.ts.map +1 -1
  123. package/lib-es/common-logic/transaction/estimateFees.js +1 -3
  124. package/lib-es/common-logic/transaction/estimateFees.js.map +1 -1
  125. package/lib-es/config.d.ts +0 -1
  126. package/lib-es/config.d.ts.map +1 -1
  127. package/lib-es/config.js.map +1 -1
  128. package/lib-es/network/gateway.d.ts +8 -22
  129. package/lib-es/network/gateway.d.ts.map +1 -1
  130. package/lib-es/network/gateway.integ.test.js +1 -2
  131. package/lib-es/network/gateway.integ.test.js.map +1 -1
  132. package/lib-es/network/gateway.js +24 -49
  133. package/lib-es/network/gateway.js.map +1 -1
  134. package/lib-es/network/node.d.ts +2 -2
  135. package/lib-es/network/node.d.ts.map +1 -1
  136. package/lib-es/network/node.js.map +1 -1
  137. package/lib-es/network/types.d.ts +1 -1
  138. package/lib-es/network/types.d.ts.map +1 -1
  139. package/lib-es/signer/getAddress.d.ts.map +1 -1
  140. package/lib-es/signer/getAddress.js +2 -2
  141. package/lib-es/signer/getAddress.js.map +1 -1
  142. package/lib-es/types/bridge.d.ts +1 -13
  143. package/lib-es/types/bridge.d.ts.map +1 -1
  144. package/lib-es/types/index.d.ts +10 -0
  145. package/lib-es/types/index.d.ts.map +1 -1
  146. package/lib-es/types/onboard.d.ts +0 -2
  147. package/lib-es/types/onboard.d.ts.map +1 -1
  148. package/lib-es/types/onboard.js.map +1 -1
  149. package/lib-es/types/signer.d.ts +1 -2
  150. package/lib-es/types/signer.d.ts.map +1 -1
  151. package/package.json +7 -7
  152. package/src/api/getBalance.integ.test.ts +5 -8
  153. package/src/api/index.ts +26 -33
  154. package/src/bridge/broadcast.ts +3 -2
  155. package/src/bridge/index.ts +0 -3
  156. package/src/bridge/onboard.integ.test.ts +3 -3
  157. package/src/bridge/onboard.ts +47 -120
  158. package/src/bridge/prepareTransaction.ts +15 -6
  159. package/src/bridge/signOperation.ts +16 -9
  160. package/src/bridge/sync.ts +19 -42
  161. package/src/bridge/updateTransaction.ts +5 -0
  162. package/src/common-logic/transaction/broadcast.test.ts +3 -3
  163. package/src/common-logic/transaction/broadcast.ts +1 -2
  164. package/src/common-logic/transaction/combine.test.ts +13 -3
  165. package/src/common-logic/transaction/combine.ts +4 -2
  166. package/src/common-logic/transaction/craftTransaction.ts +17 -15
  167. package/src/common-logic/transaction/estimateFees.ts +1 -5
  168. package/src/config.ts +0 -1
  169. package/src/network/gateway.integ.test.ts +1 -2
  170. package/src/network/gateway.ts +36 -84
  171. package/src/network/node.ts +3 -3
  172. package/src/network/types.ts +1 -1
  173. package/src/signer/getAddress.ts +4 -6
  174. package/src/types/bridge.ts +0 -16
  175. package/src/types/index.ts +11 -0
  176. package/src/types/onboard.ts +0 -3
  177. package/src/types/signer.ts +1 -2
  178. package/lib/bridge/serialization.d.ts +0 -4
  179. package/lib/bridge/serialization.d.ts.map +0 -1
  180. package/lib/bridge/serialization.js +0 -31
  181. package/lib/bridge/serialization.js.map +0 -1
  182. package/lib/bridge/sync.integ.test.d.ts +0 -2
  183. package/lib/bridge/sync.integ.test.d.ts.map +0 -1
  184. package/lib/bridge/sync.integ.test.js +0 -175
  185. package/lib/bridge/sync.integ.test.js.map +0 -1
  186. package/lib-es/bridge/serialization.d.ts +0 -4
  187. package/lib-es/bridge/serialization.d.ts.map +0 -1
  188. package/lib-es/bridge/serialization.js +0 -27
  189. package/lib-es/bridge/serialization.js.map +0 -1
  190. package/lib-es/bridge/sync.integ.test.d.ts +0 -2
  191. package/lib-es/bridge/sync.integ.test.d.ts.map +0 -1
  192. package/lib-es/bridge/sync.integ.test.js +0 -137
  193. package/lib-es/bridge/sync.integ.test.js.map +0 -1
  194. package/src/bridge/serialization.ts +0 -36
  195. package/src/bridge/sync.integ.test.ts +0 -180
@@ -1,14 +1,14 @@
1
1
  import BigNumber from "bignumber.js";
2
2
  import { Operation } from "@ledgerhq/types-live";
3
- import { decodeAccountId, encodeAccountId } from "@ledgerhq/coin-framework/account/index";
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,
@@ -20,7 +20,8 @@ const txInfoToOperationAdapter =
20
20
  fee: { value: fee },
21
21
  transfers: [{ value: transferValue }],
22
22
  } = txInfo;
23
- const type = senders.includes(partyId) ? "OUT" : "IN";
23
+
24
+ const type = senders.includes(address) ? "OUT" : "IN";
24
25
  const value = new BigNumber(transferValue);
25
26
  const feeValue = new BigNumber(fee);
26
27
 
@@ -48,31 +49,24 @@ const txInfoToOperationAdapter =
48
49
  const filterOperations = (
49
50
  transactions: OperationInfo[],
50
51
  accountId: string,
51
- partyId: string,
52
+ address: string,
52
53
  ): Operation[] => {
53
54
  return transactions
54
55
  .filter(tx => tx.type === "Receive" || tx.type === "Send")
55
- .map(txInfoToOperationAdapter(accountId, partyId));
56
+ .map(txInfoToOperationAdapter(accountId, address));
56
57
  };
57
58
 
58
- export const getAccountShape: GetAccountShape<CantonAccount> = async info => {
59
- const { address, initialAccount, currency, derivationMode, derivationPath, rest } = info;
60
-
61
- const xpubOrAddress = (
62
- (initialAccount && initialAccount.id && decodeAccountId(initialAccount.id).xpubOrAddress) ||
63
- ""
64
- ).replace(/:/g, "_");
65
- const partyId =
66
- rest?.cantonResources?.partyId ||
67
- initialAccount?.cantonResources?.partyId ||
68
- 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, "_") || "";
69
63
 
70
64
  const accountId = encodeAccountId({
71
65
  type: "js",
72
66
  version: "2",
73
67
  currencyId: currency.id,
74
68
  xpubOrAddress,
75
- derivationMode,
69
+ derivationMode: "",
76
70
  });
77
71
 
78
72
  // blockheight retrieval
@@ -80,32 +74,20 @@ export const getAccountShape: GetAccountShape<CantonAccount> = async info => {
80
74
 
81
75
  // Account info retrieval + spendable balance calculation
82
76
  // const accountInfo = await getAccountInfo(address);
83
- const balances = await getBalance(partyId);
84
-
85
- // TODO change to balance.instrument_id === "Amulet" after update on backend
86
- const balanceData = balances.find(balance => balance.instrument_id.includes("Amulet")) || {
87
- instrument_id: "Amulet",
88
- amount: 0,
89
- locked: false,
90
- };
91
-
92
- const balance = new BigNumber(balanceData.amount);
77
+ const balanceData = await getBalance(address);
78
+ const balance = new BigNumber(balanceData[0]?.amount || "0");
93
79
  const reserveMin = coinConfig.getCoinConfig().minReserve || 0;
94
- const lockedAmount = balanceData.locked ? balance : new BigNumber(0);
95
- const spendableBalance = BigNumber.max(
96
- 0,
97
- balance.minus(lockedAmount).minus(BigNumber(reserveMin)),
98
- );
80
+ const spendableBalance = balance.minus(BigNumber(reserveMin));
99
81
 
100
82
  // Tx history fetching
101
83
  const oldOperations = initialAccount?.operations || [];
102
84
  const startAt = oldOperations.length ? (oldOperations[0].blockHeight || 0) + 1 : 0;
103
- const transactionData = await getOperations(partyId, {
104
- cursor: startAt,
85
+ const transactionData = await getOperations(address, {
86
+ cursor: 0,
105
87
  limit: 100,
106
88
  });
107
89
 
108
- const newOperations = filterOperations(transactionData.operations, accountId, partyId);
90
+ const newOperations = filterOperations(transactionData.operations, accountId, address);
109
91
  const operations = mergeOps(oldOperations, newOperations);
110
92
 
111
93
  // We return the new account shape
@@ -117,11 +99,6 @@ export const getAccountShape: GetAccountShape<CantonAccount> = async info => {
117
99
  spendableBalance,
118
100
  operations,
119
101
  operationsCount: operations.length,
120
- freshAddress: address,
121
- freshAddressPath: derivationPath,
122
- cantonResources: {
123
- partyId,
124
- },
125
102
  };
126
103
 
127
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
  };
@@ -8,7 +8,7 @@ jest.mock("../../network/gateway", () => ({
8
8
 
9
9
  const mockSerialized = JSON.stringify({
10
10
  serialized: "serialized-tx",
11
- signature: "signature__PARTY__alice:123",
11
+ signature: "signature",
12
12
  });
13
13
 
14
14
  describe("broadcast", () => {
@@ -23,11 +23,11 @@ describe("broadcast", () => {
23
23
  useGateway: true,
24
24
  } as any);
25
25
 
26
- (submit as jest.Mock).mockResolvedValue({ update_id: "my-update-id" });
26
+ (submit as jest.Mock).mockResolvedValue({ updateId: "my-update-id" });
27
27
 
28
28
  const result = await broadcast(mockSerialized);
29
29
 
30
- expect(submit).toHaveBeenCalledWith("alice:123", "serialized-tx", "signature");
30
+ expect(submit).toHaveBeenCalledWith("serialized-tx", "signature");
31
31
  expect(result).toEqual("my-update-id");
32
32
  });
33
33
 
@@ -5,7 +5,6 @@ const useGateway = () => coinConfig.getCoinConfig().useGateway === true;
5
5
 
6
6
  export async function broadcast(signedTx: string): Promise<string> {
7
7
  const parsed: { serialized: string; signature: string } = JSON.parse(signedTx);
8
- const [sig, party] = parsed.signature.split("__PARTY__");
9
- if (useGateway()) return (await submit(party, parsed.serialized, sig)).update_id;
8
+ if (useGateway()) return (await submit(parsed.serialized, parsed.signature)).updateId;
10
9
  else throw new Error("Not implemented");
11
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,5 +1,7 @@
1
1
  import BigNumber from "bignumber.js";
2
- import { prepareTransferRequest, PrepareTransferResponse } from "../../network/gateway";
2
+ import { BoilerplateNativeTransaction } from "../../types";
3
+
4
+ const encodeNativeTx = (nativeTx: BoilerplateNativeTransaction) => JSON.stringify(nativeTx);
3
5
 
4
6
  export async function craftTransaction(
5
7
  account: {
@@ -10,25 +12,25 @@ export async function craftTransaction(
10
12
  transaction: {
11
13
  recipient?: string;
12
14
  amount: BigNumber;
13
- tokenId: string;
14
- expireInSeconds: number;
15
+ fee?: BigNumber;
15
16
  },
16
17
  ): Promise<{
17
- nativeTransaction: PrepareTransferResponse;
18
+ nativeTransaction: BoilerplateNativeTransaction;
18
19
  serializedTransaction: string;
19
- hash: string;
20
20
  }> {
21
- const { serialized, json, hash } = await prepareTransferRequest(account.address, {
22
- recipient: transaction.recipient || "",
23
- amount: transaction.amount.toNumber(),
24
- type: "token-transfer-request",
25
- execute_before_secs: transaction.expireInSeconds,
26
- instrument_id: transaction.tokenId,
27
- });
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,
28
+ };
29
+
30
+ const serializedTransaction = encodeNativeTx(nativeTransaction);
28
31
 
29
32
  return {
30
- nativeTransaction: json,
31
- serializedTransaction: serialized,
32
- hash,
33
+ nativeTransaction,
34
+ serializedTransaction,
33
35
  };
34
36
  }
@@ -1,8 +1,4 @@
1
- import coinConfig from "../../config";
2
-
3
- const feeValue = () => coinConfig.getCoinConfig().fee ?? 10_000;
4
-
5
1
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
6
2
  export async function estimateFees(serializedTransaction: string): Promise<bigint> {
7
- return Promise.resolve(BigInt(feeValue())); // TODO replace with real implementation
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;
@@ -58,8 +58,7 @@ describe("gateway (devnet)", () => {
58
58
  expect(response).toHaveProperty("public_key_fingerprint");
59
59
  expect(response).toHaveProperty("transactions");
60
60
  expect(response.transactions).toHaveProperty("combined_hash");
61
- expect(response.party_name).toBeDefined();
62
- expect(typeof response.party_name).toBe("string");
61
+ expect(response.party_name).toBe(keyPair.publicKeyHex);
63
62
 
64
63
  expect(response.public_key_fingerprint).toBe(keyPair.fingerprint);
65
64
  }, 30000);
@@ -1,6 +1,4 @@
1
1
  import network from "@ledgerhq/live-network";
2
- import type { LiveNetworkRequest } from "@ledgerhq/live-network/network";
3
- import { getEnv } from "@ledgerhq/live-env";
4
2
  import coinConfig from "../config";
5
3
  import {
6
4
  PrepareTransactionRequest,
@@ -39,21 +37,6 @@ type OnboardingPrepareRequest = {
39
37
  public_key_type: string;
40
38
  };
41
39
 
42
- export type PrepareTransferResponse = {
43
- hash: string;
44
- json: any; // The actual structure is complex, using any for now
45
- serialized: string;
46
- };
47
-
48
- export type PrepareTransferRequest = {
49
- type: "token-transfer-request";
50
- amount: number;
51
- recipient: string;
52
- execute_before_secs: number;
53
- instrument_id: string;
54
- reason?: string;
55
- };
56
-
57
40
  type OnboardingSubmitRequest = {
58
41
  prepare_request: OnboardingPrepareRequest;
59
42
  prepare_response: OnboardingPrepareResponse;
@@ -72,7 +55,7 @@ type TransactionSubmitRequest = {
72
55
  signature: string;
73
56
  };
74
57
 
75
- type TransactionSubmitResponse = { update_id: string };
58
+ type TransactionSubmitResponse = { updateId: string };
76
59
 
77
60
  export type InstrumentBalance = {
78
61
  instrument_id: string;
@@ -264,18 +247,6 @@ export type OperationInfo =
264
247
 
265
248
  const getGatewayUrl = () => coinConfig.getCoinConfig().gatewayUrl;
266
249
  const getNodeId = () => coinConfig.getCoinConfig().nodeId || "ledger-devnet-stg";
267
- const getNetworkType = () => coinConfig.getCoinConfig().networkType;
268
-
269
- const gatewayNetwork = <T, U = unknown>(req: LiveNetworkRequest<U>) => {
270
- const API_KEY = getEnv("CANTON_API_KEY");
271
- return network<T, U>({
272
- ...req,
273
- headers: {
274
- ...(req.headers || {}),
275
- ...(API_KEY && { "X-Ledger-Canton-Api-Key": API_KEY }),
276
- },
277
- });
278
- };
279
250
 
280
251
  export async function prepareOnboarding(
281
252
  pubKey: string,
@@ -285,13 +256,13 @@ export async function prepareOnboarding(
285
256
  const nodeId = getNodeId();
286
257
  const fullUrl = `${gatewayUrl}/v1/node/${nodeId}/onboarding/prepare`;
287
258
 
288
- const { data } = await gatewayNetwork<OnboardingPrepareResponse, OnboardingPrepareRequest>({
259
+ const { data } = await network<OnboardingPrepareResponse>({
289
260
  method: "POST",
290
261
  url: fullUrl,
291
262
  data: {
292
263
  public_key: pubKey,
293
264
  public_key_type: pubKeyType,
294
- },
265
+ } satisfies OnboardingPrepareRequest,
295
266
  });
296
267
 
297
268
  return data;
@@ -302,34 +273,35 @@ export async function submitOnboarding(
302
273
  prepareResponse: OnboardingPrepareResponse,
303
274
  signature: string,
304
275
  ) {
305
- const { data } = await gatewayNetwork<OnboardingSubmitResponse, OnboardingSubmitRequest>({
276
+ const { data } = await network<OnboardingSubmitResponse>({
306
277
  method: "POST",
307
278
  url: `${getGatewayUrl()}/v1/node/${getNodeId()}/onboarding/submit`,
308
279
  data: {
309
280
  prepare_request: prepareRequest,
310
281
  prepare_response: prepareResponse,
311
282
  signature,
312
- },
283
+ } satisfies OnboardingSubmitRequest,
313
284
  });
314
285
  return data;
315
286
  }
316
287
 
317
- export async function submit(partyId: string, serialized: string, signature: string) {
318
- const { data } = await gatewayNetwork<TransactionSubmitResponse, TransactionSubmitRequest>({
288
+ export async function submit(serializedTx: string, signature: string) {
289
+ const { data } = await network<TransactionSubmitResponse>({
319
290
  method: "POST",
320
- url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/transaction/submit`,
291
+ url: `${getGatewayUrl()}/v1/node/${getNodeId()}/transaction/submit`,
321
292
  data: {
322
- serialized,
293
+ serialized: serializedTx,
323
294
  signature,
324
- },
295
+ } satisfies TransactionSubmitRequest,
325
296
  });
326
297
  return data;
327
298
  }
328
299
 
329
300
  export async function getBalance(partyId: string): Promise<InstrumentBalance[]> {
330
- const { data } = await gatewayNetwork<InstrumentBalance[]>({
301
+ const { data } = await network<InstrumentBalance[]>({
331
302
  method: "GET",
332
- url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/balance`,
303
+ // TODO: we need better solution ?
304
+ url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId.replace(/_/g, ":")}/balance`,
333
305
  });
334
306
  return data;
335
307
  }
@@ -343,7 +315,7 @@ export async function getPartyByPubKey(pubKey: string): Promise<PartyInfo> {
343
315
  }
344
316
 
345
317
  async function getParty(identifier: string, by: "party-id" | "public-key"): Promise<PartyInfo> {
346
- const { data } = await gatewayNetwork<PartyInfo>({
318
+ const { data } = await network<PartyInfo>({
347
319
  method: "GET",
348
320
  url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${identifier}?by=${by}`,
349
321
  });
@@ -362,26 +334,26 @@ export async function getOperations(
362
334
  next: number;
363
335
  operations: OperationInfo[];
364
336
  }> {
365
- const { data } = await gatewayNetwork<{
337
+ const { data } = await network<{
366
338
  next: number;
367
339
  operations: OperationInfo[];
368
340
  }>({
369
341
  method: "GET",
370
- url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/operations`,
371
- params: options,
342
+ url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId.replace(/_/g, ":")}/operations`,
343
+ data: options,
372
344
  });
373
345
  return data;
374
346
  }
375
347
 
376
- type PrepareTapRequest = {
348
+ type PrepareTapRequestRequest = {
377
349
  partyId: string;
378
350
  amount?: number;
379
351
  };
380
352
 
381
- type PrepareTapResponse = {
382
- serialized: string;
353
+ type PrepareTapRequestResponse = {
354
+ serialized: "string";
383
355
  json: null;
384
- hash: string;
356
+ hash: "string";
385
357
  };
386
358
 
387
359
  enum TransactionType {
@@ -392,15 +364,8 @@ enum TransactionType {
392
364
  export async function prepareTapRequest({
393
365
  partyId,
394
366
  amount = 1000000,
395
- }: PrepareTapRequest): Promise<PrepareTapResponse> {
396
- if (getNetworkType() === "mainnet") {
397
- return {
398
- serialized: "",
399
- json: null,
400
- hash: "",
401
- };
402
- }
403
- const { data } = await gatewayNetwork<PrepareTapResponse, { amount: number; type: string }>({
367
+ }: PrepareTapRequestRequest): Promise<PrepareTapRequestResponse> {
368
+ const { data } = await network<PrepareTapRequestResponse>({
404
369
  method: "POST",
405
370
  url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/transaction/prepare`,
406
371
  data: {
@@ -427,34 +392,19 @@ export async function submitTapRequest({
427
392
  serialized,
428
393
  signature,
429
394
  }: SubmitTapRequestRequest): Promise<SubmitTapRequestResponse> {
430
- const { data } = await gatewayNetwork<
431
- SubmitTapRequestResponse,
432
- Omit<SubmitTapRequestRequest, "partyId">
433
- >({
395
+ const { data } = await network<SubmitTapRequestResponse>({
434
396
  method: "POST",
435
397
  url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/transaction/submit`,
436
398
  data: {
437
399
  serialized,
438
400
  signature,
439
- },
440
- });
441
- return data;
442
- }
443
-
444
- export async function prepareTransferRequest(
445
- partyId: string,
446
- params: PrepareTransferRequest,
447
- ): Promise<PrepareTransferResponse> {
448
- const { data } = await gatewayNetwork<PrepareTransferResponse, PrepareTransferRequest>({
449
- method: "POST",
450
- url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/transaction/prepare`,
451
- data: params,
401
+ } satisfies Omit<SubmitTapRequestRequest, "partyId">,
452
402
  });
453
403
  return data;
454
404
  }
455
405
 
456
406
  export async function getLedgerEnd(): Promise<number> {
457
- const { data } = await gatewayNetwork<number>({
407
+ const { data } = await network<number>({
458
408
  method: "GET",
459
409
  url: `${getGatewayUrl()}/v1/node/${getNodeId()}/ledger-end`,
460
410
  });
@@ -464,29 +414,31 @@ export async function getLedgerEnd(): Promise<number> {
464
414
  export async function preparePreApprovalTransaction(
465
415
  partyId: string,
466
416
  ): Promise<PrepareTransactionResponse> {
467
- const { data } = await gatewayNetwork<PrepareTransactionResponse, PrepareTransactionRequest>({
417
+ const { data } = await network<PrepareTransactionResponse>({
468
418
  method: "POST",
469
419
  url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/transaction/prepare`,
470
420
  data: {
471
421
  type: TransactionType.TRANSFER_PRE_APPROVAL_PROPOSAL,
472
422
  receiver: partyId,
473
- },
423
+ } satisfies PrepareTransactionRequest,
474
424
  });
475
425
  return data;
476
426
  }
477
427
 
478
428
  export async function submitPreApprovalTransaction(
479
429
  partyId: string,
480
- { serialized }: PrepareTransactionResponse,
430
+ preparedTransaction: PrepareTransactionResponse,
481
431
  signature: string,
482
432
  ): Promise<PreApprovalResult> {
483
- const { data } = await gatewayNetwork<SubmitTransactionResponse, SubmitTransactionRequest>({
433
+ const submitRequest: SubmitTransactionRequest = {
434
+ serialized: preparedTransaction.serialized,
435
+ signature,
436
+ };
437
+
438
+ const { data } = await network<SubmitTransactionResponse>({
484
439
  method: "POST",
485
440
  url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/transaction/submit`,
486
- data: {
487
- serialized,
488
- signature,
489
- },
441
+ data: submitRequest,
490
442
  });
491
443
 
492
444
  return {
@@ -3,7 +3,7 @@ import network from "@ledgerhq/live-network";
3
3
  import type { LiveNetworkRequest } from "@ledgerhq/live-network/network";
4
4
  import { getEnv } from "@ledgerhq/live-env";
5
5
  import coinConfig from "../config";
6
- import { AccountInfoResponse, SubmitResponse } from "./types";
6
+ import { AccountInfoResponse, SubmitReponse } from "./types";
7
7
  import crypto from "crypto";
8
8
 
9
9
  const getNodeUrl = () => coinConfig.getCoinConfig().nodeUrl || "";
@@ -86,10 +86,10 @@ export const getLedgerEnd = async (): Promise<number> => {
86
86
  return data.offset;
87
87
  };
88
88
 
89
- export const submit = async (signedTx: string): Promise<SubmitResponse> => {
89
+ export const submit = async (signedTx: string): Promise<SubmitReponse> => {
90
90
  // @ts-expect-error: add NODE_BOILERPLATE to libs/env/src/env.ts
91
91
  const url = `${getEnv("NODE_BOILERPLATE")}/submit`;
92
- const { data } = await network<SubmitResponse>({
92
+ const { data } = await network<SubmitReponse>({
93
93
  url,
94
94
  method: "GET",
95
95
  });
@@ -40,7 +40,7 @@ export type AccountInfoResponse = {
40
40
  validated: boolean;
41
41
  } & ResponseStatus;
42
42
 
43
- export type SubmitResponse = {
43
+ export type SubmitReponse = {
44
44
  accepted: boolean;
45
45
  tx_hash: string;
46
46
  };
@@ -1,19 +1,17 @@
1
1
  import { GetAddressOptions } from "@ledgerhq/coin-framework/derivation";
2
2
  import { GetAddressFn } from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
3
3
  import { SignerContext } from "@ledgerhq/coin-framework/signer";
4
- import { CantonSigner, CantonAddress } from "../types";
4
+ import { CantonSigner } from "../types";
5
5
 
6
6
  const getAddress = (signerContext: SignerContext<CantonSigner>): GetAddressFn => {
7
- return async (deviceId: string, { path, verify }: GetAddressOptions) => {
8
- const { address, publicKey } = await signerContext(deviceId, signer =>
9
- signer.getAddress(path, verify),
10
- );
7
+ return async (deviceId: string, { path }: GetAddressOptions) => {
8
+ const { address, publicKey } = await signerContext(deviceId, signer => signer.getAddress(path));
11
9
 
12
10
  return {
13
11
  path,
14
12
  address,
15
13
  publicKey,
16
- } satisfies CantonAddress;
14
+ };
17
15
  };
18
16
  };
19
17
 
@@ -1,8 +1,6 @@
1
1
  import type { BigNumber } from "bignumber.js";
2
2
  import type { Observable } from "rxjs";
3
3
  import type {
4
- Account,
5
- AccountRaw,
6
4
  CurrencyBridge,
7
5
  TransactionCommon,
8
6
  TransactionCommonRaw,
@@ -52,17 +50,3 @@ export type TransactionRaw = TransactionCommonRaw & {
52
50
 
53
51
  export type TransactionStatus = TransactionStatusCommon;
54
52
  export type TransactionStatusRaw = TransactionStatusCommonRaw;
55
-
56
- export type CantonResources = {
57
- partyId: string;
58
- };
59
- export type CantonResourcesRaw = {
60
- partyId: string;
61
- };
62
-
63
- export type CantonAccount = Account & {
64
- cantonResources?: CantonResources;
65
- };
66
- export type CantonAccountRaw = AccountRaw & {
67
- cantonResources: CantonResourcesRaw;
68
- };
@@ -1,3 +1,14 @@
1
1
  export * from "./bridge";
2
2
  export * from "./onboard";
3
3
  export * from "./signer";
4
+
5
+ export type BoilerplateNativeTransaction = {
6
+ TransactionType: "Payment";
7
+ Account: string;
8
+ Amount: string;
9
+ Destination: string;
10
+ Fee: string;
11
+ Sequence: number;
12
+ SigningPubKey?: string;
13
+ TxnSignature?: string;
14
+ };
@@ -1,5 +1,3 @@
1
- import { Account } from "@ledgerhq/types-live";
2
-
3
1
  export enum OnboardStatus {
4
2
  INIT,
5
3
  PREPARE,
@@ -24,7 +22,6 @@ export type CantonOnboardProgress = {
24
22
 
25
23
  export type CantonOnboardResult = {
26
24
  partyId: string;
27
- account: Partial<Account>;
28
25
  };
29
26
 
30
27
  export type CantonPreApprovalProgress = {
@@ -1,12 +1,11 @@
1
1
  export type CantonAddress = {
2
2
  publicKey: string;
3
3
  address: string;
4
- path: string; // TODO: check if necessary
5
4
  };
6
5
 
7
6
  export type CantonSignature = string; // `0x${string}`
8
7
 
9
8
  export interface CantonSigner {
10
- getAddress(path: string, display?: boolean): Promise<CantonAddress>;
9
+ getAddress(path: string): Promise<CantonAddress>;
11
10
  signTransaction(path: string, rawTx: string): Promise<CantonSignature>;
12
11
  }