Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@arcblock/vc

Package Overview
Dependencies
Maintainers
0
Versions
496
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@arcblock/vc - npm Package Compare versions

Comparing version 1.18.166 to 1.19.0

93

lib/index.js

@@ -36,5 +36,5 @@ /**

* @param {String} params.endpointScope - Endpoint scope, either be public or private
* @returns {object}
* @returns {Promise<object>}
*/
function create({
async function create({
type,

@@ -128,3 +128,3 @@ subject,

if (verify({ vc: result, ownerDid: subject.id, trustedIssuers: [issuerDid] })) {
if (await verify({ vc: result, ownerDid: subject.id, trustedIssuers: [issuerDid] })) {
return result;

@@ -147,5 +147,5 @@ }

* @throws {Error}
* @returns {boolean}
* @returns {Promise<boolean>}
*/
function verify({ vc, ownerDid, trustedIssuers, ignoreExpired = false }) {
async function verify({ vc, ownerDid, trustedIssuers, ignoreExpired = false }) {
// Integrity check

@@ -202,3 +202,3 @@ if (!vc) {

// Verify signature
if (issuer.verify(stringify(clone), fromBase64(signature)) !== true) {
if ((await issuer.verify(stringify(clone), fromBase64(signature))) !== true) {
throw Error('Verifiable credential signature not valid');

@@ -223,5 +223,5 @@ }

* @throws {Error}
* @returns {boolean}
* @returns {Promise<boolean>}
*/
function verifyPresentation({ presentation, trustedIssuers, challenge, ignoreExpired = false }) {
async function verifyPresentation({ presentation, trustedIssuers, challenge, ignoreExpired = false }) {
if (!presentation.challenge || challenge !== presentation.challenge) {

@@ -239,18 +239,20 @@ throw Error('Invalid challenge included on vc presentation');

vcList.forEach((vcStr) => {
const vcObj = JSON.parse(vcStr);
const proof = proofList.find((x) => isFromPublicKey(vcObj.credentialSubject.id, x.pk));
await Promise.all(
vcList.map(async (vcStr) => {
const vcObj = JSON.parse(vcStr);
const proof = proofList.find((x) => isFromPublicKey(vcObj.credentialSubject.id, x.pk));
if (!proof) {
throw Error(`VC does not have corresponding proof: ${vcStr}`);
}
if (!proof) {
throw Error(`VC does not have corresponding proof: ${vcStr}`);
}
const signature = proof.jws;
const holder = fromPublicKey(fromBase58(proof.pk), toTypeInfo(vcObj.credentialSubject.id));
if (holder.verify(stringify(clone), fromBase64(signature)) !== true) {
throw Error('Presentation signature invalid');
}
const signature = proof.jws;
const holder = fromPublicKey(fromBase58(proof.pk), toTypeInfo(vcObj.credentialSubject.id));
if ((await holder.verify(stringify(clone), fromBase64(signature))) !== true) {
throw Error('Presentation signature invalid');
}
verify({ vc: vcObj, ownerDid: vcObj.credentialSubject.id, trustedIssuers, ignoreExpired });
});
await verify({ vc: vcObj, ownerDid: vcObj.credentialSubject.id, trustedIssuers, ignoreExpired });
})
);

@@ -301,3 +303,4 @@ return true;

function verifyCredentialList({ credentials, trustedIssuers }) {
// eslint-disable-next-line require-await
async function verifyCredentialList({ credentials, trustedIssuers }) {
if (!credentials || !Array.isArray(credentials)) {

@@ -307,28 +310,30 @@ throw new Error('Can not verify with empty credentials list');

return credentials.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('Credential not issued by trusted issuers');
}
if (!isFromPublicKey(issuerDid, x.issuer.pk)) {
throw new Error('Credential not issuer pk not match with issuer did');
}
return Promise.all(
credentials.map(async (x) => {
// Verify issuer
const issuers = Array.isArray(trustedIssuers) ? trustedIssuers : [trustedIssuers];
const issuerDid = issuers.find((d) => d === x.issuer.id);
if (!issuerDid) {
throw new Error('Credential not issued by trusted issuers');
}
if (!isFromPublicKey(issuerDid, x.issuer.pk)) {
throw new Error('Credential not issuer pk not match with issuer did');
}
// Construct the issuer wallet
const issuer = fromPublicKey(x.issuer.pk, toTypeInfo(issuerDid));
// 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;
// NOTE: we are ignoring other fields of the proof
const clone = cloneDeep(x);
const signature = clone.proof.jws;
delete clone.proof;
// Verify signature
if (issuer.verify(stringify(clone), fromBase64(signature)) !== true) {
throw Error('Status credential signature not valid');
}
// Verify signature
if ((await issuer.verify(stringify(clone), fromBase64(signature))) !== true) {
throw Error('Status credential signature not valid');
}
return x.claim;
});
return x.claim;
})
);
}

@@ -335,0 +340,0 @@

{
"name": "@arcblock/vc",
"version": "1.18.166",
"version": "1.19.0",
"description": "Javascript lib to work with ArcBlock Verifiable Credentials",

@@ -50,6 +50,6 @@ "keywords": [

"dependencies": {
"@arcblock/did": "1.18.166",
"@ocap/mcrypto": "1.18.166",
"@ocap/util": "1.18.166",
"@ocap/wallet": "1.18.166",
"@arcblock/did": "1.19.0",
"@ocap/mcrypto": "1.19.0",
"@ocap/util": "1.19.0",
"@ocap/wallet": "1.19.0",
"debug": "^4.3.6",

@@ -60,3 +60,3 @@ "is-absolute-url": "^3.0.3",

},
"gitHead": "58c8356b3b8c238728560e4c3fef6ed1704d3ac4"
"gitHead": "1b6fac03988fb18507c8ef4c21de282762005f87"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc