@ledgerhq/coin-xrp 6.2.2 → 6.3.0-nightly.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +20 -0
- package/lib/api/index.d.ts +2 -11
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.integ.test.js +20 -5
- package/lib/api/index.integ.test.js.map +1 -1
- package/lib/api/index.js +16 -5
- package/lib/api/index.js.map +1 -1
- package/lib/api/index.test.js +18 -9
- package/lib/api/index.test.js.map +1 -1
- package/lib/index.d.ts +0 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +0 -3
- package/lib/index.js.map +1 -1
- package/lib/logic/getAccountInfo.d.ts +3 -0
- package/lib/logic/getAccountInfo.d.ts.map +1 -0
- package/lib/logic/getAccountInfo.js +9 -0
- package/lib/logic/getAccountInfo.js.map +1 -0
- package/lib/logic/getBalance.d.ts.map +1 -1
- package/lib/logic/getBalance.js +13 -1
- package/lib/logic/getBalance.js.map +1 -1
- package/lib/logic/getBalance.test.js +14 -1
- package/lib/logic/getBalance.test.js.map +1 -1
- package/lib/logic/getTransactionStatus.d.ts +3 -0
- package/lib/logic/getTransactionStatus.d.ts.map +1 -0
- package/lib/{bridge → logic}/getTransactionStatus.js +15 -19
- package/lib/logic/getTransactionStatus.js.map +1 -0
- package/lib/logic/getTransactionStatus.test.d.ts +2 -0
- package/lib/logic/getTransactionStatus.test.d.ts.map +1 -0
- package/lib/logic/getTransactionStatus.test.js +184 -0
- package/lib/logic/getTransactionStatus.test.js.map +1 -0
- package/lib/logic/index.d.ts +3 -1
- package/lib/logic/index.d.ts.map +1 -1
- package/lib/logic/index.js +5 -2
- package/lib/logic/index.js.map +1 -1
- package/lib/logic/utils.d.ts +0 -1
- package/lib/logic/utils.d.ts.map +1 -1
- package/lib/logic/utils.js +14 -10
- package/lib/logic/utils.js.map +1 -1
- package/lib/test/bridgeDatasetTest.js +7 -7
- package/lib/test/bridgeDatasetTest.js.map +1 -1
- package/lib/{bridge/transaction.d.ts → transaction.d.ts} +1 -1
- package/lib/transaction.d.ts.map +1 -0
- package/lib/transaction.js.map +1 -0
- package/lib/types/model.d.ts +7 -0
- package/lib/types/model.d.ts.map +1 -1
- package/lib-es/api/index.d.ts +2 -11
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.integ.test.js +20 -5
- package/lib-es/api/index.integ.test.js.map +1 -1
- package/lib-es/api/index.js +17 -6
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/api/index.test.js +18 -9
- package/lib-es/api/index.test.js.map +1 -1
- package/lib-es/index.d.ts +0 -1
- package/lib-es/index.d.ts.map +1 -1
- package/lib-es/index.js +0 -1
- package/lib-es/index.js.map +1 -1
- package/lib-es/logic/getAccountInfo.d.ts +3 -0
- package/lib-es/logic/getAccountInfo.d.ts.map +1 -0
- package/lib-es/logic/getAccountInfo.js +6 -0
- package/lib-es/logic/getAccountInfo.js.map +1 -0
- package/lib-es/logic/getBalance.d.ts.map +1 -1
- package/lib-es/logic/getBalance.js +14 -2
- package/lib-es/logic/getBalance.js.map +1 -1
- package/lib-es/logic/getBalance.test.js +14 -1
- package/lib-es/logic/getBalance.test.js.map +1 -1
- package/lib-es/logic/getTransactionStatus.d.ts +3 -0
- package/lib-es/logic/getTransactionStatus.d.ts.map +1 -0
- package/lib-es/{bridge → logic}/getTransactionStatus.js +13 -14
- package/lib-es/logic/getTransactionStatus.js.map +1 -0
- package/lib-es/logic/getTransactionStatus.test.d.ts +2 -0
- package/lib-es/logic/getTransactionStatus.test.d.ts.map +1 -0
- package/lib-es/logic/getTransactionStatus.test.js +159 -0
- package/lib-es/logic/getTransactionStatus.test.js.map +1 -0
- package/lib-es/logic/index.d.ts +3 -1
- package/lib-es/logic/index.d.ts.map +1 -1
- package/lib-es/logic/index.js +3 -1
- package/lib-es/logic/index.js.map +1 -1
- package/lib-es/logic/utils.d.ts +0 -1
- package/lib-es/logic/utils.d.ts.map +1 -1
- package/lib-es/logic/utils.js +13 -8
- package/lib-es/logic/utils.js.map +1 -1
- package/lib-es/test/bridgeDatasetTest.js +7 -7
- package/lib-es/test/bridgeDatasetTest.js.map +1 -1
- package/lib-es/{bridge/transaction.d.ts → transaction.d.ts} +1 -1
- package/lib-es/transaction.d.ts.map +1 -0
- package/lib-es/transaction.js.map +1 -0
- package/lib-es/types/model.d.ts +7 -0
- package/lib-es/types/model.d.ts.map +1 -1
- package/package.json +7 -8
- package/src/api/index.integ.test.ts +20 -6
- package/src/api/index.test.ts +23 -22
- package/src/api/index.ts +30 -19
- package/src/index.ts +0 -1
- package/src/logic/getAccountInfo.ts +7 -0
- package/src/logic/getBalance.test.ts +14 -1
- package/src/logic/getBalance.ts +18 -2
- package/src/logic/getTransactionStatus.test.ts +215 -0
- package/src/{bridge → logic}/getTransactionStatus.ts +18 -21
- package/src/logic/index.ts +3 -6
- package/src/logic/utils.ts +24 -8
- package/src/test/bridgeDatasetTest.ts +7 -7
- package/src/{bridge/transaction.ts → transaction.ts} +1 -1
- package/src/types/model.ts +11 -0
- package/lib/bridge/broadcast.d.ts +0 -4
- package/lib/bridge/broadcast.d.ts.map +0 -1
- package/lib/bridge/broadcast.js +0 -11
- package/lib/bridge/broadcast.js.map +0 -1
- package/lib/bridge/createTransaction.d.ts +0 -4
- package/lib/bridge/createTransaction.d.ts.map +0 -1
- package/lib/bridge/createTransaction.js +0 -18
- package/lib/bridge/createTransaction.js.map +0 -1
- package/lib/bridge/estimateMaxSpendable.d.ts +0 -4
- package/lib/bridge/estimateMaxSpendable.d.ts.map +0 -1
- package/lib/bridge/estimateMaxSpendable.js +0 -26
- package/lib/bridge/estimateMaxSpendable.js.map +0 -1
- package/lib/bridge/getTransactionStatus.d.ts +0 -4
- package/lib/bridge/getTransactionStatus.d.ts.map +0 -1
- package/lib/bridge/getTransactionStatus.js.map +0 -1
- package/lib/bridge/index.d.ts +0 -11
- package/lib/bridge/index.d.ts.map +0 -1
- package/lib/bridge/index.js +0 -47
- package/lib/bridge/index.js.map +0 -1
- package/lib/bridge/prepareTransaction.d.ts +0 -4
- package/lib/bridge/prepareTransaction.d.ts.map +0 -1
- package/lib/bridge/prepareTransaction.js +0 -14
- package/lib/bridge/prepareTransaction.js.map +0 -1
- package/lib/bridge/signOperation.d.ts +0 -5
- package/lib/bridge/signOperation.d.ts.map +0 -1
- package/lib/bridge/signOperation.js +0 -76
- package/lib/bridge/signOperation.js.map +0 -1
- package/lib/bridge/synchronization.d.ts +0 -3
- package/lib/bridge/synchronization.d.ts.map +0 -1
- package/lib/bridge/synchronization.js +0 -85
- package/lib/bridge/synchronization.js.map +0 -1
- package/lib/bridge/synchronization.test.d.ts +0 -2
- package/lib/bridge/synchronization.test.d.ts.map +0 -1
- package/lib/bridge/synchronization.test.js +0 -140
- package/lib/bridge/synchronization.test.js.map +0 -1
- package/lib/bridge/transaction.d.ts.map +0 -1
- package/lib/bridge/transaction.js.map +0 -1
- package/lib-es/bridge/broadcast.d.ts +0 -4
- package/lib-es/bridge/broadcast.d.ts.map +0 -1
- package/lib-es/bridge/broadcast.js +0 -7
- package/lib-es/bridge/broadcast.js.map +0 -1
- package/lib-es/bridge/createTransaction.d.ts +0 -4
- package/lib-es/bridge/createTransaction.d.ts.map +0 -1
- package/lib-es/bridge/createTransaction.js +0 -11
- package/lib-es/bridge/createTransaction.js.map +0 -1
- package/lib-es/bridge/estimateMaxSpendable.d.ts +0 -4
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +0 -1
- package/lib-es/bridge/estimateMaxSpendable.js +0 -19
- package/lib-es/bridge/estimateMaxSpendable.js.map +0 -1
- package/lib-es/bridge/getTransactionStatus.d.ts +0 -4
- package/lib-es/bridge/getTransactionStatus.d.ts.map +0 -1
- package/lib-es/bridge/getTransactionStatus.js.map +0 -1
- package/lib-es/bridge/index.d.ts +0 -11
- package/lib-es/bridge/index.d.ts.map +0 -1
- package/lib-es/bridge/index.js +0 -41
- package/lib-es/bridge/index.js.map +0 -1
- package/lib-es/bridge/prepareTransaction.d.ts +0 -4
- package/lib-es/bridge/prepareTransaction.d.ts.map +0 -1
- package/lib-es/bridge/prepareTransaction.js +0 -10
- package/lib-es/bridge/prepareTransaction.js.map +0 -1
- package/lib-es/bridge/signOperation.d.ts +0 -5
- package/lib-es/bridge/signOperation.d.ts.map +0 -1
- package/lib-es/bridge/signOperation.js +0 -72
- package/lib-es/bridge/signOperation.js.map +0 -1
- package/lib-es/bridge/synchronization.d.ts +0 -3
- package/lib-es/bridge/synchronization.d.ts.map +0 -1
- package/lib-es/bridge/synchronization.js +0 -78
- package/lib-es/bridge/synchronization.js.map +0 -1
- package/lib-es/bridge/synchronization.test.d.ts +0 -2
- package/lib-es/bridge/synchronization.test.d.ts.map +0 -1
- package/lib-es/bridge/synchronization.test.js +0 -135
- package/lib-es/bridge/synchronization.test.js.map +0 -1
- package/lib-es/bridge/transaction.d.ts.map +0 -1
- package/lib-es/bridge/transaction.js.map +0 -1
- package/src/bridge/broadcast.ts +0 -11
- package/src/bridge/createTransaction.ts +0 -13
- package/src/bridge/estimateMaxSpendable.ts +0 -25
- package/src/bridge/index.ts +0 -59
- package/src/bridge/prepareTransaction.ts +0 -18
- package/src/bridge/signOperation.ts +0 -100
- package/src/bridge/synchronization.test.ts +0 -153
- package/src/bridge/synchronization.ts +0 -108
- /package/lib/{bridge/transaction.js → transaction.js} +0 -0
- /package/lib-es/{bridge/transaction.js → transaction.js} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import BigNumber from "bignumber.js";
|
|
2
2
|
import { InvalidAddressBecauseDestinationIsAlsoSource } from "@ledgerhq/errors";
|
|
3
|
-
import { fromTransactionRaw } from "../
|
|
3
|
+
import { fromTransactionRaw } from "../transaction";
|
|
4
4
|
export const newAddress1 = "rZvBc5e2YR1A9otS3r9DyGh3NDP8XLLp4";
|
|
5
5
|
export const dataset = {
|
|
6
6
|
implementations: ["mock", "ripplejs"],
|
|
@@ -91,18 +91,18 @@ export const dataset = {
|
|
|
91
91
|
recipient: "rageXHB6Q4VbvvWdTzKANwjeCT4HXFCKX7",
|
|
92
92
|
amount: "10000000",
|
|
93
93
|
tag: null,
|
|
94
|
-
fee: "
|
|
94
|
+
fee: "10", // NOTE: fee is not customizable, this field is ignored
|
|
95
95
|
feeCustomUnit: null,
|
|
96
96
|
networkInfo: null,
|
|
97
97
|
}),
|
|
98
98
|
expectedStatus: {
|
|
99
99
|
amount: new BigNumber("10000000"),
|
|
100
|
-
estimatedFees: new BigNumber("
|
|
100
|
+
estimatedFees: new BigNumber("10"),
|
|
101
101
|
errors: {
|
|
102
102
|
recipient: new InvalidAddressBecauseDestinationIsAlsoSource(),
|
|
103
103
|
},
|
|
104
104
|
warnings: {},
|
|
105
|
-
totalSpent: new BigNumber("
|
|
105
|
+
totalSpent: new BigNumber("10000010"),
|
|
106
106
|
},
|
|
107
107
|
},
|
|
108
108
|
{
|
|
@@ -112,16 +112,16 @@ export const dataset = {
|
|
|
112
112
|
recipient: "rB6pwovsyrFWhPYUsjj9V3CHck985QjiXi",
|
|
113
113
|
amount: "10000000",
|
|
114
114
|
tag: 12345,
|
|
115
|
-
fee: "
|
|
115
|
+
fee: "10", // NOTE: fee is not customizable, this field is ignored
|
|
116
116
|
feeCustomUnit: null,
|
|
117
117
|
networkInfo: null,
|
|
118
118
|
}),
|
|
119
119
|
expectedStatus: {
|
|
120
120
|
amount: new BigNumber("10000000"),
|
|
121
|
-
estimatedFees: new BigNumber("
|
|
121
|
+
estimatedFees: new BigNumber("10"),
|
|
122
122
|
errors: {},
|
|
123
123
|
warnings: {},
|
|
124
|
-
totalSpent: new BigNumber("
|
|
124
|
+
totalSpent: new BigNumber("10000010"),
|
|
125
125
|
},
|
|
126
126
|
},
|
|
127
127
|
],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridgeDatasetTest.js","sourceRoot":"","sources":["../../src/test/bridgeDatasetTest.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,OAAO,EAAE,4CAA4C,EAAE,MAAM,kBAAkB,CAAC;AAChF,OAAO,EAAE,kBAAkB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"bridgeDatasetTest.js","sourceRoot":"","sources":["../../src/test/bridgeDatasetTest.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;oBACrB,gBAAgB,EAAE,IAAI;oBACtB,oCAAoC;oBACpC,KAAK,EAAE;;;;;;;;;WASN;iBACF;aACF;YACD,QAAQ,EAAE;gBACR;oBACE,YAAY,EAAE;wBACZ,QAAQ;wBAER;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sBAgCF;wBACE,QAAQ;wBAER;;;;;;;;;;;;;;;;;;;;;;sBAsBF;wBACE;4BACE,IAAI,EAAE,2CAA2C;4BACjD,WAAW,EAAE,kBAAkB,CAAC;gCAC9B,MAAM,EAAE,KAAK;gCACb,SAAS,EAAE,oCAAoC;gCAC/C,MAAM,EAAE,UAAU;gCAClB,GAAG,EAAE,IAAI;gCACT,GAAG,EAAE,IAAI,EAAE,uDAAuD;gCAClE,aAAa,EAAE,IAAI;gCACnB,WAAW,EAAE,IAAI;6BAClB,CAAC;4BACF,cAAc,EAAE;gCACd,MAAM,EAAE,IAAI,SAAS,CAAC,UAAU,CAAC;gCACjC,aAAa,EAAE,IAAI,SAAS,CAAC,IAAI,CAAC;gCAClC,MAAM,EAAE;oCACN,SAAS,EAAE,IAAI,4CAA4C,EAAE;iCAC9D;gCACD,QAAQ,EAAE,EAAE;gCACZ,UAAU,EAAE,IAAI,SAAS,CAAC,UAAU,CAAC;6BACtC;yBACF;wBACD;4BACE,IAAI,EAAE,4BAA4B;4BAClC,WAAW,EAAE,kBAAkB,CAAC;gCAC9B,MAAM,EAAE,KAAK;gCACb,SAAS,EAAE,oCAAoC;gCAC/C,MAAM,EAAE,UAAU;gCAClB,GAAG,EAAE,KAAK;gCACV,GAAG,EAAE,IAAI,EAAE,uDAAuD;gCAClE,aAAa,EAAE,IAAI;gCACnB,WAAW,EAAE,IAAI;6BAClB,CAAC;4BACF,cAAc,EAAE;gCACd,MAAM,EAAE,IAAI,SAAS,CAAC,UAAU,CAAC;gCACjC,aAAa,EAAE,IAAI,SAAS,CAAC,IAAI,CAAC;gCAClC,MAAM,EAAE,EAAE;gCACV,QAAQ,EAAE,EAAE;gCACZ,UAAU,EAAE,IAAI,SAAS,CAAC,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"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Transaction, TransactionRaw } from "
|
|
1
|
+
import type { Transaction, TransactionRaw } from "./types";
|
|
2
2
|
import type { Account } from "@ledgerhq/types-live";
|
|
3
3
|
export declare const formatTransaction: ({ amount, recipient, fee, tag, useAllAmount }: Transaction, account: Account) => string;
|
|
4
4
|
export declare const fromTransactionRaw: (tr: TransactionRaw) => Transaction;
|
|
@@ -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;;uEAvD+C,WAAW,WACjD,OAAO,KACf,MAAM;6BAmB8B,cAAc,KAAG,WAAW;0BAkB/B,WAAW,KAAG,cAAc;;;;;AAkBhE,wBAOE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../src/transaction.ts"],"names":[],"mappings":"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"}
|
package/lib-es/types/model.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TypedMapMemo } from "@ledgerhq/coin-framework/api/types";
|
|
1
2
|
export type AccountInfo = {
|
|
2
3
|
isNewAccount: boolean;
|
|
3
4
|
balance: string;
|
|
@@ -9,6 +10,12 @@ export type XrpMemo = {
|
|
|
9
10
|
format?: string;
|
|
10
11
|
type?: string;
|
|
11
12
|
};
|
|
13
|
+
export type XrpMemoKind = "destinationTag" | "memo";
|
|
14
|
+
export type XrpMemoValueMap = {
|
|
15
|
+
destinationTag: string;
|
|
16
|
+
memos: string[];
|
|
17
|
+
};
|
|
18
|
+
export type XrpMapMemo = TypedMapMemo<XrpMemoValueMap>;
|
|
12
19
|
type Order = "asc" | "desc";
|
|
13
20
|
export type ListOperationsOptions = {
|
|
14
21
|
limit?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/types/model.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG;IACxB,YAAY,EAAE,OAAO,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,KAAK,KAAK,GAAG,KAAK,GAAG,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/types/model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAElE,MAAM,MAAM,WAAW,GAAG;IACxB,YAAY,EAAE,OAAO,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,gBAAgB,GAAG,MAAM,CAAC;AAEpD,MAAM,MAAM,eAAe,GAAG;IAC5B,cAAc,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB,CAAC;AACF,MAAM,MAAM,UAAU,GAAG,YAAY,CAAC,eAAe,CAAC,CAAC;AAEvD,KAAK,KAAK,GAAG,KAAK,GAAG,MAAM,CAAC;AAE5B,MAAM,MAAM,qBAAqB,GAAG;IAElC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,KAAK,CAAC;IAEd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/coin-xrp",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.3.0-nightly.1",
|
|
4
4
|
"description": "Ledger XRP Coin integration",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ledger",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"lib/test/bot-specs"
|
|
42
42
|
],
|
|
43
43
|
"transaction": [
|
|
44
|
-
"lib/
|
|
44
|
+
"lib/transaction"
|
|
45
45
|
],
|
|
46
46
|
"types": [
|
|
47
47
|
"lib/types/index"
|
|
@@ -80,8 +80,8 @@
|
|
|
80
80
|
"default": "./lib-es/test/bot-specs.js"
|
|
81
81
|
},
|
|
82
82
|
"./transaction": {
|
|
83
|
-
"require": "./lib/
|
|
84
|
-
"default": "./lib-es/
|
|
83
|
+
"require": "./lib/transaction.js",
|
|
84
|
+
"default": "./lib-es/transaction.js"
|
|
85
85
|
},
|
|
86
86
|
"./types": {
|
|
87
87
|
"require": "./lib/types/index.js",
|
|
@@ -103,14 +103,13 @@
|
|
|
103
103
|
"invariant": "^2.2.4",
|
|
104
104
|
"ripple-address-codec": "^5.0.0",
|
|
105
105
|
"ripple-binary-codec": "^1.3.0",
|
|
106
|
-
"
|
|
107
|
-
"@ledgerhq/coin-framework": "^5.4.1",
|
|
108
|
-
"@ledgerhq/cryptoassets": "^13.20.0",
|
|
106
|
+
"@ledgerhq/cryptoassets": "^13.21.0-nightly.1",
|
|
109
107
|
"@ledgerhq/devices": "8.4.7",
|
|
110
108
|
"@ledgerhq/errors": "^6.22.0",
|
|
111
109
|
"@ledgerhq/live-network": "^2.0.12",
|
|
112
110
|
"@ledgerhq/types-live": "^6.75.0",
|
|
113
|
-
"@ledgerhq/logs": "^6.13.0"
|
|
111
|
+
"@ledgerhq/logs": "^6.13.0",
|
|
112
|
+
"@ledgerhq/coin-framework": "^5.5.0-nightly.1"
|
|
114
113
|
},
|
|
115
114
|
"devDependencies": {
|
|
116
115
|
"@faker-js/faker": "^8.4.1",
|
|
@@ -4,7 +4,7 @@ import { createApi } from ".";
|
|
|
4
4
|
//import { sign } from "ripple-keypairs";
|
|
5
5
|
|
|
6
6
|
describe("Xrp Api", () => {
|
|
7
|
-
const SENDER =
|
|
7
|
+
const SENDER = "rh1HPuRVsYYvThxG2Bs1MfjmrVC73S16Fb";
|
|
8
8
|
const api = createApi({ node: "https://s.altnet.rippletest.net:51234" });
|
|
9
9
|
|
|
10
10
|
describe("estimateFees", () => {
|
|
@@ -19,6 +19,10 @@ describe("Xrp Api", () => {
|
|
|
19
19
|
sender: SENDER,
|
|
20
20
|
amount,
|
|
21
21
|
recipient: "rKtXXTVno77jhu6tto1MAXjepyuaKaLcqB",
|
|
22
|
+
memo: {
|
|
23
|
+
type: "map",
|
|
24
|
+
memos: new Map(),
|
|
25
|
+
},
|
|
22
26
|
});
|
|
23
27
|
|
|
24
28
|
// Then
|
|
@@ -29,15 +33,14 @@ describe("Xrp Api", () => {
|
|
|
29
33
|
describe("listOperations", () => {
|
|
30
34
|
it.skip("returns a list regarding address parameter", async () => {
|
|
31
35
|
// When
|
|
32
|
-
const [tx, _] = await api.listOperations(SENDER
|
|
36
|
+
const [tx, _] = await api.listOperations(SENDER, { minHeight: 200 });
|
|
33
37
|
|
|
34
38
|
// https://blockexplorer.one/xrp/testnet/address/rh1HPuRVsYYvThxG2Bs1MfjmrVC73S16Fb
|
|
35
39
|
// as of 2025-03-18, the address has 287 transactions
|
|
36
40
|
expect(tx.length).toBeGreaterThanOrEqual(287);
|
|
37
41
|
tx.forEach(operation => {
|
|
38
42
|
const isSenderOrReceipt =
|
|
39
|
-
operation.senders.includes(SENDER
|
|
40
|
-
operation.recipients.includes(SENDER.address);
|
|
43
|
+
operation.senders.includes(SENDER) || operation.recipients.includes(SENDER);
|
|
41
44
|
expect(isSenderOrReceipt).toBeTruthy();
|
|
42
45
|
});
|
|
43
46
|
});
|
|
@@ -81,7 +84,7 @@ describe("Xrp Api", () => {
|
|
|
81
84
|
|
|
82
85
|
it("returns an amount above 0 when address has transactions", async () => {
|
|
83
86
|
// When
|
|
84
|
-
const result = await api.getBalance(SENDER
|
|
87
|
+
const result = await api.getBalance(SENDER);
|
|
85
88
|
|
|
86
89
|
// Then
|
|
87
90
|
expect(result[0].asset).toEqual({ type: "native" });
|
|
@@ -108,8 +111,11 @@ describe("Xrp Api", () => {
|
|
|
108
111
|
sender: SENDER,
|
|
109
112
|
recipient: RECIPIENT,
|
|
110
113
|
amount: BigInt(10),
|
|
114
|
+
memo: {
|
|
115
|
+
type: "map",
|
|
116
|
+
memos: new Map([["memos", ["testdata"]]]),
|
|
117
|
+
},
|
|
111
118
|
});
|
|
112
|
-
|
|
113
119
|
// Then
|
|
114
120
|
expect(result.length).toEqual(162);
|
|
115
121
|
});
|
|
@@ -121,6 +127,10 @@ describe("Xrp Api", () => {
|
|
|
121
127
|
sender: SENDER,
|
|
122
128
|
recipient: RECIPIENT,
|
|
123
129
|
amount: BigInt(10),
|
|
130
|
+
memo: {
|
|
131
|
+
type: "map",
|
|
132
|
+
memos: new Map(),
|
|
133
|
+
},
|
|
124
134
|
});
|
|
125
135
|
|
|
126
136
|
const decodedTransaction = decode(result) as { Fee: string };
|
|
@@ -136,6 +146,10 @@ describe("Xrp Api", () => {
|
|
|
136
146
|
sender: SENDER,
|
|
137
147
|
recipient: RECIPIENT,
|
|
138
148
|
amount: BigInt(10),
|
|
149
|
+
memo: {
|
|
150
|
+
type: "map",
|
|
151
|
+
memos: new Map(),
|
|
152
|
+
},
|
|
139
153
|
},
|
|
140
154
|
customFees,
|
|
141
155
|
);
|
package/src/api/index.test.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Operation, TransactionIntent } from "@ledgerhq/coin-framework/api/types";
|
|
2
2
|
import * as LogicFunctions from "../logic";
|
|
3
3
|
import { GetTransactionsOptions } from "../network";
|
|
4
|
-
import { NetworkInfo, XrpAsset } from "../types";
|
|
5
|
-
import { createApi
|
|
4
|
+
import { NetworkInfo, XrpAsset, XrpMapMemo } from "../types";
|
|
5
|
+
import { createApi } from "./index";
|
|
6
6
|
|
|
7
7
|
const mockGetServerInfos = jest.fn().mockResolvedValue({
|
|
8
8
|
info: {
|
|
@@ -285,11 +285,7 @@ describe("Testing craftTransaction function", () => {
|
|
|
285
285
|
it("should use custom user fees when user provides it for crafting a transaction", async () => {
|
|
286
286
|
const customFees = 99n;
|
|
287
287
|
await api.craftTransaction(
|
|
288
|
-
{ sender:
|
|
289
|
-
XrpAsset,
|
|
290
|
-
TransactionIntentExtra,
|
|
291
|
-
XrpSender
|
|
292
|
-
>,
|
|
288
|
+
{ sender: "foo" } as TransactionIntent<XrpAsset, XrpMapMemo>,
|
|
293
289
|
customFees,
|
|
294
290
|
);
|
|
295
291
|
|
|
@@ -303,11 +299,7 @@ describe("Testing craftTransaction function", () => {
|
|
|
303
299
|
});
|
|
304
300
|
|
|
305
301
|
it("should use default fees when user does not provide them for crafting a transaction", async () => {
|
|
306
|
-
await api.craftTransaction({ sender:
|
|
307
|
-
XrpAsset,
|
|
308
|
-
TransactionIntentExtra,
|
|
309
|
-
XrpSender
|
|
310
|
-
>);
|
|
302
|
+
await api.craftTransaction({ sender: "foo" } as TransactionIntent<XrpAsset, XrpMapMemo>);
|
|
311
303
|
|
|
312
304
|
expect(logicCraftTransactionSpy).toHaveBeenCalledWith(
|
|
313
305
|
expect.any(Object),
|
|
@@ -320,8 +312,9 @@ describe("Testing craftTransaction function", () => {
|
|
|
320
312
|
|
|
321
313
|
it("should pass signing pub key when user provides it for crafting a transaction", async () => {
|
|
322
314
|
await api.craftTransaction({
|
|
323
|
-
sender:
|
|
324
|
-
|
|
315
|
+
sender: "foo",
|
|
316
|
+
senderPublicKey: "bar",
|
|
317
|
+
} as TransactionIntent<XrpAsset, XrpMapMemo>);
|
|
325
318
|
|
|
326
319
|
expect(logicCraftTransactionSpy).toHaveBeenCalledWith(
|
|
327
320
|
expect.any(Object),
|
|
@@ -332,14 +325,19 @@ describe("Testing craftTransaction function", () => {
|
|
|
332
325
|
|
|
333
326
|
it("should pass memos when user provides it for crafting a transaction", async () => {
|
|
334
327
|
await api.craftTransaction({
|
|
335
|
-
sender:
|
|
336
|
-
|
|
337
|
-
|
|
328
|
+
sender: "foo",
|
|
329
|
+
memo: {
|
|
330
|
+
type: "map",
|
|
331
|
+
memos: new Map([["memos", ["testdata"]]]),
|
|
332
|
+
},
|
|
333
|
+
} as TransactionIntent<XrpAsset, XrpMapMemo>);
|
|
338
334
|
|
|
339
335
|
expect(logicCraftTransactionSpy).toHaveBeenCalledWith(
|
|
340
336
|
expect.any(Object),
|
|
341
337
|
expect.objectContaining({
|
|
342
|
-
|
|
338
|
+
// NOTE: before
|
|
339
|
+
// memos: [{ data: "testdata", format: "testformat", type: "testtype" }],
|
|
340
|
+
memos: [{ data: "testdata", type: "memo" }],
|
|
343
341
|
}),
|
|
344
342
|
undefined,
|
|
345
343
|
);
|
|
@@ -347,14 +345,17 @@ describe("Testing craftTransaction function", () => {
|
|
|
347
345
|
|
|
348
346
|
it("should pass destination tag when user provides it for crafting a transaction", async () => {
|
|
349
347
|
await api.craftTransaction({
|
|
350
|
-
sender:
|
|
351
|
-
|
|
352
|
-
|
|
348
|
+
sender: "foo",
|
|
349
|
+
memo: {
|
|
350
|
+
type: "map",
|
|
351
|
+
memos: new Map([["destinationTag", "1337"]]),
|
|
352
|
+
},
|
|
353
|
+
} as TransactionIntent<XrpAsset, XrpMapMemo>);
|
|
353
354
|
|
|
354
355
|
expect(logicCraftTransactionSpy).toHaveBeenCalledWith(
|
|
355
356
|
expect.any(Object),
|
|
356
357
|
expect.objectContaining({
|
|
357
|
-
destinationTag: 1337,
|
|
358
|
+
destinationTag: 1337, // logic should convert `value: string` -> `number`
|
|
358
359
|
}),
|
|
359
360
|
undefined,
|
|
360
361
|
);
|
package/src/api/index.ts
CHANGED
|
@@ -13,14 +13,15 @@ import {
|
|
|
13
13
|
craftTransaction,
|
|
14
14
|
estimateFees,
|
|
15
15
|
getBalance,
|
|
16
|
+
getAccountInfo,
|
|
16
17
|
getNextValidSequence,
|
|
17
18
|
lastBlock,
|
|
18
19
|
listOperations,
|
|
19
|
-
|
|
20
|
+
getTransactionStatus,
|
|
20
21
|
} from "../logic";
|
|
21
|
-
import { ListOperationsOptions, XrpAsset } from "../types";
|
|
22
|
+
import { ListOperationsOptions, XrpAsset, XrpMapMemo } from "../types";
|
|
22
23
|
|
|
23
|
-
export function createApi(config: XrpConfig): Api<XrpAsset,
|
|
24
|
+
export function createApi(config: XrpConfig): Api<XrpAsset, XrpMapMemo> {
|
|
24
25
|
coinConfig.setCoinConfig(() => ({ ...config, status: { type: "active" } }));
|
|
25
26
|
|
|
26
27
|
return {
|
|
@@ -31,36 +32,46 @@ export function createApi(config: XrpConfig): Api<XrpAsset, TransactionIntentExt
|
|
|
31
32
|
getBalance,
|
|
32
33
|
lastBlock,
|
|
33
34
|
listOperations: operations,
|
|
35
|
+
validateIntent: getTransactionStatus,
|
|
36
|
+
getAccountInfo,
|
|
34
37
|
};
|
|
35
38
|
}
|
|
36
39
|
|
|
37
|
-
export type TransactionIntentExtra = {
|
|
38
|
-
destinationTag?: number | null | undefined;
|
|
39
|
-
memos?: MemoInput[];
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export type XrpSender = {
|
|
43
|
-
address: string;
|
|
44
|
-
publicKey?: string;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
40
|
async function craft(
|
|
48
|
-
transactionIntent: TransactionIntent<XrpAsset,
|
|
41
|
+
transactionIntent: TransactionIntent<XrpAsset, XrpMapMemo>,
|
|
49
42
|
customFees?: bigint,
|
|
50
43
|
): Promise<string> {
|
|
51
|
-
const nextSequenceNumber = await getNextValidSequence(transactionIntent.sender
|
|
44
|
+
const nextSequenceNumber = await getNextValidSequence(transactionIntent.sender);
|
|
52
45
|
const estimatedFees = customFees !== undefined ? customFees : (await estimateFees()).fee;
|
|
46
|
+
|
|
47
|
+
const memosMap =
|
|
48
|
+
transactionIntent.memo?.type === "map" ? transactionIntent.memo.memos : new Map();
|
|
49
|
+
|
|
50
|
+
const destinationTagValue = memosMap.get("destinationTag");
|
|
51
|
+
const destinationTag =
|
|
52
|
+
typeof destinationTagValue === "string" ? Number(destinationTagValue) : undefined;
|
|
53
|
+
|
|
54
|
+
const memoStrings = memosMap.get("memos") as string[] | undefined;
|
|
55
|
+
|
|
56
|
+
let memoEntries: { type: string; data: string }[] = [];
|
|
57
|
+
|
|
58
|
+
if (Array.isArray(memoStrings) && memoStrings.length > 0) {
|
|
59
|
+
memoEntries = memoStrings.map(value => ({ type: "memo", data: value }));
|
|
60
|
+
}
|
|
61
|
+
|
|
53
62
|
const tx = await craftTransaction(
|
|
54
|
-
{ address: transactionIntent.sender
|
|
63
|
+
{ address: transactionIntent.sender, nextSequenceNumber },
|
|
55
64
|
{
|
|
56
65
|
recipient: transactionIntent.recipient,
|
|
57
66
|
amount: transactionIntent.amount,
|
|
58
67
|
fee: estimatedFees,
|
|
59
|
-
destinationTag
|
|
60
|
-
|
|
68
|
+
destinationTag,
|
|
69
|
+
// NOTE: double check before/after here
|
|
70
|
+
memos: memoEntries,
|
|
61
71
|
},
|
|
62
|
-
transactionIntent.
|
|
72
|
+
transactionIntent.senderPublicKey,
|
|
63
73
|
);
|
|
74
|
+
|
|
64
75
|
return tx.serializedTransaction;
|
|
65
76
|
}
|
|
66
77
|
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { getAccountInfo as networkGetAccountInfo } from "../network";
|
|
2
|
+
import { AccountInfo } from "../types";
|
|
3
|
+
|
|
4
|
+
export async function getAccountInfo(address: string): Promise<AccountInfo> {
|
|
5
|
+
const accountInfo = await networkGetAccountInfo(address, true);
|
|
6
|
+
return accountInfo;
|
|
7
|
+
}
|
|
@@ -2,21 +2,33 @@ import { faker } from "@faker-js/faker";
|
|
|
2
2
|
import { getBalance } from "./getBalance";
|
|
3
3
|
|
|
4
4
|
const mockGetAccountInfo = jest.fn();
|
|
5
|
+
const mockGetServerInfos = jest.fn();
|
|
5
6
|
jest.mock("../network", () => ({
|
|
6
7
|
getAccountInfo: (address: string) => mockGetAccountInfo(address),
|
|
8
|
+
getServerInfos: () => mockGetServerInfos(),
|
|
7
9
|
}));
|
|
8
10
|
|
|
9
11
|
describe("getBalance", () => {
|
|
10
12
|
afterEach(() => {
|
|
11
13
|
mockGetAccountInfo.mockClear();
|
|
14
|
+
mockGetServerInfos.mockClear();
|
|
12
15
|
});
|
|
13
16
|
|
|
14
17
|
it("returns the balance from Explorer", async () => {
|
|
18
|
+
mockGetServerInfos.mockResolvedValue({
|
|
19
|
+
info: {
|
|
20
|
+
validated_ledger: {
|
|
21
|
+
reserve_base_xrp: 23,
|
|
22
|
+
reserve_inc_xrp: 5,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
});
|
|
15
26
|
// Given
|
|
16
27
|
const balance = faker.number.bigInt(100_000_000);
|
|
17
28
|
const address = "ACCOUNT_ADDRESS";
|
|
18
29
|
mockGetAccountInfo.mockResolvedValue({
|
|
19
30
|
balance,
|
|
31
|
+
ownerCount: 0,
|
|
20
32
|
});
|
|
21
33
|
|
|
22
34
|
// When
|
|
@@ -24,7 +36,8 @@ describe("getBalance", () => {
|
|
|
24
36
|
|
|
25
37
|
// Then
|
|
26
38
|
expect(mockGetAccountInfo).toHaveBeenCalledTimes(1);
|
|
39
|
+
expect(mockGetServerInfos).toHaveBeenCalledTimes(1);
|
|
27
40
|
expect(mockGetAccountInfo.mock.lastCall[0]).toEqual(address);
|
|
28
|
-
expect(result).toEqual([{ value: balance, asset: { type: "native" } }]);
|
|
41
|
+
expect(result).toEqual([{ value: balance, asset: { type: "native" }, locked: 23000000n }]);
|
|
29
42
|
});
|
|
30
43
|
});
|
package/src/logic/getBalance.ts
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
1
|
import { Balance } from "@ledgerhq/coin-framework/api/types";
|
|
2
|
-
import { getAccountInfo } from "../network";
|
|
2
|
+
import { getAccountInfo, getServerInfos } from "../network";
|
|
3
3
|
import { XrpAsset } from "../types";
|
|
4
|
+
import { parseAPIValue } from "./common";
|
|
4
5
|
|
|
5
6
|
export async function getBalance(address: string): Promise<Balance<XrpAsset>[]> {
|
|
6
7
|
const accountInfo = await getAccountInfo(address);
|
|
7
|
-
|
|
8
|
+
const serverInfo = await getServerInfos();
|
|
9
|
+
|
|
10
|
+
const reserveMinXRP = parseAPIValue(serverInfo.info.validated_ledger.reserve_base_xrp.toString());
|
|
11
|
+
const reservePerTrustline = parseAPIValue(
|
|
12
|
+
serverInfo.info.validated_ledger.reserve_inc_xrp.toString(),
|
|
13
|
+
);
|
|
14
|
+
const trustlines = accountInfo.ownerCount;
|
|
15
|
+
|
|
16
|
+
const locked = reserveMinXRP.plus(reservePerTrustline.times(trustlines));
|
|
17
|
+
return [
|
|
18
|
+
{
|
|
19
|
+
value: BigInt(accountInfo.balance),
|
|
20
|
+
asset: { type: "native" },
|
|
21
|
+
locked: BigInt(locked.toString()),
|
|
22
|
+
},
|
|
23
|
+
];
|
|
8
24
|
}
|