Skip to content

Commit

Permalink
chore: clarify usage of JWK epk and proof types for signing
Browse files Browse the repository at this point in the history
  • Loading branch information
mirceanis committed Jun 1, 2021
1 parent 47a70a5 commit 86df3b0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "did-jwt",
"version": "5.5.0",
"description": "Library for Signing and Verifying JWTs that use DIDs as issuers",
"description": "Library for Signing and Verifying JWTs that use DIDs as issuers and JWEs that use DIDs as recipients",
"source": "src/index.ts",
"main": "./lib/index.js",
"exports": "./lib/index.modern.js",
Expand Down
15 changes: 12 additions & 3 deletions src/JWE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@ import { base64ToBytes, bytesToBase64url, decodeBase64url, toSealed } from './ut
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type ProtectedHeader = Record<string, any>

/**
* The JWK representation of an ephemeral public key.
* See https://www.rfc-editor.org/rfc/rfc7518.html#section-6
*/
interface EphemeralPublicKey {
kty: string
crv: string
x: string
kty?: string
//ECC
crv?: string
x?: string
y?: string
//RSA
n?: string
e?: string
}

interface RecipientHeader {
Expand Down
2 changes: 1 addition & 1 deletion src/JWT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type SignerAlgorithm = (payload: string, signer: Signer) => Promise<strin
export type ProofPurposeTypes =
| 'assertionMethod'
| 'authentication'
| 'keyAgreement'
// | 'keyAgreement' // keyAgreement VerificationMethod should not be used for signing
| 'capabilityDelegation'
| 'capabilityInvocation'

Expand Down
4 changes: 2 additions & 2 deletions src/xc20pEncryption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ export function x25519Decrypter(secretKey: Uint8Array): Decrypter {
): Promise<Uint8Array | null> {
validateHeader(recipient?.header)
recipient = <Recipient>recipient
if (recipient.header.epk?.crv !== crv) return null
if (recipient.header.epk?.crv !== crv || typeof recipient.header.epk.x == 'undefined') return null
const publicKey = base64ToBytes(recipient.header.epk.x)
const sharedSecret = sharedKey(secretKey, publicKey)

Expand Down Expand Up @@ -306,7 +306,7 @@ export function xc20pAuthDecrypterEcdh1PuV3x25519WithXc20PkwV2(
): Promise<Uint8Array | null> {
recipient = <Recipient>recipient
validateHeader(recipient.header)
if (recipient.header.epk?.crv !== crv) return null
if (recipient.header.epk?.crv !== crv || typeof recipient.header.epk.x == 'undefined') return null
// ECDH-1PU requires additional shared secret between
// static key of sender and static key of recipient
const publicKey = base64ToBytes(recipient.header.epk.x)
Expand Down

0 comments on commit 86df3b0

Please sign in to comment.