viewof BIND = {
const { who, why, what, where } = CONFIG;
const id = who + '/' + why + '/' + where + '/' + what;
const [ip0, ip1, ip2, ip3, p1, p2] = hash2parts(sha256(id));
return Inputs.form({
id: Inputs.text({
label: 'id',
value: id,
}),
bind: Inputs.text({
label: 'bind',
value: `${ip0}.${ip1}.${ip2}.${ip3}`,
}),
port: Inputs.text({
label: 'port',
value: `${p1<<8|p2}`,
}),
});
function *hash2parts(hash) {
const arr = hex2arr(hash);
const mask0 = new Uint8Array([0xFF, 0x00, 0x00, 0x00, 0x80, 0x00]);
const mask1 = new Uint8Array([0x7F, 0x00, 0x00, 0x00, 0x80, 0x00]);
for (let i=0, n=mask0.length; i<n; ++i) {
arr[i] &= ~mask0[i];
arr[i] |= mask1[i];
yield arr[i];
}
}
function hex2arr(hexString) {
return Uint8Array.from(hexString.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));
}
function arr2hex(bytes) {
return bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), '');
}
}