@bithomp/xrpl-api 3.7.20 → 3.7.23
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 +6 -1
- package/lib/faucet.js +11 -4
- package/lib/parse/outcome/balance_changes.js +8 -0
- package/lib/validator.js +11 -16
- package/package.json +17 -15
package/lib/connection.js
CHANGED
|
@@ -49,6 +49,11 @@ const LEDGER_CLOSED_TIMEOUT = 1000 * 20;
|
|
|
49
49
|
const SERVER_INFO_UPDATE_INTERVAL = 1000 * 60 * 5;
|
|
50
50
|
const AVAILABLE_LEDGER_INDEX_WINDOW = 1000;
|
|
51
51
|
exports.DEFAULT_API_VERSION = xrpl_1.RIPPLED_API_V1;
|
|
52
|
+
const SLOW_DOWN_ERROR_MESSAGES = [
|
|
53
|
+
"slowDown",
|
|
54
|
+
"Unexpected server response: 429",
|
|
55
|
+
"You are placing too much load on the server."
|
|
56
|
+
];
|
|
52
57
|
class Connection extends events_1.EventEmitter {
|
|
53
58
|
constructor(url, type, options = {}) {
|
|
54
59
|
super();
|
|
@@ -126,7 +131,7 @@ class Connection extends events_1.EventEmitter {
|
|
|
126
131
|
const result = await this._request(request, options);
|
|
127
132
|
let validResponse = true;
|
|
128
133
|
if (result?.error) {
|
|
129
|
-
if (
|
|
134
|
+
if (SLOW_DOWN_ERROR_MESSAGES.includes(result.error)) {
|
|
130
135
|
this.logger?.debug({
|
|
131
136
|
service: "Bithomp::XRPL::Connection",
|
|
132
137
|
function: "request",
|
package/lib/faucet.js
CHANGED
|
@@ -79,11 +79,18 @@ async function foundWallet(network, account) {
|
|
|
79
79
|
throw new Error("Invalid network");
|
|
80
80
|
}
|
|
81
81
|
const options = getAxiosFaucetOptions(network, account);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
try {
|
|
83
|
+
const data = (await (0, axios_1.default)(options)).data;
|
|
84
|
+
if (network.format === "xrpl-labs" && data.code === "tesSUCCESS") {
|
|
85
|
+
return xrplLabsToXrplResponse(data);
|
|
86
|
+
}
|
|
87
|
+
return data;
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
return {
|
|
91
|
+
error: err.message,
|
|
92
|
+
};
|
|
85
93
|
}
|
|
86
|
-
return data;
|
|
87
94
|
}
|
|
88
95
|
function getAxiosFaucetOptions(network, account) {
|
|
89
96
|
const options = {
|
|
@@ -266,6 +266,14 @@ function adjustBalancesForPaymentChannel(balanceChanges, metadata, nativeCurrenc
|
|
|
266
266
|
adjustBalancesChanges(balanceChanges, channelChanges.source.address, [
|
|
267
267
|
{ currency: channelChanges.amount.currency, value: `-${unlockedAmount.toString()}` },
|
|
268
268
|
]);
|
|
269
|
+
if (channelChanges.source.address !== tx.Account && channelChanges?.balance && channelChanges?.amount) {
|
|
270
|
+
const returnedAmount = new bignumber_js_1.default(channelChanges.amount.value).minus(new bignumber_js_1.default(channelChanges.balance.value));
|
|
271
|
+
if (!returnedAmount.isZero()) {
|
|
272
|
+
adjustBalancesChanges(balanceChanges, channelChanges.source.address, [
|
|
273
|
+
{ currency: channelChanges.amount.currency, value: `-${returnedAmount}` },
|
|
274
|
+
]);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
269
277
|
}
|
|
270
278
|
else if (channelChanges.balanceChange) {
|
|
271
279
|
adjustBalancesChanges(balanceChanges, channelChanges.source.address, [
|
package/lib/validator.js
CHANGED
|
@@ -32,9 +32,6 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
36
|
exports.classicAddressFromValidatorPK = classicAddressFromValidatorPK;
|
|
40
37
|
exports.generateSecrets = generateSecrets;
|
|
@@ -44,11 +41,12 @@ exports.verify2 = verify2;
|
|
|
44
41
|
const assert = __importStar(require("assert"));
|
|
45
42
|
const ripple_address_codec_1 = require("ripple-address-codec");
|
|
46
43
|
const Crypto = __importStar(require("crypto"));
|
|
47
|
-
const elliptic_1 = __importDefault(require("elliptic"));
|
|
48
|
-
const secp256k1 = new elliptic_1.default.ec("secp256k1");
|
|
49
|
-
const ed25519 = new elliptic_1.default.eddsa("ed25519");
|
|
50
44
|
const rippleKeypairs = __importStar(require("ripple-keypairs"));
|
|
51
45
|
const utils_1 = require("./parse/utils");
|
|
46
|
+
const secp256k1 = __importStar(require("@noble/secp256k1"));
|
|
47
|
+
const ed25519 = __importStar(require("@noble/ed25519"));
|
|
48
|
+
const sha2_js_1 = require("@noble/hashes/sha2.js");
|
|
49
|
+
ed25519.hashes.sha512 = sha2_js_1.sha512;
|
|
52
50
|
const DER_PRIVATE_KEY_PREFIX = Buffer.from("302E020100300506032B657004220420", "hex");
|
|
53
51
|
const DER_PUBLIC_KEY_PREFIX = Buffer.from("302A300506032B6570032100", "hex");
|
|
54
52
|
const VALIDATOR_HEX_PREFIX_ED25519 = "ED";
|
|
@@ -119,17 +117,14 @@ function verify2(message, signature, publicKey) {
|
|
|
119
117
|
publicKey = (0, utils_1.bytesToHex)(publicKeyBuffer.buffer);
|
|
120
118
|
}
|
|
121
119
|
if (publicKey.slice(0, 2) === VALIDATOR_HEX_PREFIX_ED25519) {
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
120
|
+
const publicKeyBytes = Buffer.from(publicKey.slice(2), "hex");
|
|
121
|
+
const signatureBytes = Buffer.from(signature, "hex");
|
|
122
|
+
return ed25519.verify(signatureBytes, message, publicKeyBytes);
|
|
126
123
|
}
|
|
127
124
|
else {
|
|
128
|
-
const computedHash = Crypto.createHash("sha512").update(message).digest().
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
125
|
+
const computedHash = Crypto.createHash("sha512").update(message).digest().slice(0, 32);
|
|
126
|
+
const publicKeyBytes = Buffer.from(publicKey, "hex");
|
|
127
|
+
const signatureBytes = Buffer.from(signature, "hex");
|
|
128
|
+
return secp256k1.verify(signatureBytes, computedHash, publicKeyBytes);
|
|
133
129
|
}
|
|
134
|
-
return false;
|
|
135
130
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bithomp/xrpl-api",
|
|
3
|
-
"version": "3.7.
|
|
3
|
+
"version": "3.7.23",
|
|
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",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
|
|
43
43
|
"lint": "eslint",
|
|
44
44
|
"prepare": "npm run build",
|
|
45
|
-
"prepublishOnly": "npm test && npm run lint",
|
|
45
|
+
"-prepublishOnly": "npm test && npm run lint",
|
|
46
46
|
"preversion": "npm run lint",
|
|
47
47
|
"version": "npm run format && git add -A src",
|
|
48
48
|
"postversion": "git push && git push --tags"
|
|
@@ -51,37 +51,39 @@
|
|
|
51
51
|
"lib/**/*"
|
|
52
52
|
],
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"
|
|
54
|
+
"@noble/ed25519": "^3.0.0",
|
|
55
|
+
"@noble/hashes": "^2.0.1",
|
|
56
|
+
"@noble/secp256k1": "^3.0.0",
|
|
57
|
+
"axios": "^1.13.4",
|
|
55
58
|
"base-x": "^5.0.1",
|
|
56
59
|
"bignumber.js": "^9.3.1",
|
|
57
|
-
"
|
|
58
|
-
"lodash": "^4.17.21",
|
|
60
|
+
"lodash": "^4.17.23",
|
|
59
61
|
"ripple-address-codec": "5.0.0",
|
|
60
|
-
"ripple-binary-codec": "2.
|
|
62
|
+
"ripple-binary-codec": "2.6.0",
|
|
61
63
|
"ripple-keypairs": "2.0.0",
|
|
62
|
-
"xrpl": "4.
|
|
64
|
+
"xrpl": "4.5.0"
|
|
63
65
|
},
|
|
64
66
|
"devDependencies": {
|
|
65
67
|
"@eslint/eslintrc": "^3.3.3",
|
|
66
68
|
"@types/chai": "^5.2.3",
|
|
67
69
|
"@types/chai-as-promised": "^8.0.2",
|
|
68
|
-
"@types/lodash": "^4.17.
|
|
70
|
+
"@types/lodash": "^4.17.23",
|
|
69
71
|
"@types/mocha": "^10.0.10",
|
|
70
72
|
"@types/nconf": "^0.10.7",
|
|
71
|
-
"@types/node": "^
|
|
72
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
73
|
-
"@typescript-eslint/parser": "^8.
|
|
74
|
-
"chai": "^6.2.
|
|
73
|
+
"@types/node": "^25.0.10",
|
|
74
|
+
"@typescript-eslint/eslint-plugin": "^8.54.0",
|
|
75
|
+
"@typescript-eslint/parser": "^8.54.0",
|
|
76
|
+
"chai": "^6.2.2",
|
|
75
77
|
"chai-as-promised": "^8.0.2",
|
|
76
|
-
"eslint": "^9.39.
|
|
78
|
+
"eslint": "^9.39.2",
|
|
77
79
|
"eslint-config-prettier": "^10.1.8",
|
|
78
80
|
"eslint-plugin-chai-friendly": "^1.1.0",
|
|
79
81
|
"eslint-plugin-import": "^2.32.0",
|
|
80
|
-
"eslint-plugin-n": "^17.23.
|
|
82
|
+
"eslint-plugin-n": "^17.23.2",
|
|
81
83
|
"eslint-plugin-promise": "^7.2.1",
|
|
82
84
|
"mocha": "^11.7.5",
|
|
83
85
|
"nconf": "^0.13.0",
|
|
84
|
-
"ts-jest": "^29.4.
|
|
86
|
+
"ts-jest": "^29.4.6",
|
|
85
87
|
"ts-node": "^10.9.2",
|
|
86
88
|
"typescript": "^5.9.3"
|
|
87
89
|
}
|