UNPKG

blockstack

Version:

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

50 lines 1.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); // @ts-ignore: Could not find a declaration file for module const inspector = require("schema-inspector"); const profileTokens_1 = require("./profileTokens"); const profileProofs_1 = require("./profileProofs"); const profileZoneFiles_1 = require("./profileZoneFiles"); const schemaDefinition = { type: 'object', properties: { '@context': { type: 'string', optional: true }, '@type': { type: 'string' } } }; /** * Represents a user profile * */ class Profile { constructor(profile = {}) { this._profile = Object.assign({}, { '@context': 'http://schema.org/' }, profile); } toJSON() { return Object.assign({}, this._profile); } toToken(privateKey) { return profileTokens_1.signProfileToken(this.toJSON(), privateKey); } static validateSchema(profile, strict = false) { schemaDefinition.strict = strict; return inspector.validate(schemaDefinition, profile); } static fromToken(token, publicKeyOrAddress = null) { const profile = profileTokens_1.extractProfile(token, publicKeyOrAddress); return new Profile(profile); } static makeZoneFile(domainName, tokenFileURL) { return profileZoneFiles_1.makeProfileZoneFile(domainName, tokenFileURL); } static validateProofs(domainName, cheerio) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return profileProofs_1.validateProofs(new Profile().toJSON(), domainName, cheerio); }); } } exports.Profile = Profile; //# sourceMappingURL=profile.js.map