// IdentityRegistry — the AUTOBASE binding of hyper-identity-core's registry.
//
// Everything this class used to hold — 19 appends, 15 updates, every user/identity/username/token
// operation, every read — moved to `hyper-identity-core`, unchanged. None of it was ever
// autobase-specific; both engines spell all of it identically, which is why the split is a subclass
// and not a fork. What is left here is the engine, and only the engine.
//
// ⛔ The engine is the PACKAGE, not an option. `hyper-identity` is autobase; `hyper-identity2` is
// autobee. An `engine: 'autobee'` option on this class would have been a lie that constructed an
// Autobase — a false green the parity harness caught once already.
import Autobase from 'autobase'
import b4a from 'b4a'
import Hyperbee from 'hyperbee'
import { BaseIdentityRegistry } from 'hyper-identity-core/registry'
import { adaptHost } from './adapt-host.js'
export class IdentityRegistry extends BaseIdentityRegistry {
static engine = 'autobase'
// autobase spells the core's `{ isIndexer }` as `{ indexer }`. See adapt-host.js — that file is
// the whole reason this method exists, and the reason it has a test of its own.
_adaptHost () { return adaptHost }
/**
* Canonical multi-writer Autobase config (mirrors keet-core-hyperdb):
* optimistic — non-indexer writers can append optimistically; their blocks linearize before
* being signed. Without this, plain writers stall and the only workaround is to
* make every device an indexer, which deadlocks during manifest migration when
* going from 2→3 indexers.
* ackInterval — auto-ack on a timer so signedLength advances even when the indexer set has no
* pending appends.
* ackThreshold — per-indexer churn budget. 4 matches keet's defaults.
* See pear-git-v3/test/keet-pattern-e2e.js for cross-machine validation.
*/
async _createBase ({ apply, rootKey }) {
return new Autobase(this._store, rootKey, {
apply,
open (store) {
return new Hyperbee(store.get('identity-view'), {
extension: false,
keyEncoding: 'utf-8',
valueEncoding: 'json'
})
},
valueEncoding: 'binary',
keyPair: this._keyPair || undefined,
// `{ key }` shape per autobase index.js:210-214. Omitted entirely when unset — passing
// `fastForward: false` would DISABLE fast-forward (index.js:125
// `fastForwardEnabled = handlers.fastForward !== false`), which is the opposite of what we
// want for a peer with no target.
fastForward: this._fastForwardTo
? { key: typeof this._fastForwardTo === 'string'
? b4a.from(this._fastForwardTo, 'hex')
: this._fastForwardTo }
: undefined,
optimistic: true,
ackInterval: 1000,
ackThreshold: 4
})
}
}
export default IdentityRegistry