@did-btcr2/method 0.13.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 (310) hide show
  1. package/LICENSE +373 -0
  2. package/README.md +7 -0
  3. package/dist/browser.js +2364 -0
  4. package/dist/browser.js.map +7 -0
  5. package/dist/browser.mjs +2364 -0
  6. package/dist/browser.mjs.map +7 -0
  7. package/dist/cjs/bitcoin/constants.js +20 -0
  8. package/dist/cjs/bitcoin/constants.js.map +1 -0
  9. package/dist/cjs/bitcoin/errors.js +11 -0
  10. package/dist/cjs/bitcoin/errors.js.map +1 -0
  11. package/dist/cjs/bitcoin/index.js +95 -0
  12. package/dist/cjs/bitcoin/index.js.map +1 -0
  13. package/dist/cjs/bitcoin/interface.js +2 -0
  14. package/dist/cjs/bitcoin/interface.js.map +1 -0
  15. package/dist/cjs/bitcoin/network.js +17 -0
  16. package/dist/cjs/bitcoin/network.js.map +1 -0
  17. package/dist/cjs/bitcoin/rest-client.js +289 -0
  18. package/dist/cjs/bitcoin/rest-client.js.map +1 -0
  19. package/dist/cjs/bitcoin/rpc-client.js +722 -0
  20. package/dist/cjs/bitcoin/rpc-client.js.map +1 -0
  21. package/dist/cjs/bitcoin/taproot.js +219 -0
  22. package/dist/cjs/bitcoin/taproot.js.map +1 -0
  23. package/dist/cjs/btcr2/beacon/aggregation/coordinator.js +120 -0
  24. package/dist/cjs/btcr2/beacon/aggregation/coordinator.js.map +1 -0
  25. package/dist/cjs/btcr2/beacon/aggregation/messages/advert.js +24 -0
  26. package/dist/cjs/btcr2/beacon/aggregation/messages/advert.js.map +1 -0
  27. package/dist/cjs/btcr2/beacon/aggregation/messages/base.js +37 -0
  28. package/dist/cjs/btcr2/beacon/aggregation/messages/base.js.map +1 -0
  29. package/dist/cjs/btcr2/beacon/aggregation/messages/cohort-set.js +25 -0
  30. package/dist/cjs/btcr2/beacon/aggregation/messages/cohort-set.js.map +1 -0
  31. package/dist/cjs/btcr2/beacon/aggregation/messages/keygen.js +8 -0
  32. package/dist/cjs/btcr2/beacon/aggregation/messages/keygen.js.map +1 -0
  33. package/dist/cjs/btcr2/beacon/aggregation/messages/opt-in.js +23 -0
  34. package/dist/cjs/btcr2/beacon/aggregation/messages/opt-in.js.map +1 -0
  35. package/dist/cjs/btcr2/beacon/aggregation/messages/sign.js +7 -0
  36. package/dist/cjs/btcr2/beacon/aggregation/messages/sign.js.map +1 -0
  37. package/dist/cjs/btcr2/beacon/aggregation/models/cohort/index.js +92 -0
  38. package/dist/cjs/btcr2/beacon/aggregation/models/cohort/index.js.map +1 -0
  39. package/dist/cjs/btcr2/beacon/aggregation/models/cohort/status.js +8 -0
  40. package/dist/cjs/btcr2/beacon/aggregation/models/cohort/status.js.map +1 -0
  41. package/dist/cjs/btcr2/beacon/aggregation/participant.js +2 -0
  42. package/dist/cjs/btcr2/beacon/aggregation/participant.js.map +1 -0
  43. package/dist/cjs/btcr2/beacon/aggregation/protocol/nostr.js +57 -0
  44. package/dist/cjs/btcr2/beacon/aggregation/protocol/nostr.js.map +1 -0
  45. package/dist/cjs/btcr2/beacon/aggregation/protocol/service.js +2 -0
  46. package/dist/cjs/btcr2/beacon/aggregation/protocol/service.js.map +1 -0
  47. package/dist/cjs/btcr2/beacon/cid-aggregate.js +116 -0
  48. package/dist/cjs/btcr2/beacon/cid-aggregate.js.map +1 -0
  49. package/dist/cjs/btcr2/beacon/factory.js +30 -0
  50. package/dist/cjs/btcr2/beacon/factory.js.map +1 -0
  51. package/dist/cjs/btcr2/beacon/singleton.js +220 -0
  52. package/dist/cjs/btcr2/beacon/singleton.js.map +1 -0
  53. package/dist/cjs/btcr2/beacon/smt-aggregate.js +126 -0
  54. package/dist/cjs/btcr2/beacon/smt-aggregate.js.map +1 -0
  55. package/dist/cjs/btcr2/crud/create.js +102 -0
  56. package/dist/cjs/btcr2/crud/create.js.map +1 -0
  57. package/dist/cjs/btcr2/crud/deactivate.js +14 -0
  58. package/dist/cjs/btcr2/crud/deactivate.js.map +1 -0
  59. package/dist/cjs/btcr2/crud/read.js +686 -0
  60. package/dist/cjs/btcr2/crud/read.js.map +1 -0
  61. package/dist/cjs/btcr2/crud/update.js +195 -0
  62. package/dist/cjs/btcr2/crud/update.js.map +1 -0
  63. package/dist/cjs/btcr2/key-manager/index.js +290 -0
  64. package/dist/cjs/btcr2/key-manager/index.js.map +1 -0
  65. package/dist/cjs/btcr2/key-manager/interface.js +2 -0
  66. package/dist/cjs/btcr2/key-manager/interface.js.map +1 -0
  67. package/dist/cjs/did-btcr2.js +222 -0
  68. package/dist/cjs/did-btcr2.js.map +1 -0
  69. package/dist/cjs/index.js +27 -0
  70. package/dist/cjs/index.js.map +1 -0
  71. package/dist/cjs/interfaces/beacon.js +41 -0
  72. package/dist/cjs/interfaces/beacon.js.map +1 -0
  73. package/dist/cjs/interfaces/crud.js +2 -0
  74. package/dist/cjs/interfaces/crud.js.map +1 -0
  75. package/dist/cjs/interfaces/ibeacon.js +2 -0
  76. package/dist/cjs/interfaces/ibeacon.js.map +1 -0
  77. package/dist/cjs/package.json +1 -0
  78. package/dist/cjs/types/bitcoin.js +62 -0
  79. package/dist/cjs/types/bitcoin.js.map +1 -0
  80. package/dist/cjs/types/crud.js +2 -0
  81. package/dist/cjs/types/crud.js.map +1 -0
  82. package/dist/cjs/utils/appendix.js +221 -0
  83. package/dist/cjs/utils/appendix.js.map +1 -0
  84. package/dist/cjs/utils/beacons.js +206 -0
  85. package/dist/cjs/utils/beacons.js.map +1 -0
  86. package/dist/cjs/utils/did-document-builder.js +61 -0
  87. package/dist/cjs/utils/did-document-builder.js.map +1 -0
  88. package/dist/cjs/utils/did-document.js +380 -0
  89. package/dist/cjs/utils/did-document.js.map +1 -0
  90. package/dist/cjs/utils/general.js +195 -0
  91. package/dist/cjs/utils/general.js.map +1 -0
  92. package/dist/cjs/utils/identifier.js +238 -0
  93. package/dist/cjs/utils/identifier.js.map +1 -0
  94. package/dist/esm/bitcoin/constants.js +20 -0
  95. package/dist/esm/bitcoin/constants.js.map +1 -0
  96. package/dist/esm/bitcoin/errors.js +11 -0
  97. package/dist/esm/bitcoin/errors.js.map +1 -0
  98. package/dist/esm/bitcoin/index.js +95 -0
  99. package/dist/esm/bitcoin/index.js.map +1 -0
  100. package/dist/esm/bitcoin/interface.js +2 -0
  101. package/dist/esm/bitcoin/interface.js.map +1 -0
  102. package/dist/esm/bitcoin/network.js +17 -0
  103. package/dist/esm/bitcoin/network.js.map +1 -0
  104. package/dist/esm/bitcoin/rest-client.js +289 -0
  105. package/dist/esm/bitcoin/rest-client.js.map +1 -0
  106. package/dist/esm/bitcoin/rpc-client.js +722 -0
  107. package/dist/esm/bitcoin/rpc-client.js.map +1 -0
  108. package/dist/esm/bitcoin/taproot.js +219 -0
  109. package/dist/esm/bitcoin/taproot.js.map +1 -0
  110. package/dist/esm/btcr2/beacon/aggregation/coordinator.js +120 -0
  111. package/dist/esm/btcr2/beacon/aggregation/coordinator.js.map +1 -0
  112. package/dist/esm/btcr2/beacon/aggregation/messages/advert.js +24 -0
  113. package/dist/esm/btcr2/beacon/aggregation/messages/advert.js.map +1 -0
  114. package/dist/esm/btcr2/beacon/aggregation/messages/base.js +37 -0
  115. package/dist/esm/btcr2/beacon/aggregation/messages/base.js.map +1 -0
  116. package/dist/esm/btcr2/beacon/aggregation/messages/cohort-set.js +25 -0
  117. package/dist/esm/btcr2/beacon/aggregation/messages/cohort-set.js.map +1 -0
  118. package/dist/esm/btcr2/beacon/aggregation/messages/keygen.js +8 -0
  119. package/dist/esm/btcr2/beacon/aggregation/messages/keygen.js.map +1 -0
  120. package/dist/esm/btcr2/beacon/aggregation/messages/opt-in.js +23 -0
  121. package/dist/esm/btcr2/beacon/aggregation/messages/opt-in.js.map +1 -0
  122. package/dist/esm/btcr2/beacon/aggregation/messages/sign.js +7 -0
  123. package/dist/esm/btcr2/beacon/aggregation/messages/sign.js.map +1 -0
  124. package/dist/esm/btcr2/beacon/aggregation/models/cohort/index.js +92 -0
  125. package/dist/esm/btcr2/beacon/aggregation/models/cohort/index.js.map +1 -0
  126. package/dist/esm/btcr2/beacon/aggregation/models/cohort/status.js +8 -0
  127. package/dist/esm/btcr2/beacon/aggregation/models/cohort/status.js.map +1 -0
  128. package/dist/esm/btcr2/beacon/aggregation/participant.js +2 -0
  129. package/dist/esm/btcr2/beacon/aggregation/participant.js.map +1 -0
  130. package/dist/esm/btcr2/beacon/aggregation/protocol/nostr.js +57 -0
  131. package/dist/esm/btcr2/beacon/aggregation/protocol/nostr.js.map +1 -0
  132. package/dist/esm/btcr2/beacon/aggregation/protocol/service.js +2 -0
  133. package/dist/esm/btcr2/beacon/aggregation/protocol/service.js.map +1 -0
  134. package/dist/esm/btcr2/beacon/cid-aggregate.js +116 -0
  135. package/dist/esm/btcr2/beacon/cid-aggregate.js.map +1 -0
  136. package/dist/esm/btcr2/beacon/factory.js +30 -0
  137. package/dist/esm/btcr2/beacon/factory.js.map +1 -0
  138. package/dist/esm/btcr2/beacon/singleton.js +220 -0
  139. package/dist/esm/btcr2/beacon/singleton.js.map +1 -0
  140. package/dist/esm/btcr2/beacon/smt-aggregate.js +126 -0
  141. package/dist/esm/btcr2/beacon/smt-aggregate.js.map +1 -0
  142. package/dist/esm/btcr2/crud/create.js +102 -0
  143. package/dist/esm/btcr2/crud/create.js.map +1 -0
  144. package/dist/esm/btcr2/crud/deactivate.js +14 -0
  145. package/dist/esm/btcr2/crud/deactivate.js.map +1 -0
  146. package/dist/esm/btcr2/crud/read.js +686 -0
  147. package/dist/esm/btcr2/crud/read.js.map +1 -0
  148. package/dist/esm/btcr2/crud/update.js +195 -0
  149. package/dist/esm/btcr2/crud/update.js.map +1 -0
  150. package/dist/esm/btcr2/key-manager/index.js +290 -0
  151. package/dist/esm/btcr2/key-manager/index.js.map +1 -0
  152. package/dist/esm/btcr2/key-manager/interface.js +2 -0
  153. package/dist/esm/btcr2/key-manager/interface.js.map +1 -0
  154. package/dist/esm/did-btcr2.js +222 -0
  155. package/dist/esm/did-btcr2.js.map +1 -0
  156. package/dist/esm/index.js +27 -0
  157. package/dist/esm/index.js.map +1 -0
  158. package/dist/esm/interfaces/beacon.js +41 -0
  159. package/dist/esm/interfaces/beacon.js.map +1 -0
  160. package/dist/esm/interfaces/crud.js +2 -0
  161. package/dist/esm/interfaces/crud.js.map +1 -0
  162. package/dist/esm/interfaces/ibeacon.js +2 -0
  163. package/dist/esm/interfaces/ibeacon.js.map +1 -0
  164. package/dist/esm/types/bitcoin.js +62 -0
  165. package/dist/esm/types/bitcoin.js.map +1 -0
  166. package/dist/esm/types/crud.js +2 -0
  167. package/dist/esm/types/crud.js.map +1 -0
  168. package/dist/esm/utils/appendix.js +221 -0
  169. package/dist/esm/utils/appendix.js.map +1 -0
  170. package/dist/esm/utils/beacons.js +206 -0
  171. package/dist/esm/utils/beacons.js.map +1 -0
  172. package/dist/esm/utils/did-document-builder.js +61 -0
  173. package/dist/esm/utils/did-document-builder.js.map +1 -0
  174. package/dist/esm/utils/did-document.js +380 -0
  175. package/dist/esm/utils/did-document.js.map +1 -0
  176. package/dist/esm/utils/general.js +195 -0
  177. package/dist/esm/utils/general.js.map +1 -0
  178. package/dist/esm/utils/identifier.js +238 -0
  179. package/dist/esm/utils/identifier.js.map +1 -0
  180. package/dist/types/bitcoin/constants.d.ts +19 -0
  181. package/dist/types/bitcoin/constants.d.ts.map +1 -0
  182. package/dist/types/bitcoin/errors.d.ts +5 -0
  183. package/dist/types/bitcoin/errors.d.ts.map +1 -0
  184. package/dist/types/bitcoin/index.d.ts +75 -0
  185. package/dist/types/bitcoin/index.d.ts.map +1 -0
  186. package/dist/types/bitcoin/interface.d.ts +86 -0
  187. package/dist/types/bitcoin/interface.d.ts.map +1 -0
  188. package/dist/types/bitcoin/network.d.ts +2 -0
  189. package/dist/types/bitcoin/network.d.ts.map +1 -0
  190. package/dist/types/bitcoin/rest-client.d.ts +268 -0
  191. package/dist/types/bitcoin/rest-client.d.ts.map +1 -0
  192. package/dist/types/bitcoin/rpc-client.d.ts +506 -0
  193. package/dist/types/bitcoin/rpc-client.d.ts.map +1 -0
  194. package/dist/types/bitcoin/taproot.d.ts +34 -0
  195. package/dist/types/bitcoin/taproot.d.ts.map +1 -0
  196. package/dist/types/btcr2/beacon/aggregation/coordinator.d.ts +74 -0
  197. package/dist/types/btcr2/beacon/aggregation/coordinator.d.ts.map +1 -0
  198. package/dist/types/btcr2/beacon/aggregation/messages/advert.d.ts +22 -0
  199. package/dist/types/btcr2/beacon/aggregation/messages/advert.d.ts.map +1 -0
  200. package/dist/types/btcr2/beacon/aggregation/messages/base.d.ts +36 -0
  201. package/dist/types/btcr2/beacon/aggregation/messages/base.d.ts.map +1 -0
  202. package/dist/types/btcr2/beacon/aggregation/messages/cohort-set.d.ts +23 -0
  203. package/dist/types/btcr2/beacon/aggregation/messages/cohort-set.d.ts.map +1 -0
  204. package/dist/types/btcr2/beacon/aggregation/messages/keygen.d.ts +6 -0
  205. package/dist/types/btcr2/beacon/aggregation/messages/keygen.d.ts.map +1 -0
  206. package/dist/types/btcr2/beacon/aggregation/messages/opt-in.d.ts +22 -0
  207. package/dist/types/btcr2/beacon/aggregation/messages/opt-in.d.ts.map +1 -0
  208. package/dist/types/btcr2/beacon/aggregation/messages/sign.d.ts +5 -0
  209. package/dist/types/btcr2/beacon/aggregation/messages/sign.d.ts.map +1 -0
  210. package/dist/types/btcr2/beacon/aggregation/models/cohort/index.d.ts +77 -0
  211. package/dist/types/btcr2/beacon/aggregation/models/cohort/index.d.ts.map +1 -0
  212. package/dist/types/btcr2/beacon/aggregation/models/cohort/status.d.ts +7 -0
  213. package/dist/types/btcr2/beacon/aggregation/models/cohort/status.d.ts.map +1 -0
  214. package/dist/types/btcr2/beacon/aggregation/participant.d.ts +1 -0
  215. package/dist/types/btcr2/beacon/aggregation/participant.d.ts.map +1 -0
  216. package/dist/types/btcr2/beacon/aggregation/protocol/nostr.d.ts +36 -0
  217. package/dist/types/btcr2/beacon/aggregation/protocol/nostr.d.ts.map +1 -0
  218. package/dist/types/btcr2/beacon/aggregation/protocol/service.d.ts +6 -0
  219. package/dist/types/btcr2/beacon/aggregation/protocol/service.d.ts.map +1 -0
  220. package/dist/types/btcr2/beacon/cid-aggregate.d.ts +103 -0
  221. package/dist/types/btcr2/beacon/cid-aggregate.d.ts.map +1 -0
  222. package/dist/types/btcr2/beacon/factory.d.ts +17 -0
  223. package/dist/types/btcr2/beacon/factory.d.ts.map +1 -0
  224. package/dist/types/btcr2/beacon/singleton.d.ts +93 -0
  225. package/dist/types/btcr2/beacon/singleton.d.ts.map +1 -0
  226. package/dist/types/btcr2/beacon/smt-aggregate.d.ts +112 -0
  227. package/dist/types/btcr2/beacon/smt-aggregate.d.ts.map +1 -0
  228. package/dist/types/btcr2/crud/create.d.ts +92 -0
  229. package/dist/types/btcr2/crud/create.d.ts.map +1 -0
  230. package/dist/types/btcr2/crud/deactivate.d.ts +13 -0
  231. package/dist/types/btcr2/crud/deactivate.d.ts.map +1 -0
  232. package/dist/types/btcr2/crud/read.d.ts +341 -0
  233. package/dist/types/btcr2/crud/read.d.ts.map +1 -0
  234. package/dist/types/btcr2/crud/update.d.ts +83 -0
  235. package/dist/types/btcr2/crud/update.d.ts.map +1 -0
  236. package/dist/types/btcr2/key-manager/index.d.ts +145 -0
  237. package/dist/types/btcr2/key-manager/index.d.ts.map +1 -0
  238. package/dist/types/btcr2/key-manager/interface.d.ts +113 -0
  239. package/dist/types/btcr2/key-manager/interface.d.ts.map +1 -0
  240. package/dist/types/did-btcr2.d.ts +117 -0
  241. package/dist/types/did-btcr2.d.ts.map +1 -0
  242. package/dist/types/index.d.ts +26 -0
  243. package/dist/types/index.d.ts.map +1 -0
  244. package/dist/types/interfaces/beacon.d.ts +57 -0
  245. package/dist/types/interfaces/beacon.d.ts.map +1 -0
  246. package/dist/types/interfaces/crud.d.ts +35 -0
  247. package/dist/types/interfaces/crud.d.ts.map +1 -0
  248. package/dist/types/interfaces/ibeacon.d.ts +66 -0
  249. package/dist/types/interfaces/ibeacon.d.ts.map +1 -0
  250. package/dist/types/types/bitcoin.d.ts +827 -0
  251. package/dist/types/types/bitcoin.d.ts.map +1 -0
  252. package/dist/types/types/crud.d.ts +38 -0
  253. package/dist/types/types/crud.d.ts.map +1 -0
  254. package/dist/types/utils/appendix.d.ts +118 -0
  255. package/dist/types/utils/appendix.d.ts.map +1 -0
  256. package/dist/types/utils/beacons.d.ts +156 -0
  257. package/dist/types/utils/beacons.d.ts.map +1 -0
  258. package/dist/types/utils/did-document-builder.d.ts +13 -0
  259. package/dist/types/utils/did-document-builder.d.ts.map +1 -0
  260. package/dist/types/utils/did-document.d.ts +211 -0
  261. package/dist/types/utils/did-document.d.ts.map +1 -0
  262. package/dist/types/utils/general.d.ts +85 -0
  263. package/dist/types/utils/general.d.ts.map +1 -0
  264. package/dist/types/utils/identifier.d.ts +59 -0
  265. package/dist/types/utils/identifier.d.ts.map +1 -0
  266. package/package.json +137 -0
  267. package/src/bitcoin/constants.ts +19 -0
  268. package/src/bitcoin/errors.ts +10 -0
  269. package/src/bitcoin/index.ts +154 -0
  270. package/src/bitcoin/interface.ts +160 -0
  271. package/src/bitcoin/network.ts +17 -0
  272. package/src/bitcoin/rest-client.ts +415 -0
  273. package/src/bitcoin/rpc-client.ts +888 -0
  274. package/src/bitcoin/taproot.ts +237 -0
  275. package/src/btcr2/beacon/aggregation/coordinator.ts +135 -0
  276. package/src/btcr2/beacon/aggregation/messages/advert.ts +36 -0
  277. package/src/btcr2/beacon/aggregation/messages/base.ts +59 -0
  278. package/src/btcr2/beacon/aggregation/messages/cohort-set.ts +37 -0
  279. package/src/btcr2/beacon/aggregation/messages/keygen.ts +8 -0
  280. package/src/btcr2/beacon/aggregation/messages/opt-in.ts +35 -0
  281. package/src/btcr2/beacon/aggregation/messages/sign.ts +7 -0
  282. package/src/btcr2/beacon/aggregation/models/cohort/index.ts +112 -0
  283. package/src/btcr2/beacon/aggregation/models/cohort/status.ts +7 -0
  284. package/src/btcr2/beacon/aggregation/participant.ts +0 -0
  285. package/src/btcr2/beacon/aggregation/protocol/nostr.ts +81 -0
  286. package/src/btcr2/beacon/aggregation/protocol/service.ts +6 -0
  287. package/src/btcr2/beacon/cid-aggregate.ts +154 -0
  288. package/src/btcr2/beacon/factory.ts +36 -0
  289. package/src/btcr2/beacon/singleton.ts +257 -0
  290. package/src/btcr2/beacon/smt-aggregate.ts +136 -0
  291. package/src/btcr2/crud/create.ts +160 -0
  292. package/src/btcr2/crud/deactivate.ts +13 -0
  293. package/src/btcr2/crud/read.ts +946 -0
  294. package/src/btcr2/crud/update.ts +277 -0
  295. package/src/btcr2/key-manager/index.ts +364 -0
  296. package/src/btcr2/key-manager/interface.ts +129 -0
  297. package/src/canonicalize.d.ts +6 -0
  298. package/src/did-btcr2.ts +288 -0
  299. package/src/index.ts +34 -0
  300. package/src/interfaces/beacon.ts +68 -0
  301. package/src/interfaces/crud.ts +36 -0
  302. package/src/interfaces/ibeacon.ts +76 -0
  303. package/src/types/bitcoin.ts +1028 -0
  304. package/src/types/crud.ts +41 -0
  305. package/src/utils/appendix.ts +257 -0
  306. package/src/utils/beacons.ts +276 -0
  307. package/src/utils/did-document-builder.ts +73 -0
  308. package/src/utils/did-document.ts +474 -0
  309. package/src/utils/general.ts +204 -0
  310. package/src/utils/identifier.ts +276 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status.js","sourceRoot":"","sources":["../../../../../../../src/btcr2/beacon/aggregation/models/cohort/status.ts"],"names":[],"mappings":"AACA,MAAM,CAAN,IAAY,aAKX;AALD,WAAY,aAAa;IACvB,iDAAgC,CAAA;IAChC,6CAA4B,CAAA;IAC5B,iDAAgC,CAAA;IAChC,yCAAwB,CAAA;AAC1B,CAAC,EALW,aAAa,KAAb,aAAa,QAKxB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=participant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"participant.js","sourceRoot":"","sources":["../../../../../src/btcr2/beacon/aggregation/participant.ts"],"names":[],"mappings":""}
