Skip to content

Commit

Permalink
update abi
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-korotya committed Jun 25, 2023
1 parent 51e80d2 commit 6ac2fbc
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 102 deletions.
19 changes: 16 additions & 3 deletions src/credentials/status/on-chain-revocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { RevocationStatus, CredentialStatus } from '../../verifiable';
import { EthConnectionConfig } from '../../storage/blockchain';
import { CredentialStatusResolver } from './resolver';
import { OnChainRevocationStorage } from '../../storage/blockchain/onchain-revocation';
import { DID } from '@iden3/js-iden3-core';

/**
* OnChainIssuer is a class that allows to interact with the onchain contract
Expand Down Expand Up @@ -32,13 +33,19 @@ export class OnChainResolver implements CredentialStatusResolver {
* @returns Promise<RevocationStatus>
*/
async getRevocationOnChain(credentialStatus: CredentialStatus): Promise<RevocationStatus> {
const { contractAddress, chainId, revocationNonce } = this.parseOnChainId(credentialStatus.id);
const { contractAddress, chainId, revocationNonce, issuer } = this.parseOnChainId(
credentialStatus.id
);
if (revocationNonce !== credentialStatus.revocationNonce) {
throw new Error('revocationNonce does not match');
}
const issuerDID = DID.parse(issuer);
const networkConfig = this.networkByChainId(chainId);
const onChainCaller = new OnChainRevocationStorage(networkConfig, contractAddress);
const revocationStatus = await onChainCaller.getRevocationStatus(revocationNonce);
const revocationStatus = await onChainCaller.getRevocationStatus(
issuerDID.id.bigInt(),
revocationNonce
);
return revocationStatus;
}

Expand All @@ -52,6 +59,7 @@ export class OnChainResolver implements CredentialStatusResolver {
contractAddress: string;
chainId: number;
revocationNonce: number;
issuer: string;
} {
const url = new URL(id);
if (!url.searchParams.has('contractAddress')) {
Expand All @@ -60,6 +68,11 @@ export class OnChainResolver implements CredentialStatusResolver {
if (!url.searchParams.has('revocationNonce')) {
throw new Error('revocationNonce not found');
}

const issuerDID = id.split('/')[0];
if (!issuerDID) {
throw new Error('issuer not found in credentialStatus id');
}
// TODO (illia-korotia): after merging core v2 need to parse contract address from did if `contractAddress` is not present in id as param
const contractId = url.searchParams.get('contractAddress');
const revocationNonce = parseInt(url.searchParams.get('revocationNonce'), 10);
Expand All @@ -71,7 +84,7 @@ export class OnChainResolver implements CredentialStatusResolver {
const chainId = parseInt(parts[0], 10);
const contractAddress = parts[1];

return { contractAddress, chainId, revocationNonce };
return { contractAddress, chainId, revocationNonce, issuer: issuerDID };
}

networkByChainId(chainId: number): EthConnectionConfig {
Expand Down
197 changes: 100 additions & 97 deletions src/storage/blockchain/onchain-revocation-abi.json
Original file line number Diff line number Diff line change
@@ -1,97 +1,100 @@
[
{
"inputs": [
{
"internalType": "uint64",
"name": "nonce",
"type": "uint64"
}
],
"name": "getRevocationStatus",
"outputs": [
{
"components": [
{
"components": [
{
"internalType": "uint256",
"name": "state",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "claimsTreeRoot",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "revocationTreeRoot",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "rootOfRoots",
"type": "uint256"
}
],
"internalType": "struct IdentityBase.IdentityStateRoots",
"name": "issuer",
"type": "tuple"
},
{
"components": [
{
"internalType": "uint256",
"name": "root",
"type": "uint256"
},
{
"internalType": "bool",
"name": "existence",
"type": "bool"
},
{
"internalType": "uint256[]",
"name": "siblings",
"type": "uint256[]"
},
{
"internalType": "uint256",
"name": "index",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "value",
"type": "uint256"
},
{
"internalType": "bool",
"name": "auxExistence",
"type": "bool"
},
{
"internalType": "uint256",
"name": "auxIndex",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "auxValue",
"type": "uint256"
}
],
"internalType": "struct SmtLib.Proof",
"name": "mtp",
"type": "tuple"
}
],
"internalType": "struct IdentityBase.CredentialStatus",
"name": "",
"type": "tuple"
}
],
"stateMutability": "view",
"type": "function"
}
]
[{
"inputs": [
{
"internalType": "uint256",
"name": "id",
"type": "uint256"
},
{
"internalType": "uint64",
"name": "nonce",
"type": "uint64"
}
],
"name": "getRevocationStatus",
"outputs": [
{
"components": [
{
"components": [
{
"internalType": "uint256",
"name": "state",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "claimsTreeRoot",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "revocationTreeRoot",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "rootOfRoots",
"type": "uint256"
}
],
"internalType": "struct IOnchainCredentialStatusResolver.IdentityStateRoots",
"name": "issuer",
"type": "tuple"
},
{
"components": [
{
"internalType": "uint256",
"name": "root",
"type": "uint256"
},
{
"internalType": "bool",
"name": "existence",
"type": "bool"
},
{
"internalType": "uint256[]",
"name": "siblings",
"type": "uint256[]"
},
{
"internalType": "uint256",
"name": "index",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "value",
"type": "uint256"
},
{
"internalType": "bool",
"name": "auxExistence",
"type": "bool"
},
{
"internalType": "uint256",
"name": "auxIndex",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "auxValue",
"type": "uint256"
}
],
"internalType": "struct IOnchainCredentialStatusResolver.Proof",
"name": "mtp",
"type": "tuple"
}
],
"internalType": "struct IOnchainCredentialStatusResolver.CredentialStatus",
"name": "",
"type": "tuple"
}
],
"stateMutability": "view",
"type": "function"
}]
4 changes: 2 additions & 2 deletions src/storage/blockchain/onchain-revocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export class OnChainRevocationStorage {
*
* @returns Promise<RevocationStatus>
*/
public async getRevocationStatus(nonce: number): Promise<RevocationStatus> {
const response = await this.onchainContract.getRevocationStatus(nonce);
public async getRevocationStatus(issuerID: bigint, nonce: number): Promise<RevocationStatus> {
const response = await this.onchainContract.getRevocationStatus(issuerID, nonce);

const issuer = OnChainRevocationStorage.convertIssuerInfo(response.issuer);
const mtp = OnChainRevocationStorage.convertSmtProofToProof(response.mtp);
Expand Down

0 comments on commit 6ac2fbc

Please sign in to comment.