@ledgerhq/coin-filecoin 1.3.2
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 +4 -0
- package/.unimportedrc.json +21 -0
- package/CHANGELOG.md +19 -0
- package/LICENSE.txt +21 -0
- package/jest.config.js +8 -0
- package/lib/api/api.d.ts +9 -0
- package/lib/api/api.d.ts.map +1 -0
- package/lib/api/api.js +99 -0
- package/lib/api/api.js.map +1 -0
- package/lib/api/index.d.ts +2 -0
- package/lib/api/index.d.ts.map +1 -0
- package/lib/api/index.js +18 -0
- package/lib/api/index.js.map +1 -0
- package/lib/bridge/broadcast.d.ts +4 -0
- package/lib/bridge/broadcast.d.ts.map +1 -0
- package/lib/bridge/broadcast.js +27 -0
- package/lib/bridge/broadcast.js.map +1 -0
- package/lib/bridge/buildOptimisticOperation.d.ts +5 -0
- package/lib/bridge/buildOptimisticOperation.d.ts.map +1 -0
- package/lib/bridge/buildOptimisticOperation.js +62 -0
- package/lib/bridge/buildOptimisticOperation.js.map +1 -0
- package/lib/bridge/createTransaction.d.ts +4 -0
- package/lib/bridge/createTransaction.d.ts.map +1 -0
- package/lib/bridge/createTransaction.js +24 -0
- package/lib/bridge/createTransaction.js.map +1 -0
- package/lib/bridge/deviceTransactionConfig.d.ts +33 -0
- package/lib/bridge/deviceTransactionConfig.d.ts.map +1 -0
- package/lib/bridge/deviceTransactionConfig.js +71 -0
- package/lib/bridge/deviceTransactionConfig.js.map +1 -0
- package/lib/bridge/estimateMaxSpendable.d.ts +4 -0
- package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -0
- package/lib/bridge/estimateMaxSpendable.js +100 -0
- package/lib/bridge/estimateMaxSpendable.js.map +1 -0
- package/lib/bridge/getTransactionStatus.d.ts +4 -0
- package/lib/bridge/getTransactionStatus.d.ts.map +1 -0
- package/lib/bridge/getTransactionStatus.js +84 -0
- package/lib/bridge/getTransactionStatus.js.map +1 -0
- package/lib/bridge/index.d.ts +8 -0
- package/lib/bridge/index.d.ts.map +1 -0
- package/lib/bridge/index.js +54 -0
- package/lib/bridge/index.js.map +1 -0
- package/lib/bridge/prepareTransaction.d.ts +4 -0
- package/lib/bridge/prepareTransaction.d.ts.map +1 -0
- package/lib/bridge/prepareTransaction.js +75 -0
- package/lib/bridge/prepareTransaction.js.map +1 -0
- package/lib/bridge/serializer.d.ts +13 -0
- package/lib/bridge/serializer.d.ts.map +1 -0
- package/lib/bridge/serializer.js +65 -0
- package/lib/bridge/serializer.js.map +1 -0
- package/lib/bridge/signOperation.d.ts +5 -0
- package/lib/bridge/signOperation.d.ts.map +1 -0
- package/lib/bridge/signOperation.js +80 -0
- package/lib/bridge/signOperation.js.map +1 -0
- package/lib/bridge/transaction.d.ts +14 -0
- package/lib/bridge/transaction.d.ts.map +1 -0
- package/lib/bridge/transaction.js +41 -0
- package/lib/bridge/transaction.js.map +1 -0
- package/lib/bridge/utils.d.ts +26 -0
- package/lib/bridge/utils.d.ts.map +1 -0
- package/lib/bridge/utils.js +67 -0
- package/lib/bridge/utils.js.map +1 -0
- package/lib/bridge/utils.unit.test.d.ts +2 -0
- package/lib/bridge/utils.unit.test.d.ts.map +1 -0
- package/lib/bridge/utils.unit.test.js +23 -0
- package/lib/bridge/utils.unit.test.js.map +1 -0
- package/lib/common-logic/index.d.ts +2 -0
- package/lib/common-logic/index.d.ts.map +1 -0
- package/lib/common-logic/index.js +13 -0
- package/lib/common-logic/index.js.map +1 -0
- package/lib/common-logic/utils.d.ts +22 -0
- package/lib/common-logic/utils.d.ts.map +1 -0
- package/lib/common-logic/utils.js +189 -0
- package/lib/common-logic/utils.js.map +1 -0
- package/lib/erc20/ERC20.json +12 -0
- package/lib/erc20/tokenAccounts.d.ts +10 -0
- package/lib/erc20/tokenAccounts.d.ts.map +1 -0
- package/lib/erc20/tokenAccounts.js +169 -0
- package/lib/erc20/tokenAccounts.js.map +1 -0
- package/lib/errors.d.ts +7 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +13 -0
- package/lib/errors.js.map +1 -0
- package/lib/hw-signMessage.d.ts +12 -0
- package/lib/hw-signMessage.d.ts.map +1 -0
- package/lib/hw-signMessage.js +32 -0
- package/lib/hw-signMessage.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +6 -0
- package/lib/index.js.map +1 -0
- package/lib/network/addresses.d.ts +16 -0
- package/lib/network/addresses.d.ts.map +1 -0
- package/lib/network/addresses.js +75 -0
- package/lib/network/addresses.js.map +1 -0
- package/lib/network/index.d.ts +2 -0
- package/lib/network/index.d.ts.map +1 -0
- package/lib/network/index.js +18 -0
- package/lib/network/index.js.map +1 -0
- package/lib/signer/getAddress.d.ts +6 -0
- package/lib/signer/getAddress.d.ts.map +1 -0
- package/lib/signer/getAddress.js +30 -0
- package/lib/signer/getAddress.js.map +1 -0
- package/lib/signer/index.d.ts +3 -0
- package/lib/signer/index.d.ts.map +1 -0
- package/lib/signer/index.js +8 -0
- package/lib/signer/index.js.map +1 -0
- package/lib/test/bot-specs.d.ts +7 -0
- package/lib/test/bot-specs.d.ts.map +1 -0
- package/lib/test/bot-specs.js +151 -0
- package/lib/test/bot-specs.js.map +1 -0
- package/lib/test/bridgeDatasetTest.d.ts +4 -0
- package/lib/test/bridgeDatasetTest.d.ts.map +1 -0
- package/lib/test/bridgeDatasetTest.js +401 -0
- package/lib/test/bridgeDatasetTest.js.map +1 -0
- package/lib/test/cli.d.ts +19 -0
- package/lib/test/cli.d.ts.map +1 -0
- package/lib/test/cli.js +59 -0
- package/lib/test/cli.js.map +1 -0
- package/lib/test/index.d.ts +6 -0
- package/lib/test/index.d.ts.map +1 -0
- package/lib/test/index.js +26 -0
- package/lib/test/index.js.map +1 -0
- package/lib/test/speculos-deviceActions.d.ts +5 -0
- package/lib/test/speculos-deviceActions.d.ts.map +1 -0
- package/lib/test/speculos-deviceActions.js +159 -0
- package/lib/test/speculos-deviceActions.js.map +1 -0
- package/lib/types/bridge.d.ts +35 -0
- package/lib/types/bridge.d.ts.map +1 -0
- package/lib/types/bridge.js +3 -0
- package/lib/types/bridge.js.map +1 -0
- package/lib/types/common.d.ts +96 -0
- package/lib/types/common.d.ts.map +1 -0
- package/lib/types/common.js +10 -0
- package/lib/types/common.js.map +1 -0
- package/lib/types/index.d.ts +4 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +20 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/signer.d.ts +19 -0
- package/lib/types/signer.d.ts.map +1 -0
- package/lib/types/signer.js +3 -0
- package/lib/types/signer.js.map +1 -0
- package/lib-es/api/api.d.ts +9 -0
- package/lib-es/api/api.d.ts.map +1 -0
- package/lib-es/api/api.js +87 -0
- package/lib-es/api/api.js.map +1 -0
- package/lib-es/api/index.d.ts +2 -0
- package/lib-es/api/index.d.ts.map +1 -0
- package/lib-es/api/index.js +2 -0
- package/lib-es/api/index.js.map +1 -0
- package/lib-es/bridge/broadcast.d.ts +4 -0
- package/lib-es/bridge/broadcast.d.ts.map +1 -0
- package/lib-es/bridge/broadcast.js +23 -0
- package/lib-es/bridge/broadcast.js.map +1 -0
- package/lib-es/bridge/buildOptimisticOperation.d.ts +5 -0
- package/lib-es/bridge/buildOptimisticOperation.d.ts.map +1 -0
- package/lib-es/bridge/buildOptimisticOperation.js +58 -0
- package/lib-es/bridge/buildOptimisticOperation.js.map +1 -0
- package/lib-es/bridge/createTransaction.d.ts +4 -0
- package/lib-es/bridge/createTransaction.d.ts.map +1 -0
- package/lib-es/bridge/createTransaction.js +17 -0
- package/lib-es/bridge/createTransaction.js.map +1 -0
- package/lib-es/bridge/deviceTransactionConfig.d.ts +33 -0
- package/lib-es/bridge/deviceTransactionConfig.d.ts.map +1 -0
- package/lib-es/bridge/deviceTransactionConfig.js +69 -0
- package/lib-es/bridge/deviceTransactionConfig.js.map +1 -0
- package/lib-es/bridge/estimateMaxSpendable.d.ts +4 -0
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -0
- package/lib-es/bridge/estimateMaxSpendable.js +93 -0
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -0
- package/lib-es/bridge/getTransactionStatus.d.ts +4 -0
- package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -0
- package/lib-es/bridge/getTransactionStatus.js +80 -0
- package/lib-es/bridge/getTransactionStatus.js.map +1 -0
- package/lib-es/bridge/index.d.ts +8 -0
- package/lib-es/bridge/index.d.ts.map +1 -0
- package/lib-es/bridge/index.js +47 -0
- package/lib-es/bridge/index.js.map +1 -0
- package/lib-es/bridge/prepareTransaction.d.ts +4 -0
- package/lib-es/bridge/prepareTransaction.d.ts.map +1 -0
- package/lib-es/bridge/prepareTransaction.js +68 -0
- package/lib-es/bridge/prepareTransaction.js.map +1 -0
- package/lib-es/bridge/serializer.d.ts +13 -0
- package/lib-es/bridge/serializer.d.ts.map +1 -0
- package/lib-es/bridge/serializer.js +58 -0
- package/lib-es/bridge/serializer.js.map +1 -0
- package/lib-es/bridge/signOperation.d.ts +5 -0
- package/lib-es/bridge/signOperation.d.ts.map +1 -0
- package/lib-es/bridge/signOperation.js +76 -0
- package/lib-es/bridge/signOperation.js.map +1 -0
- package/lib-es/bridge/transaction.d.ts +14 -0
- package/lib-es/bridge/transaction.d.ts.map +1 -0
- package/lib-es/bridge/transaction.js +33 -0
- package/lib-es/bridge/transaction.js.map +1 -0
- package/lib-es/bridge/utils.d.ts +26 -0
- package/lib-es/bridge/utils.d.ts.map +1 -0
- package/lib-es/bridge/utils.js +57 -0
- package/lib-es/bridge/utils.js.map +1 -0
- package/lib-es/bridge/utils.unit.test.d.ts +2 -0
- package/lib-es/bridge/utils.unit.test.d.ts.map +1 -0
- package/lib-es/bridge/utils.unit.test.js +21 -0
- package/lib-es/bridge/utils.unit.test.js.map +1 -0
- package/lib-es/common-logic/index.d.ts +2 -0
- package/lib-es/common-logic/index.d.ts.map +1 -0
- package/lib-es/common-logic/index.js +2 -0
- package/lib-es/common-logic/index.js.map +1 -0
- package/lib-es/common-logic/utils.d.ts +22 -0
- package/lib-es/common-logic/utils.d.ts.map +1 -0
- package/lib-es/common-logic/utils.js +175 -0
- package/lib-es/common-logic/utils.js.map +1 -0
- package/lib-es/erc20/ERC20.json +12 -0
- package/lib-es/erc20/tokenAccounts.d.ts +10 -0
- package/lib-es/erc20/tokenAccounts.d.ts.map +1 -0
- package/lib-es/erc20/tokenAccounts.js +158 -0
- package/lib-es/erc20/tokenAccounts.js.map +1 -0
- package/lib-es/errors.d.ts +7 -0
- package/lib-es/errors.d.ts.map +1 -0
- package/lib-es/errors.js +10 -0
- package/lib-es/errors.js.map +1 -0
- package/lib-es/hw-signMessage.d.ts +12 -0
- package/lib-es/hw-signMessage.d.ts.map +1 -0
- package/lib-es/hw-signMessage.js +28 -0
- package/lib-es/hw-signMessage.js.map +1 -0
- package/lib-es/index.d.ts +2 -0
- package/lib-es/index.d.ts.map +1 -0
- package/lib-es/index.js +2 -0
- package/lib-es/index.js.map +1 -0
- package/lib-es/network/addresses.d.ts +16 -0
- package/lib-es/network/addresses.d.ts.map +1 -0
- package/lib-es/network/addresses.js +64 -0
- package/lib-es/network/addresses.js.map +1 -0
- package/lib-es/network/index.d.ts +2 -0
- package/lib-es/network/index.d.ts.map +1 -0
- package/lib-es/network/index.js +2 -0
- package/lib-es/network/index.js.map +1 -0
- package/lib-es/signer/getAddress.d.ts +6 -0
- package/lib-es/signer/getAddress.d.ts.map +1 -0
- package/lib-es/signer/getAddress.js +28 -0
- package/lib-es/signer/getAddress.js.map +1 -0
- package/lib-es/signer/index.d.ts +3 -0
- package/lib-es/signer/index.d.ts.map +1 -0
- package/lib-es/signer/index.js +3 -0
- package/lib-es/signer/index.js.map +1 -0
- package/lib-es/test/bot-specs.d.ts +7 -0
- package/lib-es/test/bot-specs.d.ts.map +1 -0
- package/lib-es/test/bot-specs.js +146 -0
- package/lib-es/test/bot-specs.js.map +1 -0
- package/lib-es/test/bridgeDatasetTest.d.ts +4 -0
- package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -0
- package/lib-es/test/bridgeDatasetTest.js +395 -0
- package/lib-es/test/bridgeDatasetTest.js.map +1 -0
- package/lib-es/test/cli.d.ts +19 -0
- package/lib-es/test/cli.d.ts.map +1 -0
- package/lib-es/test/cli.js +53 -0
- package/lib-es/test/cli.js.map +1 -0
- package/lib-es/test/index.d.ts +6 -0
- package/lib-es/test/index.d.ts.map +1 -0
- package/lib-es/test/index.js +6 -0
- package/lib-es/test/index.js.map +1 -0
- package/lib-es/test/speculos-deviceActions.d.ts +5 -0
- package/lib-es/test/speculos-deviceActions.d.ts.map +1 -0
- package/lib-es/test/speculos-deviceActions.js +152 -0
- package/lib-es/test/speculos-deviceActions.js.map +1 -0
- package/lib-es/types/bridge.d.ts +35 -0
- package/lib-es/types/bridge.d.ts.map +1 -0
- package/lib-es/types/bridge.js +2 -0
- package/lib-es/types/bridge.js.map +1 -0
- package/lib-es/types/common.d.ts +96 -0
- package/lib-es/types/common.d.ts.map +1 -0
- package/lib-es/types/common.js +7 -0
- package/lib-es/types/common.js.map +1 -0
- package/lib-es/types/index.d.ts +4 -0
- package/lib-es/types/index.d.ts.map +1 -0
- package/lib-es/types/index.js +4 -0
- package/lib-es/types/index.js.map +1 -0
- package/lib-es/types/signer.d.ts +19 -0
- package/lib-es/types/signer.d.ts.map +1 -0
- package/lib-es/types/signer.js +2 -0
- package/lib-es/types/signer.js.map +1 -0
- package/package.json +135 -0
- package/src/api/api.ts +125 -0
- package/src/api/index.ts +1 -0
- package/src/bridge/broadcast.ts +20 -0
- package/src/bridge/buildOptimisticOperation.ts +58 -0
- package/src/bridge/createTransaction.ts +20 -0
- package/src/bridge/deviceTransactionConfig.ts +119 -0
- package/src/bridge/estimateMaxSpendable.ts +120 -0
- package/src/bridge/getTransactionStatus.ts +80 -0
- package/src/bridge/index.ts +63 -0
- package/src/bridge/prepareTransaction.ts +82 -0
- package/src/bridge/serializer.ts +63 -0
- package/src/bridge/signOperation.ts +97 -0
- package/src/bridge/transaction.ts +69 -0
- package/src/bridge/utils.ts +73 -0
- package/src/bridge/utils.unit.test.ts +27 -0
- package/src/common-logic/index.ts +10 -0
- package/src/common-logic/utils.ts +232 -0
- package/src/erc20/ERC20.json +12 -0
- package/src/erc20/tokenAccounts.ts +183 -0
- package/src/errors.ts +13 -0
- package/src/hw-signMessage.ts +27 -0
- package/src/index.ts +1 -0
- package/src/network/addresses.ts +93 -0
- package/src/network/index.ts +1 -0
- package/src/signer/getAddress.ts +28 -0
- package/src/signer/index.ts +3 -0
- package/src/test/bot-specs.ts +163 -0
- package/src/test/bridgeDatasetTest.ts +403 -0
- package/src/test/cli.ts +80 -0
- package/src/test/index.ts +6 -0
- package/src/test/speculos-deviceActions.ts +166 -0
- package/src/types/bridge.ts +42 -0
- package/src/types/common.ts +105 -0
- package/src/types/index.ts +3 -0
- package/src/types/signer.ts +19 -0
- package/tsconfig.json +14 -0
package/src/errors.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createCustomErrorClass } from "@ledgerhq/errors";
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* When the recipient is non f0, f4 or eth address during token transfer
|
|
5
|
+
*/
|
|
6
|
+
export const InvalidRecipientForTokenTransfer = createCustomErrorClass(
|
|
7
|
+
"InvalidRecipientForTokenTransfer",
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
* When the fee estimation endpoint fails
|
|
12
|
+
*/
|
|
13
|
+
export const FilecoinFeeEstimationFailed = createCustomErrorClass("FilecoinFeeEstimationFailed");
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { log } from "@ledgerhq/logs";
|
|
2
|
+
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
3
|
+
import { Account, AnyMessage } from "@ledgerhq/types-live";
|
|
4
|
+
import { getBufferFromString } from "./bridge/utils";
|
|
5
|
+
import { FilecoinSigner } from "./types";
|
|
6
|
+
|
|
7
|
+
export const signMessage =
|
|
8
|
+
(signerContext: SignerContext<FilecoinSigner>) =>
|
|
9
|
+
async (deviceId: string, account: Account, { message }: AnyMessage) => {
|
|
10
|
+
log("debug", "start signMessage process");
|
|
11
|
+
|
|
12
|
+
if (typeof message !== "string") throw new Error("Invalid message type");
|
|
13
|
+
if (!message) throw new Error("Message cannot be empty");
|
|
14
|
+
|
|
15
|
+
const r = await signerContext(deviceId, signer =>
|
|
16
|
+
signer.sign(account.freshAddressPath, getBufferFromString(message)),
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
rsv: {
|
|
21
|
+
r: Buffer.from(r.signature_compact.slice(0, 32)).toString("hex"),
|
|
22
|
+
s: Buffer.from(r.signature_compact.slice(32, 64)).toString("hex"),
|
|
23
|
+
v: parseInt(Buffer.from(r.signature_compact.slice(64, 65)).toString("hex"), 16),
|
|
24
|
+
},
|
|
25
|
+
signature: `0x${Buffer.from(r.signature_compact).toString("hex")}`,
|
|
26
|
+
};
|
|
27
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createBridges } from "./bridge/index";
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IAddress,
|
|
3
|
+
PROTOCOL_INDICATOR,
|
|
4
|
+
fromEthAddress,
|
|
5
|
+
isEthAddress,
|
|
6
|
+
fromString,
|
|
7
|
+
toEthAddress,
|
|
8
|
+
} from "iso-filecoin/address";
|
|
9
|
+
import { log } from "@ledgerhq/logs";
|
|
10
|
+
|
|
11
|
+
export type ValidateAddressResult =
|
|
12
|
+
| {
|
|
13
|
+
isValid: true;
|
|
14
|
+
parsedAddress: IAddress;
|
|
15
|
+
}
|
|
16
|
+
| {
|
|
17
|
+
isValid: false;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const isFilEthAddress = (addr: IAddress) =>
|
|
21
|
+
addr.protocol === PROTOCOL_INDICATOR.DELEGATED && addr.namespace === 10;
|
|
22
|
+
|
|
23
|
+
export const isIdAddress = (addr: IAddress) => addr.protocol === PROTOCOL_INDICATOR.ID;
|
|
24
|
+
|
|
25
|
+
export const isEthereumConvertableAddr = (addr: IAddress) =>
|
|
26
|
+
isIdAddress(addr) || isFilEthAddress(addr);
|
|
27
|
+
|
|
28
|
+
export const validateAddress = (input: string): ValidateAddressResult => {
|
|
29
|
+
try {
|
|
30
|
+
const parsedAddress = fromString(input);
|
|
31
|
+
return { isValid: true, parsedAddress };
|
|
32
|
+
} catch (error) {
|
|
33
|
+
log("debug", `[validateAddress] fromString invalid address`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
const parsedAddress = fromEthAddress(input, "mainnet");
|
|
38
|
+
return { isValid: true, parsedAddress };
|
|
39
|
+
} catch (error) {
|
|
40
|
+
log("debug", `[validateAddress] fromEthAddress invalid address`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return { isValid: false };
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const isRecipientValidForTokenTransfer = (addr: string): boolean => {
|
|
47
|
+
if (addr.length < 2) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const valid = validateAddress(addr);
|
|
52
|
+
if (!valid.isValid) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (isEthereumConvertableAddr(valid.parsedAddress)) {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return false;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export const getEquivalentAddress = (addr: string): string => {
|
|
64
|
+
if (isEthAddress(addr)) {
|
|
65
|
+
return fromEthAddress(addr, "mainnet").toString();
|
|
66
|
+
} else {
|
|
67
|
+
const parsed = fromString(addr);
|
|
68
|
+
if (isEthereumConvertableAddr(parsed)) {
|
|
69
|
+
return toEthAddress(parsed);
|
|
70
|
+
}
|
|
71
|
+
return "";
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export const convertAddressFilToEth = (addr: string): string => {
|
|
76
|
+
if (isEthAddress(addr)) {
|
|
77
|
+
return addr;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const parsed = fromString(addr);
|
|
81
|
+
if (isEthereumConvertableAddr(parsed)) {
|
|
82
|
+
return toEthAddress(parsed);
|
|
83
|
+
}
|
|
84
|
+
throw new Error("address is not convertible to ethereum address");
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export const convertAddressEthToFil = (addr: string): string => {
|
|
88
|
+
if (!isEthAddress(addr)) {
|
|
89
|
+
return addr;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return fromEthAddress(addr, "mainnet").toString();
|
|
93
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./addresses";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { log } from "@ledgerhq/logs";
|
|
2
|
+
|
|
3
|
+
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
4
|
+
import { GetAddressFn } from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
|
|
5
|
+
import { GetAddressOptions } from "@ledgerhq/coin-framework/derivation";
|
|
6
|
+
import { FilecoinSigner } from "../types";
|
|
7
|
+
|
|
8
|
+
function resolver(signerContext: SignerContext<FilecoinSigner>): GetAddressFn {
|
|
9
|
+
return async (deviceId: string, { path, verify }: GetAddressOptions) => {
|
|
10
|
+
log("debug", "start getAddress process");
|
|
11
|
+
|
|
12
|
+
const { r } = await signerContext(deviceId, async signer => {
|
|
13
|
+
const r = verify
|
|
14
|
+
? await signer.showAddressAndPubKey(path)
|
|
15
|
+
: await signer.getAddressAndPubKey(path);
|
|
16
|
+
|
|
17
|
+
return { r };
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
path,
|
|
22
|
+
address: r.addrString,
|
|
23
|
+
publicKey: Buffer.from(r.compressed_pk).toString("hex"),
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default resolver;
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import invariant from "invariant";
|
|
2
|
+
import { DeviceModelId } from "@ledgerhq/devices";
|
|
3
|
+
import BigNumber from "bignumber.js";
|
|
4
|
+
import type { Transaction } from "../types";
|
|
5
|
+
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/currencies";
|
|
6
|
+
import { botTest, genericTestDestination, pickSiblings } from "@ledgerhq/coin-framework/bot/specs";
|
|
7
|
+
import type { AppSpec } from "@ledgerhq/coin-framework/bot/types";
|
|
8
|
+
import { generateDeviceActionFlow } from "./speculos-deviceActions";
|
|
9
|
+
import { AccountType, BotScenario } from "../bridge/utils";
|
|
10
|
+
|
|
11
|
+
const F4_RECIPIENT = "f410fncojwmrseefktoco6rcnb3zv2eiqfli7muhvqma";
|
|
12
|
+
const ETH_RECIPIENT = "0x689c9b3232210aa9b84ef444d0ef35d11102ad1f";
|
|
13
|
+
const MIN_SAFE = new BigNumber(100000);
|
|
14
|
+
const maxAccount = 6;
|
|
15
|
+
|
|
16
|
+
const filecoinSpecs: AppSpec<Transaction> = {
|
|
17
|
+
name: "Filecoin",
|
|
18
|
+
currency: getCryptoCurrencyById("filecoin"),
|
|
19
|
+
appQuery: {
|
|
20
|
+
model: DeviceModelId.nanoSP,
|
|
21
|
+
appName: "Filecoin",
|
|
22
|
+
appVersion: "0.24.3",
|
|
23
|
+
},
|
|
24
|
+
genericDeviceAction: generateDeviceActionFlow(BotScenario.DEFAULT),
|
|
25
|
+
testTimeout: 16 * 60 * 1000,
|
|
26
|
+
minViableAmount: MIN_SAFE,
|
|
27
|
+
transactionCheck: ({ maxSpendable }) => {
|
|
28
|
+
invariant(maxSpendable.gt(MIN_SAFE), "balance is too low");
|
|
29
|
+
},
|
|
30
|
+
mutations: [
|
|
31
|
+
{
|
|
32
|
+
name: "Send small to f4 address",
|
|
33
|
+
maxRun: 1,
|
|
34
|
+
deviceAction: generateDeviceActionFlow(BotScenario.F4_RECIPIENT),
|
|
35
|
+
testDestination: genericTestDestination,
|
|
36
|
+
transaction: ({ account, bridge }) => {
|
|
37
|
+
const amount = new BigNumber("100");
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
transaction: bridge.createTransaction(account),
|
|
41
|
+
updates: [
|
|
42
|
+
{
|
|
43
|
+
recipient: F4_RECIPIENT,
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
amount,
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: "Send small to eth address",
|
|
54
|
+
maxRun: 1,
|
|
55
|
+
deviceAction: generateDeviceActionFlow(BotScenario.ETH_RECIPIENT),
|
|
56
|
+
testDestination: genericTestDestination,
|
|
57
|
+
transaction: ({ account, bridge }) => {
|
|
58
|
+
const amount = new BigNumber("100");
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
transaction: bridge.createTransaction(account),
|
|
62
|
+
updates: [
|
|
63
|
+
{
|
|
64
|
+
recipient: ETH_RECIPIENT,
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
amount,
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
};
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: "Send 50%~",
|
|
75
|
+
maxRun: 1,
|
|
76
|
+
testDestination: genericTestDestination,
|
|
77
|
+
transaction: ({ account, siblings, bridge }) => {
|
|
78
|
+
const sibling = pickSiblings(siblings, maxAccount);
|
|
79
|
+
let amount = account.spendableBalance.div(1.9 + 0.2 * Math.random()).integerValue();
|
|
80
|
+
|
|
81
|
+
if (!sibling.used && amount.lt(MIN_SAFE)) {
|
|
82
|
+
invariant(account.spendableBalance.gt(MIN_SAFE), "send is too low to activate account");
|
|
83
|
+
amount = MIN_SAFE;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
transaction: bridge.createTransaction(account),
|
|
88
|
+
updates: [
|
|
89
|
+
{
|
|
90
|
+
recipient: sibling.freshAddress,
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
amount,
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
};
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
name: "Transfer Max",
|
|
101
|
+
maxRun: 1,
|
|
102
|
+
transaction: ({ account, siblings, bridge }) => {
|
|
103
|
+
return {
|
|
104
|
+
transaction: bridge.createTransaction(account),
|
|
105
|
+
updates: [
|
|
106
|
+
{
|
|
107
|
+
recipient: pickSiblings(siblings, maxAccount).freshAddress,
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
useAllAmount: true,
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
};
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
name: "Send ~50% WFIL",
|
|
118
|
+
maxRun: 1,
|
|
119
|
+
deviceAction: generateDeviceActionFlow(BotScenario.TOKEN_TRANSFER),
|
|
120
|
+
transaction: ({ account, bridge, maxSpendable }) => {
|
|
121
|
+
invariant(maxSpendable.gt(0), "Spendable balance is too low");
|
|
122
|
+
const subAccount = account.subAccounts?.find(
|
|
123
|
+
a => a.type === AccountType.TokenAccount && a.spendableBalance.gt(0),
|
|
124
|
+
);
|
|
125
|
+
invariant(
|
|
126
|
+
subAccount && subAccount.type === AccountType.TokenAccount,
|
|
127
|
+
"no subAccount with WFIL",
|
|
128
|
+
);
|
|
129
|
+
const amount = subAccount.balance.div(1.9 + 0.2 * Math.random()).integerValue();
|
|
130
|
+
return {
|
|
131
|
+
transaction: bridge.createTransaction(account),
|
|
132
|
+
updates: [
|
|
133
|
+
{
|
|
134
|
+
subAccountId: subAccount.id,
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
recipient: F4_RECIPIENT,
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
amount,
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
};
|
|
144
|
+
},
|
|
145
|
+
test: ({ account, accountBeforeTransaction, transaction, status }) => {
|
|
146
|
+
const subAccountId = transaction.subAccountId;
|
|
147
|
+
const subAccount = account.subAccounts?.find(sa => sa.id === subAccountId);
|
|
148
|
+
const subAccountBeforeTransaction = accountBeforeTransaction.subAccounts?.find(
|
|
149
|
+
sa => sa.id === subAccountId,
|
|
150
|
+
);
|
|
151
|
+
botTest("subAccount balance moved with the tx status amount", () =>
|
|
152
|
+
expect(subAccount?.balance.toString()).toBe(
|
|
153
|
+
subAccountBeforeTransaction?.balance.minus(status.amount).toString(),
|
|
154
|
+
),
|
|
155
|
+
);
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
],
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
export default {
|
|
162
|
+
filecoinSpecs,
|
|
163
|
+
};
|