@lelantos-org/sdk / advanced / TreeStore
Class: TreeStore
Defined in: @lelantos-org/sdk/dist/sync/tree-store.d.ts:111
Constructors
Constructor
new TreeStore(
P,
fmd,
treeDepth?
): TreeStore;Defined in: @lelantos-org/sdk/dist/sync/tree-store.d.ts:126
treeDepth must equal the depth the spend path gives the circuit (WalletConfig.treeDepth). A mismatched depth raises no local error, but the proof fails to verify on-chain.
Parameters
| Parameter | Type |
|---|---|
P | Poseidon |
fmd | CommitmentFeed |
treeDepth? | number |
Returns
TreeStore
Methods
getPath()
getPath(leafIndex): MerkleProof & object;Defined in: @lelantos-org/sdk/dist/sync/tree-store.d.ts:141
Parameters
| Parameter | Type |
|---|---|
leafIndex | number |
Returns
MerkleProof & object
loadState()
loadState(state): void;Defined in: @lelantos-org/sdk/dist/sync/tree-store.d.ts:129
Parameters
| Parameter | Type |
|---|---|
state | TreeStoreState |
Returns
void
reset()
reset(): Promise<void>;Defined in: @lelantos-org/sdk/dist/sync/tree-store.d.ts:186
Discard the local tree and its persisted state so the next sync() rebuilds from leaf 0.
For trees that syncing cannot repair: sync() only appends from chunkOf(syncedCount), so a prefix that diverged from the chain (server re-index, pool redeployed under the same chain id, partially written restore) stays wrong, as does a local tree with more leaves than the chain. Every leaf is re-fetched and re-hashed, so use it only after an ordinary resync fails, as syncVerified does.
Returns
Promise<void>
root()
root(): bigint;Defined in: @lelantos-org/sdk/dist/sync/tree-store.d.ts:144
Returns
bigint
saveState()
saveState(): TreeStoreState;Defined in: @lelantos-org/sdk/dist/sync/tree-store.d.ts:130
Returns
sync()
sync(opts?): Promise<TreeSyncSummary>;Defined in: @lelantos-org/sdk/dist/sync/tree-store.d.ts:137
Fetch chunks since the last sync, insert their leaves, then persist. Idempotent: the tail chunk is re-fetched every sync and existing entries are skipped by leaf index.
Runs after any sync, reset or verification already in progress.
Parameters
| Parameter | Type |
|---|---|
opts? | TreeSyncOpts |
Returns
Promise<TreeSyncSummary>
syncVerified()
syncVerified(opts?): Promise<RootCheck>;Defined in: @lelantos-org/sdk/dist/sync/tree-store.d.ts:164
Sync, then repair until the local tree matches the chain. Passes, in increasing cost:
- Sync and check.
- If the mirror has more leaves, sync again to append the rest. Otherwise re-read the tree state: an equal count with a differing root also results from
/v1/tree-stateand the chunk feed being read at different times. - If
isKnownRootis supplied, ask the pool, which is authoritative. If it accepts the local root, the mirror is at fault and the tree is spendable. - Rebuild from leaf 0, since syncing cannot repair a diverged tree; see reset.
Parameters
| Parameter | Type |
|---|---|
opts? | TreeVerifyOpts |
Returns
Promise<RootCheck>
syncVerifiedSnapshot()
syncVerifiedSnapshot<T>(opts, read): Promise<{
check: RootCheck;
value: T | undefined;
}>;Defined in: @lelantos-org/sdk/dist/sync/tree-store.d.ts:172
syncVerified, then read against the verified tree, with no sync or reset in between. read is skipped when the tree is not spendable.
A spend needs its Merkle root and every input's path from one tree; read separately, a concurrent sync or reset could change the root between them.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
opts | TreeVerifyOpts |
read | (check) => T | Promise<T> |
Returns
Promise<{ check: RootCheck; value: T | undefined; }>
verifyRoot()
verifyRoot(): Promise<RootCheck>;Defined in: @lelantos-org/sdk/dist/sync/tree-store.d.ts:152
Check the locally built root against the mirrored chain root. This makes trusting the server's leafHash sound: a wrong leaf produces a wrong root, which surfaces here rather than as a rejected transaction.
Reports observations only; syncVerified acts on them.
Returns
Promise<RootCheck>
withPersistence()
static withPersistence(
P,
fmd,
persistence,
treeDepth?
): Promise<TreeStore>;Defined in: @lelantos-org/sdk/dist/sync/tree-store.d.ts:128
Build a TreeStore and restore any previously persisted state.
Parameters
| Parameter | Type |
|---|---|
P | Poseidon |
fmd | CommitmentFeed |
persistence | TreePersistence |
treeDepth? | number |
Returns
Promise<TreeStore>