Skip to content

Commit be576d2

Browse files
committed
Fix error message + use strict equality checks
1 parent 2f3ad30 commit be576d2

File tree

14 files changed

+29
-30
lines changed

14 files changed

+29
-30
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@docknetwork/crypto-wasm-ts",
3-
"version": "0.33.1",
3+
"version": "0.33.2",
44
"description": "Typescript abstractions over Dock's Rust crypto library's WASM wrapper",
55
"homepage": "https://github.com/docknetwork/crypto-wasm-ts",
66
"main": "lib/index.js",

src/accumulator/accumulator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ export class UniversalAccumulator extends Accumulator {
627627
if (storePresent) {
628628
await initialElementsStore.add(e);
629629
}
630-
if (currentBatch.length == batchSize) {
630+
if (currentBatch.length === batchSize) {
631631
// Batch full, take product
632632
products.push(universalAccumulatorComputeInitialFv(currentBatch, secretKey.value));
633633
currentBatch = [];
@@ -800,7 +800,7 @@ export class UniversalAccumulator extends Accumulator {
800800
const ds: Uint8Array[] = [];
801801
for (const member of members) {
802802
currentBatch.push(member);
803-
if (currentBatch.length == batchSize) {
803+
if (currentBatch.length === batchSize) {
804804
ds.push(universalAccumulatorComputeD(nonMember, currentBatch));
805805
currentBatch = [];
806806
}
@@ -874,7 +874,7 @@ export class UniversalAccumulator extends Accumulator {
874874
const members = await state.elements();
875875
for (const member of members) {
876876
currentBatch.push(member);
877-
if (currentBatch.length == batchSize) {
877+
if (currentBatch.length === batchSize) {
878878
// Current batch is full, compute `d` for all non-members
879879
for (let i = 0; i < nonMembers.length; i++) {
880880
dsForAll[i].push(universalAccumulatorComputeD(nonMembers[i], currentBatch));

src/anonymous-credentials/credential-builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ export abstract class CredentialBuilder<SecretKey, PublicKey, Signature, Signatu
204204
}
205205

206206
static hasSameFieldsAsSchema(cred: object, schema: CredentialSchema): boolean {
207-
return areArraysEqual(schema.flatten()[0], Object.keys(flatten(cred) as object).sort());
207+
return areArraysEqual(schema.flatten()[0], Object.keys(flatten(cred)).sort());
208208
}
209209

210210
protected abstract signMessageObject(

src/anonymous-credentials/presentation-builder.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ export class PresentationBuilder extends Versioned {
273273
wasmBytes?: Uint8Array,
274274
provingKey?: LegoProvingKey | LegoProvingKeyUncompressed
275275
) {
276-
if (circuitPrivateVars.length == 0) {
276+
if (circuitPrivateVars.length === 0) {
277277
throw new Error('Provide at least one private variable mapping');
278278
}
279279
this.validateCredIndex(credIdx);
@@ -322,7 +322,7 @@ export class PresentationBuilder extends Versioned {
322322
// Also collect encoded attributes used in any predicate
323323
for (let i = 0; i < numCreds; i++) {
324324
const cred = this.credentials[i][0];
325-
const schema = cred.schema as CredentialSchema;
325+
const schema = cred.schema;
326326
const flattenedSchema = schema.flatten();
327327

328328
const numAttribs = flattenedSchema[0].length;
@@ -425,7 +425,7 @@ export class PresentationBuilder extends Versioned {
425425
}
426426

427427
function circomAttrForSpec(attrName: string, encodedAttrs: Map<number, Uint8Array>): object {
428-
const nameIdx = flattenedSchema[0].indexOf(attrName as string);
428+
const nameIdx = flattenedSchema[0].indexOf(attrName);
429429
encodedAttrs.set(nameIdx, unrevealedAttrsEncoded.get(nameIdx) as Uint8Array);
430430
return unflatten({ [attrName]: null });
431431
}

src/anonymous-credentials/presentation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export class Presentation extends Versioned {
8585
circomOutputs?: Map<number, Uint8Array[][]>
8686
): VerifyResult {
8787
const numCreds = this.spec.credentials.length;
88-
if (publicKeys.length != numCreds) {
88+
if (publicKeys.length !== numCreds) {
8989
throw new Error(`Supply same no of public keys as creds. ${publicKeys.length} != ${numCreds}`);
9090
}
9191

@@ -361,7 +361,7 @@ export class Presentation extends Versioned {
361361
attributeEqualities: this.spec.attributeEqualities
362362
},
363363
attributeCiphertexts,
364-
proof: b58.encode((this.proof as CompositeProofG1).bytes)
364+
proof: b58.encode((this.proof).bytes)
365365
};
366366
}
367367

src/anonymous-credentials/schema.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ export class CredentialSchema extends Versioned {
474474
CredentialSchema.validate(schema);
475475

476476
super(CredentialSchema.VERSION);
477-
this.schema = schema as ISchema;
477+
this.schema = schema;
478478
// This is the schema in JSON-schema format. Kept to output in credentials or in `toJSON` without converting back from
479479
// internal representation; trading off memory for CPU time.
480480
this.jsonSchema = jsonSchema;
@@ -835,7 +835,7 @@ export class CredentialSchema extends Versioned {
835835
terms.add(SCHEMA_STR);
836836
terms.add(CRYPTO_VERSION_STR);
837837

838-
let ctx = {
838+
const ctx = {
839839
dk: 'https://ld.dock.io/credentials#'
840840
};
841841

@@ -890,7 +890,7 @@ export class CredentialSchema extends Versioned {
890890
): object {
891891
// util function needed only in this func
892892
const createFullName = (old: string, neww: string): string => {
893-
return old.length == 0 ? neww : `${old}.${neww}`;
893+
return old.length === 0 ? neww : `${old}.${neww}`;
894894
};
895895

896896
// Will either have a "type" property or will be defined using "$ref"
@@ -1081,14 +1081,14 @@ export class CredentialSchema extends Versioned {
10811081
} else if ('type' in schemaProps[key]) {
10821082
// key in schema
10831083
if (
1084-
schemaProps[key]['type'] == 'string' ||
1085-
schemaProps[key]['type'] == 'integer' ||
1086-
schemaProps[key]['type'] == 'number'
1084+
schemaProps[key]['type'] === 'string' ||
1085+
schemaProps[key]['type'] === 'integer' ||
1086+
schemaProps[key]['type'] === 'number'
10871087
) {
10881088
if (schemaProps[key]['type'] !== typ) {
10891089
throw new Error(`Mismatch in credential and given schema type: ${schemaProps[key]['type']} !== ${typ}`);
10901090
}
1091-
} else if (schemaProps[key]['type'] == 'array' && typ == 'array') {
1091+
} else if (schemaProps[key]['type'] === 'array' && typ === 'array') {
10921092
if (schemaProps[key]['items'].length < value.length) {
10931093
// If cred has more items than schema, add the missing ones
10941094
value.slice(schemaProps[key]['items'].length).forEach((v) => {
@@ -1098,7 +1098,7 @@ export class CredentialSchema extends Versioned {
10981098
// If cred has less items than schema, delete those items
10991099
schemaProps[key]['items'] = schemaProps[key]['items'].slice(0, value.length);
11001100
}
1101-
} else if (schemaProps[key]['type'] == 'object' && typ == 'object') {
1101+
} else if (schemaProps[key]['type'] === 'object' && typ === 'object') {
11021102
const schemaKeys = new Set([...Object.keys(schemaProps[key]['properties'])]);
11031103
const valKeys = new Set([...Object.keys(value)]);
11041104
for (const vk of valKeys) {

src/composite-proof/setup-param.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export class SetupParam extends BytearrayWrapper {
149149
}
150150

151151
static r1cs(r1cs: R1CS | ParsedR1CSFile): SetupParam {
152-
let processedR1cs = getR1CS(r1cs);
152+
const processedR1cs = getR1CS(r1cs);
153153
return new SetupParam(
154154
generateSetupParamForR1CS(
155155
processedR1cs.curveName,

src/composite-proof/statement.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ export class Statement {
490490
wasmBytes: Uint8Array,
491491
snarkPk: LegoProvingKeyUncompressed
492492
): Uint8Array {
493-
let processedR1cs = getR1CS(r1cs);
493+
const processedR1cs = getR1CS(r1cs);
494494
return generateR1CSCircomProverStatement(
495495
processedR1cs.curveName,
496496
processedR1cs.numPublic,
@@ -507,7 +507,7 @@ export class Statement {
507507
wasmBytes: Uint8Array,
508508
snarkPk: LegoProvingKey
509509
): Uint8Array {
510-
let processedR1cs = getR1CS(r1cs);
510+
const processedR1cs = getR1CS(r1cs);
511511
return generateR1CSCircomProverStatement(
512512
processedR1cs.curveName,
513513
processedR1cs.numPublic,

src/encoder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export abstract class MessageEncoder extends BytearrayWrapper {
8888
const chars: string[] = [];
8989
for (let i = 0; i < this.maxEncodedLength; i++) {
9090
// If a null character found then stop looking further
91-
if (decoded.charCodeAt(i) == 0) {
91+
if (decoded.charCodeAt(i) === 0) {
9292
break;
9393
}
9494
chars.push(decoded.charAt(i));

src/ps/signature.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class PSSignature extends MessageEncoder {
3838
throw new Error(
3939
`Number of messages ${
4040
messages.length
41-
} is different from ${params.supportedMessageCount()} supported by the secret key`
41+
} is different from ${secretKey.supportedMessageCount()} supported by the secret key`
4242
);
4343
}
4444
const sig = psSign(messages, secretKey.value, params.value);

0 commit comments

Comments
 (0)