Skip to content
Verifiabl

.NET verifier SDK: Image extraction

Class in Verifiabl.Verifier.Extraction.Images

The Verifiabl QR code found in an image file.

The payload text is encrypted, but treat it as sensitive and keep it out of logs.

public sealed class ImagePayload

Inheritance: System.Object

Constructor

Create an instance for an adapter or test fake. This reads nothing.

public ImagePayload(string? qrCode)
Parameter Type Description
qrCode System.String

Property

The text of the image’s Verifiabl QR code, unchanged, or null when it has none.

public string? QrCode { get; }

Returns: System.String

Method

Whether a QR code was found only, so the object is safe to log.

public override string ToString()

Returns: System.String

Class in Verifiabl.Verifier.Extraction.Images

Options for reading the QR code in an image file.

public sealed class ImageReadOptions

Inheritance: System.Object

Property

Time budget for reading an image file, including reading a stream, decoding and reading the QR code. Defaults to 30 seconds. It is separate from Verifiabl.Verifier.VerifierClientOptions.Timeout, which covers the verification call that follows.

public TimeSpan Timeout { get; set; }

Returns: System.TimeSpan

Class in Verifiabl.Verifier.Extraction.Images

A verified image file and the QR code read from it.

public sealed class ImageVerificationResult

Inheritance: System.Object

ImageVerificationResult(VerificationResult, ImagePayload)

Section titled “ImageVerificationResult(VerificationResult, ImagePayload)”

Constructor

Create a result for an adapter or test fake. This does not perform verification.

public ImageVerificationResult(VerificationResult verification, ImagePayload payload)
Parameter Type Description
verification Verifiabl.Verifier.VerificationResult
payload Verifiabl.Verifier.Extraction.Images.ImagePayload

Property

The verified payslip data, not an assessment of the image’s visible contents.

public VerificationResult Verification { get; }

Returns: Verifiabl.Verifier.VerificationResult

Property

The QR code read from the image.

public ImagePayload Payload { get; }

Returns: Verifiabl.Verifier.Extraction.Images.ImagePayload

Method

The reference and schema only, so the result is safe to log.

public override string ToString()

Returns: System.String

Class in Verifiabl.Verifier.Extraction.Images

Reads the Verifiabl QR code in a PNG, JPEG or WebP file, such as a photo or screenshot of a payslip.

The file is decoded and its QR codes are read in the WebAssembly sandbox. Only QR codes shaped like a Verifiabl payload are read; other codes in the image are ignored. Scan links are never fetched and the text is returned unchanged.

public static class PayslipImageReader

Inheritance: System.Object

Field

The largest image file read: 20 MiB, the same limit as the Verifiabl portal.

public const int MaxFileBytes = 20971520

Returns: System.Int32

Method

Read the QR code on the calling thread, without a time budget.

public static ImagePayload Read(byte[] file, CancellationToken cancellationToken = default)
Parameter Type Description
file System.Byte[] The image file’s bytes, at most Verifiabl.Verifier.Extraction.Images.PayslipImageReader.MaxFileBytes.
cancellationToken System.Threading.CancellationToken Stops reading within about 50 milliseconds.

Returns: Verifiabl.Verifier.Extraction.Images.ImagePayload, The QR code found, or an empty Verifiabl.Verifier.Extraction.Images.ImagePayload.

Exceptions

Type Condition
Verifiabl.Verifier.PayloadExtractionException The file is too large, cannot be decoded, or shows two different Verifiabl QR codes.
System.InvalidOperationException Wasmtime’s native library could not be loaded.

ReadAsync(byte[], ImageReadOptions?, CancellationToken)

Section titled “ReadAsync(byte[], ImageReadOptions?, CancellationToken)”

Method

Read the QR code within Verifiabl.Verifier.Extraction.Images.ImageReadOptions.Timeout.

Decoding runs on the thread pool, at most one read for each processor at a time across the process, so the time budget ends the wait even if decoding a hostile file is slow. The budget starts once the sandbox’s module is compiled, which the first read in a process waits for; see Verifiabl.Verifier.Extraction.SandboxModule.LoadAsync(System.Threading.CancellationToken).

public static Task<ImagePayload> ReadAsync(byte[] file, ImageReadOptions? options = null, CancellationToken cancellationToken = default)
Parameter Type Description
file System.Byte[] The image file’s bytes, at most Verifiabl.Verifier.Extraction.Images.PayslipImageReader.MaxFileBytes.
options Verifiabl.Verifier.Extraction.Images.ImageReadOptions Optional settings, such as the time budget.
cancellationToken System.Threading.CancellationToken Cancels reading.

Returns: System.Threading.Tasks.Task{Verifiabl.Verifier.Extraction.Images.ImagePayload}, The QR code found, or an empty Verifiabl.Verifier.Extraction.Images.ImagePayload.

Exceptions

Type Condition
Verifiabl.Verifier.PayloadExtractionException The file is too large, cannot be decoded, shows two different Verifiabl QR codes, or reading took longer than the time budget.
System.InvalidOperationException Wasmtime’s native library could not be loaded.

ReadAsync(Stream, ImageReadOptions?, CancellationToken)

Section titled “ReadAsync(Stream, ImageReadOptions?, CancellationToken)”

Method

Read the QR code from a stream within Verifiabl.Verifier.Extraction.Images.ImageReadOptions.Timeout. The stream is read to its end and not disposed.

The time budget covers reading the stream and decoding it. The stream is only read, never abandoned: if it ignores cancellation, this call waits for its read to return, so the stream is not used after the call ends.

