@proto-kit/common 0.1.1-develop.187 → 0.1.1-develop.188
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/dist/Constants.d.ts +0 -4
- package/dist/Constants.d.ts.map +0 -1
- package/dist/Constants.js +0 -3
- package/dist/config/ConfigurationAggregator.d.ts +0 -10
- package/dist/config/ConfigurationAggregator.d.ts.map +0 -1
- package/dist/config/ConfigurationAggregator.js +0 -35
- package/dist/config/ConfigurationReceiver.d.ts +0 -25
- package/dist/config/ConfigurationReceiver.d.ts.map +0 -1
- package/dist/config/ConfigurationReceiver.js +0 -36
- package/dist/config/types.d.ts +0 -2
- package/dist/config/types.d.ts.map +0 -1
- package/dist/config/types.js +0 -1
- package/dist/model/MethodPublicInput.d.ts +0 -51
- package/dist/model/MethodPublicInput.d.ts.map +0 -1
- package/dist/model/MethodPublicInput.js +0 -11
- package/dist/model/Option.d.ts +0 -89
- package/dist/model/Option.d.ts.map +0 -1
- package/dist/model/Option.js +0 -86
- package/dist/model/Path.d.ts +0 -31
- package/dist/model/Path.d.ts.map +0 -1
- package/dist/model/Path.js +0 -44
- package/dist/model/StateTransition.d.ts +0 -85
- package/dist/model/StateTransition.d.ts.map +0 -1
- package/dist/model/StateTransition.js +0 -58
- package/dist/model/StateTransitionProvableBatch.d.ts +0 -56
- package/dist/model/StateTransitionProvableBatch.d.ts.map +0 -1
- package/dist/model/StateTransitionProvableBatch.js +0 -20
- package/dist/prover/block/BlockProver.d.ts +0 -199
- package/dist/prover/block/BlockProver.d.ts.map +0 -1
- package/dist/prover/block/BlockProver.js +0 -119
- package/dist/prover/block/BlockScopedModule.d.ts +0 -3
- package/dist/prover/block/BlockScopedModule.d.ts.map +0 -1
- package/dist/prover/block/BlockScopedModule.js +0 -6
- package/dist/prover/statetransition/StateTransitionProver.d.ts +0 -92
- package/dist/prover/statetransition/StateTransitionProver.d.ts.map +0 -1
- package/dist/prover/statetransition/StateTransitionProver.js +0 -127
- package/dist/prover/statetransition/StateTransitionWitnessProvider.d.ts +0 -16
- package/dist/prover/statetransition/StateTransitionWitnessProvider.d.ts.map +0 -1
- package/dist/prover/statetransition/StateTransitionWitnessProvider.js +0 -17
- package/dist/src/model/Option.d.ts +0 -158
- package/dist/src/model/Option.d.ts.map +0 -1
- package/dist/src/model/Option.js +0 -53
- package/dist/src/model/Path.d.ts +0 -35
- package/dist/src/model/Path.d.ts.map +0 -1
- package/dist/src/model/Path.js +0 -51
- package/dist/src/model/StateTransition.d.ts +0 -201
- package/dist/src/model/StateTransition.d.ts.map +0 -1
- package/dist/src/model/StateTransition.js +0 -43
- package/dist/src/utils/PrefixedHashList.d.ts +0 -15
- package/dist/src/utils/PrefixedHashList.d.ts.map +0 -1
- package/dist/src/utils/PrefixedHashList.js +0 -28
- package/dist/src/utils/ProvableHashList.d.ts +0 -30
- package/dist/src/utils/ProvableHashList.d.ts.map +0 -1
- package/dist/src/utils/ProvableHashList.js +0 -43
- package/dist/utils/PrefixedHashList.d.ts +0 -14
- package/dist/utils/PrefixedHashList.d.ts.map +0 -1
- package/dist/utils/PrefixedHashList.js +0 -12
- package/dist/utils/PrefixedProvableHashList.d.ts +0 -8
- package/dist/utils/PrefixedProvableHashList.d.ts.map +0 -1
- package/dist/utils/PrefixedProvableHashList.js +0 -12
- package/dist/utils/ProvableHashList.d.ts +0 -26
- package/dist/utils/ProvableHashList.d.ts.map +0 -1
- package/dist/utils/ProvableHashList.js +0 -35
- package/dist/utils/Utils.d.ts +0 -22
- package/dist/utils/Utils.d.ts.map +0 -1
- package/dist/utils/Utils.js +0 -41
- package/dist/utils/merkletree/MemoryMerkleTreeStorage.d.ts +0 -26
- package/dist/utils/merkletree/MemoryMerkleTreeStorage.d.ts.map +0 -1
- package/dist/utils/merkletree/MemoryMerkleTreeStorage.js +0 -79
- package/dist/utils/merkletree/RollupMerkleTree.d.ts +0 -143
- package/dist/utils/merkletree/RollupMerkleTree.d.ts.map +0 -1
- package/dist/utils/merkletree/RollupMerkleTree.js +0 -246
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { Circuit, Field, Poseidon } from "snarkyjs";
|
|
2
|
-
/**
|
|
3
|
-
* Utilities for creating a hash list from a given value type.
|
|
4
|
-
*/
|
|
5
|
-
export class ProvableHashList {
|
|
6
|
-
constructor(valueType, commitment = Field(0)) {
|
|
7
|
-
this.valueType = valueType;
|
|
8
|
-
this.commitment = commitment;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Converts the provided value to Field[] and appends it to
|
|
12
|
-
* the current hashlist.
|
|
13
|
-
*
|
|
14
|
-
* @param value - Value to be appended to the hash list
|
|
15
|
-
* @returns Current hash list.
|
|
16
|
-
*/
|
|
17
|
-
push(value) {
|
|
18
|
-
this.commitment = this.hash([
|
|
19
|
-
this.commitment,
|
|
20
|
-
...this.valueType.toFields(value),
|
|
21
|
-
]);
|
|
22
|
-
return this;
|
|
23
|
-
}
|
|
24
|
-
remove(preimage, value) {
|
|
25
|
-
const success = this.hash([
|
|
26
|
-
preimage,
|
|
27
|
-
...this.valueType.toFields(value),
|
|
28
|
-
]).equals(this.commitment);
|
|
29
|
-
this.commitment = Circuit.if(success, preimage, this.commitment);
|
|
30
|
-
return success;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* @returns Traling hash of the current hashlist.
|
|
34
|
-
*/
|
|
35
|
-
toField() {
|
|
36
|
-
return this.commitment;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
export class DefaultProvableHashList extends ProvableHashList {
|
|
40
|
-
hash(e) {
|
|
41
|
-
return Poseidon.hash(e);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Field, FlexibleProvablePure } from "snarkyjs";
|
|
2
|
-
import { ProvableHashList } from "./ProvableHashList.js";
|
|
3
|
-
export declare class PrefixedProvableHashList<
|
|
4
|
-
Value
|
|
5
|
-
> extends ProvableHashList<Value> {
|
|
6
|
-
private readonly prefix;
|
|
7
|
-
constructor(
|
|
8
|
-
valueType: FlexibleProvablePure<Value>,
|
|
9
|
-
prefix: string,
|
|
10
|
-
internalCommitment?: Field
|
|
11
|
-
);
|
|
12
|
-
protected hash(elements: Field[]): Field;
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=PrefixedHashList.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PrefixedHashList.d.ts","sourceRoot":"","sources":["../../src/utils/PrefixedHashList.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,oBAAoB,EAAY,MAAM,UAAU,CAAC;AAEjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAGzD,qBAAa,wBAAwB,CAAC,KAAK,CAAE,SAAQ,gBAAgB,CAAC,KAAK,CAAC;IAC1E,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;gBAG7B,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC,EACtC,MAAM,EAAE,MAAM,EACd,kBAAkB,GAAE,KAAgB;IAMtC,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,GAAG,KAAK;CAGzC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Field, Poseidon } from "snarkyjs";
|
|
2
|
-
import { ProvableHashList } from "./ProvableHashList.js";
|
|
3
|
-
import { stringToField } from "./Utils";
|
|
4
|
-
export class PrefixedProvableHashList extends ProvableHashList {
|
|
5
|
-
constructor(valueType, prefix, internalCommitment = Field(0)) {
|
|
6
|
-
super(valueType, internalCommitment);
|
|
7
|
-
this.prefix = stringToField(prefix);
|
|
8
|
-
}
|
|
9
|
-
hash(elements) {
|
|
10
|
-
return Poseidon.hash([this.prefix, ...elements]);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Field, FlexibleProvablePure } from "snarkyjs";
|
|
2
|
-
import { ProvableHashList } from "./ProvableHashList.js";
|
|
3
|
-
export declare class PrefixedProvableHashList<Value> extends ProvableHashList<Value> {
|
|
4
|
-
private readonly prefix;
|
|
5
|
-
constructor(valueType: FlexibleProvablePure<Value>, prefix: string, internalCommitment?: Field);
|
|
6
|
-
protected hash(elements: Field[]): Field;
|
|
7
|
-
}
|
|
8
|
-
//# sourceMappingURL=PrefixedProvableHashList.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PrefixedProvableHashList.d.ts","sourceRoot":"","sources":["../../src/utils/PrefixedProvableHashList.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,oBAAoB,EAAY,MAAM,UAAU,CAAC;AAEjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAGzD,qBAAa,wBAAwB,CAAC,KAAK,CAAE,SAAQ,gBAAgB,CAAC,KAAK,CAAC;IAC1E,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;gBAG7B,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC,EACtC,MAAM,EAAE,MAAM,EACd,kBAAkB,GAAE,KAAgB;IAMtC,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,GAAG,KAAK;CAGzC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Field, Poseidon } from "snarkyjs";
|
|
2
|
-
import { ProvableHashList } from "./ProvableHashList.js";
|
|
3
|
-
import { stringToField } from "./utils";
|
|
4
|
-
export class PrefixedProvableHashList extends ProvableHashList {
|
|
5
|
-
constructor(valueType, prefix, internalCommitment = Field(0)) {
|
|
6
|
-
super(valueType, internalCommitment);
|
|
7
|
-
this.prefix = stringToField(prefix);
|
|
8
|
-
}
|
|
9
|
-
hash(elements) {
|
|
10
|
-
return Poseidon.hash([this.prefix, ...elements]);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Field, FlexibleProvablePure } from "snarkyjs";
|
|
2
|
-
/**
|
|
3
|
-
* Utilities for creating a hash list from a given value type.
|
|
4
|
-
*/
|
|
5
|
-
export declare abstract class ProvableHashList<Value> {
|
|
6
|
-
private readonly valueType;
|
|
7
|
-
commitment: Field;
|
|
8
|
-
constructor(valueType: FlexibleProvablePure<Value>, commitment?: Field);
|
|
9
|
-
protected abstract hash(elements: Field[]): Field;
|
|
10
|
-
/**
|
|
11
|
-
* Converts the provided value to Field[] and appends it to
|
|
12
|
-
* the current hashlist.
|
|
13
|
-
*
|
|
14
|
-
* @param value - Value to be appended to the hash list
|
|
15
|
-
* @returns Current hash list.
|
|
16
|
-
*/
|
|
17
|
-
push(value: Value): this;
|
|
18
|
-
/**
|
|
19
|
-
* @returns Traling hash of the current hashlist.
|
|
20
|
-
*/
|
|
21
|
-
toField(): Field;
|
|
22
|
-
}
|
|
23
|
-
export declare class DefaultProvableHashList<Value> extends ProvableHashList<Value> {
|
|
24
|
-
hash(elements: Field[]): Field;
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=ProvableHashList.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ProvableHashList.d.ts","sourceRoot":"","sources":["../../src/utils/ProvableHashList.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAY,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAEjE;;GAEG;AACH,8BAAsB,gBAAgB,CAAC,KAAK;IAExC,OAAO,CAAC,QAAQ,CAAC,SAAS;IACnB,UAAU,EAAE,KAAK;gBADP,SAAS,EAAE,oBAAoB,CAAC,KAAK,CAAC,EAChD,UAAU,GAAE,KAAgB;IAGrC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,GAAG,KAAK;IAEjD;;;;;;OAMG;IACI,IAAI,CAAC,KAAK,EAAE,KAAK;IAQxB;;OAEG;IACI,OAAO;CAGf;AAED,qBAAa,uBAAuB,CAAC,KAAK,CAAE,SAAQ,gBAAgB,CAAC,KAAK,CAAC;IAClE,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,GAAG,KAAK;CAGtC"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { Field, Poseidon } from "snarkyjs";
|
|
2
|
-
/**
|
|
3
|
-
* Utilities for creating a hash list from a given value type.
|
|
4
|
-
*/
|
|
5
|
-
export class ProvableHashList {
|
|
6
|
-
constructor(valueType, commitment = Field(0)) {
|
|
7
|
-
this.valueType = valueType;
|
|
8
|
-
this.commitment = commitment;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Converts the provided value to Field[] and appends it to
|
|
12
|
-
* the current hashlist.
|
|
13
|
-
*
|
|
14
|
-
* @param value - Value to be appended to the hash list
|
|
15
|
-
* @returns Current hash list.
|
|
16
|
-
*/
|
|
17
|
-
push(value) {
|
|
18
|
-
this.commitment = this.hash([
|
|
19
|
-
this.commitment,
|
|
20
|
-
...this.valueType.toFields(value),
|
|
21
|
-
]);
|
|
22
|
-
return this;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* @returns Traling hash of the current hashlist.
|
|
26
|
-
*/
|
|
27
|
-
toField() {
|
|
28
|
-
return this.commitment;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
export class DefaultProvableHashList extends ProvableHashList {
|
|
32
|
-
hash(elements) {
|
|
33
|
-
return Poseidon.hash(elements);
|
|
34
|
-
}
|
|
35
|
-
}
|
package/dist/utils/Utils.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Field, Proof } from "snarkyjs";
|
|
2
|
-
export type ReturnType<FunctionType extends Function> = FunctionType extends (...args: any[]) => infer Return ? Return : any;
|
|
3
|
-
export type ClassType = new (...args: any[]) => any;
|
|
4
|
-
export type TypedClassConstructor<Class> = new (...args: any[]) => Class;
|
|
5
|
-
export type Subclass<Class extends new (...args: any) => any> = (new (...args: any) => InstanceType<Class>) & {
|
|
6
|
-
[Key in keyof Class]: Class[Key];
|
|
7
|
-
} & {
|
|
8
|
-
prototype: InstanceType<Class>;
|
|
9
|
-
};
|
|
10
|
-
export interface ZkProgramType<PublicInputType> {
|
|
11
|
-
name: string;
|
|
12
|
-
compile: () => Promise<{
|
|
13
|
-
verificationKey: string;
|
|
14
|
-
}>;
|
|
15
|
-
verify: (proof: Proof<PublicInputType>) => Promise<boolean>;
|
|
16
|
-
digest: () => string;
|
|
17
|
-
publicInputType: TypedClassConstructor<PublicInputType>;
|
|
18
|
-
}
|
|
19
|
-
export declare function notInCircuit(): MethodDecorator;
|
|
20
|
-
export declare function stringToField(value: string): Field;
|
|
21
|
-
export declare function noop(): void;
|
|
22
|
-
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":"AAKA,OAAO,EAAW,KAAK,EAAY,KAAK,EAAE,MAAM,UAAU,CAAC;AAE3D,MAAM,MAAM,UAAU,CAAC,YAAY,SAAS,QAAQ,IAAI,YAAY,SAAS,CAC3E,GAAG,IAAI,EAAE,GAAG,EAAE,KACX,MAAM,MAAM,GACb,MAAM,GACN,GAAG,CAAC;AAER,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;AAEpD,MAAM,MAAM,qBAAqB,CAAC,KAAK,IAAI,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,KAAK,CAAC;AAEzE,MAAM,MAAM,QAAQ,CAAC,KAAK,SAAS,KAAK,GAAG,IAAI,EAAE,GAAG,KAAK,GAAG,IAAI,CAAC,KAC/D,GAAG,IAAI,EAAE,GAAG,KACT,YAAY,CAAC,KAAK,CAAC,CAAC,GAAG;KACzB,GAAG,IAAI,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC;CACjC,GAAG;IAAE,SAAS,EAAE,YAAY,CAAC,KAAK,CAAC,CAAA;CAAE,CAAC;AAEvC,MAAM,WAAW,aAAa,CAAC,eAAe;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,OAAO,CAAC;QAAE,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACpD,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,eAAe,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAC5D,MAAM,EAAE,MAAM,MAAM,CAAC;IAGrB,eAAe,EAAE,qBAAqB,CAAC,eAAe,CAAC,CAAC;CACzD;AAED,wBAAgB,YAAY,IAAI,eAAe,CAoB9C;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,SAwB1C;AAED,wBAAgB,IAAI,IAAI,IAAI,CAAG"}
|
package/dist/utils/Utils.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line max-len
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/ban-types, @typescript-eslint/no-unsafe-return,@typescript-eslint/no-empty-function */
|
|
3
|
-
import { TextEncoder } from "node:util";
|
|
4
|
-
import { Circuit, Field, Poseidon } from "snarkyjs";
|
|
5
|
-
export function notInCircuit() {
|
|
6
|
-
return function ReplacedFunction(target, propertyKey, descriptor) {
|
|
7
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
8
|
-
const childFunction = descriptor.value;
|
|
9
|
-
descriptor.value = function value(...args) {
|
|
10
|
-
if (Circuit.inCheckedComputation() || Circuit.inProver()) {
|
|
11
|
-
throw new Error(`Method ${propertyKey.toString()} is supposed to be only called outside of the circuit`);
|
|
12
|
-
}
|
|
13
|
-
// eslint-disable-next-line max-len
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
15
|
-
return childFunction.apply(this, args);
|
|
16
|
-
};
|
|
17
|
-
return descriptor;
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
export function stringToField(value) {
|
|
21
|
-
const fieldSize = Field.sizeInBytes();
|
|
22
|
-
const encoder = new TextEncoder();
|
|
23
|
-
const stringBytes = Array.from(encoder.encode(value));
|
|
24
|
-
const padding = Array.from({
|
|
25
|
-
length: fieldSize - stringBytes.length,
|
|
26
|
-
}).fill(0);
|
|
27
|
-
const data = stringBytes.concat(padding);
|
|
28
|
-
if (data.length > fieldSize) {
|
|
29
|
-
const chunks = data.reduce((a, b, index) => {
|
|
30
|
-
const arrayIndex = index / fieldSize;
|
|
31
|
-
if (a.length <= arrayIndex) {
|
|
32
|
-
a.push([]);
|
|
33
|
-
}
|
|
34
|
-
a[arrayIndex].push(b);
|
|
35
|
-
return a;
|
|
36
|
-
}, []);
|
|
37
|
-
return Poseidon.hash(chunks.map((x) => Field.fromBytes(x)));
|
|
38
|
-
}
|
|
39
|
-
return Field.fromBytes(data);
|
|
40
|
-
}
|
|
41
|
-
export function noop() { }
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { type MerkleTreeStore, type SyncMerkleTreeStore } from "./RollupMerkleTree.js";
|
|
2
|
-
export declare class NoOpMerkleTreeStorage implements SyncMerkleTreeStore {
|
|
3
|
-
parent: MerkleTreeStore;
|
|
4
|
-
openTransaction(): void;
|
|
5
|
-
commit(): void;
|
|
6
|
-
getNode(): bigint | undefined;
|
|
7
|
-
setNode(): void;
|
|
8
|
-
virtualize(): MerkleTreeStore;
|
|
9
|
-
getNodeAsync(): Promise<bigint | undefined>;
|
|
10
|
-
setNodeAsync(): Promise<void>;
|
|
11
|
-
}
|
|
12
|
-
export declare class MemoryMerkleTreeStorage implements SyncMerkleTreeStore {
|
|
13
|
-
private readonly nodes;
|
|
14
|
-
private readonly cache;
|
|
15
|
-
parent: SyncMerkleTreeStore;
|
|
16
|
-
constructor(parent?: SyncMerkleTreeStore | undefined);
|
|
17
|
-
openTransaction(): void;
|
|
18
|
-
commit(): void;
|
|
19
|
-
getNode(key: bigint, level: number): bigint | undefined;
|
|
20
|
-
setNode(key: bigint, level: number, value: bigint): void;
|
|
21
|
-
virtualize(): MerkleTreeStore;
|
|
22
|
-
getNodeAsync(key: bigint, level: number): Promise<bigint | undefined>;
|
|
23
|
-
setNodeAsync(key: bigint, level: number, value: bigint): Promise<void>;
|
|
24
|
-
cacheFromParent(index: bigint): Promise<void>;
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=MemoryMerkleTreeStorage.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MemoryMerkleTreeStorage.d.ts","sourceRoot":"","sources":["../../../src/utils/merkletree/MemoryMerkleTreeStorage.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,eAAe,EAEpB,KAAK,mBAAmB,EACzB,MAAM,uBAAuB,CAAC;AAE/B,qBAAa,qBAAsB,YAAW,mBAAmB;IACxD,MAAM,EAAE,eAAe,CAAQ;IAE/B,eAAe,IAAI,IAAI;IAIvB,MAAM,IAAI,IAAI;IAId,OAAO,IAAI,MAAM,GAAG,SAAS;IAI7B,OAAO,IAAI,IAAI;IAIf,UAAU,IAAI,eAAe;IAIvB,YAAY,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAI3C,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;CAG3C;AAED,qBAAa,uBAAwB,YAAW,mBAAmB;IACjE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAGf;IAEP,OAAO,CAAC,QAAQ,CAAC,KAAK,CAGf;IAEA,MAAM,EAAE,mBAAmB,CAAC;gBAEhB,MAAM,GAAE,mBAAmB,GAAG,SAAqB;IAI/D,eAAe,IAAI,IAAI;IAIvB,MAAM,IAAI,IAAI;IAId,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAQvD,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAIxD,UAAU,IAAI,eAAe;IAIvB,YAAY,CACvB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAIjB,YAAY,CACvB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,IAAI,CAAC;IAKH,eAAe,CAAC,KAAK,EAAE,MAAM;CAoB3C"}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-magic-numbers */
|
|
2
|
-
import { noop } from "../utils";
|
|
3
|
-
import { RollupMerkleTree, } from "./RollupMerkleTree.js";
|
|
4
|
-
export class NoOpMerkleTreeStorage {
|
|
5
|
-
constructor() {
|
|
6
|
-
this.parent = this;
|
|
7
|
-
}
|
|
8
|
-
openTransaction() {
|
|
9
|
-
noop();
|
|
10
|
-
}
|
|
11
|
-
commit() {
|
|
12
|
-
noop();
|
|
13
|
-
}
|
|
14
|
-
getNode() {
|
|
15
|
-
return undefined;
|
|
16
|
-
}
|
|
17
|
-
setNode() {
|
|
18
|
-
noop();
|
|
19
|
-
}
|
|
20
|
-
virtualize() {
|
|
21
|
-
return this;
|
|
22
|
-
}
|
|
23
|
-
async getNodeAsync() {
|
|
24
|
-
return undefined;
|
|
25
|
-
}
|
|
26
|
-
async setNodeAsync() {
|
|
27
|
-
return undefined;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
export class MemoryMerkleTreeStorage {
|
|
31
|
-
constructor(parent = undefined) {
|
|
32
|
-
this.nodes = {};
|
|
33
|
-
this.cache = {};
|
|
34
|
-
this.parent = parent ?? new NoOpMerkleTreeStorage();
|
|
35
|
-
}
|
|
36
|
-
openTransaction() {
|
|
37
|
-
noop();
|
|
38
|
-
}
|
|
39
|
-
commit() {
|
|
40
|
-
noop();
|
|
41
|
-
}
|
|
42
|
-
getNode(key, level) {
|
|
43
|
-
return (this.nodes[level]?.[key.toString()] ??
|
|
44
|
-
this.cache[level]?.[key.toString()] ??
|
|
45
|
-
this.parent.getNode(key, level));
|
|
46
|
-
}
|
|
47
|
-
setNode(key, level, value) {
|
|
48
|
-
var _a;
|
|
49
|
-
((_a = this.nodes)[level] ?? (_a[level] = {}))[key.toString()] = value;
|
|
50
|
-
}
|
|
51
|
-
virtualize() {
|
|
52
|
-
return new MemoryMerkleTreeStorage(this);
|
|
53
|
-
}
|
|
54
|
-
async getNodeAsync(key, level) {
|
|
55
|
-
return this.getNode(key, level);
|
|
56
|
-
}
|
|
57
|
-
async setNodeAsync(key, level, value) {
|
|
58
|
-
this.setNode(key, level, value);
|
|
59
|
-
return undefined;
|
|
60
|
-
}
|
|
61
|
-
async cacheFromParent(index) {
|
|
62
|
-
var _a;
|
|
63
|
-
// Algo from RollupMerkleTree.getWitness()
|
|
64
|
-
const { leafCount, height } = RollupMerkleTree;
|
|
65
|
-
if (index >= leafCount) {
|
|
66
|
-
index %= leafCount;
|
|
67
|
-
}
|
|
68
|
-
for (let level = 0; level < height - 1; level++) {
|
|
69
|
-
const isLeft = index % 2n === 0n;
|
|
70
|
-
const key = isLeft ? index + 1n : index - 1n;
|
|
71
|
-
// eslint-disable-next-line no-await-in-loop
|
|
72
|
-
const value = await this.parent.getNodeAsync(key, level);
|
|
73
|
-
if (value !== undefined) {
|
|
74
|
-
((_a = this.nodes)[level] ?? (_a[level] = {}))[key.toString()] = value;
|
|
75
|
-
}
|
|
76
|
-
index /= 2n;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import { Bool, Field } from "snarkyjs";
|
|
2
|
-
export { RollupMerkleTree, RollupMerkleWitness };
|
|
3
|
-
export { maybeSwap };
|
|
4
|
-
export interface Virtualizable<T> {
|
|
5
|
-
parent: T;
|
|
6
|
-
virtualize: () => T;
|
|
7
|
-
}
|
|
8
|
-
export interface MerkleTreeStore extends Virtualizable<MerkleTreeStore> {
|
|
9
|
-
openTransaction: () => void;
|
|
10
|
-
commit: () => void;
|
|
11
|
-
setNodeAsync: (key: bigint, level: number, value: bigint) => Promise<void>;
|
|
12
|
-
getNodeAsync: (key: bigint, level: number) => Promise<bigint | undefined>;
|
|
13
|
-
}
|
|
14
|
-
export interface SyncMerkleTreeStore extends MerkleTreeStore {
|
|
15
|
-
setNode: (key: bigint, level: number, value: bigint) => void;
|
|
16
|
-
getNode: (key: bigint, level: number) => bigint | undefined;
|
|
17
|
-
}
|
|
18
|
-
declare const RollupMerkleWitness_base: (new (value: {
|
|
19
|
-
path: Field[];
|
|
20
|
-
isLeft: Bool[];
|
|
21
|
-
}) => {
|
|
22
|
-
path: Field[];
|
|
23
|
-
isLeft: Bool[];
|
|
24
|
-
}) & {
|
|
25
|
-
_isStruct: true;
|
|
26
|
-
} & import("snarkyjs/dist/node/snarky").ProvablePure<{
|
|
27
|
-
path: Field[];
|
|
28
|
-
isLeft: Bool[];
|
|
29
|
-
}> & {
|
|
30
|
-
toInput: (x: {
|
|
31
|
-
path: Field[];
|
|
32
|
-
isLeft: Bool[];
|
|
33
|
-
}) => {
|
|
34
|
-
fields?: Field[] | undefined;
|
|
35
|
-
packed?: [Field, number][] | undefined;
|
|
36
|
-
};
|
|
37
|
-
toJSON: (x: {
|
|
38
|
-
path: Field[];
|
|
39
|
-
isLeft: Bool[];
|
|
40
|
-
}) => {
|
|
41
|
-
path: string[];
|
|
42
|
-
isLeft: boolean[];
|
|
43
|
-
};
|
|
44
|
-
fromJSON: (x: {
|
|
45
|
-
path: string[];
|
|
46
|
-
isLeft: boolean[];
|
|
47
|
-
}) => {
|
|
48
|
-
path: Field[];
|
|
49
|
-
isLeft: Bool[];
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* The {@link BaseMerkleWitness} class defines a circuit-compatible base class
|
|
54
|
-
* for [Merkle Witness'](https://computersciencewiki.org/index.php/Merkle_proof).
|
|
55
|
-
*/
|
|
56
|
-
declare class RollupMerkleWitness extends RollupMerkleWitness_base {
|
|
57
|
-
static height: number;
|
|
58
|
-
height(): number;
|
|
59
|
-
/**
|
|
60
|
-
* Calculates a root depending on the leaf value.
|
|
61
|
-
* @param leaf Value of the leaf node that belongs to this Witness.
|
|
62
|
-
* @returns The calculated root.
|
|
63
|
-
*/
|
|
64
|
-
calculateRoot(hash: Field): Field;
|
|
65
|
-
/**
|
|
66
|
-
* Calculates the index of the leaf node that belongs to this Witness.
|
|
67
|
-
* @returns Index of the leaf.
|
|
68
|
-
*/
|
|
69
|
-
calculateIndex(): Field;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* A [Merkle Tree](https://en.wikipedia.org/wiki/Merkle_tree) is a binary tree in
|
|
73
|
-
* which every leaf is the cryptography hash of a piece of data,
|
|
74
|
-
* and every node is the hash of the concatenation of its two child nodes.
|
|
75
|
-
*
|
|
76
|
-
* A Merkle Tree allows developers to easily and securely verify
|
|
77
|
-
* the integrity of large amounts of data.
|
|
78
|
-
*
|
|
79
|
-
* Take a look at our [documentation](https://docs.minaprotocol.com/en/zkapps)
|
|
80
|
-
* on how to use Merkle Trees in combination with zkApps and
|
|
81
|
-
* zero knowledge programming!
|
|
82
|
-
*
|
|
83
|
-
* Levels are indexed from leaves (level 0) to root (level N - 1).
|
|
84
|
-
*/
|
|
85
|
-
declare class RollupMerkleTree {
|
|
86
|
-
static height: number;
|
|
87
|
-
static get leafCount(): bigint;
|
|
88
|
-
private readonly zeroes;
|
|
89
|
-
readonly store: SyncMerkleTreeStore;
|
|
90
|
-
constructor(store: SyncMerkleTreeStore);
|
|
91
|
-
/**
|
|
92
|
-
* Returns a node which lives at a given index and level.
|
|
93
|
-
* @param level Level of the node.
|
|
94
|
-
* @param index Index of the node.
|
|
95
|
-
* @returns The data of the node.
|
|
96
|
-
*/
|
|
97
|
-
getNode(level: number, index: bigint): Field;
|
|
98
|
-
/**
|
|
99
|
-
* Returns the root of the [Merkle Tree](https://en.wikipedia.org/wiki/Merkle_tree).
|
|
100
|
-
* @returns The root of the Merkle Tree.
|
|
101
|
-
*/
|
|
102
|
-
getRoot(): Field;
|
|
103
|
-
private setNode;
|
|
104
|
-
/**
|
|
105
|
-
* TODO: if this is passed an index bigger than the max, it will set a couple
|
|
106
|
-
* of out-of-bounds nodes but not affect the real Merkle root. OK?
|
|
107
|
-
*/
|
|
108
|
-
/**
|
|
109
|
-
* Sets the value of a leaf node at a given index to a given value.
|
|
110
|
-
* @param index Position of the leaf node.
|
|
111
|
-
* @param leaf New value.
|
|
112
|
-
*/
|
|
113
|
-
setLeaf(index: bigint, leaf: Field): void;
|
|
114
|
-
/**
|
|
115
|
-
* Returns the witness (also known as
|
|
116
|
-
* [Merkle Proof or Merkle Witness](https://computersciencewiki.org/index.php/Merkle_proof))
|
|
117
|
-
* for the leaf at the given index.
|
|
118
|
-
* @param index Position of the leaf node.
|
|
119
|
-
* @returns The witness that belongs to the leaf.
|
|
120
|
-
*/
|
|
121
|
-
getWitness(index: bigint): RollupMerkleWitness;
|
|
122
|
-
/**
|
|
123
|
-
* Fills all leaves of the tree.
|
|
124
|
-
* @param leaves Values to fill the leaves with.
|
|
125
|
-
*/
|
|
126
|
-
fill(leaves: Field[]): void;
|
|
127
|
-
/**
|
|
128
|
-
* Returns the amount of leaf nodes.
|
|
129
|
-
* @returns Amount of leaf nodes.
|
|
130
|
-
*/
|
|
131
|
-
get leafCount(): bigint;
|
|
132
|
-
}
|
|
133
|
-
export declare namespace MerkleTreeUtils {
|
|
134
|
-
function normalizeKey(key: Field): Field;
|
|
135
|
-
function checkMembership(witness: RollupMerkleWitness, root: Field, key: Field, value: Field): Bool;
|
|
136
|
-
function computeRoot(witness: RollupMerkleWitness, value: Field): Field;
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* More efficient version of `maybeSwapBad` which
|
|
140
|
-
* reuses an intermediate variable
|
|
141
|
-
*/
|
|
142
|
-
declare function maybeSwap(b: Bool, x: Field, y: Field): [Field, Field];
|
|
143
|
-
//# sourceMappingURL=RollupMerkleTree.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RollupMerkleTree.d.ts","sourceRoot":"","sources":["../../../src/utils/merkletree/RollupMerkleTree.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,IAAI,EAAW,KAAK,EAAoB,MAAM,UAAU,CAAC;AAMlE,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,CAAC;AAIjD,OAAO,EAAE,SAAS,EAAE,CAAC;AAGrB,MAAM,WAAW,aAAa,CAAC,CAAC;IAC9B,MAAM,EAAE,CAAC,CAAC;IAEV,UAAU,EAAE,MAAM,CAAC,CAAC;CACrB;AAED,MAAM,WAAW,eAAgB,SAAQ,aAAa,CAAC,eAAe,CAAC;IACrE,eAAe,EAAE,MAAM,IAAI,CAAC;IAE5B,MAAM,EAAE,MAAM,IAAI,CAAC;IAEnB,YAAY,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAE3E,YAAY,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;CAC3E;AAED,MAAM,WAAW,mBAAoB,SAAQ,eAAe;IAC1D,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAE7D,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;CAC7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAED;;;GAGG;AACH,cAAM,mBAAoB,SAAQ,wBAGhC;IACA,OAAc,MAAM,SAAO;IAEpB,MAAM,IAAI,MAAM;IAIvB;;;;OAIG;IACI,aAAa,CAAC,IAAI,EAAE,KAAK,GAAG,KAAK;IAaxC;;;OAGG;IACI,cAAc,IAAI,KAAK;CAa/B;AAED;;;;;;;;;;;;;GAaG;AACH,cAAM,gBAAgB;IACpB,OAAc,MAAM,SAAO;IAE3B,WAAkB,SAAS,IAAI,MAAM,CAEpC;IAED,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAW;IAElC,SAAgB,KAAK,EAAE,mBAAmB,CAAC;gBAExB,KAAK,EAAE,mBAAmB;IAY7C;;;;;OAKG;IAEI,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,KAAK;IAInD;;;OAGG;IAEI,OAAO,IAAI,KAAK;IAMvB,OAAO,CAAC,OAAO;IAIf;;;OAGG;IAEH;;;;OAIG;IAEI,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK;IAkBzC;;;;;;OAMG;IAEI,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,mBAAmB;IAqBrD;;;OAGG;IAEI,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE;IAM3B;;;OAGG;IACH,IAAW,SAAS,IAAI,MAAM,CAE7B;CACF;AAGD,yBAAiB,eAAe,CAAC;IAC/B,SAAgB,YAAY,CAAC,GAAG,EAAE,KAAK,GAAG,KAAK,CAS9C;IAED,SAAgB,eAAe,CAC7B,OAAO,EAAE,mBAAmB,EAC5B,IAAI,EAAE,KAAK,EACX,GAAG,EAAE,KAAK,EACV,KAAK,EAAE,KAAK,GACX,IAAI,CAKN;IAED,SAAgB,WAAW,CACzB,OAAO,EAAE,mBAAmB,EAC5B,KAAK,EAAE,KAAK,GACX,KAAK,CAEP;CACF;AAED;;;GAGG;AACH,iBAAS,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAK9D"}
|