o1js-pack 0.3.1 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- package/.github/workflows/ci.yml +1 -1
- 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 -92
- package/build/src/lib/PackingPlant.js +190 -74
- package/build/src/lib/PackingPlant.js.map +1 -1
- package/build/src/lib/packed-types/PackedBool.d.ts +85 -77
- package/build/src/lib/packed-types/PackedBool.js +49 -47
- 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/PackedBool.test.js.map +1 -1
- package/build/src/lib/packed-types/PackedString.d.ts +181 -78
- package/build/src/lib/packed-types/PackedString.js +127 -82
- 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 -77
- package/build/src/lib/packed-types/PackedUInt32.js +49 -47
- 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/build/src/lib/packed-types/PackedUInt32.test.js.map +1 -1
- package/package.json +1 -1
- package/tests/provable/end_to_end.test.ts +65 -0
- package/tests/provable/example_packed_string_circuit.ts +47 -0
- package/tests/provable/example_packed_uint_circuit.ts +39 -0
- 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
@@ -1,84 +1,84 @@
|
|
1
|
-
import { Provable, UInt32 } from 'o1js';
|
2
|
-
import { PackedUInt32Factory } from './PackedUInt32';
|
3
|
-
describe('PackedUInt32', () => {
|
4
|
-
class PackedUInt32 extends PackedUInt32Factory(
|
5
|
-
}
|
6
|
-
describe('Outside of the circuit', () => {
|
7
|
-
const bigints = [10n, 2n ** 32n - 1n, 0n, 10n, 2n ** 32n - 100n, 42n, 0n];
|
8
|
-
const uints = bigints.map((x) => UInt32.from(x));
|
9
|
-
it('#fromBigInts', () => {
|
10
|
-
const myPackedUInt32 = PackedUInt32.fromBigInts(bigints);
|
11
|
-
expect(myPackedUInt32.toBigInts()).toMatchObject(bigints);
|
12
|
-
});
|
13
|
-
it('#pack and #unPack', () => {
|
14
|
-
const packed = PackedUInt32.pack(uints);
|
15
|
-
const unpacked = PackedUInt32.unpack(packed);
|
16
|
-
expect(unpacked.length).toBe(uints.length);
|
17
|
-
expect(unpacked).toMatchObject(uints);
|
18
|
-
});
|
19
|
-
});
|
20
|
-
describe('Provable Properties', () => {
|
21
|
-
it('#sizeInFields', () => {
|
22
|
-
class one extends PackedUInt32Factory(1) {
|
23
|
-
}
|
24
|
-
class seven extends PackedUInt32Factory(7) {
|
25
|
-
}
|
26
|
-
expect(one.sizeInFields()).toBe(1);
|
27
|
-
expect(seven.sizeInFields()).toBe(1);
|
28
|
-
});
|
29
|
-
});
|
30
|
-
describe('Defensive Cases', () => {
|
31
|
-
it('throws for input >= 8 uints', () => {
|
32
|
-
expect(() => PackedUInt32Factory(7)).not.toThrow();
|
33
|
-
expect(() => PackedUInt32Factory(8)).toThrow();
|
34
|
-
});
|
35
|
-
it('initalizes with more input than allowed', () => {
|
36
|
-
const bigints = [
|
37
|
-
10n,
|
38
|
-
2n ** 32n - 1n,
|
39
|
-
0n,
|
40
|
-
10n,
|
41
|
-
2n ** 32n - 100n,
|
42
|
-
42n,
|
43
|
-
0n,
|
44
|
-
0n,
|
45
|
-
];
|
46
|
-
expect(() => {
|
47
|
-
PackedUInt32.fromBigInts(bigints);
|
48
|
-
}).toThrow();
|
49
|
-
});
|
50
|
-
it('initalizes with less input than specified', () => {
|
51
|
-
const bigints = [10n];
|
52
|
-
const expected = [10n, 0n, 0n, 0n, 0n, 0n, 0n];
|
53
|
-
expect(PackedUInt32.fromBigInts(bigints).toBigInts()).toMatchObject(expected);
|
54
|
-
});
|
55
|
-
});
|
56
|
-
describe('In the circuit', () => {
|
57
|
-
const bigints = [10n, 2n ** 32n - 1n, 0n, 10n, 2n ** 32n - 100n, 42n, 0n];
|
58
|
-
const outsidePackedUInt = PackedUInt32.fromBigInts(bigints);
|
59
|
-
it('Initializes', () => {
|
60
|
-
expect(() => {
|
61
|
-
Provable.runAndCheck(() => {
|
62
|
-
const packedUInt32 = new PackedUInt32(outsidePackedUInt.packed
|
63
|
-
PackedUInt32.check({ packed: packedUInt32.packed });
|
64
|
-
});
|
65
|
-
}).not.toThrow();
|
66
|
-
});
|
67
|
-
it('#assertEquals', () => {
|
68
|
-
expect(() => {
|
69
|
-
Provable.runAndCheck(() => {
|
70
|
-
const packedUInt32 = new PackedUInt32(outsidePackedUInt.packed
|
71
|
-
packedUInt32.assertEquals(outsidePackedUInt);
|
72
|
-
});
|
73
|
-
}).not.toThrow();
|
74
|
-
expect(() => {
|
75
|
-
Provable.runAndCheck(() => {
|
76
|
-
const fakePacked = outsidePackedUInt.packed.add(32);
|
77
|
-
const packedUInt32 = new PackedUInt32(fakePacked
|
78
|
-
packedUInt32.assertEquals(outsidePackedUInt);
|
79
|
-
});
|
80
|
-
}).toThrow();
|
81
|
-
});
|
82
|
-
});
|
83
|
-
});
|
1
|
+
import { Provable, UInt32 } from 'o1js';
|
2
|
+
import { PackedUInt32Factory } from './PackedUInt32';
|
3
|
+
describe('PackedUInt32', () => {
|
4
|
+
class PackedUInt32 extends PackedUInt32Factory() {
|
5
|
+
}
|
6
|
+
describe('Outside of the circuit', () => {
|
7
|
+
const bigints = [10n, 2n ** 32n - 1n, 0n, 10n, 2n ** 32n - 100n, 42n, 0n];
|
8
|
+
const uints = bigints.map((x) => UInt32.from(x));
|
9
|
+
it('#fromBigInts', () => {
|
10
|
+
const myPackedUInt32 = PackedUInt32.fromBigInts(bigints);
|
11
|
+
expect(myPackedUInt32.toBigInts()).toMatchObject(bigints);
|
12
|
+
});
|
13
|
+
it('#pack and #unPack', () => {
|
14
|
+
const packed = PackedUInt32.pack(uints);
|
15
|
+
const unpacked = PackedUInt32.unpack(packed);
|
16
|
+
expect(unpacked.length).toBe(uints.length);
|
17
|
+
expect(unpacked).toMatchObject(uints);
|
18
|
+
});
|
19
|
+
});
|
20
|
+
describe('Provable Properties', () => {
|
21
|
+
it('#sizeInFields', () => {
|
22
|
+
class one extends PackedUInt32Factory(1) {
|
23
|
+
}
|
24
|
+
class seven extends PackedUInt32Factory(7) {
|
25
|
+
}
|
26
|
+
expect(one.sizeInFields()).toBe(1);
|
27
|
+
expect(seven.sizeInFields()).toBe(1);
|
28
|
+
});
|
29
|
+
});
|
30
|
+
describe('Defensive Cases', () => {
|
31
|
+
it('throws for input >= 8 uints', () => {
|
32
|
+
expect(() => PackedUInt32Factory(7)).not.toThrow();
|
33
|
+
expect(() => PackedUInt32Factory(8)).toThrow();
|
34
|
+
});
|
35
|
+
it('initalizes with more input than allowed', () => {
|
36
|
+
const bigints = [
|
37
|
+
10n,
|
38
|
+
2n ** 32n - 1n,
|
39
|
+
0n,
|
40
|
+
10n,
|
41
|
+
2n ** 32n - 100n,
|
42
|
+
42n,
|
43
|
+
0n,
|
44
|
+
0n,
|
45
|
+
];
|
46
|
+
expect(() => {
|
47
|
+
PackedUInt32.fromBigInts(bigints);
|
48
|
+
}).toThrow();
|
49
|
+
});
|
50
|
+
it('initalizes with less input than specified', () => {
|
51
|
+
const bigints = [10n];
|
52
|
+
const expected = [10n, 0n, 0n, 0n, 0n, 0n, 0n];
|
53
|
+
expect(PackedUInt32.fromBigInts(bigints).toBigInts()).toMatchObject(expected);
|
54
|
+
});
|
55
|
+
});
|
56
|
+
describe('In the circuit', () => {
|
57
|
+
const bigints = [10n, 2n ** 32n - 1n, 0n, 10n, 2n ** 32n - 100n, 42n, 0n];
|
58
|
+
const outsidePackedUInt = PackedUInt32.fromBigInts(bigints);
|
59
|
+
it('Initializes', () => {
|
60
|
+
expect(() => {
|
61
|
+
Provable.runAndCheck(() => {
|
62
|
+
const packedUInt32 = new PackedUInt32(outsidePackedUInt.packed);
|
63
|
+
PackedUInt32.check({ packed: packedUInt32.packed });
|
64
|
+
});
|
65
|
+
}).not.toThrow();
|
66
|
+
});
|
67
|
+
it('#assertEquals', () => {
|
68
|
+
expect(() => {
|
69
|
+
Provable.runAndCheck(() => {
|
70
|
+
const packedUInt32 = new PackedUInt32(outsidePackedUInt.packed);
|
71
|
+
packedUInt32.assertEquals(outsidePackedUInt);
|
72
|
+
});
|
73
|
+
}).not.toThrow();
|
74
|
+
expect(() => {
|
75
|
+
Provable.runAndCheck(() => {
|
76
|
+
const fakePacked = outsidePackedUInt.packed.add(32);
|
77
|
+
const packedUInt32 = new PackedUInt32(fakePacked);
|
78
|
+
packedUInt32.assertEquals(outsidePackedUInt);
|
79
|
+
});
|
80
|
+
}).toThrow();
|
81
|
+
});
|
82
|
+
});
|
83
|
+
});
|
84
84
|
//# sourceMappingURL=PackedUInt32.test.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"PackedUInt32.test.js","sourceRoot":"","sources":["../../../../src/lib/packed-types/Packed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,CAAC,WAAW,CAAC,GAAG,EAAE;oBACxB,MAAM,YAAY,GAAG,IAAI,YAAY,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;oBAChE,YAAY,CAAC,YAAY,CAAC,iBAAiB,CAAC,CAAC;gBAC/C,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;YACjB,MAAM,CAAC,GAAG,EAAE;gBACV,QAAQ,CAAC,WAAW,CAAC,GAAG,EAAE;oBACxB,MAAM,UAAU,GAAG,iBAAiB,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;oBACpD,MAAM,YAAY,GAAG,IAAI,YAAY,CAAC,UAAU,CAAC,CAAC;oBAClD,YAAY,CAAC,YAAY,CAAC,iBAAiB,CAAC,CAAC;gBAC/C,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;QACf,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
@@ -0,0 +1,65 @@
|
|
1
|
+
import { Votes, VotesProgram, VotesProof } from './example_packed_uint_circuit';
|
2
|
+
import {
|
3
|
+
TextInput,
|
4
|
+
TextInputProgram,
|
5
|
+
TextInputProof,
|
6
|
+
} from './example_packed_string_circuit';
|
7
|
+
import { Character, Poseidon } from 'o1js';
|
8
|
+
|
9
|
+
describe('End to End Votes Test', () => {
|
10
|
+
const init = [0n, 0n];
|
11
|
+
const initVotes = Votes.fromBigInts(init);
|
12
|
+
let initProof: VotesProof;
|
13
|
+
|
14
|
+
beforeAll(async () => {
|
15
|
+
await VotesProgram.compile();
|
16
|
+
initProof = await VotesProgram.init(initVotes);
|
17
|
+
initProof.verify();
|
18
|
+
});
|
19
|
+
|
20
|
+
describe('Incrementing votes', () => {
|
21
|
+
it('Increments the 0th index', async () => {
|
22
|
+
const unpackedVotes = [1n, 0n];
|
23
|
+
const proofVotes = Votes.fromBigInts(unpackedVotes);
|
24
|
+
const proof = await VotesProgram.incrementIndex0(proofVotes, initProof);
|
25
|
+
proof.verify();
|
26
|
+
proofVotes.packed.assertEquals(proof.publicInput.packed);
|
27
|
+
});
|
28
|
+
|
29
|
+
// Temporarily skipping, the proof does not verify, but the behavior does not match #toThrow
|
30
|
+
it.skip('throws when verifying an invalid proof', async () => {
|
31
|
+
const unpackedVotes = [1n, 0n];
|
32
|
+
const proofVotes = Votes.fromBigInts(unpackedVotes);
|
33
|
+
const proof = await VotesProgram.incrementIndex1(proofVotes, initProof);
|
34
|
+
expect(() => {
|
35
|
+
proof.verify();
|
36
|
+
}).toThrow();
|
37
|
+
});
|
38
|
+
});
|
39
|
+
});
|
40
|
+
|
41
|
+
describe('End to End Text Input Test', () => {
|
42
|
+
const init = 'Mina Protocol';
|
43
|
+
const initTextInput = TextInput.fromString(init);
|
44
|
+
let initProof: TextInputProof;
|
45
|
+
|
46
|
+
beforeAll(async () => {
|
47
|
+
await TextInputProgram.compile();
|
48
|
+
initProof = await TextInputProgram.init(initTextInput);
|
49
|
+
initProof.verify();
|
50
|
+
});
|
51
|
+
|
52
|
+
describe('Adding Input', () => {
|
53
|
+
it('adds input', async () => {
|
54
|
+
let unpackedTextInput = 'Zina Protocol';
|
55
|
+
let proofTextInput = TextInput.fromString(unpackedTextInput);
|
56
|
+
const p1 = await TextInputProgram.changeFirstLetter(
|
57
|
+
proofTextInput,
|
58
|
+
initProof,
|
59
|
+
TextInput.unpack(initProof.publicInput.packed),
|
60
|
+
Character.fromString('Z')
|
61
|
+
);
|
62
|
+
proofTextInput.assertEquals(p1.publicInput);
|
63
|
+
});
|
64
|
+
});
|
65
|
+
});
|
@@ -0,0 +1,47 @@
|
|
1
|
+
import {
|
2
|
+
Experimental,
|
3
|
+
SelfProof,
|
4
|
+
Character,
|
5
|
+
Poseidon,
|
6
|
+
Provable,
|
7
|
+
Field,
|
8
|
+
} from 'o1js';
|
9
|
+
import { MultiPackedStringFactory } from '../../src/lib/packed-types/PackedString';
|
10
|
+
|
11
|
+
export class TextInput extends MultiPackedStringFactory(3) {}
|
12
|
+
|
13
|
+
export const TextInputProgram = Experimental.ZkProgram({
|
14
|
+
publicInput: TextInput,
|
15
|
+
|
16
|
+
methods: {
|
17
|
+
init: {
|
18
|
+
privateInputs: [],
|
19
|
+
method(state: TextInput) {
|
20
|
+
const initState = TextInput.fromString('Mina Protocol');
|
21
|
+
state.assertEquals(initState);
|
22
|
+
},
|
23
|
+
},
|
24
|
+
changeFirstLetter: {
|
25
|
+
privateInputs: [SelfProof, Provable.Array(Character, 45), Character],
|
26
|
+
method(
|
27
|
+
newState: TextInput,
|
28
|
+
oldProof: SelfProof<TextInput, TextInput>,
|
29
|
+
oldCharacters: Array<Character>,
|
30
|
+
newInput: Character
|
31
|
+
) {
|
32
|
+
oldProof.verify();
|
33
|
+
const newCharacters = [
|
34
|
+
...oldCharacters.map((x) => new Character(x.value)),
|
35
|
+
];
|
36
|
+
const packed = TextInput.fromCharacters(oldCharacters);
|
37
|
+
packed.assertEquals(oldProof.publicInput);
|
38
|
+
newCharacters[0] = newInput;
|
39
|
+
const repacked = TextInput.fromCharacters(newCharacters);
|
40
|
+
newState.assertEquals(repacked);
|
41
|
+
},
|
42
|
+
},
|
43
|
+
},
|
44
|
+
});
|
45
|
+
|
46
|
+
export let TextInputProof_ = Experimental.ZkProgram.Proof(TextInputProgram);
|
47
|
+
export class TextInputProof extends TextInputProof_ {}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import { Experimental, SelfProof } from 'o1js';
|
2
|
+
import { PackedUInt32Factory } from '../../src/lib/packed-types/PackedUInt32';
|
3
|
+
|
4
|
+
export class Votes extends PackedUInt32Factory() {}
|
5
|
+
|
6
|
+
export const VotesProgram = Experimental.ZkProgram({
|
7
|
+
publicInput: Votes,
|
8
|
+
|
9
|
+
methods: {
|
10
|
+
init: {
|
11
|
+
privateInputs: [],
|
12
|
+
method(state: Votes) {
|
13
|
+
const initState = Votes.fromBigInts([0n, 0n]);
|
14
|
+
state.assertEquals(initState);
|
15
|
+
},
|
16
|
+
},
|
17
|
+
incrementIndex0: {
|
18
|
+
privateInputs: [SelfProof],
|
19
|
+
method(newState: Votes, oldProof: SelfProof<Votes, Votes>) {
|
20
|
+
oldProof.verify();
|
21
|
+
const unpacked = Votes.unpack(oldProof.publicInput.packed);
|
22
|
+
unpacked[0] = unpacked[0].add(1);
|
23
|
+
newState.assertEquals(Votes.fromUInt32s(unpacked));
|
24
|
+
},
|
25
|
+
},
|
26
|
+
incrementIndex1: {
|
27
|
+
privateInputs: [SelfProof],
|
28
|
+
method(newState: Votes, oldProof: SelfProof<Votes, Votes>) {
|
29
|
+
oldProof.verify();
|
30
|
+
const unpacked = Votes.unpack(oldProof.publicInput.packed);
|
31
|
+
unpacked[1] = unpacked[1].add(1);
|
32
|
+
newState.assertEquals(Votes.fromUInt32s(unpacked));
|
33
|
+
},
|
34
|
+
},
|
35
|
+
},
|
36
|
+
});
|
37
|
+
|
38
|
+
export let VotesProof_ = Experimental.ZkProgram.Proof(VotesProgram);
|
39
|
+
export class VotesProof extends VotesProof_ {}
|
@@ -1,51 +0,0 @@
|
|
1
|
-
import { Field, Character } from 'snarkyjs';
|
2
|
-
export declare function PackedCharacterFactory(l: number): {
|
3
|
-
new (packed: import("snarkyjs/dist/node/lib/field.js").Field, aux: Character[]): {
|
4
|
-
packed: import("snarkyjs/dist/node/lib/field.js").Field;
|
5
|
-
aux: Character[];
|
6
|
-
bitSize: bigint;
|
7
|
-
};
|
8
|
-
/**
|
9
|
-
* Unpacks a Field into its component Character parts
|
10
|
-
* @param value
|
11
|
-
* @returns the unpacked auxilliary data used to pack the value
|
12
|
-
*/
|
13
|
-
toAuxiliary(value?: {
|
14
|
-
packed: Field;
|
15
|
-
} | undefined): Character[];
|
16
|
-
pack(aux: Character[]): Field;
|
17
|
-
type: import("snarkyjs/dist/node/bindings/lib/provable-snarky.js").ProvableExtended<{
|
18
|
-
packed: import("snarkyjs/dist/node/lib/field.js").Field;
|
19
|
-
}, {
|
20
|
-
packed: string;
|
21
|
-
}>;
|
22
|
-
l: number;
|
23
|
-
unpack(f: import("snarkyjs/dist/node/lib/field.js").Field): Character[];
|
24
|
-
check(value: {
|
25
|
-
packed: import("snarkyjs/dist/node/lib/field.js").Field;
|
26
|
-
}): void;
|
27
|
-
_isStruct: true;
|
28
|
-
toFields: (value: {
|
29
|
-
packed: import("snarkyjs/dist/node/lib/field.js").Field;
|
30
|
-
}) => import("snarkyjs/dist/node/lib/field.js").Field[];
|
31
|
-
fromFields: (fields: import("snarkyjs/dist/node/lib/field.js").Field[]) => {
|
32
|
-
packed: import("snarkyjs/dist/node/lib/field.js").Field;
|
33
|
-
};
|
34
|
-
sizeInFields(): number;
|
35
|
-
toInput: (x: {
|
36
|
-
packed: import("snarkyjs/dist/node/lib/field.js").Field;
|
37
|
-
}) => {
|
38
|
-
fields?: import("snarkyjs/dist/node/lib/field.js").Field[] | undefined;
|
39
|
-
packed?: [import("snarkyjs/dist/node/lib/field.js").Field, number][] | undefined;
|
40
|
-
};
|
41
|
-
toJSON: (x: {
|
42
|
-
packed: import("snarkyjs/dist/node/lib/field.js").Field;
|
43
|
-
}) => {
|
44
|
-
packed: string;
|
45
|
-
};
|
46
|
-
fromJSON: (x: {
|
47
|
-
packed: string;
|
48
|
-
}) => {
|
49
|
-
packed: import("snarkyjs/dist/node/lib/field.js").Field;
|
50
|
-
};
|
51
|
-
};
|
@@ -1,34 +0,0 @@
|
|
1
|
-
import { Field, Provable, Character } from 'snarkyjs';
|
2
|
-
import { PackingPlant } from '../PackingPlant.js';
|
3
|
-
const SIZE_IN_BITS = 16n;
|
4
|
-
export function PackedCharacterFactory(l) {
|
5
|
-
class PackedCharacter_ extends PackingPlant(Character, l, SIZE_IN_BITS) {
|
6
|
-
/**
|
7
|
-
* Unpacks a Field into its component Character parts
|
8
|
-
* @param value
|
9
|
-
* @returns the unpacked auxilliary data used to pack the value
|
10
|
-
*/
|
11
|
-
static toAuxiliary(value) {
|
12
|
-
const auxiliary = Provable.witness(Provable.Array(Character, l), () => {
|
13
|
-
let uints_ = [];
|
14
|
-
let packedN = value?.packed.toBigInt() || 0n;
|
15
|
-
for (let i = 0; i < l; i++) {
|
16
|
-
uints_[i] = packedN & ((1n << SIZE_IN_BITS) - 1n);
|
17
|
-
packedN >>= SIZE_IN_BITS;
|
18
|
-
}
|
19
|
-
return uints_.map((x) => Character.fromString(String.fromCharCode(Number(x))));
|
20
|
-
});
|
21
|
-
return auxiliary;
|
22
|
-
}
|
23
|
-
static pack(aux) {
|
24
|
-
let f = Field(0);
|
25
|
-
for (let i = 0; i < l; i++) {
|
26
|
-
const c = Field((2n ** SIZE_IN_BITS) ** BigInt(i));
|
27
|
-
f = f.add(aux[i].value.mul(c));
|
28
|
-
}
|
29
|
-
return f;
|
30
|
-
}
|
31
|
-
}
|
32
|
-
return PackedCharacter_;
|
33
|
-
}
|
34
|
-
//# sourceMappingURL=PackedCharacter.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"PackedCharacter.js","sourceRoot":"","sources":["../../../../src/lib/packed-types/PackedCharacter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,YAAY,GAAG,GAAG,CAAC;AAEzB,MAAM,UAAU,sBAAsB,CAAC,CAAS;IAC9C,MAAM,gBAAiB,SAAQ,YAAY,CAAC,SAAS,EAAE,CAAC,EAAE,YAAY,CAAC;QACrE;;;;WAIG;QACH,MAAM,CAAC,WAAW,CAAC,KAAqC;YACtD,MAAM,SAAS,GAAG,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE;gBACpE,IAAI,MAAM,GAAa,EAAE,CAAC;gBAC1B,IAAI,OAAO,GAAG,KAAK,EAAE,MAAM,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC;gBAC7C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;oBAC1B,MAAM,CAAC,CAAC,CAAC,GAAG,OAAO,GAAG,CAAC,CAAC,EAAE,IAAI,YAAY,CAAC,GAAG,EAAE,CAAC,CAAC;oBAClD,OAAO,KAAK,YAAY,CAAC;iBAC1B;gBACD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CACtB,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CACrD,CAAC;YACJ,CAAC,CAAC,CAAC;YACH,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,CAAC,IAAI,CAAC,GAAgB;YAC1B,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;YACjB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;gBAC1B,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC,EAAE,IAAI,YAAY,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;gBACnD,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;aAChC;YACD,OAAO,CAAC,CAAC;QACX,CAAC;KACF;IACD,OAAO,gBAAgB,CAAC;AAC1B,CAAC"}
|
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
@@ -1,31 +0,0 @@
|
|
1
|
-
import { Character } from 'snarkyjs';
|
2
|
-
import { PackedCharacterFactory } from './PackedCharacter';
|
3
|
-
describe('PackedCharacter', () => {
|
4
|
-
it('packs and unpacks a string of length < 16', async () => {
|
5
|
-
const myString = 'This is a test!';
|
6
|
-
let myCharacters = [];
|
7
|
-
for (let i = 0; i < myString.length; i++) {
|
8
|
-
myCharacters.push(Character.fromString(myString[i]));
|
9
|
-
}
|
10
|
-
const PackedCharacter_15 = PackedCharacterFactory(15);
|
11
|
-
const packedCharacter_15 = new PackedCharacter_15(PackedCharacter_15.pack(myCharacters), myCharacters);
|
12
|
-
const f = packedCharacter_15.packed;
|
13
|
-
const unpacked = PackedCharacter_15.unpack(f);
|
14
|
-
const unpackedStr = unpacked.map((x) => x.toString()).join('');
|
15
|
-
expect(unpackedStr).toBe(myString);
|
16
|
-
});
|
17
|
-
it('is one field in size', async () => {
|
18
|
-
const myString = 'This is a test!';
|
19
|
-
let myCharacters = [];
|
20
|
-
for (let i = 0; i < myString.length; i++) {
|
21
|
-
myCharacters.push(Character.fromString(myString[i]));
|
22
|
-
}
|
23
|
-
const PackedCharacter_15 = PackedCharacterFactory(15);
|
24
|
-
expect(PackedCharacter_15.sizeInFields()).toBe(1);
|
25
|
-
});
|
26
|
-
it('throws for input >= 16 chars', () => {
|
27
|
-
expect(() => PackedCharacterFactory(15)).not.toThrow();
|
28
|
-
expect(() => PackedCharacterFactory(16)).toThrow();
|
29
|
-
});
|
30
|
-
});
|
31
|
-
//# sourceMappingURL=PackedCharacter.test.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"PackedCharacter.test.js","sourceRoot":"","sources":["../../../../src/lib/packed-types/PackedCharacter.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAE3D,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,EAAE,CAAC,2CAA2C,EAAE,KAAK,IAAI,EAAE;QACzD,MAAM,QAAQ,GAAG,iBAAiB,CAAC;QACnC,IAAI,YAAY,GAAG,EAAE,CAAC;QACtB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QA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GAAG,EAAE,CAAC,sBAAsB,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;QACvD,MAAM,CAAC,GAAG,EAAE,CAAC,sBAAsB,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;IACrD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
package/build/src/lib/scratch.js
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
import { Character } from 'snarkyjs';
|
2
|
-
import { PackedStringFactory } from './packed-types/PackedString';
|
3
|
-
const main = () => {
|
4
|
-
const vitalik_dot_eth = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045';
|
5
|
-
// length = 42 ~ 3 ZkStringFragments
|
6
|
-
console.log(vitalik_dot_eth, vitalik_dot_eth.length);
|
7
|
-
let myCharacters = [];
|
8
|
-
for (let i = 0; i < vitalik_dot_eth.length; i++) {
|
9
|
-
myCharacters.push(Character.fromString(vitalik_dot_eth[i]));
|
10
|
-
}
|
11
|
-
const EthAddressString = PackedStringFactory(42);
|
12
|
-
const myEthAddress = new EthAddressString(EthAddressString.pack(myCharacters), myCharacters);
|
13
|
-
console.log(EthAddressString.unpack(myEthAddress.packed).toString());
|
14
|
-
};
|
15
|
-
main();
|
16
|
-
//# sourceMappingURL=scratch.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"scratch.js","sourceRoot":"","sources":["../../../src/lib/scratch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAElE,MAAM,IAAI,GAAG,GAAG,EAAE;IAChB,MAAM,eAAe,GAAG,4CAA4C,CAAC;IAErE,oCAAoC;IACpC,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC;IAErD,IAAI,YAAY,GAAG,EAAE,CAAC;IACtB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,eAAe,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QAC/C,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;KAC7D;IAED,MAAM,gBAAgB,GAAG,mBAAmB,CAAC,EAAE,CAAC,CAAC;IACjD,MAAM,YAAY,GAAG,IAAI,gBAAgB,CACvC,gBAAgB,CAAC,IAAI,CAAC,YAAY,CAAC,EACnC,YAAY,CACb,CAAC;IAEF,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;AACvE,CAAC,CAAC;AAEF,IAAI,EAAE,CAAC"}
|
@@ -1,51 +0,0 @@
|
|
1
|
-
import { Field, Bool } from 'snarkyjs';
|
2
|
-
export declare function PackedBoolFactory(l: number): {
|
3
|
-
new (packed: import("snarkyjs/dist/node/lib/field").Field, aux: import("snarkyjs/dist/node/lib/bool").Bool[]): {
|
4
|
-
packed: import("snarkyjs/dist/node/lib/field").Field;
|
5
|
-
aux: import("snarkyjs/dist/node/lib/bool").Bool[];
|
6
|
-
bitSize: bigint;
|
7
|
-
};
|
8
|
-
/**
|
9
|
-
* Unpacks a Field into its component Bool parts
|
10
|
-
* @param value
|
11
|
-
* @returns the unpacked auxilliary data used to pack the value
|
12
|
-
*/
|
13
|
-
toAuxiliary(value?: {
|
14
|
-
packed: Field;
|
15
|
-
} | undefined): Bool[];
|
16
|
-
pack(aux: Bool[]): Field;
|
17
|
-
type: import("snarkyjs/dist/node/bindings/lib/provable-snarky").ProvableExtended<{
|
18
|
-
packed: import("snarkyjs/dist/node/lib/field").Field;
|
19
|
-
}, {
|
20
|
-
packed: string;
|
21
|
-
}>;
|
22
|
-
l: number;
|
23
|
-
unpack(f: import("snarkyjs/dist/node/lib/field").Field): import("snarkyjs/dist/node/lib/bool").Bool[];
|
24
|
-
check(value: {
|
25
|
-
packed: import("snarkyjs/dist/node/lib/field").Field;
|
26
|
-
}): void;
|
27
|
-
_isStruct: true;
|
28
|
-
toFields: (value: {
|
29
|
-
packed: import("snarkyjs/dist/node/lib/field").Field;
|
30
|
-
}) => import("snarkyjs/dist/node/lib/field").Field[];
|
31
|
-
fromFields: (fields: import("snarkyjs/dist/node/lib/field").Field[]) => {
|
32
|
-
packed: import("snarkyjs/dist/node/lib/field").Field;
|
33
|
-
};
|
34
|
-
sizeInFields(): number;
|
35
|
-
toInput: (x: {
|
36
|
-
packed: import("snarkyjs/dist/node/lib/field").Field;
|
37
|
-
}) => {
|
38
|
-
fields?: import("snarkyjs/dist/node/lib/field").Field[] | undefined;
|
39
|
-
packed?: [import("snarkyjs/dist/node/lib/field").Field, number][] | undefined;
|
40
|
-
};
|
41
|
-
toJSON: (x: {
|
42
|
-
packed: import("snarkyjs/dist/node/lib/field").Field;
|
43
|
-
}) => {
|
44
|
-
packed: string;
|
45
|
-
};
|
46
|
-
fromJSON: (x: {
|
47
|
-
packed: string;
|
48
|
-
}) => {
|
49
|
-
packed: import("snarkyjs/dist/node/lib/field").Field;
|
50
|
-
};
|
51
|
-
};
|
@@ -1,34 +0,0 @@
|
|
1
|
-
import { Field, Provable, Bool } from 'snarkyjs';
|
2
|
-
import { PackingPlant } from './PackingPlant';
|
3
|
-
const SIZE_IN_BITS = 1n;
|
4
|
-
export function PackedBoolFactory(l) {
|
5
|
-
class PackedBool_ extends PackingPlant(Bool, l, SIZE_IN_BITS) {
|
6
|
-
/**
|
7
|
-
* Unpacks a Field into its component Bool parts
|
8
|
-
* @param value
|
9
|
-
* @returns the unpacked auxilliary data used to pack the value
|
10
|
-
*/
|
11
|
-
static toAuxiliary(value) {
|
12
|
-
const auxiliary = Provable.witness(Provable.Array(Bool, l), () => {
|
13
|
-
let bools_ = [];
|
14
|
-
let packedN = value?.packed.toBigInt() || 0n;
|
15
|
-
for (let i = 0; i < l; i++) {
|
16
|
-
bools_[i] = packedN & ((1n << SIZE_IN_BITS) - 1n);
|
17
|
-
packedN >>= SIZE_IN_BITS;
|
18
|
-
}
|
19
|
-
return bools_.map((x) => Bool.fromJSON(Boolean(x)));
|
20
|
-
});
|
21
|
-
return auxiliary;
|
22
|
-
}
|
23
|
-
static pack(aux) {
|
24
|
-
let f = Field(0);
|
25
|
-
for (let i = 0; i < l; i++) {
|
26
|
-
const c = Field((2n ** SIZE_IN_BITS) ** BigInt(i));
|
27
|
-
f = f.add(aux[i].toField().mul(c));
|
28
|
-
}
|
29
|
-
return f;
|
30
|
-
}
|
31
|
-
}
|
32
|
-
return PackedBool_;
|
33
|
-
}
|
34
|
-
//# sourceMappingURL=PackedBool.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"PackedBool.js","sourceRoot":"","sources":["../../../src/packed-types/PackedBool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,MAAM,YAAY,GAAG,EAAE,CAAC;AAExB,MAAM,UAAU,iBAAiB,CAAC,CAAS;IACzC,MAAM,WAAY,SAAQ,YAAY,CAAC,IAAI,EAAE,CAAC,EAAE,YAAY,CAAC;QAC3D;;;;WAIG;QACH,MAAM,CAAC,WAAW,CAAC,KAAqC;YACtD,MAAM,SAAS,GAAG,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE;gBAC/D,IAAI,MAAM,GAAa,EAAE,CAAC;gBAC1B,IAAI,OAAO,GAAG,KAAK,EAAE,MAAM,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC;gBAC7C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,E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