Skip to content

Commit

Permalink
Merge branch 'master' into feat/update-examples
Browse files Browse the repository at this point in the history
  • Loading branch information
maycon-mello authored Dec 17, 2024
2 parents 9d153cd + b75b6b7 commit c513ccf
Show file tree
Hide file tree
Showing 2 changed files with 215 additions and 8 deletions.
20 changes: 12 additions & 8 deletions packages/wasm/src/services/credential/pex-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,20 @@ export function pexToBounds(
index,
});

bounds.push({
attributeName,
min,
max,
type,
format,
});
if (attributeName !== undefined) {
bounds.push({
attributeName,
min,
max,
type,
format,
});
}
});

descriptorBounds.push(bounds);
if (bounds.length) {
descriptorBounds.push(bounds);
}
});

return descriptorBounds;
Expand Down
203 changes: 203 additions & 0 deletions packages/wasm/src/services/credential/pex-helpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,5 +409,208 @@ describe('pex helpers', () => {

expect(bounds).toEqual([]);
});

it('should not have undefined attributeNames, exclude not found bounds', () => {
const pexRequest = {
id: '3cb2c1db-54d7-427a-a6a2-4b8f73a33700',
input_descriptors: [
{
id: 'Credential 1',
name: 'Mortgage Application Qualification',
group: ['A'],
purpose:
'Proof of assets (>100k), employment, and credit score (>800)',
constraints: {
fields: [
{
path: ['$.credentialSubject.id'],
optional: true,
},
{
path: ['$.credentialSchema.id'],
filter: {
const:
'https://schema.dock.io/ProofOfEmployment-V1-1703767227542.json',
},
},
{
path: ['$.expirationDate', '$.vc.expirationDate'],
filter: {
type: 'string',
format: 'date-time',
formatMinimum: '2024-12-10T00:00:00.000Z',
},
optional: true,
predicate: 'required',
},
],
},
},
{
id: 'Credential 2',
name: 'Mortgage Application Qualification',
group: ['A'],
purpose:
'Proof of assets (>100k), employment, and credit score (>800)',
constraints: {
fields: [
{
path: ['$.credentialSubject.id'],
optional: true,
},
{
path: ['$.expirationDate'],
optional: true,
},
{
path: ['$.credentialSchema.id'],
filter: {
const:
'https://schema.dock.io/CreditScore-V1-1732907844039.json',
},
},
{
path: ['$.credentialSubject.creditScore'],
filter: {
type: 'number',
minimum: 800,
},
predicate: 'required',
},
],
},
},
{
id: 'Credential 3',
name: 'Mortgage Application Qualification',
group: ['A'],
purpose:
'Proof of assets (>100k), employment, and credit score (>800)',
constraints: {
fields: [
{
path: ['$.credentialSubject.id'],
optional: true,
},
{
path: ['$.expirationDate'],
optional: true,
},
{
path: ['$.credentialSchema.id'],
filter: {
const:
'https://schema.dock.io/ProofOfAssets-V1-1733843536548.json',
},
},
{
path: ['$.credentialSubject.sIN'],
optional: true,
},
{
path: ['$.credentialSubject.name'],
optional: true,
},
{
path: ['$.credentialSubject.propertiesOwned'],
filter: {
type: 'number',
minimum: 1,
},
predicate: 'required',
},
{
path: ['$.credentialSubject.totalPropertyAssetValue'],
filter: {
type: 'number',
minimum: 100000,
},
predicate: 'required',
},
],
},
},
],
submission_requirements: [
{
from: 'A',
name: 'Multi Credential Request',
rule: 'pick',
count: 1,
},
],
};

const bounds = pexToBounds(pexRequest, [
{
'@context': [
'https://www.w3.org/2018/credentials/v1',
'https://ld.dock.io/credentials/extensions-v1',
'https://ld.dock.io/security/bbs23/v1',
{
CreditScore: 'dk:CreditScore',
bankruptcies: 'dk:bankruptcies',
creditScore: 'dk:creditScore',
dk: 'https://ld.dock.io/credentials#',
},
],
credentialStatus: {
id: 'dock:accumulator:0xb803980eb9433bb5d5d433f60c08fcd17e82eb2eb8ae3ac88fef79a3fb2f5fd9',
type: 'DockVBAccumulator2022',
revocationCheck: 'membership',
revocationId: '7',
},
id: 'https://creds-testnet.dock.io/15ca3b92504514756671ab5377ef23f7407f1c26c692b60363c97ba4775abab3',
type: ['VerifiableCredential', 'CreditScore'],
credentialSubject: {
name: 'tester',
creditScore: 800,
bankruptcies: 0,
},
issuanceDate: '2024-12-13T12:43:20.925Z',
issuer: {
name: 'CIBC',
description: 'CIBC - a bank',
logo: 'https://img.dock.io/e5715cbf78f2222924f5fe4e109d76a5',
id: 'did:dock:5CwdfTvda68vfdLu4yxNRFHuhdiXDzqLxw5TkoMfX6sC784a',
},
credentialSchema: {
id: 'https://schema.dock.io/CreditScore-V1-1732907844039.json',
type: 'JsonSchemaValidator2018',
details:
'{"jsonSchema":{"$id":"https://schema.dock.io/CreditScore-V1-1732907844039.json","$schema":"http://json-schema.org/draft-07/schema#","additionalProperties":true,"description":"Proof of Credit","name":"Credit Score","properties":{"@context":{"type":"string"},"credentialSchema":{"properties":{"details":{"type":"string"},"id":{"type":"string"},"type":{"type":"string"},"version":{"type":"string"}},"type":"object"},"credentialStatus":{"properties":{"id":{"type":"string"},"revocationCheck":{"type":"string"},"revocationId":{"type":"string"},"type":{"type":"string"}},"type":"object"},"credentialSubject":{"properties":{"bankruptcies":{"description":"How many times have you declared bankruptcy","title":"Bankruptcies","type":"integer"},"creditScore":{"description":"","title":"Credit Score","type":"number"},"name":{"description":"Name of individual","title":"Name","type":"string"}},"required":["creditScore","bankruptcies","name"],"type":"object"},"cryptoVersion":{"type":"string"},"id":{"type":"string"},"issuanceDate":{"format":"date-time","type":"string"},"issuer":{"properties":{"description":{"type":"string"},"id":{"type":"string"},"logo":{"type":"string"},"name":{"type":"string"}},"type":"object"},"name":{"type":"string"},"proof":{"properties":{"@context":{"items":[{"properties":{"proof":{"properties":{"@container":{"type":"string"},"@id":{"type":"string"},"@type":{"type":"string"}},"type":"object"},"sec":{"type":"string"}},"type":"object"},{"type":"string"}],"type":"array"},"created":{"format":"date-time","type":"string"},"proofPurpose":{"type":"string"},"type":{"type":"string"},"verificationMethod":{"type":"string"}},"type":"object"},"type":{"type":"string"}},"type":"object"},"parsingOptions":{"defaultDecimalPlaces":4,"defaultMinimumDate":-17592186044415,"defaultMinimumInteger":-4294967295,"useDefaults":true}}',
version: '0.4.0',
},
name: 'Credit Score',
cryptoVersion: '0.6.0',
proof: {
'@context': [
{
sec: 'https://w3id.org/security#',
proof: {
'@id': 'sec:proof',
'@type': '@id',
'@container': '@graph',
},
},
'https://ld.dock.io/security/bbs23/v1',
],
type: 'Bls12381BBSSignatureDock2023',
created: '2024-12-13T12:43:42Z',
verificationMethod:
'did:dock:5CwdfTvda68vfdLu4yxNRFHuhdiXDzqLxw5TkoMfX6sC784a#keys-2',
proofPurpose: 'assertionMethod',
proofValue:
'z2PyUbLtaHuMbrdJagELMtFqroKXSoxtMaKLshc3PvT7VXpCHWWeeDMkvGf8MoKjjhNfwGPEXn9zYZuyZv7JGETWXs2TU2aSaKAHkvcmnVXcu8D',
},
},
]);

bounds.forEach(() => {
expect(
bounds[0].every(bound => bound.attributeName !== undefined),
).toBe(true);
});
});
});
});

0 comments on commit c513ccf

Please sign in to comment.