Skip to content

Commit 9cc3fb6

Browse files
committed
Renamed UIntX to UInt
1 parent f9c7de3 commit 9cc3fb6

File tree

9 files changed

+81
-80
lines changed

9 files changed

+81
-80
lines changed

packages/api/src/graphql/modules/QueryGraphqlModule.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ import {
4747
BaseModuleType,
4848
log,
4949
ModuleContainer,
50-
ModulesRecord, NonMethods,
51-
range
50+
ModulesRecord,
51+
NonMethods,
52+
range,
5253
} from "@proto-kit/common";
5354
import { ObjMap } from "graphql/jsutils/ObjMap";
5455

packages/library/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export * from "./math/UInt";
22
export * from "./math/UInt32";
33
export * from "./math/UInt64";
44
export * from "./math/UInt112";
5-
// export * from "./math/UInt224";
5+
export * from "./math/UInt224";
66
export * from "./math/PrecisionHelper";
77
export * from "./protocol/VanillaProtocolModules";
88
export * from "./runtime/Balances";

packages/library/src/math/Types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { UIntX } from "./UInt";
1+
import { UInt } from "./UInt";
22

33
type AvailableBitLengths = 32 | 64 | 112 | 224;
44

@@ -23,5 +23,5 @@ type RecursiveSmaller<Input extends AvailableBitLengths> =
2323
*/
2424
export type FittingUInt<Input extends number> =
2525
Input extends AvailableBitLengths
26-
? UIntX<RecursiveSmaller<Input>>
27-
: UIntX<Input>;
26+
? UInt<RecursiveSmaller<Input>>
27+
: UInt<Input>;

packages/library/src/math/UInt.ts

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ const errors = {
1616

1717
export type UIntConstructor<BITS extends number> = {
1818
// new(value: Field | { value: Field }): UIntX<BITS>;
19-
from(x: UIntX<BITS> | bigint | number | string): UIntX<BITS>;
19+
from(x: UInt<BITS> | bigint | number | string): UInt<BITS>;
2020
check(x: { value: Field }): void;
21-
get zero(): UIntX<BITS>;
21+
get zero(): UInt<BITS>;
2222

2323
Unsafe: {
24-
fromField(x: Field): UIntX<BITS>
25-
}
26-
}
24+
fromField(x: Field): UInt<BITS>;
25+
};
26+
};
2727

