paseto-wasm
v1.0.2
Published
A PASETO implementation in Rust with WebAssembly (WASM) bindings
Maintainers
Readme
Enable PASETO in JavaScript browsers using WebAssembly (WASM)
Built with 🦀🕸 by Achmad Kurnianto
🌄 Background
PASETO (Platform-Agnostic Security Tokens) offers the benefits of JOSE standards (JWT, JWE, JWS) without their numerous design flaws.
This project began in 2022 when no PASETO libraries supported JavaScript browsers. The existing JavaScript/TypeScript implementations were:
pasetoby Filip Skokan - Node.js onlypaseto.jsby Samuel Judson - Uses deprecated PASETO v1 and v2 implementations
Today, you can use the paseto-ts library for browser-based PASETO implementation. For better performance, consider paseto-wasm, which leverages WebAssembly.
Initially, I planned to use the pasetors crate by Johannes, which includes WASM support but lacks comprehensive testing. After evaluating options, I chose the rusty-paseto crate for its reliable WASM support.
🚀 Usage
Installation
This crate produces the paseto-wasm library, compatible with both JavaScript browsers and Node.js.
npm install paseto-wasm # npm
yarn add paseto-wasm # yarn
pnpm add paseto-wasm # pnpm
bun add paseto-wasm # bunAPI Methods
PASETO v4 (Default)
The following methods are available by default:
encrypt_v4_local,decrypt_v4_localsign_v4_public,verify_v4_publicgenerate_v4_local_key,generate_v4_public_key_pairkey_to_paserk_local,paserk_local_to_keykey_to_paserk_secret,paserk_secret_to_keykey_to_paserk_public,paserk_public_to_keyget_local_key_id,get_public_key_id,get_secret_key_id
PASETO v3
Access v3 implementations via paseto-wasm/v3:
encrypt_v3_local,decrypt_v3_localsign_v3_public,verify_v3_publicgenerate_v3_local_key,generate_v3_public_key_pairkey_to_paserk_v3_local,paserk_v3_local_to_keykey_to_paserk_v3_secret,paserk_v3_secret_to_keykey_to_paserk_v3_public,paserk_v3_public_to_keyget_v3_local_key_id,get_v3_public_key_id,get_v3_secret_key_id
Documentation
Example usage is available in the test file. Comprehensive documentation is currently a work in progress.
📝 Contributing
🛠️ Building
pnpm run build:wasm🧪 Testing
# Node.js environment
pnpm run test:wasm:node
# Browser environment
pnpm run test:wasm:web
pnpm run test:wasm:web:v3For detailed contribution guidelines, please see CONTRIBUTING.md.
🛠️ Built With
wasm-bindgen - Facilitates communication between WebAssembly and JavaScript
rusty-paseto - PASETO implementation in Rust
📋 Roadmap
- [ ] Complete documentation
- [ ] Support PASERK in sign/verify operations
- [ ] Implement custom allocator (e.g., lol_alloc or talc) for improved performance and reduced file size
