doc: example generating keypairs with WebCrypto & node:crypto
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
- Issue type
- Documentation
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- javascript, node.js
- Domain
- cryptography, documentation
Research direction
Start from the JavaScript example in the issue, especially generateKeyPair, generateSecp256k1KeyPair, and main, and compare its WebCrypto and node:crypto usage. Confirm the documented algorithm names and expected generated files, including the open question about secp256k1 support in WebCrypto; done means the example clearly covers the intended keypair generation.
Written by the indexing model from the issue text.
Description
'use strict';
let Fs = require('node:fs/promises');
async function generateKeyPair(algo) {
let keyPair = await crypto.subtle.generateKey(algo, true, ['sign', 'verify']);
let name = algo.namedCurve || algo.name;
let privateKeyAb = await crypto.subtle.exportKey('pkcs8', keyPair.privateKey);
let privateKeyDER = new Uint8Array(privateKeyAb);
let privateKeyPath = `./key.${name}.der`.toLowerCase();
await Fs.writeFile(privateKeyPath, privateKeyDER);
let publicKeyAb = await crypto.subtle.exportKey('spki', keyPair.publicKey);
let publicKeyDER = new Uint8Array(publicKeyAb);
let publicKeyPath = `./pub.${name}.der`.toLowerCase();
await Fs.writeFile(publicKeyPath, publicKeyDER);
console.info(`Key pair generated and saved as ${privateKeyPath} and ${publicKeyPath}`);
}
let Crypto = require('node:crypto');
async function generateSecp256k1KeyPair() {
return new Promise(function (resolve, reject) {
Crypto.generateKeyPair(
'ec',
{
namedCurve: 'secp256k1',
publicKeyEncoding: {
type: 'spki',
format: 'der',
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'der',
},
},
async function (err, publicKey, privateKey) {
if (err) {
return reject(err);
}
await Fs.writeFile('./key.secp256k1.der', privateKey);
await Fs.writeFile('./pub.secp256k1.der', publicKey);
console.info(
'secp256k1 key pair generated and saved as ./key.secp256k1.der and ./pub.secp256k1.der',
);
},
);
});
}
async function main() {
await generateKeyPair({ name: 'Ed25519' });
await generateKeyPair({ name: 'ECDSA', namedCurve: 'P-256' });
// this should be possible with WebCrypto as well, but I don't know the name to use
//await generateKeyPair({ name: 'ECDSA', namedCurve: 'secp256k1' });
// it does work with node:crypto
await generateSecp256k1KeyPair();
}
main().catch(function (err) {
console.error(err.stack);
process.exit(1);
});
- Dominant language
- JavaScript
- Stars
- 2
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from BeyondCodeBootcamp/passkeys
-
Difficulty 2/5 1-3 hours Newbie friendliness 25/100
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
-
Difficulty 4/5 3-5 days Newbie friendliness 28/100
BeyondCodeBootcamp/passkeys#6 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
All issues in BeyondCodeBootcamp/passkeys
Similar issues
-
bug confirmed issue
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
open-webui/open-webui#30750 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Mend: dependency security vulnerability untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 70/100