Add examples

This commit is contained in:
2024-06-06 01:51:04 +02:00
parent 44094a31f1
commit c05f0536e2
5 changed files with 78 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
import {expect} from 'bun:test'
import {hkdf, pbkdf, Usage} from '../src/kdf'
import {PrivateWrap, SecretWrap} from '../index'
const salt = new Uint8Array(32)
const pwd = "test"
const keypair = await PrivateWrap.gen_keypair()
const kd = await pbkdf(salt, pwd)
const k = await hkdf(kd, Usage.wrap) as CryptoKey
const cipher = await SecretWrap.encrypt(keypair.privateKey, k)
const box = cipher.toString()
const unbox = SecretWrap.fromString(box)
const plain = await unbox.decrypt(k)
expect(plain).toEqual(keypair.privateKey)
console.log("pwd-wraps-ecdh OK")