@ghostlytools/cli 1.11.4 → 1.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (218) hide show
  1. package/README.md +31 -14
  2. package/dist/assets/{api-MYc6QNRs.js → api-BwEgbvvK.js} +395 -131
  3. package/dist/assets/api-BwEgbvvK.js.map +1 -0
  4. package/dist/assets/{api-BwyFq4lA.js → api-jRUXnBdX.js} +2 -2
  5. package/dist/assets/{apiKit-CfsNx9ZR.js → apiKit-BlsNk-Cx.js} +48 -11
  6. package/dist/assets/apiKit-BlsNk-Cx.js.map +1 -0
  7. package/dist/assets/appFetch-CW9fJPHh.js +602 -0
  8. package/dist/assets/appFetch-CW9fJPHh.js.map +1 -0
  9. package/dist/assets/apps-BcG4u6SM.js +1 -0
  10. package/dist/assets/{apps-h12II1us.js → apps-CL8TXHhu.js} +20 -14
  11. package/dist/assets/apps-CL8TXHhu.js.map +1 -0
  12. package/dist/assets/{argon2id-088uQfnH.js → argon2id-B9wFdSj6.js} +2 -3
  13. package/dist/assets/{argon2id-088uQfnH.js.map → argon2id-B9wFdSj6.js.map} +1 -1
  14. package/dist/assets/{arkade-Bw_4PZRG.js → arkade-DryM-q5n.js} +6 -7
  15. package/dist/assets/arkade-DryM-q5n.js.map +1 -0
  16. package/dist/assets/{backup-Chvy79SN.js → backup-BA41EDvh.js} +110 -26
  17. package/dist/assets/backup-BA41EDvh.js.map +1 -0
  18. package/dist/assets/backup-xZfV-ytw.js +1 -0
  19. package/dist/assets/bark_ffi_wasm_bg-CcafsJla.js +5 -0
  20. package/dist/assets/bark_ffi_wasm_bg-CcafsJla.js.map +1 -0
  21. package/dist/assets/{bark_ffi_wasm_bg-Bxru_BVW.wasm → bark_ffi_wasm_bg-VNmaJsc9.wasm} +0 -0
  22. package/dist/assets/{bitcoind-CdSmvy2y.js → bitcoind-Dh7n9amb.js} +4 -5
  23. package/dist/assets/{bitcoind-CdSmvy2y.js.map → bitcoind-Dh7n9amb.js.map} +1 -1
  24. package/dist/assets/bitcoindevkit_bg-BWQHx7vd.js +5 -0
  25. package/dist/assets/bitcoindevkit_bg-BWQHx7vd.js.map +1 -0
  26. package/dist/assets/bitcoindevkit_bg-DXil67yS.wasm +0 -0
  27. package/dist/assets/{blobFiles-BmsrvZc3.js → blobFiles-DDs34n0r.js} +4 -5
  28. package/dist/assets/{blobFiles-BmsrvZc3.js.map → blobFiles-DDs34n0r.js.map} +1 -1
  29. package/dist/assets/breez_sdk_spark_wasm_bg.wasm +0 -0
  30. package/dist/assets/buttons-CsGdQNnR.js +1 -0
  31. package/dist/assets/{buttons-BgoExb4E.js → buttons-SH1tNRh7.js} +45 -23
  32. package/dist/assets/buttons-SH1tNRh7.js.map +1 -0
  33. package/dist/assets/bytes-C1DNGY18.js +132 -0
  34. package/dist/assets/bytes-C1DNGY18.js.map +1 -0
  35. package/dist/assets/{childEnv-K_IzUqQx.js → childEnv-C-99hdbL.js} +2 -3
  36. package/dist/assets/{childEnv-K_IzUqQx.js.map → childEnv-C-99hdbL.js.map} +1 -1
  37. package/dist/assets/{client-DY8tZZWi.js → client-DGS-atRu.js} +5 -8
  38. package/dist/assets/{client-DY8tZZWi.js.map → client-DGS-atRu.js.map} +1 -1
  39. package/dist/assets/{codec-BnMg-Grj.js → codec-B2rH1mfx.js} +2 -4
  40. package/dist/assets/{codec-BnMg-Grj.js.map → codec-B2rH1mfx.js.map} +1 -1
  41. package/dist/assets/domainProofs-BDNP1dIy.js +280 -0
  42. package/dist/assets/domainProofs-BDNP1dIy.js.map +1 -0
  43. package/dist/assets/{endpoint-DarqblYE.js → endpoint-Cvu-taMs.js} +462 -424
  44. package/dist/assets/endpoint-Cvu-taMs.js.map +1 -0
  45. package/dist/assets/engineErrors--9hfgKlK.js +150 -0
  46. package/dist/assets/engineErrors--9hfgKlK.js.map +1 -0
  47. package/dist/assets/{envelope-CdV7vHVZ.js → envelope-Bi2kMqbp.js} +3 -4
  48. package/dist/assets/{envelope-CdV7vHVZ.js.map → envelope-Bi2kMqbp.js.map} +1 -1
  49. package/dist/assets/{errors-CAh6GLJZ.js → errors-DDLFO4Gf.js} +5 -4
  50. package/dist/assets/errors-DDLFO4Gf.js.map +1 -0
  51. package/dist/assets/{fedimintSdk-CPFfVK-G.js → fedimintSdk-D-6H9Pe7.js} +4 -5
  52. package/dist/assets/{fedimintSdk-CPFfVK-G.js.map → fedimintSdk-D-6H9Pe7.js.map} +1 -1
  53. package/dist/assets/fedimint_client_wasm_bg-Cr5xGD-w.js +5 -0
  54. package/dist/assets/{fedimint_client_wasm_bg-BtHHlFpp.js.map → fedimint_client_wasm_bg-Cr5xGD-w.js.map} +1 -1
  55. package/dist/assets/fileBytes-CCKbwqG_.js +1 -0
  56. package/dist/assets/{fileBytes-BLPZq9YU.js → fileBytes-CfvUXdSy.js} +5 -7
  57. package/dist/assets/fileBytes-CfvUXdSy.js.map +1 -0
  58. package/dist/assets/{fileBytes-B0z9A6Le.js → fileBytes-tj6-VZcB.js} +3 -4
  59. package/dist/assets/{fileBytes-B0z9A6Le.js.map → fileBytes-tj6-VZcB.js.map} +1 -1
  60. package/dist/assets/fileBytesIdb-B0zzJ6p7.js +1 -0
  61. package/dist/assets/{fileBytesIdb-Bmlrl9EO.js → fileBytesIdb-BJirUAjI.js} +4 -5
  62. package/dist/assets/{fileBytesIdb-Bmlrl9EO.js.map → fileBytesIdb-BJirUAjI.js.map} +1 -1
  63. package/dist/assets/{fileBytesOpfs-DBS0kbPT.js → fileBytesOpfs-DRUYLER4.js} +4 -5
  64. package/dist/assets/{fileBytesOpfs-DBS0kbPT.js.map → fileBytesOpfs-DRUYLER4.js.map} +1 -1
  65. package/dist/assets/{fixedHosts-CbgqrIKs.js → fixedHosts-CPSsGOI2.js} +4 -5
  66. package/dist/assets/{fixedHosts-CbgqrIKs.js.map → fixedHosts-CPSsGOI2.js.map} +1 -1
  67. package/dist/assets/{ghostly_iroh_web-BzAXJUYH.js → ghostly_iroh_web-DIj5xGmR.js} +2 -3
  68. package/dist/assets/{ghostly_iroh_web-BzAXJUYH.js.map → ghostly_iroh_web-DIj5xGmR.js.map} +1 -1
  69. package/dist/assets/{src-DJe-OYxd.js → groupMeta-DxuJzko_.js} +6009 -25536
  70. package/dist/assets/groupMeta-DxuJzko_.js.map +1 -0
  71. package/dist/assets/{host-C0NMNQLl.js → host-BxM-HMr0.js} +262 -134
  72. package/dist/assets/host-BxM-HMr0.js.map +1 -0
  73. package/dist/assets/{hyperdhtRelay-Dz7pvcBA.js → hyperdhtRelay-DLUiwfnt.js} +36 -9
  74. package/dist/assets/hyperdhtRelay-DLUiwfnt.js.map +1 -0
  75. package/dist/assets/hyperdhtRelay-bjNGacf5.js +32 -0
  76. package/dist/assets/hyperdhtRelay-bjNGacf5.js.map +1 -0
  77. package/dist/assets/{idb-CEuoNsTv.js → idb-ewvbqyDI.js} +2 -3
  78. package/dist/assets/{idb-CEuoNsTv.js.map → idb-ewvbqyDI.js.map} +1 -1
  79. package/dist/assets/identityProofs-Cksc_K7_.js +940 -0
  80. package/dist/assets/identityProofs-Cksc_K7_.js.map +1 -0
  81. package/dist/assets/{irohWeb-caAj4Dms.js → irohWeb-CbnGtUo6.js} +3231 -87
  82. package/dist/assets/irohWeb-CbnGtUo6.js.map +1 -0
  83. package/dist/assets/joinTrace-CBr1jbch.js +1 -0
  84. package/dist/assets/{joinTrace-CjRDFy85.js → joinTrace-xKBe73j9.js} +2 -3
  85. package/dist/assets/{joinTrace-CjRDFy85.js.map → joinTrace-xKBe73j9.js.map} +1 -1
  86. package/dist/assets/{legacy_ciphers-JJOu0JXL.js → legacy_ciphers-BnYATjxo.js} +2 -3
  87. package/dist/assets/{legacy_ciphers-JJOu0JXL.js.map → legacy_ciphers-BnYATjxo.js.map} +1 -1
  88. package/dist/assets/linkPreview-DdMf-YAc.js +252 -0
  89. package/dist/assets/linkPreview-DdMf-YAc.js.map +1 -0
  90. package/dist/assets/{main-C6t5zrD5.js → main-CwTaepxR.js} +296 -122
  91. package/dist/assets/main-CwTaepxR.js.map +1 -0
  92. package/dist/assets/{mainline-DCuGUSZF.js → mainline-CVrd0C1n.js} +72 -18
  93. package/dist/assets/mainline-CVrd0C1n.js.map +1 -0
  94. package/dist/assets/mints-BcBODVVW.js +1 -0
  95. package/dist/assets/{mints-j5XAOk4f.js → mints-CMDLbMeH.js} +8 -6
  96. package/dist/assets/mints-CMDLbMeH.js.map +1 -0
  97. package/dist/assets/{nacl-fast-CDhNCYHs.js → nacl-fast-B1ThWvuM.js} +2 -3
  98. package/dist/assets/{nacl-fast-CDhNCYHs.js.map → nacl-fast-B1ThWvuM.js.map} +1 -1
  99. package/dist/assets/{networkReason-BbQW1Xpc.js → networkReason-Be-hMghr.js} +10 -14
  100. package/dist/assets/{networkReason-BbQW1Xpc.js.map → networkReason-Be-hMghr.js.map} +1 -1
  101. package/dist/assets/{noble_curves-DDWn5AH0.js → noble_curves-DqpNlhAU.js} +3 -4
  102. package/dist/assets/{noble_curves-DDWn5AH0.js.map → noble_curves-DqpNlhAU.js.map} +1 -1
  103. package/dist/assets/{noble_hashes-B7AZyFyS.js → noble_hashes-LFe1N2xt.js} +3 -4
  104. package/dist/assets/{noble_hashes-B7AZyFyS.js.map → noble_hashes-LFe1N2xt.js.map} +1 -1
  105. package/dist/assets/{nwc-CSDRMZ0e.js → nwc-DKE2FXr6.js} +5 -6
  106. package/dist/assets/{nwc-CSDRMZ0e.js.map → nwc-DKE2FXr6.js.map} +1 -1
  107. package/dist/assets/nwcProvider-pL2XqSbW.js +208 -0
  108. package/dist/assets/nwcProvider-pL2XqSbW.js.map +1 -0
  109. package/dist/assets/{openpgp-BBFr-zHQ.js → openpgp-LkR_Zof0.js} +14 -15
  110. package/dist/assets/{openpgp-BBFr-zHQ.js.map → openpgp-LkR_Zof0.js.map} +1 -1
  111. package/dist/assets/ownDid-DY3rYqDI.js +862 -0
  112. package/dist/assets/ownDid-DY3rYqDI.js.map +1 -0
  113. package/dist/assets/{ownStatus-BoTf5WqQ.js → ownStatus-DtzIllg2.js} +70 -20
  114. package/dist/assets/ownStatus-DtzIllg2.js.map +1 -0
  115. package/dist/assets/pairedTransports-BKmvlKz1.js +581 -0
  116. package/dist/assets/pairedTransports-BKmvlKz1.js.map +1 -0
  117. package/dist/assets/paymentIntent-DySU3Ajm.js +349 -0
  118. package/dist/assets/paymentIntent-DySU3Ajm.js.map +1 -0
  119. package/dist/assets/pkarr-BQo4PcCg.js +367 -0
  120. package/dist/assets/pkarr-BQo4PcCg.js.map +1 -0
  121. package/dist/assets/{profiles-DszHjEJi.js → profiles-BOYGlmu2.js} +9 -10
  122. package/dist/assets/profiles-BOYGlmu2.js.map +1 -0
  123. package/dist/assets/registry-4W1LGlCF.js +1 -0
  124. package/dist/assets/{registry-Da-r6eC3.js → registry-Bep4umOM.js} +1296 -80
  125. package/dist/assets/registry-Bep4umOM.js.map +1 -0
  126. package/dist/assets/relay-Cjfmdec0.js +2219 -0
  127. package/dist/assets/relay-Cjfmdec0.js.map +1 -0
  128. package/dist/assets/resolve-CIc3KZMV.js +970 -0
  129. package/dist/assets/resolve-CIc3KZMV.js.map +1 -0
  130. package/dist/assets/{restoredRows-C3LcxmOw.js → restoredRows-D_WSHE7H.js} +3 -4
  131. package/dist/assets/{restoredRows-C3LcxmOw.js.map → restoredRows-D_WSHE7H.js.map} +1 -1
  132. package/dist/assets/secretGuard-Bm6nci0I.js +1 -0
  133. package/dist/assets/{secretGuard-CsVHDdYk.js → secretGuard-BrATm_gl.js} +43 -22
  134. package/dist/assets/{secretGuard-CsVHDdYk.js.map → secretGuard-BrATm_gl.js.map} +1 -1
  135. package/dist/assets/{server-C1jZZ61O.js → server-D4gf-LnD.js} +9797 -479
  136. package/dist/assets/server-D4gf-LnD.js.map +1 -0
  137. package/dist/assets/{sha512-BYId-G-T.js → sha512-DST9fbWH.js} +2 -3
  138. package/dist/assets/{sha512-BYId-G-T.js.map → sha512-DST9fbWH.js.map} +1 -1
  139. package/dist/assets/sshForges-BnvwmNj-.js +539 -0
  140. package/dist/assets/sshForges-BnvwmNj-.js.map +1 -0
  141. package/dist/assets/{storage-Bya5b2Xt.js → storage-BpjdxvO2.js} +243 -34
  142. package/dist/assets/storage-BpjdxvO2.js.map +1 -0
  143. package/dist/assets/text-li76pThX.js +106 -0
  144. package/dist/assets/text-li76pThX.js.map +1 -0
  145. package/dist/assets/{translate-CUuC5szR.js → translate-BcbSWkuq.js} +21 -26
  146. package/dist/assets/{translate-CUuC5szR.js.map → translate-BcbSWkuq.js.map} +1 -1
  147. package/dist/assets/{tree-store-N362nuzZ.js → tree-store-CAchkO_l.js} +22 -6
  148. package/dist/assets/tree-store-CAchkO_l.js.map +1 -0
  149. package/dist/assets/{types-Clyb52K2.js → types-CdWwgvyt.js} +2 -3
  150. package/dist/assets/{types-Clyb52K2.js.map → types-CdWwgvyt.js.map} +1 -1
  151. package/dist/assets/{unbzip2-stream-B1C-JX9L.js → unbzip2-stream-BtkYGpC5.js} +2 -3
  152. package/dist/assets/{unbzip2-stream-B1C-JX9L.js.map → unbzip2-stream-BtkYGpC5.js.map} +1 -1
  153. package/dist/assets/{usdt-DI51znt-.js → usdt-CBJ4Q5Ji.js} +7 -7
  154. package/dist/assets/usdt-CBJ4Q5Ji.js.map +1 -0
  155. package/dist/assets/{waitNotice-Cn0WJ-He.js → waitNotice-DQvZgz2T.js} +27 -4
  156. package/dist/assets/waitNotice-DQvZgz2T.js.map +1 -0
  157. package/dist/assets/{web-DwgdhfcY.js → web-68CYFCl9.js} +314 -91
  158. package/dist/assets/web-68CYFCl9.js.map +1 -0
  159. package/dist/ghostly.mjs +3 -5
  160. package/dist/ghostly.mjs.map +1 -1
  161. package/npm-shrinkwrap.json +225 -200
  162. package/package.json +16 -16
  163. package/dist/assets/api-MYc6QNRs.js.map +0 -1
  164. package/dist/assets/apiKit-CfsNx9ZR.js.map +0 -1
  165. package/dist/assets/appFetch-DVYZOZFw.js +0 -194
  166. package/dist/assets/appFetch-DVYZOZFw.js.map +0 -1
  167. package/dist/assets/apps-Dbw2Hcko.js +0 -2
  168. package/dist/assets/apps-h12II1us.js.map +0 -1
  169. package/dist/assets/arkade-Bw_4PZRG.js.map +0 -1
  170. package/dist/assets/backup-CdEzTq5C.js +0 -2
  171. package/dist/assets/backup-Chvy79SN.js.map +0 -1
  172. package/dist/assets/bark_ffi_wasm_bg-EY2uc0Bx.js +0 -6
  173. package/dist/assets/bark_ffi_wasm_bg-EY2uc0Bx.js.map +0 -1
  174. package/dist/assets/bitcoindProvider-BvoRh0D5.js +0 -97
  175. package/dist/assets/bitcoindProvider-BvoRh0D5.js.map +0 -1
  176. package/dist/assets/bitcoindevkit_bg-B-iLWrmX.js +0 -6
  177. package/dist/assets/bitcoindevkit_bg-B-iLWrmX.js.map +0 -1
  178. package/dist/assets/bitcoindevkit_bg-CRkZTSbO.wasm +0 -0
  179. package/dist/assets/buttons-BgoExb4E.js.map +0 -1
  180. package/dist/assets/buttons-DK2aAGat.js +0 -2
  181. package/dist/assets/endpoint-DarqblYE.js.map +0 -1
  182. package/dist/assets/errors-CAh6GLJZ.js.map +0 -1
  183. package/dist/assets/fedimint_client_wasm_bg-BtHHlFpp.js +0 -6
  184. package/dist/assets/fileBytes-BLPZq9YU.js.map +0 -1
  185. package/dist/assets/fileBytes-BtIyoDF2.js +0 -2
  186. package/dist/assets/fileBytesIdb-D8mAK4pF.js +0 -2
  187. package/dist/assets/host-C0NMNQLl.js.map +0 -1
  188. package/dist/assets/hyperdhtRelay-1wzya_0L.js +0 -25
  189. package/dist/assets/hyperdhtRelay-1wzya_0L.js.map +0 -1
  190. package/dist/assets/hyperdhtRelay-Dz7pvcBA.js.map +0 -1
  191. package/dist/assets/irohWeb-caAj4Dms.js.map +0 -1
  192. package/dist/assets/joinTrace-D-fnt2p3.js +0 -2
  193. package/dist/assets/jsonOut-POtMBS_V.js +0 -16
  194. package/dist/assets/jsonOut-POtMBS_V.js.map +0 -1
  195. package/dist/assets/main-C6t5zrD5.js.map +0 -1
  196. package/dist/assets/mainline-DCuGUSZF.js.map +0 -1
  197. package/dist/assets/mints-BaOmx517.js +0 -2
  198. package/dist/assets/mints-j5XAOk4f.js.map +0 -1
  199. package/dist/assets/nwcProvider-PE0wli8n.js +0 -88
  200. package/dist/assets/nwcProvider-PE0wli8n.js.map +0 -1
  201. package/dist/assets/ownDid-C1R5Kd8q.js +0 -282
  202. package/dist/assets/ownDid-C1R5Kd8q.js.map +0 -1
  203. package/dist/assets/ownStatus-BoTf5WqQ.js.map +0 -1
  204. package/dist/assets/profiles-DszHjEJi.js.map +0 -1
  205. package/dist/assets/registry-Da-r6eC3.js.map +0 -1
  206. package/dist/assets/registry-zUZBSHYv.js +0 -2
  207. package/dist/assets/resolve-tUzh4lHh.js +0 -400
  208. package/dist/assets/resolve-tUzh4lHh.js.map +0 -1
  209. package/dist/assets/secretGuard-DCb1I0_B.js +0 -2
  210. package/dist/assets/server-C1jZZ61O.js.map +0 -1
  211. package/dist/assets/src-DJe-OYxd.js.map +0 -1
  212. package/dist/assets/sshForges-C9zTO72R.js +0 -261
  213. package/dist/assets/sshForges-C9zTO72R.js.map +0 -1
  214. package/dist/assets/storage-Bya5b2Xt.js.map +0 -1
  215. package/dist/assets/tree-store-N362nuzZ.js.map +0 -1
  216. package/dist/assets/usdt-DI51znt-.js.map +0 -1
  217. package/dist/assets/waitNotice-Cn0WJ-He.js.map +0 -1
  218. package/dist/assets/web-DwgdhfcY.js.map +0 -1
