@gandlaf21/bc-ur
Version:
A JS implementation of the Uniform Resources (UR) specification from Blockchain Commons
39 lines • 1.25 kB
JavaScript
import { InvalidTypeError } from "./errors";
import { isURType } from "./utils";
import { cborEncode, cborDecode } from './cbor';
import { Buffer } from "buffer";
var UR = /** @class */ (function () {
function UR(_cborPayload, _type) {
if (_type === void 0) { _type = 'bytes'; }
this._cborPayload = _cborPayload;
this._type = _type;
if (!isURType(this._type)) {
throw new InvalidTypeError();
}
}
UR.fromBuffer = function (buf) {
return new UR(cborEncode(buf));
};
UR.from = function (value) {
return UR.fromBuffer(Buffer.from(value));
};
UR.prototype.decodeCBOR = function () {
return 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;
}());
export default UR;
//# sourceMappingURL=ur.js.map