Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function ensureClassicAddress(account: string): string {
if (isValidXAddress(account)) {
const {classicAddress, tag} = xAddressToClassicAddress(account)
// Except for special cases, X-addresses used for requests
// must not have an embedded tag. In other words,
// `tag` should be `false`.
if (tag !== false) {
throw new Error(
'This command does not support the use of a tag. Use an address without a tag.'
)
}
// For rippled requests that use an account, always use a classic address.
return classicAddress
} else {
return account
}
function getClassicAccountAndTag(
Account: string,
expectedTag?: number
): ClassicAccountAndTag {
if (isValidXAddress(Account)) {
const classic = xAddressToClassicAddress(Account)
if (expectedTag !== undefined && classic.tag !== expectedTag) {
throw new ValidationError(
'address includes a tag that does not match the tag specified in the transaction'
)
}
return {
classicAccount: classic.classicAddress,
tag: classic.tag
}
} else {
return {
classicAccount: Account,
tag: expectedTag
}
}
validator.customFormats.xAddress = function(instance) {
if (instance === undefined) {
return true
}
return isValidXAddress(instance)
}