public static Task<ImagePayload> ReadAsync(Stream file, ImageReadOptions? options = null, CancellationToken cancellationToken = default)
Parameter Type Description
file System.IO.Stream The image file’s bytes, at most Verifiabl.Verifier.Extraction.Images.PayslipImageReader.MaxFileBytes.
options Verifiabl.Verifier.Extraction.Images.ImageReadOptions Optional settings, such as the time budget.
cancellationToken System.Threading.CancellationToken Cancels reading.

Returns: System.Threading.Tasks.Task{Verifiabl.Verifier.Extraction.Images.ImagePayload}, The QR code found, or an empty Verifiabl.Verifier.Extraction.Images.ImagePayload.

Exceptions

Type Condition
Verifiabl.Verifier.PayloadExtractionException The file is too large, cannot be decoded, shows two different Verifiabl QR codes, or reading took longer than the time budget.
System.InvalidOperationException Wasmtime’s native library could not be loaded.

Class in Verifiabl.Verifier.Extraction.Images

Verifies a payslip from an image file, such as a photo or screenshot of its QR code.

public static class VerifierClientImageExtensions

Inheritance: System.Object

VerifyImageAsync(IVerifierClient, byte[], ImageReadOptions?, Guid?, CancellationToken)

Section titled “VerifyImageAsync(IVerifierClient, byte[], ImageReadOptions?, Guid?, CancellationToken)”

Method

Read the Verifiabl QR code in a PNG, JPEG or WebP file and verify it with Verifiabl.Verifier.IVerifierClient.VerifyAsync(Verifiabl.Verifier.VerificationRequest,System.Threading.CancellationToken).

Each call without idempotencyKey is a new verification with a new key. To retry a failed call without a second charge, pass the failure’s Verifiabl.Verifier.VerifierException.IdempotencyKey within 1 hour.

Reading takes up to Verifiabl.Verifier.Extraction.Images.ImageReadOptions.Timeout and verification up to the client’s own timeout, so the call can take their sum.

public static Task<ImageVerificationResult> VerifyImageAsync(this IVerifierClient client, byte[] file, ImageReadOptions? options = null, Guid? idempotencyKey = null, CancellationToken cancellationToken = default)
Parameter Type Description
client Verifiabl.Verifier.IVerifierClient Any verifier client, including a fake or decorator.
file System.Byte[] The image file’s bytes, at most Verifiabl.Verifier.Extraction.Images.PayslipImageReader.MaxFileBytes.
options Verifiabl.Verifier.Extraction.Images.ImageReadOptions Optional settings, such as the time budget.
idempotencyKey System.Nullable{System.Guid} The key of an earlier attempt to verify this image, from Verifiabl.Verifier.VerifierException.IdempotencyKey or one you saved before the first attempt, or null for a new verification. See Verifiabl.Verifier.VerificationRequest.IdempotencyKey.
cancellationToken System.Threading.CancellationToken Cancels reading and verification.

Returns: System.Threading.Tasks.Task{Verifiabl.Verifier.Extraction.Images.ImageVerificationResult}, The verified payslip and the QR code it was read from.

Exceptions

Type Condition
Verifiabl.Verifier.PayloadExtractionException No single Verifiabl QR code could be read. Nothing was sent to Verifiabl.
Verifiabl.Verifier.VerifierException The payload could not be verified, or verification could not be completed; see Verifiabl.Verifier.IVerifierClient.VerifyAsync(Verifiabl.Verifier.VerificationRequest,System.Threading.CancellationToken).
System.InvalidOperationException Wasmtime’s native library could not be loaded.

VerifyImageAsync(IVerifierClient, Stream, ImageReadOptions?, Guid?, CancellationToken)

Section titled “VerifyImageAsync(IVerifierClient, Stream, ImageReadOptions?, Guid?, CancellationToken)”

Method

Read the Verifiabl QR code in an image stream and verify it. The stream is read to its end and not disposed.

Each call without idempotencyKey is a new verification with a new key. To retry a failed call without a second charge, pass the failure’s Verifiabl.Verifier.VerifierException.IdempotencyKey within 1 hour.

Reading takes up to Verifiabl.Verifier.Extraction.Images.ImageReadOptions.Timeout and verification up to the client’s own timeout, so the call can take their sum.

public static Task<ImageVerificationResult> VerifyImageAsync(this IVerifierClient client, Stream file, ImageReadOptions? options = null, Guid? idempotencyKey = null, CancellationToken cancellationToken = default)
Parameter Type Description
client Verifiabl.Verifier.IVerifierClient Any verifier client, including a fake or decorator.
file System.IO.Stream The image file’s bytes, at most Verifiabl.Verifier.Extraction.Images.PayslipImageReader.MaxFileBytes.
options Verifiabl.Verifier.Extraction.Images.ImageReadOptions Optional settings, such as the time budget.
idempotencyKey System.Nullable{System.Guid} The key of an earlier attempt to verify this image, from Verifiabl.Verifier.VerifierException.IdempotencyKey or one you saved before the first attempt, or null for a new verification. See Verifiabl.Verifier.VerificationRequest.IdempotencyKey.
cancellationToken System.Threading.CancellationToken Cancels reading and verification.

Returns: System.Threading.Tasks.Task{Verifiabl.Verifier.Extraction.Images.ImageVerificationResult}, The verified payslip and the QR code it was read from.

Exceptions

Type Condition
Verifiabl.Verifier.PayloadExtractionException No single Verifiabl QR code could be read. Nothing was sent to Verifiabl.
Verifiabl.Verifier.VerifierException The payload could not be verified, or verification could not be completed; see Verifiabl.Verifier.IVerifierClient.VerifyAsync(Verifiabl.Verifier.VerificationRequest,System.Threading.CancellationToken).
System.InvalidOperationException Wasmtime’s native library could not be loaded.