forked from ONDC-Official/developer-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: signing keys generation using node-js
- Loading branch information
1 parent
744b663
commit f45f51d
Showing
11 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const nacl = require("tweetnacl"); | ||
const { randomBytes } = require("crypto"); | ||
|
||
function generateKeyPairs() { | ||
// Generate signing key pair | ||
const signingKeyPair = nacl.sign.keyPair(); | ||
|
||
// Generate X25519 key pair for encryption | ||
const encryptionKeyPair = nacl.box.keyPair.fromSecretKey( | ||
randomBytes(nacl.box.secretKeyLength) | ||
); | ||
|
||
return { | ||
Signing_private_key: Buffer.from(signingKeyPair.secretKey).toString( | ||
"base64" | ||
), | ||
Signing_public_key: Buffer.from(signingKeyPair.publicKey).toString( | ||
"base64" | ||
), | ||
Encryption_Privatekey: Buffer.from(encryptionKeyPair.secretKey).toString( | ||
"base64" | ||
), | ||
Encryption_Publickey: Buffer.from(encryptionKeyPair.publicKey).toString( | ||
"base64" | ||
), | ||
}; | ||
} | ||
|
||
// Example usage: | ||
const keyPairs = generateKeyPairs(); | ||
console.log(keyPairs); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "generate-key-pairs", | ||
"version": "1.0.0", | ||
"description": "This Node.js script generates key pairs for signing and encryption using the `tweetnacl` and `crypto` library.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"crypto": "^1.0.1", | ||
"tweetnacl": "^1.0.3" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Signing Key pair generation using Node.js | ||
|
||
This Node.js script generates key pairs for signing and encryption using the `tweetnacl` and `crypto` library. | ||
|
||
## Prerequisites | ||
|
||
Make sure you have Node.js installed on your system. If not, you can download it from [Node.js website](https://nodejs.org/). | ||
|
||
## Installation | ||
|
||
```bash | ||
npm i | ||
``` | ||
|
||
## Usage | ||
|
||
- Clone the repository or copy the script into your project. | ||
- Run the script using the following command: | ||
|
||
```bash | ||
node index.js | ||
``` | ||
|
||
## Output | ||
|
||
The script will output key pairs in base64-encoded format for signing and encryption. | ||
|
||
```bash | ||
{ | ||
"Signing_private_key": "BASE64_ENCODED_PRIVATE_KEY", | ||
"Signing_public_key": "BASE64_ENCODED_PUBLIC_KEY", | ||
"Encryption_Privatekey": "BASE64_ENCODED_PRIVATE_KEY", | ||
"Encryption_Publickey": "BASE64_ENCODED_PUBLIC_KEY" | ||
} | ||
|
||
``` | ||
|
||
## Example | ||
|
||
```javascript | ||
const keyPairs = generateKeyPairs(); | ||
console.log(keyPairs); | ||
``` | ||
|
||
Feel free to integrate this script into your project or use it as a reference for key pair generation in Node.js. | ||
|
||
```vbnet | ||
Copy and paste this markdown content into a `readme.md` file in your project repository. Modify it as needed based on your project structure and additional information you want to provide. | ||
|
||
``` |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.