@ledgerhq/coin-canton 0.5.0-nightly.4 → 0.5.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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +36 -39
- package/lib/api/getBalance.integ.test.js +4 -8
- package/lib/api/getBalance.integ.test.js.map +1 -1
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +8 -11
- package/lib/api/index.js.map +1 -1
- package/lib/bridge/broadcast.d.ts.map +1 -1
- package/lib/bridge/broadcast.js +1 -2
- package/lib/bridge/broadcast.js.map +1 -1
- package/lib/bridge/index.d.ts.map +1 -1
- package/lib/bridge/index.js +0 -3
- package/lib/bridge/index.js.map +1 -1
- package/lib/bridge/onboard.d.ts +3 -4
- package/lib/bridge/onboard.d.ts.map +1 -1
- package/lib/bridge/onboard.integ.test.js +3 -3
- package/lib/bridge/onboard.integ.test.js.map +1 -1
- package/lib/bridge/onboard.js +35 -95
- package/lib/bridge/onboard.js.map +1 -1
- package/lib/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib/bridge/prepareTransaction.js +7 -5
- package/lib/bridge/prepareTransaction.js.map +1 -1
- package/lib/bridge/signOperation.d.ts.map +1 -1
- package/lib/bridge/signOperation.js +9 -7
- package/lib/bridge/signOperation.js.map +1 -1
- package/lib/bridge/sync.d.ts +1 -2
- package/lib/bridge/sync.d.ts.map +1 -1
- package/lib/bridge/sync.js +15 -30
- package/lib/bridge/sync.js.map +1 -1
- package/lib/bridge/updateTransaction.d.ts.map +1 -1
- package/lib/bridge/updateTransaction.js +4 -0
- package/lib/bridge/updateTransaction.js.map +1 -1
- package/lib/common-logic/transaction/broadcast.d.ts.map +1 -1
- package/lib/common-logic/transaction/broadcast.js +1 -2
- package/lib/common-logic/transaction/broadcast.js.map +1 -1
- package/lib/common-logic/transaction/broadcast.test.js +3 -3
- 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 +3 -2
- package/lib/common-logic/transaction/combine.js.map +1 -1
- package/lib/common-logic/transaction/combine.test.js +13 -3
- package/lib/common-logic/transaction/combine.test.js.map +1 -1
- package/lib/common-logic/transaction/craftTransaction.d.ts +3 -5
- package/lib/common-logic/transaction/craftTransaction.d.ts.map +1 -1
- package/lib/common-logic/transaction/craftTransaction.js +12 -11
- package/lib/common-logic/transaction/craftTransaction.js.map +1 -1
- package/lib/common-logic/transaction/estimateFees.d.ts.map +1 -1
- package/lib/common-logic/transaction/estimateFees.js +1 -6
- package/lib/common-logic/transaction/estimateFees.js.map +1 -1
- package/lib/config.d.ts +0 -1
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js.map +1 -1
- package/lib/network/gateway.d.ts +8 -22
- package/lib/network/gateway.d.ts.map +1 -1
- package/lib/network/gateway.integ.test.js +1 -2
- package/lib/network/gateway.integ.test.js.map +1 -1
- package/lib/network/gateway.js +24 -50
- 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 +1 -13
- package/lib/types/bridge.d.ts.map +1 -1
- package/lib/types/index.d.ts +10 -0
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/onboard.d.ts +0 -2
- package/lib/types/onboard.d.ts.map +1 -1
- package/lib/types/onboard.js.map +1 -1
- package/lib/types/signer.d.ts +1 -2
- package/lib/types/signer.d.ts.map +1 -1
- package/lib-es/api/getBalance.integ.test.js +4 -8
- 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 +9 -12
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/bridge/broadcast.d.ts.map +1 -1
- package/lib-es/bridge/broadcast.js +1 -2
- package/lib-es/bridge/broadcast.js.map +1 -1
- package/lib-es/bridge/index.d.ts.map +1 -1
- package/lib-es/bridge/index.js +0 -3
- package/lib-es/bridge/index.js.map +1 -1
- package/lib-es/bridge/onboard.d.ts +3 -4
- package/lib-es/bridge/onboard.d.ts.map +1 -1
- package/lib-es/bridge/onboard.integ.test.js +3 -3
- package/lib-es/bridge/onboard.integ.test.js.map +1 -1
- package/lib-es/bridge/onboard.js +35 -92
- 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 +8 -6
- 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 -8
- package/lib-es/bridge/signOperation.js.map +1 -1
- package/lib-es/bridge/sync.d.ts +1 -2
- package/lib-es/bridge/sync.d.ts.map +1 -1
- package/lib-es/bridge/sync.js +16 -31
- 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 +4 -0
- package/lib-es/bridge/updateTransaction.js.map +1 -1
- package/lib-es/common-logic/transaction/broadcast.d.ts.map +1 -1
- package/lib-es/common-logic/transaction/broadcast.js +1 -2
- package/lib-es/common-logic/transaction/broadcast.js.map +1 -1
- package/lib-es/common-logic/transaction/broadcast.test.js +3 -3
- 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 +3 -2
- package/lib-es/common-logic/transaction/combine.js.map +1 -1
- package/lib-es/common-logic/transaction/combine.test.js +13 -3
- package/lib-es/common-logic/transaction/combine.test.js.map +1 -1
- package/lib-es/common-logic/transaction/craftTransaction.d.ts +3 -5
- package/lib-es/common-logic/transaction/craftTransaction.d.ts.map +1 -1
- package/lib-es/common-logic/transaction/craftTransaction.js +12 -11
- package/lib-es/common-logic/transaction/craftTransaction.js.map +1 -1
- package/lib-es/common-logic/transaction/estimateFees.d.ts.map +1 -1
- package/lib-es/common-logic/transaction/estimateFees.js +1 -3
- package/lib-es/common-logic/transaction/estimateFees.js.map +1 -1
- package/lib-es/config.d.ts +0 -1
- package/lib-es/config.d.ts.map +1 -1
- package/lib-es/config.js.map +1 -1
- package/lib-es/network/gateway.d.ts +8 -22
- package/lib-es/network/gateway.d.ts.map +1 -1
- package/lib-es/network/gateway.integ.test.js +1 -2
- package/lib-es/network/gateway.integ.test.js.map +1 -1
- package/lib-es/network/gateway.js +24 -49
- 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 +1 -13
- package/lib-es/types/bridge.d.ts.map +1 -1
- package/lib-es/types/index.d.ts +10 -0
- package/lib-es/types/index.d.ts.map +1 -1
- package/lib-es/types/onboard.d.ts +0 -2
- 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 +1 -2
- package/lib-es/types/signer.d.ts.map +1 -1
- package/package.json +7 -7
- package/src/api/getBalance.integ.test.ts +5 -8
- package/src/api/index.ts +26 -33
- package/src/bridge/broadcast.ts +3 -2
- package/src/bridge/index.ts +0 -3
- package/src/bridge/onboard.integ.test.ts +3 -3
- package/src/bridge/onboard.ts +47 -120
- package/src/bridge/prepareTransaction.ts +15 -6
- package/src/bridge/signOperation.ts +16 -9
- package/src/bridge/sync.ts +19 -42
- package/src/bridge/updateTransaction.ts +5 -0
- package/src/common-logic/transaction/broadcast.test.ts +3 -3
- package/src/common-logic/transaction/broadcast.ts +1 -2
- package/src/common-logic/transaction/combine.test.ts +13 -3
- package/src/common-logic/transaction/combine.ts +4 -2
- package/src/common-logic/transaction/craftTransaction.ts +17 -15
- package/src/common-logic/transaction/estimateFees.ts +1 -5
- package/src/config.ts +0 -1
- package/src/network/gateway.integ.test.ts +1 -2
- package/src/network/gateway.ts +36 -84
- package/src/network/node.ts +3 -3
- package/src/network/types.ts +1 -1
- package/src/signer/getAddress.ts +4 -6
- package/src/types/bridge.ts +0 -16
- package/src/types/index.ts +11 -0
- package/src/types/onboard.ts +0 -3
- package/src/types/signer.ts +1 -2
- package/lib/bridge/serialization.d.ts +0 -4
- package/lib/bridge/serialization.d.ts.map +0 -1
- package/lib/bridge/serialization.js +0 -31
- package/lib/bridge/serialization.js.map +0 -1
- package/lib/bridge/sync.integ.test.d.ts +0 -2
- package/lib/bridge/sync.integ.test.d.ts.map +0 -1
- package/lib/bridge/sync.integ.test.js +0 -175
- package/lib/bridge/sync.integ.test.js.map +0 -1
- package/lib-es/bridge/serialization.d.ts +0 -4
- package/lib-es/bridge/serialization.d.ts.map +0 -1
- package/lib-es/bridge/serialization.js +0 -27
- package/lib-es/bridge/serialization.js.map +0 -1
- package/lib-es/bridge/sync.integ.test.d.ts +0 -2
- package/lib-es/bridge/sync.integ.test.d.ts.map +0 -1
- package/lib-es/bridge/sync.integ.test.js +0 -137
- package/lib-es/bridge/sync.integ.test.js.map +0 -1
- package/src/bridge/serialization.ts +0 -36
- package/src/bridge/sync.integ.test.ts +0 -180
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 {
|
|
3
|
+
import { encodeAccountId } from "@ledgerhq/coin-framework/account/index";
|
|
4
4
|
import { GetAccountShape, mergeOps } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
5
|
-
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
6
5
|
import { getBalance, getLedgerEnd, getOperations, type OperationInfo } from "../network/gateway";
|
|
7
|
-
|
|
6
|
+
|
|
7
|
+
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
8
8
|
import coinConfig from "../config";
|
|
9
9
|
|
|
10
10
|
const txInfoToOperationAdapter =
|
|
11
|
-
(accountId: string,
|
|
11
|
+
(accountId: string, address: string) =>
|
|
12
12
|
(txInfo: OperationInfo): Operation => {
|
|
13
13
|
const {
|
|
14
14
|
transaction_hash,
|
|
@@ -20,7 +20,8 @@ const txInfoToOperationAdapter =
|
|
|
20
20
|
fee: { value: fee },
|
|
21
21
|
transfers: [{ value: transferValue }],
|
|
22
22
|
} = txInfo;
|
|
23
|
-
|
|
23
|
+
|
|
24
|
+
const type = senders.includes(address) ? "OUT" : "IN";
|
|
24
25
|
const value = new BigNumber(transferValue);
|
|
25
26
|
const feeValue = new BigNumber(fee);
|
|
26
27
|
|
|
@@ -48,31 +49,24 @@ const txInfoToOperationAdapter =
|
|
|
48
49
|
const filterOperations = (
|
|
49
50
|
transactions: OperationInfo[],
|
|
50
51
|
accountId: string,
|
|
51
|
-
|
|
52
|
+
address: string,
|
|
52
53
|
): Operation[] => {
|
|
53
54
|
return transactions
|
|
54
55
|
.filter(tx => tx.type === "Receive" || tx.type === "Send")
|
|
55
|
-
.map(txInfoToOperationAdapter(accountId,
|
|
56
|
+
.map(txInfoToOperationAdapter(accountId, address));
|
|
56
57
|
};
|
|
57
58
|
|
|
58
|
-
export const getAccountShape: GetAccountShape
|
|
59
|
-
const { address, initialAccount, currency, derivationMode
|
|
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, ":");
|
|
59
|
+
export const getAccountShape: GetAccountShape = async info => {
|
|
60
|
+
const { address, initialAccount, currency, derivationMode } = info;
|
|
61
|
+
// TODO: we need better solution ?
|
|
62
|
+
const xpubOrAddress = address?.replace(/:/g, "_") || "";
|
|
69
63
|
|
|
70
64
|
const accountId = encodeAccountId({
|
|
71
65
|
type: "js",
|
|
72
66
|
version: "2",
|
|
73
67
|
currencyId: currency.id,
|
|
74
68
|
xpubOrAddress,
|
|
75
|
-
derivationMode,
|
|
69
|
+
derivationMode: "",
|
|
76
70
|
});
|
|
77
71
|
|
|
78
72
|
// blockheight retrieval
|
|
@@ -80,32 +74,20 @@ export const getAccountShape: GetAccountShape<CantonAccount> = async info => {
|
|
|
80
74
|
|
|
81
75
|
// Account info retrieval + spendable balance calculation
|
|
82
76
|
// const accountInfo = await getAccountInfo(address);
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
// TODO change to balance.instrument_id === "Amulet" after update on backend
|
|
86
|
-
const balanceData = balances.find(balance => balance.instrument_id.includes("Amulet")) || {
|
|
87
|
-
instrument_id: "Amulet",
|
|
88
|
-
amount: 0,
|
|
89
|
-
locked: false,
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
const balance = new BigNumber(balanceData.amount);
|
|
77
|
+
const balanceData = await getBalance(address);
|
|
78
|
+
const balance = new BigNumber(balanceData[0]?.amount || "0");
|
|
93
79
|
const reserveMin = coinConfig.getCoinConfig().minReserve || 0;
|
|
94
|
-
const
|
|
95
|
-
const spendableBalance = BigNumber.max(
|
|
96
|
-
0,
|
|
97
|
-
balance.minus(lockedAmount).minus(BigNumber(reserveMin)),
|
|
98
|
-
);
|
|
80
|
+
const spendableBalance = balance.minus(BigNumber(reserveMin));
|
|
99
81
|
|
|
100
82
|
// Tx history fetching
|
|
101
83
|
const oldOperations = initialAccount?.operations || [];
|
|
102
84
|
const startAt = oldOperations.length ? (oldOperations[0].blockHeight || 0) + 1 : 0;
|
|
103
|
-
const transactionData = await getOperations(
|
|
104
|
-
cursor:
|
|
85
|
+
const transactionData = await getOperations(address, {
|
|
86
|
+
cursor: 0,
|
|
105
87
|
limit: 100,
|
|
106
88
|
});
|
|
107
89
|
|
|
108
|
-
const newOperations = filterOperations(transactionData.operations, accountId,
|
|
90
|
+
const newOperations = filterOperations(transactionData.operations, accountId, address);
|
|
109
91
|
const operations = mergeOps(oldOperations, newOperations);
|
|
110
92
|
|
|
111
93
|
// We return the new account shape
|
|
@@ -117,11 +99,6 @@ export const getAccountShape: GetAccountShape<CantonAccount> = async info => {
|
|
|
117
99
|
spendableBalance,
|
|
118
100
|
operations,
|
|
119
101
|
operationsCount: operations.length,
|
|
120
|
-
freshAddress: address,
|
|
121
|
-
freshAddressPath: derivationPath,
|
|
122
|
-
cantonResources: {
|
|
123
|
-
partyId,
|
|
124
|
-
},
|
|
125
102
|
};
|
|
126
103
|
|
|
127
104
|
return shape;
|
|
@@ -8,5 +8,10 @@ import type { Transaction } from "../types";
|
|
|
8
8
|
// NOTE: here is an example transaction updater function
|
|
9
9
|
// in this case, it resets fee to null depending on the patch content
|
|
10
10
|
export const updateTransaction: AccountBridge<Transaction>["updateTransaction"] = (tx, patch) => {
|
|
11
|
+
// eslint-disable-next-line no-constant-condition
|
|
12
|
+
if (patch.recipient === "boilerplate1" || true) {
|
|
13
|
+
patch = { ...patch, fee: null };
|
|
14
|
+
}
|
|
15
|
+
|
|
11
16
|
return defaultUpdateTransaction(tx, patch);
|
|
12
17
|
};
|
|
@@ -8,7 +8,7 @@ jest.mock("../../network/gateway", () => ({
|
|
|
8
8
|
|
|
9
9
|
const mockSerialized = JSON.stringify({
|
|
10
10
|
serialized: "serialized-tx",
|
|
11
|
-
signature: "
|
|
11
|
+
signature: "signature",
|
|
12
12
|
});
|
|
13
13
|
|
|
14
14
|
describe("broadcast", () => {
|
|
@@ -23,11 +23,11 @@ describe("broadcast", () => {
|
|
|
23
23
|
useGateway: true,
|
|
24
24
|
} as any);
|
|
25
25
|
|
|
26
|
-
(submit as jest.Mock).mockResolvedValue({
|
|
26
|
+
(submit as jest.Mock).mockResolvedValue({ updateId: "my-update-id" });
|
|
27
27
|
|
|
28
28
|
const result = await broadcast(mockSerialized);
|
|
29
29
|
|
|
30
|
-
expect(submit).toHaveBeenCalledWith("
|
|
30
|
+
expect(submit).toHaveBeenCalledWith("serialized-tx", "signature");
|
|
31
31
|
expect(result).toEqual("my-update-id");
|
|
32
32
|
});
|
|
33
33
|
|
|
@@ -5,7 +5,6 @@ const useGateway = () => coinConfig.getCoinConfig().useGateway === true;
|
|
|
5
5
|
|
|
6
6
|
export async function broadcast(signedTx: string): Promise<string> {
|
|
7
7
|
const parsed: { serialized: string; signature: string } = JSON.parse(signedTx);
|
|
8
|
-
|
|
9
|
-
if (useGateway()) return (await submit(party, parsed.serialized, sig)).update_id;
|
|
8
|
+
if (useGateway()) return (await submit(parsed.serialized, parsed.signature)).updateId;
|
|
10
9
|
else throw new Error("Not implemented");
|
|
11
10
|
}
|
|
@@ -3,15 +3,25 @@ import { combine } from "./combine";
|
|
|
3
3
|
describe("combine", () => {
|
|
4
4
|
it("responds with a Stringify version of the payload to broadcast", () => {
|
|
5
5
|
// GIVEN
|
|
6
|
-
const transaction =
|
|
6
|
+
const transaction = {
|
|
7
|
+
transaction: {
|
|
8
|
+
serialized: "SERIALIZED",
|
|
9
|
+
json: "JSON",
|
|
10
|
+
hash: "HASH",
|
|
11
|
+
},
|
|
12
|
+
};
|
|
7
13
|
const signature = "SIGNATURE";
|
|
8
14
|
|
|
9
15
|
// WHEN
|
|
10
|
-
const result = combine(transaction, signature);
|
|
16
|
+
const result = combine(JSON.stringify(transaction), signature);
|
|
11
17
|
|
|
12
18
|
// THEN
|
|
13
19
|
expect(JSON.parse(result)).toEqual({
|
|
14
|
-
|
|
20
|
+
transaction: {
|
|
21
|
+
serialized: "SERIALIZED",
|
|
22
|
+
json: "JSON",
|
|
23
|
+
hash: "HASH",
|
|
24
|
+
},
|
|
15
25
|
signature: "SIGNATURE",
|
|
16
26
|
});
|
|
17
27
|
});
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// Combines signature with raw transaction
|
|
2
|
-
export function combine(
|
|
2
|
+
export function combine(transaction: string, signature: string): string {
|
|
3
|
+
const tx = JSON.parse(transaction);
|
|
4
|
+
|
|
3
5
|
return JSON.stringify({
|
|
4
|
-
|
|
6
|
+
...tx,
|
|
5
7
|
signature,
|
|
6
8
|
});
|
|
7
9
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import BigNumber from "bignumber.js";
|
|
2
|
-
import {
|
|
2
|
+
import { BoilerplateNativeTransaction } from "../../types";
|
|
3
|
+
|
|
4
|
+
const encodeNativeTx = (nativeTx: BoilerplateNativeTransaction) => JSON.stringify(nativeTx);
|
|
3
5
|
|
|
4
6
|
export async function craftTransaction(
|
|
5
7
|
account: {
|
|
@@ -10,25 +12,25 @@ export async function craftTransaction(
|
|
|
10
12
|
transaction: {
|
|
11
13
|
recipient?: string;
|
|
12
14
|
amount: BigNumber;
|
|
13
|
-
|
|
14
|
-
expireInSeconds: number;
|
|
15
|
+
fee?: BigNumber;
|
|
15
16
|
},
|
|
16
17
|
): Promise<{
|
|
17
|
-
nativeTransaction:
|
|
18
|
+
nativeTransaction: BoilerplateNativeTransaction;
|
|
18
19
|
serializedTransaction: string;
|
|
19
|
-
hash: string;
|
|
20
20
|
}> {
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
const nativeTransaction: BoilerplateNativeTransaction = {
|
|
22
|
+
TransactionType: "Payment",
|
|
23
|
+
Account: account.address,
|
|
24
|
+
Amount: transaction.amount.toString(),
|
|
25
|
+
Destination: transaction.recipient || "",
|
|
26
|
+
Fee: transaction.fee?.toString() || "0",
|
|
27
|
+
Sequence: account.nextSequenceNumber || 0,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const serializedTransaction = encodeNativeTx(nativeTransaction);
|
|
28
31
|
|
|
29
32
|
return {
|
|
30
|
-
nativeTransaction
|
|
31
|
-
serializedTransaction
|
|
32
|
-
hash,
|
|
33
|
+
nativeTransaction,
|
|
34
|
+
serializedTransaction,
|
|
33
35
|
};
|
|
34
36
|
}
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import coinConfig from "../../config";
|
|
2
|
-
|
|
3
|
-
const feeValue = () => coinConfig.getCoinConfig().fee ?? 10_000;
|
|
4
|
-
|
|
5
1
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
6
2
|
export async function estimateFees(serializedTransaction: string): Promise<bigint> {
|
|
7
|
-
return Promise.resolve(BigInt(
|
|
3
|
+
return Promise.resolve(BigInt(10_000)); // TODO replace with real implementation
|
|
8
4
|
}
|
package/src/config.ts
CHANGED
|
@@ -58,8 +58,7 @@ 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).
|
|
62
|
-
expect(typeof response.party_name).toBe("string");
|
|
61
|
+
expect(response.party_name).toBe(keyPair.publicKeyHex);
|
|
63
62
|
|
|
64
63
|
expect(response.public_key_fingerprint).toBe(keyPair.fingerprint);
|
|
65
64
|
}, 30000);
|
package/src/network/gateway.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import network from "@ledgerhq/live-network";
|
|
2
|
-
import type { LiveNetworkRequest } from "@ledgerhq/live-network/network";
|
|
3
|
-
import { getEnv } from "@ledgerhq/live-env";
|
|
4
2
|
import coinConfig from "../config";
|
|
5
3
|
import {
|
|
6
4
|
PrepareTransactionRequest,
|
|
@@ -39,21 +37,6 @@ type OnboardingPrepareRequest = {
|
|
|
39
37
|
public_key_type: string;
|
|
40
38
|
};
|
|
41
39
|
|
|
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
40
|
type OnboardingSubmitRequest = {
|
|
58
41
|
prepare_request: OnboardingPrepareRequest;
|
|
59
42
|
prepare_response: OnboardingPrepareResponse;
|
|
@@ -72,7 +55,7 @@ type TransactionSubmitRequest = {
|
|
|
72
55
|
signature: string;
|
|
73
56
|
};
|
|
74
57
|
|
|
75
|
-
type TransactionSubmitResponse = {
|
|
58
|
+
type TransactionSubmitResponse = { updateId: string };
|
|
76
59
|
|
|
77
60
|
export type InstrumentBalance = {
|
|
78
61
|
instrument_id: string;
|
|
@@ -264,18 +247,6 @@ export type OperationInfo =
|
|
|
264
247
|
|
|
265
248
|
const getGatewayUrl = () => coinConfig.getCoinConfig().gatewayUrl;
|
|
266
249
|
const getNodeId = () => coinConfig.getCoinConfig().nodeId || "ledger-devnet-stg";
|
|
267
|
-
const getNetworkType = () => coinConfig.getCoinConfig().networkType;
|
|
268
|
-
|
|
269
|
-
const gatewayNetwork = <T, U = unknown>(req: LiveNetworkRequest<U>) => {
|
|
270
|
-
const API_KEY = getEnv("CANTON_API_KEY");
|
|
271
|
-
return network<T, U>({
|
|
272
|
-
...req,
|
|
273
|
-
headers: {
|
|
274
|
-
...(req.headers || {}),
|
|
275
|
-
...(API_KEY && { "X-Ledger-Canton-Api-Key": API_KEY }),
|
|
276
|
-
},
|
|
277
|
-
});
|
|
278
|
-
};
|
|
279
250
|
|
|
280
251
|
export async function prepareOnboarding(
|
|
281
252
|
pubKey: string,
|
|
@@ -285,13 +256,13 @@ export async function prepareOnboarding(
|
|
|
285
256
|
const nodeId = getNodeId();
|
|
286
257
|
const fullUrl = `${gatewayUrl}/v1/node/${nodeId}/onboarding/prepare`;
|
|
287
258
|
|
|
288
|
-
const { data } = await
|
|
259
|
+
const { data } = await network<OnboardingPrepareResponse>({
|
|
289
260
|
method: "POST",
|
|
290
261
|
url: fullUrl,
|
|
291
262
|
data: {
|
|
292
263
|
public_key: pubKey,
|
|
293
264
|
public_key_type: pubKeyType,
|
|
294
|
-
},
|
|
265
|
+
} satisfies OnboardingPrepareRequest,
|
|
295
266
|
});
|
|
296
267
|
|
|
297
268
|
return data;
|
|
@@ -302,34 +273,35 @@ export async function submitOnboarding(
|
|
|
302
273
|
prepareResponse: OnboardingPrepareResponse,
|
|
303
274
|
signature: string,
|
|
304
275
|
) {
|
|
305
|
-
const { data } = await
|
|
276
|
+
const { data } = await network<OnboardingSubmitResponse>({
|
|
306
277
|
method: "POST",
|
|
307
278
|
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/onboarding/submit`,
|
|
308
279
|
data: {
|
|
309
280
|
prepare_request: prepareRequest,
|
|
310
281
|
prepare_response: prepareResponse,
|
|
311
282
|
signature,
|
|
312
|
-
},
|
|
283
|
+
} satisfies OnboardingSubmitRequest,
|
|
313
284
|
});
|
|
314
285
|
return data;
|
|
315
286
|
}
|
|
316
287
|
|
|
317
|
-
export async function submit(
|
|
318
|
-
const { data } = await
|
|
288
|
+
export async function submit(serializedTx: string, signature: string) {
|
|
289
|
+
const { data } = await network<TransactionSubmitResponse>({
|
|
319
290
|
method: "POST",
|
|
320
|
-
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/
|
|
291
|
+
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/transaction/submit`,
|
|
321
292
|
data: {
|
|
322
|
-
serialized,
|
|
293
|
+
serialized: serializedTx,
|
|
323
294
|
signature,
|
|
324
|
-
},
|
|
295
|
+
} satisfies TransactionSubmitRequest,
|
|
325
296
|
});
|
|
326
297
|
return data;
|
|
327
298
|
}
|
|
328
299
|
|
|
329
300
|
export async function getBalance(partyId: string): Promise<InstrumentBalance[]> {
|
|
330
|
-
const { data } = await
|
|
301
|
+
const { data } = await network<InstrumentBalance[]>({
|
|
331
302
|
method: "GET",
|
|
332
|
-
|
|
303
|
+
// TODO: we need better solution ?
|
|
304
|
+
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId.replace(/_/g, ":")}/balance`,
|
|
333
305
|
});
|
|
334
306
|
return data;
|
|
335
307
|
}
|
|
@@ -343,7 +315,7 @@ export async function getPartyByPubKey(pubKey: string): Promise<PartyInfo> {
|
|
|
343
315
|
}
|
|
344
316
|
|
|
345
317
|
async function getParty(identifier: string, by: "party-id" | "public-key"): Promise<PartyInfo> {
|
|
346
|
-
const { data } = await
|
|
318
|
+
const { data } = await network<PartyInfo>({
|
|
347
319
|
method: "GET",
|
|
348
320
|
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${identifier}?by=${by}`,
|
|
349
321
|
});
|
|
@@ -362,26 +334,26 @@ export async function getOperations(
|
|
|
362
334
|
next: number;
|
|
363
335
|
operations: OperationInfo[];
|
|
364
336
|
}> {
|
|
365
|
-
const { data } = await
|
|
337
|
+
const { data } = await network<{
|
|
366
338
|
next: number;
|
|
367
339
|
operations: OperationInfo[];
|
|
368
340
|
}>({
|
|
369
341
|
method: "GET",
|
|
370
|
-
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/operations`,
|
|
371
|
-
|
|
342
|
+
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId.replace(/_/g, ":")}/operations`,
|
|
343
|
+
data: options,
|
|
372
344
|
});
|
|
373
345
|
return data;
|
|
374
346
|
}
|
|
375
347
|
|
|
376
|
-
type
|
|
348
|
+
type PrepareTapRequestRequest = {
|
|
377
349
|
partyId: string;
|
|
378
350
|
amount?: number;
|
|
379
351
|
};
|
|
380
352
|
|
|
381
|
-
type
|
|
382
|
-
serialized: string;
|
|
353
|
+
type PrepareTapRequestResponse = {
|
|
354
|
+
serialized: "string";
|
|
383
355
|
json: null;
|
|
384
|
-
hash: string;
|
|
356
|
+
hash: "string";
|
|
385
357
|
};
|
|
386
358
|
|
|
387
359
|
enum TransactionType {
|
|
@@ -392,15 +364,8 @@ enum TransactionType {
|
|
|
392
364
|
export async function prepareTapRequest({
|
|
393
365
|
partyId,
|
|
394
366
|
amount = 1000000,
|
|
395
|
-
}:
|
|
396
|
-
|
|
397
|
-
return {
|
|
398
|
-
serialized: "",
|
|
399
|
-
json: null,
|
|
400
|
-
hash: "",
|
|
401
|
-
};
|
|
402
|
-
}
|
|
403
|
-
const { data } = await gatewayNetwork<PrepareTapResponse, { amount: number; type: string }>({
|
|
367
|
+
}: PrepareTapRequestRequest): Promise<PrepareTapRequestResponse> {
|
|
368
|
+
const { data } = await network<PrepareTapRequestResponse>({
|
|
404
369
|
method: "POST",
|
|
405
370
|
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/transaction/prepare`,
|
|
406
371
|
data: {
|
|
@@ -427,34 +392,19 @@ export async function submitTapRequest({
|
|
|
427
392
|
serialized,
|
|
428
393
|
signature,
|
|
429
394
|
}: SubmitTapRequestRequest): Promise<SubmitTapRequestResponse> {
|
|
430
|
-
const { data } = await
|
|
431
|
-
SubmitTapRequestResponse,
|
|
432
|
-
Omit<SubmitTapRequestRequest, "partyId">
|
|
433
|
-
>({
|
|
395
|
+
const { data } = await network<SubmitTapRequestResponse>({
|
|
434
396
|
method: "POST",
|
|
435
397
|
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/transaction/submit`,
|
|
436
398
|
data: {
|
|
437
399
|
serialized,
|
|
438
400
|
signature,
|
|
439
|
-
},
|
|
440
|
-
});
|
|
441
|
-
return data;
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
export async function prepareTransferRequest(
|
|
445
|
-
partyId: string,
|
|
446
|
-
params: PrepareTransferRequest,
|
|
447
|
-
): Promise<PrepareTransferResponse> {
|
|
448
|
-
const { data } = await gatewayNetwork<PrepareTransferResponse, PrepareTransferRequest>({
|
|
449
|
-
method: "POST",
|
|
450
|
-
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/transaction/prepare`,
|
|
451
|
-
data: params,
|
|
401
|
+
} satisfies Omit<SubmitTapRequestRequest, "partyId">,
|
|
452
402
|
});
|
|
453
403
|
return data;
|
|
454
404
|
}
|
|
455
405
|
|
|
456
406
|
export async function getLedgerEnd(): Promise<number> {
|
|
457
|
-
const { data } = await
|
|
407
|
+
const { data } = await network<number>({
|
|
458
408
|
method: "GET",
|
|
459
409
|
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/ledger-end`,
|
|
460
410
|
});
|
|
@@ -464,29 +414,31 @@ export async function getLedgerEnd(): Promise<number> {
|
|
|
464
414
|
export async function preparePreApprovalTransaction(
|
|
465
415
|
partyId: string,
|
|
466
416
|
): Promise<PrepareTransactionResponse> {
|
|
467
|
-
const { data } = await
|
|
417
|
+
const { data } = await network<PrepareTransactionResponse>({
|
|
468
418
|
method: "POST",
|
|
469
419
|
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/transaction/prepare`,
|
|
470
420
|
data: {
|
|
471
421
|
type: TransactionType.TRANSFER_PRE_APPROVAL_PROPOSAL,
|
|
472
422
|
receiver: partyId,
|
|
473
|
-
},
|
|
423
|
+
} satisfies PrepareTransactionRequest,
|
|
474
424
|
});
|
|
475
425
|
return data;
|
|
476
426
|
}
|
|
477
427
|
|
|
478
428
|
export async function submitPreApprovalTransaction(
|
|
479
429
|
partyId: string,
|
|
480
|
-
|
|
430
|
+
preparedTransaction: PrepareTransactionResponse,
|
|
481
431
|
signature: string,
|
|
482
432
|
): Promise<PreApprovalResult> {
|
|
483
|
-
const
|
|
433
|
+
const submitRequest: SubmitTransactionRequest = {
|
|
434
|
+
serialized: preparedTransaction.serialized,
|
|
435
|
+
signature,
|
|
436
|
+
};
|
|
437
|
+
|
|
438
|
+
const { data } = await network<SubmitTransactionResponse>({
|
|
484
439
|
method: "POST",
|
|
485
440
|
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/transaction/submit`,
|
|
486
|
-
data:
|
|
487
|
-
serialized,
|
|
488
|
-
signature,
|
|
489
|
-
},
|
|
441
|
+
data: submitRequest,
|
|
490
442
|
});
|
|
491
443
|
|
|
492
444
|
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, SubmitReponse } 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<SubmitReponse> => {
|
|
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<SubmitReponse>({
|
|
93
93
|
url,
|
|
94
94
|
method: "GET",
|
|
95
95
|
});
|
package/src/network/types.ts
CHANGED
package/src/signer/getAddress.ts
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
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
|
|
4
|
+
import { CantonSigner } from "../types";
|
|
5
5
|
|
|
6
6
|
const getAddress = (signerContext: SignerContext<CantonSigner>): GetAddressFn => {
|
|
7
|
-
return async (deviceId: string, { path
|
|
8
|
-
const { address, publicKey } = await signerContext(deviceId, signer =>
|
|
9
|
-
signer.getAddress(path, verify),
|
|
10
|
-
);
|
|
7
|
+
return async (deviceId: string, { path }: GetAddressOptions) => {
|
|
8
|
+
const { address, publicKey } = await signerContext(deviceId, signer => signer.getAddress(path));
|
|
11
9
|
|
|
12
10
|
return {
|
|
13
11
|
path,
|
|
14
12
|
address,
|
|
15
13
|
publicKey,
|
|
16
|
-
}
|
|
14
|
+
};
|
|
17
15
|
};
|
|
18
16
|
};
|
|
19
17
|
|
package/src/types/bridge.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { BigNumber } from "bignumber.js";
|
|
2
2
|
import type { Observable } from "rxjs";
|
|
3
3
|
import type {
|
|
4
|
-
Account,
|
|
5
|
-
AccountRaw,
|
|
6
4
|
CurrencyBridge,
|
|
7
5
|
TransactionCommon,
|
|
8
6
|
TransactionCommonRaw,
|
|
@@ -52,17 +50,3 @@ export type TransactionRaw = TransactionCommonRaw & {
|
|
|
52
50
|
|
|
53
51
|
export type TransactionStatus = TransactionStatusCommon;
|
|
54
52
|
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/index.ts
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
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,5 +1,3 @@
|
|
|
1
|
-
import { Account } from "@ledgerhq/types-live";
|
|
2
|
-
|
|
3
1
|
export enum OnboardStatus {
|
|
4
2
|
INIT,
|
|
5
3
|
PREPARE,
|
|
@@ -24,7 +22,6 @@ export type CantonOnboardProgress = {
|
|
|
24
22
|
|
|
25
23
|
export type CantonOnboardResult = {
|
|
26
24
|
partyId: string;
|
|
27
|
-
account: Partial<Account>;
|
|
28
25
|
};
|
|
29
26
|
|
|
30
27
|
export type CantonPreApprovalProgress = {
|
package/src/types/signer.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
export type CantonAddress = {
|
|
2
2
|
publicKey: string;
|
|
3
3
|
address: string;
|
|
4
|
-
path: string; // TODO: check if necessary
|
|
5
4
|
};
|
|
6
5
|
|
|
7
6
|
export type CantonSignature = string; // `0x${string}`
|
|
8
7
|
|
|
9
8
|
export interface CantonSigner {
|
|
10
|
-
getAddress(path: string
|
|
9
|
+
getAddress(path: string): Promise<CantonAddress>;
|
|
11
10
|
signTransaction(path: string, rawTx: string): Promise<CantonSignature>;
|
|
12
11
|
}
|