@ledgerhq/coin-canton 0.5.0-nightly.1 → 0.5.0-nightly.2

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 (166) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.unimportedrc.json +12 -4
  3. package/CHANGELOG.md +21 -0
  4. package/lib/api/getBalance.integ.test.js +1 -1
  5. package/lib/api/getBalance.integ.test.js.map +1 -1
  6. package/lib/api/index.d.ts.map +1 -1
  7. package/lib/api/index.js +11 -8
  8. package/lib/api/index.js.map +1 -1
  9. package/lib/bridge/createTransaction.test.js +1 -1
  10. package/lib/bridge/createTransaction.test.js.map +1 -1
  11. package/lib/bridge/index.d.ts +3 -3
  12. package/lib/bridge/index.d.ts.map +1 -1
  13. package/lib/bridge/index.js +9 -1
  14. package/lib/bridge/index.js.map +1 -1
  15. package/lib/bridge/onboard.d.ts +10 -0
  16. package/lib/bridge/onboard.d.ts.map +1 -0
  17. package/lib/bridge/onboard.integ.test.d.ts +2 -0
  18. package/lib/bridge/onboard.integ.test.d.ts.map +1 -0
  19. package/lib/bridge/onboard.integ.test.js +156 -0
  20. package/lib/bridge/onboard.integ.test.js.map +1 -0
  21. package/lib/bridge/onboard.js +139 -0
  22. package/lib/bridge/onboard.js.map +1 -0
  23. package/lib/bridge/prepareTransaction.d.ts.map +1 -1
  24. package/lib/bridge/prepareTransaction.js +5 -7
  25. package/lib/bridge/prepareTransaction.js.map +1 -1
  26. package/lib/bridge/signOperation.d.ts.map +1 -1
  27. package/lib/bridge/signOperation.js +2 -1
  28. package/lib/bridge/signOperation.js.map +1 -1
  29. package/lib/bridge/sync.d.ts.map +1 -1
  30. package/lib/bridge/sync.integ.test.d.ts +2 -0
  31. package/lib/bridge/sync.integ.test.d.ts.map +1 -0
  32. package/lib/bridge/sync.integ.test.js +175 -0
  33. package/lib/bridge/sync.integ.test.js.map +1 -0
  34. package/lib/bridge/sync.js +39 -36
  35. package/lib/bridge/sync.js.map +1 -1
  36. package/lib/bridge/updateTransaction.d.ts.map +1 -1
  37. package/lib/bridge/updateTransaction.js +0 -4
  38. package/lib/bridge/updateTransaction.js.map +1 -1
  39. package/lib/common-logic/history/listOperations.d.ts.map +1 -1
  40. package/lib/common-logic/history/listOperations.js +19 -31
  41. package/lib/common-logic/history/listOperations.js.map +1 -1
  42. package/lib/common-logic/transaction/craftTransaction.d.ts +4 -3
  43. package/lib/common-logic/transaction/craftTransaction.d.ts.map +1 -1
  44. package/lib/common-logic/transaction/craftTransaction.js +10 -12
  45. package/lib/common-logic/transaction/craftTransaction.js.map +1 -1
  46. package/lib/network/gateway.d.ts +194 -3
  47. package/lib/network/gateway.d.ts.map +1 -1
  48. package/lib/network/gateway.integ.test.js +121 -11
  49. package/lib/network/gateway.integ.test.js.map +1 -1
  50. package/lib/network/gateway.js +96 -18
  51. package/lib/network/gateway.js.map +1 -1
  52. package/lib/network/node.d.ts +2 -2
  53. package/lib/network/node.d.ts.map +1 -1
  54. package/lib/network/node.js.map +1 -1
  55. package/lib/network/types.d.ts +1 -1
  56. package/lib/network/types.d.ts.map +1 -1
  57. package/lib/signer/getAddress.d.ts.map +1 -1
  58. package/lib/signer/getAddress.js +2 -2
  59. package/lib/signer/getAddress.js.map +1 -1
  60. package/lib/test/cantonTestUtils.d.ts +33 -0
  61. package/lib/test/cantonTestUtils.d.ts.map +1 -0
  62. package/lib/test/cantonTestUtils.js +159 -0
  63. package/lib/test/cantonTestUtils.js.map +1 -0
  64. package/lib/types/bridge.d.ts +7 -1
  65. package/lib/types/bridge.d.ts.map +1 -1
  66. package/lib/types/index.d.ts +1 -10
  67. package/lib/types/index.d.ts.map +1 -1
  68. package/lib/types/index.js +1 -0
  69. package/lib/types/index.js.map +1 -1
  70. package/lib/types/onboard.d.ts +55 -0
  71. package/lib/types/onboard.d.ts.map +1 -0
  72. package/lib/types/onboard.js +22 -0
  73. package/lib/types/onboard.js.map +1 -0
  74. package/lib-es/api/getBalance.integ.test.js +1 -1
  75. package/lib-es/api/getBalance.integ.test.js.map +1 -1
  76. package/lib-es/api/index.d.ts.map +1 -1
  77. package/lib-es/api/index.js +12 -9
  78. package/lib-es/api/index.js.map +1 -1
  79. package/lib-es/bridge/createTransaction.test.js +1 -1
  80. package/lib-es/bridge/createTransaction.test.js.map +1 -1
  81. package/lib-es/bridge/index.d.ts +3 -3
  82. package/lib-es/bridge/index.d.ts.map +1 -1
  83. package/lib-es/bridge/index.js +9 -1
  84. package/lib-es/bridge/index.js.map +1 -1
  85. package/lib-es/bridge/onboard.d.ts +10 -0
  86. package/lib-es/bridge/onboard.d.ts.map +1 -0
  87. package/lib-es/bridge/onboard.integ.test.d.ts +2 -0
  88. package/lib-es/bridge/onboard.integ.test.d.ts.map +1 -0
  89. package/lib-es/bridge/onboard.integ.test.js +151 -0
  90. package/lib-es/bridge/onboard.integ.test.js.map +1 -0
  91. package/lib-es/bridge/onboard.js +133 -0
  92. package/lib-es/bridge/onboard.js.map +1 -0
  93. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
  94. package/lib-es/bridge/prepareTransaction.js +6 -8
  95. package/lib-es/bridge/prepareTransaction.js.map +1 -1
  96. package/lib-es/bridge/signOperation.d.ts.map +1 -1
  97. package/lib-es/bridge/signOperation.js +2 -1
  98. package/lib-es/bridge/signOperation.js.map +1 -1
  99. package/lib-es/bridge/sync.d.ts.map +1 -1
  100. package/lib-es/bridge/sync.integ.test.d.ts +2 -0
  101. package/lib-es/bridge/sync.integ.test.d.ts.map +1 -0
  102. package/lib-es/bridge/sync.integ.test.js +137 -0
  103. package/lib-es/bridge/sync.integ.test.js.map +1 -0
  104. package/lib-es/bridge/sync.js +38 -35
  105. package/lib-es/bridge/sync.js.map +1 -1
  106. package/lib-es/bridge/updateTransaction.d.ts.map +1 -1
  107. package/lib-es/bridge/updateTransaction.js +0 -4
  108. package/lib-es/bridge/updateTransaction.js.map +1 -1
  109. package/lib-es/common-logic/history/listOperations.d.ts.map +1 -1
  110. package/lib-es/common-logic/history/listOperations.js +20 -29
  111. package/lib-es/common-logic/history/listOperations.js.map +1 -1
  112. package/lib-es/common-logic/transaction/craftTransaction.d.ts +4 -3
  113. package/lib-es/common-logic/transaction/craftTransaction.d.ts.map +1 -1
  114. package/lib-es/common-logic/transaction/craftTransaction.js +10 -12
  115. package/lib-es/common-logic/transaction/craftTransaction.js.map +1 -1
  116. package/lib-es/network/gateway.d.ts +194 -3
  117. package/lib-es/network/gateway.d.ts.map +1 -1
  118. package/lib-es/network/gateway.integ.test.js +122 -12
  119. package/lib-es/network/gateway.integ.test.js.map +1 -1
  120. package/lib-es/network/gateway.js +90 -17
  121. package/lib-es/network/gateway.js.map +1 -1
  122. package/lib-es/network/node.d.ts +2 -2
  123. package/lib-es/network/node.d.ts.map +1 -1
  124. package/lib-es/network/node.js.map +1 -1
  125. package/lib-es/network/types.d.ts +1 -1
  126. package/lib-es/network/types.d.ts.map +1 -1
  127. package/lib-es/signer/getAddress.d.ts.map +1 -1
  128. package/lib-es/signer/getAddress.js +2 -2
  129. package/lib-es/signer/getAddress.js.map +1 -1
  130. package/lib-es/test/cantonTestUtils.d.ts +33 -0
  131. package/lib-es/test/cantonTestUtils.d.ts.map +1 -0
  132. package/lib-es/test/cantonTestUtils.js +151 -0
  133. package/lib-es/test/cantonTestUtils.js.map +1 -0
  134. package/lib-es/types/bridge.d.ts +7 -1
  135. package/lib-es/types/bridge.d.ts.map +1 -1
  136. package/lib-es/types/index.d.ts +1 -10
  137. package/lib-es/types/index.d.ts.map +1 -1
  138. package/lib-es/types/index.js +1 -0
  139. package/lib-es/types/index.js.map +1 -1
  140. package/lib-es/types/onboard.d.ts +55 -0
  141. package/lib-es/types/onboard.d.ts.map +1 -0
  142. package/lib-es/types/onboard.js +19 -0
  143. package/lib-es/types/onboard.js.map +1 -0
  144. package/package.json +6 -6
  145. package/src/api/getBalance.integ.test.ts +1 -2
  146. package/src/api/index.ts +33 -26
  147. package/src/bridge/createTransaction.test.ts +1 -1
  148. package/src/bridge/index.ts +14 -4
  149. package/src/bridge/onboard.integ.test.ts +219 -0
  150. package/src/bridge/onboard.ts +220 -0
  151. package/src/bridge/prepareTransaction.ts +6 -15
  152. package/src/bridge/signOperation.ts +3 -2
  153. package/src/bridge/sync.integ.test.ts +180 -0
  154. package/src/bridge/sync.ts +57 -49
  155. package/src/bridge/updateTransaction.ts +0 -5
  156. package/src/common-logic/history/listOperations.ts +20 -31
  157. package/src/common-logic/transaction/craftTransaction.ts +13 -17
  158. package/src/network/gateway.integ.test.ts +156 -17
  159. package/src/network/gateway.ts +333 -26
  160. package/src/network/node.ts +3 -3
  161. package/src/network/types.ts +1 -1
  162. package/src/signer/getAddress.ts +3 -5
  163. package/src/test/cantonTestUtils.ts +181 -0
  164. package/src/types/bridge.ts +20 -0
  165. package/src/types/index.ts +1 -11
  166. package/src/types/onboard.ts +65 -0
