diff --git a/src/circuits/atomic-query-mtp-v2-on-chain.ts b/src/circuits/atomic-query-mtp-v2-on-chain.ts index 50e90e55..e3a1a26e 100644 --- a/src/circuits/atomic-query-mtp-v2-on-chain.ts +++ b/src/circuits/atomic-query-mtp-v2-on-chain.ts @@ -23,28 +23,28 @@ import { byteDecoder, byteEncoder } from '../utils'; */ export class AtomicQueryMTPV2OnChainInputs extends BaseConfig { // auth - id?: Id; - profileNonce?: bigint; - claimSubjectProfileNonce?: bigint; + id!: Id; + profileNonce!: bigint; + claimSubjectProfileNonce!: bigint; // claim issued for user - claim?: ClaimWithMTPProof; - skipClaimRevocationCheck?: boolean; - requestID?: bigint; + claim!: ClaimWithMTPProof; + skipClaimRevocationCheck!: boolean; + requestID!: bigint; - currentTimeStamp?: number; + currentTimeStamp!: number; - authClaim?: Claim; - authClaimIncMtp?: Proof; - authClaimNonRevMtp?: Proof; - treeState?: TreeState; + authClaim!: Claim; + authClaimIncMtp!: Proof; + authClaimNonRevMtp!: Proof; + treeState!: TreeState; - gistProof?: GISTProof; + gistProof!: GISTProof; - signature?: Signature; - challenge?: bigint; + signature!: Signature; + challenge!: bigint; // query - query?: Query; + query!: Query; /** * Validate inputs @@ -60,7 +60,7 @@ export class AtomicQueryMTPV2OnChainInputs extends BaseConfig { if (!this.authClaimNonRevMtp) { throw new Error(CircuitError.EmptyAuthClaimNonRevProof); } - if (!this.gistProof?.proof) { + if (!this.gistProof.proof) { throw new Error(CircuitError.EmptyGISTProof); } if (!this.signature) { @@ -78,68 +78,63 @@ export class AtomicQueryMTPV2OnChainInputs extends BaseConfig { */ inputsMarshal(): Uint8Array { this.validate(); - if (this.query?.valueProof) { + if (this.query.valueProof) { this.query.validate(); this.query.valueProof.validate(); } - const valueProof = this.query?.valueProof ?? new ValueProof(); + const valueProof = this.query.valueProof ?? new ValueProof(); const s: Partial = { - requestID: this.requestID?.toString(), - userGenesisID: this.id?.bigInt().toString(), - profileNonce: this.profileNonce?.toString(), + requestID: this.requestID.toString(), + userGenesisID: this.id.bigInt().toString(), + profileNonce: this.profileNonce.toString(), claimSubjectProfileNonce: this.claimSubjectProfileNonce?.toString(), - issuerID: this.claim?.issuerID?.bigInt().toString(), - issuerClaim: this.claim?.claim?.marshalJson(), - issuerClaimMtp: this.claim?.incProof?.proof - ? prepareSiblingsStr(this.claim.incProof.proof, this.getMTLevel()) - : undefined, - issuerClaimClaimsTreeRoot: this.claim?.incProof?.treeState?.claimsRoot?.string(), - issuerClaimRevTreeRoot: this.claim?.incProof?.treeState?.revocationRoot?.string(), - issuerClaimRootsTreeRoot: this.claim?.incProof?.treeState?.rootOfRoots?.string(), - issuerClaimIdenState: this.claim?.incProof?.treeState?.state?.string(), - issuerClaimNonRevMtp: this.claim?.nonRevProof?.proof - ? prepareSiblingsStr(this.claim.nonRevProof?.proof, this.getMTLevel()) - : undefined, - issuerClaimNonRevClaimsTreeRoot: this.claim?.nonRevProof?.treeState?.claimsRoot?.string(), - issuerClaimNonRevRevTreeRoot: this.claim?.nonRevProof?.treeState?.revocationRoot?.string(), - issuerClaimNonRevRootsTreeRoot: this.claim?.nonRevProof?.treeState?.rootOfRoots?.string(), - issuerClaimNonRevState: this.claim?.nonRevProof?.treeState?.state?.string(), - claimSchema: this.claim?.claim?.getSchemaHash().bigInt().toString(), + issuerID: this.claim.issuerID?.bigInt().toString(), + issuerClaim: this.claim.claim?.marshalJson(), + issuerClaimMtp: + this.claim.incProof?.proof && + prepareSiblingsStr(this.claim.incProof.proof, this.getMTLevel()), + issuerClaimClaimsTreeRoot: this.claim.incProof?.treeState?.claimsRoot?.string(), + issuerClaimRevTreeRoot: this.claim.incProof?.treeState?.revocationRoot?.string(), + issuerClaimRootsTreeRoot: this.claim.incProof?.treeState?.rootOfRoots?.string(), + issuerClaimIdenState: this.claim.incProof?.treeState?.state?.string(), + issuerClaimNonRevMtp: + this.claim.nonRevProof?.proof && + prepareSiblingsStr(this.claim.nonRevProof?.proof, this.getMTLevel()), + issuerClaimNonRevClaimsTreeRoot: this.claim.nonRevProof?.treeState?.claimsRoot?.string(), + issuerClaimNonRevRevTreeRoot: this.claim.nonRevProof?.treeState?.revocationRoot?.string(), + issuerClaimNonRevRootsTreeRoot: this.claim.nonRevProof?.treeState?.rootOfRoots?.string(), + issuerClaimNonRevState: this.claim.nonRevProof?.treeState?.state?.string(), + claimSchema: this.claim.claim?.getSchemaHash().bigInt().toString(), claimPathMtp: prepareSiblingsStr(valueProof.mtp, this.getMTLevelsClaimMerklization()), claimPathValue: valueProof.value.toString(), - operator: this.query?.operator, - slotIndex: this.query?.slotIndex, + operator: this.query.operator, + slotIndex: this.query.slotIndex, timestamp: this.currentTimeStamp ?? undefined, isRevocationChecked: 1, - authClaim: this.authClaim?.marshalJson(), - authClaimIncMtp: this.authClaimIncMtp - ? prepareSiblingsStr(this.authClaimIncMtp, this.getMTLevel()) - : undefined, - authClaimNonRevMtp: this.authClaimNonRevMtp - ? prepareSiblingsStr(this.authClaimNonRevMtp, this.getMTLevel()) - : undefined, - challenge: this.challenge?.toString(), - challengeSignatureR8x: this.signature?.R8[0].toString(), - challengeSignatureR8y: this.signature?.R8[1].toString(), - challengeSignatureS: this.signature?.S.toString(), - userClaimsTreeRoot: this.treeState?.claimsRoot?.string(), - userRevTreeRoot: this.treeState?.revocationRoot?.string(), - userRootsTreeRoot: this.treeState?.rootOfRoots?.string(), - userState: this.treeState?.state?.string(), - gistRoot: this.gistProof?.root?.string(), - gistMtp: this.gistProof - ? prepareSiblingsStr(this.gistProof.proof, this.getMTLevelOnChain()) - : undefined + authClaim: this.authClaim.marshalJson(), + authClaimIncMtp: + this.authClaimIncMtp && prepareSiblingsStr(this.authClaimIncMtp, this.getMTLevel()), + authClaimNonRevMtp: + this.authClaimNonRevMtp && prepareSiblingsStr(this.authClaimNonRevMtp, this.getMTLevel()), + challenge: this.challenge.toString(), + challengeSignatureR8x: this.signature.R8[0].toString(), + challengeSignatureR8y: this.signature.R8[1].toString(), + challengeSignatureS: this.signature.S.toString(), + userClaimsTreeRoot: this.treeState.claimsRoot?.string(), + userRevTreeRoot: this.treeState.revocationRoot?.string(), + userRootsTreeRoot: this.treeState.rootOfRoots?.string(), + userState: this.treeState.state?.string(), + gistRoot: this.gistProof.root?.string(), + gistMtp: this.gistProof && prepareSiblingsStr(this.gistProof.proof, this.getMTLevelOnChain()) }; if (this.skipClaimRevocationCheck) { s.isRevocationChecked = 0; } - const nodeAuxNonRev = this.claim?.nonRevProof?.proof - ? getNodeAuxValue(this.claim.nonRevProof.proof) - : undefined; + const nodeAuxNonRev = + this.claim.nonRevProof?.proof && getNodeAuxValue(this.claim.nonRevProof.proof); s.issuerClaimNonRevMtpAuxHi = nodeAuxNonRev?.key.bigInt().toString(); s.issuerClaimNonRevMtpAuxHv = nodeAuxNonRev?.value.bigInt().toString(); s.issuerClaimNonRevMtpNoAux = nodeAuxNonRev?.noAux; @@ -151,22 +146,19 @@ export class AtomicQueryMTPV2OnChainInputs extends BaseConfig { s.claimPathMtpAuxHv = nodAuxJSONLD.value.bigInt().toString(); s.claimPathKey = valueProof.path.toString(); - const values = this.query?.values - ? prepareCircuitArrayValues(this.query.values, this.getValueArrSize()) - : undefined; - s.value = values ? bigIntArrayToStringArray(values) : undefined; - - const nodeAuxAuth = this.authClaimNonRevMtp - ? getNodeAuxValue(this.authClaimNonRevMtp) - : undefined; - s.authClaimNonRevMtpAuxHi = nodeAuxAuth?.key.string(); - s.authClaimNonRevMtpAuxHv = nodeAuxAuth?.value.string(); - s.authClaimNonRevMtpNoAux = nodeAuxAuth?.noAux; - - const globalNodeAux = this.gistProof ? getNodeAuxValue(this.gistProof.proof) : undefined; - s.gistMtpAuxHi = globalNodeAux?.key.string(); - s.gistMtpAuxHv = globalNodeAux?.value.string(); - s.gistMtpNoAux = globalNodeAux?.noAux; + const values = + this.query.values && prepareCircuitArrayValues(this.query.values, this.getValueArrSize()); + s.value = values && bigIntArrayToStringArray(values); + + const nodeAuxAuth = this.authClaimNonRevMtp && getNodeAuxValue(this.authClaimNonRevMtp); + s.authClaimNonRevMtpAuxHi = nodeAuxAuth.key.string(); + s.authClaimNonRevMtpAuxHv = nodeAuxAuth.value.string(); + s.authClaimNonRevMtpNoAux = nodeAuxAuth.noAux; + + const globalNodeAux = this.gistProof && getNodeAuxValue(this.gistProof.proof); + s.gistMtpAuxHi = globalNodeAux.key.string(); + s.gistMtpAuxHv = globalNodeAux.value.string(); + s.gistMtpNoAux = globalNodeAux.noAux; return byteEncoder.encode(JSON.stringify(s)); } @@ -179,7 +171,7 @@ interface atomicQueryMTPV2OnChainCircuitInputs { profileNonce: string; claimSubjectProfileNonce: string; issuerID: string; - issuerClaim?: string[]; + issuerClaim: string[]; issuerClaimMtp: string[]; issuerClaimClaimsTreeRoot: string; @@ -204,8 +196,8 @@ interface atomicQueryMTPV2OnChainCircuitInputs { claimPathMtp: string[]; claimPathMtpNoAux: string; // 1 if aux node is empty, // 0 if non-empty or for inclusion proofs - claimPathMtpAuxHi?: string; // 0 for inclusion proof - claimPathMtpAuxHv?: string; // 0 for inclusion proof + claimPathMtpAuxHi: string; // 0 for inclusion proof + claimPathMtpAuxHv: string; // 0 for inclusion proof claimPathKey: string; // hash of path in merklized json-ld document claimPathValue: string; // value in this path in merklized json-ld document @@ -252,17 +244,17 @@ interface atomicQueryMTPV2OnChainCircuitInputs { * @extends {BaseConfig} */ export class AtomicQueryMTPV2OnChainPubSignals extends BaseConfig { - requestID?: bigint; - userID?: Id; - issuerID?: Id; - issuerClaimIdenState?: Hash; - issuerClaimNonRevState?: Hash; - timestamp?: number; - merklized?: number; - isRevocationChecked?: number; // 0 revocation not check, // 1 for check revocation - circuitQueryHash?: bigint; - challenge?: bigint; - gistRoot?: Hash; + requestID!: bigint; + userID!: Id; + issuerID!: Id; + issuerClaimIdenState!: Hash; + issuerClaimNonRevState!: Hash; + timestamp!: number; + merklized!: number; + isRevocationChecked!: number; // 0 revocation not check, // 1 for check revocation + circuitQueryHash!: bigint; + challenge!: bigint; + gistRoot!: Hash; /** * diff --git a/src/circuits/atomic-query-mtp-v2.ts b/src/circuits/atomic-query-mtp-v2.ts index 5a18aa0e..7574c5ef 100644 --- a/src/circuits/atomic-query-mtp-v2.ts +++ b/src/circuits/atomic-query-mtp-v2.ts @@ -22,18 +22,18 @@ import { byteDecoder, byteEncoder } from '../utils'; */ export class AtomicQueryMTPV2Inputs extends BaseConfig { // auth - id?: Id; - profileNonce?: bigint; - claimSubjectProfileNonce?: bigint; + id!: Id; + profileNonce!: bigint; + claimSubjectProfileNonce!: bigint; // claim issued for user - claim?: ClaimWithMTPProof; - skipClaimRevocationCheck?: boolean; - requestID?: bigint; + claim!: ClaimWithMTPProof; + skipClaimRevocationCheck!: boolean; + requestID!: bigint; - currentTimeStamp?: number; + currentTimeStamp!: number; // query - query?: Query; + query!: Query; /** * Validate AtomicQueryMTPV2 inputs @@ -52,49 +52,49 @@ export class AtomicQueryMTPV2Inputs extends BaseConfig { */ inputsMarshal(): Uint8Array { this.validate(); - if (this.query?.valueProof) { + if (this.query.valueProof) { this.query.validate(); this.query.valueProof.validate(); } - const valueProof = this.query?.valueProof ?? new ValueProof(); + const valueProof = this.query.valueProof ?? new ValueProof(); const s: Partial = { - requestID: this.requestID?.toString(), - userGenesisID: this.id?.bigInt().toString(), + requestID: this.requestID.toString(), + userGenesisID: this.id.bigInt().toString(), profileNonce: this.profileNonce?.toString(), claimSubjectProfileNonce: this.claimSubjectProfileNonce?.toString(), - issuerID: this.claim?.issuerID?.bigInt().toString(), - issuerClaim: this.claim?.claim?.marshalJson(), - issuerClaimMtp: this.claim?.incProof?.proof - ? prepareSiblingsStr(this.claim.incProof.proof, this.getMTLevel()) - : undefined, - issuerClaimClaimsTreeRoot: this.claim?.incProof?.treeState?.claimsRoot?.bigInt().toString(), - issuerClaimRevTreeRoot: this.claim?.incProof?.treeState?.revocationRoot?.bigInt().toString(), - issuerClaimRootsTreeRoot: this.claim?.incProof?.treeState?.rootOfRoots?.bigInt().toString(), - issuerClaimIdenState: this.claim?.incProof?.treeState?.state?.bigInt().toString(), - issuerClaimNonRevMtp: this.claim?.nonRevProof?.proof - ? prepareSiblingsStr(this.claim.nonRevProof.proof, this.getMTLevel()) - : undefined, - issuerClaimNonRevClaimsTreeRoot: this.claim?.nonRevProof?.treeState?.claimsRoot + issuerID: this.claim.issuerID?.bigInt().toString(), + issuerClaim: this.claim.claim?.marshalJson(), + issuerClaimMtp: + this.claim.incProof?.proof && + prepareSiblingsStr(this.claim.incProof.proof, this.getMTLevel()), + issuerClaimClaimsTreeRoot: this.claim.incProof?.treeState?.claimsRoot?.bigInt().toString(), + issuerClaimRevTreeRoot: this.claim.incProof?.treeState?.revocationRoot?.bigInt().toString(), + issuerClaimRootsTreeRoot: this.claim.incProof?.treeState?.rootOfRoots?.bigInt().toString(), + issuerClaimIdenState: this.claim.incProof?.treeState?.state?.bigInt().toString(), + issuerClaimNonRevMtp: + this.claim.nonRevProof?.proof && + prepareSiblingsStr(this.claim.nonRevProof.proof, this.getMTLevel()), + issuerClaimNonRevClaimsTreeRoot: this.claim.nonRevProof?.treeState?.claimsRoot ?.bigInt() .toString(), - issuerClaimNonRevRevTreeRoot: this.claim?.nonRevProof?.treeState?.revocationRoot + issuerClaimNonRevRevTreeRoot: this.claim.nonRevProof?.treeState?.revocationRoot ?.bigInt() .toString(), - issuerClaimNonRevRootsTreeRoot: this.claim?.nonRevProof?.treeState?.rootOfRoots + issuerClaimNonRevRootsTreeRoot: this.claim.nonRevProof?.treeState?.rootOfRoots ?.bigInt() .toString(), - issuerClaimNonRevState: this.claim?.nonRevProof?.treeState?.state?.bigInt().toString(), - claimSchema: this.claim?.claim?.getSchemaHash().bigInt().toString(), + issuerClaimNonRevState: this.claim.nonRevProof?.treeState?.state?.bigInt().toString(), + claimSchema: this.claim.claim?.getSchemaHash().bigInt().toString(), claimPathMtp: prepareSiblingsStr(valueProof.mtp, this.getMTLevelsClaimMerklization()), claimPathValue: valueProof.value.toString(), - operator: this.query?.operator, - slotIndex: this.query?.slotIndex, - timestamp: this.currentTimeStamp ?? undefined + operator: this.query.operator, + slotIndex: this.query.slotIndex, + timestamp: this.currentTimeStamp }; - const nodeAux = this.claim ? getNodeAuxValue(this.claim.nonRevProof?.proof) : undefined; + const nodeAux = getNodeAuxValue(this.claim.nonRevProof?.proof); s.issuerClaimNonRevMtpAuxHi = nodeAux?.key.bigInt().toString(); s.issuerClaimNonRevMtpAuxHv = nodeAux?.value.bigInt().toString(); s.issuerClaimNonRevMtpNoAux = nodeAux?.noAux; @@ -113,11 +113,10 @@ export class AtomicQueryMTPV2Inputs extends BaseConfig { s.isRevocationChecked = 1; } - const values = this.query?.values - ? prepareCircuitArrayValues(this.query.values, this.getValueArrSize()) - : undefined; + const values = + this.query.values && prepareCircuitArrayValues(this.query.values, this.getValueArrSize()); - s.value = values ? bigIntArrayToStringArray(values) : undefined; + s.value = bigIntArrayToStringArray(values); return byteEncoder.encode(JSON.stringify(s)); } diff --git a/src/circuits/atomic-query-sig-v2-on-chain.ts b/src/circuits/atomic-query-sig-v2-on-chain.ts index ad555f02..4e9111cd 100644 --- a/src/circuits/atomic-query-sig-v2-on-chain.ts +++ b/src/circuits/atomic-query-sig-v2-on-chain.ts @@ -22,31 +22,31 @@ import { byteDecoder, byteEncoder } from '../utils'; * @extends {BaseConfig} */ export class AtomicQuerySigV2OnChainInputs extends BaseConfig { - requestID?: bigint; + requestID!: bigint; // auth - id?: Id; - profileNonce?: bigint; - claimSubjectProfileNonce?: bigint; + id!: Id; + profileNonce!: bigint; + claimSubjectProfileNonce!: bigint; // claim issued for user - claim?: ClaimWithSigProof; - skipClaimRevocationCheck?: boolean; + claim!: ClaimWithSigProof; + skipClaimRevocationCheck!: boolean; - authClaim?: Claim; + authClaim!: Claim; - authClaimIncMtp?: Proof; - authClaimNonRevMtp?: Proof; - treeState?: TreeState; + authClaimIncMtp!: Proof; + authClaimNonRevMtp!: Proof; + treeState!: TreeState; - gistProof?: GISTProof; + gistProof!: GISTProof; - signature?: Signature; - challenge?: bigint; + signature!: Signature; + challenge!: bigint; // query - query?: Query; + query!: Query; - currentTimeStamp?: number; + currentTimeStamp!: number; /** * Validate inputs @@ -57,7 +57,7 @@ export class AtomicQuerySigV2OnChainInputs extends BaseConfig { if (!this.requestID) { throw new Error(CircuitError.EmptyRequestID); } - if (!this.claim?.nonRevProof?.proof) { + if (!this.claim.nonRevProof?.proof) { throw new Error(CircuitError.EmptyClaimNonRevProof); } @@ -85,7 +85,7 @@ export class AtomicQuerySigV2OnChainInputs extends BaseConfig { throw new Error(CircuitError.EmptyAuthClaimNonRevProof); } - if (!this.gistProof?.proof) { + if (!this.gistProof.proof) { throw new Error(CircuitError.EmptyGISTProof); } @@ -114,90 +114,87 @@ export class AtomicQuerySigV2OnChainInputs extends BaseConfig { const valueProof = this.query?.valueProof ?? new ValueProof(); const s: Partial = { - requestID: this.requestID?.toString(), - userGenesisID: this.id?.bigInt().toString(), - profileNonce: this.profileNonce?.toString(), + requestID: this.requestID.toString(), + userGenesisID: this.id.bigInt().toString(), + profileNonce: this.profileNonce.toString(), claimSubjectProfileNonce: this.claimSubjectProfileNonce?.toString(), - issuerID: this.claim?.issuerID?.bigInt().toString(), - issuerClaim: this.claim?.claim?.marshalJson(), - issuerClaimNonRevClaimsTreeRoot: this.claim?.nonRevProof?.treeState?.claimsRoot + issuerID: this.claim.issuerID?.bigInt().toString(), + issuerClaim: this.claim.claim?.marshalJson(), + issuerClaimNonRevClaimsTreeRoot: this.claim.nonRevProof?.treeState?.claimsRoot ?.bigInt() .toString(), - issuerClaimNonRevRevTreeRoot: this.claim?.nonRevProof?.treeState?.revocationRoot + issuerClaimNonRevRevTreeRoot: this.claim.nonRevProof?.treeState?.revocationRoot ?.bigInt() .toString(), - issuerClaimNonRevRootsTreeRoot: this.claim?.nonRevProof?.treeState?.rootOfRoots + issuerClaimNonRevRootsTreeRoot: this.claim.nonRevProof?.treeState?.rootOfRoots + ?.bigInt() + .toString(), + issuerClaimNonRevState: this.claim.nonRevProof?.treeState?.state?.bigInt().toString(), + issuerClaimNonRevMtp: + this.claim.nonRevProof?.proof && + prepareSiblingsStr(this.claim.nonRevProof.proof, this.getMTLevel()), + + issuerClaimSignatureR8x: + this.claim.signatureProof && this.claim.signatureProof.signature.R8[0].toString(), + issuerClaimSignatureR8y: this.claim.signatureProof?.signature.R8[1].toString(), + issuerClaimSignatureS: this.claim.signatureProof?.signature.S.toString(), + issuerAuthClaim: this.claim.signatureProof?.issuerAuthClaim?.marshalJson(), + issuerAuthClaimMtp: + this.claim.signatureProof?.issuerAuthIncProof?.proof && + prepareSiblingsStr(this.claim.signatureProof.issuerAuthIncProof.proof, this.getMTLevel()), + issuerAuthClaimsTreeRoot: this.claim.signatureProof?.issuerAuthIncProof?.treeState?.claimsRoot ?.bigInt() .toString(), - issuerClaimNonRevState: this.claim?.nonRevProof?.treeState?.state?.bigInt().toString(), - issuerClaimNonRevMtp: this.claim?.nonRevProof?.proof - ? prepareSiblingsStr(this.claim.nonRevProof.proof, this.getMTLevel()) - : undefined, - issuerClaimSignatureR8x: this.claim?.signatureProof - ? this.claim.signatureProof.signature.R8[0].toString() - : undefined, - issuerClaimSignatureR8y: this.claim?.signatureProof?.signature.R8[1].toString(), - issuerClaimSignatureS: this.claim?.signatureProof?.signature.S.toString(), - issuerAuthClaim: this.claim?.signatureProof?.issuerAuthClaim?.marshalJson(), - issuerAuthClaimMtp: this.claim?.signatureProof?.issuerAuthIncProof?.proof - ? prepareSiblingsStr(this.claim.signatureProof.issuerAuthIncProof.proof, this.getMTLevel()) - : undefined, - issuerAuthClaimsTreeRoot: - this.claim?.signatureProof?.issuerAuthIncProof?.treeState?.claimsRoot?.bigInt().toString(), issuerAuthRevTreeRoot: - this.claim?.signatureProof?.issuerAuthIncProof?.treeState?.revocationRoot + this.claim.signatureProof?.issuerAuthIncProof?.treeState?.revocationRoot ?.bigInt() .toString(), - issuerAuthRootsTreeRoot: - this.claim?.signatureProof?.issuerAuthIncProof?.treeState?.rootOfRoots?.bigInt().toString(), - - issuerAuthClaimNonRevMtp: this.claim?.signatureProof?.issuerAuthNonRevProof?.proof - ? prepareSiblingsStr( - this.claim.signatureProof.issuerAuthNonRevProof.proof, - this.getMTLevel() - ) - : undefined, + issuerAuthRootsTreeRoot: this.claim.signatureProof?.issuerAuthIncProof?.treeState?.rootOfRoots + ?.bigInt() + .toString(), - claimSchema: this.claim?.claim?.getSchemaHash().bigInt().toString(), + issuerAuthClaimNonRevMtp: + this.claim.signatureProof?.issuerAuthNonRevProof?.proof && + prepareSiblingsStr( + this.claim.signatureProof.issuerAuthNonRevProof.proof, + this.getMTLevel() + ), + claimSchema: this.claim.claim?.getSchemaHash().bigInt().toString(), claimPathMtp: prepareSiblingsStr(valueProof.mtp, this.getMTLevelsClaimMerklization()), claimPathValue: valueProof.value.toString(), operator: this.query?.operator, - timestamp: this.currentTimeStamp ? this.currentTimeStamp : undefined, + timestamp: this.currentTimeStamp, // value in this path in merklized json-ld document slotIndex: this.query?.slotIndex, isRevocationChecked: 1, - authClaim: this.authClaim?.marshalJson(), - authClaimIncMtp: this.authClaimIncMtp - ? prepareSiblingsStr(this.authClaimIncMtp, this.getMTLevel()) - : undefined, - authClaimNonRevMtp: this.authClaimNonRevMtp - ? prepareSiblingsStr(this.authClaimNonRevMtp, this.getMTLevel()) - : undefined, + authClaim: this.authClaim.marshalJson(), + authClaimIncMtp: + this.authClaimIncMtp && prepareSiblingsStr(this.authClaimIncMtp, this.getMTLevel()), + authClaimNonRevMtp: + this.authClaimNonRevMtp && prepareSiblingsStr(this.authClaimNonRevMtp, this.getMTLevel()), challenge: this.challenge?.toString(), - challengeSignatureR8x: this.signature?.R8[0].toString(), - challengeSignatureR8y: this.signature?.R8[1].toString(), - challengeSignatureS: this.signature?.S.toString(), - userClaimsTreeRoot: this.treeState?.claimsRoot?.string(), - userRevTreeRoot: this.treeState?.revocationRoot?.string(), - userRootsTreeRoot: this.treeState?.rootOfRoots?.string(), - userState: this.treeState?.state?.string(), - gistRoot: this.gistProof?.root.string(), - gistMtp: this.gistProof - ? prepareSiblingsStr(this.gistProof.proof, this.getMTLevelOnChain()) - : undefined + challengeSignatureR8x: this.signature.R8[0].toString(), + challengeSignatureR8y: this.signature.R8[1].toString(), + challengeSignatureS: this.signature.S.toString(), + userClaimsTreeRoot: this.treeState.claimsRoot?.string(), + userRevTreeRoot: this.treeState.revocationRoot?.string(), + userRootsTreeRoot: this.treeState.rootOfRoots?.string(), + userState: this.treeState.state?.string(), + gistRoot: this.gistProof.root.string(), + gistMtp: this.gistProof && prepareSiblingsStr(this.gistProof.proof, this.getMTLevelOnChain()) }; if (this.skipClaimRevocationCheck) { s.isRevocationChecked = 0; } - const nodeAuxNonRev = this.claim ? getNodeAuxValue(this.claim.nonRevProof?.proof) : undefined; + const nodeAuxNonRev = getNodeAuxValue(this.claim.nonRevProof?.proof); s.issuerClaimNonRevMtpAuxHi = nodeAuxNonRev?.key.bigInt().toString(); s.issuerClaimNonRevMtpAuxHv = nodeAuxNonRev?.value.bigInt().toString(); s.issuerClaimNonRevMtpNoAux = nodeAuxNonRev?.noAux; - const nodeAuxIssuerAuthNonRev = this.claim - ? getNodeAuxValue(this.claim.signatureProof?.issuerAuthNonRevProof.proof) - : undefined; + const nodeAuxIssuerAuthNonRev = getNodeAuxValue( + this.claim.signatureProof?.issuerAuthNonRevProof.proof + ); s.issuerAuthClaimNonRevMtpAuxHi = nodeAuxIssuerAuthNonRev?.key.bigInt().toString(); s.issuerAuthClaimNonRevMtpAuxHv = nodeAuxIssuerAuthNonRev?.value.bigInt().toString(); s.issuerAuthClaimNonRevMtpNoAux = nodeAuxIssuerAuthNonRev?.noAux; @@ -209,22 +206,18 @@ export class AtomicQuerySigV2OnChainInputs extends BaseConfig { s.claimPathMtpAuxHv = nodAuxJSONLD.value.bigInt().toString(); s.claimPathKey = valueProof.path.toString(); - const values = this.query?.values - ? prepareCircuitArrayValues(this.query.values, this.getValueArrSize()) - : undefined; - s.value = values ? bigIntArrayToStringArray(values) : undefined; - - const nodeAuxAuth = this.authClaimNonRevMtp - ? getNodeAuxValue(this.authClaimNonRevMtp) - : undefined; - s.authClaimNonRevMtpAuxHi = nodeAuxAuth?.key.string(); - s.authClaimNonRevMtpAuxHv = nodeAuxAuth?.value.string(); - s.authClaimNonRevMtpNoAux = nodeAuxAuth?.noAux; - - const globalNodeAux = this.gistProof ? getNodeAuxValue(this.gistProof.proof) : undefined; - s.gistMtpAuxHi = globalNodeAux?.key.string(); - s.gistMtpAuxHv = globalNodeAux?.value.string(); - s.gistMtpNoAux = globalNodeAux?.noAux; + const values = prepareCircuitArrayValues(this.query.values, this.getValueArrSize()); + s.value = bigIntArrayToStringArray(values); + + const nodeAuxAuth = getNodeAuxValue(this.authClaimNonRevMtp); + s.authClaimNonRevMtpAuxHi = nodeAuxAuth.key.string(); + s.authClaimNonRevMtpAuxHv = nodeAuxAuth.value.string(); + s.authClaimNonRevMtpNoAux = nodeAuxAuth.noAux; + + const globalNodeAux = getNodeAuxValue(this.gistProof.proof); + s.gistMtpAuxHi = globalNodeAux.key.string(); + s.gistMtpAuxHv = globalNodeAux.value.string(); + s.gistMtpNoAux = globalNodeAux.noAux; return byteEncoder.encode(JSON.stringify(s)); } @@ -238,81 +231,81 @@ export class AtomicQuerySigV2OnChainInputs extends BaseConfig { * @class AtomicQuerySigV2OnChainCircuitInputs */ export class AtomicQuerySigV2OnChainCircuitInputs { - requestID?: string; + requestID!: string; // user data - userGenesisID?: string; - profileNonce?: string; - claimSubjectProfileNonce?: string; + userGenesisID!: string; + profileNonce!: string; + claimSubjectProfileNonce!: string; - issuerID?: string; + issuerID!: string; // Claim - issuerClaim?: string[]; - issuerClaimNonRevClaimsTreeRoot?: string; - issuerClaimNonRevRevTreeRoot?: string; - issuerClaimNonRevRootsTreeRoot?: string; - issuerClaimNonRevState?: string; - issuerClaimNonRevMtp?: string[]; - issuerClaimNonRevMtpAuxHi?: string; - issuerClaimNonRevMtpAuxHv?: string; - issuerClaimNonRevMtpNoAux?: string; - claimSchema?: string; - issuerClaimSignatureR8x?: string; - issuerClaimSignatureR8y?: string; - issuerClaimSignatureS?: string; - issuerAuthClaim?: string[]; - issuerAuthClaimMtp?: string[]; - issuerAuthClaimNonRevMtp?: string[]; - issuerAuthClaimNonRevMtpAuxHi?: string; - issuerAuthClaimNonRevMtpAuxHv?: string; - issuerAuthClaimNonRevMtpNoAux?: string; - issuerAuthClaimsTreeRoot?: string; - issuerAuthRevTreeRoot?: string; - issuerAuthRootsTreeRoot?: string; - - isRevocationChecked?: number; + issuerClaim!: string[]; + issuerClaimNonRevClaimsTreeRoot!: string; + issuerClaimNonRevRevTreeRoot!: string; + issuerClaimNonRevRootsTreeRoot!: string; + issuerClaimNonRevState!: string; + issuerClaimNonRevMtp!: string[]; + issuerClaimNonRevMtpAuxHi!: string; + issuerClaimNonRevMtpAuxHv!: string; + issuerClaimNonRevMtpNoAux!: string; + claimSchema!: string; + issuerClaimSignatureR8x!: string; + issuerClaimSignatureR8y!: string; + issuerClaimSignatureS!: string; + issuerAuthClaim!: string[]; + issuerAuthClaimMtp!: string[]; + issuerAuthClaimNonRevMtp!: string[]; + issuerAuthClaimNonRevMtpAuxHi!: string; + issuerAuthClaimNonRevMtpAuxHv!: string; + issuerAuthClaimNonRevMtpNoAux!: string; + issuerAuthClaimsTreeRoot!: string; + issuerAuthRevTreeRoot!: string; + issuerAuthRootsTreeRoot!: string; + + isRevocationChecked!: number; // Query // JSON path - claimPathNotExists?: number; // 0 for inclusion, 1 for non-inclusion - claimPathMtp?: string[]; - claimPathMtpNoAux?: string; // 1 if aux node is empty, 0 if non-empty or for inclusion proofs - claimPathMtpAuxHi?: string; // 0 for inclusion proof - claimPathMtpAuxHv?: string; // 0 for inclusion proof - claimPathKey?: string; // hash of path in merklized json-ld document - claimPathValue?: string; // value in this path in merklized json-ld document - - operator?: number; - slotIndex?: number; - timestamp?: number; - value?: string[]; + claimPathNotExists!: number; // 0 for inclusion, 1 for non-inclusion + claimPathMtp!: string[]; + claimPathMtpNoAux!: string; // 1 if aux node is empty, 0 if non-empty or for inclusion proofs + claimPathMtpAuxHi!: string; // 0 for inclusion proof + claimPathMtpAuxHv!: string; // 0 for inclusion proof + claimPathKey!: string; // hash of path in merklized json-ld document + claimPathValue!: string; // value in this path in merklized json-ld document + + operator!: number; + slotIndex!: number; + timestamp!: number; + value!: string[]; // AuthClaim proof of inclusion - authClaim?: string[]; - authClaimIncMtp?: string[]; + authClaim!: string[]; + authClaimIncMtp!: string[]; // AuthClaim non revocation proof - authClaimNonRevMtp?: string[]; - authClaimNonRevMtpAuxHi?: string; - authClaimNonRevMtpAuxHv?: string; - authClaimNonRevMtpNoAux?: string; + authClaimNonRevMtp!: string[]; + authClaimNonRevMtpAuxHi!: string; + authClaimNonRevMtpAuxHv!: string; + authClaimNonRevMtpNoAux!: string; - challenge?: string; - challengeSignatureR8x?: string; - challengeSignatureR8y?: string; - challengeSignatureS?: string; + challenge!: string; + challengeSignatureR8x!: string; + challengeSignatureR8y!: string; + challengeSignatureS!: string; // User State - userClaimsTreeRoot?: string; - userRevTreeRoot?: string; - userRootsTreeRoot?: string; - userState?: string; + userClaimsTreeRoot!: string; + userRevTreeRoot!: string; + userRootsTreeRoot!: string; + userState!: string; // Global on-cain state - gistRoot?: string; - gistMtp?: string[]; - gistMtpAuxHi?: string; - gistMtpAuxHv?: string; - gistMtpNoAux?: string; + gistRoot!: string; + gistMtp!: string[]; + gistMtpAuxHi!: string; + gistMtpAuxHv!: string; + gistMtpNoAux!: string; } /** @@ -324,17 +317,17 @@ export class AtomicQuerySigV2OnChainCircuitInputs { * @extends {BaseConfig} */ export class AtomicQuerySigV2OnChainPubSignals extends BaseConfig { - requestID?: bigint; - userID?: Id; - issuerID?: Id; - issuerAuthState?: Hash; - issuerClaimNonRevState?: Hash; - timestamp?: number; - merklized?: number; - isRevocationChecked?: number; // 0 revocation not check, // 1 for check revocation - circuitQueryHash?: bigint; - challenge?: bigint; - gistRoot?: Hash; + requestID!: bigint; + userID!: Id; + issuerID!: Id; + issuerAuthState!: Hash; + issuerClaimNonRevState!: Hash; + timestamp!: number; + merklized!: number; + isRevocationChecked!: number; // 0 revocation not check, // 1 for check revocation + circuitQueryHash!: bigint; + challenge!: bigint; + gistRoot!: Hash; // /** diff --git a/src/circuits/atomic-query-sig-v2.ts b/src/circuits/atomic-query-sig-v2.ts index 7633e506..93c7cc38 100644 --- a/src/circuits/atomic-query-sig-v2.ts +++ b/src/circuits/atomic-query-sig-v2.ts @@ -23,20 +23,20 @@ import { byteDecoder, byteEncoder } from '../utils'; * @extends {BaseConfig} */ export class AtomicQuerySigV2Inputs extends BaseConfig { - requestID?: bigint; + requestID!: bigint; // auth - id?: Id; - profileNonce?: bigint; - claimSubjectProfileNonce?: bigint; + id!: Id; + profileNonce!: bigint; + claimSubjectProfileNonce!: bigint; // claim issued for user - claim?: ClaimWithSigProof; - skipClaimRevocationCheck?: boolean; + claim!: ClaimWithSigProof; + skipClaimRevocationCheck!: boolean; - currentTimeStamp?: number; + currentTimeStamp!: number; // query - query?: Query; + query!: Query; /** * Validate inputs @@ -46,7 +46,7 @@ export class AtomicQuerySigV2Inputs extends BaseConfig { if (!this.requestID) { throw new Error(CircuitError.EmptyRequestID); } - if (!this.claim?.nonRevProof?.proof) { + if (!this.claim.nonRevProof?.proof) { throw new Error(CircuitError.EmptyClaimNonRevProof); } @@ -62,7 +62,7 @@ export class AtomicQuerySigV2Inputs extends BaseConfig { throw new Error(CircuitError.EmptyClaimSignature); } - if (!this.query?.values && this.query?.operator !== QueryOperators.$noop) { + if (!this.query.values && this.query.operator !== QueryOperators.$noop) { throw new Error(CircuitError.EmptyQueryValue); } } @@ -74,66 +74,66 @@ export class AtomicQuerySigV2Inputs extends BaseConfig { */ inputsMarshal(): Uint8Array { this.validate(); - if (this.query?.valueProof) { + if (this.query.valueProof) { this.query.validate(); this.query.valueProof.validate(); } - const valueProof = this.query?.valueProof ?? new ValueProof(); + const valueProof = this.query.valueProof ?? new ValueProof(); const s: Partial = { - requestID: this.requestID?.toString(), - userGenesisID: this.id?.bigInt().toString(), - profileNonce: this.profileNonce?.toString(), + requestID: this.requestID.toString(), + userGenesisID: this.id.bigInt().toString(), + profileNonce: this.profileNonce.toString(), claimSubjectProfileNonce: this.claimSubjectProfileNonce?.toString(), - issuerID: this.claim?.issuerID?.bigInt().toString(), - issuerClaim: this.claim?.claim?.marshalJson(), - issuerClaimNonRevClaimsTreeRoot: this.claim?.nonRevProof?.treeState?.claimsRoot + issuerID: this.claim.issuerID?.bigInt().toString(), + issuerClaim: this.claim.claim?.marshalJson(), + issuerClaimNonRevClaimsTreeRoot: this.claim.nonRevProof?.treeState?.claimsRoot ?.bigInt() .toString(), - issuerClaimNonRevRevTreeRoot: this.claim?.nonRevProof?.treeState?.revocationRoot + issuerClaimNonRevRevTreeRoot: this.claim.nonRevProof?.treeState?.revocationRoot ?.bigInt() .toString(), - issuerClaimNonRevRootsTreeRoot: this.claim?.nonRevProof?.treeState?.rootOfRoots + issuerClaimNonRevRootsTreeRoot: this.claim.nonRevProof?.treeState?.rootOfRoots ?.bigInt() .toString(), - issuerClaimNonRevState: this.claim?.nonRevProof?.treeState?.state?.bigInt().toString(), - issuerClaimNonRevMtp: this.claim?.nonRevProof?.proof - ? prepareSiblingsStr(this.claim.nonRevProof.proof, this.getMTLevel()) - : undefined, - issuerClaimSignatureR8x: this.claim?.signatureProof?.signature.R8[0].toString(), - issuerClaimSignatureR8y: this.claim?.signatureProof?.signature.R8[1].toString(), - issuerClaimSignatureS: this.claim?.signatureProof?.signature.S.toString(), - issuerAuthClaim: this.claim?.signatureProof?.issuerAuthClaim?.marshalJson(), - issuerAuthClaimMtp: this.claim?.signatureProof?.issuerAuthIncProof?.proof - ? prepareSiblingsStr(this.claim.signatureProof.issuerAuthIncProof.proof, this.getMTLevel()) - : undefined, - issuerAuthClaimsTreeRoot: this.claim?.signatureProof?.issuerAuthIncProof.treeState?.claimsRoot + issuerClaimNonRevState: this.claim.nonRevProof?.treeState?.state?.bigInt().toString(), + issuerClaimNonRevMtp: + this.claim.nonRevProof?.proof && + prepareSiblingsStr(this.claim.nonRevProof.proof, this.getMTLevel()), + issuerClaimSignatureR8x: this.claim.signatureProof?.signature.R8[0].toString(), + issuerClaimSignatureR8y: this.claim.signatureProof?.signature.R8[1].toString(), + issuerClaimSignatureS: this.claim.signatureProof?.signature.S.toString(), + issuerAuthClaim: this.claim.signatureProof?.issuerAuthClaim?.marshalJson(), + issuerAuthClaimMtp: + this.claim.signatureProof?.issuerAuthIncProof?.proof && + prepareSiblingsStr(this.claim.signatureProof.issuerAuthIncProof.proof, this.getMTLevel()), + issuerAuthClaimsTreeRoot: this.claim.signatureProof?.issuerAuthIncProof.treeState?.claimsRoot ?.bigInt() .toString(), issuerAuthRevTreeRoot: - this.claim?.signatureProof?.issuerAuthIncProof?.treeState?.revocationRoot + this.claim.signatureProof?.issuerAuthIncProof?.treeState?.revocationRoot ?.bigInt() .toString(), - issuerAuthRootsTreeRoot: - this.claim?.signatureProof?.issuerAuthIncProof?.treeState?.rootOfRoots?.bigInt().toString(), + issuerAuthRootsTreeRoot: this.claim.signatureProof?.issuerAuthIncProof?.treeState?.rootOfRoots + ?.bigInt() + .toString(), - issuerAuthClaimNonRevMtp: this.claim?.signatureProof?.issuerAuthNonRevProof?.proof - ? prepareSiblingsStr( - this.claim.signatureProof.issuerAuthNonRevProof.proof, - this.getMTLevel() - ) - : undefined, + issuerAuthClaimNonRevMtp: + this.claim.signatureProof?.issuerAuthNonRevProof?.proof && + prepareSiblingsStr( + this.claim.signatureProof.issuerAuthNonRevProof.proof, + this.getMTLevel() + ), - claimSchema: this.claim?.claim?.getSchemaHash().bigInt().toString(), + claimSchema: this.claim.claim?.getSchemaHash().bigInt().toString(), claimPathMtp: prepareSiblingsStr(valueProof.mtp, this.getMTLevelsClaimMerklization()), claimPathValue: valueProof.value.toString(), - operator: this.query?.operator, - timestamp: this.currentTimeStamp ? this.currentTimeStamp : undefined, + operator: this.query.operator, + timestamp: this.currentTimeStamp, // value in this path in merklized json-ld document - - slotIndex: this.query?.slotIndex + slotIndex: this.query.slotIndex }; if (this.skipClaimRevocationCheck) { @@ -141,14 +141,14 @@ export class AtomicQuerySigV2Inputs extends BaseConfig { } else { s.isRevocationChecked = 1; } - const nodeAuxNonRev = this.claim ? getNodeAuxValue(this.claim.nonRevProof?.proof) : undefined; + const nodeAuxNonRev = getNodeAuxValue(this.claim.nonRevProof?.proof); s.issuerClaimNonRevMtpAuxHi = nodeAuxNonRev?.key.bigInt().toString(); s.issuerClaimNonRevMtpAuxHv = nodeAuxNonRev?.value.bigInt().toString(); s.issuerClaimNonRevMtpNoAux = nodeAuxNonRev?.noAux; - const nodeAuxIssuerAuthNonRev = this.claim?.signatureProof - ? getNodeAuxValue(this.claim.signatureProof.issuerAuthNonRevProof.proof) - : undefined; + const nodeAuxIssuerAuthNonRev = + this.claim.signatureProof && + getNodeAuxValue(this.claim.signatureProof.issuerAuthNonRevProof.proof); s.issuerAuthClaimNonRevMtpAuxHi = nodeAuxIssuerAuthNonRev?.key.bigInt().toString(); s.issuerAuthClaimNonRevMtpAuxHv = nodeAuxIssuerAuthNonRev?.value.bigInt().toString(); s.issuerAuthClaimNonRevMtpNoAux = nodeAuxIssuerAuthNonRev?.noAux; @@ -167,10 +167,8 @@ export class AtomicQuerySigV2Inputs extends BaseConfig { s.isRevocationChecked = 1; } - const values = this.query?.values - ? prepareCircuitArrayValues(this.query.values, this.getValueArrSize()) - : undefined; - s.value = values ? bigIntArrayToStringArray(values) : undefined; + const values = prepareCircuitArrayValues(this.query.values, this.getValueArrSize()); + s.value = bigIntArrayToStringArray(values); return byteEncoder.encode(JSON.stringify(s)); } @@ -227,22 +225,22 @@ interface AtomicQuerySigV2CircuitInputs { * @extends {BaseConfig} */ export class AtomicQuerySigV2PubSignals extends BaseConfig { - requestID?: bigint; - userID?: Id; - issuerID?: Id; - issuerAuthState?: Hash; - issuerClaimNonRevState?: Hash; - claimSchema?: SchemaHash; - slotIndex?: number; - operator?: number; + requestID!: bigint; + userID!: Id; + issuerID!: Id; + issuerAuthState!: Hash; + issuerClaimNonRevState!: Hash; + claimSchema!: SchemaHash; + slotIndex!: number; + operator!: number; value: bigint[] = []; - timestamp?: number; - merklized?: number; - claimPathKey?: bigint; + timestamp!: number; + merklized!: number; + claimPathKey!: bigint; // 0 for inclusion, 1 for non-inclusion - claimPathNotExists?: number; + claimPathNotExists!: number; // 0 revocation not check, // 1 for check revocation - isRevocationChecked?: number; + isRevocationChecked!: number; // /** diff --git a/src/circuits/auth-v2.ts b/src/circuits/auth-v2.ts index 5a5f0a0d..f6c13b86 100644 --- a/src/circuits/auth-v2.ts +++ b/src/circuits/auth-v2.ts @@ -15,15 +15,15 @@ import { byteDecoder, byteEncoder } from '../utils'; * @extends {BaseConfig} */ export class AuthV2Inputs extends BaseConfig { - genesisID?: Id; - profileNonce?: bigint; - authClaim?: Claim; - authClaimIncMtp?: Proof; - authClaimNonRevMtp?: Proof; - treeState?: TreeState; - gistProof?: GISTProof; - signature?: Signature; - challenge?: bigint; + genesisID!: Id; + profileNonce!: bigint; + authClaim!: Claim; + authClaimIncMtp!: Proof; + authClaimNonRevMtp!: Proof; + treeState!: TreeState; + gistProof!: GISTProof; + signature!: Signature; + challenge!: bigint; validate(): void { if (!this.genesisID) { @@ -38,7 +38,7 @@ export class AuthV2Inputs extends BaseConfig { throw new Error(CircuitError.EmptyAuthClaimNonRevProof); } - if (!this.gistProof?.proof) { + if (!this.gistProof.proof) { throw new Error(CircuitError.EmptyGISTProof); } @@ -59,37 +59,29 @@ export class AuthV2Inputs extends BaseConfig { genesisID: this.genesisID?.bigInt().toString(), profileNonce: this.profileNonce?.toString(), authClaim: this.authClaim?.marshalJson(), - authClaimIncMtp: this.authClaimIncMtp - ? prepareSiblingsStr(this.authClaimIncMtp, this.getMTLevel()) - : undefined, - authClaimNonRevMtp: this.authClaimNonRevMtp - ? prepareSiblingsStr(this.authClaimNonRevMtp, this.getMTLevel()) - : undefined, + authClaimIncMtp: prepareSiblingsStr(this.authClaimIncMtp, this.getMTLevel()), + authClaimNonRevMtp: prepareSiblingsStr(this.authClaimNonRevMtp, this.getMTLevel()), challenge: this.challenge?.toString(), - challengeSignatureR8x: this.signature?.R8[0].toString(), - challengeSignatureR8y: this.signature?.R8[1].toString(), - challengeSignatureS: this.signature?.S.toString(), - claimsTreeRoot: this.treeState?.claimsRoot?.bigInt().toString(), - revTreeRoot: this.treeState?.revocationRoot?.bigInt().toString(), - rootsTreeRoot: this.treeState?.rootOfRoots?.bigInt().toString(), - state: this.treeState?.state?.bigInt().toString(), - gistRoot: this.gistProof?.root.bigInt().toString(), - gistMtp: this.gistProof - ? prepareSiblingsStr(this.gistProof.proof, this.getMTLevelOnChain()) - : undefined + challengeSignatureR8x: this.signature.R8[0].toString(), + challengeSignatureR8y: this.signature.R8[1].toString(), + challengeSignatureS: this.signature.S.toString(), + claimsTreeRoot: this.treeState.claimsRoot?.bigInt().toString(), + revTreeRoot: this.treeState.revocationRoot?.bigInt().toString(), + rootsTreeRoot: this.treeState.rootOfRoots?.bigInt().toString(), + state: this.treeState.state?.bigInt().toString(), + gistRoot: this.gistProof.root.bigInt().toString(), + gistMtp: this.gistProof && prepareSiblingsStr(this.gistProof.proof, this.getMTLevelOnChain()) }; - const nodeAuxAuth = this.authClaimNonRevMtp - ? getNodeAuxValue(this.authClaimNonRevMtp) - : undefined; - s.authClaimNonRevMtpAuxHi = nodeAuxAuth?.key.bigInt().toString(); - s.authClaimNonRevMtpAuxHv = nodeAuxAuth?.value.bigInt().toString(); - s.authClaimNonRevMtpNoAux = nodeAuxAuth?.noAux; - - const globalNodeAux = this.gistProof ? getNodeAuxValue(this.gistProof.proof) : undefined; - s.gistMtpAuxHi = globalNodeAux?.key.bigInt().toString(); - s.gistMtpAuxHv = globalNodeAux?.value.bigInt().toString(); - s.gistMtpNoAux = globalNodeAux?.noAux; + const nodeAuxAuth = getNodeAuxValue(this.authClaimNonRevMtp); + s.authClaimNonRevMtpAuxHi = nodeAuxAuth.key.bigInt().toString(); + s.authClaimNonRevMtpAuxHv = nodeAuxAuth.value.bigInt().toString(); + s.authClaimNonRevMtpNoAux = nodeAuxAuth.noAux; + + const globalNodeAux = getNodeAuxValue(this.gistProof.proof); + s.gistMtpAuxHi = globalNodeAux.key.bigInt().toString(); + s.gistMtpAuxHv = globalNodeAux.value.bigInt().toString(); + s.gistMtpNoAux = globalNodeAux.noAux; return byteEncoder.encode(JSON.stringify(s)); } diff --git a/src/circuits/common.ts b/src/circuits/common.ts index 2cfe3852..45d8362d 100644 --- a/src/circuits/common.ts +++ b/src/circuits/common.ts @@ -27,10 +27,10 @@ export const ErrorEmptyIssuerAuthClaimNonRevProof = * @class BaseConfig */ export class BaseConfig { - mtLevel?: number; // Max levels of MT - valueArraySize?: number; // Size if( value array in identity circuit)s - mtLevelOnChain?: number; - mtLevelClaimsMerklization?: number; // max levels in the merklization + mtLevel!: number; // Max levels of MT + valueArraySize!: number; // Size if( value array in identity circuit)s + mtLevelOnChain!: number; + mtLevelClaimsMerklization!: number; // max levels in the merklization /** * getMTLevel max circuit MT levels diff --git a/src/circuits/models.ts b/src/circuits/models.ts index f96cc4bd..ee948d38 100644 --- a/src/circuits/models.ts +++ b/src/circuits/models.ts @@ -37,10 +37,10 @@ export interface ClaimNonRevStatus { * @class Query */ export class Query { - slotIndex?: number; - values?: bigint[]; - operator?: number; - valueProof?: ValueProof; + slotIndex!: number; + values!: bigint[]; + operator!: number; + valueProof!: ValueProof; /** * Validates Query instance @@ -81,12 +81,12 @@ export enum CircuitId { * @class CircuitClaim */ export class CircuitClaim { - issuerId?: Id; - claim?: CoreClaim; - treeState?: TreeState; - proof?: Proof; - nonRevProof?: ClaimNonRevStatus; // Claim non revocation proof - signatureProof?: BJJSignatureProof; + issuerId!: Id; + claim!: CoreClaim; + treeState!: TreeState; + proof!: Proof; + nonRevProof!: ClaimNonRevStatus; // Claim non revocation proof + signatureProof!: BJJSignatureProof; } /** diff --git a/src/circuits/state-transition.ts b/src/circuits/state-transition.ts index fa7de82e..4cda3f17 100644 --- a/src/circuits/state-transition.ts +++ b/src/circuits/state-transition.ts @@ -15,16 +15,16 @@ import { byteDecoder, byteEncoder } from '../utils'; * @extends {BaseConfig} */ export class StateTransitionInputs extends BaseConfig { - id?: Id; - oldTreeState?: TreeState; - newTreeState?: TreeState; + id!: Id; + oldTreeState!: TreeState; + newTreeState!: TreeState; - isOldStateGenesis?: boolean; - authClaim?: ClaimWithMTPProof; + isOldStateGenesis!: boolean; + authClaim!: ClaimWithMTPProof; - authClaimNewStateIncProof?: Proof; + authClaimNewStateIncProof!: Proof; - signature?: Signature; + signature!: Signature; /** * CircuitInputMarshal returns Circom private inputs for stateTransition.circom @@ -55,9 +55,9 @@ export class StateTransitionInputs extends BaseConfig { oldUserState: this.oldTreeState?.state?.bigInt().toString(), revTreeRoot: this.oldTreeState?.revocationRoot?.bigInt().toString(), rootsTreeRoot: this.oldTreeState?.rootOfRoots?.bigInt().toString(), - signatureR8x: this.signature?.R8[0].toString(), - signatureR8y: this.signature?.R8[1].toString(), - signatureS: this.signature?.S.toString(), + signatureR8x: this.signature.R8[0].toString(), + signatureR8y: this.signature.R8[1].toString(), + signatureS: this.signature.S.toString(), newClaimsTreeRoot: this.newTreeState?.claimsRoot?.bigInt().toString(), newRootsTreeRoot: this.newTreeState?.rootOfRoots?.bigInt().toString(), newRevTreeRoot: this.newTreeState?.revocationRoot?.bigInt().toString() diff --git a/src/credentials/status/sparse-merkle-tree.ts b/src/credentials/status/sparse-merkle-tree.ts index da90ab19..8bd8ca62 100644 --- a/src/credentials/status/sparse-merkle-tree.ts +++ b/src/credentials/status/sparse-merkle-tree.ts @@ -1,12 +1,12 @@ import { CredentialStatus, RevocationStatus, Issuer } from '../../verifiable'; import { CredentialStatusResolver } from './resolver'; -import { newHashFromBigInt, Proof, NodeAux, setBitBigEndian } from '@iden3/js-merkletree'; +import { newHashFromBigInt, Proof, setBitBigEndian } from '@iden3/js-merkletree'; export class IssuerResolver implements CredentialStatusResolver { async resolve(credentialStatus: CredentialStatus): Promise { const revStatusResp = await fetch(credentialStatus.id); - const revStatusDTO = await revStatusResp.json(); - return new RevocationStatusDTO(revStatusDTO).toRevocationStatus(); + const revStatus = await revStatusResp.json(); + return new RevocationStatusDTO(revStatus).toRevocationStatus(); } } @@ -43,12 +43,10 @@ export class RevocationStatusDTO { toRevocationStatus(): RevocationStatus { const p = new Proof(); p.existence = this.mtp.existence; - p.nodeAux = this.mtp.node_aux - ? ({ - key: newHashFromBigInt(BigInt(this.mtp.node_aux.key)), - value: newHashFromBigInt(BigInt(this.mtp.node_aux.value)) - } as NodeAux) - : undefined; + p.nodeAux = { + key: newHashFromBigInt(BigInt(this.mtp.node_aux.key)), + value: newHashFromBigInt(BigInt(this.mtp.node_aux.value)) + }; const s = this.mtp.siblings.map((s) => newHashFromBigInt(BigInt(s))); diff --git a/src/proof/proof-service.ts b/src/proof/proof-service.ts index 62008b91..5dcf1a89 100644 --- a/src/proof/proof-service.ts +++ b/src/proof/proof-service.ts @@ -416,14 +416,14 @@ export class ProofService implements IProofService { circuitInputs.authClaim = authClaimData.claim; circuitInputs.authClaimIncMtp = authClaimData.proof; circuitInputs.authClaimNonRevMtp = authPrepared.nonRevProof.proof; - + const challenge = opts.challenge!; const signature = await this._identityWallet.signChallenge( - opts.challenge ?? BigInt(proofReq.id), + challenge, authPrepared.authCredential ); circuitInputs.signature = signature; - circuitInputs.challenge = opts.challenge; + circuitInputs.challenge = challenge; const { query, vp } = await this.toCircuitsQuery( proofReq.query, @@ -540,13 +540,14 @@ export class ProofService implements IProofService { circuitInputs.authClaimIncMtp = authClaimData.proof; circuitInputs.authClaimNonRevMtp = authPrepared.nonRevProof.proof; + const challenge = opts.challenge!; const signature = await this._identityWallet.signChallenge( - opts.challenge ?? BigInt(proofReq.id), + challenge, authPrepared.authCredential ); circuitInputs.signature = signature; - circuitInputs.challenge = opts.challenge; + circuitInputs.challenge = challenge; return { inputs: circuitInputs.inputsMarshal(), vp }; } @@ -687,7 +688,7 @@ export class ProofService implements IProofService { if (!parsedQuery.fieldName) { const resultQuery = parsedQuery.query; resultQuery.operator = QueryOperators.$eq; - resultQuery.values = mtEntry ? [mtEntry] : undefined; + resultQuery.values = [mtEntry!]; return { query: resultQuery }; } if (parsedQuery.isSelectiveDisclosure) { @@ -700,7 +701,7 @@ export class ProofService implements IProofService { ); const resultQuery = parsedQuery.query; resultQuery.operator = QueryOperators.$eq; - resultQuery.values = mtEntry ? [mtEntry] : undefined; + resultQuery.values = [mtEntry!]; return { query: resultQuery, vp }; } if (parsedQuery.rawValue === null || parsedQuery.rawValue === undefined) { diff --git a/src/storage/shared/credential-storage.ts b/src/storage/shared/credential-storage.ts index 10590292..8ad45236 100644 --- a/src/storage/shared/credential-storage.ts +++ b/src/storage/shared/credential-storage.ts @@ -26,12 +26,10 @@ export class CredentialStorage implements ICredentialStorage { /** {@inheritdoc ICredentialStorage.listCredentials } */ async listCredentials(): Promise { - let creds = await this._dataSource.load(); - const mappedCreds = creds.map((cred) => - cred ? Object.assign(new W3CCredential(), cred) : undefined - ); - creds = mappedCreds.filter((i) => i !== undefined) as W3CCredential[]; - return creds; + const creds = await this._dataSource.load(); + return creds + .filter((i) => i !== undefined) + .map((cred) => cred && Object.assign(new W3CCredential(), cred)); } /** @inheritdoc */ @@ -54,7 +52,7 @@ export class CredentialStorage implements ICredentialStorage { /** {@inheritdoc ICredentialStorage.listCredentials } */ async findCredentialById(id: string): Promise { const cred = await this._dataSource.get(id); - return cred ? Object.assign(new W3CCredential(), cred) : undefined; + return cred && Object.assign(new W3CCredential(), cred); } /** {@inheritdoc ICredentialStorage.listCredentials } @@ -62,14 +60,14 @@ export class CredentialStorage implements ICredentialStorage { */ async findCredentialsByQuery(query: ProofQuery): Promise { const filters = StandardJSONCredentialsQueryFilter(query); - let creds = (await this._dataSource.load()).filter((credential) => + const creds = (await this._dataSource.load()).filter((credential) => filters.every((filter) => filter.execute(credential)) ); - const mappedCreds = creds.map((cred) => - cred ? Object.assign(new W3CCredential(), cred) : undefined - ); - creds = mappedCreds.filter((i) => i !== undefined) as W3CCredential[]; - return creds; + const mappedCreds = creds + .filter((i) => i !== undefined) + .map((cred) => Object.assign(new W3CCredential(), cred)); + + return mappedCreds; } }