-
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.
- Loading branch information
Showing
2 changed files
with
92 additions
and
1 deletion.
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 cross-org <https://github.com/cross-org> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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 +1,71 @@ | ||
## WIP | ||
# WIP | ||
|
||
Work in progress | ||
|
||
## @cross/jwt | ||
|
||
A versatile JSON Web Token (JWT) library for Deno, Bun, and Node.js providing cross-runtime compatibility. | ||
|
||
Part of the @cross suite - check out our growing collection of cross-runtime tools at | ||
[github.com/cross-org](https://github.com/cross-org). | ||
|
||
## Features | ||
|
||
- **HMAC Signing and Verification:** Securely sign and verify JWTs using HMAC with SHA-256. | ||
- **RSA Signing and Verification:** Employ robust RSA (RSASSA-PKCS1-v1_5) signatures for enhanced JWT security. | ||
- **Simple API:** Intuitive functions for generating, parsing, signing, and verifying JWTs. | ||
- **Key Generation:** Conveniently create HMAC secret keys and RSA key pairs. | ||
- **Cross-Runtime Support:** Seamlessly work across Deno, Bun, and Node.js environments. | ||
|
||
## Installation | ||
|
||
```bash | ||
#For Deno | ||
deno add @cross/jwt | ||
|
||
#For Bun | ||
bunx jsr add @cross/jwt | ||
|
||
#For Node.js | ||
npx jsr add @cross/jwt | ||
``` | ||
|
||
## Usage | ||
|
||
**HMAC Example** | ||
|
||
The most common way to sign and verify JWTs | ||
|
||
```javascript | ||
import { createJWT, generateKey, parseJWT } from "@cross/jwt"; | ||
|
||
const secret = "mySuperSecretAtLeast32CharsLongmySuperSecretAtLeast32CharsLong"; | ||
const key = await generateKey(secret); | ||
|
||
const jwt = await createJWT(key, { hello: "world" }); | ||
const data = await parseJWT(key, jwt); | ||
|
||
console.log(data); // Outputs: { hello: "world" } | ||
``` | ||
|
||
**RSA Example** | ||
|
||
```javascript | ||
import { createJWT, generateKeyPair, parseJWT } from "@cross/jwt"; | ||
|
||
const { privateKey, publicKey } = await generateKeyPair(); | ||
|
||
const jwt = await createJWT(privateKey, { userId: 123 }); | ||
const data = await parseJWT(publicKey, jwt); | ||
|
||
console.log(data); // Outputs: { userId: 123 } | ||
``` | ||
|
||
## Issues | ||
|
||
Issues or questions concerning the library can be raised at the | ||
[github repository](https://github.com/cross-org/jwt/issues) page. | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. |