@sphereon/ssi-sdk.w3c-vc-api-verifier-rest-client
Version:
250 lines (245 loc) • 8.99 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
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;
};
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// plugin.schema.json
var require_plugin_schema = __commonJS({
"plugin.schema.json"(exports, module2) {
module2.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/index.ts
var index_exports = {};
__export(index_exports, {
VcApiVerifierClient: () => VcApiVerifierClient,
events: () => events,
schema: () => schema
});
module.exports = __toCommonJS(index_exports);
// src/types/IVcApiVerifierClient.ts
var events = /* @__PURE__ */ (function(events2) {
events2["CREDENTIAL_VERIFIED"] = "credentialVerified";
return events2;
})({});
// src/agent/VcApiVerifierClient.ts
var import_cross_fetch = __toESM(require("cross-fetch"), 1);
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 (0, import_cross_fetch.default)(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();
//# sourceMappingURL=index.cjs.map