o1js-pack 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- package/.husky/pre-commit +0 -0
- package/README.md +9 -30
- package/build/src/index.d.ts +5 -5
- package/build/src/index.js +5 -5
- package/build/src/lib/PackingPlant.d.ts +132 -140
- package/build/src/lib/PackingPlant.js +190 -191
- package/build/src/lib/PackingPlant.js.map +1 -1
- package/build/src/lib/packed-types/PackedBool.d.ts +85 -90
- package/build/src/lib/packed-types/PackedBool.js +49 -48
- package/build/src/lib/packed-types/PackedBool.js.map +1 -1
- package/build/src/lib/packed-types/PackedBool.test.d.ts +1 -1
- package/build/src/lib/packed-types/PackedBool.test.js +75 -75
- package/build/src/lib/packed-types/PackedString.d.ts +181 -92
- package/build/src/lib/packed-types/PackedString.js +127 -59
- package/build/src/lib/packed-types/PackedString.js.map +1 -1
- package/build/src/lib/packed-types/PackedString.test.d.ts +1 -1
- package/build/src/lib/packed-types/PackedString.test.js +100 -99
- package/build/src/lib/packed-types/PackedString.test.js.map +1 -1
- package/build/src/lib/packed-types/PackedUInt32.d.ts +85 -90
- package/build/src/lib/packed-types/PackedUInt32.js +49 -48
- package/build/src/lib/packed-types/PackedUInt32.js.map +1 -1
- package/build/src/lib/packed-types/PackedUInt32.test.d.ts +1 -1
- package/build/src/lib/packed-types/PackedUInt32.test.js +83 -83
- package/package.json +1 -1
- package/tests/provable/end_to_end.test.ts +2 -4
- package/tests/provable/example_packed_string_circuit.ts +3 -8
- package/tests/provable/example_packed_uint_circuit.ts +6 -12
- package/build/src/lib/packed-types/PackedCharacter.d.ts +0 -51
- package/build/src/lib/packed-types/PackedCharacter.js +0 -34
- package/build/src/lib/packed-types/PackedCharacter.js.map +0 -1
- package/build/src/lib/packed-types/PackedCharacter.test.d.ts +0 -1
- package/build/src/lib/packed-types/PackedCharacter.test.js +0 -31
- package/build/src/lib/packed-types/PackedCharacter.test.js.map +0 -1
- package/build/src/lib/scratch.d.ts +0 -1
- package/build/src/lib/scratch.js +0 -16
- package/build/src/lib/scratch.js.map +0 -1
- package/build/src/packed-types/PackedBool.d.ts +0 -51
- package/build/src/packed-types/PackedBool.js +0 -34
- package/build/src/packed-types/PackedBool.js.map +0 -1
- package/build/src/packed-types/PackedBool.test.d.ts +0 -1
- package/build/src/packed-types/PackedBool.test.js +0 -101
- package/build/src/packed-types/PackedBool.test.js.map +0 -1
- package/build/src/packed-types/PackedCharacter.d.ts +0 -51
- package/build/src/packed-types/PackedCharacter.js +0 -34
- package/build/src/packed-types/PackedCharacter.js.map +0 -1
- package/build/src/packed-types/PackedCharacter.test.d.ts +0 -1
- package/build/src/packed-types/PackedCharacter.test.js +0 -31
- package/build/src/packed-types/PackedCharacter.test.js.map +0 -1
- package/build/src/packed-types/PackedUInt32.d.ts +0 -51
- package/build/src/packed-types/PackedUInt32.js +0 -34
- package/build/src/packed-types/PackedUInt32.js.map +0 -1
- package/build/src/packed-types/PackedUInt32.test.d.ts +0 -1
- package/build/src/packed-types/PackedUInt32.test.js +0 -68
- package/build/src/packed-types/PackedUInt32.test.js.map +0 -1
- package/build/src/packed-types/PackingPlant.d.ts +0 -54
- package/build/src/packed-types/PackingPlant.js +0 -45
- package/build/src/packed-types/PackingPlant.js.map +0 -1
- package/build/src/packed-types/scratch.d.ts +0 -1
- package/build/src/packed-types/scratch.js +0 -5
- package/build/src/packed-types/scratch.js.map +0 -1
- package/coverage/clover.xml +0 -166
- package/coverage/coverage-final.json +0 -5
- package/coverage/lcov-report/PackedBool.ts.html +0 -268
- package/coverage/lcov-report/PackedUInt32.ts.html +0 -313
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -131
- package/coverage/lcov-report/lib/PackingPlant.ts.html +0 -478
- package/coverage/lcov-report/lib/index.html +0 -116
- package/coverage/lcov-report/lib/packed-types/PackedBool.ts.html +0 -238
- package/coverage/lcov-report/lib/packed-types/PackedString.ts.html +0 -364
- package/coverage/lcov-report/lib/packed-types/PackedUInt32.ts.html +0 -238
- package/coverage/lcov-report/lib/packed-types/index.html +0 -146
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -196
- package/coverage/lcov.info +0 -282
package/.husky/pre-commit
CHANGED
File without changes
|
package/README.md
CHANGED
@@ -1,33 +1,18 @@
|
|
1
|
-
#
|
1
|
+
# o1js Pack
|
2
2
|
|
3
|
-
Make the most of your
|
3
|
+
Make the most of your zkApp state!
|
4
4
|
|
5
5
|
## What is it
|
6
6
|
|
7
|
-
|
7
|
+
o1js Pack is a library for [o1js](https://github.com/o1-labs/o1js/) that allows a zkApp developer to pack extra data into a single Field.
|
8
8
|
|
9
|
-
### Usage in a
|
9
|
+
### Usage in a zkApp
|
10
10
|
|
11
|
-
|
12
|
-
import {
|
13
|
-
PackedBoolFactory,
|
14
|
-
PackedStringFactory,
|
15
|
-
PackedUInt32Factory,
|
16
|
-
} from 'o1js-pack';
|
17
|
-
|
18
|
-
const MyPackedBools = PackedBoolFactory(); // Max of 254 Bools
|
19
|
-
const MyPackedString = PackedStringFactory(); // Max of 120 Characters
|
20
|
-
const MyPackedUInts = PackedUInt32Factory(); // Max of 7 UInt32s
|
21
|
-
|
22
|
-
const sevenUints = [1, 2, 3, 4, 5, 6, 7].map(x => UInt32.from(x));
|
23
|
-
const myPackedUInts = new MyPackedUInts(MyPackedUInts.pack(sevenUints), sevenUints);
|
24
|
-
```
|
11
|
+
TODO
|
25
12
|
|
26
|
-
|
13
|
+
### Smart Contract
|
27
14
|
|
28
|
-
|
29
|
-
|
30
|
-
For example, let's say there is a voting app with two independent Fields of state: `yesCount` and `noCount`. If one user issues an update to `yesCount` and another user issues an update to `noCount` at the same time, both proofs may be valid at the same time. Both transactions may succeed during the same block, since they don't interfere with each others' preconditions. With SnarkyPack, a devolper can save state by putting both `yesCount` and `noCount` into the same Field of state, making room for other state to exist on chain. The tradeoff is that two votes will no longer be able to be cast independently. `yesCount` and `noCount` depend on the same precontition, meaning that to update one or the other, you must lock both.
|
15
|
+
### ZK Program
|
31
16
|
|
32
17
|
## How to build
|
33
18
|
|
@@ -39,18 +24,12 @@ npm run build
|
|
39
24
|
|
40
25
|
```sh
|
41
26
|
npm run test src # non-proof tests
|
42
|
-
npm run
|
43
|
-
```
|
44
|
-
|
45
|
-
## How to run coverage
|
46
|
-
|
47
|
-
```sh
|
48
|
-
npm run coverage
|
27
|
+
npm run test tests/provable # provable tests
|
49
28
|
```
|
50
29
|
|
51
30
|
## Credits
|
52
31
|
|
53
|
-
Thanks to @mario_zito for seeding the idea for this library on
|
32
|
+
Thanks to @mario_zito for seeding the idea for this library on Discord ([Thread 1](https://discord.com/channels/484437221055922177/1128509274465779822), [Thread 2](https://discord.com/channels/484437221055922177/1128501705173106698)), and to @gregor for sounding out the early implementation.
|
54
33
|
|
55
34
|
Thanks to @iam-dev for early adoption!
|
56
35
|
|
package/build/src/index.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { PackedBoolFactory } from './lib/packed-types/PackedBool.js';
|
2
|
-
import { PackedUInt32Factory } from './lib/packed-types/PackedUInt32.js';
|
3
|
-
import { PackingPlant, MultiPackingPlant } from './lib/PackingPlant.js';
|
4
|
-
import { PackedStringFactory } from './lib/packed-types/PackedString.js';
|
5
|
-
export { PackedBoolFactory, PackedStringFactory, PackedUInt32Factory, PackingPlant, MultiPackingPlant, };
|
1
|
+
import { PackedBoolFactory } from './lib/packed-types/PackedBool.js';
|
2
|
+
import { PackedUInt32Factory } from './lib/packed-types/PackedUInt32.js';
|
3
|
+
import { PackingPlant, MultiPackingPlant } from './lib/PackingPlant.js';
|
4
|
+
import { PackedStringFactory } from './lib/packed-types/PackedString.js';
|
5
|
+
export { PackedBoolFactory, PackedStringFactory, PackedUInt32Factory, PackingPlant, MultiPackingPlant, };
|
package/build/src/index.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
import { PackedBoolFactory } from './lib/packed-types/PackedBool.js';
|
2
|
-
import { PackedUInt32Factory } from './lib/packed-types/PackedUInt32.js';
|
3
|
-
import { PackingPlant, MultiPackingPlant } from './lib/PackingPlant.js';
|
4
|
-
import { PackedStringFactory } from './lib/packed-types/PackedString.js';
|
5
|
-
export { PackedBoolFactory, PackedStringFactory, PackedUInt32Factory, PackingPlant, MultiPackingPlant, };
|
1
|
+
import { PackedBoolFactory } from './lib/packed-types/PackedBool.js';
|
2
|
+
import { PackedUInt32Factory } from './lib/packed-types/PackedUInt32.js';
|
3
|
+
import { PackingPlant, MultiPackingPlant } from './lib/PackingPlant.js';
|
4
|
+
import { PackedStringFactory } from './lib/packed-types/PackedString.js';
|
5
|
+
export { PackedBoolFactory, PackedStringFactory, PackedUInt32Factory, PackingPlant, MultiPackingPlant, };
|
6
6
|
//# sourceMappingURL=index.js.map
|
@@ -1,140 +1,132 @@
|
|
1
|
-
import { Field, InferProvable } from 'o1js';
|
2
|
-
export declare function PackingPlant<A, T extends InferProvable<A> = InferProvable<A>>(elementType: A, l: number, bitSize: bigint): (abstract new (packed: Field) => {
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
extractField(input: T): Field;
|
14
|
-
sizeInBits(): bigint;
|
15
|
-
unpack(f: Field): Array<T>;
|
16
|
-
/**
|
17
|
-
*
|
18
|
-
* @param unpacked Array of the implemented packed type
|
19
|
-
* @throws if the length of the array is longer than the length of the implementing factory config
|
20
|
-
*/
|
21
|
-
checkPack(unpacked: Array<T>): void;
|
22
|
-
/**
|
23
|
-
*
|
24
|
-
* @param unpacked Array of the implemented packed type, must be shorter than the max allowed, which varies by type, will throw if the input is too long
|
25
|
-
* @returns Field, packed with the information from the unpacked input
|
26
|
-
*/
|
27
|
-
pack(unpacked: Array<T>): Field;
|
28
|
-
/**
|
29
|
-
*
|
30
|
-
* @param f Field, packed with the information, as returned by #pack
|
31
|
-
* @returns Array of bigints, which can be decoded by the implementing class into the final type
|
32
|
-
*/
|
33
|
-
unpackToBigints(f: Field): Array<bigint>;
|
34
|
-
_isStruct: true;
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
packed: import("o1js/dist/node/lib/field").Field;
|
47
|
-
};
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
}
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
}
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
*
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
*
|
93
|
-
*
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
*
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
packed:
|
126
|
-
}
|
127
|
-
|
128
|
-
packed
|
129
|
-
}
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
packed: string[];
|
134
|
-
};
|
135
|
-
fromJSON: (x: {
|
136
|
-
packed: string[];
|
137
|
-
}) => {
|
138
|
-
packed: import("o1js/dist/node/lib/field").Field[];
|
139
|
-
};
|
140
|
-
};
|
1
|
+
import { Field, InferProvable } from 'o1js';
|
2
|
+
export declare function PackingPlant<A, T extends InferProvable<A> = InferProvable<A>>(elementType: A, l: number, bitSize: bigint): (abstract new (packed: Field) => {
|
3
|
+
assertEquals(other: any): void;
|
4
|
+
packed: import("o1js/dist/node/lib/field").Field;
|
5
|
+
}) & {
|
6
|
+
type: import("o1js/dist/node/bindings/lib/provable-snarky").ProvableExtended<{
|
7
|
+
packed: import("o1js/dist/node/lib/field").Field;
|
8
|
+
}, {
|
9
|
+
packed: string;
|
10
|
+
}>;
|
11
|
+
l: number;
|
12
|
+
bitSize: bigint;
|
13
|
+
extractField(input: T): Field;
|
14
|
+
sizeInBits(): bigint;
|
15
|
+
unpack(f: Field): Array<T>;
|
16
|
+
/**
|
17
|
+
*
|
18
|
+
* @param unpacked Array of the implemented packed type
|
19
|
+
* @throws if the length of the array is longer than the length of the implementing factory config
|
20
|
+
*/
|
21
|
+
checkPack(unpacked: Array<T>): void;
|
22
|
+
/**
|
23
|
+
*
|
24
|
+
* @param unpacked Array of the implemented packed type, must be shorter than the max allowed, which varies by type, will throw if the input is too long
|
25
|
+
* @returns Field, packed with the information from the unpacked input
|
26
|
+
*/
|
27
|
+
pack(unpacked: Array<T>): Field;
|
28
|
+
/**
|
29
|
+
*
|
30
|
+
* @param f Field, packed with the information, as returned by #pack
|
31
|
+
* @returns Array of bigints, which can be decoded by the implementing class into the final type
|
32
|
+
*/
|
33
|
+
unpackToBigints(f: Field): Array<bigint>;
|
34
|
+
_isStruct: true;
|
35
|
+
toFields: (value: {
|
36
|
+
packed: import("o1js/dist/node/lib/field").Field;
|
37
|
+
}) => import("o1js/dist/node/lib/field").Field[];
|
38
|
+
toAuxiliary: (value?: {
|
39
|
+
packed: import("o1js/dist/node/lib/field").Field;
|
40
|
+
} | undefined) => any[];
|
41
|
+
fromFields: (fields: import("o1js/dist/node/lib/field").Field[]) => {
|
42
|
+
packed: import("o1js/dist/node/lib/field").Field;
|
43
|
+
};
|
44
|
+
sizeInFields(): number;
|
45
|
+
check: (value: {
|
46
|
+
packed: import("o1js/dist/node/lib/field").Field;
|
47
|
+
}) => void;
|
48
|
+
toInput: (x: {
|
49
|
+
packed: import("o1js/dist/node/lib/field").Field;
|
50
|
+
}) => {
|
51
|
+
fields?: import("o1js/dist/node/lib/field").Field[] | undefined;
|
52
|
+
packed?: [import("o1js/dist/node/lib/field").Field, number][] | undefined;
|
53
|
+
};
|
54
|
+
toJSON: (x: {
|
55
|
+
packed: import("o1js/dist/node/lib/field").Field;
|
56
|
+
}) => {
|
57
|
+
packed: string;
|
58
|
+
};
|
59
|
+
fromJSON: (x: {
|
60
|
+
packed: string;
|
61
|
+
}) => {
|
62
|
+
packed: import("o1js/dist/node/lib/field").Field;
|
63
|
+
};
|
64
|
+
};
|
65
|
+
export declare function MultiPackingPlant<A, T extends InferProvable<A> = InferProvable<A>>(elementType: A, l: number, bitSize: bigint): (abstract new (packed: Array<Field>) => {
|
66
|
+
assertEquals(other: any): void;
|
67
|
+
packed: import("o1js/dist/node/lib/field").Field[];
|
68
|
+
}) & {
|
69
|
+
type: import("o1js/dist/node/bindings/lib/provable-snarky").ProvableExtended<{
|
70
|
+
packed: import("o1js/dist/node/lib/field").Field[];
|
71
|
+
}, {
|
72
|
+
packed: string[];
|
73
|
+
}>;
|
74
|
+
l: number;
|
75
|
+
n: number;
|
76
|
+
bitSize: bigint;
|
77
|
+
extractField(input: T | undefined): Field;
|
78
|
+
sizeInBits(): bigint;
|
79
|
+
elementsPerField(): number;
|
80
|
+
unpack(fields: Array<Field>): Array<T>;
|
81
|
+
/**
|
82
|
+
*
|
83
|
+
* @param unpacked Array of the implemented packed type
|
84
|
+
* @throws if the length of the array is longer than the length of the implementing factory config
|
85
|
+
*/
|
86
|
+
checkPack(unpacked: Array<T>): void;
|
87
|
+
/**
|
88
|
+
*
|
89
|
+
* @param unpacked Array of the implemented packed type, must be shorter than the max allowed, which varies by type, will throw if the input is too long
|
90
|
+
* @returns Array of Fields, packed such that each Field has as much information as possible
|
91
|
+
*
|
92
|
+
* e.g. 15 Characters pack into 1 Field. 15 or fewer Characters will return an array of 1 Field
|
93
|
+
* 30 of fewer Characters will return an aray of 2 Fields
|
94
|
+
*/
|
95
|
+
pack(unpacked: Array<T>): Array<Field>;
|
96
|
+
/**
|
97
|
+
*
|
98
|
+
* @param fields Array of Fields, packed such that each Field has as much information as possible, as returned in #pack
|
99
|
+
* @returns Array of bigints, which can be decoded by the implementing class into the final type
|
100
|
+
*/
|
101
|
+
unpackToBigints(fields: Array<Field>): Array<bigint>;
|
102
|
+
_isStruct: true;
|
103
|
+
toFields: (value: {
|
104
|
+
packed: import("o1js/dist/node/lib/field").Field[];
|
105
|
+
}) => import("o1js/dist/node/lib/field").Field[];
|
106
|
+
toAuxiliary: (value?: {
|
107
|
+
packed: import("o1js/dist/node/lib/field").Field[];
|
108
|
+
} | undefined) => any[];
|
109
|
+
fromFields: (fields: import("o1js/dist/node/lib/field").Field[]) => {
|
110
|
+
packed: import("o1js/dist/node/lib/field").Field[];
|
111
|
+
};
|
112
|
+
sizeInFields(): number;
|
113
|
+
check: (value: {
|
114
|
+
packed: import("o1js/dist/node/lib/field").Field[];
|
115
|
+
}) => void;
|
116
|
+
toInput: (x: {
|
117
|
+
packed: import("o1js/dist/node/lib/field").Field[];
|
118
|
+
}) => {
|
119
|
+
fields?: import("o1js/dist/node/lib/field").Field[] | undefined;
|
120
|
+
packed?: [import("o1js/dist/node/lib/field").Field, number][] | undefined;
|
121
|
+
};
|
122
|
+
toJSON: (x: {
|
123
|
+
packed: import("o1js/dist/node/lib/field").Field[];
|
124
|
+
}) => {
|
125
|
+
packed: string[];
|
126
|
+
};
|
127
|
+
fromJSON: (x: {
|
128
|
+
packed: string[];
|
129
|
+
}) => {
|
130
|
+
packed: import("o1js/dist/node/lib/field").Field[];
|
131
|
+
};
|
132
|
+
};
|