Skip to content
Verifiabl

.NET verifier SDK: Extraction

Class in Verifiabl.Verifier.Extraction

An image’s pixels, for reading its Verifiabl QR code with Verifiabl.Verifier.Extraction.QrPayloadReader.

Decode the image file with your own imaging library, then pass its pixels here: rows from top to bottom, tightly packed with no row padding. Alpha is not premultiplied; transparent pixels read as white. The SDK keeps a reference to the array, so do not change it while it is being read.

public sealed class QrImage

Inheritance: System.Object

Field

The largest image the SDK reads: 50 megapixels, more than an A4 page scanned at 600 dpi.

public const int MaxPixels = 50000000

Returns: System.Int32

Property

The image’s width in pixels.

public int Width { get; }

Returns: System.Int32

Property

The image’s height in pixels.

public int Height { get; }

Returns: System.Int32

Method

Pixels with 4 bytes each, in red, green, blue, alpha order.

public static QrImage FromRgba32(byte[] pixels, int width, int height)
Parameter Type Description
pixels System.Byte[]
width System.Int32
height System.Int32

Returns: Verifiabl.Verifier.Extraction.QrImage

Exceptions

Type Condition
System.ArgumentException The size is out of range or does not match the buffer.

Method

Pixels with 4 bytes each, in blue, green, red, alpha order, as Windows and Skia often store them.

public static QrImage FromBgra32(byte[] pixels, int width, int height)
Parameter Type Description
pixels System.Byte[]
width System.Int32
height System.Int32

Returns: Verifiabl.Verifier.Extraction.QrImage

Exceptions

Type Condition
System.ArgumentException The size is out of range or does not match the buffer.

Method

Greyscale pixels with 1 byte each.

public static QrImage FromGray8(byte[] pixels, int width, int height)
Parameter Type Description
pixels System.Byte[]
width System.Int32
height System.Int32

Returns: Verifiabl.Verifier.Extraction.QrImage

Exceptions

Type Condition
System.ArgumentException The size is out of range or does not match the buffer.

Class in Verifiabl.Verifier.Extraction

Reads the Verifiabl QR code in pixels that you decoded with your own imaging library.

The pixels are read in the WebAssembly sandbox with ZXing-C++, as an image file is, so a code reads the same from a file and from its pixels. 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.

The sandbox covers only the QR read. Your imaging library decodes the file in your process, where the sandbox does not contain it. To decode an untrusted file in the sandbox too, use Verifiabl.Verifier.Extraction.Images.PayslipImageReader.

public static class QrPayloadReader

Inheritance: System.Object

Method

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

Copies of the same payload count once.

public static string? Read(QrImage image, CancellationToken cancellationToken = default)
Parameter Type Description
image Verifiabl.Verifier.Extraction.QrImage The image’s pixels.
cancellationToken System.Threading.CancellationToken Stops reading within about 50 milliseconds.

Returns: System.String, The QR code text, unchanged, or null when the image has no readable Verifiabl QR code.

Exceptions

Type Condition
Verifiabl.Verifier.PayloadExtractionException The image has two different Verifiabl QR codes, or reading it needs more memory or finds more QR code text than a payslip needs.
System.OperationCanceledException cancellationToken was cancelled.
System.InvalidOperationException Wasmtime’s native library could not be loaded.

ReadAsync(QrImage, QrReadOptions?, CancellationToken)

Section titled “ReadAsync(QrImage, QrReadOptions?, CancellationToken)”

Method

Read the QR code within Verifiabl.Verifier.Extraction.QrReadOptions.Timeout.

Reading runs on the thread pool, at most one read for each processor at a time across the process, and the sandbox stops it when the time budget runs out. 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). The pixels are copied into the sandbox when the read starts, so do not change the array until the call ends. The call does not end while that copy runs, so the array is yours again afterwards, whatever the outcome.

public static Task<string?> ReadAsync(QrImage image, QrReadOptions? options = null, CancellationToken cancellationToken = default)
Parameter Type Description
image Verifiabl.Verifier.Extraction.QrImage The image’s pixels.
options Verifiabl.Verifier.Extraction.QrReadOptions Optional settings, such as the time budget.
cancellationToken System.Threading.CancellationToken Cancels reading.

Returns: System.Threading.Tasks.Task{System.String}, The QR code text, unchanged, or null when the image has no readable Verifiabl QR code.

Exceptions

Type Condition
Verifiabl.Verifier.PayloadExtractionException The image has two different Verifiabl QR codes, reading it needs more memory or finds more QR code text than a payslip needs, or reading took longer than the time budget.
System.OperationCanceledException cancellationToken was cancelled.
System.InvalidOperationException Wasmtime’s native library could not be loaded.

Class in Verifiabl.Verifier.Extraction

Options for reading the QR code in an image’s pixels.

public sealed class QrReadOptions

Inheritance: System.Object

Property

Time budget for reading the pixels. 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

The WebAssembly module that reads every PDF, image file and pixel buffer.

The decoders run in a WebAssembly module that imports nothing, so they cannot open files, use the network or read the process’s memory. Each read gets a new instance, capped at 512 MiB, that stops soon after its time budget ends or its cancellation token is cancelled. A file that makes the decoders misbehave is reported as unreadable.

public static class SandboxModule

Inheritance: System.Object

Field

The largest file a reader accepts: 20 MiB.

public const int MaxFileBytes = 20971520

Returns: System.Int32

Method

Compile the module now, instead of during the first read.

The first use in a process compiles the module, which takes about 2 seconds and longer on a busy machine. Later calls return at once. Each ReadAsync and verify method awaits this before its time budget starts, so the budget covers only the file. Call it at startup so the first file does not wait.

public static Task LoadAsync(CancellationToken cancellationToken = default)
Parameter Type Description
cancellationToken System.Threading.CancellationToken Ends the wait. Compiling continues, so a later call finds it done.

Returns: System.Threading.Tasks.Task, A task that completes when the module is ready to read files.

Exceptions

Type Condition
System.OperationCanceledException cancellationToken was cancelled.
System.InvalidOperationException The sandbox itself could not start, such as when Wasmtime’s native library could not be loaded.