// Probe the peer's membrane get-blob (rpc/v1) directly (no bridge): connect to a device control key,
// request get-blob for a CID, report size/mime. Validates the SERVE path before deploying the bridge.
// bare scripts/getblob-probe.mjs <cid> [origin|device]
import '../lib/bare-globals.js'
import Hyperswarm from 'hyperswarm'
import crypto from 'hypercore-crypto'
import b4a from 'b4a'
import c from 'compact-encoding'
import ProtomuxRPC from 'protomux-rpc'
const CONTROL = {
origin: '8ae330710aaef922dce79a907f6ff8f57e459de61d4d45f1551d5e0ff23a11d7',
device: 'e0cac0d06e67da9c79674a5ca195809300b04635d1a46254f4fd21edd1ce491d'
}
const cid = globalThis.Bare.argv[2]
const ck = CONTROL[(globalThis.Bare.argv[3] || 'origin').toLowerCase()]
if (!cid) { console.log('usage: bare scripts/getblob-probe.mjs <cid> [origin|device]'); globalThis.Bare.exit(1) }
const swarm = new Hyperswarm({ keyPair: crypto.keyPair(crypto.hash(b4a.from('getblob-probe-' + cid))) })
const done = new Promise((res, rej) => {
const to = setTimeout(() => rej(new Error('timeout')), 20000)
swarm.on('connection', async conn => {
if (b4a.toString(conn.remotePublicKey, 'hex') !== ck) return
try {
const rpc = new ProtomuxRPC(conn, { protocol: 'hyper-proto-peer/rpc/v1', valueEncoding: c.json })
const got = await rpc.request('get-blob', { cid })
clearTimeout(to); res(got)
} catch (e) { clearTimeout(to); rej(e) }
})
})
swarm.join(b4a.from(ck, 'hex'), { client: true, server: true }); await swarm.flush()
try {
const g = await done
if (g && g.bytes) console.log('GET-BLOB OK size=' + b4a.byteLength(g.bytes, 'hex') + ' mime=' + g.mimeType + ' declaredSize=' + g.size)
else console.log('GET-BLOB null (blob not found on peer)')
} catch (e) { console.log('FAIL ' + e.message) }
await swarm.destroy(); globalThis.Bare.exit(0)