Skip to content

Commit

Permalink
Fix/cred status publisher (#193)
Browse files Browse the repository at this point in the history
* Fix nullifier session typo, add types to ZeroKnowledgeProofRequest params

* Add mocked publisher
  • Loading branch information
Kolezhniuk authored Mar 7, 2024
1 parent 3052144 commit e23287c
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 26 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@0xpolygonid/js-sdk",
"version": "1.8.1",
"version": "1.8.2",
"description": "SDK to work with Polygon ID",
"main": "dist/node/cjs/index.js",
"module": "dist/node/esm/index.js",
Expand Down
6 changes: 5 additions & 1 deletion src/iden3comm/types/protocol/auth.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ZKProof } from '@iden3/js-jwz';
import { MediaType } from '../../constants';
import { JSONObject, ProtocolMessage } from '../packer';
import { DID } from '@iden3/js-iden3-core';

/** AuthorizationResponseMessage is struct the represents iden3message authorization response */
export type AuthorizationResponseMessage = {
Expand Down Expand Up @@ -46,7 +47,10 @@ export type ZeroKnowledgeProofRequest = {
circuitId: string;
optional?: boolean;
query: JSONObject;
params?: JSONObject;
params?: {
nullifierSessionId?: string | number;
verifierDid?: DID;
};
};

/** ZeroKnowledgeProofResponse represents structure of zkp response */
Expand Down
19 changes: 15 additions & 4 deletions src/identity/identity-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,15 +390,26 @@ export class IdentityWallet implements IIdentityWallet {
credentialStatusPublisherRegistry?: CredentialStatusPublisherRegistry;
}
) {
this._credentialStatusPublisherRegistry = this.getCredentialStatusPublisherRegistry(_opts);
}

