Options
All
  • Public
  • Public/Protected
  • All
Menu

snarkyjs

Index

Type aliases

AccountPrecondition: PartyBody["accountPrecondition"]
DeployArgs: { verificationKey?: { data: string; hash: string | Field }; zkappKey?: PrivateKey }

Type declaration

  • Optional verificationKey?: { data: string; hash: string | Field }
    • data: string
    • hash: string | Field
  • Optional zkappKey?: PrivateKey
FeePayerUnsigned: { authorization: UnfinishedSignature | string; body: FeePayerBody }

Type declaration

  • authorization: UnfinishedSignature | string
  • body: FeePayerBody
JSONValue: number | string | boolean | null | JSONValue[] | {}
LazyControl: Control | LazySignature | LazyProof
LazyProof: { ZkappClass: typeof SmartContract; args: any[]; kind: "lazy-proof"; method: Function }

Type declaration

  • ZkappClass: typeof SmartContract
  • args: any[]
  • kind: "lazy-proof"
  • method: Function
LazySignature: { kind: "lazy-signature"; privateKey?: PrivateKey }

Type declaration

  • kind: "lazy-signature"
  • Optional privateKey?: PrivateKey
Parties: { feePayer: FeePayerUnsigned; otherParties: Party[] }

Type declaration

Permission: Types.AuthRequired

One specific permission value.

A [[ Permission ]] tells one specific permission for our zkapp how it should behave when presented with requested modifications.

Use static factory methods on this class to use a specific behavior. See documentation on those methods to learn more.

SetOrKeep<T>: { isSome: Bool; value: T }

Either set a value or keep it the same.

Type parameters

  • T

Type declaration

  • isSome: Bool
  • value: T
State<A>: { assertEquals: any; fetch: any; get: any; set: any }

Gettable and settable state that can be checked for equality.

Type parameters

  • A

Type declaration

  • assertEquals:function
    • assertEquals(a: A): void
  • fetch:function
    • fetch(): Promise<undefined | A>
  • get:function
    • get(): A
  • set:function
    • set(a: A): void

Variables

AccountPrecondition: { ignoreAll: any; nonce: any }

Type declaration

Body: { dummy: any; keepAll: any; noUpdate: any }

Type declaration

Permission: { impossible: () => Types.AuthRequired; none: () => Types.AuthRequired; proof: () => Types.AuthRequired; proofOrSignature: () => Types.AuthRequired; signature: () => Types.AuthRequired }

Type declaration

Permissions: { default: () => Permissions; impossible: () => Types.AuthRequired; initial: () => Permissions; none: () => Types.AuthRequired; proof: () => Types.AuthRequired; proofOrSignature: () => Types.AuthRequired; signature: () => Types.AuthRequired }

Type declaration

Pickles: { compile: any; proofToString: any }

Type declaration

  • compile:function
    • compile(rules: [0, string, (statement: Statement) => void][]): { provers: ((statement: Statement) => Promise<unknown>)[]; getVerificationKeyArtifact: any; verify: any }
    • This is the core API of the Pickles library, exposed from OCaml to JS. It takes a list of circuits -- each in the form of a function which takes a public input { transaction: Field; atParty: Field } as argument --, and joins them into one single circuit which can not only provide proofs for any of the sub-circuits, but also adds the necessary circuit logic to recursively merge in earlier proofs.

      After forming that big circuit in the finite field represented by Field, it gets wrapped in a recursive circuit in the field represented by Scalar. Any SmartContract proof will go through both of these circuits, so that the final proof ends up back in Field.

      The function returns the building blocks needed for SmartContract proving:

      • provers - a list of prover functions, on for each input rule
      • verify - a function which can verify proofs from any of the provers
      • getVerificationKeyArtifact - a function which returns the verification key used in verify, in base58 format, usable to deploy a zkapp

      Parameters

      • rules: [0, string, (statement: Statement) => void][]

      Returns { provers: ((statement: Statement) => Promise<unknown>)[]; getVerificationKeyArtifact: any; verify: any }

      • provers: ((statement: Statement) => Promise<unknown>)[]
      • getVerificationKeyArtifact:function
        • getVerificationKeyArtifact(): { data: string; hash: string }
        • Returns { data: string; hash: string }

          • data: string
          • hash: string
      • verify:function
        • verify(statement: Statement, proof: unknown): Promise<boolean>
        • Parameters

          • statement: Statement
          • proof: unknown

          Returns Promise<boolean>

  • proofToString:function
    • proofToString(proof: unknown): string
Poseidon: { Sponge: typeof Sponge; hash: any }

Type declaration

ZkappStateLength: 8 = 8
isReady: Promise<undefined>

A Promise that resolves when SnarkyJS is ready to be used

Functions

  • Gettable and settable state that can be checked for equality.

    Type parameters

    • A

    Returns State<A>

  • addCachedAccount(account: { balance?: string | number | UInt64; nonce: string | number | UInt32; publicKey: string | PublicKey; zkapp?: { appState: (string | number | Field)[] } }, graphqlEndpoint?: string): void
  • Parameters

    • account: { balance?: string | number | UInt64; nonce: string | number | UInt32; publicKey: string | PublicKey; zkapp?: { appState: (string | number | Field)[] } }
      • Optional balance?: string | number | UInt64
      • nonce: string | number | UInt32
      • publicKey: string | PublicKey
      • Optional zkapp?: { appState: (string | number | Field)[] }
        • appState: (string | number | Field)[]
    • graphqlEndpoint: string = defaultGraphqlEndpoint

    Returns void

  • addMissingProofs(parties: Parties): Promise<PartiesProved>
  • arrayProp<T>(elementType: AsFieldElements<T>, length: number): (target: any, key: string) => void
  • Type parameters

    • T

    Parameters

    Returns (target: any, key: string) => void

      • (target: any, key: string): void
      • Parameters

        • target: any
        • key: string

        Returns void

  • call<S>(SmartContract: S, address: PublicKey, methodName: string, methodArguments: any, provers: Prover[], verify?: (statement: Statement, proof: unknown) => Promise<boolean>): Promise<string>
  • Type parameters

    Parameters

    • SmartContract: S
    • address: PublicKey
    • methodName: string
    • methodArguments: any
    • provers: Prover[]
    • Optional verify: (statement: Statement, proof: unknown) => Promise<boolean>
        • (statement: Statement, proof: unknown): Promise<boolean>
        • Parameters

          • statement: Statement
          • proof: unknown

          Returns Promise<boolean>

    Returns Promise<string>

  • callUnproved<S>(SmartContract: S, address: PublicKey, methodName: string, methodArguments: any, zkappKey?: PrivateKey): Promise<string>
  • circuitMain(target: any, propertyName: string, _descriptor?: PropertyDescriptor): any
  • Parameters

    • target: any
    • propertyName: string
    • Optional _descriptor: PropertyDescriptor

    Returns any

  • cloneCircuitValue<T>(obj: T): T
  • declareMethods<T>(SmartContract: T, methodArguments: Record<string, AsFieldElements<unknown>[]>): void
  • declareMethods can be used in place of the @method decorator to declare SmartContract methods along with their list of arguments. It should be placed after the class declaration. Here is an example of declaring a method update, which takes a single argument of type Field:

    class MyContract extends SmartContract {
    // ...
    update(x: Field) {
    // ...
    }
    }
    declareMethods(MyContract, { update: [Field] }); // `[Field]` is the list of arguments!

    Note that a method of the same name must still be defined on the class, just without the decorator.

    Type parameters

    Parameters

    • SmartContract: T
    • methodArguments: Record<string, AsFieldElements<unknown>[]>

    Returns void

  • declareState<T>(SmartContract: T, states: Record<string, AsFieldElements<unknown>>): void
  • declareState can be used in place of the @state decorator to declare on-chain state on a SmartContract. It should be placed after the class declaration. Here is an example of declaring a state property x of type Field.

    class MyContract extends SmartContract {
    x = State<Field>();
    // ...
    }
    declareState(MyContract, { x: Field });

    If you're using pure JS, it's not possible to use the built-in class field syntax, i.e. the following will not work:

    // THIS IS WRONG IN JS!
    class MyContract extends SmartContract {
    x = State();
    }
    declareState(MyContract, { x: Field });

    Instead, add a constructor where you assign the property:

    class MyContract extends SmartContract {
    constructor(x) {
    super();
    this.x = State();
    }
    }
    declareState(MyContract, { x: Field });

    Type parameters

    Parameters

    Returns void

  • deploy<S>(SmartContract: S, __namedParameters: { feePayerKey?: PrivateKey; feePayerNonce?: string | number; initialBalance?: string | number; shouldSignFeePayer?: boolean; transactionFee?: string | number; verificationKey: { data: string; hash: string | Field }; zkappKey: PrivateKey }): Promise<string>
  • Type parameters

    Parameters

    • SmartContract: S
    • __namedParameters: { feePayerKey?: PrivateKey; feePayerNonce?: string | number; initialBalance?: string | number; shouldSignFeePayer?: boolean; transactionFee?: string | number; verificationKey: { data: string; hash: string | Field }; zkappKey: PrivateKey }
      • Optional feePayerKey?: PrivateKey
      • Optional feePayerNonce?: string | number
      • Optional initialBalance?: string | number
      • Optional shouldSignFeePayer?: boolean
      • Optional transactionFee?: string | number
      • verificationKey: { data: string; hash: string | Field }
        • data: string
        • hash: string | Field
      • zkappKey: PrivateKey

    Returns Promise<string>

  • fetchAccount(publicKey: string | PublicKey, graphqlEndpoint?: string, config?: { timeout: undefined | number }): Promise<{ account: Account; error: undefined } | { account: undefined; error: FetchError }>
  • Gets account information on the specified publicKey by performing a GraphQL query to the specified endpoint. This will call the 'GetAccountInfo' query which fetches zkapp related account information.

    If an error is returned by the specified endpoint, an error is thrown. Otherwise, the data is returned.

    Parameters

    • publicKey: string | PublicKey

      The specified account to get account information on

    • graphqlEndpoint: string = defaultGraphqlEndpoint

      The graphql endpoint to fetch from

    • config: { timeout: undefined | number } = {}

      An object that exposes an additional timeout option

      • timeout: undefined | number

    Returns Promise<{ account: Account; error: undefined } | { account: undefined; error: FetchError }>

    zkapp information on the specified account or an error is thrown

  • getDefaultTokenId(): Field
  • getSrs(keypair: Keypair): typeof WasmFpSrs
  • Parameters

    • keypair: Keypair

      SNARK keypair, as returned by Circuit.generateKeypair

    Returns typeof WasmFpSrs

    The SRS (structured reference string), needed to reconstruct the keypair later

  • matrixProp<T>(elementType: AsFieldElements<T>, nRows: number, nColumns: number): (target: any, key: string) => void
  • Type parameters

    • T

    Parameters

    Returns (target: any, key: string) => void

      • (target: any, key: string): void
      • Parameters

        • target: any
        • key: string

        Returns void

  • method<T>(target: T & { constructor: any }, methodName: keyof T & string, descriptor: PropertyDescriptor): void
  • A decorator to use in a zkapp to mark a method as callable by anyone. You can use inside your zkapp class as:

    @method myMethod(someArg: Field) {
    // your code here
    }

    Type parameters

    Parameters

    • target: T & { constructor: any }
    • methodName: keyof T & string
    • descriptor: PropertyDescriptor

    Returns void

  • parseFetchedAccount(account: FetchedAccount): Account
  • parseFetchedAccount(account: Partial<FetchedAccount>): Partial<Account>
  • Parameters

    • account: FetchedAccount

    Returns Account

  • Parameters

    • account: Partial<FetchedAccount>

    Returns Partial<Account>

  • prop(this: any, target: any, key: string): void
  • public_(target: any, _key: string | symbol, index: number): void
  • recoverVerificationKey(srs: typeof WasmFpSrs, serializedVk: string): VerificationKey
  • Parameters

    • srs: typeof WasmFpSrs

      the "structured reference string", a set of precomputed values needed for verifying proofs

    • serializedVk: string

      string representation of a Circuit verification key

    Returns VerificationKey

    the recovered verification key

  • sendZkapp(json: string, graphqlEndpoint?: string, __namedParameters?: { timeout: undefined | number }): Promise<[FetchResponse, undefined] | [undefined, FetchError]>
  • Parameters

    • json: string
    • graphqlEndpoint: string = defaultGraphqlEndpoint
    • __namedParameters: { timeout: undefined | number } = {}
      • timeout: undefined | number

    Returns Promise<[FetchResponse, undefined] | [undefined, FetchError]>

  • sendZkappQuery(json: string): string
  • setGraphqlEndpoint(graphqlEndpoint: string): void
  • shutdown(): Promise<undefined>
  • This function must be called at the end of a nodejs program, otherwise the worker threads will continue running and the program will never terminate. From web applications, this function is a no-op.

    Returns Promise<undefined>

  • signFeePayer(transactionJson: string, feePayerKey: string | PrivateKey, __namedParameters: Object): string
  • Parameters

    • transactionJson: string
    • feePayerKey: string | PrivateKey
    • __namedParameters: Object

    Returns string

  • signJsonTransaction(transactionJson: string, privateKey: string | PrivateKey): string
  • Sign all parties of a transaction which belong to the account determined by [[ privateKey ]].

    Parameters

    • transactionJson: string
    • privateKey: string | PrivateKey

    Returns string

    the modified transaction JSON

  • A decorator to use within a zkapp to indicate what will be stored on-chain. For example, if you want to store a field element some_state in a zkapp, you can use the following in the declaration of your zkapp:

    @state(Field) some_state = State<Field>();
    

    Type parameters

    • A

    Parameters

    Returns (target: SmartContract & { constructor: any }, key: string, _descriptor?: PropertyDescriptor) => void

      • (target: SmartContract & { constructor: any }, key: string, _descriptor?: PropertyDescriptor): void
      • Parameters

        • target: SmartContract & { constructor: any }
        • key: string
        • Optional _descriptor: PropertyDescriptor

        Returns void

Generated using TypeDoc