Skip to content

Commit

Permalink
feat:Sign and verification of JWT HS256 token (#1)
Browse files Browse the repository at this point in the history
* Adds scaffold init script

* Basic scaffolding for a library

* Adds crypt model

* Example with paseto

* Updates links in readme

* Uses faora-kai

* Move away from paseto

* Drafting alligator

* Adds gecko test

* Uses lizard as HS256

* Basic test for lizard

* Successfully test lizard

* Test good and strong strength

* Extract JWT utils

* More specific payload

* Reorg code with class

* Uses store for managing JWT

* some refactoring to deal with type for keys

* Adds lizardVerify

* Combine sign and verify

* decode Jwt

* Extract assertSignAndVerify

* Adds assert-crypt

* Undeclare Result types

* Disable some of the linting that seems hard to solve

* Verify secret and expiration

* Better error messages

* Change error format

* Rename a few models

* Add a failing test for checking previous secret

* Adds optional finalMessage for error

* Support alternative secret

* Adds expected scope

* Basic validation of scope

* Adds custom validator for scope

* Add translucent to lizard name

* Trying to convert enum to list of string

* Uses readonly for prefixes

* Automatically extract prefix name

* A lot of name refactoring and fixed expiration time

* Change constructor args to obj

* Catch errors when signing

* validate payload to sign

* Adds some ts doc

* Updates dependencies

* Adds ts documentation

* Updates readme

* Adds usage.md

* Avoid typing redundant info

* Update readme

* format md
  • Loading branch information
olih authored Jun 3, 2023
1 parent 768aea6 commit 0e0f344
Show file tree
Hide file tree
Showing 41 changed files with 6,124 additions and 1 deletion.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
52 changes: 52 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Bug Report
description: File a bug report
title: "[Bug]: "
labels:
- bug
- triage
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to fill out this bug report!
- type: textarea
id: what-happened
attributes:
label: What happened?
description: Please tell us, what did you expect to happen?
placeholder: Tell us what you see!
value: A bug happened!
validations:
required: true
- type: textarea
id: version
attributes:
label: Version
description: What version of the library are you running?
placeholder: 0.0.0
validations:
required: true
- type: dropdown
id: platform
attributes:
label: On which platform(s) do you have the issue ?
multiple: true
options:
- Any
- Node.js
- Typescript node
- Firefox
- Chrome
- Safari
- Microsoft Edge
- Linux
- Windows
- MacOs
- Other
- type: textarea
id: logs
attributes:
label: Relevant log output
description: Please copy and paste any relevant log output. This will be
automatically formatted into code, so no need for back ticks.
render: shell
56 changes: 56 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Feature request
description: Suggest an idea for this project
title: "[Feature]: "
labels:
- feature
- triage
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to fill out this feature request!
- type: textarea
id: problem
attributes:
label: Describe the problem
description: Is your feature request related to a problem? Please describe.
placeholder: Describe the problem you would like to solve
value: My problem
validations:
required: true
- type: textarea
id: solution
attributes:
label: Describe the solution
description: A clear and concise description of what you want to happen.
placeholder: Tell us what you would like to see!
value: My solution
validations:
required: true
- type: textarea
id: context
attributes:
label: Additional context
description: Add any other context or screenshots about the feature request here.
placeholder: A context
value: The context
validations:
required: true
- type: checkboxes
id: suitability
attributes:
label: Is this new feature a good fit ?
description: Should this new feature really be part of this project
options:
- label: "__Needed__: an existing user is going to need this in the short term"
required: true
- label: "__Specific__: the problem is clearly understood and defined"
required: true
- label: "__Small change__: This new feature represents a reasonably small change"
required: true
- label: "__Same scope__: this new feature does not change significantly the scope
of this project"
required: true
- label: "__Long term maintenance__: moving this to a new project would make long
term maintenance harder"
required: true
36 changes: 36 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Summary of the change

Fixes: # (issue)

## Code check

- [x] `npx baldrick-broth@latest release ready` does not show any
concerning issues

## Type of change

- [ ] Bug fix (non-breaking change which fixes an issue)

- [ ] Safe refactoring (non-breaking change which improves the code or
documentation)

- [ ] New feature (non-breaking change which adds functionality)

- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)

## Motivation and context

- [ ] improve user experience
- [ ] improve consistency
- [ ] improve security
- [ ] improve documentation
- [ ] improve code
- [ ] reduce risk for unfamiliar tasks
- [ ] automate repetitive tasks

## How Has This Been Tested

