Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/verify signatures #46

Merged
merged 4 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ __debug_*
.DS_Store
*secret*
*.pem
*Key.txt
1 change: 1 addition & 0 deletions adapters/node/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
42 changes: 21 additions & 21 deletions adapters/node/generate-keys.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
const crypto = require('crypto');
const path = require('path');
const fs = require('fs');
const path = require('path');

// Generate a random private key
let privKey;
do {
privKey = crypto.randomBytes(32);
} while (crypto.createECDH('secp256k1').setPrivateKey(privKey, 'hex').getPublicKey() === null);

// Get the ECDH object and set the private key
const ecdh = crypto.createECDH('secp256k1');
ecdh.setPrivateKey(privKey);

// Generate a secp256k1 key pair
const keyPair = crypto.generateKeyPairSync('ec', {
namedCurve: 'secp256k1' // Name of the curve
});
// Get the public key in uncompressed format
const pubKey = ecdh.getPublicKey('hex', 'uncompressed');

// Export the private key as a PEM-formatted string
const privateKey = keyPair.privateKey.export({
type: 'sec1',
format: 'pem',
});
const privateKeyPath = path.join(__dirname, 'privateKey.txt');
const publicKeyPath = path.join(__dirname, 'publicKey.txt');

// Export the public key as a PEM-formatted string
const publicKey = keyPair.publicKey.export({
type: 'spki',
format: 'pem',
});
// Write private key to disk
fs.writeFileSync(privateKeyPath, privKey.toString('hex'));

// Specify the paths where the keys will be saved
const privateKeyPath = path.resolve(__dirname, 'privateKey.pem')
const publicKeyPath = path.resolve(__dirname, 'publicKey.pem')
// Write public key to disk
fs.writeFileSync(publicKeyPath, pubKey);

// Write the keys to disk
fs.writeFileSync(privateKeyPath, privateKey);
fs.writeFileSync(publicKeyPath, publicKey);
console.log(`Private key saved to ${privateKeyPath}`);
console.log(`Public key saved to ${publicKeyPath}`);
338 changes: 338 additions & 0 deletions adapters/node/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading