Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

publish genesis state #133

Merged
merged 5 commits into from
Sep 26, 2023
Merged

Conversation

ilya-korotya
Copy link
Contributor

No description provided.

credentialStatus.id = request.revocationOpts.issuerState
? `${request.revocationOpts.id}/node?state=${request.revocationOpts.issuerState}`
: `${request.revocationOpts.id}`;
break;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect default keyword which throws Error

Copy link
Contributor Author

@ilya-korotya ilya-korotya Sep 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For SparseMerkleTreeProof, Iden3commRevocationStatusV1, Iden3ReverseSparseMerkleTreeProof types we have to modify the id field. All other types remain unchanged

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add default keyword to switch statement which will throw an Error in case for some reasons request.revocationOpts.type none of available cases

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How I understand this regexp cuts end '/'. We should cut the last '/' for the agent endpoint also to be sure that SDK will not create a URL like https/agent//

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kolezhniuk @vmidylli about the default case. I disagree that we should return an error if we have an unknown type.

  1. What if the user implements a custom revocation type?
  2. We have strict typing to protect against dummy users.
  3. SDK should be flexible. All validation should be on the user side. Because we cannot know all the use cases of this SDK

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ilya-korotya ok, in case we don't need to throw an Error, I would expect default statement in any case where you need to use switch to make logic flow explicitly

default:
        return credentialStatus;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/**
   * 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:
      case CredentialStatusType.Iden3commRevocationStatusV1:
        return {
          ...credentialStatus,
          id: `${request.revocationOpts.id.replace(/\/$/, '')}/${request.revocationOpts.nonce}`
        };
      case CredentialStatusType.Iden3ReverseSparseMerkleTreeProof:
        return {
          ...credentialStatus,
          id: request.revocationOpts.issuerState
            ? `${request.revocationOpts.id}/node?state=${request.revocationOpts.issuerState}`
            : `${request.revocationOpts.id}`
        };
      default:
        return credentialStatus;
    }
  }

claimsTreeRoot: issuerData.state.claimsTreeRoot
}
};
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need else here

@@ -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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use ICredentialWallet

const issuerCred = await wallet.issueCredential(issuerDID, claimReq);
issuerCred.credentialStatus.id = rhsURL;

credWallet.getRevocationStatusFromCredential(issuerCred);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess await missed here

credentialStatus.id = request.revocationOpts.issuerState
? `${request.revocationOpts.id}/node?state=${request.revocationOpts.issuerState}`
: `${request.revocationOpts.id}`;
break;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add default keyword to switch statement which will throw an Error in case for some reasons request.revocationOpts.type none of available cases

credentialStatus.id = request.revocationOpts.issuerState
? `${request.revocationOpts.id}/node?state=${request.revocationOpts.issuerState}`
: `${request.revocationOpts.id}`;
break;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 427 to 443
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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we just call publishStateToRHS here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I did it

@@ -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(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure that we want to check public interface here? I think it is better to live it as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vmidyllic we discussed it. And we decided to add export to this function and call it inside on identity-wallet.ts

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was exported already, so this is a problem of renaming already exported function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I returned old name

};

switch (request.revocationOpts.type) {
case (CredentialStatusType.SparseMerkleTreeProof,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to write

case CredentialStatusType.SparseMerkleTreeProof:
case CredentialStatusType.Iden3commRevocationStatusV1:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is already fixed

credentialStatus.id = request.revocationOpts.issuerState
? `${request.revocationOpts.id}/node?state=${request.revocationOpts.issuerState}`
: `${request.revocationOpts.id}`;
break;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/**
   * 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:
      case CredentialStatusType.Iden3commRevocationStatusV1:
        return {
          ...credentialStatus,
          id: `${request.revocationOpts.id.replace(/\/$/, '')}/${request.revocationOpts.nonce}`
        };
      case CredentialStatusType.Iden3ReverseSparseMerkleTreeProof:
        return {
          ...credentialStatus,
          id: request.revocationOpts.issuerState
            ? `${request.revocationOpts.id}/node?state=${request.revocationOpts.issuerState}`
            : `${request.revocationOpts.id}`
        };
      default:
        return credentialStatus;
    }
  }

@vmidyllic vmidyllic merged commit 5ffd319 into main Sep 26, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants