@pezkuwi/api-derive 16.5.5

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 (304) hide show
  1. package/README.md +30 -0
  2. package/build/accounts/accountId.d.ts +17 -0
  3. package/build/accounts/flags.d.ts +29 -0
  4. package/build/accounts/idAndIndex.d.ts +15 -0
  5. package/build/accounts/idToIndex.d.ts +16 -0
  6. package/build/accounts/identity.d.ts +48 -0
  7. package/build/accounts/index.d.ts +8 -0
  8. package/build/accounts/indexToId.d.ts +15 -0
  9. package/build/accounts/indexes.d.ts +16 -0
  10. package/build/accounts/info.d.ts +18 -0
  11. package/build/accounts/types.d.ts +39 -0
  12. package/build/alliance/index.d.ts +70 -0
  13. package/build/augment.d.ts +1 -0
  14. package/build/bagsList/get.d.ts +12 -0
  15. package/build/bagsList/getExpanded.d.ts +16 -0
  16. package/build/bagsList/index.d.ts +3 -0
  17. package/build/bagsList/listNodes.d.ts +9 -0
  18. package/build/bagsList/types.d.ts +13 -0
  19. package/build/bagsList/util.d.ts +2 -0
  20. package/build/balances/account.d.ts +17 -0
  21. package/build/balances/all.d.ts +20 -0
  22. package/build/balances/index.d.ts +20 -0
  23. package/build/balances/types.d.ts +69 -0
  24. package/build/balances/votingBalances.d.ts +15 -0
  25. package/build/bounties/bounties.d.ts +12 -0
  26. package/build/bounties/helpers/filterBountyProposals.d.ts +2 -0
  27. package/build/bounties/index.d.ts +1 -0
  28. package/build/bundle.d.ts +9 -0
  29. package/build/chain/bestNumber.d.ts +11 -0
  30. package/build/chain/bestNumberFinalized.d.ts +12 -0
  31. package/build/chain/bestNumberLag.d.ts +15 -0
  32. package/build/chain/getBlock.d.ts +15 -0
  33. package/build/chain/getBlockByNumber.d.ts +16 -0
  34. package/build/chain/getHeader.d.ts +16 -0
  35. package/build/chain/index.d.ts +10 -0
  36. package/build/chain/subscribeFinalizedBlocks.d.ts +14 -0
  37. package/build/chain/subscribeFinalizedHeads.d.ts +22 -0
  38. package/build/chain/subscribeNewBlocks.d.ts +14 -0
  39. package/build/chain/subscribeNewHeads.d.ts +15 -0
  40. package/build/chain/util.d.ts +9 -0
  41. package/build/collective/helpers.d.ts +6 -0
  42. package/build/collective/index.d.ts +3 -0
  43. package/build/collective/members.d.ts +2 -0
  44. package/build/collective/prime.d.ts +2 -0
  45. package/build/collective/proposals.d.ts +6 -0
  46. package/build/collective/types.d.ts +19 -0
  47. package/build/contracts/fees.d.ts +14 -0
  48. package/build/contracts/index.d.ts +1 -0
  49. package/build/council/index.d.ts +72 -0
  50. package/build/council/types.d.ts +6 -0
  51. package/build/council/votes.d.ts +11 -0
  52. package/build/council/votesOf.d.ts +16 -0
  53. package/build/crowdloan/childKey.d.ts +15 -0
  54. package/build/crowdloan/contributions.d.ts +14 -0
  55. package/build/crowdloan/index.d.ts +3 -0
  56. package/build/crowdloan/ownContributions.d.ts +15 -0
  57. package/build/crowdloan/types.d.ts +6 -0
  58. package/build/crowdloan/util.d.ts +10 -0
  59. package/build/democracy/dispatchQueue.d.ts +12 -0
  60. package/build/democracy/index.d.ts +11 -0
  61. package/build/democracy/locks.d.ts +14 -0
  62. package/build/democracy/nextExternal.d.ts +12 -0
  63. package/build/democracy/preimages.d.ts +24 -0
  64. package/build/democracy/proposals.d.ts +12 -0
  65. package/build/democracy/referendumIds.d.ts +12 -0
  66. package/build/democracy/referendums.d.ts +11 -0
  67. package/build/democracy/referendumsActive.d.ts +12 -0
  68. package/build/democracy/referendumsFinished.d.ts +15 -0
  69. package/build/democracy/referendumsInfo.d.ts +23 -0
  70. package/build/democracy/sqrtElectorate.d.ts +13 -0
  71. package/build/democracy/types.d.ts +70 -0
  72. package/build/democracy/util.d.ts +18 -0
  73. package/build/derive.d.ts +52 -0
  74. package/build/elections/index.d.ts +1 -0
  75. package/build/elections/info.d.ts +14 -0
  76. package/build/elections/types.d.ts +18 -0
  77. package/build/imOnline/index.d.ts +1 -0
  78. package/build/imOnline/receivedHeartbeats.d.ts +13 -0
  79. package/build/index.d.ts +2 -0
  80. package/build/membership/index.d.ts +70 -0
  81. package/build/packageDetect.d.ts +1 -0
  82. package/build/packageInfo.d.ts +6 -0
  83. package/build/parachains/index.d.ts +2 -0
  84. package/build/parachains/info.d.ts +19 -0
  85. package/build/parachains/overview.d.ts +15 -0
  86. package/build/parachains/types.d.ts +38 -0
  87. package/build/parachains/util.d.ts +3 -0
  88. package/build/session/index.d.ts +3 -0
  89. package/build/session/indexes.d.ts +15 -0
  90. package/build/session/info.d.ts +13 -0
  91. package/build/session/progress.d.ts +47 -0
  92. package/build/session/types.d.ts +19 -0
  93. package/build/society/candidates.d.ts +12 -0
  94. package/build/society/index.d.ts +4 -0
  95. package/build/society/info.d.ts +12 -0
  96. package/build/society/member.d.ts +14 -0
  97. package/build/society/members.d.ts +14 -0
  98. package/build/society/types.d.ts +27 -0
  99. package/build/staking/account.d.ts +31 -0
  100. package/build/staking/cache.d.ts +12 -0
  101. package/build/staking/currentPoints.d.ts +13 -0
  102. package/build/staking/electedInfo.d.ts +23 -0
  103. package/build/staking/erasExposure.d.ts +30 -0
  104. package/build/staking/erasHistoric.d.ts +8 -0
  105. package/build/staking/erasPoints.d.ts +18 -0
  106. package/build/staking/erasPrefs.d.ts +27 -0
  107. package/build/staking/erasRewards.d.ts +14 -0
  108. package/build/staking/erasSlashes.d.ts +26 -0
  109. package/build/staking/index.d.ts +22 -0
  110. package/build/staking/keys.d.ts +35 -0
  111. package/build/staking/overview.d.ts +19 -0
  112. package/build/staking/ownExposure.d.ts +37 -0
  113. package/build/staking/ownSlashes.d.ts +35 -0
  114. package/build/staking/query.d.ts +31 -0
  115. package/build/staking/stakerExposure.d.ts +33 -0
  116. package/build/staking/stakerPoints.d.ts +22 -0
  117. package/build/staking/stakerPrefs.d.ts +24 -0
  118. package/build/staking/stakerRewards.d.ts +49 -0
  119. package/build/staking/stakerSlashes.d.ts +22 -0
  120. package/build/staking/stashes.d.ts +16 -0
  121. package/build/staking/types.d.ts +139 -0
  122. package/build/staking/util.d.ts +14 -0
  123. package/build/staking/validators.d.ts +33 -0
  124. package/build/staking/waitingInfo.d.ts +16 -0
  125. package/build/technicalCommittee/index.d.ts +70 -0
  126. package/build/treasury/index.d.ts +1 -0
  127. package/build/treasury/proposals.d.ts +12 -0
  128. package/build/tx/constants.d.ts +5 -0
  129. package/build/tx/events.d.ts +22 -0
  130. package/build/tx/extrinsicInfo.d.ts +61 -0
  131. package/build/tx/index.d.ts +3 -0
  132. package/build/tx/signingInfo.d.ts +25 -0
  133. package/build/type/HeaderExtended.d.ts +4 -0
  134. package/build/type/SignedBlockExtended.d.ts +4 -0
  135. package/build/type/index.d.ts +2 -0
  136. package/build/type/types.d.ts +15 -0
  137. package/build/type/util.d.ts +2 -0
  138. package/build/types.d.ts +79 -0
  139. package/build/util/approvalFlagsToBools.d.ts +4 -0
  140. package/build/util/blockNumber.d.ts +7 -0
  141. package/build/util/cache.d.ts +4 -0
  142. package/build/util/cacheImpl.d.ts +3 -0
  143. package/build/util/first.d.ts +4 -0
  144. package/build/util/index.d.ts +7 -0
  145. package/build/util/lazy.d.ts +4 -0
  146. package/build/util/types.d.ts +6 -0
  147. package/package.json +42 -0
  148. package/src/accounts/accountId.ts +44 -0
  149. package/src/accounts/flags.ts +90 -0
  150. package/src/accounts/idAndIndex.ts +51 -0
  151. package/src/accounts/idToIndex.ts +31 -0
  152. package/src/accounts/identity.ts +235 -0
  153. package/src/accounts/index.ts +11 -0
  154. package/src/accounts/indexToId.ts +33 -0
  155. package/src/accounts/indexes.ts +56 -0
  156. package/src/accounts/info.ts +58 -0
  157. package/src/accounts/types.ts +48 -0
  158. package/src/alliance/index.ts +76 -0
  159. package/src/augment.ts +4 -0
  160. package/src/bagsList/get.ts +79 -0
  161. package/src/bagsList/getExpanded.ts +41 -0
  162. package/src/bagsList/index.ts +6 -0
  163. package/src/bagsList/listNodes.ts +50 -0
  164. package/src/bagsList/types.ts +18 -0
  165. package/src/bagsList/util.ts +14 -0
  166. package/src/balances/account.ts +210 -0
  167. package/src/balances/all.ts +246 -0
  168. package/src/balances/index.ts +26 -0
  169. package/src/balances/types.ts +79 -0
  170. package/src/balances/votingBalances.ts +33 -0
  171. package/src/bounties/bounties.spec.ts +162 -0
  172. package/src/bounties/bounties.ts +76 -0
  173. package/src/bounties/helpers/filterBountyProposals.ts +13 -0
  174. package/src/bounties/index.ts +4 -0
  175. package/src/bundle.ts +140 -0
  176. package/src/chain/bestNumber.ts +21 -0
  177. package/src/chain/bestNumberFinalized.ts +22 -0
  178. package/src/chain/bestNumberLag.ts +33 -0
  179. package/src/chain/getBlock.ts +43 -0
  180. package/src/chain/getBlockByNumber.ts +30 -0
  181. package/src/chain/getHeader.ts +37 -0
  182. package/src/chain/index.ts +13 -0
  183. package/src/chain/subscribeFinalizedBlocks.ts +30 -0
  184. package/src/chain/subscribeFinalizedHeads.ts +62 -0
  185. package/src/chain/subscribeNewBlocks.ts +30 -0
  186. package/src/chain/subscribeNewHeads.ts +38 -0
  187. package/src/chain/util.ts +112 -0
  188. package/src/checkTypes.manual.ts +8 -0
  189. package/src/collective/helpers.ts +36 -0
  190. package/src/collective/index.ts +6 -0
  191. package/src/collective/members.ts +8 -0
  192. package/src/collective/prime.ts +25 -0
  193. package/src/collective/proposals.ts +73 -0
  194. package/src/collective/types.ts +30 -0
  195. package/src/contracts/fees.ts +61 -0
  196. package/src/contracts/index.ts +4 -0
  197. package/src/council/index.ts +79 -0
  198. package/src/council/types.ts +11 -0
  199. package/src/council/votes.ts +97 -0
  200. package/src/council/votesOf.ts +35 -0
  201. package/src/crowdloan/childKey.ts +57 -0
  202. package/src/crowdloan/contributions.ts +142 -0
  203. package/src/crowdloan/index.ts +6 -0
  204. package/src/crowdloan/ownContributions.ts +81 -0
  205. package/src/crowdloan/types.ts +11 -0
  206. package/src/crowdloan/util.ts +33 -0
  207. package/src/democracy/dispatchQueue.ts +158 -0
  208. package/src/democracy/index.ts +14 -0
  209. package/src/democracy/locks.ts +114 -0
  210. package/src/democracy/nextExternal.ts +49 -0
  211. package/src/democracy/preimages.ts +171 -0
  212. package/src/democracy/proposals.ts +81 -0
  213. package/src/democracy/referendumIds.ts +37 -0
  214. package/src/democracy/referendums.ts +39 -0
  215. package/src/democracy/referendumsActive.ts +30 -0
  216. package/src/democracy/referendumsFinished.ts +37 -0
  217. package/src/democracy/referendumsInfo.ts +181 -0
  218. package/src/democracy/sqrtElectorate.ts +29 -0
  219. package/src/democracy/types.ts +84 -0
  220. package/src/democracy/util.ts +166 -0
  221. package/src/derive.ts +41 -0
  222. package/src/elections/index.ts +4 -0
  223. package/src/elections/info.ts +126 -0
  224. package/src/elections/types.ts +22 -0
  225. package/src/imOnline/index.ts +4 -0
  226. package/src/imOnline/receivedHeartbeats.ts +65 -0
  227. package/src/index.spec.ts +103 -0
  228. package/src/index.ts +6 -0
  229. package/src/membership/index.ts +76 -0
  230. package/src/mod.ts +4 -0
  231. package/src/packageDetect.ts +11 -0
  232. package/src/packageInfo.ts +6 -0
  233. package/src/parachains/index.ts +5 -0
  234. package/src/parachains/info.ts +111 -0
  235. package/src/parachains/overview.ts +63 -0
  236. package/src/parachains/types.ts +46 -0
  237. package/src/parachains/util.ts +11 -0
  238. package/src/session/index.ts +6 -0
  239. package/src/session/indexes.ts +90 -0
  240. package/src/session/info.ts +39 -0
  241. package/src/session/progress.ts +130 -0
  242. package/src/session/types.ts +25 -0
  243. package/src/society/candidates.ts +71 -0
  244. package/src/society/index.ts +7 -0
  245. package/src/society/info.ts +50 -0
  246. package/src/society/member.ts +28 -0
  247. package/src/society/members.ts +107 -0
  248. package/src/society/types.ts +33 -0
  249. package/src/staking/account.ts +112 -0
  250. package/src/staking/cache.ts +48 -0
  251. package/src/staking/currentPoints.ts +28 -0
  252. package/src/staking/electedInfo.ts +54 -0
  253. package/src/staking/erasExposure.ts +105 -0
  254. package/src/staking/erasHistoric.ts +47 -0
  255. package/src/staking/erasPoints.ts +67 -0
  256. package/src/staking/erasPrefs.ts +63 -0
  257. package/src/staking/erasRewards.ts +52 -0
  258. package/src/staking/erasSlashes.ts +69 -0
  259. package/src/staking/index.ts +25 -0
  260. package/src/staking/keys.ts +86 -0
  261. package/src/staking/overview.ts +42 -0
  262. package/src/staking/ownExposure.ts +83 -0
  263. package/src/staking/ownSlashes.ts +68 -0
  264. package/src/staking/query.ts +230 -0
  265. package/src/staking/stakerExposure.ts +78 -0
  266. package/src/staking/stakerPoints.ts +46 -0
  267. package/src/staking/stakerPrefs.ts +45 -0
  268. package/src/staking/stakerRewards.ts +298 -0
  269. package/src/staking/stakerSlashes.ts +45 -0
  270. package/src/staking/stashes.ts +55 -0
  271. package/src/staking/types.ts +174 -0
  272. package/src/staking/util.ts +94 -0
  273. package/src/staking/validators.ts +82 -0
  274. package/src/staking/waitingInfo.ts +45 -0
  275. package/src/technicalCommittee/index.ts +76 -0
  276. package/src/test/bountyFactory.ts +39 -0
  277. package/src/test/bytesFactory.ts +15 -0
  278. package/src/test/helpers.ts +23 -0
  279. package/src/test/proposalFactory.ts +25 -0
  280. package/src/treasury/index.ts +4 -0
  281. package/src/treasury/proposals.ts +109 -0
  282. package/src/tx/constants.ts +13 -0
  283. package/src/tx/events.ts +43 -0
  284. package/src/tx/extrinsicInfo.ts +123 -0
  285. package/src/tx/index.ts +6 -0
  286. package/src/tx/signingInfo.ts +129 -0
  287. package/src/type/HeaderExtended.ts +33 -0
  288. package/src/type/SignedBlockExtended.ts +75 -0
  289. package/src/type/index.ts +5 -0
  290. package/src/type/types.ts +21 -0
  291. package/src/type/util.ts +45 -0
  292. package/src/types.ts +97 -0
  293. package/src/util/approvalFlagToBools.spec.ts +37 -0
  294. package/src/util/approvalFlagsToBools.ts +26 -0
  295. package/src/util/blockNumber.ts +15 -0
  296. package/src/util/cache.ts +65 -0
  297. package/src/util/cacheImpl.ts +30 -0
  298. package/src/util/first.ts +20 -0
  299. package/src/util/index.ts +13 -0
  300. package/src/util/lazy.ts +16 -0
  301. package/src/util/types.ts +9 -0
  302. package/tsconfig.build.json +21 -0
  303. package/tsconfig.build.tsbuildinfo +1 -0
  304. package/tsconfig.spec.json +27 -0
