Skip to content

Commit

Permalink
Fix naming and fmt
Browse files Browse the repository at this point in the history
Signed-off-by: lovesh <lovesh.bond@gmail.com>
  • Loading branch information
lovesh committed Mar 8, 2024
1 parent 25d1ede commit 268136f
Show file tree
Hide file tree
Showing 38 changed files with 376 additions and 231 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@docknetwork/crypto-wasm-ts",
"version": "0.53.0",
"version": "0.54.0",
"description": "Typescript abstractions over Dock's Rust crypto library's WASM wrapper",
"homepage": "https://github.com/docknetwork/crypto-wasm-ts",
"main": "lib/index.js",
Expand Down Expand Up @@ -38,7 +38,7 @@
"json-stringify-deterministic": "^1.0.11",
"lodash": "^4.17.21",
"lzutf8": "0.6.3",
"semver": "^7.5.4"
"semver": "^7.6.0"
},
"devDependencies": {
"@types/jest": "^29.1.0",
Expand Down
13 changes: 4 additions & 9 deletions src/anonymous-credentials/blinded-credential-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { CredentialBuilderCommon } from './credential-builder-common';
import { IBlindCredentialRequest } from './presentation-specification';
import {
BBS_PLUS_SIGNATURE_PARAMS_LABEL_BYTES,
BBS_SIGNATURE_PARAMS_LABEL_BYTES, BDDT16_MAC_PARAMS_LABEL_BYTES,
BBS_SIGNATURE_PARAMS_LABEL_BYTES,
BDDT16_MAC_PARAMS_LABEL_BYTES
} from './types-and-consts';
import { BBSCredential, BBSPlusCredential, BDDT16Credential } from './credential';
import { BBSBlindSignature, BBSSecretKey, BBSSignatureParams } from '../bbs';
Expand Down Expand Up @@ -122,13 +123,7 @@ export class BDDT16BlindedCredentialBuilder extends BlindedCredentialBuilder {
): BDDT16BlindedCredential {
const [totalAttrs, encodedAttrs] = this.getTotalAttributesAndEncodedKnownAttributes();
const params = BDDT16MacParams.getMacParamsOfRequiredSize(totalAttrs, sigParams);
const sig = BDDT16BlindMac.generate(
this.blindedCredReq.commitment,
encodedAttrs,
secretKey,
params,
false
);
const sig = BDDT16BlindMac.generate(this.blindedCredReq.commitment, encodedAttrs, secretKey, params, false);
return new BDDT16BlindedCredential(
this.version,
this.schema as CredentialSchema,
Expand All @@ -139,4 +134,4 @@ export class BDDT16BlindedCredentialBuilder extends BlindedCredentialBuilder {
this.credStatus
);
}
}
}
16 changes: 14 additions & 2 deletions src/anonymous-credentials/blinded-credential-request-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { BBSCredential, BBSPlusCredential, PSCredential } from './credential';
import {
AttributeEquality,
BBS_PLUS_SIGNATURE_PARAMS_LABEL_BYTES,
BBS_SIGNATURE_PARAMS_LABEL_BYTES, BDDT16_MAC_PARAMS_LABEL_BYTES,
BBS_SIGNATURE_PARAMS_LABEL_BYTES,
BDDT16_MAC_PARAMS_LABEL_BYTES,
BlindedAttributeEquality,
BlindSignatureType,
BoundCheckParamType,
Expand Down Expand Up @@ -325,7 +326,18 @@ export abstract class BlindedCredentialRequestBuilder<SigParams> extends Version
if (chunkBitSize !== 8 && chunkBitSize !== 16) {
throw new Error(`Only 8 and 16 supported for chunkBitSize but given ${chunkBitSize}`);
}
PresentationBuilder.processVerifiableEncs(this.presentationBuilder, this.verifEnc, attributeName, chunkBitSize, commKeyId, encryptionKeyId, snarkPkId, commKey, encryptionKey, snarkPk);
PresentationBuilder.processVerifiableEncs(
this.presentationBuilder,
this.verifEnc,
attributeName,
chunkBitSize,
commKeyId,
encryptionKeyId,
snarkPkId,
commKey,
encryptionKey,
snarkPk
);
}

