Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure o1js/src/lib #1520

Merged
merged 7 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 51 additions & 42 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,60 +1,72 @@
export type { ProvablePure } from './lib/provable-types/provable-intf.js';
export type { ProvablePure } from './lib/provable/types/provable-intf.js';
export { Ledger } from './snarky.js';
export { Field, Bool, Group, Scalar } from './lib/core.js';
export { Field, Bool, Group, Scalar } from './lib/provable/wrapped.js';
export {
createForeignField,
ForeignField,
AlmostForeignField,
CanonicalForeignField,
} from './lib/foreign-field.js';
export { createForeignCurve, ForeignCurve } from './lib/foreign-curve.js';
export { createEcdsa, EcdsaSignature } from './lib/foreign-ecdsa.js';
export { Poseidon, TokenSymbol, ProvableHashable } from './lib/hash.js';
export { Keccak } from './lib/keccak.js';
export { Hash } from './lib/hashes-combined.js';
} from './lib/provable/foreign-field.js';
export {
createForeignCurve,
ForeignCurve,
} from './lib/provable/crypto/foreign-curve.js';
export {
createEcdsa,
EcdsaSignature,
} from './lib/provable/crypto/foreign-ecdsa.js';
export {
Poseidon,
TokenSymbol,
ProvableHashable,
} from './lib/provable/crypto/poseidon.js';
export { Keccak } from './lib/provable/crypto/keccak.js';
export { Hash } from './lib/provable/crypto/hash.js';

export { assert } from './lib/gadgets/common.js';
export { assert } from './lib/provable/gadgets/common.js';

export * from './lib/signature.js';
export * from './lib/provable/crypto/signature.js';
export type {
ProvableExtended,
FlexibleProvable,
FlexibleProvablePure,
InferProvable,
} from './lib/provable-types/struct.js';
export { provable, provablePure, Struct } from './lib/provable-types/struct.js';
export { Unconstrained } from './lib/provable-types/unconstrained.js';
export { Provable } from './lib/provable.js';
export { Circuit, Keypair, public_, circuitMain } from './lib/circuit.js';
export { UInt32, UInt64, Int64, Sign, UInt8 } from './lib/int.js';
export { Bytes } from './lib/provable-types/provable-types.js';
export { Packed, Hashed } from './lib/provable-types/packed.js';
export { Gadgets } from './lib/gadgets/gadgets.js';
} from './lib/provable/types/struct.js';
export { provable, provablePure, Struct } from './lib/provable/types/struct.js';
export { Unconstrained } from './lib/provable/types/unconstrained.js';
export { Provable } from './lib/provable/provable.js';
export {
Circuit,
Keypair,
public_,
circuitMain,
} from './lib/proof-system/circuit.js';
export { UInt32, UInt64, Int64, Sign, UInt8 } from './lib/provable/int.js';
export { Bytes } from './lib/provable/wrapped-classes.js';
export { Packed, Hashed } from './lib/provable/packed.js';
export { Gadgets } from './lib/provable/gadgets/gadgets.js';
export { Types } from './bindings/mina-transaction/types.js';

export {
MerkleList,
MerkleListIterator,
} from './lib/provable-types/merkle-list.js';
export { MerkleList, MerkleListIterator } from './lib/provable/merkle-list.js';

export * as Mina from './lib/mina.js';
export * as Mina from './lib/mina/mina.js';
export {
type Transaction,
type PendingTransaction,
type IncludedTransaction,
type RejectedTransaction,
} from './lib/mina/transaction.js';
export type { DeployArgs } from './lib/zkapp.js';
export type { DeployArgs } from './lib/mina/zkapp.js';
export {
SmartContract,
method,
declareMethods,
Account,
Reducer,
} from './lib/zkapp.js';
export { state, State, declareState } from './lib/state.js';
} from './lib/mina/zkapp.js';
export { state, State, declareState } from './lib/mina/state.js';

export type { JsonProof } from './lib/proof-system.js';
export type { JsonProof } from './lib/proof-system/zkprogram.js';
export {
Proof,
SelfProof,
Expand All @@ -63,7 +75,7 @@ export {
Undefined,
Void,
VerificationKey,
} from './lib/proof-system.js';
} from './lib/proof-system/zkprogram.js';
export { Cache, CacheHeader } from './lib/proof-system/cache.js';

export {
Expand All @@ -74,7 +86,7 @@ export {
TransactionVersion,
AccountUpdateForest,
AccountUpdateTree,
} from './lib/account-update.js';
} from './lib/mina/account-update.js';

export { TokenAccountUpdateIterator } from './lib/mina/token/forest-iterator.js';
export { TokenContract } from './lib/mina/token/token-contract.js';
Expand All @@ -92,28 +104,25 @@ export {
setArchiveGraphqlEndpoint,
sendZkapp,
Lightnet,
} from './lib/fetch.js';
export * as Encryption from './lib/encryption.js';
} from './lib/mina/fetch.js';
export * as Encryption from './lib/provable/crypto/encryption.js';
export * as Encoding from './bindings/lib/encoding.js';
export { Character, CircuitString } from './lib/provable-types/string.js';
export { MerkleTree, MerkleWitness } from './lib/provable-types/merkle-tree.js';
export {
MerkleMap,
MerkleMapWitness,
} from './lib/provable-types/merkle-map.js';
export { Character, CircuitString } from './lib/provable/string.js';
export { MerkleTree, MerkleWitness } from './lib/provable/merkle-tree.js';
export { MerkleMap, MerkleMapWitness } from './lib/provable/merkle-map.js';

