@sphereon/ssi-sdk.w3c-vc-api-verifier-rest-client
Version:
220 lines (216 loc) • 7.46 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
var __commonJS = (cb, mod) => function __require() {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
// plugin.schema.json
var require_plugin_schema = __commonJS({
"plugin.schema.json"(exports, module) {
module.exports = {
IVcApiVerifierClient: {
components: {
schemas: {
IVerifyCredentialArgs: {
type: "object",
properties: {
credential: {
$ref: "#/components/schemas/CredentialPayload"
}
},
required: [
"credential"
],
additionalProperties: false
},
CredentialPayload: {
type: "object",
properties: {
issuer: {
$ref: "#/components/schemas/IssuerType"
},
credentialSubject: {
$ref: "#/components/schemas/CredentialSubject"
},
type: {
type: "array",
items: {
type: "string"
}
},
"@context": {
type: "array",
items: {
type: "string"
}
},
issuanceDate: {
$ref: "#/components/schemas/DateType"
},
expirationDate: {
$ref: "#/components/schemas/DateType"
},
credentialStatus: {
$ref: "#/components/schemas/CredentialStatusReference"
},
id: {
type: "string"
}
},
required: [
"issuer"
],
description: "Used as input when creating Verifiable Credentials"
},
IssuerType: {
anyOf: [
{
type: "object",
properties: {
id: {
type: "string"
}
},
required: [
"id"
]
},
{
type: "string"
}
],
description: "The issuer of a {@link VerifiableCredential } or the holder of a {@link VerifiablePresentation } .\n\nThe value of the issuer property MUST be either a URI or an object containing an id property. It is RECOMMENDED that the URI in the issuer or its id be one which, if de-referenced, results in a document containing machine-readable information about the issuer that can be used to verify the information expressed in the credential.\n\nSee {@link https://www.w3.org/TR/vc-data-model/#issuer | Issuer data model }"
},
CredentialSubject: {
type: "object",
properties: {
id: {
type: "string"
}
},
description: "The value of the credentialSubject property is defined as a set of objects that contain one or more properties that are each related to a subject of the verifiable credential. Each object MAY contain an id.\n\nSee {@link https://www.w3.org/TR/vc-data-model/#credential-subject | Credential Subject }"
},
DateType: {
anyOf: [
{
type: "string"
},
{
type: "string",
format: "date-time"
}
],
description: "Represents an issuance or expiration date for Credentials / Presentations. This is used as input when creating them."
},
CredentialStatusReference: {
type: "object",
properties: {
id: {
type: "string"
},
type: {
type: "string"
}
},
required: [
"id",
"type"
],
description: "Used for the discovery of information about the current status of a verifiable credential, such as whether it is suspended or revoked. The precise contents of the credential status information is determined by the specific `credentialStatus` type definition, and varies depending on factors such as whether it is simple to implement or if it is privacy-enhancing.\n\nSee {@link https://www.w3.org/TR/vc-data-model/#status | Credential Status }"
},
IVerifyCredentialResult: {
type: "object",
properties: {
checks: {
type: "array",
items: {
type: "string"
}
},
errors: {
type: "array",
items: {
type: "string"
}
},
warnings: {
type: "array",
items: {
type: "string"
}
}
},
required: [
"checks",
"errors",
"warnings"
],
additionalProperties: false
}
},
methods: {
vcApiClientVerifyCredential: {
description: "",
arguments: {
$ref: "#/components/schemas/IVerifyCredentialArgs"
},
returnType: {
$ref: "#/components/schemas/IVerifyCredentialResult"
}
}
}
}
}
};
}
});
// src/types/IVcApiVerifierClient.ts
var events = /* @__PURE__ */ (function(events2) {
events2["CREDENTIAL_VERIFIED"] = "credentialVerified";
return events2;
})({});
// src/agent/VcApiVerifierClient.ts
import fetch from "cross-fetch";
var VcApiVerifierClient = class {
static {
__name(this, "VcApiVerifierClient");
}
schema = schema.IVcApiVerfierClientAgentPlugin;
methods = {
vcApiClientVerifyCredential: this.vcApiClientVerifyCredential.bind(this)
};
verifyUrl;
constructor(options) {
this.verifyUrl = options.verifyUrl;
}
/** {@inheritDoc IVcApiVerifier.vcApiClientVerifyCredential} */
async vcApiClientVerifyCredential(args, context) {
return await fetch(this.verifyUrl, {
method: "post",
headers: {
Accept: "application/json",
"Content-Type": "application/json"
},
body: JSON.stringify({
verifiableCredential: args.credential
})
}).then(async (response) => {
if (response.status >= 400) {
throw new Error(await response.text());
} else {
return response.json();
}
}).then(async (verificationResult) => {
await context.agent.emit(events.CREDENTIAL_VERIFIED, verificationResult);
return verificationResult;
});
}
};
// src/index.ts
var schema = require_plugin_schema();
export {
VcApiVerifierClient,
events,
schema
};
//# sourceMappingURL=index.js.map