diff --git a/src/index.ts b/src/index.ts index 7989b3796..5a09e79af 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,7 +3,6 @@ export { Scalar, ProvablePure, Provable, - JSONValue, Ledger, isReady, shutdown, diff --git a/src/lib/circuit_value.ts b/src/lib/circuit_value.ts index f2ddd6ab8..eacfc5b8b 100644 --- a/src/lib/circuit_value.ts +++ b/src/lib/circuit_value.ts @@ -1,5 +1,5 @@ import 'reflect-metadata'; -import { Circuit, JSONValue, ProvablePure, Provable } from '../snarky.js'; +import { Circuit, ProvablePure, Provable } from '../snarky.js'; import { Field, Bool } from './core.js'; import { Context } from './global-context.js'; import { inCheckedComputation, snarkContext } from './proof_system.js'; @@ -138,7 +138,7 @@ abstract class CircuitValue { return (this.constructor as any).toFields(this); } - toJSON(): JSONValue { + toJSON(): any { return (this.constructor as any).toJSON(this); } @@ -205,11 +205,8 @@ abstract class CircuitValue { return (this as any).fromFields(xs.map((x) => x.toConstant())); } - static toJSON( - this: T, - v: InstanceType - ): JSONValue { - const res: { [key: string]: JSONValue } = {}; + static toJSON(this: T, v: InstanceType) { + const res: any = {}; if ((this as any).prototype._fields !== undefined) { const fields: [string, any][] = (this as any).prototype._fields; fields.forEach(([key, propType]) => { @@ -221,7 +218,7 @@ abstract class CircuitValue { static fromJSON( this: T, - value: JSONValue + value: any ): InstanceType | null { const props: any = {}; const fields: [string, any][] = (this as any).prototype._fields; @@ -436,11 +433,11 @@ function circuitMain( let primitives = new Set(['Field', 'Bool', 'Scalar', 'Group']); let complexTypes = new Set(['object', 'function']); -type ProvableExtension = { +type ProvableExtension = { toInput: (x: T) => { fields?: Field[]; packed?: [Field, number][] }; toJSON: (x: T) => TJson; }; -type ProvableExtended = Provable & +type ProvableExtended = Provable & ProvableExtension; function provable( @@ -515,7 +512,7 @@ function provable( .map((k) => toInput(typeObj[k], obj[k])) .reduce(HashInput.append, {}); } - function toJSON(typeObj: any, obj: any, isToplevel = false): JSONValue { + function toJSON(typeObj: any, obj: any, isToplevel = false): any { if (typeObj === BigInt) return obj.toString(); if (typeObj === String || typeObj === Number || typeObj === Boolean) return obj; @@ -1106,7 +1103,7 @@ type InferPrimitiveJson

= P extends typeof String ? null : P extends undefined ? null - : JSONValue; + : any; type InferCircuitValue = A extends Constructor ? A extends Provable @@ -1146,7 +1143,7 @@ type InferJson = A extends WithJson ? { [K in keyof A]: InferJson; } - : JSONValue; + : any; type IsPure = IsPureBase extends true ? true : false; diff --git a/src/lib/field.test.ts b/src/lib/field.test.ts index 8db724143..f38b425dd 100644 --- a/src/lib/field.test.ts +++ b/src/lib/field.test.ts @@ -9,7 +9,6 @@ describe('Field constructor', () => { it('handles small numbers', () => { expect(Field(5).toString()).toEqual('5'); expect(Field(1313).toString()).toEqual('1313'); - expect(Field(5).toString()).toEqual('5'); }); it('handles large numbers 2^31 <= x < 2^53', () => { @@ -17,19 +16,16 @@ describe('Field constructor', () => { expect(Field(Number.MAX_SAFE_INTEGER).toString()).toEqual( String(Number.MAX_SAFE_INTEGER) ); - expect(Field(2 ** 31).toString()).toEqual('2147483648'); }); it('handles negative numbers', () => { expect(Field(-1)).toEqual(Field(1).neg()); expect(Field(-(2 ** 31))).toEqual(Field(2 ** 31).neg()); - expect(Field(-1)).toEqual(Field(1).neg()); }); it('throws on fractional numbers', () => { expect(() => Field(0.5)).toThrow(); expect(() => Field(-1.1)).toThrow(); - expect(() => Field(0.5)).toThrow(); }); // Field(bigint), Field.fromBigInt, toBigInt diff --git a/src/lib/mina.ts b/src/lib/mina.ts index b4e2fbc43..5351212bd 100644 --- a/src/lib/mina.ts +++ b/src/lib/mina.ts @@ -1,6 +1,6 @@ // This is for an account where any of a list of public keys can update the state -import { Circuit, JSONValue, Ledger, LedgerAccount } from '../snarky.js'; +import { Circuit, Ledger, LedgerAccount } from '../snarky.js'; import { Field, Bool } from './core.js'; import { UInt32, UInt64 } from './int.js'; import { PrivateKey, PublicKey } from './signature.js'; @@ -57,7 +57,7 @@ interface TransactionId { interface Transaction { transaction: ZkappCommand; toJSON(): string; - toPretty(): JSONValue; + toPretty(): any; toGraphqlQuery(): string; sign(additionalKeys?: PrivateKey[]): Transaction; prove(): Promise<(Proof | undefined)[]>; diff --git a/src/lib/scalar.test.ts b/src/lib/scalar.test.ts index e84365c79..a460b6caf 100644 --- a/src/lib/scalar.test.ts +++ b/src/lib/scalar.test.ts @@ -175,10 +175,6 @@ describe('scalar', () => { it('fromJSON(false) should be 0', () => { expect(Scalar.fromJSON(false)!.toJSON()).toEqual('0'); }); - - it('fromJSON([]) should be undefined', () => { - expect(Scalar.fromJSON([])).toBeNull(); - }); }); describe('neg', () => { diff --git a/src/lib/zkapp.ts b/src/lib/zkapp.ts index 79ba39941..488bdd84f 100644 --- a/src/lib/zkapp.ts +++ b/src/lib/zkapp.ts @@ -5,7 +5,6 @@ import { Ledger, Pickles, Poseidon as Poseidon_, - JSONValue, Provable, } from '../snarky.js'; import { diff --git a/src/snarky.d.ts b/src/snarky.d.ts index 347a34f3b..da90b4022 100644 --- a/src/snarky.d.ts +++ b/src/snarky.d.ts @@ -13,7 +13,6 @@ export { isReady, shutdown, Pickles, - JSONValue, Account as LedgerAccount, }; @@ -359,7 +358,7 @@ declare class Field { */ static toJSON(x: Field): string; - static fromJSON(x: JSONValue): Field | null; + static fromJSON(x: string | number): Field; static check(x: Field): void; @@ -486,7 +485,7 @@ declare class Bool { static fromFields(fields: Field[]): Bool; static toJSON(x: Bool): boolean; - static fromJSON(x: JSONValue): Bool | null; + static fromJSON(x: boolean): Bool; static check(x: Bool): void; // monkey-patched in JS @@ -636,7 +635,7 @@ declare class Scalar { static random(): Scalar; static toJSON(x: Scalar): string; - static fromJSON(x: JSONValue): Scalar | null; + static fromJSON(x: string | number | boolean): Scalar; static check(x: Scalar): void; } @@ -957,12 +956,4 @@ declare const Pickles: { proofToBase64Transaction: (proof: Pickles.Proof) => string; }; -type JSONValue = - | number - | string - | boolean - | null - | Array - | { [key: string]: JSONValue }; - type AuthRequired = 'Signature' | 'Proof' | 'Either' | 'None' | 'Impossible';