@ledgerhq/coin-canton 0.5.0-nightly.4 → 0.5.0-nightly.6
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.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +20 -0
- package/lib/api/getBalance.integ.test.js +1 -1
- package/lib/api/getBalance.integ.test.js.map +1 -1
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +20 -28
- package/lib/api/index.js.map +1 -1
- package/lib/api/lastBlock.integ.test.js +1 -1
- package/lib/api/lastBlock.integ.test.js.map +1 -1
- package/lib/api/listOperations.integ.test.js +1 -1
- package/lib/api/listOperations.integ.test.js.map +1 -1
- package/lib/bridge/broadcast.d.ts.map +1 -1
- package/lib/bridge/broadcast.js +2 -2
- package/lib/bridge/broadcast.js.map +1 -1
- package/lib/bridge/broadcast.test.js +9 -0
- package/lib/bridge/broadcast.test.js.map +1 -1
- package/lib/bridge/createTransaction.js +1 -1
- package/lib/bridge/createTransaction.js.map +1 -1
- package/lib/bridge/getTransactionStatus.js +1 -1
- package/lib/bridge/getTransactionStatus.js.map +1 -1
- package/lib/bridge/onboard.d.ts +4 -3
- package/lib/bridge/onboard.d.ts.map +1 -1
- package/lib/bridge/onboard.integ.test.js +11 -8
- package/lib/bridge/onboard.integ.test.js.map +1 -1
- package/lib/bridge/onboard.js +24 -16
- package/lib/bridge/onboard.js.map +1 -1
- package/lib/bridge/prepareTransaction.js +1 -1
- package/lib/bridge/prepareTransaction.js.map +1 -1
- package/lib/bridge/signOperation.d.ts.map +1 -1
- package/lib/bridge/signOperation.js +10 -5
- package/lib/bridge/signOperation.js.map +1 -1
- package/lib/bridge/sync.d.ts.map +1 -1
- package/lib/bridge/sync.js +28 -20
- package/lib/bridge/sync.js.map +1 -1
- package/lib/common-logic/account/getBalance.d.ts +2 -1
- package/lib/common-logic/account/getBalance.d.ts.map +1 -1
- package/lib/common-logic/account/getBalance.js +7 -7
- package/lib/common-logic/account/getBalance.js.map +1 -1
- package/lib/common-logic/account/getBalance.unit.test.js +6 -3
- package/lib/common-logic/account/getBalance.unit.test.js.map +1 -1
- package/lib/common-logic/history/lastBlock.d.ts +2 -1
- package/lib/common-logic/history/lastBlock.d.ts.map +1 -1
- package/lib/common-logic/history/lastBlock.js +3 -3
- package/lib/common-logic/history/lastBlock.js.map +1 -1
- package/lib/common-logic/history/lastBlock.test.js +5 -2
- package/lib/common-logic/history/lastBlock.test.js.map +1 -1
- package/lib/common-logic/history/listOperations.d.ts +2 -1
- package/lib/common-logic/history/listOperations.d.ts.map +1 -1
- package/lib/common-logic/history/listOperations.js +2 -2
- package/lib/common-logic/history/listOperations.js.map +1 -1
- package/lib/common-logic/transaction/broadcast.d.ts +2 -1
- package/lib/common-logic/transaction/broadcast.d.ts.map +1 -1
- package/lib/common-logic/transaction/broadcast.js +4 -4
- package/lib/common-logic/transaction/broadcast.js.map +1 -1
- package/lib/common-logic/transaction/broadcast.test.js +6 -3
- package/lib/common-logic/transaction/broadcast.test.js.map +1 -1
- package/lib/common-logic/transaction/craftTransaction.d.ts +3 -1
- package/lib/common-logic/transaction/craftTransaction.d.ts.map +1 -1
- package/lib/common-logic/transaction/craftTransaction.js +8 -4
- package/lib/common-logic/transaction/craftTransaction.js.map +1 -1
- package/lib/common-logic/transaction/estimateFees.d.ts +2 -1
- package/lib/common-logic/transaction/estimateFees.d.ts.map +1 -1
- package/lib/common-logic/transaction/estimateFees.js +3 -4
- package/lib/common-logic/transaction/estimateFees.js.map +1 -1
- package/lib/network/gateway.d.ts +24 -14
- package/lib/network/gateway.d.ts.map +1 -1
- package/lib/network/gateway.integ.test.js +17 -14
- package/lib/network/gateway.integ.test.js.map +1 -1
- package/lib/network/gateway.js +33 -33
- package/lib/network/gateway.js.map +1 -1
- package/lib/types/bridge.d.ts +5 -2
- package/lib/types/bridge.d.ts.map +1 -1
- package/lib-es/api/getBalance.integ.test.js +1 -1
- package/lib-es/api/getBalance.integ.test.js.map +1 -1
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +19 -27
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/api/lastBlock.integ.test.js +1 -1
- package/lib-es/api/lastBlock.integ.test.js.map +1 -1
- package/lib-es/api/listOperations.integ.test.js +1 -1
- package/lib-es/api/listOperations.integ.test.js.map +1 -1
- package/lib-es/bridge/broadcast.d.ts.map +1 -1
- package/lib-es/bridge/broadcast.js +2 -2
- package/lib-es/bridge/broadcast.js.map +1 -1
- package/lib-es/bridge/broadcast.test.js +9 -0
- package/lib-es/bridge/broadcast.test.js.map +1 -1
- package/lib-es/bridge/createTransaction.js +1 -1
- package/lib-es/bridge/createTransaction.js.map +1 -1
- package/lib-es/bridge/getTransactionStatus.js +1 -1
- package/lib-es/bridge/getTransactionStatus.js.map +1 -1
- package/lib-es/bridge/onboard.d.ts +4 -3
- package/lib-es/bridge/onboard.d.ts.map +1 -1
- package/lib-es/bridge/onboard.integ.test.js +11 -8
- package/lib-es/bridge/onboard.integ.test.js.map +1 -1
- package/lib-es/bridge/onboard.js +24 -16
- package/lib-es/bridge/onboard.js.map +1 -1
- package/lib-es/bridge/prepareTransaction.js +1 -1
- package/lib-es/bridge/prepareTransaction.js.map +1 -1
- package/lib-es/bridge/signOperation.d.ts.map +1 -1
- package/lib-es/bridge/signOperation.js +10 -5
- package/lib-es/bridge/signOperation.js.map +1 -1
- package/lib-es/bridge/sync.d.ts.map +1 -1
- package/lib-es/bridge/sync.js +28 -20
- package/lib-es/bridge/sync.js.map +1 -1
- package/lib-es/common-logic/account/getBalance.d.ts +2 -1
- package/lib-es/common-logic/account/getBalance.d.ts.map +1 -1
- package/lib-es/common-logic/account/getBalance.js +7 -7
- package/lib-es/common-logic/account/getBalance.js.map +1 -1
- package/lib-es/common-logic/account/getBalance.unit.test.js +6 -3
- package/lib-es/common-logic/account/getBalance.unit.test.js.map +1 -1
- package/lib-es/common-logic/history/lastBlock.d.ts +2 -1
- package/lib-es/common-logic/history/lastBlock.d.ts.map +1 -1
- package/lib-es/common-logic/history/lastBlock.js +3 -3
- package/lib-es/common-logic/history/lastBlock.js.map +1 -1
- package/lib-es/common-logic/history/lastBlock.test.js +5 -2
- package/lib-es/common-logic/history/lastBlock.test.js.map +1 -1
- package/lib-es/common-logic/history/listOperations.d.ts +2 -1
- package/lib-es/common-logic/history/listOperations.d.ts.map +1 -1
- package/lib-es/common-logic/history/listOperations.js +2 -2
- package/lib-es/common-logic/history/listOperations.js.map +1 -1
- package/lib-es/common-logic/transaction/broadcast.d.ts +2 -1
- package/lib-es/common-logic/transaction/broadcast.d.ts.map +1 -1
- package/lib-es/common-logic/transaction/broadcast.js +4 -4
- package/lib-es/common-logic/transaction/broadcast.js.map +1 -1
- package/lib-es/common-logic/transaction/broadcast.test.js +6 -3
- package/lib-es/common-logic/transaction/broadcast.test.js.map +1 -1
- package/lib-es/common-logic/transaction/craftTransaction.d.ts +3 -1
- package/lib-es/common-logic/transaction/craftTransaction.d.ts.map +1 -1
- package/lib-es/common-logic/transaction/craftTransaction.js +9 -5
- package/lib-es/common-logic/transaction/craftTransaction.js.map +1 -1
- package/lib-es/common-logic/transaction/estimateFees.d.ts +2 -1
- package/lib-es/common-logic/transaction/estimateFees.d.ts.map +1 -1
- package/lib-es/common-logic/transaction/estimateFees.js +3 -4
- package/lib-es/common-logic/transaction/estimateFees.js.map +1 -1
- package/lib-es/network/gateway.d.ts +24 -14
- package/lib-es/network/gateway.d.ts.map +1 -1
- package/lib-es/network/gateway.integ.test.js +17 -14
- package/lib-es/network/gateway.integ.test.js.map +1 -1
- package/lib-es/network/gateway.js +33 -33
- package/lib-es/network/gateway.js.map +1 -1
- package/lib-es/types/bridge.d.ts +5 -2
- package/lib-es/types/bridge.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/api/getBalance.integ.test.ts +1 -1
- package/src/api/index.ts +22 -51
- package/src/api/lastBlock.integ.test.ts +1 -1
- package/src/api/listOperations.integ.test.ts +1 -1
- package/src/bridge/broadcast.test.ts +11 -0
- package/src/bridge/broadcast.ts +5 -2
- package/src/bridge/createTransaction.ts +1 -1
- package/src/bridge/getTransactionStatus.ts +1 -1
- package/src/bridge/onboard.integ.test.ts +22 -10
- package/src/bridge/onboard.ts +32 -13
- package/src/bridge/prepareTransaction.ts +1 -1
- package/src/bridge/signOperation.ts +20 -7
- package/src/bridge/sync.ts +28 -23
- package/src/common-logic/account/getBalance.ts +12 -7
- package/src/common-logic/account/getBalance.unit.test.ts +8 -3
- package/src/common-logic/history/lastBlock.test.ts +7 -2
- package/src/common-logic/history/lastBlock.ts +5 -3
- package/src/common-logic/history/listOperations.ts +3 -2
- package/src/common-logic/transaction/broadcast.test.ts +8 -3
- package/src/common-logic/transaction/broadcast.ts +6 -3
- package/src/common-logic/transaction/craftTransaction.ts +22 -5
- package/src/common-logic/transaction/estimateFees.ts +5 -4
- package/src/network/gateway.integ.test.ts +29 -11
- package/src/network/gateway.ts +66 -35
- package/src/types/bridge.ts +5 -0
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import coinConfig from "../../config";
|
|
2
|
+
import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
2
3
|
|
|
3
|
-
const feeValue = () =>
|
|
4
|
+
const feeValue = (currency: CryptoCurrency) =>
|
|
5
|
+
coinConfig.getCoinConfig(currency).fee ?? 2n * 10n ** 38n;
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return Promise.resolve(BigInt(feeValue())); // TODO replace with real implementation
|
|
7
|
+
export async function estimateFees(currency: CryptoCurrency): Promise<bigint> {
|
|
8
|
+
return Promise.resolve(BigInt(feeValue(currency)));
|
|
8
9
|
}
|
|
@@ -13,6 +13,11 @@ import {
|
|
|
13
13
|
preparePreApprovalTransaction,
|
|
14
14
|
submitPreApprovalTransaction,
|
|
15
15
|
} from "./gateway";
|
|
16
|
+
import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
17
|
+
|
|
18
|
+
const mockCurrency = {
|
|
19
|
+
id: "canton_network",
|
|
20
|
+
} as unknown as CryptoCurrency;
|
|
16
21
|
|
|
17
22
|
describe("gateway (devnet)", () => {
|
|
18
23
|
let onboardedAccount: {
|
|
@@ -50,7 +55,7 @@ describe("gateway (devnet)", () => {
|
|
|
50
55
|
};
|
|
51
56
|
|
|
52
57
|
// WHEN
|
|
53
|
-
const response = await prepareOnboarding(keyPair.publicKeyHex, "ed25519");
|
|
58
|
+
const response = await prepareOnboarding(mockCurrency, keyPair.publicKeyHex, "ed25519");
|
|
54
59
|
|
|
55
60
|
// THEN
|
|
56
61
|
expect(response).toHaveProperty("party_id");
|
|
@@ -70,11 +75,20 @@ describe("gateway (devnet)", () => {
|
|
|
70
75
|
// GIVEN
|
|
71
76
|
const { keyPair } = getOnboardedAccount();
|
|
72
77
|
const prepareRequest = { public_key: keyPair.publicKeyHex, public_key_type: "ed25519" };
|
|
73
|
-
const prepareResponse = await prepareOnboarding(
|
|
78
|
+
const prepareResponse = await prepareOnboarding(
|
|
79
|
+
mockCurrency,
|
|
80
|
+
keyPair.publicKeyHex,
|
|
81
|
+
"ed25519",
|
|
82
|
+
);
|
|
74
83
|
const signature = keyPair.sign(prepareResponse.transactions.combined_hash);
|
|
75
84
|
|
|
76
85
|
// WHEN
|
|
77
|
-
const response = await submitOnboarding(
|
|
86
|
+
const response = await submitOnboarding(
|
|
87
|
+
mockCurrency,
|
|
88
|
+
prepareRequest,
|
|
89
|
+
prepareResponse,
|
|
90
|
+
signature,
|
|
91
|
+
);
|
|
78
92
|
|
|
79
93
|
// Save onboarded account for all tests that need a valid party ID
|
|
80
94
|
onboardedAccount = {
|
|
@@ -92,7 +106,7 @@ describe("gateway (devnet)", () => {
|
|
|
92
106
|
|
|
93
107
|
describe("getLedgerEnd", () => {
|
|
94
108
|
it("should return ledger end", async () => {
|
|
95
|
-
const end = await getLedgerEnd();
|
|
109
|
+
const end = await getLedgerEnd(mockCurrency);
|
|
96
110
|
expect(end).toBeGreaterThanOrEqual(0);
|
|
97
111
|
});
|
|
98
112
|
});
|
|
@@ -100,7 +114,7 @@ describe("gateway (devnet)", () => {
|
|
|
100
114
|
describe("getBalance", () => {
|
|
101
115
|
it("should return user balance", async () => {
|
|
102
116
|
const { partyId } = getOnboardedAccount();
|
|
103
|
-
const balance = await getBalance(partyId);
|
|
117
|
+
const balance = await getBalance(mockCurrency, partyId);
|
|
104
118
|
expect(balance.length).toBeGreaterThanOrEqual(0);
|
|
105
119
|
if (balance.length > 0) {
|
|
106
120
|
expect(balance[0].amount).toBeGreaterThanOrEqual(0);
|
|
@@ -111,7 +125,7 @@ describe("gateway (devnet)", () => {
|
|
|
111
125
|
|
|
112
126
|
describe("getPartyById", () => {
|
|
113
127
|
it.skip("should return party info", async () => {
|
|
114
|
-
const party = await getPartyById("4f2e1485107adf5f");
|
|
128
|
+
const party = await getPartyById(mockCurrency, "4f2e1485107adf5f");
|
|
115
129
|
expect(party).toBeDefined();
|
|
116
130
|
});
|
|
117
131
|
});
|
|
@@ -119,6 +133,7 @@ describe("gateway (devnet)", () => {
|
|
|
119
133
|
describe("getPartyByPubKey", () => {
|
|
120
134
|
it.skip("should return party info", async () => {
|
|
121
135
|
const party = await getPartyByPubKey(
|
|
136
|
+
mockCurrency,
|
|
122
137
|
"122027c6dbbbdbffe0fa3122ae05175f3b9328e879e9ce96b670354deb64a45683c1",
|
|
123
138
|
);
|
|
124
139
|
expect(party).toBeDefined();
|
|
@@ -128,7 +143,9 @@ describe("gateway (devnet)", () => {
|
|
|
128
143
|
describe("getOperations", () => {
|
|
129
144
|
it("should return user transactions", async () => {
|
|
130
145
|
const { operations } = await getOperations(
|
|
146
|
+
mockCurrency,
|
|
131
147
|
"party-5f29bb32e9939939::12202becd8062a1d170209956cfd977fca76fcb4d2a892d08c77a7483f35a11d6440",
|
|
148
|
+
{},
|
|
132
149
|
);
|
|
133
150
|
expect(operations.length).toBeGreaterThanOrEqual(0);
|
|
134
151
|
});
|
|
@@ -141,7 +158,7 @@ describe("gateway (devnet)", () => {
|
|
|
141
158
|
const amount = 1000;
|
|
142
159
|
|
|
143
160
|
// WHEN
|
|
144
|
-
const response = await prepareTapRequest({ partyId, amount });
|
|
161
|
+
const response = await prepareTapRequest(mockCurrency, { partyId, amount });
|
|
145
162
|
|
|
146
163
|
// THEN
|
|
147
164
|
expect(response).toHaveProperty("serialized");
|
|
@@ -155,14 +172,14 @@ describe("gateway (devnet)", () => {
|
|
|
155
172
|
it("should submit tap request with proper signature", async () => {
|
|
156
173
|
// GIVEN
|
|
157
174
|
const { keyPair, partyId } = getOnboardedAccount();
|
|
158
|
-
const tapPrepareResponse = await prepareTapRequest({
|
|
175
|
+
const tapPrepareResponse = await prepareTapRequest(mockCurrency, {
|
|
159
176
|
partyId,
|
|
160
177
|
amount: 1000,
|
|
161
178
|
});
|
|
162
179
|
const tapSignature = keyPair.sign(tapPrepareResponse.hash);
|
|
163
180
|
|
|
164
181
|
// WHEN
|
|
165
|
-
const response = await submitTapRequest({
|
|
182
|
+
const response = await submitTapRequest(mockCurrency, {
|
|
166
183
|
partyId,
|
|
167
184
|
serialized: tapPrepareResponse.serialized,
|
|
168
185
|
signature: tapSignature,
|
|
@@ -182,7 +199,7 @@ describe("gateway (devnet)", () => {
|
|
|
182
199
|
const { partyId } = getOnboardedAccount();
|
|
183
200
|
|
|
184
201
|
// WHEN
|
|
185
|
-
const response = await preparePreApprovalTransaction(partyId);
|
|
202
|
+
const response = await preparePreApprovalTransaction(mockCurrency, partyId);
|
|
186
203
|
|
|
187
204
|
// THEN
|
|
188
205
|
expect(response).toHaveProperty("serialized");
|
|
@@ -196,11 +213,12 @@ describe("gateway (devnet)", () => {
|
|
|
196
213
|
it("should submit pre-approval transaction with proper signature", async () => {
|
|
197
214
|
// GIVEN
|
|
198
215
|
const { keyPair, partyId } = getOnboardedAccount();
|
|
199
|
-
const preparedTransaction = await preparePreApprovalTransaction(partyId);
|
|
216
|
+
const preparedTransaction = await preparePreApprovalTransaction(mockCurrency, partyId);
|
|
200
217
|
const preApprovalSignature = keyPair.sign(preparedTransaction.hash);
|
|
201
218
|
|
|
202
219
|
// WHEN
|
|
203
220
|
const response = await submitPreApprovalTransaction(
|
|
221
|
+
mockCurrency,
|
|
204
222
|
partyId,
|
|
205
223
|
preparedTransaction,
|
|
206
224
|
preApprovalSignature,
|
package/src/network/gateway.ts
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
SubmitTransactionResponse,
|
|
10
10
|
PreApprovalResult,
|
|
11
11
|
} from "../types/onboard";
|
|
12
|
+
import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
12
13
|
|
|
13
14
|
type OnboardingPrepareResponse = {
|
|
14
15
|
party_id: string;
|
|
@@ -47,7 +48,7 @@ export type PrepareTransferResponse = {
|
|
|
47
48
|
|
|
48
49
|
export type PrepareTransferRequest = {
|
|
49
50
|
type: "token-transfer-request";
|
|
50
|
-
amount:
|
|
51
|
+
amount: string;
|
|
51
52
|
recipient: string;
|
|
52
53
|
execute_before_secs: number;
|
|
53
54
|
instrument_id: string;
|
|
@@ -151,6 +152,9 @@ export type OperationInfo =
|
|
|
151
152
|
asset: string;
|
|
152
153
|
details: {
|
|
153
154
|
type: "pre-approval";
|
|
155
|
+
metadata: {
|
|
156
|
+
reason?: string;
|
|
157
|
+
};
|
|
154
158
|
};
|
|
155
159
|
},
|
|
156
160
|
];
|
|
@@ -193,6 +197,9 @@ export type OperationInfo =
|
|
|
193
197
|
asset: string;
|
|
194
198
|
details: {
|
|
195
199
|
type: "tap";
|
|
200
|
+
metadata: {
|
|
201
|
+
reason?: string;
|
|
202
|
+
};
|
|
196
203
|
};
|
|
197
204
|
},
|
|
198
205
|
];
|
|
@@ -235,6 +242,9 @@ export type OperationInfo =
|
|
|
235
242
|
asset: string;
|
|
236
243
|
details: {
|
|
237
244
|
type: "transfer";
|
|
245
|
+
metadata: {
|
|
246
|
+
reason?: string;
|
|
247
|
+
};
|
|
238
248
|
};
|
|
239
249
|
},
|
|
240
250
|
];
|
|
@@ -262,9 +272,10 @@ export type OperationInfo =
|
|
|
262
272
|
};
|
|
263
273
|
};
|
|
264
274
|
|
|
265
|
-
const getGatewayUrl = () => coinConfig.getCoinConfig().gatewayUrl;
|
|
266
|
-
const getNodeId = () =>
|
|
267
|
-
|
|
275
|
+
const getGatewayUrl = (currency: CryptoCurrency) => coinConfig.getCoinConfig(currency).gatewayUrl;
|
|
276
|
+
const getNodeId = (currency: CryptoCurrency) =>
|
|
277
|
+
coinConfig.getCoinConfig(currency).nodeId || "ledger-devnet-stg";
|
|
278
|
+
const getNetworkType = (currency: CryptoCurrency) => coinConfig.getCoinConfig(currency).networkType;
|
|
268
279
|
|
|
269
280
|
const gatewayNetwork = <T, U = unknown>(req: LiveNetworkRequest<U>) => {
|
|
270
281
|
const API_KEY = getEnv("CANTON_API_KEY");
|
|
@@ -278,11 +289,12 @@ const gatewayNetwork = <T, U = unknown>(req: LiveNetworkRequest<U>) => {
|
|
|
278
289
|
};
|
|
279
290
|
|
|
280
291
|
export async function prepareOnboarding(
|
|
292
|
+
currency: CryptoCurrency,
|
|
281
293
|
pubKey: string,
|
|
282
294
|
pubKeyType: string,
|
|
283
295
|
): Promise<OnboardingPrepareResponse> {
|
|
284
|
-
const gatewayUrl = getGatewayUrl();
|
|
285
|
-
const nodeId = getNodeId();
|
|
296
|
+
const gatewayUrl = getGatewayUrl(currency);
|
|
297
|
+
const nodeId = getNodeId(currency);
|
|
286
298
|
const fullUrl = `${gatewayUrl}/v1/node/${nodeId}/onboarding/prepare`;
|
|
287
299
|
|
|
288
300
|
const { data } = await gatewayNetwork<OnboardingPrepareResponse, OnboardingPrepareRequest>({
|
|
@@ -298,13 +310,14 @@ export async function prepareOnboarding(
|
|
|
298
310
|
}
|
|
299
311
|
|
|
300
312
|
export async function submitOnboarding(
|
|
313
|
+
currency: CryptoCurrency,
|
|
301
314
|
prepareRequest: OnboardingPrepareRequest,
|
|
302
315
|
prepareResponse: OnboardingPrepareResponse,
|
|
303
316
|
signature: string,
|
|
304
317
|
) {
|
|
305
318
|
const { data } = await gatewayNetwork<OnboardingSubmitResponse, OnboardingSubmitRequest>({
|
|
306
319
|
method: "POST",
|
|
307
|
-
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/onboarding/submit`,
|
|
320
|
+
url: `${getGatewayUrl(currency)}/v1/node/${getNodeId(currency)}/onboarding/submit`,
|
|
308
321
|
data: {
|
|
309
322
|
prepare_request: prepareRequest,
|
|
310
323
|
prepare_response: prepareResponse,
|
|
@@ -314,10 +327,15 @@ export async function submitOnboarding(
|
|
|
314
327
|
return data;
|
|
315
328
|
}
|
|
316
329
|
|
|
317
|
-
export async function submit(
|
|
330
|
+
export async function submit(
|
|
331
|
+
currency: CryptoCurrency,
|
|
332
|
+
partyId: string,
|
|
333
|
+
serialized: string,
|
|
334
|
+
signature: string,
|
|
335
|
+
) {
|
|
318
336
|
const { data } = await gatewayNetwork<TransactionSubmitResponse, TransactionSubmitRequest>({
|
|
319
337
|
method: "POST",
|
|
320
|
-
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/transaction/submit`,
|
|
338
|
+
url: `${getGatewayUrl(currency)}/v1/node/${getNodeId(currency)}/party/${partyId}/transaction/submit`,
|
|
321
339
|
data: {
|
|
322
340
|
serialized,
|
|
323
341
|
signature,
|
|
@@ -326,31 +344,42 @@ export async function submit(partyId: string, serialized: string, signature: str
|
|
|
326
344
|
return data;
|
|
327
345
|
}
|
|
328
346
|
|
|
329
|
-
export async function getBalance(
|
|
347
|
+
export async function getBalance(
|
|
348
|
+
currency: CryptoCurrency,
|
|
349
|
+
partyId: string,
|
|
350
|
+
): Promise<InstrumentBalance[]> {
|
|
330
351
|
const { data } = await gatewayNetwork<InstrumentBalance[]>({
|
|
331
352
|
method: "GET",
|
|
332
|
-
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/balance`,
|
|
353
|
+
url: `${getGatewayUrl(currency)}/v1/node/${getNodeId(currency)}/party/${partyId}/balance`,
|
|
333
354
|
});
|
|
334
355
|
return data;
|
|
335
356
|
}
|
|
336
357
|
|
|
337
|
-
export async function getPartyById(partyId: string): Promise<PartyInfo> {
|
|
338
|
-
return await getParty(partyId, "party-id");
|
|
358
|
+
export async function getPartyById(currency: CryptoCurrency, partyId: string): Promise<PartyInfo> {
|
|
359
|
+
return await getParty(currency, partyId, "party-id");
|
|
339
360
|
}
|
|
340
361
|
|
|
341
|
-
export async function getPartyByPubKey(
|
|
342
|
-
|
|
362
|
+
export async function getPartyByPubKey(
|
|
363
|
+
currency: CryptoCurrency,
|
|
364
|
+
pubKey: string,
|
|
365
|
+
): Promise<PartyInfo> {
|
|
366
|
+
return await getParty(currency, pubKey, "public-key");
|
|
343
367
|
}
|
|
344
368
|
|
|
345
|
-
async function getParty(
|
|
369
|
+
async function getParty(
|
|
370
|
+
currency: CryptoCurrency,
|
|
371
|
+
identifier: string,
|
|
372
|
+
by: "party-id" | "public-key",
|
|
373
|
+
): Promise<PartyInfo> {
|
|
346
374
|
const { data } = await gatewayNetwork<PartyInfo>({
|
|
347
375
|
method: "GET",
|
|
348
|
-
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${identifier}?by=${by}`,
|
|
376
|
+
url: `${getGatewayUrl(currency)}/v1/node/${getNodeId(currency)}/party/${identifier}?by=${by}`,
|
|
349
377
|
});
|
|
350
378
|
return data;
|
|
351
379
|
}
|
|
352
380
|
|
|
353
381
|
export async function getOperations(
|
|
382
|
+
currency: CryptoCurrency,
|
|
354
383
|
partyId: string,
|
|
355
384
|
options?: {
|
|
356
385
|
cursor?: number | undefined;
|
|
@@ -367,7 +396,7 @@ export async function getOperations(
|
|
|
367
396
|
operations: OperationInfo[];
|
|
368
397
|
}>({
|
|
369
398
|
method: "GET",
|
|
370
|
-
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/operations`,
|
|
399
|
+
url: `${getGatewayUrl(currency)}/v1/node/${getNodeId(currency)}/party/${partyId}/operations`,
|
|
371
400
|
params: options,
|
|
372
401
|
});
|
|
373
402
|
return data;
|
|
@@ -389,11 +418,11 @@ enum TransactionType {
|
|
|
389
418
|
TRANSFER_PRE_APPROVAL_PROPOSAL = "transfer-pre-approval-proposal",
|
|
390
419
|
}
|
|
391
420
|
|
|
392
|
-
export async function prepareTapRequest(
|
|
393
|
-
|
|
394
|
-
amount = 1000000,
|
|
395
|
-
|
|
396
|
-
if (getNetworkType() === "mainnet") {
|
|
421
|
+
export async function prepareTapRequest(
|
|
422
|
+
currency: CryptoCurrency,
|
|
423
|
+
{ partyId, amount = 1000000 }: PrepareTapRequest,
|
|
424
|
+
): Promise<PrepareTapResponse> {
|
|
425
|
+
if (getNetworkType(currency) === "mainnet") {
|
|
397
426
|
return {
|
|
398
427
|
serialized: "",
|
|
399
428
|
json: null,
|
|
@@ -402,7 +431,7 @@ export async function prepareTapRequest({
|
|
|
402
431
|
}
|
|
403
432
|
const { data } = await gatewayNetwork<PrepareTapResponse, { amount: number; type: string }>({
|
|
404
433
|
method: "POST",
|
|
405
|
-
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/transaction/prepare`,
|
|
434
|
+
url: `${getGatewayUrl(currency)}/v1/node/${getNodeId(currency)}/party/${partyId}/transaction/prepare`,
|
|
406
435
|
data: {
|
|
407
436
|
amount: parseInt(amount.toString(), 10), // Convert to integer to avoid scientific notation
|
|
408
437
|
type: TransactionType.TAP_REQUEST,
|
|
@@ -422,17 +451,16 @@ type SubmitTapRequestResponse = {
|
|
|
422
451
|
update_id: string;
|
|
423
452
|
};
|
|
424
453
|
|
|
425
|
-
export async function submitTapRequest(
|
|
426
|
-
|
|
427
|
-
serialized,
|
|
428
|
-
|
|
429
|
-
}: SubmitTapRequestRequest): Promise<SubmitTapRequestResponse> {
|
|
454
|
+
export async function submitTapRequest(
|
|
455
|
+
currency: CryptoCurrency,
|
|
456
|
+
{ partyId, serialized, signature }: SubmitTapRequestRequest,
|
|
457
|
+
): Promise<SubmitTapRequestResponse> {
|
|
430
458
|
const { data } = await gatewayNetwork<
|
|
431
459
|
SubmitTapRequestResponse,
|
|
432
460
|
Omit<SubmitTapRequestRequest, "partyId">
|
|
433
461
|
>({
|
|
434
462
|
method: "POST",
|
|
435
|
-
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/transaction/submit`,
|
|
463
|
+
url: `${getGatewayUrl(currency)}/v1/node/${getNodeId(currency)}/party/${partyId}/transaction/submit`,
|
|
436
464
|
data: {
|
|
437
465
|
serialized,
|
|
438
466
|
signature,
|
|
@@ -442,31 +470,33 @@ export async function submitTapRequest({
|
|
|
442
470
|
}
|
|
443
471
|
|
|
444
472
|
export async function prepareTransferRequest(
|
|
473
|
+
currency: CryptoCurrency,
|
|
445
474
|
partyId: string,
|
|
446
475
|
params: PrepareTransferRequest,
|
|
447
476
|
): Promise<PrepareTransferResponse> {
|
|
448
477
|
const { data } = await gatewayNetwork<PrepareTransferResponse, PrepareTransferRequest>({
|
|
449
478
|
method: "POST",
|
|
450
|
-
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/transaction/prepare`,
|
|
479
|
+
url: `${getGatewayUrl(currency)}/v1/node/${getNodeId(currency)}/party/${partyId}/transaction/prepare`,
|
|
451
480
|
data: params,
|
|
452
481
|
});
|
|
453
482
|
return data;
|
|
454
483
|
}
|
|
455
484
|
|
|
456
|
-
export async function getLedgerEnd(): Promise<number> {
|
|
485
|
+
export async function getLedgerEnd(currency: CryptoCurrency): Promise<number> {
|
|
457
486
|
const { data } = await gatewayNetwork<number>({
|
|
458
487
|
method: "GET",
|
|
459
|
-
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/ledger-end`,
|
|
488
|
+
url: `${getGatewayUrl(currency)}/v1/node/${getNodeId(currency)}/ledger-end`,
|
|
460
489
|
});
|
|
461
490
|
return data;
|
|
462
491
|
}
|
|
463
492
|
|
|
464
493
|
export async function preparePreApprovalTransaction(
|
|
494
|
+
currency: CryptoCurrency,
|
|
465
495
|
partyId: string,
|
|
466
496
|
): Promise<PrepareTransactionResponse> {
|
|
467
497
|
const { data } = await gatewayNetwork<PrepareTransactionResponse, PrepareTransactionRequest>({
|
|
468
498
|
method: "POST",
|
|
469
|
-
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/transaction/prepare`,
|
|
499
|
+
url: `${getGatewayUrl(currency)}/v1/node/${getNodeId(currency)}/party/${partyId}/transaction/prepare`,
|
|
470
500
|
data: {
|
|
471
501
|
type: TransactionType.TRANSFER_PRE_APPROVAL_PROPOSAL,
|
|
472
502
|
receiver: partyId,
|
|
@@ -476,13 +506,14 @@ export async function preparePreApprovalTransaction(
|
|
|
476
506
|
}
|
|
477
507
|
|
|
478
508
|
export async function submitPreApprovalTransaction(
|
|
509
|
+
currency: CryptoCurrency,
|
|
479
510
|
partyId: string,
|
|
480
511
|
{ serialized }: PrepareTransactionResponse,
|
|
481
512
|
signature: string,
|
|
482
513
|
): Promise<PreApprovalResult> {
|
|
483
514
|
const { data } = await gatewayNetwork<SubmitTransactionResponse, SubmitTransactionRequest>({
|
|
484
515
|
method: "POST",
|
|
485
|
-
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/transaction/submit`,
|
|
516
|
+
url: `${getGatewayUrl(currency)}/v1/node/${getNodeId(currency)}/party/${partyId}/transaction/submit`,
|
|
486
517
|
data: {
|
|
487
518
|
serialized,
|
|
488
519
|
signature,
|
package/src/types/bridge.ts
CHANGED
|
@@ -15,13 +15,16 @@ import type {
|
|
|
15
15
|
CantonPreApprovalProgress,
|
|
16
16
|
CantonPreApprovalResult,
|
|
17
17
|
} from "./onboard";
|
|
18
|
+
import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
18
19
|
|
|
19
20
|
export interface CantonCurrencyBridge extends CurrencyBridge {
|
|
20
21
|
onboardAccount: (
|
|
22
|
+
currency: CryptoCurrency,
|
|
21
23
|
deviceId: string,
|
|
22
24
|
derivationPath: string,
|
|
23
25
|
) => Observable<CantonOnboardProgress | CantonOnboardResult>;
|
|
24
26
|
authorizePreapproval: (
|
|
27
|
+
currency: CryptoCurrency,
|
|
25
28
|
deviceId: string,
|
|
26
29
|
derivationPath: string,
|
|
27
30
|
partyId: string,
|
|
@@ -43,11 +46,13 @@ export type NetworkInfoRaw = {
|
|
|
43
46
|
export type Transaction = TransactionCommon & {
|
|
44
47
|
family: "canton";
|
|
45
48
|
fee: BigNumber | null | undefined;
|
|
49
|
+
memo?: string;
|
|
46
50
|
};
|
|
47
51
|
|
|
48
52
|
export type TransactionRaw = TransactionCommonRaw & {
|
|
49
53
|
family: "canton";
|
|
50
54
|
fee: string | null | undefined;
|
|
55
|
+
memo?: string;
|
|
51
56
|
};
|
|
52
57
|
|
|
53
58
|
export type TransactionStatus = TransactionStatusCommon;
|