Skip to content

Commit

Permalink
Minor fixes for encoding
Browse files Browse the repository at this point in the history
Signed-off-by: lovesh <[email protected]>
  • Loading branch information
lovesh committed Jul 17, 2024
1 parent 51c7897 commit 5078ab0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
13 changes: 10 additions & 3 deletions src/anonymous-credentials/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/composite-proof/witness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class Witness {
return generatePoKBBSPlusSignatureWitnessConstantTime(signature.value, unrevealedMessages, encodeMessages);
}

bbdt16Mac(mac: BBDT16Mac, unrevealedMessages: Map<number, Uint8Array>, encodeMessages: boolean): Uint8Array {
static bbdt16Mac(mac: BBDT16Mac, unrevealedMessages: Map<number, Uint8Array>, encodeMessages: boolean): Uint8Array {
return generatePoKBDDT16MacWitness(mac.value, unrevealedMessages, encodeMessages);
}

Expand Down

0 comments on commit 5078ab0

Please sign in to comment.