private getCredentialStatusPublisherRegistry(
_opts:
| { credentialStatusPublisherRegistry?: CredentialStatusPublisherRegistry | undefined }
| undefined
): CredentialStatusPublisherRegistry {
if (!_opts?.credentialStatusPublisherRegistry) {
this._credentialStatusPublisherRegistry = new CredentialStatusPublisherRegistry();
this._credentialStatusPublisherRegistry.register(
const registry = new CredentialStatusPublisherRegistry();
const emptyPublisher = { publish: () => Promise.resolve() };
registry.register(
CredentialStatusType.Iden3ReverseSparseMerkleTreeProof,
new Iden3SmtRhsCredentialStatusPublisher()
);
registry.register(CredentialStatusType.SparseMerkleTreeProof, emptyPublisher);
registry.register(CredentialStatusType.Iden3commRevocationStatusV1, emptyPublisher);
return registry;
} else {
this._credentialStatusPublisherRegistry = this._opts
?.credentialStatusPublisherRegistry as CredentialStatusPublisherRegistry;
return this._opts?.credentialStatusPublisherRegistry as CredentialStatusPublisherRegistry;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/proof/provers/inputs-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,8 @@ export class InputGenerator {
circuitInputs.proofType = proofType;
circuitInputs.linkNonce = params.linkNonce ?? BigInt(0);
circuitInputs.verifierID = params.verifierDid ? DID.idFromDID(params.verifierDid) : undefined;
circuitInputs.nullifierSessionID = proofReq.params?.nullifierSessionID
? BigInt(proofReq.params?.nullifierSessionID?.toString())
circuitInputs.nullifierSessionID = proofReq.params?.nullifierSessionId
? BigInt(proofReq.params?.nullifierSessionId?.toString())
: BigInt(0);

let isEthIdentity = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
Iden3OnchainSmtCredentialStatusPublisher,
SDK_EVENTS,
MessageBus
} from '../../src';
} from '../../../src';

import {
createIdentity,
Expand All @@ -34,7 +34,7 @@ import {
RPC_URL,
WALLET_KEY,
RHS_CONTRACT_ADDRESS
} from '../helpers';
} from '../../helpers';

import chai from 'chai';
import path from 'path';
Expand Down Expand Up @@ -190,7 +190,7 @@ describe('onchain revocation checks', () => {

beforeEach(async () => {
circuitStorage = new FSCircuitStorage({
dirname: path.join(__dirname, '../proofs/testdata')
dirname: path.join(__dirname, '../../proofs/testdata')
});

const ethStorage = new EthStateStorage({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { InMemoryDataSource } from './../../src/storage/memory/data-source';
import { CredentialStorage } from './../../src/storage/shared/credential-storage';
import { Identity, IdentityStorage, IdentityWallet, Profile, byteEncoder } from '../../src';
import { BjjProvider, KMS, KmsKeyType } from '../../src/kms';
import { InMemoryPrivateKeyStore } from '../../src/kms/store';
import { IDataStorage, IStateStorage } from '../../src/storage/interfaces';
import { InMemoryMerkleTreeStorage } from '../../src/storage/memory';
import { CredentialRequest, CredentialWallet } from '../../src/credentials';
import { defaultEthConnectionConfig, EthStateStorage } from '../../src/storage/blockchain/state';
import { InMemoryDataSource } from '../../../src/storage/memory/data-source';
import { CredentialStorage } from '../../../src/storage/shared/credential-storage';
import { Identity, IdentityStorage, IdentityWallet, Profile, byteEncoder } from '../../../src';
import { BjjProvider, KMS, KmsKeyType } from '../../../src/kms';
import { InMemoryPrivateKeyStore } from '../../../src/kms/store';
import { IDataStorage, IStateStorage } from '../../../src/storage/interfaces';
import { InMemoryMerkleTreeStorage } from '../../../src/storage/memory';
import { CredentialRequest, CredentialWallet } from '../../../src/credentials';
import { defaultEthConnectionConfig, EthStateStorage } from '../../../src/storage/blockchain/state';
import {
CredentialStatus,
CredentialStatusType,
RevocationStatus,
VerifiableConstants,
W3CCredential
} from '../../src/verifiable';
} from '../../../src/verifiable';
import { Proof } from '@iden3/js-merkletree';
import { RootInfo, StateProof } from '../../src/storage/entities/state';
import { RootInfo, StateProof } from '../../../src/storage/entities/state';
import { Blockchain, DidMethod, NetworkId } from '@iden3/js-iden3-core';
import { expect } from 'chai';
import { RHSResolver } from '../../src/credentials';
import { CredentialStatusResolverRegistry } from '../../src/credentials';
import { RHSResolver } from '../../../src/credentials';
import { CredentialStatusResolverRegistry } from '../../../src/credentials';

describe('rhs', () => {
let idWallet: IdentityWallet;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { IdentityWallet } from '../../../src';
import { IDataStorage } from '../../../src/storage/interfaces';
import { CredentialRequest, CredentialWallet } from '../../../src/credentials';
import { CredentialStatusType } from '../../../src/verifiable';
import { expect } from 'chai';
import {
MOCK_STATE_STORAGE,
SEED_USER,
createIdentity,
getInMemoryDataStorage,
registerBJJIntoInMemoryKMS
} from '../../helpers';
import { DID } from '@iden3/js-iden3-core';
import fetchMock from '@gr2m/fetch-mock';
import { Proof, ZERO_HASH } from '@iden3/js-merkletree';

describe('SparseMerkleTreeProof', () => {
let idWallet: IdentityWallet;
let credWallet: CredentialWallet;

let dataStorage: IDataStorage;

let userDID: DID;
let issuerDID: DID;
const walletUrl = 'https://user-wallet.com';
const issuerWalletUrl = 'https://issuer.com';

beforeEach(async () => {
const kms = registerBJJIntoInMemoryKMS();
dataStorage = getInMemoryDataStorage(MOCK_STATE_STORAGE);

credWallet = new CredentialWallet(dataStorage);
idWallet = new IdentityWallet(kms, dataStorage, credWallet);

const { did: didUser, credential: userAuthCredential } = await createIdentity(idWallet, {
seed: SEED_USER,
revocationOpts: {
type: CredentialStatusType.SparseMerkleTreeProof,
id: walletUrl
}
});
userDID = didUser;

expect(userAuthCredential).not.to.be.undefined;

const { did: didIssuer, credential: issuerAuthCredential } = await createIdentity(idWallet, {
revocationOpts: {
type: CredentialStatusType.SparseMerkleTreeProof,
id: issuerWalletUrl
}
});
expect(issuerAuthCredential).not.to.be.undefined;
issuerDID = didIssuer;
const mockRevStatus = JSON.stringify({
mtp: new Proof(),
issuer: {
state: ZERO_HASH.hex(),
claimsTreeRoot: ZERO_HASH.hex(),
revocationTreeRoot: ZERO_HASH.hex(),
rootOfRoots: ZERO_HASH.hex()
}
});
fetchMock.spy();
fetchMock.mock(`begin:${walletUrl}`, mockRevStatus);
fetchMock.mock(`begin:${issuerWalletUrl}`, mockRevStatus);
});

afterEach(() => {
fetchMock.restore();
});

it('issue credential', async () => {
const credRequest: CredentialRequest = {
credentialSchema:
'https://raw.githubusercontent.com/iden3/claim-schema-vocab/main/schemas/json/kyc-nonmerklized.json',
type: 'KYCAgeCredential',
credentialSubject: {
id: userDID.string(),
birthday: 19960424,
documentType: 99
},
expiration: 2793526400,
revocationOpts: {
type: CredentialStatusType.SparseMerkleTreeProof,
id: walletUrl
}
};
const issuedCredential = await idWallet.issueCredential(issuerDID, credRequest);

await credWallet.save(issuedCredential);

expect(issuedCredential).not.to.be.undefined;
});
});

0 comments on commit e23287c

Please sign in to comment.