{"version":3,"file":"did-keypair.cjs","sources":["../../../src/keypairs/did-keypair.js"],"sourcesContent":["import DockKeypair from './dock-keypair';\nimport { DidKey } from '../types/did/onchain/did-key';\nimport VerificationMethodRefOrIdentRef from '../types/did/document/verification-method-ref-or-ident-ref';\nimport { ensureInstanceOf } from '../utils';\nimport { DidMethodKey } from '../types/did/onchain/typed-did';\n\n/**\n * A class representation of DID Keypair which includes a signing keypair and its associated verification method reference identifier.\n */\nexport default class DidKeypair {\n  /**\n   * Constructs a `DidKeypair` instance from the supplied keypair.\n   *\n   * @param {VerificationMethodRefOrIdentRef} keyRef - The reference of the verification method.\n   * @param {DockKeypair} keyPair - Key pair provided.\n   */\n  constructor(keyRef, keyPair) {\n    this.verificationMethodId = VerificationMethodRefOrIdentRef.from(keyRef);\n    this.keyPair = ensureInstanceOf(keyPair, DockKeypair);\n  }\n\n  /**\n   * Static function to create a `DidKeypair` instance from the provided keyPair.\n   *\n   * @param {DockKeypair} keyPair - Key pair provided.\n   * @return The new instance of `DidKeypair`.\n   */\n  static didMethodKey(keyPair) {\n    const did = DidMethodKey.fromKeypair(keyPair);\n\n    return new this([did, did.asDidMethodKey.toEncodedString()], keyPair);\n  }\n\n  /**\n   * Get the public key from the current key pair.\n   *\n   * @return The public key.\n   */\n  publicKey() {\n    return this.keyPair.publicKey();\n  }\n\n  /**\n   * Creates a new `DidKey` instance from the public key of the current key pair.\n   *\n   * @param {?number} verRels - Number indicating verification relationships.\n   * @return The new instance of `DidKey`.\n   */\n  didKey(verRels) {\n    return new DidKey(this.keyPair.publicKey(), verRels);\n  }\n\n  /**\n   * Get the DID from the current verification method ID.\n   *\n   * @return The DID.\n   */\n  get did() {\n    return this.verificationMethodId[0];\n  }\n\n  /**\n   * Get the Key ID from the current verification method ID.\n   *\n   * @return The Key ID.\n   */\n  get keyId() {\n    return this.verificationMethodId[1];\n  }\n\n  /**\n   * Sign the provided message with the key pair.\n   *\n   * @param {Uint8Array} message - The message to sign.\n   * @return The signature.\n   */\n  sign(message) {\n    return this.keyPair.sign(message);\n  }\n\n  /**\n   * Detects a key prefix from a key document\n   *\n   * @return The DidKeypair instance\n   */\n  static detectKeyPrefix(keyDocument) {\n    if (typeof keyDocument.id === 'string') {\n      return keyDocument.id.split('#')[1]?.split('-')[0] || 'keys';\n    }\n    return 'keys';\n  }\n}\n"],"names":["VerificationMethodRefOrIdentRef","ensureInstanceOf","DockKeypair","DidMethodKey","DidKey"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA;AACA;AACA;AACe,MAAM,UAAU,CAAC;AAChC;AACA;AACA;AACA;AACA;AACA;AACA,EAAE,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE;AAC/B,IAAI,IAAI,CAAC,oBAAoB,GAAGA,kDAA+B,CAAC,IAAI,CAAC,MAAM,CAAC;AAC5E,IAAI,IAAI,CAAC,OAAO,GAAGC,sBAAgB,CAAC,OAAO,EAAEC,oBAAW,CAAC;AACzD,EAAE;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA,EAAE,OAAO,YAAY,CAAC,OAAO,EAAE;AAC/B,IAAI,MAAM,GAAG,GAAGC,6CAAY,CAAC,WAAW,CAAC,OAAO,CAAC;;AAEjD,IAAI,OAAO,IAAI,IAAI,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,cAAc,CAAC,eAAe,EAAE,CAAC,EAAE,OAAO,CAAC;AACzE,EAAE;;AAEF;AACA;AACA;AACA;AACA;AACA,EAAE,SAAS,GAAG;AACd,IAAI,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE;AACnC,EAAE;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA,EAAE,MAAM,CAAC,OAAO,EAAE;AAClB,IAAI,OAAO,IAAIC,+BAAM,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,OAAO,CAAC;AACxD,EA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