@waku/rln 0.1.5-db38a7e.0 → 0.1.5-e31c6fc.0

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 (130) hide show
  1. package/bundle/_virtual/utils.js +2 -2
  2. package/bundle/_virtual/utils2.js +2 -2
  3. package/bundle/index.js +2 -1
  4. package/bundle/packages/rln/dist/contract/constants.js +5 -1
  5. package/bundle/packages/rln/dist/contract/rln_base_contract.js +18 -24
  6. package/bundle/packages/rln/dist/contract/rln_contract.js +1 -1
  7. package/bundle/packages/rln/dist/utils/bytes.js +8 -2
  8. package/bundle/packages/rln/dist/utils/metamask.js +2 -2
  9. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/random.js +1 -1
  10. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/utils.js +2 -2
  11. package/bundle/packages/rln/node_modules/@noble/hashes/_sha2.js +1 -1
  12. package/bundle/packages/rln/node_modules/@noble/hashes/hmac.js +1 -1
  13. package/bundle/packages/rln/node_modules/@noble/hashes/pbkdf2.js +1 -1
  14. package/bundle/packages/rln/node_modules/@noble/hashes/scrypt.js +1 -1
  15. package/bundle/packages/rln/node_modules/@noble/hashes/sha256.js +1 -1
  16. package/bundle/packages/rln/node_modules/@noble/hashes/sha512.js +1 -1
  17. package/bundle/packages/rln/node_modules/@noble/hashes/utils.js +1 -1
  18. package/dist/.tsbuildinfo +1 -1
  19. package/dist/contract/index.d.ts +1 -0
  20. package/dist/contract/index.js +1 -0
  21. package/dist/contract/index.js.map +1 -1
  22. package/dist/contract/rln_base_contract.d.ts +4 -4
  23. package/dist/contract/rln_base_contract.js +16 -22
  24. package/dist/contract/rln_base_contract.js.map +1 -1
  25. package/dist/index.d.ts +2 -1
  26. package/dist/index.js +1 -0
  27. package/dist/index.js.map +1 -1
  28. package/dist/keystore/keystore.js.map +1 -1
  29. package/dist/keystore/types.d.ts +2 -2
  30. package/dist/utils/bytes.js +8 -2
  31. package/dist/utils/bytes.js.map +1 -1
  32. package/package.json +1 -1
  33. package/src/contract/index.ts +1 -0
  34. package/src/contract/rln_base_contract.ts +22 -30
  35. package/src/index.ts +3 -1
  36. package/src/keystore/keystore.ts +4 -2
  37. package/src/keystore/types.ts +2 -2
  38. package/src/utils/bytes.ts +10 -2
  39. package/bundle/_virtual/__node-resolve_empty.js +0 -6
  40. package/bundle/_virtual/_node-resolve_empty.js +0 -3
  41. package/bundle/_virtual/bn.js +0 -3
  42. package/bundle/_virtual/common.js +0 -3
  43. package/bundle/_virtual/common2.js +0 -3
  44. package/bundle/_virtual/hash.js +0 -3
  45. package/bundle/_virtual/inherits_browser.js +0 -3
  46. package/bundle/_virtual/ripemd.js +0 -3
  47. package/bundle/_virtual/sha.js +0 -3
  48. package/bundle/_virtual/sha3.js +0 -3
  49. package/bundle/_virtual/utils3.js +0 -3
  50. package/bundle/node_modules/@ethersproject/abi/lib.esm/_version.js +0 -3
  51. package/bundle/node_modules/@ethersproject/abi/lib.esm/abi-coder.js +0 -96
  52. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/abstract-coder.js +0 -148
  53. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/address.js +0 -26
  54. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/anonymous.js +0 -20
  55. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/array.js +0 -210
  56. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/boolean.js +0 -18
  57. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/bytes.js +0 -30
  58. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/fixed-bytes.js +0 -26
  59. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/null.js +0 -22
  60. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/number.js +0 -43
  61. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/string.js +0 -19
  62. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/tuple.js +0 -58
  63. package/bundle/node_modules/@ethersproject/abi/lib.esm/fragments.js +0 -854
  64. package/bundle/node_modules/@ethersproject/abi/lib.esm/interface.js +0 -609
  65. package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/_version.js +0 -3
  66. package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/index.js +0 -66
  67. package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/_version.js +0 -3
  68. package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/index.js +0 -302
  69. package/bundle/node_modules/@ethersproject/address/lib.esm/_version.js +0 -3
  70. package/bundle/node_modules/@ethersproject/address/lib.esm/index.js +0 -110
  71. package/bundle/node_modules/@ethersproject/base64/lib.esm/base64.js +0 -20
  72. package/bundle/node_modules/@ethersproject/basex/lib.esm/index.js +0 -120
  73. package/bundle/node_modules/@ethersproject/bignumber/lib.esm/_version.js +0 -3
  74. package/bundle/node_modules/@ethersproject/bignumber/lib.esm/bignumber.js +0 -287
  75. package/bundle/node_modules/@ethersproject/bytes/lib.esm/_version.js +0 -3
  76. package/bundle/node_modules/@ethersproject/bytes/lib.esm/index.js +0 -402
  77. package/bundle/node_modules/@ethersproject/constants/lib.esm/addresses.js +0 -3
  78. package/bundle/node_modules/@ethersproject/constants/lib.esm/bignumbers.js +0 -8
  79. package/bundle/node_modules/@ethersproject/constants/lib.esm/hashes.js +0 -3
  80. package/bundle/node_modules/@ethersproject/contracts/lib.esm/_version.js +0 -3
  81. package/bundle/node_modules/@ethersproject/contracts/lib.esm/index.js +0 -893
  82. package/bundle/node_modules/@ethersproject/hash/lib.esm/_version.js +0 -3
  83. package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/decoder.js +0 -256
  84. package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/include.js +0 -36
  85. package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/lib.js +0 -135
  86. package/bundle/node_modules/@ethersproject/hash/lib.esm/id.js +0 -8
  87. package/bundle/node_modules/@ethersproject/hash/lib.esm/namehash.js +0 -64
  88. package/bundle/node_modules/@ethersproject/hash/lib.esm/typed-data.js +0 -443
  89. package/bundle/node_modules/@ethersproject/keccak256/lib.esm/index.js +0 -8
  90. package/bundle/node_modules/@ethersproject/keccak256/node_modules/js-sha3/src/sha3.js +0 -660
  91. package/bundle/node_modules/@ethersproject/logger/lib.esm/_version.js +0 -3
  92. package/bundle/node_modules/@ethersproject/logger/lib.esm/index.js +0 -352
  93. package/bundle/node_modules/@ethersproject/networks/lib.esm/_version.js +0 -3
  94. package/bundle/node_modules/@ethersproject/networks/lib.esm/index.js +0 -248
  95. package/bundle/node_modules/@ethersproject/properties/lib.esm/_version.js +0 -3
  96. package/bundle/node_modules/@ethersproject/properties/lib.esm/index.js +0 -127
  97. package/bundle/node_modules/@ethersproject/providers/lib.esm/_version.js +0 -3
  98. package/bundle/node_modules/@ethersproject/providers/lib.esm/base-provider.js +0 -2007
  99. package/bundle/node_modules/@ethersproject/providers/lib.esm/formatter.js +0 -422
  100. package/bundle/node_modules/@ethersproject/providers/lib.esm/json-rpc-provider.js +0 -674
  101. package/bundle/node_modules/@ethersproject/providers/lib.esm/web3-provider.js +0 -132
  102. package/bundle/node_modules/@ethersproject/rlp/lib.esm/_version.js +0 -3
  103. package/bundle/node_modules/@ethersproject/rlp/lib.esm/index.js +0 -120
  104. package/bundle/node_modules/@ethersproject/sha2/lib.esm/sha2.js +0 -8
  105. package/bundle/node_modules/@ethersproject/signing-key/lib.esm/_version.js +0 -3
  106. package/bundle/node_modules/@ethersproject/signing-key/lib.esm/elliptic.js +0 -2430
  107. package/bundle/node_modules/@ethersproject/signing-key/lib.esm/index.js +0 -76
  108. package/bundle/node_modules/@ethersproject/strings/lib.esm/_version.js +0 -3
  109. package/bundle/node_modules/@ethersproject/strings/lib.esm/utf8.js +0 -219
  110. package/bundle/node_modules/@ethersproject/transactions/lib.esm/_version.js +0 -3
  111. package/bundle/node_modules/@ethersproject/transactions/lib.esm/index.js +0 -279
  112. package/bundle/node_modules/@ethersproject/web/lib.esm/_version.js +0 -3
  113. package/bundle/node_modules/@ethersproject/web/lib.esm/geturl.js +0 -69
  114. package/bundle/node_modules/@ethersproject/web/lib.esm/index.js +0 -404
  115. package/bundle/node_modules/bech32/index.js +0 -187
  116. package/bundle/node_modules/bn.js/lib/bn.js +0 -3361
  117. package/bundle/node_modules/hash.js/lib/hash/common.js +0 -97
  118. package/bundle/node_modules/hash.js/lib/hash/hmac.js +0 -51
  119. package/bundle/node_modules/hash.js/lib/hash/ripemd.js +0 -152
  120. package/bundle/node_modules/hash.js/lib/hash/sha/1.js +0 -81
  121. package/bundle/node_modules/hash.js/lib/hash/sha/224.js +0 -33
  122. package/bundle/node_modules/hash.js/lib/hash/sha/256.js +0 -113
  123. package/bundle/node_modules/hash.js/lib/hash/sha/384.js +0 -39
  124. package/bundle/node_modules/hash.js/lib/hash/sha/512.js +0 -336
  125. package/bundle/node_modules/hash.js/lib/hash/sha/common.js +0 -53
  126. package/bundle/node_modules/hash.js/lib/hash/sha.js +0 -14
  127. package/bundle/node_modules/hash.js/lib/hash/utils.js +0 -282
  128. package/bundle/node_modules/hash.js/lib/hash.js +0 -33
  129. package/bundle/node_modules/inherits/inherits_browser.js +0 -33
  130. package/bundle/node_modules/minimalistic-assert/index.js +0 -13
