import { Versioned } from './versioned'; import { BBSCredential, BBSPlusCredential, BBDT16Credential, PSCredential } from './credential'; import { CompositeProof } from '../composite-proof'; import { LegoProvingKey, LegoProvingKeyUncompressed } from '../legosnark'; import { R1CS } from 'crypto-wasm-new'; import { AccumulatorValueType, AccumulatorWitnessType, AttributeEquality, BoundCheckParamType, BoundType, FlattenedSchema, PredicateParamType, PublicKey, SignatureParams } from './types-and-consts'; import { IBlindCredentialRequest, IPresentedAttributeBound, IPresentedAttributeInequality, IPresentedAttributeVE, PresentationSpecification } from './presentation-specification'; import { Presentation } from './presentation'; import { AccumulatorPublicKey } from '../accumulator'; import { SaverChunkedCommitmentKey, SaverChunkedCommitmentKeyUncompressed, SaverEncryptionKey, SaverEncryptionKeyUncompressed, SaverProvingKey, SaverProvingKeyUncompressed } from '../saver'; import { ParsedR1CSFile } from '../r1cs/file'; import { PederCommKey, PederCommKeyUncompressed } from '../ped-com'; /** * Arguments required to generate the corresponding AttributeBoundPseudonym * */ export interface BoundedPseudonym { /** Keys are credential indices, values are the attribute names in that credential*/ attributeNames: Map; basesForAttributes: Uint8Array[]; baseForSecretKey?: Uint8Array; secretKey?: Uint8Array; } /** * Arguments required to generate the corresponding Pseudonym * */ export interface UnboundedPseudonym { baseForSecretKey: Uint8Array; secretKey: Uint8Array; } type Credential = BBSCredential | BBSPlusCredential | PSCredential | BBDT16Credential; export declare class PresentationBuilder extends Versioned { /** Follows semver and must be updated accordingly when the logic of this class changes or the underlying crypto changes. */ static VERSION: string; /** This can specify the reason why the proof was created, or date of the proof, or self-attested attributes (as JSON string), etc */ _context?: string; /** To prevent replay attack */ _nonce?: Uint8Array; proof?: CompositeProof; /** Just for debugging */ private _proofSpec?; spec: PresentationSpecification; /** Each credential is referenced by its index in this array */ credentials: [Credential, PublicKey?][]; /** Attributes revealed from each credential, key of the map is the credential index */ revealedAttributes: Map>; /** Arguments required to calculate the attribute bound pseudonyms to be presented */ boundedPseudonyms: BoundedPseudonym[]; /** Arguments required to calculate the pseudonyms to be presented */ unboundedPseudonyms: UnboundedPseudonym[]; /** Attributes proved equal in zero knowledge */ attributeEqualities: AttributeEquality[]; /** Attributes proved inequal to a public value in zero knowledge. An attribute can be proven inequal to any number of values The 2nd item, i.e. Uint8Array in the pair is the encoded value of the public value with which inequality is proved */ attributeInequalities: Map>; /** Each credential has only one accumulator for status */ credStatuses: Map; /** Bounds on attribute. The key of the map is the credential index and for the inner map is the attribute and value of map denotes min, max, an identifier of the setup parameters for the protocol and the protocol name. An attribute can have many bound checks. */ bounds: Map>; /** Verifiable encryption of attributes. The key of the map is the credential index and for the inner map is the attribute and value of map denotes the setup parameters for the protocol and the protocol name. An attribute can have many verifiable encryptions. */ verifEnc: Map>; /** Predicates expressed as Circom programs over attributes of a single credential. For each credential, store a public, private variables, circuit id (used to fetch R1CS, WASM bytes) and attributes used in circuit */ circomPredicates: Map; /** Predicates expressed as Circom programs over attributes of multiple credentials. */ circomPredicatesMultiCred: IProverCircomPredicateMultiCred[]; /** Parameters for predicates like snark proving key for bound check, verifiable encryption, Circom program */ predicateParams: Map; /** Blinded credential request. Stores `SignatureParams` as appropriately sized params are created by the request builder already so not creating it again */ blindCredReq?: { req: IBlindCredentialRequest; sigParams: SignatureParams; encodedAttributes: Map; attrNameToIndex: Map; flattenedSchema: FlattenedSchema; blinding?: Uint8Array; /** The 2nd item, i.e. Uint8Array in the pair is the encoded value of the public value with which inequality is proved */ attributeInequalities: Map; bounds: Map; verifEnc: Map; circPred: IProverCircomPredicate[]; pseudonyms: IProverBoundedPseudonymInBlindedCredReq[]; }; constructor(); /** * Add a credential to this presentation. This will result in a proof of possession of this credential being created * @param credential * @param pk - Only certain kinds of credentials need a public key for creating presentation */ addCredential(credential: Credential, pk?: PublicKey): number; /** * * @param credIdx * @param attributeNames - Nested attribute names using the "dot" separator */ markAttributesRevealed(credIdx: number, attributeNames: Set): void; /** * Enforce equality between attributes of the credential without revealing them. * @param equality - Array of reference to attribute where each reference is a pair with 1st item being credential index * and 2nd being attribute index in the flattened attribute list. */ enforceAttributeEquality(...equality: AttributeEquality): void; /** * Add accumulator value, witness and public key for proving credential status. * @param credIdx * @param accumWitness * @param accumulated * @param accumPublicKey * @param extra */ addAccumInfoForCredStatus(credIdx: number, accumWitness: AccumulatorWitnessType, accumulated: AccumulatorValueType, accumPublicKey?: AccumulatorPublicKey, extra?: object): void; /** * Enforce inequality with a public value on a credential attribute * @param credIdx * @param attributeName * @param inEqualTo - The public value that the attribute should be unequal to, i.e. value of attribute `attributeName` != `inEqualTo` * @param paramId - If absent, the default commitment key is used * @param param */ enforceAttributeInequality(credIdx: number, attributeName: string, inEqualTo: any, paramId?: string, param?: PederCommKey | PederCommKeyUncompressed): void; /** * Enforce bounds on given attribute from given credential index. The attribute value should lie in `[min, max)` * @param credIdx * @param attributeName - Nested attribute names use the "dot" separator * @param min * @param max * @param paramId - An identifier, unique in the context of this builder that identifies a param. If absent, transparent range proof (Bulletproofs++) is used * @param param - This is optional because if the param is already added in previous call to `enforceBounds`, * then it shouldn't be passed. This is done to avoid copying/passing large objects in memory. */ enforceBounds(credIdx: number, attributeName: string, min: BoundType, max: BoundType, paramId?: string, param?: BoundCheckParamType): void; /** * * @param credIdx * @param attributeName - Nested attribute names use the "dot" separator * @param chunkBitSize * @param commKeyId - An identifier, unique in the context of this builder that identifies a commitment key. * @param encryptionKeyId - An identifier, unique in the context of this builder that identifies an encryption key. * @param snarkPkId - An identifier, unique in the context of this builder that identifies a snark proving key. * @param commKey - This is optional because if the commitment key is already added in previous call to `verifiablyEncrypt`, * then it shouldn't be passed. This is done to avoid copying/passing large objects in memory. * @param encryptionKey - This is optional because if the encryption key is already added in previous call to `verifiablyEncrypt`, * then it shouldn't be passed. This is done to avoid copying/passing large objects in memory. * @param snarkPk - This is optional because if the snark proving key is already added in previous call to `verifiablyEncrypt`, * then it shouldn't be passed. This is done to avoid copying/passing large objects in memory. */ verifiablyEncrypt(credIdx: number, attributeName: string, chunkBitSize: number, commKeyId: string, encryptionKeyId: string, snarkPkId: string, commKey?: SaverChunkedCommitmentKey | SaverChunkedCommitmentKeyUncompressed, encryptionKey?: SaverEncryptionKey | SaverEncryptionKeyUncompressed, snarkPk?: SaverProvingKey | SaverProvingKeyUncompressed): void; /** * Enforce a predicate written as a Circom program over a credential's attributes * @param credIdx - The credential index whose attributes are used as witness in the Circom program * @param circuitPrivateVars - Mapping of private variables from Circom program to attribute names. A variable can be a single value * or an array and thus can correspond to a single attribute or array of attributes. Is an array of pairs where the first item of pair * is the private variable name and the second item is the attribute name(s) * @param circuitPublicVars - Mapping of public variables from Circom program to publicly known values. Is an array of pairs where the * first item of pair is the public variable name and the second item is the value as a bytearray or array of bytearrays * @param circuitId * @param provingKeyId * @param r1cs * @param wasmBytes * @param provingKey */ enforceCircomPredicate(credIdx: number, circuitPrivateVars: [string, string | string[]][], circuitPublicVars: [string, Uint8Array | Uint8Array[]][], circuitId: string, provingKeyId: string, r1cs?: R1CS | ParsedR1CSFile, wasmBytes?: Uint8Array, provingKey?: LegoProvingKey | LegoProvingKeyUncompressed): void; /** * Enforce a predicate written as a Circom program over a many credentials' attributes * @param circuitPrivateVars - Mapping of private variables from Circom program to pairs where each pair corresponds to a credential attribute. * The 1st item of the pair is the credential index and 2nd item is the attribute name in that credential * @param circuitPublicVars - Mapping of public variables from Circom program to its corresponding values * @param circuitId * @param provingKeyId * @param r1cs * @param wasmBytes * @param provingKey */ enforceCircomPredicateAcrossMultipleCredentials(circuitPrivateVars: [string, [number, string] | [number, string][]][], circuitPublicVars: [string, Uint8Array | Uint8Array[]][], circuitId: string, provingKeyId: string, r1cs?: R1CS | ParsedR1CSFile, wasmBytes?: Uint8Array, provingKey?: LegoProvingKey | LegoProvingKeyUncompressed): void; addBoundedPseudonym(basesForAttribute: Uint8Array[], attributeNames: Map, baseForSecretKey?: Uint8Array, secretKey?: Uint8Array): number; addUnboundedPseudonym(baseForSecretKey: Uint8Array, secretKey: Uint8Array): number; /** * Create a presentation */ finalize(): Presentation; get context(): string | undefined; set context(context: string | undefined); get nonce(): Uint8Array | undefined; set nonce(nonce: Uint8Array | undefined); validateCredIndex(credIdx: number): void; updatePredicateParams(id: string, val?: PredicateParamType): void; static r1csParamId(circuitId: string): string; static wasmParamId(circuitId: string): string; private static addLegoProvingKeyToTracker; private static addSmcKVProverParamsToTracker; private processAttributeInequalities; private processBoundChecks; private processVerifiableEncs; private processCircomPredicates; private formatAttributesForSpec; private formatAttributeCiphertexts; private encodeCircomAttrsAndFormatPredicatesForSpec; private createCircomStatement; static enforceAttributeInequalities(self: any, ineqs: Map, attributeName: string, inEqualTo: any, paramId?: string, param?: PederCommKey | PederCommKeyUncompressed): void; /** * Process bounds and the corresponding params when enforcing bound check on an attribute. * @param self - the object storing all the predicate params. Will be updates * @param boundsMap - The map of attribute name to bounds. Will be updated. * @param attributeName * @param vmin * @param vmax * @param paramId * @param param */ static processBounds(self: any, boundsMap: Map, attributeName: string, vmin: BoundType, vmax: BoundType, paramId?: string, param?: BoundCheckParamType): void; static processVerifiableEncs(self: any, verEncsMap: Map, attributeName: string, chunkBitSize: number, commKeyId: string, encryptionKeyId: string, snarkPkId: string, commKey?: SaverChunkedCommitmentKey | SaverChunkedCommitmentKeyUncompressed, encryptionKey?: SaverEncryptionKey | SaverEncryptionKeyUncompressed, snarkPk?: SaverProvingKey | SaverProvingKeyUncompressed): void; } export interface IProverCircomPredicate { privateVars: [string, string | string[]][]; publicVars: [string, Uint8Array | Uint8Array[]][]; circuitId: string; provingKeyId: string; } export interface IProverCircomPredicateMultiCred { privateVars: [string, [number, string] | [number, string][]][]; publicVars: [string, Uint8Array | Uint8Array[]][]; circuitId: string; provingKeyId: string; } export interface IProverBoundedPseudonymInBlindedCredReq { basesForAttributes: Uint8Array[]; baseForSecretKey?: Uint8Array; credentialAttributes: Map; blindedAttributes: string[]; secretKey?: Uint8Array; } export {}; //# sourceMappingURL=presentation-builder.d.ts.map