Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add helper for generating content key #367

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 36 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,23 @@ module.exports = class Hyperdrive extends ReadyResource {
return this.entries()[Symbol.asyncIterator]()
}

_generateBlobsManifest () {
const m = this.db.core.manifest
if (m.version < 1 || this.db.core.core.compat) return null
static getContentKey (m, key) {
if (m instanceof Hypercore) {
if (m.core.compat) return null
return Hyperdrive.getContentKey(m.manifest, m.key)
}

const signers = []
const manifest = generateContentManifest(m, key)
if (!manifest) return null

for (const s of m.signers) {
const namespace = crypto.hash([BLOBS, this.core.key, s.namespace])
signers.push({ ...s, namespace })
}
return Hypercore.key(manifest)
}

return {
version: m.version,
hash: 'blake2b',
allowPatch: m.allowPatch,
quorum: m.quorum,
signers,
prologue: null // TODO: could be configurable through the header still...
}
_generateBlobsManifest () {
const m = this.db.core.manifest
if (this.db.core.core.compat) return null

return generateContentManifest(m, this.core.key)
}

get id () {
Expand Down Expand Up @@ -625,3 +623,25 @@ function prefixRange (name, prev = '/') {
// '0' is binary +1 of /
return { gt: name + prev, lt: name + '0' }
}

function generateContentManifest (m, key) {
if (m.version < 1) return null

const signers = []

if (!key) key = Hypercore.key(m)

for (const s of m.signers) {
const namespace = crypto.hash([BLOBS, key, s.namespace])
signers.push({ ...s, namespace })
}

return {
version: m.version,
hash: 'blake2b',
allowPatch: m.allowPatch,
quorum: m.quorum,
signers,
prologue: null // TODO: could be configurable through the header still...
}
}
Loading