Skip to content

Commit

Permalink
Merge branch 'main' into v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Kolezhniuk committed Jul 3, 2023
2 parents 590e98f + 43c5237 commit 2609c06
Show file tree
Hide file tree
Showing 24 changed files with 684 additions and 469 deletions.
23 changes: 21 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
CredentialWallet,
KMS,
core,
CredentialStatusType
CredentialStatusType,
CredentialStatusResolverRegistry,
IssuerResolver,
RHSResolver,
OnChainResolver
} = IdenPolygonIdSdk;

const run = async () => {
Expand All @@ -52,7 +56,22 @@
}
}
};
const credWallet = new CredentialWallet(dataStorage);

const resolvers = new CredentialStatusResolverRegistry();
resolvers.register(
CredentialStatusType.SparseMerkleTreeProof,
new IssuerResolver()
);
resolvers.register(
CredentialStatusType.Iden3ReverseSparseMerkleTreeProof,
new RHSResolver(dataStorage.states)
);
resolvers.register(
CredentialStatusType.Iden3OnchainSparseMerkleTreeProof2023,
new OnChainResolver([defaultEthConnectionConfig])
)

const credWallet = new CredentialWallet(dataStorage, resolvers);
wallet = new IdentityWallet(kms, dataStorage, credWallet);
console.log(wallet);

Expand Down
116 changes: 7 additions & 109 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 3 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@0xpolygonid/js-sdk",
"version": "1.0.0-beta.9",
"version": "1.0.0-beta.12",
"description": "SDK to work with Polygon ID",
"main": "dist/cjs/index.js",
"module": "dist/esm_esbuild/index.js",
Expand Down Expand Up @@ -72,7 +72,7 @@
"dependencies": {
"@iden3/js-crypto": "1.0.0-beta.1",
"@iden3/js-iden3-core": "https://github.com/iden3/js-iden3-core#v2",
"@iden3/js-jsonld-merklization": "1.0.0-beta.8",
"@iden3/js-jsonld-merklization": "1.0.0-beta.15",
"@iden3/js-jwz": "1.0.0-beta.2",
"@iden3/js-merkletree": "1.0.0-beta.4",
"@lumeweb/js-sha3-browser": "^0.8.1",
Expand All @@ -93,23 +93,7 @@
"rfc4648": "^1.5.2",
"snarkjs": "^0.5.0",
"uint8arrays": "^3.0.0",
"uuid": "^9.0.0",
"@esbuild-plugins/node-globals-polyfill": "^0.1.1",
"@esbuild-plugins/node-modules-polyfill": "^0.1.4",
"@microsoft/api-documenter": "^7.20.1",
"@microsoft/api-extractor": "^7.34.4",
"@typescript-eslint/eslint-plugin": "^5.41.0",
"chokidar": "^3.5.3",
"esbuild": "^0.15.15",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"fetch-mock": "^9.11.0",
"madge": "^6.0.0",
"prettier": "^2.7.1",
"rimraf": "^2.7.1",
"ts-loader": "^9.4.1",
"ts-node": "^10.9.1",
"typescript": "^4.8.4"
"uuid": "^9.0.0"
},
"browserslist": {
"production": [
Expand Down
30 changes: 23 additions & 7 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 All @@ -15,30 +16,39 @@ export class OnChainResolver implements CredentialStatusResolver {
/**
*
* Creates an instance of OnChainIssuer.
* @param {Array<EthConnectionConfig>} - onhcain contract address
* @param {Array<EthConnectionConfig>} - onchain contract address
* @param {string} - list of EthConnectionConfig
*/
constructor(private readonly _configs: EthConnectionConfig[]) {}

async resolve(credentialStatus: CredentialStatus): Promise<RevocationStatus> {
return this.getRevocationOnChain(credentialStatus);
async resolve(
credentialStatus: CredentialStatus,
opts: {
issuer: DID;
}
): Promise<RevocationStatus> {
return this.getRevocationOnChain(credentialStatus, opts.issuer);
}

/**
* Gets partial revocation status info from onchain issuer contract.
*
* @param {CredentialStatus} credentialStatus - credential status section of credential
* @param {Map<number, string>} listofNetworks - list of supported networks. ChainId: RPC URL
* @param {DID} issuerDid - issuer did
* @returns Promise<RevocationStatus>
*/
async getRevocationOnChain(credentialStatus: CredentialStatus): Promise<RevocationStatus> {
async getRevocationOnChain(
credentialStatus: CredentialStatus,
issuer: DID
): Promise<RevocationStatus> {
const { contractAddress, chainId, revocationNonce } = this.parseOnChainId(credentialStatus.id);
if (revocationNonce !== credentialStatus.revocationNonce) {
throw new Error('revocationNonce does not match');
}
const networkConfig = this.networkByChainId(chainId);
const onChainCaller = new OnChainRevocationStorage(networkConfig, contractAddress);
const revocationStatus = await onChainCaller.getRevocationStatus(revocationNonce);
const id = DID.idFromDID(issuer);
const revocationStatus = await onChainCaller.getRevocationStatus(id.bigInt(), revocationNonce);
return revocationStatus;
}

Expand All @@ -52,6 +62,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 +71,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 +87,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
Loading

0 comments on commit 2609c06

Please sign in to comment.