Add examples
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
import {expect} from 'bun:test'
|
||||
|
||||
import {PrivateWrap} from '../index'
|
||||
|
||||
const key_wraps = await PrivateWrap.gen_keypair()
|
||||
const key_wrapped = await PrivateWrap.gen_keypair()
|
||||
|
||||
const cipher = await PrivateWrap.encrypt(key_wrapped.privateKey, key_wraps.publicKey)
|
||||
const box = await cipher.toString()
|
||||
const unbox = await PrivateWrap.fromString(box)
|
||||
const plain = await unbox.decrypt(key_wraps.privateKey)
|
||||
|
||||
expect(plain).toEqual(key_wrapped.privateKey)
|
||||
console.log("ecdh-wraps-ecdh OK")
|
||||
@@ -0,0 +1,14 @@
|
||||
import {expect} from 'bun:test'
|
||||
|
||||
import {PrivateWrap, SecretBox} from '../index'
|
||||
|
||||
const k_wraps = await PrivateWrap.gen_keypair()
|
||||
const k_wrapped = await SecretBox.gen_key()
|
||||
|
||||
const cipher = await PrivateWrap.encrypt(k_wrapped, k_wraps.publicKey)
|
||||
const box = await cipher.toString()
|
||||
const unbox = await PrivateWrap.fromString(box)
|
||||
const plain = await unbox.decrypt(k_wraps.privateKey) as CryptoKey
|
||||
|
||||
expect(plain).toEqual(k_wrapped)
|
||||
console.log("ecdh-wraps-key OK")
|
||||
@@ -0,0 +1,14 @@
|
||||
import {expect} from 'bun:test'
|
||||
|
||||
import {SecretWrap, PrivateWrap} from '../index'
|
||||
|
||||
const key_wraps = await SecretWrap.gen_key()
|
||||
const key_wrapped = await PrivateWrap.gen_keypair()
|
||||
|
||||
const cipher = await SecretWrap.encrypt(key_wrapped.privateKey, key_wraps)
|
||||
const box = cipher.toString()
|
||||
const unbox = SecretWrap.fromString(box)
|
||||
const plain = await unbox.decrypt(key_wraps)
|
||||
|
||||
expect(plain).toEqual(key_wrapped.privateKey)
|
||||
console.log("key-wraps-ecdh OK")
|
||||
@@ -0,0 +1,17 @@
|
||||
import {expect} from 'bun:test'
|
||||
|
||||
import {hkdf, pbkdf, Usage} from '../src/kdf'
|
||||
import {get_pubkey, sign, verify} from '../src/signature'
|
||||
|
||||
const salt = new Uint8Array(32)
|
||||
const pwd = "test"
|
||||
const message = new TextEncoder().encode("Yeet")
|
||||
|
||||
const kd = await pbkdf(salt, pwd)
|
||||
const privk = await hkdf(kd, Usage.sign) as Uint8Array
|
||||
const pubk = await get_pubkey(privk)
|
||||
|
||||
const sig = await sign(message, privk)
|
||||
const verification = await verify(message, pubk, sig)
|
||||
expect(verification).toBeTrue()
|
||||
console.log("pwd-to-signing OK")
|
||||
@@ -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")
|
||||
Reference in New Issue
Block a user