diff --git a/crypto/poseidon.unit-test.ts b/crypto/poseidon.unit-test.ts index 04149ba2..f84b9965 100644 --- a/crypto/poseidon.unit-test.ts +++ b/crypto/poseidon.unit-test.ts @@ -5,7 +5,7 @@ import { expect } from 'expect'; import { bigIntToBytes, parseHexString32 } from './bigint-helpers.js'; import { test, Random } from '../../lib/testing/property.js'; import { Test } from '../../snarky.js'; -import { FieldConst } from '../../lib/field.js'; +import { FieldConst } from '../../lib/provable-core/fieldvar.js'; import { MlArray } from '../../lib/ml/base.js'; function checkTestVectors( diff --git a/lib/binable.unit-test.ts b/lib/binable.unit-test.ts index 5b674e39..da40d9ee 100644 --- a/lib/binable.unit-test.ts +++ b/lib/binable.unit-test.ts @@ -10,8 +10,8 @@ import { withCheck, withVersionNumber, } from './binable.js'; -import { PublicKey, Scalar } from '../../provable/curve-bigint.js'; -import { Bool, Field, UInt64 } from '../../provable/field-bigint.js'; +import { PublicKey, Scalar } from '../../mina-signer/src/curve-bigint.js'; +import { Bool, Field, UInt64 } from '../../mina-signer/src/field-bigint.js'; // uint diff --git a/lib/generic.ts b/lib/generic.ts index 21ed9124..9720930f 100644 --- a/lib/generic.ts +++ b/lib/generic.ts @@ -26,13 +26,12 @@ type GenericProvable = { sizeInFields(): number; check: (x: T) => void; }; -interface GenericProvablePure extends GenericProvable { - toFields: (x: T) => Field[]; - toAuxiliary: (x?: T) => any[]; +type GenericProvablePure = Omit< + GenericProvable, + 'fromFields' +> & { fromFields: (x: Field[]) => T; - sizeInFields(): number; - check: (x: T) => void; -} +}; type GenericSignable = { toInput: (x: T) => { fields?: Field[]; packed?: [Field, number][] }; diff --git a/lib/provable-bigint.ts b/lib/provable-bigint.ts deleted file mode 100644 index 0774a7ef..00000000 --- a/lib/provable-bigint.ts +++ /dev/null @@ -1,76 +0,0 @@ -import { bigIntToBytes } from '../crypto/bigint-helpers.js'; -import { createDerivers } from './provable-generic.js'; -import { - GenericHashInput, - GenericProvableExtended, - GenericSignable, -} from './generic.js'; -import { BinableWithBits, defineBinable, withBits } from './binable.js'; - -export { - signable, - ProvableExtended, - ProvableBigint, - BinableBigint, - HashInput, - Signable, -}; - -type Field = bigint; - -let { signable } = createDerivers(); - -type Signable = GenericSignable; -type ProvableExtended = GenericProvableExtended; -type HashInput = GenericHashInput; - -function ProvableBigint< - T extends bigint = bigint, - TJSON extends string = string ->(check: (x: bigint) => void): Signable { - return { - toInput(x) { - return { fields: [x], packed: [] }; - }, - toJSON(x) { - return x.toString() as TJSON; - }, - fromJSON(json) { - if (isNaN(json as any) || isNaN(parseFloat(json))) { - throw Error(`fromJSON: expected a numeric string, got "${json}"`); - } - let x = BigInt(json) as T; - check(x); - return x; - }, - empty() { - return 0n as T; - }, - }; -} - -function BinableBigint( - sizeInBits: number, - check: (x: bigint) => void -): BinableWithBits { - let sizeInBytes = Math.ceil(sizeInBits / 8); - return withBits( - defineBinable({ - toBytes(x) { - return bigIntToBytes(x, sizeInBytes); - }, - readBytes(bytes, start) { - let x = 0n; - let bitPosition = 0n; - let end = Math.min(start + sizeInBytes, bytes.length); - for (let i = start; i < end; i++) { - x += BigInt(bytes[i]) << bitPosition; - bitPosition += 8n; - } - check(x); - return [x as T, end]; - }, - }), - sizeInBits - ); -} diff --git a/lib/provable-snarky.ts b/lib/provable-snarky.ts deleted file mode 100644 index c2a8d7a6..00000000 --- a/lib/provable-snarky.ts +++ /dev/null @@ -1,102 +0,0 @@ -import { Provable, ProvablePure } from '../../snarky.js'; -import { Field } from '../../lib/core.js'; -import { - createDerivers, - NonMethods, - InferProvable as GenericInferProvable, - InferJson, - InferredProvable as GenericInferredProvable, - IsPure as GenericIsPure, - createHashInput, - Constructor, -} from './provable-generic.js'; -import { Tuple } from '../../lib/util/types.js'; -import { GenericHashInput } from './generic.js'; - -// external API -export { - ProvableExtended, - provable, - provablePure, - provableTuple, - provableFromClass, -}; - -// internal API -export { - NonMethods, - HashInput, - InferProvable, - InferJson, - InferredProvable, - IsPure, -}; - -type ProvableExtension = { - toInput: (x: T) => { fields?: Field[]; packed?: [Field, number][] }; - toJSON: (x: T) => TJson; - fromJSON: (x: TJson) => T; - empty: () => T; -}; -type ProvableExtended = Provable & - ProvableExtension; -type ProvablePureExtended = ProvablePure & - ProvableExtension; - -type InferProvable = GenericInferProvable; -type InferredProvable = GenericInferredProvable; -type IsPure = GenericIsPure; - -type HashInput = GenericHashInput; -const HashInput = createHashInput(); - -const { provable } = createDerivers(); - -function provablePure( - typeObj: A -): ProvablePureExtended, InferJson> { - return provable(typeObj, { isPure: true }) as any; -} - -function provableTuple>(types: T): InferredProvable { - return provable(types) as any; -} - -function provableFromClass>( - Class: Constructor & { check?: (x: T) => void; empty?: () => T }, - typeObj: A -): IsPure extends true - ? ProvablePureExtended> - : ProvableExtended> { - let raw = provable(typeObj); - return { - sizeInFields: raw.sizeInFields, - toFields: raw.toFields, - toAuxiliary: raw.toAuxiliary, - fromFields(fields, aux) { - return construct(Class, raw.fromFields(fields, aux)); - }, - check(value) { - if (Class.check !== undefined) { - Class.check(value); - } else { - raw.check(value); - } - }, - toInput: raw.toInput, - toJSON: raw.toJSON, - fromJSON(x) { - return construct(Class, raw.fromJSON(x)); - }, - empty() { - return Class.empty !== undefined - ? Class.empty() - : construct(Class, raw.empty()); - }, - } satisfies ProvableExtended> as any; -} - -function construct(Class: Constructor, value: Raw): T { - let instance = Object.create(Class.prototype); - return Object.assign(instance, value); -} diff --git a/mina-transaction/transaction-leaves-bigint.ts b/mina-transaction/transaction-leaves-bigint.ts index 6564abdb..3076edda 100644 --- a/mina-transaction/transaction-leaves-bigint.ts +++ b/mina-transaction/transaction-leaves-bigint.ts @@ -4,15 +4,15 @@ import { UInt32, UInt64, Sign, -} from '../../provable/field-bigint.js'; -import { PublicKey } from '../../provable/curve-bigint.js'; +} from '../../mina-signer/src/field-bigint.js'; +import { PublicKey } from '../../mina-signer/src/curve-bigint.js'; import { derivedLeafTypesSignable } from './derived-leaves.js'; import { createEvents } from '../../lib/events.js'; import { Poseidon, HashHelpers, packToFields, -} from '../../provable/poseidon-bigint.js'; +} from '../../mina-signer/src/poseidon-bigint.js'; import { mocks, protocolVersions } from '../crypto/constants.js'; export { PublicKey, Field, Bool, AuthRequired, UInt64, UInt32, Sign, TokenId }; diff --git a/mina-transaction/transaction-leaves.ts b/mina-transaction/transaction-leaves.ts index 9935b338..90c0564d 100644 --- a/mina-transaction/transaction-leaves.ts +++ b/mina-transaction/transaction-leaves.ts @@ -9,7 +9,7 @@ import { packToFields, emptyHashWithPrefix, } from '../../lib/hash.js'; -import { provable } from '../../lib/circuit-value.js'; +import { provable } from '../../lib/provable-types/struct.js'; import { mocks, protocolVersions } from '../crypto/constants.js'; export { PublicKey, Field, Bool, AuthRequired, UInt64, UInt32, Sign, TokenId };