Remove pwd and jwt (server only)

Closes #9
This commit is contained in:
2024-05-14 14:38:30 +02:00
parent 968292713f
commit 605cab4c85
5 changed files with 1 additions and 54 deletions
-2
View File
@@ -1,4 +1,2 @@
export * as JWT from 'jwt'
export * as pwd from 'pwd'
export * as signature from 'signature'
export * as boxes from 'boxes'
+1 -2
View File
@@ -1,6 +1,6 @@
{
"name": "crypto",
"description": "Various crypto utils for hashing, encryption, signature, ...",
"description": "Various crypto utils for encryption, signature, ...",
"module": "index.ts",
"type": "module",
"files": ["index.ts"],
@@ -8,7 +8,6 @@
"test": "bun test"
},
"dependencies": {
"jose": "^5.3.0",
"log": "^6.3.1",
"result": "git+git@git.pband.ch:typescript/result.git",
"zxcvbn": "^4.4.2"
-8
View File
@@ -1,8 +0,0 @@
export type JWT = `${string}.${string}.${string}`
export function create() : JWT {
throw "todo"
}
export function verify() : boolean {
throw "todo"
}
-7
View File
@@ -1,7 +0,0 @@
export function hash(pwd: string) : Promise<string> {
return Bun.password.hash(pwd)
}
export async function verify(pwd: string, hash: string) : Promise<boolean> {
return Bun.password.verify(pwd, hash).catch(() => false)
}
-35
View File
@@ -1,35 +0,0 @@
import {test, expect} from 'bun:test'
import {pwd} from '../index'
test('base case', async () => {
const password = "AwesomePassword123!"
const hash = await pwd.hash(password)
const verification = await pwd.verify(password, hash)
expect(verification).toBe(true)
})
test('wrong password', async () => {
const password1 = "AwesomePassword123!"
const password2 = "AwesomePassword321!"
expect(password1).not.toEqual(password2)
const hash = await pwd.hash(password1)
const verification = await pwd.verify(password2, hash)
expect(verification).toBe(false)
})
test('salt changes', async () => {
const password = "AwesomePassword123!"
const hash1 = await pwd.hash(password)
const hash2 = await pwd.hash(password)
expect(hash1).not.toEqual(hash2)
})
test('tampered hash', async () => {
const password = "AwesomePassword123"
const hash = await pwd.hash(password)
const tamperedHash = hash.replace('a', 'b')
const verification = await pwd.verify(password, tamperedHash)
expect(verification).toBe(false)
})