This repository has been archived by the owner on Sep 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
mmr.ts
59 lines (56 loc) · 2.44 KB
/
mmr.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// https://github.com/paritytech/substrate/blob/6c5ac31/primitives/merkle-mountain-range/src/lib.rs#L37
/**
* A type to describe leaf position in the MMR.
*
* Note this is different from [`NodeIndex`], which can be applied to
* both leafs and inner nodes. Leafs will always have consecutive `LeafIndex`,
* but might be actually at different positions in the MMR `NodeIndex`.
*/
export type LeafIndex = number
// https://github.com/paritytech/substrate/blob/eddf888/frame/merkle-mountain-range/rpc/src/lib.rs#L49
/** Retrieved MMR leaf and its proof. */
export interface LeafProof {
/** Block hash the proof was generated for. */
blockHash: string
/** SCALE-encoded leaf data. */
leaf: string
/** SCALE-encoded proof data. See [sp_mmr_primitives::Proof]. */
proof: string
}
// https://github.com/paritytech/substrate/blob/eddf888/frame/merkle-mountain-range/rpc/src/lib.rs#L72
/** Retrieved MMR leaves and their proof. */
export interface LeafBatchProof {
/** Block hash the proof was generated for. */
blockHash: string
/** SCALE-encoded vector of `LeafData`. */
leaves: string
/** SCALE-encoded proof data. See [sp_mmr_primitives::Proof]. */
proof: string
}
// https://github.com/paritytech/substrate/blob/eddf888/frame/merkle-mountain-range/rpc/src/lib.rs#L99
export type MmrCalls = {
/**
* Generate MMR proof for given leaf index.
*
* This method calls into a runtime with MMR pallet included and attempts to generate
* MMR proof for leaf at given `leaf_index`.
* Optionally, a block hash at which the runtime should be queried can be specified.
*
* Returns the (full) leaf itself and a proof for this leaf (compact encoding, i.e. hash of
* the leaf). Both parameters are SCALE-encoded.
*/
mmr_generateProof(leafIndex: LeafIndex, at?: string): LeafProof
/**
* Generate MMR proof for the given leaf indices.
*
* This method calls into a runtime with MMR pallet included and attempts to generate
* MMR proof for a set of leaves at the given `leaf_indices`.
* Optionally, a block hash at which the runtime should be queried can be specified.
*
* Returns the leaves and a proof for these leaves (compact encoding, i.e. hash of
* the leaves). Both parameters are SCALE-encoded.
* The order of entries in the `leaves` field of the returned struct
* is the same as the order of the entries in `leaf_indices` supplied
*/
mmr_generateBatchProof(leafIndices: LeafIndex[], at?: string): LeafBatchProof
}