Initial release of Web Tools 0.0.5

This commit is contained in:
mid
2026-08-07 21:51:15 +08:00
commit fa14e9e5b9
71 changed files with 6365 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
import { describe, expect, it } from 'vitest'
import { formatBytes, parseHex } from '../src/lib/bytes'
import { base64UrlToHex, formatPem, generateRsaKeyPair } from '../src/lib/rsa'
describe('RSA key generation', () => {
it('formats DER and JWK integer values', () => {
expect(formatPem(Uint8Array.from([0, 1, 2, 3]), 'PUBLIC KEY')).toBe('-----BEGIN PUBLIC KEY-----\nAAECAw==\n-----END PUBLIC KEY-----\n')
expect(base64UrlToHex('AQAB')).toBe('010001')
})
it('generates an exportable 2048-bit key pair using a cryptographic provider', async () => {
const result = await generateRsaKeyPair(2048)
expect(result.publicKeyPem).toMatch(/^-----BEGIN PUBLIC KEY-----/)
expect(result.privateKeyPem).toMatch(/^-----BEGIN PRIVATE KEY-----/)
expect(result.modulusHex).toHaveLength(512)
expect(result.exponentHex).toBe('010001')
expect(formatBytes(parseHex(result.exponentHex), { format: 'byte-array' })).toBe('0x01, 0x00, 0x01')
expect(['Web Crypto', 'node-forge']).toContain(result.source)
}, 20_000)
})