@pezkuwi/api 16.5.6 → 16.5.8

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 (379) hide show
  1. package/build/LICENSE +201 -0
  2. package/build/README.md +100 -0
  3. package/build/augment.d.ts +1 -0
  4. package/build/augment.js +1 -0
  5. package/build/base/Decorate.d.ts +143 -0
  6. package/build/base/Decorate.js +752 -0
  7. package/build/base/Events.d.ts +67 -0
  8. package/build/base/Events.js +78 -0
  9. package/build/base/Getters.d.ts +163 -0
  10. package/build/base/Getters.js +207 -0
  11. package/build/base/Init.d.ts +44 -0
  12. package/build/base/Init.js +400 -0
  13. package/build/base/find.d.ts +3 -0
  14. package/build/base/find.js +7 -0
  15. package/build/base/index.d.ts +47 -0
  16. package/build/base/index.js +57 -0
  17. package/build/base/types.d.ts +15 -0
  18. package/build/base/types.js +1 -0
  19. package/build/bundle-pezkuwi-api.js +26247 -0
  20. package/build/bundle.d.ts +7 -0
  21. package/build/bundle.js +7 -0
  22. package/build/cjs/augment.d.ts +1 -0
  23. package/build/cjs/augment.js +3 -0
  24. package/build/cjs/base/Decorate.d.ts +143 -0
  25. package/build/cjs/base/Decorate.js +756 -0
  26. package/build/cjs/base/Events.d.ts +67 -0
  27. package/build/cjs/base/Events.js +82 -0
  28. package/build/cjs/base/Getters.d.ts +163 -0
  29. package/build/cjs/base/Getters.js +211 -0
  30. package/build/cjs/base/Init.d.ts +44 -0
  31. package/build/cjs/base/Init.js +404 -0
  32. package/build/cjs/base/find.d.ts +3 -0
  33. package/build/cjs/base/find.js +11 -0
  34. package/build/cjs/base/index.d.ts +47 -0
  35. package/build/cjs/base/index.js +61 -0
  36. package/build/cjs/base/types.d.ts +15 -0
  37. package/build/cjs/base/types.js +2 -0
  38. package/build/cjs/bundle.d.ts +7 -0
  39. package/build/cjs/bundle.js +17 -0
  40. package/build/cjs/index.d.ts +2 -0
  41. package/build/cjs/index.js +5 -0
  42. package/build/cjs/package.json +3 -0
  43. package/build/cjs/packageDetect.d.ts +1 -0
  44. package/build/cjs/packageDetect.js +10 -0
  45. package/build/cjs/packageInfo.d.ts +6 -0
  46. package/build/cjs/packageInfo.js +4 -0
  47. package/build/cjs/promise/Api.d.ts +158 -0
  48. package/build/cjs/promise/Api.js +195 -0
  49. package/build/cjs/promise/Combinator.d.ts +12 -0
  50. package/build/cjs/promise/Combinator.js +72 -0
  51. package/build/cjs/promise/decorateMethod.d.ts +14 -0
  52. package/build/cjs/promise/decorateMethod.js +75 -0
  53. package/build/cjs/promise/index.d.ts +2 -0
  54. package/build/cjs/promise/index.js +7 -0
  55. package/build/cjs/promise/types.d.ts +5 -0
  56. package/build/cjs/promise/types.js +2 -0
  57. package/build/cjs/rx/Api.d.ts +155 -0
  58. package/build/cjs/rx/Api.js +173 -0
  59. package/build/cjs/rx/decorateMethod.d.ts +3 -0
  60. package/build/cjs/rx/decorateMethod.js +6 -0
  61. package/build/cjs/rx/index.d.ts +2 -0
  62. package/build/cjs/rx/index.js +7 -0
  63. package/build/cjs/submittable/Result.d.ts +31 -0
  64. package/build/cjs/submittable/Result.js +84 -0
  65. package/build/cjs/submittable/createClass.d.ts +12 -0
  66. package/build/cjs/submittable/createClass.js +277 -0
  67. package/build/cjs/submittable/createSubmittable.d.ts +8 -0
  68. package/build/cjs/submittable/createSubmittable.js +8 -0
  69. package/build/cjs/submittable/index.d.ts +2 -0
  70. package/build/cjs/submittable/index.js +7 -0
  71. package/build/cjs/submittable/types.d.ts +1 -0
  72. package/build/cjs/submittable/types.js +2 -0
  73. package/build/cjs/types/calls.d.ts +1 -0
  74. package/build/cjs/types/calls.js +4 -0
  75. package/build/cjs/types/consts.d.ts +1 -0
  76. package/build/cjs/types/consts.js +4 -0
  77. package/build/cjs/types/errors.d.ts +1 -0
  78. package/build/cjs/types/errors.js +4 -0
  79. package/build/cjs/types/events.d.ts +1 -0
  80. package/build/cjs/types/events.js +4 -0
  81. package/build/cjs/types/index.d.ts +114 -0
  82. package/build/cjs/types/index.js +13 -0
  83. package/build/cjs/types/storage.d.ts +1 -0
  84. package/build/cjs/types/storage.js +4 -0
  85. package/build/cjs/types/submittable.d.ts +1 -0
  86. package/build/cjs/types/submittable.js +4 -0
  87. package/build/cjs/util/augmentObject.d.ts +9 -0
  88. package/build/cjs/util/augmentObject.js +84 -0
  89. package/build/cjs/util/decorate.d.ts +16 -0
  90. package/build/cjs/util/decorate.js +17 -0
  91. package/build/cjs/util/filterEvents.d.ts +6 -0
  92. package/build/cjs/util/filterEvents.js +25 -0
  93. package/build/cjs/util/index.d.ts +4 -0
  94. package/build/cjs/util/index.js +11 -0
  95. package/build/cjs/util/isKeyringPair.d.ts +3 -0
  96. package/build/cjs/util/isKeyringPair.js +7 -0
  97. package/build/cjs/util/logging.d.ts +1 -0
  98. package/build/cjs/util/logging.js +5 -0
  99. package/build/cjs/util/validate.d.ts +3 -0
  100. package/build/cjs/util/validate.js +26 -0
  101. package/build/index.d.ts +2 -0
  102. package/build/index.js +2 -0
  103. package/build/package.json +612 -0
  104. package/build/packageDetect.d.ts +1 -0
  105. package/build/packageDetect.js +8 -0
  106. package/build/packageInfo.d.ts +6 -0
  107. package/build/packageInfo.js +1 -0
  108. package/build/promise/Api.d.ts +158 -0
  109. package/build/promise/Api.js +191 -0
  110. package/build/promise/Combinator.d.ts +12 -0
  111. package/build/promise/Combinator.js +68 -0
  112. package/build/promise/decorateMethod.d.ts +14 -0
  113. package/build/promise/decorateMethod.js +71 -0
  114. package/build/promise/index.d.ts +2 -0
  115. package/build/promise/index.js +2 -0
  116. package/build/promise/types.d.ts +5 -0
  117. package/build/promise/types.js +1 -0
  118. package/build/rx/Api.d.ts +155 -0
  119. package/build/rx/Api.js +169 -0
  120. package/build/rx/decorateMethod.d.ts +3 -0
  121. package/build/rx/decorateMethod.js +3 -0
  122. package/build/rx/index.d.ts +2 -0
  123. package/build/rx/index.js +2 -0
  124. package/build/submittable/Result.d.ts +31 -0
  125. package/build/submittable/Result.js +80 -0
  126. package/build/submittable/createClass.d.ts +12 -0
  127. package/build/submittable/createClass.js +274 -0
  128. package/build/submittable/createSubmittable.d.ts +8 -0
  129. package/build/submittable/createSubmittable.js +5 -0
  130. package/build/submittable/index.d.ts +2 -0
  131. package/build/submittable/index.js +2 -0
  132. package/build/submittable/types.d.ts +1 -0
  133. package/build/submittable/types.js +1 -0
  134. package/build/types/calls.d.ts +1 -0
  135. package/build/types/calls.js +1 -0
  136. package/build/types/consts.d.ts +1 -0
  137. package/build/types/consts.js +1 -0
  138. package/build/types/errors.d.ts +1 -0
  139. package/build/types/errors.js +1 -0
  140. package/build/types/events.d.ts +1 -0
  141. package/build/types/events.js +1 -0
  142. package/build/types/index.d.ts +114 -0
  143. package/build/types/index.js +8 -0
  144. package/build/types/storage.d.ts +1 -0
  145. package/build/types/storage.js +1 -0
  146. package/build/types/submittable.d.ts +1 -0
  147. package/build/types/submittable.js +1 -0
  148. package/build/util/augmentObject.d.ts +9 -0
  149. package/build/util/augmentObject.js +81 -0
  150. package/build/util/decorate.d.ts +16 -0
  151. package/build/util/decorate.js +14 -0
  152. package/build/util/filterEvents.d.ts +6 -0
  153. package/build/util/filterEvents.js +22 -0
  154. package/build/util/index.d.ts +4 -0
  155. package/build/util/index.js +4 -0
  156. package/build/util/isKeyringPair.d.ts +3 -0
  157. package/build/util/isKeyringPair.js +4 -0
  158. package/build/util/logging.d.ts +1 -0
  159. package/build/util/logging.js +2 -0
  160. package/build/util/validate.d.ts +3 -0
  161. package/build/util/validate.js +23 -0
  162. package/build-deno/README.md +95 -0
  163. package/build-deno/augment.ts +2 -0
  164. package/build-deno/base/Decorate.ts +1100 -0
  165. package/build-deno/base/Events.ts +89 -0
  166. package/build-deno/base/Getters.ts +243 -0
  167. package/build-deno/base/Init.ts +523 -0
  168. package/build-deno/base/find.ts +12 -0
  169. package/build-deno/base/index.ts +83 -0
  170. package/build-deno/base/types.ts +17 -0
  171. package/build-deno/bundle.ts +11 -0
  172. package/build-deno/checkTypes.manual.ts +320 -0
  173. package/build-deno/index.ts +4 -0
  174. package/build-deno/mod.ts +2 -0
  175. package/build-deno/packageDetect.ts +12 -0
  176. package/build-deno/packageInfo.ts +3 -0
  177. package/build-deno/promise/Api.ts +212 -0
  178. package/build-deno/promise/Combinator.ts +89 -0
  179. package/build-deno/promise/decorateMethod.ts +111 -0
  180. package/build-deno/promise/index.ts +3 -0
  181. package/build-deno/promise/types.ts +7 -0
  182. package/build-deno/rx/Api.ts +184 -0
  183. package/build-deno/rx/decorateMethod.ts +7 -0
  184. package/build-deno/rx/index.ts +3 -0
  185. package/build-deno/submittable/Result.ts +109 -0
  186. package/build-deno/submittable/createClass.ts +436 -0
  187. package/build-deno/submittable/createSubmittable.ts +17 -0
  188. package/build-deno/submittable/index.ts +3 -0
  189. package/build-deno/submittable/types.ts +2 -0
  190. package/build-deno/test/SingleAccountSigner.ts +51 -0
  191. package/build-deno/test/index.ts +3 -0
  192. package/build-deno/test/logEvents.ts +21 -0
  193. package/build-deno/types/calls.ts +2 -0
  194. package/build-deno/types/consts.ts +2 -0
  195. package/build-deno/types/errors.ts +2 -0
  196. package/build-deno/types/events.ts +2 -0
  197. package/build-deno/types/index.ts +124 -0
  198. package/build-deno/types/storage.ts +2 -0
  199. package/build-deno/types/submittable.ts +2 -0
  200. package/build-deno/util/augmentObject.ts +109 -0
  201. package/build-deno/util/decorate.ts +38 -0
  202. package/build-deno/util/filterEvents.ts +32 -0
  203. package/build-deno/util/index.ts +6 -0
  204. package/build-deno/util/isKeyringPair.ts +9 -0
  205. package/build-deno/util/logging.ts +4 -0
  206. package/build-deno/util/validate.ts +32 -0
  207. package/build-tsc/augment.d.ts +1 -0
  208. package/build-tsc/base/Decorate.d.ts +143 -0
  209. package/build-tsc/base/Events.d.ts +67 -0
  210. package/build-tsc/base/Getters.d.ts +163 -0
  211. package/build-tsc/base/Init.d.ts +44 -0
  212. package/build-tsc/base/find.d.ts +3 -0
  213. package/build-tsc/base/index.d.ts +47 -0
  214. package/build-tsc/base/types.d.ts +15 -0
  215. package/build-tsc/bundle.d.ts +7 -0
  216. package/build-tsc/index.d.ts +2 -0
  217. package/build-tsc/packageDetect.d.ts +1 -0
  218. package/build-tsc/packageInfo.d.ts +6 -0
  219. package/build-tsc/promise/Api.d.ts +158 -0
  220. package/build-tsc/promise/Combinator.d.ts +12 -0
  221. package/build-tsc/promise/decorateMethod.d.ts +14 -0
  222. package/build-tsc/promise/index.d.ts +2 -0
  223. package/build-tsc/promise/types.d.ts +5 -0
  224. package/build-tsc/rx/Api.d.ts +155 -0
  225. package/build-tsc/rx/decorateMethod.d.ts +3 -0
  226. package/build-tsc/rx/index.d.ts +2 -0
  227. package/build-tsc/submittable/Result.d.ts +31 -0
  228. package/build-tsc/submittable/createClass.d.ts +12 -0
  229. package/build-tsc/submittable/createSubmittable.d.ts +8 -0
  230. package/build-tsc/submittable/index.d.ts +2 -0
  231. package/build-tsc/submittable/types.d.ts +1 -0
  232. package/build-tsc/types/calls.d.ts +1 -0
  233. package/build-tsc/types/consts.d.ts +1 -0
  234. package/build-tsc/types/errors.d.ts +1 -0
  235. package/build-tsc/types/events.d.ts +1 -0
  236. package/build-tsc/types/index.d.ts +114 -0
  237. package/build-tsc/types/storage.d.ts +1 -0
  238. package/build-tsc/types/submittable.d.ts +1 -0
  239. package/build-tsc/util/augmentObject.d.ts +9 -0
  240. package/build-tsc/util/decorate.d.ts +16 -0
  241. package/build-tsc/util/filterEvents.d.ts +6 -0
  242. package/build-tsc/util/index.d.ts +4 -0
  243. package/build-tsc/util/isKeyringPair.d.ts +3 -0
  244. package/build-tsc/util/logging.d.ts +1 -0
  245. package/build-tsc/util/validate.d.ts +3 -0
  246. package/build-tsc-cjs/augment.js +3 -0
  247. package/build-tsc-cjs/base/Decorate.js +756 -0
  248. package/build-tsc-cjs/base/Events.js +82 -0
  249. package/build-tsc-cjs/base/Getters.js +211 -0
  250. package/build-tsc-cjs/base/Init.js +404 -0
  251. package/build-tsc-cjs/base/find.js +11 -0
  252. package/build-tsc-cjs/base/index.js +61 -0
  253. package/build-tsc-cjs/base/types.js +2 -0
  254. package/build-tsc-cjs/bundle.js +17 -0
  255. package/build-tsc-cjs/index.js +5 -0
  256. package/build-tsc-cjs/packageDetect.js +10 -0
  257. package/build-tsc-cjs/packageInfo.js +4 -0
  258. package/build-tsc-cjs/promise/Api.js +195 -0
  259. package/build-tsc-cjs/promise/Combinator.js +72 -0
  260. package/build-tsc-cjs/promise/decorateMethod.js +75 -0
  261. package/build-tsc-cjs/promise/index.js +7 -0
  262. package/build-tsc-cjs/promise/types.js +2 -0
  263. package/build-tsc-cjs/rx/Api.js +173 -0
  264. package/build-tsc-cjs/rx/decorateMethod.js +6 -0
  265. package/build-tsc-cjs/rx/index.js +7 -0
  266. package/build-tsc-cjs/submittable/Result.js +84 -0
  267. package/build-tsc-cjs/submittable/createClass.js +277 -0
  268. package/build-tsc-cjs/submittable/createSubmittable.js +8 -0
  269. package/build-tsc-cjs/submittable/index.js +7 -0
  270. package/build-tsc-cjs/submittable/types.js +2 -0
  271. package/build-tsc-cjs/types/calls.js +4 -0
  272. package/build-tsc-cjs/types/consts.js +4 -0
  273. package/build-tsc-cjs/types/errors.js +4 -0
  274. package/build-tsc-cjs/types/events.js +4 -0
  275. package/build-tsc-cjs/types/index.js +13 -0
  276. package/build-tsc-cjs/types/storage.js +4 -0
  277. package/build-tsc-cjs/types/submittable.js +4 -0
  278. package/build-tsc-cjs/util/augmentObject.js +84 -0
  279. package/build-tsc-cjs/util/decorate.js +17 -0
  280. package/build-tsc-cjs/util/filterEvents.js +25 -0
  281. package/build-tsc-cjs/util/index.js +11 -0
  282. package/build-tsc-cjs/util/isKeyringPair.js +7 -0
  283. package/build-tsc-cjs/util/logging.js +5 -0
  284. package/build-tsc-cjs/util/validate.js +26 -0
  285. package/build-tsc-esm/augment.js +1 -0
  286. package/build-tsc-esm/base/Decorate.js +752 -0
  287. package/build-tsc-esm/base/Events.js +78 -0
  288. package/build-tsc-esm/base/Getters.js +207 -0
  289. package/build-tsc-esm/base/Init.js +400 -0
  290. package/build-tsc-esm/base/find.js +7 -0
  291. package/build-tsc-esm/base/index.js +57 -0
  292. package/build-tsc-esm/base/types.js +1 -0
  293. package/build-tsc-esm/bundle.js +7 -0
  294. package/build-tsc-esm/index.js +2 -0
  295. package/build-tsc-esm/packageDetect.js +8 -0
  296. package/build-tsc-esm/packageInfo.js +1 -0
  297. package/build-tsc-esm/promise/Api.js +191 -0
  298. package/build-tsc-esm/promise/Combinator.js +68 -0
  299. package/build-tsc-esm/promise/decorateMethod.js +71 -0
  300. package/build-tsc-esm/promise/index.js +2 -0
  301. package/build-tsc-esm/promise/types.js +1 -0
  302. package/build-tsc-esm/rx/Api.js +169 -0
  303. package/build-tsc-esm/rx/decorateMethod.js +3 -0
  304. package/build-tsc-esm/rx/index.js +2 -0
  305. package/build-tsc-esm/submittable/Result.js +80 -0
  306. package/build-tsc-esm/submittable/createClass.js +274 -0
  307. package/build-tsc-esm/submittable/createSubmittable.js +5 -0
  308. package/build-tsc-esm/submittable/index.js +2 -0
  309. package/build-tsc-esm/submittable/types.js +1 -0
  310. package/build-tsc-esm/types/calls.js +1 -0
  311. package/build-tsc-esm/types/consts.js +1 -0
  312. package/build-tsc-esm/types/errors.js +1 -0
  313. package/build-tsc-esm/types/events.js +1 -0
  314. package/build-tsc-esm/types/index.js +8 -0
  315. package/build-tsc-esm/types/storage.js +1 -0
  316. package/build-tsc-esm/types/submittable.js +1 -0
  317. package/build-tsc-esm/util/augmentObject.js +81 -0
  318. package/build-tsc-esm/util/decorate.js +14 -0
  319. package/build-tsc-esm/util/filterEvents.js +22 -0
  320. package/build-tsc-esm/util/index.js +4 -0
  321. package/build-tsc-esm/util/isKeyringPair.js +4 -0
  322. package/build-tsc-esm/util/logging.js +2 -0
  323. package/build-tsc-esm/util/validate.js +23 -0
  324. package/bundle-pezkuwi-api.js +26240 -26231
  325. package/cjs/packageInfo.js +1 -1
  326. package/package.json +12 -12
  327. package/packageInfo.js +1 -1
  328. package/src/augment.ts +4 -0
  329. package/src/base/Decorate.ts +1103 -0
  330. package/src/base/Events.ts +91 -0
  331. package/src/base/Getters.ts +245 -0
  332. package/src/base/Init.ts +525 -0
  333. package/src/base/find.ts +14 -0
  334. package/src/base/index.ts +85 -0
  335. package/src/base/types.ts +19 -0
  336. package/src/bundle.ts +16 -0
  337. package/src/checkTypes.manual.ts +323 -0
  338. package/src/index.ts +6 -0
  339. package/src/mod.ts +4 -0
  340. package/src/packageDetect.ts +16 -0
  341. package/src/packageInfo.ts +6 -0
  342. package/src/promise/Api.ts +214 -0
  343. package/src/promise/Combinator.ts +91 -0
  344. package/src/promise/Combinators.spec.ts +109 -0
  345. package/src/promise/decorateMethod.ts +118 -0
  346. package/src/promise/index.spec.ts +167 -0
  347. package/src/promise/index.ts +5 -0
  348. package/src/promise/types.ts +9 -0
  349. package/src/rx/Api.ts +186 -0
  350. package/src/rx/decorateMethod.ts +9 -0
  351. package/src/rx/index.ts +5 -0
  352. package/src/submittable/Result.ts +111 -0
  353. package/src/submittable/createClass.ts +438 -0
  354. package/src/submittable/createSubmittable.ts +19 -0
  355. package/src/submittable/index.ts +5 -0
  356. package/src/submittable/types.ts +4 -0
  357. package/src/test/SingleAccountSigner.ts +53 -0
  358. package/src/test/index.ts +5 -0
  359. package/src/test/logEvents.ts +24 -0
  360. package/src/types/calls.ts +4 -0
  361. package/src/types/consts.ts +4 -0
  362. package/src/types/errors.ts +4 -0
  363. package/src/types/events.ts +4 -0
  364. package/src/types/index.ts +137 -0
  365. package/src/types/storage.ts +4 -0
  366. package/src/types/submittable.ts +4 -0
  367. package/src/util/augmentObject.spec.ts +54 -0
  368. package/src/util/augmentObject.ts +112 -0
  369. package/src/util/decorate.ts +43 -0
  370. package/src/util/filterEvents.ts +34 -0
  371. package/src/util/index.ts +10 -0
  372. package/src/util/isKeyringPair.ts +11 -0
  373. package/src/util/logging.ts +6 -0
  374. package/src/util/validate.spec.ts +72 -0
  375. package/src/util/validate.ts +36 -0
  376. package/tsconfig.build.json +25 -0
  377. package/tsconfig.build.tsbuildinfo +1 -0
  378. package/tsconfig.spec.json +26 -0
  379. package/tsconfig.spec.tsbuildinfo +1 -0
