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,100 +1,101 @@
|
|
1
|
-
import { Character, Provable } from 'o1js';
|
2
|
-
import { PackedStringFactory } from './PackedString';
|
3
|
-
describe('PackedString', () => {
|
4
|
-
describe('Outside of the Circuit', () => {
|
5
|
-
const vitalik_dot_eth = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045';
|
6
|
-
class EthAddressString extends
|
7
|
-
}
|
8
|
-
let characters = [];
|
9
|
-
beforeEach(() => {
|
10
|
-
characters = [];
|
11
|
-
for (let i = 0; i < vitalik_dot_eth.length; i++) {
|
12
|
-
characters.push(Character.fromString(vitalik_dot_eth[i]));
|
13
|
-
}
|
14
|
-
});
|
15
|
-
it('#fromString', () => {
|
16
|
-
const myEthAddress = EthAddressString.fromString(vitalik_dot_eth);
|
17
|
-
expect(myEthAddress.toString()).toBe(vitalik_dot_eth);
|
18
|
-
});
|
19
|
-
it('#
|
20
|
-
const myEthAddress = EthAddressString.
|
21
|
-
expect(myEthAddress.toString()).toBe(vitalik_dot_eth);
|
22
|
-
});
|
23
|
-
it('#pack and #unPack', () => {
|
24
|
-
const
|
25
|
-
const
|
26
|
-
expect(packed.length).toBe(Math.ceil(vitalik_dot_eth.length / 15));
|
27
|
-
expect(unpacked.length).toBe(
|
28
|
-
expect(unpacked.
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
expect(
|
41
|
-
expect(
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
const
|
50
|
-
|
51
|
-
expect(
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
EthAddressString
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
myEthAddress
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
fakePacked
|
93
|
-
|
94
|
-
myEthAddress
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
});
|
1
|
+
import { Character, Provable } from 'o1js';
|
2
|
+
import { PackedStringFactory, MultiPackedStringFactory } from './PackedString';
|
3
|
+
describe('PackedString', () => {
|
4
|
+
describe('Outside of the Circuit', () => {
|
5
|
+
const vitalik_dot_eth = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045';
|
6
|
+
class EthAddressString extends MultiPackedStringFactory(3) {
|
7
|
+
}
|
8
|
+
let characters = [];
|
9
|
+
beforeEach(() => {
|
10
|
+
characters = [];
|
11
|
+
for (let i = 0; i < vitalik_dot_eth.length; i++) {
|
12
|
+
characters.push(Character.fromString(vitalik_dot_eth[i]));
|
13
|
+
}
|
14
|
+
});
|
15
|
+
it('#fromString', () => {
|
16
|
+
const myEthAddress = EthAddressString.fromString(vitalik_dot_eth);
|
17
|
+
expect(myEthAddress.toString()).toBe(vitalik_dot_eth);
|
18
|
+
});
|
19
|
+
it('#fromCharacters', () => {
|
20
|
+
const myEthAddress = EthAddressString.fromCharacters(characters);
|
21
|
+
expect(myEthAddress.toString()).toBe(vitalik_dot_eth);
|
22
|
+
});
|
23
|
+
it('#pack and #unPack', () => {
|
24
|
+
const unpacked = EthAddressString.unpack(EthAddressString.fromCharacters(characters).packed);
|
25
|
+
const packed = EthAddressString.pack(unpacked);
|
26
|
+
expect(packed.length).toBe(Math.ceil(vitalik_dot_eth.length / 15));
|
27
|
+
expect(unpacked.length).toBe(EthAddressString.l);
|
28
|
+
expect(unpacked.length).toBe(45);
|
29
|
+
expect(unpacked.slice(0, characters.length).toString()).toBe(characters.toString());
|
30
|
+
});
|
31
|
+
});
|
32
|
+
describe('Provable Properties', () => {
|
33
|
+
it('#sizeInFields', () => {
|
34
|
+
class one extends PackedStringFactory(15) {
|
35
|
+
}
|
36
|
+
class two extends MultiPackedStringFactory(2) {
|
37
|
+
}
|
38
|
+
class three extends MultiPackedStringFactory(3) {
|
39
|
+
}
|
40
|
+
expect(one.sizeInFields()).toBe(1);
|
41
|
+
expect(two.sizeInFields()).toBe(2);
|
42
|
+
expect(three.sizeInFields()).toBe(3);
|
43
|
+
});
|
44
|
+
});
|
45
|
+
describe('Defensive Cases', () => {
|
46
|
+
it('Initializes a class with fewer than allowed characters', () => {
|
47
|
+
class String10 extends PackedStringFactory(10) {
|
48
|
+
}
|
49
|
+
const string0 = String10.fromString('');
|
50
|
+
const string2 = String10.fromString('ab');
|
51
|
+
expect(string0.toString()).toBe('');
|
52
|
+
expect(string2.toString()).toBe('ab');
|
53
|
+
});
|
54
|
+
it('Initializes a class with more than allowed characters', () => {
|
55
|
+
class String10 extends PackedStringFactory(10) {
|
56
|
+
}
|
57
|
+
expect(() => {
|
58
|
+
String10.fromString('abcdefghijk');
|
59
|
+
}).toThrow();
|
60
|
+
});
|
61
|
+
it('Exceeds maximum size string', () => {
|
62
|
+
const tooLong = 'too long!'.repeat(20);
|
63
|
+
class MaxString extends MultiPackedStringFactory(8) {
|
64
|
+
}
|
65
|
+
expect(() => {
|
66
|
+
MaxString.fromString(tooLong);
|
67
|
+
}).toThrow();
|
68
|
+
});
|
69
|
+
});
|
70
|
+
describe('In the circuit', () => {
|
71
|
+
const vitalik_dot_eth = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045';
|
72
|
+
class EthAddressString extends MultiPackedStringFactory(3) {
|
73
|
+
}
|
74
|
+
const outsideEthAddress = EthAddressString.fromString(vitalik_dot_eth);
|
75
|
+
it('Initializes a string', () => {
|
76
|
+
expect(() => {
|
77
|
+
Provable.runAndCheck(() => {
|
78
|
+
const myEthAddress = new EthAddressString(outsideEthAddress.packed);
|
79
|
+
EthAddressString.check({ packed: myEthAddress.packed });
|
80
|
+
});
|
81
|
+
}).not.toThrow();
|
82
|
+
});
|
83
|
+
it('#assertEquals', () => {
|
84
|
+
expect(() => {
|
85
|
+
Provable.runAndCheck(() => {
|
86
|
+
const myEthAddress = new EthAddressString(outsideEthAddress.packed);
|
87
|
+
myEthAddress.assertEquals(outsideEthAddress);
|
88
|
+
});
|
89
|
+
}).not.toThrow();
|
90
|
+
expect(() => {
|
91
|
+
Provable.runAndCheck(() => {
|
92
|
+
const fakePacked = [...outsideEthAddress.packed];
|
93
|
+
fakePacked[0] = fakePacked[0].add(1);
|
94
|
+
const myEthAddress = new EthAddressString(fakePacked);
|
95
|
+
myEthAddress.assertEquals(outsideEthAddress);
|
96
|
+
});
|
97
|
+
}).toThrow();
|
98
|
+
});
|
99
|
+
});
|
100
|
+
});
|
100
101
|
//# sourceMappingURL=PackedString.test.js.map
|
@@ -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;
|
1
|
+
{"version":3,"file":"PackedString.test.js","sourceRoot":"","sources":["../../../../src/lib/packed-types/PackedString.test.ts"],"names":[],"mappings":"AAAA,OAA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|
2
|
-
export declare function PackedUInt32Factory(l
|
3
|
-
new (packed: import("o1js/dist/node/lib/field.js").Field
|
4
|
-
toBigInts(): Array<bigint>;
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
}): void;
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
assertEquals(other: any): void;
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
packed:
|
47
|
-
}
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
packed:
|
71
|
-
}
|
72
|
-
|
73
|
-
packed
|
74
|
-
}
|
75
|
-
|
76
|
-
|
77
|
-
}
|
1
|
+
import { Field, UInt32 } from 'o1js';
|
2
|
+
export declare function PackedUInt32Factory(l?: number): {
|
3
|
+
new (packed: import("o1js/dist/node/lib/field.js").Field): {
|
4
|
+
toBigInts(): Array<bigint>;
|
5
|
+
assertEquals(other: {
|
6
|
+
assertEquals(other: any): void;
|
7
|
+
packed: import("o1js/dist/node/lib/field.js").Field;
|
8
|
+
}): void;
|
9
|
+
packed: import("o1js/dist/node/lib/field.js").Field;
|
10
|
+
};
|
11
|
+
extractField(input: UInt32): Field;
|
12
|
+
sizeInBits(): bigint;
|
13
|
+
/**
|
14
|
+
*
|
15
|
+
* @param f Field, packed with the information, as returned by #pack
|
16
|
+
* @returns Array of UInt32
|
17
|
+
*/
|
18
|
+
unpack(f: Field): UInt32[];
|
19
|
+
/**
|
20
|
+
*
|
21
|
+
* @param uint32s Array of UInt32s to be packed
|
22
|
+
* @returns Instance of the implementing class
|
23
|
+
*/
|
24
|
+
fromUInt32s(uint32s: Array<UInt32>): {
|
25
|
+
toBigInts(): Array<bigint>;
|
26
|
+
assertEquals(other: {
|
27
|
+
assertEquals(other: any): void;
|
28
|
+
packed: import("o1js/dist/node/lib/field.js").Field;
|
29
|
+
}): void;
|
30
|
+
packed: import("o1js/dist/node/lib/field.js").Field;
|
31
|
+
};
|
32
|
+
/**
|
33
|
+
*
|
34
|
+
* @param bigints Array of bigints to be packed
|
35
|
+
* @returns Instance of the implementing class
|
36
|
+
*/
|
37
|
+
fromBigInts(bigints: Array<bigint>): {
|
38
|
+
toBigInts(): Array<bigint>;
|
39
|
+
assertEquals(other: {
|
40
|
+
assertEquals(other: any): void;
|
41
|
+
packed: import("o1js/dist/node/lib/field.js").Field;
|
42
|
+
}): void;
|
43
|
+
packed: import("o1js/dist/node/lib/field.js").Field;
|
44
|
+
};
|
45
|
+
type: import("o1js/dist/node/bindings/lib/provable-snarky.js").ProvableExtended<{
|
46
|
+
packed: import("o1js/dist/node/lib/field.js").Field;
|
47
|
+
}, {
|
48
|
+
packed: string;
|
49
|
+
}>;
|
50
|
+
l: number;
|
51
|
+
bitSize: bigint;
|
52
|
+
checkPack(unpacked: UInt32[]): void;
|
53
|
+
pack(unpacked: UInt32[]): import("o1js/dist/node/lib/field.js").Field;
|
54
|
+
unpackToBigints(f: import("o1js/dist/node/lib/field.js").Field): bigint[];
|
55
|
+
_isStruct: true;
|
56
|
+
toFields: (value: {
|
57
|
+
packed: import("o1js/dist/node/lib/field.js").Field;
|
58
|
+
}) => import("o1js/dist/node/lib/field.js").Field[];
|
59
|
+
toAuxiliary: (value?: {
|
60
|
+
packed: import("o1js/dist/node/lib/field.js").Field;
|
61
|
+
} | undefined) => any[];
|
62
|
+
fromFields: (fields: import("o1js/dist/node/lib/field.js").Field[]) => {
|
63
|
+
packed: import("o1js/dist/node/lib/field.js").Field;
|
64
|
+
};
|
65
|
+
sizeInFields(): number;
|
66
|
+
check: (value: {
|
67
|
+
packed: import("o1js/dist/node/lib/field.js").Field;
|
68
|
+
}) => void;
|
69
|
+
toInput: (x: {
|
70
|
+
packed: import("o1js/dist/node/lib/field.js").Field;
|
71
|
+
}) => {
|
72
|
+
fields?: import("o1js/dist/node/lib/field.js").Field[] | undefined;
|
73
|
+
packed?: [import("o1js/dist/node/lib/field.js").Field, number][] | undefined;
|
74
|
+
};
|
75
|
+
toJSON: (x: {
|
76
|
+
packed: import("o1js/dist/node/lib/field.js").Field;
|
77
|
+
}) => {
|
78
|
+
packed: string;
|
79
|
+
};
|
80
|
+
fromJSON: (x: {
|
81
|
+
packed: string;
|
82
|
+
}) => {
|
83
|
+
packed: import("o1js/dist/node/lib/field.js").Field;
|
84
|
+
};
|
85
|
+
};
|
@@ -1,48 +1,50 @@
|
|
1
|
-
import {
|
2
|
-
import { PackingPlant } from '../PackingPlant.js';
|
3
|
-
const
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
return
|
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
|
-
}
|
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
|
+
}
|
48
50
|
//# sourceMappingURL=PackedUInt32.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"PackedUInt32.js","sourceRoot":"","sources":["../../../../src/lib/pack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