text: 'use strict';
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  
  var _regenerator = require('babel-runtime/regenerator');
  
  var _regenerator2 = _interopRequireDefault(_regenerator);
  
  var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
  
  var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
  
  exports.ES256KSigner = ES256KSigner;
  
  var _base64url = require('base64url');
  
  var _base64url2 = _interopRequireDefault(_base64url);
  
  var _buffer = require('buffer');
  
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  
  function ES256KSigner() {
    var recoverable = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  
    function toJose(_ref) {
      var r = _ref.r,
          s = _ref.s,
          recoveryParam = _ref.recoveryParam;
  
      var jose = _buffer.Buffer.alloc(recoverable ? 65 : 64);
      _buffer.Buffer.from(r, 'hex').copy(jose, 0);
      _buffer.Buffer.from(s, 'hex').copy(jose, 32);
      if (recoverable) {
        if (recoveryParam === undefined) throw new Error('Signer did not return a recoveryParam');
        jose[64] = recoveryParam;
      }
      return _base64url2.default.encode(jose);
    }
  
    return function () {
      var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(payload, signer) {
        var signature;
        return _regenerator2.default.wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                _context.next = 2;
                return signer(payload);
  
              case 2:
                signature = _context.sent;
                return _context.abrupt('return', toJose(signature));
  
              case 4:
              case 'end':
                return _context.stop();
            }
          }
        }, _callee, this);
      }));
  
      function sign(_x2, _x3) {
        return _ref2.apply(this, arguments);
      }
  
      return sign;
    }();
  }
  
  var algorithms = { ES256K: ES256KSigner(), 'ES256K-R': ES256KSigner(true) };
  
  function SignerAlgorithm(alg) {
    var impl = algorithms[alg];
    if (!impl) throw new Error('Unsupported algorithm ' + alg);
    return impl;
  }
  module.exports = SignerAlgorithm;