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

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 (199) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.unimportedrc.json +12 -4
  3. package/CHANGELOG.md +32 -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/broadcast.d.ts.map +1 -1
  10. package/lib/bridge/broadcast.js +2 -1
  11. package/lib/bridge/broadcast.js.map +1 -1
  12. package/lib/bridge/createTransaction.test.js +1 -1
  13. package/lib/bridge/createTransaction.test.js.map +1 -1
  14. package/lib/bridge/index.d.ts +3 -3
  15. package/lib/bridge/index.d.ts.map +1 -1
  16. package/lib/bridge/index.js +9 -1
  17. package/lib/bridge/index.js.map +1 -1
  18. package/lib/bridge/onboard.d.ts +10 -0
  19. package/lib/bridge/onboard.d.ts.map +1 -0
  20. package/lib/bridge/onboard.integ.test.d.ts +2 -0
  21. package/lib/bridge/onboard.integ.test.d.ts.map +1 -0
  22. package/lib/bridge/onboard.integ.test.js +156 -0
  23. package/lib/bridge/onboard.integ.test.js.map +1 -0
  24. package/lib/bridge/onboard.js +139 -0
  25. package/lib/bridge/onboard.js.map +1 -0
  26. package/lib/bridge/prepareTransaction.d.ts.map +1 -1
  27. package/lib/bridge/prepareTransaction.js +5 -7
  28. package/lib/bridge/prepareTransaction.js.map +1 -1
  29. package/lib/bridge/signOperation.d.ts.map +1 -1
  30. package/lib/bridge/signOperation.js +7 -9
  31. package/lib/bridge/signOperation.js.map +1 -1
  32. package/lib/bridge/sync.d.ts.map +1 -1
  33. package/lib/bridge/sync.integ.test.d.ts +2 -0
  34. package/lib/bridge/sync.integ.test.d.ts.map +1 -0
  35. package/lib/bridge/sync.integ.test.js +175 -0
  36. package/lib/bridge/sync.integ.test.js.map +1 -0
  37. package/lib/bridge/sync.js +40 -36
  38. package/lib/bridge/sync.js.map +1 -1
  39. package/lib/bridge/updateTransaction.d.ts.map +1 -1
  40. package/lib/bridge/updateTransaction.js +0 -4
  41. package/lib/bridge/updateTransaction.js.map +1 -1
  42. package/lib/common-logic/history/listOperations.d.ts.map +1 -1
  43. package/lib/common-logic/history/listOperations.js +19 -31
  44. package/lib/common-logic/history/listOperations.js.map +1 -1
  45. package/lib/common-logic/transaction/broadcast.d.ts.map +1 -1
  46. package/lib/common-logic/transaction/broadcast.js +2 -1
  47. package/lib/common-logic/transaction/broadcast.js.map +1 -1
  48. package/lib/common-logic/transaction/broadcast.test.js +3 -3
  49. package/lib/common-logic/transaction/broadcast.test.js.map +1 -1
  50. package/lib/common-logic/transaction/combine.d.ts +1 -1
  51. package/lib/common-logic/transaction/combine.d.ts.map +1 -1
  52. package/lib/common-logic/transaction/combine.js +2 -3
  53. package/lib/common-logic/transaction/combine.js.map +1 -1
  54. package/lib/common-logic/transaction/combine.test.js +3 -13
  55. package/lib/common-logic/transaction/combine.test.js.map +1 -1
  56. package/lib/common-logic/transaction/craftTransaction.d.ts +5 -3
  57. package/lib/common-logic/transaction/craftTransaction.d.ts.map +1 -1
  58. package/lib/common-logic/transaction/craftTransaction.js +11 -12
  59. package/lib/common-logic/transaction/craftTransaction.js.map +1 -1
  60. package/lib/network/gateway.d.ts +196 -5
  61. package/lib/network/gateway.d.ts.map +1 -1
  62. package/lib/network/gateway.integ.test.js +121 -11
  63. package/lib/network/gateway.integ.test.js.map +1 -1
  64. package/lib/network/gateway.js +99 -21
  65. package/lib/network/gateway.js.map +1 -1
  66. package/lib/network/node.d.ts +2 -2
  67. package/lib/network/node.d.ts.map +1 -1
  68. package/lib/network/node.js.map +1 -1
  69. package/lib/network/types.d.ts +1 -1
  70. package/lib/network/types.d.ts.map +1 -1
  71. package/lib/signer/getAddress.d.ts.map +1 -1
  72. package/lib/signer/getAddress.js +2 -2
  73. package/lib/signer/getAddress.js.map +1 -1
  74. package/lib/test/cantonTestUtils.d.ts +33 -0
  75. package/lib/test/cantonTestUtils.d.ts.map +1 -0
  76. package/lib/test/cantonTestUtils.js +159 -0
  77. package/lib/test/cantonTestUtils.js.map +1 -0
  78. package/lib/types/bridge.d.ts +7 -1
  79. package/lib/types/bridge.d.ts.map +1 -1
  80. package/lib/types/index.d.ts +1 -10
  81. package/lib/types/index.d.ts.map +1 -1
  82. package/lib/types/index.js +1 -0
  83. package/lib/types/index.js.map +1 -1
  84. package/lib/types/onboard.d.ts +55 -0
  85. package/lib/types/onboard.d.ts.map +1 -0
  86. package/lib/types/onboard.js +22 -0
  87. package/lib/types/onboard.js.map +1 -0
  88. package/lib-es/api/getBalance.integ.test.js +1 -1
  89. package/lib-es/api/getBalance.integ.test.js.map +1 -1
  90. package/lib-es/api/index.d.ts.map +1 -1
  91. package/lib-es/api/index.js +12 -9
  92. package/lib-es/api/index.js.map +1 -1
  93. package/lib-es/bridge/broadcast.d.ts.map +1 -1
  94. package/lib-es/bridge/broadcast.js +2 -1
  95. package/lib-es/bridge/broadcast.js.map +1 -1
  96. package/lib-es/bridge/createTransaction.test.js +1 -1
  97. package/lib-es/bridge/createTransaction.test.js.map +1 -1
  98. package/lib-es/bridge/index.d.ts +3 -3
  99. package/lib-es/bridge/index.d.ts.map +1 -1
  100. package/lib-es/bridge/index.js +9 -1
  101. package/lib-es/bridge/index.js.map +1 -1
  102. package/lib-es/bridge/onboard.d.ts +10 -0
  103. package/lib-es/bridge/onboard.d.ts.map +1 -0
  104. package/lib-es/bridge/onboard.integ.test.d.ts +2 -0
  105. package/lib-es/bridge/onboard.integ.test.d.ts.map +1 -0
  106. package/lib-es/bridge/onboard.integ.test.js +151 -0
  107. package/lib-es/bridge/onboard.integ.test.js.map +1 -0
  108. package/lib-es/bridge/onboard.js +133 -0
  109. package/lib-es/bridge/onboard.js.map +1 -0
  110. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
  111. package/lib-es/bridge/prepareTransaction.js +6 -8
  112. package/lib-es/bridge/prepareTransaction.js.map +1 -1
  113. package/lib-es/bridge/signOperation.d.ts.map +1 -1
  114. package/lib-es/bridge/signOperation.js +8 -10
  115. package/lib-es/bridge/signOperation.js.map +1 -1
  116. package/lib-es/bridge/sync.d.ts.map +1 -1
  117. package/lib-es/bridge/sync.integ.test.d.ts +2 -0
  118. package/lib-es/bridge/sync.integ.test.d.ts.map +1 -0
  119. package/lib-es/bridge/sync.integ.test.js +137 -0
  120. package/lib-es/bridge/sync.integ.test.js.map +1 -0
  121. package/lib-es/bridge/sync.js +39 -35
  122. package/lib-es/bridge/sync.js.map +1 -1
  123. package/lib-es/bridge/updateTransaction.d.ts.map +1 -1
  124. package/lib-es/bridge/updateTransaction.js +0 -4
  125. package/lib-es/bridge/updateTransaction.js.map +1 -1
  126. package/lib-es/common-logic/history/listOperations.d.ts.map +1 -1
  127. package/lib-es/common-logic/history/listOperations.js +20 -29
  128. package/lib-es/common-logic/history/listOperations.js.map +1 -1
  129. package/lib-es/common-logic/transaction/broadcast.d.ts.map +1 -1
  130. package/lib-es/common-logic/transaction/broadcast.js +2 -1
  131. package/lib-es/common-logic/transaction/broadcast.js.map +1 -1
  132. package/lib-es/common-logic/transaction/broadcast.test.js +3 -3
  133. package/lib-es/common-logic/transaction/broadcast.test.js.map +1 -1
  134. package/lib-es/common-logic/transaction/combine.d.ts +1 -1
  135. package/lib-es/common-logic/transaction/combine.d.ts.map +1 -1
  136. package/lib-es/common-logic/transaction/combine.js +2 -3
  137. package/lib-es/common-logic/transaction/combine.js.map +1 -1
  138. package/lib-es/common-logic/transaction/combine.test.js +3 -13
  139. package/lib-es/common-logic/transaction/combine.test.js.map +1 -1
  140. package/lib-es/common-logic/transaction/craftTransaction.d.ts +5 -3
  141. package/lib-es/common-logic/transaction/craftTransaction.d.ts.map +1 -1
  142. package/lib-es/common-logic/transaction/craftTransaction.js +11 -12
  143. package/lib-es/common-logic/transaction/craftTransaction.js.map +1 -1
  144. package/lib-es/network/gateway.d.ts +196 -5
  145. package/lib-es/network/gateway.d.ts.map +1 -1
  146. package/lib-es/network/gateway.integ.test.js +122 -12
  147. package/lib-es/network/gateway.integ.test.js.map +1 -1
  148. package/lib-es/network/gateway.js +93 -20
  149. package/lib-es/network/gateway.js.map +1 -1
  150. package/lib-es/network/node.d.ts +2 -2
  151. package/lib-es/network/node.d.ts.map +1 -1
  152. package/lib-es/network/node.js.map +1 -1
  153. package/lib-es/network/types.d.ts +1 -1
  154. package/lib-es/network/types.d.ts.map +1 -1
  155. package/lib-es/signer/getAddress.d.ts.map +1 -1
  156. package/lib-es/signer/getAddress.js +2 -2
  157. package/lib-es/signer/getAddress.js.map +1 -1
  158. package/lib-es/test/cantonTestUtils.d.ts +33 -0
  159. package/lib-es/test/cantonTestUtils.d.ts.map +1 -0
  160. package/lib-es/test/cantonTestUtils.js +151 -0
  161. package/lib-es/test/cantonTestUtils.js.map +1 -0
  162. package/lib-es/types/bridge.d.ts +7 -1
  163. package/lib-es/types/bridge.d.ts.map +1 -1
  164. package/lib-es/types/index.d.ts +1 -10
  165. package/lib-es/types/index.d.ts.map +1 -1
  166. package/lib-es/types/index.js +1 -0
  167. package/lib-es/types/index.js.map +1 -1
  168. package/lib-es/types/onboard.d.ts +55 -0
  169. package/lib-es/types/onboard.d.ts.map +1 -0
  170. package/lib-es/types/onboard.js +19 -0
  171. package/lib-es/types/onboard.js.map +1 -0
  172. package/package.json +7 -7
  173. package/src/api/getBalance.integ.test.ts +1 -2
  174. package/src/api/index.ts +33 -26
  175. package/src/bridge/broadcast.ts +2 -3
  176. package/src/bridge/createTransaction.test.ts +1 -1
  177. package/src/bridge/index.ts +14 -4
  178. package/src/bridge/onboard.integ.test.ts +219 -0
  179. package/src/bridge/onboard.ts +220 -0
  180. package/src/bridge/prepareTransaction.ts +6 -15
  181. package/src/bridge/signOperation.ts +9 -16
  182. package/src/bridge/sync.integ.test.ts +180 -0
  183. package/src/bridge/sync.ts +61 -49
  184. package/src/bridge/updateTransaction.ts +0 -5
  185. package/src/common-logic/history/listOperations.ts +20 -31
  186. package/src/common-logic/transaction/broadcast.test.ts +3 -3
  187. package/src/common-logic/transaction/broadcast.ts +2 -1
  188. package/src/common-logic/transaction/combine.test.ts +3 -13
  189. package/src/common-logic/transaction/combine.ts +2 -4
  190. package/src/common-logic/transaction/craftTransaction.ts +15 -17
  191. package/src/network/gateway.integ.test.ts +156 -17
  192. package/src/network/gateway.ts +337 -30
  193. package/src/network/node.ts +3 -3
  194. package/src/network/types.ts +1 -1
  195. package/src/signer/getAddress.ts +3 -5
  196. package/src/test/cantonTestUtils.ts +181 -0
  197. package/src/types/bridge.ts +20 -0
  198. package/src/types/index.ts +1 -11
  199. package/src/types/onboard.ts +65 -0
