Files
discordeno/packages/utils/tests/verifySignature.spec.ts
Jonathan Ho eaf8782d34 test: fix rest and utils test (#2723)
* test(utils): fix  cant import collection

* test(rest): await expect

* fix(utils): deno compactability

* test(utils): typing

* fix(utils): add return type
2023-01-15 11:04:20 -06:00

40 lines
1.1 KiB
TypeScript

import { expect } from 'chai'
import { afterEach, beforeEach, describe, it } from 'mocha'
import { Buffer } from 'node:buffer'
import Sinon from 'sinon'
import nacl from 'tweetnacl'
// import { verifySignature } from '../src/verifySignature.js'
let verifySignature: any
describe.skip('verifySignature.ts', () => {
let publicKey: Uint8Array
let secretKey: Uint8Array
let clock: Sinon.SinonFakeTimers
beforeEach(() => {
clock = Sinon.useFakeTimers()
;({ publicKey, secretKey } = nacl.sign.keyPair())
})
afterEach(() => {
Sinon.restore()
clock.restore()
})
it('reutrn true if signature is verified', () => {
const timestamp = Date.now().toString()
const body = 'test body'
const signature = nacl.sign.detached(Buffer.from(timestamp + body), secretKey)
const verifiedSignature = verifySignature({
publicKey: Buffer.from(publicKey).toString('hex'),
signature: Buffer.from(signature).toString('hex'),
timestamp,
body,
})
expect(verifiedSignature.body).equal(body)
expect(verifiedSignature.isValid).true
})
})