mcl_core_ownership_proof (mcl_core v1.0.0)

View Source

Proof that an identity authorised exactly this request, once: the asserted_by block of a payload (mcl-om#7, mcl-om#7).

The signer sends asserted_by => #{identity => Hex, proof => Proof} beside the fields it authorises. The proof signs the deterministic CBOR (macula_record_cbor:encode/1) of a map with text keys: tag "macula.ownership_proof", v 2, identity (32 bytes), realm (32 bytes), procedure (text), timestamp (ms), nonce (16 bytes) and fields: the payload as the handler receives it, minus asserted_by and minus caller in every key form. caller is never signed: macula_station_link:with_caller/2 merges the authenticated atom caller, and from macula 12.11.1 it also removes a caller-sent text "caller" before the handler runs, so a signed caller could never be rebuilt. Dropping it on both sides gives the same result on any macula version.

The fields are re-encoded raw, never unwrapped: after macula 12's strict decode, text arrives as {text, B} and bytes as B, and those encode as different CBOR types. The one exception is a decoded null, which the frame hands over as undefined and which becomes null again. This departs from macula_signed_object, which signs bytes it never re-encodes, on purpose: what must be bound is what the handler reads, and that exists only as a decoded term.

make/5,6 takes fields in the form an Erlang caller hands macula:call, and applies the frame's own conversion to them (atoms and binary keys to text keys, undefined to null, atom values to text), so the signer encodes what the verifier will rebuild.

Replay: the nonce is recorded in mcl_core_ownership_proof_replay only after the signature has verified, so an identical proof is accepted once. The cache is per instance and empty after a restart, so a captured proof can be accepted once by each instance, and once more after a restart, within its 60 s window.

Summary

Functions

A wire-transported identity (hex text or 32 raw bytes) as its raw bytes.

A wire-transported string as a plain binary; undefined passes through.

The asserted_by block for Fields, signed now by Key for Identity in the realm Realm (32 bytes) and Procedure.

make/5 at a chosen timestamp, so a test can prove a stale proof fails.

The exact bytes that are signed. Exported so another SDK's signer can be checked against it byte for byte.

Verify that Proof shows Identity (32 bytes) authorised the fields of Payload (as the handler received it) for Procedure in Realm.

Verify the asserted_by block of a payload as the handler received it.

Types

fields/0

-type fields() :: #{term() => term()}.

reason/0

-type reason() ::
          missing_proof | unsupported_version | stale_proof | replayed | bad_signature |
          invalid_identity.

Functions

decode_identity(V)

-spec decode_identity(term()) -> binary() | undefined.

A wire-transported identity (hex text or 32 raw bytes) as its raw bytes.

decode_text(V)

-spec decode_text(term()) -> binary() | undefined.

A wire-transported string as a plain binary; undefined passes through.

make(Key, Identity, Realm, Procedure, Fields)

-spec make(macula_node_keys:node_key(), binary(), binary(), binary(), fields()) -> map().

The asserted_by block for Fields, signed now by Key for Identity in the realm Realm (32 bytes) and Procedure.

make(Key, Identity, Realm, Procedure, Fields, Timestamp)

-spec make(macula_node_keys:node_key(), binary(), binary(), binary(), fields(), integer()) -> map().

make/5 at a chosen timestamp, so a test can prove a stale proof fails.

message(Identity, Realm, Procedure, Timestamp, Nonce, Fields)

-spec message(binary(), binary(), binary(), integer(), binary(), fields()) -> binary().

The exact bytes that are signed. Exported so another SDK's signer can be checked against it byte for byte.

verify(Identity, Proof, Procedure, Realm, Payload)

-spec verify(binary(), map(), binary(), binary(), map()) -> ok | {error, reason()}.

Verify that Proof shows Identity (32 bytes) authorised the fields of Payload (as the handler received it) for Procedure in Realm.

verify_asserted_by(Payload, Procedure, Realm)

-spec verify_asserted_by(map(), binary(), binary()) -> ok | {error, reason()}.

Verify the asserted_by block of a payload as the handler received it.