@@ -1,17 +1,1246 @@
1
- import { An as pubkyHomeserverOf, At as checkDidJws, Bt as normalizeDid, Ca as dnsProofName, Cd as randomBytes, Cn as isPubkyProofFolder, Ct as shortAtprotoDid, Dd as utf8Encode, Dn as pubkyProofFile, Dt as DID_FILE_MAX_BYTES, Ed as utf8Decode, En as pubkyProofCapability, Et as DID_DOCUMENT_MAX_BYTES, Ft as didWebDocumentUrl, Gt as staticDidDocument, Ht as parseDidDocument, It as didWebFile, Ki as IdentityCheckUnavailable, Kt as strictBase64Url, Lt as didWebFileNames, Mt as didGhostlyServiceEntry, Nt as didJwsAlg, On as pubkyProofPath, Pa as wellKnownUrl, Pt as didSignedMessages, Qt as resolveDidDht, Rt as didWebFileUrl, Sn as isPubkyKey, Ta as domainWellKnownFile, Tn as normalizePubkyKey, Tt as verifyAtprotoRecordProof, Ut as parseDidSignaturePaste, Vt as parseDid, Wt as signingKeys, _t as atprotoProofRecord, at as parseSshSignature, bt as isAtprotoDid, ct as verifySshSignature, dt as decodeAnyBitcoinAddress, ft as ATPROTO_DECLARED_SCOPE, ht as ATPROTO_PROOF_SCOPE, it as parseSshPublicKey, jt as checkDidSignature, ka as normalizeDomain, kn as homeserverWebEndpoint, kt as DidError, lt as verifyBitcoinMessage, mt as ATPROTO_PROOF_COLLECTION, nt as SSHSIG_NAMESPACE, od as openRelayPayload, pt as ATPROTO_FULL_SCOPE, qt as DidDhtError, rd as RELAY_PAYLOAD_MAX_BYTES, rt as SshSigError, st as sshSignCommand, ut as BitcoinAddressError, vt as atprotoProofRkey, wa as domainTxtRecord, wd as toBase64Url, wn as newPubkyProofFolder, wt as AtprotoProofError, xd as fromBase64Url, xn as PUBKY_PROOF_MAX_BYTES, xt as normalizeAtprotoHandle, yt as checkAtprotoProofRecord, zt as didWebHost } from "./src-DJe-OYxd.js";
2
- import { c as boundedIdentityFetch, i as registeredIdentityProviders, s as reserveAdapterIds, t as ownDid, u as testBuild } from "./ownDid-C1R5Kd8q.js";
3
- import { a as verifiedAtprotoHandle, c as assertDomainRecord, d as chosenResolver, f as resolverById, i as resolveAtprotoHandle, l as assertNip05, p as pkarrRelays, r as resolveAtprotoDid, s as DomainCheckError, t as assertPublicServer, u as assertPublicHost } from "./resolve-tUzh4lHh.js";
4
- import { a as PUBKY_RELAYS, c as isConfigured, d as providerForIssuer, i as validForgeLogin, l as issuerFor, n as SSH_FORGE_LABEL, o as audiences, r as checkSshForge, s as clientIdFor, t as SSH_FORGE_HOST, u as oidcProviders } from "./sshForges-C9zTO72R.js";
1
+ import { a as fromZ32, d as utf8Decode, f as utf8Encode, i as fromBase64Url, l as toBase64Url, n as concatBytes, o as isZ32Key, s as randomBytes, t as bytesEqual, u as toZ32 } from "./bytes-C1DNGY18.js";
2
+ import { a as domainWellKnownFile, i as domainTxtRecord, l as normalizeDomain, m as wellKnownUrl, r as dnsProofName } from "./domainProofs-BDNP1dIy.js";
3
+ import { C as normalizeAtprotoHandle, E as verifyAtprotoRecordProof, S as isAtprotoDid, T as AtprotoProofError, _ as ATPROTO_PROOF_COLLECTION, a as verifiedAtprotoHandle, b as atprotoProofRkey, c as assertDomainRecord, d as chosenResolver, f as resolverById, g as ATPROTO_FULL_SCOPE, h as ATPROTO_DECLARED_SCOPE, i as resolveAtprotoHandle, l as assertNip05, p as pkarrRelays, r as resolveAtprotoDid, s as DomainCheckError, t as assertPublicServer, u as assertPublicHost, v as ATPROTO_PROOF_SCOPE, w as shortAtprotoDid, x as checkAtprotoProofRecord, y as atprotoProofRecord } from "./resolve-CIc3KZMV.js";
4
+ import { _ as sshSignCommand, a as PUBKY_RELAYS, c as isConfigured, d as providerForIssuer, g as parseSshSignature, h as parseSshPublicKey, i as validForgeLogin, l as issuerFor, m as SshSigError, n as SSH_FORGE_LABEL, o as audiences, p as SSHSIG_NAMESPACE, r as checkSshForge, s as clientIdFor, t as SSH_FORGE_HOST, u as oidcProviders, v as verifySshSignature } from "./sshForges-BnvwmNj-.js";
5
+ import { s as IdentityCheckUnavailable } from "./identityProofs-Cksc_K7_.js";
6
+ import { C as normalizePubkyKey, E as pubkyProofPath, S as newPubkyProofFolder, T as pubkyProofFile, _ as resolveDidDht, b as isPubkyKey, c as boundedIdentityFetch, f as DidDhtError, i as registeredIdentityProviders, s as reserveAdapterIds, t as ownDid, u as testBuild, w as pubkyProofCapability, x as isPubkyProofFolder, y as PUBKY_PROOF_MAX_BYTES } from "./ownDid-DY3rYqDI.js";
7
+ import { c as openRelayPayload, f as decodeDnsAnswers, h as readDnsName, i as RELAY_PAYLOAD_MAX_BYTES } from "./pkarr-BQo4PcCg.js";
5
8
  import { ed25519 } from "@noble/curves/ed25519.js";
6
9
  import { sha256 } from "@noble/hashes/sha2.js";
7
- import { schnorr } from "@noble/curves/secp256k1.js";
10
+ import { base58, base64, bech32, bech32m, createBase58check } from "@scure/base";
11
+ import { schnorr, secp256k1 } from "@noble/curves/secp256k1.js";
12
+ import { p256 } from "@noble/curves/nist.js";
13
+ import { ripemd160 } from "@noble/hashes/legacy.js";
14
+ import { bytesToNumberBE } from "@noble/curves/utils.js";
8
15
  import { generateSecretKey } from "nostr-tools/pure";
9
16
  import { decode, npubEncode } from "nostr-tools/nip19";
