Skip to content

Instantly share code, notes, and snippets.

@WietseWind
Last active October 9, 2023 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WietseWind/1f2b34ef6092e6f10762b5d526e89c86 to your computer and use it in GitHub Desktop.
Save WietseWind/1f2b34ef6092e6f10762b5d526e89c86 to your computer and use it in GitHub Desktop.
Validator keys to XRPL account (by @RichardAH)
// 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