@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,92 @@
|
|
|
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 invariant from "invariant";
|
|
11
|
+
import { Observable } from "rxjs";
|
|
12
|
+
import BigNumber from "bignumber.js";
|
|
13
|
+
import { encode } from "ripple-binary-codec";
|
|
14
|
+
import { FeeNotLoaded } from "@ledgerhq/errors";
|
|
15
|
+
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
16
|
+
import XrplDefinitions from "ripple-binary-codec/dist/enums/definitions.json";
|
|
17
|
+
import { getNextValidSequence, removeCachedRecipientIsNew, UINT32_MAX, validateTag } from "./logic";
|
|
18
|
+
import { getLedgerIndex } from "./api";
|
|
19
|
+
const LEDGER_OFFSET = 20;
|
|
20
|
+
const { TRANSACTION_TYPES } = XrplDefinitions;
|
|
21
|
+
export const buildSignOperation = (signerContext) => ({ account, deviceId, transaction }) => new Observable(o => {
|
|
22
|
+
removeCachedRecipientIsNew(transaction.recipient);
|
|
23
|
+
function main() {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
var _a;
|
|
26
|
+
const { fee } = transaction;
|
|
27
|
+
if (!fee)
|
|
28
|
+
throw new FeeNotLoaded();
|
|
29
|
+
try {
|
|
30
|
+
const tag = transaction.tag ? transaction.tag : undefined;
|
|
31
|
+
const nextSequenceNumber = yield getNextValidSequence(account);
|
|
32
|
+
const xrplTransaction = {
|
|
33
|
+
TransactionType: "Payment",
|
|
34
|
+
Account: account.freshAddress,
|
|
35
|
+
Amount: transaction.amount.toFixed(),
|
|
36
|
+
Destination: transaction.recipient,
|
|
37
|
+
DestinationTag: tag,
|
|
38
|
+
Fee: fee.toFixed(),
|
|
39
|
+
Flags: 2147483648,
|
|
40
|
+
Sequence: nextSequenceNumber,
|
|
41
|
+
LastLedgerSequence: (yield getLedgerIndex()) + LEDGER_OFFSET,
|
|
42
|
+
};
|
|
43
|
+
if (tag)
|
|
44
|
+
invariant(validateTag(new BigNumber(tag)), `tag is set but is not in a valid format, should be between [0 - ${UINT32_MAX.toString()}]`);
|
|
45
|
+
o.next({
|
|
46
|
+
type: "device-signature-requested",
|
|
47
|
+
});
|
|
48
|
+
const signature = (yield signerContext(deviceId, (signer) => __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
const { freshAddressPath: derivationPath } = account;
|
|
50
|
+
const { publicKey } = yield signer.getAddress(derivationPath);
|
|
51
|
+
const serializedTransaction = encode(Object.assign(Object.assign({}, xrplTransaction), { SigningPubKey: publicKey }));
|
|
52
|
+
const transactionSignature = yield signer.signTransaction(derivationPath, serializedTransaction);
|
|
53
|
+
return encode(Object.assign(Object.assign({}, xrplTransaction), { SigningPubKey: publicKey, TxnSignature: transactionSignature })).toUpperCase();
|
|
54
|
+
})));
|
|
55
|
+
o.next({
|
|
56
|
+
type: "device-signature-granted",
|
|
57
|
+
});
|
|
58
|
+
const hash = "";
|
|
59
|
+
const operation = {
|
|
60
|
+
id: encodeOperationId(account.id, hash, "OUT"),
|
|
61
|
+
hash,
|
|
62
|
+
accountId: account.id,
|
|
63
|
+
type: "OUT",
|
|
64
|
+
value: transaction.amount,
|
|
65
|
+
fee,
|
|
66
|
+
blockHash: null,
|
|
67
|
+
blockHeight: null,
|
|
68
|
+
senders: [account.freshAddress],
|
|
69
|
+
recipients: [transaction.recipient],
|
|
70
|
+
date: new Date(),
|
|
71
|
+
transactionSequenceNumber: nextSequenceNumber,
|
|
72
|
+
extra: {},
|
|
73
|
+
};
|
|
74
|
+
o.next({
|
|
75
|
+
type: "signed",
|
|
76
|
+
signedOperation: {
|
|
77
|
+
operation,
|
|
78
|
+
signature,
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
catch (e) {
|
|
83
|
+
if (e instanceof Error) {
|
|
84
|
+
throw new Error((_a = e === null || e === void 0 ? void 0 : e.data) === null || _a === void 0 ? void 0 : _a.resultMessage);
|
|
85
|
+
}
|
|
86
|
+
throw e;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
main().then(() => o.complete(), e => o.error(e));
|
|
91
|
+
});
|
|
92
|
+
//# sourceMappingURL=signOperation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signOperation.js","sourceRoot":"","sources":["../src/signOperation.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGhD,OAAO,EAAE,iBAAi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C;oBAC/B,UAAU,EAAE,CAAC,WAAW,CAAC,SAAS,CAAC;oBACnC,IAAI,EAAE,IAAI,IAAI,EAAE;oBAChB,yBAAyB,EAAE,kBAAkB;oBAC7C,KAAK,EAAE,EAAE;iBACV,CAAC;gBAEF,CAAC,CAAC,IAAI,CAAC;oBACL,IAAI,EAAE,QAAQ;oBACd,eAAe,EAAE;wBACf,SAAS;wBACT,SAAS;qBACV;iBACF,CAAC,CAAC;YACL,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,IAAI,CAAC,YAAY,KAAK,EAAE,CAAC;oBACvB,MAAM,IAAI,KAAK,CACb,MAAC,CAAmD,aAAnD,CAAC,uBAAD,CAAC,CAAoD,IAAI,0CAAE,aAAa,CAC1E,CAAC;gBACJ,CAAC;gBAED,MAAM,CAAC,CAAC;YACV,CAAC;QACH,CAAC;KAAA;IAED,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,11 @@
|
|
|
1
|
+
export type XrpAddress = {
|
|
2
|
+
publicKey: string;
|
|
3
|
+
address: string;
|
|
4
|
+
chainCode?: string;
|
|
5
|
+
};
|
|
6
|
+
export type XrpSignature = string;
|
|
7
|
+
export interface XrpSigner {
|
|
8
|
+
getAddress(path: string, display?: boolean, chainCode?: boolean, ed25519?: boolean): Promise<XrpAddress>;
|
|
9
|
+
signTransaction(path: string, rawTxHex: string, ed25519?: boolean): Promise<XrpSignature>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=signer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../src/signer.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC;AAElC,MAAM,WAAW,SAAS;IACxB,UAAU,CACR,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,OAAO,EACjB,SAAS,CAAC,EAAE,OAAO,EACnB,OAAO,CAAC,EAAE,OAAO,GAChB,OAAO,CAAC,UAAU,CAAC,CAAC;IACvB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;CAC3F"}
|
package/lib-es/signer.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signer.js","sourceRoot":"","sources":["../src/signer.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"specs.d.ts","sourceRoot":"","sources":["../src/specs.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oCAAoC,CAAC;AAKlE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;;;;AA8D3C,wBAEE"}
|
package/lib-es/specs.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import invariant from "invariant";
|
|
2
|
+
import expect from "expect";
|
|
3
|
+
import { DeviceModelId } from "@ledgerhq/devices";
|
|
4
|
+
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/currencies";
|
|
5
|
+
import { parseCurrencyUnit } from "@ledgerhq/coin-framework/currencies/index";
|
|
6
|
+
import { botTest, genericTestDestination, pickSiblings } from "@ledgerhq/coin-framework/bot/specs";
|
|
7
|
+
import { acceptTransaction } from "./speculos-deviceActions";
|
|
8
|
+
const currency = getCryptoCurrencyById("ripple");
|
|
9
|
+
const minAmountCutoff = parseCurrencyUnit(currency.units[0], "0.1");
|
|
10
|
+
const reserve = parseCurrencyUnit(currency.units[0], "20");
|
|
11
|
+
const xrp = {
|
|
12
|
+
name: "XRP",
|
|
13
|
+
currency,
|
|
14
|
+
appQuery: {
|
|
15
|
+
model: DeviceModelId.nanoS,
|
|
16
|
+
appName: "XRP",
|
|
17
|
+
},
|
|
18
|
+
genericDeviceAction: acceptTransaction,
|
|
19
|
+
minViableAmount: minAmountCutoff,
|
|
20
|
+
mutations: [
|
|
21
|
+
{
|
|
22
|
+
name: "move ~50%",
|
|
23
|
+
maxRun: 2,
|
|
24
|
+
testDestination: genericTestDestination,
|
|
25
|
+
transaction: ({ account, siblings, bridge, maxSpendable }) => {
|
|
26
|
+
invariant(maxSpendable.gt(minAmountCutoff), "balance is too low");
|
|
27
|
+
const transaction = bridge.createTransaction(account);
|
|
28
|
+
const sibling = pickSiblings(siblings, 3);
|
|
29
|
+
const recipient = sibling.freshAddress;
|
|
30
|
+
let amount = maxSpendable.div(1.9 + 0.2 * Math.random()).integerValue();
|
|
31
|
+
if (!sibling.used && amount.lt(reserve)) {
|
|
32
|
+
invariant(maxSpendable.gt(reserve.plus(minAmountCutoff)), "not enough funds to send to new account");
|
|
33
|
+
amount = reserve;
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
transaction,
|
|
37
|
+
updates: [
|
|
38
|
+
{
|
|
39
|
+
amount,
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
recipient,
|
|
43
|
+
},
|
|
44
|
+
Math.random() > 0.5
|
|
45
|
+
? {
|
|
46
|
+
tag: 123,
|
|
47
|
+
}
|
|
48
|
+
: null,
|
|
49
|
+
],
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
test: ({ account, accountBeforeTransaction, operation }) => {
|
|
53
|
+
botTest("account balance moved with operation.value", () => expect(account.balance.toString()).toBe(accountBeforeTransaction.balance.minus(operation.value).toString()));
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57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1 @@
|
|
|
1
|
+
{"version":3,"file":"speculos-deviceActions.d.ts","sourceRoot":"","sources":["../src/speculos-deviceActions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AACvE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAO3C,eAAO,MAAM,iBAAiB,EAAE,YAAY,CAAC,WAAW,EAAE,GAAG,CA4C3D,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { deviceActionFlow, formatDeviceAmount, SpeculosButton, } from "@ledgerhq/coin-framework/bot/specs";
|
|
2
|
+
export const acceptTransaction = deviceActionFlow({
|
|
3
|
+
steps: [
|
|
4
|
+
{
|
|
5
|
+
title: "Transaction Type",
|
|
6
|
+
button: SpeculosButton.RIGHT,
|
|
7
|
+
expectedValue: () => "Payment",
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
title: "Amount",
|
|
11
|
+
button: SpeculosButton.RIGHT,
|
|
12
|
+
expectedValue: ({ account, status }) => formatDeviceAmount(account.currency, status.amount),
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
title: "Fee",
|
|
16
|
+
button: SpeculosButton.RIGHT,
|
|
17
|
+
expectedValue: ({ account, status }) => formatDeviceAmount(account.currency, status.estimatedFees),
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
title: "Destination Tag",
|
|
21
|
+
button: SpeculosButton.RIGHT,
|
|
22
|
+
expectedValue: ({ transaction }) => String(transaction.tag),
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
title: "Destination",
|
|
26
|
+
button: SpeculosButton.RIGHT,
|
|
27
|
+
trimValue: true,
|
|
28
|
+
expectedValue: ({ transaction }) => transaction.recipient,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
title: "Account",
|
|
32
|
+
button: SpeculosButton.RIGHT,
|
|
33
|
+
trimValue: true,
|
|
34
|
+
expectedValue: ({ account }) => account.freshAddress,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
title: "Accept",
|
|
38
|
+
button: SpeculosButton.BOTH,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
title: "Sign transaction",
|
|
42
|
+
button: SpeculosButton.BOTH,
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
});
|
|
46
|
+
//# sourceMappingURL=speculos-deviceActions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"speculos-deviceActions.js","sourceRoot":"","sources":["../src/speculos-deviceActions.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,GACf,MAAM,oCAAoC,CAAC;AAE5C,MAAM,CAAC,MAAM,iBAAiB,GAAmC,gBAAgB,CAAC;IAChF,KAAK,EAAE;QACL;YACE,KAAK,EAAE,kBAAkB;YACzB,MAAM,EAAE,cAAc,CAAC,KAAK;YAC5B,aAAa,EAAE,GAAG,EAAE,CAAC,SAAS;SAC/B;QACD;YACE,KAAK,EAAE,QAAQ;YACf,MAAM,EAAE,cAAc,CAAC,KAAK;YAC5B,aAAa,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,kBAAkB,CAAC,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC;SAC5F;QACD;YACE,KAAK,EAAE,KAAK;YACZ,MAAM,EAAE,cAAc,CAAC,KAAK;YAC5B,aAAa,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,CACrC,kBAAkB,CAAC,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,aAAa,CAAC;SAC7D;QACD;YACE,KAAK,EAAE,iBAAiB;YACxB,MAAM,EAAE,cAAc,CAAC,KAAK;YAC5B,aAAa,EAAE,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC;SAC5D;QACD;YACE,KAAK,EAAE,aAAa;YACpB,MAAM,EAAE,cAAc,CAAC,KAAK;YAC5B,SAAS,EAAE,IAAI;YACf,aAAa,EAAE,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,WAAW,CAAC,SAAS;SAC1D;QACD;YACE,KAAK,EAAE,SAAS;YAChB,MAAM,EAAE,cAAc,CAAC,KAAK;YAC5B,SAAS,EAAE,IAAI;YACf,aAAa,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,YAAY;SACrD;QACD;YACE,KAAK,EAAE,QAAQ;YACf,MAAM,EAAE,cAAc,CAAC,IAAI;SAC5B;QACD;YACE,KAAK,EAAE,kBAAkB;YACzB,MAAM,EAAE,cAAc,CAAC,IAAI;SAC5B;KACF;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"synchronization.d.ts","sourceRoot":"","sources":["../src/synchronization.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAY,MAAM,2CAA2C,CAAC;AAItF,eAAO,MAAM,eAAe,EAAE,eAiE7B,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
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 { encodeAccountId } from "@ledgerhq/coin-framework/account/index";
|
|
12
|
+
import { mergeOps } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
13
|
+
import { getAccountInfo, getServerInfos, getTransactions, parseAPIValue } from "./api";
|
|
14
|
+
import { NEW_ACCOUNT_ERROR_MESSAGE, filterOperations } from "./logic";
|
|
15
|
+
export const getAccountShape = (info) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
const { address, initialAccount, currency, derivationMode } = info;
|
|
17
|
+
const accountId = encodeAccountId({
|
|
18
|
+
type: "js",
|
|
19
|
+
version: "2",
|
|
20
|
+
currencyId: currency.id,
|
|
21
|
+
xpubOrAddress: address,
|
|
22
|
+
derivationMode,
|
|
23
|
+
});
|
|
24
|
+
const accountInfo = yield getAccountInfo(address);
|
|
25
|
+
if (!accountInfo || accountInfo.error === NEW_ACCOUNT_ERROR_MESSAGE) {
|
|
26
|
+
return {
|
|
27
|
+
id: accountId,
|
|
28
|
+
xpub: address,
|
|
29
|
+
blockHeight: 0,
|
|
30
|
+
balance: new BigNumber(0),
|
|
31
|
+
spendableBalance: new BigNumber(0),
|
|
32
|
+
operations: [],
|
|
33
|
+
operationsCount: 0,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const serverInfo = yield getServerInfos();
|
|
37
|
+
const reserveMinXRP = parseAPIValue(serverInfo.info.validated_ledger.reserve_base_xrp.toString());
|
|
38
|
+
const reservePerTrustline = parseAPIValue(serverInfo.info.validated_ledger.reserve_inc_xrp.toString());
|
|
39
|
+
const oldOperations = (initialAccount === null || initialAccount === void 0 ? void 0 : initialAccount.operations) || [];
|
|
40
|
+
const startAt = oldOperations.length ? (oldOperations[0].blockHeight || 0) + 1 : 0;
|
|
41
|
+
const ledgers = serverInfo.info.complete_ledgers.split("-");
|
|
42
|
+
const minLedgerVersion = Number(ledgers[0]);
|
|
43
|
+
const maxLedgerVersion = Number(ledgers[1]);
|
|
44
|
+
const trustlines = accountInfo.account_data.OwnerCount;
|
|
45
|
+
const balance = new BigNumber(accountInfo.account_data.Balance);
|
|
46
|
+
const spendableBalance = new BigNumber(accountInfo.account_data.Balance)
|
|
47
|
+
.minus(reserveMinXRP)
|
|
48
|
+
.minus(reservePerTrustline.times(trustlines));
|
|
49
|
+
const newTransactions = yield getTransactions(address, {
|
|
50
|
+
ledger_index_min: Math.max(startAt, // if there is no ops, it might be after a clear and we prefer to pull from the oldest possible history
|
|
51
|
+
minLedgerVersion),
|
|
52
|
+
ledger_index_max: maxLedgerVersion,
|
|
53
|
+
});
|
|
54
|
+
const newOperations = filterOperations(newTransactions, accountId, address);
|
|
55
|
+
const operations = mergeOps(oldOperations, newOperations);
|
|
56
|
+
const shape = {
|
|
57
|
+
id: accountId,
|
|
58
|
+
xpub: address,
|
|
59
|
+
blockHeight: maxLedgerVersion,
|
|
60
|
+
balance,
|
|
61
|
+
spendableBalance,
|
|
62
|
+
operations,
|
|
63
|
+
operationsCount: operations.length,
|
|
64
|
+
};
|
|
65
|
+
return shape;
|
|
66
|
+
});
|
|
67
|
+
//# sourceMappingURL=synchronization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"synchronization.js","sourceRoot":"","sources":["../src/synchronization.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AACzE,OAAO,EAAmB,QAAQ,EAAE,MAAM,2CAA2C,CAAC;AACtF,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACvF,OAAO,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEtE,MAAM,CAAC,MAAM,eAAe,GAAoB,CAAM,IAAI,EAAC,EAAE;IAC3D,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC;IACnE,MAAM,SAAS,GAAG,eAAe,CAAC;QAChC,IAAI,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AAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAE5C,MAAM,UAAU,GAAG,WAAW,CAAC,YAAY,CAAC,UAAU,CAAC;IAEvD,MAAM,OAAO,GAAG,IAAI,SAAS,CAAC,WAAW,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IAChE,MAAM,gBAAgB,GAAG,IAAI,SAAS,CAAC,WAAW,CAAC,YAAY,CAAC,OAAO,CAAC;SACrE,KAAK,CAAC,aAAa,CAAC;SACpB,KAAK,CAAC,mBAAmB,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;IAEhD,MAAM,eAAe,GAAG,MAAM,eAAe,CAAC,OAAO,EAAE;QACrD,gBAAgB,EAAE,IAAI,CAAC,GAAG,CACxB,OAAO,EAAE,uGAAuG;QAChH,gBAAgB,CACjB;QACD,gBAAgB,EAAE,gBAAgB;KACnC,CAAC,CAAC;IACH,MAAM,aAAa,GAAG,gBAAgB,CAAC,eAAe,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;IAE5E,MAAM,UAAU,GAAG,QAAQ,CAAC,aAAa,EAAE,aAA4B,CAAC,CAAC;IAEzE,MAAM,KAAK,GAAG;QACZ,EAAE,EAAE,SAAS;QACb,IAAI,EAAE,OAAO;QACb,WAAW,EAAE,gBAAgB;QAC7B,OAAO;QACP,gBAAgB;QAChB,UAAU;QACV,eAAe,EAAE,UAAU,CAAC,MAAM;KACnC,CAAC;IAEF,OAAO,KAAK,CAAC;AACf,CAAC,CAAA,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Transaction, TransactionRaw } from "./types";
|
|
2
|
+
import type { Account } from "@ledgerhq/types-live";
|
|
3
|
+
export declare const formatTransaction: ({ amount, recipient, fee, tag, useAllAmount }: Transaction, account: Account) => string;
|
|
4
|
+
export declare const fromTransactionRaw: (tr: TransactionRaw) => Transaction;
|
|
5
|
+
export declare const toTransactionRaw: (t: Transaction) => TransactionRaw;
|
|
6
|
+
declare const _default: {
|
|
7
|
+
formatTransaction: ({ amount, recipient, fee, tag, useAllAmount }: Transaction, account: Account) => string;
|
|
8
|
+
fromTransactionRaw: (tr: TransactionRaw) => Transaction;
|
|
9
|
+
toTransactionRaw: (t: Transaction) => TransactionRaw;
|
|
10
|
+
fromTransactionStatusRaw: (ts: import("@ledgerhq/types-live").TransactionStatusCommonRaw) => import("@ledgerhq/types-live").TransactionStatusCommon;
|
|
11
|
+
toTransactionStatusRaw: (ts: import("@ledgerhq/types-live").TransactionStatusCommon) => import("@ledgerhq/types-live").TransactionStatusCommonRaw;
|
|
12
|
+
formatTransactionStatus: (t: import("@ledgerhq/types-live").TransactionCommon, { errors, warnings, estimatedFees, amount, totalSpent }: import("@ledgerhq/types-live").TransactionStatusCommon, mainAccount: Account) => string;
|
|
13
|
+
};
|
|
14
|
+
export default _default;
|
|
15
|
+
//# sourceMappingURL=transaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../src/transaction.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAQ3D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAIpD,eAAO,MAAM,iBAAiB,kDACmB,WAAW,WACjD,OAAO,KACf,MAiB6B,CAAC;AAEjC,eAAO,MAAM,kBAAkB,OAAQ,cAAc,KAAG,WAgBvD,CAAC;AAEF,eAAO,MAAM,gBAAgB,MAAO,WAAW,KAAG,cAgBjD,CAAC;;;;;;;;;AAEF,wBAOE"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import { formatTransactionStatus } from "@ledgerhq/coin-framework/formatters";
|
|
3
|
+
import { fromTransactionCommonRaw, fromTransactionStatusRawCommon as fromTransactionStatusRaw, toTransactionCommonRaw, toTransactionStatusRawCommon as toTransactionStatusRaw, } from "@ledgerhq/coin-framework/serialization/transaction";
|
|
4
|
+
import { getAccountCurrency } from "@ledgerhq/coin-framework/account/index";
|
|
5
|
+
import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/index";
|
|
6
|
+
export const formatTransaction = ({ amount, recipient, fee, tag, useAllAmount }, account) => `
|
|
7
|
+
SEND ${useAllAmount
|
|
8
|
+
? "MAX"
|
|
9
|
+
: formatCurrencyUnit(getAccountCurrency(account).units[0], amount, {
|
|
10
|
+
showCode: true,
|
|
11
|
+
disableRounding: true,
|
|
12
|
+
})}
|
|
13
|
+
TO ${recipient}
|
|
14
|
+
with fee=${!fee
|
|
15
|
+
? "?"
|
|
16
|
+
: formatCurrencyUnit(getAccountCurrency(account).units[0], fee, {
|
|
17
|
+
showCode: true,
|
|
18
|
+
disableRounding: true,
|
|
19
|
+
})}${tag ? "\n tag=" + tag : ""}`;
|
|
20
|
+
export const fromTransactionRaw = (tr) => {
|
|
21
|
+
const common = fromTransactionCommonRaw(tr);
|
|
22
|
+
const { networkInfo } = tr;
|
|
23
|
+
return Object.assign(Object.assign({}, common), { family: tr.family, tag: tr.tag, fee: tr.fee ? new BigNumber(tr.fee) : null, feeCustomUnit: tr.feeCustomUnit,
|
|
24
|
+
// FIXME remove this field. this is not good.. we're dereferencing here. we should instead store an index (to lookup in currency.units on UI)
|
|
25
|
+
networkInfo: networkInfo && {
|
|
26
|
+
family: networkInfo.family,
|
|
27
|
+
serverFee: new BigNumber(networkInfo.serverFee),
|
|
28
|
+
baseReserve: new BigNumber(networkInfo.baseReserve),
|
|
29
|
+
} });
|
|
30
|
+
};
|
|
31
|
+
export const toTransactionRaw = (t) => {
|
|
32
|
+
const common = toTransactionCommonRaw(t);
|
|
33
|
+
const { networkInfo } = t;
|
|
34
|
+
return Object.assign(Object.assign({}, common), { family: t.family, tag: t.tag, fee: t.fee ? t.fee.toString() : null, feeCustomUnit: t.feeCustomUnit,
|
|
35
|
+
// FIXME remove this field. this is not good.. we're dereferencing here. we should instead store an index (to lookup in currency.units on UI)
|
|
36
|
+
networkInfo: networkInfo && {
|
|
37
|
+
family: networkInfo.family,
|
|
38
|
+
serverFee: networkInfo.serverFee.toString(),
|
|
39
|
+
baseReserve: networkInfo.baseReserve.toString(),
|
|
40
|
+
} });
|
|
41
|
+
};
|
|
42
|
+
export default {
|
|
43
|
+
formatTransaction,
|
|
44
|
+
fromTransactionRaw,
|
|
45
|
+
toTransactionRaw,
|
|
46
|
+
fromTransactionStatusRaw,
|
|
47
|
+
toTransactionStatusRaw,
|
|
48
|
+
formatTransactionStatus,
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=transaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../src/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAC9E,OAAO,EACL,wBAAwB,EACxB,8BAA8B,IAAI,wBAAwB,EAC1D,sBAAsB,EACtB,4BAA4B,IAAI,sBAAsB,GACvD,MAAM,oDAAoD,CAAC;AAE5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAC;AAE/E,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,EAAE,YAAY,EAAe,EAC1D,OAAgB,EACR,EAAE,CAAC;OAEX,YAAY;IACV,CAAC,CAAC,KAAK;IACP,CAAC,CAAC,kBAAkB,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE;QAC/D,QAAQ,EAAE,IAAI;QACd,eAAe,EAAE,IAAI;KACtB,CACP;KACK,SAAS;WAEZ,CAAC,GAAG;IACF,CAAC,CAAC,G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GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,IAAI,EACpC,aAAa,EAAE,CAAC,CAAC,aAAa;QAC9B,6IAA6I;QAC7I,WAAW,EAAE,WAAW,IAAI;YAC1B,MAAM,EAAE,WAAW,CAAC,MAAM;YAC1B,SAAS,EAAE,WAAW,CAAC,SAAS,CAAC,QAAQ,EAAE;YAC3C,WAAW,EAAE,WAAW,CAAC,WAAW,CAAC,QAAQ,EAAE;SAChD,IACD;AACJ,CAAC,CAAC;AAEF,eAAe;IACb,iBAAiB;IACjB,kBAAkB;IAClB,gBAAgB;IAChB,wBAAwB;IACxB,sBAAsB;IACtB,uBAAuB;CACxB,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { BigNumber } from "bignumber.js";
|
|
2
|
+
import type { Unit } from "@ledgerhq/types-cryptoassets";
|
|
3
|
+
import type { TransactionCommon, TransactionCommonRaw, TransactionStatusCommon, TransactionStatusCommonRaw } from "@ledgerhq/types-live";
|
|
4
|
+
export type NetworkInfo = {
|
|
5
|
+
family: "xrp";
|
|
6
|
+
serverFee: BigNumber;
|
|
7
|
+
baseReserve: BigNumber;
|
|
8
|
+
};
|
|
9
|
+
export type NetworkInfoRaw = {
|
|
10
|
+
family: "xrp";
|
|
11
|
+
serverFee: string;
|
|
12
|
+
baseReserve: string;
|
|
13
|
+
};
|
|
14
|
+
export type Transaction = TransactionCommon & {
|
|
15
|
+
family: "xrp";
|
|
16
|
+
fee: BigNumber | null | undefined;
|
|
17
|
+
networkInfo: NetworkInfo | null | undefined;
|
|
18
|
+
tag: number | null | undefined;
|
|
19
|
+
feeCustomUnit: Unit | null | undefined;
|
|
20
|
+
};
|
|
21
|
+
export type TransactionRaw = TransactionCommonRaw & {
|
|
22
|
+
family: "xrp";
|
|
23
|
+
fee: string | null | undefined;
|
|
24
|
+
networkInfo: NetworkInfoRaw | null | undefined;
|
|
25
|
+
tag: number | null | undefined;
|
|
26
|
+
feeCustomUnit: Unit | null | undefined;
|
|
27
|
+
};
|
|
28
|
+
export type TransactionStatus = TransactionStatusCommon;
|
|
29
|
+
export type TransactionStatusRaw = TransactionStatusCommonRaw;
|
|
30
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,KAAK,EACV,iBAAiB,EACjB,oBAAoB,EACpB,uBAAuB,EACvB,0BAA0B,EAC3B,MAAM,sBAAsB,CAAC;AAE9B,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,KAAK,CAAC;IACd,SAAS,EAAE,SAAS,CAAC;IACrB,WAAW,EAAE,SAAS,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,EAAE,KAAK,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,iBAAiB,GAAG;IAC5C,MAAM,EAAE,KAAK,CAAC;IACd,GAAG,EAAE,SAAS,GAAG,IAAI,GAAG,SAAS,CAAC;IAClC,WAAW,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,CAAC;IAC5C,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAC/B,aAAa,EAAE,IAAI,GAAG,IAAI,GAAG,SAAS,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,oBAAoB,GAAG;IAClD,MAAM,EAAE,KAAK,CAAC;IACd,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAC/B,WAAW,EAAE,cAAc,GAAG,IAAI,GAAG,SAAS,CAAC;IAC/C,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAC/B,aAAa,EAAE,IAAI,GAAG,IAAI,GAAG,SAAS,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,uBAAuB,CAAC;AACxD,MAAM,MAAM,oBAAoB,GAAG,0BAA0B,CAAC"}
|
package/lib-es/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ledgerhq/coin-xrp",
|
|
3
|
+
"version": "0.2.0-next.0",
|
|
4
|
+
"description": "Ledger XRP Coin integration",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"Ledger",
|
|
7
|
+
"LedgerWallet",
|
|
8
|
+
"xrp",
|
|
9
|
+
"Ripple",
|
|
10
|
+
"Hardware Wallet"
|
|
11
|
+
],
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/LedgerHQ/ledger-live.git"
|
|
15
|
+
},
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/LedgerHQ/ledger-live/issues"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://github.com/LedgerHQ/ledger-live/tree/develop/libs/coin-modules/coin-xrp",
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"typesVersions": {
|
|
24
|
+
"*": {
|
|
25
|
+
"lib/*": [
|
|
26
|
+
"lib/*"
|
|
27
|
+
],
|
|
28
|
+
"lib-es/*": [
|
|
29
|
+
"lib-es/*"
|
|
30
|
+
],
|
|
31
|
+
"*": [
|
|
32
|
+
"lib/*"
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"exports": {
|
|
37
|
+
"./lib/*": "./lib/*.js",
|
|
38
|
+
"./lib-es/*": "./lib-es/*.js",
|
|
39
|
+
"./*": {
|
|
40
|
+
"require": "./lib/*.js",
|
|
41
|
+
"default": "./lib-es/*.js"
|
|
42
|
+
},
|
|
43
|
+
"./package.json": "./package.json"
|
|
44
|
+
},
|
|
45
|
+
"license": "Apache-2.0",
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"bignumber.js": "^9.1.2",
|
|
48
|
+
"invariant": "^2.2.4",
|
|
49
|
+
"ripple-address-codec": "^5.0.0",
|
|
50
|
+
"ripple-binary-codec": "^1.3.0",
|
|
51
|
+
"rxjs": "^7.8.1",
|
|
52
|
+
"@ledgerhq/coin-framework": "^0.14.0-next.0",
|
|
53
|
+
"@ledgerhq/cryptoassets": "^13.1.0-next.0",
|
|
54
|
+
"@ledgerhq/devices": "^8.4.0-next.0",
|
|
55
|
+
"@ledgerhq/errors": "^6.17.0-next.0",
|
|
56
|
+
"@ledgerhq/live-network": "^1.3.0-next.0",
|
|
57
|
+
"@ledgerhq/types-live": "^6.48.0-next.0"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@types/invariant": "^2.2.37",
|
|
61
|
+
"@types/jest": "^29.5.12",
|
|
62
|
+
"expect": "^27.4.6",
|
|
63
|
+
"jest": "^29.7.0",
|
|
64
|
+
"ts-jest": "^29.1.1",
|
|
65
|
+
"typescript": "^5.4.5",
|
|
66
|
+
"@ledgerhq/types-cryptoassets": "^7.13.0-next.0"
|
|
67
|
+
},
|
|
68
|
+
"scripts": {
|
|
69
|
+
"clean": "rimraf lib lib-es",
|
|
70
|
+
"build": "tsc && tsc -m ES6 --outDir lib-es",
|
|
71
|
+
"coverage": "jest --coverage --testPathIgnorePatterns='/bridge.integration.test.ts|node_modules|lib-es|lib/' --passWithNoTests && mv coverage/coverage-final.json coverage/coverage-xrp.json",
|
|
72
|
+
"prewatch": "pnpm build",
|
|
73
|
+
"watch": "tsc --watch",
|
|
74
|
+
"doc": "documentation readme src/** --section=API --pe ts --re ts --re d.ts",
|
|
75
|
+
"lint": "eslint ./src --no-error-on-unmatched-pattern --ext .ts,.tsx --cache",
|
|
76
|
+
"lint:fix": "pnpm lint --fix",
|
|
77
|
+
"test": "jest",
|
|
78
|
+
"typecheck": "tsc --noEmit",
|
|
79
|
+
"unimported": "unimported"
|
|
80
|
+
}
|
|
81
|
+
}
|