mina-attestations
Version:
Private Attestations on Mina
89 lines (88 loc) • 3.79 kB
TypeScript
import { PublicKey, Signature, Field, PrivateKey } from 'o1js';
import { type InferNestedProvable, NestedProvable, type NestedProvableFor } from './nested.ts';
import type { JSONValue } from './types.ts';
import type { ImportedWitnessSpec } from './credential-imported.ts';
export { type Credential, type CredentialSpec, type WitnessSpec, type CredentialType, type CredentialInputs, type CredentialOutputs, hashCredential, verifyCredentials, signCredentials, type StoredCredential, withOwner, Unsigned, unsafeMissingOwner, createUnsigned, credentialMatchesSpec, };
/**
* A credential is a generic piece of data (the "attributes") along with an owner represented by a public key.
*/
type Credential<Data = unknown> = {
owner: PublicKey;
data: Data;
};
/**
* The different types of credential we currently support.
*/
type CredentialType = 'unsigned' | 'native' | 'imported';
/**
* A credential spec is:
* - a string `credentialType` identifying the credential type
* - a "witness" type for private parameters
* - a type for data (which is left generic when defining credential types)
* - a function `verify(...)` that verifies the credential inside a ZkProgram circuit
* - a function `validate(...)` that verifies the credential in normal JS
* - a function `issuer(...)` that derives a commitment to the "issuer" of the credential, e.g. a public key for signed credentials
* - a function `matchesSpec(...)` that decides whether a stored credential's witness matches the spec
*/
type CredentialSpec<Witness = unknown, Data = unknown> = {
credentialType: CredentialType;
data: NestedProvableFor<Data>;
witness: WitnessSpec;
witnessType(type: WitnessSpec): NestedProvableFor<Witness>;
verify(witness: Witness, credHash: Field): void;
issuer(witness: Witness): Field;
validate(witness: Witness, credHash: Field): Promise<void>;
matchesSpec(witness: Witness): boolean;
};
type WitnessSpec = ImportedWitnessSpec | undefined;
/**
* Credential in stored form, including the witness and metadata.
*/
type StoredCredential<Data = unknown, Witness = unknown> = {
version: 'v0';
witness: Witness;
metadata: JSONValue | undefined;
credential: Credential<Data>;
};
/**
* Hash a credential.
*/
declare function hashCredential({ owner, data }: Credential): import("node_modules/o1js/dist/node/lib/provable/field.js").Field;
/**
* Inputs to verify credentials inside a presentation proof.
*/
type CredentialInputs = {
context: Field;
ownerSignature: Signature;
credentials: {
spec: CredentialSpec;
credential: Credential;
witness: unknown;
}[];
};
/**
* Outputs of verifying credentials, used as inputs to application circuit.
*/
type CredentialOutputs = {
owner: PublicKey;
credentials: {
data: unknown;
witness: unknown;
issuer: Field;
}[];
};
declare function verifyCredentials({ context, ownerSignature, credentials, }: CredentialInputs): CredentialOutputs;
declare function signCredentials<Private, Data>(ownerKey: PrivateKey, context: Field, ...credentials: {
credentialType: CredentialSpec<Private, Data>;
credential: Credential<Data>;
witness: Private;
}[]): Signature;
declare function credentialMatchesSpec(spec: CredentialSpec, credential: StoredCredential): boolean;
type Unsigned<Data> = StoredCredential<Data, undefined>;
declare function Unsigned<DataType extends NestedProvable>(data: DataType): CredentialSpec<undefined, InferNestedProvable<DataType>>;
declare function unsafeMissingOwner(): PublicKey;
declare function createUnsigned<Data>(data: Data, metadata?: JSONValue): Unsigned<Data>;
declare function withOwner<DataType extends NestedProvable>(data: DataType): {
owner: typeof PublicKey;
data: DataType;
};