// Test helper: a getRecordStore(did) backed by per-DID OverlayRepoStores under a temp dir — the same
// content-addressed record byte store the appview now uses (bytes live once here, index holds pointers).
// roomKey16 derivation is IDENTICAL to hpp/device-node + bin/favela-web (hash('atproto-base/v1/room-key' ‖ did)).
import { OverlayRepoStore } from 'atproto-store/lib/overlay-repo-store.js'
import crypto from 'hypercore-crypto'
import b4a from 'b4a'
import { join } from 'bare-path'
const NS_ROOMKEY = b4a.from('atproto-base/v1/room-key')
const roomKey16 = (did) => b4a.toString(crypto.hash([NS_ROOMKEY, b4a.from(did)]), 'hex').slice(0, 16)
export function mkGetRecordStore (baseDir) {
const stores = new Map()
return async (did) => {
if (!stores.has(did)) stores.set(did, await new OverlayRepoStore(join(baseDir, roomKey16(did)), { did }).ready())
return stores.get(did)
}
}