Skip to content

Commit

Permalink
Change parameter to Uint8Array, do hashing internally
Browse files Browse the repository at this point in the history
  • Loading branch information
wes-smith committed Feb 5, 2024
1 parent ab02ca6 commit daba1ca
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
6 changes: 4 additions & 2 deletions lib/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ export function createCryptosuite({extraInformation = new Uint8Array()} = {}) {

async function _createSignData({cryptosuite, document, proof, documentLoader}) {
const options = {documentLoader};
const externalHash = cryptosuite.options.extraInformation;

//create hash from extraInformation
const hasher = createHasher();
const externalHash = await hasher.hash(cryptosuite.options.extraInformation);

// canonize and hash proof
const proofHash = await hashCanonizedProof({document, proof, options});

// canonize and hash document
const docCanon = await canonize(document);
const hasher = createHasher();
const docHash = await hasher.hash(stringToUtf8Bytes(docCanon));

// current order of hashing: proof hash + document hash + external hash
Expand Down
11 changes: 9 additions & 2 deletions test/EcdsaXi2023Cryptosuite.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ import {DataIntegrityProof} from '@digitalbazaar/data-integrity';
import {loader} from './documentLoader.js';

const documentLoader = loader.build();
const extraInformation = '6d721ae5d334cead832a8576bdd24d9a';
const extraInformation = new Uint8Array([12, 52, 75, 63, 74, 85, 21, 5, 62, 10,
12, 52, 75, 63, 74, 85, 21, 5, 62, 100,
12, 52, 75, 63, 74, 85, 21, 5, 62, 100,
12, 52, 75, 63, 74, 85, 21, 5, 62, 100,
12, 52, 75, 63, 74, 85, 21, 5, 62, 100,
12, 52, 75, 63, 74, 85, 21, 5, 62, 100,
12, 52, 75, 63
]);
const ecdsaXi2023Cryptosuite = createCryptosuite({extraInformation});

describe('EcdsaXi2023Cryptosuite', () => {
Expand Down Expand Up @@ -192,7 +199,7 @@ describe('EcdsaXi2023Cryptosuite', () => {
expect(error.name).to.equal('jsonld.ValidationError');
});

it('should fail to sign with non-string extraInformation', async () => {
it('should fail to sign with non-bytes extraInformation', async () => {
const unsignedCredential = JSON.parse(JSON.stringify(credential));
unsignedCredential.type.push('UndefinedType');

Expand Down
4 changes: 2 additions & 2 deletions test/testSignVerify.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ const unsignedCredential = {
}
};

const utf8Encode = new TextEncoder();
const extraInformation = utf8Encode.encode('6d721ae5d334cead832a8576bdd24d9a');
const extraInformation = new Uint8Array([12, 52, 75, 63, 74, 85,
21, 5, 62, 100]);

// create suite
const suite = new DataIntegrityProof({
Expand Down

0 comments on commit daba1ca

Please sign in to comment.