added apps
This commit is contained in:
13
node_modules/next-crypto/.eslintrc.json
generated
vendored
Normal file
13
node_modules/next-crypto/.eslintrc.json
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"env": {
|
||||
"es2021": true,
|
||||
"node": true
|
||||
},
|
||||
"extends": "airbnb-base",
|
||||
"plugins": ["prettier"],
|
||||
"parserOptions": {
|
||||
"ecmaVersion": "latest",
|
||||
"sourceType": "module"
|
||||
},
|
||||
"rules": {}
|
||||
}
|
||||
4
node_modules/next-crypto/.husky/pre-commit
generated
vendored
Normal file
4
node_modules/next-crypto/.husky/pre-commit
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env sh
|
||||
. "$(dirname -- "$0")/_/husky.sh"
|
||||
|
||||
npm run format && npm run lint
|
||||
4
node_modules/next-crypto/.prettierignore
generated
vendored
Normal file
4
node_modules/next-crypto/.prettierignore
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
build
|
||||
coverage
|
||||
node_modules
|
||||
*.md
|
||||
5
node_modules/next-crypto/.prettierrc
generated
vendored
Normal file
5
node_modules/next-crypto/.prettierrc
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"tabWidth": 2,
|
||||
"singleQuote": true,
|
||||
"plugins": ["prettier-plugin-organize-imports"]
|
||||
}
|
||||
21
node_modules/next-crypto/LICENSE
generated
vendored
Normal file
21
node_modules/next-crypto/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Maurice Butler
|
||||
|
||||
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.
|
||||
34
node_modules/next-crypto/README.md
generated
vendored
Normal file
34
node_modules/next-crypto/README.md
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
# Next Crypto
|
||||
|
||||
Next Crypto uses aes-gcm encryption for encrypting and decrypting with Next.JS (created for running in edge runtime).
|
||||
|
||||
You can encrypt any sensitive data and store it where you need (session data in cookies, etc..).
|
||||
|
||||
You need only 1 required argument with your secret.
|
||||
|
||||
Works async by default.
|
||||
|
||||
## Installation
|
||||
|
||||
Using NPM:
|
||||
|
||||
`npm install next-crypto`
|
||||
|
||||
Using Yarn:
|
||||
|
||||
`yarn add next-crypto`
|
||||
|
||||
Using Pnpm:
|
||||
|
||||
`pnpm add next-crypto`
|
||||
|
||||
## Usage
|
||||
|
||||
```javascript
|
||||
import NextCrypto from 'next-crypto';
|
||||
|
||||
const crypto = new NextCrypto('secret key');
|
||||
|
||||
const encrypted = await crypto.encrypt('hello!');
|
||||
const decrypted = await crypto.decrypt(encrypted);
|
||||
```
|
||||
8
node_modules/next-crypto/index.d.ts
generated
vendored
Normal file
8
node_modules/next-crypto/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
declare class NextCrypto {
|
||||
constructor(secret: string);
|
||||
|
||||
async encrypt(plain: string): Promise<string>;
|
||||
async decrypt(encrypted: string): Promise<string | null>;
|
||||
}
|
||||
|
||||
export default NextCrypto;
|
||||
90
node_modules/next-crypto/index.js
generated
vendored
Normal file
90
node_modules/next-crypto/index.js
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
class NextCrypto {
|
||||
constructor(secret) {
|
||||
this.secret = secret;
|
||||
}
|
||||
|
||||
async encrypt(plain) {
|
||||
if (!crypto) {
|
||||
throw new Error(
|
||||
'No WebAPI crypto module found. Do you call me in the right place?',
|
||||
);
|
||||
}
|
||||
|
||||
const iv = crypto.getRandomValues(new Uint8Array(12));
|
||||
|
||||
const alg = { name: 'AES-GCM', iv };
|
||||
const keyHash = await crypto.subtle.digest(
|
||||
'SHA-256',
|
||||
new TextEncoder().encode(this.secret),
|
||||
);
|
||||
|
||||
const encodedPlaintext = new TextEncoder().encode(plain);
|
||||
|
||||
const secretKey = await crypto.subtle.importKey(
|
||||
'raw',
|
||||
keyHash,
|
||||
alg,
|
||||
false,
|
||||
['encrypt'],
|
||||
);
|
||||
|
||||
const ciphertext = await crypto.subtle.encrypt(
|
||||
{
|
||||
name: 'AES-GCM',
|
||||
iv,
|
||||
},
|
||||
secretKey,
|
||||
encodedPlaintext,
|
||||
);
|
||||
|
||||
return `${Buffer.from(ciphertext).toString('base64')};${Buffer.from(
|
||||
iv,
|
||||
).toString('base64')}`;
|
||||
}
|
||||
|
||||
async decrypt(encrypted) {
|
||||
if (!crypto) {
|
||||
throw new Error(
|
||||
'No WebAPI crypto module found. Do you call me in the right place?',
|
||||
);
|
||||
}
|
||||
|
||||
const ciphertext = encrypted.split(';')[0];
|
||||
const iv = encrypted.split(';')[1];
|
||||
|
||||
if (!ciphertext || !iv) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const alg = { name: 'AES-GCM', iv };
|
||||
const keyHash = await crypto.subtle.digest(
|
||||
'SHA-256',
|
||||
new TextEncoder().encode(this.secret),
|
||||
);
|
||||
|
||||
const secretKey = await crypto.subtle.importKey(
|
||||
'raw',
|
||||
keyHash,
|
||||
alg,
|
||||
false,
|
||||
['decrypt'],
|
||||
);
|
||||
|
||||
try {
|
||||
const cleartext = await crypto.subtle.decrypt(
|
||||
{
|
||||
name: 'AES-GCM',
|
||||
iv: Buffer.from(iv, 'base64'),
|
||||
},
|
||||
secretKey,
|
||||
Buffer.from(ciphertext, 'base64'),
|
||||
);
|
||||
|
||||
return new TextDecoder().decode(cleartext);
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = NextCrypto;
|
||||
38
node_modules/next-crypto/package.json
generated
vendored
Normal file
38
node_modules/next-crypto/package.json
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"name": "next-crypto",
|
||||
"version": "1.0.8",
|
||||
"description": "A simple encryption module for Next.JS edge runtime.",
|
||||
"main": "index.js",
|
||||
"types": "index.d.ts",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/ilyahahaha/next_crypto.git"
|
||||
},
|
||||
"author": "Ilya Kuchmenko <42113015+ilyahahaha@users.noreply.github.com>",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"encrypt",
|
||||
"decrypt",
|
||||
"encryption",
|
||||
"decryption",
|
||||
"nextjs"
|
||||
],
|
||||
"bugs": {
|
||||
"url": "https://github.com/ilyahahaha/next_crypto/issues"
|
||||
},
|
||||
"homepage": "https://github.com/ilyahahaha/next_crypto",
|
||||
"devDependencies": {
|
||||
"eslint": "^8.50.0",
|
||||
"eslint-config-airbnb-base": "^15.0.0",
|
||||
"eslint-plugin-import": "^2.28.1",
|
||||
"eslint-plugin-prettier": "^5.0.0",
|
||||
"husky": "^8.0.3",
|
||||
"prettier": "^3.0.3",
|
||||
"prettier-plugin-organize-imports": "^3.2.3"
|
||||
},
|
||||
"scripts": {
|
||||
"prepare": "husky install",
|
||||
"format": "prettier --write --ignore-unknown .",
|
||||
"lint": "npx eslint ."
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user