@arcblock/vc
Advanced tools
Comparing version 1.8.21 to 1.8.22
@@ -177,3 +177,3 @@ /** | ||
* - It is signed by VC's owner | ||
* - It contain chanllege | ||
* - It contain challenge | ||
* - It has valid signature by the issuer | ||
@@ -221,2 +221,71 @@ * - It is not expired | ||
function createStatusList({ statusList, issuer, issuanceDate }) { | ||
if (!statusList || !Array.isArray(statusList) || !statusList.length) { | ||
throw new Error('Can not create with empty status list'); | ||
} | ||
const { wallet, name } = issuer; | ||
const issuerDid = wallet.toAddress(); | ||
const typeInfo = toTypeInfo(issuerDid); | ||
const vcType = { ...typeInfo, role: types.RoleType.ROLE_VC }; | ||
const issued = issuanceDate || new Date().toISOString(); | ||
return statusList.map((x) => { | ||
const vc = { claim: x }; | ||
vc.id = fromPublicKeyHash(wallet.hash(stringify(vc.claim)), vcType); | ||
vc.issued = issued; | ||
vc.issuer = { | ||
id: issuerDid, | ||
pk: toBase58(wallet.publicKey), | ||
name: name || issuerDid, | ||
}; | ||
const signature = wallet.sign(stringify(vc)); | ||
vc.proof = { | ||
type: proofTypes[typeInfo.pk], | ||
created: issued, | ||
proofPurpose: 'assertionMethod', | ||
jws: toBase64(signature), | ||
}; | ||
return vc; | ||
}); | ||
} | ||
function verifyStatusList({ statusList, trustedIssuers }) { | ||
if (!statusList || !Array.isArray(statusList) || !statusList.length) { | ||
throw new Error('Can not verify with empty status list'); | ||
} | ||
return statusList.map((x) => { | ||
// Verify issuer | ||
const issuers = Array.isArray(trustedIssuers) ? trustedIssuers : [trustedIssuers]; | ||
const issuerDid = issuers.find((d) => d === x.issuer.id); | ||
if (!issuerDid) { | ||
throw new Error('Status credential not issued by trusted issuers'); | ||
} | ||
if (!isFromPublicKey(issuerDid, x.issuer.pk)) { | ||
throw new Error('Status credential not issuer pk not match with issuer did'); | ||
} | ||
// Construct the issuer wallet | ||
const issuer = fromPublicKey(x.issuer.pk, toTypeInfo(issuerDid)); | ||
// NOTE: we are ignoring other fields of the proof | ||
const clone = cloneDeep(x); | ||
const signature = clone.proof.jws; | ||
delete clone.proof; | ||
delete clone.signature; | ||
// Verify signature | ||
if (issuer.verify(stringify(clone), fromBase64(signature)) !== true) { | ||
throw Error('Status credential signature not valid'); | ||
} | ||
return x.claim; | ||
}); | ||
} | ||
module.exports = { | ||
@@ -228,2 +297,4 @@ create, | ||
proofTypes, | ||
createStatusList, | ||
verifyStatusList, | ||
}; |
{ | ||
"name": "@arcblock/vc", | ||
"version": "1.8.21", | ||
"version": "1.8.22", | ||
"description": "Javascript lib to work with ArcBlock Verifiable Credentials", | ||
@@ -48,6 +48,6 @@ "keywords": [ | ||
"dependencies": { | ||
"@arcblock/did": "^1.8.21", | ||
"@ocap/mcrypto": "^1.8.21", | ||
"@ocap/util": "^1.8.21", | ||
"@ocap/wallet": "^1.8.21", | ||
"@arcblock/did": "^1.8.22", | ||
"@ocap/mcrypto": "^1.8.22", | ||
"@ocap/util": "^1.8.22", | ||
"@ocap/wallet": "^1.8.22", | ||
"debug": "^4.3.1", | ||
@@ -57,3 +57,3 @@ "json-stable-stringify": "^1.0.1", | ||
}, | ||
"gitHead": "cb4f079d33d05c3d096bdbeceff85cd5ee4902ed" | ||
"gitHead": "97085d6296793205ad7aae0b4c9b7f8a7b7ff62c" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14215
307
+ Added@arcblock/did@1.18.164(transitive)
+ Added@ocap/mcrypto@1.18.164(transitive)
+ Added@ocap/util@1.18.164(transitive)
+ Added@ocap/wallet@1.18.164(transitive)
+ Addedjson-stable-stringify@1.2.1(transitive)
- Removed@arcblock/did@1.18.162(transitive)
- Removed@ocap/mcrypto@1.18.162(transitive)
- Removed@ocap/util@1.18.162(transitive)
- Removed@ocap/wallet@1.18.162(transitive)
- Removedjson-stable-stringify@1.2.0(transitive)
Updated@arcblock/did@^1.8.22
Updated@ocap/mcrypto@^1.8.22
Updated@ocap/util@^1.8.22
Updated@ocap/wallet@^1.8.22