@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,888 @@
1
+ import { default as RpcClient } from 'bitcoin-core';
2
+ import {
3
+ AddMultiSigAddressParams,
4
+ BatchOption,
5
+ BitcoinSignature,
6
+ BlockHashOptions,
7
+ BlockHeader,
8
+ BlockResponse,
9
+ BlockV0,
10
+ BlockV1,
11
+ BlockV2,
12
+ BlockV3,
13
+ BumpFeeOptions,
14
+ BumpFeeResult,
15
+ ChainInfo,
16
+ CreateMultisigParams,
17
+ CreateMultiSigResult,
18
+ CreateRawTxInputs,
19
+ CreateRawTxOutputs,
20
+ CreateWalletDescriptorOptions,
21
+ CreateWalletDescriptorsResult,
22
+ CreateWalletParams,
23
+ CreateWalletResult,
24
+ DecodedRawTransaction,
25
+ DerivedAddresses,
26
+ FeeEstimateMode,
27
+ FundRawTxOptions,
28
+ FundRawTxResult,
29
+ GetBlockParams,
30
+ GetUTXOsResult,
31
+ IClientConfig,
32
+ ImportDescriptorRequest,
33
+ ImportMultiOptions,
34
+ ImportMultiRequest,
35
+ ImportMultiResult,
36
+ ListTransactionsParams,
37
+ ListTransactionsResult,
38
+ ListUnspentParams,
39
+ MemoryStats,
40
+ MempoolContent,
41
+ MempoolInfo,
42
+ MethodNameInLowerCase,
43
+ MiningInfo,
44
+ Outpoint,
45
+ PeerInfo,
46
+ RawTransactionResponse,
47
+ RawTransactionV0,
48
+ RawTransactionV1,
49
+ RawTransactionV2,
50
+ ReturnFormatOptions,
51
+ RpcClientConfig,
52
+ ScanBlocksParams,
53
+ ScriptDecoded,
54
+ SendAllParams,
55
+ SendAllResult,
56
+ SendManyParams,
57
+ SignedRawTx,
58
+ UnspentTxInfo,
59
+ ValidateAddressResult,
60
+ VerbosityLevel,
61
+ WalletTransaction
62
+ } from '../types/bitcoin.js';
63
+ import { DEFAULT_RPC_CLIENT_CONFIG } from './constants.js';
64
+ import { BitcoinRpcError } from './errors.js';
65
+ import { IBitcoinRpc } from './interface.js';
66
+
67
+ /**
68
+ * Encapsulates a {@link RpcClient | Client} object from {@link https://www.npmjs.com/package/bitcoin-core | `bitcoin-core`}.
69
+ * Implements a strongly-typed {@link IBitcoinRpc | IBitcoinRpc interface} for added expresivity and developer support.
70
+ * @class BitcoinRpc
71
+ * @type {BitcoinRpc}
72
+ */
73
+ export default class BitcoinRpc implements IBitcoinRpc {
74
+ /**
75
+ * The encapsulated {@link RpcClientConfig} object.
76
+ * @private
77
+ * @type {RpcClient} An instance of the Client class from {@link https://www.npmjs.com/package/bitcoin-core | `bitcoin-core`}.
78
+ * See {@link https://github.com/ruimarinho/bitcoin-core/blob/master/src/index.d.ts#L64 | `Client`} for more information.
79
+ */
80
+ private _client: RpcClient;
81
+
82
+ /**
83
+ * The encapsulated {@link RpcClientConfig} object.
84
+ * @private
85
+ * @type {RpcClientConfig} ClientConfig from {@link https://www.npmjs.com/package/bitcoin-core | `bitcoin-core`}.
86
+ * See {@link https://github.com/ruimarinho/bitcoin-core/blob/master/src/index.d.ts#L39 | `ClientConfig`} for more information.
87
+ */
88
+ private _config: RpcClientConfig;
89
+
90
+ /**
91
+ * Constructs a new {@link BitcoinRpc} instance from a new {@link RpcClient | RpcClient}.
92
+ * @param {RpcClientConfig} config The bitcoin-core client instance.
93
+ * @example
94
+ * ```
95
+ * import BitcoinRpc from '@did-btcr2/method';
96
+ * const bob = BitcoinRpc.connect(); // To use default polar config, pass no args. Polar must run locally.
97
+ * ```
98
+ */
99
+ constructor(config: RpcClientConfig) {
100
+ this._config = new RpcClientConfig(config);
101
+ this._client = new RpcClient(this._config);
102
+ }
103
+
104
+ /**
105
+ * Get the config for the current BitcoinRpc object.
106
+ * @returns {RpcClientConfig} The encapsulated {@link RpcClientConfig} object.
107
+ * @example
108
+ * ```
109
+ * import BitcoinRpc from '@did-btcr2/method';
110
+ * const alice = BitcoinRpc.connect();
111
+ * const config = alice.config;
112
+ * ```
113
+ */
114
+ get config(): RpcClientConfig {
115
+ const config = this._config;
116
+ return config;
117
+ }
118
+
119
+ /**
120
+ * Get the client for the current BitcoinRpc object.
121
+ * @returns {RpcClient} The encapsulated {@link RpcClient} object.
122
+ * @example
123
+ * ```
124
+ * const alice = BitcoinRpc.connect();
125
+ * const config = alice.client;
126
+ * ```
127
+ */
128
+ get client(): RpcClient {
129
+ const client = this._client;
130
+ return client;
131
+ }
132
+
133
+ /**
134
+ * Static method initializes a new BitcoinRpc client with the given configuration.
135
+ * The RpcClient returned by this method does not have any named methods.
136
+ * Use this method to create and pass a new RpcClient instance to a BitcoinRpc constructor.
137
+ *
138
+ * @param {IClientConfig} config The configuration object for the client (optional).
139
+ * @returns {RpcClient} A new RpcClient instance.
140
+ * @example
141
+ * ```
142
+ * const options: IClientConfig = {
143
+ * host: 'http://localhost:18443',
144
+ * username: 'alice',
145
+ * password: 'alicepass',
146
+ * version: '28.1.0',
147
+ * }
148
+ * const aliceClient = BitcoinRpc.initialize(options); // Client config required
149
+ * const alice = new BitcoinRpc(aliceClient);
150
+ * ```
151
+ */
152
+ public static initialize(config?: IClientConfig): RpcClient {
153
+ const rpcConfig = RpcClientConfig.initialize(config);
154
+ return new RpcClient(rpcConfig);
155
+ }
156
+
157
+ /**
158
+ * Static method connects to a bitcoin node running the bitcoin core daemon (bitcoind).
159
+ * To use default polar config, do not pass a config. See {@link DEFAULT_RPC_CLIENT_CONFIG} for default config.
160
+ * @required A locally running {@link https://github.com/jamaljsr/polar | Polar Lightning} regtest node.
161
+ *
162
+ * @param {?RpcClientConfig} config The configuration object for the client (optional).
163
+ * @returns A new {@link BitcoinRpc} instance.
164
+ * @example
165
+ * ```
166
+ * const alice = BitcoinRpc.connect();
167
+ * ```
168
+ */
169
+ public static connect(config?: RpcClientConfig): BitcoinRpc {
170
+ const client = this.initialize(config ?? DEFAULT_RPC_CLIENT_CONFIG);
171
+ return new BitcoinRpc(client);
172
+ }
173
+
174
+ /**
175
+ * Check if the given error is a JSON-RPC error.
176
+ * @param {unknown} e The error to check.
177
+ * @returns {boolean} True if the error is a JSON-RPC error, false otherwise.
178
+ */
179
+ public isJsonRpcError(e: unknown): e is Error & { name: 'RpcError'; code?: number } {
180
+ return (
181
+ e instanceof Error &&
182
+ e.name === 'RpcError' &&
183
+ typeof (e as any).code === 'number'
184
+ );
185
+ }
186
+
187
+ /**
188
+ * Executes a JSON-RPC command on the bitcoind node.
189
+ * @param {MethodNameInLowerCase} method The name of the method to call.
190
+ * @param {Array<any>} parameters The parameters to pass to the method.
191
+ * @returns {Promise<T>} A promise resolving to the result of the command.
192
+ */
193
+ private async executeRpc<T>(method: MethodNameInLowerCase, parameters: Array<any> = []): Promise<T> {
194
+ try {
195
+ // raw call
196
+ const raw = await this.client.command(
197
+ [{ method, parameters }] as BatchOption[]
198
+ );
199
+ // normalization/unwrapping, if needed
200
+ const normalized = JSON.unprototyped(raw) ? JSON.normalize(raw) : raw;
201
+ const result = Array.isArray(normalized)
202
+ ? normalized[normalized.length - 1]
203
+ : normalized;
204
+ return result as T;
205
+ } catch (err: unknown) {
206
+ this.handleError(err, method, parameters);
207
+ }
208
+ }
209
+
210
+ /**
211
+ * Handle errors that occur while executing commands.
212
+ * @param methods An array of {@link BatchOption} objects.
213
+ * @param error The error that was thrown.
214
+ * @throws Throws a {@link BitcoinRpcError} with the error message.
215
+ */
216
+ private handleError(err: unknown, method: string, params: any[]): never {
217
+ if (this.isJsonRpcError(err)) {
218
+ // a bitcoind JSON‑RPC error
219
+ throw new BitcoinRpcError(
220
+ err.code!,
221
+ `RPC ${method} failed: ${err.message}`,
222
+ { method, params }
223
+ );
224
+ }
225
+
226
+ if (err instanceof Error) {
227
+ // network, HTTP, or unexpected client error
228
+ throw new BitcoinRpcError(
229
+ 'NETWORK_ERROR',
230
+ `Network error in ${method}: ${err.message}`,
231
+ { method, params, original: err }
232
+ );
233
+ }
234
+
235
+ // absolutely unknown
236
+ throw new BitcoinRpcError(
237
+ 'UNKNOWN_ERROR',
238
+ `Unknown failure in ${method}`,
239
+ { method, params, err }
240
+ );
241
+ }
242
+
243
+ /**
244
+ * TODO: Comments
245
+ */
246
+ public async getUnspentTransactionOutputs(outpoints: Outpoint[]): Promise<GetUTXOsResult> {
247
+ return this.client.getUnspentTransactionOutputs(outpoints);
248
+ }
249
+
250
+ /**
251
+ * TODO: Comments
252
+ */
253
+ public async getTransactionByHash(hash: string, options?: ReturnFormatOptions): Promise<string> {
254
+ return this.client.getTransactionByHash(hash, options);
255
+ }
256
+
257
+ /**
258
+ * TODO: Comments
259
+ */
260
+ public async getBlockHeadersByHash(hash: string, count: number, options?: ReturnFormatOptions): Promise<BlockHeader[]> {
261
+ return this.client.getBlockHeadersByHash(hash, count, options);
262
+ }
263
+
264
+ /**
265
+ * TODO: Comments
266
+ */
267
+ public async getMemoryPoolContent(): Promise<MempoolContent> {
268
+ return this.client.getMemoryPoolContent();
269
+ }
270
+
271
+ /**
272
+ * TODO: Comments
273
+ */
274
+ public async getMemoryPoolInformation(): Promise<MempoolInfo> {
275
+ return this.client.getMemoryPoolInformation();
276
+ }
277
+
278
+ /**
279
+ * Alias for `getblock <hash> 2`
280
+ */
281
+ public async getBlockByHash(hash: string, options?: BlockHashOptions): Promise<BlockHeader> {
282
+ return this.client.getBlockByHash(hash, options);
283
+ }
284
+
285
+ /**
286
+ * TODO: Comments
287
+ */
288
+ public async abandonTransaction(txid: string): Promise<void> {
289
+ return await this.executeRpc('abandontransaction', [txid]);
290
+ }
291
+
292
+ /**
293
+ * TODO: Comments
294
+ */
295
+ public async abortRescan(): Promise<void> {
296
+ return await this.executeRpc('abortrescan');
297
+ }
298
+
299
+ /**
300
+ * TODO: Comments
301
+ */
302
+ public async addMultiSigAddress(params: AddMultiSigAddressParams): Promise<string> {
303
+ return await this.executeRpc('addmultisigaddress', [params]);
304
+ }
305
+
306
+ /**
307
+ * TODO: Comments
308
+ */
309
+ public async addWitnessAddress(address: string): Promise<void> {
310
+ return await this.executeRpc('addwitnessaddress', [address]);
311
+ }
312
+
313
+ /**
314
+ * TODO: Comments
315
+ */
316
+ public async backupWallet(destination: string): Promise<void> {
317
+ return await this.executeRpc('backupwallet', [destination]);
318
+ }
319
+
320
+ /**
321
+ * TODO: Comments
322
+ */
323
+ public async bumpFee(txid: string, options?: BumpFeeOptions): Promise<BumpFeeResult> {
324
+ return await this.executeRpc('bumpfee', [txid, options]);
325
+ }
326
+
327
+ /**
328
+ * TODO: Comments
329
+ */
330
+ public async createMultiSig(nrequired: number, keys: string[]): Promise<CreateMultiSigResult> {
331
+ return await this.executeRpc('createmultisig', [nrequired, keys]);
332
+ }
333
+
334
+ /**
335
+ * TODO: Comments
336
+ */
337
+ public async createWallet(params: CreateWalletParams): Promise<CreateWalletResult> {
338
+ return await this.executeRpc('createwallet', [params]);
339
+ }
340
+
341
+ /**
342
+ * TODO: Comments
343
+ */
344
+ public async decodeScript(hexstring: string): Promise<ScriptDecoded> {
345
+ return await this.executeRpc('decodescript', [hexstring]);
346
+ }
347
+
348
+ /**
349
+ * TODO: Comments
350
+ */
351
+ public async getBestBlockHash(): Promise<string> {
352
+ return await this.executeRpc('getbestblockhash', []);
353
+ }
354
+
355
+ /**
356
+ * Returns the block data associated with a `blockhash` of a valid block.
357
+ * @param {GetBlockParams} params See {@link GetBlockParams} for details.
358
+ * @param {?string} params.blockhash The blockhash of the block to query.
359
+ * @param {?number} params.height The block height of the block to query.
360
+ * @param {?VerbosityLevel} params.verbosity The verbosity level. See {@link VerbosityLevel}.
361
+ * @returns {BlockResponse} A promise resolving to a {@link BlockResponse} formatted depending on `verbosity` level.
362
+ * @throws {BitcoinRpcError} If neither `blockhash` nor `height` is provided.
363
+ */
364
+ public async getBlock({ blockhash, height, verbosity }: GetBlockParams): Promise<BlockResponse | undefined> {
365
+ // Check if blockhash or height is provided, if neither throw an error
366
+ if(!blockhash && height === undefined) {
367
+ throw new BitcoinRpcError('blockhash or height required', 'INVALID_PARAMS_GET_BLOCK', { blockhash, height });
368
+ }
369
+
370
+ // If height is provided, get the blockhash
371
+ blockhash ??= await this.getBlockHash(height!);
372
+ if(!blockhash || typeof blockhash !== 'string') {
373
+ return undefined;
374
+ }
375
+ // Get the block data
376
+ const block = await this.executeRpc('getblock', [blockhash, verbosity ?? 3]);
377
+
378
+ // Return the block data depending on verbosity level
379
+ switch(verbosity) {
380
+ case 0:
381
+ return block as BlockV0;
382
+ case 1:
383
+ return block as BlockV1;
384
+ case 2:
385
+ return block as BlockV2;
386
+ case 3:
387
+ return block as BlockV3;
388
+ default:
389
+ return block as BlockV3;
390
+ }
391
+ }
392
+
393
+ /**
394
+ * Returns the blockheight of the most-work fully-validated chain. The genesis block has height 0.
395
+ * @returns {Blockheight} The number of the blockheight with the most-work of the fully-validated chain.
396
+ */
397
+ public async getBlockCount(): Promise<number> {
398
+ return await this.executeRpc('getblockcount');
399
+ }
400
+
401
+ /**
402
+ * Returns the blockhash of the block at the given height in the active chain.
403
+ */
404
+ public async getBlockHash(height: number): Promise<string> {
405
+ return await this.executeRpc('getblockhash', [height]);
406
+ }
407
+
408
+ /**
409
+ * TODO: Comments
410
+ */
411
+ public async getBlockHeader(hash: string, verbose?: boolean): Promise<string | BlockHeader> {
412
+ return await this.executeRpc('getblockheader', [hash, verbose]);
413
+ }
414
+
415
+ /**
416
+ * TODO: Comments
417
+ */
418
+ public async getBlockchainInfo(): Promise<ChainInfo> {
419
+ return this.client.getBlockchainInformation();
420
+ }
421
+
422
+ /**
423
+ * TODO: Comments
424
+ */
425
+ public async getInfo(...args: any[]): Promise<void> {
426
+ return await this.executeRpc('getinfo', [...args]);
427
+ }
428
+
429
+ /**
430
+ * TODO: Comments
431
+ */
432
+ public async getMemoryInfo(mode?: 'stats' | 'mallocinfo'): Promise<MemoryStats | string> {
433
+ return await this.executeRpc('getmemoryinfo', [mode]);
434
+ }
435
+
436
+ /**
437
+ * TODO: Comments
438
+ */
439
+ public async scanBlocks(params: ScanBlocksParams): Promise<any> {
440
+ return await this.executeRpc('scanblocks', [params]);
441
+ }
442
+
443
+ /**
444
+ * TODO: Comments
445
+ */
446
+ public async fundRawTransaction(hexstring: string, options: FundRawTxOptions): Promise<FundRawTxResult> {
447
+ return await this.executeRpc('fundrawtransaction', [hexstring, options]);
448
+ }
449
+
450
+ /**
451
+ * Sign inputs for raw transaction (serialized, hex-encoded).
452
+ * The second optional argument (may be null) is an array of previous transaction outputs that
453
+ * this transaction depends on but may not yet be in the block chain.
454
+ * Requires wallet passphrase to be set with walletpassphrase call if wallet is encrypted.
455
+ * @param {string} hexstring The hex-encoded transaction to send.
456
+ */
457
+ public async signRawTransaction(hexstring: string): Promise<SignedRawTx> {
458
+ return await this.executeRpc<SignedRawTx>('signrawtransactionwithwallet', [hexstring]);
459
+ }
460
+
461
+ /**
462
+ * Submit a raw transaction (serialized, hex-encoded) to local node and network.
463
+ *
464
+ * The transaction will be sent unconditionally to all peers, so using sendrawtransaction
465
+ * for manual rebroadcast may degrade privacy by leaking the transaction's origin, as
466
+ * nodes will normally not rebroadcast non-wallet transactions already in their mempool.
467
+ *
468
+ * @param {string} hexstring The hex-encoded transaction to send.
469
+ * @param {numbner} [maxfeerate] If not passed, default is 0.10.
470
+ * @returns {Promise<string>} A promise resolving to the transaction hash in hex.
471
+ */
472
+ public async sendRawTransaction(
473
+ hexstring: string,
474
+ maxfeerate?: number | string,
475
+ maxBurnAmount?: number | string
476
+ ): Promise<string> {
477
+ console.log('sendRawTransaction', { hexstring, maxfeerate, maxBurnAmount });
478
+ return await this.executeRpc<string>('sendrawtransaction', [hexstring, maxfeerate ?? 0.10, maxBurnAmount ?? 0.00]);
479
+ }
480
+
481
+ /**
482
+ * Combines calls to `signRawTransaction` and `sendRawTransaction`.
483
+ * @param {string} params.hexstring The hex-encoded transaction to send.
484
+ * @returns {Promise<string>} A promise resolving to the transaction hash in hex.
485
+ */
486
+ public async signAndSendRawTransaction(hexstring: string): Promise<string> {
487
+ const signedRawTx = await this.signRawTransaction(hexstring,);
488
+ return await this.sendRawTransaction(signedRawTx.hex);
489
+ }
490
+
491
+ /**
492
+ * Combines calls to `createRawTransaction`, `signRawTransaction` and `sendRawTransaction`.
493
+ * @param {CreateRawTxInputs[]} inputs The inputs to the transaction (required).
494
+ * @param {CreateRawTxOutputs[]} outputs The outputs of the transaction (required).
495
+ * @returns {Promise<string>} A promise resolving to the transaction hash in hex.
496
+ */
497
+ public async createSignSendRawTransaction(inputs: CreateRawTxInputs[], outputs: CreateRawTxOutputs[]): Promise<string> {
498
+ const rawTx = await this.createRawTransaction(inputs, outputs);
499
+ const signedRawTx = await this.signRawTransaction(rawTx);
500
+ const sentRawTx = await this.sendRawTransaction(signedRawTx.hex);
501
+ return sentRawTx;
502
+ }
503
+
504
+ /**
505
+ * TODO: Comments
506
+ */
507
+ public async listTransactions(params: ListTransactionsParams): Promise<ListTransactionsResult> {
508
+ return await this.executeRpc('listtransactions', [params]);
509
+ }
510
+
511
+ /**
512
+ * TODO: Comments
513
+ */
514
+ public async decodeRawTransaction(hexstring: string): Promise<DecodedRawTransaction> {
515
+ return await this.executeRpc('decoderawtransaction', [hexstring]);
516
+ }
517
+
518
+ /**
519
+ * TODO: Comments
520
+ */
521
+ public async combineRawTransaction(txs: string[]): Promise<string> {
522
+ return await this.executeRpc<string>('combinerawtransaction', [txs]);
523
+ }
524
+
525
+ /**
526
+ * Create a transaction spending the given inputs and creating new outputs.
527
+ * Outputs can be addresses or data.
528
+ * Returns hex-encoded raw transaction.
529
+ * Note that the transaction's inputs are not signed, and
530
+ * it is not stored in the wallet or transmitted to the network.
531
+ * @param {TxInForCreateRaw[]} inputs The inputs to the transaction (required).
532
+ * @param {CreateRawTxOutputs[]} outputs The outputs of the transaction (required).
533
+ * @param {number} [locktime] The locktime of the transaction (optional).
534
+ * @param {boolean} [replacable] Whether the transaction is replaceable (optional).
535
+ * @returns {string} The hex-encoded raw transaction.
536
+ */
537
+ public async createRawTransaction(inputs: CreateRawTxInputs[], outputs: CreateRawTxOutputs[], locktime?: number, replacable?: boolean): Promise<string> {
538
+ return await this.executeRpc<string>('createrawtransaction', [inputs, outputs, locktime, replacable]);
539
+ }
540
+
541
+ /**
542
+ * Creates a multi-signature address with n signature of m keys required.
543
+ *
544
+ * @param {CreateMultisigParams} params The parameters for the createMultisig command.
545
+ * @param {number} params.nrequired The number of required signatures out of the n keys (required).
546
+ * @param {string[]} params.keys The hex-encoded public keys (required).
547
+ * @param {?string} params.address_type The address type to use (optional, options=["legacy", "p2sh-segwit", "bech32"], default="legacy").
548
+ * @returns {CreateMultiSigResult} json object with the address and redeemScript.
549
+ *
550
+ * @example Create a multisig address from 2 public keys
551
+ * ```
552
+ * const bob = BitcoinRpc.connect();
553
+ * const keys = [
554
+ * '03789ed0bb717d88f7d321a368d905e7430207ebbd82bd342cf11ae157a7ace5fd',
555
+ * '03dbc6764b8884a92e871274b87583e6d5c2a58819473e17e107ef3f6aa5a61626'
556
+ * ];
557
+ * const multisig = await bob.createMultisig({ nrequired: 2, keys });
558
+ * ```
559
+ */
560
+ public async createMultisig({ nrequired, keys, address_type }: CreateMultisigParams): Promise<CreateMultiSigResult> {
561
+ return await this.executeRpc('createmultisig', [nrequired, keys, address_type]);
562
+ }
563
+
564
+ /**
565
+ * TODO: Comments
566
+ */
567
+ public async getDescriptorInfo(descriptor: string): Promise<any> {
568
+ return await this.executeRpc('getdescriptorinfo', [descriptor]);
569
+ }
570
+
571
+ /**
572
+ * TODO: Comments
573
+ */
574
+ public async signMessageWithPrivkey(privkey: string, message: string): Promise<BitcoinSignature> {
575
+ return await this.executeRpc('signmessagewithprivkey', [privkey, message]);
576
+ }
577
+
578
+ /**
579
+ * TODO: Comments
580
+ */
581
+ public async validateAddress(address: string): Promise<ValidateAddressResult> {
582
+ return await this.executeRpc('validateaddress', [address]);
583
+ }
584
+
585
+ /**
586
+ * TODO: Comments
587
+ */
588
+ public async verifyMessage(address: string, signature: string, message: string): Promise<boolean> {
589
+ return await this.executeRpc('verifymessage', [address, signature, message]);
590
+ }
591
+
592
+ /**
593
+ * Derives one or more addresses corresponding to an output descriptor.
594
+ * Examples of output descriptors are:
595
+ * pkh(<pubkey>) P2PKH outputs for the given pubkey
596
+ * wpkh(<pubkey>) Native segwit P2PKH outputs for the given pubkey
597
+ * sh(multi(<n>,<pubkey>,<pubkey>,...)) P2SH-multisig outputs for the given threshold and pubkeys
598
+ * raw(<hex script>) Outputs whose output script equals the specified hex-encoded bytes
599
+ * tr(<pubkey>,multi_a(<n>,<pubkey>,<pubkey>,...)) P2TR-multisig outputs for the given threshold and pubkeys
600
+ *
601
+ * In the above, <pubkey> either refers to a fixed public key in hexadecimal notation, or to an xpub/xprv optionally followed by one
602
+ * or more path elements separated by "/", where "h" represents a hardened child key.
603
+ *
604
+ * See {@link https://github.com/bitcoin/bitcoin/blob/master/doc/descriptors.md | github.com/bitcoin/bitcoin/descriptors.md}
605
+ * for more information.
606
+ * @async
607
+ * @param {string} descriptor The descriptor.
608
+ * @param {Array<number>} range If descriptor is ranged, must specify end or [begin,end] to derive.
609
+ * @returns {Array<DerivedAddresses>} a list of derived addresses
610
+ * @example First three native segwit receive addresses
611
+ * ```
612
+ * const bitcoind = BitcoinRpc.connect()
613
+ * const addresses = bitcoind.deriveAddresses("wpkh([d34db33f/84h/0h/0h]xpub6DJ2dN.../0/*)#cjjspncu", [0,2])
614
+ * ```
615
+ */
616
+ public async deriveAddresses(descriptor: string, range?: Array<number>): Promise<Array<DerivedAddresses>> {
617
+ return await this.executeRpc('deriveaddresses', [descriptor, range]);
618
+ }
619
+
620
+ /**
621
+ * TODO: Comments
622
+ */
623
+ public async addMultisigAddress(): Promise<any> {
624
+ return await this.executeRpc('addmultisigaddress');
625
+ }
626
+
627
+ /**
628
+ * Creates the wallet's descriptor for the given address type. The address type must be one that the
629
+ * wallet does not already have a descriptor for. Requires wallet passphrase to be set with walletpassphrase call
630
+ * if wallet is encrypted.
631
+ * @param type The address type the descriptor will produce. Options are "legacy", "p2sh-segwit", "bech32", and "bech32m". (string, required)
632
+ * @param options Options object that can be used to pass named arguments, listed below. (json object, optional)
633
+ * @param options.internal Whether to only make one descriptor that is internal (if parameter is true) or external (if parameter is false)
634
+ * (boolean, optional, default=Both external and internal will be generated unless this parameter is specified)
635
+ * @param options.hdkey The HD key that the wallet knows the private key of, listed using 'gethdkeys', to use for this descriptor's key.
636
+ * (string, optional, default=The HD key used by all other active descriptors)
637
+ * @returns A {@link CreateWalletDescriptorsResult} response object
638
+ */
639
+ public async createWalletDescriptor(type: string, options: CreateWalletDescriptorOptions): Promise<CreateWalletDescriptorsResult> {
640
+ return await this.executeRpc('createwalletdescriptor', [type, options]);
641
+ }
642
+
643
+ /**
644
+ * TODO: Comments
645
+ */
646
+ public async getBalance(): Promise<any> {
647
+ return await this.executeRpc('getbalance');
648
+ }
649
+
650
+ /**
651
+ * TODO: Comments
652
+ */
653
+ public async getNewAddress(account?: string): Promise<string> {
654
+ return await this.executeRpc('getnewaddress', [account]);
655
+ }
656
+
657
+ /**
658
+ * TODO: Comments
659
+ */
660
+ public async importAddress(script: string, label?: string, rescan?: boolean, p2sh?: boolean): Promise<void> {
661
+ return await this.executeRpc('importaddress', [script, label, rescan, p2sh]);
662
+ }
663
+
664
+ /**
665
+ * Import descriptors.
666
+ *
667
+ * This will trigger a rescan of the blockchain based on the earliest timestamp of all descriptors being imported.
668
+ * Requires a new wallet backup. Note: This call can take over an hour to complete if using an early timestamp;
669
+ * during that time, other rpc calls may report that the imported keys, addresses or scripts exist but related
670
+ * transactions are still missing. The rescan is significantly faster if block filters are available
671
+ * (using startup option "-blockfilterindex=1").
672
+ *
673
+ * @param requests Array of {@link ImportDescriptorRequest} objects to be imported
674
+ * @returns Array of {@link ImportDescriptorResult} objects
675
+ * @returns
676
+ */
677
+ public async importDescriptors(requests: Array<ImportDescriptorRequest>): Promise<any> {
678
+ return await this.executeRpc('importdescriptors', [requests]);
679
+ }
680
+
681
+ /**
682
+ * TODO: Comments
683
+ */
684
+ public async importMulti(requests: ImportMultiRequest[], options?: ImportMultiOptions): Promise<Array<ImportMultiResult>> {
685
+ return await this.executeRpc('importmulti', [requests, options]);
686
+ }
687
+
688
+ /**
689
+ * TODO: Comments
690
+ */
691
+ public async listUnspent(params: ListUnspentParams): Promise<UnspentTxInfo[]> {
692
+ return await this.executeRpc('listunspent', [params]);
693
+ }
694
+
695
+ /**
696
+ * TODO: Comments
697
+ */
698
+ public async rescanBlockchain(): Promise<any> {
699
+ return await this.executeRpc('addmultisigaddress');
700
+ }
701
+
702
+ /**
703
+ * Send an amount to a given address.
704
+ * @async
705
+ * @param {string} address The address to send to.
706
+ * @param {number} amount The amount to send in BTC.
707
+ * @returns {Promise<SendToAddressResult>} A promise resolving to the transaction id.
708
+ */
709
+ public async sendToAddress(address: string, amount: number): Promise<RawTransactionV2> {
710
+ const txid = await this.executeRpc<string>('sendtoaddress', [address, amount]);
711
+ return await this.getRawTransaction(txid) as RawTransactionV2;
712
+ }
713
+
714
+ /**
715
+ * TODO: Comments
716
+ */
717
+ public async signMessage(): Promise<any> {
718
+ return await this.executeRpc('signmessage');
719
+ }
720
+
721
+ /**
722
+ * TODO: Comments
723
+ */
724
+ public async signRawTransactionWithWallet(): Promise<any> {
725
+ return await this.executeRpc('signrawtransactionwithwallet');
726
+ }
727
+
728
+ /**
729
+ * TODO: Comments
730
+ */
731
+ public async send(): Promise<any> {
732
+ return await this.executeRpc('send');
733
+ }
734
+
735
+ /**
736
+ * @warning EXPERIMENTAL this call may be changed in future releases.
737
+ *
738
+ * Spend the value of all (or specific) confirmed UTXOs & unconfirmed change in the wallet to one or
739
+ * more recipients. Unconfirmed inbound UTXOs and locked UTXOs will not be spent. Sendall will respect the
740
+ * avoid_reuse wallet flag. If your wallet contains many small inputs, either because it received tiny payments or as
741
+ * a result of accumulating change, consider using `send_max` to exclude inputs that are worth less than the fees
742
+ * needed to spend them.
743
+ *
744
+ * @param {SendAllParams} params The parameters for the sendAll command.
745
+ * @param {Recipients} params.recipients The recipient destination addresses.
746
+ * Each address may only appear once. Optionally some recipients can be specified with an
747
+ * amount to perform payments, but at least one address must appear without a specified amount.
748
+ * @param {SendAllOptions} params.options Options object that can be used to pass named arguments.
749
+ * @param {} params.options.conf_target Confirmation target in blocks. numeric, optional, default=wallet -txconfirmtarget.
750
+ * @param estimate_mode The fee estimate mode, must be one of (case insensitive). string, optional, default="unset".
751
+ * See {@link FeeEstimateMode} for possible values.
752
+ * @param fee_rate Specify a fee rate in sat/vB. numeric or string, optional, default=not set,
753
+ * falls back to wallet fee estimation
754
+ * @param options: Options object that can be used to pass named arguments. json object, optional
755
+ *
756
+ * @returns A promise resolving to a {@link SendAllResult} object
757
+ *
758
+ * @example
759
+ * Spend all UTXOs from the wallet with a fee rate of 1 sat/vB using named arguments
760
+ * const bob = BitcoinRpc.connect({
761
+ * username: 'bob',
762
+ * password: 'bobpass',
763
+ * host: 'http://127.0.0.1:18443',
764
+ * allowDefaultWallet: true,
765
+ * version: '28.1.0'
766
+ * });
767
+ * const sendall = await bob.sendAll({
768
+ * recipients: [
769
+ * 'bc1q09vm5lfy0j5reeulh4x5752q25uqqvz34hufdl',
770
+ * 'bc1q02ad21edsxd23d32dfgqqsz4vv4nmtfzuklhy3'
771
+ * ],
772
+ * options: { fee_rate: 1.1 }
773
+ * });
774
+ */
775
+ public async sendAll(params: SendAllParams): Promise<SendAllResult> {
776
+ return await this.executeRpc('sendall', [params]);
777
+ }
778
+
779
+ /**
780
+ * TODO: Comments
781
+ */
782
+ public async sendMany(params: SendManyParams): Promise<string> {
783
+ return await this.executeRpc('sendmany', [params]);
784
+ }
785
+
786
+ /**
787
+ * Get detailed information about in-wallet transaction <txid>.
788
+ * @param txid: The transaction id. (string, required)
789
+ * @param {boolean} include_watchonly Whether to include watch-only addresses in balance calculation and details.
790
+ * @returns {WalletTransaction} A promise resolving to a {@link WalletTransaction} object.
791
+ */
792
+ public async getTransaction(txid: string, include_watchonly?: boolean): Promise<WalletTransaction> {
793
+ return await this.executeRpc('gettransaction', [txid, include_watchonly]);
794
+ }
795
+
796
+ /**
797
+ * Get detailed information about a transaction.
798
+ *
799
+ * By default, this call only returns a transaction if it is in the mempool. If -txindex is enabled
800
+ * and no blockhash argument is passed, it will return the transaction if it is in the mempool or any block.
801
+ * If a blockhash argument is passed, it will return the transaction if the specified block is available and
802
+ * the transaction is in that block.
803
+ * @async
804
+ * @param {string} txid The transaction id (required).
805
+ * @param {?VerbosityLevel} verbosity Response format: 0 (hex), 1 (json) or 2 (jsonext).
806
+ * @param {?string} blockhash The block in which to look for the transaction (optional).
807
+ * @returns {GetRawTransaction} A promise resolving to data about a transaction in the form specified by verbosity.
808
+ */
809
+ public async getRawTransaction(txid: string, verbosity?: VerbosityLevel, blockhash?: string): Promise<RawTransactionResponse> {
810
+ // Get the raw transaction
811
+ const rawTransaction = await this.executeRpc('getrawtransaction', [txid, verbosity ?? 2, blockhash]);
812
+ // Return the raw transaction based on verbosity
813
+ switch(verbosity) {
814
+ case 0:
815
+ return rawTransaction as RawTransactionV0;
816
+ case 1:
817
+ return rawTransaction as RawTransactionV1;
818
+ case 2:
819
+ return rawTransaction as RawTransactionV2;
820
+ default:
821
+ return rawTransaction as RawTransactionV2;
822
+ }
823
+ }
824
+
825
+ /**
826
+ * Get detailed information about multiple transactions. An extension of {@link getRawTransaction}.
827
+ *
828
+ * @async
829
+ * @param {Array<string>} txids An array of transaction ids.
830
+ * @param {?VerbosityLevel} verbosity Response format: 0 (hex), 1 (json) or 2 (jsonext).
831
+ * @returns {Promise<Array<RawTransactionResponse>>}
832
+ */
833
+ public async getRawTransactions(txids: string[], verbosity?: VerbosityLevel): Promise<RawTransactionResponse[]> {
834
+ return await Promise.all(
835
+ txids.map(
836
+ async (txid) => await this.getRawTransaction(txid, verbosity ?? 2)
837
+ )
838
+ );
839
+ }
840
+
841
+ clearBanned(): Promise<void> {
842
+ throw new Error('Method not implemented.');
843
+ }
844
+
845
+ disconnectNode(address?: string, nodeid?: number): Promise<void> {
846
+ throw new Error('Method not implemented.' + address + nodeid);
847
+ }
848
+
849
+ dumpPrivKey(address: string): Promise<string> {
850
+ throw new Error('Method not implemented.' + address);
851
+ }
852
+
853
+ dumpWallet(filename: string): Promise<{ filename: string; }> {
854
+ throw new Error('Method not implemented.' + filename);
855
+ }
856
+
857
+ encryptWallet(passphrase: string): Promise<void> {
858
+ throw new Error('Method not implemented.' + passphrase);
859
+ }
860
+
861
+ estimateSmartFee(conf_target: number, estimate_mode?: FeeEstimateMode): Promise<{ feerate?: number; errors?: string[]; blocks?: number; }> {
862
+ throw new Error('Method not implemented.' + conf_target + estimate_mode);
863
+ }
864
+
865
+ getConnectionCount(): Promise<number> {
866
+ throw new Error('Method not implemented.');
867
+ }
868
+
869
+ getDifficulty(): Promise<number> {
870
+ throw new Error('Method not implemented.');
871
+ }
872
+
873
+ getMempoolInfo(): Promise<MempoolInfo> {
874
+ throw new Error('Method not implemented.');
875
+ }
876
+
877
+ getMiningInfo(): Promise<MiningInfo> {
878
+ throw new Error('Method not implemented.');
879
+ }
880
+
881
+ getPeerInfo(): Promise<PeerInfo[]> {
882
+ throw new Error('Method not implemented.');
883
+ }
884
+
885
+ walletLock(passphrase: string, timeout: number): Promise<void> {
886
+ throw new Error('Method not implemented.' + passphrase + timeout);
887
+ }
888
+ }