Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
kigawas committed Oct 11, 2024
0 parents commit 1dbaad6
Show file tree
Hide file tree
Showing 21 changed files with 1,686 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: kigawas
28 changes: 28 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: CD

on:
release:
types: [published]

jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v4

- uses: actions/setup-node@v4
with:
node-version: 22
registry-url: "https://registry.npmjs.org"

- run: pnpm install && pnpm test -- --bail 1

- run: pnpm run build && npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_CONFIG_PROVENANCE: true
33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: CI

on:
push:
branches: [main]

pull_request:
branches: [main]

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
node: [18, 20, 22]
steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v4

- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: pnpm
cache-dependency-path: pnpm-lock.yaml

- run: pnpm install && pnpm test -- --bail 1

- uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
- run: pnpm run build && npm publish --dry-run
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules/
coverage/
dist/

bun.lockb
deno.lock

.DS_Store
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019-2024 Weiliang Li

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.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# @ecies/ciphers

Node/Pure js symmetric ciphers adapter.

On browsers (or deno), it'll use `@noble/ciphers`'s implementation.

On node (or bun), it'll use `node:crypto`'s implementation.

Check the [example](./example/) folder for the bun/deno usage.
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
theme: jekyll-theme-minimal
9 changes: 9 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# example

## bun

Run with `bun install && bun run index.ts`

## deno

Run with `deno run main.ts`
12 changes: 12 additions & 0 deletions example/bun/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { aes256gcm } from "@ecies/ciphers";
import { randomBytes } from "@noble/ciphers/webcrypto";

const TEXT = "helloworld🌍";
const encoder = new TextEncoder();
const decoder = new TextDecoder();
const msg = encoder.encode(TEXT);

const key = randomBytes();
const nonce = randomBytes(16);
const cipher = aes256gcm(key, nonce);
console.log("decrypted:", decoder.decode(cipher.decrypt(cipher.encrypt(msg))));
14 changes: 14 additions & 0 deletions example/bun/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "bun-example",
"module": "index.ts",
"type": "module",
"dependencies": {
"@ecies/ciphers": "^0.1.0"
},
"devDependencies": {
"bun-types": "latest"
},
"peerDependencies": {
"typescript": "^5.6.3"
}
}
22 changes: 22 additions & 0 deletions example/bun/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"lib": ["ESNext"],
"module": "esnext",
"target": "esnext",
"moduleResolution": "bundler",
"moduleDetection": "force",
"allowImportingTsExtensions": true,
"noEmit": true,
"composite": true,
"strict": true,
"downlevelIteration": true,
"skipLibCheck": true,
"jsx": "react-jsx",
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"allowJs": true,
"types": [
"bun-types" // add Bun global
]
}
}
9 changes: 9 additions & 0 deletions example/deno/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"tasks": {
"dev": "deno run --watch main.ts"
},
"imports": {
"@ecies/ciphers": "npm:@ecies/ciphers@0.1.0",
"@noble/ciphers": "npm:@noble/ciphers@1.0.0"
}
}
12 changes: 12 additions & 0 deletions example/deno/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { aes256gcm } from "@ecies/ciphers";
import { randomBytes } from "@noble/ciphers/webcrypto";

const TEXT = "helloworld🌍";
const encoder = new TextEncoder();
const decoder = new TextDecoder();
const msg = encoder.encode(TEXT);

const key = randomBytes();
const nonce = randomBytes(16);
const cipher = aes256gcm(key, nonce);
console.log("decrypted:", decoder.decode(cipher.decrypt(cipher.encrypt(msg))));
48 changes: 48 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "@ecies/ciphers",
"description": "Node/Pure js symmetric ciphers adapter",
"license": "MIT",
"author": {
"name": "Weiliang Li",
"email": "to.be.impressive@gmail.com",
"url": "https://github.com/kigawas"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ecies/js-ciphers.git"
},
"version": "0.1.0",
"engines": {
"node": ">=16.0.0"
},
"keywords": [
"cryptography",
"aes"
],
"main": "dist/node.js",
"types": "dist/node.d.ts",
"files": [
"dist"
],
"exports": {
"types": "./dist/node.d.ts",
"browser": "./dist/noble.js",
"deno": "./dist/noble.js",
"bun": "./dist/node.js",
"default": "./dist/node.js"
},
"scripts": {
"build": "npx tsc",
"test": "vitest"
},
"dependencies": {
"@noble/ciphers": "^1.0.0"
},
"devDependencies": {
"@types/node": "^22.7.5",
"@vitest/coverage-v8": "^2.1.2",
"typescript": "^5.6.3",
"vitest": "^2.1.2"
},
"packageManager": "pnpm@9.12.1+sha512.e5a7e52a4183a02d5931057f7a0dbff9d5e9ce3161e33fa68ae392125b79282a8a8a470a51dfc8a0ed86221442eb2fb57019b0990ed24fab519bf0e1bc5ccfc4"
}
Loading

0 comments on commit 1dbaad6

Please sign in to comment.