Skip to content

MAKS11060/ed25519-verify-request

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ed25519 Verify request

Request validation using the Ed25519 algorithm.

Install

npm install @maks11060/ed25519-verify-request
pnpm add @maks11060/ed25519-verify-request

Usage

import {verify, getCryptoKey} from '@maks11060/ed25519-verify-request'

const publicKey = env['PUBLIC_KEY']
const cryptoKey = await getCryptoKey(publicKey)

if (await verify(request, cryptoKey)) {
  return new Response('Verify')
}

Example

import {verify, getCryptoKey} from '@maks11060/ed25519-verify-request'

const request = new Request(new URL('https://localhost.com'), {
  method: 'POST',
  headers: {
    'X-Signature-Ed25519': '99c4903df0b00ac32ba158db956ee39586adf05fea6be714055ac79a80bfd9dff59399b7da01ced95d0a252daee6bdb07e5f59cc546322bb779fd749b04f170c',
    'X-Signature-Timestamp': '202204091535',
  },
  body: new TextEncoder().encode('testmessage'),
})

const publicKey = '9c7d775851a98ceb09a80928c1f8ff56706a0f5d91d841c72850fcd92e065b8f'
const cryptoKey = await getCryptoKey(publicKey)

await verify(request, cryptoKey) // true

Api

  • getCryptoKey() Import Ed25519 Public key to CryptoKey

  • verify(request, key) return Boolean

About

Request verify using the Ed25519 alg.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published