// lib/membership.js — the hot-path gate (SPEC §2, §4-enroll).
//
// After the one-time enrollment ceremony writes a `grant` into the durable
// plane, every connection check is just "is this peer's key in member/*" —
// a local Hyperbee read (~µs, zero network). Enrollment is expensive and rare;
// this check is cheap and per-connection.
const b4a = require('b4a')
async function isMember (base, publicKey) {
const hex = b4a.isBuffer(publicKey) ? b4a.toString(publicKey, 'hex') : publicKey
const node = await base.view.get('member/' + hex)
return !!node
}
async function memberRole (base, publicKey) {
const hex = b4a.isBuffer(publicKey) ? b4a.toString(publicKey, 'hex') : publicKey
const node = await base.view.get('member/' + hex)
return node ? node.value.role : null
}
module.exports = { isMember, memberRole }