pub struct AccountId(pub u128);Expand description
128-bit account identity. Deterministic function of the canonical tuple, so
any party that knows (ledger_id, owner, unit, purpose) can derive it with
no allocation-time coordination, and it is TigerBeetle-compatible (TB account
ids are u128).
PLAN DECISION 1: AccountId = blake3_128(canonical_dag_cbor(ledger_id, owner, unit, purpose)). The unit already names its issuer (INV-1), so the
issuer is baked into the id transitively.
§Interop contract — normative account-id encoding
The hashed body is canonical DAG-CBOR (the same wire format
hyprstream-pds::dag_cbor emits: sorted map keys, minimal-width integers,
definite lengths). Account ids are a contract other implementations
re-derive, so the byte layout below is normative — it supersedes the earlier
bespoke length-prefixed encoding.
The body is a single definite-length DAG-CBOR array in this fixed order (no maps, so canonicality needs no key-sorting):
[
"hs-ledger-account-id-v1", // domain-separation tag
<ledger_id : tstr>,
<owner : tstr>,
<unit_issuer: tstr>, // unit.issuer
<unit_code : tstr>, // unit.resource_class
<purpose : purpose-encoding>
]where purpose-encoding is itself canonical DAG-CBOR:
Purpose | encoding |
|---|---|
Available | unsigned 0 |
Escrow { peer_cell } | [1, <peer_cell:tstr>] |
IssuerLiability | unsigned 2 |
Remote { home_cell } | [3, <home_cell:tstr>] |
Bond | unsigned 4 |
The id is the 128-bit blake3 XOF (blake3::Hasher::finalize_xof, 16 bytes,
read big-endian into a u128) of those bytes. Two implementations that agree
on this layout derive byte-identical ids.
Tuple Fields§
§0: u128Implementations§
Source§impl AccountId
impl AccountId
Sourcepub fn derive(
ledger_id: &Did,
owner: &Did,
unit: &UnitId,
purpose: &Purpose,
) -> Result<Self, LedgerError>
pub fn derive( ledger_id: &Did, owner: &Did, unit: &UnitId, purpose: &Purpose, ) -> Result<Self, LedgerError>
Derive the canonical account id over the normative DAG-CBOR encoding
(see the AccountId rustdoc for the interop wire format).
Returns Result because the CBOR serializer is fallible at the API
level (ciborium::into_writer). Over this fixed set of small types
(text strings, small unsigned ints, definite-length arrays) an encode
error is unreachable in practice; rather than unwrap (lint-denied) we
map the impossible failure to LedgerError::Internal, which is
fail-closed and retryable. Call sites propagate it.