Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
put (key, value, callback) {
if (!Buffer.isBuffer(key)) {
return callback(errcode(new Error('DNS datastore key must be a buffer'), 'ERR_INVALID_KEY'))
}
if (!Buffer.isBuffer(value)) {
return callback(errcode(new Error(`DNS datastore value must be a buffer`), 'ERR_INVALID_VALUE'))
}
const cid = new Cid(key.slice(ipns.namespaceLength))
// http://localhost:8000
// https://ipns.dev
ky.put(
'https://ipns.dev',
{
json: {
key: cid.toV1().toString(),
record: value.toString('base64')
}
})
.then(data => {
setImmediate(() => callback())
})
.catch(err => {
setImmediate(() => callback(err))
})
}
async put (key, value) {
const start = Date.now()
if (key.toString().startsWith('/pk/')) {
return
}
if (!Buffer.isBuffer(key)) {
throw errcode(new Error('Workers datastore key must be a buffer'), 'ERR_INVALID_KEY')
}
if (!Buffer.isBuffer(value)) {
throw errcode(new Error(`Workers datastore value must be a buffer`), 'ERR_INVALID_VALUE')
}
const keyStr = keyToBase32(key)
await ky.put(
'https://workers.ipns.dev',
{
json: {
key: keyStr,
value: value.toString('base64')
}
})
console.log(`
Workers Store
Domain: workers.ipns.dev
Key: ${keyStr}
Time: ${(Date.now() - start)}ms
`)
}
async put (key, value) {
const start = Date.now()
if (key.toString().startsWith('/pk/')) {
return
}
if (!Buffer.isBuffer(key)) {
throw errcode(new Error('MDNS datastore key must be a buffer'), 'ERR_INVALID_KEY')
}
if (!Buffer.isBuffer(value)) {
throw errcode(new Error(`MDNS datastore value must be a buffer`), 'ERR_INVALID_VALUE')
}
const keyStr = keyToBase32(key)
await ky.put(
'http://ipns.local:8000',
{
json: {
key: keyStr,
record: value.toString('base64')
}
})
console.log(`
Local Store
Domain: ipns.local
Key: ${keyStr}
Time: ${(Date.now() - start)}ms
`)
}