o1js-pack 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,44 +1,53 @@
1
1
  import { Field, Character } from 'o1js';
2
- export declare function PackedStringFactory(l: number): {
3
- new (packed: import("o1js/dist/node/lib/field.js").Field[], aux: Character[]): {
2
+ export declare function PackedStringFactory(l?: number): {
3
+ new (packed: import("o1js/dist/node/lib/field.js").Field[]): {
4
4
  toString(): string;
5
- packed: import("o1js/dist/node/lib/field.js").Field[];
6
- aux: Character[];
7
5
  bitSize: bigint;
8
6
  assertEquals(other: {
9
- packed: import("o1js/dist/node/lib/field.js").Field[];
10
- aux: Character[];
11
7
  bitSize: bigint;
12
8
  assertEquals(other: any): void;
9
+ packed: import("o1js/dist/node/lib/field.js").Field[];
13
10
  }): void;
11
+ packed: import("o1js/dist/node/lib/field.js").Field[];
14
12
  };
15
- toAuxiliary(value?: {
16
- packed: Array<Field>;
17
- } | undefined): Character[];
18
- pack(aux: Character[]): Array<Field>;
19
- fromString(str: string): {
13
+ extractField(input: Character): Field;
14
+ sizeInBits(): bigint;
15
+ elementsPerField(): number;
16
+ /**
17
+ *
18
+ * @param fields Array of Fields, containing packed Characters
19
+ * @returns Array of Character
20
+ */
21
+ unpack(fields: Field[]): Character[];
22
+ /**
23
+ *
24
+ * @param characters Array of Character to be packed
25
+ * @returns Instance of the implementing class
26
+ */
27
+ fromCharacters(characters: Array<Character>): {
20
28
  toString(): string;
21
- packed: import("o1js/dist/node/lib/field.js").Field[];
22
- aux: Character[];
23
29
  bitSize: bigint;
24
30
  assertEquals(other: {
25
- packed: import("o1js/dist/node/lib/field.js").Field[];
26
- aux: Character[];
27
31
  bitSize: bigint;
28
32
  assertEquals(other: any): void;
33
+ packed: import("o1js/dist/node/lib/field.js").Field[];
29
34
  }): void;
35
+ packed: import("o1js/dist/node/lib/field.js").Field[];
30
36
  };
31
- fromAuxiliary(aux: Array<Character>): {
37
+ /**
38
+ *
39
+ * @param str string to be packed
40
+ * @returns Instance of the implementing class
41
+ */
42
+ fromString(str: string): {
32
43
  toString(): string;
33
- packed: import("o1js/dist/node/lib/field.js").Field[];
34
- aux: Character[];
35
44
  bitSize: bigint;
36
45
  assertEquals(other: {
37
- packed: import("o1js/dist/node/lib/field.js").Field[];
38
- aux: Character[];
39
46
  bitSize: bigint;
40
47
  assertEquals(other: any): void;
48
+ packed: import("o1js/dist/node/lib/field.js").Field[];
41
49
  }): void;
50
+ packed: import("o1js/dist/node/lib/field.js").Field[];
42
51
  };
43
52
  type: import("o1js/dist/node/bindings/lib/provable-snarky.js").ProvableExtended<{
44
53
  packed: import("o1js/dist/node/lib/field.js").Field[];
@@ -47,11 +56,16 @@ export declare function PackedStringFactory(l: number): {
47
56
  }>;
48
57
  l: number;
49
58
  n: number;
50
- unpack(fields: import("o1js/dist/node/lib/field.js").Field[]): Character[];
59
+ checkPack(unpacked: Character[]): void;
60
+ pack(unpacked: Character[]): import("o1js/dist/node/lib/field.js").Field[];
61
+ unpackToBigints(fields: import("o1js/dist/node/lib/field.js").Field[]): bigint[];
51
62
  _isStruct: true;
52
63
  toFields: (value: {
53
64
  packed: import("o1js/dist/node/lib/field.js").Field[];
54
65
  }) => import("o1js/dist/node/lib/field.js").Field[];
66
+ toAuxiliary: (value?: {
67
+ packed: import("o1js/dist/node/lib/field.js").Field[];
68
+ } | undefined) => any[];
55
69
  fromFields: (fields: import("o1js/dist/node/lib/field.js").Field[]) => {
56
70
  packed: import("o1js/dist/node/lib/field.js").Field[];
57
71
  };
@@ -1,75 +1,52 @@
1
1
  import { Field, Provable, Character } from 'o1js';
2
2
  import { MultiPackingPlant } from '../PackingPlant.js';
3
3
  const SIZE_IN_BITS = 16n;
4
+ const L = 15; // Default to one-field worth of characters
4
5
  const CHARS_PER_FIELD = 15;
5
- export function PackedStringFactory(l) {
6
+ export function PackedStringFactory(l = L) {
6
7
  class PackedString_ extends MultiPackingPlant(Character, l, SIZE_IN_BITS) {
7
- static toAuxiliary(value) {
8
- const auxiliary = Provable.witness(Provable.Array(Character, l), () => {
9
- let uints_ = new Array(l);
10
- uints_.fill(0n);
11
- let packedNs = new Array(this.n);
12
- packedNs.fill(0n);
13
- const packedArg = new Array(this.n);
14
- packedArg.fill(Field(0), 0, this.n);
15
- for (let i = 0; i < this.n; i++) {
16
- if (value?.packed[i]) {
17
- packedArg[i] = value?.packed[i];
18
- }
19
- }
20
- if (packedArg.length !== this.n) {
21
- throw new Error(`Packed value must be exactly ${this.n} in length`);
22
- }
23
- for (let i = 0; i < this.n; i++) {
24
- packedNs[i] = packedArg[i].toConstant().toBigInt();
25
- }
26
- for (let i = 0; i < packedNs.length; i++) {
27
- let packedN = packedNs[i];
28
- for (let j = 0; j < CHARS_PER_FIELD; j++) {
29
- const k = i * CHARS_PER_FIELD + j;
30
- uints_[k] = packedN & ((1n << SIZE_IN_BITS) - 1n);
31
- packedN >>= SIZE_IN_BITS;
32
- }
33
- }
34
- return uints_.map((x) => Character.fromString(String.fromCharCode(Number(x))));
8
+ static extractField(input) {
9
+ return input.value;
10
+ }
11
+ static sizeInBits() {
12
+ return SIZE_IN_BITS;
13
+ }
14
+ static elementsPerField() {
15
+ return CHARS_PER_FIELD;
16
+ }
17
+ /**
18
+ *
19
+ * @param fields Array of Fields, containing packed Characters
20
+ * @returns Array of Character
21
+ */
22
+ static unpack(fields) {
23
+ const unpacked = Provable.witness(Provable.Array(Character, l), () => {
24
+ let unpacked = this.unpackToBigints(fields);
25
+ return unpacked.map((x) => Character.fromString(String.fromCharCode(Number(x))));
35
26
  });
36
- return auxiliary;
27
+ return unpacked;
37
28
  }
38
- static pack(aux) {
39
- let fields = [];
40
- let mutableAux = [...aux];
41
- while (mutableAux.length > 0) {
42
- const initialChar = mutableAux.shift();
43
- if (!initialChar) {
44
- throw new Error('Unexpected Array Length');
45
- }
46
- // f = initialChar.value is the same as f = 0; f += char.value * c^0;
47
- // If f is initialized as 0, then it is a "constant" field and can't be added to a "variable" field in a proof
48
- let f = initialChar.value;
49
- const n = Math.min(mutableAux.length + 1, CHARS_PER_FIELD);
50
- for (let i = 1; i < n; i++) {
51
- const char = mutableAux.shift();
52
- if (!char) {
53
- throw new Error('Unexpected Array Length');
54
- }
55
- const value = char.value || Field(0);
56
- const c = Field((2n ** SIZE_IN_BITS) ** BigInt(i));
57
- f = f.add(value.mul(c));
58
- }
59
- fields.push(f);
60
- }
61
- return fields;
29
+ /**
30
+ *
31
+ * @param characters Array of Character to be packed
32
+ * @returns Instance of the implementing class
33
+ */
34
+ static fromCharacters(characters) {
35
+ const packed = this.pack(characters);
36
+ return new PackedString_(packed);
62
37
  }
38
+ /**
39
+ *
40
+ * @param str string to be packed
41
+ * @returns Instance of the implementing class
42
+ */
63
43
  static fromString(str) {
64
- let characters = [];
44
+ let characters = new Array(l);
45
+ characters.fill(new Character(Field(0)), 0, l);
65
46
  for (let i = 0; i < str.length; i++) {
66
- characters.push(Character.fromString(str[i]));
47
+ characters[i] = Character.fromString(str[i]);
67
48
  }
68
- return this.fromAuxiliary(characters);
69
- }
70
- static fromAuxiliary(aux) {
71
- const packed = this.pack(aux);
72
- return new PackedString_(packed, aux);
49
+ return this.fromCharacters(characters);
73
50
  }
74
51
  toString() {
75
52
  const nullChar = String.fromCharCode(0);
@@ -1 +1 @@
1
- {"version":3,"file":"PackedString.js","sourceRoot":"","sources":["../../../../src/lib/packed-types/PackedString.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEvD,MAAM,YAAY,GAAG,GAAG,CAAC;AACzB,MAAM,eAAe,GAAG,EAAE,CAAC;AAE3B,MAAM,UAAU,mBAAmB,CAAC,CAAS;IAC3C,MAAM,aAAc,SAAQ,iBAAiB,CAAC,SAAS,EAAE,CAAC,EAAE,YAAY,CAAC;QACvE,MAAM,CAAC,WAAW,CAChB,KAA4C;YAE5C,MAAM,SAAS,GAAG,QAAQ,CAAC,O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I,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YACrC,OAAO,IAAI,aAAa,CAAC,MAAM,CAAC,CAAC;QACnC,CAAC;QAED;;;;WAIG;QACH,MAAM,CAAC,UAAU,CAAC,GAAW;YAC3B,IAAI,UAAU,GAAqB,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC;YAChD,UAAU,CAAC,IAAI,CAAC,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;YAC/C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;gBACnC,UAAU,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;aAC9C;YACD,OAAO,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;QACzC,CAAC;QAED,QAAQ;YACN,MAAM,QAAQ,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;YACxC,OAAO,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;iBACrC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,KAAK,QAAQ,CAAC;iBACxC,IAAI,CAAC,EAAE,CAAC,CAAC;QACd,CAAC;KACF;IACD,OAAO,aAAa,CAAC;AACvB,CAAC"}
@@ -16,8 +16,8 @@ describe('PackedString', () => {
16
16
  const myEthAddress = EthAddressString.fromString(vitalik_dot_eth);
17
17
  expect(myEthAddress.toString()).toBe(vitalik_dot_eth);
18
18
  });
19
- it('#fromAuxilliary', () => {
20
- const myEthAddress = EthAddressString.fromAuxiliary(characters);
19
+ it('#fromCharacters', () => {
20
+ const myEthAddress = EthAddressString.fromCharacters(characters);
21
21
  expect(myEthAddress.toString()).toBe(vitalik_dot_eth);
22
22
  });
23
23
  it('#pack and #unPack', () => {
@@ -54,7 +54,7 @@ describe('PackedString', () => {
54
54
  class String10 extends PackedStringFactory(10) {
55
55
  }
56
56
  expect(() => {
57
- const string11 = String10.fromString('abcdefghijk');
57
+ String10.fromString('abcdefghijk');
58
58
  }).toThrow();
59
59
  });
60
60
  it('Exceeds maximum size string', () => {
@@ -74,7 +74,7 @@ describe('PackedString', () => {
74
74
  it('Initializes a string', () => {
75
75
  expect(() => {
76
76
  Provable.runAndCheck(() => {
77
- const myEthAddress = new EthAddressString(outsideEthAddress.packed, outsideEthAddress.aux);
77
+ const myEthAddress = new EthAddressString(outsideEthAddress.packed);
78
78
  EthAddressString.check({ packed: myEthAddress.packed });
79
79
  });
80
80
  }).not.toThrow();
@@ -82,7 +82,7 @@ describe('PackedString', () => {
82
82
  it('#assertEquals', () => {
83
83
  expect(() => {
84
84
  Provable.runAndCheck(() => {
85
- const myEthAddress = new EthAddressString(outsideEthAddress.packed, outsideEthAddress.aux);
85
+ const myEthAddress = new EthAddressString(outsideEthAddress.packed);
86
86
  myEthAddress.assertEquals(outsideEthAddress);
87
87
  });
88
88
  }).not.toThrow();
@@ -90,7 +90,7 @@ describe('PackedString', () => {
90
90
  Provable.runAndCheck(() => {
91
91
  const fakePacked = [...outsideEthAddress.packed];
92
92
  fakePacked[0] = fakePacked[0].add(1);
93
- const myEthAddress = new EthAddressString(fakePacked, outsideEthAddress.aux);
93
+ const myEthAddress = new EthAddressString(fakePacked);
94
94
  myEthAddress.assertEquals(outsideEthAddress);
95
95
  });
96
96
  }).toThrow();
@@ -1 +1 @@
1
- {"version":3,"file":"PackedString.test.js","sourceRoot":"","sources":["../../../../src/lib/packed-types/PackedString.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAS,QAAQ,EAAE,MAAM,MAAM,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAErD,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,QAAQ,CAAC,wBAAwB,E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Q,CAAC,WAAW,CAAC,GAAG,EAAE;oBACxB,MAAM,YAAY,GAAG,IAAI,gBAAgB,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;oBAEpE,YAAY,CAAC,YAAY,CAAC,iBAAiB,CAAC,CAAC;gBAC/C,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;YAEjB,MAAM,CAAC,GAAG,EAAE;gBACV,QAAQ,CAAC,WAAW,CAAC,GAAG,EAAE;oBACxB,MAAM,UAAU,GAAG,CAAC,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC;oBACjD,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;oBACrC,MAAM,YAAY,GAAG,IAAI,gBAAgB,CAAC,UAAU,CAAC,CAAC;oBAEtD,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"}
@@ -1,44 +1,52 @@
1
1
  import { Field, UInt32 } from 'o1js';
2
- export declare function PackedUInt32Factory(l: number): {
3
- new (packed: import("o1js/dist/node/lib/field.js").Field, aux: UInt32[]): {
2
+ export declare function PackedUInt32Factory(l?: number): {
3
+ new (packed: import("o1js/dist/node/lib/field.js").Field): {
4
4
  toBigInts(): Array<bigint>;
5
- packed: import("o1js/dist/node/lib/field.js").Field;
6
- aux: UInt32[];
7
5
  bitSize: bigint;
8
6
  assertEquals(other: {
9
- packed: import("o1js/dist/node/lib/field.js").Field;
10
- aux: UInt32[];
11
7
  bitSize: bigint;
12
8
  assertEquals(other: any): void;
9
+ packed: import("o1js/dist/node/lib/field.js").Field;
13
10
  }): void;
11
+ packed: import("o1js/dist/node/lib/field.js").Field;
14
12
  };
15
- toAuxiliary(value?: {
16
- packed: Field;
17
- } | undefined): Array<UInt32>;
18
- pack(aux: Array<UInt32>): Field;
19
- fromAuxiliary(aux: Array<UInt32>): {
13
+ extractField(input: UInt32): Field;
14
+ sizeInBits(): bigint;
15
+ /**
16
+ *
17
+ * @param f Field, packed with the information, as returned by #pack
18
+ * @returns Array of UInt32
19
+ */
20
+ unpack(f: Field): UInt32[];
21
+ /**
22
+ *
23
+ * @param uint32s Array of UInt32s to be packed
24
+ * @returns Instance of the implementing class
25
+ */
26
+ fromUInt32s(uint32s: Array<UInt32>): {
20
27
  toBigInts(): Array<bigint>;
21
- packed: import("o1js/dist/node/lib/field.js").Field;
22
- aux: UInt32[];
23
28
  bitSize: bigint;
24
29
  assertEquals(other: {
25
- packed: import("o1js/dist/node/lib/field.js").Field;
26
- aux: UInt32[];
27
30
  bitSize: bigint;
28
31
  assertEquals(other: any): void;
32
+ packed: import("o1js/dist/node/lib/field.js").Field;
29
33
  }): void;
34
+ packed: import("o1js/dist/node/lib/field.js").Field;
30
35
  };
36
+ /**
37
+ *
38
+ * @param bigints Array of bigints to be packed
39
+ * @returns Instance of the implementing class
40
+ */
31
41
  fromBigInts(bigints: Array<bigint>): {
32
42
  toBigInts(): Array<bigint>;
33
- packed: import("o1js/dist/node/lib/field.js").Field;
34
- aux: UInt32[];
35
43
  bitSize: bigint;
36
44
  assertEquals(other: {
37
- packed: import("o1js/dist/node/lib/field.js").Field;
38
- aux: UInt32[];
39
45
  bitSize: bigint;
40
46
  assertEquals(other: any): void;
47
+ packed: import("o1js/dist/node/lib/field.js").Field;
41
48
  }): void;
49
+ packed: import("o1js/dist/node/lib/field.js").Field;
42
50
  };
43
51
  type: import("o1js/dist/node/bindings/lib/provable-snarky.js").ProvableExtended<{
44
52
  packed: import("o1js/dist/node/lib/field.js").Field;
@@ -46,11 +54,16 @@ export declare function PackedUInt32Factory(l: number): {
46
54
  packed: string;
47
55
  }>;
48
56
  l: number;
49
- unpack(f: import("o1js/dist/node/lib/field.js").Field): UInt32[];
57
+ checkPack(unpacked: UInt32[]): void;
58
+ pack(unpacked: UInt32[]): import("o1js/dist/node/lib/field.js").Field;
59
+ unpackToBigints(f: import("o1js/dist/node/lib/field.js").Field): bigint[];
50
60
  _isStruct: true;
51
61
  toFields: (value: {
52
62
  packed: import("o1js/dist/node/lib/field.js").Field;
53
63
  }) => import("o1js/dist/node/lib/field.js").Field[];
64
+ toAuxiliary: (value?: {
65
+ packed: import("o1js/dist/node/lib/field.js").Field;
66
+ } | undefined) => any[];
54
67
  fromFields: (fields: import("o1js/dist/node/lib/field.js").Field[]) => {
55
68
  packed: import("o1js/dist/node/lib/field.js").Field;
56
69
  };
@@ -1,43 +1,44 @@
1
- import { Field, Provable, UInt32 } from 'o1js';
1
+ import { Provable, UInt32 } from 'o1js';
2
2
  import { PackingPlant } from '../PackingPlant.js';
3
+ const L = 7; // 7 32-bit uints fit in one Field
3
4
  const SIZE_IN_BITS = 32n;
4
- export function PackedUInt32Factory(l) {
5
+ export function PackedUInt32Factory(l = L) {
5
6
  class PackedUInt32_ extends PackingPlant(UInt32, l, SIZE_IN_BITS) {
6
- static toAuxiliary(value) {
7
- const auxiliary = Provable.witness(Provable.Array(UInt32, l), () => {
8
- let uints_ = new Array(l);
9
- uints_.fill(0n);
10
- let packedN;
11
- if (value && value.packed) {
12
- packedN = value.packed.toBigInt();
13
- }
14
- else {
15
- throw new Error('No Packed Value Provided');
16
- }
17
- for (let i = 0; i < l; i++) {
18
- uints_[i] = packedN & ((1n << SIZE_IN_BITS) - 1n);
19
- packedN >>= SIZE_IN_BITS;
20
- }
21
- return uints_.map((x) => UInt32.from(x));
22
- });
23
- return auxiliary;
7
+ static extractField(input) {
8
+ return input.value;
9
+ }
10
+ static sizeInBits() {
11
+ return SIZE_IN_BITS;
24
12
  }
25
- static pack(aux) {
26
- let f = aux[0].value;
27
- const n = Math.min(aux.length, l);
28
- for (let i = 1; i < n; i++) {
29
- const c = Field((2n ** SIZE_IN_BITS) ** BigInt(i));
30
- f = f.add(aux[i].value.mul(c));
31
- }
32
- return f;
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
+ return unpacked;
33
24
  }
34
- static fromAuxiliary(aux) {
35
- const packed = PackedUInt32_.pack(aux);
36
- return new PackedUInt32_(packed, aux);
25
+ /**
26
+ *
27
+ * @param uint32s Array of UInt32s to be packed
28
+ * @returns Instance of the implementing class
29
+ */
30
+ static fromUInt32s(uint32s) {
31
+ const packed = PackedUInt32_.pack(uint32s);
32
+ return new PackedUInt32_(packed);
37
33
  }
34
+ /**
35
+ *
36
+ * @param bigints Array of bigints to be packed
37
+ * @returns Instance of the implementing class
38
+ */
38
39
  static fromBigInts(bigints) {
39
40
  const uint32s = bigints.map((x) => UInt32.from(x));
40
- return this.fromAuxiliary(uint32s);
41
+ return PackedUInt32_.fromUInt32s(uint32s);
41
42
  }
42
43
  toBigInts() {
43
44
  return PackedUInt32_.unpack(this.packed).map((x) => x.toBigint());
@@ -1 +1 @@
1
- {"version":3,"file":"PackedUInt32.js","sourceRoot":"","sources":["../../../../src/lib/packed-types/PackedUInt32.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,YAAY,GAAG,GAAG,CAAC;AAEzB,MAAM,UAAU,mBAAmB,CAAC,CAAS;IAC3C,MAAM,aAAc,SAAQ,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,YAAY,CAAC;QAC/D,MAAM,CAAC,WAAW,CAAC,KAAqC;YACtD,MAAM,SAAS,GAAG,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC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AAU;YACf,OAAO,YAAY,CAAC;QACtB,CAAC;QAED;;;;WAIG;QACH,MAAM,CAAC,MAAM,CAAC,CAAQ;YACpB,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE;gBAChE,MAAM,QAAQ,GAAG,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;gBACzC,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;YAC7C,CAAC,CAAC,CAAC;YACH,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,7 +1,7 @@
1
1
  import { Provable, UInt32 } from 'o1js';
2
2
  import { PackedUInt32Factory } from './PackedUInt32';
3
3
  describe('PackedUInt32', () => {
4
- class PackedUInt32 extends PackedUInt32Factory(7) {
4
+ class PackedUInt32 extends PackedUInt32Factory() {
5
5
  }
6
6
  describe('Outside of the circuit', () => {
7
7
  const bigints = [10n, 2n ** 32n - 1n, 0n, 10n, 2n ** 32n - 100n, 42n, 0n];
@@ -59,7 +59,7 @@ describe('PackedUInt32', () => {
59
59
  it('Initializes', () => {
60
60
  expect(() => {
61
61
  Provable.runAndCheck(() => {
62
- const packedUInt32 = new PackedUInt32(outsidePackedUInt.packed, outsidePackedUInt.aux);
62
+ const packedUInt32 = new PackedUInt32(outsidePackedUInt.packed);
63
63
  PackedUInt32.check({ packed: packedUInt32.packed });
64
64
  });
65
65
  }).not.toThrow();
@@ -67,14 +67,14 @@ describe('PackedUInt32', () => {
67
67
  it('#assertEquals', () => {
68
68
  expect(() => {
69
69
  Provable.runAndCheck(() => {
70
- const packedUInt32 = new PackedUInt32(outsidePackedUInt.packed, outsidePackedUInt.aux);
70
+ const packedUInt32 = new PackedUInt32(outsidePackedUInt.packed);
71
71
  packedUInt32.assertEquals(outsidePackedUInt);
72
72
  });
73
73
  }).not.toThrow();
74
74
  expect(() => {
75
75
  Provable.runAndCheck(() => {
76
76
  const fakePacked = outsidePackedUInt.packed.add(32);
77
- const packedUInt32 = new PackedUInt32(fakePacked, outsidePackedUInt.aux);
77
+ const packedUInt32 = new PackedUInt32(fakePacked);
78
78
  packedUInt32.assertEquals(outsidePackedUInt);
79
79
  });
80
80
  }).toThrow();
@@ -1 +1 @@
1
- {"version":3,"file":"PackedUInt32.test.js","sourceRoot":"","sources":["../../../../src/lib/packed-types/PackedUInt32.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAErD,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,MAAM,YAAa,SAAQ,mBAAmB,CAAC,CAAC,CAAC;KAAG;IACpD,QAAQ,CAAC,wBAAwB,EAAE,GAAG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AY,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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "o1js-pack",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "",
5
5
  "author": "45930",
6
6
  "license": "Apache-2.0",
@@ -0,0 +1,67 @@
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(new TextInput(initProof.publicInput.packed).packed),
60
+ Character.fromString('Z')
61
+ );
62
+ Poseidon.hash(proofTextInput.packed).assertEquals(
63
+ Poseidon.hash(p1.publicInput.packed)
64
+ );
65
+ });
66
+ });
67
+ });