UNPKG

@sphereon/ssi-sdk.w3c-vc-api-verifier-rest-client

Version:

54 lines 2.5 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.VcApiVerifierClient = void 0; const index_1 = require("../index"); const IVcApiVerifierClient_1 = require("../types/IVcApiVerifierClient"); const cross_fetch_1 = require("cross-fetch"); /** * {@inheritDoc IVcApiVerifier} */ class VcApiVerifierClient { constructor(options) { this.schema = index_1.schema.IVcApiVerfierClientAgentPlugin; this.methods = { vcApiClientVerifyCredential: this.vcApiClientVerifyCredential.bind(this), }; this.verifyUrl = options.verifyUrl; } /** {@inheritDoc IVcApiVerifier.vcApiClientVerifyCredential} */ vcApiClientVerifyCredential(args, context) { return __awaiter(this, void 0, void 0, function* () { return yield (0, cross_fetch_1.fetch)(this.verifyUrl, { method: 'post', headers: { Accept: 'application/json', 'Content-Type': 'application/json', }, body: JSON.stringify({ verifiableCredential: args.credential }), }) .then((response) => __awaiter(this, void 0, void 0, function* () { if (response.status >= 400) { throw new Error(yield response.text()); } else { return response.json(); } })) .then((verificationResult) => __awaiter(this, void 0, void 0, function* () { yield context.agent.emit(IVcApiVerifierClient_1.events.CREDENTIAL_VERIFIED, verificationResult); return verificationResult; })); }); } } exports.VcApiVerifierClient = VcApiVerifierClient; //# sourceMappingURL=VcApiVerifierClient.js.map