mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-21 12:15:50 +00:00
- Removed key generation from mnemonic, as it is deprecated and will soon be removed from rippled
- Added base58 seed - Updated readme accordingly
This commit is contained in:
@@ -7,18 +7,18 @@ have to install the necessary node.js dedpendencies:
|
|||||||
|
|
||||||
## Command-line usage:
|
## Command-line usage:
|
||||||
|
|
||||||
### Password like seed
|
### Base58 formatted seed:
|
||||||
|
|
||||||
|
npm start "snJj9fYixUfpNCBn9LzLdLv5QqUKZ"
|
||||||
|
|
||||||
|
### Hex formatted seed:
|
||||||
|
|
||||||
|
npm start "BB664A14F510A366404BC4352A2230A5"
|
||||||
|
|
||||||
|
### Password like seed:
|
||||||
|
|
||||||
npm start "sEdSKaCy2JT7JaM7v95H9SxkhP9wS2r"
|
npm start "sEdSKaCy2JT7JaM7v95H9SxkhP9wS2r"
|
||||||
|
|
||||||
### Rippled RFC1751 Mnemonic
|
|
||||||
|
|
||||||
npm start "KANT FISH GENE COST WEB JAKE CHUM HAD SOD MID KICK BOTH"
|
|
||||||
|
|
||||||
### Hex formatted seed
|
|
||||||
|
|
||||||
npm start "21edc3dec3ef1873cf8f333381c5f360c3"
|
|
||||||
|
|
||||||
### Random seed
|
### Random seed
|
||||||
|
|
||||||
npm start
|
npm start
|
||||||
@@ -1,13 +1,12 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
//organize imports
|
// Organize imports
|
||||||
const assert = require("assert")
|
const assert = require("assert")
|
||||||
const brorand = require("brorand")
|
const brorand = require("brorand")
|
||||||
const BN = require("bn.js")
|
const BN = require("bn.js")
|
||||||
const elliptic = require("elliptic");
|
const elliptic = require("elliptic");
|
||||||
const Ed25519 = elliptic.eddsa('ed25519');
|
const Ed25519 = elliptic.eddsa('ed25519');
|
||||||
const Secp256k1 = elliptic.ec('secp256k1');
|
const Secp256k1 = elliptic.ec('secp256k1');
|
||||||
const { rfc1751MnemonicToKey, keyToRFC1751Mnemonic } = require("xrpl/dist/npm/Wallet/rfc1751");
|
|
||||||
const hashjs = require("hash.js");
|
const hashjs = require("hash.js");
|
||||||
const Sha512 = require("ripple-keypairs/dist/Sha512")
|
const Sha512 = require("ripple-keypairs/dist/Sha512")
|
||||||
const { codec, encodeAccountPublic, encodeNodePublic } = require("ripple-address-codec");
|
const { codec, encodeAccountPublic, encodeNodePublic } = require("ripple-address-codec");
|
||||||
@@ -49,34 +48,34 @@ class Seed {
|
|||||||
|
|
||||||
_initSeed(seedValue) {
|
_initSeed(seedValue) {
|
||||||
|
|
||||||
//default to random seed
|
// No input given - default to random seed
|
||||||
if (!seedValue || seedValue === '') {
|
if (!seedValue || seedValue === '') {
|
||||||
const randomBuffer = brorand(16)
|
const randomBuffer = brorand(16)
|
||||||
return [...randomBuffer]
|
return [...randomBuffer]
|
||||||
}
|
}
|
||||||
|
|
||||||
//from hex formatted seed
|
// From base58 formatted seed
|
||||||
|
try {
|
||||||
|
const base58decoded = codec.decodeChecked(seedValue)
|
||||||
|
if (base58decoded[0] === XRPL_SEED_PREFIX && base58decoded.length === 17) {
|
||||||
|
return [...base58decoded.slice(1)];
|
||||||
|
}
|
||||||
|
} catch (exception) {
|
||||||
|
// Continue probing the seed for different format
|
||||||
|
}
|
||||||
|
|
||||||
|
// From hex formatted seed
|
||||||
if (isHex(seedValue)) {
|
if (isHex(seedValue)) {
|
||||||
const decoded = hexToBytes(seedValue);
|
const decoded = hexToBytes(seedValue);
|
||||||
if(decoded.length === 16) {
|
if(decoded.length === 16) {
|
||||||
return decoded
|
return decoded
|
||||||
} else {
|
} else {
|
||||||
//Raise Error
|
// Raise Error
|
||||||
throw new Error("incorrect decoded seed length")
|
throw new Error("incorrect decoded seed length")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//from rfc1751 Mnemonic
|
// From password seed
|
||||||
try {
|
|
||||||
const rippledMnemonic = rfc1751MnemonicToKey(seedValue)
|
|
||||||
if (rippledMnemonic.length === 16) {
|
|
||||||
return [...rippledMnemonic]
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
//try next seed mode
|
|
||||||
}
|
|
||||||
|
|
||||||
//from password seed
|
|
||||||
const encoded = encodeUTF8(seedValue)
|
const encoded = encodeUTF8(seedValue)
|
||||||
return hashjs.sha512().update(encoded).digest().slice(0, 16);
|
return hashjs.sha512().update(encoded).digest().slice(0, 16);
|
||||||
}
|
}
|
||||||
@@ -131,6 +130,7 @@ class Seed {
|
|||||||
hasher.addU32(i);
|
hasher.addU32(i);
|
||||||
const key = hasher.first256BN();
|
const key = hasher.first256BN();
|
||||||
/* istanbul ignore else */
|
/* istanbul ignore else */
|
||||||
|
/* istanbul ignore else */
|
||||||
if (key.cmpn(0) > 0 && key.cmp(order) < 0) {
|
if (key.cmpn(0) > 0 && key.cmp(order) < 0) {
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
@@ -164,7 +164,6 @@ class Seed {
|
|||||||
toString() {
|
toString() {
|
||||||
const base58Seed = codec.encodeChecked([XRPL_SEED_PREFIX].concat(this.bytes))
|
const base58Seed = codec.encodeChecked([XRPL_SEED_PREFIX].concat(this.bytes))
|
||||||
const hexSeed = Buffer.from(this.bytes).toString('hex').toUpperCase()
|
const hexSeed = Buffer.from(this.bytes).toString('hex').toUpperCase()
|
||||||
const rfc1751Rippled = keyToRFC1751Mnemonic(bytesToHex(this.bytes))
|
|
||||||
|
|
||||||
const base58ED25519Account = this.getBase58ED25519Account();
|
const base58ED25519Account = this.getBase58ED25519Account();
|
||||||
|
|
||||||
@@ -174,7 +173,6 @@ class Seed {
|
|||||||
const out = `
|
const out = `
|
||||||
Seed (base58): ${base58Seed}
|
Seed (base58): ${base58Seed}
|
||||||
Seed (hex): ${hexSeed}
|
Seed (hex): ${hexSeed}
|
||||||
Seed (rippled RFC-1751): ${rfc1751Rippled}
|
|
||||||
|
|
||||||
Ed25519 Secret Key (hex): ${this.ED25519Keypair.privateKey}
|
Ed25519 Secret Key (hex): ${this.ED25519Keypair.privateKey}
|
||||||
Ed25519 Public Key (hex): ${this.ED25519Keypair.publicKey}
|
Ed25519 Public Key (hex): ${this.ED25519Keypair.publicKey}
|
||||||
|
|||||||
Reference in New Issue
Block a user