import { FeatureFlags, Field, PrivateKey, Provable, ProvableType, PublicKey, Signature, UInt32, Unconstrained, VerificationKey } from 'o1js'; import { Spec, type Input, type Claims } from './program-spec.ts'; import { type Program } from './program.ts'; import { type CredentialSpec, type StoredCredential } from './credential.ts'; import { type NetworkId, type WalletDerivedContext, type HttpsInputContext, type HttpsWalletContext, type ZkAppInputContext } from './context.ts'; export { PresentationRequest, HttpsRequest, ZkAppRequest, Presentation, ProvablePresentation, }; export { type PresentationRequestType, pickCredentials }; type PresentationRequestType = 'no-context' | 'zk-app' | 'https'; type PresentationRequest = Record, InputContext = any, WalletContext = any> = { type: RequestType; spec: Spec; claims: Claims; inputContext: InputContext; program?: unknown; verificationKey?: VerificationKey; deriveContext( /** * Context that is passed in from the input request / server-side */ inputContext: InputContext, /** * Application-specific context that is passed in from the wallet / client-side */ walletContext: WalletContext, /** * Context automatically (re-)derived on the client */ derivedContext: WalletDerivedContext): Field; }; type CompiledRequest> = { spec: Spec; program: Program; verificationKey: VerificationKey; ProvablePresentation: typeof ProvablePresentation & { from(input: Presentation): ProvablePresentation; provable: Provable, Presentation>; }; }; declare const PresentationRequest: { https>(spec: Spec, claims: Claims, context: { action: string; }): HttpsRequest; httpsFromCompiled>(compiled: CompiledRequest, claims: Claims, context: { action: string; }): HttpsRequest; zkApp>(spec: Spec, claims: Claims, context: { publicKey: PublicKey; tokenId?: Field; methodName: string; network: NetworkId; nonce?: UInt32; }): ZkAppRequest; zkAppFromCompiled>(compiled: CompiledRequest, claims: Claims, context: { publicKey: PublicKey; tokenId?: Field; methodName: string; network?: NetworkId; nonce?: UInt32; }): ZkAppRequest; noContext>(spec: Spec, claims: Claims): NoContextRequest; toJSON(request: PresentationRequest): string; fromJSON, K extends PresentationRequestType = PresentationRequestType>(expectedType: K, json: string): R; }; type Presentation = Record> = { version: 'v0'; claims: Claims; outputClaim: Output; serverNonce: Field; clientNonce: Field; proof: { proof: string; maxProofsVerified: 0 | 1 | 2; }; }; type Output = R extends PresentationRequest ? O : never; type Inputs = R extends PresentationRequest ? I : never; type WalletContext = R extends PresentationRequest ? W : never; declare const Presentation: { precompile>(spec: Spec): Promise>; compile(request: R): Promise & { program: Program, Inputs>; verificationKey: VerificationKey; }>; /** * Create a presentation, given the request, context, and credentials. * * The first argument is the private key of the credential's owner, which is needed to sign credentials. */ create: typeof createPresentation; /** * Prepare a presentation, given the request, context, and credentials * * This way creating the presentation doesn't require the private key of the owner but * instead lets the wallet to handle the signing process */ prepare: typeof preparePresentation; /** * Finalize presentation given request, signature, and prepared data from preparePresentation */ finalize: typeof finalizePresentation; /** * Verify a presentation against a request and context. * * Returns the verified output claim of the proof, to be consumed by application-specific logic. */ verify: typeof verifyPresentation; /** * Serialize a presentation to JSON. */ toJSON: typeof toJSON; /** * Deserialize a presentation from JSON. */ fromJSON: typeof fromJSON; }; declare function preparePresentation({ request, context: walletContext, credentials, }: { request: R; context: WalletContext; credentials: (StoredCredential & { key?: string; })[]; }): Promise<{ context: Field; messageFields: string[]; credentialsUsed: Record; serverNonce: Field; clientNonce: Field; compiledRequest: CompiledRequest, Inputs>; }>; declare function finalizePresentation(request: R, ownerSignature: Signature, preparedData: { serverNonce: Field; clientNonce: Field; context: Field; credentialsUsed: Record; compiledRequest: { program: Program, Inputs>; }; }): Promise, Inputs>>; declare function createPresentation(ownerKey: PrivateKey, params: { request: R; context: WalletContext; credentials: (StoredCredential & { key?: string; })[]; }): Promise, Inputs>>; declare function verifyPresentation(request: R, presentation: Presentation>, context: WalletContext): Promise>; declare function toJSON>(presentation: Presentation): string; declare function fromJSON(presentationJson: string): Presentation; declare function pickCredentials(spec: Spec, [...credentials]: (StoredCredential & { key?: string; })[]): { credentialsUsed: Record; credentialsAndSpecs: (StoredCredential & { spec: CredentialSpec; })[]; }; type RequestFromType = Record> = Type extends 'no-context' ? NoContextRequest : Type extends 'zk-app' ? ZkAppRequest : Type extends 'https' ? HttpsRequest : never; type NoContextRequest = Record> = PresentationRequest<'no-context', Output, Inputs, undefined, undefined>; type HttpsRequest = Record> = PresentationRequest<'https', Output, Inputs, HttpsInputContext, HttpsWalletContext>; type ZkAppRequest = Record> = PresentationRequest<'zk-app', Output, Inputs, ZkAppInputContext, undefined>; declare function HttpsRequest>(request: { spec: Spec; claims: Claims; inputContext: HttpsInputContext; program?: Program; verificationKey?: VerificationKey; }): HttpsRequest; declare function ZkAppRequest>(request: { spec: Spec; claims: Claims; inputContext: ZkAppInputContext; program?: Program; verificationKey?: VerificationKey; }): ZkAppRequest; /** * Presentation that can be verified inside a zkApp. * * Create a subclass for your presentation as follows: * * ```ts * let compiled = await Presentation.precompile(spec); * class ProvablePresentation extends compiled.ProvablePresentation {} * ``` */ declare class ProvablePresentation = any> { claims: Claims; outputClaim: Output; clientNonce: Field; serverNonce: Unconstrained; proof: Unconstrained; constructor(input: { claims: Claims; outputClaim: Output; clientNonce: Field; serverNonce: Unconstrained; proof: Unconstrained; }); compiledRequest(): { claimsType: ProvableType>; outputClaimType: ProvableType; tagName: string; verificationKey: VerificationKey; maxProofsVerified: 0 | 1 | 2; featureFlags: FeatureFlags; }; /** * Verify presentation in a provable context. * * Input is the zkApp which this presentation is verified in. * * Pass in the public key, token id and current method of your zkapp to make sure * you don't accept presentations that were intended for a different context. * * Optionally, you can further restrict context by passing in the network and nonce. */ verify(context: { publicKey: PublicKey; tokenId: Field; methodName: string; network?: NetworkId; nonce?: UInt32; }): { claims: Claims; outputClaim: Output; }; static get provable(): Provable>; }