@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,136 @@
1
+ import { Btcr2Error, DidUpdatePayload } from '@did-btcr2/common';
2
+ import { DidServiceEndpoint } from '@web5/dids';
3
+ import { Beacon } from '../../interfaces/beacon.js';
4
+ import { BeaconService, BeaconSignal } from '../../interfaces/ibeacon.js';
5
+ import { RawTransactionV2 } from '../../types/bitcoin.js';
6
+ import { BeaconSidecarData, SignalsMetadata, SMTAggregateSidecar } from '../../types/crud.js';
7
+
8
+ /**
9
+ * TODO: Finish implementation
10
+ *
11
+ * Implements {@link https://dcdpr.github.io/did-btcr2/#smtaggregate-beacon | 5.3 SMTAggregate Beacon}.
12
+ *
13
+ * A SMTAggregate Beacon is a Beacon whose Beacon Signals are Bitcoin transactions containing the root of a Sparse
14
+ * Merkle Tree (SMT). The SMT root attests to a set of DID Update Payloads, however, the updates themselves MUST be
15
+ * provided along with a proof of inclusion against the SMT root through a Sidecar mechanism during resolution. Using
16
+ * the SMT root a resolver can then verify the inclusion proof for the given DID Update Payload. If a DID document
17
+ * includes a SMTAggregator Beacon in their set of Beacon services, then they MUST provide proofs for each signal that
18
+ * the Beacon broadcasts. If they did not submit an update to their DID in a signal, then they MUST provide a proof of
19
+ * non-inclusion for that signal.
20
+ *
21
+ * @class SMTAggregateBeacon
22
+ * @type {SMTAggregateBeacon}
23
+ * @extends {Beacon}
24
+ */
25
+ export class SMTAggregateBeacon extends Beacon {
26
+ /**
27
+ * Creates an instance of SMTAggregateBeacon.
28
+ * @param {BeaconService} service The Beacon service.
29
+ * @param {?BeaconSidecarData} [sidecar] Optional sidecar data.
30
+ */
31
+ constructor(service: BeaconService, sidecar?: BeaconSidecarData<SMTAggregateSidecar>) {
32
+ super({ ...service, type: 'SMTAggregateBeacon' }, sidecar);
33
+ }
34
+
35
+ /**
36
+ * Get the Beacon service.
37
+ * @readonly
38
+ * @type {BeaconService} The Beacon service.
39
+ */
40
+ get service(): BeaconService {
41
+ const service = {
42
+ type : this.type,
43
+ id : this.id,
44
+ serviceEndpoint : this.serviceEndpoint
45
+ };
46
+ return service;
47
+ }
48
+
49
+ /**
50
+ * TODO: Figure out if this is necessary or not.
51
+ * @param {string} didUpdatePayload The DID Update Payload to generate the signal for.
52
+ * @returns {BeaconSignal} The generated signal.
53
+ * @throws {Btcr2Error} if the signal is invalid.
54
+ */
55
+ public generateSignal(didUpdatePayload: string): BeaconSignal {
56
+ throw new Btcr2Error('Method not implemented.', `METHOD_NOT_IMPLEMENTED`, {didUpdatePayload});
57
+ }
58
+
59
+ /**
60
+ * Implements {@link https://dcdpr.github.io/did-btcr2/#establish-beacon | 5.3.1 Establish Beacon}.
61
+ *
62
+ * The Establish Beacon algorithm is essentially the same as for the CIDAggregate Beacon in Establish CIDAggregate
63
+ * Beacon. A cohort of DID controllers need to coordinate to produce a Bitcoin address that will act as the Beacon.
64
+ * It is RECOMMENDED this is an n-of-n P2TR address, with n being the set of DID controllers in the cohort. Once the
65
+ * address has been created, and all parties in the cohort acknowledge their intention to participate in that Beacon,
66
+ * each DID controller SHOULD add the Beacon as a service to their DID document.
67
+ *
68
+ * Additionally, the SMTAggregate Beacon cohort participants MUST register the did:btcr2 identifiers they intend use
69
+ * this Beacon with. This is so the Beacon coordinator can generate the necessary proofs of both inclusion and
70
+ * non-inclusion for each DID.
71
+ *
72
+ * Static, convenience method for establishing a Beacon object.
73
+ *
74
+ * @param {string} id The Beacon ID.
75
+ * @param {string} type The Beacon type.
76
+ * @param {DidServiceEndpoint} serviceEndpoint The service endpoint.
77
+ * @returns {Beacon} The Beacon.
78
+ */
79
+ public static establish(id: string, type: string, serviceEndpoint: DidServiceEndpoint): SMTAggregateBeacon {
80
+ return new SMTAggregateBeacon({ id, type, serviceEndpoint });
81
+ }
82
+
83
+ /**
84
+ *
85
+ * Implements {@link https://dcdpr.github.io/did-btcr2/#broadcast-smtaggregate-beacon-signal | 5.3.2 Broadcast SMTAggregate Beacon Signal}.
86
+ *
87
+ * See {@link Beacon.broadcastSignal | Beacon Interface Method broadcastSignal} for more information.
88
+ *
89
+ * To publish a DID Update Payload, the DID controller MUST get a hash of the DID Update Payload included at the leaf
90
+ * of the Sparse Merkle Tree (SMT) identified by their did:btcr2 identifier and receive an inclusion proof for this
91
+ * data. If a member of the Beacon cohort does not wish to announce an update in a Beacon Signal, they MUST receive
92
+ * and verify a proof of non-inclusion for their DID. Upon verifying the non-inclusion proof against the SMT root
93
+ * contained in the Beacon Signal, they SHOULD accept and authorize the signal following the MuSig2 protocol. Once all
94
+ * members of the cohort have authorized the signal, it can be broadcast as a transaction to the Bitcoin network. DID
95
+ * controllers are responsible for persisting their DID updates and proofs, these will need to be provided through a
96
+ * Sidecar mechanism during a resolution process.
97
+ *
98
+ * @param {DidUpdatePayload} didUpdatePayload The DID Update Payload to broadcast.
99
+ * @returns {Promise<SignalMetadata>} The signal metadata.
100
+ * @throws {Btcr2Error} if the signal is invalid.
101
+ */
102
+ public broadcastSignal(didUpdatePayload: DidUpdatePayload): Promise<SignalsMetadata> {
103
+ throw new Btcr2Error('Method not implemented.', `METHOD_NOT_IMPLEMENTED`, didUpdatePayload);
104
+ }
105
+
106
+
107
+ /**
108
+ * Implements {@link https://dcdpr.github.io/did-btcr2/#process-smtaggregate-beacon-signal | 5.3.3 Process SMTAggregate Beacon Signal}.
109
+ *
110
+ * See {@link Beacon.processSignal | Beacon Interface Method processSignal} for more information.
111
+ *
112
+ * A Beacon Signal from a SMTAggregate Beacon is a Bitcoin transaction with the first transaction output of the format
113
+ * [OP_RETURN, OP_PUSH32, <32bytes>]. The 32 bytes of data contained within this transaction output represent the root
114
+ * of a Sparse Merkle Tree (SMT). This SMT aggregates a set of hashes of DID Update payloads. In order to process
115
+ * these Beacon Signals, the resolver MUST have been passed Sidecar data for this signal containing either the DID
116
+ * Update payload object and a SMT proof that the hash of this object is in the SMT at the leaf indexed by the
117
+ * did:btc1identifier being resolved. Or theSidecar data:: MUST contain a proof that the leaf indexed by the
118
+ * did:btc1identifier is empty, thereby proving that theSMT:: does not contain an update for their identifier.
119
+ *
120
+ * The Process SMTAggregate Beacon Signal is called by the Process Beacon Signals algorithm as part of the Read
121
+ * operation. It takes as inputs a did:btcr2 identifier, btc1Identifier, a Beacon Signal, tx, and a optional object,
122
+ * signalSidecarData, containing any sidecar data provided to the resolver for the Beacon Signal identified by the
123
+ * Bitcoin transaction identifier.
124
+ *
125
+ * It returns the DID Update payload announced by the Beacon Signal for the did:btcr2 identifier being resolved or
126
+ * throws an error.
127
+ *
128
+ * @param {RawTransactionV2} signal The raw transaction signal.
129
+ * @param {SignalsMetadata} signalsMetadata The signals metadata.
130
+ * @returns {Promise<DidUpdatePayload | undefined>} The updated DID document.
131
+ * @throws {Btcr2Error} if the signal is invalid.
132
+ */
133
+ public processSignal(signal: RawTransactionV2, signalsMetadata: SignalsMetadata): Promise<DidUpdatePayload | undefined> {
134
+ throw new Btcr2Error('Method not implemented.', `METHOD_NOT_IMPLEMENTED`, {signal, signalsMetadata});
135
+ }
136
+ }
@@ -0,0 +1,160 @@
1
+ import { Btcr2IdentifierTypes, KeyBytes, PatchOperation } from '@did-btcr2/common';
2
+ import { PublicKey } from '@did-btcr2/keypair';
3
+ import { DidCreateOptions as IDidCreateOptions } from '@web5/dids';
4
+ import { getNetwork } from '../../bitcoin/network.js';
5
+ import { BeaconUtils } from '../../utils/beacons.js';
6
+ import { Btc1DidDocument, IntermediateDidDocument } from '../../utils/did-document.js';
7
+ import { Btc1Identifier } from '../../utils/identifier.js';
8
+ import { Btc1KeyManager } from '../key-manager/index.js';
9
+
10
+ export type Btc1CreateParams = Btc1CreateKeyParams | Btc1CreateExternalParams;
11
+ export interface CreateIdentifierParams {
12
+ genesisBytes: Uint8Array;
13
+ newtork?: string;
14
+ version?: string;
15
+ }
16
+ export type Btc1CreateResponse = {
17
+ did: string;
18
+ initialDocument: Btc1DidDocument;
19
+ };
20
+ export interface Btc1UpdateConstructParams {
21
+ identifier: string;
22
+ sourceDocument: Btc1DidDocument;
23
+ sourceVersionId: number;
24
+ patch: PatchOperation[];
25
+ }
26
+ export interface Btc1UpdateParams extends Btc1UpdateConstructParams {
27
+ verificationMethodId: string;
28
+ beaconIds: string[];
29
+ }
30
+ export interface DidCreateOptions extends IDidCreateOptions<Btc1KeyManager> {
31
+ /** DID BTCR2 Version Number */
32
+ version?: number;
33
+ /** Bitcoin Network */
34
+ network?: string;
35
+ }
36
+ export type Btc1CreateKeyParams = {
37
+ idType: 'KEY';
38
+ pubKeyBytes: KeyBytes;
39
+ options?: DidCreateOptions;
40
+ };
41
+ export type Btc1CreateExternalParams = {
42
+ idType: 'EXTERNAL';
43
+ intermediateDocument: IntermediateDidDocument;
44
+ options?: DidCreateOptions;
45
+ };
46
+
47
+ /**
48
+ * Implements section {@link https://dcdpr.github.io/did-btcr2/#create | 4.1 Create}.
49
+ *
50
+ * A did:btcr2 identifier and associated DID document can either be created deterministically from a cryptographic seed,
51
+ * or it can be created from an arbitrary genesis intermediate DID document representation. In both cases, DID creation
52
+ * can be undertaken in an offline manner, i.e., the DID controller does not need to interact with the Bitcoin network
53
+ * to create their DID.
54
+ *
55
+ * @class Btc1Create
56
+ * @type {Btc1Create}
57
+ */
58
+ export class Btc1Create {
59
+ /**
60
+ * Implements {@link https://dcdpr.github.io/did-btcr2/#deterministic-key-based-creation | 4.1.1 Deterministic Key-Based Creation}.
61
+ *
62
+ * For deterministic key-based creation, the did:btcr2 identifier encodes a secp256k1 public key. The key is then used
63
+ * to deterministically generate the initial DID document.
64
+ *
65
+ * @param {Btc1CreateKeyParams} params See {@link Btc1CreateKeyParams} for details.
66
+ * @param {number} params.version did-btcr2 identifier version.
67
+ * @param {string} params.network did-btcr2 bitcoin network.
68
+ * @param {KeyBytes} params.pubKeyBytes public key bytes for id creation.
69
+ * @returns {Btc1CreateResponse} A response object of type {@link Btc1CreateResponse}.
70
+ * @throws {DidError} if the public key is missing or invalid.
71
+ */
72
+ public static deterministic({ pubKeyBytes, options }: {
73
+ pubKeyBytes: KeyBytes;
74
+ options: DidCreateOptions;
75
+ }): Btc1CreateResponse {
76
+ // Deconstruct options and set the default values
77
+ const { version = 1, network = 'bitcoin' } = options;
78
+
79
+ // Set idType to "KEY"
80
+ const idType = Btcr2IdentifierTypes.KEY;
81
+
82
+ // Call the the did:btcr2 Identifier Encoding algorithm
83
+ const identifier = Btc1Identifier.encode({ version, network, idType, genesisBytes: pubKeyBytes });
84
+
85
+ // Instantiate PublicKey object and get the multibase formatted publicKey
86
+ const { compressed: publicKey, multibase: publicKeyMultibase } = new PublicKey(pubKeyBytes);
87
+
88
+ // Generate the service field for the DID Document
89
+ const service = BeaconUtils.generateBeaconServices({
90
+ identifier,
91
+ publicKey,
92
+ network : getNetwork(network),
93
+ type : 'SingletonBeacon',
94
+ });
95
+
96
+ // Create initialDocument ensuring conformant to spec as Btc1DidDocument
97
+ const initialDocument = new Btc1DidDocument({
98
+ id : identifier,
99
+ controller : [identifier],
100
+ verificationMethod : [{
101
+ id : `${identifier}#initialKey`,
102
+ type : 'Multikey',
103
+ controller : identifier,
104
+ publicKeyMultibase : publicKeyMultibase.address,
105
+ }],
106
+ service,
107
+ });
108
+
109
+ // Return did & initialDocument
110
+ return { did: identifier, initialDocument };
111
+ }
112
+
113
+ /**
114
+ * Implements {@link https://dcdpr.github.io/did-btcr2/#external-initial-document-creation | 4.1.2 External Initial Document Creation}.
115
+ *
116
+ * Creates a did:btcr2 identifier from some initiating arbitrary DID document. This allows for more complex
117
+ * initial DID documents, including the ability to include Service Endpoints and Beacons that support aggregation.
118
+ * Inputs include `intermediateDocument`, optional version and network returning initialDidDocument. The
119
+ * intermediateDocument should be a valid DID document except all places where the DID document requires the use of
120
+ * the identifier (e.g. the id field). These fields should use placeholder value
121
+ * `did:btcr2:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`. The intermediateDocument should include at
122
+ * least one verificationMethod and service of the type SingletonBeacon.
123
+ *
124
+ * @param {Btc1CreateExternalParams} params See {@link Btc1CreateExternalParams} for details.
125
+ * @param {number} params.version Identifier version.
126
+ * @param {string} params.network Identifier network name.
127
+ * @param {string} params.documentBytes Intermediate DID Document bytes.
128
+ * @returns {Btc1CreateResponse} A Promise resolving to {@link Btc1CreateResponses}.
129
+ * @throws {DidError} if the verificationMethod or service objects are missing required properties
130
+ */
131
+ public static async external({ intermediateDocument, options }: {
132
+ intermediateDocument: IntermediateDidDocument;
133
+ options: DidCreateOptions;
134
+ }): Promise<Btc1CreateResponse> {
135
+ // 1. Set idType to "EXTERNAL"
136
+ const idType = Btcr2IdentifierTypes.EXTERNAL;
137
+
138
+ // 2. Set version to 1
139
+ // 3. Set network to the desired network.
140
+ const { version = 1, network = 'bitcoin' } = options;
141
+
142
+ // Validate intermediateDocument
143
+ intermediateDocument.validateIntermediate();
144
+
145
+ // 4. Set genesisBytes to the result of passing intermediateDocument into the JSON Canonicalization and Hash
146
+ // algorithm.
147
+ const genesisBytes = await JSON.canonicalization.canonicalhash(intermediateDocument);
148
+
149
+ // 5. Pass idType, version, network, and genesisBytes to the did:btcr2 Identifier Encoding algorithm, retrieving id.
150
+ // 6. Set did to id
151
+ const did = Btc1Identifier.encode({ idType, genesisBytes, version, network });
152
+
153
+ // 7. Set initialDocument to a copy of the intermediateDocument.
154
+ // 8. Replace all did:btcr2:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx values in the initialDocument with the did.
155
+ const initialDocument = intermediateDocument.toBtc1DidDocument(did);
156
+
157
+ // Return DID & DID Document.
158
+ return { did, initialDocument };
159
+ }
160
+ }
@@ -0,0 +1,13 @@
1
+ import { DidBtc1 } from '../../did-btcr2.js';
2
+
3
+ /**
4
+ * Implements {@link https://dcdpr.github.io/did-btcr2/#deactivate | 4.4 Deactivate}
5
+ * To deactivate a did:btcr2, the DID controller MUST add the property deactivated with the value true on the DID
6
+ * document. To do this, the DID controller constructs a valid DID Update Payload with a JSON patch that adds this
7
+ * property and announces the payload through a Beacon in their current DID document following the algorithm in Update.
8
+ * Once a did:btcr2 has been deactivated this state is considered permanent and resolution MUST terminate.
9
+ * @class Btc1Deactivate
10
+ * @type {Btc1Deactivate}
11
+ * @extends {DidBtc1}
12
+ */
13
+ export class Btc1Deactivate extends DidBtc1 {}