A bech32 address like bc1qjpjanssen2x7586qzr8fnmk0epfdttqwfkkvlx is encoded as hex (809065d9c2199a8dea1f4010ce99eecfc852d5ac0e) inside the Counterparty data.
The encoded hex address corresponds to step 3 in this guide (with prefix 80 being the version byte).
I’ve written a function that converts address to hex:
function bech32toHex(address) { //https://en.bitcoin.it/wiki/Bech32
const CHARSET = 'qpzry9x8gf2tvdw0s3jn54khce6mua7l';
address = address.toLowerCase();
let data = [];
for (let p = 4; p < address.length; ++p) {
let d = CHARSET.indexOf(address.charAt(p));
if (d === -1) {
return null;
}
data.push(d);
}
let bin5 = [];
for (let i = 0; i <= 32; i++) {
bin5.push(data[i].toString(2).padStart(5, '0'));
}
let binString = ''
for (let i = 0; i < bin5.length; i++) {
binString += bin5[i];
}
let bin8 = binString.match(/.{8}/g);
let hex = '';
for (let i = 0; i < bin8.length; i++) {
hex += parseInt(bin8[i], 2).toString(16).padStart(2, '0');
}
return hex;
}
It’s on my TODO to write the reverse function, hexToBech32() but it’s not a priority right now. If someone feels like trying, go ahead – I’d be grateful if you share the result.