@ledgerhq/coin-xrp 0.2.0-next.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/.eslintrc.js +20 -0
- package/.turbo/turbo-build.log +4 -0
- package/.unimportedrc.json +27 -0
- package/CHANGELOG.md +19 -0
- package/LICENSE.txt +21 -0
- package/jest.config.js +6 -0
- package/lib/api/index.d.ts +12 -0
- package/lib/api/index.d.ts.map +1 -0
- package/lib/api/index.js +117 -0
- package/lib/api/index.js.map +1 -0
- package/lib/api/types.d.ts +188 -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/js.d.ts +10 -0
- package/lib/bridge/js.d.ts.map +1 -0
- package/lib/bridge/js.js +47 -0
- package/lib/bridge/js.js.map +1 -0
- package/lib/broadcast.d.ts +4 -0
- package/lib/broadcast.d.ts.map +1 -0
- package/lib/broadcast.js +25 -0
- package/lib/broadcast.js.map +1 -0
- package/lib/cli-transaction.d.ts +26 -0
- package/lib/cli-transaction.d.ts.map +1 -0
- package/lib/cli-transaction.js +32 -0
- package/lib/cli-transaction.js.map +1 -0
- package/lib/config.d.ts +9 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +16 -0
- package/lib/config.js.map +1 -0
- package/lib/createTransaction.d.ts +4 -0
- package/lib/createTransaction.d.ts.map +1 -0
- package/lib/createTransaction.js +18 -0
- package/lib/createTransaction.js.map +1 -0
- package/lib/datasets/dataset-1.d.ts +5 -0
- package/lib/datasets/dataset-1.d.ts.map +1 -0
- package/lib/datasets/dataset-1.js +154 -0
- package/lib/datasets/dataset-1.js.map +1 -0
- package/lib/deviceTransactionConfig.d.ts +11 -0
- package/lib/deviceTransactionConfig.d.ts.map +1 -0
- package/lib/deviceTransactionConfig.js +27 -0
- package/lib/deviceTransactionConfig.js.map +1 -0
- package/lib/estimateMaxSpendable.d.ts +4 -0
- package/lib/estimateMaxSpendable.d.ts.map +1 -0
- package/lib/estimateMaxSpendable.js +31 -0
- package/lib/estimateMaxSpendable.js.map +1 -0
- package/lib/getTransactionStatus.d.ts +4 -0
- package/lib/getTransactionStatus.d.ts.map +1 -0
- package/lib/getTransactionStatus.js +82 -0
- package/lib/getTransactionStatus.js.map +1 -0
- package/lib/hw-getAddress.d.ts +6 -0
- package/lib/hw-getAddress.d.ts.map +1 -0
- package/lib/hw-getAddress.js +23 -0
- package/lib/hw-getAddress.js.map +1 -0
- package/lib/logic.d.ts +11 -0
- package/lib/logic.d.ts.map +1 -0
- package/lib/logic.js +93 -0
- package/lib/logic.js.map +1 -0
- package/lib/prepareTransaction.d.ts +4 -0
- package/lib/prepareTransaction.d.ts.map +1 -0
- package/lib/prepareTransaction.js +53 -0
- package/lib/prepareTransaction.js.map +1 -0
- package/lib/signOperation.d.ts +6 -0
- package/lib/signOperation.d.ts.map +1 -0
- package/lib/signOperation.js +99 -0
- package/lib/signOperation.js.map +1 -0
- package/lib/signer.d.ts +11 -0
- package/lib/signer.d.ts.map +1 -0
- package/lib/signer.js +3 -0
- package/lib/signer.js.map +1 -0
- package/lib/specs.d.ts +7 -0
- package/lib/specs.d.ts.map +1 -0
- package/lib/specs.js +66 -0
- package/lib/specs.js.map +1 -0
- package/lib/speculos-deviceActions.d.ts +4 -0
- package/lib/speculos-deviceActions.d.ts.map +1 -0
- package/lib/speculos-deviceActions.js +49 -0
- package/lib/speculos-deviceActions.js.map +1 -0
- package/lib/synchronization.d.ts +3 -0
- package/lib/synchronization.d.ts.map +1 -0
- package/lib/synchronization.js +74 -0
- package/lib/synchronization.js.map +1 -0
- package/lib/transaction.d.ts +15 -0
- package/lib/transaction.d.ts.map +1 -0
- package/lib/transaction.js +56 -0
- package/lib/transaction.js.map +1 -0
- package/lib/types.d.ts +30 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +3 -0
- package/lib/types.js.map +1 -0
- package/lib-es/api/index.d.ts +12 -0
- package/lib-es/api/index.d.ts.map +1 -0
- package/lib-es/api/index.js +105 -0
- package/lib-es/api/index.js.map +1 -0
- package/lib-es/api/types.d.ts +188 -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/js.d.ts +10 -0
- package/lib-es/bridge/js.d.ts.map +1 -0
- package/lib-es/bridge/js.js +40 -0
- package/lib-es/bridge/js.js.map +1 -0
- package/lib-es/broadcast.d.ts +4 -0
- package/lib-es/broadcast.d.ts.map +1 -0
- package/lib-es/broadcast.js +21 -0
- package/lib-es/broadcast.js.map +1 -0
- package/lib-es/cli-transaction.d.ts +26 -0
- package/lib-es/cli-transaction.d.ts.map +1 -0
- package/lib-es/cli-transaction.js +26 -0
- package/lib-es/cli-transaction.js.map +1 -0
- package/lib-es/config.d.ts +9 -0
- package/lib-es/config.d.ts.map +1 -0
- package/lib-es/config.js +11 -0
- package/lib-es/config.js.map +1 -0
- package/lib-es/createTransaction.d.ts +4 -0
- package/lib-es/createTransaction.d.ts.map +1 -0
- package/lib-es/createTransaction.js +11 -0
- package/lib-es/createTransaction.js.map +1 -0
- package/lib-es/datasets/dataset-1.d.ts +5 -0
- package/lib-es/datasets/dataset-1.d.ts.map +1 -0
- package/lib-es/datasets/dataset-1.js +148 -0
- package/lib-es/datasets/dataset-1.js.map +1 -0
- package/lib-es/deviceTransactionConfig.d.ts +11 -0
- package/lib-es/deviceTransactionConfig.d.ts.map +1 -0
- package/lib-es/deviceTransactionConfig.js +25 -0
- package/lib-es/deviceTransactionConfig.js.map +1 -0
- package/lib-es/estimateMaxSpendable.d.ts +4 -0
- package/lib-es/estimateMaxSpendable.d.ts.map +1 -0
- package/lib-es/estimateMaxSpendable.js +24 -0
- package/lib-es/estimateMaxSpendable.js.map +1 -0
- package/lib-es/getTransactionStatus.d.ts +4 -0
- package/lib-es/getTransactionStatus.d.ts.map +1 -0
- package/lib-es/getTransactionStatus.js +75 -0
- package/lib-es/getTransactionStatus.js.map +1 -0
- package/lib-es/hw-getAddress.d.ts +6 -0
- package/lib-es/hw-getAddress.d.ts.map +1 -0
- package/lib-es/hw-getAddress.js +21 -0
- package/lib-es/hw-getAddress.js.map +1 -0
- package/lib-es/logic.d.ts +11 -0
- package/lib-es/logic.d.ts.map +1 -0
- package/lib-es/logic.js +82 -0
- package/lib-es/logic.js.map +1 -0
- package/lib-es/prepareTransaction.d.ts +4 -0
- package/lib-es/prepareTransaction.d.ts.map +1 -0
- package/lib-es/prepareTransaction.js +46 -0
- package/lib-es/prepareTransaction.js.map +1 -0
- package/lib-es/signOperation.d.ts +6 -0
- package/lib-es/signOperation.d.ts.map +1 -0
- package/lib-es/signOperation.js +92 -0
- package/lib-es/signOperation.js.map +1 -0
- package/lib-es/signer.d.ts +11 -0
- package/lib-es/signer.d.ts.map +1 -0
- package/lib-es/signer.js +2 -0
- package/lib-es/signer.js.map +1 -0
- package/lib-es/specs.d.ts +7 -0
- package/lib-es/specs.d.ts.map +1 -0
- package/lib-es/specs.js +61 -0
- package/lib-es/specs.js.map +1 -0
- package/lib-es/speculos-deviceActions.d.ts +4 -0
- package/lib-es/speculos-deviceActions.d.ts.map +1 -0
- package/lib-es/speculos-deviceActions.js +46 -0
- package/lib-es/speculos-deviceActions.js.map +1 -0
- package/lib-es/synchronization.d.ts +3 -0
- package/lib-es/synchronization.d.ts.map +1 -0
- package/lib-es/synchronization.js +67 -0
- package/lib-es/synchronization.js.map +1 -0
- package/lib-es/transaction.d.ts +15 -0
- package/lib-es/transaction.d.ts.map +1 -0
- package/lib-es/transaction.js +50 -0
- package/lib-es/transaction.js.map +1 -0
- package/lib-es/types.d.ts +30 -0
- package/lib-es/types.d.ts.map +1 -0
- package/lib-es/types.js +2 -0
- package/lib-es/types.js.map +1 -0
- package/package.json +81 -0
- package/please-add-coverage.test.ts +3 -0
- package/src/api/index.ts +138 -0
- package/src/api/types.ts +191 -0
- package/src/bridge/js.ts +56 -0
- package/src/broadcast.ts +20 -0
- package/src/cli-transaction.ts +44 -0
- package/src/config.ts +19 -0
- package/src/createTransaction.ts +13 -0
- package/src/datasets/dataset-1.ts +153 -0
- package/src/deviceTransactionConfig.ts +41 -0
- package/src/estimateMaxSpendable.ts +25 -0
- package/src/getTransactionStatus.ts +86 -0
- package/src/hw-getAddress.ts +20 -0
- package/src/logic.ts +101 -0
- package/src/prepareTransaction.ts +48 -0
- package/src/signOperation.ts +129 -0
- package/src/signer.ts +17 -0
- package/src/specs.ts +73 -0
- package/src/speculos-deviceActions.ts +53 -0
- package/src/synchronization.ts +73 -0
- package/src/transaction.ts +79 -0
- package/src/types.ts +39 -0
- package/tsconfig.json +13 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { InvalidAddressBecauseDestinationIsAlsoSource } from "@ledgerhq/errors";
|
|
3
|
+
import { fromTransactionRaw } from "../transaction";
|
|
4
|
+
export const newAddress1 = "rZvBc5e2YR1A9otS3r9DyGh3NDP8XLLp4";
|
|
5
|
+
export const dataset = {
|
|
6
|
+
implementations: ["mock", "ripplejs"],
|
|
7
|
+
currencies: {
|
|
8
|
+
ripple: {
|
|
9
|
+
scanAccounts: [
|
|
10
|
+
{
|
|
11
|
+
name: "ripple seed 1",
|
|
12
|
+
unstableAccounts: true,
|
|
13
|
+
// our account is getting spammed...
|
|
14
|
+
apdus: `
|
|
15
|
+
=> e00200400d038000002c8000009080000000
|
|
16
|
+
<= 2103c73f64083463fa923e1530af6f558204853873c6a45cbfb1f2f1e2ac2a5d989c2272734a4675764165634c333153513750594864504b6b3335625a456f78446d5231789000
|
|
17
|
+
=> e002004015058000002c80000090800000000000000000000000
|
|
18
|
+
<= 2103d1adcff3e0cf1232b1416a75cd6f23b49dd6a25c69bc291a1f6783ec6825ec062272616765584842365134566276765764547a4b414e776a65435434485846434b58379000
|
|
19
|
+
=> e002004015058000002c80000090800000010000000000000000
|
|
20
|
+
<= 21036da109ee84825eab0f55fb57bcf9ef0b05621e71fb0400266fb42d6f68f9487c2272425065393169766d67384347573450414e6f657555555173756d337470786a55469000
|
|
21
|
+
=> e002004015058000002c80000090800000020000000000000000
|
|
22
|
+
<= 2102df9a55b79fb3668dac70fee7372806195841cd713ab8da9fba82240f9db8a23921725a76426335653259523141396f745333723944794768334e445038584c4c70349000
|
|
23
|
+
`,
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
accounts: [
|
|
27
|
+
{
|
|
28
|
+
transactions: [
|
|
29
|
+
// FIXME
|
|
30
|
+
/*
|
|
31
|
+
{
|
|
32
|
+
name: "not enough spendable balance with base reserve",
|
|
33
|
+
transaction: fromTransactionRaw({
|
|
34
|
+
family: "xrp",
|
|
35
|
+
recipient: "rB6pwovsyrFWhPYUsjj9V3CHck985QjiXi",
|
|
36
|
+
amount: "15000000",
|
|
37
|
+
tag: null,
|
|
38
|
+
fee: "1",
|
|
39
|
+
feeCustomUnit: null,
|
|
40
|
+
networkInfo: null,
|
|
41
|
+
}),
|
|
42
|
+
expectedStatus: {
|
|
43
|
+
amount: BigNumber("15000000"),
|
|
44
|
+
estimatedFees: BigNumber("1"),
|
|
45
|
+
errors: {
|
|
46
|
+
amount: new NotEnoughSpendableBalance(null, {
|
|
47
|
+
minimumAmount: formatCurrencyUnit(
|
|
48
|
+
rippleUnit,
|
|
49
|
+
BigNumber("20"),
|
|
50
|
+
{
|
|
51
|
+
disableRounding: true,
|
|
52
|
+
useGrouping: false,
|
|
53
|
+
showCode: true,
|
|
54
|
+
}
|
|
55
|
+
),
|
|
56
|
+
}),
|
|
57
|
+
},
|
|
58
|
+
warnings: {},
|
|
59
|
+
totalSpent: BigNumber("15000001"),
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
*/
|
|
63
|
+
// FIXME
|
|
64
|
+
/*
|
|
65
|
+
{
|
|
66
|
+
name: "operation amount to low to create the recipient account",
|
|
67
|
+
transaction: fromTransactionRaw({
|
|
68
|
+
family: "xrp",
|
|
69
|
+
recipient: newAddress1,
|
|
70
|
+
amount: "10000000",
|
|
71
|
+
tag: null,
|
|
72
|
+
fee: "1",
|
|
73
|
+
feeCustomUnit: null,
|
|
74
|
+
networkInfo: null
|
|
75
|
+
}),
|
|
76
|
+
expectedStatus: {
|
|
77
|
+
amount: BigNumber("10000000"),
|
|
78
|
+
estimatedFees: BigNumber("1"),
|
|
79
|
+
errors: {
|
|
80
|
+
amount: new NotEnoughBalanceBecauseDestinationNotCreated()
|
|
81
|
+
},
|
|
82
|
+
warnings: {},
|
|
83
|
+
totalSpent: BigNumber("10000001")
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
*/
|
|
87
|
+
{
|
|
88
|
+
name: "recipient and sender must not be the same",
|
|
89
|
+
transaction: fromTransactionRaw({
|
|
90
|
+
family: "xrp",
|
|
91
|
+
recipient: "rageXHB6Q4VbvvWdTzKANwjeCT4HXFCKX7",
|
|
92
|
+
amount: "10000000",
|
|
93
|
+
tag: null,
|
|
94
|
+
fee: "1",
|
|
95
|
+
feeCustomUnit: null,
|
|
96
|
+
networkInfo: null,
|
|
97
|
+
}),
|
|
98
|
+
expectedStatus: {
|
|
99
|
+
amount: new BigNumber("10000000"),
|
|
100
|
+
estimatedFees: new BigNumber("1"),
|
|
101
|
+
errors: {
|
|
102
|
+
recipient: new InvalidAddressBecauseDestinationIsAlsoSource(),
|
|
103
|
+
},
|
|
104
|
+
warnings: {},
|
|
105
|
+
totalSpent: new BigNumber("10000001"),
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
name: "Operation with tag succeed",
|
|
110
|
+
transaction: fromTransactionRaw({
|
|
111
|
+
family: "xrp",
|
|
112
|
+
recipient: "rB6pwovsyrFWhPYUsjj9V3CHck985QjiXi",
|
|
113
|
+
amount: "10000000",
|
|
114
|
+
tag: 12345,
|
|
115
|
+
fee: "1",
|
|
116
|
+
feeCustomUnit: null,
|
|
117
|
+
networkInfo: null,
|
|
118
|
+
}),
|
|
119
|
+
expectedStatus: {
|
|
120
|
+
amount: new BigNumber("10000000"),
|
|
121
|
+
estimatedFees: new BigNumber("1"),
|
|
122
|
+
errors: {},
|
|
123
|
+
warnings: {},
|
|
124
|
+
totalSpent: new BigNumber("10000001"),
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
raw: {
|
|
129
|
+
id: "ripplejs:2:ripple:rageXHB6Q4VbvvWdTzKANwjeCT4HXFCKX7:",
|
|
130
|
+
seedIdentifier: "rageXHB6Q4VbvvWdTzKANwjeCT4HXFCKX7",
|
|
131
|
+
name: "XRP 1",
|
|
132
|
+
derivationMode: "",
|
|
133
|
+
index: 0,
|
|
134
|
+
freshAddress: "rageXHB6Q4VbvvWdTzKANwjeCT4HXFCKX7",
|
|
135
|
+
freshAddressPath: "44'/144'/0'/0/0",
|
|
136
|
+
blockHeight: 0,
|
|
137
|
+
operations: [],
|
|
138
|
+
pendingOperations: [],
|
|
139
|
+
currencyId: "ripple",
|
|
140
|
+
lastSyncDate: "",
|
|
141
|
+
balance: "21000310",
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
],
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
//# sourceMappingURL=dataset-1.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataset-1.js","sourceRoot":"","sources":["../../src/datasets/dataset-1.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,OAAO,EAAE,4CAA4C,EAAE,MAAM,kBAAkB,CAAC;AAChF,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAGpD,MAAM,CAAC,MAAM,WAAW,GAAG,mCAAmC,CAAC;AAE/D,MAAM,CAAC,MAAM,OAAO,GAA6B;IAC/C,eAAe,EAAE,CAAC,MAAM,EAAE,UAAU,CAAC;IACrC,UAAU,EAAE;QACV,MAAM,EAAE;YACN,YAAY,EAAE;gBACZ;oBACE,IAAI,EAAE,eAAe;o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AC,UAAU,CAAC;6BACtC;yBACF;qBACF;oBACD,GAAG,EAAE;wBACH,EAAE,EAAE,uDAAuD;wBAC3D,cAAc,EAAE,oCAAoC;wBACpD,IAAI,EAAE,OAAO;wBACb,cAAc,EAAE,EAAE;wBAClB,KAAK,EAAE,CAAC;wBACR,YAAY,EAAE,oCAAoC;wBAClD,gBAAgB,EAAE,iBAAiB;wBACnC,WAAW,EAAE,CAAC;wBACd,UAAU,EAAE,EAAE;wBACd,iBAAiB,EAAE,EAAE;wBACrB,UAAU,EAAE,QAAQ;wBACpB,YAAY,EAAE,EAAE;wBAChB,OAAO,EAAE,UAAU;qBACpB;iBACF;aACF;SACF;KACF;CACF,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AccountLike, Account } from "@ledgerhq/types-live";
|
|
2
|
+
import type { Transaction, TransactionStatus } from "./types";
|
|
3
|
+
import type { CommonDeviceTransactionField } from "@ledgerhq/coin-framework/transaction/common";
|
|
4
|
+
declare function getDeviceTransactionConfig({ transaction: { tag }, status: { amount, estimatedFees }, }: {
|
|
5
|
+
account: AccountLike;
|
|
6
|
+
parentAccount: Account | null | undefined;
|
|
7
|
+
transaction: Transaction;
|
|
8
|
+
status: TransactionStatus;
|
|
9
|
+
}): Array<CommonDeviceTransactionField>;
|
|
10
|
+
export default getDeviceTransactionConfig;
|
|
11
|
+
//# sourceMappingURL=deviceTransactionConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deviceTransactionConfig.d.ts","sourceRoot":"","sources":["../src/deviceTransactionConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC9D,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,6CAA6C,CAAC;AAEhG,iBAAS,0BAA0B,CAAC,EAClC,WAAW,EAAE,EAAE,GAAG,EAAE,EACpB,MAAM,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE,GAClC,EAAE;IACD,OAAO,EAAE,WAAW,CAAC;IACrB,aAAa,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC;IAC1C,WAAW,EAAE,WAAW,CAAC;IACzB,MAAM,EAAE,iBAAiB,CAAC;CAC3B,GAAG,KAAK,CAAC,4BAA4B,CAAC,CA0BtC;AAED,eAAe,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
function getDeviceTransactionConfig({ transaction: { tag }, status: { amount, estimatedFees }, }) {
|
|
2
|
+
const fields = [];
|
|
3
|
+
if (!amount.isZero()) {
|
|
4
|
+
fields.push({
|
|
5
|
+
type: "amount",
|
|
6
|
+
label: "Amount",
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
if (!estimatedFees.isZero()) {
|
|
10
|
+
fields.push({
|
|
11
|
+
type: "fees",
|
|
12
|
+
label: "Fees",
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
if (tag) {
|
|
16
|
+
fields.push({
|
|
17
|
+
type: "text",
|
|
18
|
+
label: "Tag",
|
|
19
|
+
value: tag ? String(tag) : "",
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return fields;
|
|
23
|
+
}
|
|
24
|
+
export default getDeviceTransactionConfig;
|
|
25
|
+
//# sourceMappingURL=deviceTransactionConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deviceTransactionConfig.js","sourceRoot":"","sources":["../src/deviceTransactionConfig.ts"],"names":[],"mappings":"AAIA,SAAS,0BAA0B,CAAC,EAClC,WAAW,EAAE,EAAE,GAAG,EAAE,EACpB,MAAM,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE,GAMlC;IACC,MAAM,MAAM,GAAwC,EAAE,CAAC;IAEvD,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC;QACrB,MAAM,CAAC,IAAI,CAAC;YACV,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,QAAQ;SAChB,CAAC,CAAC;IACL,CAAC;IAED,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,EAAE,CAAC;QAC5B,MAAM,CAAC,IAAI,CAAC;YACV,IAAI,EAAE,MAAM;YACZ,KAAK,EAAE,MAAM;SACd,CAAC,CAAC;IACL,CAAC;IAED,IAAI,GAAG,EAAE,CAAC;QACR,MAAM,CAAC,IAAI,CAAC;YACV,IAAI,EAAE,MAAM;YACZ,KAAK,EAAE,KAAK;YACZ,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE;SAC9B,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,eAAe,0BAA0B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"estimateMaxSpendable.d.ts","sourceRoot":"","sources":["../src/estimateMaxSpendable.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAMrD,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,eAAO,MAAM,oBAAoB,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC,sBAAsB,CAenF,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import BigNumber from "bignumber.js";
|
|
11
|
+
import { getMainAccount } from "@ledgerhq/coin-framework/account/index";
|
|
12
|
+
import { getAbandonSeedAddress } from "@ledgerhq/cryptoassets/abandonseed";
|
|
13
|
+
import { getTransactionStatus } from "./getTransactionStatus";
|
|
14
|
+
import { prepareTransaction } from "./prepareTransaction";
|
|
15
|
+
import { createTransaction } from "./createTransaction";
|
|
16
|
+
export const estimateMaxSpendable = (_a) => __awaiter(void 0, [_a], void 0, function* ({ account, parentAccount, transaction, }) {
|
|
17
|
+
const mainAccount = getMainAccount(account, parentAccount);
|
|
18
|
+
const newTransaction = yield prepareTransaction(mainAccount, Object.assign(Object.assign(Object.assign({}, createTransaction(account)), transaction), { recipient: (transaction === null || transaction === void 0 ? void 0 : transaction.recipient) || getAbandonSeedAddress("ripple"),
|
|
19
|
+
// public testing seed abandonx11,about
|
|
20
|
+
amount: new BigNumber(0) }));
|
|
21
|
+
const status = yield getTransactionStatus(mainAccount, newTransaction);
|
|
22
|
+
return BigNumber.max(0, account.spendableBalance.minus(status.estimatedFees));
|
|
23
|
+
});
|
|
24
|
+
//# sourceMappingURL=estimateMaxSpendable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"estimateMaxSpendable.js","sourceRoot":"","sources":["../src/estimateMaxSpendable.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,OAAO,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGxD,MAAM,CAAC,MAAM,oBAAoB,GAAuD,KAIrF,EAAE,4CAJ0F,EAC7F,OAAO,EACP,aAAa,EACb,WAAW,GACZ;IACC,MAAM,WAAW,GAAG,cAAc,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IAC3D,MAAM,cAAc,GAAG,MAAM,kBAAkB,CAAC,WAAW,gDACtD,iBAAiB,CAAC,OAAO,CAAC,GAC1B,WAAW,KACd,SAAS,EAAE,CAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,SAAS,KAAI,qBAAqB,CAAC,QAAQ,CAAC;QACpE,uCAAuC;QACvC,MAAM,EAAE,IAAI,SAAS,CAAC,CAAC,CAAC,IACxB,CAAC;IACH,MAAM,MAAM,GAAG,MAAM,oBAAoB,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;IACvE,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,KAAK,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC;AAChF,CAAC,CAAA,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Account, AccountBridge } from "@ledgerhq/types-live";
|
|
2
|
+
import { Transaction, TransactionStatus } from "./types";
|
|
3
|
+
export declare const getTransactionStatus: AccountBridge<Transaction, Account, TransactionStatus>["getTransactionStatus"];
|
|
4
|
+
//# sourceMappingURL=getTransactionStatus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getTransactionStatus.d.ts","sourceRoot":"","sources":["../src/getTransactionStatus.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE9D,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAIzD,eAAO,MAAM,oBAAoB,EAAE,aAAa,CAC9C,WAAW,EACX,OAAO,EACP,iBAAiB,CAClB,CAAC,sBAAsB,CA8DvB,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { AmountRequired, FeeNotLoaded, FeeRequired, FeeTooHigh, InvalidAddress, InvalidAddressBecauseDestinationIsAlsoSource, NotEnoughBalanceBecauseDestinationNotCreated, NotEnoughSpendableBalance, RecipientRequired, } from "@ledgerhq/errors";
|
|
11
|
+
import BigNumber from "bignumber.js";
|
|
12
|
+
import { isValidClassicAddress } from "ripple-address-codec";
|
|
13
|
+
import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/index";
|
|
14
|
+
import { getServerInfos, parseAPIValue } from "./api";
|
|
15
|
+
import { cachedRecipientIsNew } from "./logic";
|
|
16
|
+
export const getTransactionStatus = (account, transaction) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
const errors = {};
|
|
18
|
+
const warnings = {};
|
|
19
|
+
const serverInfos = yield getServerInfos();
|
|
20
|
+
const reserveBaseXRP = parseAPIValue(serverInfos.info.validated_ledger.reserve_base_xrp.toString());
|
|
21
|
+
const estimatedFees = new BigNumber(transaction.fee || 0);
|
|
22
|
+
const totalSpent = new BigNumber(transaction.amount).plus(estimatedFees);
|
|
23
|
+
const amount = new BigNumber(transaction.amount);
|
|
24
|
+
if (amount.gt(0) && estimatedFees.times(10).gt(amount)) {
|
|
25
|
+
warnings.feeTooHigh = new FeeTooHigh();
|
|
26
|
+
}
|
|
27
|
+
if (!transaction.fee) {
|
|
28
|
+
errors.fee = new FeeNotLoaded();
|
|
29
|
+
}
|
|
30
|
+
else if (transaction.fee.eq(0)) {
|
|
31
|
+
errors.fee = new FeeRequired();
|
|
32
|
+
}
|
|
33
|
+
else if (totalSpent.gt(account.balance.minus(reserveBaseXRP))) {
|
|
34
|
+
errors.amount = new NotEnoughSpendableBalance("", {
|
|
35
|
+
minimumAmount: formatCurrencyUnit(account.currency.units[0], reserveBaseXRP, {
|
|
36
|
+
disableRounding: true,
|
|
37
|
+
useGrouping: false,
|
|
38
|
+
showCode: true,
|
|
39
|
+
}),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
else if (transaction.recipient &&
|
|
43
|
+
(yield cachedRecipientIsNew(transaction.recipient)) &&
|
|
44
|
+
transaction.amount.lt(reserveBaseXRP)) {
|
|
45
|
+
errors.amount = new NotEnoughBalanceBecauseDestinationNotCreated("", {
|
|
46
|
+
minimalAmount: formatCurrencyUnit(account.currency.units[0], reserveBaseXRP, {
|
|
47
|
+
disableRounding: true,
|
|
48
|
+
useGrouping: false,
|
|
49
|
+
showCode: true,
|
|
50
|
+
}),
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
if (!transaction.recipient) {
|
|
54
|
+
errors.recipient = new RecipientRequired("");
|
|
55
|
+
}
|
|
56
|
+
else if (account.freshAddress === transaction.recipient) {
|
|
57
|
+
errors.recipient = new InvalidAddressBecauseDestinationIsAlsoSource();
|
|
58
|
+
}
|
|
59
|
+
else if (!isValidClassicAddress(transaction.recipient)) {
|
|
60
|
+
errors.recipient = new InvalidAddress("", {
|
|
61
|
+
currencyName: account.currency.name,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
if (!errors.amount && amount.eq(0)) {
|
|
65
|
+
errors.amount = new AmountRequired();
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
errors,
|
|
69
|
+
warnings,
|
|
70
|
+
estimatedFees,
|
|
71
|
+
amount,
|
|
72
|
+
totalSpent,
|
|
73
|
+
};
|
|
74
|
+
});
|
|
75
|
+
//# sourceMappingURL=getTransactionStatus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getTransactionStatus.js","sourceRoot":"","sources":["../src/getTransactionStatus.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EACL,cAAc,EACd,YAAY,EACZ,WAAW,EACX,UAAU,EACV,cAAc,EACd,4CAA4C,EAC5C,4CAA4C,EAC5C,yBAAyB,EACzB,iBAAiB,GAClB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAC;AAE/E,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAE/C,MAAM,CAAC,MAAM,oBAAoB,GAIL,CAAO,OAAO,EAAE,WAAW,EAAE,EAAE;IACzD,MAAM,MAAM,GAA0B,EAAE,CAAC;IACzC,MAAM,QAAQ,GAA0B,EAAE,CAAC;IAC3C,MAAM,WAAW,GAAG,MAAM,cAAc,EAAE,CAAC;IAC3C,MAAM,cAAc,GAAG,aAAa,CAClC,WAAW,CAAC,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,QAAQ,EAAE,CAC9D,CAAC;IACF,MAAM,aAAa,GAAG,IAAI,SAAS,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;IAC1D,MAAM,UAAU,GAAG,IAAI,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IACzE,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAEjD,IAAI,MAAM,CAAC,EAAE,CA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AC;IAED,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE,CAAC;QAC3B,MAAM,CAAC,SAAS,GAAG,IAAI,iBAAiB,CAAC,EAAE,CAAC,CAAC;IAC/C,CAAC;SAAM,IAAI,OAAO,CAAC,YAAY,KAAK,WAAW,CAAC,SAAS,EAAE,CAAC;QAC1D,MAAM,CAAC,SAAS,GAAG,IAAI,4CAA4C,EAAE,CAAC;IACxE,CAAC;SAAM,IAAI,CAAC,qBAAqB,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,CAAC;QACzD,MAAM,CAAC,SAAS,GAAG,IAAI,cAAc,CAAC,EAAE,EAAE;YACxC,YAAY,EAAE,OAAO,CAAC,QAAQ,CAAC,IAAI;SACpC,CAAC,CAAC;IACL,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACnC,MAAM,CAAC,MAAM,GAAG,IAAI,cAAc,EAAE,CAAC;IACvC,CAAC;IAED,OAAO;QACL,MAAM;QACN,QAAQ;QACR,aAAa;QACb,MAAM;QACN,UAAU;KACX,CAAC;AACJ,CAAC,CAAA,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { GetAddressFn } from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
|
|
2
|
+
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
3
|
+
import { XrpSigner } from "./signer";
|
|
4
|
+
declare const resolver: (signerContext: SignerContext<XrpSigner>) => GetAddressFn;
|
|
5
|
+
export default resolver;
|
|
6
|
+
//# sourceMappingURL=hw-getAddress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hw-getAddress.d.ts","sourceRoot":"","sources":["../src/hw-getAddress.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,mDAAmD,CAAC;AACjF,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAc,SAAS,EAAE,MAAM,UAAU,CAAC;AAEjD,QAAA,MAAM,QAAQ,kBAAmB,cAAc,SAAS,CAAC,KAAG,YAY3D,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
const resolver = (signerContext) => {
|
|
11
|
+
return (deviceId_1, _a) => __awaiter(void 0, [deviceId_1, _a], void 0, function* (deviceId, { path, verify }) {
|
|
12
|
+
const { address, publicKey } = (yield signerContext(deviceId, signer => signer.getAddress(path, verify, false)));
|
|
13
|
+
return {
|
|
14
|
+
path,
|
|
15
|
+
address,
|
|
16
|
+
publicKey,
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
export default resolver;
|
|
21
|
+
//# sourceMappingURL=hw-getAddress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hw-getAddress.js","sourceRoot":"","sources":["../src/hw-getAddress.ts"],"names":[],"mappings":";;;;;;;;;AAKA,MAAM,QAAQ,GAAG,CAAC,aAAuC,EAAgB,EAAE;IACzE,OAAO,iBAA8D,EAAE,wDAAzD,QAAgB,EAAE,EAAE,IAAI,EAAE,MAAM,EAAqB;QACjE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,CAAC,MAAM,aAAa,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE,CACrE,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,CACvC,CAAe,CAAC;QAEjB,OAAO;YACL,IAAI;YACJ,OAAO;YACP,SAAS;SACV,CAAC;IACJ,CAAC,CAAA,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { Account, Operation } from "@ledgerhq/types-live";
|
|
3
|
+
import { XrplOperation } from "./api/types";
|
|
4
|
+
export declare const NEW_ACCOUNT_ERROR_MESSAGE = "actNotFound";
|
|
5
|
+
export declare const UINT32_MAX: BigNumber;
|
|
6
|
+
export declare const validateTag: (tag: BigNumber) => boolean;
|
|
7
|
+
export declare const getNextValidSequence: (account: Account) => Promise<number>;
|
|
8
|
+
export declare const cachedRecipientIsNew: (recipient: string) => Promise<boolean>;
|
|
9
|
+
export declare const removeCachedRecipientIsNew: (recipient: string) => void;
|
|
10
|
+
export declare const filterOperations: (transactions: XrplOperation[], accountId: string, address: string) => Operation[];
|
|
11
|
+
//# sourceMappingURL=logic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logic.d.ts","sourceRoot":"","sources":["../src/logic.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAG1D,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,eAAO,MAAM,yBAAyB,gBAAgB,CAAC;AACvD,eAAO,MAAM,UAAU,WAAoC,CAAC;AAK5D,eAAO,MAAM,WAAW,QAAS,SAAS,YAIzC,CAAC;AAEF,eAAO,MAAM,oBAAoB,YAAmB,OAAO,oBAG1D,CAAC;AAiBF,eAAO,MAAM,oBAAoB,cAAqB,MAAM,qBAI3D,CAAC;AACF,eAAO,MAAM,0BAA0B,cAAe,MAAM,SAE3D,CAAC;AA0CF,eAAO,MAAM,gBAAgB,iBACb,aAAa,EAAE,aAClB,MAAM,WACR,MAAM,gBAShB,CAAC"}
|
package/lib-es/logic.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import BigNumber from "bignumber.js";
|
|
11
|
+
import { isValidClassicAddress } from "ripple-address-codec";
|
|
12
|
+
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
13
|
+
import { getAccountInfo } from "./api";
|
|
14
|
+
export const NEW_ACCOUNT_ERROR_MESSAGE = "actNotFound";
|
|
15
|
+
export const UINT32_MAX = new BigNumber(2).pow(32).minus(1);
|
|
16
|
+
/** @see https://xrpl.org/basic-data-types.html#specifying-time */
|
|
17
|
+
const RIPPLE_EPOCH = 946684800;
|
|
18
|
+
export const validateTag = (tag) => {
|
|
19
|
+
return (!tag.isNaN() && tag.isFinite() && tag.isInteger() && tag.isPositive() && tag.lte(UINT32_MAX));
|
|
20
|
+
};
|
|
21
|
+
export const getNextValidSequence = (account) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
+
const accInfo = yield getAccountInfo(account.freshAddress, true);
|
|
23
|
+
return accInfo.account_data.Sequence;
|
|
24
|
+
});
|
|
25
|
+
function isRecipientValid(recipient) {
|
|
26
|
+
return isValidClassicAddress(recipient);
|
|
27
|
+
}
|
|
28
|
+
const recipientIsNew = (recipient) => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
|
+
if (!isRecipientValid(recipient))
|
|
30
|
+
return false;
|
|
31
|
+
const info = yield getAccountInfo(recipient);
|
|
32
|
+
if (info.error === NEW_ACCOUNT_ERROR_MESSAGE) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
return false;
|
|
36
|
+
});
|
|
37
|
+
const cacheRecipientsNew = {};
|
|
38
|
+
export const cachedRecipientIsNew = (recipient) => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
+
if (recipient in cacheRecipientsNew)
|
|
40
|
+
return cacheRecipientsNew[recipient];
|
|
41
|
+
cacheRecipientsNew[recipient] = yield recipientIsNew(recipient);
|
|
42
|
+
return cacheRecipientsNew[recipient];
|
|
43
|
+
});
|
|
44
|
+
export const removeCachedRecipientIsNew = (recipient) => {
|
|
45
|
+
delete cacheRecipientsNew[recipient];
|
|
46
|
+
};
|
|
47
|
+
const XrplOperationToLiveOperation = (accountId, address) => ({ meta: { delivered_amount }, tx: { Fee, hash, inLedger, date, Account, Destination, Sequence }, }) => {
|
|
48
|
+
const type = Account === address ? "OUT" : "IN";
|
|
49
|
+
let value = delivered_amount && typeof delivered_amount === "string"
|
|
50
|
+
? new BigNumber(delivered_amount)
|
|
51
|
+
: new BigNumber(0);
|
|
52
|
+
const feeValue = new BigNumber(Fee);
|
|
53
|
+
if (type === "OUT") {
|
|
54
|
+
if (!Number.isNaN(feeValue)) {
|
|
55
|
+
value = value.plus(feeValue);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const toEpochDate = (RIPPLE_EPOCH + date) * 1000;
|
|
59
|
+
const op = {
|
|
60
|
+
id: encodeOperationId(accountId, hash, type),
|
|
61
|
+
hash: hash,
|
|
62
|
+
accountId: accountId,
|
|
63
|
+
type,
|
|
64
|
+
value,
|
|
65
|
+
fee: feeValue,
|
|
66
|
+
blockHash: null,
|
|
67
|
+
blockHeight: inLedger,
|
|
68
|
+
senders: [Account],
|
|
69
|
+
recipients: [Destination],
|
|
70
|
+
date: new Date(toEpochDate),
|
|
71
|
+
transactionSequenceNumber: Sequence,
|
|
72
|
+
extra: {},
|
|
73
|
+
};
|
|
74
|
+
return op;
|
|
75
|
+
};
|
|
76
|
+
export const filterOperations = (transactions, accountId, address) => {
|
|
77
|
+
return transactions
|
|
78
|
+
.filter(({ tx, meta }) => tx.TransactionType === "Payment" && typeof meta.delivered_amount === "string")
|
|
79
|
+
.map(XrplOperationToLiveOperation(accountId, address))
|
|
80
|
+
.filter((op) => Boolean(op));
|
|
81
|
+
};
|
|
82
|
+
//# sourceMappingURL=logic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logic.js","sourceRoot":"","sources":["../src/logic.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAEvE,OAAO,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAEvC,MAAM,CAAC,MAAM,yBAAyB,GAAG,aAAa,CAAC;AACvD,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAE5D,kEAAkE;AAClE,MAAM,YAAY,GAAG,SAAS,CAAC;AAE/B,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAc,EAAE,EAAE;IAC5C,OAAO,CACL,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,GAAG,CAAC,QAAQ,EAAE,IAAI,GAAG,CAAC,SAAS,EAAE,IAAI,GAAG,CAAC,UAAU,EAAE,IAAI,GAAG,CAAC,GAAG,CAAC,UAA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G,CAC9B,YAA6B,EAC7B,SAAiB,EACjB,OAAe,EACf,EAAE;IACF,OAAO,YAAY;SAChB,MAAM,CACL,CAAC,EAAE,EAAE,EAAE,IAAI,EAAiB,EAAE,EAAE,CAC9B,EAAE,CAAC,eAAe,KAAK,SAAS,IAAI,OAAO,IAAI,CAAC,gBAAgB,KAAK,QAAQ,CAChF;SACA,GAAG,CAAC,4BAA4B,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;SACrD,MAAM,CAAC,CAAC,EAAE,EAAmB,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;AAClD,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prepareTransaction.d.ts","sourceRoot":"","sources":["../src/prepareTransaction.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,OAAO,EAAe,WAAW,EAAE,MAAM,SAAS,CAAC;AAanD,eAAO,MAAM,kBAAkB,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC,oBAAoB,CA8B/E,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import BigNumber from "bignumber.js";
|
|
11
|
+
import { NetworkDown } from "@ledgerhq/errors";
|
|
12
|
+
import { getServerInfos, parseAPIValue } from "./api";
|
|
13
|
+
// FIXME this could be cleaner
|
|
14
|
+
const remapError = (error) => {
|
|
15
|
+
const msg = error.message;
|
|
16
|
+
if (msg.includes("Unable to resolve host") || msg.includes("Network is down")) {
|
|
17
|
+
return new NetworkDown();
|
|
18
|
+
}
|
|
19
|
+
return error;
|
|
20
|
+
};
|
|
21
|
+
export const prepareTransaction = (account, transaction) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
+
let networkInfo = transaction.networkInfo;
|
|
23
|
+
if (!networkInfo) {
|
|
24
|
+
try {
|
|
25
|
+
const info = yield getServerInfos();
|
|
26
|
+
const serverFee = parseAPIValue(info.info.validated_ledger.base_fee_xrp.toString());
|
|
27
|
+
networkInfo = {
|
|
28
|
+
family: "xrp",
|
|
29
|
+
serverFee,
|
|
30
|
+
baseReserve: new BigNumber(0), // NOT USED. will refactor later.
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
if (e instanceof Error) {
|
|
35
|
+
throw remapError(e);
|
|
36
|
+
}
|
|
37
|
+
throw e;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const fee = transaction.fee || networkInfo.serverFee;
|
|
41
|
+
if (transaction.networkInfo !== networkInfo || transaction.fee !== fee) {
|
|
42
|
+
return Object.assign(Object.assign({}, transaction), { networkInfo, fee });
|
|
43
|
+
}
|
|
44
|
+
return transaction;
|
|
45
|
+
});
|
|
46
|
+
//# sourceMappingURL=prepareTransaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prepareTransaction.js","sourceRoot":"","sources":["../src/prepareTransaction.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAGtD,8BAA8B;AAC9B,MAAM,UAAU,GAAG,CAAC,KAAY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} from "@ledgerhq/types-live";
|
|
2
|
+
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
3
|
+
import { XrpSigner } from "./signer";
|
|
4
|
+
import { Transaction } from "./types";
|
|
5
|
+
export declare const buildSignOperation: (signerContext: SignerContext<XrpSigner>) => AccountBridge<Transaction>["signOperation"];
|
|
6
|
+
//# sourceMappingURL=signOperation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signOperation.d.ts","sourceRoot":"","sources":["../src/signOperation.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAa,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAIhE,OAAO,EAAgB,SAAS,EAAE,MAAM,UAAU,CAAC;AAEnD,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAmBtC,eAAO,MAAM,kBAAkB,kBACb,cAAc,SAAS,CAAC,KAAG,cAAc,WAAW,CAAC,CAAC,eAAe,CAgGjF,CAAC"}
|