-
Notifications
You must be signed in to change notification settings - Fork 9
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
Fix empty objects in credential throws error #16
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ import { ValueType, ValueTypes } from './schema'; | |
import { Encoder } from '../bbs-plus'; | ||
import { SetupParam, Statement, WitnessEqualityMetaStatement } from '../composite-proof'; | ||
import { SetupParamsTracker } from './setup-params-tracker'; | ||
import { isEmptyObject } from '../util'; | ||
|
||
export function dockAccumulatorParams(): AccumulatorParams { | ||
return Accumulator.generateParams(ACCUMULATOR_PARAMS_LABEL_BYTES); | ||
|
@@ -56,7 +57,8 @@ export function dockSaverEncryptionGensUncompressed(): SaverEncryptionGensUncomp | |
export function flattenTill2ndLastKey(obj: object): [string[], object[]] { | ||
const flattened = {}; | ||
const temp = flatten(obj) as object; | ||
for (const k of Object.keys(temp)) { | ||
const tempKeys = Object.keys(temp).filter((key) => typeof temp[key] !== 'object' || !isEmptyObject(temp[key])); | ||
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. The following for loop is going to iterate over keys of |
||
for (const k of tempKeys) { | ||
// taken from https://stackoverflow.com/a/5555607 | ||
const pos = k.lastIndexOf('.'); | ||
const name = k.substring(0, pos); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -871,4 +871,17 @@ describe('Credential signing and verification', () => { | |
checkResult(recreatedCred.verify(pk)); | ||
} | ||
}); | ||
|
||
it('for credential with auto-generated schema and empty objects', () => { | ||
const builder = new CredentialBuilder(); | ||
builder.schema = new CredentialSchema(CredentialSchema.essential()); | ||
builder.subject = { | ||
fname: 'John', | ||
emptyObject: {}, | ||
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. There should be a similar test for an empty array. |
||
lname: 'Smith', | ||
}; | ||
|
||
const cred = builder.sign(sk, undefined, {requireSameFieldsAsSchema: false}); | ||
checkResult(cred.verify(pk)); | ||
}); | ||
}); |
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.
This isn't needed as it will ignore credential values for which the schema has an empty object type. Such a schema is not valid and an error should be thrown. Secondly, is ignoring those fields what you want?
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.
that is intended, because that value cant exactly be encoded (unless its stringified to {} but that seems pointless to me?)
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.
Why? The schema should never have an empty object.