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
@@ -1,49 +1,50 @@
|
|
1
|
-
import { Provable, UInt32 } from 'o1js';
|
2
|
-
import { PackingPlant } from '../PackingPlant.js';
|
3
|
-
const L = 7; // 7 32-bit uints fit in one Field
|
4
|
-
const SIZE_IN_BITS = 32n;
|
5
|
-
export function PackedUInt32Factory(l = L) {
|
6
|
-
class PackedUInt32_ extends PackingPlant(UInt32, l, SIZE_IN_BITS) {
|
7
|
-
static extractField(input) {
|
8
|
-
return input.value;
|
9
|
-
}
|
10
|
-
static sizeInBits() {
|
11
|
-
return SIZE_IN_BITS;
|
12
|
-
}
|
13
|
-
/**
|
14
|
-
*
|
15
|
-
* @param f Field, packed with the information, as returned by #pack
|
16
|
-
* @returns Array of UInt32
|
17
|
-
*/
|
18
|
-
static unpack(f) {
|
19
|
-
const unpacked = Provable.witness(Provable.Array(UInt32, l), () => {
|
20
|
-
const unpacked = this.unpackToBigints(f);
|
21
|
-
return unpacked.map((x) => UInt32.from(x));
|
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
|
-
|
1
|
+
import { Provable, UInt32 } from 'o1js';
|
2
|
+
import { PackingPlant } from '../PackingPlant.js';
|
3
|
+
const L = 7; // 7 32-bit uints fit in one Field
|
4
|
+
const SIZE_IN_BITS = 32n;
|
5
|
+
export function PackedUInt32Factory(l = L) {
|
6
|
+
class PackedUInt32_ extends PackingPlant(UInt32, l, SIZE_IN_BITS) {
|
7
|
+
static extractField(input) {
|
8
|
+
return input.value;
|
9
|
+
}
|
10
|
+
static sizeInBits() {
|
11
|
+
return SIZE_IN_BITS;
|
12
|
+
}
|
13
|
+
/**
|
14
|
+
*
|
15
|
+
* @param f Field, packed with the information, as returned by #pack
|
16
|
+
* @returns Array of UInt32
|
17
|
+
*/
|
18
|
+
static unpack(f) {
|
19
|
+
const unpacked = Provable.witness(Provable.Array(UInt32, l), () => {
|
20
|
+
const unpacked = this.unpackToBigints(f);
|
21
|
+
return unpacked.map((x) => UInt32.from(x));
|
22
|
+
});
|
23
|
+
f.assertEquals(PackedUInt32_.pack(unpacked));
|
24
|
+
return unpacked;
|
25
|
+
}
|
26
|
+
/**
|
27
|
+
*
|
28
|
+
* @param uint32s Array of UInt32s to be packed
|
29
|
+
* @returns Instance of the implementing class
|
30
|
+
*/
|
31
|
+
static fromUInt32s(uint32s) {
|
32
|
+
const packed = PackedUInt32_.pack(uint32s);
|
33
|
+
return new PackedUInt32_(packed);
|
34
|
+
}
|
35
|
+
/**
|
36
|
+
*
|
37
|
+
* @param bigints Array of bigints to be packed
|
38
|
+
* @returns Instance of the implementing class
|
39
|
+
*/
|
40
|
+
static fromBigInts(bigints) {
|
41
|
+
const uint32s = bigints.map((x) => UInt32.from(x));
|
42
|
+
return PackedUInt32_.fromUInt32s(uint32s);
|
43
|
+
}
|
44
|
+
toBigInts() {
|
45
|
+
return PackedUInt32_.unpack(this.packed).map((x) => x.toBigint());
|
46
|
+
}
|
47
|
+
}
|
48
|
+
return PackedUInt32_;
|
49
|
+
}
|
49
50
|
//# sourceMappingURL=PackedUInt32.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"PackedUInt32.js","sourceRoot":"","sources":["../../../../src/lib/packed-types/PackedUInt32.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,QAAQ,EAAE,MAAM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AC,QAAQ,CAAC,CAAC,CAAC;YAC7C,OAAO,QAAQ,CAAC;QAClB,CAAC;QAED;;;;WAIG;QACH,MAAM,CAAC,WAAW,CAAC,OAAsB;YACvC,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC3C,OAAO,IAAI,aAAa,CAAC,MAAM,CAAC,CAAC;QACnC,CAAC;QAED;;;;WAIG;QACH,MAAM,CAAC,WAAW,CAAC,OAAsB;YACvC,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;YACnD,OAAO,aAAa,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QAC5C,CAAC;QAED,SAAS;YACP,OAAO,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;QACpE,CAAC;KACF;IACD,OAAO,aAAa,CAAC;AACvB,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
export {};
|
1
|
+
export {};
|
@@ -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
|
package/package.json
CHANGED
@@ -56,12 +56,10 @@ describe('End to End Text Input Test', () => {
|
|
56
56
|
const p1 = await TextInputProgram.changeFirstLetter(
|
57
57
|
proofTextInput,
|
58
58
|
initProof,
|
59
|
-
TextInput.unpack(
|
59
|
+
TextInput.unpack(initProof.publicInput.packed),
|
60
60
|
Character.fromString('Z')
|
61
61
|
);
|
62
|
-
|
63
|
-
Poseidon.hash(p1.publicInput.packed)
|
64
|
-
);
|
62
|
+
proofTextInput.assertEquals(p1.publicInput);
|
65
63
|
});
|
66
64
|
});
|
67
65
|
});
|
@@ -6,10 +6,9 @@ import {
|
|
6
6
|
Provable,
|
7
7
|
Field,
|
8
8
|
} from 'o1js';
|
9
|
-
import {
|
9
|
+
import { MultiPackedStringFactory } from '../../src/lib/packed-types/PackedString';
|
10
10
|
|
11
|
-
|
12
|
-
export class TextInput extends PackedStringFactory(MAX_LENGTH) {}
|
11
|
+
export class TextInput extends MultiPackedStringFactory(3) {}
|
13
12
|
|
14
13
|
export const TextInputProgram = Experimental.ZkProgram({
|
15
14
|
publicInput: TextInput,
|
@@ -23,11 +22,7 @@ export const TextInputProgram = Experimental.ZkProgram({
|
|
23
22
|
},
|
24
23
|
},
|
25
24
|
changeFirstLetter: {
|
26
|
-
privateInputs: [
|
27
|
-
SelfProof,
|
28
|
-
Provable.Array(Character, MAX_LENGTH),
|
29
|
-
Character,
|
30
|
-
],
|
25
|
+
privateInputs: [SelfProof, Provable.Array(Character, 45), Character],
|
31
26
|
method(
|
32
27
|
newState: TextInput,
|
33
28
|
oldProof: SelfProof<TextInput, TextInput>,
|
@@ -18,24 +18,18 @@ export const VotesProgram = Experimental.ZkProgram({
|
|
18
18
|
privateInputs: [SelfProof],
|
19
19
|
method(newState: Votes, oldProof: SelfProof<Votes, Votes>) {
|
20
20
|
oldProof.verify();
|
21
|
-
const
|
22
|
-
|
23
|
-
|
24
|
-
);
|
25
|
-
expectedUnpacked[0] = expectedUnpacked[0].add(1);
|
26
|
-
newState.assertEquals(Votes.fromUInt32s(expectedUnpacked));
|
21
|
+
const unpacked = Votes.unpack(oldProof.publicInput.packed);
|
22
|
+
unpacked[0] = unpacked[0].add(1);
|
23
|
+
newState.assertEquals(Votes.fromUInt32s(unpacked));
|
27
24
|
},
|
28
25
|
},
|
29
26
|
incrementIndex1: {
|
30
27
|
privateInputs: [SelfProof],
|
31
28
|
method(newState: Votes, oldProof: SelfProof<Votes, Votes>) {
|
32
29
|
oldProof.verify();
|
33
|
-
const
|
34
|
-
|
35
|
-
|
36
|
-
);
|
37
|
-
expectedUnpacked[1] = expectedUnpacked[1].add(1);
|
38
|
-
newState.assertEquals(Votes.fromUInt32s(expectedUnpacked));
|
30
|
+
const unpacked = Votes.unpack(oldProof.publicInput.packed);
|
31
|
+
unpacked[1] = unpacked[1].add(1);
|
32
|
+
newState.assertEquals(Votes.fromUInt32s(unpacked));
|
39
33
|
},
|
40
34
|
},
|
41
35
|
},
|
@@ -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;;;;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@@ -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;AAE3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AAM,kBAAkB,GAAG,sBAAsB,CAAC,EAAE,CAAC,CAAC;QAEtD,MAAM,CAAC,kBAAkB,CAAC,YAAY,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8BAA8B,EAAE,GAAG,EAAE;QACtC,MAAM,CAAC,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,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