diff --git a/packages/snap/snap.manifest.json b/packages/snap/snap.manifest.json index de76887..7a2bed1 100644 --- a/packages/snap/snap.manifest.json +++ b/packages/snap/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/rarimo/rarime.git" }, "source": { - "shasum": "5sXjO21gbxwavfxcs5k4eSyqjf+NPm2blEqGomDaivA=", + "shasum": "dq6AjScyw50X2HFij7/NnQDeRqAjY2LcDAqjhuei7Jg=", "location": { "npm": { "filePath": "dist/bundle.js", diff --git a/packages/zkp-iden3/src/helpers/index.ts b/packages/zkp-iden3/src/helpers/index.ts index e07e8d8..5ee6a28 100644 --- a/packages/zkp-iden3/src/helpers/index.ts +++ b/packages/zkp-iden3/src/helpers/index.ts @@ -1,4 +1,3 @@ export * from './file-helpers'; export * from './identity-helpers'; -export * from './model-helpers'; export * from './proof-helpers'; diff --git a/packages/zkp-iden3/src/helpers/model-helpers.ts b/packages/zkp-iden3/src/helpers/model-helpers.ts deleted file mode 100644 index 5ffcbb3..0000000 --- a/packages/zkp-iden3/src/helpers/model-helpers.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { Proof } from '@iden3/js-merkletree'; - -import type { ProofType } from '@/enums'; -import type { CredentialStatus, State } from '@/types'; - -export class IssuerData { - id!: string; - - state!: State; - - authCoreClaim?: string; - - mtp?: Proof; - - credentialStatus?: CredentialStatus; - - updateUrl!: string; -} - -export class Iden3SparseMerkleTreeProof { - type!: ProofType; - - issuerData!: IssuerData; - - mtp!: Proof; - - coreClaim!: string; - - id!: string; -} - -export class BJJSignatureProof2021 { - type!: ProofType; - - issuerData!: IssuerData; - - signature!: string; - - coreClaim!: string; -} - -export class ValueProof { - path: bigint; - - value?: bigint; - - mtp: Proof; - - constructor() { - this.path = BigInt(0); - this.value = BigInt(0); - this.mtp = new Proof(); - } -} - -export class Query { - slotIndex!: number; - - values!: bigint[]; - - operator!: number; - - valueProof?: ValueProof; -} diff --git a/packages/zkp-iden3/src/helpers/proof-helpers.ts b/packages/zkp-iden3/src/helpers/proof-helpers.ts index a23bdc7..216690a 100644 --- a/packages/zkp-iden3/src/helpers/proof-helpers.ts +++ b/packages/zkp-iden3/src/helpers/proof-helpers.ts @@ -21,18 +21,19 @@ import get from 'lodash/get'; import { QueryOperators } from '@/const'; import { ProofType } from '@/enums'; import { parseDidV2 } from '@/helpers/identity-helpers'; -import { Query, ValueProof } from '@/helpers/model-helpers'; import type { + BJJSignatureProofRaw, CircuitClaim, GISTProof, + Iden3SparseMerkleTreeProofRaw, JSONSchema, - MTProof, NodeAuxValue, QueryWithFieldName, RevocationStatus, StateProof, TreeState, W3CCredential, + Query, } from '@/types'; const proofFromJson = (proofJson: ProofJSON) => { @@ -80,18 +81,24 @@ const parseRequest = async (req?: { [key: string]: unknown; }): Promise => { if (!req) { - const query = new Query(); + const query: Query = {} as Query; + query.operator = QueryOperators.$eq; + return { query, fieldName: '' }; } const entries = Object.entries(req); + if (entries.length > 1) { throw new TypeError(`multiple requests not supported`); } const [fieldName, fieldReq] = entries[0]; + // FIXME + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore const fieldReqEntries = Object.entries(fieldReq); if (fieldReqEntries.length > 1) { @@ -99,7 +106,8 @@ const parseRequest = async (req?: { } const isSelectiveDisclosure = fieldReqEntries.length === 0; - const query = new Query(); + + const query: Query = {} as Query; if (isSelectiveDisclosure) { return { query, fieldName, isSelectiveDisclosure }; @@ -118,6 +126,9 @@ const parseRequest = async (req?: { values[index] = BigInt(value[index]); } } else { + // FIXME + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore values[0] = BigInt(value); } @@ -244,7 +255,7 @@ export const newCircuitClaimData = async ( const smtProof = credential.proof?.find( (el) => el.type === ProofType.Iden3SparseMerkleTreeProof, - ); + ) as Iden3SparseMerkleTreeProofRaw; if (smtProof) { const revStatus = await getRevocationStatus( @@ -252,8 +263,6 @@ export const newCircuitClaimData = async ( convertEndianSwappedCoreStateHashHex(coreStateHash), ); - console.log('smtProof, data: ', revStatus); - circuitClaim = { ...circuitClaim, // incProof === smtProf @@ -271,7 +280,7 @@ export const newCircuitClaimData = async ( const sigProof = credential.proof?.find( (el) => el.type === ProofType.BJJSignature, - ); + ) as BJJSignatureProofRaw; if (sigProof) { const decodedSignature = Hex.decodeString(sigProof.signature); @@ -282,50 +291,10 @@ export const newCircuitClaimData = async ( convertEndianSwappedCoreStateHashHex(coreStateHash), ); - // console.log({ - // issuer: { - // claimsTreeRoot: - // '1a8fbdad9eaf8702e569bc5c1bd988baa14469982744f89a46543bc33043511f', - // revocationTreeRoot: - // 'eacc453b6b3d987e92e388666bebf5747ac918c22425fcc2c0207591c5d07822', - // rootOfRoots: - // '7c98f890aa1ab4fb52f7ab80cde62ce3e79bdc32dea4a97dd2b9717786a20f1b', - // state: - // '5ce0bdc7302eacde7da5db124f7ffce064479c7f59945b561b9f1984b308bd22', - // }, - // mtp: { - // existence: true, - // siblings: [ - // '12093648908151120008052400909983258657552456266206697304620000445575205299483', - // '21207046084208924821615313824986664896343424734449779018426019923028527893512', - // '2650766217307169652346299538052870810256415910274979821667202646242371010646', - // '3940160070763561296886138749041017192490236508112256863100410822822127805105', - // '1488336216580447661974529389680263071193229863568905848735299764005998493025', - // '11818731402331560172832129751709360787097755860909631916313928838796177663844', - // '8184543025293941192968566111354234433242540077051388134300485218432794255114', - // '0', - // '14185129435883483469188834471252788770088609928909097596128219973907887252238', - // '11618884846836233701534192031149078459646746176490461254607602387970783513937', - // ], - // }, - // }); - - console.log('issuerAuthClaimIncMtp', issuerAuthClaimIncMtp); - - const rs: RevocationStatus = await getRevocationStatus( + const revStatus: RevocationStatus = await getRevocationStatus( sigProof.issuerData.credentialStatus.id, ); - const issuerAuthNonRevProof: MTProof = { - treeState: buildTreeState( - rs.issuer.state!, - rs.issuer.claimsTreeRoot!, - rs.issuer.revocationTreeRoot!, - rs.issuer.rootOfRoots!, - ), - proof: rs.mtp, - }; - if (!sigProof.issuerData.mtp) { throw new TypeError('issuer auth credential must have a mtp proof'); } @@ -341,14 +310,22 @@ export const newCircuitClaimData = async ( signatureProof: { signature, issuerAuthClaim: new Claim().fromHex(sigProof.issuerData.authCoreClaim), - issuerAuthNonRevProof, + issuerAuthNonRevProof: { + proof: revStatus.mtp, + treeState: buildTreeState( + revStatus.issuer.state, + revStatus.issuer.claimsTreeRoot, + revStatus.issuer.revocationTreeRoot, + revStatus.issuer.rootOfRoots, + ), + }, issuerAuthIncProof: { proof: issuerAuthClaimIncMtp.mtp, treeState: buildTreeState( - issuerAuthClaimIncMtp.issuer.state!, - issuerAuthClaimIncMtp.issuer.claimsTreeRoot!, - issuerAuthClaimIncMtp.issuer.revocationTreeRoot!, - issuerAuthClaimIncMtp.issuer.rootOfRoots!, + issuerAuthClaimIncMtp.issuer.state, + issuerAuthClaimIncMtp.issuer.claimsTreeRoot, + issuerAuthClaimIncMtp.issuer.revocationTreeRoot, + issuerAuthClaimIncMtp.issuer.rootOfRoots, ), }, }, @@ -381,7 +358,9 @@ export const toCircuitsQuery = async ( ): Promise => { const prepareNonMerklizedQuery = async (): Promise => { const stringByPath = ( - obj: { [key: string]: unknown }, + // FIXME + // eslint-disable-next-line + obj: { [key: string]: any }, path: string, ): string => { const parts = path.split('.'); @@ -532,12 +511,13 @@ export const toCircuitsQuery = async ( const { proof, value: mtValue } = await mk.proof(path); const pathKey = await path.mtEntry(); - parsedQuery.query.valueProof = new ValueProof(); - parsedQuery.query.valueProof.mtp = proof; - parsedQuery.query.valueProof.path = pathKey; - parsedQuery.query.valueProof.mtp = proof; const mtEntry = await mtValue?.mtEntry(); - parsedQuery.query.valueProof.value = mtEntry; + + parsedQuery.query.valueProof = { + mtp: proof, + path: pathKey, + value: mtEntry, + }; // for merklized credentials slotIndex in query must be equal to zero // and not a position of merklization root. diff --git a/packages/zkp-iden3/src/instances/zkp-gen.ts b/packages/zkp-iden3/src/instances/zkp-gen.ts index c7cc133..9447082 100644 --- a/packages/zkp-iden3/src/instances/zkp-gen.ts +++ b/packages/zkp-iden3/src/instances/zkp-gen.ts @@ -15,7 +15,6 @@ import { defaultMTLevelsOnChain, defaultValueArraySize, } from '@/const'; -import { type Query } from '@/helpers'; import { buildTreeState, getFileBytes, @@ -34,6 +33,7 @@ import type { GISTProof, NodeAuxValue, W3CCredential, + Query, } from '@/types'; type Config = { @@ -131,6 +131,10 @@ export class ZkpGen { this.timestamp = Math.floor(Date.now() / 1000); + if (!this.circuitClaimData.signatureProof) { + throw new TypeError('circuitClaimData.signatureProof is not defined'); + } + this.nodeAuxIssuerAuthNonRev = getNodeAuxValue( this.circuitClaimData.signatureProof.issuerAuthNonRevProof.proof, ); @@ -220,6 +224,10 @@ export class ZkpGen { } generateQuerySigV2OnChainInputs() { + if (!this.circuitClaimData.signatureProof) { + throw new TypeError('circuitClaimData.signatureProof is not defined'); + } + return JSON.stringify({ /* we have no constraints for "requestID" in this circuit, it is used as a unique identifier for the request */ /* and verifier can use it to identify the request, and verify the proof of specific request in case of multiple query requests */ @@ -333,6 +341,10 @@ export class ZkpGen { } generateQuerySigV2Inputs() { + if (!this.circuitClaimData.signatureProof) { + throw new TypeError('circuitClaimData.signatureProof is not defined'); + } + return JSON.stringify({ /* we have no constraints for "requestID" in this circuit, it is used as a unique identifier for the request */ /* and verifier can use it to identify the request, and verify the proof of specific request in case of multiple query requests */ @@ -415,6 +427,10 @@ export class ZkpGen { } generateQueryMTPV2Inputs() { + if (!this.circuitClaimData.incProof) { + throw new TypeError('circuitClaimData.incProof is not defined'); + } + return JSON.stringify({ /* we have no constraints for "requestID" in this circuit, it is used as a unique identifier for the request */ /* and verifier can use it to identify the request, and verify the proof of specific request in case of multiple query requests */ @@ -481,6 +497,10 @@ export class ZkpGen { } generateQueryMTPV2OnChainInputs() { + if (!this.circuitClaimData.incProof) { + throw new TypeError('circuitClaimData.incProof is not defined'); + } + return JSON.stringify({ /* we have no constraints for "requestID" in this circuit, it is used as a unique identifier for the request */ /* and verifier can use it to identify the request, and verify the proof of specific request in case of multiple query requests */ diff --git a/packages/zkp-iden3/src/types/proof-types.ts b/packages/zkp-iden3/src/types/proof-types.ts index b611259..965a7e0 100644 --- a/packages/zkp-iden3/src/types/proof-types.ts +++ b/packages/zkp-iden3/src/types/proof-types.ts @@ -1,9 +1,8 @@ import type { Signature } from '@iden3/js-crypto'; import type { Claim, Id } from '@iden3/js-iden3-core'; -import type { Hash, Proof } from '@iden3/js-merkletree'; +import type { Proof, Hash } from '@iden3/js-merkletree'; import type { ProofType } from '@/enums'; -import type { Query } from '@/helpers'; export type CredentialStatus = { id: string; @@ -78,10 +77,10 @@ export type W3CCredential = { export type RevocationStatus = { mtp: Proof; issuer: { - state?: string; - rootOfRoots?: string; - claimsTreeRoot?: string; - revocationTreeRoot?: string; + state: string; + rootOfRoots: string; + claimsTreeRoot: string; + revocationTreeRoot: string; }; }; @@ -103,44 +102,28 @@ export type TreeState = { rootOfRoots: Hash; }; +// FIXME: used for nonRevProof, but names not appropriate export type ClaimNonRevStatus = { treeState: TreeState; proof: Proof; }; -export type MTProof = { - proof: Proof; - treeState?: TreeState; -}; - -// TODO: mb remove -export type BJJSignatureProof = { - signature: Signature; - issuerAuthClaim?: Claim; - issuerAuthIncProof: MTProof; - issuerAuthNonRevProof: MTProof; -}; - export type QueryWithFieldName = { query: Query; fieldName: string; isSelectiveDisclosure?: boolean; }; -export type SerializationSchema = { - indexDataSlotA: string; - indexDataSlotB: string; - valueDataSlotA: string; - valueDataSlotB: string; -}; - -export type SchemaMetadata = { - uris: { [key: string]: string }; - serialization?: SerializationSchema; -}; - export type JSONSchema = { - $metadata: SchemaMetadata; + $metadata: { + uris: { [key: string]: string }; + serialization?: { + indexDataSlotA: string; + indexDataSlotB: string; + valueDataSlotA: string; + valueDataSlotB: string; + }; + }; $schema: string; type: string; }; @@ -167,14 +150,34 @@ export type GISTProof = { proof: Proof; }; -// refactored models - export type CircuitClaim = { issuerId: Id; claim: Claim; - signatureProof?: BJJSignatureProof; + signatureProof?: { + signature: Signature; + issuerAuthClaim?: Claim; + issuerAuthIncProof: { + proof: Proof; + treeState?: TreeState; + }; + issuerAuthNonRevProof: { + proof: Proof; + treeState?: TreeState; + }; + }; incProof?: { proof: Proof; treeState: TreeState; }; }; + +export type Query = { + slotIndex: number; + values: bigint[]; + operator: number; + valueProof?: { + path: bigint; + value?: bigint; + mtp: Proof; + }; +};