10
- //#region ../browser/src/proofs/contract.ts
17
+ // ../core/src/pkdns.ts
18
+ /**
19
+ * Pubky's PKDNS records, read (https://pubky.org). A Pubky key's signed Pkarr packet names its homeserver in an
20
+ * HTTPS (or SVCB) record at `_pubky` whose target is the homeserver's own key; the homeserver's packet names, in
21
+ * HTTPS records at its root, where it answers: its Pubky TLS endpoint (target ".", for native clients) and an ICANN
22
+ * host name for browsers. The Pubky SDK resolves exactly this. Packets reach these functions already checked
23
+ * against their key (`openRelayPayload`); nothing here trusts a host or URL from anywhere else.
24
+ */
25
+ var SVCB = 64;
26
+ var HTTPS = 65;
27
+ /** SvcParamKey "port" (RFC 9460). */
28
+ var PORT = 3;
29
+ var Z32 = /^[ybndrfg8ejkmcpqxot1uwisza345h769]{52}$/;
30
+ var u16 = (data, at) => data[at] << 8 | data[at + 1];
31
+ /** Every SVCB and HTTPS record of a DNS packet, in packet order. Throws on a malformed one. */
32
+ function decodeSvcbRecords(dnsPacket) {
33
+ const records = [];
34
+ for (const answer of decodeDnsAnswers(dnsPacket)) {
35
+ if (answer.type !== SVCB && answer.type !== HTTPS) continue;
36
+ const end = answer.offset + answer.length;
37
+ if (answer.length < 3) throw new Error("SVCB record too short");
38
+ const priority = u16(dnsPacket, answer.offset);
39
+ const { name: target, next } = readDnsName(dnsPacket, answer.offset + 2);
40
+ if (next > end) throw new Error("SVCB target out of bounds");
41
+ const params = /* @__PURE__ */ new Map();
42
+ for (let at = next; at < end;) {
43
+ if (at + 4 > end) throw new Error("SVCB parameter out of bounds");
44
+ const key = u16(dnsPacket, at), length = u16(dnsPacket, at + 2);
45
+ at += 4;
46
+ if (at + length > end) throw new Error("SVCB parameter out of bounds");
47
+ if (!params.has(key)) params.set(key, dnsPacket.slice(at, at + length));
48
+ at += length;
49
+ }
50
+ records.push({
51
+ name: answer.name.toLowerCase(),
52
+ priority,
53
+ target: target.toLowerCase(),
54
+ params
55
+ });
56
+ }
57
+ return records;
58
+ }
59
+ /**
60
+ * The homeserver a Pubky key's packet names: the z-base-32 key its `_pubky` record points at, or undefined. The target
61
+ * is read next as a key (`pubkyRecords` checks the homeserver's packet against it), so only a canonical one names a
62
+ * homeserver; a respelled one is none, not a lookup that fails as "no records".
63
+ */
64
+ function pubkyHomeserverOf(dnsPacket, userZ32) {
65
+ const record = decodeSvcbRecords(dnsPacket).find((r) => r.name === `_pubky.${userZ32}` || r.name === "_pubky");
66
+ return record && isZ32Key(record.target) ? record.target : void 0;
67
+ }
68
+ /**
69
+ * The homeserver's web endpoint from its own packet: of the HTTPS/SVCB records at its root, the lowest priority one
70
+ * whose target is a public ICANN host name (not ".", not another Pkarr key, not a name that only works on private
71
+ * networks, which would point a contact's app inward), with its port parameter. Undefined when there is none.
72
+ */
73
+ function homeserverWebEndpoint(dnsPacket, homeserverZ32) {
74
+ const records = decodeSvcbRecords(dnsPacket).filter((r) => (r.name === homeserverZ32 || r.name === "") && r.priority > 0).sort((a, b) => a.priority - b.priority);
75
+ for (const r of records) {
76
+ if (!r.target || Z32.test(r.target.split(".")[0])) continue;
77
+ let host;
78
+ try {
79
+ host = normalizeDomain(r.target);
80
+ } catch {
81
+ continue;
82
+ }
83
+ const port = r.params.get(PORT);
84
+ if (port && port.length !== 2) continue;
85
+ const number = port ? u16(port, 0) : void 0;
86
+ if (number === 0) continue;
87
+ return number === void 0 || number === 443 ? { host } : {
88
+ host,
89
+ port: number
90
+ };
91
+ }
92
+ }
93
+ // ../core/src/did.ts
94
+ /**
95
+ * Decentralized identifiers (W3C DID Core 1.0) as external identities, network-free half: DID syntax,
96
+ * the documents did:key and did:jwk carry in the identifier itself, did:web's URLs, strict parsing of a
97
+ * fetched DID document, and JWS / raw signatures by the keys it lists. Fetching did:web documents and
98
+ * did:dht records is the browser's (`packages/browser/src/proofs/did.ts`).
99
+ *
100
+ * Only keys a document lists under `authentication` or `assertionMethod` may sign for the DID: a key
101
+ * listed only for key agreement or capability delegation does not speak for it.
102
+ */
103
+ var DidError = class extends Error {};
104
+ var DID_METHODS = [
105
+ "key",
106
+ "jwk",
107
+ "dht",
108
+ "web"
109
+ ];
110
+ var RELATIONSHIPS = ["authentication", "assertionMethod"];
111
+ /** A fetched did.json. */
112
+ var DID_DOCUMENT_MAX_BYTES = 65536;
113
+ /** The statement file a did:web publishes beside its did.json. */
114
+ var DID_FILE_MAX_BYTES = 16384;
115
+ /** Entries read from each list of a document; the rest are ignored. */
116
+ var MAX_ENTRIES = 64;
117
+ /** The service type a did.json uses to vouch for a Ghostly proof. */
118
+ var DID_GHOSTLY_SERVICE = "GhostlyIdentityProof";
119
+ var METHOD_NAME = /^[a-z0-9]+$/;
120
+ var Z32_KEY = /^[ybndrfg8ejkmcpqxot1uwisza345h769]{52}$/;
121
+ var B64URL = /^[A-Za-z0-9_-]*$/;
122
+ var SEGMENT$1 = /^[A-Za-z0-9._~-]{1,64}$/;
123
+ var HEX64$2 = /^[a-f0-9]{64}$/;
124
+ var METHOD_LIST = "did:key, did:jwk, did:dht and did:web";
125
+ /** base64url without padding, strictly: decoding and encoding again gives the same text. */
126
+ function strictBase64Url(value) {
127
+ if (typeof value !== "string" || !B64URL.test(value) || value.length % 4 === 1) throw new DidError("Not base64url");
128
+ const pad = "=".repeat((4 - value.length % 4) % 4);
129
+ const bytes = Uint8Array.from(atob(value.replace(/-/g, "+").replace(/_/g, "/") + pad), (c) => c.charCodeAt(0));
130
+ if (toBase64Url(bytes) !== value) throw new DidError("Not canonical base64url");
131
+ return bytes;
132
+ }
133
+ var isObject = (v) => !!v && typeof v === "object" && !Array.isArray(v);
134
+ /**
135
+ * The DID a person typed, checked and in canonical form, or a message they can act on. Methods other than
136
+ * the four Ghostly checks are refused with "not supported yet"; a DID URL (a `#fragment`, `?query` or
137
+ * `/path`) is refused, since it names something inside a DID rather than the DID.
138
+ */
139
+ function parseDid(input) {
140
+ if (typeof input !== "string") throw new DidError("Enter a DID, like did:key:z6Mk… or did:web:example.com");
141
+ const value = input.trim();
142
+ if (!/^did:/i.test(value)) throw new DidError("Enter a DID, like did:key:z6Mk… or did:web:example.com");
143
+ if (value.length > 512) throw new DidError(`That DID is too long (at most 512 characters)`);
144
+ if (/[#?/]/.test(value)) throw new DidError("Enter the DID alone, without a #fragment, ?query or /path");
145
+ const rest = value.slice(4);
146
+ const colon = rest.indexOf(":");
147
+ const method = colon > 0 ? rest.slice(0, colon) : "";
148
+ const id = colon > 0 ? rest.slice(colon + 1) : "";
149
+ if (!METHOD_NAME.test(method.toLowerCase()) || !id) throw new DidError("That is not a DID: it looks like did:<method>:<identifier>");
150
+ if (method !== method.toLowerCase() && DID_METHODS.includes(method.toLowerCase())) throw new DidError(`Write the method in lowercase: did:${method.toLowerCase()}:…`);
151
+ if (!DID_METHODS.includes(method)) throw new DidError(`did:${method} is not supported yet. Ghostly checks ${METHOD_LIST}.`);
152
+ if (!/^[\x21-\x7e]+$/.test(id)) throw new DidError("A DID has no spaces or other special characters");
153
+ switch (method) {
154
+ case "key":
155
+ staticKey(`did:key:${id}`);
156
+ return {
157
+ did: `did:key:${id}`,
158
+ method: "key",
159
+ id
160
+ };
161
+ case "jwk":
162
+ staticKey(`did:jwk:${id}`);
163
+ return {
164
+ did: `did:jwk:${id}`,
165
+ method: "jwk",
166
+ id
167
+ };
168
+ case "dht": {
169
+ const key = id.toLowerCase();
170
+ if (!Z32_KEY.test(key) || toZ32(fromZ32(key)) !== key) throw new DidError("A did:dht identifier is 52 z-base-32 characters");
171
+ return {
172
+ did: `did:dht:${key}`,
173
+ method: "dht",
174
+ id: key
175
+ };
176
+ }
177
+ case "web": {
178
+ const web = parseWeb(id);
179
+ return {
180
+ did: `did:web:${web.id}`,
181
+ method: "web",
182
+ id: web.id
183
+ };
184
+ }
185
+ }
186
+ }
187
+ /** The canonical form of a DID Ghostly checks (a lowercase did:web host, a lowercase did:dht key). */
188
+ var normalizeDid = (input) => parseDid(input).did;
189
+ function parseWeb(id) {
190
+ const [hostPart, ...path] = id.split(":");
191
+ const portMatch = /^(.*)%3a(\d{1,5})$/i.exec(hostPart);
192
+ const hostInput = portMatch ? portMatch[1] : hostPart;
193
+ if (/%/.test(hostInput)) throw new DidError("A did:web domain has no percent-encoding, other than %3A before a port");
194
+ let host;
195
+ try {
196
+ host = normalizeDomain(hostInput);
197
+ } catch (e) {
198
+ throw new DidError(`did:web: ${e.message}`);
199
+ }
200
+ if (hostInput.toLowerCase().replace(/\.$/, "") !== host) throw new DidError("did:web: write the domain as ASCII (punycode for international names)");
201
+ let port;
202
+ if (portMatch) {
203
+ port = Number(portMatch[2]);
204
+ if (!(port >= 1 && port <= 65535) || String(port) !== portMatch[2]) throw new DidError("did:web: that port is not valid");
205
+ }
206
+ if (path.length > 8) throw new DidError("did:web: at most 8 path segments");
207
+ for (const segment of path) if (!SEGMENT$1.test(segment) || segment === "." || segment === "..") throw new DidError("did:web: each path segment is letters, digits, dots, dashes, underscores or tildes");
208
+ return {
209
+ id: [`${host}${port ? `%3A${port}` : ""}`, ...path].join(":"),
210
+ host,
211
+ port,
212
+ path
213
+ };
214
+ }
215
+ /**
216
+ * A did:web (or one of its URLs) as `parseDid` writes it: the domain in lowercase, the port's `%3a` written `%3A`.
217
+ * A domain and percent-encoding are case-insensitive (RFC 3986), so a document may write either, and parseDid
218
+ * lowercased what the person typed. The path and the fragment are left as they are; one parseDid refuses too.
219
+ */
220
+ var webForm = (value) => {
221
+ if (!value.startsWith("did:web:")) return value;
222
+ const at = value.indexOf("#");
223
+ const part = at < 0 ? value : value.slice(0, at);
224
+ let did;
225
+ try {
226
+ did = /^[\x21-\x7e]+$/.test(part) ? parseDid(part).did : part;
227
+ } catch {
228
+ did = part.replace(/%3a/g, "%3A");
229
+ }
230
+ return at < 0 ? did : did + value.slice(at);
231
+ };
232
+ var web = (did) => {
233
+ const parsed = parseDid(did);
234
+ if (parsed.method !== "web") throw new DidError("Not a did:web");
235
+ return parseWeb(parsed.id);
236
+ };
237
+ /** The host a did:web lives on (no port): the name looked up before contacting it. */
238
+ var didWebHost = (did) => web(did).host;
239
+ var origin = (w) => `https://${w.host}${w.port ? `:${w.port}` : ""}`;
240
+ /** did:web → its did.json: `/.well-known/did.json` for a bare domain, `/<path>/did.json` otherwise. */
241
+ function didWebDocumentUrl(did) {
242
+ const w = web(did);
243
+ return `${origin(w)}/${w.path.length ? w.path.join("/") : ".well-known"}/did.json`;
244
+ }
245
+ /** Where a did:web publishes the statement of proof `proofId`: `ghostly/<id>.json` beside its did.json. */
246
+ function didWebFileUrl(did, proofId) {
247
+ if (!HEX64$2.test(proofId)) throw new DidError("Invalid proof id");
248
+ const w = web(did);
249
+ return `${origin(w)}/${w.path.length ? w.path.join("/") : ".well-known"}/ghostly/${proofId}.json`;
250
+ }
251
+ /** The body of that file: the DID and the exact statement text. */
252
+ function didWebFile(did, statement) {
253
+ return JSON.stringify({
254
+ ghostly: 1,
255
+ did,
256
+ statement
257
+ }, null, 2) + "\n";
258
+ }
259
+ /** True when `text` is a statement file for exactly this DID and statement. */
260
+ function didWebFileNames(text, did, statement) {
261
+ if (typeof text !== "string" || utf8Encode(text).length > 16384) return false;
262
+ let body;
263
+ try {
264
+ body = JSON.parse(text);
265
+ } catch {
266
+ return false;
267
+ }
268
+ return isObject(body) && body.ghostly === 1 && typeof body.did === "string" && webForm(body.did) === did && body.statement === statement;
269
+ }
270
+ /** The service entry a did.json can carry instead of the file. */
271
+ function didGhostlyServiceEntry(did, key, proofId) {
272
+ return {
273
+ id: `${did}#ghostly-${proofId.slice(0, 12)}`,
274
+ type: DID_GHOSTLY_SERVICE,
275
+ serviceEndpoint: {
276
+ key,
277
+ proof: proofId
278
+ }
279
+ };
280
+ }
281
+ /** Multicodec prefixes (unsigned varint) of the public keys Ghostly checks, and X25519 to name it when refused. */
282
+ var MULTICODEC = [
283
+ {
284
+ prefix: [237, 1],
285
+ curve: "Ed25519",
286
+ length: 32
287
+ },
288
+ {
289
+ prefix: [231, 1],
290
+ curve: "secp256k1",
291
+ length: 33
292
+ },
293
+ {
294
+ prefix: [128, 36],
295
+ curve: "P-256",
296
+ length: 33
297
+ },
298
+ {
299
+ prefix: [236, 1],
300
+ curve: "X25519",
301
+ length: 32
302
+ }
303
+ ];
304
+ /** A public key on its curve, validated; ECDSA keys compressed. */
305
+ function curveKey(curve, bytes) {
306
+ let smallOrder;
307
+ try {
308
+ if (curve !== "Ed25519") return (curve === "secp256k1" ? secp256k1 : p256).Point.fromBytes(bytes).toBytes(true);
309
+ if (bytes.length !== 32) throw new Error();
310
+ smallOrder = ed25519.Point.fromBytes(bytes).isSmallOrder();
311
+ } catch {
312
+ throw new DidError(`That ${curve} key is not a valid point`);
313
+ }
314
+ if (smallOrder) throw new DidError("That Ed25519 key is a point of small order, which no secret key goes with");
315
+ return bytes;
316
+ }
317
+ /** A `z…` multibase (base58btc) multicodec key. X25519 and unknown codecs are `undefined`. */
318
+ function multikey(value) {
319
+ if (typeof value !== "string" || !value.startsWith("z") || value.length > 128) return void 0;
320
+ let bytes;
321
+ try {
322
+ bytes = base58.decode(value.slice(1));
323
+ } catch {
324
+ return;
325
+ }
326
+ const codec = MULTICODEC.find((c) => bytes[0] === c.prefix[0] && bytes[1] === c.prefix[1]);
327
+ if (!codec || bytes.length !== codec.length + 2) return void 0;
328
+ if (codec.curve === "X25519") return { curve: "X25519" };
329
+ return {
330
+ curve: codec.curve,
331
+ publicKey: curveKey(codec.curve, bytes.subarray(2))
332
+ };
333
+ }
334
+ var JWK_CURVES = {
335
+ Ed25519: {
336
+ kty: "OKP",
337
+ curve: "Ed25519"
338
+ },
339
+ secp256k1: {
340
+ kty: "EC",
341
+ curve: "secp256k1"
342
+ },
343
+ "P-256": {
344
+ kty: "EC",
345
+ curve: "P-256"
346
+ }
347
+ };
348
+ /** A public JWK. Other curves are `undefined`; a malformed one throws. */
349
+ function jwkKey(jwk) {
350
+ if (!isObject(jwk)) throw new DidError("That JWK is not an object");
351
+ const spec = typeof jwk.crv === "string" ? JWK_CURVES[jwk.crv] : void 0;
352
+ if (!spec || jwk.kty !== spec.kty) return void 0;
353
+ const coordinate = (v) => {
354
+ const b = strictBase64Url(v);
355
+ if (b.length !== 32) throw new DidError("JWK coordinates are 32 bytes");
356
+ return b;
357
+ };
358
+ try {
359
+ if (spec.curve === "Ed25519") return {
360
+ curve: "Ed25519",
361
+ publicKey: curveKey("Ed25519", coordinate(jwk.x))
362
+ };
363
+ return {
364
+ curve: spec.curve,
365
+ publicKey: curveKey(spec.curve, concatBytes(Uint8Array.of(4), coordinate(jwk.x), coordinate(jwk.y)))
366
+ };
367
+ } catch (e) {
368
+ throw e instanceof DidError && /point/.test(e.message) ? e : new DidError(`That ${spec.curve} JWK is malformed`);
369
+ }
370
+ }
371
+ /**
372
+ * The single key of a did:key or did:jwk, from the identifier itself, as the method specs build their
373
+ * documents: did:key's `#<multibase>` and did:jwk's `#0`, both for authentication and assertionMethod
374
+ * (a did:jwk marked `"use": "enc"` is for encryption only).
375
+ */
376
+ function staticKey(did) {
377
+ if (did.startsWith("did:key:")) {
378
+ const mb = did.slice(8);
379
+ const key = multikey(mb);
380
+ if (!key) throw new DidError("That did:key is not an Ed25519, secp256k1 or P-256 key Ghostly can read");
381
+ if (key.curve === "X25519") throw new DidError("That did:key is an X25519 encryption key: it cannot sign");
382
+ return {
383
+ id: `${did}#${mb}`,
384
+ curve: key.curve,
385
+ publicKey: key.publicKey,
386
+ relationships: [...RELATIONSHIPS]
387
+ };
388
+ }
389
+ let jwk;
390
+ try {
391
+ jwk = JSON.parse(utf8Decode(strictBase64Url(did.slice(8))));
392
+ } catch {
393
+ throw new DidError("That did:jwk does not hold a JSON Web Key");
394
+ }
395
+ if (!isObject(jwk)) throw new DidError("That did:jwk does not hold a JSON Web Key");
396
+ if ("d" in jwk || "p" in jwk || "k" in jwk) throw new DidError("That did:jwk contains a private key. Never share it: make a new key");
397
+ const key = jwkKey(jwk);
398
+ if (!key) throw new DidError("That did:jwk is not an Ed25519, secp256k1 or P-256 key");
399
+ return {
400
+ id: `${did}#0`,
401
+ curve: key.curve,
402
+ publicKey: key.publicKey,
403
+ relationships: jwk.use === "enc" ? [] : [...RELATIONSHIPS]
404
+ };
405
+ }
406
+ /** The document of a did:key or did:jwk, which needs no network. */
407
+ function staticDidDocument(did) {
408
+ const parsed = parseDid(did);
409
+ if (parsed.method !== "key" && parsed.method !== "jwk") throw new DidError(`did:${parsed.method} is resolved over the network`);
410
+ return {
411
+ did: parsed.did,
412
+ keys: [staticKey(parsed.did)],
413
+ skipped: 0,
414
+ services: []
415
+ };
416
+ }
417
+ /** An id as absolute `<did>#<fragment>`, from `#frag` or the absolute form; undefined for another DID's. */
418
+ function methodId(did, id) {
419
+ if (typeof id !== "string" || id.length > 640) return void 0;
420
+ const absolute = id.startsWith("#") ? `${did}${id}` : webForm(id);
421
+ return absolute.startsWith(`${did}#`) && absolute.length > did.length + 1 && /^[\x21-\x7e]+$/.test(absolute) ? absolute : void 0;
422
+ }
423
+ /** Key material of one verification method: `publicKeyJwk`, `publicKeyMultibase` or (Ed25519 2018) `publicKeyBase58`. */
424
+ function methodKey(vm) {
425
+ try {
426
+ if (vm.publicKeyJwk !== void 0) return jwkKey(vm.publicKeyJwk);
427
+ if (typeof vm.publicKeyMultibase === "string") {
428
+ const key = multikey(vm.publicKeyMultibase);
429
+ if (key && key.curve !== "X25519") return key;
430
+ if (!key && vm.type === "Ed25519VerificationKey2020" && vm.publicKeyMultibase.startsWith("z")) {
431
+ const raw = base58.decode(vm.publicKeyMultibase.slice(1));
432
+ if (raw.length === 32) return {
433
+ curve: "Ed25519",
434
+ publicKey: curveKey("Ed25519", raw)
435
+ };
436
+ }
437
+ return;
438
+ }
439
+ if (typeof vm.publicKeyBase58 === "string" && vm.type === "Ed25519VerificationKey2018" && vm.publicKeyBase58.length <= 64) return {
440
+ curve: "Ed25519",
441
+ publicKey: curveKey("Ed25519", base58.decode(vm.publicKeyBase58))
442
+ };
443
+ } catch {
444
+ return;
445
+ }
446
+ }
447
+ var list = (value, name) => {
448
+ if (value === void 0) return [];
449
+ if (!Array.isArray(value)) throw new DidError(`The DID document's ${name} is not a list`);
450
+ return value.slice(0, MAX_ENTRIES);
451
+ };
452
+ /**
453
+ * A fetched or resolved DID document, strictly: it must be for exactly `did`; verification methods are
454
+ * read from `verificationMethod` and from `authentication` / `assertionMethod` (references or embedded);
455
+ * `GhostlyIdentityProof` services are kept. Keys Ghostly cannot use are counted in `skipped`.
456
+ */
457
+ function parseDidDocument(did, raw) {
458
+ if (!isObject(raw)) throw new DidError("The DID document is not a JSON object");
459
+ if (typeof raw.id !== "string" || webForm(raw.id) !== did) throw new DidError(typeof raw.id === "string" ? `The DID document is for another DID (${raw.id.slice(0, 80)})` : "The DID document has no id");
460
+ const keys = /* @__PURE__ */ new Map();
461
+ const unusable = /* @__PURE__ */ new Set();
462
+ let skipped = 0;
463
+ const add = (vm) => {
464
+ if (!isObject(vm)) {
465
+ skipped++;
466
+ return;
467
+ }
468
+ const id = methodId(did, vm.id);
469
+ if (!id) {
470
+ skipped++;
471
+ return;
472
+ }
473
+ if (keys.has(id) || unusable.has(id)) return id;
474
+ const key = methodKey(vm);
475
+ if (!key) {
476
+ unusable.add(id);
477
+ skipped++;
478
+ return id;
479
+ }
480
+ keys.set(id, {
481
+ id,
482
+ ...key,
483
+ relationships: []
484
+ });
485
+ return id;
486
+ };
487
+ for (const vm of list(raw.verificationMethod, "verificationMethod")) add(vm);
488
+ for (const relationship of RELATIONSHIPS) for (const entry of list(raw[relationship], relationship)) {
489
+ const id = typeof entry === "string" ? methodId(did, entry) : add(entry);
490
+ const key = id ? keys.get(id) : void 0;
491
+ if (key && !key.relationships.includes(relationship)) key.relationships.push(relationship);
492
+ }
493
+ const services = [];
494
+ for (const s of list(raw.service, "service")) {
495
+ if (!isObject(s)) continue;
496
+ const types = Array.isArray(s.type) ? s.type : [s.type];
497
+ const endpoint = s.serviceEndpoint;
498
+ if (!types.includes("GhostlyIdentityProof") || !isObject(endpoint)) continue;
499
+ if (typeof endpoint.key === "string" && Z32_KEY.test(endpoint.key) && typeof endpoint.proof === "string" && HEX64$2.test(endpoint.proof)) services.push({
500
+ id: typeof s.id === "string" ? s.id.slice(0, 200) : "",
501
+ key: endpoint.key,
502
+ proof: endpoint.proof
503
+ });
504
+ }
505
+ return {
506
+ did,
507
+ keys: [...keys.values()].slice(0, MAX_ENTRIES),
508
+ skipped,
509
+ services: services.slice(0, 16)
510
+ };
511
+ }
512
+ /** Keys that may sign for the DID. */
513
+ var signingKeys = (doc) => doc.keys.filter((k) => k.relationships.length > 0);
514
+ /** JWS `alg` values Ghostly checks, and the curve each needs (RFC 8037, RFC 8812, RFC 7518, RFC 9864's Ed25519). */
515
+ var DID_JWS_ALGS = {
516
+ EdDSA: "Ed25519",
517
+ Ed25519: "Ed25519",
518
+ ES256K: "secp256k1",
519
+ ES256: "P-256"
520
+ };
521
+ /** The `alg` a person's tool should write for a key on this curve. */
522
+ var didJwsAlg = (curve) => ({
523
+ Ed25519: "EdDSA",
524
+ secp256k1: "ES256K",
525
+ "P-256": "ES256"
526
+ })[curve];
527
+ /** A compact JWS, attached or detached (`header..signature`), checked for shape only. */
528
+ function parseDidJws(input) {
529
+ const jws = typeof input === "string" ? input.trim() : "";
530
+ if (!jws || jws.length > 4096) throw new DidError("That is not a compact JWS");
531
+ const parts = jws.split(".");
532
+ if (parts.length !== 3 || !parts[0] || !parts[2]) throw new DidError("A compact JWS has three parts separated by dots");
533
+ let header;
534
+ try {
535
+ const bytes = strictBase64Url(parts[0]);
536
+ if (bytes.length > 2048) throw new Error();
537
+ header = JSON.parse(utf8Decode(bytes));
538
+ } catch {
539
+ throw new DidError("The JWS header is not base64url JSON");
540
+ }
541
+ if (!isObject(header)) throw new DidError("The JWS header is not a JSON object");
542
+ const alg = header.alg;
543
+ if (typeof alg !== "string" || !DID_JWS_ALGS[alg]) throw new DidError(`The JWS uses ${typeof alg === "string" ? "another algorithm" : "no algorithm"}: Ghostly checks EdDSA, ES256K and ES256`);
544
+ if (header.kid !== void 0 && (typeof header.kid !== "string" || header.kid.length > 640)) throw new DidError("The JWS kid is not a key id");
545
+ if (header.b64 !== void 0 && typeof header.b64 !== "boolean") throw new DidError("The JWS b64 header is not true or false");
546
+ const crit = header.crit;
547
+ if (crit !== void 0 && (!Array.isArray(crit) || !crit.length || crit.some((c) => c !== "b64"))) throw new DidError("The JWS requires an extension Ghostly does not know (crit)");
548
+ const b64 = header.b64 !== false;
549
+ if (!b64 && !(Array.isArray(crit) && crit.includes("b64"))) throw new DidError("A JWS with b64 false must list it in crit");
550
+ if (!b64 && parts[1]) throw new DidError("A JWS with b64 false must be detached (header..signature)");
551
+ let signature;
552
+ try {
553
+ signature = strictBase64Url(parts[2]);
554
+ } catch {
555
+ throw new DidError("The JWS signature is not base64url");
556
+ }
557
+ if (signature.length !== 64) throw new DidError(`A ${alg} signature is 64 bytes`);
558
+ if (parts[1]) try {
559
+ strictBase64Url(parts[1]);
560
+ } catch {
561
+ throw new DidError("The JWS payload is not base64url");
562
+ }
563
+ return {
564
+ alg,
565
+ curve: DID_JWS_ALGS[alg],
566
+ kid: header.kid,
567
+ b64,
568
+ header: parts[0],
569
+ payload: parts[1],
570
+ signature
571
+ };
572
+ }
573
+ /** What a JWS signs for one candidate message: its own payload when attached (which must be that message). */
574
+ function signingInput(jws, message) {
575
+ if (jws.payload) return bytesEqual(strictBase64Url(jws.payload), message) ? utf8Encode(`${jws.header}.${jws.payload}`) : void 0;
576
+ return jws.b64 ? utf8Encode(`${jws.header}.${toBase64Url(message)}`) : concatBytes(utf8Encode(`${jws.header}.`), message);
577
+ }
578
+ function verifyWith(key, signature, message, format = "compact") {
579
+ try {
580
+ if (key.curve === "Ed25519") return format === "compact" && ed25519.verify(signature, message, key.publicKey, { zip215: false });
581
+ return (key.curve === "secp256k1" ? secp256k1 : p256).verify(signature, message, key.publicKey, {
582
+ prehash: true,
583
+ lowS: false,
584
+ format
585
+ });
586
+ } catch {
587
+ return false;
588
+ }
589
+ }
590
+ var refusedKey = () => new DidError("Signed by a key the DID document does not list under authentication or assertionMethod");
591
+ /**
592
+ * Which key of `doc` made this JWS over one of `messages` (the statement, and the statement with a
593
+ * trailing newline some tools add). With a `kid`, only that key is tried. Refused unless the key is
594
+ * listed for authentication or assertionMethod.
595
+ */
596
+ function checkDidJws(input, messages, doc) {
597
+ const jws = parseDidJws(input);
598
+ let candidates = doc.keys.filter((k) => k.curve === jws.curve);
599
+ if (jws.kid !== void 0) {
600
+ const kid = methodId(doc.did, jws.kid);
601
+ if (!kid) throw new DidError(`The JWS names a key that is not a key of ${doc.did}`);
602
+ candidates = candidates.filter((k) => k.id === kid);
603
+ if (!candidates.length) throw new DidError(doc.keys.some((k) => k.id === kid) ? `The key the JWS names is not a ${jws.curve} key: the JWS says ${jws.alg}` : "The DID document does not list the key the JWS names");
604
+ }
605
+ if (!candidates.length) throw new DidError(`The DID document lists no ${jws.curve} key for ${jws.alg}`);
606
+ let inputs;
607
+ try {
608
+ inputs = messages.map((m) => signingInput(jws, m)).filter((m) => !!m);
609
+ } catch {
610
+ inputs = [];
611
+ }
612
+ if (!inputs.length) throw new DidError("The JWS carries another text: sign exactly the statement shown");
613
+ let refused;
614
+ for (const key of candidates) {
615
+ if (!inputs.some((m) => verifyWith(key, jws.signature, m))) continue;
616
+ if (!key.relationships.length) {
617
+ refused ??= key;
618
+ continue;
619
+ }
620
+ return {
621
+ key,
622
+ alg: jws.alg
623
+ };
624
+ }
625
+ if (refused) throw refusedKey();
626
+ throw new DidError("The JWS signature does not match: sign exactly the statement shown, with a key of this DID");
627
+ }
628
+ /**
629
+ * Which key of `doc` made this raw signature over one of `messages`: Ed25519 (64 bytes), or ECDSA with
630
+ * SHA-256 on secp256k1 or P-256 (64 bytes r‖s, or DER as OpenSSL writes it). `vm` narrows it to one key.
631
+ * Returns the signature in its canonical form (r‖s for ECDSA).
632
+ */
633
+ function checkDidSignature(signature, messages, doc, vm) {
634
+ let candidates = doc.keys;
635
+ if (vm !== void 0) {
636
+ const id = methodId(doc.did, vm);
637
+ if (!id) throw new DidError(`The proof names a key that is not a key of ${doc.did}`);
638
+ candidates = candidates.filter((k) => k.id === id);
639
+ if (!candidates.length) throw new DidError("The DID document does not list the key the proof names");
640
+ }
641
+ const der = signature.length !== 64 && signature[0] === 48;
642
+ if (signature.length !== 64 && !der) throw new DidError("A signature is 64 bytes (or DER, for ECDSA)");
643
+ let refused;
644
+ for (const key of candidates) {
645
+ if (der && key.curve === "Ed25519") continue;
646
+ if (!messages.some((m) => verifyWith(key, signature, m, der ? "der" : "compact"))) continue;
647
+ if (!key.relationships.length) {
648
+ refused ??= key;
649
+ continue;
650
+ }
651
+ const canonical = der ? (key.curve === "secp256k1" ? secp256k1 : p256).Signature.fromBytes(signature, "der").toBytes("compact") : signature;
652
+ return {
653
+ key,
654
+ alg: key.curve === "Ed25519" ? "Ed25519" : `ECDSA ${key.curve}`,
655
+ signature: canonical
656
+ };
657
+ }
658
+ if (refused) throw refusedKey();
659
+ throw new DidError("The signature does not match: sign exactly the statement shown, with a key of this DID");
660
+ }
661
+ function parseDidSignaturePaste(pasted) {
662
+ const tokens = (typeof pasted === "string" ? pasted : "").trim().split(/\s+/).filter(Boolean);
663
+ if (!tokens.length) throw new DidError("Paste the signature");
664
+ const vm = tokens.length > 1 && /^(did:|#)/.test(tokens[0]) ? tokens[0] : void 0;
665
+ const text = (vm ? tokens.slice(1) : tokens).join("");
666
+ if (text.split(".").length === 3) {
667
+ if (vm) throw new DidError("Paste the JWS alone: its header names the key (kid)");
668
+ return {
669
+ kind: "jws",
670
+ jws: text
671
+ };
672
+ }
673
+ if (text.length > 400) throw new DidError("That is too long for a signature");
674
+ let signature;
675
+ if (/^(?:[0-9a-fA-F]{2})+$/.test(text)) signature = Uint8Array.from(text.match(/../g), (h) => parseInt(h, 16));
676
+ else {
677
+ const url = text.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
678
+ try {
679
+ signature = strictBase64Url(url);
680
+ } catch {
681
+ signature = void 0;
682
+ }
683
+ }
684
+ if (!signature) throw new DidError("That is not a signature: paste a JWS, or a signature in hex or base64");
685
+ return {
686
+ kind: "raw",
687
+ vm,
688
+ signature
689
+ };
690
+ }
691
+ /** The statement bytes a signature may cover: exactly the statement, or with the newline `echo` adds. */
692
+ var didSignedMessages = (statement) => [utf8Encode(statement), utf8Encode(`${statement}\n`)];
693
+ // ../core/src/bitcoinScript.ts
694
+ var base58check = createBase58check(sha256);
695
+ var sha256d = (...parts) => sha256(sha256(concatBytes(...parts)));
696
+ var hash160 = (data) => ripemd160(sha256(data));
697
+ /** Base58 versions: P2PKH, P2SH. Every test network (testnet3/4, signet, mutinynet, regtest) shares one pair. */
698
+ var BASE58 = {
699
+ mainnet: [0, 5],
700
+ testnet: [111, 196]
701
+ };
702
+ var HRP = {
703
+ mainnet: ["bc"],
704
+ testnet: ["tb", "bcrt"]
705
+ };
706
+ function decodeSegwit(address) {
707
+ if (address !== address.toLowerCase() && address !== address.toUpperCase()) return void 0;
708
+ const lower = address.toLowerCase();
709
+ for (const [coder, v0] of [[bech32, true], [bech32m, false]]) {
710
+ let decoded;
711
+ try {
712
+ decoded = coder.decode(lower, 90);
713
+ } catch {
714
+ continue;
715
+ }
716
+ if (decoded.words.length < 1) return void 0;
717
+ const version = decoded.words[0];
718
+ if (version > 16 || version === 0 !== v0) return void 0;
719
+ let program;
720
+ try {
721
+ program = coder.fromWords(decoded.words.slice(1));
722
+ } catch {
723
+ return;
724
+ }
725
+ if (program.length < 2 || program.length > 40 || version === 0 && program.length !== 20 && program.length !== 32) return void 0;
726
+ return {
727
+ hrp: decoded.prefix,
728
+ version,
729
+ program
730
+ };
731
+ }
732
+ }
733
+ /** An address refused, with a reason fit to show the person. */
734
+ var BitcoinAddressError = class extends Error {};
735
+ /** Decodes `address` for `network`, or throws a `BitcoinAddressError` saying what is wrong with it. */
736
+ function decodeBitcoinAddress(address, network) {
737
+ if (typeof address !== "string" || address.length < 14 || address.length > 90) throw new BitcoinAddressError("Not a Bitcoin address");
738
+ const other = network === "mainnet" ? "testnet" : "mainnet";
739
+ const wrongNetwork = () => new BitcoinAddressError(network === "mainnet" ? "This is a test-network address; switch the wallets to Testnet to use it" : "This is a mainnet address; switch the wallets to Mainnet to use it");
740
+ const segwit = decodeSegwit(address);
741
+ if (segwit) {
742
+ if (!HRP[network].includes(segwit.hrp)) {
743
+ if (HRP[other].includes(segwit.hrp)) throw wrongNetwork();
744
+ throw new BitcoinAddressError("Not a Bitcoin address");
745
+ }
746
+ const { version, program } = segwit;
747
+ return {
748
+ address,
749
+ type: version === 0 ? program.length === 20 ? "p2wpkh" : "p2wsh" : version === 1 && program.length === 32 ? "p2tr" : "witness-unknown",
750
+ network,
751
+ scriptPubKey: concatBytes(Uint8Array.of(version === 0 ? 0 : 80 + version, program.length), program),
752
+ program,
753
+ witnessVersion: version
754
+ };
755
+ }
756
+ let payload;
757
+ try {
758
+ payload = base58check.decode(address);
759
+ } catch {
760
+ throw new BitcoinAddressError("Not a Bitcoin address (bad checksum?)");
761
+ }
762
+ if (payload.length !== 21) throw new BitcoinAddressError("Not a Bitcoin address");
763
+ const [pkh, sh] = BASE58[network];
764
+ const hash = payload.slice(1);
765
+ if (payload[0] === pkh) return {
766
+ address,
767
+ type: "p2pkh",
768
+ network,
769
+ program: hash,
770
+ scriptPubKey: concatBytes(Uint8Array.of(118, 169, 20), hash, Uint8Array.of(136, 172))
771
+ };
772
+ if (payload[0] === sh) return {
773
+ address,
774
+ type: "p2sh",
775
+ network,
776
+ program: hash,
777
+ scriptPubKey: concatBytes(Uint8Array.of(169, 20), hash, Uint8Array.of(135))
778
+ };
779
+ if (BASE58[other].includes(payload[0])) throw wrongNetwork();
780
+ throw new BitcoinAddressError("Not a Bitcoin address");
781
+ }
782
+ function compactSize(n) {
783
+ if (n < 253) return Uint8Array.of(n);
784
+ if (n <= 65535) return Uint8Array.of(253, n & 255, n >>> 8);
785
+ if (n <= 4294967295) {
786
+ const b = /* @__PURE__ */ new Uint8Array(5);
787
+ b[0] = 254;
788
+ new DataView(b.buffer).setUint32(1, n, true);
789
+ return b;
790
+ }
791
+ throw new Error("Too large");
792
+ }
793
+ var varBytes = (b) => concatBytes(compactSize(b.length), b);
794
+ var u32 = (n) => {
795
+ const b = /* @__PURE__ */ new Uint8Array(4);
796
+ new DataView(b.buffer).setUint32(0, n >>> 0, true);
797
+ return b;
798
+ };
799
+ var u64 = (n) => {
800
+ const b = /* @__PURE__ */ new Uint8Array(8);
801
+ new DataView(b.buffer).setBigUint64(0, n, true);
802
+ return b;
803
+ };
804
+ function encodeTx(tx, withWitness = tx.inputs.some((i) => i.witness.length > 0)) {
805
+ const parts = [u32(tx.version)];
806
+ if (withWitness) parts.push(Uint8Array.of(0, 1));
807
+ parts.push(compactSize(tx.inputs.length));
808
+ for (const i of tx.inputs) parts.push(i.txid, u32(i.vout), varBytes(i.scriptSig), u32(i.sequence));
809
+ parts.push(compactSize(tx.outputs.length));
810
+ for (const o of tx.outputs) parts.push(u64(o.value), varBytes(o.script));
811
+ if (withWitness) for (const i of tx.inputs) parts.push(encodeWitness(i.witness));
812
+ parts.push(u32(tx.lockTime));
813
+ return concatBytes(...parts);
814
+ }
815
+ var encodeWitness = (stack) => concatBytes(compactSize(stack.length), ...stack.map(varBytes));
816
+ /** The id other transactions refer to it by, in internal byte order (reverse it for display). */
817
+ var txHash = (tx) => sha256d(encodeTx(tx, false));
818
+ /** A strict reader: canonical sizes only, and the whole input must be consumed. */
819
+ var ByteReader = class {
820
+ bytes;
821
+ at = 0;
822
+ constructor(bytes) {
823
+ this.bytes = bytes;
824
+ }
825
+ get done() {
826
+ return this.at === this.bytes.length;
827
+ }
828
+ take(n) {
829
+ if (!Number.isSafeInteger(n) || n < 0 || this.at + n > this.bytes.length) throw new Error("Truncated data");
830
+ const out = this.bytes.slice(this.at, this.at + n);
831
+ this.at += n;
832
+ return out;
833
+ }
834
+ peek() {
835
+ if (this.done) throw new Error("Truncated data");
836
+ return this.bytes[this.at];
837
+ }
838
+ u32() {
839
+ return new DataView(this.take(4).buffer).getUint32(0, true);
840
+ }
841
+ i32() {
842
+ return new DataView(this.take(4).buffer).getInt32(0, true);
843
+ }
844
+ u64() {
845
+ return new DataView(this.take(8).buffer).getBigUint64(0, true);
846
+ }
847
+ compactSize() {
848
+ const first = this.take(1)[0];
849
+ const [n, min] = first < 253 ? [first, 0] : first === 253 ? [new DataView(this.take(2).buffer).getUint16(0, true), 253] : first === 254 ? [this.u32(), 65536] : [Number(this.u64()), 4294967296];
850
+ if (n < min || n > 33554432) throw new Error("Non-canonical size");
851
+ return n;
852
+ }
853
+ varBytes() {
854
+ return this.take(this.compactSize());
855
+ }
856
+ end() {
857
+ if (!this.done) throw new Error("Unexpected trailing data");
858
+ }
859
+ };
860
+ function decodeWitness(bytes) {
861
+ const r = new ByteReader(bytes);
862
+ const stack = readWitness(r);
863
+ r.end();
864
+ return stack;
865
+ }
866
+ function readWitness(r) {
867
+ const n = r.compactSize();
868
+ return Array.from({ length: n }, () => r.varBytes());
869
+ }
870
+ function decodeTx(bytes) {
871
+ const r = new ByteReader(bytes);
872
+ const version = r.i32();
873
+ let segwit = false;
874
+ if (r.peek() === 0) {
875
+ r.take(1);
876
+ if (r.take(1)[0] !== 1) throw new Error("Unknown transaction flag");
877
+ segwit = true;
878
+ }
879
+ const inputs = Array.from({ length: r.compactSize() }, () => ({
880
+ txid: r.take(32),
881
+ vout: r.u32(),
882
+ scriptSig: r.varBytes(),
883
+ sequence: r.u32(),
884
+ witness: []
885
+ }));
886
+ const outputs = Array.from({ length: r.compactSize() }, () => ({
887
+ value: r.u64(),
888
+ script: r.varBytes()
889
+ }));
890
+ if (segwit) {
891
+ for (const input of inputs) input.witness = readWitness(r);
892
+ if (inputs.every((i) => i.witness.length === 0)) throw new Error("Superfluous witness flag");
893
+ }
894
+ const lockTime = r.u32();
895
+ r.end();
896
+ return {
897
+ version,
898
+ inputs,
899
+ outputs,
900
+ lockTime
901
+ };
902
+ }
903
+ /** The address decoded on whichever network it belongs to (mainnet first), or a `BitcoinAddressError`. */
904
+ function decodeAnyBitcoinAddress(address) {
905
+ try {
906
+ return decodeBitcoinAddress(address, "mainnet");
907
+ } catch (e) {
908
+ if (!(e instanceof BitcoinAddressError) || !/test-network/.test(e.message)) throw e;
909
+ return decodeBitcoinAddress(address, "testnet");
910
+ }
911
+ }
912
+ // ../core/src/bip322.ts
913
+ /** A refusal while verifying; `inconclusive` for what cannot be checked rather than what failed. */
914
+ var MessageRefusal = class extends Error {
915
+ state;
916
+ constructor(state, reason) {
917
+ super(reason);
918
+ this.state = state;
919
+ }
920
+ };
921
+ var invalid = (reason) => new MessageRefusal("invalid", reason);
922
+ var inconclusive = (reason) => new MessageRefusal("inconclusive", reason);
923
+ var SIGHASH_DEFAULT = 0;
924
+ var SIGHASH_ALL = 1;
925
+ var OP_RETURN = Uint8Array.of(106);
926
+ var ZERO32 = /* @__PURE__ */ new Uint8Array(32);
927
+ var bip322MessageHash = (message) => schnorr.utils.taggedHash("BIP0322-signed-message", utf8Encode(message));
928
+ /** The virtual transaction whose only output pays the address; `to_sign` spends it. */
929
+ function bip322ToSpend(message, scriptPubKey) {
930
+ return {
931
+ version: 0,
932
+ lockTime: 0,
933
+ inputs: [{
934
+ txid: ZERO32,
935
+ vout: 4294967295,
936
+ sequence: 0,
937
+ witness: [],
938
+ scriptSig: concatBytes(Uint8Array.of(0, 32), bip322MessageHash(message))
939
+ }],
940
+ outputs: [{
941
+ value: 0n,
942
+ script: scriptPubKey
943
+ }]
944
+ };
945
+ }
946
+ /** `to_sign` with every field at the default the simple format assumes. */
947
+ function bip322ToSign(toSpend, witness = []) {
948
+ return {
949
+ version: 0,
950
+ lockTime: 0,
951
+ inputs: [{
952
+ txid: txHash(toSpend),
953
+ vout: 0,
954
+ sequence: 0,
955
+ scriptSig: /* @__PURE__ */ new Uint8Array(0),
956
+ witness
957
+ }],
958
+ outputs: [{
959
+ value: 0n,
960
+ script: OP_RETURN
961
+ }]
962
+ };
963
+ }
964
+ /** Standard base64, whitespace (a pasted line break) ignored; missing padding tolerated. */
965
+ function decodeBase64(text) {
966
+ const clean = text.replace(/\s+/g, "");
967
+ const padded = clean.length % 4 === 0 ? clean : clean + "=".repeat(4 - clean.length % 4);
968
+ try {
969
+ return base64.decode(padded);
970
+ } catch {
971
+ throw invalid("The signature is not valid base64");
972
+ }
973
+ }
974
+ /** BIP 143, for witness v0. `scriptCode` is the P2PKH script of the key. */
975
+ function sighashV0(tx, scriptCode, hashType) {
976
+ const input = tx.inputs[0];
977
+ return sha256d(u32(tx.version), sha256d(...tx.inputs.map((i) => concatBytes(i.txid, u32(i.vout)))), sha256d(...tx.inputs.map((i) => u32(i.sequence))), input.txid, u32(input.vout), varBytes(scriptCode), u64(0n), u32(input.sequence), sha256d(...tx.outputs.map((o) => concatBytes(u64(o.value), varBytes(o.script)))), u32(tx.lockTime), u32(hashType));
978
+ }
979
+ /** BIP 341 key path, SIGHASH_DEFAULT or SIGHASH_ALL, no annex. */
980
+ function sighashV1(tx, scriptPubKey, hashType) {
981
+ const input = tx.inputs[0];
982
+ return schnorr.utils.taggedHash("TapSighash", concatBytes(Uint8Array.of(0, hashType), u32(tx.version), u32(tx.lockTime), sha256(concatBytes(input.txid, u32(input.vout))), sha256(u64(0n)), sha256(varBytes(scriptPubKey)), sha256(u32(input.sequence)), sha256(concatBytes(...tx.outputs.map((o) => concatBytes(u64(o.value), varBytes(o.script))))), Uint8Array.of(0), u32(0)));
983
+ }
984
+ /** The original sighash, for P2PKH: the input's script replaced by the spent output's, the rest as is. */
985
+ function sighashLegacy(tx, scriptPubKey, hashType) {
986
+ return sha256d(encodeTx({
987
+ ...tx,
988
+ inputs: tx.inputs.map((i, n) => ({
989
+ ...i,
990
+ witness: [],
991
+ scriptSig: n === 0 ? scriptPubKey : /* @__PURE__ */ new Uint8Array(0)
992
+ }))
993
+ }, false), u32(hashType));
994
+ }
995
+ /** A check that throws on malformed input (a point off the curve…) simply does not hold. */
996
+ function holds$1(check) {
997
+ try {
998
+ return check();
999
+ } catch {
1000
+ return false;
1001
+ }
1002
+ }
1003
+ /** BIP 66 strict DER, the signature still carrying its sighash byte (Bitcoin Core's IsValidSignatureEncoding). */
1004
+ function isStrictDer(sig) {
1005
+ if (sig.length < 9 || sig.length > 73 || sig[0] !== 48 || sig[1] !== sig.length - 3 || sig[2] !== 2) return false;
1006
+ const lenR = sig[3];
1007
+ if (lenR === 0 || 5 + lenR >= sig.length) return false;
1008
+ const lenS = sig[5 + lenR];
1009
+ if (lenS === 0 || lenR + lenS + 7 !== sig.length || sig[4 + lenR] !== 2) return false;
1010
+ if (sig[4] & 128 || lenR > 1 && sig[4] === 0 && !(sig[5] & 128)) return false;
1011
+ if (sig[6 + lenR] & 128 || lenS > 1 && sig[6 + lenR] === 0 && !(sig[7 + lenR] & 128)) return false;
1012
+ return true;
1013
+ }
1014
+ /** An ECDSA check with BIP-322's required rules: SIGHASH_ALL, strict DER, low S, a valid public key. */
1015
+ function checkEcdsa(sigWithType, pubkey, sighash, compressedOnly) {
1016
+ if (sigWithType.length === 0) throw invalid("The signature is empty");
1017
+ if (!(pubkey.length === 33 ? pubkey[0] === 2 || pubkey[0] === 3 : pubkey.length === 65 && !compressedOnly && pubkey[0] === 4)) throw invalid("The signature carries a malformed public key");
1018
+ const hashType = sigWithType[sigWithType.length - 1];
1019
+ if (hashType !== SIGHASH_ALL) throw invalid("BIP-322 signatures must use SIGHASH_ALL");
1020
+ if (!isStrictDer(sigWithType)) throw invalid("The signature is not strictly DER-encoded");
1021
+ if (!holds$1(() => secp256k1.verify(sigWithType.subarray(0, -1), sighash(hashType), pubkey, {
1022
+ prehash: false,
1023
+ lowS: true,
1024
+ format: "der"
1025
+ }))) throw invalid("The signature does not match this address and message");
1026
+ }
1027
+ var P2PKH_SCRIPT = (hash) => concatBytes(Uint8Array.of(118, 169, 20), hash, Uint8Array.of(136, 172));
1028
+ function checkP2wpkh(tx, program) {
1029
+ const witness = tx.inputs[0].witness;
1030
+ if (witness.length !== 2) throw invalid("The signature does not match this address and message");
1031
+ const [sig, pubkey] = witness;
1032
+ if (pubkey.length !== 33 || !bytesEqual(hash160(pubkey), program)) throw invalid("The signature does not match this address and message");
1033
+ checkEcdsa(sig, pubkey, (t) => sighashV0(tx, P2PKH_SCRIPT(program), t), true);
1034
+ }
1035
+ /**
1036
+ * Whether a script-path witness commits to `outputKey` (BIP 341). When it does, a script runs that this
1037
+ * verifier cannot interpret; when it does not, the spend fails whatever the script says.
1038
+ */
1039
+ function commitsToOutputKey(stack, outputKey) {
1040
+ const control = stack[stack.length - 1], script = stack[stack.length - 2];
1041
+ if (control.length < 33 || (control.length - 33) % 32 !== 0 || control.length > 4129) return false;
1042
+ try {
1043
+ const internal = schnorr.utils.lift_x(bytesToNumberBE(control.subarray(1, 33)));
1044
+ let node = schnorr.utils.taggedHash("TapLeaf", Uint8Array.of(control[0] & 254), varBytes(script));
1045
+ for (let at = 33; at < control.length; at += 32) {
1046
+ const sibling = control.subarray(at, at + 32);
1047
+ node = schnorr.utils.taggedHash("TapBranch", ...compareBytes(node, sibling) < 0 ? [node, sibling] : [sibling, node]);
1048
+ }
1049
+ const tweak = bytesToNumberBE(schnorr.utils.taggedHash("TapTweak", control.subarray(1, 33), node));
1050
+ if (tweak >= secp256k1.Point.Fn.ORDER) return false;
1051
+ const q = internal.add(secp256k1.Point.BASE.multiply(tweak)).toAffine();
1052
+ return q.x === bytesToNumberBE(outputKey) && Number(q.y & 1n) === (control[0] & 1);
1053
+ } catch {
1054
+ return false;
1055
+ }
1056
+ }
1057
+ function compareBytes(a, b) {
1058
+ for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return a[i] - b[i];
1059
+ return 0;
1060
+ }
1061
+ function checkP2tr(tx, scriptPubKey, outputKey) {
1062
+ const witness = tx.inputs[0].witness;
1063
+ if (witness.length === 0) throw invalid("The signature does not match this address and message");
1064
+ if (witness.length > 1) {
1065
+ if (witness[witness.length - 1][0] === 80) throw inconclusive("Taproot signatures with an annex cannot be checked here");
1066
+ if (commitsToOutputKey(witness, outputKey)) throw inconclusive("Taproot script-path signatures cannot be checked here; sign with the address's key path");
1067
+ throw invalid("The signature does not match this address and message");
1068
+ }
1069
+ const sig = witness[0];
1070
+ let hashType;
1071
+ if (sig.length === 64) hashType = SIGHASH_DEFAULT;
1072
+ else if (sig.length === 65 && sig[64] === SIGHASH_ALL) hashType = SIGHASH_ALL;
1073
+ else if (sig.length === 65) throw invalid("BIP-322 signatures must use SIGHASH_ALL or SIGHASH_DEFAULT");
1074
+ else throw invalid("The signature does not match this address and message");
1075
+ if (!holds$1(() => schnorr.verify(sig.subarray(0, 64), sighashV1(tx, scriptPubKey, hashType), outputKey))) throw invalid("The signature does not match this address and message");
1076
+ }
1077
+ /** Exactly two direct pushes, as P2PKH's scriptSig: `<sig> <pubkey>` (MINIMALDATA holds for these sizes). */
1078
+ function parseTwoPushes(script) {
1079
+ const items = [];
1080
+ for (let at = 0; at < script.length;) {
1081
+ const n = script[at];
1082
+ if (n < 1 || n > 75 || at + 1 + n > script.length) throw invalid("The signature does not match this address and message");
1083
+ items.push(script.subarray(at + 1, at + 1 + n));
1084
+ at += 1 + n;
1085
+ }
1086
+ if (items.length !== 2) throw invalid("The signature does not match this address and message");
1087
+ return [items[0], items[1]];
1088
+ }
1089
+ function checkInput(tx, address) {
1090
+ const input = tx.inputs[0];
1091
+ const { scriptPubKey, program } = address;
1092
+ switch (address.type) {
1093
+ case "p2wpkh":
1094
+ if (input.scriptSig.length) throw invalid("A native SegWit input carries no scriptSig");
1095
+ checkP2wpkh(tx, program);
1096
+ return "p2wpkh";
1097
+ case "p2tr":
1098
+ if (input.scriptSig.length) throw invalid("A native SegWit input carries no scriptSig");
1099
+ checkP2tr(tx, scriptPubKey, program);
1100
+ return "p2tr";
1101
+ case "p2pkh": {
1102
+ if (input.witness.length) throw invalid("A P2PKH input carries no witness");
1103
+ const [sig, pubkey] = parseTwoPushes(input.scriptSig);
1104
+ if (!bytesEqual(hash160(pubkey), program)) throw invalid("The signature does not match this address and message");
1105
+ checkEcdsa(sig, pubkey, (t) => sighashLegacy(tx, scriptPubKey, t), false);
1106
+ return "p2pkh";
1107
+ }
1108
+ case "p2sh": {
1109
+ const s = input.scriptSig;
1110
+ if (s.length !== 23 || s[0] !== 22 || s[1] !== 0 || s[2] !== 20) throw inconclusive("Only P2SH-wrapped single-key SegWit (P2SH-P2WPKH) can be checked here, not a multisig or other script");
1111
+ const redeem = s.subarray(1);
1112
+ if (!bytesEqual(hash160(redeem), program)) throw invalid("The signature does not match this address and message");
1113
+ checkP2wpkh(tx, redeem.subarray(2));
1114
+ return "p2sh-p2wpkh";
1115
+ }
1116
+ case "p2wsh": throw inconclusive("Script (P2WSH) addresses such as multisig cannot be checked here");
1117
+ default: throw inconclusive("This address type cannot be checked here");
1118
+ }
1119
+ }
1120
+ /** Checks a BIP-322 signature — `smp…`, `ful…`, or an unprefixed one read as simple — or throws a `MessageRefusal`. */
1121
+ function verifyBip322(address, message, signature) {
1122
+ const text = signature.trim();
1123
+ if (text.startsWith("pof")) throw inconclusive("Proof-of-funds signatures are not accepted: Ghostly does not check balances or coins");
1124
+ const format = text.startsWith("ful") ? "bip322-full" : "bip322-simple";
1125
+ const bytes = decodeBase64(text.startsWith("smp") || text.startsWith("ful") ? text.slice(3) : text);
1126
+ if (bytes.length === 0) throw invalid("The signature is empty");
1127
+ const toSpend = bip322ToSpend(message, address.scriptPubKey);
1128
+ let toSign;
1129
+ if (format === "bip322-simple") {
1130
+ if (address.type === "p2pkh" || address.type === "p2sh") throw invalid("A simple BIP-322 signature is only for native SegWit addresses; this one needs the full format (ful…)");
1131
+ let witness;
1132
+ try {
1133
+ witness = decodeWitness(bytes);
1134
+ } catch {
1135
+ throw invalid("The signature is not a BIP-322 witness");
1136
+ }
1137
+ toSign = bip322ToSign(toSpend, witness);
1138
+ } else {
1139
+ try {
1140
+ toSign = decodeTx(bytes);
1141
+ } catch {
1142
+ throw invalid("The signature is not a BIP-322 full transaction");
1143
+ }
1144
+ if (toSign.inputs.length !== 1) throw inconclusive("Signatures over extra coins (proof of funds) are not accepted");
1145
+ const [input] = toSign.inputs;
1146
+ if (!bytesEqual(input.txid, txHash(toSpend)) || input.vout !== 0) throw invalid("The signature does not match this address and message");
1147
+ if (toSign.outputs.length !== 1 || toSign.outputs[0].value !== 0n || !bytesEqual(toSign.outputs[0].script, OP_RETURN)) throw invalid("The signature is not a BIP-322 transaction");
1148
+ if (toSign.version !== 0 && toSign.version !== 2) throw inconclusive("Unknown BIP-322 transaction version");
1149
+ }
1150
+ const script = checkInput(toSign, address);
1151
+ const { lockTime } = toSign, { sequence } = toSign.inputs[0];
1152
+ return lockTime || sequence ? {
1153
+ format,
1154
+ script,
1155
+ lockTime,
1156
+ sequence
1157
+ } : {
1158
+ format,
1159
+ script
1160
+ };
1161
+ }
1162
+ // ../core/src/bitcoinMessage.ts
1163
+ /**
1164
+ * Verifies a signed message for a Bitcoin address, in either format wallets produce:
1165
+ *
1166
+ * - **BIP-322** (see bip322.ts): `smp…` / `ful…`, or unprefixed from wallets that predate the prefixes.
1167
+ * - **Legacy signmessage** (Bitcoin Core `signmessage`, Electrum, most hardware wallets): a 65-byte
1168
+ * recoverable ECDSA signature. BIP-322 restricts it to **P2PKH** addresses (1…, m…, n…), and so does
1169
+ * this verifier: for SegWit addresses the legacy format does not commit to the script, and wallets
1170
+ * disagree on its header bytes (BIP 137 vs Electrum).
1171
+ *
1172
+ * A valid result proves the signer could sign for the address when they signed. It does not prove a
1173
+ * balance, a past payment, or that they would spend from it.
1174
+ */
1175
+ var MAX_MESSAGE = 16384;
1176
+ var MAX_SIGNATURE$1 = 16384;
1177
+ var MAGIC = utf8Encode("Bitcoin Signed Message:\n");
1178
+ /** The digest `signmessage` signs: double SHA-256 of the length-prefixed magic and message. */
1179
+ function legacyMessageHash(message) {
1180
+ const bytes = utf8Encode(message);
1181
+ return sha256d(compactSize(MAGIC.length), MAGIC, compactSize(bytes.length), bytes);
1182
+ }
1183
+ /** Header bytes 27-34 are P2PKH (uncompressed 27-30, compressed 31-34); 35-42 are BIP 137 SegWit headers. */
1184
+ var isLegacySignature = (bytes) => bytes.length === 65 && bytes[0] >= 27 && bytes[0] <= 42;
1185
+ function verifyLegacy(address, message, bytes) {
1186
+ if (address.type !== "p2pkh") throw new MessageRefusal("invalid", "This is a legacy (signmessage) signature, which Ghostly accepts only for legacy 1…/m…/n… addresses. Sign with BIP-322 for this address.");
1187
+ const header = bytes[0];
1188
+ if (header > 34) throw new MessageRefusal("invalid", "This legacy signature is marked for a SegWit address, not this one");
1189
+ const compressed = header >= 31;
1190
+ const recovery = header - 27 & 3;
1191
+ let pubkey;
1192
+ try {
1193
+ pubkey = secp256k1.Signature.fromBytes(concatBytes(Uint8Array.of(recovery), bytes.subarray(1)), "recovered").recoverPublicKey(legacyMessageHash(message)).toBytes(compressed);
1194
+ } catch {
1195
+ throw new MessageRefusal("invalid", "The signature does not match this address and message");
1196
+ }
1197
+ if (!bytesEqual(hash160(pubkey), address.program)) throw new MessageRefusal("invalid", "The signature does not match this address and message");
1198
+ }
1199
+ /** Never throws: every refusal comes back as `invalid` or `inconclusive` with a reason fit to show. */
1200
+ function verifyBitcoinMessage({ address, message, signature, network }) {
1201
+ try {
1202
+ if (typeof message !== "string" || typeof signature !== "string" || typeof address !== "string") throw new MessageRefusal("invalid", "Missing address, message or signature");
1203
+ if (utf8Encode(message).length > MAX_MESSAGE) throw new MessageRefusal("invalid", "The message is too long");
1204
+ const text = signature.trim();
1205
+ if (!text) throw new MessageRefusal("invalid", "The signature is empty");
1206
+ if (text.length > MAX_SIGNATURE$1) throw new MessageRefusal("invalid", "The signature is too long");
1207
+ const decoded = decodeBitcoinAddress(address.trim(), network);
1208
+ if (!/^(smp|ful|pof)/.test(text)) {
1209
+ const bytes = decodeBase64(text);
1210
+ if (isLegacySignature(bytes)) {
1211
+ verifyLegacy(decoded, message, bytes);
1212
+ return {
1213
+ state: "valid",
1214
+ format: "legacy",
1215
+ script: "p2pkh"
1216
+ };
1217
+ }
1218
+ }
1219
+ return {
1220
+ state: "valid",
1221
+ ...verifyBip322(decoded, message, text)
1222
+ };
1223
+ } catch (e) {
1224
+ if (e instanceof MessageRefusal) return {
1225
+ state: e.state,
1226
+ reason: e.message
1227
+ };
1228
+ if (e instanceof BitcoinAddressError) return {
1229
+ state: "invalid",
1230
+ reason: e.message
1231
+ };
1232
+ return {
1233
+ state: "invalid",
1234
+ reason: "The signature could not be read"
1235
+ };
1236
+ }
1237
+ }
1238
+ // ../browser/src/proofs/contract.ts
11
1239
  /** `english` with its `{{name}}`s filled in: what `ProviderSay` returns where no app language is at hand (the CLI, tests). */
12
1240
  var englishSay = (_key, english, values) => values ? english.replace(/\{\{(\w+)\}\}/g, (all, name) => name in values ? String(values[name]) : all) : english;
13
- //#endregion
14
- //#region ../browser/src/proofs/bitcoinWallets.ts
1241
+ /** A signer's own wait for the person's approval ended (Pubky's relay forgot the request): a time-out, not a failure. */
1242
+ var SignerTimeout = class extends Error {};
1243
+ // ../browser/src/proofs/bitcoinWallets.ts
15
1244
  /** What a proof proves and what it does not; shown next to every Bitcoin proof, given or received. */
16
1245
  var BITCOIN_PROOF_LIMITS = [
17
1246
  "Proves: whoever made this signature could sign with the key behind this address when they signed.",
@@ -116,8 +1345,7 @@ var BITCOIN_WALLET_GUIDES = [
116
1345
  function guidesFor(script) {
117
1346
  return BITCOIN_WALLET_GUIDES.filter((g) => g.scripts.includes(script));
118
1347
  }
119
- //#endregion
120
- //#region ../browser/src/proofs/providers/bitcoin.ts
1348
+ // ../browser/src/proofs/providers/bitcoin.ts
121
1349
  var MAX_SIGNATURE = 8192;
122
1350
  var SIGNATURE = /^(smp|ful|pof)?[A-Za-z0-9+/]+={0,2}$/;
123
1351
  /** Each address type's name, said under `scripts.<type>` (exported for the app's drift guard). */
@@ -277,8 +1505,7 @@ var bitcoin = {
277
1505
  };
278
1506
  }
279
1507
  };
280
- //#endregion
281
- //#region ../browser/src/proofs/displaySource.ts
1508
+ // ../browser/src/proofs/displaySource.ts
282
1509
  /**
283
1510
  * Where a proof's name came from (`display.source`), and how a Nostr proof was checked (`verified.source`), in the
284
1511
  * fixed words the providers write them in. The app says these
@@ -298,8 +1525,7 @@ var NOSTR_SIGNATURE_SOURCE = "Nostr signature (NIP-01, BIP-340)";
298
1525
  function oidcDisplaySource(provider, email, nameUnchecked = false) {
299
1526
  return `Signed by ${provider}${email === "verified" ? `; email verified by ${provider}` : email === "unverified" ? `; email not verified by ${provider}` : ""}${nameUnchecked ? `; name set on the account, not checked by ${provider}` : ""}`;
300
1527
  }
301
- //#endregion
302
- //#region ../browser/src/proofs/nostr.ts
1528
+ // ../browser/src/proofs/nostr.ts
303
1529
  function extensionSigner() {
304
1530
  return globalThis.nostr;
305
1531
  }
@@ -331,7 +1557,8 @@ function parseProofBunker(input) {
331
1557
  /**
332
1558
  * Runs `work` with the person's Nostr signer: the page's NIP-07 extension, or a NIP-46 bunker. `permissions`
333
1559
  * is what the bunker is asked for (NIP-46 `connect`): the identity proof's `sign_event:30078` by default;
334
- * the social layer asks for the kinds it publishes.
1560
+ * the social layer asks for the kinds it publishes. `timeoutMs`: how long the person has to approve, 2 minutes by default
1561
+ * (the CLI waits its --timeout).
335
1562
  */
336
1563
  async function withNostrSigner(options, work) {
337
1564
  options.signal.throwIfAborted();
@@ -341,20 +1568,6 @@ async function withNostrSigner(options, work) {
341
1568
  let timer;
342
1569
  let abort;
343
1570
  let closed = false;
344
- const guard = {
345
- getPublicKey: async () => {
346
- if (closed) throw new Error("Signer request cancelled");
347
- const key = await active.getPublicKey();
348
- if (closed) throw new Error("Signer request cancelled");
349
- return key;
350
- },
351
- signEvent: async (event) => {
352
- if (closed) throw new Error("Signer request cancelled");
353
- const signed = await active.signEvent(event);
354
- if (closed) throw new Error("Signer request cancelled");
355
- return signed;
356
- }
357
- };
358
1571
  let active;
359
1572
  try {
360
1573
  const timeout = new Promise((_, reject) => {
@@ -365,10 +1578,24 @@ async function withNostrSigner(options, work) {
365
1578
  options.signal.addEventListener("abort", abort, { once: true });
366
1579
  timer = setTimeout(() => {
367
1580
  closed = true;
368
- reject(/* @__PURE__ */ new Error("Signer timed out. Your Ghostly identity is unchanged."));
369
- }, 12e4);
1581
+ reject(new SignerTimeout("Signer timed out. Your Ghostly identity is unchanged."));
1582
+ }, options.timeoutMs ?? 12e4);
370
1583
  });
371
- const action = async () => {
1584
+ timeout.catch(() => {});
1585
+ /**
1586
+ * Only the signer's own steps (connecting, its key, a signature) are ended by the two minutes or the cancel. What
1587
+ * `work` does with an answer, such as the engine checking and saving the proof (a NIP-05 lookup takes up to 30 s),
1588
+ * runs to its end: cut short, the person read "unchanged" of a proof that was saved (agents#6035).
1589
+ */
1590
+ const step = async (asked) => {
1591
+ if (closed) throw new Error("Signer request cancelled");
1592
+ return Promise.race([asked(), timeout]);
1593
+ };
1594
+ const guard = {
1595
+ getPublicKey: () => step(() => active.getPublicKey()),
1596
+ signEvent: (event) => step(() => active.signEvent(event))
1597
+ };
1598
+ const connect = async () => {
372
1599
  if (options.bunker) {
373
1600
  const bp = parseProofBunker(options.bunker);
374
1601
  const [{ BunkerSigner }, { SimplePool }] = await Promise.all([import("nostr-tools/nip46"), import("nostr-tools/pool")]);
@@ -378,6 +1605,7 @@ async function withNostrSigner(options, work) {
378
1605
  signer = BunkerSigner.fromBunker(clientKey, bp, {
379
1606
  pool,
380
1607
  skipSwitchRelays: true,
1608
+ timeout: 0,
381
1609
  onauth: (url) => {
382
1610
  try {
383
1611
  const u = new URL(url);
@@ -396,10 +1624,10 @@ async function withNostrSigner(options, work) {
396
1624
  active = extensionSigner();
397
1625
  if (!active) throw new Error("No NIP-07 signer in this window. Use a bunker connection from your Nostr signer.");
398
1626
  }
399
- if (closed) throw new Error("Signer request cancelled");
400
- return work(guard);
401
1627
  };
402
- return await Promise.race([action(), timeout]);
1628
+ await Promise.race([connect(), timeout]);
1629
+ if (closed) throw new Error("Signer request cancelled");
1630
+ return await work(guard);
403
1631
  } finally {
404
1632
  closed = true;
405
1633
  if (timer) clearTimeout(timer);
@@ -409,8 +1637,7 @@ async function withNostrSigner(options, work) {
409
1637
  clientKey?.fill(0);
410
1638
  }
411
1639
  }
412
- //#endregion
413
- //#region ../browser/src/proofs/providers/nostr.ts
1640
+ // ../browser/src/proofs/providers/nostr.ts
414
1641
  /**
415
1642
  * NIP-78 application data (kind 30078): no new kind is claimed. Signers show it as such; it is never
416
1643
  * published to a relay — the event travels only to the contacts the person shares it with.
@@ -427,7 +1654,7 @@ function nostrProofTemplate(statement) {
427
1654
  tags: [["d", "ghostly-identity-proof"], ["expiration", String(expiresAt)]]
428
1655
  };
429
1656
  }
430
- var hex$1 = (b) => Array.from(b, (x) => x.toString(16).padStart(2, "0")).join("");
1657
+ var hex$2 = (b) => Array.from(b, (x) => x.toString(16).padStart(2, "0")).join("");
431
1658
  var unhex$1 = (s) => Uint8Array.from(s.match(/../g), (x) => parseInt(x, 16));
432
1659
  function normalizeNostrKey(input) {
433
1660
  const value = input.trim();
@@ -455,7 +1682,8 @@ function nostrSigner(id) {
455
1682
  run: (ctx, work) => withNostrSigner({
456
1683
  bunker: id === "nip46" ? ctx.values.bunker : void 0,
457
1684
  signal: ctx.signal,
458
- onAuth: ctx.onAuthUrl
1685
+ onAuth: ctx.onAuthUrl,
1686
+ timeoutMs: ctx.waitMs
459
1687
  }, (signer) => {
460
1688
  return work({
461
1689
  subject: async () => normalizeNostrKey(await signer.getPublicKey()),
@@ -511,7 +1739,7 @@ var nostr = {
511
1739
  const expected = nostrProofTemplate(statement);
512
1740
  if (event.pubkey !== statement.binding.subject) throw new Error("Signed by another Nostr key");
513
1741
  if (event.kind !== expected.kind || event.created_at !== expected.created_at || event.content !== expected.content || JSON.stringify(event.tags) !== JSON.stringify(expected.tags)) throw new Error("The signer did not sign the exact Ghostly statement");
514
- const id = hex$1(sha256(utf8Encode(JSON.stringify([
1742
+ const id = hex$2(sha256(utf8Encode(JSON.stringify([
515
1743
  0,
516
1744
  event.pubkey,
517
1745
  event.created_at,
@@ -533,8 +1761,7 @@ var nostr = {
533
1761
  };
534
1762
  }
535
1763
  };
536
- //#endregion
537
- //#region ../browser/src/proofs/providers/domain.ts
1764
+ // ../browser/src/proofs/providers/domain.ts
538
1765
  /**
539
1766
  * A long domain as a card shows it: its end, the part that names who owns it (`…ghostly.tools`), never its start, which
540
1767
  * is whatever the owner chose (`github.com.account-…` under any domain they own). Whole labels from the end, as many as
@@ -629,7 +1856,8 @@ function nip05Signer(id) {
629
1856
  return withNostrSigner({
630
1857
  bunker: extension ? void 0 : ctx.values.bunker,
631
1858
  signal: ctx.signal,
632
- onAuth: ctx.onAuthUrl
1859
+ onAuth: ctx.onAuthUrl,
1860
+ timeoutMs: ctx.waitMs
633
1861
  }, (signer) => {
634
1862
  return work({
635
1863
  subject: async () => domain,
@@ -717,8 +1945,7 @@ var domain = {
717
1945
  };
718
1946
  }
719
1947
  };
720
- //#endregion
721
- //#region ../browser/src/proofs/openpgp.ts
1948
+ // ../browser/src/proofs/openpgp.ts
722
1949
  /**
723
1950
  * OpenPGP identity proofs (RFC 9580, and the RFC 4880 v4 keys people actually have).
724
1951
  *
@@ -767,7 +1994,7 @@ var PGP_LIMITS = {
767
1994
  var loading;
768
1995
  /** The only place OpenPGP.js is imported: a separate chunk, fetched on first use. */
769
1996
  function loadOpenPgp() {
770
- loading ??= import("./openpgp-BBFr-zHQ.js").then((m) => m).catch((e) => {
1997
+ loading ??= import("./openpgp-LkR_Zof0.js").then((m) => m).catch((e) => {
771
1998
  loading = void 0;
772
1999
  throw e;
773
2000
  });
@@ -1318,8 +2545,7 @@ async function keyserverVerifiedEmails(keyserverArmored, fingerprint, options =
1318
2545
  const emails = info.userIds.map((u) => /<([^<>\s]+@[^<>\s]+)>\s*$/.exec(u)?.[1] ?? (/^[^<>\s]+@[^<>\s]+$/.test(u) ? u : void 0));
1319
2546
  return [...new Set(emails.filter((e) => !!e).map((e) => e.toLowerCase()))];
1320
2547
  }
1321
- //#endregion
1322
- //#region ../browser/src/proofs/providers/openpgp.ts
2548
+ // ../browser/src/proofs/providers/openpgp.ts
1323
2549
  /**
1324
2550
  * OpenPGP keys, signed with the person's own gpg — a YubiKey or another OpenPGP card works unchanged,
1325
2551
  * since gpg drives it. The subject is the primary key's fingerprint. See docs/wisps/305-openpgp.md.
@@ -1456,8 +2682,7 @@ var openpgp = {
1456
2682
  };
1457
2683
  }
1458
2684
  };
1459
- //#endregion
1460
- //#region ../browser/src/proofs/providers/ssh.ts
2685
+ // ../browser/src/proofs/providers/ssh.ts
1461
2686
  var FINGERPRINT = /^SHA256:[A-Za-z0-9+/]{43}$/;
1462
2687
  /** The line `ssh-keygen -l -f key.pub` prints: bits, fingerprint, comment, type ("256 SHA256:… me@laptop (ED25519)"). */
1463
2688
  var KEYGEN_LIST_LINE = /^\d+ (SHA256:[A-Za-z0-9+/]{43}) .* \([A-Z0-9-]+\)$/;
@@ -1638,15 +2863,13 @@ function forgeProvider(forge) {
1638
2863
  }
1639
2864
  var sshGithub = forgeProvider("github");
1640
2865
  var sshGitlab = forgeProvider("gitlab");
1641
- //#endregion
1642
- //#region ../browser/src/host.ts
2866
+ // ../browser/src/host.ts
1643
2867
  var current = null;
1644
2868
  function getBrowserHost() {
1645
2869
  if (!current) throw new Error("No browser host configured");
1646
2870
  return current;
1647
2871
  }
1648
- //#endregion
1649
- //#region ../browser/src/proofs/oidc/jwks.ts
2872
+ // ../browser/src/proofs/oidc/jwks.ts
1650
2873
  /**
1651
2874
  * A provider's signing keys, fetched from its pinned JWKS URL with limits and
1652
2875
  * cached. A key ID that is not in the cached set triggers one early refetch
@@ -1893,8 +3116,7 @@ async function verifyIdToken(token, options) {
1893
3116
  tenant: provider.id === "microsoft" ? text(claims.tid, 64) : void 0
1894
3117
  };
1895
3118
  }
1896
- //#endregion
1897
- //#region ../browser/src/proofs/oidc/flow.ts
3119
+ // ../browser/src/proofs/oidc/flow.ts
1898
3120
  /** Optional platform prefix (desktop `d.<port>.`, Android deep link `a.`), then 32 random bytes. */
1899
3121
  var STATE = /^(?:d\.\d{1,5}\.|a\.)?[A-Za-z0-9_-]{43}$/;
1900
3122
  function scopeFor$1(provider, reveal) {
@@ -2042,8 +3264,7 @@ function refuseUnchosenClaims(provider, idToken, reveal) {
2042
3264
  throw new Error(claim === "hd" ? `This is a work or school ${provider.name} account: ${provider.name} adds its organisation’s domain to the sign-in, and your contacts would see it. Choose to share your email too, or sign in with a personal account.` : `${provider.name} added more to the sign-in than you chose to share. Choose to share your ${coveredBy} too, or sign in with another account.`);
2043
3265
  }
2044
3266
  }
2045
- //#endregion
2046
- //#region ../browser/src/proofs/providers/oidc.ts
3267
+ // ../browser/src/proofs/providers/oidc.ts
2047
3268
  /** How long after the statement the sign-in may have happened: time to pick an account and approve. */
2048
3269
  var SIGN_IN_WINDOW = 900;
2049
3270
  var TOKEN = /^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/;
@@ -2183,8 +3404,7 @@ function createOidcIdentityProvider(options = {}) {
2183
3404
  };
2184
3405
  }
2185
3406
  var oidc = createOidcIdentityProvider();
2186
- //#endregion
2187
- //#region ../browser/src/proofs/did.ts
3407
+ // ../browser/src/proofs/did.ts
2188
3408
  /** Resolutions are shared for this long: back-to-back checks and the add dialog's preview, never a stale key for long. */
2189
3409
  var CACHE_MS = 3e4;
2190
3410
  var cache = /* @__PURE__ */ new Map();
@@ -2289,8 +3509,7 @@ async function resolveDid(input, options) {
2289
3509
  async function fetchDidWebFile(did, proofId, options) {
2290
3510
  return fetchDidWeb(did, didWebFileUrl(did, proofId), DID_FILE_MAX_BYTES, options);
2291
3511
  }
2292
- //#endregion
2293
- //#region ../browser/src/proofs/providers/did.ts
3512
+ // ../browser/src/proofs/providers/did.ts
2294
3513
  var VM = /^did:[a-z0-9]+:[\x21-\x7e]+#[\x21-\x7e]+$/;
2295
3514
  var SIG = /^[A-Za-z0-9_-]{86}$/;
2296
3515
  var exactKeys$1 = (raw, keys) => !!raw && typeof raw === "object" && !Array.isArray(raw) && Object.keys(raw).sort().join(",") === keys;
@@ -2601,8 +3820,7 @@ var did = {
2601
3820
  };
2602
3821
  }
2603
3822
  };
2604
- //#endregion
2605
- //#region ../browser/src/proofs/atproto/oauth.ts
3823
+ // ../browser/src/proofs/atproto/oauth.ts
2606
3824
  /**
2607
3825
  * The prover's half of AT Protocol proofs: AT Protocol OAuth (PAR + PKCE + DPoP, through the official
2608
3826
  * `@atproto/oauth-client`) against the person's own server, then one record written or deleted. Every
@@ -2858,8 +4076,7 @@ async function unpublishAtprotoProof(proofKey, options) {
2858
4076
  if (!response.ok) throw new Error(`Your server did not delete the record (${await xrpcError(response)}).`);
2859
4077
  });
2860
4078
  }
2861
- //#endregion
2862
- //#region ../browser/src/proofs/providers/atproto.ts
4079
+ // ../browser/src/proofs/providers/atproto.ts
2863
4080
  /** The proof CAR: a commit, the tree path and one small record. Real repositories' paths are a few KiB. */
2864
4081
  var RECORD_PROOF_MAX_BYTES = 262144;
2865
4082
  function currentHost() {
@@ -3056,8 +4273,7 @@ function createAtprotoIdentityProvider(options = {}) {
3056
4273
  };
3057
4274
  }
3058
4275
  var atproto = createAtprotoIdentityProvider();
3059
- //#endregion
3060
- //#region ../browser/src/proofs/pubky.ts
4276
+ // ../browser/src/proofs/pubky.ts
3061
4277
  /**
3062
4278
  * Pubky, browser side: reading a key's records and files the way a contact's app does (through the proof
3063
4279
  * contract's bounded `ctx.fetch` only), and asking the person to approve one Pubky auth request in Pubky Ring or
@@ -3158,7 +4374,7 @@ async function readPubkyFile(key, path, fetch, signal, relays, resolver = chosen
3158
4374
  var PUBKY_CLIENT_ID = "ghostly.tools";
3159
4375
  var PASSPORT_ORIGIN = "https://passport.pubky.app";
3160
4376
  /** How long one request waits: Pubky's relay keeps a message about five minutes. */
3161
- var APPROVAL_TIMEOUT = 3e5;
4377
+ var PUBKY_APPROVAL_TIMEOUT = 3e5;
3162
4378
  var POLL_EVERY = 1e3;
3163
4379
  /**
3164
4380
  * Passport's authorize page for a request. The authorization URL carries the relay secret: it goes in the fragment
@@ -3210,7 +4426,7 @@ function firstApproval(requests, signal, timeoutMs, onSettled) {
3210
4426
  settle();
3211
4427
  };
3212
4428
  const cancel = () => end(() => reject(signal.reason));
3213
- const timer = setTimeout(() => end(() => reject(/* @__PURE__ */ new Error("Nobody approved the request in time. Start again for a new one."))), timeoutMs);
4429
+ const timer = setTimeout(() => end(() => reject(new SignerTimeout("Nobody approved the request in time. Start again for a new one."))), timeoutMs);
3214
4430
  if (signal.aborted) cancel();
3215
4431
  else signal.addEventListener("abort", cancel, { once: true });
3216
4432
  const pause = () => new Promise((done) => {
@@ -3390,7 +4606,7 @@ async function approveAndWork(options, work, { grant, cookie, opened, settled, c
3390
4606
  const { signal } = options;
3391
4607
  let session, viaCookie;
3392
4608
  try {
3393
- const first = await firstApproval([grant, cookie], signal, options.timeoutMs ?? APPROVAL_TIMEOUT, settled);
4609
+ const first = await firstApproval([grant, cookie], signal, options.timeoutMs ?? 3e5, settled);
3394
4610
  session = first.session;
3395
4611
  viaCookie = first.request === cookie;
3396
4612
  } finally {
@@ -3435,8 +4651,7 @@ async function approveAndWork(options, work, { grant, cookie, opened, settled, c
3435
4651
  approved.free();
3436
4652
  }
3437
4653
  }
3438
- //#endregion
3439
- //#region ../browser/src/proofs/providers/pubky.ts
4654
+ // ../browser/src/proofs/providers/pubky.ts
3440
4655
  var short = (key) => `pubky${key.slice(0, 4)}…${key.slice(-4)}`;
3441
4656
  /** Strict: exactly `{ folder }`, 64 hex characters. Nothing else, so no evidence can name a host or another path. */
3442
4657
  function parseEvidence(raw) {
@@ -3447,8 +4662,10 @@ function parseEvidence(raw) {
3447
4662
  function createPubkyIdentityProvider(options = {}) {
3448
4663
  const approve = (capability, ctx, work) => {
3449
4664
  if (!ctx.onApproval) throw new Error("This screen cannot show a Pubky request");
4665
+ const wait = ctx.waitMs ? { timeoutMs: Math.min(ctx.waitMs, PUBKY_APPROVAL_TIMEOUT) } : {};
3450
4666
  return withPubkyApproval({
3451
4667
  ...options.approval,
4668
+ ...wait,
3452
4669
  capability,
3453
4670
  signal: ctx.signal,
3454
4671
  onApproval: ctx.onApproval,
@@ -3486,6 +4703,7 @@ function createPubkyIdentityProvider(options = {}) {
3486
4703
  kind: "in-app",
3487
4704
  label: "Pubky Ring or Pubky Passport",
3488
4705
  action: "Continue",
4706
+ maxWaitMs: PUBKY_APPROVAL_TIMEOUT,
3489
4707
  description: "One request: approve it in Pubky Passport in your browser, or scan it with Pubky Ring. Ghostly only asks to write one small file to a new folder of your homeserver.",
3490
4708
  run(ctx, work) {
3491
4709
  const folder = newPubkyProofFolder();
@@ -3546,7 +4764,7 @@ var testIdentitiesEnabled = () => {
3546
4764
  }
3547
4765
  };
3548
4766
  var HEX64 = /^[a-f0-9]{64}$/;
3549
- var hex = (b) => Array.from(b, (x) => x.toString(16).padStart(2, "0")).join("");
4767
+ var hex$1 = (b) => Array.from(b, (x) => x.toString(16).padStart(2, "0")).join("");
3550
4768
  var unhex = (s) => Uint8Array.from(s.match(/../g), (x) => parseInt(x, 16));
3551
4769
  var normalizeHexKey = (input) => {
3552
4770
  const v = input.trim().toLowerCase();
@@ -3564,7 +4782,7 @@ var fakeKeyring = {
3564
4782
  fakeSeed = value;
3565
4783
  }
3566
4784
  };
3567
- var fakeKeySubject = (seed = fakeKeyring.seed) => hex(ed25519.getPublicKey(seed));
4785
+ var fakeKeySubject = (seed = fakeKeyring.seed) => hex$1(ed25519.getPublicKey(seed));
3568
4786
  var fakeKeySign = (statement, seed = fakeKeyring.seed) => ({ sig: toBase64Url(ed25519.sign(statement.bytes, seed)) });
3569
4787
  var fakeKey = {
3570
4788
  id: "fake-key",
@@ -3763,8 +4981,7 @@ var FAKE_IDENTITY_PROVIDERS = [
3763
4981
  }
3764
4982
  }
3765
4983
  ];
3766
- //#endregion
3767
- //#region ../browser/src/proofs/registry.ts
4984
+ // ../browser/src/proofs/registry.ts
3768
4985
  /**
3769
4986
  * Every identity-proof provider built into Ghostly. Adding one is adding its module under `providers/`
3770
4987
  * and ONE line here; see PROOFS.md. The order is the order of the picker on the Identities page. A
@@ -3804,7 +5021,6 @@ function identityProviders() {
3804
5021
  function identityProvider(id, providers = identityProviders()) {
3805
5022
  return providers.find((p) => p.id === id);
3806
5023
  }
3807
- //#endregion
3808
- export { parseProofBunker as i, identityProvider as n, identityProviders as r, IDENTITY_PROVIDERS as t };
5024
+ export { SignerTimeout as a, parseProofBunker as i, identityProvider as n, identityProviders as r, IDENTITY_PROVIDERS as t };
3809
5025
 
3810
- //# sourceMappingURL=registry-Da-r6eC3.js.map
5026
+ //# sourceMappingURL=registry-Bep4umOM.js.map