- [x] Unit tests
- [ ] Automated browser tests
- [ ] Manual tests
48 changes: 48 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: CI
on:
- push
jobs:
build:
name: Build, lint, and test on Node ${{ matrix.node }} and ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
node:
- 18.x
os:
- macOS-latest
- ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Use Node ${{ matrix.node }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- name: Installation
run: yarn install
- name: Create temp folder
run: mkdir temp
- name: Run zest unit tests
run: |
if [ -d "spec" ]; then
npx npx baldrick-broth@latest test spec
else
echo "No zest files. Skipping"
fi
- name: Run pest integration tests
run: |
if [ -d "pest-spec" ]; then
npx npx baldrick-broth@latest test pest
else
echo "No pest files. Skipping"
fi
- name: Build
run: yarn build
- name: Test Report
uses: dorny/test-reporter@v1
if: success() || failure()
with:
name: Pest
path: report/*.pest.mocha.json
reporter: mocha-json
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.log
.DS_Store
node_modules/
dist/
report/
temp/
.message
.todo.yaml
6 changes: 6 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"printWidth": 80,
"semi": true,
"singleQuote": true,
"trailingComma": "es5"
}
6 changes: 6 additions & 0 deletions .remarkrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
settings:
bullet: "*"
plugins:
- remark-preset-lint-consistent
- remark-preset-lint-recommended
- remark-preset-lint-markdown-style-guide
106 changes: 106 additions & 0 deletions .vscode/baldrick.code-snippets
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{
"filter-no-null": {
"scope": "javascript,typescript",
"prefix": "filter-no-null",
"body": "const removeNulls = <S>(value: S | undefined): value is S => value != null;",
"description": "Filter out undefined values"
},
"eslint-disable-line": {
"scope": "javascript,typescript",
"prefix": "eslint-disable-line",
"body": "// eslint-disable-line $0",
"description": "Disable linting a specific Line"
},
"eslint-disable-next-line": {
"scope": "javascript,typescript",
"prefix": "eslint-disable-next-line",
"body": "// eslint-disable-next-line $0",
"description": "Disable linting for next line"
},
"jest-regression-inline": {
"scope": "javascript,typescript",
"prefix": "jest-regression-inline",
"body": [
"import { $1 } from '../src/${TM_FILENAME_BASE/.test//}';",
"",
"describe('${TM_FILENAME_BASE/.test//}', () => {",
" it('should provide', () => {",
" const opts = {};",
" const actual = $1(opts);",
" expect(actual).toMatchInlineSnapshot();",
" });",
"});",
""
],
"description": "Unit test to provide regression with a snapshot"
},
"mock-console": {
"scope": "javascript,typescript",
"prefix": "mock-console",
"body": "jest.spyOn(global.console, \"${1|log,info,warn,error|}\").mockImplementation(() => {});",
"description": "Mock console in unit tests"
},
"stringify": {
"scope": "javascript,typescript",
"prefix": "stringify",
"body": [
"const toJsonString = (value: object): string =>",
" JSON.stringify(value, null, 2);"
],
"description": "stringify an object"
},
"error-message-id": {
"scope": "javascript,typescript",
"prefix": "error-message-id",
"body": [
"($RANDOM)"
],
"description": "Generate an error message id"
},
"add decision": {
"scope": "markdown,md",
"prefix": "add decision",
"body": [
"## Title Fixme",
"",
"* MUST-HAVE.",
"* Created: ${CURRENT_MONTH_NAME} ${CURRENT_YEAR}",
"",
"### Context and Problem Statement",
"",
"> Fixme",
"",
"### Decision Drivers",
"",
"* Fixme",
"",
"### Considered Options",
"",
"* Fixme",
"",
"### Decision Outcome",
"",
"Chosen option: Fixme",
"",
"#### Positive Consequences",
"",
"* Fixme",
"",
"#### Negative Consequences",
"",
"* Fixme",
"",
"### Pros and Cons of the Options",
"",
"#### Option title fixme",
"",
"Description fixme",
"",
"* Pros: ",
" * Fixme",
"* Cons:",
" * Fixme"
],
"description": "Adds architecture decision record"
}
}
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"makefile.extensionOutputFolder": "./.vscode",
"yaml.schemas": {
"./script/schema/project.schema.json": "script/data/project.yaml"
}
}
19 changes: 19 additions & 0 deletions .xo-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"prettier": true,
"nodeVersion": 18,
"envs": [
"es2022",
"node"
],
"rules": {
"unicorn/prevent-abbreviations": "off",
"unicorn/no-array-callback-reference": "off",
"unicorn/prefer-json-parse-buffer": "off",
"unicorn/no-array-reduce": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-floating-promises": "off"

}
}
3 changes: 3 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# API of lunar-obsidian-crypt

> List of functions and variables for `lunar-obsidian-crypt`
Loading

0 comments on commit 0e0f344

Please sign in to comment.