@@ -0,0 +1,235 @@
1
+ // Copyright 2017-2025 @polkadot/api-derive authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { Observable } from 'rxjs';
5
+ import type { Bytes, Data, Struct } from '@pezkuwi/types';
6
+ import type { AccountId, H160 } from '@pezkuwi/types/interfaces';
7
+ import type { PalletIdentityLegacyIdentityInfo, PalletIdentityRegistration } from '@pezkuwi/types/lookup';
8
+ import type { Option } from '@pezkuwi/types-codec';
9
+ import type { ITuple } from '@pezkuwi/types-codec/types';
10
+ import type { DeriveAccountRegistration, DeriveApi, DeriveHasIdentity } from '../types.js';
11
+
12
+ import { combineLatest, map, of, switchMap } from 'rxjs';
13
+
14
+ import { isHex, u8aToString } from '@pezkuwi/util';
15
+
16
+ import { firstMemo, memo } from '../util/index.js';
17
+
18
+ type IdentityInfoAdditional = PalletIdentityLegacyIdentityInfo['additional'][0];
19
+
20
+ interface PeopleIdentityInfo extends Struct {
21
+ display: Data;
22
+ legal: Data;
23
+ web: Data;
24
+ matrix: Data;
25
+ email: Data;
26
+ pgpFingerprint: Option<H160>;
27
+ image: Data;
28
+ twitter: Data;
29
+ github: Data;
30
+ discord: Data;
31
+ }
32
+
33
+ const UNDEF_HEX = { toHex: () => undefined };
34
+
35
+ function dataAsString (data: Data): string | undefined {
36
+ if (!data) {
37
+ return data;
38
+ }
39
+
40
+ return data.isRaw
41
+ ? u8aToString(data.asRaw.toU8a(true))
42
+ : data.isNone
43
+ ? undefined
44
+ : data.toHex();
45
+ }
46
+
47
+ function extractOther (additional: IdentityInfoAdditional[]): Record<string, string> {
48
+ return additional.reduce((other: Record<string, string>, [_key, _value]): Record<string, string> => {
49
+ const key = dataAsString(_key);
50
+ const value = dataAsString(_value);
51
+
52
+ if (key && value) {
53
+ other[key] = value;
54
+ }
55
+
56
+ return other;
57
+ }, {});
58
+ }
59
+
60
+ // handle compatibility between generations of structures
61
+ function identityCompat (identityOfOpt: Option<ITuple<[PalletIdentityRegistration, Option<Bytes>]>> | Option<PalletIdentityRegistration>): PalletIdentityRegistration {
62
+ const identity = identityOfOpt.unwrap();
63
+
64
+ return Array.isArray(identity)
65
+ ? identity[0]
66
+ : identity;
67
+ }
68
+
69
+ function extractIdentity (identityOfOpt?: Option<ITuple<[PalletIdentityRegistration, Option<Bytes>]>> | Option<PalletIdentityRegistration>, superOf?: [AccountId, Data]): DeriveAccountRegistration {
70
+ if (!identityOfOpt?.isSome) {
71
+ return { judgements: [] };
72
+ }
73
+
74
+ const { info, judgements } = identityCompat(identityOfOpt);
75
+ const topDisplay = dataAsString(info.display);
76
+
77
+ return {
78
+ discord: dataAsString((info as unknown as PeopleIdentityInfo).discord),
79
+ display: (superOf && dataAsString(superOf[1])) || topDisplay,
80
+ displayParent: superOf && topDisplay,
81
+ email: dataAsString(info.email),
82
+ github: dataAsString((info as unknown as PeopleIdentityInfo).github),
83
+ image: dataAsString(info.image),
84
+ judgements,
85
+ legal: dataAsString(info.legal),
86
+ matrix: dataAsString((info as unknown as PeopleIdentityInfo).matrix),
87
+ other: info.additional ? extractOther(info.additional) : {},
88
+ parent: superOf?.[0],
89
+ pgp: info.pgpFingerprint.unwrapOr(UNDEF_HEX).toHex(),
90
+ riot: dataAsString(info.riot),
91
+ twitter: dataAsString(info.twitter),
92
+ web: dataAsString(info.web)
93
+ };
94
+ }
95
+
96
+ function getParent (api: DeriveApi, identityOfOpt: Option<ITuple<[PalletIdentityRegistration, Option<Bytes>]>> | Option<PalletIdentityRegistration> | undefined, superOfOpt: Option<ITuple<[AccountId, Data]>> | undefined): Observable<[Option<ITuple<[PalletIdentityRegistration, Option<Bytes>]>> | Option<PalletIdentityRegistration> | undefined, [AccountId, Data] | undefined]> {
97
+ if (identityOfOpt?.isSome) {
98
+ // this identity has something set
99
+ return of([identityOfOpt, undefined]);
100
+ } else if (superOfOpt?.isSome) {
101
+ const superOf = superOfOpt.unwrap();
102
+
103
+ return combineLatest([
104
+ api.derive.accounts._identity(superOf[0]).pipe(
105
+ map(([info]) => info)
106
+ ),
107
+ of(superOf)
108
+ ]);
109
+ }
110
+
111
+ // nothing of value returned
112
+ return of([undefined, undefined]);
113
+ }
114
+
115
+ export function _identity (instanceId: string, api: DeriveApi): (accountId?: AccountId | Uint8Array | string) => Observable<[Option<ITuple<[PalletIdentityRegistration, Option<Bytes>]>> | Option<PalletIdentityRegistration> | undefined, Option<ITuple<[AccountId, Data]>> | undefined]> {
116
+ return memo(instanceId, (accountId?: AccountId | Uint8Array | string): Observable<[Option<ITuple<[PalletIdentityRegistration, Option<Bytes>]>> | Option<PalletIdentityRegistration> | undefined, Option<ITuple<[AccountId, Data]>> | undefined]> =>
117
+ accountId && api.query.identity?.identityOf
118
+ ? combineLatest([
119
+ api.query.identity.identityOf(accountId),
120
+ api.query.identity.superOf(accountId)
121
+ ])
122
+ : of([undefined, undefined])
123
+ );
124
+ }
125
+
126
+ /**
127
+ * @name identity
128
+ * @description Retrieves the on chain identity information for a given account.
129
+ * @param {(AccountId | Uint8Array | string)} accoutId The account identifier to query the identity for.
130
+ * @example
131
+ * ```javascript
132
+ * const ALICE = "13xAUH";
133
+ *
134
+ * api.derive.accounts.identity(ALICE, (identity) => {
135
+ * console.log(
136
+ * "Account Identity:",
137
+ * Object.keys(identity).map((key) => `${key}: ${identity[key]}`)
138
+ * );
139
+ * });
140
+ * ```
141
+ */
142
+ export function identity (instanceId: string, api: DeriveApi): (accountId?: AccountId | Uint8Array | string) => Observable<DeriveAccountRegistration> {
143
+ return memo(instanceId, (accountId?: AccountId | Uint8Array | string): Observable<DeriveAccountRegistration> =>
144
+ api.derive.accounts._identity(accountId).pipe(
145
+ switchMap(([identityOfOpt, superOfOpt]) =>
146
+ getParent(api, identityOfOpt, superOfOpt)
147
+ ),
148
+ map(([identityOfOpt, superOf]) =>
149
+ extractIdentity(identityOfOpt, superOf)
150
+ ),
151
+ switchMap((identity) =>
152
+ getSubIdentities(identity, api, accountId)
153
+ )
154
+ )
155
+ );
156
+ }
157
+
158
+ // if an account has no parents it will extract its subidentities
159
+ // otherwise if the account is a subidentity, obtain all subidentities of its parent.
160
+ function getSubIdentities (identity: DeriveAccountRegistration, api: DeriveApi, accountId?: AccountId | Uint8Array | string): Observable<DeriveAccountRegistration> {
161
+ const targetAccount = identity.parent || accountId;
162
+
163
+ if (!targetAccount || !api.query.identity) {
164
+ // No valid accountId return the identity as-is
165
+ return of(identity);
166
+ }
167
+
168
+ return api.query.identity.subsOf(targetAccount).pipe(
169
+ map((subsResponse) => {
170
+ const subs = subsResponse[1];
171
+
172
+ return {
173
+ ...identity,
174
+ subs
175
+ };
176
+ })
177
+ );
178
+ }
179
+
180
+ /**
181
+ * @name hasIdentity
182
+ * @description Checks if a specific account has an identity registered on chain.
183
+ * @param {(AccountId | Uint8Array | string)} accoutId The account identifier to query.
184
+ * @example
185
+ * ```javascript
186
+ * const ALICE = "13AU";
187
+ * console.log(await api.derive.accounts.hasIdentity(ALICE));
188
+ * ```
189
+ */
190
+ export const hasIdentity = /*#__PURE__*/ firstMemo(
191
+ (api: DeriveApi, accountId: AccountId | Uint8Array | string) =>
192
+ api.derive.accounts.hasIdentityMulti([accountId])
193
+ );
194
+
195
+ /**
196
+ * @name hasIdentityMulti
197
+ * @description Checks whether multiple accounts have on chain identities registered.
198
+ * @param {(AccountId | Uint8Array | string)[]} accountIds Array of account identifiers to query.
199
+ * @example
200
+ * ```javascript
201
+ * const ALICE = "13AU";
202
+ * const BOB = "16WW";
203
+ * console.log(await api.derive.accounts.hasIdentityMulti([ALICE, BOB]));
204
+ * ```
205
+ */
206
+ export function hasIdentityMulti (instanceId: string, api: DeriveApi): (accountIds: (AccountId | Uint8Array | string)[]) => Observable<DeriveHasIdentity[]> {
207
+ return memo(instanceId, (accountIds: (AccountId | Uint8Array | string)[]): Observable<DeriveHasIdentity[]> =>
208
+ api.query.identity?.identityOf
209
+ ? combineLatest([
210
+ api.query.identity.identityOf.multi(accountIds),
211
+ api.query.identity.superOf.multi(accountIds)
212
+ ]).pipe(
213
+ map(([identities, supers]) =>
214
+ identities.map((identityOfOpt, index): DeriveHasIdentity => {
215
+ const superOfOpt = supers[index];
216
+ const parentId = superOfOpt && superOfOpt.isSome
217
+ ? superOfOpt.unwrap()[0].toString()
218
+ : undefined;
219
+ let display: string | undefined;
220
+
221
+ if (identityOfOpt && identityOfOpt.isSome) {
222
+ const value = dataAsString(identityCompat(identityOfOpt).info.display);
223
+
224
+ if (value && !isHex(value)) {
225
+ display = value;
226
+ }
227
+ }
228
+
229
+ return { display, hasIdentity: !!(display || parentId), parentId };
230
+ })
231
+ )
232
+ )
233
+ : of(accountIds.map(() => ({ hasIdentity: false })))
234
+ );
235
+ }
@@ -0,0 +1,11 @@
1
+ // Copyright 2017-2025 @polkadot/api-derive authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export * from './accountId.js';
5
+ export * from './flags.js';
6
+ export * from './idAndIndex.js';
7
+ export * from './identity.js';
8
+ export * from './idToIndex.js';
9
+ export * from './indexes.js';
10
+ export * from './indexToId.js';
11
+ export * from './info.js';
@@ -0,0 +1,33 @@
1
+ // Copyright 2017-2025 @polkadot/api-derive authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { Observable } from 'rxjs';
5
+ import type { AccountId, AccountIndex } from '@pezkuwi/types/interfaces';
6
+ import type { DeriveApi } from '../types.js';
7
+
8
+ import { map, of } from 'rxjs';
9
+
10
+ import { memo } from '../util/index.js';
11
+
12
+ /**
13
+ * @name indexToId
14
+ * @description Resolves an AccountIndex (short address) to the full AccountId.
15
+ * @param {( AccountIndex | string )} accountIndex An accounts index in different formats.
16
+ * @example
17
+ * ```javascript
18
+ * const ALICE = "13AU";
19
+ * const id = await api.derive.accounts.indexToId(ALICE);
20
+ * console.log(id);
21
+ * ```
22
+ */
23
+ export function indexToId (instanceId: string, api: DeriveApi): (accountIndex: AccountIndex | string) => Observable<AccountId | undefined> {
24
+ return memo(instanceId, (accountIndex: AccountIndex | string): Observable<AccountId | undefined> =>
25
+ api.query.indices
26
+ ? api.query.indices.accounts(accountIndex).pipe(
27
+ map((optResult): AccountId | undefined =>
28
+ optResult.unwrapOr([])[0]
29
+ )
30
+ )
31
+ : of(undefined)
32
+ );
33
+ }
@@ -0,0 +1,56 @@
1
+ // Copyright 2017-2025 @polkadot/api-derive authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { Observable } from 'rxjs';
5
+ import type { AccountIndexes, DeriveApi } from '../types.js';
6
+
7
+ import { map, of, startWith } from 'rxjs';
8
+
9
+ import { memo } from '../util/index.js';
10
+
11
+ let indicesCache: AccountIndexes | null = null;
12
+
13
+ function queryAccounts (api: DeriveApi): Observable<AccountIndexes> {
14
+ return api.query.indices.accounts.entries().pipe(
15
+ map((entries): AccountIndexes =>
16
+ entries.reduce((indexes: AccountIndexes, [key, idOpt]): AccountIndexes => {
17
+ if (idOpt.isSome) {
18
+ indexes[idOpt.unwrap()[0].toString()] = api.registry.createType('AccountIndex', key.args[0]);
19
+ }
20
+
21
+ return indexes;
22
+ }, {})
23
+ )
24
+ );
25
+ }
26
+
27
+ /**
28
+ * @name indexes
29
+ * @returns Returns all the indexes on the system.
30
+ * @description This is an unwieldly query since it loops through
31
+ * all of the enumsets and returns all of the values found. This could be up to 32k depending
32
+ * on the number of active accounts in the system.
33
+ * @example
34
+ * ```javascript
35
+ * api.derive.accounts.indexes((indexes) => {
36
+ * console.log('All existing AccountIndexes', indexes);
37
+ * });
38
+ * ```
39
+ */
40
+ export function indexes (instanceId: string, api: DeriveApi): () => Observable<AccountIndexes> {
41
+ return memo(instanceId, (): Observable<AccountIndexes> =>
42
+ indicesCache
43
+ ? of(indicesCache)
44
+ : (
45
+ api.query.indices
46
+ ? queryAccounts(api).pipe(startWith({}))
47
+ : of({} as AccountIndexes)
48
+ ).pipe(
49
+ map((indices): AccountIndexes => {
50
+ indicesCache = indices;
51
+
52
+ return indices;
53
+ })
54
+ )
55
+ );
56
+ }
@@ -0,0 +1,58 @@
1
+ // Copyright 2017-2025 @polkadot/api-derive authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { Observable } from 'rxjs';
5
+ import type { Bytes, Option, u32 } from '@pezkuwi/types';
6
+ import type { AccountId, AccountIndex, Address, Balance } from '@pezkuwi/types/interfaces';
7
+ import type { ITuple } from '@pezkuwi/types/types';
8
+ import type { DeriveAccountInfo, DeriveAccountRegistration, DeriveApi } from '../types.js';
9
+
10
+ import { combineLatest, map, of, switchMap } from 'rxjs';
11
+
12
+ import { u8aToString } from '@pezkuwi/util';
13
+
14
+ import { memo } from '../util/index.js';
15
+
16
+ function retrieveNick (api: DeriveApi, accountId?: AccountId): Observable<string | undefined> {
17
+ return ((
18
+ accountId && api.query['nicks']?.['nameOf']
19
+ ? api.query['nicks']['nameOf'](accountId)
20
+ : of(undefined)
21
+ ) as Observable<Option<ITuple<[Bytes, Balance]>> | undefined>).pipe(
22
+ map((nameOf): string | undefined =>
23
+ nameOf?.isSome
24
+ ? u8aToString(nameOf.unwrap()[0]).substring(0, (api.consts['nicks']['maxLength'] as u32).toNumber())
25
+ : undefined
26
+ )
27
+ );
28
+ }
29
+
30
+ /**
31
+ * @name info
32
+ * @description Returns aux. info with regards to an account, current that includes the accountId, accountIndex, identity and nickname
33
+ * @param {(AccountIndex | AccountId | Address | Uint8Array | string | null)} address An accounts in different formats.
34
+ * @example
35
+ * ```javascript
36
+ * const ALICE = "13AU";
37
+ * const info = await api.derive.accounts.info(ALICE);
38
+ * console.log(
39
+ * "Account Info: ",
40
+ * Object.keys(info).map((key) => `${key}: ${info[key]}`)
41
+ * );
42
+ * ```
43
+ */
44
+ export function info (instanceId: string, api: DeriveApi): (address?: AccountIndex | AccountId | Address | Uint8Array | string | null) => Observable<DeriveAccountInfo> {
45
+ return memo(instanceId, (address?: AccountIndex | AccountId | Address | Uint8Array | string | null): Observable<DeriveAccountInfo> =>
46
+ api.derive.accounts.idAndIndex(address).pipe(
47
+ switchMap(([accountId, accountIndex]): Observable<[Partial<DeriveAccountInfo>, DeriveAccountRegistration, string | undefined]> =>
48
+ combineLatest([
49
+ of({ accountId, accountIndex }),
50
+ api.derive.accounts.identity(accountId),
51
+ retrieveNick(api, accountId)
52
+ ])
53
+ ),
54
+ map(([{ accountId, accountIndex }, identity, nickname]): DeriveAccountInfo => ({
55
+ accountId, accountIndex, identity, nickname
56
+ }))
57
+ ));
58
+ }
@@ -0,0 +1,48 @@
1
+ // Copyright 2017-2025 @polkadot/api-derive authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { AccountId, AccountIndex, RegistrationJudgement } from '@pezkuwi/types/interfaces';
5
+ import type { Vec } from '@pezkuwi/types-codec';
6
+
7
+ export type AccountIdAndIndex = [AccountId | undefined, AccountIndex | undefined];
8
+
9
+ export type AccountIndexes = Record<string, AccountIndex>;
10
+
11
+ export interface DeriveAccountRegistration {
12
+ discord?: string | undefined;
13
+ display?: string | undefined;
14
+ displayParent?: string | undefined;
15
+ email?: string | undefined;
16
+ github?: string | undefined;
17
+ image?: string | undefined;
18
+ legal?: string | undefined;
19
+ matrix?: string | undefined;
20
+ other?: Record<string, string> | undefined;
21
+ parent?: AccountId | undefined;
22
+ pgp?: string | undefined;
23
+ riot?: string | undefined;
24
+ subs?: Vec<AccountId> | undefined;
25
+ twitter?: string | undefined;
26
+ web?: string | undefined;
27
+ judgements: RegistrationJudgement[];
28
+ }
29
+
30
+ export interface DeriveAccountFlags {
31
+ isCouncil: boolean;
32
+ isSociety: boolean;
33
+ isSudo: boolean;
34
+ isTechCommittee: boolean;
35
+ }
36
+
37
+ export interface DeriveAccountInfo {
38
+ accountId?: AccountId | undefined;
39
+ accountIndex?: AccountIndex | undefined;
40
+ identity: DeriveAccountRegistration;
41
+ nickname?: string | undefined;
42
+ }
43
+
44
+ export interface DeriveHasIdentity {
45
+ display?: string | undefined;
46
+ hasIdentity: boolean;
47
+ parentId?: string | undefined;
48
+ }
@@ -0,0 +1,76 @@
1
+ // Copyright 2017-2025 @polkadot/api-derive authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { hasProposals as collectiveHasProposals, members as collectiveMembers, prime as collectivePrime, proposal as collectiveProposal, proposalCount as collectiveProposalCount, proposalHashes as collectiveProposalHashes, proposals as collectiveProposals } from '../collective/index.js';
5
+
6
+ /**
7
+ * @name members
8
+ * @description Retrieves the list of members in the "allianceMotion" collective.
9
+ * @example
10
+ * ```javascript
11
+ * const members = await api.derive.alliance.members();
12
+ * console.log(`Members: ${JSON.stringify(members)});
13
+ * ```
14
+ */
15
+ export const members = /*#__PURE__*/ collectiveMembers('allianceMotion');
16
+
17
+ /**
18
+ * @name hasProposals
19
+ * @description Checks if there are any active proposals in the "allianceMotion" collective.
20
+ * @example
21
+ * ```javascript
22
+ * const exists = await api.derive.alliance.hasProposals();
23
+ * console.log(exists);
24
+ * ```
25
+ */
26
+ export const hasProposals = /*#__PURE__*/ collectiveHasProposals('allianceMotion');
27
+ /**
28
+ * @name proposal
29
+ * @description Retrieves details of a specific proposal in the "allianceMotion" collective by its hash.
30
+ * @example
31
+ * ```javascript
32
+ * const proposalDetails = await api.derive.alliance.proposal(PROPOSAL_HASH);
33
+ * console.log(proposalDetails);
34
+ * ```
35
+ */
36
+ export const proposal = /*#__PURE__*/ collectiveProposal('allianceMotion');
37
+ /**
38
+ * @name proposalCount
39
+ * @description Retrieves the total number of proposals in the "allianceMotion" collective.
40
+ * @example
41
+ * ```javascript
42
+ * const count = await api.derive.alliance.proposalCount();
43
+ * console.log(`Amount of proposals: ${count}`);
44
+ * ```
45
+ */
46
+ export const proposalCount = /*#__PURE__*/ collectiveProposalCount('allianceMotion');
47
+ /**
48
+ * @name proposalHashes
49
+ * @description Retrieves an array of hashes for all active proposals in the "allianceMotion" collective.
50
+ * @example
51
+ * ```javascript
52
+ * const hashes = await api.derive.alliance.proposalHashes();
53
+ * console.log(`Proposals ${JSON.stringify(hashes)}`);
54
+ * ```
55
+ */
56
+ export const proposalHashes = /*#__PURE__*/ collectiveProposalHashes('allianceMotion');
57
+ /**
58
+ * @name proposals
59
+ * @description Retrieves a list of all active proposals in the "allianceMotion" collective.
60
+ * @example
61
+ * ```javascript
62
+ * const proposals = await api.derive.alliance.proposals();
63
+ * console.log(proposals);
64
+ * ```
65
+ */
66
+ export const proposals = /*#__PURE__*/ collectiveProposals('allianceMotion');
67
+ /**
68
+ * @name prime
69
+ * @description Retrieves the prime member of the "allianceMotion" collective, if one exists.
70
+ * @example
71
+ * ```javascript
72
+ * const primeMember = await api.derive.alliance.prime();
73
+ * console.log(primeMember);
74
+ * ```
75
+ */
76
+ export const prime = /*#__PURE__*/ collectivePrime('allianceMotion');
package/src/augment.ts ADDED
@@ -0,0 +1,4 @@
1
+ // Copyright 2017-2025 @polkadot/api-derive authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import '@pezkuwi/api-augment';
@@ -0,0 +1,79 @@
1
+ // Copyright 2017-2025 @polkadot/api-derive authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { Observable } from 'rxjs';
5
+ import type { Option, u64 } from '@pezkuwi/types';
6
+ import type { PalletBagsListListBag } from '@pezkuwi/types/lookup';
7
+ import type { BN } from '@pezkuwi/util';
8
+ import type { DeriveApi } from '../types.js';
9
+ import type { Bag } from './types.js';
10
+
11
+ import { map, of, switchMap } from 'rxjs';
12
+
13
+ import { BN_ZERO, bnToBn, objectSpread } from '@pezkuwi/util';
14
+
15
+ import { memo } from '../util/index.js';
16
+ import { getQueryInterface } from './util.js';
17
+
18
+ function orderBags (ids: BN[], bags: Option<PalletBagsListListBag>[]): Bag[] {
19
+ const sorted = ids
20
+ .map((id, index) => ({
21
+ bag: bags[index].unwrapOr(null),
22
+ id,
23
+ key: id.toString()
24
+ }))
25
+ .sort((a, b) => b.id.cmp(a.id));
26
+ const max = sorted.length - 1;
27
+
28
+ return sorted.map((entry, index): Bag =>
29
+ objectSpread(entry, {
30
+ bagLower: index === max
31
+ ? BN_ZERO
32
+ : sorted[index + 1].id,
33
+ bagUpper: entry.id,
34
+ index
35
+ })
36
+ );
37
+ }
38
+
39
+ export function _getIds (instanceId: string, api: DeriveApi): (ids: (BN | number)[]) => Observable<Bag[]> {
40
+ const query = getQueryInterface(api);
41
+
42
+ return memo(instanceId, (_ids: (BN | number)[]): Observable<Bag[]> => {
43
+ const ids = _ids.map((id) => bnToBn(id));
44
+
45
+ return ids.length
46
+ ? query.listBags.multi<Option<PalletBagsListListBag>>(ids).pipe(
47
+ map((bags) => orderBags(ids, bags))
48
+ )
49
+ : of([]);
50
+ });
51
+ }
52
+
53
+ export function all (instanceId: string, api: DeriveApi): () => Observable<Bag[]> {
54
+ const query = getQueryInterface(api);
55
+
56
+ return memo(instanceId, (): Observable<Bag[]> =>
57
+ query.listBags.keys<[u64]>().pipe(
58
+ switchMap((keys) =>
59
+ api.derive.bagsList._getIds(keys.map(({ args: [id] }) => id))
60
+ ),
61
+ map((list) =>
62
+ list.filter(({ bag }) => bag)
63
+ )
64
+ )
65
+ );
66
+ }
67
+
68
+ /**
69
+ * @name get
70
+ * @param {(BN | number)} id The id of the bag to retrieve.
71
+ * @description Retrieves a specific bag from the BagsList pallet by its id.
72
+ */
73
+ export function get (instanceId: string, api: DeriveApi): (id: BN | number) => Observable<Bag> {
74
+ return memo(instanceId, (id: BN | number): Observable<Bag> =>
75
+ api.derive.bagsList._getIds([bnToBn(id)]).pipe(
76
+ map((bags) => bags[0])
77
+ )
78
+ );
79
+ }
@@ -0,0 +1,41 @@
1
+ // Copyright 2017-2025 @polkadot/api-derive authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { Observable } from 'rxjs';
5
+ import type { BN } from '@pezkuwi/util';
6
+ import type { DeriveApi } from '../types.js';
7
+ import type { Bag, BagExpanded } from './types.js';
8
+
9
+ import { map, switchMap } from 'rxjs';
10
+
11
+ import { objectSpread } from '@pezkuwi/util';
12
+
13
+ import { memo } from '../util/index.js';
14
+
15
+ /**
16
+ * @name expand
17
+ * @description Expands a given bag by retrieving all its nodes (accounts contained within the bag).
18
+ * @param {Bag} bag The bag to be expanded.
19
+ */
20
+ export function expand (instanceId: string, api: DeriveApi): (bag: Bag) => Observable<BagExpanded> {
21
+ return memo(instanceId, (bag: Bag): Observable<BagExpanded> =>
22
+ api.derive.bagsList.listNodes(bag.bag).pipe(
23
+ map((nodes) => objectSpread({ nodes }, bag))
24
+ )
25
+ );
26
+ }
27
+
28
+ /**
29
+ * @name getExpanded
30
+ * @description Retrieves and expands a specific bag from the BagsList pallet.
31
+ * @param {BN | number} id The id of the bag to expand.
32
+ */
33
+ export function getExpanded (instanceId: string, api: DeriveApi): (id: BN | number) => Observable<BagExpanded> {
34
+ return memo(instanceId, (id: BN | number): Observable<BagExpanded> =>
35
+ api.derive.bagsList.get(id).pipe(
36
+ switchMap((bag) =>
37
+ api.derive.bagsList.expand(bag)
38
+ )
39
+ )
40
+ );
41
+ }
@@ -0,0 +1,6 @@
1
+ // Copyright 2017-2025 @polkadot/api-derive authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export * from './get.js';
5
+ export * from './getExpanded.js';
6
+ export * from './listNodes.js';