From 2660c56cd2b379f3e01dcd6b06736e1cbd72caec Mon Sep 17 00:00:00 2001 From: Ilya Date: Tue, 12 Sep 2023 19:35:43 +0300 Subject: [PATCH 1/5] publish genesis state --- src/credentials/credential-wallet.ts | 43 ++++++-- .../status/reverse-sparse-merkle-tree.ts | 101 ++++++++++++------ src/identity/identity-wallet.ts | 53 ++++++++- tests/credentials/mock.ts | 28 +++++ tests/handlers/fetch.test.ts | 1 + tests/identity/id.test.ts | 69 ++++++++++-- 6 files changed, 240 insertions(+), 55 deletions(-) diff --git a/src/credentials/credential-wallet.ts b/src/credentials/credential-wallet.ts index 0f4dcfed..1235d09b 100644 --- a/src/credentials/credential-wallet.ts +++ b/src/credentials/credential-wallet.ts @@ -66,6 +66,7 @@ export interface CredentialRequest { * id: string; * nonce?: number; * type: CredentialStatusType; + * issuerState?: string; * }} * @memberof CredentialRequest */ @@ -73,6 +74,7 @@ export interface CredentialRequest { id: string; nonce?: number; type: CredentialStatusType; + issuerState?: string; }; } @@ -342,19 +344,40 @@ export class CredentialWallet implements ICredentialWallet { type: VerifiableConstants.JSON_SCHEMA_VALIDATOR }; - const id = - request.revocationOpts.type === CredentialStatusType.SparseMerkleTreeProof - ? `${request.revocationOpts.id.replace(/\/$/, '')}/${request.revocationOpts.nonce}` - : request.revocationOpts.id; - - cr.credentialStatus = { - id, - revocationNonce: request.revocationOpts.nonce, - type: request.revocationOpts.type - }; + cr.credentialStatus = this.buildCredentialStatus(request); return cr; }; + + /** + * Builds credential status + * @param {CredentialRequest} request + * @returns `CredentialStatus` + */ + private buildCredentialStatus(request: CredentialRequest): CredentialStatus { + const credentialStatus: CredentialStatus = { + id: request.revocationOpts.id, + type: request.revocationOpts.type, + revocationNonce: request.revocationOpts.nonce + }; + + switch (request.revocationOpts.type) { + case (CredentialStatusType.SparseMerkleTreeProof, + CredentialStatusType.Iden3commRevocationStatusV1): + credentialStatus.id = `${request.revocationOpts.id.replace(/\/$/, '')}/${ + request.revocationOpts.nonce + }`; + break; + case CredentialStatusType.Iden3ReverseSparseMerkleTreeProof: + credentialStatus.id = request.revocationOpts.issuerState + ? `${request.revocationOpts.id}/node?state=${request.revocationOpts.issuerState}` + : `${request.revocationOpts.id}`; + break; + } + + return credentialStatus; + } + /** * {@inheritDoc ICredentialWallet.findById} */ diff --git a/src/credentials/status/reverse-sparse-merkle-tree.ts b/src/credentials/status/reverse-sparse-merkle-tree.ts index 8aa142d2..1fe8cdd0 100644 --- a/src/credentials/status/reverse-sparse-merkle-tree.ts +++ b/src/credentials/status/reverse-sparse-merkle-tree.ts @@ -7,11 +7,12 @@ import { NodeAux, ZERO_HASH, setBitBigEndian, - testBit + testBit, + newHashFromHex } from '@iden3/js-merkletree'; import { IStateStorage } from '../../storage'; import { CredentialStatusResolver, CredentialStatusResolveOptions } from './resolver'; -import { CredentialStatus, RevocationStatus } from '../../verifiable'; +import { CredentialStatus, IssuerData, RevocationStatus } from '../../verifiable'; import { strMTHex } from '../../circuits'; import { VerifiableConstants, CredentialStatusType } from '../../verifiable/constants'; @@ -124,28 +125,12 @@ export class RHSResolver implements CredentialStatusResolver { } try { - return await this.getStatus(credentialStatus, credentialStatusResolveOptions.issuerDID); + return await this.getStatus( + credentialStatus, + credentialStatusResolveOptions.issuerDID, + credentialStatusResolveOptions.issuerData + ); } catch (e: unknown) { - const errMsg = (e as { reason: string })?.reason ?? (e as Error).message ?? (e as string); - if ( - !!credentialStatusResolveOptions.issuerData && - errMsg.includes(VerifiableConstants.ERRORS.IDENTITY_DOES_NOT_EXIST) && - isIssuerGenesis( - credentialStatusResolveOptions.issuerDID.string(), - credentialStatusResolveOptions.issuerData.state.value - ) - ) { - return { - mtp: new Proof(), - issuer: { - state: credentialStatusResolveOptions.issuerData.state.value, - revocationTreeRoot: credentialStatusResolveOptions.issuerData.state.revocationTreeRoot, - rootOfRoots: credentialStatusResolveOptions.issuerData.state.rootOfRoots, - claimsTreeRoot: credentialStatusResolveOptions.issuerData.state.claimsTreeRoot - } - }; - } - if (credentialStatus?.statusIssuer?.type === CredentialStatusType.SparseMerkleTreeProof) { try { return await (await fetch(credentialStatus.id)).json(); @@ -161,21 +146,65 @@ export class RHSResolver implements CredentialStatusResolver { * Gets revocation status from rhs service. * @param {CredentialStatus} credentialStatus * @param {DID} issuerDID + * @param {IssuerData} issuerData * @returns Promise */ private async getStatus( credentialStatus: CredentialStatus, - issuerDID: DID + issuerDID: DID, + issuerData?: IssuerData ): Promise { const id = DID.idFromDID(issuerDID); - const latestStateInfo = await this._state.getLatestStateById(id.bigInt()); + + let latestState: bigint; + try { + const latestStateInfo = await this._state.getLatestStateById(id.bigInt()); + latestState = latestStateInfo?.state || BigInt(0); + } catch (e) { + const errMsg = (e as { reason: string })?.reason ?? (e as Error).message ?? (e as string); + if (errMsg.includes(VerifiableConstants.ERRORS.IDENTITY_DOES_NOT_EXIST)) { + const currentState = this.extractState(credentialStatus.id); + if (!currentState) { + return this.getRevocationStatusFromIssuerData(issuerDID, issuerData); + } + const currentStateBigInt = newHashFromHex(currentState).bigInt(); + if (!isGenesisStateId(id.bigInt(), currentStateBigInt, id.type())) { + throw new Error(`state ${currentState} is not genesis`); + } + latestState = currentStateBigInt; + } else { + throw e; + } + } + + const rhsHost = credentialStatus.id.split('/node')[0]; const hashedRevNonce = newHashFromBigInt(BigInt(credentialStatus.revocationNonce ?? 0)); - const hashedIssuerRoot = newHashFromBigInt(BigInt(latestStateInfo?.state ?? 0)); - return await this.getRevocationStatusFromRHS( - hashedRevNonce, - hashedIssuerRoot, - credentialStatus.id - ); + const hashedIssuerRoot = newHashFromBigInt(latestState); + return await this.getRevocationStatusFromRHS(hashedRevNonce, hashedIssuerRoot, rhsHost); + } + + /** + * Extract revocation status from issuer data. + * @param {DID} issuerDID + * @param {IssuerData} issuerData + */ + private getRevocationStatusFromIssuerData( + issuerDID: DID, + issuerData?: IssuerData + ): RevocationStatus { + if (!!issuerData && isIssuerGenesis(issuerDID.string(), issuerData.state.value)) { + return { + mtp: new Proof(), + issuer: { + state: issuerData.state.value, + revocationTreeRoot: issuerData.state.revocationTreeRoot, + rootOfRoots: issuerData.state.rootOfRoots, + claimsTreeRoot: issuerData.state.claimsTreeRoot + } + }; + } else { + throw new Error(`issuer data is empty`); + } } /** @@ -280,6 +309,16 @@ export class RHSResolver implements CredentialStatusResolver { } return p; } + + /** + * Get state param from rhs url + * @param {string} id + * @returns string | null + */ + private extractState(id: string): string | null { + const u = new URL(id); + return u.searchParams.get('state'); + } } /** diff --git a/src/identity/identity-wallet.ts b/src/identity/identity-wallet.ts index 836fc557..2cbf1a1a 100644 --- a/src/identity/identity-wallet.ts +++ b/src/identity/identity-wallet.ts @@ -34,8 +34,7 @@ import { CredentialStatusType, ProofQuery } from '../verifiable'; -import { CredentialRequest, ICredentialWallet } from '../credentials'; -import { pushHashesToRHS, TreesModel } from '../credentials/rhs'; +import { CredentialRequest, ICredentialWallet, pushHashesToRHS, TreesModel } from '../credentials'; import { TreeState } from '../circuits'; import { byteEncoder } from '../utils'; import { Options, getDocumentLoader } from '@iden3/js-jsonld-merklization'; @@ -223,6 +222,20 @@ export interface IIdentityWallet { */ publishStateToRHS(issuerDID: DID, rhsURL: string, revokedNonces?: number[]): Promise; + /** + * + * + * @param {TreesModel} treeModel - trees model to publish + * @param {string} rhsURL - reverse hash service URL + * @param {number[]} [revokedNonces] - revoked nonces for the period from the last published + * @returns `Promise` + */ + publishSpecificStateToRHS( + treeModel: TreesModel, + rhsURL: string, + revokedNonces?: number[] + ): Promise; + /** * Extracts core claim from signature or merkle tree proof. If both proof persists core claim must be the same * @@ -370,7 +383,8 @@ export class IdentityWallet implements IIdentityWallet { revocationOpts: { nonce: revNonce, id: opts.revocationOpts.id.replace(/\/$/, ''), - type: opts.revocationOpts.type + type: opts.revocationOpts.type, + issuerState: currentState.hex() } }; @@ -409,6 +423,26 @@ export class IdentityWallet implements IIdentityWallet { credential.proof = [mtpProof]; + if (opts.revocationOpts.type === CredentialStatusType.Iden3ReverseSparseMerkleTreeProof) { + const revocationTree = await this._storage.mt.getMerkleTreeByIdentifierAndType( + did.string(), + MerkleTreeType.Revocations + ); + + const rootOfRootsTree = await this._storage.mt.getMerkleTreeByIdentifierAndType( + did.string(), + MerkleTreeType.Roots + ); + + const trees: TreesModel = { + state: currentState, + claimsTree: claimsTree, + revocationTree: revocationTree, + rootsTree: rootOfRootsTree + }; + await pushHashesToRHS(currentState, trees, opts.revocationOpts.id); + } + await this._storage.identity.saveIdentity({ did: did.string(), state: currentState, @@ -618,6 +652,9 @@ export class IdentityWallet implements IIdentityWallet { const jsonSchema = schema as JSONSchema; let credential: W3CCredential = new W3CCredential(); + const issuerRoots = await this.getDIDTreeModel(issuerDID); + req.revocationOpts.issuerState = issuerRoots.state.hex(); + req.revocationOpts.nonce = typeof req.revocationOpts.nonce === 'number' ? req.revocationOpts.nonce @@ -803,10 +840,18 @@ export class IdentityWallet implements IIdentityWallet { return credentials; } + /** {@inheritDoc IIdentityWallet.publishSpecificStateToRHS} */ + async publishSpecificStateToRHS( + treeModel: TreesModel, + rhsURL: string, + revokedNonces?: number[] + ): Promise { + await pushHashesToRHS(treeModel.state, treeModel, rhsURL, revokedNonces); + } + /** {@inheritDoc IIdentityWallet.publishStateToRHS} */ async publishStateToRHS(issuerDID: DID, rhsURL: string, revokedNonces?: number[]): Promise { const treeState = await this.getDIDTreeModel(issuerDID); - await pushHashesToRHS( treeState.state, { diff --git a/tests/credentials/mock.ts b/tests/credentials/mock.ts index e411d69f..b8aa65d3 100644 --- a/tests/credentials/mock.ts +++ b/tests/credentials/mock.ts @@ -83,3 +83,31 @@ export const cred4 = createTestCredential({ expirationDate: '2023-11-11', issuanceDate: '2022-11-11' }); + +export const cred5 = createTestCredential({ + id: 'test4', + '@context': ['context4'], + credentialSchema: { + id: 'credentialSchemaId', + type: 'credentialSchemaType' + }, + proof: ['some proof4'], + type: ['type4'], + credentialStatus: { + id: 'https://rhs-staging.polygonid.me', + type: 'Iden3ReverseSparseMerkleTreeProof', + nonce: 10 + }, + issuer: 'issuer4', + credentialSubject: { + countOfFines: 0, + country: { + name: 'Spain', + code: 'ES', + insured: true, + hasOwnPackage: 'false' + } + }, + expirationDate: '2023-11-11', + issuanceDate: '2022-11-11' +}); diff --git a/tests/handlers/fetch.test.ts b/tests/handlers/fetch.test.ts index 2158db90..afde8fb7 100644 --- a/tests/handlers/fetch.test.ts +++ b/tests/handlers/fetch.test.ts @@ -179,6 +179,7 @@ describe('fetch', () => { }; packageMgr.pack = async (): Promise => byteEncoder.encode(mockedToken); fetchHandler = new FetchHandler(packageMgr); + fetchMock.spy(); fetchMock.post(agentUrl, JSON.parse(mockedCredResponse)); }); diff --git a/tests/identity/id.test.ts b/tests/identity/id.test.ts index db68641b..63738298 100644 --- a/tests/identity/id.test.ts +++ b/tests/identity/id.test.ts @@ -21,6 +21,8 @@ import { CredentialStatusResolverRegistry } from '../../src/credentials'; import { RHSResolver } from '../../src/credentials'; describe('identity', () => { + const rhsURL = process.env.RHS_URL as string; + let credWallet: CredentialWallet; let wallet: IdentityWallet; let dataStorage: IDataStorage; @@ -76,7 +78,7 @@ describe('identity', () => { new RHSResolver(dataStorage.states) ); - const credWallet = new CredentialWallet(dataStorage, resolvers); + credWallet = new CredentialWallet(dataStorage, resolvers); wallet = new IdentityWallet(kms, dataStorage, credWallet); }); it('createIdentity', async () => { @@ -89,7 +91,7 @@ describe('identity', () => { seed: seedPhrase, revocationOpts: { type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof, - id: 'http://rhs.com/node' + id: rhsURL } }); expect(did.string()).to.equal( @@ -115,7 +117,7 @@ describe('identity', () => { seed: seedPhrase, revocationOpts: { type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof, - id: 'http://rhs.com/node' + id: rhsURL } }); expect(did.string()).to.equal( @@ -145,7 +147,7 @@ describe('identity', () => { seed: seedPhrase, revocationOpts: { type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof, - id: 'http://rhs.com/node' + id: rhsURL } }); expect(did.string()).to.equal( @@ -171,7 +173,7 @@ describe('identity', () => { seed: seedPhrase, revocationOpts: { type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof, - id: 'http://rhs.com/node' + id: rhsURL } }); expect(did.string()).to.equal( @@ -192,7 +194,7 @@ describe('identity', () => { seed: seedPhrase, revocationOpts: { type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof, - id: 'http://rhs.com/node' + id: rhsURL } }); expect(did.string()).to.equal( @@ -214,7 +216,7 @@ describe('identity', () => { seed: seedPhrase, revocationOpts: { type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof, - id: 'http://rhs.com/node' + id: rhsURL } }); expect(did.string()).to.equal( @@ -237,7 +239,7 @@ describe('identity', () => { seed: seedPhraseIssuer, revocationOpts: { type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof, - id: 'http://rhs.com/node' + id: rhsURL } }); @@ -254,7 +256,7 @@ describe('identity', () => { seed: seedPhraseUser, revocationOpts: { type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof, - id: 'http://rhs.com/node' + id: rhsURL } }); expect(userAuthCredential).not.to.be.undefined; @@ -271,11 +273,58 @@ describe('identity', () => { expiration: 12345678888, revocationOpts: { type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof, - id: 'http://rhs.com/node' + id: rhsURL } }; const issuerCred = await wallet.issueCredential(issuerDID, claimReq); expect(issuerCred.credentialSubject.id).to.equal(userDID.string()); }); + + it('build non-inclusion proof from issuer data', async () => { + const seedPhraseIssuer: Uint8Array = byteEncoder.encode('seedseedseedseedseedseedseedseed'); + const seedPhraseUser: Uint8Array = byteEncoder.encode('userseedseedseedseedseedseeduser'); + + const { did: issuerDID } = await wallet.createIdentity({ + method: DidMethod.Iden3, + blockchain: Blockchain.Polygon, + networkId: NetworkId.Mumbai, + seed: seedPhraseIssuer, + revocationOpts: { + type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof, + id: rhsURL + } + }); + + const { did: userDID } = await wallet.createIdentity({ + method: DidMethod.Iden3, + blockchain: Blockchain.Polygon, + networkId: NetworkId.Mumbai, + seed: seedPhraseUser, + revocationOpts: { + type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof, + id: rhsURL + } + }); + + const claimReq: 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: 12345678888, + revocationOpts: { + type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof, + id: rhsURL + } + }; + const issuerCred = await wallet.issueCredential(issuerDID, claimReq); + issuerCred.credentialStatus.id = rhsURL; + + credWallet.getRevocationStatusFromCredential(issuerCred); + }); }); From 326f22c23b11aeea9d3ed6a8ae82ba0a9bc85677 Mon Sep 17 00:00:00 2001 From: Ilya Date: Thu, 14 Sep 2023 00:46:30 +0300 Subject: [PATCH 2/5] fix comments --- src/credentials/status/reverse-sparse-merkle-tree.ts | 3 +-- tests/identity/id.test.ts | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/credentials/status/reverse-sparse-merkle-tree.ts b/src/credentials/status/reverse-sparse-merkle-tree.ts index 1fe8cdd0..a7befe0a 100644 --- a/src/credentials/status/reverse-sparse-merkle-tree.ts +++ b/src/credentials/status/reverse-sparse-merkle-tree.ts @@ -202,9 +202,8 @@ export class RHSResolver implements CredentialStatusResolver { claimsTreeRoot: issuerData.state.claimsTreeRoot } }; - } else { - throw new Error(`issuer data is empty`); } + throw new Error(`issuer data is empty`); } /** diff --git a/tests/identity/id.test.ts b/tests/identity/id.test.ts index 63738298..36ca0a91 100644 --- a/tests/identity/id.test.ts +++ b/tests/identity/id.test.ts @@ -12,7 +12,7 @@ import { InMemoryPrivateKeyStore } from '../../src/kms/store'; import { MerkleTreeType } from '../../src/storage/entities/mt'; import { IDataStorage, IStateStorage } from '../../src/storage/interfaces'; import { InMemoryDataSource, InMemoryMerkleTreeStorage } from '../../src/storage/memory'; -import { CredentialRequest, CredentialWallet } from '../../src/credentials'; +import { CredentialRequest, ICredentialWallet, CredentialWallet } from '../../src/credentials'; import { CredentialStatusType, VerifiableConstants, W3CCredential } from '../../src/verifiable'; import { RootInfo, StateProof } from '../../src/storage/entities/state'; import { Blockchain, DidMethod, NetworkId } from '@iden3/js-iden3-core'; @@ -22,7 +22,7 @@ import { RHSResolver } from '../../src/credentials'; describe('identity', () => { const rhsURL = process.env.RHS_URL as string; - let credWallet: CredentialWallet; + let credWallet: ICredentialWallet; let wallet: IdentityWallet; let dataStorage: IDataStorage; @@ -325,6 +325,6 @@ describe('identity', () => { const issuerCred = await wallet.issueCredential(issuerDID, claimReq); issuerCred.credentialStatus.id = rhsURL; - credWallet.getRevocationStatusFromCredential(issuerCred); + await credWallet.getRevocationStatusFromCredential(issuerCred); }); }); From 028425e3da49f73733b6103970882336b8371ded Mon Sep 17 00:00:00 2001 From: Ilya Date: Wed, 20 Sep 2023 22:01:36 +0300 Subject: [PATCH 3/5] fix comments --- src/credentials/credential-wallet.ts | 13 +++++++------ src/credentials/rhs.ts | 2 +- src/identity/identity-wallet.ts | 13 +++++++++---- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/credentials/credential-wallet.ts b/src/credentials/credential-wallet.ts index 1235d09b..478ff625 100644 --- a/src/credentials/credential-wallet.ts +++ b/src/credentials/credential-wallet.ts @@ -362,16 +362,17 @@ export class CredentialWallet implements ICredentialWallet { }; switch (request.revocationOpts.type) { - case (CredentialStatusType.SparseMerkleTreeProof, - CredentialStatusType.Iden3commRevocationStatusV1): - credentialStatus.id = `${request.revocationOpts.id.replace(/\/$/, '')}/${ - request.revocationOpts.nonce + case CredentialStatusType.SparseMerkleTreeProof: + credentialStatus.id = `${credentialStatus.id.replace(/\/$/, '')}/${ + credentialStatus.revocationNonce }`; break; case CredentialStatusType.Iden3ReverseSparseMerkleTreeProof: credentialStatus.id = request.revocationOpts.issuerState - ? `${request.revocationOpts.id}/node?state=${request.revocationOpts.issuerState}` - : `${request.revocationOpts.id}`; + ? `${credentialStatus.id.replace(/\/$/, '')}/node?state=${ + request.revocationOpts.issuerState + }` + : `${credentialStatus.id.replace(/\/$/, '')}`; break; } diff --git a/src/credentials/rhs.ts b/src/credentials/rhs.ts index cd4cfe39..f88f1018 100644 --- a/src/credentials/rhs.ts +++ b/src/credentials/rhs.ts @@ -35,7 +35,7 @@ export interface TreesModel { * @param {number[]} [revokedNonces] - revoked nonces since last published info * @returns void */ -export async function pushHashesToRHS( +export async function publishStateToRHS( state: Hash, trees: TreesModel, rhsUrl: string, diff --git a/src/identity/identity-wallet.ts b/src/identity/identity-wallet.ts index 2cbf1a1a..75477c1d 100644 --- a/src/identity/identity-wallet.ts +++ b/src/identity/identity-wallet.ts @@ -34,7 +34,12 @@ import { CredentialStatusType, ProofQuery } from '../verifiable'; -import { CredentialRequest, ICredentialWallet, pushHashesToRHS, TreesModel } from '../credentials'; +import { + CredentialRequest, + ICredentialWallet, + publishStateToRHS, + TreesModel +} from '../credentials'; import { TreeState } from '../circuits'; import { byteEncoder } from '../utils'; import { Options, getDocumentLoader } from '@iden3/js-jsonld-merklization'; @@ -440,7 +445,7 @@ export class IdentityWallet implements IIdentityWallet { revocationTree: revocationTree, rootsTree: rootOfRootsTree }; - await pushHashesToRHS(currentState, trees, opts.revocationOpts.id); + await publishStateToRHS(currentState, trees, opts.revocationOpts.id); } await this._storage.identity.saveIdentity({ @@ -846,13 +851,13 @@ export class IdentityWallet implements IIdentityWallet { rhsURL: string, revokedNonces?: number[] ): Promise { - await pushHashesToRHS(treeModel.state, treeModel, rhsURL, revokedNonces); + await publishStateToRHS(treeModel.state, treeModel, rhsURL, revokedNonces); } /** {@inheritDoc IIdentityWallet.publishStateToRHS} */ async publishStateToRHS(issuerDID: DID, rhsURL: string, revokedNonces?: number[]): Promise { const treeState = await this.getDIDTreeModel(issuerDID); - await pushHashesToRHS( + await publishStateToRHS( treeState.state, { revocationTree: treeState.revocationTree, From 21ee57754ed52f1a4b684b83f1eaf0906be02c37 Mon Sep 17 00:00:00 2001 From: Ilya Date: Thu, 21 Sep 2023 16:57:33 +0300 Subject: [PATCH 4/5] call publishStateToRHS instead of pushHashesToRHS --- src/credentials/rhs.ts | 2 +- src/identity/identity-wallet.ts | 29 ++++------------------------- 2 files changed, 5 insertions(+), 26 deletions(-) diff --git a/src/credentials/rhs.ts b/src/credentials/rhs.ts index f88f1018..cd4cfe39 100644 --- a/src/credentials/rhs.ts +++ b/src/credentials/rhs.ts @@ -35,7 +35,7 @@ export interface TreesModel { * @param {number[]} [revokedNonces] - revoked nonces since last published info * @returns void */ -export async function publishStateToRHS( +export async function pushHashesToRHS( state: Hash, trees: TreesModel, rhsUrl: string, diff --git a/src/identity/identity-wallet.ts b/src/identity/identity-wallet.ts index 75477c1d..ce539e07 100644 --- a/src/identity/identity-wallet.ts +++ b/src/identity/identity-wallet.ts @@ -34,12 +34,7 @@ import { CredentialStatusType, ProofQuery } from '../verifiable'; -import { - CredentialRequest, - ICredentialWallet, - publishStateToRHS, - TreesModel -} from '../credentials'; +import { CredentialRequest, ICredentialWallet, pushHashesToRHS, TreesModel } from '../credentials'; import { TreeState } from '../circuits'; import { byteEncoder } from '../utils'; import { Options, getDocumentLoader } from '@iden3/js-jsonld-merklization'; @@ -429,23 +424,7 @@ export class IdentityWallet implements IIdentityWallet { credential.proof = [mtpProof]; if (opts.revocationOpts.type === CredentialStatusType.Iden3ReverseSparseMerkleTreeProof) { - const revocationTree = await this._storage.mt.getMerkleTreeByIdentifierAndType( - did.string(), - MerkleTreeType.Revocations - ); - - const rootOfRootsTree = await this._storage.mt.getMerkleTreeByIdentifierAndType( - did.string(), - MerkleTreeType.Roots - ); - - const trees: TreesModel = { - state: currentState, - claimsTree: claimsTree, - revocationTree: revocationTree, - rootsTree: rootOfRootsTree - }; - await publishStateToRHS(currentState, trees, opts.revocationOpts.id); + await this.publishStateToRHS(did, opts.revocationOpts.id); } await this._storage.identity.saveIdentity({ @@ -851,13 +830,13 @@ export class IdentityWallet implements IIdentityWallet { rhsURL: string, revokedNonces?: number[] ): Promise { - await publishStateToRHS(treeModel.state, treeModel, rhsURL, revokedNonces); + await pushHashesToRHS(treeModel.state, treeModel, rhsURL, revokedNonces); } /** {@inheritDoc IIdentityWallet.publishStateToRHS} */ async publishStateToRHS(issuerDID: DID, rhsURL: string, revokedNonces?: number[]): Promise { const treeState = await this.getDIDTreeModel(issuerDID); - await publishStateToRHS( + await pushHashesToRHS( treeState.state, { revocationTree: treeState.revocationTree, From 8b8797cddf14885c58fc5a434c31cb11a8e77522 Mon Sep 17 00:00:00 2001 From: Ilya Date: Tue, 26 Sep 2023 15:54:34 +0300 Subject: [PATCH 5/5] fixs --- src/credentials/credential-wallet.ts | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/credentials/credential-wallet.ts b/src/credentials/credential-wallet.ts index 478ff625..675b4988 100644 --- a/src/credentials/credential-wallet.ts +++ b/src/credentials/credential-wallet.ts @@ -363,20 +363,22 @@ export class CredentialWallet implements ICredentialWallet { switch (request.revocationOpts.type) { case CredentialStatusType.SparseMerkleTreeProof: - credentialStatus.id = `${credentialStatus.id.replace(/\/$/, '')}/${ - credentialStatus.revocationNonce - }`; - break; + return { + ...credentialStatus, + id: `${credentialStatus.id.replace(/\/$/, '')}/${credentialStatus.revocationNonce}` + }; case CredentialStatusType.Iden3ReverseSparseMerkleTreeProof: - credentialStatus.id = request.revocationOpts.issuerState - ? `${credentialStatus.id.replace(/\/$/, '')}/node?state=${ - request.revocationOpts.issuerState - }` - : `${credentialStatus.id.replace(/\/$/, '')}`; - break; + return { + ...credentialStatus, + id: request.revocationOpts.issuerState + ? `${credentialStatus.id.replace(/\/$/, '')}/node?state=${ + request.revocationOpts.issuerState + }` + : `${credentialStatus.id.replace(/\/$/, '')}` + }; + default: + return credentialStatus; } - - return credentialStatus; } /**