@@ -0,0 +1,525 @@
1
+ // Copyright 2017-2025 @pezkuwi/api authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { Observable, Subscription } from 'rxjs';
5
+ import type { Bytes, Text, u32, Vec } from '@pezkuwi/types';
6
+ import type { ExtDef } from '@pezkuwi/types/extrinsic/signedExtensions/types';
7
+ import type { BlockHash, ChainProperties, Hash, HeaderPartial, RuntimeVersion, RuntimeVersionApi, RuntimeVersionPartial } from '@pezkuwi/types/interfaces';
8
+ import type { Registry } from '@pezkuwi/types/types';
9
+ import type { BN } from '@pezkuwi/util';
10
+ import type { HexString } from '@pezkuwi/util/types';
11
+ import type { ApiBase, ApiDecoration, ApiOptions, ApiTypes, DecorateMethod } from '../types/index.js';
12
+ import type { VersionedRegistry } from './types.js';
13
+
14
+ import { firstValueFrom, map, of, switchMap } from 'rxjs';
15
+
16
+ import { Metadata, TypeRegistry } from '@pezkuwi/types';
17
+ import { LATEST_EXTRINSIC_VERSION } from '@pezkuwi/types/extrinsic/constants';
18
+ import { getSpecAlias, getSpecExtensions, getSpecHasher, getSpecRpc, getSpecTypes, getUpgradeVersion } from '@pezkuwi/types-known';
19
+ import { assertReturn, BN_ZERO, isUndefined, logger, noop, objectSpread, u8aEq, u8aToHex, u8aToU8a } from '@pezkuwi/util';
20
+ import { blake2AsHex, cryptoWaitReady } from '@pezkuwi/util-crypto';
21
+
22
+ import { Decorate } from './Decorate.js';
23
+
24
+ const KEEPALIVE_INTERVAL = 10000;
25
+ const WITH_VERSION_SHORTCUT = false;
26
+
27
+ const SUPPORTED_METADATA_VERSIONS = [16, 15, 14];
28
+
29
+ const l = logger('api/init');
30
+
31
+ function textToString (t: Text): string {
32
+ return t.toString();
33
+ }
34
+
35
+ export abstract class Init<ApiType extends ApiTypes> extends Decorate<ApiType> {
36
+ #atLast: [string, ApiDecoration<ApiType>] | null = null;
37
+ #healthTimer: ReturnType<typeof setInterval> | null = null;
38
+ #registries: VersionedRegistry<ApiType>[] = [];
39
+ #updateSub?: Subscription | null = null;
40
+ #waitingRegistries: Record<HexString, Promise<VersionedRegistry<ApiType>>> = {};
41
+
42
+ constructor (options: ApiOptions, type: ApiTypes, decorateMethod: DecorateMethod<ApiType>) {
43
+ super(options, type, decorateMethod);
44
+
45
+ // all injected types added to the registry for overrides
46
+ this.registry.setKnownTypes(options);
47
+
48
+ // We only register the types (global) if this is not a cloned instance.
49
+ // Do right up-front, so we get in the user types before we are actually
50
+ // doing anything on-chain, this ensures we have the overrides in-place
51
+ if (!options.source) {
52
+ this.registerTypes(options.types);
53
+ } else {
54
+ this.#registries = options.source.#registries as VersionedRegistry<ApiType>[];
55
+ }
56
+
57
+ this._rpc = this._decorateRpc(this._rpcCore, this._decorateMethod);
58
+ this._rx.rpc = this._decorateRpc(this._rpcCore, this._rxDecorateMethod);
59
+
60
+ if (this.supportMulti) {
61
+ this._queryMulti = this._decorateMulti(this._decorateMethod);
62
+ this._rx.queryMulti = this._decorateMulti(this._rxDecorateMethod);
63
+ }
64
+
65
+ this._rx.signer = options.signer;
66
+
67
+ this._rpcCore.setRegistrySwap((blockHash: Uint8Array) => this.getBlockRegistry(blockHash));
68
+
69
+ this._rpcCore.setResolveBlockHash((blockNumber) => firstValueFrom(this._rpcCore.chain.getBlockHash(blockNumber)));
70
+
71
+ if (this.hasSubscriptions) {
72
+ this._rpcCore.provider.on('disconnected', () => this.#onProviderDisconnect());
73
+ this._rpcCore.provider.on('error', (e: Error) => this.#onProviderError(e));
74
+ this._rpcCore.provider.on('connected', () => this.#onProviderConnect());
75
+ } else if (!this._options.noInitWarn) {
76
+ l.warn('Api will be available in a limited mode since the provider does not support subscriptions');
77
+ }
78
+
79
+ // If the provider was instantiated earlier, and has already emitted a
80
+ // 'connected' event, then the `on('connected')` won't fire anymore. To
81
+ // cater for this case, we call manually `this._onProviderConnect`.
82
+ if (this._rpcCore.provider.isConnected) {
83
+ this.#onProviderConnect().catch(noop);
84
+ }
85
+ }
86
+
87
+ /**
88
+ * @description Decorates a registry based on the runtime version
89
+ */
90
+ private _initRegistry (registry: Registry, chain: Text, version: { specName: Text, specVersion: BN }, metadata: Metadata, chainProps?: ChainProperties): void {
91
+ registry.clearCache();
92
+ registry.setChainProperties(chainProps || this.registry.getChainProperties());
93
+ registry.setKnownTypes(this._options);
94
+ registry.register(getSpecTypes(registry, chain, version.specName, version.specVersion));
95
+ registry.setHasher(getSpecHasher(registry, chain, version.specName));
96
+
97
+ // for bundled types, pull through the aliases defined
98
+ if (registry.knownTypes.typesBundle) {
99
+ registry.knownTypes.typesAlias = getSpecAlias(registry, chain, version.specName);
100
+ }
101
+
102
+ registry.setMetadata(metadata, undefined, objectSpread<ExtDef>({}, getSpecExtensions(registry, chain, version.specName), this._options.signedExtensions), this._options.noInitWarn);
103
+ }
104
+
105
+ /**
106
+ * @description Returns the default versioned registry
107
+ */
108
+ private _getDefaultRegistry (): VersionedRegistry<ApiType> {
109
+ return assertReturn(this.#registries.find(({ isDefault }) => isDefault), 'Initialization error, cannot find the default registry');
110
+ }
111
+
112
+ /**
113
+ * @description Returns a decorated API instance at a specific point in time
114
+ */
115
+ public async at (blockHash: Uint8Array | string, knownVersion?: RuntimeVersion): Promise<ApiDecoration<ApiType>> {
116
+ const u8aHash = u8aToU8a(blockHash);
117
+ const u8aHex = u8aToHex(u8aHash);
118
+ const registry = await this.getBlockRegistry(u8aHash, knownVersion);
119
+
120
+ if (!this.#atLast || this.#atLast[0] !== u8aHex) {
121
+ // always create a new decoration - since we are pointing to a specific hash, this
122
+ // means that all queries needs to use that hash (not a previous one already existing)
123
+ this.#atLast = [u8aHex, this._createDecorated(registry, true, null, u8aHash).decoratedApi];
124
+ }
125
+
126
+ return this.#atLast[1];
127
+ }
128
+
129
+ private async _createBlockRegistry (blockHash: Uint8Array, header: HeaderPartial, version: RuntimeVersionPartial): Promise<VersionedRegistry<ApiType>> {
130
+ const registry = new TypeRegistry(blockHash);
131
+ const metadata = await this._retrieveMetadata(version.apis, header.parentHash, registry);
132
+ const runtimeChain = this._runtimeChain;
133
+
134
+ if (!runtimeChain) {
135
+ throw new Error('Invalid initializion order, runtimeChain is not available');
136
+ }
137
+
138
+ this._initRegistry(registry, runtimeChain, version, metadata);
139
+
140
+ // add our new registry
141
+ const result = { counter: 0, lastBlockHash: blockHash, metadata, registry, runtimeVersion: version };
142
+
143
+ this.#registries.push(result);
144
+
145
+ return result;
146
+ }
147
+
148
+ private _cacheBlockRegistryProgress (key: HexString, creator: () => Promise<VersionedRegistry<ApiType>>): Promise<VersionedRegistry<ApiType>> {
149
+ // look for waiting resolves
150
+ let waiting = this.#waitingRegistries[key];
151
+
152
+ if (isUndefined(waiting)) {
153
+ // nothing waiting, construct new
154
+ waiting = this.#waitingRegistries[key] = new Promise<VersionedRegistry<ApiType>>((resolve, reject): void => {
155
+ creator()
156
+ .then((registry): void => {
157
+ delete this.#waitingRegistries[key];
158
+ resolve(registry);
159
+ })
160
+ .catch((error): void => {
161
+ delete this.#waitingRegistries[key];
162
+ reject(error);
163
+ });
164
+ });
165
+ }
166
+
167
+ return waiting;
168
+ }
169
+
170
+ private _getBlockRegistryViaVersion (blockHash: Uint8Array, version?: RuntimeVersionPartial): VersionedRegistry<ApiType> | null {
171
+ if (version) {
172
+ // check for pre-existing registries. We also check specName, e.g. it
173
+ // could be changed like in Westmint with upgrade from shell -> westmint
174
+ const existingViaVersion = this.#registries.find(({ runtimeVersion: { specName, specVersion } }) =>
175
+ specName.eq(version.specName) &&
176
+ specVersion.eq(version.specVersion)
177
+ );
178
+
179
+ if (existingViaVersion) {
180
+ existingViaVersion.counter++;
181
+ existingViaVersion.lastBlockHash = blockHash;
182
+
183
+ return existingViaVersion;
184
+ }
185
+ }
186
+
187
+ return null;
188
+ }
189
+
190
+ private async _getBlockRegistryViaHash (blockHash: Uint8Array): Promise<VersionedRegistry<ApiType>> {
191
+ // ensure we have everything required
192
+ if (!this._genesisHash || !this._runtimeVersion) {
193
+ throw new Error('Cannot retrieve data on an uninitialized chain');
194
+ }
195
+
196
+ // We have to assume that on the RPC layer the calls used here does not call back into
197
+ // the registry swap, so getHeader & getRuntimeVersion should not be historic
198
+ const header = this.registry.createType('HeaderPartial',
199
+ this._genesisHash.eq(blockHash)
200
+ ? { number: BN_ZERO, parentHash: this._genesisHash }
201
+ : await firstValueFrom(this._rpcCore.chain.getHeader.raw(blockHash))
202
+ );
203
+
204
+ if (header.parentHash.isEmpty) {
205
+ l.warn(`Unable to retrieve header ${blockHash.toString()} and parent ${header.parentHash.toString()} from supplied hash`);
206
+ throw new Error('Unable to retrieve header and parent from supplied hash');
207
+ }
208
+
209
+ // get the runtime version, either on-chain or via an known upgrade history
210
+ const [firstVersion, lastVersion] = getUpgradeVersion(this._genesisHash, header.number);
211
+ const version = this.registry.createType('RuntimeVersionPartial',
212
+ WITH_VERSION_SHORTCUT && (
213
+ firstVersion && (
214
+ lastVersion ||
215
+ firstVersion.specVersion.eq(this._runtimeVersion.specVersion)
216
+ )
217
+ )
218
+ ? { apis: firstVersion.apis, specName: this._runtimeVersion.specName, specVersion: firstVersion.specVersion }
219
+ : await firstValueFrom(this._rpcCore.state.getRuntimeVersion.raw(header.parentHash))
220
+ );
221
+
222
+ return (
223
+ // try to find via version
224
+ this._getBlockRegistryViaVersion(blockHash, version) ||
225
+ // return new or in-flight result
226
+ await this._cacheBlockRegistryProgress(version.toHex(), () => this._createBlockRegistry(blockHash, header, version))
227
+ );
228
+ }
229
+
230
+ /**
231
+ * @description Sets up a registry based on the block hash defined
232
+ */
233
+ public async getBlockRegistry (blockHash: Uint8Array, knownVersion?: RuntimeVersion): Promise<VersionedRegistry<ApiType>> {
234
+ return (
235
+ // try to find via blockHash
236
+ this.#registries.find(({ lastBlockHash }) =>
237
+ lastBlockHash && u8aEq(lastBlockHash, blockHash)
238
+ ) ||
239
+ // try to find via version
240
+ this._getBlockRegistryViaVersion(blockHash, knownVersion) ||
241
+ // return new or in-flight result
242
+ await this._cacheBlockRegistryProgress(u8aToHex(blockHash), () => this._getBlockRegistryViaHash(blockHash))
243
+ );
244
+ }
245
+
246
+ protected async _loadMeta (): Promise<boolean> {
247
+ // on re-connection to the same chain, we don't want to re-do everything from chain again
248
+ if (this._isReady) {
249
+ // on re-connection only re-subscribe to chain updates if we are not a clone
250
+ if (!this._options.source) {
251
+ this._subscribeUpdates();
252
+ }
253
+
254
+ return true;
255
+ }
256
+
257
+ this._unsubscribeUpdates();
258
+
259
+ // only load from on-chain if we are not a clone (default path), alternatively
260
+ // just use the values from the source instance provided
261
+ [this._genesisHash, this._runtimeMetadata] = this._options.source?._isReady
262
+ ? await this._metaFromSource(this._options.source)
263
+ : await this._metaFromChain(this._options.metadata);
264
+
265
+ return this._initFromMeta(this._runtimeMetadata);
266
+ }
267
+
268
+ // eslint-disable-next-line @typescript-eslint/require-await
269
+ private async _metaFromSource (source: ApiBase<any>): Promise<[Hash, Metadata]> {
270
+ this._extrinsicType = source.extrinsicVersion;
271
+ this._runtimeChain = source.runtimeChain;
272
+ this._runtimeVersion = source.runtimeVersion;
273
+
274
+ // manually build a list of all available methods in this RPC, we are
275
+ // going to filter on it to align the cloned RPC without making a call
276
+ const sections = Object.keys(source.rpc);
277
+ const rpcs: string[] = [];
278
+
279
+ for (let s = 0, scount = sections.length; s < scount; s++) {
280
+ const section = sections[s];
281
+ const methods = Object.keys((source.rpc as unknown as Record<string, Record<string, unknown>>)[section]);
282
+
283
+ for (let m = 0, mcount = methods.length; m < mcount; m++) {
284
+ rpcs.push(`${section}_${methods[m]}`);
285
+ }
286
+ }
287
+
288
+ this._filterRpc(rpcs, getSpecRpc(this.registry, source.runtimeChain, source.runtimeVersion.specName));
289
+
290
+ return [source.genesisHash, source.runtimeMetadata];
291
+ }
292
+
293
+ // subscribe to metadata updates, inject the types on changes
294
+ private _subscribeUpdates (): void {
295
+ if (this.#updateSub || !this.hasSubscriptions) {
296
+ return;
297
+ }
298
+
299
+ this.#updateSub = this._rpcCore.state.subscribeRuntimeVersion().pipe(
300
+ switchMap((version: RuntimeVersion): Observable<boolean> =>
301
+ // only retrieve the metadata when the on-chain version has been changed
302
+ this._runtimeVersion?.specVersion.eq(version.specVersion)
303
+ ? of(false)
304
+ : this._rpcCore.state.getMetadata().pipe(
305
+ map((metadata: Metadata): boolean => {
306
+ l.log(`Runtime version updated to spec=${version.specVersion.toString()}, tx=${version.transactionVersion.toString()}`);
307
+
308
+ this._runtimeMetadata = metadata;
309
+ this._runtimeVersion = version;
310
+ this._rx.runtimeVersion = version;
311
+
312
+ // update the default registry version
313
+ const thisRegistry = this._getDefaultRegistry();
314
+ const runtimeChain = this._runtimeChain;
315
+
316
+ if (!runtimeChain) {
317
+ throw new Error('Invalid initializion order, runtimeChain is not available');
318
+ }
319
+
320
+ // setup the data as per the current versions
321
+ thisRegistry.metadata = metadata;
322
+ thisRegistry.runtimeVersion = version;
323
+
324
+ this._initRegistry(this.registry, runtimeChain, version, metadata);
325
+ this._injectMetadata(thisRegistry, true);
326
+
327
+ return true;
328
+ })
329
+ )
330
+ )
331
+ ).subscribe();
332
+ }
333
+
334
+ private async _metaFromChain (optMetadata?: Record<string, HexString>): Promise<[Hash, Metadata]> {
335
+ const [genesisHash, runtimeVersion, chain, chainProps, rpcMethods] = await Promise.all([
336
+ firstValueFrom(this._rpcCore.chain.getBlockHash(0)),
337
+ firstValueFrom(this._rpcCore.state.getRuntimeVersion()),
338
+ firstValueFrom(this._rpcCore.system.chain()),
339
+ firstValueFrom(this._rpcCore.system.properties()),
340
+ firstValueFrom(this._rpcCore.rpc.methods())
341
+ ]);
342
+
343
+ // set our chain version & genesisHash as returned
344
+ this._runtimeChain = chain;
345
+ this._runtimeVersion = runtimeVersion;
346
+ this._rx.runtimeVersion = runtimeVersion;
347
+
348
+ // retrieve metadata, either from chain or as pass-in via options
349
+ const metadataKey = `${genesisHash.toHex() || '0x'}-${runtimeVersion.specVersion.toString()}`;
350
+ const metadata = optMetadata?.[metadataKey]
351
+ ? new Metadata(this.registry, optMetadata[metadataKey])
352
+ : await this._retrieveMetadata(runtimeVersion.apis);
353
+
354
+ // initializes the registry & RPC
355
+ this._initRegistry(this.registry, chain, runtimeVersion, metadata, chainProps);
356
+ this._filterRpc(rpcMethods.methods.map(textToString), getSpecRpc(this.registry, chain, runtimeVersion.specName));
357
+ this._subscribeUpdates();
358
+
359
+ // setup the initial registry, when we have none
360
+ if (!this.#registries.length) {
361
+ this.#registries.push({ counter: 0, isDefault: true, metadata, registry: this.registry, runtimeVersion });
362
+ }
363
+
364
+ // get unique types & validate
365
+ metadata.getUniqTypes(this._options.throwOnUnknown || false);
366
+
367
+ return [genesisHash, metadata];
368
+ }
369
+
370
+ private _initFromMeta (metadata: Metadata): boolean {
371
+ const runtimeVersion = this._runtimeVersion;
372
+
373
+ if (!runtimeVersion) {
374
+ throw new Error('Invalid initializion order, runtimeVersion is not available');
375
+ }
376
+
377
+ // ExtrinsicV5 is not fully supported yet, for that reason we default to version 4
378
+ this._extrinsicType = metadata.asLatest.extrinsic.versions.at(0) || LATEST_EXTRINSIC_VERSION;
379
+ this._rx.extrinsicType = this._extrinsicType;
380
+ this._rx.genesisHash = this._genesisHash;
381
+ this._rx.runtimeVersion = runtimeVersion;
382
+
383
+ // inject metadata and adjust the types as detected
384
+ this._injectMetadata(this._getDefaultRegistry(), true);
385
+
386
+ // derive is last, since it uses the decorated rx
387
+ this._rx.derive = this._decorateDeriveRx(this._rxDecorateMethod);
388
+ this._derive = this._decorateDerive(this._decorateMethod);
389
+
390
+ return true;
391
+ }
392
+
393
+ /**
394
+ * @internal
395
+ *
396
+ * Tries to use runtime api calls to retrieve metadata. This ensures the api initializes with the latest metadata.
397
+ * If the runtime call is not there it will use the rpc method.
398
+ */
399
+ private async _retrieveMetadata (apis: Vec<RuntimeVersionApi>, at?: BlockHash | string | Uint8Array, registry?: TypeRegistry): Promise<Metadata> {
400
+ let metadataVersion: u32 | null = null;
401
+ const metadataApi = apis.find(([a]) => a.eq(blake2AsHex('Metadata', 64)));
402
+ const typeRegistry = registry || this.registry;
403
+
404
+ // This chain does not have support for the metadataApi, or does not have the required version.
405
+ if (!metadataApi || metadataApi[1].toNumber() < 2) {
406
+ l.warn('MetadataApi not available, rpc::state::get_metadata will be used.');
407
+
408
+ return at
409
+ ? new Metadata(typeRegistry, await firstValueFrom(this._rpcCore.state.getMetadata.raw<HexString>(at)))
410
+ : await firstValueFrom(this._rpcCore.state.getMetadata());
411
+ }
412
+
413
+ try {
414
+ const metadataVersionsAsBytes = at
415
+ ? await firstValueFrom(this._rpcCore.state.call.raw('Metadata_metadata_versions', '0x', at))
416
+ : await firstValueFrom(this._rpcCore.state.call('Metadata_metadata_versions', '0x'));
417
+ const versions = typeRegistry.createType('Vec<u32>', metadataVersionsAsBytes);
418
+
419
+ // For unstable versions of the metadata the last value is set to u32 MAX in the runtime. This ensures only supported stable versions are used.
420
+ metadataVersion = versions.filter((ver) => SUPPORTED_METADATA_VERSIONS.includes(ver.toNumber())).reduce((largest, current) => current.gt(largest) ? current : largest);
421
+ } catch (e) {
422
+ l.debug((e as Error).message);
423
+ l.warn('error with state_call::Metadata_metadata_versions, rpc::state::get_metadata will be used');
424
+ }
425
+
426
+ // When the metadata version does not align with the latest supported versions we ensure not to call the metadata runtime call.
427
+ // I noticed on some previous runtimes that have support for `Metadata_metadata_at_version` that very irregular versions were being returned.
428
+ // This was evident with runtime 1000000 - it return a very large number. This ensures we always stick within what is supported.
429
+ if (metadataVersion && !SUPPORTED_METADATA_VERSIONS.includes(metadataVersion.toNumber())) {
430
+ metadataVersion = null;
431
+ }
432
+
433
+ if (metadataVersion) {
434
+ try {
435
+ const metadataBytes = at
436
+ ? await firstValueFrom(this._rpcCore.state.call.raw<Bytes>('Metadata_metadata_at_version', u8aToHex(metadataVersion.toU8a()), at))
437
+ : await firstValueFrom(this._rpcCore.state.call('Metadata_metadata_at_version', u8aToHex(metadataVersion.toU8a())));
438
+ // When the metadata is called with `at` it is required to use `.raw`. Therefore since the length prefix is not present the
439
+ // need to create a `Raw` type is necessary before creating the `OpaqueMetadata` type or else there will be a magic number
440
+ // mismatch
441
+ const rawMeta = at
442
+ ? typeRegistry.createType('Raw', metadataBytes).toU8a()
443
+ : metadataBytes;
444
+ const opaqueMetadata = typeRegistry.createType('Option<OpaqueMetadata>', rawMeta).unwrapOr(null);
445
+
446
+ if (opaqueMetadata) {
447
+ return new Metadata(typeRegistry, opaqueMetadata.toHex());
448
+ }
449
+ } catch (e) {
450
+ l.debug((e as Error).message);
451
+ l.warn('error with state_call::Metadata_metadata_at_version, rpc::state::get_metadata will be used');
452
+ }
453
+ }
454
+
455
+ return at
456
+ ? new Metadata(typeRegistry, await firstValueFrom(this._rpcCore.state.getMetadata.raw<HexString>(at)))
457
+ : await firstValueFrom(this._rpcCore.state.getMetadata());
458
+ }
459
+
460
+ private _subscribeHealth (): void {
461
+ this._unsubscribeHealth();
462
+
463
+ // Only enable the health keepalive on WS, not needed on HTTP
464
+ this.#healthTimer = this.hasSubscriptions
465
+ ? setInterval((): void => {
466
+ firstValueFrom(this._rpcCore.system.health.raw()).catch(noop);
467
+ }, KEEPALIVE_INTERVAL)
468
+ : null;
469
+ }
470
+
471
+ private _unsubscribeHealth (): void {
472
+ if (this.#healthTimer) {
473
+ clearInterval(this.#healthTimer);
474
+ this.#healthTimer = null;
475
+ }
476
+ }
477
+
478
+ private _unsubscribeUpdates (): void {
479
+ if (this.#updateSub) {
480
+ this.#updateSub.unsubscribe();
481
+ this.#updateSub = null;
482
+ }
483
+ }
484
+
485
+ protected _unsubscribe (): void {
486
+ this._unsubscribeHealth();
487
+ this._unsubscribeUpdates();
488
+ }
489
+
490
+ async #onProviderConnect (): Promise<void> {
491
+ this._isConnected.next(true);
492
+ this.emit('connected');
493
+
494
+ try {
495
+ const cryptoReady = this._options.initWasm === false
496
+ ? true
497
+ : await cryptoWaitReady();
498
+ const hasMeta = await this._loadMeta();
499
+
500
+ this._subscribeHealth();
501
+
502
+ if (hasMeta && !this._isReady && cryptoReady) {
503
+ this._isReady = true;
504
+
505
+ this.emit('ready', this);
506
+ }
507
+ } catch (_error) {
508
+ const error = new Error(`FATAL: Unable to initialize the API: ${(_error as Error).message}`);
509
+
510
+ l.error(error);
511
+
512
+ this.emit('error', error);
513
+ }
514
+ }
515
+
516
+ #onProviderDisconnect (): void {
517
+ this._isConnected.next(false);
518
+ this._unsubscribe();
519
+ this.emit('disconnected');
520
+ }
521
+
522
+ #onProviderError (error: Error): void {
523
+ this.emit('error', error);
524
+ }
525
+ }
@@ -0,0 +1,14 @@
1
+ // Copyright 2017-2025 @pezkuwi/api authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { CallFunction, Registry, RegistryError } from '@pezkuwi/types/types';
5
+
6
+ import { u8aToU8a } from '@pezkuwi/util';
7
+
8
+ export function findCall (registry: Registry, callIndex: Uint8Array | string): CallFunction {
9
+ return registry.findMetaCall(u8aToU8a(callIndex));
10
+ }
11
+
12
+ export function findError (registry: Registry, errorIndex: Uint8Array | string): RegistryError {
13
+ return registry.findMetaError(u8aToU8a(errorIndex));
14
+ }
@@ -0,0 +1,85 @@
1
+ // Copyright 2017-2025 @pezkuwi/api authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { SignerPayloadRawBase } from '@pezkuwi/types/types';
5
+ import type { ApiOptions, ApiTypes, DecorateMethod, Signer } from '../types/index.js';
6
+
7
+ import { isString, objectSpread, u8aToHex, u8aToU8a } from '@pezkuwi/util';
8
+
9
+ import { Getters } from './Getters.js';
10
+
11
+ interface KeyringSigner {
12
+ sign (message: Uint8Array): Uint8Array;
13
+ }
14
+
15
+ interface SignerRawOptions {
16
+ signer?: Signer;
17
+ }
18
+
19
+ export abstract class ApiBase<ApiType extends ApiTypes> extends Getters<ApiType> {
20
+ /**
21
+ * @description Create an instance of the class
22
+ *
23
+ * @param options Options object to create API instance or a Provider instance
24
+ *
25
+ * @example
26
+ * <BR>
27
+ *
28
+ * ```javascript
29
+ * import Api from '@pezkuwi/api/promise';
30
+ *
31
+ * const api = new Api().isReady();
32
+ *
33
+ * api.rpc.subscribeNewHeads((header) => {
34
+ * console.log(`new block #${header.number.toNumber()}`);
35
+ * });
36
+ * ```
37
+ */
38
+ constructor (options: ApiOptions = {}, type: ApiTypes, decorateMethod: DecorateMethod<ApiType>) {
39
+ super(options, type, decorateMethod);
40
+ }
41
+
42
+ /**
43
+ * @description Connect from the underlying provider, halting all network traffic
44
+ */
45
+ public connect (): Promise<void> {
46
+ return this._rpcCore.connect();
47
+ }
48
+
49
+ /**
50
+ * @description Disconnect from the underlying provider, halting all network traffic
51
+ */
52
+ public disconnect (): Promise<void> {
53
+ this._unsubscribe();
54
+
55
+ return this._rpcCore.disconnect();
56
+ }
57
+
58
+ /**
59
+ * @description Set an external signer which will be used to sign extrinsic when account passed in is not KeyringPair
60
+ */
61
+ public setSigner (signer: Signer | undefined): void {
62
+ this._rx.signer = signer;
63
+ }
64
+
65
+ /**
66
+ * @description Signs a raw signer payload, string or Uint8Array
67
+ */
68
+ public async sign (address: KeyringSigner | string, data: SignerPayloadRawBase, { signer }: SignerRawOptions = {}): Promise<string> {
69
+ if (isString(address)) {
70
+ const _signer = signer || this._rx.signer;
71
+
72
+ if (!_signer?.signRaw) {
73
+ throw new Error('No signer exists with a signRaw interface. You possibly need to pass through an explicit keypair for the origin so it can be used for signing.');
74
+ }
75
+
76
+ return (
77
+ await _signer.signRaw(
78
+ objectSpread({ type: 'bytes' }, data, { address })
79
+ )
80
+ ).signature;
81
+ }
82
+
83
+ return u8aToHex(address.sign(u8aToU8a(data.data)));
84
+ }
85
+ }
@@ -0,0 +1,19 @@
1
+ // Copyright 2017-2025 @pezkuwi/api authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { Metadata } from '@pezkuwi/types';
5
+ import type { RuntimeVersionPartial } from '@pezkuwi/types/interfaces';
6
+ import type { DecoratedMeta } from '@pezkuwi/types/metadata/decorate/types';
7
+ import type { Registry } from '@pezkuwi/types/types';
8
+ import type { ApiDecoration, ApiTypes } from '../types/index.js';
9
+
10
+ export interface VersionedRegistry<ApiType extends ApiTypes> {
11
+ counter: number;
12
+ decoratedApi?: ApiDecoration<ApiType>;
13
+ decoratedMeta?: DecoratedMeta;
14
+ isDefault?: boolean;
15
+ lastBlockHash?: Uint8Array | null;
16
+ metadata: Metadata;
17
+ registry: Registry;
18
+ runtimeVersion: RuntimeVersionPartial;
19
+ }
package/src/bundle.ts ADDED
@@ -0,0 +1,16 @@
1
+ // Copyright 2017-2025 @pezkuwi/api authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import '@pezkuwi/rpc-augment';
5
+
6
+ // all external
7
+ export { Keyring } from '@pezkuwi/keyring';
8
+ export { HttpProvider, ScProvider, WsProvider } from '@pezkuwi/rpc-provider';
9
+
10
+ // all named
11
+ export { packageInfo } from './packageInfo.js';
12
+ export { SubmittableResult } from './submittable/index.js';
13
+
14
+ // all starred
15
+ export * from './promise/index.js';
16
+ export * from './rx/index.js';