@ledgerhq/coin-canton 0.5.0-nightly.5 → 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 +32 -47
- package/lib/api/getBalance.integ.test.js +5 -9
- package/lib/api/getBalance.integ.test.js.map +1 -1
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +25 -20
- 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 -3
- package/lib/bridge/broadcast.js.map +1 -1
- package/lib/bridge/broadcast.test.js +0 -9
- 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 +0 -3
- package/lib/bridge/index.js.map +1 -1
- package/lib/bridge/onboard.d.ts +5 -7
- package/lib/bridge/onboard.d.ts.map +1 -1
- package/lib/bridge/onboard.integ.test.js +11 -14
- package/lib/bridge/onboard.integ.test.js.map +1 -1
- package/lib/bridge/onboard.js +42 -110
- 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 +11 -14
- 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 +21 -41
- 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/account/getBalance.d.ts +1 -2
- 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 +3 -6
- package/lib/common-logic/account/getBalance.unit.test.js.map +1 -1
- package/lib/common-logic/history/lastBlock.d.ts +1 -2
- 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 +2 -5
- package/lib/common-logic/history/lastBlock.test.js.map +1 -1
- package/lib/common-logic/history/listOperations.d.ts +1 -2
- 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 +1 -2
- package/lib/common-logic/transaction/broadcast.d.ts.map +1 -1
- package/lib/common-logic/transaction/broadcast.js +4 -5
- package/lib/common-logic/transaction/broadcast.js.map +1 -1
- package/lib/common-logic/transaction/broadcast.test.js +5 -8
- 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 +4 -8
- package/lib/common-logic/transaction/craftTransaction.d.ts.map +1 -1
- package/lib/common-logic/transaction/craftTransaction.js +12 -15
- package/lib/common-logic/transaction/craftTransaction.js.map +1 -1
- package/lib/common-logic/transaction/estimateFees.d.ts +1 -2
- package/lib/common-logic/transaction/estimateFees.d.ts.map +1 -1
- package/lib/common-logic/transaction/estimateFees.js +3 -7
- 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 +17 -41
- package/lib/network/gateway.d.ts.map +1 -1
- package/lib/network/gateway.integ.test.js +15 -19
- package/lib/network/gateway.integ.test.js.map +1 -1
- package/lib/network/gateway.js +48 -74
- 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 +3 -18
- 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 +5 -9
- 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 +24 -19
- 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 -3
- package/lib-es/bridge/broadcast.js.map +1 -1
- package/lib-es/bridge/broadcast.test.js +0 -9
- 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 +0 -3
- package/lib-es/bridge/index.js.map +1 -1
- package/lib-es/bridge/onboard.d.ts +5 -7
- package/lib-es/bridge/onboard.d.ts.map +1 -1
- package/lib-es/bridge/onboard.integ.test.js +11 -14
- package/lib-es/bridge/onboard.integ.test.js.map +1 -1
- package/lib-es/bridge/onboard.js +42 -107
- 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 +12 -15
- 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 +22 -42
- 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/account/getBalance.d.ts +1 -2
- 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 +3 -6
- package/lib-es/common-logic/account/getBalance.unit.test.js.map +1 -1
- package/lib-es/common-logic/history/lastBlock.d.ts +1 -2
- 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 +2 -5
- package/lib-es/common-logic/history/lastBlock.test.js.map +1 -1
- package/lib-es/common-logic/history/listOperations.d.ts +1 -2
- 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 +1 -2
- package/lib-es/common-logic/transaction/broadcast.d.ts.map +1 -1
- package/lib-es/common-logic/transaction/broadcast.js +4 -5
- package/lib-es/common-logic/transaction/broadcast.js.map +1 -1
- package/lib-es/common-logic/transaction/broadcast.test.js +5 -8
- 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 +4 -8
- package/lib-es/common-logic/transaction/craftTransaction.d.ts.map +1 -1
- package/lib-es/common-logic/transaction/craftTransaction.js +12 -15
- package/lib-es/common-logic/transaction/craftTransaction.js.map +1 -1
- package/lib-es/common-logic/transaction/estimateFees.d.ts +1 -2
- 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/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 +17 -41
- package/lib-es/network/gateway.d.ts.map +1 -1
- package/lib-es/network/gateway.integ.test.js +15 -19
- package/lib-es/network/gateway.integ.test.js.map +1 -1
- package/lib-es/network/gateway.js +48 -73
- 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 +3 -18
- 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 +6 -9
- package/src/api/index.ts +44 -22
- package/src/api/lastBlock.integ.test.ts +1 -1
- package/src/api/listOperations.integ.test.ts +1 -1
- package/src/bridge/broadcast.test.ts +0 -11
- package/src/bridge/broadcast.ts +2 -4
- package/src/bridge/createTransaction.ts +1 -1
- package/src/bridge/getTransactionStatus.ts +1 -1
- package/src/bridge/index.ts +0 -3
- package/src/bridge/onboard.integ.test.ts +13 -25
- package/src/bridge/onboard.ts +51 -143
- package/src/bridge/prepareTransaction.ts +15 -6
- package/src/bridge/signOperation.ts +20 -26
- package/src/bridge/sync.ts +27 -53
- package/src/bridge/updateTransaction.ts +5 -0
- package/src/common-logic/account/getBalance.ts +7 -12
- package/src/common-logic/account/getBalance.unit.test.ts +3 -8
- package/src/common-logic/history/lastBlock.test.ts +2 -7
- package/src/common-logic/history/lastBlock.ts +3 -5
- package/src/common-logic/history/listOperations.ts +2 -3
- package/src/common-logic/transaction/broadcast.test.ts +5 -10
- package/src/common-logic/transaction/broadcast.ts +3 -7
- 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 +15 -30
- package/src/common-logic/transaction/estimateFees.ts +3 -7
- package/src/config.ts +0 -1
- package/src/network/gateway.integ.test.ts +12 -31
- package/src/network/gateway.ts +62 -141
- 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 -21
- 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
|
@@ -3,14 +3,15 @@ import { createApi } from ".";
|
|
|
3
3
|
|
|
4
4
|
let api: AlpacaApi;
|
|
5
5
|
|
|
6
|
-
describe
|
|
6
|
+
describe("devnet", () => {
|
|
7
7
|
beforeAll(() => {
|
|
8
8
|
api = createApi({
|
|
9
9
|
nodeUrl: "https://wallet-validator-devnet-canton.ledger-test.com/v2",
|
|
10
10
|
networkType: "devnet",
|
|
11
11
|
gatewayUrl: "https://canton-gateway.api.live.ledger-test.com",
|
|
12
12
|
useGateway: true,
|
|
13
|
-
nativeInstrumentId:
|
|
13
|
+
nativeInstrumentId:
|
|
14
|
+
"6e9fc50fb94e56751b49f09ba2dc84da53a9d7cff08115ebb4f6b7a12d0c990c:Splice.Amulet:Amulet",
|
|
14
15
|
});
|
|
15
16
|
});
|
|
16
17
|
|
|
@@ -19,13 +20,9 @@ describe.skip("devnet", () => {
|
|
|
19
20
|
const balance = await api.getBalance(
|
|
20
21
|
"party-4f2e1485107adf5f::122027c6dbbbdbffe0fa3122ae05175f3b9328e879e9ce96b670354deb64a45683c1",
|
|
21
22
|
);
|
|
22
|
-
expect(balance.length).toBeGreaterThanOrEqual(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (nativeBalance) {
|
|
26
|
-
expect(nativeBalance.value).toBeGreaterThanOrEqual(BigInt(0));
|
|
27
|
-
}
|
|
28
|
-
}
|
|
23
|
+
expect(balance.length).toBeGreaterThanOrEqual(1);
|
|
24
|
+
const nativeBalance = balance.find(b => b.asset.type === "native");
|
|
25
|
+
expect(nativeBalance?.value).toBeGreaterThanOrEqual(0);
|
|
29
26
|
});
|
|
30
27
|
});
|
|
31
28
|
});
|
package/src/api/index.ts
CHANGED
|
@@ -2,42 +2,38 @@ import {
|
|
|
2
2
|
AlpacaApi,
|
|
3
3
|
Block,
|
|
4
4
|
BlockInfo,
|
|
5
|
+
CraftedTransaction,
|
|
5
6
|
Cursor,
|
|
6
7
|
FeeEstimation,
|
|
7
8
|
Page,
|
|
8
9
|
Reward,
|
|
9
10
|
Stake,
|
|
10
11
|
TransactionIntent,
|
|
11
|
-
Operation,
|
|
12
|
-
Balance,
|
|
13
|
-
Pagination,
|
|
14
12
|
} from "@ledgerhq/coin-framework/api/index";
|
|
15
13
|
import coinConfig, { type CantonConfig } from "../config";
|
|
16
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
broadcast,
|
|
16
|
+
combine,
|
|
17
|
+
craftTransaction,
|
|
18
|
+
estimateFees,
|
|
19
|
+
getBalance,
|
|
20
|
+
getNextValidSequence,
|
|
21
|
+
lastBlock,
|
|
22
|
+
listOperations,
|
|
23
|
+
} from "../common-logic";
|
|
24
|
+
import BigNumber from "bignumber.js";
|
|
17
25
|
|
|
18
26
|
export function createApi(config: CantonConfig): AlpacaApi {
|
|
19
27
|
coinConfig.setCoinConfig(() => ({ ...config, status: { type: "active" } }));
|
|
20
28
|
|
|
21
29
|
return {
|
|
22
|
-
broadcast
|
|
23
|
-
throw new Error("broadcast is not supported");
|
|
24
|
-
},
|
|
30
|
+
broadcast,
|
|
25
31
|
combine,
|
|
26
|
-
craftTransaction
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
},
|
|
32
|
-
getBalance(_address: string): Promise<Balance[]> {
|
|
33
|
-
throw new Error("getBalance is not supported");
|
|
34
|
-
},
|
|
35
|
-
lastBlock(): Promise<BlockInfo> {
|
|
36
|
-
throw new Error("listOperations is not supported");
|
|
37
|
-
},
|
|
38
|
-
listOperations(_address: string, _pagination: Pagination): Promise<[Operation[], string]> {
|
|
39
|
-
throw new Error("listOperations is not supported");
|
|
40
|
-
},
|
|
32
|
+
craftTransaction: craft,
|
|
33
|
+
estimateFees: estimate,
|
|
34
|
+
getBalance,
|
|
35
|
+
lastBlock,
|
|
36
|
+
listOperations,
|
|
41
37
|
getBlock(_height): Promise<Block> {
|
|
42
38
|
throw new Error("getBlock is not supported");
|
|
43
39
|
},
|
|
@@ -52,3 +48,29 @@ export function createApi(config: CantonConfig): AlpacaApi {
|
|
|
52
48
|
},
|
|
53
49
|
};
|
|
54
50
|
}
|
|
51
|
+
|
|
52
|
+
async function craft(transactionIntent: TransactionIntent): Promise<CraftedTransaction> {
|
|
53
|
+
const nextSequenceNumber = await getNextValidSequence(transactionIntent.sender);
|
|
54
|
+
const tx = await craftTransaction(
|
|
55
|
+
{ address: transactionIntent.sender, nextSequenceNumber },
|
|
56
|
+
{
|
|
57
|
+
recipient: transactionIntent.recipient,
|
|
58
|
+
amount: new BigNumber(transactionIntent.amount.toString()),
|
|
59
|
+
},
|
|
60
|
+
);
|
|
61
|
+
return { transaction: tx.serializedTransaction };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function estimate(transactionIntent: TransactionIntent): Promise<FeeEstimation> {
|
|
65
|
+
const { serializedTransaction } = await craftTransaction(
|
|
66
|
+
{ address: transactionIntent.sender },
|
|
67
|
+
{
|
|
68
|
+
recipient: transactionIntent.recipient,
|
|
69
|
+
amount: new BigNumber(transactionIntent.amount.toString()),
|
|
70
|
+
},
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const value = await estimateFees(serializedTransaction);
|
|
74
|
+
|
|
75
|
+
return { value };
|
|
76
|
+
}
|
|
@@ -4,11 +4,6 @@ jest.mock("@ledgerhq/coin-framework/operation");
|
|
|
4
4
|
jest.mock("../common-logic");
|
|
5
5
|
import { patchOperationWithHash } from "@ledgerhq/coin-framework/operation";
|
|
6
6
|
import { broadcast as broadcastLogic } from "../common-logic";
|
|
7
|
-
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
8
|
-
|
|
9
|
-
const mockCurrency = {
|
|
10
|
-
id: "canton_network",
|
|
11
|
-
} as unknown as CryptoCurrency;
|
|
12
7
|
|
|
13
8
|
describe("broadcast", () => {
|
|
14
9
|
let patchOperationSpy: jest.SpyInstance;
|
|
@@ -21,9 +16,6 @@ describe("broadcast", () => {
|
|
|
21
16
|
|
|
22
17
|
it("should broadcast", () => {
|
|
23
18
|
broadcast({
|
|
24
|
-
account: {
|
|
25
|
-
currency: mockCurrency,
|
|
26
|
-
},
|
|
27
19
|
signedOperation: {
|
|
28
20
|
signature: undefined,
|
|
29
21
|
operation: undefined,
|
|
@@ -34,9 +26,6 @@ describe("broadcast", () => {
|
|
|
34
26
|
|
|
35
27
|
it("should patch operation with hash", () => {
|
|
36
28
|
broadcast({
|
|
37
|
-
account: {
|
|
38
|
-
currency: mockCurrency,
|
|
39
|
-
},
|
|
40
29
|
signedOperation: {
|
|
41
30
|
signature: undefined,
|
|
42
31
|
operation: undefined,
|
package/src/bridge/broadcast.ts
CHANGED
|
@@ -4,10 +4,8 @@ import { broadcast as broadcastLogic } from "../common-logic";
|
|
|
4
4
|
import { Transaction } from "../types";
|
|
5
5
|
|
|
6
6
|
export const broadcast: AccountBridge<Transaction>["broadcast"] = async ({
|
|
7
|
-
|
|
8
|
-
signedOperation,
|
|
7
|
+
signedOperation: { signature, operation },
|
|
9
8
|
}) => {
|
|
10
|
-
const
|
|
11
|
-
const hash = await broadcastLogic(account.currency, signature);
|
|
9
|
+
const hash = await broadcastLogic(signature);
|
|
12
10
|
return patchOperationWithHash(operation, hash);
|
|
13
11
|
};
|
|
@@ -25,7 +25,7 @@ export const getTransactionStatus: AccountBridge<
|
|
|
25
25
|
const warnings: Record<string, Error> = {};
|
|
26
26
|
|
|
27
27
|
// reserveAmount is the minimum amount of currency that an account must hold in order to stay activated
|
|
28
|
-
const reserveAmount = new BigNumber(coinConfig.getCoinConfig(
|
|
28
|
+
const reserveAmount = new BigNumber(coinConfig.getCoinConfig().minReserve || 0);
|
|
29
29
|
const estimatedFees = new BigNumber(transaction.fee || 0);
|
|
30
30
|
const totalSpent = new BigNumber(transaction.amount).plus(estimatedFees);
|
|
31
31
|
const amount = new BigNumber(transaction.amount);
|
package/src/bridge/index.ts
CHANGED
|
@@ -21,7 +21,6 @@ import { buildSignOperation } from "./signOperation";
|
|
|
21
21
|
import { getAccountShape } from "./sync";
|
|
22
22
|
import { updateTransaction } from "./updateTransaction";
|
|
23
23
|
import { buildOnboardAccount, buildAuthorizePreapproval } from "./onboard";
|
|
24
|
-
import { assignFromAccountRaw, assignToAccountRaw } from "./serialization";
|
|
25
24
|
|
|
26
25
|
export function createBridges(
|
|
27
26
|
signerContext: SignerContext<CantonSigner>,
|
|
@@ -63,8 +62,6 @@ export function createBridges(
|
|
|
63
62
|
sync,
|
|
64
63
|
receive,
|
|
65
64
|
signOperation,
|
|
66
|
-
assignToAccountRaw,
|
|
67
|
-
assignFromAccountRaw,
|
|
68
65
|
getSerializedAddressParameters,
|
|
69
66
|
};
|
|
70
67
|
|
|
@@ -10,14 +10,10 @@ import {
|
|
|
10
10
|
CantonPreApprovalResult,
|
|
11
11
|
} from "../types/onboard";
|
|
12
12
|
import coinConfig from "../config";
|
|
13
|
-
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
14
13
|
|
|
15
|
-
describe("onboard
|
|
14
|
+
describe("onboard integration tests", () => {
|
|
16
15
|
const mockDeviceId = "test-device-id";
|
|
17
16
|
const mockDerivationPath = "44'/6767'/0'/0'/0'";
|
|
18
|
-
const mockCurrency = {
|
|
19
|
-
id: "canton_network",
|
|
20
|
-
} as unknown as CryptoCurrency;
|
|
21
17
|
|
|
22
18
|
let onboardedAccount: {
|
|
23
19
|
keyPair: ReturnType<typeof generateMockKeyPair>;
|
|
@@ -57,7 +53,7 @@ describe("onboard (devnet)", () => {
|
|
|
57
53
|
|
|
58
54
|
const onboardObservable = buildOnboardAccount(mockSignerContext);
|
|
59
55
|
const onboardValues = await firstValueFrom(
|
|
60
|
-
onboardObservable(
|
|
56
|
+
onboardObservable(mockDeviceId, mockDerivationPath).pipe(toArray()),
|
|
61
57
|
);
|
|
62
58
|
const onboardResult = onboardValues.find(
|
|
63
59
|
(value): value is CantonOnboardResult => "partyId" in value,
|
|
@@ -76,7 +72,7 @@ describe("onboard (devnet)", () => {
|
|
|
76
72
|
};
|
|
77
73
|
|
|
78
74
|
// WHEN
|
|
79
|
-
const result = await isAccountOnboarded(
|
|
75
|
+
const result = await isAccountOnboarded(keyPair.publicKeyHex);
|
|
80
76
|
|
|
81
77
|
// THEN
|
|
82
78
|
expect(result).not.toBe(false);
|
|
@@ -91,10 +87,10 @@ describe("onboard (devnet)", () => {
|
|
|
91
87
|
const keyPair = generateMockKeyPair();
|
|
92
88
|
|
|
93
89
|
// WHEN
|
|
94
|
-
const result = await isAccountOnboarded(
|
|
90
|
+
const result = await isAccountOnboarded(keyPair.publicKeyHex);
|
|
95
91
|
|
|
96
92
|
// THEN
|
|
97
|
-
expect(result).
|
|
93
|
+
expect(result).toBe(false);
|
|
98
94
|
}, 15000);
|
|
99
95
|
|
|
100
96
|
it("should handle errors gracefully when checking non-existent party", async () => {
|
|
@@ -102,10 +98,10 @@ describe("onboard (devnet)", () => {
|
|
|
102
98
|
const keyPair = generateMockKeyPair();
|
|
103
99
|
|
|
104
100
|
// WHEN
|
|
105
|
-
const result = await isAccountOnboarded(
|
|
101
|
+
const result = await isAccountOnboarded(keyPair.publicKeyHex);
|
|
106
102
|
|
|
107
103
|
// THEN
|
|
108
|
-
expect(result).
|
|
104
|
+
expect(result).toBe(false);
|
|
109
105
|
}, 15000);
|
|
110
106
|
});
|
|
111
107
|
|
|
@@ -121,7 +117,7 @@ describe("onboard (devnet)", () => {
|
|
|
121
117
|
|
|
122
118
|
// WHEN
|
|
123
119
|
const allValues = await firstValueFrom(
|
|
124
|
-
onboardObservable(
|
|
120
|
+
onboardObservable(mockDeviceId, mockDerivationPath).pipe(toArray()),
|
|
125
121
|
);
|
|
126
122
|
const progressValues = allValues.filter(
|
|
127
123
|
(value): value is CantonOnboardProgress => "status" in value && !("partyId" in value),
|
|
@@ -153,7 +149,7 @@ describe("onboard (devnet)", () => {
|
|
|
153
149
|
|
|
154
150
|
// WHEN
|
|
155
151
|
const secondOnboardValues = await firstValueFrom(
|
|
156
|
-
secondOnboardObservable(
|
|
152
|
+
secondOnboardObservable(mockDeviceId, mockDerivationPath).pipe(toArray()),
|
|
157
153
|
);
|
|
158
154
|
const secondResult = secondOnboardValues.find(
|
|
159
155
|
(value): value is CantonOnboardResult => "partyId" in value,
|
|
@@ -174,12 +170,9 @@ describe("onboard (devnet)", () => {
|
|
|
174
170
|
|
|
175
171
|
// WHEN
|
|
176
172
|
const preapprovalValues = await firstValueFrom(
|
|
177
|
-
preapprovalObservable(
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
mockDerivationPath,
|
|
181
|
-
onboardResult.partyId,
|
|
182
|
-
).pipe(toArray()),
|
|
173
|
+
preapprovalObservable(mockDeviceId, mockDerivationPath, onboardResult.partyId).pipe(
|
|
174
|
+
toArray(),
|
|
175
|
+
),
|
|
183
176
|
);
|
|
184
177
|
|
|
185
178
|
const progressValues = preapprovalValues.filter(
|
|
@@ -215,12 +208,7 @@ describe("onboard (devnet)", () => {
|
|
|
215
208
|
// WHEN & THEN
|
|
216
209
|
try {
|
|
217
210
|
await firstValueFrom(
|
|
218
|
-
preapprovalObservable(
|
|
219
|
-
mockCurrency,
|
|
220
|
-
mockDeviceId,
|
|
221
|
-
mockDerivationPath,
|
|
222
|
-
"invalid-party-id-123",
|
|
223
|
-
),
|
|
211
|
+
preapprovalObservable(mockDeviceId, mockDerivationPath, "invalid-party-id-123"),
|
|
224
212
|
);
|
|
225
213
|
expect(true).toBe(true);
|
|
226
214
|
} catch (error) {
|
package/src/bridge/onboard.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { Observable } from "rxjs";
|
|
2
2
|
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
3
|
-
import {
|
|
4
|
-
import { getDerivationModesForCurrency } from "@ledgerhq/coin-framework/derivation";
|
|
5
|
-
import { getAccountShape } from "./sync";
|
|
6
|
-
import { CantonAccount, CantonSigner } from "../types";
|
|
7
|
-
import type { Account, DerivationMode } from "@ledgerhq/types-live";
|
|
3
|
+
import { CantonSigner } from "../types/signer";
|
|
8
4
|
import {
|
|
9
5
|
prepareOnboarding,
|
|
10
6
|
submitOnboarding,
|
|
@@ -23,10 +19,8 @@ import {
|
|
|
23
19
|
CantonPreApprovalResult,
|
|
24
20
|
PrepareTransactionResponse,
|
|
25
21
|
} from "../types/onboard";
|
|
26
|
-
import resolver from "../signer";
|
|
27
|
-
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
28
22
|
|
|
29
|
-
async function
|
|
23
|
+
async function getKeypair(
|
|
30
24
|
signerContext: SignerContext<CantonSigner>,
|
|
31
25
|
deviceId: string,
|
|
32
26
|
derivationPath: string,
|
|
@@ -38,27 +32,25 @@ async function _getKeypair(
|
|
|
38
32
|
}
|
|
39
33
|
|
|
40
34
|
export const isAccountOnboarded = async (
|
|
41
|
-
currency: CryptoCurrency,
|
|
42
35
|
publicKey: string,
|
|
43
|
-
): Promise<
|
|
36
|
+
): Promise<false | { party_id: string }> => {
|
|
44
37
|
try {
|
|
45
|
-
const { party_id } = await getPartyByPubKey(
|
|
38
|
+
const { party_id } = await getPartyByPubKey(publicKey);
|
|
46
39
|
|
|
47
40
|
if (party_id) {
|
|
48
|
-
return {
|
|
41
|
+
return { party_id };
|
|
49
42
|
} else {
|
|
50
|
-
return
|
|
43
|
+
return false;
|
|
51
44
|
}
|
|
52
45
|
} catch (err) {
|
|
53
46
|
log("[isAccountOnboarded] Error checking party status (likely not onboarded):", err);
|
|
54
|
-
return
|
|
47
|
+
return false;
|
|
55
48
|
}
|
|
56
49
|
};
|
|
57
50
|
|
|
58
51
|
export const buildOnboardAccount =
|
|
59
52
|
(signerContext: SignerContext<CantonSigner>) =>
|
|
60
53
|
(
|
|
61
|
-
currency: CryptoCurrency,
|
|
62
54
|
deviceId: string,
|
|
63
55
|
derivationPath: string,
|
|
64
56
|
): Observable<CantonOnboardProgress | CantonOnboardResult> =>
|
|
@@ -67,36 +59,22 @@ export const buildOnboardAccount =
|
|
|
67
59
|
observer.next({
|
|
68
60
|
status: OnboardStatus.INIT,
|
|
69
61
|
});
|
|
70
|
-
const
|
|
71
|
-
const getAddress = resolver(signerContext);
|
|
72
|
-
const { address, publicKey } = await getAddress(deviceId, {
|
|
73
|
-
path: derivationPath,
|
|
74
|
-
currency,
|
|
75
|
-
derivationMode: derivationMode || "",
|
|
76
|
-
});
|
|
62
|
+
const keypair = await getKeypair(signerContext, deviceId, derivationPath);
|
|
77
63
|
|
|
78
64
|
observer.next({
|
|
79
65
|
status: OnboardStatus.PREPARE,
|
|
80
66
|
});
|
|
81
67
|
|
|
82
|
-
const
|
|
83
|
-
if (
|
|
84
|
-
const account = await createAccount({
|
|
85
|
-
address,
|
|
86
|
-
derivationPath,
|
|
87
|
-
partyId,
|
|
88
|
-
currency,
|
|
89
|
-
derivationMode,
|
|
90
|
-
});
|
|
68
|
+
const isOnboardedResult = await isAccountOnboarded(keypair.publicKey);
|
|
69
|
+
if (isOnboardedResult && isOnboardedResult.party_id) {
|
|
91
70
|
observer.next({
|
|
92
|
-
partyId,
|
|
93
|
-
account,
|
|
71
|
+
partyId: isOnboardedResult.party_id,
|
|
94
72
|
});
|
|
95
73
|
observer.complete();
|
|
96
74
|
return;
|
|
97
75
|
}
|
|
98
76
|
|
|
99
|
-
const preparedTransaction = await prepareOnboarding(
|
|
77
|
+
const preparedTransaction = await prepareOnboarding(keypair.publicKey, "ed25519");
|
|
100
78
|
|
|
101
79
|
observer.next({
|
|
102
80
|
status: OnboardStatus.SIGN,
|
|
@@ -111,44 +89,26 @@ export const buildOnboardAccount =
|
|
|
111
89
|
});
|
|
112
90
|
|
|
113
91
|
const result = await submitOnboarding(
|
|
114
|
-
|
|
115
|
-
{ public_key: publicKey, public_key_type: "ed25519" },
|
|
92
|
+
{ public_key: keypair.publicKey, public_key_type: "ed25519" },
|
|
116
93
|
preparedTransaction,
|
|
117
94
|
signature,
|
|
118
|
-
).catch(
|
|
95
|
+
).catch(err => {
|
|
119
96
|
if (err.type === "PARTY_ALREADY_EXISTS") {
|
|
120
|
-
const account = await createAccount({
|
|
121
|
-
address,
|
|
122
|
-
derivationPath,
|
|
123
|
-
partyId: preparedTransaction.party_id,
|
|
124
|
-
currency,
|
|
125
|
-
derivationMode,
|
|
126
|
-
});
|
|
127
97
|
observer.next({
|
|
128
98
|
partyId: preparedTransaction.party_id,
|
|
129
|
-
account,
|
|
130
99
|
});
|
|
131
100
|
return observer.complete();
|
|
132
101
|
}
|
|
133
102
|
throw err;
|
|
134
103
|
});
|
|
135
104
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
partyId: result.party.party_id,
|
|
144
|
-
currency,
|
|
145
|
-
derivationMode,
|
|
146
|
-
});
|
|
147
|
-
observer.next({
|
|
148
|
-
partyId: result.party.party_id,
|
|
149
|
-
account,
|
|
150
|
-
});
|
|
151
|
-
}
|
|
105
|
+
observer.next({
|
|
106
|
+
status: OnboardStatus.SUCCESS,
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
observer.next({
|
|
110
|
+
partyId: result?.party?.party_id || "unknown",
|
|
111
|
+
});
|
|
152
112
|
|
|
153
113
|
observer.complete();
|
|
154
114
|
}
|
|
@@ -165,7 +125,6 @@ export const buildOnboardAccount =
|
|
|
165
125
|
export const buildAuthorizePreapproval =
|
|
166
126
|
(signerContext: SignerContext<CantonSigner>) =>
|
|
167
127
|
(
|
|
168
|
-
currency: CryptoCurrency,
|
|
169
128
|
deviceId: string,
|
|
170
129
|
derivationPath: string,
|
|
171
130
|
partyId: string,
|
|
@@ -176,10 +135,8 @@ export const buildAuthorizePreapproval =
|
|
|
176
135
|
status: PreApprovalStatus.PREPARE,
|
|
177
136
|
});
|
|
178
137
|
|
|
179
|
-
const preparedTransaction: PrepareTransactionResponse =
|
|
180
|
-
|
|
181
|
-
partyId,
|
|
182
|
-
);
|
|
138
|
+
const preparedTransaction: PrepareTransactionResponse =
|
|
139
|
+
await preparePreApprovalTransaction(partyId);
|
|
183
140
|
|
|
184
141
|
observer.next({
|
|
185
142
|
status: PreApprovalStatus.SIGN,
|
|
@@ -194,7 +151,6 @@ export const buildAuthorizePreapproval =
|
|
|
194
151
|
});
|
|
195
152
|
|
|
196
153
|
const { isApproved } = await submitPreApprovalTransaction(
|
|
197
|
-
currency,
|
|
198
154
|
partyId,
|
|
199
155
|
preparedTransaction,
|
|
200
156
|
signature,
|
|
@@ -208,35 +164,38 @@ export const buildAuthorizePreapproval =
|
|
|
208
164
|
isApproved,
|
|
209
165
|
});
|
|
210
166
|
|
|
167
|
+
// TODO: remove after demo
|
|
211
168
|
const handleTapRequest = async () => {
|
|
212
169
|
try {
|
|
213
|
-
|
|
170
|
+
observer.next({
|
|
171
|
+
status: PreApprovalStatus.PREPARE,
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
const { serialized, hash } = await prepareTapRequest({
|
|
175
|
+
partyId,
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
observer.next({
|
|
179
|
+
status: PreApprovalStatus.SIGN,
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
const signature = await signerContext(deviceId, signer =>
|
|
183
|
+
signer.signTransaction(derivationPath, hash),
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
observer.next({
|
|
187
|
+
status: PreApprovalStatus.SUBMIT,
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
await submitTapRequest({
|
|
214
191
|
partyId,
|
|
192
|
+
serialized,
|
|
193
|
+
signature,
|
|
215
194
|
});
|
|
216
195
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
const signature = await signerContext(deviceId, signer =>
|
|
223
|
-
signer.signTransaction(derivationPath, hash),
|
|
224
|
-
);
|
|
225
|
-
|
|
226
|
-
observer.next({
|
|
227
|
-
status: PreApprovalStatus.SUBMIT,
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
await submitTapRequest(currency, {
|
|
231
|
-
partyId,
|
|
232
|
-
serialized,
|
|
233
|
-
signature,
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
observer.next({
|
|
237
|
-
status: PreApprovalStatus.SUCCESS,
|
|
238
|
-
});
|
|
239
|
-
}
|
|
196
|
+
observer.next({
|
|
197
|
+
status: PreApprovalStatus.SUCCESS,
|
|
198
|
+
});
|
|
240
199
|
} catch (err) {
|
|
241
200
|
// Tap request failure should not break the pre-approval flow
|
|
242
201
|
}
|
|
@@ -255,58 +214,7 @@ export const buildAuthorizePreapproval =
|
|
|
255
214
|
);
|
|
256
215
|
});
|
|
257
216
|
|
|
258
|
-
const
|
|
259
|
-
address,
|
|
260
|
-
partyId,
|
|
261
|
-
derivationPath,
|
|
262
|
-
currency,
|
|
263
|
-
derivationMode,
|
|
264
|
-
index = 0,
|
|
265
|
-
}: {
|
|
266
|
-
address: string;
|
|
267
|
-
derivationPath: string;
|
|
268
|
-
partyId: string;
|
|
269
|
-
currency: CryptoCurrency;
|
|
270
|
-
derivationMode: DerivationMode;
|
|
271
|
-
index?: number;
|
|
272
|
-
}): Promise<Partial<Account>> => {
|
|
273
|
-
const accountShape = await getAccountShape(
|
|
274
|
-
{
|
|
275
|
-
address,
|
|
276
|
-
currency,
|
|
277
|
-
derivationMode,
|
|
278
|
-
derivationPath,
|
|
279
|
-
index,
|
|
280
|
-
rest: {
|
|
281
|
-
cantonResources: {
|
|
282
|
-
partyId,
|
|
283
|
-
},
|
|
284
|
-
},
|
|
285
|
-
},
|
|
286
|
-
{ paginationConfig: {} },
|
|
287
|
-
);
|
|
288
|
-
|
|
289
|
-
const account: Partial<CantonAccount> = {
|
|
290
|
-
...accountShape,
|
|
291
|
-
type: "Account",
|
|
292
|
-
xpub: partyId.replace(/:/g, "_"),
|
|
293
|
-
index,
|
|
294
|
-
// operations: [],
|
|
295
|
-
currency,
|
|
296
|
-
derivationMode,
|
|
297
|
-
lastSyncDate: new Date(),
|
|
298
|
-
pendingOperations: [],
|
|
299
|
-
seedIdentifier: address,
|
|
300
|
-
balanceHistoryCache: emptyHistoryCache,
|
|
301
|
-
cantonResources: {
|
|
302
|
-
partyId,
|
|
303
|
-
},
|
|
304
|
-
};
|
|
305
|
-
|
|
306
|
-
return account;
|
|
307
|
-
};
|
|
308
|
-
|
|
309
|
-
const log = (message: string, ...rest: unknown[]) => {
|
|
217
|
+
const log = (message: string, ...rest: any[]) => {
|
|
310
218
|
// eslint-disable-next-line no-console
|
|
311
219
|
console.log(message, ...rest);
|
|
312
220
|
};
|
|
@@ -1,16 +1,25 @@
|
|
|
1
1
|
import { AccountBridge } from "@ledgerhq/types-live";
|
|
2
2
|
import { Transaction } from "../types";
|
|
3
|
-
import { estimateFees } from "../common-logic";
|
|
3
|
+
import { craftTransaction, estimateFees } from "../common-logic";
|
|
4
|
+
import { getNextSequence } from "../network/node";
|
|
4
5
|
import BigNumber from "bignumber.js";
|
|
5
|
-
import { updateTransaction } from "./updateTransaction";
|
|
6
6
|
|
|
7
7
|
export const prepareTransaction: AccountBridge<Transaction>["prepareTransaction"] = async (
|
|
8
8
|
account,
|
|
9
9
|
transaction,
|
|
10
10
|
) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
const seq = await getNextSequence(account.freshAddress);
|
|
12
|
+
|
|
13
|
+
const craftedTransaction = await craftTransaction(
|
|
14
|
+
{ address: account.freshAddress, nextSequenceNumber: seq },
|
|
15
|
+
{ amount: transaction.amount, recipient: transaction.recipient },
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
const fee = await estimateFees(craftedTransaction.serializedTransaction);
|
|
19
|
+
|
|
20
|
+
if (transaction.fee !== new BigNumber(fee.toString())) {
|
|
21
|
+
return { ...transaction, fee: new BigNumber(fee.toString()) };
|
|
14
22
|
}
|
|
15
|
-
|
|
23
|
+
|
|
24
|
+
return transaction;
|
|
16
25
|
};
|