- Add dev.sh script for managing regtest development environment - Implement cmd_fund to fund ATM app owner via Lightning.Pub API - Add --fund flag to cmd_up for automatic funding on startup - Update setup_atm_app to write VITE_APP_ID to machine .env - Fix Electron IPC to pass appId and extensionApiUrl to renderer - Restructure repo from nested lamassu-next/ to root The dev.sh script now supports: - ./dev.sh up --fund # Start regtest and auto-fund ATM - ./dev.sh fund # Fund existing ATM app - ./dev.sh status # Show environment status - ./dev.sh reset # Clean restart Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
117 lines
3.1 KiB
TypeScript
117 lines
3.1 KiB
TypeScript
#!/usr/bin/env npx tsx
|
|
/**
|
|
* CLINK Integration Test
|
|
*
|
|
* Tests the CLINK protocol against a local Lightning.Pub instance.
|
|
*
|
|
* Usage: npx tsx scripts/test-clink.ts
|
|
*/
|
|
|
|
import { generateSecretKey, getPublicKey, finalizeEvent, nip44 } from 'nostr-tools'
|
|
import { hexToBytes } from '@noble/hashes/utils'
|
|
|
|
// Lightning.Pub service info (from docker logs)
|
|
const LIGHTNING_PUB_PUBKEY = '0943fe710a0f48c77a0bdd11bd186d320cd1b01615cf9ec36fa2dc45bd86e92f'
|
|
const RELAY_URL = 'ws://localhost:7777'
|
|
|
|
// CLINK Event Kinds
|
|
const KIND_OFFER = 21001
|
|
const KIND_DEBIT = 21002
|
|
|
|
async function main() {
|
|
console.log('CLINK Integration Test')
|
|
console.log('======================\n')
|
|
|
|
// Generate a test keypair
|
|
const sk = generateSecretKey()
|
|
const pk = getPublicKey(sk)
|
|
console.log('Test client pubkey:', pk)
|
|
console.log('Lightning.Pub pubkey:', LIGHTNING_PUB_PUBKEY)
|
|
console.log('Relay:', RELAY_URL)
|
|
console.log('')
|
|
|
|
// Connect to relay
|
|
const WebSocket = (await import('ws')).default
|
|
const ws = new WebSocket(RELAY_URL)
|
|
|
|
await new Promise<void>((resolve, reject) => {
|
|
ws.on('open', () => {
|
|
console.log('Connected to relay\n')
|
|
resolve()
|
|
})
|
|
ws.on('error', reject)
|
|
})
|
|
|
|
// Subscribe to responses from Lightning.Pub
|
|
const subId = 'clink-test'
|
|
ws.send(
|
|
JSON.stringify([
|
|
'REQ',
|
|
subId,
|
|
{
|
|
kinds: [KIND_OFFER, KIND_DEBIT],
|
|
'#p': [pk],
|
|
since: Math.floor(Date.now() / 1000) - 10,
|
|
},
|
|
])
|
|
)
|
|
|
|
// Handle incoming messages
|
|
ws.on('message', (data) => {
|
|
const msg = JSON.parse(data.toString())
|
|
if (msg[0] === 'EVENT') {
|
|
const event = msg[2]
|
|
console.log('Received event kind:', event.kind)
|
|
|
|
// Decrypt the content
|
|
try {
|
|
const decrypted = nip44.decrypt(sk, event.pubkey, event.content)
|
|
console.log('Decrypted response:', JSON.parse(decrypted))
|
|
} catch (e) {
|
|
console.log('Raw content:', event.content)
|
|
}
|
|
} else if (msg[0] === 'EOSE') {
|
|
console.log('End of stored events\n')
|
|
} else if (msg[0] === 'OK') {
|
|
console.log('Event published:', msg[1], msg[2] ? 'success' : 'failed', msg[3] || '')
|
|
}
|
|
})
|
|
|
|
// Create a CLINK Offer request (kind 21001)
|
|
// This requests an invoice from Lightning.Pub
|
|
console.log('Sending CLINK Offer request (kind 21001)...')
|
|
|
|
const offerRequest = {
|
|
offer: 'lno1...', // Would be a real BOLT12 offer in production
|
|
amount_sats: 100,
|
|
payer_data: {
|
|
name: 'Test ATM',
|
|
},
|
|
}
|
|
|
|
// Encrypt the request content
|
|
const encryptedContent = nip44.encrypt(sk, LIGHTNING_PUB_PUBKEY, JSON.stringify(offerRequest))
|
|
|
|
const event = finalizeEvent(
|
|
{
|
|
kind: KIND_OFFER,
|
|
created_at: Math.floor(Date.now() / 1000),
|
|
tags: [['p', LIGHTNING_PUB_PUBKEY]],
|
|
content: encryptedContent,
|
|
},
|
|
sk
|
|
)
|
|
|
|
ws.send(JSON.stringify(['EVENT', event]))
|
|
console.log('Event ID:', event.id)
|
|
console.log('')
|
|
|
|
// Wait for response
|
|
console.log('Waiting for response (5s)...')
|
|
await new Promise((resolve) => setTimeout(resolve, 5000))
|
|
|
|
ws.close()
|
|
console.log('\nTest complete')
|
|
}
|
|
|
|
main().catch(console.error)
|