@ledgerhq/coin-casper 1.4.0-nightly.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 +4 -0
- package/.unimportedrc.json +49 -0
- package/CHANGELOG.md +11 -0
- package/LICENSE.txt +21 -0
- package/jest.config.js +8 -0
- package/lib/api/index.d.ts +11 -0
- package/lib/api/index.d.ts.map +1 -0
- package/lib/api/index.js +129 -0
- package/lib/api/index.js.map +1 -0
- package/lib/api/types.d.ts +105 -0
- package/lib/api/types.d.ts.map +1 -0
- package/lib/api/types.js +3 -0
- package/lib/api/types.js.map +1 -0
- package/lib/bridge/bridgeHelpers/accountShape.d.ts +3 -0
- package/lib/bridge/bridgeHelpers/accountShape.d.ts.map +1 -0
- package/lib/bridge/bridgeHelpers/accountShape.js +38 -0
- package/lib/bridge/bridgeHelpers/accountShape.js.map +1 -0
- package/lib/bridge/bridgeHelpers/addresses.d.ts +18 -0
- package/lib/bridge/bridgeHelpers/addresses.d.ts.map +1 -0
- package/lib/bridge/bridgeHelpers/addresses.js +83 -0
- package/lib/bridge/bridgeHelpers/addresses.js.map +1 -0
- package/lib/bridge/bridgeHelpers/fee.d.ts +3 -0
- package/lib/bridge/bridgeHelpers/fee.d.ts.map +1 -0
- package/lib/bridge/bridgeHelpers/fee.js +13 -0
- package/lib/bridge/bridgeHelpers/fee.js.map +1 -0
- package/lib/bridge/bridgeHelpers/transferId.d.ts +2 -0
- package/lib/bridge/bridgeHelpers/transferId.d.ts.map +1 -0
- package/lib/bridge/bridgeHelpers/transferId.js +14 -0
- package/lib/bridge/bridgeHelpers/transferId.js.map +1 -0
- package/lib/bridge/bridgeHelpers/txn.d.ts +9 -0
- package/lib/bridge/bridgeHelpers/txn.d.ts.map +1 -0
- package/lib/bridge/bridgeHelpers/txn.js +100 -0
- package/lib/bridge/bridgeHelpers/txn.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 +15 -0
- package/lib/bridge/broadcast.js.map +1 -0
- package/lib/bridge/buildOptimisticOperation.d.ts +4 -0
- package/lib/bridge/buildOptimisticOperation.d.ts.map +1 -0
- package/lib/bridge/buildOptimisticOperation.js +27 -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 +19 -0
- package/lib/bridge/createTransaction.js.map +1 -0
- package/lib/bridge/deviceTransactionConfig.d.ts +18 -0
- package/lib/bridge/deviceTransactionConfig.d.ts.map +1 -0
- package/lib/bridge/deviceTransactionConfig.js +26 -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 +23 -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 +75 -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 +16 -0
- package/lib/bridge/prepareTransaction.js.map +1 -0
- package/lib/bridge/signOperation.d.ts +6 -0
- package/lib/bridge/signOperation.d.ts.map +1 -0
- package/lib/bridge/signOperation.js +47 -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 +53 -0
- package/lib/bridge/transaction.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 +14 -0
- package/lib/common-logic/utils.d.ts.map +1 -0
- package/lib/common-logic/utils.js +53 -0
- package/lib/common-logic/utils.js.map +1 -0
- package/lib/common-logic/utils.unit.test.d.ts +2 -0
- package/lib/common-logic/utils.unit.test.d.ts.map +1 -0
- package/lib/common-logic/utils.unit.test.js +50 -0
- package/lib/common-logic/utils.unit.test.js.map +1 -0
- package/lib/consts.d.ts +10 -0
- package/lib/consts.d.ts.map +1 -0
- package/lib/consts.js +18 -0
- package/lib/consts.js.map +1 -0
- package/lib/errors.d.ts +10 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +8 -0
- package/lib/errors.js.map +1 -0
- package/lib/hw-signMessage.d.ts +23 -0
- package/lib/hw-signMessage.d.ts.map +1 -0
- package/lib/hw-signMessage.js +24 -0
- package/lib/hw-signMessage.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 +25 -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 +110 -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 +177 -0
- package/lib/test/bridgeDatasetTest.js.map +1 -0
- package/lib/test/cli.d.ts +15 -0
- package/lib/test/cli.d.ts.map +1 -0
- package/lib/test/cli.js +30 -0
- package/lib/test/cli.js.map +1 -0
- package/lib/test/index.d.ts +4 -0
- package/lib/test/index.d.ts.map +1 -0
- package/lib/test/index.js +20 -0
- package/lib/test/index.js.map +1 -0
- package/lib/test/speculos-deviceActions.d.ts +4 -0
- package/lib/test/speculos-deviceActions.d.ts.map +1 -0
- package/lib/test/speculos-deviceActions.js +53 -0
- package/lib/test/speculos-deviceActions.js.map +1 -0
- package/lib/types/common.d.ts +23 -0
- package/lib/types/common.d.ts.map +1 -0
- package/lib/types/common.js +3 -0
- package/lib/types/common.js.map +1 -0
- package/lib/types/index.d.ts +3 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +19 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/signer.d.ts +21 -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/index.d.ts +11 -0
- package/lib-es/api/index.d.ts.map +1 -0
- package/lib-es/api/index.js +118 -0
- package/lib-es/api/index.js.map +1 -0
- package/lib-es/api/types.d.ts +105 -0
- package/lib-es/api/types.d.ts.map +1 -0
- package/lib-es/api/types.js +2 -0
- package/lib-es/api/types.js.map +1 -0
- package/lib-es/bridge/bridgeHelpers/accountShape.d.ts +3 -0
- package/lib-es/bridge/bridgeHelpers/accountShape.d.ts.map +1 -0
- package/lib-es/bridge/bridgeHelpers/accountShape.js +31 -0
- package/lib-es/bridge/bridgeHelpers/accountShape.js.map +1 -0
- package/lib-es/bridge/bridgeHelpers/addresses.d.ts +18 -0
- package/lib-es/bridge/bridgeHelpers/addresses.d.ts.map +1 -0
- package/lib-es/bridge/bridgeHelpers/addresses.js +74 -0
- package/lib-es/bridge/bridgeHelpers/addresses.js.map +1 -0
- package/lib-es/bridge/bridgeHelpers/fee.d.ts +3 -0
- package/lib-es/bridge/bridgeHelpers/fee.d.ts.map +1 -0
- package/lib-es/bridge/bridgeHelpers/fee.js +6 -0
- package/lib-es/bridge/bridgeHelpers/fee.js.map +1 -0
- package/lib-es/bridge/bridgeHelpers/transferId.d.ts +2 -0
- package/lib-es/bridge/bridgeHelpers/transferId.d.ts.map +1 -0
- package/lib-es/bridge/bridgeHelpers/transferId.js +10 -0
- package/lib-es/bridge/bridgeHelpers/transferId.js.map +1 -0
- package/lib-es/bridge/bridgeHelpers/txn.d.ts +9 -0
- package/lib-es/bridge/bridgeHelpers/txn.d.ts.map +1 -0
- package/lib-es/bridge/bridgeHelpers/txn.js +91 -0
- package/lib-es/bridge/bridgeHelpers/txn.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 +11 -0
- package/lib-es/bridge/broadcast.js.map +1 -0
- package/lib-es/bridge/buildOptimisticOperation.d.ts +4 -0
- package/lib-es/bridge/buildOptimisticOperation.d.ts.map +1 -0
- package/lib-es/bridge/buildOptimisticOperation.js +23 -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 +12 -0
- package/lib-es/bridge/createTransaction.js.map +1 -0
- package/lib-es/bridge/deviceTransactionConfig.d.ts +18 -0
- package/lib-es/bridge/deviceTransactionConfig.d.ts.map +1 -0
- package/lib-es/bridge/deviceTransactionConfig.js +24 -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 +16 -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 +68 -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 +12 -0
- package/lib-es/bridge/prepareTransaction.js.map +1 -0
- package/lib-es/bridge/signOperation.d.ts +6 -0
- package/lib-es/bridge/signOperation.d.ts.map +1 -0
- package/lib-es/bridge/signOperation.js +43 -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 +45 -0
- package/lib-es/bridge/transaction.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 +14 -0
- package/lib-es/common-logic/utils.d.ts.map +1 -0
- package/lib-es/common-logic/utils.js +39 -0
- package/lib-es/common-logic/utils.js.map +1 -0
- package/lib-es/common-logic/utils.unit.test.d.ts +2 -0
- package/lib-es/common-logic/utils.unit.test.d.ts.map +1 -0
- package/lib-es/common-logic/utils.unit.test.js +48 -0
- package/lib-es/common-logic/utils.unit.test.js.map +1 -0
- package/lib-es/consts.d.ts +10 -0
- package/lib-es/consts.d.ts.map +1 -0
- package/lib-es/consts.js +15 -0
- package/lib-es/consts.js.map +1 -0
- package/lib-es/errors.d.ts +10 -0
- package/lib-es/errors.d.ts.map +1 -0
- package/lib-es/errors.js +5 -0
- package/lib-es/errors.js.map +1 -0
- package/lib-es/hw-signMessage.d.ts +23 -0
- package/lib-es/hw-signMessage.d.ts.map +1 -0
- package/lib-es/hw-signMessage.js +20 -0
- package/lib-es/hw-signMessage.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 +23 -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 +105 -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 +171 -0
- package/lib-es/test/bridgeDatasetTest.js.map +1 -0
- package/lib-es/test/cli.d.ts +15 -0
- package/lib-es/test/cli.d.ts.map +1 -0
- package/lib-es/test/cli.js +24 -0
- package/lib-es/test/cli.js.map +1 -0
- package/lib-es/test/index.d.ts +4 -0
- package/lib-es/test/index.d.ts.map +1 -0
- package/lib-es/test/index.js +4 -0
- package/lib-es/test/index.js.map +1 -0
- package/lib-es/test/speculos-deviceActions.d.ts +4 -0
- package/lib-es/test/speculos-deviceActions.d.ts.map +1 -0
- package/lib-es/test/speculos-deviceActions.js +50 -0
- package/lib-es/test/speculos-deviceActions.js.map +1 -0
- package/lib-es/types/common.d.ts +23 -0
- package/lib-es/types/common.d.ts.map +1 -0
- package/lib-es/types/common.js +2 -0
- package/lib-es/types/common.js.map +1 -0
- package/lib-es/types/index.d.ts +3 -0
- package/lib-es/types/index.d.ts.map +1 -0
- package/lib-es/types/index.js +3 -0
- package/lib-es/types/index.js.map +1 -0
- package/lib-es/types/signer.d.ts +21 -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 +127 -0
- package/src/api/index.ts +166 -0
- package/src/api/types.ts +113 -0
- package/src/bridge/bridgeHelpers/accountShape.ts +39 -0
- package/src/bridge/bridgeHelpers/addresses.ts +94 -0
- package/src/bridge/bridgeHelpers/fee.ts +6 -0
- package/src/bridge/bridgeHelpers/transferId.ts +9 -0
- package/src/bridge/bridgeHelpers/txn.ts +121 -0
- package/src/bridge/broadcast.ts +18 -0
- package/src/bridge/buildOptimisticOperation.ts +31 -0
- package/src/bridge/createTransaction.ts +15 -0
- package/src/bridge/deviceTransactionConfig.ts +46 -0
- package/src/bridge/estimateMaxSpendable.ts +26 -0
- package/src/bridge/getTransactionStatus.ts +96 -0
- package/src/bridge/index.ts +65 -0
- package/src/bridge/prepareTransaction.ts +19 -0
- package/src/bridge/signOperation.ts +73 -0
- package/src/bridge/transaction.ts +61 -0
- package/src/common-logic/index.ts +10 -0
- package/src/common-logic/utils.ts +53 -0
- package/src/common-logic/utils.unit.test.ts +75 -0
- package/src/consts.ts +18 -0
- package/src/errors.ts +5 -0
- package/src/hw-signMessage.ts +30 -0
- package/src/signer/getAddress.ts +31 -0
- package/src/signer/index.ts +3 -0
- package/src/test/bot-specs.ts +127 -0
- package/src/test/bridgeDatasetTest.ts +178 -0
- package/src/test/cli.ts +36 -0
- package/src/test/index.ts +3 -0
- package/src/test/speculos-deviceActions.ts +54 -0
- package/src/types/common.ts +38 -0
- package/src/types/index.ts +2 -0
- package/src/types/signer.ts +20 -0
- package/tsconfig.json +15 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { AmountRequired, InvalidAddress, InvalidAddressBecauseDestinationIsAlsoSource, NotEnoughBalance, RecipientRequired, } from "@ledgerhq/errors";
|
|
3
|
+
import { getAddress, isAddressValid } from "./bridgeHelpers/addresses";
|
|
4
|
+
import { isTransferIdValid } from "./bridgeHelpers/transferId";
|
|
5
|
+
import { CasperInvalidTransferId } from "../errors";
|
|
6
|
+
import { CASPER_MINIMUM_VALID_AMOUNT_MOTES, CASPER_MAX_TRANSFER_ID, MayBlockAccountError, InvalidMinimumAmountError, } from "../consts";
|
|
7
|
+
export const getTransactionStatus = async (account, transaction) => {
|
|
8
|
+
const errors = {};
|
|
9
|
+
const warnings = {};
|
|
10
|
+
const { balance, spendableBalance } = account;
|
|
11
|
+
const { address } = getAddress(account);
|
|
12
|
+
const { recipient, useAllAmount } = transaction;
|
|
13
|
+
let { amount } = transaction;
|
|
14
|
+
if (!recipient) {
|
|
15
|
+
errors.recipient = new RecipientRequired();
|
|
16
|
+
}
|
|
17
|
+
else if (!isAddressValid(recipient)) {
|
|
18
|
+
errors.recipient = new InvalidAddress("", {
|
|
19
|
+
currencyName: account.currency.name,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
else if (recipient.toLowerCase() === address.toLowerCase()) {
|
|
23
|
+
errors.recipient = new InvalidAddressBecauseDestinationIsAlsoSource();
|
|
24
|
+
}
|
|
25
|
+
if (!isAddressValid(address)) {
|
|
26
|
+
errors.sender = new InvalidAddress("", {
|
|
27
|
+
currencyName: account.currency.name,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
else if (!isTransferIdValid(transaction.transferId)) {
|
|
31
|
+
errors.sender = new CasperInvalidTransferId("", {
|
|
32
|
+
maxTransferId: CASPER_MAX_TRANSFER_ID,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
const estimatedFees = transaction.fees;
|
|
36
|
+
let totalSpent = new BigNumber(0);
|
|
37
|
+
if (useAllAmount) {
|
|
38
|
+
totalSpent = account.spendableBalance;
|
|
39
|
+
amount = totalSpent.minus(estimatedFees);
|
|
40
|
+
if (amount.lte(0) || totalSpent.gt(balance)) {
|
|
41
|
+
errors.amount = new NotEnoughBalance();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (!useAllAmount) {
|
|
45
|
+
totalSpent = amount.plus(estimatedFees);
|
|
46
|
+
if (amount.eq(0)) {
|
|
47
|
+
errors.amount = new AmountRequired();
|
|
48
|
+
}
|
|
49
|
+
if (totalSpent.gt(account.spendableBalance)) {
|
|
50
|
+
errors.amount = new NotEnoughBalance();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (amount.lt(CASPER_MINIMUM_VALID_AMOUNT_MOTES) && !errors.amount) {
|
|
54
|
+
errors.amount = InvalidMinimumAmountError;
|
|
55
|
+
}
|
|
56
|
+
if (spendableBalance.minus(totalSpent).minus(estimatedFees).lt(CASPER_MINIMUM_VALID_AMOUNT_MOTES)) {
|
|
57
|
+
warnings.amount = MayBlockAccountError;
|
|
58
|
+
}
|
|
59
|
+
// log("debug", "[getTransactionStatus] finish fn");
|
|
60
|
+
return {
|
|
61
|
+
errors,
|
|
62
|
+
warnings,
|
|
63
|
+
estimatedFees,
|
|
64
|
+
amount,
|
|
65
|
+
totalSpent,
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
//# sourceMappingURL=getTransactionStatus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getTransactionStatus.js","sourceRoot":"","sources":["../../src/bridge/getTransactionStatus.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,OAAO,EACL,cAAc,EACd,cAAc,EACd,4CAA4C,EAC5C,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEvE,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EACL,iCAAiC,EACjC,sBAAsB,EACtB,oBAAoB,EACpB,yBAAyB,GAC1B,MAAM,WAAW,CAAC;AAEnB,MAAM,CAAC,MAAM,oBAAoB,GAIL,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,EAAE;IACzD,MAAM,MAAM,GAAgC,EAAE,CAAC;IAC/C,MAAM,QAAQ,GAAkC,EAAE,CAAC;IAEnD,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC;IAC9C,MAAM,EAAE,O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AAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;YAC5C,MAAM,CAAC,MAAM,GAAG,IAAI,gBAAgB,EAAE,CAAC;QACzC,CAAC;IACH,CAAC;IAED,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QACxC,IAAI,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACjB,MAAM,CAAC,MAAM,GAAG,IAAI,cAAc,EAAE,CAAC;QACvC,CAAC;QAED,IAAI,UAAU,CAAC,EAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,EAAE,CAAC;YAC5C,MAAM,CAAC,MAAM,GAAG,IAAI,gBAAgB,EAAE,CAAC;QACzC,CAAC;IACH,CAAC;IAED,IAAI,MAAM,CAAC,EAAE,CAAC,iCAAiC,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;QACnE,MAAM,CAAC,MAAM,GAAG,yBAAyB,CAAC;IAC5C,CAAC;IAED,IACE,gBAAgB,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,EAAE,CAAC,iCAAiC,CAAC,EAC7F,CAAC;QACD,QAAQ,CAAC,MAAM,GAAG,oBAAoB,CAAC;IACzC,CAAC;IAED,oDAAoD;IAEpD,OAAO;QACL,MAAM;QACN,QAAQ;QACR,aAAa;QACb,MAAM;QACN,UAAU;KACX,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
2
|
+
import type { Account, AccountBridge, CurrencyBridge } from "@ledgerhq/types-live";
|
|
3
|
+
import type { Transaction, CasperSigner } from "../types";
|
|
4
|
+
export declare function createBridges(signerContext: SignerContext<CasperSigner>): {
|
|
5
|
+
currencyBridge: CurrencyBridge;
|
|
6
|
+
accountBridge: AccountBridge<Transaction, Account, import("@ledgerhq/types-live").TransactionStatusCommon>;
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bridge/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACnF,OAAO,KAAK,EAAE,WAAW,EAAqB,YAAY,EAAE,MAAM,UAAU,CAAC;AAgD7E,wBAAgB,aAAa,CAAC,aAAa,EAAE,aAAa,CAAC,YAAY,CAAC;;;EAKvE"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { getSerializedAddressParameters, makeAccountBridgeReceive, makeScanAccounts, makeSync, updateTransaction, } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
2
|
+
import resolver from "../signer";
|
|
3
|
+
import getAddressWrapper from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
|
|
4
|
+
import { getTransactionStatus } from "./getTransactionStatus";
|
|
5
|
+
import { estimateMaxSpendable } from "./estimateMaxSpendable";
|
|
6
|
+
import { prepareTransaction } from "./prepareTransaction";
|
|
7
|
+
import { createTransaction } from "./createTransaction";
|
|
8
|
+
import { getAccountShape } from "./bridgeHelpers/accountShape";
|
|
9
|
+
import { buildSignOperation } from "./signOperation";
|
|
10
|
+
import { broadcast } from "./broadcast";
|
|
11
|
+
function buildCurrencyBridge(signerContext) {
|
|
12
|
+
const getAddress = resolver(signerContext);
|
|
13
|
+
const scanAccounts = makeScanAccounts({
|
|
14
|
+
getAccountShape,
|
|
15
|
+
getAddressFn: getAddressWrapper(getAddress),
|
|
16
|
+
});
|
|
17
|
+
return {
|
|
18
|
+
preload: () => Promise.resolve({}),
|
|
19
|
+
hydrate: () => { },
|
|
20
|
+
scanAccounts,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const sync = makeSync({ getAccountShape });
|
|
24
|
+
function buildAccountBridge(signerContext) {
|
|
25
|
+
const getAddress = resolver(signerContext);
|
|
26
|
+
const receive = makeAccountBridgeReceive(getAddressWrapper(getAddress));
|
|
27
|
+
const signOperation = buildSignOperation(signerContext);
|
|
28
|
+
return {
|
|
29
|
+
estimateMaxSpendable,
|
|
30
|
+
createTransaction,
|
|
31
|
+
updateTransaction,
|
|
32
|
+
getTransactionStatus,
|
|
33
|
+
prepareTransaction,
|
|
34
|
+
sync,
|
|
35
|
+
receive,
|
|
36
|
+
signOperation,
|
|
37
|
+
broadcast,
|
|
38
|
+
getSerializedAddressParameters,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export function createBridges(signerContext) {
|
|
42
|
+
return {
|
|
43
|
+
currencyBridge: buildCurrencyBridge(signerContext),
|
|
44
|
+
accountBridge: buildAccountBridge(signerContext),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/bridge/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,8BAA8B,EAC9B,wBAAwB,EACxB,gBAAgB,EAChB,QAAQ,EACR,iBAAiB,GAClB,MAAM,2CAA2C,CAAC;AACnD,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,iBAAiB,MAAM,mDAAmD,CAAC;AAIlF,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAA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AAE,MAAM,sBAAsB,CAAC;AAGrD,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,eAAO,MAAM,kBAAkB,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC,oBAAoB,CAa/E,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { updateTransaction } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
2
|
+
import { getEstimatedFees } from "./bridgeHelpers/fee";
|
|
3
|
+
export const prepareTransaction = async (account, transaction) => {
|
|
4
|
+
// log("debug", "[prepareTransaction] start fn");
|
|
5
|
+
const fees = getEstimatedFees();
|
|
6
|
+
const amount = transaction.useAllAmount
|
|
7
|
+
? account.spendableBalance.minus(transaction.fees)
|
|
8
|
+
: transaction.amount;
|
|
9
|
+
// log("debug", "[prepareTransaction] finish fn");
|
|
10
|
+
return updateTransaction(transaction, { fees, amount });
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=prepareTransaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prepareTransaction.js","sourceRoot":"","sources":["../../src/bridge/prepareTransaction.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,2CAA2C,CAAC;AAC9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAGvD,MAAM,CAAC,MAAM,kBAAkB,GAAqD,KAAK,EACvF,OAAO,EACP,WAAW,EACW,EAAE;IACxB,iDAAiD;IACjD,MAAM,IAAI,GAAG,gBAAgB,EAAE,CAAC;IAEhC,MAAM,MAAM,GAAG,WAAW,CAAC,YAAY;QACrC,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC;QAClD,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC;IAEvB,kDAAkD;IAClD,OAAO,iBAAiB,CAAC,WAAW,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;AAC1D,CAAC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Account, AccountBridge } from "@ledgerhq/types-live";
|
|
2
|
+
import { Transaction } from "../types";
|
|
3
|
+
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
4
|
+
import { CasperSigner } from "../types";
|
|
5
|
+
export declare const buildSignOperation: (signerContext: SignerContext<CasperSigner>) => AccountBridge<Transaction, Account>["signOperation"];
|
|
6
|
+
//# sourceMappingURL=signOperation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signOperation.d.ts","sourceRoot":"","sources":["../../src/bridge/signOperation.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAG9D,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAGxC,eAAO,MAAM,kBAAkB,kBAEZ,cAAc,YAAY,CAAC,KACzC,cAAc,WAAW,EAAE,OAAO,CAAC,CAAC,eAAe,CA0DlD,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Observable } from "rxjs";
|
|
2
|
+
import { log } from "@ledgerhq/logs";
|
|
3
|
+
import { DeployUtil } from "casper-js-sdk";
|
|
4
|
+
import { casperGetCLPublicKey, getAddress } from "../bridge/bridgeHelpers/addresses";
|
|
5
|
+
import { createNewDeploy } from "../bridge/bridgeHelpers/txn";
|
|
6
|
+
import { buildOptimisticOperation } from "./buildOptimisticOperation";
|
|
7
|
+
export const buildSignOperation = (signerContext) => ({ account, transaction, deviceId }) => new Observable(o => {
|
|
8
|
+
async function main() {
|
|
9
|
+
// log("debug", "[signOperation] start fn");
|
|
10
|
+
const { recipient } = transaction;
|
|
11
|
+
const { address, derivationPath } = getAddress(account);
|
|
12
|
+
const deploy = createNewDeploy(address, recipient, transaction.amount, transaction.fees, transaction.transferId);
|
|
13
|
+
// Serialize tx
|
|
14
|
+
const deployBytes = DeployUtil.deployToBytes(deploy);
|
|
15
|
+
log("debug", `[signOperation] serialized deploy: [${deployBytes.toString()}]`);
|
|
16
|
+
o.next({
|
|
17
|
+
type: "device-signature-requested",
|
|
18
|
+
});
|
|
19
|
+
// Sign by device
|
|
20
|
+
const { r } = await signerContext(deviceId, async (signer) => {
|
|
21
|
+
const r = await signer.sign(derivationPath, Buffer.from(deployBytes));
|
|
22
|
+
return { r };
|
|
23
|
+
});
|
|
24
|
+
o.next({
|
|
25
|
+
type: "device-signature-granted",
|
|
26
|
+
});
|
|
27
|
+
// signature verification
|
|
28
|
+
const deployHash = deploy.hash.toString();
|
|
29
|
+
const signature = r.signatureRS;
|
|
30
|
+
// sign deploy object
|
|
31
|
+
const signedDeploy = DeployUtil.setSignature(deploy, signature, casperGetCLPublicKey(address));
|
|
32
|
+
const operation = buildOptimisticOperation(account, transaction, deployHash);
|
|
33
|
+
o.next({
|
|
34
|
+
type: "signed",
|
|
35
|
+
signedOperation: {
|
|
36
|
+
operation,
|
|
37
|
+
signature: JSON.stringify(DeployUtil.deployToJson(signedDeploy)),
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
main().then(() => o.complete(), e => o.error(e));
|
|
42
|
+
});
|
|
43
|
+
//# sourceMappingURL=signOperation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signOperation.js","sourceRoot":"","sources":["../../src/bridge/signOperation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AACrF,OAAO,EAAE,eAAe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;QAC1C,MAAM,SAAS,GAAG,CAAC,CAAC,WAAW,CAAC;QAEhC,qBAAqB;QACrB,MAAM,YAAY,GAAG,UAAU,CAAC,YAAY,CAC1C,MAAM,EACN,SAAS,EACT,oBAAoB,CAAC,OAAO,CAAC,CAC9B,CAAC;QAEF,MAAM,SAAS,GAAG,wBAAwB,CAAC,OAAO,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;QAE7E,CAAC,CAAC,IAAI,CAAC;YACL,IAAI,EAAE,QAAQ;YACd,eAAe,EAAE;gBACf,SAAS;gBACT,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;aACjE;SACF,CAAC,CAAC;IACL,CAAC;IACD,IAAI,EAAE,CAAC,IAAI,CACT,GAAG,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,EAClB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAChB,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Transaction, TransactionRaw } from "../types";
|
|
2
|
+
import type { Account } from "@ledgerhq/types-live";
|
|
3
|
+
export declare const formatTransaction: ({ recipient, useAllAmount, amount }: Transaction, account: Account) => string;
|
|
4
|
+
export declare const fromTransactionRaw: (tr: TransactionRaw) => Transaction;
|
|
5
|
+
declare const _default: {
|
|
6
|
+
formatTransaction: ({ recipient, useAllAmount, amount }: Transaction, account: Account) => string;
|
|
7
|
+
fromTransactionRaw: (tr: TransactionRaw) => Transaction;
|
|
8
|
+
toTransactionRaw: (t: Transaction) => TransactionRaw;
|
|
9
|
+
fromTransactionStatusRaw: (ts: import("@ledgerhq/types-live").TransactionStatusCommonRaw) => import("@ledgerhq/types-live").TransactionStatusCommon;
|
|
10
|
+
toTransactionStatusRaw: (ts: import("@ledgerhq/types-live").TransactionStatusCommon) => import("@ledgerhq/types-live").TransactionStatusCommonRaw;
|
|
11
|
+
formatTransactionStatus: (t: import("@ledgerhq/types-live").TransactionCommon, { errors, warnings, estimatedFees, amount, totalSpent }: import("@ledgerhq/types-live").TransactionStatusCommon, mainAccount: Account) => string;
|
|
12
|
+
};
|
|
13
|
+
export default _default;
|
|
14
|
+
//# sourceMappingURL=transaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../src/bridge/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAQ5D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAKpD,eAAO,MAAM,iBAAiB,wCACS,WAAW,WACvC,OAAO,KACf,MAYa,CAAC;AAEjB,eAAO,MAAM,kBAAkB,OAAQ,cAAc,KAAG,WASvD,CAAC;;;;;;;;;AAcF,wBAOE"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { formatTransactionStatus } from "@ledgerhq/coin-framework/formatters";
|
|
2
|
+
import { fromTransactionCommonRaw, fromTransactionStatusRawCommon as fromTransactionStatusRaw, toTransactionCommonRaw, toTransactionStatusRawCommon as toTransactionStatusRaw, } from "@ledgerhq/coin-framework/serialization";
|
|
3
|
+
import { getAccountCurrency } from "@ledgerhq/coin-framework/account/index";
|
|
4
|
+
import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/index";
|
|
5
|
+
import BigNumber from "bignumber.js";
|
|
6
|
+
export const formatTransaction = ({ recipient, useAllAmount, amount }, account) => `
|
|
7
|
+
SEND ${useAllAmount
|
|
8
|
+
? "MAX"
|
|
9
|
+
: amount.isZero()
|
|
10
|
+
? ""
|
|
11
|
+
: " " +
|
|
12
|
+
formatCurrencyUnit(getAccountCurrency(account).units[0], amount, {
|
|
13
|
+
showCode: true,
|
|
14
|
+
disableRounding: true,
|
|
15
|
+
})}
|
|
16
|
+
TO ${recipient}`;
|
|
17
|
+
export const fromTransactionRaw = (tr) => {
|
|
18
|
+
const common = fromTransactionCommonRaw(tr);
|
|
19
|
+
return {
|
|
20
|
+
...common,
|
|
21
|
+
family: tr.family,
|
|
22
|
+
fees: new BigNumber(tr.fees),
|
|
23
|
+
amount: new BigNumber(tr.amount),
|
|
24
|
+
transferId: tr.transferId,
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
const toTransactionRaw = (t) => {
|
|
28
|
+
const common = toTransactionCommonRaw(t);
|
|
29
|
+
return {
|
|
30
|
+
...common,
|
|
31
|
+
family: t.family,
|
|
32
|
+
amount: t.amount.toFixed(),
|
|
33
|
+
fees: t.fees.toString(),
|
|
34
|
+
transferId: t.transferId,
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
export default {
|
|
38
|
+
formatTransaction,
|
|
39
|
+
fromTransactionRaw,
|
|
40
|
+
toTransactionRaw,
|
|
41
|
+
fromTransactionStatusRaw,
|
|
42
|
+
toTransactionStatusRaw,
|
|
43
|
+
formatTransactionStatus,
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=transaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../src/bridge/transaction.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAC9E,OAAO,EACL,wBAAwB,EACxB,8BAA8B,IAAI,wBAAwB,EAC1D,sBAAsB,EACtB,4BAA4B,IAAI,sBAAsB,GACvD,MAAM,wCAAwC,CAAC;AAEhD,OAAO,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAC;AAC/E,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAe,EAChD,OAAgB,EACR,EAAE,CAAC;OA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[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,OAAO,EACP,UAAU,EACV,aAAa,EACb,OAAO,EACP,cAAc,EACd,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/common-logic/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,OAAO,EACP,UAAU,EACV,aAAa,EACb,OAAO,EACP,cAAc,EACd,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
export declare const isNoErrorReturnCode: (code: number) => boolean;
|
|
4
|
+
export declare const getPath: (path: string) => string;
|
|
5
|
+
export declare const isValidHex: (msg: string) => boolean;
|
|
6
|
+
export declare const isValidBase64: (msg: string) => boolean;
|
|
7
|
+
export declare const isError: (r: {
|
|
8
|
+
returnCode: number;
|
|
9
|
+
errorMessage: string;
|
|
10
|
+
}) => void;
|
|
11
|
+
export declare const methodToString: (method: number) => string;
|
|
12
|
+
export declare const getBufferFromString: (message: string) => Buffer;
|
|
13
|
+
export declare function getRandomTransferID(): string;
|
|
14
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/common-logic/utils.ts"],"names":[],"mappings":";;AAOA,eAAO,MAAM,mBAAmB,SAAU,MAAM,KAAG,OAA0B,CAAC;AAE9E,eAAO,MAAM,OAAO,SAAU,MAAM,KAAG,MACqB,CAAC;AAE7D,eAAO,MAAM,UAAU,QAAS,MAAM,KAAG,OAAmC,CAAC;AAC7E,eAAO,MAAM,aAAa,QAAS,MAAM,KAAG,OAAsC,CAAC;AAEnF,eAAO,MAAM,OAAO,MAAO;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,KAAG,IAEzE,CAAC;AAEF,eAAO,MAAM,cAAc,WAAY,MAAM,KAAG,MAO/C,CAAC;AAEF,eAAO,MAAM,mBAAmB,YAAa,MAAM,KAAG,MAUrD,CAAC;AAYF,wBAAgB,mBAAmB,IAAI,MAAM,CAE5C"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
const validHexRegExp = new RegExp(/[0-9A-Fa-f]{6}/g);
|
|
3
|
+
const validBase64RegExp = new RegExp(/^(?:[A-Za-z\d+/]{4})*(?:[A-Za-z\d+/]{3}=|[A-Za-z\d+/]{2}==)?$/);
|
|
4
|
+
export const isNoErrorReturnCode = (code) => code === 0x9000;
|
|
5
|
+
export const getPath = (path) => path && path.substring(0, 2) !== "m/" ? `m/${path}` : path;
|
|
6
|
+
export const isValidHex = (msg) => validHexRegExp.test(msg);
|
|
7
|
+
export const isValidBase64 = (msg) => validBase64RegExp.test(msg);
|
|
8
|
+
export const isError = (r) => {
|
|
9
|
+
if (!isNoErrorReturnCode(r.returnCode))
|
|
10
|
+
throw new Error(`${r.returnCode} - ${r.errorMessage}`);
|
|
11
|
+
};
|
|
12
|
+
export const methodToString = (method) => {
|
|
13
|
+
switch (method) {
|
|
14
|
+
case 0:
|
|
15
|
+
return "Token transfer";
|
|
16
|
+
default:
|
|
17
|
+
return "Unknown";
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
export const getBufferFromString = (message) => {
|
|
21
|
+
if (isValidHex(message)) {
|
|
22
|
+
return Buffer.from(message, "hex");
|
|
23
|
+
}
|
|
24
|
+
if (isValidBase64(message)) {
|
|
25
|
+
return Buffer.from(message, "base64");
|
|
26
|
+
}
|
|
27
|
+
return Buffer.from(message);
|
|
28
|
+
};
|
|
29
|
+
function randomIntFromInterval(min, max) {
|
|
30
|
+
const minBig = new BigNumber(min);
|
|
31
|
+
const maxBig = new BigNumber(max);
|
|
32
|
+
const random = BigNumber.random().multipliedBy(maxBig.minus(minBig).plus(1)).plus(minBig);
|
|
33
|
+
const randomInt = random.integerValue(BigNumber.ROUND_FLOOR);
|
|
34
|
+
return randomInt.toString();
|
|
35
|
+
}
|
|
36
|
+
export function getRandomTransferID() {
|
|
37
|
+
return randomIntFromInterval(0, Number.MAX_SAFE_INTEGER);
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/common-logic/utils.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,MAAM,cAAc,GAAG,IAAI,MAAM,CAAC,iBAAiB,CAAC,CAAC;AACrD,MAAM,iBAAiB,GAAG,IAAI,MAAM,CAClC,+DAA+D,CAChE,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,IAAY,EAAW,EAAE,CAAC,IAAI,KAAK,MAAM,CAAC;AAE9E,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,IAAY,EAAU,EAAE,CAC9C,IAAI,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAE7D,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,GAAW,EAAW,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC7E,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,GAAW,EAAW,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAEnF,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,CAA+C,EAAQ,EAAE;IAC/E,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAC,UAAU,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAA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CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.unit.test.d.ts","sourceRoot":"","sources":["../../src/common-logic/utils.unit.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { CLPublicKeyTag } from "casper-js-sdk";
|
|
2
|
+
import { casperAddressFromPubKey, isAddressValid } from "../bridge/bridgeHelpers/addresses";
|
|
3
|
+
describe("Casper addresses", () => {
|
|
4
|
+
const pubKeys = {
|
|
5
|
+
// valid
|
|
6
|
+
validSecp256k1: "0203a17118ec0e64c4e4fdbdbee0ea14d118c9aaf08c6c81bbb776cae607ceb84ecb",
|
|
7
|
+
validEd25519: "016470ae57b0a3ad5a679d2e0422909bfb9ded445e20cbe6b4c9806f844c94d401",
|
|
8
|
+
validSecp256k1Checksum: "0203A17118eC0e64c4e4FdbDbEe0eA14D118C9aAf08C6c81bbB776Cae607cEB84EcB", // Checksummed
|
|
9
|
+
validEd25519Checksum: "016470AE57b0a3aD5A679d2e0422909Bfb9dEd445e20cbE6B4c9806f844c94d401", // Checksummed
|
|
10
|
+
// invalid
|
|
11
|
+
invalidSecp256k1: "0203A17118ec0e64c4e4fdbdbee0ea14d118c9aaf08c6c81bbc776cae607ceb84ecb",
|
|
12
|
+
invalidEd25519: "016470ae57b0a3ad5a679d2e0422909bfb9ded445e20cbe6b8c9806f844c94D401",
|
|
13
|
+
invalidAddresstype: "036470ae57b0a3ad5a679d2e0422909bfb9ded445e20cbe6b8c9806f844c94d401", // Invalid address type
|
|
14
|
+
invalidLength: "12345", // Invalid length
|
|
15
|
+
invalidCharacter: "xyz123", // Contains non-hex characters
|
|
16
|
+
invalidChecksum: "016470ae57b0a3ad5a679d2e0422909bfb9ded445e20cbe6b4c9806f844c94D400", // Invalid checksum
|
|
17
|
+
};
|
|
18
|
+
test("Check if valid addresses are valid", () => {
|
|
19
|
+
expect(isAddressValid(pubKeys.validEd25519)).toBe(true);
|
|
20
|
+
expect(isAddressValid(pubKeys.validSecp256k1)).toBe(true);
|
|
21
|
+
});
|
|
22
|
+
test("Check if invalid addresses are invalid", () => {
|
|
23
|
+
expect(isAddressValid(pubKeys.invalidEd25519)).toBe(false);
|
|
24
|
+
expect(isAddressValid(pubKeys.invalidSecp256k1)).toBe(false);
|
|
25
|
+
expect(isAddressValid(pubKeys.invalidLength)).toBe(false);
|
|
26
|
+
expect(isAddressValid(pubKeys.invalidCharacter)).toBe(false);
|
|
27
|
+
expect(isAddressValid(pubKeys.invalidChecksum)).toBe(false);
|
|
28
|
+
});
|
|
29
|
+
test("Get the address from the publick key", () => {
|
|
30
|
+
/**
|
|
31
|
+
* Extracts the public key and key signature from a given Casper address.
|
|
32
|
+
*
|
|
33
|
+
* @param {string} address - The Casper address from which to extract the public key and key signature.
|
|
34
|
+
* @returns {{ pubkey: Buffer, keySig: CLPublicKeyTag }} An object containing the public key as a Buffer and the key signature as a CLPublicKeyTag.
|
|
35
|
+
*/
|
|
36
|
+
function casperPubKeyFromAddress(address) {
|
|
37
|
+
const keySig = parseInt(address.slice(0, 2), 10);
|
|
38
|
+
const pubkeyHex = address.slice(2);
|
|
39
|
+
const pubkey = Buffer.from(pubkeyHex, "hex");
|
|
40
|
+
return { pubkey, keySig };
|
|
41
|
+
}
|
|
42
|
+
expect(casperAddressFromPubKey(casperPubKeyFromAddress(pubKeys.validSecp256k1).pubkey, CLPublicKeyTag.SECP256K1)).toBe(pubKeys.validSecp256k1);
|
|
43
|
+
expect(casperAddressFromPubKey(casperPubKeyFromAddress(pubKeys.validSecp256k1Checksum).pubkey, CLPublicKeyTag.SECP256K1)).toBe(pubKeys.validSecp256k1Checksum.toLowerCase());
|
|
44
|
+
expect(casperAddressFromPubKey(casperPubKeyFromAddress(pubKeys.validEd25519).pubkey, CLPublicKeyTag.ED25519)).toBe(pubKeys.validEd25519);
|
|
45
|
+
expect(casperAddressFromPubKey(casperPubKeyFromAddress(pubKeys.validEd25519Checksum).pubkey, CLPublicKeyTag.ED25519)).toBe(pubKeys.validEd25519Checksum.toLowerCase());
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
//# sourceMappingURL=utils.unit.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.unit.test.js","sourceRoot":"","sources":["../../src/common-logic/utils.unit.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAE5F,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,MAAM,OAAO,GAAG;QACd,QAAQ;QACR,cAAc,EAAE,sEAAsE;QACtF,YAAY,EAAE,oEAAoE;QAClF,sBAAsB,EAAE,sEAAsE,EAAE,cAAc;QAC9G,oBAAoB,EAAE,oEAAoE,EAAE,cAAc;QAC1G,UAAU;QACV,gBAAgB,EAAE,sEAAsE;QACxF,cAAc,EAAE,oEAAoE;QACpF,kBAAkB,EAAE,oEAAoE,EAAE,uBAAuB;QACjH,aAAa,EAAE,OAAO,EAAE,iBAAiB;QACzC,gBAAgB,EAAE,QAAQ,EAAE,8BAA8B;QAC1D,eAAe,EAAE,oEAAoE,EAAE,mBAAmB;KAC3G,CAAC;IAEF,IAAI,CAAC,oCAAoC,EAAE,GAAG,EAAE;QAC9C,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACxD,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,wCAAwC,EAAE,GAAG,EAAE;QAClD,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC3D,MAAM,CAAC,cAAc,CAAC,O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MAAM,EACpD,cAAc,CAAC,OAAO,CACvB,CACF,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QAC7B,MAAM,CACJ,uBAAuB,CACrB,uBAAuB,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC,MAAM,EAC5D,cAAc,CAAC,OAAO,CACvB,CACF,CAAC,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,WAAW,EAAE,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const CASPER_FEES_MOTES: number;
|
|
2
|
+
export declare const CASPER_FEES_CSPR = 0.1;
|
|
3
|
+
export declare const CASPER_MINIMUM_VALID_AMOUNT_MOTES: number;
|
|
4
|
+
export declare const CASPER_MINIMUM_VALID_AMOUNT_CSPR = 2.5;
|
|
5
|
+
export declare const CASPER_NETWORK = "casper";
|
|
6
|
+
export declare const CASPER_CHECKSUM_HEX_LEN = 32;
|
|
7
|
+
export declare const CASPER_MAX_TRANSFER_ID = "18446744073709551615";
|
|
8
|
+
export declare const MayBlockAccountError: Error;
|
|
9
|
+
export declare const InvalidMinimumAmountError: Error;
|
|
10
|
+
//# sourceMappingURL=consts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,iBAAiB,QAAY,CAAC;AAC3C,eAAO,MAAM,gBAAgB,MAAM,CAAC;AACpC,eAAO,MAAM,iCAAiC,QAAY,CAAC;AAC3D,eAAO,MAAM,gCAAgC,MAAM,CAAC;AACpD,eAAO,MAAM,cAAc,WAAW,CAAC;AACvC,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAE1C,eAAO,MAAM,sBAAsB,yBAAyB,CAAC;AAE7D,eAAO,MAAM,oBAAoB,OAE/B,CAAC;AAEH,eAAO,MAAM,yBAAyB,OAEpC,CAAC"}
|
package/lib-es/consts.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { InvalidMinimumAmount, MayBlockAccount } from "./errors";
|
|
2
|
+
export const CASPER_FEES_MOTES = 0.1 * 1e9;
|
|
3
|
+
export const CASPER_FEES_CSPR = 0.1;
|
|
4
|
+
export const CASPER_MINIMUM_VALID_AMOUNT_MOTES = 2.5 * 1e9;
|
|
5
|
+
export const CASPER_MINIMUM_VALID_AMOUNT_CSPR = 2.5;
|
|
6
|
+
export const CASPER_NETWORK = "casper";
|
|
7
|
+
export const CASPER_CHECKSUM_HEX_LEN = 32;
|
|
8
|
+
export const CASPER_MAX_TRANSFER_ID = "18446744073709551615";
|
|
9
|
+
export const MayBlockAccountError = new MayBlockAccount("", {
|
|
10
|
+
minAmount: `${CASPER_MINIMUM_VALID_AMOUNT_CSPR + CASPER_FEES_CSPR} CSPR`,
|
|
11
|
+
});
|
|
12
|
+
export const InvalidMinimumAmountError = new InvalidMinimumAmount("", {
|
|
13
|
+
minAmount: `${CASPER_MINIMUM_VALID_AMOUNT_CSPR} CSPR`,
|
|
14
|
+
});
|
|
15
|
+
//# sourceMappingURL=consts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEjE,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,GAAG,GAAG,CAAC;AAC3C,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,CAAC;AACpC,MAAM,CAAC,MAAM,iCAAiC,GAAG,GAAG,GAAG,GAAG,CAAC;AAC3D,MAAM,CAAC,MAAM,gCAAgC,GAAG,GAAG,CAAC;AACpD,MAAM,CAAC,MAAM,cAAc,GAAG,QAAQ,CAAC;AACvC,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAE1C,MAAM,CAAC,MAAM,sBAAsB,GAAG,sBAAsB,CAAC;AAE7D,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,eAAe,CAAC,EAAE,EAAE;IAC1D,SAAS,EAAE,GAAG,gCAAgC,GAAG,gBAAgB,OAAO;CACzE,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,yBAAyB,GAAG,IAAI,oBAAoB,CAAC,EAAE,EAAE;IACpE,SAAS,EAAE,GAAG,gCAAgC,OAAO;CACtD,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const CasperInvalidTransferId: import("@ledgerhq/errors/lib/helpers").LedgerErrorConstructor<{
|
|
2
|
+
[key: string]: unknown;
|
|
3
|
+
}>;
|
|
4
|
+
export declare const InvalidMinimumAmount: import("@ledgerhq/errors/lib/helpers").LedgerErrorConstructor<{
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
}>;
|
|
7
|
+
export declare const MayBlockAccount: import("@ledgerhq/errors/lib/helpers").LedgerErrorConstructor<{
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
}>;
|
|
10
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,uBAAuB;;EAAoD,CAAC;AACzF,eAAO,MAAM,oBAAoB;;EAAiD,CAAC;AACnF,eAAO,MAAM,eAAe;;EAA4C,CAAC"}
|
package/lib-es/errors.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { createCustomErrorClass } from "@ledgerhq/errors";
|
|
2
|
+
export const CasperInvalidTransferId = createCustomErrorClass("CasperInvalidTransferId");
|
|
3
|
+
export const InvalidMinimumAmount = createCustomErrorClass("InvalidMinimumAmount");
|
|
4
|
+
export const MayBlockAccount = createCustomErrorClass("MayBlockAccount");
|
|
5
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAE1D,MAAM,CAAC,MAAM,uBAAuB,GAAG,sBAAsB,CAAC,yBAAyB,CAAC,CAAC;AACzF,MAAM,CAAC,MAAM,oBAAoB,GAAG,sBAAsB,CAAC,sBAAsB,CAAC,CAAC;AACnF,MAAM,CAAC,MAAM,eAAe,GAAG,sBAAsB,CAAC,iBAAiB,CAAC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
2
|
+
import { CasperSigner } from "./types";
|
|
3
|
+
import { Account, AnyMessage } from "@ledgerhq/types-live";
|
|
4
|
+
export declare const signMessage: (signerContext: SignerContext<CasperSigner>) => (deviceId: string, account: Account, { message }: AnyMessage) => Promise<{
|
|
5
|
+
rsv: {
|
|
6
|
+
r: string;
|
|
7
|
+
s: string;
|
|
8
|
+
v: number;
|
|
9
|
+
};
|
|
10
|
+
signature: string;
|
|
11
|
+
}>;
|
|
12
|
+
declare const _default: {
|
|
13
|
+
signMessage: (signerContext: SignerContext<CasperSigner>) => (deviceId: string, account: Account, { message }: AnyMessage) => Promise<{
|
|
14
|
+
rsv: {
|
|
15
|
+
r: string;
|
|
16
|
+
s: string;
|
|
17
|
+
v: number;
|
|
18
|
+
};
|
|
19
|
+
signature: string;
|
|
20
|
+
}>;
|
|
21
|
+
};
|
|
22
|
+
export default _default;
|
|
23
|
+
//# sourceMappingURL=hw-signMessage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hw-signMessage.d.ts","sourceRoot":"","sources":["../src/hw-signMessage.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAE3D,eAAO,MAAM,WAAW,kBACN,cAAc,YAAY,CAAC,gBAC1B,MAAM,WAAW,OAAO,eAAe,UAAU;;;;;;;EAmBjE,CAAC;;;;;;;;;;;AAEJ,wBAA+B"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { log } from "@ledgerhq/logs";
|
|
2
|
+
import { getBufferFromString } from "./common-logic/utils";
|
|
3
|
+
export const signMessage = (signerContext) => async (deviceId, account, { message }) => {
|
|
4
|
+
log("debug", "start signMessage process");
|
|
5
|
+
if (!message)
|
|
6
|
+
throw new Error(`Message cannot be empty`);
|
|
7
|
+
if (typeof message !== "string")
|
|
8
|
+
throw new Error(`Signing EIP712Message not supported`);
|
|
9
|
+
const r = await signerContext(deviceId, async (signer) => await signer.sign(account.freshAddressPath, getBufferFromString(message)));
|
|
10
|
+
return {
|
|
11
|
+
rsv: {
|
|
12
|
+
r: Buffer.from(r.signature_compact.slice(0, 32)).toString("hex"),
|
|
13
|
+
s: Buffer.from(r.signature_compact.slice(32, 64)).toString("hex"),
|
|
14
|
+
v: parseInt(Buffer.from(r.signature_compact.slice(64, 65)).toString("hex"), 16),
|
|
15
|
+
},
|
|
16
|
+
signature: `0x${Buffer.from(r.signature_compact).toString("hex")}`,
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export default { signMessage };
|
|
20
|
+
//# sourceMappingURL=hw-signMessage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hw-signMessage.js","sourceRoot":"","sources":["../src/hw-signMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAGrC,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAG3D,MAAM,CAAC,MAAM,WAAW,GACtB,CAAC,aAA0C,EAAE,EAAE,CAC/C,KAAK,EAAE,QAAgB,EAAE,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"@ledgerhq/coin-framework/signer";
|
|
3
|
+
import { CasperSigner } from "../types";
|
|
4
|
+
declare function resolver(signerContext: SignerContext<CasperSigner>): GetAddressFn;
|
|
5
|
+
export default resolver;
|
|
6
|
+
//# sourceMappingURL=getAddress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAddress.d.ts","sourceRoot":"","sources":["../../src/signer/getAddress.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,mDAAmD,CAAC;AAEjF,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAGhE,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,iBAAS,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC,YAAY,CAAC,GAAG,YAAY,CAoB1E;AAED,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { log } from "@ledgerhq/logs";
|
|
2
|
+
import { CLPublicKeyTag } from "casper-js-sdk";
|
|
3
|
+
import { casperAddressFromPubKey } from "../bridge/bridgeHelpers/addresses";
|
|
4
|
+
function resolver(signerContext) {
|
|
5
|
+
return async (deviceId, { path, verify }) => {
|
|
6
|
+
log("debug", "start getAddress process");
|
|
7
|
+
const { r } = await signerContext(deviceId, async (signer) => {
|
|
8
|
+
const r = verify
|
|
9
|
+
? await signer.showAddressAndPubKey(path)
|
|
10
|
+
: await signer.getAddressAndPubKey(path);
|
|
11
|
+
return { r };
|
|
12
|
+
});
|
|
13
|
+
return {
|
|
14
|
+
path,
|
|
15
|
+
address: r.Address.length
|
|
16
|
+
? r.Address.toString().toLowerCase()
|
|
17
|
+
: casperAddressFromPubKey(r.publicKey, CLPublicKeyTag.SECP256K1),
|
|
18
|
+
publicKey: r.publicKey.toString("hex"),
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export default resolver;
|
|
23
|
+
//# sourceMappingURL=getAddress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAddress.js","sourceRoot":"","sources":["../../src/signer/getAddress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAIrC,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAG5E,SAAS,QAAQ,CAAC,aAA0C;IAC1D,OAAO,KAAK,EAAE,QAAgB,EAAE,EAAE,IAAI,EAAE,MAAM,EAAqB,EAAE,EAAE;QACrE,GAAG,CAAC,OAAO,EAAE,0BAA0B,CAAC,CAAC;QAEzC,MAAM,EAAE,CAAC,EAAE,GAAG,MAAM,aAAa,CAAC,QAAQ,EAAE,KAAK,EAAC,MAAM,EAAC,EAAE;YACzD,MAAM,CAAC,GAAG,MAAM;gBACd,CAAC,CAAC,MAAM,MAAM,CAAC,oBAAoB,CAAC,IAAI,CAAC;gBACzC,CAAC,CAAC,MAAM,MAAM,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC;YAE3C,OAAO,EAAE,CAAC,EAAE,CAAC;QACf,CAAC,CAAC,CAAC;QAEH,OAAO;YACL,IAAI;YACJ,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM;gBACvB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,WAAW,EAAE;gBACpC,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC,SAAS,EAAE,cAAc,CAAC,SAAS,CAAC;YAClE,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC;SACvC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAED,eAAe,QAAQ,CAAC"}
|