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))