mirror of
https://github.com/therootcompany/keypairs.js.git
synced 2024-11-16 17:29:03 +00:00
Compare commits
No commits in common. "main" and "v0.9.1" have entirely different histories.
@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"esversion": 11,
|
|
||||||
"node": true,
|
|
||||||
"unused": true,
|
|
||||||
"curly": true
|
|
||||||
}
|
|
||||||
82
README.md
82
README.md
@ -1,4 +1,4 @@
|
|||||||
# [@root/keypairs](https://git.rootprojects.org/root/keypairs.js)
|
# @root/keypairs
|
||||||
|
|
||||||
Lightweight JavaScript RSA and ECDSA utils that work on Windows, Mac, and Linux
|
Lightweight JavaScript RSA and ECDSA utils that work on Windows, Mac, and Linux
|
||||||
using modern node.js APIs (no need for C compiler).
|
using modern node.js APIs (no need for C compiler).
|
||||||
@ -20,8 +20,6 @@ and [Rasha.js (RSA)](https://git.coolaj86.com/coolaj86/rasha.js/).
|
|||||||
- [ ] Auth0
|
- [ ] Auth0
|
||||||
- [ ] CLI
|
- [ ] CLI
|
||||||
- See [keypairs-cli](https://npmjs.com/packages/keypairs-cli/)
|
- See [keypairs-cli](https://npmjs.com/packages/keypairs-cli/)
|
||||||
- [x] Node
|
|
||||||
- [x] Browsers (Webpack >=5)
|
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
|
|
||||||
@ -42,7 +40,7 @@ A brief introduction to the APIs:
|
|||||||
```js
|
```js
|
||||||
// generate a new keypair as jwk
|
// generate a new keypair as jwk
|
||||||
// (defaults to EC P-256 when no options are specified)
|
// (defaults to EC P-256 when no options are specified)
|
||||||
Keypairs.generate().then(function (pair) {
|
Keypairs.generate().then(function(pair) {
|
||||||
console.log(pair.private);
|
console.log(pair.private);
|
||||||
console.log(pair.public);
|
console.log(pair.public);
|
||||||
});
|
});
|
||||||
@ -51,7 +49,7 @@ Keypairs.generate().then(function (pair) {
|
|||||||
```js
|
```js
|
||||||
// JWK to PEM
|
// JWK to PEM
|
||||||
// (supports various 'format' and 'encoding' options)
|
// (supports various 'format' and 'encoding' options)
|
||||||
return Keypairs.export({ jwk: pair.private, format: 'pkcs8' }).then(function (
|
return Keypairs.export({ jwk: pair.private, format: 'pkcs8' }).then(function(
|
||||||
pem
|
pem
|
||||||
) {
|
) {
|
||||||
console.log(pem);
|
console.log(pem);
|
||||||
@ -60,14 +58,14 @@ return Keypairs.export({ jwk: pair.private, format: 'pkcs8' }).then(function (
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
// PEM to JWK
|
// PEM to JWK
|
||||||
return Keypairs.import({ pem: pem }).then(function (jwk) {
|
return Keypairs.import({ pem: pem }).then(function(jwk) {
|
||||||
console.log(jwk);
|
console.log(jwk);
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// Thumbprint a JWK (SHA256)
|
// Thumbprint a JWK (SHA256)
|
||||||
return Keypairs.thumbprint({ jwk: jwk }).then(function (thumb) {
|
return Keypairs.thumbprint({ jwk: jwk }).then(function(thumb) {
|
||||||
console.log(thumb);
|
console.log(thumb);
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
@ -88,72 +86,6 @@ return Keypairs.signJwt({
|
|||||||
By default ECDSA keys will be used since they've had native support in node
|
By default ECDSA keys will be used since they've had native support in node
|
||||||
_much_ longer than RSA has, and they're smaller, and faster to generate.
|
_much_ longer than RSA has, and they're smaller, and faster to generate.
|
||||||
|
|
||||||
## Webpack 5+ (for Browsers)
|
|
||||||
|
|
||||||
This package includes native browser versions of all special functions.
|
|
||||||
|
|
||||||
Since Webpack 5 now fully supports vanilla JavaScript and exclusive browser builds out-of-the-box,
|
|
||||||
it's pretty easy to create a minimal config to use Keypairs in your browser projects:
|
|
||||||
|
|
||||||
`webpack.config.js`:
|
|
||||||
|
|
||||||
```js
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var path = require('path');
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
entry: './main.js',
|
|
||||||
mode: 'development',
|
|
||||||
devServer: {
|
|
||||||
contentBase: path.join(__dirname, 'dist'),
|
|
||||||
port: 3001
|
|
||||||
},
|
|
||||||
output: {
|
|
||||||
publicPath: 'http://localhost:3001/'
|
|
||||||
},
|
|
||||||
module: {
|
|
||||||
rules: [{}]
|
|
||||||
},
|
|
||||||
plugins: []
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
`main.js`:
|
|
||||||
|
|
||||||
```js
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var Keypairs = require('./keypairs.js');
|
|
||||||
|
|
||||||
Keypairs.generate().then(function (pair) {
|
|
||||||
console.log(pair.private);
|
|
||||||
console.log(pair.public);
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
`index.html`:
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<body>
|
|
||||||
<script src="./dist/main.js"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
||||||
|
|
||||||
```bash
|
|
||||||
npm install --save-dev webpack@5
|
|
||||||
# Or, if webpack 5 is still in beta: npm install --save-dev webpack@next
|
|
||||||
|
|
||||||
npm install --save-dev webpack-cli
|
|
||||||
|
|
||||||
npx webpack --mode=production
|
|
||||||
|
|
||||||
ls dist/main.js
|
|
||||||
```
|
|
||||||
|
|
||||||
## API Overview
|
## API Overview
|
||||||
|
|
||||||
- generate (JWK)
|
- generate (JWK)
|
||||||
@ -192,7 +124,7 @@ Option Examples:
|
|||||||
Example:
|
Example:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
Keypairs.parse({ key: '...' }).catch(function (e) {
|
Keypairs.parse({ key: '...' }).catch(function(e) {
|
||||||
// could not be parsed or was a public key
|
// could not be parsed or was a public key
|
||||||
console.warn(e);
|
console.warn(e);
|
||||||
return Keypairs.generate();
|
return Keypairs.generate();
|
||||||
@ -213,7 +145,7 @@ Option Examples:
|
|||||||
Example:
|
Example:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
Keypairs.parseOrGenerate({ key: process.env['PRIVATE_KEY'] }).then(function (
|
Keypairs.parseOrGenerate({ key: process.env['PRIVATE_KEY'] }).then(function(
|
||||||
pair
|
pair
|
||||||
) {
|
) {
|
||||||
console.log(pair.public);
|
console.log(pair.public);
|
||||||
|
|||||||
@ -9,7 +9,5 @@ sha2.sum = function (alg, str) {
|
|||||||
data = encoder.encode(str);
|
data = encoder.encode(str);
|
||||||
}
|
}
|
||||||
var sha = 'SHA-' + String(alg).replace(/^sha-?/i, '');
|
var sha = 'SHA-' + String(alg).replace(/^sha-?/i, '');
|
||||||
return window.crypto.subtle.digest(sha, data).then(function (buf) {
|
return window.crypto.subtle.digest(sha, data);
|
||||||
return new Uint8Array(buf);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|||||||
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@root/keypairs",
|
"name": "@root/keypairs",
|
||||||
"version": "0.10.2",
|
"version": "0.9.1",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@root/keypairs",
|
"name": "@root/keypairs",
|
||||||
"version": "0.10.2",
|
"version": "0.9.1",
|
||||||
"description": "Lightweight, Zero-Dependency RSA and EC/ECDSA crypto for Node.js and Browsers",
|
"description": "Lightweight, Zero-Dependency RSA and EC/ECDSA crypto for Node.js and Browsers",
|
||||||
"main": "keypairs.js",
|
"main": "keypairs.js",
|
||||||
"browser": {
|
"browser": {
|
||||||
@ -20,7 +20,7 @@
|
|||||||
],
|
],
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/therootcompany/keypairs.js.git"
|
"url": "https://git.rootprojects.org/root/csr.js.git"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"ASN.1",
|
"ASN.1",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user