Blob
Reference for mo:core/Blob in the core library.
Blob is the binary value surface for serialization, certified data, and
principal conversions. Its conversion and hashing functions are trusted runtime
wrappers; Blob.Spec.size is the proof-facing abstraction used by contracts.
Import
mo:core/Blob
Status
- Runtime module
Public API
Types
Blob
Modules
Spec
Functions
empty() : Blob
Constructs the empty value for this module's data structure.
Contract
ensures size(result) == 0;
ensures isEmpty(result);
Use when: code or specifications need this operation with the documented contract.
isEmpty(blob : Blob) : Bool
Checks the predicate described by the return contract.
Contract
ensures result == (size(blob) == 0);
Use when: a branch condition or contract needs this predicate as a named fact.
size(blob : Blob) : Nat
Returns the length or cardinality represented by the value.
Contract
ensures result == Spec.size(blob);
Use when: code or specifications need this operation with the documented contract.
fromArray(bytes : [Nat8]) : Blob
Converts between the module type and the target representation.
Contract
ensures size(result) == bytes.size();
Use when: crossing between this module's value and another representation.
fromVarArray(bytes : [var Nat8]) : Blob
Converts between the module type and the target representation.
Contract
ensures size(result) == bytes.size();
Use when: crossing between this module's value and another representation.
toArray(blob : Blob) : [Nat8]
Converts between the module type and the target representation.
Contract
ensures result.size() == size(blob);
Use when: crossing between this module's value and another representation.
toVarArray(blob : Blob) : [var Nat8]
Converts between the module type and the target representation.
Contract
ensures result.size() == size(blob);
Use when: crossing between this module's value and another representation.
hash(blob : Blob) : Types.Hash
Computes the core hash value for a blob.
Use when: code needs the core hash value for a blob.
compare(b1 : Blob, b2 : Blob) : Types.Order
Compares the supplied values and relates the result to the underlying order.
Contract
ensures result == #less ==> b1 < b2;
ensures result == #equal ==> b1 == b2;
ensures result == #greater ==> b1 > b2;
ensures b1 < b2 ==> result == #less;
ensures b1 == b2 ==> result == #equal;
ensures b1 > b2 ==> result == #greater;
Use when: code or contracts need an explicit comparison helper instead of an operator.
equal(blob1 : Blob, blob2 : Blob) : Bool
Compares the supplied values and relates the result to the underlying order.
Contract
ensures result == (blob1 == blob2);
Use when: code or contracts need an explicit comparison helper instead of an operator.
notEqual(blob1 : Blob, blob2 : Blob) : Bool
Compares the supplied values and relates the result to the underlying order.
Contract
ensures result == (blob1 != blob2);
Use when: code or contracts need an explicit comparison helper instead of an operator.
less(blob1 : Blob, blob2 : Blob) : Bool
Compares the supplied values and relates the result to the underlying order.
Contract
ensures result == (blob1 < blob2);
Use when: code or contracts need an explicit comparison helper instead of an operator.
lessOrEqual(blob1 : Blob, blob2 : Blob) : Bool
Compares the supplied values and relates the result to the underlying order.
Contract
ensures result == (blob1 <= blob2);
Use when: code or contracts need an explicit comparison helper instead of an operator.
greater(blob1 : Blob, blob2 : Blob) : Bool
Compares the supplied values and relates the result to the underlying order.
Contract
ensures result == (blob1 > blob2);
Use when: code or contracts need an explicit comparison helper instead of an operator.
greaterOrEqual(blob1 : Blob, blob2 : Blob) : Bool
Compares the supplied values and relates the result to the underlying order.
Contract
ensures result == (blob1 >= blob2);
Use when: code or contracts need an explicit comparison helper instead of an operator.
Spec Module
Spec Functions
size(blob : Blob) : Nat
Provides a ghost/spec-only abstraction for contracts and proofs.
Use when: Use in contracts, ghost code, or lemmas when the runtime value needs an abstract proof model.
Summary
- Runtime module under
mo:core/Blob. - Exposes 15 public functions.
- Includes 1 spec helpers in
Spec.