57 lines
1.6 KiB
JavaScript
57 lines
1.6 KiB
JavaScript
#!/usr/bin/env bare
|
|
/**
|
|
* Run under Bare: `bare scripts/holesail-seed-determinism.mjs`
|
|
*
|
|
* Proves upstream holesail: same 64-hex ctor `key` ⇒ same `hs.info.url`; ctor `key`
|
|
* must NOT be swapped from hex to z32 suffix without changing the tunnel.
|
|
*/
|
|
import HolesailMod from 'holesail'
|
|
import { randomBytes } from 'bare-crypto'
|
|
|
|
const Ho = HolesailMod.default || HolesailMod
|
|
|
|
const port = 18080 + Math.floor(Math.random() * 2000)
|
|
const host = '127.0.0.1'
|
|
|
|
async function urlForCtorKey(k) {
|
|
const hs = new Ho({
|
|
server: true,
|
|
client: false,
|
|
port,
|
|
host,
|
|
key: k,
|
|
log: false
|
|
})
|
|
await hs.ready()
|
|
const u =
|
|
hs.info && typeof hs.info === 'object' && 'url' in hs.info
|
|
? String(/** @type {{ url?: string }} */ (hs.info).url || '')
|
|
: ''
|
|
await hs.close()
|
|
return u
|
|
}
|
|
|
|
const hex = randomBytes(32).toString('hex')
|
|
const uHex1 = await urlForCtorKey(hex)
|
|
const uHex2 = await urlForCtorKey(hex)
|
|
|
|
const sfx = uHex1.startsWith('hs://') ? uHex1.slice(9) : ''
|
|
const uZ32 = sfx ? await urlForCtorKey(sfx) : ''
|
|
|
|
console.log('[holesail-determinism] same hex twice:', uHex1 === uHex2, uHex1)
|
|
console.log('[holesail-determinism] hex vs z32 ctor same url:', uHex1 === uZ32, {
|
|
hexUrl: uHex1,
|
|
z32Url: uZ32
|
|
})
|
|
|
|
if (!(uHex1 === uHex2)) {
|
|
console.error('FAIL: hex ctor not deterministic')
|
|
process.exitCode = 1
|
|
} else if (uHex1 === uZ32) {
|
|
console.log('NOTE: hex and z32 ctor matched (unexpected for holesail SHA256 inputs)')
|
|
} else {
|
|
console.log(
|
|
'OK: hex seed and z32 suffix are different ctor inputs — persist 64-hex seed; do not overwrite with z32.'
|
|
)
|
|
}
|