@ledgerhq/coin-canton 0.5.0 → 0.5.1-nightly.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.
- package/CHANGELOG.md +12 -0
- package/lib/api/getBalance.integ.test.js +9 -5
- 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 -25
- 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 +3 -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/index.d.ts.map +1 -1
- package/lib/bridge/index.js +3 -0
- package/lib/bridge/index.js.map +1 -1
- package/lib/bridge/onboard.d.ts +7 -5
- package/lib/bridge/onboard.d.ts.map +1 -1
- package/lib/bridge/onboard.integ.test.js +14 -11
- package/lib/bridge/onboard.integ.test.js.map +1 -1
- package/lib/bridge/onboard.js +110 -42
- package/lib/bridge/onboard.js.map +1 -1
- package/lib/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib/bridge/prepareTransaction.js +5 -7
- package/lib/bridge/prepareTransaction.js.map +1 -1
- package/lib/bridge/serialization.d.ts +4 -0
- package/lib/bridge/serialization.d.ts.map +1 -0
- package/lib/bridge/serialization.js +31 -0
- package/lib/bridge/serialization.js.map +1 -0
- package/lib/bridge/signOperation.d.ts.map +1 -1
- package/lib/bridge/signOperation.js +14 -11
- package/lib/bridge/signOperation.js.map +1 -1
- package/lib/bridge/sync.d.ts +2 -1
- package/lib/bridge/sync.d.ts.map +1 -1
- package/lib/bridge/sync.integ.test.d.ts +2 -0
- package/lib/bridge/sync.integ.test.d.ts.map +1 -0
- package/lib/bridge/sync.integ.test.js +175 -0
- package/lib/bridge/sync.integ.test.js.map +1 -0
- package/lib/bridge/sync.js +50 -27
- package/lib/bridge/sync.js.map +1 -1
- package/lib/bridge/updateTransaction.d.ts.map +1 -1
- package/lib/bridge/updateTransaction.js +0 -4
- package/lib/bridge/updateTransaction.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 +5 -4
- package/lib/common-logic/transaction/broadcast.js.map +1 -1
- package/lib/common-logic/transaction/broadcast.test.js +8 -5
- package/lib/common-logic/transaction/broadcast.test.js.map +1 -1
- package/lib/common-logic/transaction/combine.d.ts +1 -1
- package/lib/common-logic/transaction/combine.d.ts.map +1 -1
- package/lib/common-logic/transaction/combine.js +2 -3
- package/lib/common-logic/transaction/combine.js.map +1 -1
- package/lib/common-logic/transaction/combine.test.js +3 -13
- package/lib/common-logic/transaction/combine.test.js.map +1 -1
- package/lib/common-logic/transaction/craftTransaction.d.ts +8 -4
- package/lib/common-logic/transaction/craftTransaction.d.ts.map +1 -1
- package/lib/common-logic/transaction/craftTransaction.js +15 -12
- 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 +7 -3
- package/lib/common-logic/transaction/estimateFees.js.map +1 -1
- package/lib/config.d.ts +1 -0
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js.map +1 -1
- package/lib/network/gateway.d.ts +41 -17
- package/lib/network/gateway.d.ts.map +1 -1
- package/lib/network/gateway.integ.test.js +19 -15
- package/lib/network/gateway.integ.test.js.map +1 -1
- package/lib/network/gateway.js +74 -48
- package/lib/network/gateway.js.map +1 -1
- package/lib/network/node.d.ts +2 -2
- package/lib/network/node.d.ts.map +1 -1
- package/lib/network/node.js.map +1 -1
- package/lib/network/types.d.ts +1 -1
- package/lib/network/types.d.ts.map +1 -1
- package/lib/signer/getAddress.d.ts.map +1 -1
- package/lib/signer/getAddress.js +2 -2
- package/lib/signer/getAddress.js.map +1 -1
- package/lib/types/bridge.d.ts +18 -3
- package/lib/types/bridge.d.ts.map +1 -1
- package/lib/types/index.d.ts +0 -10
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/onboard.d.ts +2 -0
- package/lib/types/onboard.d.ts.map +1 -1
- package/lib/types/onboard.js.map +1 -1
- package/lib/types/signer.d.ts +2 -1
- package/lib/types/signer.d.ts.map +1 -1
- package/lib-es/api/getBalance.integ.test.js +9 -5
- 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 -24
- 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 +3 -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/index.d.ts.map +1 -1
- package/lib-es/bridge/index.js +3 -0
- package/lib-es/bridge/index.js.map +1 -1
- package/lib-es/bridge/onboard.d.ts +7 -5
- package/lib-es/bridge/onboard.d.ts.map +1 -1
- package/lib-es/bridge/onboard.integ.test.js +14 -11
- package/lib-es/bridge/onboard.integ.test.js.map +1 -1
- package/lib-es/bridge/onboard.js +107 -42
- package/lib-es/bridge/onboard.js.map +1 -1
- package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib-es/bridge/prepareTransaction.js +6 -8
- package/lib-es/bridge/prepareTransaction.js.map +1 -1
- package/lib-es/bridge/serialization.d.ts +4 -0
- package/lib-es/bridge/serialization.d.ts.map +1 -0
- package/lib-es/bridge/serialization.js +27 -0
- package/lib-es/bridge/serialization.js.map +1 -0
- package/lib-es/bridge/signOperation.d.ts.map +1 -1
- package/lib-es/bridge/signOperation.js +15 -12
- package/lib-es/bridge/signOperation.js.map +1 -1
- package/lib-es/bridge/sync.d.ts +2 -1
- package/lib-es/bridge/sync.d.ts.map +1 -1
- package/lib-es/bridge/sync.integ.test.d.ts +2 -0
- package/lib-es/bridge/sync.integ.test.d.ts.map +1 -0
- package/lib-es/bridge/sync.integ.test.js +137 -0
- package/lib-es/bridge/sync.integ.test.js.map +1 -0
- package/lib-es/bridge/sync.js +51 -28
- package/lib-es/bridge/sync.js.map +1 -1
- package/lib-es/bridge/updateTransaction.d.ts.map +1 -1
- package/lib-es/bridge/updateTransaction.js +0 -4
- package/lib-es/bridge/updateTransaction.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 +5 -4
- package/lib-es/common-logic/transaction/broadcast.js.map +1 -1
- package/lib-es/common-logic/transaction/broadcast.test.js +8 -5
- package/lib-es/common-logic/transaction/broadcast.test.js.map +1 -1
- package/lib-es/common-logic/transaction/combine.d.ts +1 -1
- package/lib-es/common-logic/transaction/combine.d.ts.map +1 -1
- package/lib-es/common-logic/transaction/combine.js +2 -3
- package/lib-es/common-logic/transaction/combine.js.map +1 -1
- package/lib-es/common-logic/transaction/combine.test.js +3 -13
- package/lib-es/common-logic/transaction/combine.test.js.map +1 -1
- package/lib-es/common-logic/transaction/craftTransaction.d.ts +8 -4
- package/lib-es/common-logic/transaction/craftTransaction.d.ts.map +1 -1
- package/lib-es/common-logic/transaction/craftTransaction.js +15 -12
- 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 +4 -3
- package/lib-es/common-logic/transaction/estimateFees.js.map +1 -1
- package/lib-es/config.d.ts +1 -0
- package/lib-es/config.d.ts.map +1 -1
- package/lib-es/config.js.map +1 -1
- package/lib-es/network/gateway.d.ts +41 -17
- package/lib-es/network/gateway.d.ts.map +1 -1
- package/lib-es/network/gateway.integ.test.js +19 -15
- package/lib-es/network/gateway.integ.test.js.map +1 -1
- package/lib-es/network/gateway.js +73 -48
- package/lib-es/network/gateway.js.map +1 -1
- package/lib-es/network/node.d.ts +2 -2
- package/lib-es/network/node.d.ts.map +1 -1
- package/lib-es/network/node.js.map +1 -1
- package/lib-es/network/types.d.ts +1 -1
- package/lib-es/network/types.d.ts.map +1 -1
- package/lib-es/signer/getAddress.d.ts.map +1 -1
- package/lib-es/signer/getAddress.js +2 -2
- package/lib-es/signer/getAddress.js.map +1 -1
- package/lib-es/types/bridge.d.ts +18 -3
- package/lib-es/types/bridge.d.ts.map +1 -1
- package/lib-es/types/index.d.ts +0 -10
- package/lib-es/types/index.d.ts.map +1 -1
- package/lib-es/types/onboard.d.ts +2 -0
- package/lib-es/types/onboard.d.ts.map +1 -1
- package/lib-es/types/onboard.js.map +1 -1
- package/lib-es/types/signer.d.ts +2 -1
- package/lib-es/types/signer.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/api/getBalance.integ.test.ts +9 -6
- package/src/api/index.ts +22 -44
- 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 +4 -2
- package/src/bridge/createTransaction.ts +1 -1
- package/src/bridge/getTransactionStatus.ts +1 -1
- package/src/bridge/index.ts +3 -0
- package/src/bridge/onboard.integ.test.ts +25 -13
- package/src/bridge/onboard.ts +143 -51
- package/src/bridge/prepareTransaction.ts +6 -15
- package/src/bridge/serialization.ts +36 -0
- package/src/bridge/signOperation.ts +26 -20
- package/src/bridge/sync.integ.test.ts +180 -0
- package/src/bridge/sync.ts +61 -33
- package/src/bridge/updateTransaction.ts +0 -5
- 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 +10 -5
- package/src/common-logic/transaction/broadcast.ts +7 -3
- package/src/common-logic/transaction/combine.test.ts +3 -13
- package/src/common-logic/transaction/combine.ts +2 -4
- package/src/common-logic/transaction/craftTransaction.ts +30 -15
- package/src/common-logic/transaction/estimateFees.ts +8 -3
- package/src/config.ts +1 -0
- package/src/network/gateway.integ.test.ts +31 -12
- package/src/network/gateway.ts +141 -62
- package/src/network/node.ts +3 -3
- package/src/network/types.ts +1 -1
- package/src/signer/getAddress.ts +6 -4
- package/src/types/bridge.ts +21 -0
- package/src/types/index.ts +0 -11
- package/src/types/onboard.ts +3 -0
- package/src/types/signer.ts +2 -1
package/src/network/gateway.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
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";
|
|
3
5
|
import {
|
|
4
6
|
PrepareTransactionRequest,
|
|
@@ -7,6 +9,7 @@ import {
|
|
|
7
9
|
SubmitTransactionResponse,
|
|
8
10
|
PreApprovalResult,
|
|
9
11
|
} from "../types/onboard";
|
|
12
|
+
import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
10
13
|
|
|
11
14
|
type OnboardingPrepareResponse = {
|
|
12
15
|
party_id: string;
|
|
@@ -37,6 +40,21 @@ type OnboardingPrepareRequest = {
|
|
|
37
40
|
public_key_type: string;
|
|
38
41
|
};
|
|
39
42
|
|
|
43
|
+
export type PrepareTransferResponse = {
|
|
44
|
+
hash: string;
|
|
45
|
+
json: any; // The actual structure is complex, using any for now
|
|
46
|
+
serialized: string;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export type PrepareTransferRequest = {
|
|
50
|
+
type: "token-transfer-request";
|
|
51
|
+
amount: string;
|
|
52
|
+
recipient: string;
|
|
53
|
+
execute_before_secs: number;
|
|
54
|
+
instrument_id: string;
|
|
55
|
+
reason?: string;
|
|
56
|
+
};
|
|
57
|
+
|
|
40
58
|
type OnboardingSubmitRequest = {
|
|
41
59
|
prepare_request: OnboardingPrepareRequest;
|
|
42
60
|
prepare_response: OnboardingPrepareResponse;
|
|
@@ -55,7 +73,7 @@ type TransactionSubmitRequest = {
|
|
|
55
73
|
signature: string;
|
|
56
74
|
};
|
|
57
75
|
|
|
58
|
-
type TransactionSubmitResponse = {
|
|
76
|
+
type TransactionSubmitResponse = { update_id: string };
|
|
59
77
|
|
|
60
78
|
export type InstrumentBalance = {
|
|
61
79
|
instrument_id: string;
|
|
@@ -134,6 +152,9 @@ export type OperationInfo =
|
|
|
134
152
|
asset: string;
|
|
135
153
|
details: {
|
|
136
154
|
type: "pre-approval";
|
|
155
|
+
metadata: {
|
|
156
|
+
reason?: string;
|
|
157
|
+
};
|
|
137
158
|
};
|
|
138
159
|
},
|
|
139
160
|
];
|
|
@@ -176,6 +197,9 @@ export type OperationInfo =
|
|
|
176
197
|
asset: string;
|
|
177
198
|
details: {
|
|
178
199
|
type: "tap";
|
|
200
|
+
metadata: {
|
|
201
|
+
reason?: string;
|
|
202
|
+
};
|
|
179
203
|
};
|
|
180
204
|
},
|
|
181
205
|
];
|
|
@@ -218,6 +242,9 @@ export type OperationInfo =
|
|
|
218
242
|
asset: string;
|
|
219
243
|
details: {
|
|
220
244
|
type: "transfer";
|
|
245
|
+
metadata: {
|
|
246
|
+
reason?: string;
|
|
247
|
+
};
|
|
221
248
|
};
|
|
222
249
|
},
|
|
223
250
|
];
|
|
@@ -245,84 +272,114 @@ export type OperationInfo =
|
|
|
245
272
|
};
|
|
246
273
|
};
|
|
247
274
|
|
|
248
|
-
const getGatewayUrl = () => coinConfig.getCoinConfig().gatewayUrl;
|
|
249
|
-
const getNodeId = () =>
|
|
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;
|
|
279
|
+
|
|
280
|
+
const gatewayNetwork = <T, U = unknown>(req: LiveNetworkRequest<U>) => {
|
|
281
|
+
const API_KEY = getEnv("CANTON_API_KEY");
|
|
282
|
+
return network<T, U>({
|
|
283
|
+
...req,
|
|
284
|
+
headers: {
|
|
285
|
+
...(req.headers || {}),
|
|
286
|
+
...(API_KEY && { "X-Ledger-Canton-Api-Key": API_KEY }),
|
|
287
|
+
},
|
|
288
|
+
});
|
|
289
|
+
};
|
|
250
290
|
|
|
251
291
|
export async function prepareOnboarding(
|
|
292
|
+
currency: CryptoCurrency,
|
|
252
293
|
pubKey: string,
|
|
253
294
|
pubKeyType: string,
|
|
254
295
|
): Promise<OnboardingPrepareResponse> {
|
|
255
|
-
const gatewayUrl = getGatewayUrl();
|
|
256
|
-
const nodeId = getNodeId();
|
|
296
|
+
const gatewayUrl = getGatewayUrl(currency);
|
|
297
|
+
const nodeId = getNodeId(currency);
|
|
257
298
|
const fullUrl = `${gatewayUrl}/v1/node/${nodeId}/onboarding/prepare`;
|
|
258
299
|
|
|
259
|
-
const { data } = await
|
|
300
|
+
const { data } = await gatewayNetwork<OnboardingPrepareResponse, OnboardingPrepareRequest>({
|
|
260
301
|
method: "POST",
|
|
261
302
|
url: fullUrl,
|
|
262
303
|
data: {
|
|
263
304
|
public_key: pubKey,
|
|
264
305
|
public_key_type: pubKeyType,
|
|
265
|
-
}
|
|
306
|
+
},
|
|
266
307
|
});
|
|
267
308
|
|
|
268
309
|
return data;
|
|
269
310
|
}
|
|
270
311
|
|
|
271
312
|
export async function submitOnboarding(
|
|
313
|
+
currency: CryptoCurrency,
|
|
272
314
|
prepareRequest: OnboardingPrepareRequest,
|
|
273
315
|
prepareResponse: OnboardingPrepareResponse,
|
|
274
316
|
signature: string,
|
|
275
317
|
) {
|
|
276
|
-
const { data } = await
|
|
318
|
+
const { data } = await gatewayNetwork<OnboardingSubmitResponse, OnboardingSubmitRequest>({
|
|
277
319
|
method: "POST",
|
|
278
|
-
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/onboarding/submit`,
|
|
320
|
+
url: `${getGatewayUrl(currency)}/v1/node/${getNodeId(currency)}/onboarding/submit`,
|
|
279
321
|
data: {
|
|
280
322
|
prepare_request: prepareRequest,
|
|
281
323
|
prepare_response: prepareResponse,
|
|
282
324
|
signature,
|
|
283
|
-
}
|
|
325
|
+
},
|
|
284
326
|
});
|
|
285
327
|
return data;
|
|
286
328
|
}
|
|
287
329
|
|
|
288
|
-
export async function submit(
|
|
289
|
-
|
|
330
|
+
export async function submit(
|
|
331
|
+
currency: CryptoCurrency,
|
|
332
|
+
partyId: string,
|
|
333
|
+
serialized: string,
|
|
334
|
+
signature: string,
|
|
335
|
+
) {
|
|
336
|
+
const { data } = await gatewayNetwork<TransactionSubmitResponse, TransactionSubmitRequest>({
|
|
290
337
|
method: "POST",
|
|
291
|
-
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/transaction/submit`,
|
|
338
|
+
url: `${getGatewayUrl(currency)}/v1/node/${getNodeId(currency)}/party/${partyId}/transaction/submit`,
|
|
292
339
|
data: {
|
|
293
|
-
serialized
|
|
340
|
+
serialized,
|
|
294
341
|
signature,
|
|
295
|
-
}
|
|
342
|
+
},
|
|
296
343
|
});
|
|
297
344
|
return data;
|
|
298
345
|
}
|
|
299
346
|
|
|
300
|
-
export async function getBalance(
|
|
301
|
-
|
|
347
|
+
export async function getBalance(
|
|
348
|
+
currency: CryptoCurrency,
|
|
349
|
+
partyId: string,
|
|
350
|
+
): Promise<InstrumentBalance[]> {
|
|
351
|
+
const { data } = await gatewayNetwork<InstrumentBalance[]>({
|
|
302
352
|
method: "GET",
|
|
303
|
-
|
|
304
|
-
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId.replace(/_/g, ":")}/balance`,
|
|
353
|
+
url: `${getGatewayUrl(currency)}/v1/node/${getNodeId(currency)}/party/${partyId}/balance`,
|
|
305
354
|
});
|
|
306
355
|
return data;
|
|
307
356
|
}
|
|
308
357
|
|
|
309
|
-
export async function getPartyById(partyId: string): Promise<PartyInfo> {
|
|
310
|
-
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");
|
|
311
360
|
}
|
|
312
361
|
|
|
313
|
-
export async function getPartyByPubKey(
|
|
314
|
-
|
|
362
|
+
export async function getPartyByPubKey(
|
|
363
|
+
currency: CryptoCurrency,
|
|
364
|
+
pubKey: string,
|
|
365
|
+
): Promise<PartyInfo> {
|
|
366
|
+
return await getParty(currency, pubKey, "public-key");
|
|
315
367
|
}
|
|
316
368
|
|
|
317
|
-
async function getParty(
|
|
318
|
-
|
|
369
|
+
async function getParty(
|
|
370
|
+
currency: CryptoCurrency,
|
|
371
|
+
identifier: string,
|
|
372
|
+
by: "party-id" | "public-key",
|
|
373
|
+
): Promise<PartyInfo> {
|
|
374
|
+
const { data } = await gatewayNetwork<PartyInfo>({
|
|
319
375
|
method: "GET",
|
|
320
|
-
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${identifier}?by=${by}`,
|
|
376
|
+
url: `${getGatewayUrl(currency)}/v1/node/${getNodeId(currency)}/party/${identifier}?by=${by}`,
|
|
321
377
|
});
|
|
322
378
|
return data;
|
|
323
379
|
}
|
|
324
380
|
|
|
325
381
|
export async function getOperations(
|
|
382
|
+
currency: CryptoCurrency,
|
|
326
383
|
partyId: string,
|
|
327
384
|
options?: {
|
|
328
385
|
cursor?: number | undefined;
|
|
@@ -334,26 +391,26 @@ export async function getOperations(
|
|
|
334
391
|
next: number;
|
|
335
392
|
operations: OperationInfo[];
|
|
336
393
|
}> {
|
|
337
|
-
const { data } = await
|
|
394
|
+
const { data } = await gatewayNetwork<{
|
|
338
395
|
next: number;
|
|
339
396
|
operations: OperationInfo[];
|
|
340
397
|
}>({
|
|
341
398
|
method: "GET",
|
|
342
|
-
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId
|
|
343
|
-
|
|
399
|
+
url: `${getGatewayUrl(currency)}/v1/node/${getNodeId(currency)}/party/${partyId}/operations`,
|
|
400
|
+
params: options,
|
|
344
401
|
});
|
|
345
402
|
return data;
|
|
346
403
|
}
|
|
347
404
|
|
|
348
|
-
type
|
|
405
|
+
type PrepareTapRequest = {
|
|
349
406
|
partyId: string;
|
|
350
407
|
amount?: number;
|
|
351
408
|
};
|
|
352
409
|
|
|
353
|
-
type
|
|
354
|
-
serialized:
|
|
410
|
+
type PrepareTapResponse = {
|
|
411
|
+
serialized: string;
|
|
355
412
|
json: null;
|
|
356
|
-
hash:
|
|
413
|
+
hash: string;
|
|
357
414
|
};
|
|
358
415
|
|
|
359
416
|
enum TransactionType {
|
|
@@ -361,13 +418,20 @@ enum TransactionType {
|
|
|
361
418
|
TRANSFER_PRE_APPROVAL_PROPOSAL = "transfer-pre-approval-proposal",
|
|
362
419
|
}
|
|
363
420
|
|
|
364
|
-
export async function prepareTapRequest(
|
|
365
|
-
|
|
366
|
-
amount = 1000000,
|
|
367
|
-
|
|
368
|
-
|
|
421
|
+
export async function prepareTapRequest(
|
|
422
|
+
currency: CryptoCurrency,
|
|
423
|
+
{ partyId, amount = 1000000 }: PrepareTapRequest,
|
|
424
|
+
): Promise<PrepareTapResponse> {
|
|
425
|
+
if (getNetworkType(currency) === "mainnet") {
|
|
426
|
+
return {
|
|
427
|
+
serialized: "",
|
|
428
|
+
json: null,
|
|
429
|
+
hash: "",
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
const { data } = await gatewayNetwork<PrepareTapResponse, { amount: number; type: string }>({
|
|
369
433
|
method: "POST",
|
|
370
|
-
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/transaction/prepare`,
|
|
434
|
+
url: `${getGatewayUrl(currency)}/v1/node/${getNodeId(currency)}/party/${partyId}/transaction/prepare`,
|
|
371
435
|
data: {
|
|
372
436
|
amount: parseInt(amount.toString(), 10), // Convert to integer to avoid scientific notation
|
|
373
437
|
type: TransactionType.TAP_REQUEST,
|
|
@@ -387,58 +451,73 @@ type SubmitTapRequestResponse = {
|
|
|
387
451
|
update_id: string;
|
|
388
452
|
};
|
|
389
453
|
|
|
390
|
-
export async function submitTapRequest(
|
|
391
|
-
|
|
392
|
-
serialized,
|
|
393
|
-
|
|
394
|
-
}
|
|
395
|
-
|
|
454
|
+
export async function submitTapRequest(
|
|
455
|
+
currency: CryptoCurrency,
|
|
456
|
+
{ partyId, serialized, signature }: SubmitTapRequestRequest,
|
|
457
|
+
): Promise<SubmitTapRequestResponse> {
|
|
458
|
+
const { data } = await gatewayNetwork<
|
|
459
|
+
SubmitTapRequestResponse,
|
|
460
|
+
Omit<SubmitTapRequestRequest, "partyId">
|
|
461
|
+
>({
|
|
396
462
|
method: "POST",
|
|
397
|
-
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/transaction/submit`,
|
|
463
|
+
url: `${getGatewayUrl(currency)}/v1/node/${getNodeId(currency)}/party/${partyId}/transaction/submit`,
|
|
398
464
|
data: {
|
|
399
465
|
serialized,
|
|
400
466
|
signature,
|
|
401
|
-
}
|
|
467
|
+
},
|
|
402
468
|
});
|
|
403
469
|
return data;
|
|
404
470
|
}
|
|
405
471
|
|
|
406
|
-
export async function
|
|
407
|
-
|
|
472
|
+
export async function prepareTransferRequest(
|
|
473
|
+
currency: CryptoCurrency,
|
|
474
|
+
partyId: string,
|
|
475
|
+
params: PrepareTransferRequest,
|
|
476
|
+
): Promise<PrepareTransferResponse> {
|
|
477
|
+
const { data } = await gatewayNetwork<PrepareTransferResponse, PrepareTransferRequest>({
|
|
478
|
+
method: "POST",
|
|
479
|
+
url: `${getGatewayUrl(currency)}/v1/node/${getNodeId(currency)}/party/${partyId}/transaction/prepare`,
|
|
480
|
+
data: params,
|
|
481
|
+
});
|
|
482
|
+
return data;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
export async function getLedgerEnd(currency: CryptoCurrency): Promise<number> {
|
|
486
|
+
const { data } = await gatewayNetwork<number>({
|
|
408
487
|
method: "GET",
|
|
409
|
-
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/ledger-end`,
|
|
488
|
+
url: `${getGatewayUrl(currency)}/v1/node/${getNodeId(currency)}/ledger-end`,
|
|
410
489
|
});
|
|
411
490
|
return data;
|
|
412
491
|
}
|
|
413
492
|
|
|
414
493
|
export async function preparePreApprovalTransaction(
|
|
494
|
+
currency: CryptoCurrency,
|
|
415
495
|
partyId: string,
|
|
416
496
|
): Promise<PrepareTransactionResponse> {
|
|
417
|
-
const { data } = await
|
|
497
|
+
const { data } = await gatewayNetwork<PrepareTransactionResponse, PrepareTransactionRequest>({
|
|
418
498
|
method: "POST",
|
|
419
|
-
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/transaction/prepare`,
|
|
499
|
+
url: `${getGatewayUrl(currency)}/v1/node/${getNodeId(currency)}/party/${partyId}/transaction/prepare`,
|
|
420
500
|
data: {
|
|
421
501
|
type: TransactionType.TRANSFER_PRE_APPROVAL_PROPOSAL,
|
|
422
502
|
receiver: partyId,
|
|
423
|
-
}
|
|
503
|
+
},
|
|
424
504
|
});
|
|
425
505
|
return data;
|
|
426
506
|
}
|
|
427
507
|
|
|
428
508
|
export async function submitPreApprovalTransaction(
|
|
509
|
+
currency: CryptoCurrency,
|
|
429
510
|
partyId: string,
|
|
430
|
-
|
|
511
|
+
{ serialized }: PrepareTransactionResponse,
|
|
431
512
|
signature: string,
|
|
432
513
|
): Promise<PreApprovalResult> {
|
|
433
|
-
const
|
|
434
|
-
serialized: preparedTransaction.serialized,
|
|
435
|
-
signature,
|
|
436
|
-
};
|
|
437
|
-
|
|
438
|
-
const { data } = await network<SubmitTransactionResponse>({
|
|
514
|
+
const { data } = await gatewayNetwork<SubmitTransactionResponse, SubmitTransactionRequest>({
|
|
439
515
|
method: "POST",
|
|
440
|
-
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/transaction/submit`,
|
|
441
|
-
data:
|
|
516
|
+
url: `${getGatewayUrl(currency)}/v1/node/${getNodeId(currency)}/party/${partyId}/transaction/submit`,
|
|
517
|
+
data: {
|
|
518
|
+
serialized,
|
|
519
|
+
signature,
|
|
520
|
+
},
|
|
442
521
|
});
|
|
443
522
|
|
|
444
523
|
return {
|
package/src/network/node.ts
CHANGED
|
@@ -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,
|
|
6
|
+
import { AccountInfoResponse, SubmitResponse } 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<
|
|
89
|
+
export const submit = async (signedTx: string): Promise<SubmitResponse> => {
|
|
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<
|
|
92
|
+
const { data } = await network<SubmitResponse>({
|
|
93
93
|
url,
|
|
94
94
|
method: "GET",
|
|
95
95
|
});
|
package/src/network/types.ts
CHANGED
package/src/signer/getAddress.ts
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
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 } from "../types";
|
|
4
|
+
import { CantonSigner, CantonAddress } from "../types";
|
|
5
5
|
|
|
6
6
|
const getAddress = (signerContext: SignerContext<CantonSigner>): GetAddressFn => {
|
|
7
|
-
return async (deviceId: string, { path }: GetAddressOptions) => {
|
|
8
|
-
const { address, publicKey } = await signerContext(deviceId, signer =>
|
|
7
|
+
return async (deviceId: string, { path, verify }: GetAddressOptions) => {
|
|
8
|
+
const { address, publicKey } = await signerContext(deviceId, signer =>
|
|
9
|
+
signer.getAddress(path, verify),
|
|
10
|
+
);
|
|
9
11
|
|
|
10
12
|
return {
|
|
11
13
|
path,
|
|
12
14
|
address,
|
|
13
15
|
publicKey,
|
|
14
|
-
};
|
|
16
|
+
} satisfies CantonAddress;
|
|
15
17
|
};
|
|
16
18
|
};
|
|
17
19
|
|
package/src/types/bridge.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { BigNumber } from "bignumber.js";
|
|
2
2
|
import type { Observable } from "rxjs";
|
|
3
3
|
import type {
|
|
4
|
+
Account,
|
|
5
|
+
AccountRaw,
|
|
4
6
|
CurrencyBridge,
|
|
5
7
|
TransactionCommon,
|
|
6
8
|
TransactionCommonRaw,
|
|
@@ -13,13 +15,16 @@ import type {
|
|
|
13
15
|
CantonPreApprovalProgress,
|
|
14
16
|
CantonPreApprovalResult,
|
|
15
17
|
} from "./onboard";
|
|
18
|
+
import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
16
19
|
|
|
17
20
|
export interface CantonCurrencyBridge extends CurrencyBridge {
|
|
18
21
|
onboardAccount: (
|
|
22
|
+
currency: CryptoCurrency,
|
|
19
23
|
deviceId: string,
|
|
20
24
|
derivationPath: string,
|
|
21
25
|
) => Observable<CantonOnboardProgress | CantonOnboardResult>;
|
|
22
26
|
authorizePreapproval: (
|
|
27
|
+
currency: CryptoCurrency,
|
|
23
28
|
deviceId: string,
|
|
24
29
|
derivationPath: string,
|
|
25
30
|
partyId: string,
|
|
@@ -41,12 +46,28 @@ export type NetworkInfoRaw = {
|
|
|
41
46
|
export type Transaction = TransactionCommon & {
|
|
42
47
|
family: "canton";
|
|
43
48
|
fee: BigNumber | null | undefined;
|
|
49
|
+
memo?: string;
|
|
44
50
|
};
|
|
45
51
|
|
|
46
52
|
export type TransactionRaw = TransactionCommonRaw & {
|
|
47
53
|
family: "canton";
|
|
48
54
|
fee: string | null | undefined;
|
|
55
|
+
memo?: string;
|
|
49
56
|
};
|
|
50
57
|
|
|
51
58
|
export type TransactionStatus = TransactionStatusCommon;
|
|
52
59
|
export type TransactionStatusRaw = TransactionStatusCommonRaw;
|
|
60
|
+
|
|
61
|
+
export type CantonResources = {
|
|
62
|
+
partyId: string;
|
|
63
|
+
};
|
|
64
|
+
export type CantonResourcesRaw = {
|
|
65
|
+
partyId: string;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export type CantonAccount = Account & {
|
|
69
|
+
cantonResources?: CantonResources;
|
|
70
|
+
};
|
|
71
|
+
export type CantonAccountRaw = AccountRaw & {
|
|
72
|
+
cantonResources: CantonResourcesRaw;
|
|
73
|
+
};
|
package/src/types/index.ts
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
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
|
-
};
|
package/src/types/onboard.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Account } from "@ledgerhq/types-live";
|
|
2
|
+
|
|
1
3
|
export enum OnboardStatus {
|
|
2
4
|
INIT,
|
|
3
5
|
PREPARE,
|
|
@@ -22,6 +24,7 @@ export type CantonOnboardProgress = {
|
|
|
22
24
|
|
|
23
25
|
export type CantonOnboardResult = {
|
|
24
26
|
partyId: string;
|
|
27
|
+
account: Partial<Account>;
|
|
25
28
|
};
|
|
26
29
|
|
|
27
30
|
export type CantonPreApprovalProgress = {
|
package/src/types/signer.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
export type CantonAddress = {
|
|
2
2
|
publicKey: string;
|
|
3
3
|
address: string;
|
|
4
|
+
path: string; // TODO: check if necessary
|
|
4
5
|
};
|
|
5
6
|
|
|
6
7
|
export type CantonSignature = string; // `0x${string}`
|
|
7
8
|
|
|
8
9
|
export interface CantonSigner {
|
|
9
|
-
getAddress(path: string): Promise<CantonAddress>;
|
|
10
|
+
getAddress(path: string, display?: boolean): Promise<CantonAddress>;
|
|
10
11
|
signTransaction(path: string, rawTx: string): Promise<CantonSignature>;
|
|
11
12
|
}
|