Skip to content

Commit

Permalink
Add tests, fix cryptosuite format
Browse files Browse the repository at this point in the history
  • Loading branch information
wes-smith committed Feb 2, 2024
1 parent afaff45 commit 1518661
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export function createCryptosuite({extraInformation = ''} = {}) {
const options = {extraInformation};
return {
name,
canonize,
requiredAlgorithm,
createVerifier,
createVerifyData: _createSignData,
Expand Down
30 changes: 29 additions & 1 deletion test/EcdsaXi2023Cryptosuite.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ import {
ecdsaSecp256KeyPair
} from './mock-data.js';
import {DataIntegrityProof} from '@digitalbazaar/data-integrity';
import {cryptosuite as ecdsaXi2023Cryptosuite} from '../lib/index.js';
import {createCryptosuite} from '../lib/index.js';

Check failure on line 16 in test/EcdsaXi2023Cryptosuite.spec.js

View workflow job for this annotation

GitHub Actions / lint (20.x)

Imports should be sorted alphabetically

import {loader} from './documentLoader.js';

const documentLoader = loader.build();
const extraInformation = '6d721ae5d334cead832a8576bdd24d9a';
const ecdsaXi2023Cryptosuite = createCryptosuite({extraInformation});

describe('EcdsaXi2023Cryptosuite', () => {
describe('exports', () => {
Expand Down Expand Up @@ -189,7 +191,33 @@ describe('EcdsaXi2023Cryptosuite', () => {
expect(error).to.exist;
expect(error.name).to.equal('jsonld.ValidationError');
});

Check failure on line 194 in test/EcdsaXi2023Cryptosuite.spec.js

View workflow job for this annotation

GitHub Actions / lint (20.x)

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

const badCryptosuite = createCryptosuite(100);
const keyPair = await EcdsaMultikey.from({...ecdsaMultikeyKeyPair});
const date = '2023-03-01T21:29:24Z';
const suite = new DataIntegrityProof({
signer: keyPair.signer(), date, cryptosuite: badCryptosuite
});

let error;
try {
await jsigs.sign(unsignedCredential, {
suite,
purpose: new AssertionProofPurpose(),
documentLoader
});
} catch(e) {
error = e;
}

expect(error).to.exist;
expect(error.name).to.equal('jsonld.ValidationError');
});

Check failure on line 220 in test/EcdsaXi2023Cryptosuite.spec.js

View workflow job for this annotation

GitHub Actions / lint (20.x)

Trailing spaces not allowed
it('should fail to sign with incorrect signer algorithm', async () => {
const keyPair = await EcdsaMultikey.from({...ecdsaMultikeyKeyPair});
const date = '2023-03-01T21:29:24Z';
Expand Down

0 comments on commit 1518661

Please sign in to comment.