import { PublicKey, Signature, Field, PrivateKey } from 'o1js'; import { type InferNestedProvable, NestedProvable, type NestedProvableFor } from './nested.ts'; import type { Json } 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 = { 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 = { credentialType: CredentialType; data: NestedProvableFor; witness: WitnessSpec; witnessType(type: WitnessSpec): NestedProvableFor; verify(witness: Witness, credHash: Field): void; issuer(witness: Witness): Field; validate(witness: Witness, credHash: Field): Promise; matchesSpec(witness: Witness): boolean; }; type WitnessSpec = ImportedWitnessSpec | undefined; /** * Credential in stored form, including the witness and metadata. */ type StoredCredential = { version: 'v0'; witness: Witness; metadata: Json | undefined; credential: Credential; }; /** * 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(ownerKey: PrivateKey, context: Field, ...credentials: { credentialType: CredentialSpec; credential: Credential; witness: Private; }[]): Signature; declare function credentialMatchesSpec(spec: CredentialSpec, credential: StoredCredential): boolean; type Unsigned = StoredCredential; declare function Unsigned(data: DataType): CredentialSpec>; declare function unsafeMissingOwner(): PublicKey; declare function createUnsigned(data: Data, metadata?: Json): Unsigned; declare function withOwner(data: DataType): { owner: typeof PublicKey; data: DataType; };