From 9498abc2047bd90a4ba33db3e582c16a30aec790 Mon Sep 17 00:00:00 2001 From: Matt Schoch Date: Tue, 26 Mar 2024 15:08:10 -0400 Subject: [PATCH] SignJWT does not require a PK --- packages/signature/src/lib/sign.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/signature/src/lib/sign.ts b/packages/signature/src/lib/sign.ts index 6692a70de..520e7daa0 100644 --- a/packages/signature/src/lib/sign.ts +++ b/packages/signature/src/lib/sign.ts @@ -4,10 +4,8 @@ import { keccak_256 as keccak256 } from '@noble/hashes/sha3' import { SignJWT, base64url, importJWK } from 'jose' import { isHex, signatureToHex, toBytes, toHex } from 'viem' import { hash } from './hash-request' -import { privateKeySchema } from './schemas' -import { EcdsaSignature, Header, Hex, Jwk, JwsdHeader, Payload, PrivateKey, SigningAlg } from './types' +import { EcdsaSignature, Header, Hex, Jwk, JwsdHeader, Payload, SigningAlg } from './types' import { hexToBase64Url } from './utils' -import { validate } from './validate' export async function signJwsd( rawBody: string | object, @@ -31,10 +29,12 @@ export async function signJwt( opts: { alg?: SigningAlg } = {}, signer?: (payload: string) => Promise ): Promise { - const pk = validate(privateKeySchema, jwk, 'Invalid Private Key JWK') + if (!jwk.kid || !jwk.alg) { + throw new Error('JWK must have a kid and alg') + } const header: Header = { - kid: pk.kid, - alg: opts.alg || pk.alg, // TODO: add separate type for `ES256k-KECCAK` + kid: jwk.kid, + alg: opts.alg || jwk.alg, // TODO: add separate type for `ES256k-KECCAK` typ: 'JWT' }