{"ast":null,"code":"import { encodeBase64toUint8 } from '../base64';\nimport { decodeCBOR, encodeCBOR } from '../cbor';\nimport { Buffer } from 'buffer';\nvar PaymentRequest = /** @class */function () {\n  function PaymentRequest(transport, id, amount, unit, mints, description, singleUse) {\n    if (singleUse === void 0) {\n      singleUse = false;\n    }\n    this.transport = transport;\n    this.id = id;\n    this.amount = amount;\n    this.unit = unit;\n    this.mints = mints;\n    this.description = description;\n    this.singleUse = singleUse;\n  }\n  PaymentRequest.prototype.toEncodedRequest = function () {\n    var rawRequest = {\n      t: this.transport.map(function (t) {\n        return {\n          t: t.type,\n          a: t.target,\n          g: t.tags\n        };\n      })\n    };\n    if (this.id) {\n      rawRequest.i = this.id;\n    }\n    if (this.amount) {\n      rawRequest.a = this.amount;\n    }\n    if (this.unit) {\n      rawRequest.u = this.unit;\n    }\n    if (this.mints) {\n      rawRequest.m = this.mints;\n    }\n    if (this.description) {\n      rawRequest.d = this.description;\n    }\n    if (this.singleUse) {\n      rawRequest.s = this.singleUse;\n    }\n    var data = encodeCBOR(rawRequest);\n    var encodedData = Buffer.from(data).toString('base64');\n    return 'creq' + 'A' + encodedData;\n  };\n  PaymentRequest.prototype.getTransport = function (type) {\n    return this.transport.find(function (t) {\n      return t.type === type;\n    });\n  };\n  PaymentRequest.fromEncodedRequest = function (encodedRequest) {\n    if (!encodedRequest.startsWith('creq')) {\n      throw new Error('unsupported pr: invalid prefix');\n    }\n    var version = encodedRequest[4];\n    if (version !== 'A') {\n      throw new Error('unsupported pr version');\n    }\n    var encodedData = encodedRequest.slice(5);\n    var data = encodeBase64toUint8(encodedData);\n    var decoded = decodeCBOR(data);\n    var transports = decoded.t.map(function (t) {\n      return {\n        type: t.t,\n        target: t.a,\n        tags: t.g\n      };\n    });\n    return new PaymentRequest(transports, decoded.i, decoded.a, decoded.u, decoded.m, decoded.d, decoded.s);\n  };\n  return PaymentRequest;\n}();\nexport { PaymentRequest };\n//# sourceMappingURL=PaymentRequest.js.map","map":null,"metadata":{},"sourceType":"module","externalDependencies":[]}