Skip to content

Commit

Permalink
chore: avoid adding subtyp if doc number not set
Browse files Browse the repository at this point in the history
  • Loading branch information
mastro993 committed Nov 19, 2024
1 parent 642b76b commit 487e770
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/credential/trustmark/get-credential-trustmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type GetCredentialTrustmarkJwt = (
walletInstanceAttestation: string,
wiaCryptoContext: CryptoContext,
credentialType: string,
documentNumber?: string
docNumber?: string
) => Promise<string>;

/**
Expand All @@ -16,15 +16,15 @@ 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.
*/
export const getCredentialTrustmarkJwt: GetCredentialTrustmarkJwt = async (
walletInstanceAttestation,
wiaCryptoContext,
credentialType,
documentNumber
docNumber
): Promise<string> => {
/**
* Check that the public key used to sign the trustmark is the one used for the WIA
Expand All @@ -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
*/
Expand All @@ -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")
Expand Down

0 comments on commit 487e770

Please sign in to comment.