Skip to content

Commit 54a847c

Browse files
committed
Initial plugin
0 parents  commit 54a847c

10 files changed

Lines changed: 1086 additions & 0 deletions

File tree

.github/workflows/pr.yml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: Test Suite
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
8+
jobs:
9+
build:
10+
name: 'Run Tests'
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
name: Checkout Code
15+
16+
- name: List Directory Contents (for Troubleshooting)
17+
run: |
18+
pwd
19+
ls -l
20+
21+
- uses: actions/setup-node@v1
22+
name: Setup Node.js
23+
with:
24+
node-version: '14'
25+
26+
- uses: actions/cache@v2
27+
name: Establish npm Cache
28+
with:
29+
path: ~/.npm
30+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
31+
restore-keys: |
32+
${{ runner.os }}-node-
33+
34+
- uses: actions/cache@v2
35+
name: Establish Docker Cache
36+
id: cache
37+
with:
38+
path: docker-cache
39+
key: ${{ runner.os }}-docker-${{ github.sha }}
40+
restore-keys: |
41+
${{ runner.os }}-docker-
42+
43+
- name: Load cached Docker layers
44+
run: |
45+
if [ -d "docker-cache" ]; then
46+
cat docker-cache/x* > my-image.tar
47+
docker load < my-image.tar
48+
rm -rf docker-cache
49+
fi
50+
51+
- name: Download Dev Tooling
52+
id: setup
53+
run: |
54+
echo ${{ secrets.GH_DOCKER_TOKEN }} | docker login https://docker.pkg.github.com -u ${{ secrets.GH_DOCKER_USER }} --password-stdin
55+
base=$(curl -L -s 'https://registry.hub.docker.com/v2/repositories/author/dev-base/tags?page_size=1'|jq '."results"[]["name"]')
56+
base=$(sed -e 's/^"//' -e 's/"$//' <<<"$base")
57+
echo Retrieving author/dev/dev-base:$base
58+
docker pull author/dev-base:$base
59+
# docker pull docker.pkg.github.com/author/dev/dev-base:$base
60+
61+
deno=$(curl -L -s 'https://registry.hub.docker.com/v2/repositories/author/dev-deno/tags?page_size=1'|jq '."results"[]["name"]')
62+
deno=$(sed -e 's/^"//' -e 's/"$//' <<<"$deno")
63+
echo Retrieving author/dev/dev-deno:$deno
64+
# docker pull docker.pkg.github.com/author/dev/dev-deno:$deno
65+
docker pull author/dev-deno:$deno
66+
67+
browser=$(curl -L -s 'https://registry.hub.docker.com/v2/repositories/author/dev-browser/tags?page_size=1'|jq '."results"[]["name"]')
68+
browser=$(sed -e 's/^"//' -e 's/"$//' <<<"$browser")
69+
echo Retrieving author/dev/dev-browser:$browser
70+
# docker pull docker.pkg.github.com/author/dev/dev-browser:$browser
71+
docker pull author/dev-browser:$browser
72+
73+
node=$(curl -L -s 'https://registry.hub.docker.com/v2/repositories/author/dev-node/tags?page_size=1'|jq '."results"[]["name"]')
74+
node=$(sed -e 's/^"//' -e 's/"$//' <<<"$node")
75+
echo Retrieving author/dev/dev-node:$node
76+
# docker pull docker.pkg.github.com/author/dev/dev-node:$node
77+
docker pull author/dev-node:$node
78+
79+
# node -e "const p=new Set(Object.keys(require('./package.json').peerDependencies));p.delete('@author.io/dev');console.log('npm i ' + Array.from(p).join(' '))"
80+
version=$(npm show @author.io/dev version)
81+
echo $version
82+
npm i -g @author.io/dev@$version
83+
dev -v
84+
env:
85+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
86+
87+
- name: Test
88+
if: success()
89+
run: |
90+
dev -v
91+
npm run ci

