Server IP : 85.214.239.14 / Your IP : 3.129.71.13 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /lib/node_modules/npm/node_modules/@tufjs/models/dist/ |
Upload File : |
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Key = void 0; const util_1 = __importDefault(require("util")); const error_1 = require("./error"); const utils_1 = require("./utils"); const key_1 = require("./utils/key"); // A container class representing the public portion of a Key. class Key { constructor(options) { const { keyID, keyType, scheme, keyVal, unrecognizedFields } = options; this.keyID = keyID; this.keyType = keyType; this.scheme = scheme; this.keyVal = keyVal; this.unrecognizedFields = unrecognizedFields || {}; } // Verifies the that the metadata.signatures contains a signature made with // this key and is correctly signed. verifySignature(metadata) { const signature = metadata.signatures[this.keyID]; if (!signature) throw new error_1.UnsignedMetadataError('no signature for key found in metadata'); if (!this.keyVal.public) throw new error_1.UnsignedMetadataError('no public key found'); const publicKey = (0, key_1.getPublicKey)({ keyType: this.keyType, scheme: this.scheme, keyVal: this.keyVal.public, }); const signedData = metadata.signed.toJSON(); try { if (!utils_1.crypto.verifySignature(signedData, publicKey, signature.sig)) { throw new error_1.UnsignedMetadataError(`failed to verify ${this.keyID} signature`); } } catch (error) { if (error instanceof error_1.UnsignedMetadataError) { throw error; } throw new error_1.UnsignedMetadataError(`failed to verify ${this.keyID} signature`); } } equals(other) { if (!(other instanceof Key)) { return false; } return (this.keyID === other.keyID && this.keyType === other.keyType && this.scheme === other.scheme && util_1.default.isDeepStrictEqual(this.keyVal, other.keyVal) && util_1.default.isDeepStrictEqual(this.unrecognizedFields, other.unrecognizedFields)); } toJSON() { return { keytype: this.keyType, scheme: this.scheme, keyval: this.keyVal, ...this.unrecognizedFields, }; } static fromJSON(keyID, data) { const { keytype, scheme, keyval, ...rest } = data; if (typeof keytype !== 'string') { throw new TypeError('keytype must be a string'); } if (typeof scheme !== 'string') { throw new TypeError('scheme must be a string'); } if (!utils_1.guard.isStringRecord(keyval)) { throw new TypeError('keyval must be a string record'); } return new Key({ keyID, keyType: keytype, scheme, keyVal: keyval, unrecognizedFields: rest, }); } } exports.Key = Key;