Skip to content

Commit

Permalink
Format & fix credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
Kolezhniuk committed Jul 13, 2023
1 parent e344fcb commit 22566a9
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 53 deletions.
4 changes: 2 additions & 2 deletions src/circuits/atomic-query-mtp-v2-on-chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ export class AtomicQueryMTPV2OnChainInputs extends BaseConfig {
s.isRevocationChecked = 0;
}

const nodeAuxNonRev = this.claim?.nonRevProof?.proof ?
getNodeAuxValue(this.claim.nonRevProof.proof)
const nodeAuxNonRev = this.claim?.nonRevProof?.proof
? getNodeAuxValue(this.claim.nonRevProof.proof)
: undefined;
s.issuerClaimNonRevMtpAuxHi = nodeAuxNonRev?.key.bigInt().toString();
s.issuerClaimNonRevMtpAuxHv = nodeAuxNonRev?.value.bigInt().toString();
Expand Down
17 changes: 8 additions & 9 deletions src/circuits/atomic-query-sig-v2-on-chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,14 @@ export class AtomicQuerySigV2OnChainInputs extends BaseConfig {
issuerAuthClaimMtp: this.claim?.signatureProof?.issuerAuthIncProof?.proof
? prepareSiblingsStr(this.claim.signatureProof.issuerAuthIncProof.proof, this.getMTLevel())
: undefined,
issuerAuthClaimsTreeRoot: this.claim?.signatureProof?.issuerAuthIncProof?.treeState?.claimsRoot
?.bigInt()
.toString(),
issuerAuthRevTreeRoot: this.claim?.signatureProof?.issuerAuthIncProof?.treeState?.revocationRoot
?.bigInt()
.toString(),
issuerAuthRootsTreeRoot: this.claim?.signatureProof?.issuerAuthIncProof?.treeState?.rootOfRoots
?.bigInt()
.toString(),
issuerAuthClaimsTreeRoot:
this.claim?.signatureProof?.issuerAuthIncProof?.treeState?.claimsRoot?.bigInt().toString(),
issuerAuthRevTreeRoot:
this.claim?.signatureProof?.issuerAuthIncProof?.treeState?.revocationRoot
?.bigInt()
.toString(),
issuerAuthRootsTreeRoot:
this.claim?.signatureProof?.issuerAuthIncProof?.treeState?.rootOfRoots?.bigInt().toString(),

issuerAuthClaimNonRevMtp: this.claim?.signatureProof?.issuerAuthNonRevProof?.proof
? prepareSiblingsStr(
Expand Down
12 changes: 6 additions & 6 deletions src/circuits/atomic-query-sig-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ export class AtomicQuerySigV2Inputs extends BaseConfig {
issuerAuthClaimsTreeRoot: this.claim?.signatureProof?.issuerAuthIncProof.treeState?.claimsRoot
?.bigInt()
.toString(),
issuerAuthRevTreeRoot: this.claim?.signatureProof?.issuerAuthIncProof?.treeState?.revocationRoot
?.bigInt()
.toString(),
issuerAuthRootsTreeRoot: this.claim?.signatureProof?.issuerAuthIncProof?.treeState?.rootOfRoots
?.bigInt()
.toString(),
issuerAuthRevTreeRoot:
this.claim?.signatureProof?.issuerAuthIncProof?.treeState?.revocationRoot
?.bigInt()
.toString(),
issuerAuthRootsTreeRoot:
this.claim?.signatureProof?.issuerAuthIncProof?.treeState?.rootOfRoots?.bigInt().toString(),

issuerAuthClaimNonRevMtp: this.claim?.signatureProof?.issuerAuthNonRevProof?.proof
? prepareSiblingsStr(
Expand Down
28 changes: 13 additions & 15 deletions src/circuits/auth-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ export class AuthV2Inputs extends BaseConfig {
genesisID: this.genesisID?.bigInt().toString(),
profileNonce: this.profileNonce?.toString(),
authClaim: this.authClaim?.marshalJson(),
authClaimIncMtp: this.authClaimIncMtp ?
prepareSiblingsStr(this.authClaimIncMtp, this.getMTLevel()) :
undefined,
authClaimNonRevMtp: this.authClaimNonRevMtp ?
prepareSiblingsStr(this.authClaimNonRevMtp, this.getMTLevel()) :
undefined,
authClaimIncMtp: this.authClaimIncMtp
? prepareSiblingsStr(this.authClaimIncMtp, this.getMTLevel())
: undefined,
authClaimNonRevMtp: this.authClaimNonRevMtp
? prepareSiblingsStr(this.authClaimNonRevMtp, this.getMTLevel())
: undefined,
challenge: this.challenge?.toString(),
challengeSignatureR8x: this.signature?.R8[0].toString(),
challengeSignatureR8y: this.signature?.R8[1].toString(),
Expand All @@ -74,21 +74,19 @@ export class AuthV2Inputs extends BaseConfig {
rootsTreeRoot: this.treeState?.rootOfRoots?.bigInt().toString(),
state: this.treeState?.state?.bigInt().toString(),
gistRoot: this.gistProof?.root.bigInt().toString(),
gistMtp: this.gistProof ?
prepareSiblingsStr(this.gistProof.proof, this.getMTLevelOnChain()) :
undefined
gistMtp: this.gistProof
? prepareSiblingsStr(this.gistProof.proof, this.getMTLevelOnChain())
: undefined
};

const nodeAuxAuth = this.authClaimNonRevMtp ?
getNodeAuxValue(this.authClaimNonRevMtp) :
undefined;
const nodeAuxAuth = this.authClaimNonRevMtp
? getNodeAuxValue(this.authClaimNonRevMtp)
: undefined;
s.authClaimNonRevMtpAuxHi = nodeAuxAuth?.key.bigInt().toString();
s.authClaimNonRevMtpAuxHv = nodeAuxAuth?.value.bigInt().toString();
s.authClaimNonRevMtpNoAux = nodeAuxAuth?.noAux;

const globalNodeAux = this.gistProof ?
getNodeAuxValue(this.gistProof.proof) :
undefined;
const globalNodeAux = this.gistProof ? getNodeAuxValue(this.gistProof.proof) : undefined;
s.gistMtpAuxHi = globalNodeAux?.key.bigInt().toString();
s.gistMtpAuxHv = globalNodeAux?.value.bigInt().toString();
s.gistMtpNoAux = globalNodeAux?.noAux;
Expand Down
2 changes: 1 addition & 1 deletion src/credentials/credential-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ export class CredentialWallet implements ICredentialWallet {
issuerDID: DID,
issuerData: IssuerData
): Promise<RevocationStatus> {
const statusResolver = this._credentialStatusResolverRegistry.get(credStatus.type);
const statusResolver = this._credentialStatusResolverRegistry?.get(credStatus.type);
if (!statusResolver) {
throw new Error(`credential status resolver does not exist for ${credStatus.type} type`);
}
Expand Down
5 changes: 2 additions & 3 deletions src/credentials/status/on-chain-revocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ export class OnChainResolver implements CredentialStatusResolver {
}
// 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);

const parts = contractId.split(':');
const revocationNonce = parseInt(url.searchParams.get('revocationNonce')!, 10);
const parts = contractId!.split(':');
if (parts.length != 2) {
throw new Error('invalid contract address');
}
Expand Down
2 changes: 1 addition & 1 deletion src/credentials/status/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class CredentialStatusResolverRegistry {
this.resolvers.set(type, resolver);
}

get(type: CredentialStatusType): CredentialStatusResolver {
get(type: CredentialStatusType): CredentialStatusResolver | undefined {
return this.resolvers.get(type);
}
}
4 changes: 2 additions & 2 deletions src/credentials/status/reverse-sparse-merkle-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ export class RHSResolver implements CredentialStatusResolver {
): Promise<RevocationStatus> {
try {
return await this.getStatus(credentialStatus, opts);
} catch (e) {
const errMsg = e.reason ?? e.message;
} catch (e: unknown) {
const errMsg = (e as Error).message;
if (
!!opts.issuerData &&
errMsg.includes(VerifiableConstants.ERRORS.IDENTITY_DOES_NOT_EXIST) &&
Expand Down
17 changes: 11 additions & 6 deletions src/credentials/status/sparse-merkle-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ import { newHashFromBigInt, Proof, NodeAux, setBitBigEndian } from '@iden3/js-me

export class IssuerResolver implements CredentialStatusResolver {
async resolve(credentialStatus: CredentialStatus): Promise<RevocationStatus> {
const revStatusDTO = await (await fetch(credentialStatus.id)).json();
return Object.assign(new RevocationStatusDTO(), revStatusDTO).toRevocationStatus();
const revStatusResp = await fetch(credentialStatus.id);
const revStatusDTO = await revStatusResp.json();
return new RevocationStatusDTO(revStatusDTO).toRevocationStatus();
}
}

/**
* Proof dto as a partial result of fetching credential status with type SparseMerkleTreeProof
*
* @export
* @class ProofDTO
* @interface ProofDTO
*/
export class ProofDTO {
export interface ProofDTO {
existence: boolean;
siblings: string[];
node_aux: {
Expand All @@ -32,8 +33,12 @@ export class ProofDTO {
* @class RevocationStatusDTO
*/
export class RevocationStatusDTO {
issuer: Issuer;
mtp: ProofDTO;
issuer!: Issuer;
mtp!: ProofDTO;

constructor(payload: object) {
Object.assign(this, payload);
}

toRevocationStatus(): RevocationStatus {
const p = new Proof();
Expand Down
3 changes: 2 additions & 1 deletion src/iden3comm/packers/jws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ export class JWSPacker implements IPacker {
throw new Error('Missing sender DID');
}

const vmTypes: string[] = SUPPORTED_PUBLIC_KEY_TYPES[params.alg as keyof typeof SUPPORTED_PUBLIC_KEY_TYPES];
const vmTypes: string[] =
SUPPORTED_PUBLIC_KEY_TYPES[params.alg as keyof typeof SUPPORTED_PUBLIC_KEY_TYPES];
if (!vmTypes?.length) {
throw new Error(`No supported verification methods for algorithm ${params.alg}`);
}
Expand Down
4 changes: 3 additions & 1 deletion src/identity/identity-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,9 @@ export class IdentityWallet implements IIdentityWallet {
if (!issuerAuthBJJCredential.proof) {
throw new Error('issuer auth credential must have proof');
}
const mtpAuthBJJProof = (issuerAuthBJJCredential.proof as unknown[])[0] as Iden3SparseMerkleTreeProof;
const mtpAuthBJJProof = (
issuerAuthBJJCredential.proof as unknown[]
)[0] as Iden3SparseMerkleTreeProof;

const sigProof: BJJSignatureProof2021 = {
type: ProofType.BJJSignature,
Expand Down
2 changes: 1 addition & 1 deletion src/proof/proof-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ export class ProofService implements IProofService {
if (sigProof) {
const signature = await bJJSignatureFromHexString(sigProof.signature);
const issuer = DID.parse(sigProof.issuerData.id);

let rs: RevocationStatus | undefined;

if (sigProof.issuerData.credentialStatus) {
Expand Down
3 changes: 2 additions & 1 deletion src/schema-processor/json/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export class JsonSchemaValidator {
if (!draft) {
validator = defaultJSONSchemaValidator;
}
const ajv = JSON_SCHEMA_VALIDATORS_REGISTRY[draft as keyof typeof JSON_SCHEMA_VALIDATORS_REGISTRY];
const ajv =
JSON_SCHEMA_VALIDATORS_REGISTRY[draft as keyof typeof JSON_SCHEMA_VALIDATORS_REGISTRY];
validator = ajv ?? defaultJSONSchemaValidator;
const validate = validator.compile(schema);
const valid = validate(data);
Expand Down
12 changes: 8 additions & 4 deletions src/storage/shared/credential-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ export class CredentialStorage implements ICredentialStorage {
/** {@inheritdoc ICredentialStorage.listCredentials } */
async listCredentials(): Promise<W3CCredential[]> {
let creds = await this._dataSource.load();
let mappedCreds = creds.map((cred) => (cred ? Object.assign(new W3CCredential(), cred) : undefined));
creds = mappedCreds.filter(i => i !== undefined) as W3CCredential[];
let mappedCreds = creds.map((cred) =>
cred ? Object.assign(new W3CCredential(), cred) : undefined
);
creds = mappedCreds.filter((i) => i !== undefined) as W3CCredential[];
return creds;
}

Expand Down Expand Up @@ -64,8 +66,10 @@ export class CredentialStorage implements ICredentialStorage {
filters.every((filter) => filter.execute(credential))
);

const mappedCreds = creds.map((cred) => (cred ? Object.assign(new W3CCredential(), cred) : undefined));
creds = mappedCreds.filter(i => i !== undefined) as W3CCredential[];
const mappedCreds = creds.map((cred) =>
cred ? Object.assign(new W3CCredential(), cred) : undefined
);
creds = mappedCreds.filter((i) => i !== undefined) as W3CCredential[];
return creds;
}
}

0 comments on commit 22566a9

Please sign in to comment.