o1js-pack 0.4.0 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +14 -29
- package/build/src/index.d.ts +2 -2
- package/build/src/index.js +2 -2
- package/build/src/index.js.map +1 -1
- package/build/src/lib/PackingPlant.d.ts +4 -12
- package/build/src/lib/PackingPlant.js +11 -12
- package/build/src/lib/PackingPlant.js.map +1 -1
- package/build/src/lib/packed-types/PackedBool.d.ts +1 -6
- package/build/src/lib/packed-types/PackedBool.js +1 -0
- package/build/src/lib/packed-types/PackedBool.js.map +1 -1
- package/build/src/lib/packed-types/PackedString.d.ts +96 -7
- package/build/src/lib/packed-types/PackedString.js +78 -10
- package/build/src/lib/packed-types/PackedString.js.map +1 -1
- package/build/src/lib/packed-types/PackedString.test.js +11 -10
- package/build/src/lib/packed-types/PackedString.test.js.map +1 -1
- package/build/src/lib/packed-types/PackedUInt32.d.ts +1 -6
- package/build/src/lib/packed-types/PackedUInt32.js +1 -0
- package/build/src/lib/packed-types/PackedUInt32.js.map +1 -1
- package/examples/smart_contract/election/README.md +3 -0
- package/examples/smart_contract/election/contract.ts +79 -0
- package/examples/smart_contract/election/run.ts +98 -0
- package/examples/zk_program/age_gate/README.md +7 -0
- package/examples/zk_program/age_gate/circuit.ts +75 -0
- package/examples/zk_program/age_gate/non-packed-circuit.ts +68 -0
- package/examples/zk_program/age_gate/non-packed-run.ts +36 -0
- package/examples/zk_program/age_gate/run.ts +35 -0
- 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,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,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACxC,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SACtD;QAED,MAAM,kBAAkB,GAAG,sBAAsB,CAAC,EAAE,CAAC,CAAC;QAEtD,MAAM,kBAAkB,GAAG,IAAI,kBAAkB,CAC/C,kBAAkB,CAAC,IAAI,CAAC,YAAY,CAAC,EACrC,YAAY,CACb,CAAC;QACF,MAAM,CAAC,GAAG,kBAAkB,CAAC,MAAM,CAAC;QACpC,MAAM,QAAQ,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAE9C,MAAM,WAAW,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAE/D,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACrC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sBAAsB,EAAE,KAAK,IAAI,EAAE;QACpC,MAAM,QAAQ,GAAG,iBAAiB,CAAC;QACnC,IAAI,YAAY,GAAG,EAAE,CAAC;QACtB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACxC,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SACtD;QAED,MAAM,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,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,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,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACtD,CAAC,CAAC,CAAC;YACH,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,CAAC,IAAI,CAAC,GAAW;YACrB,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,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;aACpC;YACD,OAAO,CAAC,CAAC;QACX,CAAC;KACF;IACD,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
@@ -1,101 +0,0 @@
|
|
1
|
-
import { Bool } from 'snarkyjs';
|
2
|
-
import { PackedBoolFactory } from './PackedBool';
|
3
|
-
describe('PackedBool', () => {
|
4
|
-
it('packs and unpacks 2 Bool values', async () => {
|
5
|
-
const myBooleans = [false, true];
|
6
|
-
const myBools = myBooleans.map((b) => Bool(b));
|
7
|
-
const PackedBool_2 = PackedBoolFactory(2);
|
8
|
-
const packedBool_2 = new PackedBool_2(PackedBool_2.pack(myBools), myBools);
|
9
|
-
const f = packedBool_2.packed;
|
10
|
-
const unpacked = PackedBool_2.unpack(f);
|
11
|
-
expect(unpacked[0].toBoolean()).toBe(false);
|
12
|
-
expect(unpacked[1].toBoolean()).toBe(true);
|
13
|
-
expect(unpacked[0].toBoolean()).toBe(packedBool_2.aux[0].toBoolean());
|
14
|
-
expect(unpacked[1].toBoolean()).toBe(packedBool_2.aux[1].toBoolean());
|
15
|
-
});
|
16
|
-
it('packs and unpacks 50 Bool values', async () => {
|
17
|
-
const myBooleans = [
|
18
|
-
true,
|
19
|
-
true,
|
20
|
-
false,
|
21
|
-
false,
|
22
|
-
true,
|
23
|
-
false,
|
24
|
-
true,
|
25
|
-
true,
|
26
|
-
true,
|
27
|
-
false,
|
28
|
-
true,
|
29
|
-
true,
|
30
|
-
false,
|
31
|
-
false,
|
32
|
-
true,
|
33
|
-
false,
|
34
|
-
true,
|
35
|
-
true,
|
36
|
-
true,
|
37
|
-
false,
|
38
|
-
true,
|
39
|
-
true,
|
40
|
-
false,
|
41
|
-
false,
|
42
|
-
true,
|
43
|
-
false,
|
44
|
-
true,
|
45
|
-
true,
|
46
|
-
true,
|
47
|
-
false,
|
48
|
-
true,
|
49
|
-
true,
|
50
|
-
false,
|
51
|
-
false,
|
52
|
-
true,
|
53
|
-
false,
|
54
|
-
true,
|
55
|
-
true,
|
56
|
-
true,
|
57
|
-
false,
|
58
|
-
true,
|
59
|
-
true,
|
60
|
-
false,
|
61
|
-
false,
|
62
|
-
true,
|
63
|
-
false,
|
64
|
-
true,
|
65
|
-
true,
|
66
|
-
true,
|
67
|
-
false,
|
68
|
-
];
|
69
|
-
const myBools = myBooleans.map((b) => Bool(b));
|
70
|
-
const PackedBool_50 = PackedBoolFactory(50);
|
71
|
-
const packedBool_50 = new PackedBool_50(PackedBool_50.pack(myBools), myBools);
|
72
|
-
const f = packedBool_50.packed;
|
73
|
-
const unpacked = PackedBool_50.unpack(f);
|
74
|
-
expect(unpacked[0].toBoolean()).toBe(myBooleans[0]);
|
75
|
-
expect(unpacked[1].toBoolean()).toBe(myBooleans[1]);
|
76
|
-
expect(unpacked[15].toBoolean()).toBe(myBooleans[15]);
|
77
|
-
expect(unpacked[20].toBoolean()).toBe(myBooleans[20]);
|
78
|
-
expect(unpacked[35].toBoolean()).toBe(myBooleans[35]);
|
79
|
-
expect(unpacked[49].toBoolean()).toBe(myBooleans[49]);
|
80
|
-
});
|
81
|
-
it('mixes and matches class types', () => {
|
82
|
-
const myBooleans = [true, true, false, false, true, false];
|
83
|
-
const myBools = myBooleans.map((b) => Bool(b));
|
84
|
-
const PackedBool_2 = PackedBoolFactory(2);
|
85
|
-
const PackedBool_50 = PackedBoolFactory(50);
|
86
|
-
const packedBool_2 = new PackedBool_2(PackedBool_2.pack(myBools), myBools);
|
87
|
-
const packedBool_50 = new PackedBool_50(PackedBool_2.pack(myBools), myBools);
|
88
|
-
// TODO: Is this desired behavior?
|
89
|
-
console.log(PackedBool_2.toAuxiliary({ packed: packedBool_2.packed }).toString());
|
90
|
-
// > console.log
|
91
|
-
// > true,true
|
92
|
-
console.log(PackedBool_50.toAuxiliary({ packed: packedBool_50.packed }).toString());
|
93
|
-
// > console.log
|
94
|
-
// > true,true,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false
|
95
|
-
});
|
96
|
-
it('throws for input >= 255 bools', () => {
|
97
|
-
expect(() => PackedBoolFactory(254)).not.toThrow();
|
98
|
-
expect(() => PackedBoolFactory(255)).toThrow();
|
99
|
-
});
|
100
|
-
});
|
101
|
-
//# sourceMappingURL=PackedBool.test.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"PackedBool.test.js","sourceRoot":"","sources":["../../../src/packed-types/PackedBool.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,EAAE,CAAC,iCAAiC,EAAE,KAAK,IAAI,EAAE;QAC/C,MAAM,UAAU,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QACjC,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/C,MAAM,YAAY,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAC;QAE1C,MAAM,YAAY,GAAG,IAAI,YAAY,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC;QAC3E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 -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/packed-types/PackedCharacter.ts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AC,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/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,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACxC,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SACtD;QAED,MAAM,kBAAkB,GAAG,sBAAsB,CAAC,EAAE,CAAC,CAAC;QAEtD,MAAM,kBAAkB,GAAG,IAAI,kBAAkB,CAC/C,kBAAkB,CAAC,IAAI,CAAC,YAAY,CAAC,EACrC,YAAY,CACb,CAAC;QACF,MAAM,CAAC,GAAG,kBAAkB,CAAC,MAAM,CAAC;QACpC,MAAM,QAAQ,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAE9C,MAAM,WAAW,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAE/D,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACrC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sBAAsB,EAAE,KAAK,IAAI,EAAE;QACpC,MAAM,QAAQ,GAAG,iBAAiB,CAAC;QACnC,IAAI,YAAY,GAAG,EAAE,CAAC;QACtB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACxC,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SACtD;QAED,MAAM,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,51 +0,0 @@
|
|
1
|
-
import { Field, UInt32 } from 'snarkyjs';
|
2
|
-
export declare function PackedUInt32Factory(l: number): {
|
3
|
-
new (packed: import("snarkyjs/dist/node/lib/field").Field, aux: UInt32[]): {
|
4
|
-
packed: import("snarkyjs/dist/node/lib/field").Field;
|
5
|
-
aux: UInt32[];
|
6
|
-
bitSize: bigint;
|
7
|
-
};
|
8
|
-
/**
|
9
|
-
* Unpacks a Field into its component UInt32 parts
|
10
|
-
* @param value
|
11
|
-
* @returns the unpacked auxilliary data used to pack the value
|
12
|
-
*/
|
13
|
-
toAuxiliary(value?: {
|
14
|
-
packed: Field;
|
15
|
-
} | undefined): UInt32[];
|
16
|
-
pack(aux: UInt32[]): 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): UInt32[];
|
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, UInt32 } from 'snarkyjs';
|
2
|
-
import { PackingPlant } from './PackingPlant';
|
3
|
-
const SIZE_IN_BITS = 32n;
|
4
|
-
export function PackedUInt32Factory(l) {
|
5
|
-
class PackedUInt32_ extends PackingPlant(UInt32, l, SIZE_IN_BITS) {
|
6
|
-
/**
|
7
|
-
* Unpacks a Field into its component UInt32 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(UInt32, 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) => UInt32.from(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 PackedUInt32_;
|
33
|
-
}
|
34
|
-
//# sourceMappingURL=PackedUInt32.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"PackedUInt32.js","sourceRoot":"","sources":["../../../src/packed-types/PackedUInt32.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,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;;;;WAIG;QACH,MAAM,CAAC,WAAW,CAAC,KAAqC;YACtD,MAAM,SAAS,GAAG,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE;gBACjE,IAAI,MAAM,GAAa,EAAE,CAAC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