Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
pubkeyToBech32: function(pubkey, prefix) {
// '1624DE6420' is ed25519 pubkey prefix
let pubkeyAminoPrefix = Buffer.from('1624DE6420', 'hex')
let buffer = Buffer.alloc(37)
pubkeyAminoPrefix.copy(buffer, 0)
Buffer.from(pubkey.value, 'base64').copy(buffer, pubkeyAminoPrefix.length)
return bech32.encode(prefix, bech32.toWords(buffer))
},
bech32ToPubkey: function(pubkey) {
static toBech32(prefix, str) {
let strByte = BECH32.toWords(Buffer.from(str, 'hex'))
return BECH32.encode(prefix, strByte)
}
}
function hexToWord (hex) {
let buffer = hexToBuffer(hex)
return bech32.toWords(buffer)
}
lazy.prop(o, 'address', () => {
if (!o.hash) return;
const words = bech32.toWords(o.hash);
words.unshift(0x00);
return bech32.encode(network.bech32, words);
});
lazy.prop(o, 'hash', () => {
function purposeCommitEncoder (data) {
let buffer
if (data !== undefined && (typeof data === 'string' || data instanceof String)) {
if (data.match(/^([a-zA-Z0-9]{2})*$/)) {
buffer = Buffer.from(data, 'hex')
} else {
buffer = sha256(Buffer.from(data, 'utf8'))
}
} else {
throw new Error('purpose or purpose commit must be a string or hex string')
}
return bech32.toWords(buffer)
}
function hexToWord (hex) {
let buffer = hexToBuffer(hex)
return bech32.toWords(buffer)
}
export function getBech32Address(hash, prefix='desmos') {
if (!hash) return ''
let address = Buffer.from(hash, `hex`)
let words = bech32.toWords(address)
return bech32.encode(prefix, words)
}
function toBech32(data, version, prefix) {
const words = bech32.toWords(data);
words.unshift(version);
return bech32.encode(prefix, words);
}
exports.toBech32 = toBech32;
lazy.prop(o, 'address', () => {
if (!o.hash) return;
const words = bech32.toWords(o.hash);
words.unshift(0x00);
return bech32.encode(network.bech32, words);
});
lazy.prop(o, 'hash', () => {
function purposeCommitEncoder (data) {
let buffer
if (data !== undefined && (typeof data === 'string' || data instanceof String)) {
if (data.match(/^([a-zA-Z0-9]{2})*$/)) {
buffer = Buffer.from(data, 'hex')
} else {
buffer = sha256(Buffer.from(data, 'utf8'))
}
} else {
throw new Error('purpose or purpose commit must be a string or hex string')
}
return bech32.toWords(buffer)
}