@ledgerhq/coin-canton 0.5.0-nightly.3 → 0.5.0-nightly.4
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 +12 -0
- package/lib/api/getBalance.integ.test.js +7 -3
- package/lib/api/getBalance.integ.test.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 +4 -3
- package/lib/bridge/onboard.d.ts.map +1 -1
- package/lib/bridge/onboard.integ.test.js +2 -2
- package/lib/bridge/onboard.integ.test.js.map +1 -1
- package/lib/bridge/onboard.js +95 -35
- package/lib/bridge/onboard.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/sync.d.ts +2 -1
- package/lib/bridge/sync.d.ts.map +1 -1
- package/lib/bridge/sync.integ.test.js +2 -2
- package/lib/bridge/sync.integ.test.js.map +1 -1
- package/lib/bridge/sync.js +20 -12
- package/lib/bridge/sync.js.map +1 -1
- package/lib/common-logic/transaction/estimateFees.d.ts.map +1 -1
- package/lib/common-logic/transaction/estimateFees.js +6 -1
- 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 +5 -13
- package/lib/network/gateway.d.ts.map +1 -1
- package/lib/network/gateway.integ.test.js +2 -1
- package/lib/network/gateway.integ.test.js.map +1 -1
- package/lib/network/gateway.js +11 -4
- package/lib/network/gateway.js.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 +13 -1
- package/lib/types/bridge.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 +7 -3
- package/lib-es/api/getBalance.integ.test.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 +4 -3
- package/lib-es/bridge/onboard.d.ts.map +1 -1
- package/lib-es/bridge/onboard.integ.test.js +2 -2
- package/lib-es/bridge/onboard.integ.test.js.map +1 -1
- package/lib-es/bridge/onboard.js +92 -35
- package/lib-es/bridge/onboard.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/sync.d.ts +2 -1
- package/lib-es/bridge/sync.d.ts.map +1 -1
- package/lib-es/bridge/sync.integ.test.js +2 -2
- package/lib-es/bridge/sync.integ.test.js.map +1 -1
- package/lib-es/bridge/sync.js +21 -13
- package/lib-es/bridge/sync.js.map +1 -1
- package/lib-es/common-logic/transaction/estimateFees.d.ts.map +1 -1
- package/lib-es/common-logic/transaction/estimateFees.js +3 -1
- 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 +5 -13
- package/lib-es/network/gateway.d.ts.map +1 -1
- package/lib-es/network/gateway.integ.test.js +2 -1
- package/lib-es/network/gateway.integ.test.js.map +1 -1
- package/lib-es/network/gateway.js +11 -4
- package/lib-es/network/gateway.js.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 +13 -1
- package/lib-es/types/bridge.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 +3 -3
- package/src/api/getBalance.integ.test.ts +7 -3
- package/src/bridge/index.ts +3 -0
- package/src/bridge/onboard.integ.test.ts +2 -2
- package/src/bridge/onboard.ts +120 -47
- package/src/bridge/serialization.ts +36 -0
- package/src/bridge/sync.integ.test.ts +2 -2
- package/src/bridge/sync.ts +27 -19
- package/src/common-logic/transaction/estimateFees.ts +5 -1
- package/src/config.ts +1 -0
- package/src/network/gateway.integ.test.ts +2 -1
- package/src/network/gateway.ts +17 -23
- package/src/signer/getAddress.ts +6 -4
- package/src/types/bridge.ts +16 -0
- package/src/types/onboard.ts +3 -0
- package/src/types/signer.ts +2 -1
package/src/bridge/sync.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import BigNumber from "bignumber.js";
|
|
2
2
|
import { Operation } from "@ledgerhq/types-live";
|
|
3
|
-
import { encodeAccountId } from "@ledgerhq/coin-framework/account/index";
|
|
3
|
+
import { decodeAccountId, encodeAccountId } from "@ledgerhq/coin-framework/account/index";
|
|
4
4
|
import { GetAccountShape, mergeOps } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
5
|
-
import { getBalance, getLedgerEnd, getOperations, type OperationInfo } from "../network/gateway";
|
|
6
|
-
|
|
7
5
|
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
6
|
+
import { getBalance, getLedgerEnd, getOperations, type OperationInfo } from "../network/gateway";
|
|
7
|
+
import { CantonAccount } from "../types";
|
|
8
8
|
import coinConfig from "../config";
|
|
9
9
|
|
|
10
10
|
const txInfoToOperationAdapter =
|
|
11
|
-
(accountId: string,
|
|
11
|
+
(accountId: string, partyId: string) =>
|
|
12
12
|
(txInfo: OperationInfo): Operation => {
|
|
13
13
|
const {
|
|
14
14
|
transaction_hash,
|
|
@@ -20,7 +20,7 @@ const txInfoToOperationAdapter =
|
|
|
20
20
|
fee: { value: fee },
|
|
21
21
|
transfers: [{ value: transferValue }],
|
|
22
22
|
} = txInfo;
|
|
23
|
-
const type = senders.includes(
|
|
23
|
+
const type = senders.includes(partyId) ? "OUT" : "IN";
|
|
24
24
|
const value = new BigNumber(transferValue);
|
|
25
25
|
const feeValue = new BigNumber(fee);
|
|
26
26
|
|
|
@@ -48,24 +48,31 @@ const txInfoToOperationAdapter =
|
|
|
48
48
|
const filterOperations = (
|
|
49
49
|
transactions: OperationInfo[],
|
|
50
50
|
accountId: string,
|
|
51
|
-
|
|
51
|
+
partyId: string,
|
|
52
52
|
): Operation[] => {
|
|
53
53
|
return transactions
|
|
54
54
|
.filter(tx => tx.type === "Receive" || tx.type === "Send")
|
|
55
|
-
.map(txInfoToOperationAdapter(accountId,
|
|
55
|
+
.map(txInfoToOperationAdapter(accountId, partyId));
|
|
56
56
|
};
|
|
57
57
|
|
|
58
|
-
export const getAccountShape: GetAccountShape = async info => {
|
|
59
|
-
const { address, initialAccount, currency, derivationMode } = info;
|
|
60
|
-
|
|
61
|
-
const xpubOrAddress =
|
|
58
|
+
export const getAccountShape: GetAccountShape<CantonAccount> = async info => {
|
|
59
|
+
const { address, initialAccount, currency, derivationMode, derivationPath, rest } = info;
|
|
60
|
+
|
|
61
|
+
const xpubOrAddress = (
|
|
62
|
+
(initialAccount && initialAccount.id && decodeAccountId(initialAccount.id).xpubOrAddress) ||
|
|
63
|
+
""
|
|
64
|
+
).replace(/:/g, "_");
|
|
65
|
+
const partyId =
|
|
66
|
+
rest?.cantonResources?.partyId ||
|
|
67
|
+
initialAccount?.cantonResources?.partyId ||
|
|
68
|
+
xpubOrAddress.replace(/_/g, ":");
|
|
62
69
|
|
|
63
70
|
const accountId = encodeAccountId({
|
|
64
71
|
type: "js",
|
|
65
72
|
version: "2",
|
|
66
73
|
currencyId: currency.id,
|
|
67
74
|
xpubOrAddress,
|
|
68
|
-
derivationMode
|
|
75
|
+
derivationMode,
|
|
69
76
|
});
|
|
70
77
|
|
|
71
78
|
// blockheight retrieval
|
|
@@ -73,7 +80,7 @@ export const getAccountShape: GetAccountShape = async info => {
|
|
|
73
80
|
|
|
74
81
|
// Account info retrieval + spendable balance calculation
|
|
75
82
|
// const accountInfo = await getAccountInfo(address);
|
|
76
|
-
const balances = await getBalance(
|
|
83
|
+
const balances = await getBalance(partyId);
|
|
77
84
|
|
|
78
85
|
// TODO change to balance.instrument_id === "Amulet" after update on backend
|
|
79
86
|
const balanceData = balances.find(balance => balance.instrument_id.includes("Amulet")) || {
|
|
@@ -93,16 +100,12 @@ export const getAccountShape: GetAccountShape = async info => {
|
|
|
93
100
|
// Tx history fetching
|
|
94
101
|
const oldOperations = initialAccount?.operations || [];
|
|
95
102
|
const startAt = oldOperations.length ? (oldOperations[0].blockHeight || 0) + 1 : 0;
|
|
96
|
-
const transactionData = await getOperations(
|
|
103
|
+
const transactionData = await getOperations(partyId, {
|
|
97
104
|
cursor: startAt,
|
|
98
105
|
limit: 100,
|
|
99
106
|
});
|
|
100
107
|
|
|
101
|
-
const newOperations = filterOperations(
|
|
102
|
-
transactionData.operations,
|
|
103
|
-
accountId,
|
|
104
|
-
address.replace(/_/g, ":"),
|
|
105
|
-
);
|
|
108
|
+
const newOperations = filterOperations(transactionData.operations, accountId, partyId);
|
|
106
109
|
const operations = mergeOps(oldOperations, newOperations);
|
|
107
110
|
|
|
108
111
|
// We return the new account shape
|
|
@@ -114,6 +117,11 @@ export const getAccountShape: GetAccountShape = async info => {
|
|
|
114
117
|
spendableBalance,
|
|
115
118
|
operations,
|
|
116
119
|
operationsCount: operations.length,
|
|
120
|
+
freshAddress: address,
|
|
121
|
+
freshAddressPath: derivationPath,
|
|
122
|
+
cantonResources: {
|
|
123
|
+
partyId,
|
|
124
|
+
},
|
|
117
125
|
};
|
|
118
126
|
|
|
119
127
|
return shape;
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
import coinConfig from "../../config";
|
|
2
|
+
|
|
3
|
+
const feeValue = () => coinConfig.getCoinConfig().fee ?? 10_000;
|
|
4
|
+
|
|
1
5
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2
6
|
export async function estimateFees(serializedTransaction: string): Promise<bigint> {
|
|
3
|
-
return Promise.resolve(BigInt(
|
|
7
|
+
return Promise.resolve(BigInt(feeValue())); // TODO replace with real implementation
|
|
4
8
|
}
|
package/src/config.ts
CHANGED
|
@@ -58,7 +58,8 @@ describe("gateway (devnet)", () => {
|
|
|
58
58
|
expect(response).toHaveProperty("public_key_fingerprint");
|
|
59
59
|
expect(response).toHaveProperty("transactions");
|
|
60
60
|
expect(response.transactions).toHaveProperty("combined_hash");
|
|
61
|
-
expect(response.party_name).
|
|
61
|
+
expect(response.party_name).toBeDefined();
|
|
62
|
+
expect(typeof response.party_name).toBe("string");
|
|
62
63
|
|
|
63
64
|
expect(response.public_key_fingerprint).toBe(keyPair.fingerprint);
|
|
64
65
|
}, 30000);
|
package/src/network/gateway.ts
CHANGED
|
@@ -54,16 +54,6 @@ export type PrepareTransferRequest = {
|
|
|
54
54
|
reason?: string;
|
|
55
55
|
};
|
|
56
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
|
-
|
|
67
57
|
type OnboardingSubmitRequest = {
|
|
68
58
|
prepare_request: OnboardingPrepareRequest;
|
|
69
59
|
prepare_response: OnboardingPrepareResponse;
|
|
@@ -274,6 +264,7 @@ export type OperationInfo =
|
|
|
274
264
|
|
|
275
265
|
const getGatewayUrl = () => coinConfig.getCoinConfig().gatewayUrl;
|
|
276
266
|
const getNodeId = () => coinConfig.getCoinConfig().nodeId || "ledger-devnet-stg";
|
|
267
|
+
const getNetworkType = () => coinConfig.getCoinConfig().networkType;
|
|
277
268
|
|
|
278
269
|
const gatewayNetwork = <T, U = unknown>(req: LiveNetworkRequest<U>) => {
|
|
279
270
|
const API_KEY = getEnv("CANTON_API_KEY");
|
|
@@ -338,8 +329,7 @@ export async function submit(partyId: string, serialized: string, signature: str
|
|
|
338
329
|
export async function getBalance(partyId: string): Promise<InstrumentBalance[]> {
|
|
339
330
|
const { data } = await gatewayNetwork<InstrumentBalance[]>({
|
|
340
331
|
method: "GET",
|
|
341
|
-
|
|
342
|
-
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId.replace(/_/g, ":")}/balance`,
|
|
332
|
+
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/balance`,
|
|
343
333
|
});
|
|
344
334
|
return data;
|
|
345
335
|
}
|
|
@@ -377,21 +367,21 @@ export async function getOperations(
|
|
|
377
367
|
operations: OperationInfo[];
|
|
378
368
|
}>({
|
|
379
369
|
method: "GET",
|
|
380
|
-
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId
|
|
370
|
+
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/operations`,
|
|
381
371
|
params: options,
|
|
382
372
|
});
|
|
383
373
|
return data;
|
|
384
374
|
}
|
|
385
375
|
|
|
386
|
-
type
|
|
376
|
+
type PrepareTapRequest = {
|
|
387
377
|
partyId: string;
|
|
388
378
|
amount?: number;
|
|
389
379
|
};
|
|
390
380
|
|
|
391
|
-
type
|
|
392
|
-
serialized:
|
|
381
|
+
type PrepareTapResponse = {
|
|
382
|
+
serialized: string;
|
|
393
383
|
json: null;
|
|
394
|
-
hash:
|
|
384
|
+
hash: string;
|
|
395
385
|
};
|
|
396
386
|
|
|
397
387
|
enum TransactionType {
|
|
@@ -402,11 +392,15 @@ enum TransactionType {
|
|
|
402
392
|
export async function prepareTapRequest({
|
|
403
393
|
partyId,
|
|
404
394
|
amount = 1000000,
|
|
405
|
-
}:
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
395
|
+
}: PrepareTapRequest): Promise<PrepareTapResponse> {
|
|
396
|
+
if (getNetworkType() === "mainnet") {
|
|
397
|
+
return {
|
|
398
|
+
serialized: "",
|
|
399
|
+
json: null,
|
|
400
|
+
hash: "",
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
const { data } = await gatewayNetwork<PrepareTapResponse, { amount: number; type: string }>({
|
|
410
404
|
method: "POST",
|
|
411
405
|
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/transaction/prepare`,
|
|
412
406
|
data: {
|
|
@@ -451,7 +445,7 @@ export async function prepareTransferRequest(
|
|
|
451
445
|
partyId: string,
|
|
452
446
|
params: PrepareTransferRequest,
|
|
453
447
|
): Promise<PrepareTransferResponse> {
|
|
454
|
-
const { data } = await
|
|
448
|
+
const { data } = await gatewayNetwork<PrepareTransferResponse, PrepareTransferRequest>({
|
|
455
449
|
method: "POST",
|
|
456
450
|
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/transaction/prepare`,
|
|
457
451
|
data: params,
|
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,
|
|
@@ -50,3 +52,17 @@ export type TransactionRaw = TransactionCommonRaw & {
|
|
|
50
52
|
|
|
51
53
|
export type TransactionStatus = TransactionStatusCommon;
|
|
52
54
|
export type TransactionStatusRaw = TransactionStatusCommonRaw;
|
|
55
|
+
|
|
56
|
+
export type CantonResources = {
|
|
57
|
+
partyId: string;
|
|
58
|
+
};
|
|
59
|
+
export type CantonResourcesRaw = {
|
|
60
|
+
partyId: string;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export type CantonAccount = Account & {
|
|
64
|
+
cantonResources?: CantonResources;
|
|
65
|
+
};
|
|
66
|
+
export type CantonAccountRaw = AccountRaw & {
|
|
67
|
+
cantonResources: CantonResourcesRaw;
|
|
68
|
+
};
|
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
|
}
|