Skip to content

Instantly share code, notes, and snippets.

@davidpeach
Created February 16, 2021 15:23
Show Gist options
  • Save davidpeach/09e83ad8cf7c0697763d9a791eea2df5 to your computer and use it in GitHub Desktop.
Save davidpeach/09e83ad8cf7c0697763d9a791eea2df5 to your computer and use it in GitHub Desktop.
# When hitting the websocket endpoint, the key generated seems to often get messed up.
# Sometimes like this:
883a ff42 4864 0162 8659 a29b 3900 73e4
3fff 9634 11dd 4285 fefc 3d4a ff63 6fd5
# More often like this:
³B1¿Ç?Àam¢å¡öY9ì©zŒ uö1ve‹…µ
const ed = require('noble-ed25519')
const WebSocket = require('ws')
const fs = require('fs')
const wss = new WebSocket.Server({ port: 7777 })
wss.on('connection', ws => {
ws.on('message', message => {
if (message === 'GENERATE_KEYS') {
let privateKey = ed.utils.randomPrivateKey() // 32-byte Uint8Array or string.
// console.log(privateKey)
fs.writeFileSync(__dirname + '/keys/private-key', privateKey)
console.log('KEY GENERATION DONE')
//const msgHash = 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef';
;(async () => {
let publicKey = await ed.getPublicKey(privateKey)
fs.writeFileSync(__dirname + '/keys/public-key', publicKey)
// const signature = await ed.sign(this.messageToSend, privateKey)
// const isSigned = await ed.verify(signature, this.messageToSend, publicKey)
// console.log(publicKey, signature, isSigned, api.getPrivateKey())
})();
}
})
ws.send('ho!')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment