-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update function to check VC validity, add check: whether the attester…
…'s sequence is the same in proof
- Loading branch information
1 parent
d61c738
commit dfd33dc
Showing
7 changed files
with
90 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,9 +14,10 @@ import type { | |
import { isArray, isHex, isJsonObject, isNull, isNumber, isString, isUndefined } from '@polkadot/util'; | ||
|
||
import { isBase32, isBase58, isBase64 } from '@zcloak/crypto'; | ||
import { isDidUrl } from '@zcloak/did/utils'; | ||
import { isAttester, isDidUrl } from '@zcloak/did/utils'; | ||
|
||
import { ALL_HASH_TYPES, ALL_SIG_TYPES, ALL_VP_TYPES } from './defaults'; | ||
import { parseDid } from '@zcloak/did-resolver/parseDid'; | ||
|
||
/** | ||
* @name isHashType | ||
|
@@ -61,6 +62,37 @@ export function isProof(input: unknown): input is Proof { | |
); | ||
} | ||
|
||
/** | ||
* @name isAttesterMapping | ||
* @description | ||
* check the `attester` is the same in [[Proof]] | ||
*/ | ||
export function isAttesterMapping(issuer: unknown, proof: unknown): boolean { | ||
if (isProof(proof)) { | ||
const issuerInProof = parseDid(proof.verificationMethod).did; | ||
return issuer === issuerInProof; | ||
} else return false; | ||
} | ||
|
||
/** | ||
* @name isAttesterProof | ||
* @description | ||
* check the Proof is qualified or not | ||
*/ | ||
export function isAttesterProof(issuer: unknown, proof: unknown): boolean { | ||
// version 0 & version 1, only one attester and one proof | ||
if (typeof issuer === 'string' && isArray(proof) && proof.length === 1) { | ||
return isAttesterMapping(issuer, proof); | ||
} else if (isArray(issuer) && isArray(proof) && issuer.length === proof.length) { | ||
let check = true; | ||
for (let i = 0; i < issuer.length; i++) { | ||
check = isAttesterMapping(issuer[i], proof[i]) && check; | ||
} | ||
return check; | ||
} else { | ||
return false; | ||
} | ||
} | ||
/** | ||
* @name isRawCredential | ||
* @description | ||
|
@@ -118,10 +150,10 @@ export function isVC(input: unknown): input is VerifiableCredential<boolean> { | |
isString(input.version) && | ||
isNumber(input.issuanceDate) && | ||
(isUndefined(input.expirationDate) || isNull(input.expirationDate) || isNumber(input.expirationDate)) && | ||
isDidUrl(input.issuer) && | ||
isAttester(input.issuer, input.version as string) && | ||
This comment has been minimized.
Sorry, something went wrong.
jonathanxuu
Author
Collaborator
|
||
isHex(input.digest) && | ||
isArray(input.proof) && | ||
!input.proof.map((p) => isProof(p)).includes(false) && | ||
isAttesterProof(input.issuer, input.proof) && | ||
isHex(input.ctype) && | ||
(isJsonObject(input.credentialSubject) || isHex(input.credentialSubject)) && | ||
isDidUrl(input.holder) && | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Remove
throw new Error
, change toreturn false
in check functionAlready removed in the next commit