Last active
October 9, 2023 13:34
-
-
Save WietseWind/1f2b34ef6092e6f10762b5d526e89c86 to your computer and use it in GitHub Desktop.
Validator keys to XRPL account (by @RichardAH)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Reworked (2) version of https://github.com/RichardAH/xrpl-tools/blob/master/validator-address-tool/vatool.js | |
// Testnet faucet: | |
// curl -X POST -H 'content-type:application/json' --data '{"destination":"ryyyyyyyyyyyyyyy", "xrpAmount": "1010" }' https://faucet.altnet.rippletest.net/accounts | |
// Run: | |
// node index.mjs pxxxxxxxxxxxxxxxx ryyyyyyyyyyyyyyyyyyyyy wss://testnet.xrpl-labs.com | |
// ^^ Validator key ^^ Rekey to (address) ^^ Optional: node, default: ws://localhost:6005 | |
import { codec as RAC } from 'ripple-address-codec' | |
import { signAndSubmit, utils, derive } from 'xrpl-accountlib' | |
import elliptic from 'elliptic' | |
const ec = new elliptic.eddsa('ed25519') | |
if (process.argv.length < 4) { | |
console.log( | |
`Rekey validator address tool\n` + | |
`Usage: node ${process.argv[1]} validator_secret_key raddr_to_rekey_to [ ws node, default: ws://localhost:6005 ]` | |
) | |
process.exit(1) | |
} | |
const [ PrivateKey, RegularKey, Endpoint ] = [ process.argv[2], process.argv[3], process.argv?.[4] ] | |
const endpoint = Endpoint ?? 'ws://localhost:6005' | |
const account = derive.privatekey('ED' + Buffer.from(ec.keyFromSecret(RAC._codec.decode(PrivateKey).slice(1, 33)).secret()).toString('hex').toUpperCase()) | |
const accountInfo = await utils.accountAndLedgerSequence(endpoint, account) | |
const tx = { | |
TransactionType: 'SetRegularKey', | |
Account: account.address, | |
RegularKey, | |
...accountInfo.txValues, | |
NetworkID: accountInfo.txValues.NetworkID >= 1024 ? accountInfo.txValues.NetworkID : undefined, | |
} | |
const result = await signAndSubmit(tx, endpoint, account) | |
console.log(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment