forked from Mirrors/doipjs
Allows multiple claim methods
This commit is contained in:
parent
37913c9327
commit
8a1f8ad586
2 changed files with 37 additions and 22 deletions
|
@ -200,33 +200,50 @@ const run = async (proofData, claimData, fingerprint) => {
|
||||||
errors: []
|
errors: []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const claimMethods = Array.isArray(claimData.claim)
|
||||||
|
? claimData.claim
|
||||||
|
: [claimData.claim]
|
||||||
|
|
||||||
switch (claimData.proof.request.format) {
|
switch (claimData.proof.request.format) {
|
||||||
case E.ProofFormat.JSON:
|
case E.ProofFormat.JSON:
|
||||||
|
for (let index = 0; index < claimMethods.length; index++) {
|
||||||
|
const claimMethod = claimMethods[index]
|
||||||
try {
|
try {
|
||||||
res.result = await runJSON(
|
res.result = res.result || await runJSON(
|
||||||
proofData,
|
proofData,
|
||||||
claimData.claim.path,
|
claimMethod.path,
|
||||||
fingerprint,
|
fingerprint,
|
||||||
claimData.claim.format,
|
claimMethod.format,
|
||||||
claimData.claim.relation
|
claimMethod.relation
|
||||||
)
|
)
|
||||||
res.completed = true
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
res.errors.push(error.message ? error.message : error)
|
res.errors.push(error.message ? error.message : error)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
res.completed = true
|
||||||
break
|
break
|
||||||
case E.ProofFormat.TEXT:
|
case E.ProofFormat.TEXT:
|
||||||
|
for (let index = 0; index < claimMethods.length; index++) {
|
||||||
|
const claimMethod = claimMethods[index]
|
||||||
try {
|
try {
|
||||||
res.result = await containsProof(proofData,
|
res.result = res.result || await containsProof(
|
||||||
|
proofData,
|
||||||
fingerprint,
|
fingerprint,
|
||||||
claimData.claim.format)
|
claimMethod.format
|
||||||
res.completed = true
|
)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
res.errors.push('err_unknown_text_verification')
|
res.errors.push('err_unknown_text_verification')
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
res.completed = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reset the errors if one of the claim methods was successful
|
||||||
|
if (res.result) {
|
||||||
|
res.errors = []
|
||||||
|
}
|
||||||
|
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,10 +49,8 @@ const pattern = {
|
||||||
data: _.isObject,
|
data: _.isObject,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
claim: {
|
claim: (x) => {
|
||||||
format: _.isInteger,
|
return _.isObject(x) || _.isArray(x)
|
||||||
relation: _.isInteger,
|
|
||||||
path: _.isArray,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue