Skip to content

Commit

Permalink
SignJWT does not require a PK
Browse files Browse the repository at this point in the history
  • Loading branch information
mattschoch committed Mar 26, 2024
1 parent ada6ac7 commit 9498abc
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/signature/src/lib/sign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -31,10 +29,12 @@ export async function signJwt(
opts: { alg?: SigningAlg } = {},
signer?: (payload: string) => Promise<string>
): Promise<string> {
const pk = validate<PrivateKey>(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'
}

Expand Down

0 comments on commit 9498abc

Please sign in to comment.