From 5078ab01757712b9f1e8f6e25ebd352a0a9cfa02 Mon Sep 17 00:00:00 2001 From: lovesh Date: Wed, 17 Jul 2024 23:22:09 +0530 Subject: [PATCH] Minor fixes for encoding Signed-off-by: lovesh --- package.json | 2 +- src/anonymous-credentials/schema.ts | 13 ++++++++++--- src/composite-proof/witness.ts | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index cb12d50..2849296 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@docknetwork/crypto-wasm-ts", - "version": "0.64.0", + "version": "0.65.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", diff --git a/src/anonymous-credentials/schema.ts b/src/anonymous-credentials/schema.ts index aa66129..e7fdc15 100644 --- a/src/anonymous-credentials/schema.ts +++ b/src/anonymous-credentials/schema.ts @@ -544,6 +544,8 @@ export class CredentialSchema extends Versioned { CredentialSchema.validate(schema); if (overrides !== undefined && overrides.version !== undefined) { + // Revisit: if overrides.version is older, should useConstantTimeEncoder be set to false. This would be overriding + // the caller's intent but looks correct. super(overrides.version); } else { super(CredentialSchema.VERSION); @@ -917,7 +919,9 @@ export class CredentialSchema extends Versioned { } } } - return new CredentialSchema(jsonSchema, parsingOptions, false, { version: version }, fullJsonSchema); + // For older version, a variable time message encoder was mistakenly used + const useConstantTimeEncoder = semver.gte(version, '0.5.0'); + return new CredentialSchema(jsonSchema, parsingOptions, false, { version: version }, fullJsonSchema, useConstantTimeEncoder); } /** @@ -1294,15 +1298,18 @@ export class CredentialSchema extends Versioned { const newJsonSchema = _.cloneDeep(schema.getEmbeddedJsonSchema()) as IEmbeddedJsonSchema; const props = newJsonSchema.properties; CredentialSchema.generateFromCredential(cred, props, schema.version); + // For older version, a variable time message encoder was mistakenly used + const useConstantTimeEncoder = semver.gte(schema.version, '0.5.0'); if (schema.hasEmbeddedJsonSchema()) { - return new CredentialSchema(newJsonSchema, schema.parsingOptions, false, { version: schema.version }); + return new CredentialSchema(newJsonSchema, schema.parsingOptions, false, { version: schema.version }, undefined, useConstantTimeEncoder); } else { return new CredentialSchema( schema.jsonSchema, schema.parsingOptions, false, { version: schema.version }, - newJsonSchema + newJsonSchema, + useConstantTimeEncoder ); } } diff --git a/src/composite-proof/witness.ts b/src/composite-proof/witness.ts index 4241d69..bca58e5 100644 --- a/src/composite-proof/witness.ts +++ b/src/composite-proof/witness.ts @@ -114,7 +114,7 @@ export class Witness { return generatePoKBBSPlusSignatureWitnessConstantTime(signature.value, unrevealedMessages, encodeMessages); } - bbdt16Mac(mac: BBDT16Mac, unrevealedMessages: Map, encodeMessages: boolean): Uint8Array { + static bbdt16Mac(mac: BBDT16Mac, unrevealedMessages: Map, encodeMessages: boolean): Uint8Array { return generatePoKBDDT16MacWitness(mac.value, unrevealedMessages, encodeMessages); }