28-
export abstract class UIntX<BITS extends number> extends Struct({
28+
export abstract class UInt<BITS extends number> extends Struct({
2929
value: Field,
3030
}) {
3131
public static readonly assertionFunction: (bool: Bool, msg?: string) => void =
@@ -45,7 +45,7 @@ export abstract class UIntX<BITS extends number> extends Struct({
4545
}
4646

4747
/**
48-
* Creates a {@link UIntX} with a value of 18,446,744,073,709,551,615.
48+
* Creates a {@link UInt} with a value of 18,446,744,073,709,551,615.
4949
*/
5050
public static maxIntField(numBits: number): Field {
5151
return Field((1n << BigInt(numBits)) - 1n);
@@ -64,28 +64,28 @@ export abstract class UIntX<BITS extends number> extends Struct({
6464
}
6565
}
6666

67-
public abstract numBits(): BITS
67+
public abstract numBits(): BITS;
6868

6969
public abstract constructorReference(): UIntConstructor<BITS>;
7070

71-
private fromField(value: Field): UIntX<BITS> {
72-
return this.constructorReference().Unsafe.fromField(value)
71+
private fromField(value: Field): UInt<BITS> {
72+
return this.constructorReference().Unsafe.fromField(value);
7373
}
7474

75-
private from(value: UIntX<BITS> | string | number | bigint): UIntX<BITS> {
76-
return this.constructorReference().from(value)
75+
private from(value: UInt<BITS> | string | number | bigint): UInt<BITS> {
76+
return this.constructorReference().from(value);
7777
}
7878

7979
/**
80-
* Turns the {@link UIntX} into a string.
80+
* Turns the {@link UInt} into a string.
8181
* @returns
8282
*/
8383
public toString() {
8484
return this.value.toString();
8585
}
8686

8787
/**
88-
* Turns the {@link UIntX} into a {@link BigInt}.
88+
* Turns the {@link UInt} into a {@link BigInt}.
8989
* @returns
9090
*/
9191
public toBigInt() {
@@ -97,7 +97,7 @@ export abstract class UIntX<BITS extends number> extends Struct({
9797
*
9898
* `x.divMod(y)` returns the quotient and the remainder.
9999
*/
100-
public divMod(divisor: UIntX<BITS> | bigint | number | string) {
100+
public divMod(divisor: UInt<BITS> | bigint | number | string) {
101101
let x = this.value;
102102
let divisor_ = this.from(divisor).value;
103103

@@ -114,14 +114,14 @@ export abstract class UIntX<BITS extends number> extends Struct({
114114

115115
divisor_ = divisor_.seal();
116116

117-
UIntX.assertionFunction(divisor_.equals(0).not(), "Division by 0");
117+
UInt.assertionFunction(divisor_.equals(0).not(), "Division by 0");
118118

119119
let q = Provable.witness(Field, () => {
120120
const divisorInt = divisor_.toBigInt();
121121
return new Field(x.toBigInt() / (divisorInt == 0n ? 1n : divisorInt));
122122
});
123123

124-
UIntX.assertionFunction(
124+
UInt.assertionFunction(
125125
q.rangeCheckHelper(this.numBits()).equals(q),
126126
"Divison overflowing"
127127
);
@@ -136,15 +136,15 @@ export abstract class UIntX<BITS extends number> extends Struct({
136136
// TODO: Could be a bit more efficient
137137
let r = x.sub(q.mul(divisor_)).seal();
138138

139-
UIntX.assertionFunction(
139+
UInt.assertionFunction(
140140
r.rangeCheckHelper(this.numBits()).equals(r),
141141
"Divison overflowing, remainder"
142142
);
143143

144144
let r_ = this.fromField(r);
145145
let q_ = this.fromField(q);
146146

147-
UIntX.assertionFunction(
147+
UInt.assertionFunction(
148148
r_.lessThan(this.fromField(divisor_)),
149149
"Divison failure, remainder larger than divisor"
150150
);
@@ -159,7 +159,7 @@ export abstract class UIntX<BITS extends number> extends Struct({
159159
* `z` such that `z * y <= x`.
160160
*
161161
*/
162-
public div(y: UIntX<BITS> | bigint | number): UIntX<BITS> {
162+
public div(y: UInt<BITS> | bigint | number): UInt<BITS> {
163163
return this.divMod(y).quotient;
164164
}
165165

@@ -178,7 +178,7 @@ export abstract class UIntX<BITS extends number> extends Struct({
178178
* @returns rest: The remainder indicating how far off the result
179179
* is from the "real" sqrt
180180
*/
181-
public sqrtMod(): { sqrt: UIntX<BITS>; rest: UIntX<BITS> } {
181+
public sqrtMod(): { sqrt: UInt<BITS>; rest: UInt<BITS> } {
182182
let x = this.value;
183183

184184
if (x.isConstant()) {
@@ -241,7 +241,7 @@ export abstract class UIntX<BITS extends number> extends Struct({
241241
/**
242242
* Wraps sqrtMod() by only returning the sqrt and omitting the rest field.
243243
*/
244-
public sqrtFloor(): UIntX<BITS> {
244+
public sqrtFloor(): UInt<BITS> {
245245
return this.sqrtMod().sqrt;
246246
}
247247

@@ -251,14 +251,14 @@ export abstract class UIntX<BITS extends number> extends Struct({
251251
* `x.mod(y)` returns the value `z` such that `0 <= z < y` and
252252
* `x - z` is divisble by `y`.
253253
*/
254-
public mod(y: UIntX<BITS> | bigint | number) {
254+
public mod(y: UInt<BITS> | bigint | number) {
255255
return this.divMod(y).rest;
256256
}
257257

258258
/**
259259
* Multiplication with overflow checking.
260260
*/
261-
public mul(y: UIntX<BITS> | bigint | number) {
261+
public mul(y: UInt<BITS> | bigint | number) {
262262
let yField = this.from(y).value;
263263
let z = this.value.mul(yField);
264264

@@ -267,7 +267,7 @@ export abstract class UIntX<BITS extends number> extends Struct({
267267
z.assertGreaterThan(this.value, "Multiplication overflowing");
268268
}
269269

270-
UIntX.assertionFunction(
270+
UInt.assertionFunction(
271271
z.rangeCheckHelper(this.numBits()).equals(z),
272272
"Multiplication overflowing"
273273
);
@@ -277,9 +277,9 @@ export abstract class UIntX<BITS extends number> extends Struct({
277277
/**
278278
* Addition with overflow checking.
279279
*/
280-
public add(y: UIntX<BITS> | bigint | number) {
280+
public add(y: UInt<BITS> | bigint | number) {
281281
let z = this.value.add(this.from(y).value);
282-
UIntX.assertionFunction(
282+
UInt.assertionFunction(
283283
z.rangeCheckHelper(this.numBits()).equals(z),
284284
"Addition overflowing"
285285
);
@@ -289,35 +289,35 @@ export abstract class UIntX<BITS extends number> extends Struct({
289289
/**
290290
* Subtraction with underflow checking.
291291
*/
292-
public sub(y: UIntX<BITS> | bigint | number) {
292+
public sub(y: UInt<BITS> | bigint | number) {
293293
let z = this.value.sub(this.from(y).value);
294-
UIntX.assertionFunction(
294+
UInt.assertionFunction(
295295
z.rangeCheckHelper(this.numBits()).equals(z),
296296
"Subtraction overflow"
297297
);
298298
return this.fromField(z);
299299
}
300300

301301
/**
302-
* Checks if a {@link UIntX} is less than or equal to another one.
302+
* Checks if a {@link UInt} is less than or equal to another one.
303303
*/
304-
public lessThanOrEqual(y: UIntX<BITS>) {
304+
public lessThanOrEqual(y: UInt<BITS>) {
305305
if (this.value.isConstant() && y.value.isConstant()) {
306306
return Bool(this.value.toBigInt() <= y.value.toBigInt());
307307
}
308308
let xMinusY = this.value.sub(y.value).seal();
309309
let yMinusX = xMinusY.neg();
310310
let yMinusXFits = yMinusX.rangeCheckHelper(this.numBits()).equals(yMinusX);
311311
let xMinusYFits = xMinusY.rangeCheckHelper(this.numBits()).equals(xMinusY);
312-
UIntX.assertionFunction(xMinusYFits.or(yMinusXFits));
312+
UInt.assertionFunction(xMinusYFits.or(yMinusXFits));
313313
// x <= y if y - x fits in 64 bits
314314
return yMinusXFits;
315315
}
316316

317317
/**
318-
* Asserts that a {@link UIntX} is less than or equal to another one.
318+
* Asserts that a {@link UInt} is less than or equal to another one.
319319
*/
320-
public assertLessThanOrEqual(y: UIntX<BITS>, message?: string) {
320+
public assertLessThanOrEqual(y: UInt<BITS>, message?: string) {
321321
if (this.value.isConstant() && y.value.isConstant()) {
322322
let x0 = this.value.toBigInt();
323323
let y0 = y.value.toBigInt();
@@ -330,67 +330,67 @@ export abstract class UIntX<BITS extends number> extends Struct({
330330
return;
331331
}
332332
let yMinusX = y.value.sub(this.value).seal();
333-
UIntX.assertionFunction(
333+
UInt.assertionFunction(
334334
yMinusX.rangeCheckHelper(this.numBits()).equals(yMinusX),
335335
message
336336
);
337337
}
338338

339339
/**
340340
*
341-
* Checks if a {@link UIntX} is less than another one.
341+
* Checks if a {@link UInt} is less than another one.
342342
*/
343-
public lessThan(y: UIntX<BITS>) {
343+
public lessThan(y: UInt<BITS>) {
344344
return this.lessThanOrEqual(y).and(this.value.equals(y.value).not());
345345
}
346346

347347
/**
348-
* Asserts that a {@link UIntX} is less than another one.
348+
* Asserts that a {@link UInt} is less than another one.
349349
*/
350-
public assertLessThan(y: UIntX<BITS>, message?: string) {
351-
UIntX.assertionFunction(this.lessThan(y), message);
350+
public assertLessThan(y: UInt<BITS>, message?: string) {
351+
UInt.assertionFunction(this.lessThan(y), message);
352352
}
353353

354354
/**
355-
* Checks if a {@link UIntX} is greater than another one.
355+
* Checks if a {@link UInt} is greater than another one.
356356
*/
357-
public greaterThan(y: UIntX<BITS>) {
357+
public greaterThan(y: UInt<BITS>) {
358358
return y.lessThan(this);
359359
}
360360

361361
/**
362-
* Asserts that a {@link UIntX} is greater than another one.
362+
* Asserts that a {@link UInt} is greater than another one.
363363
*/
364-
public assertGreaterThan(y: UIntX<BITS>, message?: string) {
364+
public assertGreaterThan(y: UInt<BITS>, message?: string) {
365365
y.assertLessThan(this, message);
366366
}
367367

368368
/**
369-
* Checks if a {@link UIntX} is greater than or equal to another one.
369+
* Checks if a {@link UInt} is greater than or equal to another one.
370370
*/
371-
public greaterThanOrEqual(y: UIntX<BITS>) {
371+
public greaterThanOrEqual(y: UInt<BITS>) {
372372
return this.lessThan(y).not();
373373
}
374374

375375
/**
376-
* Asserts that a {@link UIntX} is greater than or equal to another one.
376+
* Asserts that a {@link UInt} is greater than or equal to another one.
377377
*/
378-
public assertGreaterThanOrEqual(y: UIntX<BITS>, message?: string) {
378+
public assertGreaterThanOrEqual(y: UInt<BITS>, message?: string) {
379379
y.assertLessThanOrEqual(this, message);
380380
}
381381

382382
/**
383-
* Checks if a {@link UIntX} is equal to another one.
383+
* Checks if a {@link UInt} is equal to another one.
384384
*/
385-
public equals(y: UIntX<BITS> | bigint | number): Bool {
385+
public equals(y: UInt<BITS> | bigint | number): Bool {
386386
return this.from(y).value.equals(this.value);
387387
}
388388

389389
/**
390-
* Asserts that a {@link UIntX} is equal to another one.
390+
* Asserts that a {@link UInt} is equal to another one.
391391
*/
392-
public assertEquals(y: UIntX<BITS> | bigint | number, message?: string) {
393-
UIntX.assertionFunction(this.equals(y), message);
392+
public assertEquals(y: UInt<BITS> | bigint | number, message?: string) {
393+
UInt.assertionFunction(this.equals(y), message);
394394
}
395395

396396
// /**

packages/library/src/math/UInt112.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Field } from "o1js";
2-
import { UIntConstructor, UIntX } from "./UInt";
2+
import { UIntConstructor, UInt } from "./UInt";
33

4-
export class UInt112 extends UIntX<112> {
4+
export class UInt112 extends UInt<112> {
55
public static Unsafe = {
66
fromField(value: Field) {
77
return new UInt112({ value });
@@ -10,14 +10,14 @@ export class UInt112 extends UIntX<112> {
1010

1111
public static check(x: { value: Field }) {
1212
const actual = x.value.rangeCheckHelper(112);
13-
UIntX.assertionFunction(actual.equals(x.value));
13+
UInt.assertionFunction(actual.equals(x.value));
1414
}
1515

16-
public static from(x: UIntX<112> | bigint | number | string): UInt112 {
17-
if (x instanceof UIntX) {
16+
public static from(x: UInt<112> | bigint | number | string): UInt112 {
17+
if (x instanceof UInt) {
1818
return x;
1919
}
20-
return new UInt112({ value: UIntX.checkConstant(Field(x), 112) });
20+
return new UInt112({ value: UInt.checkConstant(Field(x), 112) });
2121
}
2222

2323
public static get zero() {

packages/library/src/math/UInt224.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Field, UInt64 } from "o1js";
2-
import { UIntConstructor, UIntX } from "./UInt";
2+
import { UIntConstructor, UInt } from "./UInt";
33

4-
export class UInt224 extends UIntX<224> {
4+
export class UInt224 extends UInt<224> {
55
public static Unsafe = {
66
fromField(value: Field) {
77
return new UInt224({ value });
@@ -10,14 +10,14 @@ export class UInt224 extends UIntX<224> {
1010

1111
public static check(x: { value: Field }) {
1212
const actual = x.value.rangeCheckHelper(224);
13-
UIntX.assertionFunction(actual.equals(x.value));
13+
UInt.assertionFunction(actual.equals(x.value));
1414
}
1515

16-
public static from(x: UIntX<224> | bigint | number | string): UInt224 {
17-
if (x instanceof UIntX) {
16+
public static from(x: UInt<224> | bigint | number | string): UInt224 {
17+
if (x instanceof UInt) {
1818
return x;
1919
}
20-
return new UInt224({ value: UIntX.checkConstant(Field(x), 224) });
20+
return new UInt224({ value: UInt.checkConstant(Field(x), 224) });
2121
}
2222

2323
public static get zero() {

0 commit comments

Comments
 (0)