"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.createVerificationMethod = exports.createIidVerificationMethods = exports.createAgentIidContext = void 0;
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var _encoding = require("@cosmjs/encoding");
var _codegen = require("../codegen");
var _bs = _interopRequireDefault(require("bs58"));
/**
 * Only use SECP generated creds!!!
 */
var createVerificationMethod = exports.createVerificationMethod = function createVerificationMethod(did, pubkey, controller) {
  var type = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "secp";
  var pubkeyBase58 = _bs["default"].encode(pubkey);
  return _codegen.ixo.iid.v1beta1.VerificationMethod.fromPartial({
    id: did + "#" + pubkeyBase58,
    type: type === "ed" ? "Ed25519VerificationKey2018" : "EcdsaSecp256k1VerificationKey2019",
    publicKeyBase58: pubkeyBase58,
    controller: controller
  });
};
/**
 * Only use SECP generated user creds!!!
 */
var createIidVerificationMethods = exports.createIidVerificationMethods = function createIidVerificationMethods(_ref) {
  var did = _ref.did,
    pubkey = _ref.pubkey,
    controller = _ref.controller,
    address = _ref.address,
    _ref$type = _ref.type,
    type = _ref$type === void 0 ? "secp" : _ref$type;
  var pubkeyHex = (0, _encoding.toHex)(pubkey);
  var pubkeyBase58 = _bs["default"].encode(pubkey);
  return [_codegen.ixo.iid.v1beta1.Verification.fromPartial({
    relationships: ["authentication"],
    method: _codegen.ixo.iid.v1beta1.VerificationMethod.fromPartial({
      id: did,
      type: type === "ed" ? "Ed25519VerificationKey2018" : "EcdsaSecp256k1VerificationKey2019",
      publicKeyBase58: pubkeyBase58,
      controller: controller
    })
  }), _codegen.ixo.iid.v1beta1.Verification.fromPartial({
    relationships: ["authentication"],
    method: _codegen.ixo.iid.v1beta1.VerificationMethod.fromPartial({
      id: did + "#" + pubkeyHex,
      type: type === "ed" ? "Ed25519VerificationKey2018" : "EcdsaSecp256k1VerificationKey2019",
      publicKeyMultibase: "F" + pubkeyHex,
      controller: controller
    })
  }), _codegen.ixo.iid.v1beta1.Verification.fromPartial({
    relationships: ["authentication"],
    method: _codegen.ixo.iid.v1beta1.VerificationMethod.fromPartial({
      id: did + "#" + pubkeyBase58,
      type: type === "ed" ? "Ed25519VerificationKey2018" : "EcdsaSecp256k1VerificationKey2019",
      publicKeyBase58: pubkeyBase58,
      controller: controller
    })
  }), _codegen.ixo.iid.v1beta1.Verification.fromPartial({
    relationships: ["authentication"],
    method: _codegen.ixo.iid.v1beta1.VerificationMethod.fromPartial({
      id: did + "#" + address,
      type: "CosmosAccountAddress",
      blockchainAccountID: address,
      controller: controller
    })
  })];
};
var createAgentIidContext = exports.createAgentIidContext = function createAgentIidContext(contexts) {
  return [_codegen.ixo.iid.v1beta1.Context.fromPartial({
    key: "ixo",
    val: "https://w3id.org/ixo/context/v1"
    // val: "https://w3id.org/ixo/ns/context/v1",
  })].concat((0, _toConsumableArray2["default"])(contexts ? contexts.map(function (_ref2) {
    var key = _ref2.key,
      val = _ref2.val;
    return _codegen.ixo.iid.v1beta1.Context.fromPartial({
      key: key,
      val: val
    });
  }) : []));
};