@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
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { Observable } from "rxjs";
|
|
2
|
-
import BigNumber from "bignumber.js";
|
|
3
2
|
import { FeeNotLoaded } from "@ledgerhq/errors";
|
|
4
3
|
import { AccountBridge, Operation } from "@ledgerhq/types-live";
|
|
5
4
|
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
6
5
|
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
7
|
-
import { combine, craftTransaction } from "../common-logic";
|
|
8
|
-
import { Transaction, CantonSigner } from "../types";
|
|
6
|
+
import { combine, craftTransaction, getNextValidSequence } from "../common-logic";
|
|
7
|
+
import { Transaction, CantonSigner, BoilerplateNativeTransaction } from "../types";
|
|
9
8
|
|
|
10
9
|
export const buildSignOperation =
|
|
11
10
|
(signerContext: SignerContext<CantonSigner>): AccountBridge<Transaction>["signOperation"] =>
|
|
@@ -21,36 +20,30 @@ export const buildSignOperation =
|
|
|
21
20
|
type: "device-signature-requested",
|
|
22
21
|
});
|
|
23
22
|
|
|
23
|
+
const nextSequenceNumber = await getNextValidSequence(account.freshAddress);
|
|
24
|
+
|
|
24
25
|
const signature = await signerContext(deviceId, async signer => {
|
|
25
26
|
const { freshAddressPath: derivationPath } = account;
|
|
26
|
-
const
|
|
27
|
-
.cantonResources.partyId;
|
|
28
|
-
const params: {
|
|
29
|
-
recipient?: string;
|
|
30
|
-
amount: BigNumber;
|
|
31
|
-
tokenId: string;
|
|
32
|
-
expireInSeconds: number;
|
|
33
|
-
memo?: string;
|
|
34
|
-
} = {
|
|
35
|
-
recipient: transaction.recipient,
|
|
36
|
-
amount: transaction.amount,
|
|
37
|
-
expireInSeconds: 60 * 60,
|
|
38
|
-
tokenId: "Amulet",
|
|
39
|
-
};
|
|
40
|
-
if (transaction.memo) {
|
|
41
|
-
params.memo = transaction.memo;
|
|
42
|
-
}
|
|
27
|
+
const { publicKey } = await signer.getAddress(derivationPath);
|
|
43
28
|
|
|
44
|
-
const {
|
|
45
|
-
|
|
29
|
+
const { nativeTransaction, serializedTransaction } = await craftTransaction(
|
|
30
|
+
{
|
|
31
|
+
address: account.freshAddress,
|
|
32
|
+
publicKey,
|
|
33
|
+
},
|
|
46
34
|
{
|
|
47
|
-
|
|
35
|
+
recipient: transaction.recipient,
|
|
36
|
+
amount: transaction.amount,
|
|
37
|
+
fee: fee,
|
|
48
38
|
},
|
|
49
|
-
params,
|
|
50
39
|
);
|
|
51
|
-
const transactionSignature = await signer.signTransaction(derivationPath, hash);
|
|
52
40
|
|
|
53
|
-
|
|
41
|
+
const transactionSignature = await signer.signTransaction(
|
|
42
|
+
derivationPath,
|
|
43
|
+
serializedTransaction,
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
return combine(serializedTransaction, transactionSignature);
|
|
54
47
|
});
|
|
55
48
|
|
|
56
49
|
o.next({
|
|
@@ -71,6 +64,7 @@ export const buildSignOperation =
|
|
|
71
64
|
senders: [account.freshAddress],
|
|
72
65
|
recipients: [transaction.recipient],
|
|
73
66
|
date: new Date(),
|
|
67
|
+
transactionSequenceNumber: nextSequenceNumber,
|
|
74
68
|
extra: {},
|
|
75
69
|
};
|
|
76
70
|
|
package/src/bridge/sync.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import BigNumber from "bignumber.js";
|
|
2
|
-
import { Operation
|
|
3
|
-
import {
|
|
2
|
+
import { Operation } from "@ledgerhq/types-live";
|
|
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,
|
|
@@ -18,17 +18,12 @@ const txInfoToOperationAdapter =
|
|
|
18
18
|
recipients,
|
|
19
19
|
transaction_timestamp,
|
|
20
20
|
fee: { value: fee },
|
|
21
|
-
transfers: [{ value: transferValue
|
|
21
|
+
transfers: [{ value: transferValue }],
|
|
22
22
|
} = txInfo;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
type = senders.includes(partyId) ? "OUT" : "IN";
|
|
26
|
-
} else if (txInfo.type === "Receive") {
|
|
27
|
-
type = "IN";
|
|
28
|
-
}
|
|
23
|
+
|
|
24
|
+
const type = senders.includes(address) ? "OUT" : "IN";
|
|
29
25
|
const value = new BigNumber(transferValue);
|
|
30
26
|
const feeValue = new BigNumber(fee);
|
|
31
|
-
const memo = details.metadata.reason;
|
|
32
27
|
|
|
33
28
|
const op: Operation = {
|
|
34
29
|
id: encodeOperationId(accountId, transaction_hash, type),
|
|
@@ -45,7 +40,6 @@ const txInfoToOperationAdapter =
|
|
|
45
40
|
transactionSequenceNumber: height,
|
|
46
41
|
extra: {
|
|
47
42
|
uid,
|
|
48
|
-
memo,
|
|
49
43
|
},
|
|
50
44
|
};
|
|
51
45
|
|
|
@@ -55,60 +49,45 @@ const txInfoToOperationAdapter =
|
|
|
55
49
|
const filterOperations = (
|
|
56
50
|
transactions: OperationInfo[],
|
|
57
51
|
accountId: string,
|
|
58
|
-
|
|
52
|
+
address: string,
|
|
59
53
|
): Operation[] => {
|
|
60
|
-
return transactions
|
|
54
|
+
return transactions
|
|
55
|
+
.filter(tx => tx.type === "Receive" || tx.type === "Send")
|
|
56
|
+
.map(txInfoToOperationAdapter(accountId, address));
|
|
61
57
|
};
|
|
62
58
|
|
|
63
|
-
export const getAccountShape: GetAccountShape
|
|
64
|
-
const { address, initialAccount, currency, derivationMode
|
|
65
|
-
|
|
66
|
-
const xpubOrAddress = (
|
|
67
|
-
(initialAccount && initialAccount.id && decodeAccountId(initialAccount.id).xpubOrAddress) ||
|
|
68
|
-
""
|
|
69
|
-
).replace(/:/g, "_");
|
|
70
|
-
const partyId =
|
|
71
|
-
rest?.cantonResources?.partyId ||
|
|
72
|
-
initialAccount?.cantonResources?.partyId ||
|
|
73
|
-
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, "_") || "";
|
|
74
63
|
|
|
75
64
|
const accountId = encodeAccountId({
|
|
76
65
|
type: "js",
|
|
77
66
|
version: "2",
|
|
78
67
|
currencyId: currency.id,
|
|
79
68
|
xpubOrAddress,
|
|
80
|
-
derivationMode,
|
|
69
|
+
derivationMode: "",
|
|
81
70
|
});
|
|
82
71
|
|
|
72
|
+
// blockheight retrieval
|
|
73
|
+
const blockHeight = await getLedgerEnd();
|
|
74
|
+
|
|
83
75
|
// Account info retrieval + spendable balance calculation
|
|
84
76
|
// const accountInfo = await getAccountInfo(address);
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
amount: 0,
|
|
90
|
-
locked: false,
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
const balance = new BigNumber(balanceData.amount);
|
|
94
|
-
const reserveMin = coinConfig.getCoinConfig(currency).minReserve || 0;
|
|
95
|
-
const lockedAmount = balanceData.locked ? balance : new BigNumber(0);
|
|
96
|
-
const spendableBalance = BigNumber.max(
|
|
97
|
-
0,
|
|
98
|
-
balance.minus(lockedAmount).minus(BigNumber(reserveMin)),
|
|
99
|
-
);
|
|
77
|
+
const balanceData = await getBalance(address);
|
|
78
|
+
const balance = new BigNumber(balanceData[0]?.amount || "0");
|
|
79
|
+
const reserveMin = coinConfig.getCoinConfig().minReserve || 0;
|
|
80
|
+
const spendableBalance = balance.minus(BigNumber(reserveMin));
|
|
100
81
|
|
|
101
82
|
// Tx history fetching
|
|
102
83
|
const oldOperations = initialAccount?.operations || [];
|
|
103
84
|
const startAt = oldOperations.length ? (oldOperations[0].blockHeight || 0) + 1 : 0;
|
|
104
|
-
const transactionData = await getOperations(
|
|
105
|
-
cursor:
|
|
85
|
+
const transactionData = await getOperations(address, {
|
|
86
|
+
cursor: 0,
|
|
106
87
|
limit: 100,
|
|
107
88
|
});
|
|
108
|
-
// blockheight retrieval
|
|
109
|
-
const blockHeight = await getLedgerEnd(currency);
|
|
110
89
|
|
|
111
|
-
const newOperations = filterOperations(transactionData.operations, accountId,
|
|
90
|
+
const newOperations = filterOperations(transactionData.operations, accountId, address);
|
|
112
91
|
const operations = mergeOps(oldOperations, newOperations);
|
|
113
92
|
|
|
114
93
|
// We return the new account shape
|
|
@@ -120,11 +99,6 @@ export const getAccountShape: GetAccountShape<CantonAccount> = async info => {
|
|
|
120
99
|
spendableBalance,
|
|
121
100
|
operations,
|
|
122
101
|
operationsCount: operations.length,
|
|
123
|
-
freshAddress: address,
|
|
124
|
-
freshAddressPath: derivationPath,
|
|
125
|
-
cantonResources: {
|
|
126
|
-
partyId,
|
|
127
|
-
},
|
|
128
102
|
};
|
|
129
103
|
|
|
130
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
|
};
|
|
@@ -1,28 +1,23 @@
|
|
|
1
1
|
import { Balance } from "@ledgerhq/coin-framework/api/types";
|
|
2
2
|
import { getBalance as gatewayGetBalance, type InstrumentBalance } from "../../network/gateway";
|
|
3
3
|
import coinConfig from "../../config";
|
|
4
|
-
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
5
4
|
|
|
6
|
-
const useGateway = (
|
|
7
|
-
|
|
8
|
-
const getNativeId = (currency: CryptoCurrency) =>
|
|
9
|
-
coinConfig.getCoinConfig(currency).nativeInstrumentId;
|
|
5
|
+
const useGateway = () => coinConfig.getCoinConfig().useGateway === true;
|
|
6
|
+
const getNativeId = () => coinConfig.getCoinConfig().nativeInstrumentId;
|
|
10
7
|
|
|
11
|
-
function adaptInstrument(
|
|
8
|
+
function adaptInstrument(instrument: InstrumentBalance): Balance {
|
|
12
9
|
return {
|
|
13
10
|
value: BigInt(instrument.amount),
|
|
14
11
|
locked: instrument.locked === true ? BigInt(instrument.amount) : BigInt(0),
|
|
15
12
|
asset:
|
|
16
|
-
getNativeId(
|
|
13
|
+
getNativeId() === instrument.instrument_id
|
|
17
14
|
? { type: "native" }
|
|
18
15
|
: { type: "token", assetReference: instrument.instrument_id },
|
|
19
16
|
};
|
|
20
17
|
}
|
|
21
18
|
|
|
22
|
-
export async function getBalance(
|
|
23
|
-
if (useGateway(
|
|
24
|
-
return (await gatewayGetBalance(
|
|
25
|
-
adaptInstrument(currency, instrument),
|
|
26
|
-
);
|
|
19
|
+
export async function getBalance(partyId: string): Promise<Balance[]> {
|
|
20
|
+
if (useGateway())
|
|
21
|
+
return (await gatewayGetBalance(partyId)).map(instrument => adaptInstrument(instrument));
|
|
27
22
|
else throw new Error("Not implemented");
|
|
28
23
|
}
|
|
@@ -2,11 +2,6 @@ import { getBalance as getBalanceFromNetwork } from "../../network/gateway";
|
|
|
2
2
|
import * as coinConfigModule from "../../config";
|
|
3
3
|
import { getBalance } from "./getBalance";
|
|
4
4
|
import { Balance } from "@ledgerhq/coin-framework/api/types";
|
|
5
|
-
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
6
|
-
|
|
7
|
-
const mockCurrency = {
|
|
8
|
-
id: "canton_network",
|
|
9
|
-
} as unknown as CryptoCurrency;
|
|
10
5
|
|
|
11
6
|
jest.mock("../../network/gateway", () => ({
|
|
12
7
|
getBalance: jest.fn(),
|
|
@@ -40,9 +35,9 @@ describe("getBalance", () => {
|
|
|
40
35
|
|
|
41
36
|
(getBalanceFromNetwork as jest.Mock).mockResolvedValue(mockInstruments);
|
|
42
37
|
|
|
43
|
-
const result = await getBalance(
|
|
38
|
+
const result = await getBalance("party-id");
|
|
44
39
|
|
|
45
|
-
expect(getBalanceFromNetwork).toHaveBeenCalledWith(
|
|
40
|
+
expect(getBalanceFromNetwork).toHaveBeenCalledWith("party-id");
|
|
46
41
|
expect(result).toEqual<Balance[]>([
|
|
47
42
|
{
|
|
48
43
|
value: BigInt(1000),
|
|
@@ -62,7 +57,7 @@ describe("getBalance", () => {
|
|
|
62
57
|
useGateway: false,
|
|
63
58
|
} as any);
|
|
64
59
|
|
|
65
|
-
await expect(getBalance(
|
|
60
|
+
await expect(getBalance("party-id")).rejects.toThrow("Not implemented");
|
|
66
61
|
expect(getBalanceFromNetwork).not.toHaveBeenCalled();
|
|
67
62
|
});
|
|
68
63
|
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { lastBlock } from "./lastBlock";
|
|
2
2
|
import { getLedgerEnd as gatewayGetLedgerEnd } from "../../network/gateway";
|
|
3
3
|
import { getLedgerEnd as nodeGetLedgerEnd } from "../../network/node";
|
|
4
|
-
import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
5
4
|
|
|
6
5
|
jest.mock("../../network/gateway", () => ({
|
|
7
6
|
getLedgerEnd: jest.fn(),
|
|
@@ -19,10 +18,6 @@ jest.mock("../../config", () => ({
|
|
|
19
18
|
|
|
20
19
|
import coinConfig from "../../config";
|
|
21
20
|
|
|
22
|
-
const mockCurrency = {
|
|
23
|
-
id: "canton_network",
|
|
24
|
-
} as unknown as CryptoCurrency;
|
|
25
|
-
|
|
26
21
|
describe("lastBlock", () => {
|
|
27
22
|
beforeEach(() => {
|
|
28
23
|
jest.clearAllMocks();
|
|
@@ -32,7 +27,7 @@ describe("lastBlock", () => {
|
|
|
32
27
|
(coinConfig.getCoinConfig as jest.Mock).mockReturnValue({ useGateway: true });
|
|
33
28
|
(gatewayGetLedgerEnd as jest.Mock).mockResolvedValue(100);
|
|
34
29
|
|
|
35
|
-
const result = await lastBlock(
|
|
30
|
+
const result = await lastBlock();
|
|
36
31
|
|
|
37
32
|
expect(result).toEqual({ height: 100 });
|
|
38
33
|
expect(gatewayGetLedgerEnd).toHaveBeenCalledTimes(1);
|
|
@@ -43,7 +38,7 @@ describe("lastBlock", () => {
|
|
|
43
38
|
(coinConfig.getCoinConfig as jest.Mock).mockReturnValue({ useGateway: false });
|
|
44
39
|
(nodeGetLedgerEnd as jest.Mock).mockResolvedValue(200);
|
|
45
40
|
|
|
46
|
-
const result = await lastBlock(
|
|
41
|
+
const result = await lastBlock();
|
|
47
42
|
|
|
48
43
|
expect(result).toEqual({ height: 200 });
|
|
49
44
|
expect(nodeGetLedgerEnd).toHaveBeenCalledTimes(1);
|
|
@@ -2,13 +2,11 @@ import type { BlockInfo } from "@ledgerhq/coin-framework/api/index";
|
|
|
2
2
|
import { getLedgerEnd as nodeGetLedgerEnd } from "../../network/node";
|
|
3
3
|
import { getLedgerEnd } from "../../network/gateway";
|
|
4
4
|
import coinConfig from "../../config";
|
|
5
|
-
import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
6
5
|
|
|
7
|
-
const useGateway = (
|
|
8
|
-
coinConfig.getCoinConfig(currency).useGateway === true;
|
|
6
|
+
const useGateway = () => coinConfig.getCoinConfig().useGateway === true;
|
|
9
7
|
|
|
10
|
-
export async function lastBlock(
|
|
8
|
+
export async function lastBlock(): Promise<BlockInfo> {
|
|
11
9
|
return {
|
|
12
|
-
height: useGateway(
|
|
10
|
+
height: useGateway() ? await getLedgerEnd() : await nodeGetLedgerEnd(),
|
|
13
11
|
};
|
|
14
12
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Operation, Pagination } from "@ledgerhq/coin-framework/api/index";
|
|
2
2
|
import { getOperations } from "../../network/gateway";
|
|
3
|
-
import
|
|
3
|
+
import coinConfig from "../../config";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Returns list of operations associated to an account.
|
|
@@ -10,11 +10,10 @@ import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
|
10
10
|
* Impl to finalize when backend is ready
|
|
11
11
|
*/
|
|
12
12
|
export async function listOperations(
|
|
13
|
-
currency: CryptoCurrency,
|
|
14
13
|
partyId: string,
|
|
15
14
|
page: Pagination,
|
|
16
15
|
): Promise<[Operation[], string]> {
|
|
17
|
-
const { operations, next } = await getOperations(
|
|
16
|
+
const { operations, next } = await getOperations(partyId, {
|
|
18
17
|
cursor: page.pagingToken !== undefined ? parseInt(page.pagingToken) : undefined,
|
|
19
18
|
minOffset: page.minHeight,
|
|
20
19
|
limit: page.limit,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { submit } from "../../network/gateway";
|
|
2
2
|
import * as coinConfigModule from "../../config";
|
|
3
3
|
import { broadcast } from "./broadcast";
|
|
4
|
-
import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
5
4
|
|
|
6
5
|
jest.mock("../../network/gateway", () => ({
|
|
7
6
|
submit: jest.fn(),
|
|
@@ -9,13 +8,9 @@ jest.mock("../../network/gateway", () => ({
|
|
|
9
8
|
|
|
10
9
|
const mockSerialized = JSON.stringify({
|
|
11
10
|
serialized: "serialized-tx",
|
|
12
|
-
signature: "
|
|
11
|
+
signature: "signature",
|
|
13
12
|
});
|
|
14
13
|
|
|
15
|
-
const mockCurrency = {
|
|
16
|
-
id: "canton_network",
|
|
17
|
-
} as unknown as CryptoCurrency;
|
|
18
|
-
|
|
19
14
|
describe("broadcast", () => {
|
|
20
15
|
const mockGetCoinConfig = jest.spyOn(coinConfigModule.default, "getCoinConfig");
|
|
21
16
|
|
|
@@ -28,11 +23,11 @@ describe("broadcast", () => {
|
|
|
28
23
|
useGateway: true,
|
|
29
24
|
} as any);
|
|
30
25
|
|
|
31
|
-
(submit as jest.Mock).mockResolvedValue({
|
|
26
|
+
(submit as jest.Mock).mockResolvedValue({ updateId: "my-update-id" });
|
|
32
27
|
|
|
33
|
-
const result = await broadcast(
|
|
28
|
+
const result = await broadcast(mockSerialized);
|
|
34
29
|
|
|
35
|
-
expect(submit).toHaveBeenCalledWith(
|
|
30
|
+
expect(submit).toHaveBeenCalledWith("serialized-tx", "signature");
|
|
36
31
|
expect(result).toEqual("my-update-id");
|
|
37
32
|
});
|
|
38
33
|
|
|
@@ -41,7 +36,7 @@ describe("broadcast", () => {
|
|
|
41
36
|
useGateway: false,
|
|
42
37
|
} as any);
|
|
43
38
|
|
|
44
|
-
await expect(broadcast(
|
|
39
|
+
await expect(broadcast(mockSerialized)).rejects.toThrow("Not implemented");
|
|
45
40
|
expect(submit).not.toHaveBeenCalled();
|
|
46
41
|
});
|
|
47
42
|
});
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import coinConfig from "../../config";
|
|
2
2
|
import { submit } from "../../network/gateway";
|
|
3
|
-
import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
4
3
|
|
|
5
|
-
const useGateway = (
|
|
6
|
-
coinConfig.getCoinConfig(currency).useGateway === true;
|
|
4
|
+
const useGateway = () => coinConfig.getCoinConfig().useGateway === true;
|
|
7
5
|
|
|
8
|
-
export async function broadcast(
|
|
6
|
+
export async function broadcast(signedTx: string): Promise<string> {
|
|
9
7
|
const parsed: { serialized: string; signature: string } = JSON.parse(signedTx);
|
|
10
|
-
|
|
11
|
-
if (useGateway(currency))
|
|
12
|
-
return (await submit(currency, party, parsed.serialized, sig)).update_id;
|
|
8
|
+
if (useGateway()) return (await submit(parsed.serialized, parsed.signature)).updateId;
|
|
13
9
|
else throw new Error("Not implemented");
|
|
14
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,13 +1,9 @@
|
|
|
1
1
|
import BigNumber from "bignumber.js";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
PrepareTransferResponse,
|
|
6
|
-
} from "../../network/gateway";
|
|
7
|
-
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
2
|
+
import { BoilerplateNativeTransaction } from "../../types";
|
|
3
|
+
|
|
4
|
+
const encodeNativeTx = (nativeTx: BoilerplateNativeTransaction) => JSON.stringify(nativeTx);
|
|
8
5
|
|
|
9
6
|
export async function craftTransaction(
|
|
10
|
-
currency: CryptoCurrency,
|
|
11
7
|
account: {
|
|
12
8
|
address: string;
|
|
13
9
|
nextSequenceNumber?: number;
|
|
@@ -16,36 +12,25 @@ export async function craftTransaction(
|
|
|
16
12
|
transaction: {
|
|
17
13
|
recipient?: string;
|
|
18
14
|
amount: BigNumber;
|
|
19
|
-
|
|
20
|
-
expireInSeconds: number;
|
|
21
|
-
memo?: string;
|
|
15
|
+
fee?: BigNumber;
|
|
22
16
|
},
|
|
23
17
|
): Promise<{
|
|
24
|
-
nativeTransaction:
|
|
18
|
+
nativeTransaction: BoilerplateNativeTransaction;
|
|
25
19
|
serializedTransaction: string;
|
|
26
|
-
hash: string;
|
|
27
20
|
}> {
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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,
|
|
34
28
|
};
|
|
35
29
|
|
|
36
|
-
|
|
37
|
-
params.reason = transaction.memo;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const { serialized, json, hash } = await prepareTransferRequest(
|
|
41
|
-
currency,
|
|
42
|
-
account.address,
|
|
43
|
-
params,
|
|
44
|
-
);
|
|
30
|
+
const serializedTransaction = encodeNativeTx(nativeTransaction);
|
|
45
31
|
|
|
46
32
|
return {
|
|
47
|
-
nativeTransaction
|
|
48
|
-
serializedTransaction
|
|
49
|
-
hash,
|
|
33
|
+
nativeTransaction,
|
|
34
|
+
serializedTransaction,
|
|
50
35
|
};
|
|
51
36
|
}
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const feeValue = (currency: CryptoCurrency) => coinConfig.getCoinConfig(currency).fee ?? 1;
|
|
5
|
-
|
|
6
|
-
export async function estimateFees(currency: CryptoCurrency): Promise<bigint> {
|
|
7
|
-
return Promise.resolve(BigInt(feeValue(currency)));
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2
|
+
export async function estimateFees(serializedTransaction: string): Promise<bigint> {
|
|
3
|
+
return Promise.resolve(BigInt(10_000)); // TODO replace with real implementation
|
|
8
4
|
}
|