#!/usr/bin/env bare
await import('bare-node-runtime/global')
import Corestore from 'corestore'
import Hyperbee from 'hyperbee'
const publicKey = 'UDsArSJ8AAAAI7WNMFsAABAjtY0wWwAAAQAAAAAAAAA='
console.log(`Checking identity for public key: ${publicKey}`)
const storage = './pear-git-storage'
const store = new Corestore(storage)
const registryCore = store.get({ name: 'registry' })
const registry = new Hyperbee(registryCore, {
keyEncoding: 'utf-8',
valueEncoding: 'json'
})
await registry.ready()
// Check pubkey index
const pubkeyEntry = await registry.get(`pubkey:${publicKey}`)
console.log('\npubkey index entry:', pubkeyEntry ? pubkeyEntry.value : 'NOT FOUND')
// Check if identity exists
if (pubkeyEntry) {
const identityEntry = await registry.get(`identity:${pubkeyEntry.value.identityId}`)
console.log('\nidentity entry:', identityEntry ? identityEntry.value : 'NOT FOUND')
}
// List all identities
console.log('\nAll identities in database:')
for await (const entry of registry.createReadStream({ gt: 'identity:', lt: 'identity:\xff' })) {
console.log(' ', entry.key, '->', entry.value.identityId.substring(0, 20) + '...')
}
// List all pubkey indexes
console.log('\nAll pubkey indexes in database:')
for await (const entry of registry.createReadStream({ gt: 'pubkey:', lt: 'pubkey:\xff' })) {
console.log(' ', entry.key)
}
process.exit(0)