mina-attestations
Version:
Private Attestations on Mina
104 lines (103 loc) • 4.68 kB
TypeScript
import { Bool, Field, Signature, PublicKey, type InferProvable, Provable, type From } from 'o1js';
import type { ExcludeFromRecord } from './types.ts';
import { ProvableType } from './o1js-missing.ts';
import { type InferNestedProvable, NestedProvable, type NestedProvableFor } from './nested.ts';
import { type CredentialSpec, type Credential, type CredentialInputs, type CredentialOutputs } from './credential.ts';
import { type InputToNode, Node } from './operation.ts';
export type { PublicInputs, PrivateInputs, UserInputs, RootValue, Input, Claims, RootType, };
export { Spec, Claim, Constant, publicInputTypes, publicOutputType, privateInputTypes, splitUserInputs, extractCredentialInputs, rootValue, isCredentialSpec, };
type Spec<Output = unknown, Inputs extends Record<string, Input> = Record<string, Input>> = {
inputs: Inputs;
assert: Node<Bool>;
outputClaim: Node<Output>;
};
/**
* Specify a ZkProgram that verifies and selectively discloses data
*/
declare function Spec<Output, Inputs extends Record<string, Input>>(inputs: Inputs, spec: (inputs: {
[K in keyof Inputs]: InputToNode<Inputs[K]>;
}) => {
assert?: Node<Bool> | Node<Bool>[];
outputClaim: Node<Output>;
}): Spec<Output, Inputs>;
declare function Spec<Inputs extends Record<string, Input>>(inputs: Inputs, spec: (inputs: {
[K in keyof Inputs]: InputToNode<Inputs[K]>;
}) => {
assert?: Node<Bool> | Node<Bool>[];
}): Spec<undefined, Inputs>;
type Constant<Data> = {
type: 'constant';
data: ProvableType<Data>;
value: Data;
};
type Claim<Data> = {
type: 'claim';
data: NestedProvableFor<Data>;
};
type Input<Data = any> = (CredentialSpec<any, Data> & {
type?: undefined;
}) | Constant<Data> | Claim<Data>;
declare function isCredentialSpec(input: Input | undefined): input is CredentialSpec;
declare function Constant<DataType extends ProvableType>(data: DataType, value: From<DataType>): Constant<InferProvable<DataType>>;
declare function Claim<DataType extends NestedProvable>(data: DataType): Claim<InferNestedProvable<DataType>>;
declare function publicInputTypes({ inputs }: Spec): {
context: typeof Field;
claims: NestedProvable;
};
type CredentialInputType = {
credential: {
owner: PublicKey;
data: unknown;
};
witness: unknown;
};
declare function privateInputTypes({ inputs }: Spec): NestedProvableFor<{
ownerSignature: Signature;
credentials: Record<string, CredentialInputType>;
}>;
declare function publicOutputType(spec: Spec): Provable<unknown>;
type RootType = Record<string, NestedProvable | CredentialSpec>;
declare function splitUserInputs<I extends Spec['inputs']>(userInputs: UserInputs<I>): {
publicInput: PublicInputs<I>;
privateInput: PrivateInputs<I>;
};
declare function extractCredentialInputs(spec: Spec, { context }: PublicInputs<any>, { ownerSignature, credentials }: PrivateInputs<any>): CredentialInputs;
declare function rootValue<S extends Spec>(spec: S, publicInputs: PublicInputs<any>, privateInputs: PrivateInputs<any>, credentialOutputs: CredentialOutputs): RootValue<S['inputs']>;
type Claims<Inputs extends Record<string, Input>> = ExcludeFromRecord<MapToClaims<Inputs>, never>;
type PublicInputs<Inputs extends Record<string, Input>> = {
context: Field;
claims: Claims<Inputs>;
};
type Credentials<Inputs extends Record<string, Input>> = ExcludeFromRecord<MapToCredentials<Inputs>, never>;
type PrivateInputs<Inputs extends Record<string, Input>> = {
ownerSignature: Signature;
credentials: Credentials<Inputs>;
};
type UserInputs<Inputs extends Record<string, Input>> = {
context: Field;
ownerSignature: Signature;
claims: ExcludeFromRecord<MapToClaims<Inputs>, never>;
credentials: ExcludeFromRecord<MapToCredentials<Inputs>, never>;
};
type RootValue<Inputs extends Record<string, Input> = Record<string, Input>> = ExcludeFromRecord<MapToDataInput<Inputs>, never> & {
owner: PublicKey;
};
type MapToClaims<T extends Record<string, Input>> = {
[K in keyof T]: ToClaim<T[K]>;
};
type MapToCredentials<T extends Record<string, Input>> = {
[K in keyof T]: ToCredential<T[K]>;
};
type MapToDataInput<T extends Record<string, Input>> = {
[K in keyof T]: ToDataInput<T[K]>;
};
type ToClaim<T extends Input> = T extends Claim<infer Data> ? Data : never;
type ToCredential<T extends Input> = T extends CredentialSpec<infer Witness, infer Data> ? {
credential: Credential<Data>;
witness: Witness;
} : never;
type ToDataInput<T extends Input> = T extends CredentialSpec<infer Witness, infer Data> ? {
data: Data;
witness: Witness;
issuer: Field;
} : T extends Input<infer Data> ? Data : never;