2026-07-17 13:50:30 +08:00
|
|
|
import assert from 'node:assert/strict'
|
|
|
|
|
import test from 'node:test'
|
|
|
|
|
|
2026-07-26 23:47:30 +08:00
|
|
|
import { hmacSha256Base64Url, sha256Hex } from '../src/crypto'
|
2026-07-17 13:50:30 +08:00
|
|
|
|
2026-07-26 23:47:30 +08:00
|
|
|
test('sha256Hex uses the canonical lowercase digest', () => {
|
2026-07-17 13:50:30 +08:00
|
|
|
assert.equal(
|
2026-07-26 23:47:30 +08:00
|
|
|
sha256Hex('xuqm'),
|
|
|
|
|
'8d7c5b94129df39d6bec13e9fed29bb15fd1715f2e75a506436d9464bd38250c',
|
2026-07-17 13:50:30 +08:00
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
2026-07-26 23:47:30 +08:00
|
|
|
test('hmacSha256Base64Url returns an unpadded URL-safe value', () => {
|
|
|
|
|
assert.match(hmacSha256Base64Url('secret', 'payload'), /^[A-Za-z0-9_-]+$/)
|
2026-07-17 13:50:30 +08:00
|
|
|
})
|