Envelope class

Envelope contains an arbitrary Uint8List payload, signed by a libp2p peer.

Envelopes are signed in the context of a particular "domain", which is a string specified when creating and verifying the envelope. You must know the domain string used to produce the envelope in order to verify the signature and access the payload.

Constructors

Envelope.new({required PublicKey publicKey, required Uint8List payloadType, required Uint8List rawPayload, required Uint8List signature})

Properties

hashCode int
The hash code for this object.
no setterinherited
payloadType Uint8List
A binary identifier that indicates what kind of data is contained in the payload.
final
publicKey PublicKey
The public key that can be used to verify the signature and derive the peer id of the signer.
final
rawPayload Uint8List
The envelope payload.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

equal(Envelope? other) bool
Returns true if the other Envelope has the same public key, payload, payload type, and signature.
marshal() Future<Uint8List>
Returns a byte slice containing a serialized protobuf representation of an Envelope.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
record() Future<PeerRecord>
Returns the Envelope's payload unmarshalled as a RecordBase. The concrete type of the returned RecordBase depends on which RecordBase type was registered for the Envelope's payloadType.
toString() String
A string representation of this object.
inherited
typedRecord(RecordBase destRecord) Future<void>
Unmarshals the Envelope's payload to the given RecordBase instance.
validate(String domain) Future<void>
Returns null if the envelope signature is valid for the given 'domain', or throws an error if signature validation fails.

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

consumeEnvelope(Uint8List data, String domain) Future<(Envelope, RecordBase)>
Unmarshals a serialized Envelope and validates its signature using the provided 'domain' string. If validation fails, an error is returned.
consumeTypedEnvelope<T extends RecordBase>(Uint8List data, RecordBase destRecord) Future<Envelope>
Unmarshals a serialized Envelope and validates its signature. Unlike consumeEnvelope, this method does not try to automatically determine the type of RecordBase to unmarshal the Envelope's payload into.
seal(RecordBase rec, PrivateKey privateKey) Future<Envelope>
Creates a new envelope by marshaling the given RecordBase, placing the marshaled bytes inside an Envelope, and signing with the given private key.