@bithomp/xrpl-api 3.0.0 → 3.0.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/lib/ledger/transaction.js +1 -1
- package/lib/parse/utils.d.ts +2 -1
- package/lib/parse/utils.js +14 -1
- package/lib/wallet.d.ts +8 -2
- package/lib/wallet.js +22 -5
- package/package.json +1 -1
|
@@ -196,7 +196,7 @@ async function submitPaymentTransactionV1(data, definitions, validateTx) {
|
|
|
196
196
|
}
|
|
197
197
|
transaction.Sequence = submitParams.sequence;
|
|
198
198
|
transaction.LastLedgerSequence = submitParams.lastLedgerSequence;
|
|
199
|
-
const wallet = (0, wallet_1.walletFromSeed)(data.secret);
|
|
199
|
+
const wallet = (0, wallet_1.walletFromSeed)(data.secret, { seedAddress: transaction.Account });
|
|
200
200
|
const signedTransaction = (0, wallet_1.signTransaction)(wallet, transaction, false, definitions, validateTx).tx_blob;
|
|
201
201
|
return await submit(signedTransaction, { connection, definitions });
|
|
202
202
|
}
|
package/lib/parse/utils.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ declare function normalizeNodes(metadata: TransactionMetadata): any[];
|
|
|
10
10
|
declare function hexToString(hex: string | undefined): string | undefined;
|
|
11
11
|
declare function stringToHex(value: string | undefined): string | undefined;
|
|
12
12
|
declare function bytesToHex(value: Uint8Array | ArrayBufferLike): string;
|
|
13
|
+
declare function hexToBytes(value: string): Uint8Array;
|
|
13
14
|
declare function parseUint32(buf: Buffer, cur: number): string;
|
|
14
15
|
declare function parseUint64(buf: Buffer, cur: number): string;
|
|
15
|
-
export { parseQuality, parseTimestamp, adjustQualityForXRP, isPartialPayment, removeGenericCounterparty, normalizeNodes, hexToString, stringToHex, bytesToHex, parseUint32, parseUint64, };
|
|
16
|
+
export { parseQuality, parseTimestamp, adjustQualityForXRP, isPartialPayment, removeGenericCounterparty, normalizeNodes, hexToString, stringToHex, bytesToHex, hexToBytes, parseUint32, parseUint64, };
|
package/lib/parse/utils.js
CHANGED
|
@@ -3,7 +3,7 @@ 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.parseUint64 = exports.parseUint32 = exports.bytesToHex = exports.stringToHex = exports.hexToString = exports.normalizeNodes = exports.removeGenericCounterparty = exports.isPartialPayment = exports.adjustQualityForXRP = exports.parseTimestamp = exports.parseQuality = void 0;
|
|
6
|
+
exports.parseUint64 = exports.parseUint32 = exports.hexToBytes = exports.bytesToHex = exports.stringToHex = exports.hexToString = exports.normalizeNodes = exports.removeGenericCounterparty = exports.isPartialPayment = exports.adjustQualityForXRP = exports.parseTimestamp = exports.parseQuality = void 0;
|
|
7
7
|
const lodash_1 = __importDefault(require("lodash"));
|
|
8
8
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
9
9
|
const xrpl_1 = require("xrpl");
|
|
@@ -69,6 +69,19 @@ function bytesToHex(value) {
|
|
|
69
69
|
return Buffer.from(value).toString("hex").toUpperCase();
|
|
70
70
|
}
|
|
71
71
|
exports.bytesToHex = bytesToHex;
|
|
72
|
+
function hexToBytes(value) {
|
|
73
|
+
if (value.length % 2 !== 0) {
|
|
74
|
+
throw new Error("Invalid hex string length");
|
|
75
|
+
}
|
|
76
|
+
if (!/^[0-9a-fA-F]*$/.test(value)) {
|
|
77
|
+
throw new Error("Invalid hex string");
|
|
78
|
+
}
|
|
79
|
+
if (value.length === 0) {
|
|
80
|
+
return new Uint8Array(0);
|
|
81
|
+
}
|
|
82
|
+
return Uint8Array.from(Buffer.from(value, "hex"));
|
|
83
|
+
}
|
|
84
|
+
exports.hexToBytes = hexToBytes;
|
|
72
85
|
function parseUint32(buf, cur) {
|
|
73
86
|
return ((BigInt(buf[cur]) << 24n) + (BigInt(buf[cur + 1]) << 16n) + (BigInt(buf[cur + 2]) << 8n) + BigInt(buf[cur + 3]) + "");
|
|
74
87
|
}
|
package/lib/wallet.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { Wallet, Transaction } from "xrpl";
|
|
2
|
+
import { Wallet, Transaction, ECDSA } from "xrpl";
|
|
3
3
|
import { XrplDefinitionsBase, XrplDefinitions, DEFAULT_DEFINITIONS } from "ripple-binary-codec";
|
|
4
4
|
interface GenerateAddressInterface {
|
|
5
5
|
publicKey: string;
|
|
@@ -8,7 +8,13 @@ interface GenerateAddressInterface {
|
|
|
8
8
|
seed: string;
|
|
9
9
|
}
|
|
10
10
|
export declare function isValidSecret(secret: string): boolean;
|
|
11
|
-
export
|
|
11
|
+
export interface WalletFromSeedInterface {
|
|
12
|
+
masterAddress?: string;
|
|
13
|
+
algorithm?: ECDSA;
|
|
14
|
+
seedAddress?: string;
|
|
15
|
+
ignoreSeedPayload?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare function walletFromSeed(seed: string, options?: WalletFromSeedInterface): Wallet;
|
|
12
18
|
export declare function generateAddress(): GenerateAddressInterface;
|
|
13
19
|
export declare function isValidClassicAddress(address: string): boolean;
|
|
14
20
|
export declare function checksumClassicAddress(buffer: Buffer): Buffer;
|
package/lib/wallet.js
CHANGED
|
@@ -53,11 +53,28 @@ function isValidSecret(secret) {
|
|
|
53
53
|
return false;
|
|
54
54
|
}
|
|
55
55
|
exports.isValidSecret = isValidSecret;
|
|
56
|
-
function walletFromSeed(seed) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
function walletFromSeed(seed, options) {
|
|
57
|
+
options = { ignoreSeedPayload: false, ...options };
|
|
58
|
+
let algorithm = options.algorithm;
|
|
59
|
+
if (!options.ignoreSeedPayload && !options.algorithm) {
|
|
60
|
+
const decodedSeed = (0, ripple_address_codec_1.decodeSeed)(seed);
|
|
61
|
+
if (decodedSeed.type === "secp256k1") {
|
|
62
|
+
if (options.seedAddress) {
|
|
63
|
+
const { publicKey } = (0, ripple_keypairs_1.deriveKeypair)(seed, { algorithm: xrpl_1.ECDSA.secp256k1 });
|
|
64
|
+
const classicAddress = (0, ripple_keypairs_1.deriveAddress)(publicKey);
|
|
65
|
+
if (classicAddress === options.seedAddress) {
|
|
66
|
+
algorithm = xrpl_1.ECDSA.secp256k1;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
algorithm = xrpl_1.ECDSA.ed25519;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
algorithm = xrpl_1.ECDSA.secp256k1;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const wallet = xrpl_1.Wallet.fromSeed(seed, { algorithm, masterAddress: options.masterAddress });
|
|
61
78
|
return wallet;
|
|
62
79
|
}
|
|
63
80
|
exports.walletFromSeed = walletFromSeed;
|