UNPKG

@gandlaf21/bc-ur

Version:

A JS implementation of the Uniform Resources (UR) specification from Blockchain Commons

41 lines (40 loc) 1.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var errors_1 = require("./errors"); var utils_1 = require("./utils"); var cbor_1 = require("./cbor"); var buffer_1 = require("buffer"); var UR = /** @class */ (function () { function UR(_cborPayload, _type) { if (_type === void 0) { _type = 'bytes'; } this._cborPayload = _cborPayload; this._type = _type; if (!utils_1.isURType(this._type)) { throw new errors_1.InvalidTypeError(); } } UR.fromBuffer = function (buf) { return new UR(cbor_1.cborEncode(buf)); }; UR.from = function (value) { return UR.fromBuffer(buffer_1.Buffer.from(value)); }; UR.prototype.decodeCBOR = function () { return cbor_1.cborDecode(this._cborPayload); }; Object.defineProperty(UR.prototype, "type", { get: function () { return this._type; }, enumerable: false, configurable: true }); Object.defineProperty(UR.prototype, "cbor", { get: function () { return this._cborPayload; }, enumerable: false, configurable: true }); UR.prototype.equals = function (ur2) { return this.type === ur2.type && this.cbor.equals(ur2.cbor); }; return UR; }()); exports.default = UR;