Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const getIdKeys = (pid) => {
const pkBuffer = Buffer.from('/pk/')
const ipnsBuffer = Buffer.from('/ipns/')
return {
routingPubKey: new Key(Buffer.concat([pkBuffer, pid])), // Added on https://github.com/ipfs/js-ipns/pull/8#issue-213857876 (pkKey will be deprecated in a future release)
pkKey: new Key(rawStdEncoding(Buffer.concat([pkBuffer, pid]))),
routingKey: new Key(Buffer.concat([ipnsBuffer, pid])), // Added on https://github.com/ipfs/js-ipns/pull/6#issue-213631461 (ipnsKey will be deprecated in a future release)
ipnsKey: new Key(rawStdEncoding(Buffer.concat([ipnsBuffer, pid])))
}
}
return new Promise((resolve, reject) => {
const ds = ipfs._repo.datastore
if (!ds) {
return ipfs.once('start', () => {
datastore(ipfs, collaboration).then(resolve).catch(reject)
})
}
// resolve(ds)
resolve(new NamespaceStore(ds, new Key(`peer-base-collab-${collaboration.fqn()}`)))
})
}
const getIdKeys = (pid) => {
const pkBuffer = Buffer.from('/pk/')
const ipnsBuffer = Buffer.from('/ipns/')
return {
routingPubKey: new Key(Buffer.concat([pkBuffer, pid])), // Added on https://github.com/ipfs/js-ipns/pull/8#issue-213857876 (pkKey will be deprecated in a future release)
pkKey: new Key(rawStdEncoding(Buffer.concat([pkBuffer, pid]))),
routingKey: new Key(Buffer.concat([ipnsBuffer, pid])), // Added on https://github.com/ipfs/js-ipns/pull/6#issue-213631461 (ipnsKey will be deprecated in a future release)
ipnsKey: new Key(rawStdEncoding(Buffer.concat([ipnsBuffer, pid])))
}
}
async _getLocal (key) {
// encode key - base32(/ipns/{cid})
const routingKey = new Key('/' + encodeBase32(key), false)
let dsVal
try {
dsVal = await this._datastore.get(routingKey)
} catch (err) {
if (err.code !== 'ERR_NOT_FOUND') {
const errMsg = `unexpected error getting the ipns record for ${routingKey.toString()}`
log.error(errMsg)
throw errcode(new Error(errMsg), 'ERR_UNEXPECTED_ERROR_GETTING_RECORD')
}
const errMsg = `local record requested was not found for ${routingKey.toString()}`
log.error(errMsg)
throw errcode(new Error(errMsg), 'ERR_NOT_FOUND')
}
beforeEach(() => {
keyRef = `key${testCounter}`
key = (new Key(keyRef)).toBuffer()
record = new Record(key, Buffer.from(value))
serializedRecord = record.serialize()
})
function DsInfoName (name) {
return new DS.Key(infoPrefix + name)
}
function DsName (name) {
return new DS.Key('/' + name)
}
_routingKey (key) {
return new Key('/' + encodeBase32(key), false)
}
}