@hlf-core/common
This is the lowest layer of the whole ecosystem — the part that is tied neither to the runtime
environment nor to any particular side. @hlf-core/common knows nothing about fabric-shim or
fabric-network, and that is exactly why the very same code runs happily in chaincode, on the
backend, and in the frontend. Put simply, this is the shared vocabulary that every other package
speaks.
The central thing here is StateKey, the builder for composite state keys. It is covered in a
separate section, “StateKey and state keys”, because the way a key is
built determines which data queries are even possible.
User identity is described by UserUtil and the IUser<S, R> interface — identifiers of the form
user_<time>_<hash>, roles, status, and a crypto key. This is covered in detail in the
“User identification” section. The crypto key itself is a pair of
“value and algorithm” (CryptoKey / ICryptoKey).
The command model grows from here too. HlfTransportCommand<T> and HlfTransportCommandAsync<U, V>
extend the base commands from @ts-core, adding the isReadonly flag — the very read/write split
that the entire transport rests on. And InitiatedDto adds an initiatorUid field to any DTO:
sometimes it matters to know not only who signed the transaction, but also on whose behalf the
operation was truly initiated, and these are not always the same user.
Finally, domain errors. Error<T>, built on top of ExtendedError from @ts-core, carries a
machine-readable code (ErrorCode), and thanks to that an error raised in chaincode reaches the
client not as a faceless failure but as a clear cause with a code.
const key = new StateKey('→coin~account');
key.key('coin_RUB', 'user_abc'); // →coin~account:coin_RUB~user_abc
key.prefix('coin_RUB'); // →coin~account:coin_RUB~