Get the expiration date as Unix timestamp if set.
Returns the expiration time in seconds since Unix epoch (1970-01-01),
suitable for use in the SHL payload exp
field.
Unix timestamp in seconds, or undefined if no expiration set
Get the expiration date as a Date object if set.
Date object representing expiration time, or undefined if no expiration set
Get the SHL flags if set.
Returns the flag string indicating SHL capabilities.
Flag string, or undefined if no flags set
Get the server-generated ID for database if set.
Returns the optional ID that can be used by server implementations to identify this SHL in the DB.
Server-generated ID string, or undefined if no ID was provided
Check if this SHL is a direct-file link (bypasses manifest).
Returns true if the SHL has the 'U' flag, indicating that the url
points
directly to a single encrypted file retrievable via GET.
Check if this SHL supports long-term access with updates.
Returns true if the SHL has the 'L' flag, indicating that clients may poll the manifest URL for updates over time.
True if long-term access is supported, false otherwise
Get the base64url-encoded encryption key for files.
Returns the 256-bit symmetric encryption key used for JWE file encryption, encoded as base64url (always 43 characters).
Base64url-encoded encryption key (43 characters)
Get the human-readable label if set.
Returns the optional short description of the shared data. Maximum length is 80 characters as per SHL specification.
Label string, or undefined if no label set
Get the complete SHL payload object for serialization.
Returns the payload structure that gets base64url-encoded in the SHL URI. Includes all fields: url, key, version, and optional exp, flag, label.
SHL payload object conforming to v1 specification
Check if this SHL requires a passcode for access.
Returns true if the SHL has the 'P' flag, indicating that a passcode must be provided when fetching the manifest.
True if passcode is required, false otherwise
Get the full manifest URL that servers must handle.
Returns the complete HTTPS URL where the manifest can be fetched via POST request as specified in the SMART Health Links protocol.
Complete manifest URL (e.g., 'https://shl.example.org/manifests/abc123.../manifest.json')
Get the SHL payload version.
Always returns 1 for the current SMART Health Links v1 specification.
Version number (always 1)
Generate a QR code as a Data URL for the SHL URI.
Creates a QR code image encoded as a base64 Data URL that can be used directly in HTML img tags or displayed in applications.
Optional
params: SHLQREncodeParamsOptional QR code generation options. The object can contain:
viewerURL
: URL of the SHL viewer to prefix the QR code like https://example.org/viewer#shlink:/... (default: no URL)width
: Width of the QR code image in pixels (default: 256)margin
: Margin around the QR code in modules (default: 1)errorCorrectionLevel
: Error correction level 'L', 'M', 'Q', or 'H' (default: 'M', per spec)color
: Color options for dark and light modulesPromise that resolves to a Data URL string
const shl = SHL.generate({
baseManifestURL: 'https://shl.example.org',
manifestPath: '/manifest.json'
});
const qrCodeDataURL = await shl.asQR();
// Use in HTML: <img src={qrCodeDataURL} alt="SHL QR Code" />
// With custom options
const customQR = await shl.asQR({
width: 512,
errorCorrectionLevel: 'H',
color: { dark: '#000000', light: '#FFFFFF' }
});
Static
fromStatic factory method to create an SHL from a parsed payload.
This method is used internally by SHLViewer to reconstruct SHL objects from parsed SHL URIs. It does not generate new keys or paths, but uses the provided values from an existing payload.
Validated SHL payload from a parsed URI
Optional
id: stringOptional server-generated ID for database
SHL instance reconstructed from the payload
Static
generateCreate an immutable SHL representing a SMART Health Link payload and URI.
The SHL payload contains a cryptographically secure manifest URL and encryption key.
The manifest URL is constructed as: ${baseManifestURL}/${entropy}/${manifestPath}
where entropy
is a
32-byte base64url string (43 chars). The encryption key is a separate 32-byte base64url string (43 chars)
placed in the SHL payload key
.
Base URL for constructing manifest URLs (e.g., 'https://shl.example.org/manifests/')
Optional
expirationDate?: DateOptional expiration date for the SHL. When set, fills the exp
field in the SHL payload with Unix timestamp.
Optional
flag?: SHLFlagOptional flag for the SHL (see SHLFlag)
Optional
id?: stringOptional server-generated ID for database.
Optional
label?: stringOptional short description of the shared data. Maximum 80 characters.
Optional
manifestPath?: stringOptional manifestPath for constructing manifest URLs (e.g., '/manifest.json')
New SHL instance with generated full manifest URL and encryption key
SHLFormatError When label exceeds 80 characters
// SHL with server-generated ID and passcode protection
const shl = SHL.generate({
id: 'server-generated-uuid',
baseManifestURL: 'https://shl.example.org',
manifestPath: '/manifest.json',
expirationDate: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000), // 30 days
flag: 'P',
label: 'Lab Results - Valid for 30 days'
});
Static
parseStatic method to parse a SHL URI into an SHL object.
Handles both bare SHL URIs and viewer-prefixed URIs:
shlink:/eyJ1cmwiOi4uLn0
(bare)https://viewer.example/#shlink:/eyJ1cmwiOi4uLn0
(viewer-prefixed)Validates URI format, decodes base64url payload, parses JSON, and validates payload structure according to SHL specification.
SHL URI to parse
SHL instance with parsed payload data
SHLFormatError When URI format is invalid, payload cannot be decoded, or payload structure is invalid
Generate the SHL URI following the SMART Health Links specification.
Creates a shlink:/
URI with base64url-encoded JSON payload containing
the manifest URL, encryption key, and optional metadata (expiration, flags, label).
SHL URI string in format shlink:/<base64url-encoded-payload>
// SHL with expiration and passcode protection
const shl = SHL.generate({
baseManifestURL: 'https://shl.example.org',
manifestPath: '/manifest.json',
expirationDate: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000), // 30 days
flag: 'P',
label: 'Lab Results - Valid for 30 days'
});
// Generate the SHL URI
const uri = shl.toURI();
// Returns: shlink:/eyJ1cmwiOiJodHRwczovL3NobC5leGFtcGxlLm9yZy9tYW5pZmVzdHMvLi4uXCIsXCJrZXlcIjpcIi4uLlwiLFwidlwiOjF9
Immutable SHL class representing a SMART Health Link payload and URI.
This class handles the SHL "pointer" - the payload containing url, key, flags, etc. It provides methods to generate SHL URIs and access payload properties. Use SHLManifestBuilder to manage the manifest and files referenced by this SHL.
SMART Health Links enable secure sharing of health data through encrypted links. The SHL contains a manifest URL and encryption key, allowing recipients to fetch and decrypt the shared health information.
Example