-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add 3 ecdsa-sd-2023 proof value tests (D -> C) #101
Open
aljones15
wants to merge
7
commits into
add-cbor-tests-sd
Choose a base branch
from
add-3-sd-proofValue-tests
base: add-cbor-tests-sd
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6424fef
Add test fixture for invalid proofValue prefix.
aljones15 f2563cd
Move base proof assertion to assertions and reuse.
aljones15 31e6d79
Start on invalid disclosure proofValue header.
aljones15 6ae2f34
Fix: getBs funcs are not async.
aljones15 9417172
Restore missing expect to sd suite.
aljones15 e59889f
Append proofValue with invalid proof header bytes.
aljones15 ccccede
Account for keyType when fetching invalid proof header bytes fixture.
aljones15 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -13,6 +13,7 @@ import {klona} from 'klona'; | |||||||||
import varint from 'varint'; | ||||||||||
|
||||||||||
const should = chai.should(); | ||||||||||
const {expect} = chai; | ||||||||||
|
||||||||||
// RegExp with bs58 characters in it | ||||||||||
const bs58 = | ||||||||||
|
@@ -29,18 +30,18 @@ export const proofBytes = { | |||||||||
'P-384': 96 | ||||||||||
}; | ||||||||||
|
||||||||||
export const shouldHaveByteLength = async ( | ||||||||||
export const shouldHaveByteLength = ( | ||||||||||
multibaseString, | ||||||||||
expectedByteLength | ||||||||||
) => { | ||||||||||
const bytes = await getBs58Bytes(multibaseString); | ||||||||||
const bytes = getBs58Bytes(multibaseString); | ||||||||||
bytes.length.should.eql( | ||||||||||
expectedByteLength, | ||||||||||
`Expected byteLength of ${expectedByteLength} received ${bytes.length}.`); | ||||||||||
}; | ||||||||||
|
||||||||||
export const shouldHaveHeaderBytes = async (multibaseString, headerBytes) => { | ||||||||||
const bytes = await getBs64UrlBytes(multibaseString); | ||||||||||
export const shouldHaveHeaderBytes = (multibaseString, headerBytes) => { | ||||||||||
const bytes = getBs64UrlBytes(multibaseString); | ||||||||||
const actualHeaderBytes = Array.from(bytes.slice(0, headerBytes.length)); | ||||||||||
actualHeaderBytes.should.eql( | ||||||||||
Array.from(headerBytes), | ||||||||||
|
@@ -53,7 +54,7 @@ export const shouldBeMulticodecEncoded = async s => { | |||||||||
if(s.startsWith(multibaseMultikeyHeaderP256)) { | ||||||||||
// example of a P-256 publicKeyMultibase - | ||||||||||
// zDnaepHgv4AU1btQ8dp6EYbvgJ6M1ovzKnSpXJUPU2hshXLvp | ||||||||||
const bytes = await getBs58Bytes(s); | ||||||||||
const bytes = getBs58Bytes(s); | ||||||||||
bytes.length.should.equal(35); | ||||||||||
// bytes example => Uint8Array(35) [ | ||||||||||
// 128, 36, 3, 98, 121, 153, 205, 199, | ||||||||||
|
@@ -71,7 +72,7 @@ export const shouldBeMulticodecEncoded = async s => { | |||||||||
} | ||||||||||
|
||||||||||
if(s.startsWith(multibaseMultikeyHeaderP384)) { | ||||||||||
const bytes = await getBs58Bytes(s); | ||||||||||
const bytes = getBs58Bytes(s); | ||||||||||
bytes.length.should.equal(51); | ||||||||||
// get the two-byte prefix | ||||||||||
const prefix = Array.from(bytes.slice(0, 2)); | ||||||||||
|
@@ -182,3 +183,36 @@ export function itRejectsInvalidCryptosuite(expectedValidSuites, { | |||||||||
await verificationFail({credential, verifier: endpoint}); | ||||||||||
}); | ||||||||||
} | ||||||||||
|
||||||||||
export async function shouldBeBaseProofValue({proof, name}) { | ||||||||||
expect( | ||||||||||
proof, | ||||||||||
`Expected VC from issuer ${name} to have an ' + | ||||||||||
'"ecdsa-sd-2023" proof`).to.exist; | ||||||||||
expect( | ||||||||||
proof.proofValue, | ||||||||||
`Expected VC from issuer ${name} to have a ' + | ||||||||||
'"proof.proofValue"` | ||||||||||
).to.exist; | ||||||||||
expect( | ||||||||||
proof.proofValue, | ||||||||||
`Expected VC "proof.proofValue" from issuer ${name} to be ` + | ||||||||||
'a string.' | ||||||||||
).to.be.a.string; | ||||||||||
//Ensure the proofValue string starts with u, indicating that it | ||||||||||
//is a multibase-base64url-no-pad-encoded value, throwing an | ||||||||||
//error if it does not. | ||||||||||
expect( | ||||||||||
proof.proofValue.startsWith('u'), | ||||||||||
`Expected "proof.proofValue" to start with u received ` + | ||||||||||
`${proof.proofValue[0]}`).to.be.true; | ||||||||||
Comment on lines
+207
to
+208
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
// now test the encoding which is bs64 url no pad for this suite | ||||||||||
expect( | ||||||||||
shouldBeBs64UrlNoPad(proof.proofValue), | ||||||||||
'Expected "proof.proofValue" to be bs64 url no pad encoded.' | ||||||||||
Comment on lines
+209
to
+212
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When aimed at humans, best to use the full string for "bs64 url no pad encoded". |
||||||||||
).to.be.true; | ||||||||||
shouldHaveHeaderBytes( | ||||||||||
proof.proofValue, | ||||||||||
new Uint8Array([0xd9, 0x5d, 0x00]) | ||||||||||
); | ||||||||||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either all
Expect ...
clauses should end with a fullstop.
, or none should. I prefer the former.I also note mixed up use of
'
and`
. I strongly advise that these be used consistently, especially but not only in any given statement.I'm not going to make all the suggestions the above would call for, unless you request that I do so. (I'm betting that changes will be needed throughout the documents touched by this PR, and possibly across other documents.)