Kill the Clipboard - SMART Health Cards Library - v1.0.0
    Preparing search index...

    Function encryptSHLFile

    • Encrypts content as JWE Compact using A256GCM direct encryption.

      Follows the SMART Health Links specification for file encryption using:

      • Direct key agreement (alg: 'dir')
      • AES-256-GCM encryption (enc: 'A256GCM')
      • Optional raw DEFLATE compression (zip: 'DEF')
      • Content type in protected header (cty: contentType)

      Parameters

      • params: {
            content: string;
            contentType: SHLFileContentType;
            enableCompression?: boolean;
            key: string;
        }
        • content: string

          Content to encrypt as a UTF-8 string

        • contentType: SHLFileContentType

          MIME content type for the cty header. Used by decryption to identify file format. Typically 'application/smart-health-card' or 'application/fhir+json'.

        • OptionalenableCompression?: boolean

          Whether to compress content with raw DEFLATE before encryption. Recommended for verbose content like FHIR JSON. Not recommended for already-compressed content like SMART Health Cards.

        • key: string

          256-bit encryption key encoded as base64url (43 characters). Should be generated using cryptographically secure random bytes.

      Returns Promise<string>

      JWE Compact serialization string (5 base64url parts separated by dots)

      SHLEncryptionError When encryption fails due to invalid key, content, or crypto operations

      // Encrypt FHIR resource with compression
      const fhirJson = JSON.stringify(myFhirBundle);
      const jwe = await encryptSHLFile({
      content: fhirJson,
      key: 'abc123...', // 43-char base64url key
      contentType: 'application/fhir+json',
      enableCompression: true
      });

      // Encrypt SMART Health Card without compression
      const shcJson = JSON.stringify({ verifiableCredential: [jwsString] });
      const jwe = await encryptSHLFile({
      content: shcJson,
      key: 'abc123...', // same key as above
      contentType: 'application/smart-health-card',
      enableCompression: false
      });