@pezkuwi/api 16.5.5 → 16.5.6

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 (204) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +12 -12
  3. package/augment.js +1 -0
  4. package/base/Decorate.js +752 -0
  5. package/base/Events.js +78 -0
  6. package/base/Getters.js +207 -0
  7. package/base/Init.js +400 -0
  8. package/base/find.js +7 -0
  9. package/{build/base → base}/index.d.ts +1 -1
  10. package/base/index.js +57 -0
  11. package/bundle-pezkuwi-api.js +26238 -0
  12. package/{src/bundle.ts → bundle.js} +0 -9
  13. package/cjs/augment.d.ts +1 -0
  14. package/cjs/augment.js +3 -0
  15. package/cjs/base/Decorate.d.ts +143 -0
  16. package/cjs/base/Decorate.js +756 -0
  17. package/cjs/base/Events.d.ts +67 -0
  18. package/cjs/base/Events.js +82 -0
  19. package/cjs/base/Getters.d.ts +163 -0
  20. package/cjs/base/Getters.js +211 -0
  21. package/cjs/base/Init.d.ts +44 -0
  22. package/cjs/base/Init.js +404 -0
  23. package/cjs/base/find.d.ts +3 -0
  24. package/cjs/base/find.js +11 -0
  25. package/cjs/base/index.d.ts +47 -0
  26. package/cjs/base/index.js +61 -0
  27. package/{src/base/types.ts → cjs/base/types.d.ts} +8 -12
  28. package/cjs/base/types.js +2 -0
  29. package/cjs/bundle.d.ts +7 -0
  30. package/cjs/bundle.js +17 -0
  31. package/cjs/index.js +5 -0
  32. package/cjs/package.json +3 -0
  33. package/cjs/packageDetect.d.ts +1 -0
  34. package/cjs/packageDetect.js +10 -0
  35. package/cjs/packageInfo.js +4 -0
  36. package/{build → cjs}/promise/Api.d.ts +2 -2
  37. package/cjs/promise/Api.js +195 -0
  38. package/cjs/promise/Combinator.js +72 -0
  39. package/cjs/promise/decorateMethod.js +75 -0
  40. package/cjs/promise/index.js +7 -0
  41. package/cjs/promise/types.js +2 -0
  42. package/{build → cjs}/rx/Api.d.ts +2 -2
  43. package/cjs/rx/Api.js +173 -0
  44. package/cjs/rx/decorateMethod.js +6 -0
  45. package/cjs/rx/index.js +7 -0
  46. package/cjs/submittable/Result.js +84 -0
  47. package/cjs/submittable/createClass.js +277 -0
  48. package/cjs/submittable/createSubmittable.js +8 -0
  49. package/cjs/submittable/index.js +7 -0
  50. package/cjs/submittable/types.js +2 -0
  51. package/cjs/types/calls.js +4 -0
  52. package/cjs/types/consts.js +4 -0
  53. package/cjs/types/errors.js +4 -0
  54. package/cjs/types/events.js +4 -0
  55. package/cjs/types/index.js +13 -0
  56. package/cjs/types/storage.js +4 -0
  57. package/cjs/types/submittable.js +4 -0
  58. package/cjs/util/augmentObject.js +84 -0
  59. package/cjs/util/decorate.js +17 -0
  60. package/cjs/util/filterEvents.js +25 -0
  61. package/cjs/util/index.js +11 -0
  62. package/cjs/util/isKeyringPair.js +7 -0
  63. package/cjs/util/logging.js +5 -0
  64. package/cjs/util/validate.js +26 -0
  65. package/index.d.ts +2 -0
  66. package/index.js +2 -0
  67. package/package.json +588 -22
  68. package/packageDetect.d.ts +1 -0
  69. package/{src/packageDetect.ts → packageDetect.js} +0 -8
  70. package/packageInfo.d.ts +6 -0
  71. package/packageInfo.js +1 -0
  72. package/promise/Api.d.ts +158 -0
  73. package/promise/Api.js +191 -0
  74. package/promise/Combinator.d.ts +12 -0
  75. package/promise/Combinator.js +68 -0
  76. package/promise/decorateMethod.d.ts +14 -0
  77. package/promise/decorateMethod.js +71 -0
  78. package/promise/index.d.ts +2 -0
  79. package/promise/index.js +2 -0
  80. package/{src/promise/types.ts → promise/types.d.ts} +0 -4
  81. package/promise/types.js +1 -0
  82. package/rx/Api.d.ts +155 -0
  83. package/{src/rx/Api.ts → rx/Api.js} +67 -84
  84. package/rx/decorateMethod.d.ts +3 -0
  85. package/rx/decorateMethod.js +3 -0
  86. package/rx/index.d.ts +2 -0
  87. package/rx/index.js +2 -0
  88. package/submittable/Result.d.ts +31 -0
  89. package/submittable/Result.js +80 -0
  90. package/submittable/createClass.d.ts +12 -0
  91. package/submittable/createClass.js +274 -0
  92. package/submittable/createSubmittable.d.ts +8 -0
  93. package/submittable/createSubmittable.js +5 -0
  94. package/{src/submittable/index.ts → submittable/index.d.ts} +0 -3
  95. package/submittable/index.js +2 -0
  96. package/{src/submittable/types.ts → submittable/types.d.ts} +0 -3
  97. package/submittable/types.js +1 -0
  98. package/types/calls.d.ts +1 -0
  99. package/types/calls.js +1 -0
  100. package/types/consts.d.ts +1 -0
  101. package/types/consts.js +1 -0
  102. package/types/errors.d.ts +1 -0
  103. package/types/errors.js +1 -0
  104. package/types/events.d.ts +1 -0
  105. package/types/events.js +1 -0
  106. package/types/index.d.ts +114 -0
  107. package/types/index.js +8 -0
  108. package/types/storage.d.ts +1 -0
  109. package/types/storage.js +1 -0
  110. package/types/submittable.d.ts +1 -0
  111. package/types/submittable.js +1 -0
  112. package/util/augmentObject.d.ts +9 -0
  113. package/util/augmentObject.js +81 -0
  114. package/util/decorate.d.ts +16 -0
  115. package/util/decorate.js +14 -0
  116. package/util/filterEvents.d.ts +6 -0
  117. package/util/filterEvents.js +22 -0
  118. package/{src/util/index.ts → util/index.d.ts} +0 -6
  119. package/util/index.js +4 -0
  120. package/util/isKeyringPair.d.ts +3 -0
  121. package/util/isKeyringPair.js +4 -0
  122. package/util/logging.d.ts +1 -0
  123. package/util/logging.js +2 -0
  124. package/util/validate.d.ts +3 -0
  125. package/util/validate.js +23 -0
  126. package/src/augment.ts +0 -4
  127. package/src/base/Decorate.ts +0 -1103
  128. package/src/base/Events.ts +0 -91
  129. package/src/base/Getters.ts +0 -245
  130. package/src/base/Init.ts +0 -525
  131. package/src/base/find.ts +0 -14
  132. package/src/base/index.ts +0 -85
  133. package/src/checkTypes.manual.ts +0 -323
  134. package/src/index.ts +0 -6
  135. package/src/mod.ts +0 -4
  136. package/src/packageInfo.ts +0 -6
  137. package/src/promise/Api.ts +0 -214
  138. package/src/promise/Combinator.ts +0 -91
  139. package/src/promise/Combinators.spec.ts +0 -109
  140. package/src/promise/decorateMethod.ts +0 -118
  141. package/src/promise/index.spec.ts +0 -167
  142. package/src/promise/index.ts +0 -5
  143. package/src/rx/decorateMethod.ts +0 -9
  144. package/src/rx/index.ts +0 -5
  145. package/src/submittable/Result.ts +0 -111
  146. package/src/submittable/createClass.ts +0 -438
  147. package/src/submittable/createSubmittable.ts +0 -19
  148. package/src/test/SingleAccountSigner.ts +0 -53
  149. package/src/test/index.ts +0 -5
  150. package/src/test/logEvents.ts +0 -24
  151. package/src/types/calls.ts +0 -4
  152. package/src/types/consts.ts +0 -4
  153. package/src/types/errors.ts +0 -4
  154. package/src/types/events.ts +0 -4
  155. package/src/types/index.ts +0 -137
  156. package/src/types/storage.ts +0 -4
  157. package/src/types/submittable.ts +0 -4
  158. package/src/util/augmentObject.spec.ts +0 -54
  159. package/src/util/augmentObject.ts +0 -112
  160. package/src/util/decorate.ts +0 -43
  161. package/src/util/filterEvents.ts +0 -34
  162. package/src/util/isKeyringPair.ts +0 -11
  163. package/src/util/logging.ts +0 -6
  164. package/src/util/validate.spec.ts +0 -72
  165. package/src/util/validate.ts +0 -36
  166. package/tsconfig.build.json +0 -25
  167. package/tsconfig.build.tsbuildinfo +0 -1
  168. package/tsconfig.spec.json +0 -26
  169. /package/{build/augment.d.ts → augment.d.ts} +0 -0
  170. /package/{build/base → base}/Decorate.d.ts +0 -0
  171. /package/{build/base → base}/Events.d.ts +0 -0
  172. /package/{build/base → base}/Getters.d.ts +0 -0
  173. /package/{build/base → base}/Init.d.ts +0 -0
  174. /package/{build/base → base}/find.d.ts +0 -0
  175. /package/{build/base → base}/types.d.ts +0 -0
  176. /package/{build/packageDetect.d.ts → base/types.js} +0 -0
  177. /package/{build/bundle.d.ts → bundle.d.ts} +0 -0
  178. /package/{build → cjs}/index.d.ts +0 -0
  179. /package/{build → cjs}/packageInfo.d.ts +0 -0
  180. /package/{build → cjs}/promise/Combinator.d.ts +0 -0
  181. /package/{build → cjs}/promise/decorateMethod.d.ts +0 -0
  182. /package/{build → cjs}/promise/index.d.ts +0 -0
  183. /package/{build → cjs}/promise/types.d.ts +0 -0
  184. /package/{build → cjs}/rx/decorateMethod.d.ts +0 -0
  185. /package/{build → cjs}/rx/index.d.ts +0 -0
  186. /package/{build → cjs}/submittable/Result.d.ts +0 -0
  187. /package/{build → cjs}/submittable/createClass.d.ts +0 -0
  188. /package/{build → cjs}/submittable/createSubmittable.d.ts +0 -0
  189. /package/{build → cjs}/submittable/index.d.ts +0 -0
  190. /package/{build → cjs}/submittable/types.d.ts +0 -0
  191. /package/{build → cjs}/types/calls.d.ts +0 -0
  192. /package/{build → cjs}/types/consts.d.ts +0 -0
  193. /package/{build → cjs}/types/errors.d.ts +0 -0
  194. /package/{build → cjs}/types/events.d.ts +0 -0
  195. /package/{build → cjs}/types/index.d.ts +0 -0
  196. /package/{build → cjs}/types/storage.d.ts +0 -0
  197. /package/{build → cjs}/types/submittable.d.ts +0 -0
  198. /package/{build → cjs}/util/augmentObject.d.ts +0 -0
  199. /package/{build → cjs}/util/decorate.d.ts +0 -0
  200. /package/{build → cjs}/util/filterEvents.d.ts +0 -0
  201. /package/{build → cjs}/util/index.d.ts +0 -0
  202. /package/{build → cjs}/util/isKeyringPair.d.ts +0 -0
  203. /package/{build → cjs}/util/logging.d.ts +0 -0
  204. /package/{build → cjs}/util/validate.d.ts +0 -0
