From 487e7707ded53770221c2377974e36eb09547593 Mon Sep 17 00:00:00 2001 From: Federico Mastrini Date: Tue, 19 Nov 2024 09:12:23 +0100 Subject: [PATCH] chore: avoid adding `subtyp` if doc number not set --- .../trustmark/get-credential-trustmark.ts | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/credential/trustmark/get-credential-trustmark.ts b/src/credential/trustmark/get-credential-trustmark.ts index 8740cce..1e8c611 100644 --- a/src/credential/trustmark/get-credential-trustmark.ts +++ b/src/credential/trustmark/get-credential-trustmark.ts @@ -7,7 +7,7 @@ export type GetCredentialTrustmarkJwt = ( walletInstanceAttestation: string, wiaCryptoContext: CryptoContext, credentialType: string, - documentNumber?: string + docNumber?: string ) => Promise; /** @@ -16,7 +16,7 @@ export type GetCredentialTrustmarkJwt = ( * @param walletInstanceAttestation the Wallet Instance's attestation * @param wiaCryptoContext The Wallet Instance's crypto context associated with the walletInstanceAttestation parameter * @param credentialType The type of credential for which the trustmark is generated - * @param documentNumber (Optional) Document number contained in the credential, if applicable + * @param docNumber (Optional) Document number contained in the credential, if applicable * @throws {IoWalletError} If the public key associated to the WIA is not the same for the CryptoContext * @returns A promise that resolves to the signed JWT string, representing the credential's trustmark. */ @@ -24,7 +24,7 @@ export const getCredentialTrustmarkJwt: GetCredentialTrustmarkJwt = async ( walletInstanceAttestation, wiaCryptoContext, credentialType, - documentNumber + docNumber ): Promise => { /** * Check that the public key used to sign the trustmark is the one used for the WIA @@ -43,13 +43,6 @@ export const getCredentialTrustmarkJwt: GetCredentialTrustmarkJwt = async ( ); } - /** - * Obfuscate the document number before adding it to the payload - */ - const obfuscatedDocumentNumber = documentNumber - ? obfuscateString(documentNumber) - : undefined; - /** * Generate Trustmark signed JWT */ @@ -60,7 +53,10 @@ export const getCredentialTrustmarkJwt: GetCredentialTrustmarkJwt = async ( .setPayload({ iss: walletInstanceAttestation, sub: credentialType, - subtyp: obfuscatedDocumentNumber, + /** + * If present, the document number is obfuscated before adding it to the payload + */ + ...(docNumber ? { subtyp: obfuscateString(docNumber) } : {}), }) .setIssuedAt() .setExpirationTime("2m")