Created
February 16, 2021 15:23
-
-
Save davidpeach/09e83ad8cf7c0697763d9a791eea2df5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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‹…µ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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