enforceCircomPredicateOnBlindedAttribute(
Expand Down
8 changes: 6 additions & 2 deletions src/anonymous-credentials/blinded-credential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import {
BBS_BLINDED_CRED_PROOF_TYPE,
BBS_CRED_PROOF_TYPE,
BBS_PLUS_BLINDED_CRED_PROOF_TYPE,
BBS_PLUS_CRED_PROOF_TYPE, BDDT16_BLINDED_CRED_PROOF_TYPE, BDDT16_CRED_PROOF_TYPE,
BBS_PLUS_CRED_PROOF_TYPE,
BDDT16_BLINDED_CRED_PROOF_TYPE,
BDDT16_CRED_PROOF_TYPE,
PROOF_STR,
TYPE_STR
} from './types-and-consts';
Expand Down Expand Up @@ -49,7 +51,9 @@ export abstract class BlindedCredential<BlindSig> extends CredentialCommon<Blind
}

protected static validateProofType(typ: string) {
if (![BBS_BLINDED_CRED_PROOF_TYPE, BBS_PLUS_BLINDED_CRED_PROOF_TYPE, BDDT16_BLINDED_CRED_PROOF_TYPE].includes(typ)) {
if (
![BBS_BLINDED_CRED_PROOF_TYPE, BBS_PLUS_BLINDED_CRED_PROOF_TYPE, BDDT16_BLINDED_CRED_PROOF_TYPE].includes(typ)
) {
throw new Error(`Invalid proof type ${typ}`);
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/anonymous-credentials/credential-builder-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
SCHEMA_STR,
STATUS_STR,
SUBJECT_STR,
TYPE_STR, MEM_CHECK_KV_STR
TYPE_STR,
MEM_CHECK_KV_STR
} from './types-and-consts';

/**
Expand Down Expand Up @@ -61,7 +62,9 @@ export abstract class CredentialBuilderCommon extends Versioned {

setCredentialStatus(registryId: string, revCheck: string, memberValue: unknown) {
if (revCheck !== MEM_CHECK_STR && revCheck !== NON_MEM_CHECK_STR && revCheck !== MEM_CHECK_KV_STR) {
throw new Error(`Revocation check should be either ${MEM_CHECK_STR} or ${NON_MEM_CHECK_STR} or ${MEM_CHECK_KV_STR} but was ${revCheck}`);
throw new Error(
`Revocation check should be either ${MEM_CHECK_STR} or ${NON_MEM_CHECK_STR} or ${MEM_CHECK_KV_STR} but was ${revCheck}`
);
}
this._credStatus = {
[TYPE_STR]: RevocationStatusProtocol.Vb22,
Expand Down
3 changes: 2 additions & 1 deletion src/anonymous-credentials/credential-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
SCHEMA_STR,
BBS_PLUS_SIGNATURE_PARAMS_LABEL_BYTES,
BBS_SIGNATURE_PARAMS_LABEL_BYTES,
PS_SIGNATURE_PARAMS_LABEL_BYTES, BDDT16_MAC_PARAMS_LABEL_BYTES
PS_SIGNATURE_PARAMS_LABEL_BYTES,
BDDT16_MAC_PARAMS_LABEL_BYTES
} from './types-and-consts';
import { BBSCredential, BBSPlusCredential, BDDT16Credential, Credential, PSCredential } from './credential';
import { flatten } from 'flat';
Expand Down
18 changes: 12 additions & 6 deletions src/anonymous-credentials/credential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import {
PS_SIGNATURE_PARAMS_LABEL_BYTES,
SCHEMA_STR,
STATUS_STR,
SUBJECT_STR, BDDT16_CRED_PROOF_TYPE, BDDT16_MAC_PARAMS_LABEL_BYTES
SUBJECT_STR,
BDDT16_CRED_PROOF_TYPE,
BDDT16_MAC_PARAMS_LABEL_BYTES
} from './types-and-consts';
import { VerifyResult } from 'crypto-wasm-new';
import { BBSPublicKey, BBSSignature, BBSSignatureParams } from '../bbs';
Expand Down Expand Up @@ -221,7 +223,7 @@ export class PSCredential extends Credential<PSPublicKey, PSSignature, PSSignatu

export class BDDT16Credential extends Credential<undefined, BDDT16Mac, BDDT16MacParams> {
verify(publicKey: undefined, signatureParams?: BDDT16MacParams): VerifyResult {
throw new Error(`Not applicable`)
throw new Error(`Not applicable`);
}

/**
Expand All @@ -239,15 +241,19 @@ export class BDDT16Credential extends Credential<undefined, BDDT16Mac, BDDT16Mac
);
}

verifyUsingValidityProof(proof: BDDT16MacProofOfValidity, publicKey: BDDT16MacPublicKeyG1, signatureParams: BDDT16MacParams) : VerifyResult {
verifyUsingValidityProof(
proof: BDDT16MacProofOfValidity,
publicKey: BDDT16MacPublicKeyG1,
signatureParams?: BDDT16MacParams
): VerifyResult {
const cred = this.serializeForSigning();
return proof.verifyMessageObject(
return proof.verifyWithMessageObject(
this.signature,
cred,
publicKey,
signatureParams ?? BDDT16_MAC_PARAMS_LABEL_BYTES,
this.schema.encoder
)
);
}

/**
Expand Down Expand Up @@ -282,4 +288,4 @@ export class BDDT16Credential extends Credential<undefined, BDDT16Mac, BDDT16Mac
static getSigType(): SignatureType {
return SignatureType.Bddt16;
}
}
}
14 changes: 7 additions & 7 deletions src/anonymous-credentials/delegated-proof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import { ID_STR, REV_CHECK_STR, RevocationStatusProtocol, SignatureType, TYPE_ST
import { Versioned } from './versioned';

export interface IDelegatedCredentialProof {
sigType: SignatureType,
proof: BDDT16DelegatedProof
sigType: SignatureType;
proof: BDDT16DelegatedProof;
}

export interface IDelegatedCredentialStatusProof {
[ID_STR]: string;
[TYPE_STR]: RevocationStatusProtocol;
[REV_CHECK_STR]: string;
proof: VBAccumMembershipDelegatedProof
proof: VBAccumMembershipDelegatedProof;
}

export class DelegatedProof extends Versioned {
Expand All @@ -30,10 +30,10 @@ export class DelegatedProof extends Versioned {
}

verify(credentialSecretKey?: BDDT16MacSecretKey, accumSecretKey?: AccumulatorSecretKey): VerifyResult {
const r = {verified: true, error: ""}
const r = { verified: true, error: '' };
if (this.credential !== undefined) {
if (credentialSecretKey === undefined) {
throw new Error('Secret key not provided for credential')
throw new Error('Secret key not provided for credential');
}
const rc = this.credential.proof.verify(credentialSecretKey);
if (!rc.verified) {
Expand All @@ -42,7 +42,7 @@ export class DelegatedProof extends Versioned {
}
if (this.status !== undefined) {
if (accumSecretKey === undefined) {
throw new Error('Secret key not provided for accumulator')
throw new Error('Secret key not provided for accumulator');
}
const rc = this.status.proof.verify(accumSecretKey);
if (!rc.verified) {
Expand All @@ -51,4 +51,4 @@ export class DelegatedProof extends Versioned {
}
return r;
}
}
}
Loading

0 comments on commit 268136f

Please sign in to comment.