-
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.
Add documentation and Github Actions (#4)
- Loading branch information
1 parent
cdd9ed4
commit f295955
Showing
11 changed files
with
512 additions
and
222 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,49 @@ | ||
name: Pull Request Checks | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
build: | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, macos-latest, windows-latest] | ||
node-version: [16.x, 18.x, 20.x] | ||
|
||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Use Node.js ${{ matrix.node-version }} ${{ matrix.os }} | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
|
||
- name: Install dependencies | ||
run: npm ci | ||
|
||
- name: Run tests | ||
run: npm test | ||
|
||
- name: Run build | ||
run: npm run build | ||
|
||
- name: Coveralls Parallel | ||
uses: coverallsapp/github-action@v2 | ||
with: | ||
flag-name: run-${{ join(matrix.*, '-') }} | ||
parallel: true | ||
|
||
finish: | ||
needs: build | ||
if: ${{ always() }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Coveralls Finished | ||
uses: coverallsapp/github-action@v2 | ||
with: | ||
parallel-finished: true | ||
carryforward: "run-1,run-2" |
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,30 @@ | ||
name: Release new package version | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*' | ||
|
||
jobs: | ||
publish-npm: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Use Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 16.x | ||
registry-url: 'https://registry.npmjs.org' | ||
|
||
- name: Install dependencies | ||
run: npm ci | ||
|
||
- name: Build | ||
run: npm run build | ||
|
||
- name: Publish | ||
run: npm publish | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
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 |
---|---|---|
@@ -1,2 +1,164 @@ | ||
# @blocksoft/cryptomate | ||
NodeJS crypto module wrapper for easier use | ||
|
||
Ergonomic, zero-dependency crypto module wrapper for ECDSA and EdDSA signatures. | ||
|
||
[![Pull Request Checks](https://github.com/PlamenHristov/cryptomate/actions/workflows/pr.yml/badge.svg?branch=main&event=release)](https://github.com/PlamenHristov/cryptomate/actions/workflows/pr.yml) | ||
[![Coverage Status](https://coveralls.io/repos/github/PlamenHristov/cryptomate/badge.svg?branch=main)](https://coveralls.io/github/PlamenHristov/cryptomate?branch=main) | ||
[![Known Vulnerabilities](https://snyk.io/test/github/PlamenHristov/cryptomate/badge.svg?targetFile=package.json)](https://snyk.io/test/github/PlamenHristov/cryptomate?targetFile=package.json) | ||
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) | ||
|
||
Key features of the module include: | ||
|
||
- Generation of ECDSA and EdDSA key pairs. | ||
- Conversion between PEM (Privacy-Enhanced Mail) and DER (Distinguished Encoding Rules) formats. | ||
- Extraction of public key from a given private key. | ||
- Message signing and verification using ECDSA and EdDSA algorithms. | ||
|
||
## Installation | ||
|
||
To install `@blocksoft/cryptomate`, use the following npm command: | ||
|
||
```bash | ||
npm i --save @blocksoft/cryptomate | ||
``` | ||
|
||
## Quick Start | ||
|
||
Here is an example demonstrating the use of the ECDSA functionality provided by this module: | ||
|
||
```javascript | ||
const {ECDSA, EC_CURVE, Key, SignatureEncoding} = require('@blocksoft/cryptomate'); | ||
|
||
// Generate an ECDSA key pair. | ||
const ecdsa = ECDSA.withCurve(EC_CURVE.secp256k1).genKeyPair(); | ||
|
||
// Sign a message. | ||
let message = "Hello, World!"; | ||
let signature = ecdsa.sign(message, SignatureEncoding.HEX); | ||
|
||
// Verify the signature. | ||
console.log(ecdsa.verify(message, signature)); // Outputs: true | ||
|
||
// Export keys in PEM format. | ||
let privateKeyPEM = ecdsa.toPEM(Key.privateKey); | ||
let publicKeyPEM = ecdsa.toPEM(Key.publicKey); | ||
|
||
// Import keys from PEM format. | ||
let importedECDSA = ECDSA.withCurve(EC_CURVE.secp256k1).fromPEM(privateKeyPEM, Key.privateKey); | ||
|
||
``` | ||
|
||
## API Reference | ||
|
||
### ECDSA | ||
|
||
#### ECDSA.withCurve(curve) | ||
|
||
A factory method to construct an ECDSA object with a given elliptic curve. | ||
|
||
##### Parameters | ||
|
||
- `curve` - The elliptic curve to use. This can be one of the following values: | ||
- `EC_CURVE.P_256` - NIST P-256 curve. | ||
- `EC_CURVE.P_384` - NIST P-384 curve. | ||
- `EC_CURVE.P_521` - NIST P-521 curve. | ||
- `EC_CURVE.SECP256K1` - SECP256K1 curve. | ||
- `EC_CURVE.SECP256R1` - SECP256R1 curve. | ||
- `EC_CURVE.SECP384R1` - SECP384R1 curve. | ||
- `EC_CURVE.SECP521R1` - SECP521R1 curve. | ||
- ... | ||
|
||
##### Returns | ||
|
||
An ECDSA object with the given elliptic curve. | ||
|
||
#### ECDSA.genKeyPair() | ||
|
||
Generates a new ECDSA key pair. | ||
|
||
##### Returns | ||
|
||
An ECDSA object with a newly generated key pair. | ||
|
||
#### ECDSA.fromPEM(pem, keyType) | ||
|
||
Constructs an ECDSA object from a given PEM string. | ||
|
||
##### Parameters | ||
|
||
- `pem` - The PEM string to construct the ECDSA object from. | ||
- `keyType` - The type of key to construct. This can be one of the following values: | ||
- `Key.privateKey` - Private key. | ||
- `Key.publicKey` - Public key. | ||
|
||
##### Returns | ||
|
||
An ECDSA object with the given PEM string. | ||
|
||
#### ECDSA.toPEM(keyType) | ||
|
||
Converts the ECDSA object to a PEM string. | ||
|
||
##### Parameters | ||
|
||
- `keyType` - The type of key to convert. This can be one of the following values: | ||
- `Key.privateKey` - Private key. | ||
- `Key.publicKey` - Public key. | ||
|
||
##### Returns | ||
|
||
A PEM string representing the ECDSA object. | ||
|
||
#### ECDSA.getPublicKey() | ||
|
||
Extracts the public key from the ECDSA object. | ||
|
||
##### Returns | ||
|
||
A Buffer object containing the public key. | ||
|
||
#### ECDSA.sign(message, encoding) | ||
|
||
Signs a message using the ECDSA object. | ||
|
||
##### Parameters | ||
|
||
- `message` - The message to sign. | ||
- `encoding` - The encoding of the message. This can be one of the following values: | ||
- `SignatureEncoding.HEX` - The message is encoded in hexadecimal format. | ||
- `SignatureEncoding.BASE64` - The message is encoded in Base64 format. | ||
- `SignatureEncoding.UTF8` - The message is encoded in UTF-8 format. | ||
- ... | ||
|
||
##### Returns | ||
|
||
A Buffer object containing the signature. | ||
|
||
#### ECDSA.verify(message, signature, encoding) | ||
|
||
Verifies a signature using the ECDSA object. | ||
|
||
##### Parameters | ||
|
||
- `message` - The message to verify. | ||
- `signature` - The signature to verify. | ||
- `encoding` - The encoding of the message. This can be one of the following values: | ||
- `SignatureEncoding.HEX` - The message is encoded in hexadecimal format. | ||
- `SignatureEncoding.BASE64` - The message is encoded in Base64 format. | ||
- `SignatureEncoding.UTF8` - The message is encoded in UTF-8 format. | ||
- ... | ||
|
||
##### Returns | ||
|
||
A boolean value indicating whether the signature is valid. | ||
|
||
### EdDSA | ||
|
||
Please note that the EdDSA class shares similar method names and functionalities to the ECDSA class for key pair | ||
generation, | ||
signing and verifying messages, and importing/exporting keys in various formats. | ||
Refer to the ECDSA API documentation provided above for further details. | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. |
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
Oops, something went wrong.