Skip to content

Commit

Permalink
Merge pull request 0xPolygonID#23 from 0xPolygonID/fix/verify-mtp-pro…
Browse files Browse the repository at this point in the history
…of-params

fix verifyProof for MTP & update depricated publishStateToRHS
  • Loading branch information
vmidyllic authored Mar 18, 2024
2 parents 469d6fd + d30e7f5 commit 1816dc7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
37 changes: 30 additions & 7 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,11 @@ async function transitState() {

console.log('================= push states to rhs ===================');

await identityWallet.publishStateToRHS(issuerDID, rhsUrl);
await identityWallet.publishRevocationInfoByCredentialStatusType(
issuerDID,
CredentialStatusType.Iden3ReverseSparseMerkleTreeProof,
{ rhsUrl }
);

console.log('================= publish to blockchain ===================');

Expand Down Expand Up @@ -284,7 +288,11 @@ async function transitStateThirdPartyDID() {

console.log('================= third party: push states to rhs ===================');

await identityWallet.publishStateToRHS(issuerDID, rhsUrl);
await identityWallet.publishRevocationInfoByCredentialStatusType(
issuerDID,
CredentialStatusType.Iden3ReverseSparseMerkleTreeProof,
{ rhsUrl }
);

console.log('================= publish to blockchain ===================');

Expand Down Expand Up @@ -345,7 +353,11 @@ async function generateProofs(useMongoStore = false) {

console.log('================= push states to rhs ===================');

await identityWallet.publishStateToRHS(issuerDID, rhsUrl);
await identityWallet.publishRevocationInfoByCredentialStatusType(
issuerDID,
CredentialStatusType.Iden3ReverseSparseMerkleTreeProof,
{ rhsUrl }
);

console.log('================= publish to blockchain ===================');

Expand Down Expand Up @@ -390,11 +402,14 @@ async function generateProofs(useMongoStore = false) {
credentialRequest
);

const { proof: proofMTP } = await proofService.generateProof(proofReqMtp, userDID);
const { proof: proofMTP, pub_signals: pub_signalsMTP } = await proofService.generateProof(
proofReqMtp,
userDID
);

console.log(JSON.stringify(proofMTP));
const mtpProofOk = await proofService.verifyProof(
{ proof, pub_signals },
{ proof: proofMTP, pub_signals: pub_signalsMTP },
CircuitId.AtomicQueryMTPV2
);
console.log('valid: ', mtpProofOk);
Expand Down Expand Up @@ -454,7 +469,11 @@ async function handleAuthRequest(useMongoStore = false) {

console.log('================= push states to rhs ===================');

await identityWallet.publishStateToRHS(issuerDID, rhsUrl);
await identityWallet.publishRevocationInfoByCredentialStatusType(
issuerDID,
CredentialStatusType.Iden3ReverseSparseMerkleTreeProof,
{ rhsUrl }
);

console.log('================= publish to blockchain ===================');

Expand Down Expand Up @@ -849,7 +868,11 @@ async function handleAuthRequestV3CircuitsBetaStateTransition() {
const res = await identityWallet.addCredentialsToMerkleTree([issuedCred], issuerDID);
console.log('=============== added to merkle tree ===============');

await identityWallet.publishStateToRHS(issuerDID, rhsUrl);
await identityWallet.publishRevocationInfoByCredentialStatusType(
issuerDID,
CredentialStatusType.Iden3ReverseSparseMerkleTreeProof,
{ rhsUrl }
);
console.log('=============== published to rhs ===============');

const ethSigner = new ethers.Wallet(walletKey, (dataStorage.states as EthStateStorage).provider);
Expand Down
14 changes: 12 additions & 2 deletions walletSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ import {
PackageManager,
AgentResolver,
FSCircuitStorage,
AbstractPrivateKeyStore
AbstractPrivateKeyStore,
CredentialStatusPublisherRegistry,
Iden3SmtRhsCredentialStatusPublisher
} from '@0xpolygonid/js-sdk';
import path from 'path';
import dotenv from 'dotenv';
Expand Down Expand Up @@ -126,7 +128,15 @@ export async function initIdentityWallet(
const kms = new KMS();
kms.registerKeyProvider(KmsKeyType.BabyJubJub, bjjProvider);

return new IdentityWallet(kms, dataStorage, credentialWallet);
const credentialStatusPublisherRegistry = new CredentialStatusPublisherRegistry();
credentialStatusPublisherRegistry.register(
CredentialStatusType.Iden3ReverseSparseMerkleTreeProof,
new Iden3SmtRhsCredentialStatusPublisher()
);

return new IdentityWallet(kms, dataStorage, credentialWallet, {
credentialStatusPublisherRegistry
});
}

export async function initInMemoryDataStorageAndWallets(config: {
Expand Down

0 comments on commit 1816dc7

Please sign in to comment.