.github/workflows/release.yml

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
name: Test Suite
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
build:
10+
name: 'Release'
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
name: Checkout Code
15+
16+
- uses: actions/setup-node@v1
17+
name: Setup Node.js
18+
with:
19+
node-version: '14'
20+
21+
- uses: actions/cache@v2
22+
name: Establish Docker Cache
23+
id: cache
24+
with:
25+
path: docker-cache
26+
key: ${{ runner.os }}-docker-${{ github.sha }}
27+
restore-keys: |
28+
${{ runner.os }}-docker-
29+
30+
- name: Load cached Docker layers
31+
run: |
32+
if [ -d "docker-cache" ]; then
33+
cat docker-cache/x* > my-image.tar
34+
docker load < my-image.tar
35+
rm -rf docker-cache
36+
fi
37+
38+
- name: Setup Build Tooling
39+
id: setup
40+
run: |
41+
base=$(curl -L -s 'https://registry.hub.docker.com/v2/repositories/author/dev-base/tags?page_size=1'|jq '."results"[]["name"]')
42+
base=$(sed -e 's/^"//' -e 's/"$//' <<<"$base")
43+
echo Retrieving author/dev/dev-base:$base
44+
docker pull author/dev-base:$base
45+
46+
deno=$(curl -L -s 'https://registry.hub.docker.com/v2/repositories/author/dev-deno/tags?page_size=1'|jq '."results"[]["name"]')
47+
deno=$(sed -e 's/^"//' -e 's/"$//' <<<"$deno")
48+
echo Retrieving author/dev/dev-deno:$deno
49+
docker pull author/dev-deno:$deno
50+
51+
browser=$(curl -L -s 'https://registry.hub.docker.com/v2/repositories/author/dev-browser/tags?page_size=1'|jq '."results"[]["name"]')
52+
browser=$(sed -e 's/^"//' -e 's/"$//' <<<"$browser")
53+
echo Retrieving author/dev/dev-browser:$browser
54+
docker pull author/dev-browser:$browser
55+
56+
node=$(curl -L -s 'https://registry.hub.docker.com/v2/repositories/author/dev-node/tags?page_size=1'|jq '."results"[]["name"]')
57+
node=$(sed -e 's/^"//' -e 's/"$//' <<<"$node")
58+
echo Retrieving author/dev/dev-node:$node
59+
docker pull author/dev-node:$node
60+
61+
# node -e "const p=new Set(Object.keys(require('./package.json').peerDependencies));p.delete('@author.io/dev');console.log('npm i ' + Array.from(p).join(' '))"
62+
version=$(npm show @author.io/dev version)
63+
echo $version
64+
npm i -g @author.io/dev@$version
65+
env:
66+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67+
68+
- name: Test
69+
if: success()
70+
run: |
71+
dev -v
72+
npm run ci
73+
74+
- name: Tag
75+
id: autotagger
76+
if: success()
77+
uses: butlerlogic/action-autotag@stable
78+
with:
79+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
80+
81+
# If the new version/tag is a pre-release (i.e. 1.0.0-beta.1), create
82+
# an environment variable indicating it is a prerelease.
83+
- name: Pre-release
84+
if: steps.autotagger.outputs.tagname != ''
85+
run: |
86+
if [[ "${{ steps.autotagger.output.version }}" == *"-"* ]]; then echo "::set-env IS_PRERELEASE=true";else echo "::set-env IS_PRERELEASE=''";fi
87+
88+
- name: Release
89+
id: create_release
90+
if: steps.autotagger.outputs.tagname != ''
91+
uses: actions/create-release@v1.0.0
92+
env:
93+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
94+
with:
95+
tag_name: ${{ steps.autotagger.outputs.tagname }}
96+
release_name: ${{ steps.autotagger.outputs.tagname }}
97+
body: ${{ steps.autotagger.outputs.tagmessage }}
98+
draft: false
99+
prerelease: env.IS_PRERELEASE != ''
100+
101+
# Build tarballs of the module code.
102+
- name: Build Release Artifacts
103+
id: build_release
104+
if: steps.create_release.outputs.id != ''
105+
run: |
106+
dev build --pack --mode ci --peer
107+
cp -rf .dist ./dist
108+
109+
# Upload tarballs to the release.
110+
- name: Upload Release Artifacts
111+
uses: AButler/upload-release-assets@v2.0
112+
if: steps.create_release.outputs.id != ''
113+
with:
114+
files: '.dist/*.tar.gz'
115+
repo-token: ${{ secrets.GITHUB_TOKEN }}
116+
release-tag: ${{ steps.autotagger.outputs.tagname }}
117+
118+
- name: Publish to npm
119+
id: publish_npm
120+
if: steps.autotagger.outputs.tagname != ''
121+
uses: author/action-publish@stable
122+
with:
123+
scan: ./dist
124+
env:
125+
REGISTRY_TOKEN: ${{ secrets.NPM_REGISTRY_TOKEN }}
126+
127+
- name: Rollback Release
128+
if: failure() && steps.create_release.outputs.id != ''
129+
uses: author/action-rollback@stable
130+
with:
131+
tag: ${{ steps.autotagger.outputs.tagname }}
132+
env:
133+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
*.log
2+
*.old
3+
old_*
4+
.*
5+
!.github
6+
!.*ignore
7+
!.*.yml
8+
!.*rc
9+
!.npmrc
10+
env.json
11+
/**/env.json
12+
node_modules

.npmignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
build
2+
test
3+
examples
4+
.*
5+
*.log
6+
*.md

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) <year> <owner>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<h1 align="center">NGN Crypto<br/><img src="https://img.shields.io/npm/v/@ngnjs/crypto?label=%40ngnjs/crypto&logo=npm&style=social"/></h1>
2+
3+
The NGN Cryptography plugin implements [libcrypto](https://github.com/ngnjs/libcrrypto), making it accessible from NGN and for all other NGN plugins. The following libcrypto methods are available:
4+
5+
- `generateKeys()`
6+
- `sign()`
7+
- `verify()`
8+
- `encrypt()`
9+
- `decrypt()`
10+
- `encryptJSON()`
11+
- `decryptJSON()`
12+
- `encryptionAlgorithm()`
13+
14+
**Notice:** libcrypto contains additional features which aren't commonly used. This plugin exposes the minimum number of functions required to cover the most common cryptography needs in the smallest package possible. The other functions can be imported directly from libcrypto into projects that need them.
15+
16+
The fundamental/basic example:
17+
18+
```javascript
19+
import NGN from 'https://cdn.jsdelivr.net/npm/ngn@latest/index.js'
20+
import from 'https://cdn.jsdelivr.net/npm/@ngnjs/crypto/index.js'
21+
22+
// The crypto library is accessible from the NGN namespace
23+
const crypto = NGN.crypto
24+
25+
// Key Generation
26+
const { publicKey, privateKey } = await crypto.generateKeys()
27+
28+
// Content signing/verification
29+
const content = 'my data'
30+
const signature = await crypto.sign(content, privateKey)
31+
const verified = await crypto.verify(content, signature, publicKey)
32+
33+
// Shared key encryption
34+
const sharedKey = 'my secret'
35+
const encrypted = await crypto.encrypt(content, sharedKey)
36+
const decrypted = await crypto.decrypt(encrypted, sharedKey)
37+
38+
// Public key encryption/Private key decryption
39+
const encrypted = await crypto.encrypt(content, publicKey)
40+
const decrypted = await crypto.encrypt(content, privateKey)
41+
```
42+
43+
For more specific examples and documentation, see the [libcrypto repository](https://github.com/ngnjs/libcrypto).

0 commit comments

Comments
 (0)