Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

Account address prefix

node v10.24.1
version: 3.0.0
endpointsharetweet
const codec = require('ripple-address-codec') const findPrefix = (desiredPrefix, payloadLength) => { const rippleCodec = codec.codecs.ripple if (rippleCodec.base !== 58) { throw new Error('Only works for base58') } const factor = Math.log(256) / Math.log(rippleCodec.base) const totalLength = payloadLength + 4 // for checksum const chars = totalLength * factor const requiredChars = Math.ceil(chars + 0.2) const alphabetPosition = Math.floor((rippleCodec.alphabet.length) / 2) - 1 const padding = rippleCodec.alphabet[alphabetPosition] const rcPad = new Array(requiredChars + 1).join(padding) const template = desiredPrefix + rcPad const bytes = rippleCodec.decodeRaw(template) const version = bytes.slice(0, -totalLength) return version } console.log(findPrefix('X', 29))
Loading…

no comments

    sign in to comment