Skip to content

Commit

Permalink
Add test to check if "publicKeyMultibase" is 35 bytes in length and
Browse files Browse the repository at this point in the history
multibase base58-btc encoded.
  • Loading branch information
JSAssassin committed Nov 2, 2023
1 parent 7a3013a commit b3ad55e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
39 changes: 38 additions & 1 deletion tests/10-create.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
* Copyright 2022 Digital Bazaar, Inc. All Rights Reserved
*/

import {bs58Decode, createInitialVc, getPublicKeyBytes} from './helpers.js';
import {
bs58Decode, createInitialVc, getPublicKeyBytes, shouldBeBs58
} from './helpers.js';
import chai from 'chai';
import {
checkDataIntegrityProofFormat
Expand Down Expand Up @@ -75,6 +77,41 @@ describe('eddsa-2022 (create)', function() {
).should.equal(true, 'Expected at least one proof to have "type" ' +
'property value "Multikey".');
});
it('Dereferencing the "verificationMethod" MUST result in an ' +
'object containing a type property with "Multikey" value.',
function() {
verificationMethodDocuments.should.not.eql([], 'Expected ' +
'at least one "verificationMethodDocument".');
verificationMethodDocuments.some(
verificationMethodDocument =>
verificationMethodDocument?.type === 'Multikey'
).should.equal(true, 'Expected at least one proof to have "type" ' +
'property value "Multikey".');
});
it('The "publicKeyMultibase" value of the verification method MUST ' +
'be 35 bytes in length and starts with the base-58-btc prefix (z).',
async function() {
verificationMethodDocuments.should.not.eql([], 'Expected ' +
'at least one "verificationMethodDocument".');
for(const verificationMethodDocument of verificationMethodDocuments) {
const multibase = 'z';
const {publicKeyMultibase} = verificationMethodDocument;
const isMultibaseEncoded =
publicKeyMultibase.startsWith(multibase) &&
shouldBeBs58(publicKeyMultibase);
isMultibaseEncoded.should.equal(
true,
'Expected "publicKeyMultibase" value of the verification ' +
'method to be multibase base58-btc encoded value'
);
const publicKeyMultibaseBytes = bs58Decode({
id: publicKeyMultibase
});
publicKeyMultibaseBytes.byteLength.should.equal(35, 'Expected ' +
'"publicKeyMultibase" value of the verification method to ' +
'be 35 bytes in length.');
}
});
it('"proofValue" field when decoded to raw bytes, MUST be 64 bytes ' +
'in length if the associated public key is 32 bytes or 114 bytes ' +
'in length if the public key is 57 bytes.', async function() {
Expand Down
6 changes: 6 additions & 0 deletions tests/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,9 @@ export const getPublicKeyBytes = async ({did}) => {
export const bs58Decode = ({id}) => decoder.decode(id);

export const bs58Encode = data => encoder.encode(data);

// RegExp with bs58 characters in it
const bs58 =
/^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]+$/;
// assert something is entirely bs58 encoded
export const shouldBeBs58 = s => bs58.test(s);

0 comments on commit b3ad55e

Please sign in to comment.