Skip to content

Commit

Permalink
feat: add v3.local, v3.public, and v4.public
Browse files Browse the repository at this point in the history
Additionally allows raw byte key sequences to be passed in V2, V3, and
V4's `.sign()` and `.verify()` methods as the "key" argument.

Also adds utility functions to convert raw byte sequences to KeyObject.

BREAKING CHANGE: Node.js runtime version v16.0.0 or greater is now required
  • Loading branch information
panva committed Jul 30, 2021
1 parent 84a07e1 commit ea32ad8
Show file tree
Hide file tree
Showing 72 changed files with 3,231 additions and 1,526 deletions.
21 changes: 3 additions & 18 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,14 @@ on:
- cron: 0 12 * * 1-5

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/setup-node@v1
with:
node-version: 12
- run: npx panva/npm-install-retry
- run: npm run lint
- run: npm run lint-ts

test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version:
- 12.19.0
- 12
- 14.15.0
- 14
- 15.0.1
- 15
- '>=15'
- 16.0.0
- 16
- '>=16'
os:
- ubuntu-latest
- windows-latest
Expand Down
6 changes: 6 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "all",
"singleQuote": true,
"printWidth": 100,
"semi": false
}
89 changes: 26 additions & 63 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@

> [PASETO](https://paseto.io): <strong>P</strong>latform-<strong>A</strong>gnostic <strong>SE</strong>curity <strong>TO</strong>kens for Node.js no dependencies.
## Implemented specs & features
## Implemented Protocol Versions

All crypto operations are using their async node's crypto API, where such API is not available the
operation is pushed to a [Worker Thread](https://nodejs.org/api/worker_threads.html) so that your
main thread's I/O is not blocked.

<br>

| | v1.local | v1.public | v2.local | v2.public |
| | v1 | v2 | v3 | v4 |
| -- | -- | -- | -- | -- |
| supported? |||||
| local |||||
| public |||||

## Support

Expand All @@ -21,6 +16,8 @@ If you or your business use paseto, please consider becoming a [sponsor][support
## Documentation

- [API Documentation][documentation]
- [PASETO Protocol Version v4][documentation-v4]
- [PASETO Protocol Version v3][documentation-v3]
- [PASETO Protocol Version v2][documentation-v2]
- [PASETO Protocol Version v1][documentation-v1]

Expand All @@ -43,7 +40,13 @@ const { decode } = paseto
const { V1 } = paseto // { sign, verify, encrypt, decrypt, generateKey }

// PASETO Protocol Version v2 specific API
const { V2 } = paseto // { sign, verify, generateKey }
const { V2 } = paseto // { sign, verify, generateKey, bytesToKeyObject, keyObjectToBytes }

// PASETO Protocol Version v3 specific API
const { V3 } = paseto // { sign, verify, encrypt, decrypt, generateKey, bytesToKeyObject, keyObjectToBytes }

// PASETO Protocol Version v4 specific API
const { V4 } = paseto // { sign, verify, generateKey, bytesToKeyObject, keyObjectToBytes }

// errors utilized by paseto
const { errors } = paseto
Expand Down Expand Up @@ -75,57 +78,15 @@ const { V2: { verify } } = paseto
})()
```

#### Keys

Node's [KeyObject](https://nodejs.org/api/crypto.html#crypto_class_keyobject) is ultimately what the
library works with, depending on the operation, if the key parameter is not already a KeyObject
instance the corresponding `create` function will be called with the input

- [`crypto.createSecretKey()`](https://nodejs.org/api/crypto.html#crypto_crypto_createsecretkey_key)
for local encrypt/decrypt operations
- [`crypto.createPublicKey()`](https://nodejs.org/api/crypto.html#crypto_crypto_createpublickey_key)
for public verify operations
- [`crypto.createPrivateKey()`](https://nodejs.org/api/crypto.html#crypto_crypto_createprivatekey_key)
for public sign operations

You can also generate keys valid for the given operation directly through paseto

```js
const crypto = require('crypto')
const { V1, V2 } = paseto
## FAQ

(async () => {
{
const key = await V1.generateKey('local')
console.log(key instanceof crypto.KeyObject)
// true
console.log(key.type === 'secret')
// true
console.log(key.symmetricKeySize === 32)
// true
}
{
const key = await V1.generateKey('public')
console.log(key instanceof crypto.KeyObject)
// true
console.log(key.type === 'private')
// true
console.log(key.asymmetricKeyType === 'rsa')
// true
}
{
const key = await V2.generateKey('public')
console.log(key instanceof crypto.KeyObject)
// true
console.log(key.type === 'private')
// true
console.log(key.asymmetricKeyType === 'ed25519')
// true
}
})()
```
#### Supported Versions

## FAQ
| Version | Security Fixes 🔑 | Other Bug Fixes 🐞 | New Features ⭐ |
| ------- | --------- | -------- | -------- |
| [3.x.x](https://github.com/panva/paseto) ||||
| [2.x.x](https://github.com/panva/paseto/tree/v2.x) || ✅ until 2022-04-30 ||
| [1.x.x](https://github.com/panva/paseto/tree/v1.x) ||||

#### Semver?

Expand All @@ -136,10 +97,12 @@ private API and is subject to change between any versions.

#### How do I use it outside of Node.js

It is **only built for Node.js** environment versions ^12.19.0 || >=14.15.0
It is **only built for Node.js** environment versions >=16.0.0


[documentation]: https://github.com/panva/paseto/blob/master/docs/README.md
[documentation-v2]: https://github.com/panva/paseto/blob/master/docs/README.md#v2-paseto-protocol-version-v2
[documentation-v1]: https://github.com/panva/paseto/blob/master/docs/README.md#v1-paseto-protocol-version-v1
[documentation]: https://github.com/panva/paseto/blob/main/docs/README.md
[documentation-v4]: https://github.com/panva/paseto/blob/main/docs/README.md#v4-paseto-protocol-version-v4
[documentation-v3]: https://github.com/panva/paseto/blob/main/docs/README.md#v3-paseto-protocol-version-v3
[documentation-v2]: https://github.com/panva/paseto/blob/main/docs/README.md#v2-paseto-protocol-version-v2
[documentation-v1]: https://github.com/panva/paseto/blob/main/docs/README.md#v1-paseto-protocol-version-v1
[support-sponsor]: https://github.com/sponsors/panva
Loading

0 comments on commit ea32ad8

Please sign in to comment.