@@ -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
  });
@@ -1,11 +1,37 @@
1
1
  import network from "@ledgerhq/live-network";
2
+ import type { LiveNetworkRequest } from "@ledgerhq/live-network/network";
3
+ import { getEnv } from "@ledgerhq/live-env";
2
4
  import coinConfig from "../config";
5
+ import {
6
+ PrepareTransactionRequest,
7
+ PrepareTransactionResponse,
8
+ SubmitTransactionRequest,
9
+ SubmitTransactionResponse,
10
+ PreApprovalResult,
11
+ } from "../types/onboard";
3
12
 
4
13
  type OnboardingPrepareResponse = {
5
14
  party_id: string;
6
15
  party_name: string;
7
16
  public_key_fingerprint: string;
8
- topology_transactions_hash: string;
17
+ transactions: {
18
+ namespace_transaction: {
19
+ serialized: string;
20
+ json: object;
21
+ hash: string;
22
+ };
23
+ party_to_key_transaction: {
24
+ serialized: string;
25
+ json: object;
26
+ hash: string;
27
+ };
28
+ party_to_participant_transaction: {
29
+ serialized: string;
30
+ json: object;
31
+ hash: string;
32
+ };
33
+ combined_hash: string;
34
+ };
9
35
  };
10
36
 
11
37
  type OnboardingPrepareRequest = {
@@ -13,6 +39,31 @@ type OnboardingPrepareRequest = {
13
39
  public_key_type: string;
14
40
  };
15
41
 
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
+ export type PrepareTapRequest = {
58
+ type: "tap-request";
59
+ amount: number;
60
+ };
61
+
62
+ export type PreparePreapprovalRequest = {
63
+ type: "transfer-pre-approval-proposal";
64
+ receiver: string;
65
+ };
66
+
16
67
  type OnboardingSubmitRequest = {
17
68
  prepare_request: OnboardingPrepareRequest;
18
69
  prepare_response: OnboardingPrepareResponse;
@@ -31,7 +82,7 @@ type TransactionSubmitRequest = {
31
82
  signature: string;
32
83
  };
33
84
 
34
- type TransactionSubmitResponse = { updateId: string };
85
+ type TransactionSubmitResponse = { update_id: string };
35
86
 
36
87
  export type InstrumentBalance = {
37
88
  instrument_id: string;
@@ -63,6 +114,9 @@ export type CreatedEvent = BaseEvent & {
63
114
  };
64
115
  signatories: string[];
65
116
  observers: string[];
117
+ details: {
118
+ createArguments: { fields: unknown[] };
119
+ };
66
120
  };
67
121
 
68
122
  type ExercisedEvent = BaseEvent & {
@@ -90,21 +144,165 @@ export type TxInfo = {
90
144
  trace_context: string;
91
145
  };
92
146
 
147
+ export type OperationInfo =
148
+ | {
149
+ uid: string;
150
+ transaction_hash: string;
151
+ transaction_timestamp: string;
152
+ status: "Success";
153
+ type: "Initialize";
154
+ senders: string[];
155
+ recipients: string[];
156
+ transfers: [
157
+ {
158
+ address: string;
159
+ type: "Initialize";
160
+ value: string;
161
+ asset: string;
162
+ details: {
163
+ type: "pre-approval";
164
+ };
165
+ },
166
+ ];
167
+ block: {
168
+ height: number;
169
+ time: string;
170
+ hash: string;
171
+ };
172
+ fee: {
173
+ value: string;
174
+ asset: {
175
+ type: "native";
176
+ issuer: null;
177
+ };
178
+ details: {
179
+ type: string;
180
+ };
181
+ };
182
+ asset: {
183
+ type: "token";
184
+ issuer: string;
185
+ };
186
+ details: {
187
+ type: "pre-approval";
188
+ };
189
+ }
190
+ | {
191
+ uid: string;
192
+ transaction_hash: string;
193
+ transaction_timestamp: string;
194
+ status: "Success";
195
+ type: "Receive";
196
+ senders: string[];
197
+ recipients: string[];
198
+ transfers: [
199
+ {
200
+ address: string;
201
+ type: "Receive";
202
+ value: string;
203
+ asset: string;
204
+ details: {
205
+ type: "tap";
206
+ };
207
+ },
208
+ ];
209
+ block: {
210
+ height: number;
211
+ time: string;
212
+ hash: string;
213
+ };
214
+ fee: {
215
+ value: string;
216
+ asset: {
217
+ type: "native";
218
+ issuer: null;
219
+ };
220
+ details: {
221
+ type: string;
222
+ };
223
+ };
224
+ asset: {
225
+ type: "native";
226
+ issuer: null;
227
+ };
228
+ details: {
229
+ type: "tap";
230
+ };
231
+ }
232
+ | {
233
+ uid: string;
234
+ transaction_hash: string;
235
+ transaction_timestamp: string;
236
+ status: "Success";
237
+ type: "Send";
238
+ senders: string[];
239
+ recipients: string[];
240
+ transfers: [
241
+ {
242
+ address: string;
243
+ type: "Send";
244
+ value: string;
245
+ asset: string;
246
+ details: {
247
+ type: "transfer";
248
+ };
249
+ },
250
+ ];
251
+ block: {
252
+ height: number;
253
+ time: string;
254
+ hash: string;
255
+ };
256
+ fee: {
257
+ value: string;
258
+ asset: {
259
+ type: "native";
260
+ issuer: null;
261
+ };
262
+ details: {
263
+ type: string;
264
+ };
265
+ };
266
+ asset: {
267
+ type: "native";
268
+ issuer: null;
269
+ };
270
+ details: {
271
+ type: "transfer";
272
+ };
273
+ };
274
+
93
275
  const getGatewayUrl = () => coinConfig.getCoinConfig().gatewayUrl;
94
- const getNodeId = () => coinConfig.getCoinConfig().nodeId || "ledger-live-devnet-prd";
276
+ const getNodeId = () => coinConfig.getCoinConfig().nodeId || "ledger-devnet-stg";
277
+
278
+ const gatewayNetwork = <T, U = unknown>(req: LiveNetworkRequest<U>) => {
279
+ const API_KEY = getEnv("CANTON_API_KEY");
280
+ return network<T, U>({
281
+ ...req,
282
+ headers: {
283
+ ...(req.headers || {}),
284
+ ...(API_KEY && { "X-Ledger-Canton-Api-Key": API_KEY }),
285
+ },
286
+ });
287
+ };
95
288
 
96
289
  export async function prepareOnboarding(
97
290
  pubKey: string,
98
291
  pubKeyType: string,
99
292
  ): Promise<OnboardingPrepareResponse> {
100
- const { data } = await network<OnboardingPrepareResponse>({
293
+ const gatewayUrl = getGatewayUrl();
294
+ const nodeId = getNodeId();
295
+ const fullUrl = `${gatewayUrl}/v1/node/${nodeId}/onboarding/prepare`;
296
+
297
+ const { data } = await gatewayNetwork<OnboardingPrepareResponse, OnboardingPrepareRequest>({
101
298
  method: "POST",
102
- url: `${getGatewayUrl()}/v1/node/${getNodeId()}/onboarding/prepare`,
299
+ url: fullUrl,
103
300
  data: {
104
301
  public_key: pubKey,
105
302
  public_key_type: pubKeyType,
106
- } satisfies OnboardingPrepareRequest,
303
+ },
107
304
  });
305
+
108
306
  return data;
109
307
  }
110
308
 
@@ -113,58 +311,56 @@ export async function submitOnboarding(
113
311
  prepareResponse: OnboardingPrepareResponse,
114
312
  signature: string,
115
313
  ) {
116
- const { data } = await network<OnboardingSubmitResponse>({
314
+ const { data } = await gatewayNetwork<OnboardingSubmitResponse, OnboardingSubmitRequest>({
117
315
  method: "POST",
118
316
  url: `${getGatewayUrl()}/v1/node/${getNodeId()}/onboarding/submit`,
119
317
  data: {
120
318
  prepare_request: prepareRequest,
121
319
  prepare_response: prepareResponse,
122
320
  signature,
123
- } satisfies OnboardingSubmitRequest,
321
+ },
124
322
  });
125
323
  return data;
126
324
  }
127
325
 
128
- export async function submit(serializedTx: string, signature: string) {
129
- const { data } = await network<TransactionSubmitResponse>({
326
+ export async function submit(partyId: string, serialized: string, signature: string) {
327
+ const { data } = await gatewayNetwork<TransactionSubmitResponse, TransactionSubmitRequest>({
130
328
  method: "POST",
131
- url: `${getGatewayUrl()}/v1/node/${getNodeId()}/transaction/submit`,
329
+ url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/transaction/submit`,
132
330
  data: {
133
- serialized: serializedTx,
331
+ serialized,
134
332
  signature,
135
- } satisfies TransactionSubmitRequest,
333
+ },
136
334
  });
137
335
  return data;
138
336
  }
139
337
 
140
338
  export async function getBalance(partyId: string): Promise<InstrumentBalance[]> {
141
- const { data } = await network<InstrumentBalance[]>({
339
+ const { data } = await gatewayNetwork<InstrumentBalance[]>({
142
340
  method: "GET",
143
- url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/balance`,
341
+ // TODO: we need better solution ?
342
+ url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId.replace(/_/g, ":")}/balance`,
144
343
  });
145
344
  return data;
146
345
  }
147
346
 
148
347
  export async function getPartyById(partyId: string): Promise<PartyInfo> {
149
- return await getParty(partyId, "ID");
348
+ return await getParty(partyId, "party-id");
150
349
  }
151
350
 
152
351
  export async function getPartyByPubKey(pubKey: string): Promise<PartyInfo> {
153
- return await getParty(pubKey, "PK");
352
+ return await getParty(pubKey, "public-key");
154
353
  }
155
354
 
156
- async function getParty(identifier: string, by: "ID" | "PK"): Promise<PartyInfo> {
157
- const { data } = await network<PartyInfo>({
355
+ async function getParty(identifier: string, by: "party-id" | "public-key"): Promise<PartyInfo> {
356
+ const { data } = await gatewayNetwork<PartyInfo>({
158
357
  method: "GET",
159
- url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${identifier}`,
160
- data: {
161
- by,
162
- },
358
+ url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${identifier}?by=${by}`,
163
359
  });
164
360
  return data;
165
361
  }
166
362
 
167
- export async function getTransactions(
363
+ export async function getOperations(
168
364
  partyId: string,
169
365
  options?: {
170
366
  cursor?: number | undefined;
@@ -174,23 +370,134 @@ export async function getTransactions(
174
370
  },
175
371
  ): Promise<{
176
372
  next: number;
177
- transactions: TxInfo[];
373
+ operations: OperationInfo[];
178
374
  }> {
179
- const { data } = await network<{
375
+ const { data } = await gatewayNetwork<{
180
376
  next: number;
181
- transactions: TxInfo[];
377
+ operations: OperationInfo[];
182
378
  }>({
183
379
  method: "GET",
184
- url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/transactions`,
185
- data: options,
380
+ url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId.replace(/_/g, ":")}/operations`,
381
+ params: options,
382
+ });
383
+ return data;
384
+ }
385
+
386
+ type PrepareTapRequestRequest = {
387
+ partyId: string;
388
+ amount?: number;
389
+ };
390
+
391
+ type PrepareTapRequestResponse = {
392
+ serialized: "string";
393
+ json: null;
394
+ hash: "string";
395
+ };
396
+
397
+ enum TransactionType {
398
+ TAP_REQUEST = "tap-request",
399
+ TRANSFER_PRE_APPROVAL_PROPOSAL = "transfer-pre-approval-proposal",
400
+ }
401
+
402
+ export async function prepareTapRequest({
403
+ partyId,
404
+ amount = 1000000,
405
+ }: PrepareTapRequestRequest): Promise<PrepareTapRequestResponse> {
406
+ const { data } = await gatewayNetwork<
407
+ PrepareTapRequestResponse,
408
+ { amount: number; type: string }
409
+ >({
410
+ method: "POST",
411
+ url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/transaction/prepare`,
412
+ data: {
413
+ amount: parseInt(amount.toString(), 10), // Convert to integer to avoid scientific notation
414
+ type: TransactionType.TAP_REQUEST,
415
+ },
416
+ });
417
+ return data;
418
+ }
419
+
420
+ type SubmitTapRequestRequest = {
421
+ partyId: string;
422
+ serialized: string;
423
+ signature: string;
424
+ };
425
+
426
+ type SubmitTapRequestResponse = {
427
+ submission_id: string;
428
+ update_id: string;
429
+ };
430
+
431
+ export async function submitTapRequest({
432
+ partyId,
433
+ serialized,
434
+ signature,
435
+ }: SubmitTapRequestRequest): Promise<SubmitTapRequestResponse> {
436
+ const { data } = await gatewayNetwork<
437
+ SubmitTapRequestResponse,
438
+ Omit<SubmitTapRequestRequest, "partyId">
439
+ >({
440
+ method: "POST",
441
+ url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/transaction/submit`,
442
+ data: {
443
+ serialized,
444
+ signature,
445
+ },
446
+ });
447
+ return data;
448
+ }
449
+
450
+ export async function prepareTransferRequest(
451
+ partyId: string,
452
+ params: PrepareTransferRequest,
453
+ ): Promise<PrepareTransferResponse> {
454
+ const { data } = await network<PrepareTransferResponse>({
455
+ method: "POST",
456
+ url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/transaction/prepare`,
457
+ data: params,
186
458
  });
187
459
  return data;
188
460
  }
189
461
 
190
462
  export async function getLedgerEnd(): Promise<number> {
191
- const { data } = await network<number>({
463
+ const { data } = await gatewayNetwork<number>({
192
464
  method: "GET",
193
465
  url: `${getGatewayUrl()}/v1/node/${getNodeId()}/ledger-end`,
194
466
  });
195
467
  return data;
196
468
  }
469
+
470
+ export async function preparePreApprovalTransaction(
471
+ partyId: string,
472
+ ): Promise<PrepareTransactionResponse> {
473
+ const { data } = await gatewayNetwork<PrepareTransactionResponse, PrepareTransactionRequest>({
474
+ method: "POST",
475
+ url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/transaction/prepare`,
476
+ data: {
477
+ type: TransactionType.TRANSFER_PRE_APPROVAL_PROPOSAL,
478
+ receiver: partyId,
479
+ },
480
+ });
481
+ return data;
482
+ }
483
+
484
+ export async function submitPreApprovalTransaction(
485
+ partyId: string,
486
+ { serialized }: PrepareTransactionResponse,
487
+ signature: string,
488
+ ): Promise<PreApprovalResult> {
489
+ const { data } = await gatewayNetwork<SubmitTransactionResponse, SubmitTransactionRequest>({
490
+ method: "POST",
491
+ url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/transaction/submit`,
492
+ data: {
493
+ serialized,
494
+ signature,
495
+ },
496
+ });
497
+
498
+ return {
499
+ isApproved: true,
500
+ submissionId: data.submission_id,
501
+ updateId: data.update_id,
502
+ };
503
+ }