export { Nullifier } from './lib/nullifier.js';
export { Nullifier } from './lib/provable/crypto/nullifier.js';

export { ZkProgram } from './lib/proof-system.js';
export { ZkProgram } from './lib/proof-system/zkprogram.js';

export { Crypto } from './lib/crypto.js';
export { Crypto } from './lib/provable/crypto/crypto.js';

export type { NetworkId } from './mina-signer/mina-signer.js';

export { setNumberOfWorkers } from './lib/proof-system/workers.js';

// experimental APIs
import { memoizeWitness } from './lib/provable.js';
import { memoizeWitness } from './lib/provable/provable.js';
export { Experimental };

const Experimental_ = {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/mina/account-update-layout.unit-test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Mina } from '../../index.js';
import { AccountUpdate, AccountUpdateTree } from '../account-update.js';
import { UInt64 } from '../int.js';
import { SmartContract, method } from '../zkapp.js';
import { AccountUpdate, AccountUpdateTree } from './account-update.js';
import { UInt64 } from '../provable/int.js';
import { SmartContract, method } from './zkapp.js';

// smart contract which creates an account update that has a child of its own

Expand Down
65 changes: 39 additions & 26 deletions src/lib/account-update.ts → src/lib/mina/account-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@ import {
provable,
provablePure,
StructNoJson,
} from './provable-types/struct.js';
import { memoizationContext, memoizeWitness, Provable } from './provable.js';
import { Field, Bool } from './core.js';
import { Pickles, Test } from '../snarky.js';
import { jsLayout } from '../bindings/mina-transaction/gen/js-layout.js';
} from '../provable/types/struct.js';
import {
memoizationContext,
memoizeWitness,
Provable,
} from '../provable/provable.js';
import { Field, Bool } from '../provable/wrapped.js';
import { Pickles, Test } from '../../snarky.js';
import { jsLayout } from '../../bindings/mina-transaction/gen/js-layout.js';
import {
Types,
TypesBigint,
toJSONEssential,
} from '../bindings/mina-transaction/types.js';
import { PrivateKey, PublicKey } from './signature.js';
import { UInt64, UInt32, Int64, Sign } from './int.js';
} from '../../bindings/mina-transaction/types.js';
import { PrivateKey, PublicKey } from '../provable/crypto/signature.js';
import { UInt64, UInt32, Int64, Sign } from '../provable/int.js';
import type { SmartContract } from './zkapp.js';
import {
Preconditions,
Expand All @@ -27,49 +31,58 @@ import {
ClosedInterval,
getAccountPreconditions,
} from './precondition.js';
import { dummyBase64Proof, Empty, Proof, Prover } from './proof-system.js';
import { Memo } from '../mina-signer/src/memo.js';
import {
dummyBase64Proof,
Empty,
Proof,
Prover,
} from '../proof-system/zkprogram.js';
import { Memo } from '../../mina-signer/src/memo.js';
import {
Events,
Actions,
} from '../bindings/mina-transaction/transaction-leaves.js';
} from '../../bindings/mina-transaction/transaction-leaves.js';
import { TokenId as Base58TokenId } from './base58-encodings.js';
import { hashWithPrefix, packToFields, Poseidon } from './hash.js';
import {
hashWithPrefix,
packToFields,
Poseidon,
} from '../provable/crypto/poseidon.js';
import {
mocks,
prefixes,
protocolVersions,
} from '../bindings/crypto/constants.js';
import { MlArray } from './ml/base.js';
} from '../../bindings/crypto/constants.js';
import { MlArray } from '../ml/base.js';
import {
Signature,
signFieldElement,
zkAppBodyPrefix,
} from '../mina-signer/src/signature.js';
import { MlFieldConstArray } from './ml/fields.js';
} from '../../mina-signer/src/signature.js';
import { MlFieldConstArray } from '../ml/fields.js';
import {
accountUpdatesToCallForest,
CallForest,
callForestHashGeneric,
transactionCommitments,
} from '../mina-signer/src/sign-zkapp-command.js';
import { currentTransaction } from './mina/transaction-context.js';
import { isSmartContract } from './mina/smart-contract-base.js';
import { activeInstance } from './mina/mina-instance.js';
} from '../../mina-signer/src/sign-zkapp-command.js';
import { currentTransaction } from './transaction-context.js';
import { isSmartContract } from './smart-contract-base.js';
import { activeInstance } from './mina-instance.js';
import {
emptyHash,
genericHash,
MerkleList,
MerkleListBase,
} from './provable-types/merkle-list.js';
import { Hashed } from './provable-types/packed.js';
} from '../provable/merkle-list.js';
import { Hashed } from '../provable/packed.js';
import {
accountUpdateLayout,
smartContractContext,
} from './mina/smart-contract-context.js';
import { assert } from './util/assert.js';
import { RandomId } from './provable-types/auxiliary.js';
import { NetworkId } from '../mina-signer/src/types.js';
} from './smart-contract-context.js';
import { assert } from '../util/assert.js';
import { RandomId } from '../provable/types/auxiliary.js';
import { NetworkId } from '../../mina-signer/src/types.js';

