@bithomp/xrpl-api 3.1.16 → 3.1.18
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/lib/connection.js +1 -0
- package/lib/ledger/account_tx.js +3 -2
- package/lib/models/account_info.d.ts +48 -0
- package/lib/models/account_info.js +34 -2
- package/lib/parse/outcome/delivered_amount.d.ts +3 -0
- package/lib/parse/outcome/delivered_amount.js +44 -0
- package/lib/parse/outcome/index.d.ts +1 -0
- package/lib/parse/outcome/index.js +3 -1
- package/lib/parse/outcome.js +1 -40
- package/lib/parse/specification/settings.js +1 -1
- package/lib/wallet.d.ts +8 -1
- package/lib/wallet.js +77 -4
- package/package.json +8 -8
package/lib/connection.js
CHANGED
|
@@ -99,6 +99,7 @@ class Connection extends events_1.EventEmitter {
|
|
|
99
99
|
}
|
|
100
100
|
const response = await this.client.connection.request(request);
|
|
101
101
|
this.updateLatency((0, utils_1.getTimestamp)() - startTimestamp);
|
|
102
|
+
this.connectionValidation();
|
|
102
103
|
return response;
|
|
103
104
|
}
|
|
104
105
|
catch (err) {
|
package/lib/ledger/account_tx.js
CHANGED
|
@@ -45,7 +45,7 @@ async function getTransactions(account, options = { limit: DEFAULT_LIMIT }) {
|
|
|
45
45
|
if (!connection) {
|
|
46
46
|
throw new Error("There is no connection");
|
|
47
47
|
}
|
|
48
|
-
const
|
|
48
|
+
const command = {
|
|
49
49
|
command: "account_tx",
|
|
50
50
|
account,
|
|
51
51
|
ledger_index_min: options.ledgerIndexMin,
|
|
@@ -56,7 +56,8 @@ async function getTransactions(account, options = { limit: DEFAULT_LIMIT }) {
|
|
|
56
56
|
forward: !!options.forward,
|
|
57
57
|
limit: options.limit,
|
|
58
58
|
marker: options.marker,
|
|
59
|
-
}
|
|
59
|
+
};
|
|
60
|
+
const response = await connection.request(command);
|
|
60
61
|
if (!response) {
|
|
61
62
|
return {
|
|
62
63
|
account,
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { LedgerEntry, AccountSetAsfFlags } from "xrpl";
|
|
2
2
|
import { QueueData } from "../types/queue_data";
|
|
3
|
+
export declare enum XahauAccountRootFlags {
|
|
4
|
+
lsfURITokenIssuer = 1073741824,
|
|
5
|
+
lsfDisallowIncomingRemit = 2147483648
|
|
6
|
+
}
|
|
3
7
|
export declare const AccountRootFlagsKeys: {
|
|
4
8
|
passwordSpent: LedgerEntry.AccountRootFlags;
|
|
5
9
|
requireDestTag: LedgerEntry.AccountRootFlags;
|
|
@@ -15,6 +19,41 @@ export declare const AccountRootFlagsKeys: {
|
|
|
15
19
|
disallowIncomingPayChan: LedgerEntry.AccountRootFlags;
|
|
16
20
|
disallowIncomingTrustline: LedgerEntry.AccountRootFlags;
|
|
17
21
|
};
|
|
22
|
+
export declare const XRPLAccountRootFlagsKeys: {
|
|
23
|
+
amm: LedgerEntry.AccountRootFlags;
|
|
24
|
+
allowTrustLineClawback: LedgerEntry.AccountRootFlags;
|
|
25
|
+
passwordSpent: LedgerEntry.AccountRootFlags;
|
|
26
|
+
requireDestTag: LedgerEntry.AccountRootFlags;
|
|
27
|
+
requireAuth: LedgerEntry.AccountRootFlags;
|
|
28
|
+
depositAuth: LedgerEntry.AccountRootFlags;
|
|
29
|
+
disallowXRP: LedgerEntry.AccountRootFlags;
|
|
30
|
+
disableMaster: LedgerEntry.AccountRootFlags;
|
|
31
|
+
noFreeze: LedgerEntry.AccountRootFlags;
|
|
32
|
+
globalFreeze: LedgerEntry.AccountRootFlags;
|
|
33
|
+
defaultRipple: LedgerEntry.AccountRootFlags;
|
|
34
|
+
disallowIncomingNFTokenOffer: LedgerEntry.AccountRootFlags;
|
|
35
|
+
disallowIncomingCheck: LedgerEntry.AccountRootFlags;
|
|
36
|
+
disallowIncomingPayChan: LedgerEntry.AccountRootFlags;
|
|
37
|
+
disallowIncomingTrustline: LedgerEntry.AccountRootFlags;
|
|
38
|
+
};
|
|
39
|
+
export declare const XahauAccountRootFlagsKeys: {
|
|
40
|
+
uriTokenIssuer: XahauAccountRootFlags;
|
|
41
|
+
disallowIncomingRemit: XahauAccountRootFlags;
|
|
42
|
+
passwordSpent: LedgerEntry.AccountRootFlags;
|
|
43
|
+
requireDestTag: LedgerEntry.AccountRootFlags;
|
|
44
|
+
requireAuth: LedgerEntry.AccountRootFlags;
|
|
45
|
+
depositAuth: LedgerEntry.AccountRootFlags;
|
|
46
|
+
disallowXRP: LedgerEntry.AccountRootFlags;
|
|
47
|
+
disableMaster: LedgerEntry.AccountRootFlags;
|
|
48
|
+
noFreeze: LedgerEntry.AccountRootFlags;
|
|
49
|
+
globalFreeze: LedgerEntry.AccountRootFlags;
|
|
50
|
+
defaultRipple: LedgerEntry.AccountRootFlags;
|
|
51
|
+
disallowIncomingNFTokenOffer: LedgerEntry.AccountRootFlags;
|
|
52
|
+
disallowIncomingCheck: LedgerEntry.AccountRootFlags;
|
|
53
|
+
disallowIncomingPayChan: LedgerEntry.AccountRootFlags;
|
|
54
|
+
disallowIncomingTrustline: LedgerEntry.AccountRootFlags;
|
|
55
|
+
};
|
|
56
|
+
export declare function getAccountRootFlagsKeys(): Record<string, number>;
|
|
18
57
|
export interface AccountRootFlagsKeysInterface {
|
|
19
58
|
passwordSpent?: boolean;
|
|
20
59
|
requireDestTag?: boolean;
|
|
@@ -29,6 +68,13 @@ export interface AccountRootFlagsKeysInterface {
|
|
|
29
68
|
disallowIncomingCheck?: boolean;
|
|
30
69
|
disallowIncomingPayChan?: boolean;
|
|
31
70
|
disallowIncomingTrustline?: boolean;
|
|
71
|
+
amm?: boolean;
|
|
72
|
+
allowTrustLineClawback?: boolean;
|
|
73
|
+
uriTokenIssuer?: boolean;
|
|
74
|
+
disallowIncomingRemit?: boolean;
|
|
75
|
+
}
|
|
76
|
+
export declare enum XahauAccountSetAsfFlags {
|
|
77
|
+
asfDisallowIncomingRemit = 16
|
|
32
78
|
}
|
|
33
79
|
export declare const AccountSetFlags: {
|
|
34
80
|
requireDestinationTag: AccountSetAsfFlags;
|
|
@@ -45,6 +91,8 @@ export declare const AccountSetFlags: {
|
|
|
45
91
|
disallowIncomingCheck: AccountSetAsfFlags;
|
|
46
92
|
disallowIncomingPayChan: AccountSetAsfFlags;
|
|
47
93
|
disallowIncomingTrustline: AccountSetAsfFlags;
|
|
94
|
+
allowTrustLineClawback: AccountSetAsfFlags;
|
|
95
|
+
disallowIncomingRemit: XahauAccountSetAsfFlags;
|
|
48
96
|
};
|
|
49
97
|
export declare const SignerListFlagsKeys: {
|
|
50
98
|
oneOwnerCount: LedgerEntry.SignerListFlags;
|
|
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.AccountFields = exports.SignerListFlagsKeys = exports.AccountSetFlags = exports.AccountRootFlagsKeys = void 0;
|
|
6
|
+
exports.AccountFields = exports.SignerListFlagsKeys = exports.AccountSetFlags = exports.XahauAccountSetAsfFlags = exports.XahauAccountRootFlagsKeys = exports.XRPLAccountRootFlagsKeys = exports.AccountRootFlagsKeys = exports.XahauAccountRootFlags = void 0;
|
|
7
|
+
exports.getAccountRootFlagsKeys = getAccountRootFlagsKeys;
|
|
7
8
|
exports.getSettings = getSettings;
|
|
8
9
|
exports.parseAccountFlags = parseAccountFlags;
|
|
9
10
|
exports.parseAccountFields = parseAccountFields;
|
|
@@ -12,6 +13,12 @@ const xrpl_1 = require("xrpl");
|
|
|
12
13
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
13
14
|
const common_1 = require("../common");
|
|
14
15
|
const flags_1 = require("../parse/ledger/flags");
|
|
16
|
+
const client_1 = require("../client");
|
|
17
|
+
var XahauAccountRootFlags;
|
|
18
|
+
(function (XahauAccountRootFlags) {
|
|
19
|
+
XahauAccountRootFlags[XahauAccountRootFlags["lsfURITokenIssuer"] = 1073741824] = "lsfURITokenIssuer";
|
|
20
|
+
XahauAccountRootFlags[XahauAccountRootFlags["lsfDisallowIncomingRemit"] = 2147483648] = "lsfDisallowIncomingRemit";
|
|
21
|
+
})(XahauAccountRootFlags || (exports.XahauAccountRootFlags = XahauAccountRootFlags = {}));
|
|
15
22
|
exports.AccountRootFlagsKeys = {
|
|
16
23
|
passwordSpent: xrpl_1.LedgerEntry.AccountRootFlags.lsfPasswordSpent,
|
|
17
24
|
requireDestTag: xrpl_1.LedgerEntry.AccountRootFlags.lsfRequireDestTag,
|
|
@@ -27,6 +34,29 @@ exports.AccountRootFlagsKeys = {
|
|
|
27
34
|
disallowIncomingPayChan: xrpl_1.LedgerEntry.AccountRootFlags.lsfDisallowIncomingPayChan,
|
|
28
35
|
disallowIncomingTrustline: xrpl_1.LedgerEntry.AccountRootFlags.lsfDisallowIncomingTrustline,
|
|
29
36
|
};
|
|
37
|
+
exports.XRPLAccountRootFlagsKeys = {
|
|
38
|
+
...exports.AccountRootFlagsKeys,
|
|
39
|
+
amm: xrpl_1.LedgerEntry.AccountRootFlags.lsfAMM,
|
|
40
|
+
allowTrustLineClawback: xrpl_1.LedgerEntry.AccountRootFlags.lsfAllowTrustLineClawback,
|
|
41
|
+
};
|
|
42
|
+
exports.XahauAccountRootFlagsKeys = {
|
|
43
|
+
...exports.AccountRootFlagsKeys,
|
|
44
|
+
uriTokenIssuer: XahauAccountRootFlags.lsfURITokenIssuer,
|
|
45
|
+
disallowIncomingRemit: XahauAccountRootFlags.lsfDisallowIncomingRemit,
|
|
46
|
+
};
|
|
47
|
+
function getAccountRootFlagsKeys() {
|
|
48
|
+
const nativeCurrency = (0, client_1.getNativeCurrency)();
|
|
49
|
+
if (nativeCurrency === "XAH") {
|
|
50
|
+
return exports.XahauAccountRootFlagsKeys;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
return exports.XRPLAccountRootFlagsKeys;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
var XahauAccountSetAsfFlags;
|
|
57
|
+
(function (XahauAccountSetAsfFlags) {
|
|
58
|
+
XahauAccountSetAsfFlags[XahauAccountSetAsfFlags["asfDisallowIncomingRemit"] = 16] = "asfDisallowIncomingRemit";
|
|
59
|
+
})(XahauAccountSetAsfFlags || (exports.XahauAccountSetAsfFlags = XahauAccountSetAsfFlags = {}));
|
|
30
60
|
exports.AccountSetFlags = {
|
|
31
61
|
requireDestinationTag: xrpl_1.AccountSetAsfFlags.asfRequireDest,
|
|
32
62
|
requireAuthorization: xrpl_1.AccountSetAsfFlags.asfRequireAuth,
|
|
@@ -42,6 +72,8 @@ exports.AccountSetFlags = {
|
|
|
42
72
|
disallowIncomingCheck: xrpl_1.AccountSetAsfFlags.asfDisallowIncomingCheck,
|
|
43
73
|
disallowIncomingPayChan: xrpl_1.AccountSetAsfFlags.asfDisallowIncomingPayChan,
|
|
44
74
|
disallowIncomingTrustline: xrpl_1.AccountSetAsfFlags.asfDisallowIncomingTrustline,
|
|
75
|
+
allowTrustLineClawback: xrpl_1.AccountSetAsfFlags.asfAllowTrustLineClawback,
|
|
76
|
+
disallowIncomingRemit: XahauAccountSetAsfFlags.asfDisallowIncomingRemit,
|
|
45
77
|
};
|
|
46
78
|
exports.SignerListFlagsKeys = {
|
|
47
79
|
oneOwnerCount: xrpl_1.LedgerEntry.SignerListFlags.lsfOneOwnerCount,
|
|
@@ -65,7 +97,7 @@ function getSettings(accountInfo, excludeFalse = true) {
|
|
|
65
97
|
};
|
|
66
98
|
}
|
|
67
99
|
function parseAccountFlags(value, options = {}) {
|
|
68
|
-
return (0, flags_1.parseFlags)(value,
|
|
100
|
+
return (0, flags_1.parseFlags)(value, getAccountRootFlagsKeys(), options);
|
|
69
101
|
}
|
|
70
102
|
function parseAccountFields(accountInfo, options = {}) {
|
|
71
103
|
const settings = {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.parseDeliveredAmount = parseDeliveredAmount;
|
|
7
|
+
const import_1 = require("../ledger/import");
|
|
8
|
+
const amount_1 = __importDefault(require("../ledger/amount"));
|
|
9
|
+
const utils_1 = require("../utils");
|
|
10
|
+
const balance_changes_1 = require("./balance_changes");
|
|
11
|
+
function parseDeliveredAmount(tx) {
|
|
12
|
+
if (!["Import", "Payment"].includes(tx.TransactionType) || tx.meta.TransactionResult !== "tesSUCCESS") {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
if (tx.meta.delivered_amount && tx.meta.delivered_amount === "unavailable") {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
if (tx.meta.delivered_amount) {
|
|
19
|
+
return (0, amount_1.default)(tx.meta.delivered_amount);
|
|
20
|
+
}
|
|
21
|
+
if (tx.meta.DeliveredAmount) {
|
|
22
|
+
return (0, amount_1.default)(tx.meta.DeliveredAmount);
|
|
23
|
+
}
|
|
24
|
+
if (tx.Amount && !(0, utils_1.isPartialPayment)(tx)) {
|
|
25
|
+
return (0, amount_1.default)(tx.Amount);
|
|
26
|
+
}
|
|
27
|
+
if (tx.TransactionType === "Import") {
|
|
28
|
+
const balanceChanges = (0, balance_changes_1.parseBalanceChanges)(tx.meta);
|
|
29
|
+
const blob = (0, import_1.parseImportBlob)(tx.Blob);
|
|
30
|
+
if (typeof blob === "string") {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
const account = blob.transaction.tx.Account;
|
|
34
|
+
const balanceChange = balanceChanges[account];
|
|
35
|
+
if (!balanceChange || balanceChange.length !== 1) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
currency: balanceChange[0].currency,
|
|
40
|
+
value: balanceChange[0].value,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
@@ -14,3 +14,4 @@ export { parseUNLReportChanges } from "./unl_report_changes";
|
|
|
14
14
|
export { parseAmmChanges } from "./amm_changes";
|
|
15
15
|
export { parseDIDChanges } from "./did_changes";
|
|
16
16
|
export { parseOracleChanges } from "./oracle_changes";
|
|
17
|
+
export { parseDeliveredAmount } from "./delivered_amount";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseOracleChanges = exports.parseDIDChanges = exports.parseAmmChanges = exports.parseUNLReportChanges = exports.parseEscrowChanges = exports.parseEmittedTxns = exports.parseHooksExecutions = exports.parseOrderbookChanges = exports.parseChannelChanges = exports.parseLockedBalanceChanges = exports.parseBalanceChanges = exports.parseURITokenSellOfferChanges = exports.parseURITokenChanges = exports.parseNFTokenOfferChanges = exports.parseNFTokenChanges = exports.parseAffectedObjects = void 0;
|
|
3
|
+
exports.parseDeliveredAmount = exports.parseOracleChanges = exports.parseDIDChanges = exports.parseAmmChanges = exports.parseUNLReportChanges = exports.parseEscrowChanges = exports.parseEmittedTxns = exports.parseHooksExecutions = exports.parseOrderbookChanges = exports.parseChannelChanges = exports.parseLockedBalanceChanges = exports.parseBalanceChanges = exports.parseURITokenSellOfferChanges = exports.parseURITokenChanges = exports.parseNFTokenOfferChanges = exports.parseNFTokenChanges = exports.parseAffectedObjects = void 0;
|
|
4
4
|
var affected_objects_1 = require("./affected_objects");
|
|
5
5
|
Object.defineProperty(exports, "parseAffectedObjects", { enumerable: true, get: function () { return affected_objects_1.parseAffectedObjects; } });
|
|
6
6
|
var nftoken_changes_1 = require("./nftoken_changes");
|
|
@@ -33,3 +33,5 @@ var did_changes_1 = require("./did_changes");
|
|
|
33
33
|
Object.defineProperty(exports, "parseDIDChanges", { enumerable: true, get: function () { return did_changes_1.parseDIDChanges; } });
|
|
34
34
|
var oracle_changes_1 = require("./oracle_changes");
|
|
35
35
|
Object.defineProperty(exports, "parseOracleChanges", { enumerable: true, get: function () { return oracle_changes_1.parseOracleChanges; } });
|
|
36
|
+
var delivered_amount_1 = require("./delivered_amount");
|
|
37
|
+
Object.defineProperty(exports, "parseDeliveredAmount", { enumerable: true, get: function () { return delivered_amount_1.parseDeliveredAmount; } });
|
package/lib/parse/outcome.js
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.parseOutcome = parseOutcome;
|
|
7
4
|
const index_1 = require("./outcome/index");
|
|
8
|
-
const import_1 = require("./ledger/import");
|
|
9
|
-
const amount_1 = __importDefault(require("./ledger/amount"));
|
|
10
5
|
const utils_1 = require("./utils");
|
|
11
6
|
const common_1 = require("../common");
|
|
12
7
|
function removeEmptyCounterparty(amount) {
|
|
@@ -26,40 +21,6 @@ function removeEmptyCounterpartyInOrderbookChanges(orderbookChanges) {
|
|
|
26
21
|
});
|
|
27
22
|
});
|
|
28
23
|
}
|
|
29
|
-
function parseDeliveredAmount(tx) {
|
|
30
|
-
if (!["Import", "Payment"].includes(tx.TransactionType) || tx.meta.TransactionResult !== "tesSUCCESS") {
|
|
31
|
-
return undefined;
|
|
32
|
-
}
|
|
33
|
-
if (tx.meta.delivered_amount && tx.meta.delivered_amount === "unavailable") {
|
|
34
|
-
return undefined;
|
|
35
|
-
}
|
|
36
|
-
if (tx.meta.delivered_amount) {
|
|
37
|
-
return (0, amount_1.default)(tx.meta.delivered_amount);
|
|
38
|
-
}
|
|
39
|
-
if (tx.meta.DeliveredAmount) {
|
|
40
|
-
return (0, amount_1.default)(tx.meta.DeliveredAmount);
|
|
41
|
-
}
|
|
42
|
-
if (tx.Amount && !(0, utils_1.isPartialPayment)(tx)) {
|
|
43
|
-
return (0, amount_1.default)(tx.Amount);
|
|
44
|
-
}
|
|
45
|
-
if (tx.TransactionType === "Import") {
|
|
46
|
-
const balanceChanges = (0, index_1.parseBalanceChanges)(tx.meta);
|
|
47
|
-
const blob = (0, import_1.parseImportBlob)(tx.Blob);
|
|
48
|
-
if (typeof blob === "string") {
|
|
49
|
-
return undefined;
|
|
50
|
-
}
|
|
51
|
-
const account = blob.transaction.tx.Account;
|
|
52
|
-
const balanceChange = balanceChanges[account];
|
|
53
|
-
if (!balanceChange || balanceChange.length !== 1) {
|
|
54
|
-
return undefined;
|
|
55
|
-
}
|
|
56
|
-
return {
|
|
57
|
-
currency: balanceChange[0].currency,
|
|
58
|
-
value: balanceChange[0].value,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
return undefined;
|
|
62
|
-
}
|
|
63
24
|
function parseOutcome(tx, nativeCurrency, definitions) {
|
|
64
25
|
const metadata = tx.meta || tx.metaData;
|
|
65
26
|
if (!metadata) {
|
|
@@ -106,6 +67,6 @@ function parseOutcome(tx, nativeCurrency, definitions) {
|
|
|
106
67
|
emittedTxns,
|
|
107
68
|
ledgerVersion: tx.ledger_index,
|
|
108
69
|
indexInLedger: tx.meta.TransactionIndex,
|
|
109
|
-
deliveredAmount: parseDeliveredAmount(tx),
|
|
70
|
+
deliveredAmount: (0, index_1.parseDeliveredAmount)(tx),
|
|
110
71
|
});
|
|
111
72
|
}
|
|
@@ -50,7 +50,7 @@ function parseSettingsFlags(tx) {
|
|
|
50
50
|
const changedFlags = oldFlags ^ newFlags;
|
|
51
51
|
const setFlags = newFlags & changedFlags;
|
|
52
52
|
const clearedFlags = oldFlags & changedFlags;
|
|
53
|
-
Object.entries(account_info_1.
|
|
53
|
+
Object.entries((0, account_info_1.getAccountRootFlagsKeys)()).forEach((entry) => {
|
|
54
54
|
const [flagName, flagValue] = entry;
|
|
55
55
|
if (setFlags & flagValue) {
|
|
56
56
|
settings[flagName] = true;
|
package/lib/wallet.d.ts
CHANGED
|
@@ -6,6 +6,12 @@ interface GenerateAddressInterface {
|
|
|
6
6
|
address: string;
|
|
7
7
|
seed: string;
|
|
8
8
|
}
|
|
9
|
+
export interface VerifySignatureInterface {
|
|
10
|
+
signedBy?: string;
|
|
11
|
+
signatureValid?: boolean;
|
|
12
|
+
signatureMultiSign?: boolean;
|
|
13
|
+
error?: string;
|
|
14
|
+
}
|
|
9
15
|
export declare function isValidSecret(secret: string): boolean;
|
|
10
16
|
export interface WalletFromSeedInterface {
|
|
11
17
|
masterAddress?: string;
|
|
@@ -21,6 +27,7 @@ export declare function signTransaction(wallet: Wallet, transaction: Transaction
|
|
|
21
27
|
tx_blob: string;
|
|
22
28
|
hash: string;
|
|
23
29
|
};
|
|
24
|
-
export declare function verifyTransaction(
|
|
30
|
+
export declare function verifyTransaction(signedTransaction: Transaction | string, definitions?: XrplDefinitionsBase): boolean;
|
|
31
|
+
export declare function verifySignature(signedTransaction: Transaction | string, explicitMultiSigner?: string | null, definitions?: XrplDefinitionsBase): VerifySignatureInterface;
|
|
25
32
|
declare function hashSignedTx(tx: Transaction | string, definitions?: XrplDefinitionsBase, validateTx?: boolean): string;
|
|
26
33
|
export { XrplDefinitionsBase, XrplDefinitions, DEFAULT_DEFINITIONS, hashSignedTx };
|
package/lib/wallet.js
CHANGED
|
@@ -34,6 +34,7 @@ exports.isValidClassicAddress = isValidClassicAddress;
|
|
|
34
34
|
exports.checksumClassicAddress = checksumClassicAddress;
|
|
35
35
|
exports.signTransaction = signTransaction;
|
|
36
36
|
exports.verifyTransaction = verifyTransaction;
|
|
37
|
+
exports.verifySignature = verifySignature;
|
|
37
38
|
exports.hashSignedTx = hashSignedTx;
|
|
38
39
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
39
40
|
const omitBy_1 = __importDefault(require("lodash/omitBy"));
|
|
@@ -147,11 +148,83 @@ function signTransaction(wallet, transaction, multisign, definitions, validateTx
|
|
|
147
148
|
hash: hashSignedTx(serialized, definitions),
|
|
148
149
|
};
|
|
149
150
|
}
|
|
150
|
-
function verifyTransaction(
|
|
151
|
-
const tx = typeof signedTransaction === "string" ? (0, ripple_binary_codec_1.decode)(signedTransaction) : signedTransaction;
|
|
152
|
-
const messageHex = (0, ripple_binary_codec_1.encodeForSigning)(tx);
|
|
151
|
+
function verifyTransaction(signedTransaction, definitions) {
|
|
152
|
+
const tx = typeof signedTransaction === "string" ? (0, ripple_binary_codec_1.decode)(signedTransaction, definitions) : signedTransaction;
|
|
153
|
+
const messageHex = (0, ripple_binary_codec_1.encodeForSigning)(tx, definitions);
|
|
153
154
|
const signature = tx.TxnSignature;
|
|
154
|
-
|
|
155
|
+
const publicKey = tx.SigningPubKey;
|
|
156
|
+
return (0, ripple_keypairs_1.verify)(messageHex, signature, publicKey);
|
|
157
|
+
}
|
|
158
|
+
function verifySignature(signedTransaction, explicitMultiSigner, definitions) {
|
|
159
|
+
let tx;
|
|
160
|
+
let signedBy = "";
|
|
161
|
+
let signatureValid = false;
|
|
162
|
+
try {
|
|
163
|
+
if (typeof signedTransaction === "string") {
|
|
164
|
+
tx = (0, ripple_binary_codec_1.decode)(signedTransaction, definitions);
|
|
165
|
+
}
|
|
166
|
+
else if (signedTransaction !== null && typeof signedTransaction === "object") {
|
|
167
|
+
tx = signedTransaction;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
catch (err) {
|
|
171
|
+
return { signatureValid: false, error: err.message };
|
|
172
|
+
}
|
|
173
|
+
if (!tx) {
|
|
174
|
+
return { signatureValid: false, error: "The transaction could not be decoded." };
|
|
175
|
+
}
|
|
176
|
+
if (!tx.TxnSignature && !tx.Signers) {
|
|
177
|
+
return { signatureValid: false, error: "The transaction must be signed to verify the signature." };
|
|
178
|
+
}
|
|
179
|
+
const signatureMultiSign = typeof tx.Signers !== "undefined" &&
|
|
180
|
+
Array.isArray(tx.Signers) &&
|
|
181
|
+
tx.Signers.length > 0 &&
|
|
182
|
+
typeof tx.SigningPubKey === "string" &&
|
|
183
|
+
tx.SigningPubKey === "";
|
|
184
|
+
try {
|
|
185
|
+
if (signatureMultiSign && explicitMultiSigner && explicitMultiSigner.match(/^r/)) {
|
|
186
|
+
signedBy = explicitMultiSigner;
|
|
187
|
+
}
|
|
188
|
+
else if (signatureMultiSign && explicitMultiSigner) {
|
|
189
|
+
signedBy = (0, ripple_keypairs_1.deriveAddress)(explicitMultiSigner);
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
let signer = tx.SigningPubKey;
|
|
193
|
+
if (signatureMultiSign && tx.Signers && tx.Signers.length > 0) {
|
|
194
|
+
const firstSigner = Object.values(tx.Signers)[0];
|
|
195
|
+
signer = firstSigner.Signer.SigningPubKey;
|
|
196
|
+
}
|
|
197
|
+
signedBy = (0, ripple_keypairs_1.deriveAddress)(signer);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
catch (err) {
|
|
201
|
+
return { signatureValid: false, error: err.message };
|
|
202
|
+
}
|
|
203
|
+
try {
|
|
204
|
+
if (signatureMultiSign && tx.Signers) {
|
|
205
|
+
const matchingSigners = Object.values(tx.Signers).filter((signer) => {
|
|
206
|
+
return (0, ripple_keypairs_1.deriveAddress)(signer.Signer.SigningPubKey) === signedBy;
|
|
207
|
+
});
|
|
208
|
+
if (matchingSigners.length > 0) {
|
|
209
|
+
const multiSigner = matchingSigners[0];
|
|
210
|
+
signatureValid = (0, ripple_keypairs_1.verify)((0, ripple_binary_codec_1.encodeForMultisigning)(tx, signedBy, definitions), multiSigner.Signer.TxnSignature, multiSigner.Signer.SigningPubKey);
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
return { signatureValid: false, error: "Explicit MultiSigner not in Signers" };
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
signatureValid = (0, ripple_keypairs_1.verify)((0, ripple_binary_codec_1.encodeForSigning)(tx, definitions), tx.TxnSignature, tx.SigningPubKey);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
catch (err) {
|
|
221
|
+
return { signedBy, signatureValid: false, error: err.message };
|
|
222
|
+
}
|
|
223
|
+
return {
|
|
224
|
+
signedBy,
|
|
225
|
+
signatureValid,
|
|
226
|
+
signatureMultiSign,
|
|
227
|
+
};
|
|
155
228
|
}
|
|
156
229
|
function computeSignature(tx, privateKey, signAs, definitions) {
|
|
157
230
|
if (signAs) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bithomp/xrpl-api",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.18",
|
|
4
4
|
"description": "A Bithomp JavaScript/TypeScript library for interacting with the XRP Ledger",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -55,28 +55,28 @@
|
|
|
55
55
|
"axios": "^1.7.7",
|
|
56
56
|
"base-x": "^5.0.0",
|
|
57
57
|
"bignumber.js": "^9.1.2",
|
|
58
|
-
"elliptic": "^6.6.
|
|
58
|
+
"elliptic": "^6.6.1",
|
|
59
59
|
"lodash": "^4.17.21",
|
|
60
60
|
"ripple-address-codec": "^5.0.0",
|
|
61
61
|
"ripple-binary-codec": "^2.1.0",
|
|
62
62
|
"xrpl": "^4.0.0"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@types/chai": "^
|
|
66
|
-
"@types/chai-as-promised": "^
|
|
67
|
-
"@types/lodash": "^4.17.
|
|
65
|
+
"@types/chai": "^5.0.1",
|
|
66
|
+
"@types/chai-as-promised": "^8.0.1",
|
|
67
|
+
"@types/lodash": "^4.17.13",
|
|
68
68
|
"@types/mocha": "^10.0.9",
|
|
69
69
|
"@types/nconf": "^0.10.7",
|
|
70
70
|
"@types/node": "^20.14.15",
|
|
71
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
72
|
-
"@typescript-eslint/parser": "^8.
|
|
71
|
+
"@typescript-eslint/eslint-plugin": "^8.14.0",
|
|
72
|
+
"@typescript-eslint/parser": "^8.14.0",
|
|
73
73
|
"chai": "^4.5.0",
|
|
74
74
|
"chai-as-promised": "^7.1.2",
|
|
75
75
|
"eslint": "^8.57.0",
|
|
76
76
|
"eslint-config-prettier": "^9.1.0",
|
|
77
77
|
"eslint-plugin-chai-friendly": "^1.0.1",
|
|
78
78
|
"eslint-plugin-import": "^2.31.0",
|
|
79
|
-
"eslint-plugin-n": "^17.
|
|
79
|
+
"eslint-plugin-n": "^17.13.2",
|
|
80
80
|
"eslint-plugin-promise": "^7.1.0",
|
|
81
81
|
"mocha": "^10.8.2",
|
|
82
82
|
"nconf": "^0.12.1",
|