Skip to content

Commit

Permalink
Merge pull request #391 from Concordium/fix-set-membership-proof-for-…
Browse files Browse the repository at this point in the history
…legal-country

Add legal country for set and not-set membership proofs
  • Loading branch information
DOBEN authored Sep 12, 2024
2 parents 7253e91 + 6c9e337 commit 36b6354
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
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

0 comments on commit 36b6354

Please sign in to comment.