@@ -0,0 +1,277 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createClass = createClass;
4
+ const rxjs_1 = require("rxjs");
5
+ const util_1 = require("@pezkuwi/util");
6
+ const index_js_1 = require("../util/index.js");
7
+ const Result_js_1 = require("./Result.js");
8
+ function makeEraOptions(api, registry, partialOptions, { header, mortalLength, nonce }) {
9
+ if (!header) {
10
+ if (partialOptions.era && !partialOptions.blockHash) {
11
+ throw new Error('Expected blockHash to be passed alongside non-immortal era options');
12
+ }
13
+ if ((0, util_1.isNumber)(partialOptions.era)) {
14
+ // since we have no header, it is immortal, remove any option overrides
15
+ // so we only supply the genesisHash and no era to the construction
16
+ delete partialOptions.era;
17
+ delete partialOptions.blockHash;
18
+ }
19
+ return makeSignOptions(api, partialOptions, { nonce });
20
+ }
21
+ return makeSignOptions(api, partialOptions, {
22
+ blockHash: header.hash,
23
+ era: registry.createTypeUnsafe('ExtrinsicEra', [{
24
+ current: header.number,
25
+ period: partialOptions.era || mortalLength
26
+ }]),
27
+ nonce
28
+ });
29
+ }
30
+ function makeSignAndSendOptions(partialOptions, statusCb) {
31
+ let options = {};
32
+ if ((0, util_1.isFunction)(partialOptions)) {
33
+ statusCb = partialOptions;
34
+ }
35
+ else {
36
+ options = (0, util_1.objectSpread)({}, partialOptions);
37
+ }
38
+ return [options, statusCb];
39
+ }
40
+ function makeSignOptions(api, partialOptions, extras) {
41
+ return (0, util_1.objectSpread)({ blockHash: api.genesisHash, genesisHash: api.genesisHash }, partialOptions, extras, { runtimeVersion: api.runtimeVersion, signedExtensions: api.registry.signedExtensions, version: api.extrinsicType });
42
+ }
43
+ function optionsOrNonce(partialOptions = {}) {
44
+ return (0, util_1.isBn)(partialOptions) || (0, util_1.isNumber)(partialOptions)
45
+ ? { nonce: partialOptions }
46
+ : partialOptions;
47
+ }
48
+ function createClass({ api, apiType, blockHash, decorateMethod }) {
49
+ // an instance of the base extrinsic for us to extend
50
+ const ExtrinsicBase = api.registry.createClass('Extrinsic');
51
+ const extrinsicInfoMap = new WeakMap();
52
+ class Submittable extends ExtrinsicBase {
53
+ #ignoreStatusCb;
54
+ #transformResult = (util_1.identity);
55
+ constructor(registry, extrinsic) {
56
+ super(registry, extrinsic, { version: api.extrinsicType });
57
+ this.#ignoreStatusCb = apiType === 'rxjs';
58
+ }
59
+ get hasDryRun() {
60
+ return (0, util_1.isFunction)(api.rpc.system?.dryRun);
61
+ }
62
+ get hasPaymentInfo() {
63
+ return (0, util_1.isFunction)(api.call.transactionPaymentApi?.queryInfo);
64
+ }
65
+ // dry run an extrinsic
66
+ dryRun(account, optionsOrHash) {
67
+ if (!this.hasDryRun) {
68
+ throw new Error('The system.dryRun RPC call is not available in your environment');
69
+ }
70
+ if (blockHash || (0, util_1.isString)(optionsOrHash) || (0, util_1.isU8a)(optionsOrHash)) {
71
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
72
+ return decorateMethod(() => api.rpc.system.dryRun(this.toHex(), blockHash || optionsOrHash));
73
+ }
74
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return,@typescript-eslint/no-unsafe-call
75
+ return decorateMethod(() => this.#observeSign(account, optionsOrHash).pipe((0, rxjs_1.switchMap)(() => api.rpc.system.dryRun(this.toHex()))))();
76
+ }
77
+ // calculate the payment info for this transaction (if signed and submitted)
78
+ paymentInfo(account, optionsOrHash) {
79
+ if (!this.hasPaymentInfo) {
80
+ throw new Error('The transactionPaymentApi.queryInfo runtime call is not available in your environment');
81
+ }
82
+ if (blockHash || (0, util_1.isString)(optionsOrHash) || (0, util_1.isU8a)(optionsOrHash)) {
83
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
84
+ return decorateMethod(() => api.callAt(blockHash || optionsOrHash).pipe((0, rxjs_1.switchMap)((callAt) => {
85
+ const u8a = this.toU8a();
86
+ return callAt.transactionPaymentApi.queryInfo(u8a, u8a.length);
87
+ })));
88
+ }
89
+ const [allOptions] = makeSignAndSendOptions(optionsOrHash);
90
+ const address = (0, index_js_1.isKeyringPair)(account) ? account.address : account.toString();
91
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return,@typescript-eslint/no-unsafe-call
92
+ return decorateMethod(() => api.derive.tx.signingInfo(address, allOptions.nonce, allOptions.era).pipe((0, rxjs_1.first)(), (0, rxjs_1.switchMap)((signingInfo) => {
93
+ // setup our options (same way as in signAndSend)
94
+ const eraOptions = makeEraOptions(api, this.registry, allOptions, signingInfo);
95
+ const signOptions = makeSignOptions(api, eraOptions, {});
96
+ // 1. Don't use the internal objects inside the new tx (hence toU8a)
97
+ // 2. Don't override the data from existing signed extrinsics
98
+ // 3. Ensure that this object stays intact, with no new sign after operation
99
+ const u8a = api.tx(this.toU8a()).signFake(address, signOptions).toU8a();
100
+ return api.call.transactionPaymentApi.queryInfo(u8a, u8a.length);
101
+ })))();
102
+ }
103
+ // send implementation for both immediate Hash and statusCb variants
104
+ send(statusCb) {
105
+ const isSubscription = api.hasSubscriptions && (this.#ignoreStatusCb || !!statusCb);
106
+ const updatedInfo = extrinsicInfoMap.get(this);
107
+ extrinsicInfoMap.delete(this);
108
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return,@typescript-eslint/no-unsafe-call
109
+ return decorateMethod(isSubscription
110
+ ? () => this.#observeSubscribe(updatedInfo)
111
+ : () => this.#observeSend(updatedInfo))(statusCb);
112
+ }
113
+ /**
114
+ * @description Signs a transaction, returning `this` to allow chaining. E.g.: `signAsync(...).send()`. Like `.signAndSend` this will retrieve the nonce and blockHash to send the tx with.
115
+ */
116
+ signAsync(account, partialOptions) {
117
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return,@typescript-eslint/no-unsafe-call
118
+ return decorateMethod(() => this.#observeSign(account, partialOptions).pipe((0, rxjs_1.map)((info) => {
119
+ // If we got a full signed transaction from the signer, attach it
120
+ if (info.signedTransaction) {
121
+ const extrinsic = new Submittable(api.registry, info.signedTransaction);
122
+ extrinsicInfoMap.set(this, info);
123
+ return extrinsic;
124
+ }
125
+ // Fallback if signer didn’t return signedTransaction
126
+ return this;
127
+ })))();
128
+ }
129
+ // signAndSend implementation for all 3 cases above
130
+ signAndSend(account, partialOptions, optionalStatusCb) {
131
+ const [options, statusCb] = makeSignAndSendOptions(partialOptions, optionalStatusCb);
132
+ const isSubscription = api.hasSubscriptions && (this.#ignoreStatusCb || !!statusCb);
133
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return,@typescript-eslint/no-unsafe-call
134
+ return decorateMethod(() => this.#observeSign(account, options).pipe((0, rxjs_1.switchMap)((info) => isSubscription
135
+ ? this.#observeSubscribe(info)
136
+ : this.#observeSend(info))) // FIXME This is wrong, SubmittableResult is _not_ a codec
137
+ )(statusCb);
138
+ }
139
+ // adds a transform to the result, applied before result is returned
140
+ withResultTransform(transform) {
141
+ this.#transformResult = transform;
142
+ return this;
143
+ }
144
+ #observeSign = (account, partialOptions) => {
145
+ const address = (0, index_js_1.isKeyringPair)(account) ? account.address : account.toString();
146
+ const options = optionsOrNonce(partialOptions);
147
+ return api.derive.tx.signingInfo(address, options.nonce, options.era).pipe((0, rxjs_1.first)(), (0, rxjs_1.mergeMap)(async (signingInfo) => {
148
+ const eraOptions = makeEraOptions(api, this.registry, options, signingInfo);
149
+ let updateId = -1;
150
+ let signedTx = null;
151
+ if ((0, index_js_1.isKeyringPair)(account)) {
152
+ this.sign(account, eraOptions);
153
+ }
154
+ else {
155
+ const result = await this.#signViaSigner(address, eraOptions, signingInfo.header);
156
+ updateId = result.id;
157
+ if (result.signedTransaction) {
158
+ signedTx = result.signedTransaction;
159
+ }
160
+ }
161
+ return { options: eraOptions, signedTransaction: signedTx, updateId };
162
+ }));
163
+ };
164
+ #observeStatus = (txHash, status) => {
165
+ if (!status.isFinalized && !status.isInBlock) {
166
+ return (0, rxjs_1.of)(this.#transformResult(new Result_js_1.SubmittableResult({
167
+ status,
168
+ txHash
169
+ })));
170
+ }
171
+ const blockHash = status.isInBlock
172
+ ? status.asInBlock
173
+ : status.asFinalized;
174
+ return api.derive.tx.events(blockHash).pipe((0, rxjs_1.map)(({ block, events }) => this.#transformResult(new Result_js_1.SubmittableResult({
175
+ ...(0, index_js_1.filterEvents)(txHash, block, events, status),
176
+ status,
177
+ txHash
178
+ }))), (0, rxjs_1.catchError)((internalError) => (0, rxjs_1.of)(this.#transformResult(new Result_js_1.SubmittableResult({
179
+ internalError,
180
+ status,
181
+ txHash
182
+ })))));
183
+ };
184
+ #observeSend = (info) => {
185
+ return api.rpc.author.submitExtrinsic(info?.signedTransaction || this).pipe((0, rxjs_1.tap)((hash) => {
186
+ this.#updateSigner(hash, info);
187
+ }));
188
+ };
189
+ #observeSubscribe = (info) => {
190
+ const txHash = this.hash;
191
+ return api.rpc.author.submitAndWatchExtrinsic(info?.signedTransaction || this).pipe((0, rxjs_1.switchMap)((status) => this.#observeStatus(txHash, status)), (0, rxjs_1.tap)((status) => {
192
+ this.#updateSigner(status, info);
193
+ }));
194
+ };
195
+ #signViaSigner = async (address, options, header) => {
196
+ const signer = options.signer || api.signer;
197
+ const allowCallDataAlteration = options.allowCallDataAlteration ?? true;
198
+ if (!signer) {
199
+ throw new Error('No signer specified, either via api.setSigner or via sign options. You possibly need to pass through an explicit keypair for the origin so it can be used for signing.');
200
+ }
201
+ const payload = this.registry.createTypeUnsafe('SignerPayload', [(0, util_1.objectSpread)({}, options, {
202
+ address,
203
+ blockNumber: header ? header.number : 0,
204
+ method: this.method
205
+ })]);
206
+ let result;
207
+ if ((0, util_1.isFunction)(signer.signPayload)) {
208
+ result = await signer.signPayload(payload.toPayload());
209
+ if (result.signedTransaction && !options.withSignedTransaction) {
210
+ throw new Error('The `signedTransaction` field may not be submitted when `withSignedTransaction` is disabled');
211
+ }
212
+ if (result.signedTransaction && options.withSignedTransaction) {
213
+ const ext = this.registry.createTypeUnsafe('Extrinsic', [result.signedTransaction]);
214
+ const newSignerPayload = this.registry.createTypeUnsafe('SignerPayload', [(0, util_1.objectSpread)({}, {
215
+ address,
216
+ assetId: ext.assetId && ext.assetId.isSome ? ext.assetId.toHex() : null,
217
+ blockHash: payload.blockHash,
218
+ blockNumber: header ? header.number : 0,
219
+ era: ext.era.toHex(),
220
+ genesisHash: payload.genesisHash,
221
+ metadataHash: ext.metadataHash ? ext.metadataHash.toHex() : null,
222
+ method: ext.method.toHex(),
223
+ mode: ext.mode ? ext.mode.toHex() : null,
224
+ nonce: ext.nonce.toHex(),
225
+ runtimeVersion: payload.runtimeVersion,
226
+ signedExtensions: payload.signedExtensions,
227
+ tip: ext.tip ? ext.tip.toHex() : null,
228
+ version: payload.version
229
+ })]);
230
+ if (!ext.isSigned) {
231
+ throw new Error(`When using the signedTransaction field, the transaction must be signed. Recieved isSigned: ${ext.isSigned}`);
232
+ }
233
+ if (!allowCallDataAlteration) {
234
+ this.#validateSignedTransaction(payload, ext);
235
+ }
236
+ // This is only used for signAsync - signAndSend does not need to adjust the super payload or
237
+ // add the signature.
238
+ super.addSignature(address, result.signature, newSignerPayload.toPayload());
239
+ return { id: result.id, signedTransaction: result.signedTransaction };
240
+ }
241
+ }
242
+ else if ((0, util_1.isFunction)(signer.signRaw)) {
243
+ result = await signer.signRaw(payload.toRaw());
244
+ }
245
+ else {
246
+ throw new Error('Invalid signer interface, it should implement either signPayload or signRaw (or both)');
247
+ }
248
+ // Here we explicitly call `toPayload()` again instead of working with an object
249
+ // (reference) as passed to the signer. This means that we are sure that the
250
+ // payload data is not modified from our inputs, but the signer
251
+ super.addSignature(address, result.signature, payload.toPayload());
252
+ return { id: result.id };
253
+ };
254
+ #updateSigner = (status, info) => {
255
+ if (info && (info.updateId !== -1)) {
256
+ const { options, updateId } = info;
257
+ const signer = options.signer || api.signer;
258
+ if (signer && (0, util_1.isFunction)(signer.update)) {
259
+ signer.update(updateId, status);
260
+ }
261
+ }
262
+ };
263
+ /**
264
+ * When a signer includes `signedTransaction` within the SignerResult this will validate
265
+ * specific fields within the signed extrinsic against the original payload that was passed
266
+ * to the signer.
267
+ */
268
+ #validateSignedTransaction = (signerPayload, signedExt) => {
269
+ const payload = signerPayload.toPayload();
270
+ const errMsg = (field) => `signAndSend: ${field} does not match the original payload`;
271
+ if (payload.method !== signedExt.method.toHex()) {
272
+ throw new Error(errMsg('call data'));
273
+ }
274
+ };
275
+ }
276
+ return Submittable;
277
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createSubmittable = createSubmittable;
4
+ const createClass_js_1 = require("./createClass.js");
5
+ function createSubmittable(apiType, api, decorateMethod, registry, blockHash) {
6
+ const Submittable = (0, createClass_js_1.createClass)({ api, apiType, blockHash, decorateMethod });
7
+ return (extrinsic) => new Submittable(registry || api.registry, extrinsic);
8
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SubmittableResult = exports.createSubmittable = void 0;
4
+ var createSubmittable_js_1 = require("./createSubmittable.js");
5
+ Object.defineProperty(exports, "createSubmittable", { enumerable: true, get: function () { return createSubmittable_js_1.createSubmittable; } });
6
+ var Result_js_1 = require("./Result.js");
7
+ Object.defineProperty(exports, "SubmittableResult", { enumerable: true, get: function () { return Result_js_1.SubmittableResult; } });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("@pezkuwi/api-base/types/calls"), exports);
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("@pezkuwi/api-base/types/consts"), exports);
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("@pezkuwi/api-base/types/errors"), exports);
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("@pezkuwi/api-base/types/events"), exports);
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApiBase = void 0;
4
+ const tslib_1 = require("tslib");
5
+ var index_js_1 = require("../base/index.js");
6
+ Object.defineProperty(exports, "ApiBase", { enumerable: true, get: function () { return index_js_1.ApiBase; } });
7
+ tslib_1.__exportStar(require("@pezkuwi/api/types/calls"), exports);
8
+ tslib_1.__exportStar(require("@pezkuwi/api/types/consts"), exports);
9
+ tslib_1.__exportStar(require("@pezkuwi/api/types/errors"), exports);
10
+ tslib_1.__exportStar(require("@pezkuwi/api/types/events"), exports);
11
+ tslib_1.__exportStar(require("@pezkuwi/api/types/storage"), exports);
12
+ tslib_1.__exportStar(require("@pezkuwi/api/types/submittable"), exports);
13
+ tslib_1.__exportStar(require("@pezkuwi/api-base/types"), exports);
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("@pezkuwi/api-base/types/storage"), exports);
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("@pezkuwi/api-base/types/submittable"), exports);
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.augmentObject = augmentObject;
4
+ const util_1 = require("@pezkuwi/util");
5
+ const l = (0, util_1.logger)('api/augment');
6
+ function logLength(type, values, and = []) {
7
+ return values.length
8
+ ? ` ${values.length} ${type}${and.length ? ' and' : ''}`
9
+ : '';
10
+ }
11
+ function logValues(type, values) {
12
+ return values.length
13
+ ? `\n\t${type.padStart(7)}: ${values.sort().join(', ')}`
14
+ : '';
15
+ }
16
+ function warn(prefix, type, [added, removed]) {
17
+ if (added.length || removed.length) {
18
+ l.warn(`api.${prefix}: Found${logLength('added', added, removed)}${logLength('removed', removed)} ${type}:${logValues('added', added)}${logValues('removed', removed)}`);
19
+ }
20
+ }
21
+ function findSectionExcludes(a, b) {
22
+ return a.filter((s) => !b.includes(s));
23
+ }
24
+ function findSectionIncludes(a, b) {
25
+ return a.filter((s) => b.includes(s));
26
+ }
27
+ function extractSections(src, dst) {
28
+ const srcSections = Object.keys(src);
29
+ const dstSections = Object.keys(dst);
30
+ return [
31
+ findSectionExcludes(srcSections, dstSections),
32
+ findSectionExcludes(dstSections, srcSections)
33
+ ];
34
+ }
35
+ function findMethodExcludes(src, dst) {
36
+ const srcSections = Object.keys(src);
37
+ const dstSections = findSectionIncludes(Object.keys(dst), srcSections);
38
+ const excludes = [];
39
+ for (let s = 0, scount = dstSections.length; s < scount; s++) {
40
+ const section = dstSections[s];
41
+ const srcMethods = Object.keys(src[section]);
42
+ const dstMethods = Object.keys(dst[section]);
43
+ for (let d = 0, mcount = dstMethods.length; d < mcount; d++) {
44
+ const method = dstMethods[d];
45
+ if (!srcMethods.includes(method)) {
46
+ excludes.push(`${section}.${method}`);
47
+ }
48
+ }
49
+ }
50
+ return excludes;
51
+ }
52
+ function extractMethods(src, dst) {
53
+ return [
54
+ findMethodExcludes(dst, src),
55
+ findMethodExcludes(src, dst)
56
+ ];
57
+ }
58
+ /**
59
+ * @description Takes a decorated api section (e.g. api.tx) and augment it with the details. It does not override what is
60
+ * already available, but rather just adds new missing items into the result object.
61
+ * @internal
62
+ */
63
+ function augmentObject(prefix, src, dst, fromEmpty = false) {
64
+ fromEmpty && (0, util_1.objectClear)(dst);
65
+ // NOTE: This part is slightly problematic since it will get the
66
+ // values for at least all the sections and the names of the methods
67
+ // (Since methods won't be decorated before lazy, this _may_ be ok)
68
+ if (prefix && Object.keys(dst).length) {
69
+ warn(prefix, 'modules', extractSections(src, dst));
70
+ warn(prefix, 'calls', extractMethods(src, dst));
71
+ }
72
+ const sections = Object.keys(src);
73
+ for (let i = 0, count = sections.length; i < count; i++) {
74
+ const section = sections[i];
75
+ const methods = src[section];
76
+ // We don't set here with a lazy interface, we decorate based
77
+ // on the top-level structure (this bypasses adding lazy onto lazy)
78
+ if (!dst[section]) {
79
+ dst[section] = {};
80
+ }
81
+ (0, util_1.lazyMethods)(dst[section], Object.keys(methods), (m) => methods[m]);
82
+ }
83
+ return dst;
84
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decorateDeriveSections = decorateDeriveSections;
4
+ const api_derive_1 = require("@pezkuwi/api-derive");
5
+ /**
6
+ * This is a section decorator which keeps all type information.
7
+ */
8
+ function decorateDeriveSections(decorateMethod, derives) {
9
+ const getKeys = (s) => Object.keys(derives[s]);
10
+ const creator = (s, m) => decorateMethod(derives[s][m]);
11
+ const result = {};
12
+ const names = Object.keys(derives);
13
+ for (let i = 0, count = names.length; i < count; i++) {
14
+ (0, api_derive_1.lazyDeriveSection)(result, names[i], getKeys, creator);
15
+ }
16
+ return result;
17
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.filterEvents = filterEvents;
4
+ const util_1 = require("@pezkuwi/util");
5
+ const logging_js_1 = require("./logging.js");
6
+ function filterEvents(txHash, { block: { extrinsics, header } }, allEvents, status) {
7
+ // extrinsics to hashes
8
+ for (const [txIndex, x] of extrinsics.entries()) {
9
+ if (x.hash.eq(txHash)) {
10
+ return {
11
+ blockNumber: (0, util_1.isCompact)(header.number) ? header.number.unwrap() : header.number,
12
+ events: allEvents.filter(({ phase }) => phase.isApplyExtrinsic &&
13
+ phase.asApplyExtrinsic.eqn(txIndex)),
14
+ txIndex
15
+ };
16
+ }
17
+ }
18
+ // if we do get the block after finalized, it _should_ be there
19
+ // only warn on filtering with isInBlock (finalization finalizes after)
20
+ if (status.isInBlock) {
21
+ const allHashes = extrinsics.map((x) => x.hash.toHex());
22
+ logging_js_1.l.warn(`block ${header.hash.toHex()}: Unable to find extrinsic ${txHash.toHex()} inside ${allHashes.join(', ')}`);
23
+ }
24
+ return {};
25
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.l = exports.isKeyringPair = exports.filterEvents = void 0;
4
+ const tslib_1 = require("tslib");
5
+ var filterEvents_js_1 = require("./filterEvents.js");
6
+ Object.defineProperty(exports, "filterEvents", { enumerable: true, get: function () { return filterEvents_js_1.filterEvents; } });
7
+ var isKeyringPair_js_1 = require("./isKeyringPair.js");
8
+ Object.defineProperty(exports, "isKeyringPair", { enumerable: true, get: function () { return isKeyringPair_js_1.isKeyringPair; } });
9
+ var logging_js_1 = require("./logging.js");
10
+ Object.defineProperty(exports, "l", { enumerable: true, get: function () { return logging_js_1.l; } });
11
+ tslib_1.__exportStar(require("./decorate.js"), exports);
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isKeyringPair = isKeyringPair;
4
+ const util_1 = require("@pezkuwi/util");
5
+ function isKeyringPair(account) {
6
+ return (0, util_1.isFunction)(account.sign);
7
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.l = void 0;
4
+ const util_1 = require("@pezkuwi/util");
5
+ exports.l = (0, util_1.logger)('api/util');
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractStorageArgs = extractStorageArgs;
4
+ const util_1 = require("@pezkuwi/util");
5
+ function sig({ lookup }, { method, section }, args) {
6
+ return `${section}.${method}(${args.map((a) => lookup.getTypeDef(a).type).join(', ')})`;
7
+ }
8
+ function extractStorageArgs(registry, creator, _args) {
9
+ const args = _args.filter((a) => !(0, util_1.isUndefined)(a));
10
+ if (creator.meta.type.isPlain) {
11
+ if (args.length !== 0) {
12
+ throw new Error(`${sig(registry, creator, [])} does not take any arguments, ${args.length} found`);
13
+ }
14
+ }
15
+ else {
16
+ const { hashers, key } = creator.meta.type.asMap;
17
+ const keys = hashers.length === 1
18
+ ? [key]
19
+ : registry.lookup.getSiType(key).def.asTuple.map((t) => t);
20
+ if (args.length !== keys.length) {
21
+ throw new Error(`${sig(registry, creator, keys)} is a map, requiring ${keys.length} arguments, ${args.length} found`);
22
+ }
23
+ }
24
+ // pass as tuple
25
+ return [creator, args];
26
+ }
package/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import './packageDetect.js';
2
+ export * from './bundle.js';
package/index.js ADDED
@@ -0,0 +1,2 @@
1
+ import './packageDetect.js';
2
+ export * from './bundle.js';