{"ast":null,"code":"import _asyncToGenerator from \"/home/mleku/src/orly.dev/next/signer/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js\";\n// Fallback UUID generator for contexts where crypto.randomUUID is unavailable\nfunction generateUUID() {\n  if (typeof crypto !== 'undefined' && crypto.randomUUID) {\n    return crypto.randomUUID();\n  }\n  // Fallback using crypto.getRandomValues\n  const bytes = new Uint8Array(16);\n  crypto.getRandomValues(bytes);\n  bytes[6] = bytes[6] & 0x0f | 0x40; // Version 4\n  bytes[8] = bytes[8] & 0x3f | 0x80; // Variant 10\n  const hex = [...bytes].map(b => b.toString(16).padStart(2, '0')).join('');\n  return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;\n}\nclass Messenger {\n  #requests = new Map();\n  constructor() {\n    window.addEventListener('message', this.#handleCallResponse.bind(this));\n  }\n  request(method, params) {\n    var _this = this;\n    return _asyncToGenerator(function* () {\n      const id = generateUUID();\n      return new Promise((resolve, reject) => {\n        _this.#requests.set(id, {\n          resolve,\n          reject\n        });\n        window.postMessage({\n          id,\n          ext: 'smesh-signer',\n          method,\n          params\n        }, '*');\n      });\n    })();\n  }\n  #handleCallResponse(message) {\n    // We also will receive our own messages, that we sent.\n    // We have to ignore them (they will not have a response field).\n    if (!message.data || message.data.response === null || message.data.response === undefined || message.data.ext !== 'smesh-signer' || !this.#requests.has(message.data.id)) {\n      return;\n    }\n    if (message.data.response.error) {\n      this.#requests.get(message.data.id)?.reject(message.data.response.error);\n    } else {\n      this.#requests.get(message.data.id)?.resolve(message.data.response);\n    }\n    this.#requests.delete(message.data.id);\n  }\n}\nconst nostr = {\n  messenger: new Messenger(),\n  getPublicKey() {\n    var _this2 = this;\n    return _asyncToGenerator(function* () {\n      debug('getPublicKey received');\n      const pubkey = yield _this2.messenger.request('getPublicKey', {});\n      debug(`getPublicKey response:`);\n      debug(pubkey);\n      return pubkey;\n    })();\n  },\n  signEvent(event) {\n    var _this3 = this;\n    return _asyncToGenerator(function* () {\n      debug('signEvent received');\n      const signedEvent = yield _this3.messenger.request('signEvent', event);\n      debug('signEvent response:');\n      debug(signedEvent);\n      return signedEvent;\n    })();\n  },\n  getRelays() {\n    var _this4 = this;\n    return _asyncToGenerator(function* () {\n      debug('getRelays received');\n      const relays = yield _this4.messenger.request('getRelays', {});\n      debug('getRelays response:');\n      debug(relays);\n      return relays;\n    })();\n  },\n  nip04: {\n    that: this,\n    encrypt(peerPubkey, plaintext) {\n      return _asyncToGenerator(function* () {\n        debug('nip04.encrypt received');\n        const ciphertext = yield nostr.messenger.request('nip04.encrypt', {\n          peerPubkey,\n          plaintext\n        });\n        debug('nip04.encrypt response:');\n        debug(ciphertext);\n        return ciphertext;\n      })();\n    },\n    decrypt(peerPubkey, ciphertext) {\n      return _asyncToGenerator(function* () {\n        debug('nip04.decrypt received');\n        const plaintext = yield nostr.messenger.request('nip04.decrypt', {\n          peerPubkey,\n          ciphertext\n        });\n        debug('nip04.decrypt response:');\n        debug(plaintext);\n        return plaintext;\n      })();\n    }\n  },\n  nip44: {\n    encrypt(peerPubkey, plaintext) {\n      return _asyncToGenerator(function* () {\n        debug('nip44.encrypt received');\n        const ciphertext = yield nostr.messenger.request('nip44.encrypt', {\n          peerPubkey,\n          plaintext\n        });\n        debug('nip44.encrypt response:');\n        debug(ciphertext);\n        return ciphertext;\n      })();\n    },\n    decrypt(peerPubkey, ciphertext) {\n      return _asyncToGenerator(function* () {\n        debug('nip44.decrypt received');\n        const plaintext = yield nostr.messenger.request('nip44.decrypt', {\n          peerPubkey,\n          ciphertext\n        });\n        debug('nip44.decrypt response:');\n        debug(plaintext);\n        return plaintext;\n      })();\n    }\n  },\n  mls: {\n    init(relayURLs, lastEventTS) {\n      return _asyncToGenerator(function* () {\n        return yield nostr.messenger.request('mls.init', {\n          relayURLs,\n          lastEventTS: lastEventTS || 0\n        });\n      })();\n    },\n    sendDM(recipient, content) {\n      return _asyncToGenerator(function* () {\n        return yield nostr.messenger.request('mls.sendDM', {\n          recipient,\n          content\n        });\n      })();\n    },\n    subscribe() {\n      return _asyncToGenerator(function* () {\n        return yield nostr.messenger.request('mls.subscribe', {});\n      })();\n    },\n    publishKP() {\n      return _asyncToGenerator(function* () {\n        return yield nostr.messenger.request('mls.publishKP', {});\n      })();\n    },\n    listGroups() {\n      return _asyncToGenerator(function* () {\n        return yield nostr.messenger.request('mls.listGroups', {});\n      })();\n    },\n    deliverEvent(subId, eventJSON) {\n      return _asyncToGenerator(function* () {\n        return yield nostr.messenger.request('mls.deliverEvent', {\n          subId,\n          eventJSON\n        });\n      })();\n    }\n  }\n};\nwindow.nostr = nostr;\n// Create a shared messenger instance for WebLN\nconst weblnMessenger = nostr.messenger;\nconst webln = {\n  enabled: false,\n  enable() {\n    var _this5 = this;\n    return _asyncToGenerator(function* () {\n      debug('webln.enable received');\n      yield weblnMessenger.request('webln.enable', {});\n      _this5.enabled = true;\n      debug('webln.enable completed');\n      // Dispatch webln:enabled event as per WebLN spec\n      window.dispatchEvent(new Event('webln:enabled'));\n    })();\n  },\n  getInfo() {\n    return _asyncToGenerator(function* () {\n      debug('webln.getInfo received');\n      const info = yield weblnMessenger.request('webln.getInfo', {});\n      debug('webln.getInfo response:');\n      debug(info);\n      return info;\n    })();\n  },\n  sendPayment(paymentRequest) {\n    return _asyncToGenerator(function* () {\n      debug('webln.sendPayment received');\n      const result = yield weblnMessenger.request('webln.sendPayment', {\n        paymentRequest\n      });\n      debug('webln.sendPayment response:');\n      debug(result);\n      return result;\n    })();\n  },\n  keysend(args) {\n    return _asyncToGenerator(function* () {\n      debug('webln.keysend received');\n      const result = yield weblnMessenger.request('webln.keysend', args);\n      debug('webln.keysend response:');\n      debug(result);\n      return result;\n    })();\n  },\n  makeInvoice(args) {\n    return _asyncToGenerator(function* () {\n      debug('webln.makeInvoice received');\n      // Normalize args to RequestInvoiceArgs\n      let normalizedArgs;\n      if (typeof args === 'string' || typeof args === 'number') {\n        normalizedArgs = {\n          amount: args\n        };\n      } else {\n        normalizedArgs = args;\n      }\n      const result = yield weblnMessenger.request('webln.makeInvoice', normalizedArgs);\n      debug('webln.makeInvoice response:');\n      debug(result);\n      return result;\n    })();\n  },\n  signMessage() {\n    throw new Error('signMessage is not supported - NWC does not provide node signing capabilities');\n  },\n  verifyMessage() {\n    throw new Error('verifyMessage is not supported - NWC does not provide message verification');\n  }\n};\nwindow.webln = webln;\n// Dispatch webln:ready event to signal that webln is available\n// This is dispatched on document as per the WebLN standard\ndocument.dispatchEvent(new Event('webln:ready'));\n// Listen for MLS push messages from the extension background.\n// These arrive via content script relay and are dispatched as custom events\n// so the page app can handle them (publish events, display DMs, etc.).\nwindow.addEventListener('message', event => {\n  if (event.data?.ext !== 'smesh-signer' || event.data?.type !== 'mls-push') return;\n  window.dispatchEvent(new CustomEvent('nostr-mls', {\n    detail: event.data.data\n  }));\n});\nconst debug = function (value) {\n  console.log('[signer]', typeof value === 'string' ? value : JSON.stringify(value));\n};\nexport {};","map":null,"metadata":{},"sourceType":"module","externalDependencies":[]}