Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
ttl: 10800,
class: 'IN',
type: 'DNSKEY',
data: {
flags: 256,
protocol: 3,
algorithm: 13,
publicKey: ''
+ 'I5nPs6clFa1gnwn9IpVDGdJLfEONzgD1NcfuEwEIVuIoHdZGgvVblsLNbRO+'
+ 'spW3nQYHg92svhy1HOjTiFBIsQ=='
}
});
// . DS 35215 13 2
// 7C50EA94A63AEECB65B510D1EAC1846C973A89D4AB292287D5A4D715136B57A3
exports.ds = dnssec.createDS(exports.ksk, dnssec.hashes.SHA256);
exports.signKSK = function signKSK(section, type) {
return dnssec.signType(section, type, exports.ksk, exports.kskPriv);
};
exports.signZSK = function signZSK(section, type) {
return dnssec.signType(section, type, exports.zsk, exports.zskPriv);
};
fromString(str) {
assert(typeof str === 'string');
assert(str.length <= 255);
str = str.toLowerCase();
const parts = str.split('@');
if (parts.length > 1) {
const name = util.fqdn(parts[0]);
assert(isName(name));
const ips = parts[1].split(',');
assert(ips.length <= 2);
this.type = types.GLUE;
this.target = name;
for (const ip of ips) {
const [type, addr] = parseIP(ip);
switch (type) {
case types.ONION:
throw new Error('Bad glue address.');
case types.INET4:
if (addr === '0.0.0.0')
assert(str[index - 1] === '?' || str[index - 1] === '&');
str = str.substring(index + 7);
const parts = str.split(/[:&]/);
assert(parts.length >= 2);
const [nid, nin] = parts;
assert(nid.length <= 255);
assert(nin.length <= 255);
assert(isSingle(nid));
this.nid = util.fqdn(nid);
this.nin = nin;
return this;
}
fromString(str) {
assert(typeof str === 'string');
assert(str.length <= 512);
const parts = str.split(':');
assert(parts.length === 2);
const [currency, address] = parts;
assert(currency.length <= 255);
assert(address.length <= 255);
assert(isSingle(currency));
this.currency = util.fqdn(currency);
this.address = address;
return this;
}
getSize() {
if (util.equal(this.currency, 'handshake.')) {
const {hash} = bech32.decode(this.address);
return 1 + 2 + hash.length;
}
if (util.equal(this.currency, 'bitcoin.') && bech32.test(this.address)) {
const {hash} = bech32.decode(this.address);
return 1 + 2 + hash.length;
}
if (util.equal(this.currency, 'ethereum.'))
return 1 + 20;
return 1 + sizeName(this.currency) + 1 + this.address.length;
}
getSize() {
if (util.equal(this.currency, 'handshake.')) {
const {hash} = bech32.decode(this.address);
return 1 + 2 + hash.length;
}
if (util.equal(this.currency, 'bitcoin.') && bech32.test(this.address)) {
const {hash} = bech32.decode(this.address);
return 1 + 2 + hash.length;
}
if (util.equal(this.currency, 'ethereum.'))
return 1 + 20;
return 1 + sizeName(this.currency) + 1 + this.address.length;
}
getSize() {
if (util.equal(this.currency, 'handshake.')) {
const {hash} = bech32.decode(this.address);
return 1 + 2 + hash.length;
}
if (util.equal(this.currency, 'bitcoin.') && bech32.test(this.address)) {
const {hash} = bech32.decode(this.address);
return 1 + 2 + hash.length;
}
if (util.equal(this.currency, 'ethereum.'))
return 1 + 20;
return 1 + sizeName(this.currency) + 1 + this.address.length;
}
assert(hash.length >= 1);
assert(hash.length <= 128);
const test = hrp === 'ts' ? 0x80 : 0x00;
const size = hash.length - 1;
const field = test | size;
bw.writeU8(1);
bw.writeU8(field);
bw.writeU8(version);
bw.writeBytes(hash);
return this;
}
if (util.equal(this.currency, 'bitcoin.') && bech32.test(this.address)) {
const {hrp, version, hash} = bech32.decode(this.address);
assert(hash.length >= 1);
assert(hash.length <= 128);
const test = hrp === 'tb' ? 0x80 : 0x00;
const size = hash.length - 1;
const field = test | size;
bw.writeU8(2);
bw.writeU8(field);
bw.writeU8(version);
bw.writeBytes(hash);
return this;
}
toPointer(name) {
assert(typeof name === 'string');
assert(util.isFQDN(name));
assert(this.isINET());
const ip = IP.toBuffer(this.target);
const data = ipPack(ip);
const hash = base32.encodeHex(data);
const labels = util.split(name);
const tld = util.label(name, labels, -1);
return `_${hash}.${tld}.`;
}
toPointer(name) {
assert(typeof name === 'string');
assert(util.isFQDN(name));
assert(this.isINET());
const ip = IP.toBuffer(this.target);
const data = ipPack(ip);
const hash = base32.encodeHex(data);
const labels = util.split(name);
const tld = util.label(name, labels, -1);
return `_${hash}.${tld}.`;
}