OverviewFilesCommitsIssuesDocsReleasesPeers

hyper-identity commits / 62fd652

Expose writable getter + onWritable subscription on IdentityRegistry
Mirrors need a way to know 'we can now append' and react exactly when identity autobase flips writable after replication of the ADD_WRITER pre-auth. Autobase already emits 'writable' — just surface it. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
62fd652d9416fe73f939747a4faca1ce44218c32
by plankatron <noreply@anthropic.com> · 2026-04-20T22:06:52.000Z

Changed files (1) +22 -0

lib/auth/identity-registry.js +22 -0
……@@ -915,6 +915,28 @@ export class IdentityRegistry {
915915 * @param {string} devicePubkey — this device's hyperident pubkey (hex)
916916 * @param {Object<string,string>} keys — { namespace: localKeyHex, ... }
917917 */
918 /**
919 * True if this peer is a writer on the identity autobase (can append).
920 * Mirrors this check straight off the underlying autobase.
921 */
922 get writable () {
923 return this._base ? this._base.writable : false
924 }
925
926 /**
927 * Subscribe to writable transitions. Callback fires when this peer
928 * becomes (or was already) a writer on the identity autobase — useful
929 * for apps that want to act the moment they can append.
930 * Returns an unsubscribe function.
931 */
932 onWritable (cb) {
933 if (!this._base) return () => {}
934 if (this._base.writable) { queueMicrotask(() => { try { cb() } catch {} }) }
935 const handler = () => { try { cb() } catch {} }
936 this._base.on('writable', handler)
937 return () => this._base.off('writable', handler)
938 }
939
918940 async registerMirrorWriters (devicePubkey, keys) {
919941 if (!devicePubkey || typeof devicePubkey !== 'string' || devicePubkey.length !== 64) {
920942 throw new Error('registerMirrorWriters requires 64-char hex devicePubkey')