/**
* Test relay push with fixed ANProto signature
*/
import { WebSocket } from 'ws'
import { ANProto } from './lib/anproto.js'
import { YAMLHelper } from './lib/yaml-helper.js'
// Your pubkey (get from: pear run . cli whoami)
const PUBKEY = 'OEMqT42p1NhSH5cyOejXRIbQwT3TciFe5kMZ6gqBJIE='
// Your keypair (132 chars) - get from Hyperbee metadata
const KEYPAIR_STRING = 'OEMqT42p1NhSH5cyOejXRIbQwT3TciFe5kMZ6gqBJIE=5w5eLkSf2+vfZWjj3t4a+r8NhBq+yx9bHwZQtvElD10wQypPjanU2FIflzI56NdEhtDBPdNyIV7mQxnqCoEkgQ=='
async function testPush() {
console.log('🧪 Testing relay push with fixed signature...\n')
// Load keypair
const keypair = ANProto.loadKeypair(KEYPAIR_STRING)
console.log('✓ Loaded keypair')
console.log(' Pubkey:', PUBKEY)
// Create test message
const metadata = {
name: 'TestUser',
image: null,
previous: null
}
const messageText = 'TEST RELAY PUSH - Signature Fix Test - ' + Date.now()
const yaml = YAMLHelper.create(metadata, messageText)
console.log('\n✓ Created YAML message:')
console.log(yaml.substring(0, 100) + '...')
// Hash and sign
const contentHash = ANProto.hash(yaml)
console.log('\n✓ Content hash:', contentHash.substring(0, 32) + '...')
const signature = ANProto.sign(contentHash, keypair)
console.log('✓ Signature length:', signature.length, 'chars')
console.log(' Signature:', signature.substring(0, 50) + '...')
// Connect to relay
console.log('\n📤 Connecting to wss://7rnx.net/relay/')
const ws = new WebSocket('wss://7rnx.net/relay/')
return new Promise((resolve, reject) => {
const timeout = setTimeout(() => {
ws.close()
reject(new Error('Connection timeout (10s)'))
}, 10000)
ws.on('open', () => {
clearTimeout(timeout)
console.log('✓ Connected!')
try {
// Send in order: pubkey, content, signature
ws.send(PUBKEY)
console.log(' → Sent pubkey')
ws.send(yaml)
console.log(' → Sent YAML content')
ws.send(signature)
console.log(' → Sent signature')
// Wait for relay to process
setTimeout(() => {
ws.close()
console.log('\n✅ Push complete!')
console.log('\nCheck relay: curl https://7rnx.net/relay/all | jq length')
resolve()
}, 2000)
} catch (err) {
clearTimeout(timeout)
ws.close()
reject(err)
}
})
ws.on('error', (err) => {
clearTimeout(timeout)
console.error('❌ WebSocket error:', err.message)
reject(err)
})
ws.on('message', (data) => {
console.log(' ← Received:', data.toString().substring(0, 50))
})
})
}
testPush().then(() => {
console.log('\n✅ Test successful!')
process.exit(0)
}).catch(err => {
console.error('\n❌ Test failed:', err.message)
process.exit(1)
})