@@ -0,0 +1,57 @@
1
+ import { SchnorrKeyPair, SecretKey } from '@did-btcr2/keypair';
2
+ import { SimplePool, } from 'nostr-tools/pool';
3
+ import { Btc1Identifier } from '../../../../utils/identifier.js';
4
+ export class NostrAdapter {
5
+ name = 'nostr';
6
+ config;
7
+ handlers = new Map();
8
+ constructor(config = { keys: {}, components: {}, relays: ['wss://relay.damus.io'] }) {
9
+ this.config = config;
10
+ this.config.keys = this.config.keys || SchnorrKeyPair.generate().raw;
11
+ this.config.did = config.did || Btc1Identifier.encode({
12
+ idType: config.components.idType || 'KEY',
13
+ version: config.components.version || 1,
14
+ network: config.components.network || 'signet',
15
+ genesisBytes: this.config.keys.public
16
+ });
17
+ }
18
+ async start() {
19
+ const pool = new SimplePool();
20
+ pool.subscribe(this.config.relays, { pubkey: this.config.did, kinds: [1059] }, {
21
+ onclose: (reasons) => console.log('Subscription closed for reasons:', reasons),
22
+ onevent: async (event) => {
23
+ console.log('Received event:', event);
24
+ }
25
+ });
26
+ }
27
+ registerMessageHandler(messageType, handler) {
28
+ this.handlers.set(messageType, handler);
29
+ }
30
+ /**
31
+ * Sends a message to a recipient using the Nostr protocol.
32
+ * This method is a placeholder and should be implemented with actual Nostr message sending logic.
33
+ * @param message
34
+ * @param recipient
35
+ * @param sender
36
+ */
37
+ async sendMessage(message, recipient, sender) {
38
+ // TODO: Implement message sending logic via Nostr
39
+ console.log(`Sending message to ${recipient} from ${sender}:`, message);
40
+ }
41
+ /**
42
+ * Generates a Nostr identity using the SecretKey and Btc1Identifier classes.
43
+ * @returns {string} A BTCR2 DID used for communication over the nostr protocol
44
+ */
45
+ generateIdentity() {
46
+ this.config.keys.secret = SecretKey.random();
47
+ this.config.keys.public = SecretKey.getPublicKey(this.config.keys.secret);
48
+ this.config.did = Btc1Identifier.encode({
49
+ idType: this.config.components.idType || 'KEY',
50
+ version: this.config.components.version || 1,
51
+ network: this.config.components.network || 'signet',
52
+ genesisBytes: this.config.keys.public
53
+ });
54
+ return this.config.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AAI,CAAC,MAAM;SACvC,CACF,CAAC;QACF,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;IACzB,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.js","sourceRoot":"","sources":["../../../../../../src/btcr2/beacon/aggregation/protocol/service.ts"],"names":[],"mappings":""}
@@ -0,0 +1,116 @@
1
+ import { Btcr2Error } from '@did-btcr2/common';
2
+ import { Beacon } from '../../interfaces/beacon.js';
3
+ /**
4
+ * Implements {@link https://dcdpr.github.io/did-btcr2/#cidaggregate-beacon | 5.2 CIDAggregate Beacon}.
5
+ *
6
+ * A Beacon of the type CIDAggregatoBeacon is a Beacon that publishes Bitcoin transactions containing a Content
7
+ * Identifier (CID) announcing an Aggregated DID Update Bundle. An Aggregated DID Update Bundle is a JSON object that
8
+ * maps did:btcr2 identifiers to CID values for the individual DID Update Payloads. The Aggregated DID Update Bundle CID
9
+ * (bundleCID) SHOULD be resolvable against a Content Addressable Storage (CAS) system such as IPFS, while the CID for
10
+ * the DID Update Payload (payloadCID) MAY be resolvable against a CAS or provided through a Sidecar mechanism. It is
11
+ * RECOMMENDED that this type of Beacon is only included in a DID document if the DID controller is REQUIRED to
12
+ * participate in authorizing Bitcoin transactions from this Beacon. In other words, this Beacon SHOULD identify an
13
+ * n-of-n P2TR Bitcoin address where n is the number of unique DID controllers submitting updates through the Beacon.
14
+ *
15
+ * @class CIDAggregateBeacon
16
+ * @type {CIDAggregateBeacon}
17
+ * @extends {Beacon}
18
+ */
19
+ export class CIDAggregateBeacon extends Beacon {
20
+ /**
21
+ * Creates an instance of CIDAggregateBeacon.
22
+ * @param {BeaconService} service The service of the Beacon.
23
+ * @param {?BeaconSidecarData} [sidecar] The sidecar data of the Beacon.
24
+ */
25
+ constructor(service, sidecar) {
26
+ super({ ...service, type: 'CIDAggregateBeacon' }, sidecar);
27
+ }
28
+ get service() {
29
+ return {
30
+ type: this.type,
31
+ id: this.id,
32
+ serviceEndpoint: this.serviceEndpoint
33
+ };
34
+ }
35
+ /**
36
+ * TODO: Finish implementation
37
+ *
38
+ * Implements {@link https://dcdpr.github.io/did-btcr2/#establish-cidaggregate-beacon | 5.2.1 Establish CIDAggregate Beacon}.
39
+ *
40
+ * To establish a CIDAggregatorBeacon, a cohort of cooperating parties SHOULD generate an n-of-n P2TR Bitcoin address
41
+ * where each party contributes a public key. Furthermore, each party SHOULD verify that their key is part of the
42
+ * address and all other keys that are part of the address are keys with controllers able to produce valid signatures.
43
+ * To establish a Beacon there are two roles. One is the cohort participant, they want to join a Beacon cohort and
44
+ * submit a request to do so with a key and proof of control over that key. The other is the Beacon coordinator, they
45
+ * advertise and curate Beacon cohorts by combining Beacon participants into cohorts, verifying proofs of control, and
46
+ * producing Beacon addresses.
47
+ *
48
+ * @param {string} id The identifier of the Beacon.
49
+ * @param {string} type The type of the Beacon.
50
+ * @param {DidServiceEndpoint} serviceEndpoint The service endpoint of the Beacon.
51
+ * @returns {CIDAggregateBeacon} The established CIDAggregate Beacon.
52
+ */
53
+ static establish(id, type, serviceEndpoint) {
54
+ return new CIDAggregateBeacon({ id, type, serviceEndpoint });
55
+ }
56
+ /**
57
+ * TODO: Figure out if this is necessary or not.
58
+ * @param {string} didUpdatePayload The DID Update Payload to generate the signal for.
59
+ * @returns {BeaconSignal} The generated signal.
60
+ * @throws {Btcr2Error} if the signal is invalid.
61
+ */
62
+ generateSignal(didUpdatePayload) {
63
+ throw new Btcr2Error('Method not implemented.', `METHOD_NOT_IMPLEMENTED`, { didUpdatePayload });
64
+ }
65
+ /**
66
+ * TODO: Finish implementation
67
+ *
68
+ * Implements {@link https://dcdpr.github.io/did-btcr2/#process-cidaggregate-beacon-signal | 5.2.3 Process CIDAggregate Beacon Signal}.
69
+ *
70
+ * A Beacon Signal from a CIDAggregate Beacon is a Bitcoin transaction that contains the hashBytes of a DID Update
71
+ * Bundle in its first transaction output. The corresponding DID Update Bundle MUST either be provided through Sidecar
72
+ * Data or by converting hashBytes into a IPFS v1 Content Identifier and attempting to retrieve it from Content
73
+ * Addressable Storage. The DID Update Bundle maps from did:btcr2 identifiers to hashes of DID Update payloads
74
+ * applicable for that identifier. Again this algorithm attempts to retrieve and validate the DID Update Payload
75
+ * identified for the identifier being resolved. If successful, the DID Update Payload is returned.
76
+ *
77
+ * The Process CIDAggregate Beacon Signal algorithm is called by the Process Beacon Signals algorithm as part of the
78
+ * Read operation.
79
+ *
80
+ * It takes as inputs a did:btcr2 identifier, btc1Identifier, a Beacon Signal, tx, and a optional
81
+ * object, signalSidecarData, containing any sidecar data provided to the resolver for the Beacon Signal identified by
82
+ * the Bitcoin transaction identifier.
83
+ *
84
+ * It returns the DID Update payload announced by the Beacon Signal for the
85
+ * did:btcr2 identifier being resolved or throws an error.
86
+ *
87
+ * @param {RawTransactionV2} signal Bitcoin transaction representing a Beacon Signal.
88
+ * @param {SignalsMetadata} signalsMetadata Optional sidecar data for the Beacon Signal.
89
+ * @returns {Promise<DidUpdatePayload | undefined>} The DID Update payload announced by the Beacon Signal.
90
+ * @throws {DidError} if the signalTx is invalid or the signalsMetadata is invalid.
91
+ */
92
+ processSignal(signal, signalsMetadata) {
93
+ throw new Btcr2Error('Method not implemented.', `METHOD_NOT_IMPLEMENTED`, { signal, signalsMetadata });
94
+ }
95
+ /**
96
+ * TODO: Finish implementation
97
+ *
98
+ * Implements {@link https://dcdpr.github.io/did-btcr2/#broadcast-cidaggregate-beacon-signal | 5.2.2 Broadcast CIDAggregate Beacon Signal}.
99
+ *
100
+ * The Broadcast CIDAggregate Beacon Signal algorithm involving two roles: a set of cohort participants and a Beacon
101
+ * coordinator. The Beacon coordinator collects individual DID Update Payload Content Identifiers (CIDs) for specific
102
+ * did:btc1s and aggregates them into a DID Update Bundle, which is then published to a Content Addressable Storage
103
+ * (CAS). The CID for the DID Update Bundle is included in a Partially Signed Bitcoin Transaction (PSBT) transaction
104
+ * output spent from the Beacon’s n-of-n address. Each of the n cohort participants in the Beacon MUST sign the
105
+ * transaction before it can be broadcast to the network. It is RECOMMENDED that cohort participants keep a copy of
106
+ * the DID Update Bundle and separately pin it to the CAS.
107
+ *
108
+ * @param {DidUpdatePayload} didUpdatePayload The verificationMethod object to be used for signing.
109
+ * @returns {SignalsMetadata} Successful output of a bitcoin transaction.
110
+ * @throws {SingletonBeaconError} if the bitcoin address is invalid or unfunded.
111
+ */
112
+ broadcastSignal(didUpdatePayload) {
113
+ throw new Btcr2Error('Method not implemented.', `METHOD_NOT_IMPLEMENTED`, didUpdatePayload);
114
+ }
115
+ }
116
+ //# sourceMappingURL=cid-aggregate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cid-aggregate.js","sourceRoot":"","sources":["../../../../src/btcr2/beacon/cid-aggregate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAyC,MAAM,mBAAmB,CAAC;AAEtF,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAKpD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,kBAAmB,SAAQ,MAAM;IAC5C;;;;OAIG;IACH,YAAY,OAAsB,EAAE,OAAgD;QAClF,KAAK,CAAC,EAAE,GAAG,OAAO,EAAE,IAAI,EAAE,oBAAoB,EAAE,EAAE,OAAO,CAAC,CAAC;IAC7D,CAAC;IACD,IAAI,OAAO;QACT,OAAO;YACL,IAAI,EAAc,IAAI,CAAC,IAAI;YAC3B,EAAE,EAAgB,IAAI,CAAC,EAAE;YACzB,eAAe,EAAG,IAAI,CAAC,eAAe;SACvC,CAAC;IACJ,CAAC;IAGD;;;;;;;;;;;;;;;;;OAiBG;IACH,MAAM,CAAC,SAAS,CAAC,EAAU,EAAE,IAAY,EAAE,eAAmC;QAC5E,OAAO,IAAI,kBAAkB,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC,CAAC;IAC/D,CAAC;IAGD;;;;;OAKG;IACH,cAAc,CAAC,gBAAwB;QACrC,MAAM,IAAI,UAAU,CAAC,yBAAyB,EAAE,wBAAwB,EAAE,EAAC,gBAAgB,EAAC,CAAC,CAAC;IAChG,CAAC;IAGD;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,aAAa,CAAC,MAAwB,EAAE,eAAgC;QACtE,MAAM,IAAI,UAAU,CAAC,yBAAyB,EAAE,wBAAwB,EAAE,EAAC,MAAM,EAAE,eAAe,EAAC,CAAC,CAAC;IACvG,CAAC;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,eAAe,CAAC,gBAAkC;QAChD,MAAM,IAAI,UAAU,CAAC,yBAAyB,EAAE,wBAAwB,EAAE,gBAAgB,CAAC,CAAC;IAC9F,CAAC;CA4BF"}
@@ -0,0 +1,30 @@
1
+ import { Btcr2Error } from '@did-btcr2/common';
2
+ import { CIDAggregateBeacon } from './cid-aggregate.js';
3
+ import { SingletonBeacon } from './singleton.js';
4
+ import { SMTAggregateBeacon } from './smt-aggregate.js';
5
+ /**
6
+ * Beacon Factory pattern to create Beacon instances.
7
+ * @class BeaconFactory
8
+ * @type {BeaconFactory}
9
+ */
10
+ export class BeaconFactory {
11
+ /**
12
+ * Establish a Beacon instance based on the provided service and optional sidecar data.
13
+ * @param {BeaconService} service - The beacon service configuration.
14
+ * @param {SidecarData} [sidecar] - The optional sidecar data.
15
+ * @returns {Beacon} The established Beacon instance.
16
+ */
17
+ static establish(service, sidecar) {
18
+ switch (service.type) {
19
+ case 'SingletonBeacon':
20
+ return new SingletonBeacon(service, sidecar);
21
+ case 'CIDAggregateBeacon':
22
+ return new CIDAggregateBeacon(service, sidecar);
23
+ case 'SMTAggregateBeacon':
24
+ return new SMTAggregateBeacon(service, sidecar);
25
+ default:
26
+ throw new Btcr2Error('Invalid Beacon Type', 'INVALID_BEACON_ERROR', { service, sidecar });
27
+ }
28
+ }
29
+ }
30
+ //# sourceMappingURL=factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../../src/btcr2/beacon/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAExD;;;;GAIG;AACH,MAAM,OAAO,aAAa;IACxB;;;;;OAKG;IACH,MAAM,CAAC,SAAS,CAAC,OAAsB,EAAE,OAAqB;QAC5D,QAAQ,OAAO,CAAC,IAAI,EAAE,CAAC;YACrB,KAAK,iBAAiB;gBACpB,OAAO,IAAI,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC/C,KAAK,oBAAoB;gBACvB,OAAO,IAAI,kBAAkB,CAAC,OAAO,EAAE,OAA8B,CAAC,CAAC;YACzE,KAAK,oBAAoB;gBACvB,OAAO,IAAI,kBAAkB,CAAC,OAAO,EAAE,OAA8B,CAAC,CAAC;YACzE;gBACE,MAAM,IAAI,UAAU,CAClB,qBAAqB,EACrB,sBAAsB,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,CAC7C,CAAC;QACN,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,220 @@
1
+ import { INVALID_SIDECAR_DATA, LATE_PUBLISHING_ERROR, SingletonBeaconError } from '@did-btcr2/common';
2
+ import { opcodes, Psbt, script } from 'bitcoinjs-lib';
3
+ import { base58btc } from 'multiformats/bases/base58';
4
+ import bitcoinNetwork, { Bitcoin } from '../../bitcoin/index.js';
5
+ import { Beacon } from '../../interfaces/beacon.js';
6
+ import { Btc1Appendix } from '../../utils/appendix.js';
7
+ import { Btc1KeyManager, Signer } from '../key-manager/index.js';
8
+ /**
9
+ * Implements {@link https://dcdpr.github.io/did-btcr2/#singleton-beacon | 5.1 Singleton Beacon}.
10
+ *
11
+ * A Singleton Beacon enables a single entity to independently post a DID Update Payload in a Beacon Signal. Its is a
12
+ * Beacon that can be used to publish a single DID Update Payload targeting a single DID document. The serviceEndpoint
13
+ * for this Beacon Type is a Bitcoin address represented as a URI following the BIP21 scheme. It is recommended that
14
+ * this Bitcoin address be under the sole control of the DID controller. How the Bitcoin address and the cryptographic
15
+ * material that controls it are generated is left to the implementation.
16
+ *
17
+ * @class SingletonBeacon
18
+ * @type {SingletonBeacon}
19
+ * @extends {Beacon}
20
+ */
21
+ export class SingletonBeacon extends Beacon {
22
+ /**
23
+ * Creates an instance of SingletonBeacon.
24
+ * @param {BeaconService} service The Beacon service.
25
+ * @param {?BeaconSidecarData} [sidecar] Optional sidecar data.
26
+ */
27
+ constructor(service, sidecar) {
28
+ super({ ...service, type: 'SingletonBeacon' }, sidecar);
29
+ }
30
+ /**
31
+ * Get the Beacon service.
32
+ * @readonly
33
+ * @type {BeaconService} The Beacon service.
34
+ */
35
+ get service() {
36
+ return {
37
+ type: this.type,
38
+ id: this.id,
39
+ serviceEndpoint: this.serviceEndpoint
40
+ };
41
+ }
42
+ /**
43
+ * Implements {@link https://dcdpr.github.io/did-btcr2/#establish-singleton-beacon | 5.1.1 Establish Singleton Beacon}.
44
+ *
45
+ * Static, convenience method for establishing a Beacon object.
46
+ *
47
+ * A Singleton Beacon is a Beacon that can be used to publish a single DID Update Payload targeting a single DID
48
+ * document. The serviceEndpoint for this Beacon Type is a Bitcoin address represented as a URI following the BIP21
49
+ * scheme. It is RECOMMENDED that this Bitcoin address be under the sole control of the DID controller. How the
50
+ * Bitcoin address and the cryptographic material that controls it are generated is left to the implementation.
51
+ * The Establish Singleton Beacon algorithm takes in a Bitcoin address and a serviceId and returns a Singleton Beacon service.
52
+ * It returns a SignletonBeacon object with the given id, type, and serviceEndpoint.
53
+ *
54
+ * @param {string} service The Beacon service.
55
+ * @param {BeaconSidecarData<SingletonSidecar>} sidecar The sidecar data.
56
+ * @returns {SingletonBeacon} The Singleton Beacon.
57
+ */
58
+ static establish(service, sidecar) {
59
+ return new SingletonBeacon(service, sidecar);
60
+ }
61
+ /**
62
+ * TODO: Figure out if this is necessary or not.
63
+ * @param {string} didUpdatePayload The DID Update Payload to generate the signal for.
64
+ * @returns {BeaconSignal} The generated signal.
65
+ * @throws {Btcr2Error} if the signal is invalid.
66
+ */
67
+ generateSignal(didUpdatePayload) {
68
+ throw new Error('Method not implemented.' + didUpdatePayload);
69
+ }
70
+ /**
71
+ * TODO: Finish implementation per spec
72
+ *
73
+ * Implements {@link https://dcdpr.github.io/did-btcr2/#process-singleton-beacon-signal | 5.1.3 Process Singleton Beacon Signal}.
74
+ * See {@link Beacon.processSignal | Abstract Beacon Interface Method processSignal} for more details.
75
+ *
76
+ * The Process Singleton Beacon Signal algorithm is called by the Process Beacon Signals algorithm as part of the Read
77
+ * operation. It takes a Bitcoin transaction representing a Beacon Signal and optional signalSidecarData containing
78
+ * any sidecar data provided to the resolver for the Beacon Signal identified by the Bitcoin transaction identifier.
79
+ * It returns the DID Update payload announced by the Beacon Signal or throws an error.
80
+ *
81
+ * @param {RawTransactionV2} signal Bitcoin transaction representing a Beacon Signal.
82
+ * @param {SignalsMetadata} signalsMetadata: SignalsMetadata Optional sidecar data for the Beacon Signal.
83
+ * @returns {Promise<DidUpdatePayload | undefined>} The DID Update payload announced by the Beacon Signal.
84
+ * @throws {DidError} if the signalTx is invalid or the signalSidecarData is invalid.
85
+ */
86
+ async processSignal(signal, signalsMetadata) {
87
+ // 1. Initialize a txOut variable to the 0th transaction output of the tx.
88
+ const output = signal.vout.filter((vout) => (vout['scriptpubkey_asm'] || vout['scriptPubKey'].asm).includes('OP_RETURN'))?.[0];
89
+ if (!output) {
90
+ throw new SingletonBeaconError('No OP_RETURN output found in transaction outputs.', 'NO_OP_RETURN', { signal });
91
+ }
92
+ const outputMap = new Map(Object.entries(output));
93
+ // 2. Set didUpdatePayload to null.
94
+ let didUpdatePayload = undefined;
95
+ // 3. Check txout is of the format [OP_RETURN, OP_PUSH32, <32bytes>], if not, then return didUpdatePayload.
96
+ // The Bitcoin transaction is not a Beacon Signal.
97
+ const UPDATE_PAYLOAD_HASH = (outputMap.get('scriptpubkey_asm') ?? outputMap.get('scriptPubKey').asm).split(' ').last();
98
+ if (!UPDATE_PAYLOAD_HASH) {
99
+ return undefined;
100
+ }
101
+ // 4. Set hashBytes to the 32 bytes in the txout.
102
+ const hashBytes = JSON.canonicalization.encode(Buffer.fromHex(UPDATE_PAYLOAD_HASH), 'base58');
103
+ // Convert signalsMetadata to a Map for easier access
104
+ const signalsMetadataMap = new Map(Object.entries(signalsMetadata));
105
+ // 5. If signalsMetadata:
106
+ if (signalsMetadata) {
107
+ // 5.1 Set didUpdatePayload to signalsMetadata.updatePayload
108
+ didUpdatePayload = signalsMetadataMap.get(signal.txid)?.btc1Update;
109
+ if (!didUpdatePayload) {
110
+ throw new SingletonBeaconError('Update Payload not found in signal metadata.', 'PROCESS_SIGNAL_ERROR');
111
+ }
112
+ // 5.2 Set updateHashBytes to the result of passing didUpdatePayload to the JSON Canonicalization and Hash algorithm.
113
+ const updateHashBytes = await JSON.canonicalization.process(didUpdatePayload, 'base58');
114
+ // 5.3 If updateHashBytes does not equal hashBytes, MUST throw an invalidSidecarData error.
115
+ if (updateHashBytes !== hashBytes) {
116
+ throw new SingletonBeaconError(`Hash mismatch: updateHashBytes ${updateHashBytes} !== hashBytes ${hashBytes}.`, INVALID_SIDECAR_DATA, { UPDATE_PAYLOAD_HASH, didUpdatePayload });
117
+ }
118
+ // 7. Return didUpdatePayload.
119
+ return didUpdatePayload;
120
+ }
121
+ // 6. Else:
122
+ // 6.1 Set didUpdatePayload to the result of passing hashBytes into the Fetch Content from Addressable Storage algorithm.
123
+ const didUpdatePayloadString = await Btc1Appendix.fetchFromCas(base58btc.decode(hashBytes));
124
+ if (!didUpdatePayloadString || !JSON.parse(didUpdatePayloadString)) {
125
+ throw new SingletonBeaconError('Update payload not found in addressable storage.', INVALID_SIDECAR_DATA);
126
+ }
127
+ didUpdatePayload = JSON.parse(didUpdatePayloadString);
128
+ // 6.2 If didUpdatePayload is null, MUST raise a latePublishingError. MAY identify Beacon Signal to resolver and request additional Sidecar data be provided.
129
+ if (!didUpdatePayload) {
130
+ throw new SingletonBeaconError('Update payload hash does not match transaction hash.', LATE_PUBLISHING_ERROR);
131
+ }
132
+ // 7. Return didUpdatePayload.
133
+ return didUpdatePayload;
134
+ }
135
+ /**
136
+ * Implements {@link https://dcdpr.github.io/did-btcr2/#broadcast-singleton-beacon-signal | 5.1.2 Broadcast Singleton Beacon Signal}.
137
+ *
138
+ * The Broadcast Singleton Beacon Signal algorithm is called by the Announce DID Update algorithm as part of the
139
+ * Update operation, if the Beacon being used is of the type SingletonBeacon. It takes as input a Beacon service and a
140
+ * secured didUpdatePayload. The algorithm constructs a Bitcoin transaction that spends from the Beacon address
141
+ * identified in the service and contains a transaction output of the format [OP_RETURN, OP_PUSH32, <hashBytes>],
142
+ * where hashBytes is the SHA256 hash of the canonical didUpdatePayload. The Bitcoin transaction is then signed and
143
+ * broadcast to the Bitcoin network, thereby publicly announcing a DID update in a Beacon Signal. It returns a
144
+ * signalMetadata object mapping the Bitcoin transaction identifier of the Beacon Signal to the necessary data needed
145
+ * to verify the signal announces a specific DID Update Payload.
146
+ *
147
+ * TODO: Design and implement a way to construct, sign and send via RPC
148
+ *
149
+ * @param {DidUpdatePayload} didUpdatePayload The verificationMethod object to be used for signing.
150
+ * @returns {SignedRawTx} Successful output of a bitcoin transaction.
151
+ * @throws {SingletonBeaconError} if the bitcoin address is invalid or unfunded.
152
+ */
153
+ async broadcastSignal(didUpdatePayload) {
154
+ // Grab the connection configuration from the environment variable or default to the rpc config
155
+ const bitcoin = bitcoinNetwork ?? new Bitcoin();
156
+ // 1. Initialize an addressURI variable to beacon.serviceEndpoint.
157
+ // 2. Set bitcoinAddress to the decoding of addressURI following BIP21.
158
+ const bitcoinAddress = this.service.serviceEndpoint.replace('bitcoin:', '');
159
+ // 3. Ensure bitcoinAddress is funded, if not, fund this address.
160
+ // let inputs: Array<CreateRawTxInputs> = [];
161
+ const utxos = await bitcoin.rest.address.getUtxos(bitcoinAddress);
162
+ if (!utxos.length) {
163
+ // TODO: Discuss what to do here because sending to a beacon address does not allow you to spend from it immediately.
164
+ throw new SingletonBeaconError('No UTXOs found, please fund address!', 'UNFUNDED_BEACON_ADDRESS', { bitcoinAddress });
165
+ }
166
+ const utxo = utxos.sort((a, b) => b.status.block_height - a.status.block_height)[0];
167
+ if (!utxo) {
168
+ throw new SingletonBeaconError('Beacon bitcoin address unfunded or utxos unconfirmed.', 'UNFUNDED_BEACON_ADDRESS', { bitcoinAddress });
169
+ }
170
+ // 4. Set hashBytes to the result of passing didUpdatePayload to the JSON Canonicalization and Hash algorithm.
171
+ const hashBytes = Buffer.fromHex(await JSON.canonicalization.process(didUpdatePayload));
172
+ if (hashBytes.length !== 32)
173
+ throw new SingletonBeaconError('Hash must be 32 bytes');
174
+ // 5. Initialize spendTx to a Bitcoin transaction that spends a transaction controlled by the bitcoinAddress and
175
+ // contains at least one transaction output. This output MUST have the following format
176
+ // [OP_RETURN, OP_PUSH32, hashBytes]
177
+ const { txid, vout } = utxo;
178
+ const prevTx = await bitcoin.rest.transaction.getHex(txid);
179
+ const input = {
180
+ hash: txid,
181
+ index: vout,
182
+ nonWitnessUtxo: Buffer.fromHex(prevTx)
183
+ };
184
+ // TODO: Figure out a good way to estimate fees
185
+ const spendTx = new Psbt({ network: bitcoin.network.data })
186
+ .addInput(input)
187
+ .addOutput({ address: bitcoinAddress, value: BigInt(utxo.value) - BigInt(500) })
188
+ .addOutput({ script: script.compile([opcodes.OP_RETURN, hashBytes]), value: 0n });
189
+ // 6. Retrieve the cryptographic material, e.g private key or signing capability, associated with the bitcoinAddress
190
+ // or service. How this is done is left to the implementer.
191
+ // TODO: Determine how we want to handle this. Currently, this code uses the RPC to handle signing.
192
+ console.log('Btc1KeyManager', Btc1KeyManager.instance);
193
+ console.log('this.service.id', this.service.id);
194
+ const multikey = await Btc1KeyManager.getKeyPair(this.service.id);
195
+ console.log('multikey', multikey);
196
+ if (!multikey) {
197
+ throw new Error('Key pair not found.');
198
+ }
199
+ const signer = new Signer({ multikey, network: bitcoin.network.name });
200
+ // 7. Sign the spendTx.
201
+ const signedTx = spendTx.signInput(0, signer)
202
+ .finalizeAllInputs()
203
+ .extractTransaction()
204
+ .toHex();
205
+ if (!spendTx) {
206
+ throw new SingletonBeaconError('Failed to sign raw transaction.', 'RAW_TX_SIGN_FAILED', { spendTx });
207
+ }
208
+ // 8. Broadcast spendTx to the Bitcoin network.
209
+ const spentTx = await bitcoin.rest.transaction.send(signedTx);
210
+ if (!spentTx) {
211
+ throw new SingletonBeaconError('Failed to send raw transaction.', 'SEND_FAILED', { spentTx });
212
+ }
213
+ // 9. Set signalId to the Bitcoin transaction identifier of spendTx.
214
+ // 10. Initialize signalMetadata to an empty object.
215
+ // 11. Set signalMetadata.updatePayload to didUpdatePayload.
216
+ // 12. Return the object {<signalId>: { updatePayload: DidUpdatePayload; proofs?: any; }}.
217
+ return { [spentTx]: { btc1Update: didUpdatePayload } };
218
+ }
219
+ }
220
+ //# sourceMappingURL=singleton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"singleton.js","sourceRoot":"","sources":["../../../../src/btcr2/beacon/singleton.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,oBAAoB,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACxH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,cAAc,EAAE,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEjE,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAIpD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEjE;;;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EAAE,gBAAgB,EAAE,EAAE,CAAC;IACzD,CAAC;CACF"}
@@ -0,0 +1,126 @@
1
+ import { Btcr2Error } from '@did-btcr2/common';
2
+ import { Beacon } from '../../interfaces/beacon.js';
3
+ /**
4
+ * TODO: Finish implementation
5
+ *
6
+ * Implements {@link https://dcdpr.github.io/did-btcr2/#smtaggregate-beacon | 5.3 SMTAggregate Beacon}.
7
+ *
8
+ * A SMTAggregate Beacon is a Beacon whose Beacon Signals are Bitcoin transactions containing the root of a Sparse
9
+ * Merkle Tree (SMT). The SMT root attests to a set of DID Update Payloads, however, the updates themselves MUST be
10
+ * provided along with a proof of inclusion against the SMT root through a Sidecar mechanism during resolution. Using
11
+ * the SMT root a resolver can then verify the inclusion proof for the given DID Update Payload. If a DID document
12
+ * includes a SMTAggregator Beacon in their set of Beacon services, then they MUST provide proofs for each signal that
13
+ * the Beacon broadcasts. If they did not submit an update to their DID in a signal, then they MUST provide a proof of
14
+ * non-inclusion for that signal.
15
+ *
16
+ * @class SMTAggregateBeacon
17
+ * @type {SMTAggregateBeacon}
18
+ * @extends {Beacon}
19
+ */
20
+ export class SMTAggregateBeacon extends Beacon {
21
+ /**
22
+ * Creates an instance of SMTAggregateBeacon.
23
+ * @param {BeaconService} service The Beacon service.
24
+ * @param {?BeaconSidecarData} [sidecar] Optional sidecar data.
25
+ */
26
+ constructor(service, sidecar) {
27
+ super({ ...service, type: 'SMTAggregateBeacon' }, sidecar);
28
+ }
29
+ /**
30
+ * Get the Beacon service.
31
+ * @readonly
32
+ * @type {BeaconService} The Beacon service.
33
+ */
34
+ get service() {
35
+ const service = {
36
+ type: this.type,
37
+ id: this.id,
38
+ serviceEndpoint: this.serviceEndpoint
39
+ };
40
+ return service;
41
+ }
42
+ /**
43
+ * TODO: Figure out if this is necessary or not.
44
+ * @param {string} didUpdatePayload The DID Update Payload to generate the signal for.
45
+ * @returns {BeaconSignal} The generated signal.
46
+ * @throws {Btcr2Error} if the signal is invalid.
47
+ */
48
+ generateSignal(didUpdatePayload) {
49
+ throw new Btcr2Error('Method not implemented.', `METHOD_NOT_IMPLEMENTED`, { didUpdatePayload });
50
+ }
51
+ /**
52
+ * Implements {@link https://dcdpr.github.io/did-btcr2/#establish-beacon | 5.3.1 Establish Beacon}.
53
+ *
54
+ * The Establish Beacon algorithm is essentially the same as for the CIDAggregate Beacon in Establish CIDAggregate
55
+ * Beacon. A cohort of DID controllers need to coordinate to produce a Bitcoin address that will act as the Beacon.
56
+ * It is RECOMMENDED this is an n-of-n P2TR address, with n being the set of DID controllers in the cohort. Once the
57
+ * address has been created, and all parties in the cohort acknowledge their intention to participate in that Beacon,
58
+ * each DID controller SHOULD add the Beacon as a service to their DID document.
59
+ *
60
+ * Additionally, the SMTAggregate Beacon cohort participants MUST register the did:btcr2 identifiers they intend use
61
+ * this Beacon with. This is so the Beacon coordinator can generate the necessary proofs of both inclusion and
62
+ * non-inclusion for each DID.
63
+ *
64
+ * Static, convenience method for establishing a Beacon object.
65
+ *
66
+ * @param {string} id The Beacon ID.
67
+ * @param {string} type The Beacon type.
68
+ * @param {DidServiceEndpoint} serviceEndpoint The service endpoint.
69
+ * @returns {Beacon} The Beacon.
70
+ */
71
+ static establish(id, type, serviceEndpoint) {
72
+ return new SMTAggregateBeacon({ id, type, serviceEndpoint });
73
+ }
74
+ /**
75
+ *
76
+ * Implements {@link https://dcdpr.github.io/did-btcr2/#broadcast-smtaggregate-beacon-signal | 5.3.2 Broadcast SMTAggregate Beacon Signal}.
77
+ *
78
+ * See {@link Beacon.broadcastSignal | Beacon Interface Method broadcastSignal} for more information.
79
+ *
80
+ * To publish a DID Update Payload, the DID controller MUST get a hash of the DID Update Payload included at the leaf
81
+ * of the Sparse Merkle Tree (SMT) identified by their did:btcr2 identifier and receive an inclusion proof for this
82
+ * data. If a member of the Beacon cohort does not wish to announce an update in a Beacon Signal, they MUST receive
83
+ * and verify a proof of non-inclusion for their DID. Upon verifying the non-inclusion proof against the SMT root
84
+ * contained in the Beacon Signal, they SHOULD accept and authorize the signal following the MuSig2 protocol. Once all
85
+ * members of the cohort have authorized the signal, it can be broadcast as a transaction to the Bitcoin network. DID
86
+ * controllers are responsible for persisting their DID updates and proofs, these will need to be provided through a
87
+ * Sidecar mechanism during a resolution process.
88
+ *
89
+ * @param {DidUpdatePayload} didUpdatePayload The DID Update Payload to broadcast.
90
+ * @returns {Promise<SignalMetadata>} The signal metadata.
91
+ * @throws {Btcr2Error} if the signal is invalid.
92
+ */
93
+ broadcastSignal(didUpdatePayload) {
94
+ throw new Btcr2Error('Method not implemented.', `METHOD_NOT_IMPLEMENTED`, didUpdatePayload);
95
+ }
96
+ /**
97
+ * Implements {@link https://dcdpr.github.io/did-btcr2/#process-smtaggregate-beacon-signal | 5.3.3 Process SMTAggregate Beacon Signal}.
98
+ *
99
+ * See {@link Beacon.processSignal | Beacon Interface Method processSignal} for more information.
100
+ *
101
+ * A Beacon Signal from a SMTAggregate Beacon is a Bitcoin transaction with the first transaction output of the format
102
+ * [OP_RETURN, OP_PUSH32, <32bytes>]. The 32 bytes of data contained within this transaction output represent the root
103
+ * of a Sparse Merkle Tree (SMT). This SMT aggregates a set of hashes of DID Update payloads. In order to process
104
+ * these Beacon Signals, the resolver MUST have been passed Sidecar data for this signal containing either the DID
105
+ * Update payload object and a SMT proof that the hash of this object is in the SMT at the leaf indexed by the
106
+ * did:btc1identifier being resolved. Or theSidecar data:: MUST contain a proof that the leaf indexed by the
107
+ * did:btc1identifier is empty, thereby proving that theSMT:: does not contain an update for their identifier.
108
+ *
109
+ * The Process SMTAggregate Beacon Signal is called by the Process Beacon Signals algorithm as part of the Read
110
+ * operation. It takes as inputs a did:btcr2 identifier, btc1Identifier, a Beacon Signal, tx, and a optional object,
111
+ * signalSidecarData, containing any sidecar data provided to the resolver for the Beacon Signal identified by the
112
+ * Bitcoin transaction identifier.
113
+ *
114
+ * It returns the DID Update payload announced by the Beacon Signal for the did:btcr2 identifier being resolved or
115
+ * throws an error.
116
+ *
117
+ * @param {RawTransactionV2} signal The raw transaction signal.
118
+ * @param {SignalsMetadata} signalsMetadata The signals metadata.
119
+ * @returns {Promise<DidUpdatePayload | undefined>} The updated DID document.
120
+ * @throws {Btcr2Error} if the signal is invalid.
121
+ */
122
+ processSignal(signal, signalsMetadata) {
123
+ throw new Btcr2Error('Method not implemented.', `METHOD_NOT_IMPLEMENTED`, { signal, signalsMetadata });
124
+ }
125
+ }
126
+ //# sourceMappingURL=smt-aggregate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"smt-aggregate.js","sourceRoot":"","sources":["../../../../src/btcr2/beacon/smt-aggregate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAoB,MAAM,mBAAmB,CAAC;AAEjE,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAKpD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,kBAAmB,SAAQ,MAAM;IAC5C;;;;OAIG;IACH,YAAY,OAAsB,EAAE,OAAgD;QAClF,KAAK,CAAC,EAAE,GAAG,OAAO,EAAE,IAAI,EAAE,oBAAoB,EAAE,EAAE,OAAO,CAAC,CAAC;IAC7D,CAAC;IAED;;;;OAIG;IACH,IAAI,OAAO;QACT,MAAM,OAAO,GAAG;YACd,IAAI,EAAc,IAAI,CAAC,IAAI;YAC3B,EAAE,EAAgB,IAAI,CAAC,EAAE;YACzB,eAAe,EAAG,IAAI,CAAC,eAAe;SACvC,CAAC;QACF,OAAO,OAAO,CAAC;IACjB,CAAC;IAED;;;;;OAKG;IACI,cAAc,CAAC,gBAAwB;QAC5C,MAAM,IAAI,UAAU,CAAC,yBAAyB,EAAE,wBAAwB,EAAE,EAAC,gBAAgB,EAAC,CAAC,CAAC;IAChG,CAAC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACI,MAAM,CAAC,SAAS,CAAC,EAAU,EAAE,IAAY,EAAE,eAAmC;QACnF,OAAO,IAAI,kBAAkB,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,eAA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