// external API
export {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { mocks } from '../bindings/crypto/constants.js';
import { mocks } from '../../bindings/crypto/constants.js';
import {
AccountUpdate,
PrivateKey,
Field,
Mina,
Int64,
Types,
} from '../index.js';
import { Test } from '../snarky.js';
} from '../../index.js';
import { Test } from '../../snarky.js';
import { expect } from 'expect';

let address = PrivateKey.random().toPublicKey();
Expand Down
12 changes: 6 additions & 6 deletions src/lib/mina/account.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Types } from '../../bindings/mina-transaction/types.js';
import { Bool, Field } from '../core.js';
import { Permissions } from '../account-update.js';
import { UInt32, UInt64 } from '../int.js';
import { PublicKey } from '../signature.js';
import { TokenId, ReceiptChainHash } from '../base58-encodings.js';
import { Bool, Field } from '../provable/wrapped.js';
import { Permissions } from './account-update.js';
import { UInt32, UInt64 } from '../provable/int.js';
import { PublicKey } from '../provable/crypto/signature.js';
import { TokenId, ReceiptChainHash } from './base58-encodings.js';
import { genericLayoutFold } from '../../bindings/lib/from-layout.js';
import {
customTypes,
TypeMap,
} from '../../bindings/mina-transaction/gen/transaction.js';
import { jsLayout } from '../../bindings/mina-transaction/gen/js-layout.js';
import { ProvableExtended } from '../provable-types/struct.js';
import { ProvableExtended } from '../provable/types/struct.js';
import { FetchedAccount } from './graphql.js';

export { Account, PartialAccount };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fieldEncodings } from './base58.js';
import { Field } from './core.js';
import { fieldEncodings } from '../util/base58.js';
import { Field } from '../provable/wrapped.js';

export { TokenId, ReceiptChainHash, LedgerHash, EpochSeed, StateHash };

Expand Down
4 changes: 2 additions & 2 deletions src/lib/mina/errors.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Types } from '../../bindings/mina-transaction/types.js';
import { TokenId } from '../account-update.js';
import { Int64 } from '../int.js';
import { TokenId } from './account-update.js';
import { Int64 } from '../provable/int.js';

export { invalidTransactionError };

Expand Down
6 changes: 3 additions & 3 deletions src/lib/events.ts → src/lib/mina/events.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { prefixes } from '../bindings/crypto/constants.js';
import { prefixToField } from '../bindings/lib/binable.js';
import { prefixes } from '../../bindings/crypto/constants.js';
import { prefixToField } from '../../bindings/lib/binable.js';
import {
GenericProvableExtended,
GenericSignableField,
} from '../bindings/lib/generic.js';
} from '../../bindings/lib/generic.js';

export { createEvents, dataAsHash };

Expand Down
12 changes: 6 additions & 6 deletions src/lib/fetch.ts → src/lib/mina/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import 'isomorphic-fetch';
import { Field } from './core.js';
import { UInt32, UInt64 } from './int.js';
import { Field } from '../provable/wrapped.js';
import { UInt32, UInt64 } from '../provable/int.js';
import { Actions, TokenId } from './account-update.js';
import { PublicKey, PrivateKey } from './signature.js';
import { PublicKey, PrivateKey } from '../provable/crypto/signature.js';
import { NetworkValue } from './precondition.js';
import { Types } from '../bindings/mina-transaction/types.js';
import { Types } from '../../bindings/mina-transaction/types.js';
import { ActionStates } from './mina.js';
import { LedgerHash, EpochSeed, StateHash } from './base58-encodings.js';
import {
Account,
fillPartialAccount,
parseFetchedAccount,
PartialAccount,
} from './mina/account.js';
} from './account.js';
import {
type LastBlockQueryResponse,
type GenesisConstantsResponse,
Expand All @@ -35,7 +35,7 @@ import {
genesisConstantsQuery,
accountQuery,
currentSlotQuery,
} from './mina/graphql.js';
} from './graphql.js';

export {
fetchAccount,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { removeJsonQuotes } from './mina/graphql.js';
import { removeJsonQuotes } from './graphql.js';
import { expect } from 'expect';

console.log('testing regex helpers');
Expand Down
6 changes: 3 additions & 3 deletions src/lib/mina/graphql.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { UInt32 } from '../int.js';
import type { ZkappCommand } from '../account-update.js';
import type { ActionStatesStringified } from '../fetch.js';
import { UInt32 } from '../provable/int.js';
import type { ZkappCommand } from './account-update.js';
import type { ActionStatesStringified } from './fetch.js';
import { Types } from '../../bindings/mina-transaction/types.js';

export {
Expand Down
Loading
Loading