puter/tools/keygen/gen-peer-keys.js
2024-08-08 15:13:32 -04:00

20 lines
443 B
JavaScript

const nacl = require('tweetnacl');
const pair = nacl.box.keyPair();
const format_key = key => {
const version = new Uint8Array([0x31]);
const buffer = Buffer.concat([
Buffer.from(version),
Buffer.from(key),
]);
return buffer.toString('base64');
};
console.log(JSON.stringify({
keys: {
public: format_key(pair.publicKey),
secret: format_key(pair.secretKey),
},
}, undefined, ' '));