Skip to content
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 legal country for set and not-set membership proofs #391

Merged
merged 4 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Added

- Add `legalCountry` as an allowed attribute for set/not-set membership proofs.

## 8.0.1

### Breaking changes
Expand Down
8 changes: 7 additions & 1 deletion packages/sdk/src/id/idProofTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,10 @@ export const attributesWithRange: AttributeKey[] = ['dob', 'idDocIssuedAt', 'idD
/**
* The attributes that can be used for (non)membership statements
*/
export const attributesWithSet: AttributeKey[] = ['countryOfResidence', 'nationality', 'idDocType', 'idDocIssuer'];
export const attributesWithSet: AttributeKey[] = [
'countryOfResidence',
'nationality',
'idDocType',
'idDocIssuer',
'legalCountry',
];
5 changes: 5 additions & 0 deletions packages/sdk/src/id/idProofs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ function verifySetStatement(statement: MembershipStatement | NonMembershipStatem
throw new Error('idDocType values must be one from IdDocType enum');
}
break;
case AttributeKeyString.legalCountry:
if (!statement.set.every(isISO3166_1Alpha2)) {
throw new Error(statement.attributeTag + ' values must be ISO3166-1 Alpha 2 codes in upper case');
}
break;
default:
throw new Error(statement.attributeTag + ' is not allowed to be used in ' + typeName + ' statements');
}
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/test/ci/idProofs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ test('Upper bound must be greater than lower bound for attribute statement', ()
test('Unknown attribute tags are rejected', () => {
const builder = new IdStatementBuilder(true);
expect(() => builder.addMembership(-1 as unknown as AttributesKeys, ['DK'])).toThrow();
expect(() => builder.addMembership(15 as unknown as AttributesKeys, ['DK'])).toThrow();
expect(() => builder.addMembership(16 as unknown as AttributesKeys, ['DK'])).toThrow();
expect(() => builder.addMembership(1000 as unknown as AttributesKeys, ['DK'])).toThrow();
});

Expand Down
Loading