UNPKG

blockstack

Version:

The Blockstack Javascript library for authentication, identity, and storage.

56 lines 2.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const serviceUtils_1 = require("./serviceUtils"); const fetchUtil_1 = require("../../fetchUtil"); /** * @ignore */ class Service { validateProof(proof, ownerAddress, cheerio, name = null) { return tslib_1.__awaiter(this, void 0, void 0, function* () { try { const proofUrl = this.getProofUrl(proof); const res = yield fetchUtil_1.fetchPrivate(proofUrl); if (res.status !== 200) { throw new Error(`Proof url ${proofUrl} returned unexpected http status ${res.status}. Unable to validate proof.`); } const text = yield res.text(); // Validate identity in provided proof body/tags if required if (this.shouldValidateIdentityInBody() && proof.identifier !== this.getProofIdentity(text, cheerio)) { return proof; } const proofText = this.getProofStatement(text, cheerio); proof.valid = serviceUtils_1.containsValidProofStatement(proofText, name) || serviceUtils_1.containsValidAddressProofStatement(proofText, ownerAddress); return proof; } catch (error) { console.error(error); proof.valid = false; return proof; } }); } shouldValidateIdentityInBody() { return false; } prefixScheme(proofUrl) { if (!proofUrl.startsWith('https://') && !proofUrl.startsWith('http://')) { return `https://${proofUrl}`; } else if (proofUrl.startsWith('http://')) { return proofUrl.replace('http://', 'https://'); } else { return proofUrl; } } getProofIdentity(searchText, _cheerio) { return searchText; } } exports.Service = Service; //# sourceMappingURL=service.js.map