@@ -1,404 +0,0 @@
1
- import { isBytesLike, hexlify } from '../../bytes/lib.esm/index.js';
2
- import { shallowCopy } from '../../properties/lib.esm/index.js';
3
- import { toUtf8Bytes, toUtf8String } from '../../strings/lib.esm/utf8.js';
4
- import { Logger } from '../../logger/lib.esm/index.js';
5
- import { version } from './_version.js';
6
- import { getUrl } from './geturl.js';
7
- import { encode, decode } from '../../base64/lib.esm/base64.js';
8
-
9
- var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
10
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
11
- return new (P || (P = Promise))(function (resolve, reject) {
12
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
13
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
14
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
15
- step((generator = generator.apply(thisArg, _arguments || [])).next());
16
- });
17
- };
18
- const logger = new Logger(version);
19
- function staller(duration) {
20
- return new Promise((resolve) => {
21
- setTimeout(resolve, duration);
22
- });
23
- }
24
- function bodyify(value, type) {
25
- if (value == null) {
26
- return null;
27
- }
28
- if (typeof (value) === "string") {
29
- return value;
30
- }
31
- if (isBytesLike(value)) {
32
- if (type && (type.split("/")[0] === "text" || type.split(";")[0].trim() === "application/json")) {
33
- try {
34
- return toUtf8String(value);
35
- }
36
- catch (error) { }
37
- }
38
- return hexlify(value);
39
- }
40
- return value;
41
- }
42
- function unpercent(value) {
43
- return toUtf8Bytes(value.replace(/%([0-9a-f][0-9a-f])/gi, (all, code) => {
44
- return String.fromCharCode(parseInt(code, 16));
45
- }));
46
- }
47
- // This API is still a work in progress; the future changes will likely be:
48
- // - ConnectionInfo => FetchDataRequest<T = any>
49
- // - FetchDataRequest.body? = string | Uint8Array | { contentType: string, data: string | Uint8Array }
50
- // - If string => text/plain, Uint8Array => application/octet-stream (if content-type unspecified)
51
- // - FetchDataRequest.processFunc = (body: Uint8Array, response: FetchDataResponse) => T
52
- // For this reason, it should be considered internal until the API is finalized
53
- function _fetchData(connection, body, processFunc) {
54
- // How many times to retry in the event of a throttle
55
- const attemptLimit = (typeof (connection) === "object" && connection.throttleLimit != null) ? connection.throttleLimit : 12;
56
- logger.assertArgument((attemptLimit > 0 && (attemptLimit % 1) === 0), "invalid connection throttle limit", "connection.throttleLimit", attemptLimit);
57
- const throttleCallback = ((typeof (connection) === "object") ? connection.throttleCallback : null);
58
- const throttleSlotInterval = ((typeof (connection) === "object" && typeof (connection.throttleSlotInterval) === "number") ? connection.throttleSlotInterval : 100);
59
- logger.assertArgument((throttleSlotInterval > 0 && (throttleSlotInterval % 1) === 0), "invalid connection throttle slot interval", "connection.throttleSlotInterval", throttleSlotInterval);
60
- const errorPassThrough = ((typeof (connection) === "object") ? !!(connection.errorPassThrough) : false);
61
- const headers = {};
62
- let url = null;
63
- // @TODO: Allow ConnectionInfo to override some of these values
64
- const options = {
65
- method: "GET",
66
- };
67
- let allow304 = false;
68
- let timeout = 2 * 60 * 1000;
69
- if (typeof (connection) === "string") {
70
- url = connection;
71
- }
72
- else if (typeof (connection) === "object") {
73
- if (connection == null || connection.url == null) {
74
- logger.throwArgumentError("missing URL", "connection.url", connection);
75
- }
76
- url = connection.url;
77
- if (typeof (connection.timeout) === "number" && connection.timeout > 0) {
78
- timeout = connection.timeout;
79
- }
80
- if (connection.headers) {
81
- for (const key in connection.headers) {
82
- headers[key.toLowerCase()] = { key: key, value: String(connection.headers[key]) };
83
- if (["if-none-match", "if-modified-since"].indexOf(key.toLowerCase()) >= 0) {
84
- allow304 = true;
85
- }
86
- }
87
- }
88
- options.allowGzip = !!connection.allowGzip;
89
- if (connection.user != null && connection.password != null) {
90
- if (url.substring(0, 6) !== "https:" && connection.allowInsecureAuthentication !== true) {
91
- logger.throwError("basic authentication requires a secure https url", Logger.errors.INVALID_ARGUMENT, { argument: "url", url: url, user: connection.user, password: "[REDACTED]" });
92
- }
93
- const authorization = connection.user + ":" + connection.password;
94
- headers["authorization"] = {
95
- key: "Authorization",
96
- value: "Basic " + encode(toUtf8Bytes(authorization))
97
- };
98
- }
99
- if (connection.skipFetchSetup != null) {
100
- options.skipFetchSetup = !!connection.skipFetchSetup;
101
- }
102
- if (connection.fetchOptions != null) {
103
- options.fetchOptions = shallowCopy(connection.fetchOptions);
104
- }
105
- }
106
- const reData = new RegExp("^data:([^;:]*)?(;base64)?,(.*)$", "i");
107
- const dataMatch = ((url) ? url.match(reData) : null);
108
- if (dataMatch) {
109
- try {
110
- const response = {
111
- statusCode: 200,
112
- statusMessage: "OK",
113
- headers: { "content-type": (dataMatch[1] || "text/plain") },
114
- body: (dataMatch[2] ? decode(dataMatch[3]) : unpercent(dataMatch[3]))
115
- };
116
- let result = response.body;
117
- if (processFunc) {
118
- result = processFunc(response.body, response);
119
- }
120
- return Promise.resolve(result);
121
- }
122
- catch (error) {
123
- logger.throwError("processing response error", Logger.errors.SERVER_ERROR, {
124
- body: bodyify(dataMatch[1], dataMatch[2]),
125
- error: error,
126
- requestBody: null,
127
- requestMethod: "GET",
128
- url: url
129
- });
130
- }
131
- }
132
- if (body) {
133
- options.method = "POST";
134
- options.body = body;
135
- if (headers["content-type"] == null) {
136
- headers["content-type"] = { key: "Content-Type", value: "application/octet-stream" };
137
- }
138
- if (headers["content-length"] == null) {
139
- headers["content-length"] = { key: "Content-Length", value: String(body.length) };
140
- }
141
- }
142
- const flatHeaders = {};
143
- Object.keys(headers).forEach((key) => {
144
- const header = headers[key];
145
- flatHeaders[header.key] = header.value;
146
- });
147
- options.headers = flatHeaders;
148
- const runningTimeout = (function () {
149
- let timer = null;
150
- const promise = new Promise(function (resolve, reject) {
151
- if (timeout) {
152
- timer = setTimeout(() => {
153
- if (timer == null) {
154
- return;
155
- }
156
- timer = null;
157
- reject(logger.makeError("timeout", Logger.errors.TIMEOUT, {
158
- requestBody: bodyify(options.body, flatHeaders["content-type"]),
159
- requestMethod: options.method,
160
- timeout: timeout,
161
- url: url
162
- }));
163
- }, timeout);
164
- }
165
- });
166
- const cancel = function () {
167
- if (timer == null) {
168
- return;
169
- }
170
- clearTimeout(timer);
171
- timer = null;
172
- };
173
- return { promise, cancel };
174
- })();
175
- const runningFetch = (function () {
176
- return __awaiter(this, void 0, void 0, function* () {
177
- for (let attempt = 0; attempt < attemptLimit; attempt++) {
178
- let response = null;
179
- try {
180
- response = yield getUrl(url, options);
181
- if (attempt < attemptLimit) {
182
- if (response.statusCode === 301 || response.statusCode === 302) {
183
- // Redirection; for now we only support absolute locataions
184
- const location = response.headers.location || "";
185
- if (options.method === "GET" && location.match(/^https:/)) {
186
- url = response.headers.location;
187
- continue;
188
- }
189
- }
190
- else if (response.statusCode === 429) {
191
- // Exponential back-off throttling
192
- let tryAgain = true;
193
- if (throttleCallback) {
194
- tryAgain = yield throttleCallback(attempt, url);
195
- }
196
- if (tryAgain) {
197
- let stall = 0;
198
- const retryAfter = response.headers["retry-after"];
199
- if (typeof (retryAfter) === "string" && retryAfter.match(/^[1-9][0-9]*$/)) {
200
- stall = parseInt(retryAfter) * 1000;
201
- }
202
- else {
203
- stall = throttleSlotInterval * parseInt(String(Math.random() * Math.pow(2, attempt)));
204
- }
205
- //console.log("Stalling 429");
206
- yield staller(stall);
207
- continue;
208
- }
209
- }
210
- }
211
- }
212
- catch (error) {
213
- response = error.response;
214
- if (response == null) {
215
- runningTimeout.cancel();
216
- logger.throwError("missing response", Logger.errors.SERVER_ERROR, {
217
- requestBody: bodyify(options.body, flatHeaders["content-type"]),
218
- requestMethod: options.method,
219
- serverError: error,
220
- url: url
221
- });
222
- }
223
- }
224
- let body = response.body;
225
- if (allow304 && response.statusCode === 304) {
226
- body = null;
227
- }
228
- else if (!errorPassThrough && (response.statusCode < 200 || response.statusCode >= 300)) {
229
- runningTimeout.cancel();
230
- logger.throwError("bad response", Logger.errors.SERVER_ERROR, {
231
- status: response.statusCode,
232
- headers: response.headers,
233
- body: bodyify(body, ((response.headers) ? response.headers["content-type"] : null)),
234
- requestBody: bodyify(options.body, flatHeaders["content-type"]),
235
- requestMethod: options.method,
236
- url: url
237
- });
238
- }
239
- if (processFunc) {
240
- try {
241
- const result = yield processFunc(body, response);
242
- runningTimeout.cancel();
243
- return result;
244
- }
245
- catch (error) {
246
- // Allow the processFunc to trigger a throttle
247
- if (error.throttleRetry && attempt < attemptLimit) {
248
- let tryAgain = true;
249
- if (throttleCallback) {
250
- tryAgain = yield throttleCallback(attempt, url);
251
- }
252
- if (tryAgain) {
253
- const timeout = throttleSlotInterval * parseInt(String(Math.random() * Math.pow(2, attempt)));
254
- //console.log("Stalling callback");
255
- yield staller(timeout);
256
- continue;
257
- }
258
- }
259
- runningTimeout.cancel();
260
- logger.throwError("processing response error", Logger.errors.SERVER_ERROR, {
261
- body: bodyify(body, ((response.headers) ? response.headers["content-type"] : null)),
262
- error: error,
263
- requestBody: bodyify(options.body, flatHeaders["content-type"]),
264
- requestMethod: options.method,
265
- url: url
266
- });
267
- }
268
- }
269
- runningTimeout.cancel();
270
- // If we had a processFunc, it either returned a T or threw above.
271
- // The "body" is now a Uint8Array.
272
- return body;
273
- }
274
- return logger.throwError("failed response", Logger.errors.SERVER_ERROR, {
275
- requestBody: bodyify(options.body, flatHeaders["content-type"]),
276
- requestMethod: options.method,
277
- url: url
278
- });
279
- });
280
- })();
281
- return Promise.race([runningTimeout.promise, runningFetch]);
282
- }
283
- function fetchJson(connection, json, processFunc) {
284
- let processJsonFunc = (value, response) => {
285
- let result = null;
286
- if (value != null) {
287
- try {
288
- result = JSON.parse(toUtf8String(value));
289
- }
290
- catch (error) {
291
- logger.throwError("invalid JSON", Logger.errors.SERVER_ERROR, {
292
- body: value,
293
- error: error
294
- });
295
- }
296
- }
297
- if (processFunc) {
298
- result = processFunc(result, response);
299
- }
300
- return result;
301
- };
302
- // If we have json to send, we must
303
- // - add content-type of application/json (unless already overridden)
304
- // - convert the json to bytes
305
- let body = null;
306
- if (json != null) {
307
- body = toUtf8Bytes(json);
308
- // Create a connection with the content-type set for JSON
309
- const updated = (typeof (connection) === "string") ? ({ url: connection }) : shallowCopy(connection);
310
- if (updated.headers) {
311
- const hasContentType = (Object.keys(updated.headers).filter((k) => (k.toLowerCase() === "content-type")).length) !== 0;
312
- if (!hasContentType) {
313
- updated.headers = shallowCopy(updated.headers);
314
- updated.headers["content-type"] = "application/json";
315
- }
316
- }
317
- else {
318
- updated.headers = { "content-type": "application/json" };
319
- }
320
- connection = updated;
321
- }
322
- return _fetchData(connection, body, processJsonFunc);
323
- }
324
- function poll(func, options) {
325
- if (!options) {
326
- options = {};
327
- }
328
- options = shallowCopy(options);
329
- if (options.floor == null) {
330
- options.floor = 0;
331
- }
332
- if (options.ceiling == null) {
333
- options.ceiling = 10000;
334
- }
335
- if (options.interval == null) {
336
- options.interval = 250;
337
- }
338
- return new Promise(function (resolve, reject) {
339
- let timer = null;
340
- let done = false;
341
- // Returns true if cancel was successful. Unsuccessful cancel means we're already done.
342
- const cancel = () => {
343
- if (done) {
344
- return false;
345
- }
346
- done = true;
347
- if (timer) {
348
- clearTimeout(timer);
349
- }
350
- return true;
351
- };
352
- if (options.timeout) {
353
- timer = setTimeout(() => {
354
- if (cancel()) {
355
- reject(new Error("timeout"));
356
- }
357
- }, options.timeout);
358
- }
359
- const retryLimit = options.retryLimit;
360
- let attempt = 0;
361
- function check() {
362
- return func().then(function (result) {
363
- // If we have a result, or are allowed null then we're done
364
- if (result !== undefined) {
365
- if (cancel()) {
366
- resolve(result);
367
- }
368
- }
369
- else if (options.oncePoll) {
370
- options.oncePoll.once("poll", check);
371
- }
372
- else if (options.onceBlock) {
373
- options.onceBlock.once("block", check);
374
- // Otherwise, exponential back-off (up to 10s) our next request
375
- }
376
- else if (!done) {
377
- attempt++;
378
- if (attempt > retryLimit) {
379
- if (cancel()) {
380
- reject(new Error("retry limit reached"));
381
- }
382
- return;
383
- }
384
- let timeout = options.interval * parseInt(String(Math.random() * Math.pow(2, attempt)));
385
- if (timeout < options.floor) {
386
- timeout = options.floor;
387
- }
388
- if (timeout > options.ceiling) {
389
- timeout = options.ceiling;
390
- }
391
- setTimeout(check, timeout);
392
- }
393
- return null;
394
- }, function (error) {
395
- if (cancel()) {
396
- reject(error);
397
- }
398
- });
399
- }
400
- check();
401
- });
402
- }
403
-
404
- export { _fetchData, fetchJson, poll };
@@ -1,187 +0,0 @@
1
- import { getDefaultExportFromCjs } from '../../_virtual/_commonjsHelpers.js';
2
-
3
- var ALPHABET = 'qpzry9x8gf2tvdw0s3jn54khce6mua7l';
4
-
5
- // pre-compute lookup table
6
- var ALPHABET_MAP = {};
7
- for (var z = 0; z < ALPHABET.length; z++) {
8
- var x = ALPHABET.charAt(z);
9
-
10
- if (ALPHABET_MAP[x] !== undefined) throw new TypeError(x + ' is ambiguous')
11
- ALPHABET_MAP[x] = z;
12
- }
13
-
14
- function polymodStep (pre) {
15
- var b = pre >> 25;
16
- return ((pre & 0x1FFFFFF) << 5) ^
17
- (-((b >> 0) & 1) & 0x3b6a57b2) ^
18
- (-((b >> 1) & 1) & 0x26508e6d) ^
19
- (-((b >> 2) & 1) & 0x1ea119fa) ^
20
- (-((b >> 3) & 1) & 0x3d4233dd) ^
21
- (-((b >> 4) & 1) & 0x2a1462b3)
22
- }
23
-
24
- function prefixChk (prefix) {
25
- var chk = 1;
26
- for (var i = 0; i < prefix.length; ++i) {
27
- var c = prefix.charCodeAt(i);
28
- if (c < 33 || c > 126) return 'Invalid prefix (' + prefix + ')'
29
-
30
- chk = polymodStep(chk) ^ (c >> 5);
31
- }
32
- chk = polymodStep(chk);
33
-
34
- for (i = 0; i < prefix.length; ++i) {
35
- var v = prefix.charCodeAt(i);
36
- chk = polymodStep(chk) ^ (v & 0x1f);
37
- }
38
- return chk
39
- }
40
-
41
- function encode (prefix, words, LIMIT) {
42
- LIMIT = LIMIT || 90;
43
- if ((prefix.length + 7 + words.length) > LIMIT) throw new TypeError('Exceeds length limit')
44
-
45
- prefix = prefix.toLowerCase();
46
-
47
- // determine chk mod
48
- var chk = prefixChk(prefix);
49
- if (typeof chk === 'string') throw new Error(chk)
50
-
51
- var result = prefix + '1';
52
- for (var i = 0; i < words.length; ++i) {
53
- var x = words[i];
54
- if ((x >> 5) !== 0) throw new Error('Non 5-bit word')
55
-
56
- chk = polymodStep(chk) ^ x;
57
- result += ALPHABET.charAt(x);
58
- }
59
-
60
- for (i = 0; i < 6; ++i) {
61
- chk = polymodStep(chk);
62
- }
63
- chk ^= 1;
64
-
65
- for (i = 0; i < 6; ++i) {
66
- var v = (chk >> ((5 - i) * 5)) & 0x1f;
67
- result += ALPHABET.charAt(v);
68
- }
69
-
70
- return result
71
- }
72
-
73
- function __decode (str, LIMIT) {
74
- LIMIT = LIMIT || 90;
75
- if (str.length < 8) return str + ' too short'
76
- if (str.length > LIMIT) return 'Exceeds length limit'
77
-
78
- // don't allow mixed case
79
- var lowered = str.toLowerCase();
80
- var uppered = str.toUpperCase();
81
- if (str !== lowered && str !== uppered) return 'Mixed-case string ' + str
82
- str = lowered;
83
-
84
- var split = str.lastIndexOf('1');
85
- if (split === -1) return 'No separator character for ' + str
86
- if (split === 0) return 'Missing prefix for ' + str
87
-
88
- var prefix = str.slice(0, split);
89
- var wordChars = str.slice(split + 1);
90
- if (wordChars.length < 6) return 'Data too short'
91
-
92
- var chk = prefixChk(prefix);
93
- if (typeof chk === 'string') return chk
94
-
95
- var words = [];
96
- for (var i = 0; i < wordChars.length; ++i) {
97
- var c = wordChars.charAt(i);
98
- var v = ALPHABET_MAP[c];
99
- if (v === undefined) return 'Unknown character ' + c
100
- chk = polymodStep(chk) ^ v;
101
-
102
- // not in the checksum?
103
- if (i + 6 >= wordChars.length) continue
104
- words.push(v);
105
- }
106
-
107
- if (chk !== 1) return 'Invalid checksum for ' + str
108
- return { prefix: prefix, words: words }
109
- }
110
-
111
- function decodeUnsafe () {
112
- var res = __decode.apply(null, arguments);
113
- if (typeof res === 'object') return res
114
- }
115
-
116
- function decode (str) {
117
- var res = __decode.apply(null, arguments);
118
- if (typeof res === 'object') return res
119
-
120
- throw new Error(res)
121
- }
122
-
123
- function convert (data, inBits, outBits, pad) {
124
- var value = 0;
125
- var bits = 0;
126
- var maxV = (1 << outBits) - 1;
127
-
128
- var result = [];
129
- for (var i = 0; i < data.length; ++i) {
130
- value = (value << inBits) | data[i];
131
- bits += inBits;
132
-
133
- while (bits >= outBits) {
134
- bits -= outBits;
135
- result.push((value >> bits) & maxV);
136
- }
137
- }
138
-
139
- if (pad) {
140
- if (bits > 0) {
141
- result.push((value << (outBits - bits)) & maxV);
142
- }
143
- } else {
144
- if (bits >= inBits) return 'Excess padding'
145
- if ((value << (outBits - bits)) & maxV) return 'Non-zero padding'
146
- }
147
-
148
- return result
149
- }
150
-
151
- function toWordsUnsafe (bytes) {
152
- var res = convert(bytes, 8, 5, true);
153
- if (Array.isArray(res)) return res
154
- }
155
-
156
- function toWords (bytes) {
157
- var res = convert(bytes, 8, 5, true);
158
- if (Array.isArray(res)) return res
159
-
160
- throw new Error(res)
161
- }
162
-
163
- function fromWordsUnsafe (words) {
164
- var res = convert(words, 5, 8, false);
165
- if (Array.isArray(res)) return res
166
- }
167
-
168
- function fromWords (words) {
169
- var res = convert(words, 5, 8, false);
170
- if (Array.isArray(res)) return res
171
-
172
- throw new Error(res)
173
- }
174
-
175
- var bech32 = {
176
- decodeUnsafe: decodeUnsafe,
177
- decode: decode,
178
- encode: encode,
179
- toWordsUnsafe: toWordsUnsafe,
180
- toWords: toWords,
181
- fromWordsUnsafe: fromWordsUnsafe,
182
- fromWords: fromWords
183
- };
184
-
185
- var bech32$1 = /*@__PURE__*/getDefaultExportFromCjs(bech32);
186
-
187
- export { bech32$1 as default };