17 releases (11 major breaking)

14.0.0 Apr 8, 2024
13.0.0 Mar 18, 2024
12.0.0 Feb 26, 2024
11.0.0 Feb 13, 2024
0.1.0-dev.2 Jul 27, 2023

#1028 in Magic Beans

Download history 1086/week @ 2024-01-02 1163/week @ 2024-01-09 809/week @ 2024-01-16 1145/week @ 2024-01-23 689/week @ 2024-01-30 1085/week @ 2024-02-06 1988/week @ 2024-02-13 2080/week @ 2024-02-20 1746/week @ 2024-02-27 1058/week @ 2024-03-05 1185/week @ 2024-03-12 2486/week @ 2024-03-19 1567/week @ 2024-03-26 1816/week @ 2024-04-02 1917/week @ 2024-04-09 1134/week @ 2024-04-16

6,866 downloads per month
Used in 120 crates (6 directly)

Apache-2.0

790KB
15K SLoC

Statement store

Statement store is an off-chain data-store for signed statements accessible via RPC and OCW.

Nodes hold a number of statements with a proof of authenticity owing to an account ID. OCWs can place items in the data-store (with valid signatures) for any accounts whose keys they control. Users can also submit pre-signed statements via RPC. Statements can also be submitted from on-chain logic through an on-chain event.

A new system event NewStatement is added to the runtime. This event allows any account on-chain to declare that they want to make a statement for the store. Within the node store and for broadcasting, the statement would be accompanied with the hash of the block and index of the event within it, essentially taking the place of a real signature.

Statements comprise an optional proof of authenticity (e.g. a signature) and a number of fields. For statements without a proof, nodes would gossip statements randomly with a rate-limiter to minimise the chance of being overrun by a misbehaving node. These will generally be disregarded by nodes unless they are gossiped by several different peers or if a peer pays for it somehow (e.g. gossiping something valuable).

Each field is effectively a key/value pair. Fields must be sorted and the same field type may not be repeated. Depending on which keys are present, clients may index the message for ease of retrieval.

Formally, Statement is equivalent to the type Vec<Field> and Field is the SCALE-encoded enumeration:

  • 0: AuthenticityProof(Proof): The signature of the message. For cryptography where the public key cannot be derived from the signature together with the message data, then this will also include the signer's public key. The message data is all fields of the messages fields except the signature concatenated together without the length prefix that a Vec would usually imply. This is so that the signature can be derived without needing to re-encode the statement.
  • 1: DecryptionKey([u8; 32]): The decryption key identifier which should be used to decrypt the statement's data. In the absence of this field Data should be treated as not encrypted.
  • 2: Priority(u32): Priority specifier. Higher priority statements should be kept around at the cost of lower priority statements if multiple statements from the same sender are competing for persistence or transport. Nodes should disregard when considering unsigned statements.
  • 3: Channel([u8; 32]): The channel identifier. Only one message of a given channel should be retained at once (the one of highest priority). Nodes should disregard when considering unsigned statements.
  • 4: Topic1([u8; 32])): First topic identifier.
  • 5: Topic2([u8; 32])): Second topic identifier.
  • 6: Topic3([u8; 32])): Third topic identifier.
  • 7: Topic4([u8; 32])): Fourth topic identifier.
  • 8: Data(Vec<u8>): General data segment. No special meaning.

Proof is defined as the SCALE-encoded enumeration:

  • 0: Sr25519 { signature: [u8; 64], signer: [u8; 32] }
  • 1: Ed25519 { signature: [u8; 64], signer: [u8; 32] )
  • 2: Secp256k1Ecdsa { signature: [u8; 65], signer: [u8; 33] )
  • 3: OnChain { who: [u8; 32], block_hash: [u8; 32], event_index: u64 }

Potential uses

Potential use-cases are various and include:

  • ring-signature aggregation;
  • messaging;
  • state-channels;
  • deferral of the initial "advertising" phase of multi-party transactions;
  • publication of preimage data whose hash is referenced on-chain;
  • effective transferal of fee payment to a second-party.

License: Apache-2.0

Dependencies

~15–30MB
~482K SLoC