@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,129 @@
1
+ import { HashBytes, Hex, SignatureBytes } from '@did-btcr2/common';
2
+ import { Multikey, SchnorrMultikey } from '@did-btcr2/cryptosuite';
3
+ import { SchnorrKeyPair, PublicKey } from '@did-btcr2/keypair';
4
+ import { KeyValueStore } from '@web5/common';
5
+
6
+ export type Btc1KeyManagerOptions = {
7
+ importKey?: boolean;
8
+ active?: boolean
9
+ };
10
+
11
+ /** Alias type for Btc1KeyManager keyUri */
12
+ export type KeyIdentifier = string;
13
+
14
+ /** Params for initializing a Btc1KeyManager class instance. */
15
+ export type KeyManagerParams = {
16
+ /**
17
+ * An optional property to specify a custom `KeyValueStore` instance for key management. If not
18
+ * provided, {@link Btc1KeyManager | `Btc1KeyManager`} uses a default `MemoryStore` instance.
19
+ * This store is responsible for managing cryptographic keys, allowing them to be retrieved,
20
+ * stored, and managed during cryptographic operations.
21
+ * @type {KeyValueStore<KeyIdentifier, KeyPair>}
22
+ */
23
+ store?: KeyValueStore<KeyIdentifier, SchnorrMultikey>;
24
+
25
+ /**
26
+ * An optional property to specify a key URI for the key manager. If not provided, the key manager
27
+ * will generate a key URI based on the public key of the key pair.
28
+ * @type {KeyIdentifier}
29
+ */
30
+ keyUri?: KeyIdentifier;
31
+
32
+ /**
33
+ * An optional property to specify the DID contoller id.
34
+ * @type {string}
35
+ */
36
+ id?: string;
37
+
38
+ /**
39
+ * An optional property to specify the DID controller.\
40
+ * @type {string}
41
+ */
42
+ controller?: string;
43
+
44
+ /**
45
+ * An optional property to pass in an initial key pair
46
+ * @type {SchnorrKeyPair}
47
+ */
48
+ keys?: SchnorrKeyPair;
49
+ };
50
+
51
+ export type GenerateKeyParams = {
52
+ id: string;
53
+ controller: string;
54
+ options: Btc1KeyManagerOptions
55
+ };
56
+
57
+ /**
58
+ * The interface for the Btc1KeyManager class.
59
+ * @interface KeyManager
60
+ * @type {KeyManager}
61
+ */
62
+ export interface KeyManager {
63
+ /**
64
+ * The URI of the active key.
65
+ * @type {KeyIdentifier}
66
+ */
67
+ activeKeyUri?: KeyIdentifier;
68
+
69
+ /**
70
+ * Exports the full key pair from the key store.
71
+ * @param {KeyIdentifier} keyUri The URI of the key to export.
72
+ * @returns {Promise<Multikey | undefined>} The key pair associated with the key URI.
73
+ * @throws {Btc1KeyManagerError} If the key is not found in the key store.
74
+ */
75
+ exportKey(keyUri?: KeyIdentifier): Promise<Multikey | undefined>;
76
+
77
+ /**
78
+ * Gets the public key of a key pair.
79
+ * @param {KeyIdentifier} keyUri The URI of the key to get the public key for.
80
+ * @returns {Promise<PublicKey>} The public key of the key pair.
81
+ */
82
+ getPublicKey(keyUri: KeyIdentifier): Promise<PublicKey>;
83
+
84
+ /**
85
+ * Imports a key pair into the key store.
86
+ * @param {SchnorrKeyPair} keyPair The key pair to import.
87
+ * @param {string} keyUri The full DID controller + fragment identifier (e.g. 'did:btcr2:xyz#key-1').
88
+ * @param {Btc1KeyManagerOptions} options The options for importing the key pair.
89
+ * @param {boolean} options.active Whether to set the imported key as active.
90
+ * @returns {Promise<KeyIdentifier>} A promise that resolves to the key identifier of the imported key.
91
+ */
92
+ importKey(keyPair: SchnorrKeyPair, keyUri: string, options: Btc1KeyManagerOptions): Promise<KeyIdentifier>;
93
+ }
94
+
95
+ export interface CryptoSigner {
96
+ /**
97
+ * Signs a message with a key pair.
98
+ * @param {Hex} data The data to sign.
99
+ * @param {?KeyIdentifier} keyUri The URI of the key to sign the data with.
100
+ * @returns {Promise<SignatureBytes>} The signature of the input data.
101
+ */
102
+ sign(data: Hex, keyUri?: KeyIdentifier): Promise<SignatureBytes>;
103
+
104
+ /**
105
+ * Verifies if a signature was produced by a key pair.
106
+ * @param {SignatureBytes} signature The signature to verify.
107
+ * @param {Hex} data The data that was signed.
108
+ * @param {?KeyIdentifier} keyUri The URI of the key to use for verification.
109
+ * @returns {Promise<boolean>} A promise that resolves if the signature is valid, and rejects otherwise.
110
+ */
111
+ verify(signature: SignatureBytes, data: Hex, keyUri?: KeyIdentifier): Promise<boolean>;
112
+
113
+ /**
114
+ * Returns the sha256 hash of the input data.
115
+ * @param {Uint8Array} data The data to hash.
116
+ * @returns {HashBytes} The sha256 hash of the input data.
117
+ */
118
+ digest(data: Uint8Array): HashBytes;
119
+ }
120
+
121
+ export interface BitcoinSigner {
122
+ /**
123
+ * Signs a Bitcoin transaction with a key pair.
124
+ * @param txHex The hex-encoded transaction to sign.
125
+ * @param keyUri The URI of the key to sign the transaction with.
126
+ * @returns {Promise<Hex>} A promise that resolves to the hex-encoded signed transaction.
127
+ */
128
+ signTransaction(txHex: Hex, keyUri?: KeyIdentifier): Promise<Hex>;
129
+ }
@@ -0,0 +1,6 @@
1
+ // canonicalize.d.ts
2
+ declare module 'canonicalize' {
3
+ const canonicalize: any;
4
+ export default canonicalize;
5
+ }
6
+
@@ -0,0 +1,288 @@
1
+ import {
2
+ Btcr2Error,
3
+ Btcr2IdentifierTypes,
4
+ INVALID_DID,
5
+ INVALID_DID_DOCUMENT,
6
+ METHOD_NOT_SUPPORTED,
7
+ PatchOperation,
8
+ W3C_DID_RESOLUTION_V1
9
+ } from '@did-btcr2/common';
10
+ import type {
11
+ DidResolutionResult,
12
+ DidVerificationMethod
13
+ } from '@web5/dids';
14
+ import {
15
+ Did,
16
+ DidError,
17
+ DidErrorCode,
18
+ DidMethod,
19
+ EMPTY_DID_RESOLUTION_RESULT
20
+ } from '@web5/dids';
21
+ import { initEccLib } from 'bitcoinjs-lib';
22
+ import * as tinysecp from 'tiny-secp256k1';
23
+ import { Btc1Create, Btc1CreateParams, Btc1CreateResponse } from './btcr2/crud/create.js';
24
+ import { Btc1Read } from './btcr2/crud/read.js';
25
+ import { Btc1Update } from './btcr2/crud/update.js';
26
+ import { DidResolutionOptions } from './interfaces/crud.js';
27
+ import { Btc1Appendix } from './utils/appendix.js';
28
+ import { Btc1DidDocument, Btc1VerificationMethod } from './utils/did-document.js';
29
+ import { Btc1Identifier } from './utils/identifier.js';
30
+
31
+ /** Initialize tiny secp256k1 */
32
+ initEccLib(tinysecp);
33
+
34
+ /**
35
+ * Implements {@link https://dcdpr.github.io/did-btcr2 | did:btcr2 DID Method Specification}.
36
+ * did:btcr2 is a censorship resistant DID Method using the Bitcoin blockchain as a Verifiable Data Registry to announce
37
+ * changes to the DID document. It improves on prior work by allowing: zero-cost off-chain DID creation; aggregated
38
+ * updates for scalable on-chain update costs; long-term identifiers that can support frequent updates; private
39
+ * communication of the DID document; private DID resolution; and non-repudiation appropriate for serious contracts.
40
+ *
41
+ * @class DidBtc1
42
+ * @type {DidBtc1}
43
+ *
44
+ */
45
+ export class DidBtc1 implements DidMethod {
46
+ /** @type {string} Name of the DID method, as defined in the DID BTCR2 specification */
47
+ public static methodName: string = 'btcr2';
48
+
49
+ /**
50
+ * Entry point for section {@link https://dcdpr.github.io/did-btcr2/#create | 4.1 Create}.
51
+ * See {@link Btc1Create} for implementation details.
52
+ *
53
+ * A did:btcr2 identifier and associated DID document can either be created deterministically from a cryptographic
54
+ * seed, or it can be created from an arbitrary genesis intermediate DID document representation. In both cases,
55
+ * DID creation can be undertaken in an offline manner, i.e., the DID controller does not need to interact with the
56
+ * Bitcoin network to create their DID.
57
+ * @param {Btc1CreateParams} params See {@link Btc1CreateParams} for details.
58
+ * @param {IdType} params.idType Type of identifier to create (key or external).
59
+ * @param {KeyBytes} params.pubKeyBytes Public key byte array used to create a btcr2 "key" identifier.
60
+ * @param {IntermediateDocument} params.intermediateDocument DID Document used to create a btcr2 "external" identifier.
61
+ * @param {DidCreateOptions} params.options See {@link DidCreateOptions} for create options.
62
+ * @param {number} params.options.version Version number of the btcr2 method.
63
+ * @param {string} params.options.network Bitcoin network name (mainnet, testnet, signet, regtest).
64
+ * @returns {Promise<CreateResponse>} Promise resolving to a CreateResponse object.
65
+ * @throws {DidBtc1Error} if any of the checks fail
66
+ */
67
+ public static async create(params: Btc1CreateParams): Promise<Btc1CreateResponse> {
68
+ // Deconstruct the idType and options from the params
69
+ const { idType, options = {} } = params;
70
+
71
+ // If idType is key, call Btc1Create.deterministic
72
+ if(idType === Btcr2IdentifierTypes.KEY) {
73
+ // Deconstruct the pubKeyBytes from the params
74
+ const { pubKeyBytes } = params;
75
+
76
+ // Return call to Btc1Create.deterministic
77
+ return Btc1Create.deterministic({ pubKeyBytes, options });
78
+ }
79
+
80
+ // If idType is external, call Btc1Create.external
81
+ if(idType === Btcr2IdentifierTypes.EXTERNAL) {
82
+ // Deconstruct the intermediateDocument from the params
83
+ const { intermediateDocument } = params;
84
+
85
+ // Return call to Btc1Create.external
86
+ return await Btc1Create.external({ intermediateDocument, options });
87
+ }
88
+
89
+ // Throw error if idType is not key or external
90
+ throw new Btcr2Error('Invalid idType: expected "KEY" or "EXTERNAL"', INVALID_DID, params);
91
+ }
92
+
93
+ /**
94
+ * Entry point for section {@link https://dcdpr.github.io/did-btcr2/#read | 7.2 Read}.
95
+ * See {@link Btc1Read} for implementation details.
96
+ *
97
+ * The Read operation is an algorithm consisting of a series of subroutine algorithms executed by a resolver after a
98
+ * resolution request identifying a specific did:btcr2 identifier is received from a client at Resolution Time. The
99
+ * request MUST always contain the resolutionOptions object containing additional information to be used in resolution.
100
+ * This object MAY be empty. See the DID Resolution specification for further details about the DID Resolution Options
101
+ * object. The resolver then attempts to resolve the DID document of the identifier at a specific Target Time. The
102
+ * Target Time is either provided in resolutionOptions or is set to the Resolution Time of the request.
103
+ *
104
+ * @param {string} identifier a valid did:btcr2 identifier to be resolved
105
+ * @param {DidResolutionOptions} [resolutionsOptions] see {@link https://www.w3.org/TR/did-1.0/#did-resolution-options | DidResolutionOptions}
106
+ * @param {number} options.versionId the version of the identifier and/or DID document
107
+ * @param {number} options.versionTime a timestamp used during resolution as a bound for when to stop resolving
108
+ * @param {Btc1DidDocument} options.sidecarData data necessary for resolving a DID
109
+ * @param {string} options.network Bitcoin network name (mainnet, testnet, signet, regtest).
110
+ * @returns {DidResolutionResult} Promise resolving to a DID Resolution Result containing the `targetDocument`
111
+ * @throws {Error} if the resolution fails for any reason
112
+ * @throws {DidError} InvalidDid if the identifier is invalid
113
+ * @example
114
+ * ```ts
115
+ * const resolution = await DidBtc1.resolve('did:btcr2:k1q0dygyp3gz969tp46dychzy4q78c2k3js68kvyr0shanzg67jnuez2cfplh')
116
+ * ```
117
+ */
118
+ public static async resolve(identifier: string, resolutionsOptions: DidResolutionOptions = {}): Promise<DidResolutionResult> {
119
+ try {
120
+ // 1. Pass identifier to the did:btcr2 Identifier Decoding algorithm, retrieving idType, version, network, and genesisBytes.
121
+ // 2. Set identifierComponents to a map of idType, version, network, and genesisBytes.
122
+ const identifierComponents = Btc1Identifier.decode(identifier);
123
+
124
+ // 3. Set initialDocument to the result of running the algorithm in Resolve Initial Document passing in the
125
+ // identifier, identifierComponents and resolutionOptions.
126
+ const initialDocument = await Btc1Read.initialDocument({ identifier, identifierComponents, resolutionsOptions });
127
+
128
+ // 4. Set targetDocument to the result of running the algorithm in Resolve Target Document passing in
129
+ // initialDocument and resolutionOptions.
130
+ const targetDocument = await Btc1Read.targetDocument({ initialDocument, resolutionsOptions });
131
+
132
+ // 5. Return targetDocument.
133
+ const didResolutionResult: DidResolutionResult = {
134
+ '@context' : W3C_DID_RESOLUTION_V1,
135
+ didResolutionMetadata : { contentType: 'application/ld+json' },
136
+ didDocumentMetadata : { created: new Date().getUTCDateTime() },
137
+ didDocument : targetDocument,
138
+ };
139
+
140
+ // Return didResolutionResult;
141
+ return didResolutionResult;
142
+ } catch (error: any) {
143
+ console.error(error);
144
+ // Rethrow any unexpected errors that are not a `DidError`.
145
+ if (!(error instanceof DidError)) throw new Error(error);
146
+
147
+ // Return a DID Resolution Result with the appropriate error code.
148
+ return {
149
+ ...EMPTY_DID_RESOLUTION_RESULT,
150
+ didResolutionMetadata : {
151
+ error : error.code,
152
+ ...error.message && { errorMessage: error.message }
153
+ }
154
+ };
155
+ }
156
+ }
157
+
158
+ /**
159
+ * Entry point for section {@link https://dcdpr.github.io/did-btcr2/#update | 4.3 Update}.
160
+ * See {@link Btc1Update} for implementation details.
161
+ *
162
+ * An update to a did:btcr2 document is an invoked capability using the ZCAP-LD data format, signed by a
163
+ * verificationMethod that has the authority to make the update as specified in the previous DID document. Capability
164
+ * invocations for updates MUST be authorized using Data Integrity following the bip340-jcs-2025
165
+ * cryptosuite with a proofPurpose of capabilityInvocation.
166
+ *
167
+ * The Update algorithm takes as inputs a btc1Identifier, sourceDocument, sourceVersionId, documentPatch, a
168
+ * verificationMethodId and an array of beaconIds. The sourceDocument is the DID document being updated. The
169
+ * documentPatch is a JSON Patch object containing a set of transformations to be applied to the sourceDocument.
170
+ * The result of these transformations MUST produce a DID document conformant to the DID Core specification. The
171
+ * verificationMethodId is an identifier for a verificationMethod within the sourceDocument. The verificationMethod
172
+ * identified MUST be a BIP340 Multikey. The beaconIds MUST identify service endpoints with one of the three Beacon
173
+ * Types SingletonBeacon, CIDAggregateBeacon, and SMTAggregateBeacon.
174
+ *
175
+ * @param {Btc1UpdateParams} params Required parameters for the update operation.
176
+ * @param {string} params.identifier The btcr2 identifier to be updated.
177
+ * @param {Btc1DidDocument} params.sourceDocument The DID document being updated.
178
+ * @param {string} params.sourceVersionId The versionId of the source document.
179
+ * @param {Btc1DocumentPatch} params.documentPatch The JSON patch to be applied to the source document.
180
+ * @param {string} params.verificationMethodId The verificationMethod ID to sign the update
181
+ * @param {string[]} params.beaconIds The beacon IDs to announce the update
182
+ * @returns {Promise<void>} Promise resolving to void
183
+ * @throws {Btcr2Error} if the verificationMethod type is not `Multikey` or the publicKeyMultibase header is not `zQ3s`
184
+ */
185
+ public static async update(params: {
186
+ identifier: string;
187
+ sourceDocument: Btc1DidDocument;
188
+ sourceVersionId: number;
189
+ patch: PatchOperation[];
190
+ verificationMethodId: string;
191
+ beaconIds: string[];
192
+ }): Promise<any> {
193
+ // Deconstruct the params
194
+ const {
195
+ identifier,
196
+ sourceDocument,
197
+ sourceVersionId,
198
+ patch,
199
+ verificationMethodId: methodId,
200
+ beaconIds,
201
+ } = params;
202
+
203
+ // 1. Set unsignedUpdate to the result of passing btc1Identifier, sourceDocument,
204
+ // sourceVersionId, and documentPatch into the Construct DID Update
205
+ // Payload algorithm.
206
+ const didUpdatePayload = await Btc1Update.construct({
207
+ identifier,
208
+ sourceDocument,
209
+ sourceVersionId,
210
+ patch,
211
+ });
212
+
213
+ // 2. Set verificationMethod to the result of retrieving the verificationMethod
214
+ // from sourceDocument using the verificationMethodId.
215
+ const verificationMethod = this.getSigningMethod({ didDocument: sourceDocument, methodId, });
216
+
217
+ // Validate the verificationMethod exists in the sourceDocument
218
+ if (!verificationMethod) {
219
+ throw new Btcr2Error('Verification method not found in did document', INVALID_DID_DOCUMENT, sourceDocument);
220
+ }
221
+
222
+ // 3. Validate the verificationMethod is a BIP340 Multikey:
223
+ // 3.1 verificationMethod.type == Multikey
224
+ if (verificationMethod.type !== 'Multikey') {
225
+ throw new Btcr2Error('Invalid type: must be type "Multikey"', INVALID_DID_DOCUMENT, verificationMethod);
226
+ }
227
+
228
+ // 3.2 verificationMethod.publicKeyMultibase[4] == zQ3s
229
+ const mbasePrefix = verificationMethod.publicKeyMultibase?.slice(0, 4);
230
+ if (mbasePrefix !== 'zQ3s') {
231
+ throw new Btcr2Error(`Invalid publicKeyMultibase prefix ${mbasePrefix}`, INVALID_DID_DOCUMENT, verificationMethod);
232
+ }
233
+
234
+ // 4. Set didUpdateInvocation to the result of passing btc1Identifier, unsignedUpdate as didUpdatePayload, and
235
+ // verificationMethod to the Invoke DID Update Payload algorithm.
236
+ const didUpdateInvocation = await Btc1Update.invoke({ identifier, verificationMethod, didUpdatePayload, });
237
+
238
+ // 5. Set signalsMetadata to the result of passing btc1Identifier, sourceDocument, beaconIds and didUpdateInvocation
239
+ // to the Announce DID Update algorithm.
240
+ const signalsMetadata = await Btc1Update.announce({ sourceDocument, beaconIds, didUpdateInvocation, });
241
+
242
+ // 6. Return signalsMetadata. It is up to implementations to ensure that the signalsMetadata is persisted.
243
+ return signalsMetadata;
244
+ // TODO: Should we be applying the patch, producing a target did document and returning it?
245
+ }
246
+
247
+ /**
248
+ * Given the W3C DID Document of a `did:btcr2` identifier, return the signing verification method that will be used
249
+ * for signing messages and credentials. If given, the `methodId` parameter is used to select the
250
+ * verification method. If not given, the Identity Key's verification method with an ID fragment
251
+ * of '#initialKey' is used.
252
+ *
253
+ * @param {{ didDocument: Btc1DidDocument; methodId?: string; }} params Parameters for the `getSigningMethod` method.
254
+ * @param {DidDocument} params.didDocument DID Document to get the verification method from.
255
+ * @param {string} params.methodId Optional ID of the verification method to use for signing.
256
+ * @returns {Btc1VerificationMethod} Promise resolving to the {@link Btc1VerificationMethod} object used for signing.
257
+ * @throws {DidError} if the parsed did method does not match `btcr2` or signing method could not be determined.
258
+ */
259
+ public static getSigningMethod({ didDocument, methodId }: {
260
+ didDocument: Btc1DidDocument;
261
+ methodId?: string;
262
+ }): Btc1VerificationMethod {
263
+ // Set the default methodId to the first assertionMethod if not given
264
+ methodId ??= '#initialKey';
265
+
266
+ // Verify the DID method is supported.
267
+ const parsedDid = Did.parse(didDocument.id);
268
+ if (parsedDid && parsedDid.method !== this.methodName) {
269
+ throw new Btcr2Error(`Method not supported: ${parsedDid.method}`, METHOD_NOT_SUPPORTED, { identifier: didDocument.id });
270
+ }
271
+
272
+ // Attempt to find a verification method that matches the given method ID, or if not given,
273
+ // find the first verification method intended for signing claims.
274
+ const verificationMethod = didDocument.verificationMethod?.find(
275
+ (vm: DidVerificationMethod) => Btc1Appendix.extractDidFragment(vm.id) === (Btc1Appendix.extractDidFragment(methodId)
276
+ ?? Btc1Appendix.extractDidFragment(didDocument.assertionMethod?.[0]))
277
+ );
278
+
279
+ // If no verification method is found, throw an error
280
+ if (!(verificationMethod && verificationMethod.publicKeyMultibase)) {
281
+ throw new DidError(
282
+ DidErrorCode.InternalError,
283
+ 'A verification method intended for signing could not be determined from the DID Document'
284
+ );
285
+ }
286
+ return verificationMethod as Btc1VerificationMethod;
287
+ }
288
+ }
package/src/index.ts ADDED
@@ -0,0 +1,34 @@
1
+
2
+ export * from './bitcoin/constants.js';
3
+ export * from './bitcoin/interface.js';
4
+ export * from './bitcoin/network.js';
5
+ export * from './bitcoin/rpc-client.js';
6
+
7
+ export * from './btcr2/beacon/cid-aggregate.js';
8
+ export * from './btcr2/beacon/factory.js';
9
+ export * from './btcr2/beacon/singleton.js';
10
+ export * from './btcr2/beacon/smt-aggregate.js';
11
+
12
+ export * from './btcr2/crud/create.js';
13
+ export * from './btcr2/crud/deactivate.js';
14
+ export * from './btcr2/crud/read.js';
15
+ export * from './btcr2/crud/update.js';
16
+
17
+ export * from './btcr2/key-manager/index.js';
18
+ export * from './btcr2/key-manager/interface.js';
19
+
20
+ export * from './interfaces/beacon.js';
21
+ export * from './interfaces/crud.js';
22
+ export * from './interfaces/ibeacon.js';
23
+
24
+ export * from './types/bitcoin.js';
25
+ export * from './types/crud.js';
26
+
27
+ export * from './utils/appendix.js';
28
+ export * from './utils/beacons.js';
29
+ export * from './utils/did-document-builder.js';
30
+ export * from './utils/did-document.js';
31
+ export * from './utils/general.js';
32
+ export * from './utils/identifier.js';
33
+
34
+ export * from './did-btcr2.js';
@@ -0,0 +1,68 @@
1
+ import { DidUpdatePayload } from '@did-btcr2/common';
2
+ import { DidServiceEndpoint } from '@web5/dids';
3
+ import { RawTransactionRest } from '../bitcoin/rest-client.js';
4
+ import { RawTransactionV2 } from '../types/bitcoin.js';
5
+ import { SidecarData, SignalsMetadata } from '../types/crud.js';
6
+ import { BeaconService, BeaconSignal, IBeacon } from './ibeacon.js';
7
+
8
+ /**
9
+ * Implements {@link https://dcdpr.github.io/did-btcr2/#update-beacons | 5. Beacons}.
10
+ * Beacons are the mechanism by which a DID controller announces an update to their DID document by broadcasting an
11
+ * attestation to this update onto the public Bitcoin network. Beacons are identified by a Bitcoin address and emit
12
+ * Beacon Signals by broadcasting a valid Bitcoin transaction that spends from this Beacon address. These transactions
13
+ * include attestations to a set of didUpdatePayloads, either in the form of Content Identifiers (CIDs) or Sparse Merkle
14
+ * Tree (SMT) roots. Beacons are included as a service in DID documents, with the Service Endpoint identifying a Bitcoin
15
+ * address to watch for Beacon Signals. All Beacon Signals broadcast from this Beacon MUST be processed as part of
16
+ * resolution (see Read). The type of the Beacon service in the DID document defines how Beacon Signals SHOULD be
17
+ * processed.
18
+ * did:btcr2 supports different Beacon Types, with each type defining a set of algorithms for:
19
+ * 1. How a Beacon can be established and added as a service to a DID document.
20
+ * 2. How attestations to DID updates are broadcast within Beacon Signals.
21
+ * 3. How a resolver processes a Beacon Signal, identifying, verifying, and applying the authorized mutations to a
22
+ * DID document for a specific DID.
23
+ * This is an extendable mechanism, such that in the future new Beacon Types could be added. It would be up to the
24
+ * resolver to determine if the Beacon Type is a mechanism they support and are willing to trust. If they are unable to
25
+ * support a Beacon Type and a DID they are resolving uses that type then the DID MUST be treated as invalid.
26
+ * The current, active Beacons of a DID document are specified in the document’s service property. By updating the DID
27
+ * document, a DID controller can change the set of Beacons they can use to broadcast updates to their DID document over
28
+ * time. Resolution of a DID MUST process signals from all Beacons identified in the latest DID document and apply them
29
+ * in order determined by the version specified by the didUpdatePayload.
30
+ * All resolvers of did:btcr2 DIDs MUST support the core Beacon Types defined in this specification.
31
+ *
32
+ * @abstract
33
+ * @class Beacon
34
+ * @type {Beacon}
35
+ */
36
+ export abstract class Beacon implements IBeacon {
37
+ public id: string;
38
+ public type: string;
39
+ public serviceEndpoint: DidServiceEndpoint;
40
+ public sidecar?: SidecarData;
41
+
42
+ constructor({ id, type, serviceEndpoint }: BeaconService, sidecar?: SidecarData) {
43
+ this.id = id;
44
+ this.type = type;
45
+ this.serviceEndpoint = serviceEndpoint;
46
+ this.sidecar = sidecar;
47
+ }
48
+
49
+ /**
50
+ * Returns the Beacon Service object.
51
+ */
52
+ abstract get service(): BeaconService;
53
+
54
+ /**
55
+ * Generates a Beacon Signal (implemented by subclasses).
56
+ */
57
+ abstract generateSignal(didUpdatePayload: string): BeaconSignal;
58
+
59
+ /**
60
+ * Processes a Beacon Signal (implemented by subclasses).
61
+ */
62
+ abstract processSignal(signal: RawTransactionRest | RawTransactionV2, signalsMetadata: SignalsMetadata): Promise<DidUpdatePayload | undefined>
63
+
64
+ /**
65
+ * Broadcasts a Beacon Signal (implemented by subclasses).
66
+ */
67
+ abstract broadcastSignal(didUpdatePayload: DidUpdatePayload): Promise<SignalsMetadata>;
68
+ }
@@ -0,0 +1,36 @@
1
+ import { BitcoinNetworkNames, UnixTimestamp } from '@did-btcr2/common';
2
+ import { DidResolutionOptions as IDidResolutionOptions } from '@web5/dids';
3
+ import BitcoinRpc from '../bitcoin/rpc-client.js';
4
+ import { SidecarData } from '../types/crud.js';
5
+ import { Btc1DidDocument } from '../utils/did-document.js';
6
+
7
+ /**
8
+ * Options for resolving a DID Document
9
+ * @param {?number} versionId The versionId for resolving the DID Document
10
+ * @param {?UnixTimestamp} versionTime The versionTime for resolving the DID Document
11
+ * @param {?BitcoinRpc} rpc BitcoinRpc client connection
12
+ * @param {?SidecarData} sidecarData The sidecar data for resolving the DID Document
13
+ */
14
+ export interface DidResolutionOptions extends IDidResolutionOptions {
15
+ versionId?: number
16
+ versionTime?: UnixTimestamp;
17
+ sidecarData?: SidecarData;
18
+ network?: BitcoinNetworkNames;
19
+ rpc?: BitcoinRpc;
20
+ }
21
+ export interface Btc1RootCapability {
22
+ '@context': string;
23
+ id: string;
24
+ controller: string;
25
+ invocationTarget: string;
26
+ }
27
+ export interface ReadBlockchainParams {
28
+ contemporaryDidDocument: Btc1DidDocument;
29
+ contemporaryBlockHeight: number | 1;
30
+ currentVersionId: number | 1;
31
+ targetVersionId?: number;
32
+ targetBlockHeight: number;
33
+ updateHashHistory: string[];
34
+ sidecarData?: SidecarData;
35
+ options?: DidResolutionOptions;
36
+ }
@@ -0,0 +1,76 @@
1
+ import { DidUpdatePayload, UnixTimestamp } from '@did-btcr2/common';
2
+ import { DidServiceEndpoint, DidService as IDidService } from '@web5/dids';
3
+ import { RawTransactionV2 } from '../types/bitcoin.js';
4
+ import { SignalsMetadata } from '../types/crud.js';
5
+ import { RawTransactionRest } from '../bitcoin/rest-client.js';
6
+
7
+ /**
8
+ * Beacon interface
9
+ * @interface IBeacon
10
+ * @type {IBeacon}
11
+ */
12
+ export interface IBeacon {
13
+ /**
14
+ * A unique identifier for the Beacon
15
+ * @type {string}
16
+ */
17
+ id: string;
18
+
19
+ /**
20
+ * The type of the Beacon
21
+ * @type {string}
22
+ */
23
+ type: string;
24
+
25
+ /**
26
+ * The service endpoint of the Beacon
27
+ * @type {string}
28
+ */
29
+ serviceEndpoint: DidServiceEndpoint;
30
+
31
+ /**
32
+ * Returns the Beacon Service object
33
+ * @type {BeaconService}
34
+ */
35
+ service: BeaconService;
36
+
37
+ /**
38
+ * Generates a Beacon Signal Transaction
39
+ * @param {string} didUpdatePayload The DID update payload
40
+ * @returns {BeaconSignal} The Beacon Signal
41
+ */
42
+ generateSignal(didUpdatePayload: string): BeaconSignal;
43
+
44
+ /**
45
+ * Processes a Beacon Signal.
46
+ * @param {RawTransactionV2} signal The raw transaction
47
+ * @param {SidecarData} signalsMetadata The signals metadata from the sidecar data
48
+ * @returns {Promise<DidUpdatePayload | undefined>} The DID update payload
49
+ */
50
+ processSignal(signal: RawTransactionV2, signalsMetadata: SignalsMetadata): Promise<DidUpdatePayload | undefined>;
51
+
52
+
53
+ /**
54
+ * Broadcasts a signal.
55
+ * @param {DidUpdatePayload} didUpdatePayload The DID update payload.
56
+ * @returns {Promise<SignalMetadata>} The signal metadata.
57
+ */
58
+ broadcastSignal(didUpdatePayload: DidUpdatePayload): Promise<SignalsMetadata>;
59
+ }
60
+
61
+ export interface BeaconService extends IDidService {
62
+ serviceEndpoint: DidServiceEndpoint;
63
+ casType?: string;
64
+ }
65
+
66
+ export interface BeaconServiceAddress extends BeaconService {
67
+ address: string;
68
+ }
69
+ export interface BeaconSignal {
70
+ beaconId: string;
71
+ beaconType: string;
72
+ beaconAddress: string;
73
+ tx: RawTransactionRest | RawTransactionV2;
74
+ blockheight: number;
75
+ blocktime: UnixTimestamp;
76
+ }