@@ -1,12 +1,7 @@
1
1
  import type { Operation, Pagination } from "@ledgerhq/coin-framework/api/index";
2
- import { CreatedEvent, getTransactions, TxInfo } from "../../network/gateway";
2
+ import { getOperations } from "../../network/gateway";
3
3
  import coinConfig from "../../config";
4
4
 
5
- const getNativeContractId = () =>
6
- coinConfig.getCoinConfig().nativeInstrumentId !== undefined
7
- ? coinConfig.getCoinConfig().nativeInstrumentId?.split(".")[0]
8
- : "";
9
-
10
5
  /**
11
6
  * Returns list of operations associated to an account.
12
7
  * @param partyId Account partyId
@@ -18,37 +13,31 @@ export async function listOperations(
18
13
  partyId: string,
19
14
  page: Pagination,
20
15
  ): Promise<[Operation[], string]> {
21
- const { transactions, next } = await getTransactions(partyId, {
16
+ const { operations, next } = await getOperations(partyId, {
22
17
  cursor: page.pagingToken !== undefined ? parseInt(page.pagingToken) : undefined,
23
18
  minOffset: page.minHeight,
24
19
  limit: page.limit,
25
20
  });
26
21
  const ops: Operation[] = [];
27
- for (const tx of transactions) {
28
- for (let i = 0; i < tx.events.length; i++) {
29
- const event: CreatedEvent = tx.events[i]["CantonCreatedEvent"] as CreatedEvent;
30
- if (event && event.template_id.module_name === "Splice.Amulet") {
31
- ops.push({
32
- id: tx.update_id + "-" + i,
33
- type: event.signatories.includes(partyId) ? "OUT" : "IN",
34
- value: BigInt(0), // to be finalized when details are available on backend
35
- senders: event.signatories.includes(partyId) ? [partyId] : [],
36
- recipients: event.signatories.includes(partyId) ? [] : [partyId],
37
- asset:
38
- event.contract_id === getNativeContractId()
39
- ? { type: "native" }
40
- : { type: "token", assetReference: event.contract_id },
41
- tx: {
42
- hash: tx.update_id,
43
- fees: BigInt(0), // to be finalized when details are available on backend
44
- date: new Date(tx.record_time.seconds),
45
- block: {
46
- height: tx.offset,
47
- time: new Date(tx.effective_at.seconds),
48
- },
22
+ for (const tx of operations) {
23
+ if (tx.type === "Send") {
24
+ ops.push({
25
+ id: tx.uid,
26
+ type: tx.senders.includes(partyId) ? "OUT" : "IN",
27
+ value: BigInt(tx.transfers[0].value),
28
+ senders: tx.senders,
29
+ recipients: tx.recipients,
30
+ asset: tx.asset,
31
+ tx: {
32
+ hash: tx.block.hash,
33
+ fees: BigInt(tx.fee.value),
34
+ date: new Date(tx.transaction_timestamp),
35
+ block: {
36
+ height: tx.block.height,
37
+ time: new Date(tx.block.time),
49
38
  },
50
- });
51
- }
39
+ },
40
+ });
52
41
  }
53
42
  }
54
43
  return [ops, next + ""];
@@ -1,7 +1,5 @@
1
1
  import BigNumber from "bignumber.js";
2
- import { BoilerplateNativeTransaction } from "../../types";
3
-
4
- const encodeNativeTx = (nativeTx: BoilerplateNativeTransaction) => JSON.stringify(nativeTx);
2
+ import { prepareTransferRequest, PrepareTransferResponse } from "../../network/gateway";
5
3
 
6
4
  export async function craftTransaction(
7
5
  account: {
@@ -12,25 +10,23 @@ export async function craftTransaction(
12
10
  transaction: {
13
11
  recipient?: string;
14
12
  amount: BigNumber;
15
- fee?: BigNumber;
13
+ tokenId: string;
14
+ expireInSeconds: number;
16
15
  },
17
16
  ): Promise<{
18
- nativeTransaction: BoilerplateNativeTransaction;
17
+ nativeTransaction: PrepareTransferResponse;
19
18
  serializedTransaction: string;
20
19
  }> {
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);
20
+ const { serialized, json } = await prepareTransferRequest(account.address, {
21
+ recipient: transaction.recipient || "",
22
+ amount: transaction.amount.toNumber(),
23
+ type: "token-transfer-request",
24
+ execute_before_secs: transaction.expireInSeconds,
25
+ instrument_id: transaction.tokenId,
26
+ });
31
27
 
32
28
  return {
33
- nativeTransaction,
34
- serializedTransaction,
29
+ nativeTransaction: json,
30
+ serializedTransaction: serialized,
35
31
  };
36
32
  }
@@ -1,15 +1,26 @@
1
1
  import coinConfig from "../config";
2
+ import { generateMockKeyPair } from "../test/cantonTestUtils";
2
3
  import {
3
4
  getLedgerEnd,
4
5
  prepareOnboarding,
5
6
  getBalance,
6
- getTransactions,
7
+ getOperations,
7
8
  getPartyById,
8
9
  getPartyByPubKey,
10
+ submitOnboarding,
11
+ prepareTapRequest,
12
+ submitTapRequest,
13
+ preparePreApprovalTransaction,
14
+ submitPreApprovalTransaction,
9
15
  } from "./gateway";
10
16
 
11
17
  describe("gateway (devnet)", () => {
12
- beforeAll(() => {
18
+ let onboardedAccount: {
19
+ keyPair: ReturnType<typeof generateMockKeyPair>;
20
+ partyId: string;
21
+ } | null = null;
22
+
23
+ beforeAll(async () => {
13
24
  coinConfig.setCoinConfig(() => ({
14
25
  gatewayUrl: "https://canton-gateway.api.live.ledger-test.com",
15
26
  useGateway: true,
@@ -18,18 +29,63 @@ describe("gateway (devnet)", () => {
18
29
  type: "active",
19
30
  },
20
31
  }));
21
- });
32
+ }, 60000);
33
+
34
+ const getOnboardedAccount = () => {
35
+ if (!onboardedAccount) {
36
+ throw new Error("Shared onboarded account not available. Check beforeAll setup.");
37
+ }
38
+ return onboardedAccount;
39
+ };
22
40
 
23
41
  describe("prepareOnboarding", () => {
24
42
  it("should prepare onboarding", async () => {
25
- const response = await prepareOnboarding(
26
- "c59f7f29374d24506dd6490a5db472cf00958e195e146f3dc9c97f96d5c51097",
27
- "ed25519",
28
- );
43
+ // GIVEN
44
+ const keyPair = generateMockKeyPair();
45
+
46
+ // Save onboarded account for all tests that need a valid party ID
47
+ onboardedAccount = {
48
+ keyPair,
49
+ partyId: "", // set in next test
50
+ };
51
+
52
+ // WHEN
53
+ const response = await prepareOnboarding(keyPair.publicKeyHex, "ed25519");
54
+
55
+ // THEN
29
56
  expect(response).toHaveProperty("party_id");
30
57
  expect(response).toHaveProperty("party_name");
31
58
  expect(response).toHaveProperty("public_key_fingerprint");
32
- expect(response).toHaveProperty("topology_transactions_hash");
59
+ expect(response).toHaveProperty("transactions");
60
+ expect(response.transactions).toHaveProperty("combined_hash");
61
+ expect(response.party_name).toBe(keyPair.publicKeyHex);
62
+
63
+ expect(response.public_key_fingerprint).toBe(keyPair.fingerprint);
64
+ }, 30000);
65
+ });
66
+
67
+ describe("submitOnboarding", () => {
68
+ it("should submit onboarding with proper signature", async () => {
69
+ // GIVEN
70
+ const { keyPair } = getOnboardedAccount();
71
+ const prepareRequest = { public_key: keyPair.publicKeyHex, public_key_type: "ed25519" };
72
+ const prepareResponse = await prepareOnboarding(keyPair.publicKeyHex, "ed25519");
73
+ const signature = keyPair.sign(prepareResponse.transactions.combined_hash);
74
+
75
+ // WHEN
76
+ const response = await submitOnboarding(prepareRequest, prepareResponse, signature);
77
+
78
+ // Save onboarded account for all tests that need a valid party ID
79
+ onboardedAccount = {
80
+ keyPair,
81
+ partyId: response.party.party_id,
82
+ };
83
+
84
+ // THEN
85
+ expect(response).toHaveProperty("party");
86
+ expect(response.party).toHaveProperty("party_id");
87
+ expect(response.party).toHaveProperty("public_key");
88
+ expect(response.party.public_key).toBe(keyPair.publicKeyHex);
33
89
  }, 30000);
34
90
  });
35
91
 
@@ -42,12 +98,13 @@ describe("gateway (devnet)", () => {
42
98
 
43
99
  describe("getBalance", () => {
44
100
  it("should return user balance", async () => {
45
- const balance = await getBalance(
46
- "party-4f2e1485107adf5f::122027c6dbbbdbffe0fa3122ae05175f3b9328e879e9ce96b670354deb64a45683c1",
47
- );
48
- expect(balance.length).toBeGreaterThanOrEqual(1);
49
- expect(balance[0].amount).toBeGreaterThanOrEqual(0);
50
- expect(balance[0].instrument_id.includes("Splice")).toBe(true);
101
+ const { partyId } = getOnboardedAccount();
102
+ const balance = await getBalance(partyId);
103
+ expect(balance.length).toBeGreaterThanOrEqual(0);
104
+ if (balance.length > 0) {
105
+ expect(balance[0].amount).toBeGreaterThanOrEqual(0);
106
+ expect(balance[0]).toHaveProperty("instrument_id");
107
+ }
51
108
  });
52
109
  });
53
110
 
@@ -67,12 +124,94 @@ describe("gateway (devnet)", () => {
67
124
  });
68
125
  });
69
126
 
70
- describe("getTransactions", () => {
127
+ describe("getOperations", () => {
71
128
  it("should return user transactions", async () => {
72
- const { transactions } = await getTransactions(
129
+ const { operations } = await getOperations(
73
130
  "party-5f29bb32e9939939::12202becd8062a1d170209956cfd977fca76fcb4d2a892d08c77a7483f35a11d6440",
74
131
  );
75
- expect(transactions.length).toBeGreaterThanOrEqual(0);
132
+ expect(operations.length).toBeGreaterThanOrEqual(0);
76
133
  });
77
134
  });
135
+
136
+ describe("prepareTapRequest", () => {
137
+ it("should prepare tap request for onboarded party", async () => {
138
+ // GIVEN
139
+ const { partyId } = getOnboardedAccount();
140
+ const amount = 1000;
141
+
142
+ // WHEN
143
+ const response = await prepareTapRequest({ partyId, amount });
144
+
145
+ // THEN
146
+ expect(response).toHaveProperty("serialized");
147
+ expect(response).toHaveProperty("hash");
148
+ expect(typeof response.serialized).toBe("string");
149
+ expect(typeof response.hash).toBe("string");
150
+ }, 30000);
151
+ });
152
+
153
+ describe("submitTapRequest", () => {
154
+ it("should submit tap request with proper signature", async () => {
155
+ // GIVEN
156
+ const { keyPair, partyId } = getOnboardedAccount();
157
+ const tapPrepareResponse = await prepareTapRequest({
158
+ partyId,
159
+ amount: 1000,
160
+ });
161
+ const tapSignature = keyPair.sign(tapPrepareResponse.hash);
162
+
163
+ // WHEN
164
+ const response = await submitTapRequest({
165
+ partyId,
166
+ serialized: tapPrepareResponse.serialized,
167
+ signature: tapSignature,
168
+ });
169
+
170
+ // THEN
171
+ expect(response).toHaveProperty("submission_id");
172
+ expect(response).toHaveProperty("update_id");
173
+ expect(typeof response.submission_id).toBe("string");
174
+ expect(typeof response.update_id).toBe("string");
175
+ }, 30000);
176
+ });
177
+
178
+ describe("preparePreApprovalTransaction", () => {
179
+ it("should prepare pre-approval transaction for onboarded party", async () => {
180
+ // GIVEN
181
+ const { partyId } = getOnboardedAccount();
182
+
183
+ // WHEN
184
+ const response = await preparePreApprovalTransaction(partyId);
185
+
186
+ // THEN
187
+ expect(response).toHaveProperty("serialized");
188
+ expect(response).toHaveProperty("hash");
189
+ expect(typeof response.serialized).toBe("string");
190
+ expect(typeof response.hash).toBe("string");
191
+ }, 30000);
192
+ });
193
+
194
+ describe("submitPreApprovalTransaction", () => {
195
+ it("should submit pre-approval transaction with proper signature", async () => {
196
+ // GIVEN
197
+ const { keyPair, partyId } = getOnboardedAccount();
198
+ const preparedTransaction = await preparePreApprovalTransaction(partyId);
199
+ const preApprovalSignature = keyPair.sign(preparedTransaction.hash);
200
+
201
+ // WHEN
202
+ const response = await submitPreApprovalTransaction(
203
+ partyId,
204
+ preparedTransaction,
205
+ preApprovalSignature,
206
+ );
207
+
208
+ // THEN
209
+ expect(response).toHaveProperty("isApproved");
210
+ expect(response).toHaveProperty("submissionId");
211
+ expect(response).toHaveProperty("updateId");
212
+ expect(response.isApproved).toBe(true);
213
+ expect(typeof response.submissionId).toBe("string");
214
+ expect(typeof response.updateId).toBe("string");
215
+ }, 30000);
216
+ });
78
217
  });