koilib 2.2.0 → 2.3.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.
- package/README.md +17 -8
- package/dist/koinos.js +2495 -2298
- package/dist/koinos.min.js +1 -1
- package/lib/Contract.d.ts +47 -152
- package/lib/Contract.js +61 -148
- package/lib/Contract.js.map +1 -1
- package/lib/Provider.d.ts +1 -4
- package/lib/Provider.js +1 -1
- package/lib/Provider.js.map +1 -1
- package/lib/Serializer.d.ts +81 -0
- package/lib/Serializer.js +169 -0
- package/lib/Serializer.js.map +1 -0
- package/lib/Signer.d.ts +130 -24
- package/lib/Signer.js +151 -47
- package/lib/Signer.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/index2.js +2 -0
- package/lib/index2.js.map +1 -1
- package/lib/interface.d.ts +161 -24
- package/lib/{krc20-proto.json → jsonDescriptors/krc20-proto.json} +1 -1
- package/lib/{protocol-proto.json → jsonDescriptors/protocol-proto.json} +22 -18
- package/lib/utils.d.ts +249 -1
- package/lib/utils.js +4 -2
- package/lib/utils.js.map +1 -1
- package/package.json +2 -4
package/dist/koinos.js
CHANGED
|
@@ -138,58 +138,58 @@ module.exports = base
|
|
|
138
138
|
/***/ ((module) => {
|
|
139
139
|
|
|
140
140
|
"use strict";
|
|
141
|
-
|
|
142
|
-
module.exports = asPromise;
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Callback as used by {@link util.asPromise}.
|
|
146
|
-
* @typedef asPromiseCallback
|
|
147
|
-
* @type {function}
|
|
148
|
-
* @param {Error|null} error Error, if any
|
|
149
|
-
* @param {...*} params Additional arguments
|
|
150
|
-
* @returns {undefined}
|
|
151
|
-
*/
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Returns a promise from a node-style callback function.
|
|
155
|
-
* @memberof util
|
|
156
|
-
* @param {asPromiseCallback} fn Function to call
|
|
157
|
-
* @param {*} ctx Function context
|
|
158
|
-
* @param {...*} params Function arguments
|
|
159
|
-
* @returns {Promise<*>} Promisified function
|
|
160
|
-
*/
|
|
161
|
-
function asPromise(fn, ctx/*, varargs */) {
|
|
162
|
-
var params = new Array(arguments.length - 1),
|
|
163
|
-
offset = 0,
|
|
164
|
-
index = 2,
|
|
165
|
-
pending = true;
|
|
166
|
-
while (index < arguments.length)
|
|
167
|
-
params[offset++] = arguments[index++];
|
|
168
|
-
return new Promise(function executor(resolve, reject) {
|
|
169
|
-
params[offset] = function callback(err/*, varargs */) {
|
|
170
|
-
if (pending) {
|
|
171
|
-
pending = false;
|
|
172
|
-
if (err)
|
|
173
|
-
reject(err);
|
|
174
|
-
else {
|
|
175
|
-
var params = new Array(arguments.length - 1),
|
|
176
|
-
offset = 0;
|
|
177
|
-
while (offset < params.length)
|
|
178
|
-
params[offset++] = arguments[offset];
|
|
179
|
-
resolve.apply(null, params);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
try {
|
|
184
|
-
fn.apply(ctx || null, params);
|
|
185
|
-
} catch (err) {
|
|
186
|
-
if (pending) {
|
|
187
|
-
pending = false;
|
|
188
|
-
reject(err);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
}
|
|
141
|
+
|
|
142
|
+
module.exports = asPromise;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Callback as used by {@link util.asPromise}.
|
|
146
|
+
* @typedef asPromiseCallback
|
|
147
|
+
* @type {function}
|
|
148
|
+
* @param {Error|null} error Error, if any
|
|
149
|
+
* @param {...*} params Additional arguments
|
|
150
|
+
* @returns {undefined}
|
|
151
|
+
*/
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Returns a promise from a node-style callback function.
|
|
155
|
+
* @memberof util
|
|
156
|
+
* @param {asPromiseCallback} fn Function to call
|
|
157
|
+
* @param {*} ctx Function context
|
|
158
|
+
* @param {...*} params Function arguments
|
|
159
|
+
* @returns {Promise<*>} Promisified function
|
|
160
|
+
*/
|
|
161
|
+
function asPromise(fn, ctx/*, varargs */) {
|
|
162
|
+
var params = new Array(arguments.length - 1),
|
|
163
|
+
offset = 0,
|
|
164
|
+
index = 2,
|
|
165
|
+
pending = true;
|
|
166
|
+
while (index < arguments.length)
|
|
167
|
+
params[offset++] = arguments[index++];
|
|
168
|
+
return new Promise(function executor(resolve, reject) {
|
|
169
|
+
params[offset] = function callback(err/*, varargs */) {
|
|
170
|
+
if (pending) {
|
|
171
|
+
pending = false;
|
|
172
|
+
if (err)
|
|
173
|
+
reject(err);
|
|
174
|
+
else {
|
|
175
|
+
var params = new Array(arguments.length - 1),
|
|
176
|
+
offset = 0;
|
|
177
|
+
while (offset < params.length)
|
|
178
|
+
params[offset++] = arguments[offset];
|
|
179
|
+
resolve.apply(null, params);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
try {
|
|
184
|
+
fn.apply(ctx || null, params);
|
|
185
|
+
} catch (err) {
|
|
186
|
+
if (pending) {
|
|
187
|
+
pending = false;
|
|
188
|
+
reject(err);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
193
|
|
|
194
194
|
|
|
195
195
|
/***/ }),
|
|
@@ -198,145 +198,145 @@ function asPromise(fn, ctx/*, varargs */) {
|
|
|
198
198
|
/***/ ((__unused_webpack_module, exports) => {
|
|
199
199
|
|
|
200
200
|
"use strict";
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* A minimal base64 implementation for number arrays.
|
|
205
|
-
* @memberof util
|
|
206
|
-
* @namespace
|
|
207
|
-
*/
|
|
208
|
-
var base64 = exports;
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Calculates the byte length of a base64 encoded string.
|
|
212
|
-
* @param {string} string Base64 encoded string
|
|
213
|
-
* @returns {number} Byte length
|
|
214
|
-
*/
|
|
215
|
-
base64.length = function length(string) {
|
|
216
|
-
var p = string.length;
|
|
217
|
-
if (!p)
|
|
218
|
-
return 0;
|
|
219
|
-
var n = 0;
|
|
220
|
-
while (--p % 4 > 1 && string.charAt(p) === "=")
|
|
221
|
-
++n;
|
|
222
|
-
return Math.ceil(string.length * 3) / 4 - n;
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
// Base64 encoding table
|
|
226
|
-
var b64 = new Array(64);
|
|
227
|
-
|
|
228
|
-
// Base64 decoding table
|
|
229
|
-
var s64 = new Array(123);
|
|
230
|
-
|
|
231
|
-
// 65..90, 97..122, 48..57, 43, 47
|
|
232
|
-
for (var i = 0; i < 64;)
|
|
233
|
-
s64[b64[i] = i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i - 59 | 43] = i++;
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* Encodes a buffer to a base64 encoded string.
|
|
237
|
-
* @param {Uint8Array} buffer Source buffer
|
|
238
|
-
* @param {number} start Source start
|
|
239
|
-
* @param {number} end Source end
|
|
240
|
-
* @returns {string} Base64 encoded string
|
|
241
|
-
*/
|
|
242
|
-
base64.encode = function encode(buffer, start, end) {
|
|
243
|
-
var parts = null,
|
|
244
|
-
chunk = [];
|
|
245
|
-
var i = 0, // output index
|
|
246
|
-
j = 0, // goto index
|
|
247
|
-
t; // temporary
|
|
248
|
-
while (start < end) {
|
|
249
|
-
var b = buffer[start++];
|
|
250
|
-
switch (j) {
|
|
251
|
-
case 0:
|
|
252
|
-
chunk[i++] = b64[b >> 2];
|
|
253
|
-
t = (b & 3) << 4;
|
|
254
|
-
j = 1;
|
|
255
|
-
break;
|
|
256
|
-
case 1:
|
|
257
|
-
chunk[i++] = b64[t | b >> 4];
|
|
258
|
-
t = (b & 15) << 2;
|
|
259
|
-
j = 2;
|
|
260
|
-
break;
|
|
261
|
-
case 2:
|
|
262
|
-
chunk[i++] = b64[t | b >> 6];
|
|
263
|
-
chunk[i++] = b64[b & 63];
|
|
264
|
-
j = 0;
|
|
265
|
-
break;
|
|
266
|
-
}
|
|
267
|
-
if (i > 8191) {
|
|
268
|
-
(parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
|
|
269
|
-
i = 0;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
if (j) {
|
|
273
|
-
chunk[i++] = b64[t];
|
|
274
|
-
chunk[i++] = 61;
|
|
275
|
-
if (j === 1)
|
|
276
|
-
chunk[i++] = 61;
|
|
277
|
-
}
|
|
278
|
-
if (parts) {
|
|
279
|
-
if (i)
|
|
280
|
-
parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
|
|
281
|
-
return parts.join("");
|
|
282
|
-
}
|
|
283
|
-
return String.fromCharCode.apply(String, chunk.slice(0, i));
|
|
284
|
-
};
|
|
285
|
-
|
|
286
|
-
var invalidEncoding = "invalid encoding";
|
|
287
|
-
|
|
288
|
-
/**
|
|
289
|
-
* Decodes a base64 encoded string to a buffer.
|
|
290
|
-
* @param {string} string Source string
|
|
291
|
-
* @param {Uint8Array} buffer Destination buffer
|
|
292
|
-
* @param {number} offset Destination offset
|
|
293
|
-
* @returns {number} Number of bytes written
|
|
294
|
-
* @throws {Error} If encoding is invalid
|
|
295
|
-
*/
|
|
296
|
-
base64.decode = function decode(string, buffer, offset) {
|
|
297
|
-
var start = offset;
|
|
298
|
-
var j = 0, // goto index
|
|
299
|
-
t; // temporary
|
|
300
|
-
for (var i = 0; i < string.length;) {
|
|
301
|
-
var c = string.charCodeAt(i++);
|
|
302
|
-
if (c === 61 && j > 1)
|
|
303
|
-
break;
|
|
304
|
-
if ((c = s64[c]) === undefined)
|
|
305
|
-
throw Error(invalidEncoding);
|
|
306
|
-
switch (j) {
|
|
307
|
-
case 0:
|
|
308
|
-
t = c;
|
|
309
|
-
j = 1;
|
|
310
|
-
break;
|
|
311
|
-
case 1:
|
|
312
|
-
buffer[offset++] = t << 2 | (c & 48) >> 4;
|
|
313
|
-
t = c;
|
|
314
|
-
j = 2;
|
|
315
|
-
break;
|
|
316
|
-
case 2:
|
|
317
|
-
buffer[offset++] = (t & 15) << 4 | (c & 60) >> 2;
|
|
318
|
-
t = c;
|
|
319
|
-
j = 3;
|
|
320
|
-
break;
|
|
321
|
-
case 3:
|
|
322
|
-
buffer[offset++] = (t & 3) << 6 | c;
|
|
323
|
-
j = 0;
|
|
324
|
-
break;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
if (j === 1)
|
|
328
|
-
throw Error(invalidEncoding);
|
|
329
|
-
return offset - start;
|
|
330
|
-
};
|
|
331
|
-
|
|
332
|
-
/**
|
|
333
|
-
* Tests if the specified string appears to be base64 encoded.
|
|
334
|
-
* @param {string} string String to test
|
|
335
|
-
* @returns {boolean} `true` if probably base64 encoded, otherwise false
|
|
336
|
-
*/
|
|
337
|
-
base64.test = function test(string) {
|
|
338
|
-
return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(string);
|
|
339
|
-
};
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* A minimal base64 implementation for number arrays.
|
|
205
|
+
* @memberof util
|
|
206
|
+
* @namespace
|
|
207
|
+
*/
|
|
208
|
+
var base64 = exports;
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Calculates the byte length of a base64 encoded string.
|
|
212
|
+
* @param {string} string Base64 encoded string
|
|
213
|
+
* @returns {number} Byte length
|
|
214
|
+
*/
|
|
215
|
+
base64.length = function length(string) {
|
|
216
|
+
var p = string.length;
|
|
217
|
+
if (!p)
|
|
218
|
+
return 0;
|
|
219
|
+
var n = 0;
|
|
220
|
+
while (--p % 4 > 1 && string.charAt(p) === "=")
|
|
221
|
+
++n;
|
|
222
|
+
return Math.ceil(string.length * 3) / 4 - n;
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
// Base64 encoding table
|
|
226
|
+
var b64 = new Array(64);
|
|
227
|
+
|
|
228
|
+
// Base64 decoding table
|
|
229
|
+
var s64 = new Array(123);
|
|
230
|
+
|
|
231
|
+
// 65..90, 97..122, 48..57, 43, 47
|
|
232
|
+
for (var i = 0; i < 64;)
|
|
233
|
+
s64[b64[i] = i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i - 59 | 43] = i++;
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Encodes a buffer to a base64 encoded string.
|
|
237
|
+
* @param {Uint8Array} buffer Source buffer
|
|
238
|
+
* @param {number} start Source start
|
|
239
|
+
* @param {number} end Source end
|
|
240
|
+
* @returns {string} Base64 encoded string
|
|
241
|
+
*/
|
|
242
|
+
base64.encode = function encode(buffer, start, end) {
|
|
243
|
+
var parts = null,
|
|
244
|
+
chunk = [];
|
|
245
|
+
var i = 0, // output index
|
|
246
|
+
j = 0, // goto index
|
|
247
|
+
t; // temporary
|
|
248
|
+
while (start < end) {
|
|
249
|
+
var b = buffer[start++];
|
|
250
|
+
switch (j) {
|
|
251
|
+
case 0:
|
|
252
|
+
chunk[i++] = b64[b >> 2];
|
|
253
|
+
t = (b & 3) << 4;
|
|
254
|
+
j = 1;
|
|
255
|
+
break;
|
|
256
|
+
case 1:
|
|
257
|
+
chunk[i++] = b64[t | b >> 4];
|
|
258
|
+
t = (b & 15) << 2;
|
|
259
|
+
j = 2;
|
|
260
|
+
break;
|
|
261
|
+
case 2:
|
|
262
|
+
chunk[i++] = b64[t | b >> 6];
|
|
263
|
+
chunk[i++] = b64[b & 63];
|
|
264
|
+
j = 0;
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
if (i > 8191) {
|
|
268
|
+
(parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
|
|
269
|
+
i = 0;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
if (j) {
|
|
273
|
+
chunk[i++] = b64[t];
|
|
274
|
+
chunk[i++] = 61;
|
|
275
|
+
if (j === 1)
|
|
276
|
+
chunk[i++] = 61;
|
|
277
|
+
}
|
|
278
|
+
if (parts) {
|
|
279
|
+
if (i)
|
|
280
|
+
parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
|
|
281
|
+
return parts.join("");
|
|
282
|
+
}
|
|
283
|
+
return String.fromCharCode.apply(String, chunk.slice(0, i));
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
var invalidEncoding = "invalid encoding";
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Decodes a base64 encoded string to a buffer.
|
|
290
|
+
* @param {string} string Source string
|
|
291
|
+
* @param {Uint8Array} buffer Destination buffer
|
|
292
|
+
* @param {number} offset Destination offset
|
|
293
|
+
* @returns {number} Number of bytes written
|
|
294
|
+
* @throws {Error} If encoding is invalid
|
|
295
|
+
*/
|
|
296
|
+
base64.decode = function decode(string, buffer, offset) {
|
|
297
|
+
var start = offset;
|
|
298
|
+
var j = 0, // goto index
|
|
299
|
+
t; // temporary
|
|
300
|
+
for (var i = 0; i < string.length;) {
|
|
301
|
+
var c = string.charCodeAt(i++);
|
|
302
|
+
if (c === 61 && j > 1)
|
|
303
|
+
break;
|
|
304
|
+
if ((c = s64[c]) === undefined)
|
|
305
|
+
throw Error(invalidEncoding);
|
|
306
|
+
switch (j) {
|
|
307
|
+
case 0:
|
|
308
|
+
t = c;
|
|
309
|
+
j = 1;
|
|
310
|
+
break;
|
|
311
|
+
case 1:
|
|
312
|
+
buffer[offset++] = t << 2 | (c & 48) >> 4;
|
|
313
|
+
t = c;
|
|
314
|
+
j = 2;
|
|
315
|
+
break;
|
|
316
|
+
case 2:
|
|
317
|
+
buffer[offset++] = (t & 15) << 4 | (c & 60) >> 2;
|
|
318
|
+
t = c;
|
|
319
|
+
j = 3;
|
|
320
|
+
break;
|
|
321
|
+
case 3:
|
|
322
|
+
buffer[offset++] = (t & 3) << 6 | c;
|
|
323
|
+
j = 0;
|
|
324
|
+
break;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
if (j === 1)
|
|
328
|
+
throw Error(invalidEncoding);
|
|
329
|
+
return offset - start;
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Tests if the specified string appears to be base64 encoded.
|
|
334
|
+
* @param {string} string String to test
|
|
335
|
+
* @returns {boolean} `true` if probably base64 encoded, otherwise false
|
|
336
|
+
*/
|
|
337
|
+
base64.test = function test(string) {
|
|
338
|
+
return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(string);
|
|
339
|
+
};
|
|
340
340
|
|
|
341
341
|
|
|
342
342
|
/***/ }),
|
|
@@ -345,105 +345,105 @@ base64.test = function test(string) {
|
|
|
345
345
|
/***/ ((module) => {
|
|
346
346
|
|
|
347
347
|
"use strict";
|
|
348
|
-
|
|
349
|
-
module.exports = codegen;
|
|
350
|
-
|
|
351
|
-
/**
|
|
352
|
-
* Begins generating a function.
|
|
353
|
-
* @memberof util
|
|
354
|
-
* @param {string[]} functionParams Function parameter names
|
|
355
|
-
* @param {string} [functionName] Function name if not anonymous
|
|
356
|
-
* @returns {Codegen} Appender that appends code to the function's body
|
|
357
|
-
*/
|
|
358
|
-
function codegen(functionParams, functionName) {
|
|
359
|
-
|
|
360
|
-
/* istanbul ignore if */
|
|
361
|
-
if (typeof functionParams === "string") {
|
|
362
|
-
functionName = functionParams;
|
|
363
|
-
functionParams = undefined;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
var body = [];
|
|
367
|
-
|
|
368
|
-
/**
|
|
369
|
-
* Appends code to the function's body or finishes generation.
|
|
370
|
-
* @typedef Codegen
|
|
371
|
-
* @type {function}
|
|
372
|
-
* @param {string|Object.<string,*>} [formatStringOrScope] Format string or, to finish the function, an object of additional scope variables, if any
|
|
373
|
-
* @param {...*} [formatParams] Format parameters
|
|
374
|
-
* @returns {Codegen|Function} Itself or the generated function if finished
|
|
375
|
-
* @throws {Error} If format parameter counts do not match
|
|
376
|
-
*/
|
|
377
|
-
|
|
378
|
-
function Codegen(formatStringOrScope) {
|
|
379
|
-
// note that explicit array handling below makes this ~50% faster
|
|
380
|
-
|
|
381
|
-
// finish the function
|
|
382
|
-
if (typeof formatStringOrScope !== "string") {
|
|
383
|
-
var source = toString();
|
|
384
|
-
if (codegen.verbose)
|
|
385
|
-
console.log("codegen: " + source); // eslint-disable-line no-console
|
|
386
|
-
source = "return " + source;
|
|
387
|
-
if (formatStringOrScope) {
|
|
388
|
-
var scopeKeys = Object.keys(formatStringOrScope),
|
|
389
|
-
scopeParams = new Array(scopeKeys.length + 1),
|
|
390
|
-
scopeValues = new Array(scopeKeys.length),
|
|
391
|
-
scopeOffset = 0;
|
|
392
|
-
while (scopeOffset < scopeKeys.length) {
|
|
393
|
-
scopeParams[scopeOffset] = scopeKeys[scopeOffset];
|
|
394
|
-
scopeValues[scopeOffset] = formatStringOrScope[scopeKeys[scopeOffset++]];
|
|
395
|
-
}
|
|
396
|
-
scopeParams[scopeOffset] = source;
|
|
397
|
-
return Function.apply(null, scopeParams).apply(null, scopeValues); // eslint-disable-line no-new-func
|
|
398
|
-
}
|
|
399
|
-
return Function(source)(); // eslint-disable-line no-new-func
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
// otherwise append to body
|
|
403
|
-
var formatParams = new Array(arguments.length - 1),
|
|
404
|
-
formatOffset = 0;
|
|
405
|
-
while (formatOffset < formatParams.length)
|
|
406
|
-
formatParams[formatOffset] = arguments[++formatOffset];
|
|
407
|
-
formatOffset = 0;
|
|
408
|
-
formatStringOrScope = formatStringOrScope.replace(/%([%dfijs])/g, function replace($0, $1) {
|
|
409
|
-
var value = formatParams[formatOffset++];
|
|
410
|
-
switch ($1) {
|
|
411
|
-
case "d": case "f": return String(Number(value));
|
|
412
|
-
case "i": return String(Math.floor(value));
|
|
413
|
-
case "j": return JSON.stringify(value);
|
|
414
|
-
case "s": return String(value);
|
|
415
|
-
}
|
|
416
|
-
return "%";
|
|
417
|
-
});
|
|
418
|
-
if (formatOffset !== formatParams.length)
|
|
419
|
-
throw Error("parameter count mismatch");
|
|
420
|
-
body.push(formatStringOrScope);
|
|
421
|
-
return Codegen;
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
function toString(functionNameOverride) {
|
|
425
|
-
return "function " + (functionNameOverride || functionName || "") + "(" + (functionParams && functionParams.join(",") || "") + "){\n " + body.join("\n ") + "\n}";
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
Codegen.toString = toString;
|
|
429
|
-
return Codegen;
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
/**
|
|
433
|
-
* Begins generating a function.
|
|
434
|
-
* @memberof util
|
|
435
|
-
* @function codegen
|
|
436
|
-
* @param {string} [functionName] Function name if not anonymous
|
|
437
|
-
* @returns {Codegen} Appender that appends code to the function's body
|
|
438
|
-
* @variation 2
|
|
439
|
-
*/
|
|
440
|
-
|
|
441
|
-
/**
|
|
442
|
-
* When set to `true`, codegen will log generated code to console. Useful for debugging.
|
|
443
|
-
* @name util.codegen.verbose
|
|
444
|
-
* @type {boolean}
|
|
445
|
-
*/
|
|
446
|
-
codegen.verbose = false;
|
|
348
|
+
|
|
349
|
+
module.exports = codegen;
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Begins generating a function.
|
|
353
|
+
* @memberof util
|
|
354
|
+
* @param {string[]} functionParams Function parameter names
|
|
355
|
+
* @param {string} [functionName] Function name if not anonymous
|
|
356
|
+
* @returns {Codegen} Appender that appends code to the function's body
|
|
357
|
+
*/
|
|
358
|
+
function codegen(functionParams, functionName) {
|
|
359
|
+
|
|
360
|
+
/* istanbul ignore if */
|
|
361
|
+
if (typeof functionParams === "string") {
|
|
362
|
+
functionName = functionParams;
|
|
363
|
+
functionParams = undefined;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
var body = [];
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Appends code to the function's body or finishes generation.
|
|
370
|
+
* @typedef Codegen
|
|
371
|
+
* @type {function}
|
|
372
|
+
* @param {string|Object.<string,*>} [formatStringOrScope] Format string or, to finish the function, an object of additional scope variables, if any
|
|
373
|
+
* @param {...*} [formatParams] Format parameters
|
|
374
|
+
* @returns {Codegen|Function} Itself or the generated function if finished
|
|
375
|
+
* @throws {Error} If format parameter counts do not match
|
|
376
|
+
*/
|
|
377
|
+
|
|
378
|
+
function Codegen(formatStringOrScope) {
|
|
379
|
+
// note that explicit array handling below makes this ~50% faster
|
|
380
|
+
|
|
381
|
+
// finish the function
|
|
382
|
+
if (typeof formatStringOrScope !== "string") {
|
|
383
|
+
var source = toString();
|
|
384
|
+
if (codegen.verbose)
|
|
385
|
+
console.log("codegen: " + source); // eslint-disable-line no-console
|
|
386
|
+
source = "return " + source;
|
|
387
|
+
if (formatStringOrScope) {
|
|
388
|
+
var scopeKeys = Object.keys(formatStringOrScope),
|
|
389
|
+
scopeParams = new Array(scopeKeys.length + 1),
|
|
390
|
+
scopeValues = new Array(scopeKeys.length),
|
|
391
|
+
scopeOffset = 0;
|
|
392
|
+
while (scopeOffset < scopeKeys.length) {
|
|
393
|
+
scopeParams[scopeOffset] = scopeKeys[scopeOffset];
|
|
394
|
+
scopeValues[scopeOffset] = formatStringOrScope[scopeKeys[scopeOffset++]];
|
|
395
|
+
}
|
|
396
|
+
scopeParams[scopeOffset] = source;
|
|
397
|
+
return Function.apply(null, scopeParams).apply(null, scopeValues); // eslint-disable-line no-new-func
|
|
398
|
+
}
|
|
399
|
+
return Function(source)(); // eslint-disable-line no-new-func
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// otherwise append to body
|
|
403
|
+
var formatParams = new Array(arguments.length - 1),
|
|
404
|
+
formatOffset = 0;
|
|
405
|
+
while (formatOffset < formatParams.length)
|
|
406
|
+
formatParams[formatOffset] = arguments[++formatOffset];
|
|
407
|
+
formatOffset = 0;
|
|
408
|
+
formatStringOrScope = formatStringOrScope.replace(/%([%dfijs])/g, function replace($0, $1) {
|
|
409
|
+
var value = formatParams[formatOffset++];
|
|
410
|
+
switch ($1) {
|
|
411
|
+
case "d": case "f": return String(Number(value));
|
|
412
|
+
case "i": return String(Math.floor(value));
|
|
413
|
+
case "j": return JSON.stringify(value);
|
|
414
|
+
case "s": return String(value);
|
|
415
|
+
}
|
|
416
|
+
return "%";
|
|
417
|
+
});
|
|
418
|
+
if (formatOffset !== formatParams.length)
|
|
419
|
+
throw Error("parameter count mismatch");
|
|
420
|
+
body.push(formatStringOrScope);
|
|
421
|
+
return Codegen;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
function toString(functionNameOverride) {
|
|
425
|
+
return "function " + (functionNameOverride || functionName || "") + "(" + (functionParams && functionParams.join(",") || "") + "){\n " + body.join("\n ") + "\n}";
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
Codegen.toString = toString;
|
|
429
|
+
return Codegen;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* Begins generating a function.
|
|
434
|
+
* @memberof util
|
|
435
|
+
* @function codegen
|
|
436
|
+
* @param {string} [functionName] Function name if not anonymous
|
|
437
|
+
* @returns {Codegen} Appender that appends code to the function's body
|
|
438
|
+
* @variation 2
|
|
439
|
+
*/
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* When set to `true`, codegen will log generated code to console. Useful for debugging.
|
|
443
|
+
* @name util.codegen.verbose
|
|
444
|
+
* @type {boolean}
|
|
445
|
+
*/
|
|
446
|
+
codegen.verbose = false;
|
|
447
447
|
|
|
448
448
|
|
|
449
449
|
/***/ }),
|
|
@@ -452,82 +452,82 @@ codegen.verbose = false;
|
|
|
452
452
|
/***/ ((module) => {
|
|
453
453
|
|
|
454
454
|
"use strict";
|
|
455
|
-
|
|
456
|
-
module.exports = EventEmitter;
|
|
457
|
-
|
|
458
|
-
/**
|
|
459
|
-
* Constructs a new event emitter instance.
|
|
460
|
-
* @classdesc A minimal event emitter.
|
|
461
|
-
* @memberof util
|
|
462
|
-
* @constructor
|
|
463
|
-
*/
|
|
464
|
-
function EventEmitter() {
|
|
465
|
-
|
|
466
|
-
/**
|
|
467
|
-
* Registered listeners.
|
|
468
|
-
* @type {Object.<string,*>}
|
|
469
|
-
* @private
|
|
470
|
-
*/
|
|
471
|
-
this._listeners = {};
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
/**
|
|
475
|
-
* Registers an event listener.
|
|
476
|
-
* @param {string} evt Event name
|
|
477
|
-
* @param {function} fn Listener
|
|
478
|
-
* @param {*} [ctx] Listener context
|
|
479
|
-
* @returns {util.EventEmitter} `this`
|
|
480
|
-
*/
|
|
481
|
-
EventEmitter.prototype.on = function on(evt, fn, ctx) {
|
|
482
|
-
(this._listeners[evt] || (this._listeners[evt] = [])).push({
|
|
483
|
-
fn : fn,
|
|
484
|
-
ctx : ctx || this
|
|
485
|
-
});
|
|
486
|
-
return this;
|
|
487
|
-
};
|
|
488
|
-
|
|
489
|
-
/**
|
|
490
|
-
* Removes an event listener or any matching listeners if arguments are omitted.
|
|
491
|
-
* @param {string} [evt] Event name. Removes all listeners if omitted.
|
|
492
|
-
* @param {function} [fn] Listener to remove. Removes all listeners of `evt` if omitted.
|
|
493
|
-
* @returns {util.EventEmitter} `this`
|
|
494
|
-
*/
|
|
495
|
-
EventEmitter.prototype.off = function off(evt, fn) {
|
|
496
|
-
if (evt === undefined)
|
|
497
|
-
this._listeners = {};
|
|
498
|
-
else {
|
|
499
|
-
if (fn === undefined)
|
|
500
|
-
this._listeners[evt] = [];
|
|
501
|
-
else {
|
|
502
|
-
var listeners = this._listeners[evt];
|
|
503
|
-
for (var i = 0; i < listeners.length;)
|
|
504
|
-
if (listeners[i].fn === fn)
|
|
505
|
-
listeners.splice(i, 1);
|
|
506
|
-
else
|
|
507
|
-
++i;
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
return this;
|
|
511
|
-
};
|
|
512
|
-
|
|
513
|
-
/**
|
|
514
|
-
* Emits an event by calling its listeners with the specified arguments.
|
|
515
|
-
* @param {string} evt Event name
|
|
516
|
-
* @param {...*} args Arguments
|
|
517
|
-
* @returns {util.EventEmitter} `this`
|
|
518
|
-
*/
|
|
519
|
-
EventEmitter.prototype.emit = function emit(evt) {
|
|
520
|
-
var listeners = this._listeners[evt];
|
|
521
|
-
if (listeners) {
|
|
522
|
-
var args = [],
|
|
523
|
-
i = 1;
|
|
524
|
-
for (; i < arguments.length;)
|
|
525
|
-
args.push(arguments[i++]);
|
|
526
|
-
for (i = 0; i < listeners.length;)
|
|
527
|
-
listeners[i].fn.apply(listeners[i++].ctx, args);
|
|
528
|
-
}
|
|
529
|
-
return this;
|
|
530
|
-
};
|
|
455
|
+
|
|
456
|
+
module.exports = EventEmitter;
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* Constructs a new event emitter instance.
|
|
460
|
+
* @classdesc A minimal event emitter.
|
|
461
|
+
* @memberof util
|
|
462
|
+
* @constructor
|
|
463
|
+
*/
|
|
464
|
+
function EventEmitter() {
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Registered listeners.
|
|
468
|
+
* @type {Object.<string,*>}
|
|
469
|
+
* @private
|
|
470
|
+
*/
|
|
471
|
+
this._listeners = {};
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Registers an event listener.
|
|
476
|
+
* @param {string} evt Event name
|
|
477
|
+
* @param {function} fn Listener
|
|
478
|
+
* @param {*} [ctx] Listener context
|
|
479
|
+
* @returns {util.EventEmitter} `this`
|
|
480
|
+
*/
|
|
481
|
+
EventEmitter.prototype.on = function on(evt, fn, ctx) {
|
|
482
|
+
(this._listeners[evt] || (this._listeners[evt] = [])).push({
|
|
483
|
+
fn : fn,
|
|
484
|
+
ctx : ctx || this
|
|
485
|
+
});
|
|
486
|
+
return this;
|
|
487
|
+
};
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* Removes an event listener or any matching listeners if arguments are omitted.
|
|
491
|
+
* @param {string} [evt] Event name. Removes all listeners if omitted.
|
|
492
|
+
* @param {function} [fn] Listener to remove. Removes all listeners of `evt` if omitted.
|
|
493
|
+
* @returns {util.EventEmitter} `this`
|
|
494
|
+
*/
|
|
495
|
+
EventEmitter.prototype.off = function off(evt, fn) {
|
|
496
|
+
if (evt === undefined)
|
|
497
|
+
this._listeners = {};
|
|
498
|
+
else {
|
|
499
|
+
if (fn === undefined)
|
|
500
|
+
this._listeners[evt] = [];
|
|
501
|
+
else {
|
|
502
|
+
var listeners = this._listeners[evt];
|
|
503
|
+
for (var i = 0; i < listeners.length;)
|
|
504
|
+
if (listeners[i].fn === fn)
|
|
505
|
+
listeners.splice(i, 1);
|
|
506
|
+
else
|
|
507
|
+
++i;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
return this;
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* Emits an event by calling its listeners with the specified arguments.
|
|
515
|
+
* @param {string} evt Event name
|
|
516
|
+
* @param {...*} args Arguments
|
|
517
|
+
* @returns {util.EventEmitter} `this`
|
|
518
|
+
*/
|
|
519
|
+
EventEmitter.prototype.emit = function emit(evt) {
|
|
520
|
+
var listeners = this._listeners[evt];
|
|
521
|
+
if (listeners) {
|
|
522
|
+
var args = [],
|
|
523
|
+
i = 1;
|
|
524
|
+
for (; i < arguments.length;)
|
|
525
|
+
args.push(arguments[i++]);
|
|
526
|
+
for (i = 0; i < listeners.length;)
|
|
527
|
+
listeners[i].fn.apply(listeners[i++].ctx, args);
|
|
528
|
+
}
|
|
529
|
+
return this;
|
|
530
|
+
};
|
|
531
531
|
|
|
532
532
|
|
|
533
533
|
/***/ }),
|
|
@@ -536,782 +536,782 @@ EventEmitter.prototype.emit = function emit(evt) {
|
|
|
536
536
|
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
537
537
|
|
|
538
538
|
"use strict";
|
|
539
|
-
|
|
540
|
-
module.exports = fetch;
|
|
541
|
-
|
|
542
|
-
var asPromise = __webpack_require__(4537),
|
|
543
|
-
inquire = __webpack_require__(7199);
|
|
544
|
-
|
|
545
|
-
var fs = inquire("fs");
|
|
546
|
-
|
|
547
|
-
/**
|
|
548
|
-
* Node-style callback as used by {@link util.fetch}.
|
|
549
|
-
* @typedef FetchCallback
|
|
550
|
-
* @type {function}
|
|
551
|
-
* @param {?Error} error Error, if any, otherwise `null`
|
|
552
|
-
* @param {string} [contents] File contents, if there hasn't been an error
|
|
553
|
-
* @returns {undefined}
|
|
554
|
-
*/
|
|
555
|
-
|
|
556
|
-
/**
|
|
557
|
-
* Options as used by {@link util.fetch}.
|
|
558
|
-
* @typedef FetchOptions
|
|
559
|
-
* @type {Object}
|
|
560
|
-
* @property {boolean} [binary=false] Whether expecting a binary response
|
|
561
|
-
* @property {boolean} [xhr=false] If `true`, forces the use of XMLHttpRequest
|
|
562
|
-
*/
|
|
563
|
-
|
|
564
|
-
/**
|
|
565
|
-
* Fetches the contents of a file.
|
|
566
|
-
* @memberof util
|
|
567
|
-
* @param {string} filename File path or url
|
|
568
|
-
* @param {FetchOptions} options Fetch options
|
|
569
|
-
* @param {FetchCallback} callback Callback function
|
|
570
|
-
* @returns {undefined}
|
|
571
|
-
*/
|
|
572
|
-
function fetch(filename, options, callback) {
|
|
573
|
-
if (typeof options === "function") {
|
|
574
|
-
callback = options;
|
|
575
|
-
options = {};
|
|
576
|
-
} else if (!options)
|
|
577
|
-
options = {};
|
|
578
|
-
|
|
579
|
-
if (!callback)
|
|
580
|
-
return asPromise(fetch, this, filename, options); // eslint-disable-line no-invalid-this
|
|
581
|
-
|
|
582
|
-
// if a node-like filesystem is present, try it first but fall back to XHR if nothing is found.
|
|
583
|
-
if (!options.xhr && fs && fs.readFile)
|
|
584
|
-
return fs.readFile(filename, function fetchReadFileCallback(err, contents) {
|
|
585
|
-
return err && typeof XMLHttpRequest !== "undefined"
|
|
586
|
-
? fetch.xhr(filename, options, callback)
|
|
587
|
-
: err
|
|
588
|
-
? callback(err)
|
|
589
|
-
: callback(null, options.binary ? contents : contents.toString("utf8"));
|
|
590
|
-
});
|
|
591
|
-
|
|
592
|
-
// use the XHR version otherwise.
|
|
593
|
-
return fetch.xhr(filename, options, callback);
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
/**
|
|
597
|
-
* Fetches the contents of a file.
|
|
598
|
-
* @name util.fetch
|
|
599
|
-
* @function
|
|
600
|
-
* @param {string} path File path or url
|
|
601
|
-
* @param {FetchCallback} callback Callback function
|
|
602
|
-
* @returns {undefined}
|
|
603
|
-
* @variation 2
|
|
604
|
-
*/
|
|
605
|
-
|
|
606
|
-
/**
|
|
607
|
-
* Fetches the contents of a file.
|
|
608
|
-
* @name util.fetch
|
|
609
|
-
* @function
|
|
610
|
-
* @param {string} path File path or url
|
|
611
|
-
* @param {FetchOptions} [options] Fetch options
|
|
612
|
-
* @returns {Promise<string|Uint8Array>} Promise
|
|
613
|
-
* @variation 3
|
|
614
|
-
*/
|
|
615
|
-
|
|
616
|
-
/**/
|
|
617
|
-
fetch.xhr = function fetch_xhr(filename, options, callback) {
|
|
618
|
-
var xhr = new XMLHttpRequest();
|
|
619
|
-
xhr.onreadystatechange /* works everywhere */ = function fetchOnReadyStateChange() {
|
|
620
|
-
|
|
621
|
-
if (xhr.readyState !== 4)
|
|
622
|
-
return undefined;
|
|
623
|
-
|
|
624
|
-
// local cors security errors return status 0 / empty string, too. afaik this cannot be
|
|
625
|
-
// reliably distinguished from an actually empty file for security reasons. feel free
|
|
626
|
-
// to send a pull request if you are aware of a solution.
|
|
627
|
-
if (xhr.status !== 0 && xhr.status !== 200)
|
|
628
|
-
return callback(Error("status " + xhr.status));
|
|
629
|
-
|
|
630
|
-
// if binary data is expected, make sure that some sort of array is returned, even if
|
|
631
|
-
// ArrayBuffers are not supported. the binary string fallback, however, is unsafe.
|
|
632
|
-
if (options.binary) {
|
|
633
|
-
var buffer = xhr.response;
|
|
634
|
-
if (!buffer) {
|
|
635
|
-
buffer = [];
|
|
636
|
-
for (var i = 0; i < xhr.responseText.length; ++i)
|
|
637
|
-
buffer.push(xhr.responseText.charCodeAt(i) & 255);
|
|
638
|
-
}
|
|
639
|
-
return callback(null, typeof Uint8Array !== "undefined" ? new Uint8Array(buffer) : buffer);
|
|
640
|
-
}
|
|
641
|
-
return callback(null, xhr.responseText);
|
|
642
|
-
};
|
|
643
|
-
|
|
644
|
-
if (options.binary) {
|
|
645
|
-
// ref: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Sending_and_Receiving_Binary_Data#Receiving_binary_data_in_older_browsers
|
|
646
|
-
if ("overrideMimeType" in xhr)
|
|
647
|
-
xhr.overrideMimeType("text/plain; charset=x-user-defined");
|
|
648
|
-
xhr.responseType = "arraybuffer";
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
xhr.open("GET", filename);
|
|
652
|
-
xhr.send();
|
|
653
|
-
};
|
|
654
539
|
|
|
540
|
+
module.exports = fetch;
|
|
655
541
|
|
|
656
|
-
|
|
542
|
+
var asPromise = __webpack_require__(4537),
|
|
543
|
+
inquire = __webpack_require__(7199);
|
|
657
544
|
|
|
658
|
-
|
|
659
|
-
/***/ ((module) => {
|
|
545
|
+
var fs = inquire("fs");
|
|
660
546
|
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
*
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
*
|
|
674
|
-
* @
|
|
675
|
-
* @
|
|
676
|
-
|
|
677
|
-
* @param {Uint8Array} buf Target buffer
|
|
678
|
-
* @param {number} pos Target buffer offset
|
|
679
|
-
* @returns {undefined}
|
|
680
|
-
*/
|
|
681
|
-
|
|
682
|
-
/**
|
|
683
|
-
* Writes a 32 bit float to a buffer using big endian byte order.
|
|
684
|
-
* @name util.float.writeFloatBE
|
|
685
|
-
* @function
|
|
686
|
-
* @param {number} val Value to write
|
|
687
|
-
* @param {Uint8Array} buf Target buffer
|
|
688
|
-
* @param {number} pos Target buffer offset
|
|
689
|
-
* @returns {undefined}
|
|
690
|
-
*/
|
|
691
|
-
|
|
692
|
-
/**
|
|
693
|
-
* Reads a 32 bit float from a buffer using little endian byte order.
|
|
694
|
-
* @name util.float.readFloatLE
|
|
695
|
-
* @function
|
|
696
|
-
* @param {Uint8Array} buf Source buffer
|
|
697
|
-
* @param {number} pos Source buffer offset
|
|
698
|
-
* @returns {number} Value read
|
|
699
|
-
*/
|
|
700
|
-
|
|
701
|
-
/**
|
|
702
|
-
* Reads a 32 bit float from a buffer using big endian byte order.
|
|
703
|
-
* @name util.float.readFloatBE
|
|
704
|
-
* @function
|
|
705
|
-
* @param {Uint8Array} buf Source buffer
|
|
706
|
-
* @param {number} pos Source buffer offset
|
|
707
|
-
* @returns {number} Value read
|
|
708
|
-
*/
|
|
709
|
-
|
|
710
|
-
/**
|
|
711
|
-
* Writes a 64 bit double to a buffer using little endian byte order.
|
|
712
|
-
* @name util.float.writeDoubleLE
|
|
713
|
-
* @function
|
|
714
|
-
* @param {number} val Value to write
|
|
715
|
-
* @param {Uint8Array} buf Target buffer
|
|
716
|
-
* @param {number} pos Target buffer offset
|
|
717
|
-
* @returns {undefined}
|
|
718
|
-
*/
|
|
719
|
-
|
|
720
|
-
/**
|
|
721
|
-
* Writes a 64 bit double to a buffer using big endian byte order.
|
|
722
|
-
* @name util.float.writeDoubleBE
|
|
723
|
-
* @function
|
|
724
|
-
* @param {number} val Value to write
|
|
725
|
-
* @param {Uint8Array} buf Target buffer
|
|
726
|
-
* @param {number} pos Target buffer offset
|
|
727
|
-
* @returns {undefined}
|
|
728
|
-
*/
|
|
729
|
-
|
|
730
|
-
/**
|
|
731
|
-
* Reads a 64 bit double from a buffer using little endian byte order.
|
|
732
|
-
* @name util.float.readDoubleLE
|
|
733
|
-
* @function
|
|
734
|
-
* @param {Uint8Array} buf Source buffer
|
|
735
|
-
* @param {number} pos Source buffer offset
|
|
736
|
-
* @returns {number} Value read
|
|
737
|
-
*/
|
|
738
|
-
|
|
739
|
-
/**
|
|
740
|
-
* Reads a 64 bit double from a buffer using big endian byte order.
|
|
741
|
-
* @name util.float.readDoubleBE
|
|
742
|
-
* @function
|
|
743
|
-
* @param {Uint8Array} buf Source buffer
|
|
744
|
-
* @param {number} pos Source buffer offset
|
|
745
|
-
* @returns {number} Value read
|
|
746
|
-
*/
|
|
747
|
-
|
|
748
|
-
// Factory function for the purpose of node-based testing in modified global environments
|
|
749
|
-
function factory(exports) {
|
|
750
|
-
|
|
751
|
-
// float: typed array
|
|
752
|
-
if (typeof Float32Array !== "undefined") (function() {
|
|
753
|
-
|
|
754
|
-
var f32 = new Float32Array([ -0 ]),
|
|
755
|
-
f8b = new Uint8Array(f32.buffer),
|
|
756
|
-
le = f8b[3] === 128;
|
|
757
|
-
|
|
758
|
-
function writeFloat_f32_cpy(val, buf, pos) {
|
|
759
|
-
f32[0] = val;
|
|
760
|
-
buf[pos ] = f8b[0];
|
|
761
|
-
buf[pos + 1] = f8b[1];
|
|
762
|
-
buf[pos + 2] = f8b[2];
|
|
763
|
-
buf[pos + 3] = f8b[3];
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
function writeFloat_f32_rev(val, buf, pos) {
|
|
767
|
-
f32[0] = val;
|
|
768
|
-
buf[pos ] = f8b[3];
|
|
769
|
-
buf[pos + 1] = f8b[2];
|
|
770
|
-
buf[pos + 2] = f8b[1];
|
|
771
|
-
buf[pos + 3] = f8b[0];
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
/* istanbul ignore next */
|
|
775
|
-
exports.writeFloatLE = le ? writeFloat_f32_cpy : writeFloat_f32_rev;
|
|
776
|
-
/* istanbul ignore next */
|
|
777
|
-
exports.writeFloatBE = le ? writeFloat_f32_rev : writeFloat_f32_cpy;
|
|
778
|
-
|
|
779
|
-
function readFloat_f32_cpy(buf, pos) {
|
|
780
|
-
f8b[0] = buf[pos ];
|
|
781
|
-
f8b[1] = buf[pos + 1];
|
|
782
|
-
f8b[2] = buf[pos + 2];
|
|
783
|
-
f8b[3] = buf[pos + 3];
|
|
784
|
-
return f32[0];
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
function readFloat_f32_rev(buf, pos) {
|
|
788
|
-
f8b[3] = buf[pos ];
|
|
789
|
-
f8b[2] = buf[pos + 1];
|
|
790
|
-
f8b[1] = buf[pos + 2];
|
|
791
|
-
f8b[0] = buf[pos + 3];
|
|
792
|
-
return f32[0];
|
|
793
|
-
}
|
|
794
|
-
|
|
795
|
-
/* istanbul ignore next */
|
|
796
|
-
exports.readFloatLE = le ? readFloat_f32_cpy : readFloat_f32_rev;
|
|
797
|
-
/* istanbul ignore next */
|
|
798
|
-
exports.readFloatBE = le ? readFloat_f32_rev : readFloat_f32_cpy;
|
|
799
|
-
|
|
800
|
-
// float: ieee754
|
|
801
|
-
})(); else (function() {
|
|
802
|
-
|
|
803
|
-
function writeFloat_ieee754(writeUint, val, buf, pos) {
|
|
804
|
-
var sign = val < 0 ? 1 : 0;
|
|
805
|
-
if (sign)
|
|
806
|
-
val = -val;
|
|
807
|
-
if (val === 0)
|
|
808
|
-
writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos);
|
|
809
|
-
else if (isNaN(val))
|
|
810
|
-
writeUint(2143289344, buf, pos);
|
|
811
|
-
else if (val > 3.4028234663852886e+38) // +-Infinity
|
|
812
|
-
writeUint((sign << 31 | 2139095040) >>> 0, buf, pos);
|
|
813
|
-
else if (val < 1.1754943508222875e-38) // denormal
|
|
814
|
-
writeUint((sign << 31 | Math.round(val / 1.401298464324817e-45)) >>> 0, buf, pos);
|
|
815
|
-
else {
|
|
816
|
-
var exponent = Math.floor(Math.log(val) / Math.LN2),
|
|
817
|
-
mantissa = Math.round(val * Math.pow(2, -exponent) * 8388608) & 8388607;
|
|
818
|
-
writeUint((sign << 31 | exponent + 127 << 23 | mantissa) >>> 0, buf, pos);
|
|
819
|
-
}
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
exports.writeFloatLE = writeFloat_ieee754.bind(null, writeUintLE);
|
|
823
|
-
exports.writeFloatBE = writeFloat_ieee754.bind(null, writeUintBE);
|
|
824
|
-
|
|
825
|
-
function readFloat_ieee754(readUint, buf, pos) {
|
|
826
|
-
var uint = readUint(buf, pos),
|
|
827
|
-
sign = (uint >> 31) * 2 + 1,
|
|
828
|
-
exponent = uint >>> 23 & 255,
|
|
829
|
-
mantissa = uint & 8388607;
|
|
830
|
-
return exponent === 255
|
|
831
|
-
? mantissa
|
|
832
|
-
? NaN
|
|
833
|
-
: sign * Infinity
|
|
834
|
-
: exponent === 0 // denormal
|
|
835
|
-
? sign * 1.401298464324817e-45 * mantissa
|
|
836
|
-
: sign * Math.pow(2, exponent - 150) * (mantissa + 8388608);
|
|
837
|
-
}
|
|
838
|
-
|
|
839
|
-
exports.readFloatLE = readFloat_ieee754.bind(null, readUintLE);
|
|
840
|
-
exports.readFloatBE = readFloat_ieee754.bind(null, readUintBE);
|
|
841
|
-
|
|
842
|
-
})();
|
|
843
|
-
|
|
844
|
-
// double: typed array
|
|
845
|
-
if (typeof Float64Array !== "undefined") (function() {
|
|
846
|
-
|
|
847
|
-
var f64 = new Float64Array([-0]),
|
|
848
|
-
f8b = new Uint8Array(f64.buffer),
|
|
849
|
-
le = f8b[7] === 128;
|
|
850
|
-
|
|
851
|
-
function writeDouble_f64_cpy(val, buf, pos) {
|
|
852
|
-
f64[0] = val;
|
|
853
|
-
buf[pos ] = f8b[0];
|
|
854
|
-
buf[pos + 1] = f8b[1];
|
|
855
|
-
buf[pos + 2] = f8b[2];
|
|
856
|
-
buf[pos + 3] = f8b[3];
|
|
857
|
-
buf[pos + 4] = f8b[4];
|
|
858
|
-
buf[pos + 5] = f8b[5];
|
|
859
|
-
buf[pos + 6] = f8b[6];
|
|
860
|
-
buf[pos + 7] = f8b[7];
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
function writeDouble_f64_rev(val, buf, pos) {
|
|
864
|
-
f64[0] = val;
|
|
865
|
-
buf[pos ] = f8b[7];
|
|
866
|
-
buf[pos + 1] = f8b[6];
|
|
867
|
-
buf[pos + 2] = f8b[5];
|
|
868
|
-
buf[pos + 3] = f8b[4];
|
|
869
|
-
buf[pos + 4] = f8b[3];
|
|
870
|
-
buf[pos + 5] = f8b[2];
|
|
871
|
-
buf[pos + 6] = f8b[1];
|
|
872
|
-
buf[pos + 7] = f8b[0];
|
|
873
|
-
}
|
|
874
|
-
|
|
875
|
-
/* istanbul ignore next */
|
|
876
|
-
exports.writeDoubleLE = le ? writeDouble_f64_cpy : writeDouble_f64_rev;
|
|
877
|
-
/* istanbul ignore next */
|
|
878
|
-
exports.writeDoubleBE = le ? writeDouble_f64_rev : writeDouble_f64_cpy;
|
|
879
|
-
|
|
880
|
-
function readDouble_f64_cpy(buf, pos) {
|
|
881
|
-
f8b[0] = buf[pos ];
|
|
882
|
-
f8b[1] = buf[pos + 1];
|
|
883
|
-
f8b[2] = buf[pos + 2];
|
|
884
|
-
f8b[3] = buf[pos + 3];
|
|
885
|
-
f8b[4] = buf[pos + 4];
|
|
886
|
-
f8b[5] = buf[pos + 5];
|
|
887
|
-
f8b[6] = buf[pos + 6];
|
|
888
|
-
f8b[7] = buf[pos + 7];
|
|
889
|
-
return f64[0];
|
|
890
|
-
}
|
|
891
|
-
|
|
892
|
-
function readDouble_f64_rev(buf, pos) {
|
|
893
|
-
f8b[7] = buf[pos ];
|
|
894
|
-
f8b[6] = buf[pos + 1];
|
|
895
|
-
f8b[5] = buf[pos + 2];
|
|
896
|
-
f8b[4] = buf[pos + 3];
|
|
897
|
-
f8b[3] = buf[pos + 4];
|
|
898
|
-
f8b[2] = buf[pos + 5];
|
|
899
|
-
f8b[1] = buf[pos + 6];
|
|
900
|
-
f8b[0] = buf[pos + 7];
|
|
901
|
-
return f64[0];
|
|
902
|
-
}
|
|
903
|
-
|
|
904
|
-
/* istanbul ignore next */
|
|
905
|
-
exports.readDoubleLE = le ? readDouble_f64_cpy : readDouble_f64_rev;
|
|
906
|
-
/* istanbul ignore next */
|
|
907
|
-
exports.readDoubleBE = le ? readDouble_f64_rev : readDouble_f64_cpy;
|
|
908
|
-
|
|
909
|
-
// double: ieee754
|
|
910
|
-
})(); else (function() {
|
|
911
|
-
|
|
912
|
-
function writeDouble_ieee754(writeUint, off0, off1, val, buf, pos) {
|
|
913
|
-
var sign = val < 0 ? 1 : 0;
|
|
914
|
-
if (sign)
|
|
915
|
-
val = -val;
|
|
916
|
-
if (val === 0) {
|
|
917
|
-
writeUint(0, buf, pos + off0);
|
|
918
|
-
writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos + off1);
|
|
919
|
-
} else if (isNaN(val)) {
|
|
920
|
-
writeUint(0, buf, pos + off0);
|
|
921
|
-
writeUint(2146959360, buf, pos + off1);
|
|
922
|
-
} else if (val > 1.7976931348623157e+308) { // +-Infinity
|
|
923
|
-
writeUint(0, buf, pos + off0);
|
|
924
|
-
writeUint((sign << 31 | 2146435072) >>> 0, buf, pos + off1);
|
|
925
|
-
} else {
|
|
926
|
-
var mantissa;
|
|
927
|
-
if (val < 2.2250738585072014e-308) { // denormal
|
|
928
|
-
mantissa = val / 5e-324;
|
|
929
|
-
writeUint(mantissa >>> 0, buf, pos + off0);
|
|
930
|
-
writeUint((sign << 31 | mantissa / 4294967296) >>> 0, buf, pos + off1);
|
|
931
|
-
} else {
|
|
932
|
-
var exponent = Math.floor(Math.log(val) / Math.LN2);
|
|
933
|
-
if (exponent === 1024)
|
|
934
|
-
exponent = 1023;
|
|
935
|
-
mantissa = val * Math.pow(2, -exponent);
|
|
936
|
-
writeUint(mantissa * 4503599627370496 >>> 0, buf, pos + off0);
|
|
937
|
-
writeUint((sign << 31 | exponent + 1023 << 20 | mantissa * 1048576 & 1048575) >>> 0, buf, pos + off1);
|
|
938
|
-
}
|
|
939
|
-
}
|
|
940
|
-
}
|
|
941
|
-
|
|
942
|
-
exports.writeDoubleLE = writeDouble_ieee754.bind(null, writeUintLE, 0, 4);
|
|
943
|
-
exports.writeDoubleBE = writeDouble_ieee754.bind(null, writeUintBE, 4, 0);
|
|
944
|
-
|
|
945
|
-
function readDouble_ieee754(readUint, off0, off1, buf, pos) {
|
|
946
|
-
var lo = readUint(buf, pos + off0),
|
|
947
|
-
hi = readUint(buf, pos + off1);
|
|
948
|
-
var sign = (hi >> 31) * 2 + 1,
|
|
949
|
-
exponent = hi >>> 20 & 2047,
|
|
950
|
-
mantissa = 4294967296 * (hi & 1048575) + lo;
|
|
951
|
-
return exponent === 2047
|
|
952
|
-
? mantissa
|
|
953
|
-
? NaN
|
|
954
|
-
: sign * Infinity
|
|
955
|
-
: exponent === 0 // denormal
|
|
956
|
-
? sign * 5e-324 * mantissa
|
|
957
|
-
: sign * Math.pow(2, exponent - 1075) * (mantissa + 4503599627370496);
|
|
958
|
-
}
|
|
959
|
-
|
|
960
|
-
exports.readDoubleLE = readDouble_ieee754.bind(null, readUintLE, 0, 4);
|
|
961
|
-
exports.readDoubleBE = readDouble_ieee754.bind(null, readUintBE, 4, 0);
|
|
962
|
-
|
|
963
|
-
})();
|
|
964
|
-
|
|
965
|
-
return exports;
|
|
966
|
-
}
|
|
967
|
-
|
|
968
|
-
// uint helpers
|
|
969
|
-
|
|
970
|
-
function writeUintLE(val, buf, pos) {
|
|
971
|
-
buf[pos ] = val & 255;
|
|
972
|
-
buf[pos + 1] = val >>> 8 & 255;
|
|
973
|
-
buf[pos + 2] = val >>> 16 & 255;
|
|
974
|
-
buf[pos + 3] = val >>> 24;
|
|
975
|
-
}
|
|
976
|
-
|
|
977
|
-
function writeUintBE(val, buf, pos) {
|
|
978
|
-
buf[pos ] = val >>> 24;
|
|
979
|
-
buf[pos + 1] = val >>> 16 & 255;
|
|
980
|
-
buf[pos + 2] = val >>> 8 & 255;
|
|
981
|
-
buf[pos + 3] = val & 255;
|
|
982
|
-
}
|
|
983
|
-
|
|
984
|
-
function readUintLE(buf, pos) {
|
|
985
|
-
return (buf[pos ]
|
|
986
|
-
| buf[pos + 1] << 8
|
|
987
|
-
| buf[pos + 2] << 16
|
|
988
|
-
| buf[pos + 3] << 24) >>> 0;
|
|
989
|
-
}
|
|
990
|
-
|
|
991
|
-
function readUintBE(buf, pos) {
|
|
992
|
-
return (buf[pos ] << 24
|
|
993
|
-
| buf[pos + 1] << 16
|
|
994
|
-
| buf[pos + 2] << 8
|
|
995
|
-
| buf[pos + 3]) >>> 0;
|
|
996
|
-
}
|
|
547
|
+
/**
|
|
548
|
+
* Node-style callback as used by {@link util.fetch}.
|
|
549
|
+
* @typedef FetchCallback
|
|
550
|
+
* @type {function}
|
|
551
|
+
* @param {?Error} error Error, if any, otherwise `null`
|
|
552
|
+
* @param {string} [contents] File contents, if there hasn't been an error
|
|
553
|
+
* @returns {undefined}
|
|
554
|
+
*/
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* Options as used by {@link util.fetch}.
|
|
558
|
+
* @typedef FetchOptions
|
|
559
|
+
* @type {Object}
|
|
560
|
+
* @property {boolean} [binary=false] Whether expecting a binary response
|
|
561
|
+
* @property {boolean} [xhr=false] If `true`, forces the use of XMLHttpRequest
|
|
562
|
+
*/
|
|
997
563
|
|
|
564
|
+
/**
|
|
565
|
+
* Fetches the contents of a file.
|
|
566
|
+
* @memberof util
|
|
567
|
+
* @param {string} filename File path or url
|
|
568
|
+
* @param {FetchOptions} options Fetch options
|
|
569
|
+
* @param {FetchCallback} callback Callback function
|
|
570
|
+
* @returns {undefined}
|
|
571
|
+
*/
|
|
572
|
+
function fetch(filename, options, callback) {
|
|
573
|
+
if (typeof options === "function") {
|
|
574
|
+
callback = options;
|
|
575
|
+
options = {};
|
|
576
|
+
} else if (!options)
|
|
577
|
+
options = {};
|
|
998
578
|
|
|
999
|
-
|
|
579
|
+
if (!callback)
|
|
580
|
+
return asPromise(fetch, this, filename, options); // eslint-disable-line no-invalid-this
|
|
581
|
+
|
|
582
|
+
// if a node-like filesystem is present, try it first but fall back to XHR if nothing is found.
|
|
583
|
+
if (!options.xhr && fs && fs.readFile)
|
|
584
|
+
return fs.readFile(filename, function fetchReadFileCallback(err, contents) {
|
|
585
|
+
return err && typeof XMLHttpRequest !== "undefined"
|
|
586
|
+
? fetch.xhr(filename, options, callback)
|
|
587
|
+
: err
|
|
588
|
+
? callback(err)
|
|
589
|
+
: callback(null, options.binary ? contents : contents.toString("utf8"));
|
|
590
|
+
});
|
|
1000
591
|
|
|
1001
|
-
|
|
1002
|
-
|
|
592
|
+
// use the XHR version otherwise.
|
|
593
|
+
return fetch.xhr(filename, options, callback);
|
|
594
|
+
}
|
|
1003
595
|
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
*
|
|
1010
|
-
* @
|
|
1011
|
-
* @
|
|
1012
|
-
|
|
1013
|
-
*/
|
|
1014
|
-
function inquire(moduleName) {
|
|
1015
|
-
try {
|
|
1016
|
-
var mod = eval("quire".replace(/^/,"re"))(moduleName); // eslint-disable-line no-eval
|
|
1017
|
-
if (mod && (mod.length || Object.keys(mod).length))
|
|
1018
|
-
return mod;
|
|
1019
|
-
} catch (e) {} // eslint-disable-line no-empty
|
|
1020
|
-
return null;
|
|
1021
|
-
}
|
|
596
|
+
/**
|
|
597
|
+
* Fetches the contents of a file.
|
|
598
|
+
* @name util.fetch
|
|
599
|
+
* @function
|
|
600
|
+
* @param {string} path File path or url
|
|
601
|
+
* @param {FetchCallback} callback Callback function
|
|
602
|
+
* @returns {undefined}
|
|
603
|
+
* @variation 2
|
|
604
|
+
*/
|
|
1022
605
|
|
|
606
|
+
/**
|
|
607
|
+
* Fetches the contents of a file.
|
|
608
|
+
* @name util.fetch
|
|
609
|
+
* @function
|
|
610
|
+
* @param {string} path File path or url
|
|
611
|
+
* @param {FetchOptions} [options] Fetch options
|
|
612
|
+
* @returns {Promise<string|Uint8Array>} Promise
|
|
613
|
+
* @variation 3
|
|
614
|
+
*/
|
|
1023
615
|
|
|
1024
|
-
|
|
616
|
+
/**/
|
|
617
|
+
fetch.xhr = function fetch_xhr(filename, options, callback) {
|
|
618
|
+
var xhr = new XMLHttpRequest();
|
|
619
|
+
xhr.onreadystatechange /* works everywhere */ = function fetchOnReadyStateChange() {
|
|
620
|
+
|
|
621
|
+
if (xhr.readyState !== 4)
|
|
622
|
+
return undefined;
|
|
623
|
+
|
|
624
|
+
// local cors security errors return status 0 / empty string, too. afaik this cannot be
|
|
625
|
+
// reliably distinguished from an actually empty file for security reasons. feel free
|
|
626
|
+
// to send a pull request if you are aware of a solution.
|
|
627
|
+
if (xhr.status !== 0 && xhr.status !== 200)
|
|
628
|
+
return callback(Error("status " + xhr.status));
|
|
629
|
+
|
|
630
|
+
// if binary data is expected, make sure that some sort of array is returned, even if
|
|
631
|
+
// ArrayBuffers are not supported. the binary string fallback, however, is unsafe.
|
|
632
|
+
if (options.binary) {
|
|
633
|
+
var buffer = xhr.response;
|
|
634
|
+
if (!buffer) {
|
|
635
|
+
buffer = [];
|
|
636
|
+
for (var i = 0; i < xhr.responseText.length; ++i)
|
|
637
|
+
buffer.push(xhr.responseText.charCodeAt(i) & 255);
|
|
638
|
+
}
|
|
639
|
+
return callback(null, typeof Uint8Array !== "undefined" ? new Uint8Array(buffer) : buffer);
|
|
640
|
+
}
|
|
641
|
+
return callback(null, xhr.responseText);
|
|
642
|
+
};
|
|
1025
643
|
|
|
1026
|
-
|
|
1027
|
-
|
|
644
|
+
if (options.binary) {
|
|
645
|
+
// ref: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Sending_and_Receiving_Binary_Data#Receiving_binary_data_in_older_browsers
|
|
646
|
+
if ("overrideMimeType" in xhr)
|
|
647
|
+
xhr.overrideMimeType("text/plain; charset=x-user-defined");
|
|
648
|
+
xhr.responseType = "arraybuffer";
|
|
649
|
+
}
|
|
1028
650
|
|
|
1029
|
-
"
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
/**
|
|
1033
|
-
* A minimal path module to resolve Unix, Windows and URL paths alike.
|
|
1034
|
-
* @memberof util
|
|
1035
|
-
* @namespace
|
|
1036
|
-
*/
|
|
1037
|
-
var path = exports;
|
|
1038
|
-
|
|
1039
|
-
var isAbsolute =
|
|
1040
|
-
/**
|
|
1041
|
-
* Tests if the specified path is absolute.
|
|
1042
|
-
* @param {string} path Path to test
|
|
1043
|
-
* @returns {boolean} `true` if path is absolute
|
|
1044
|
-
*/
|
|
1045
|
-
path.isAbsolute = function isAbsolute(path) {
|
|
1046
|
-
return /^(?:\/|\w+:)/.test(path);
|
|
1047
|
-
};
|
|
1048
|
-
|
|
1049
|
-
var normalize =
|
|
1050
|
-
/**
|
|
1051
|
-
* Normalizes the specified path.
|
|
1052
|
-
* @param {string} path Path to normalize
|
|
1053
|
-
* @returns {string} Normalized path
|
|
1054
|
-
*/
|
|
1055
|
-
path.normalize = function normalize(path) {
|
|
1056
|
-
path = path.replace(/\\/g, "/")
|
|
1057
|
-
.replace(/\/{2,}/g, "/");
|
|
1058
|
-
var parts = path.split("/"),
|
|
1059
|
-
absolute = isAbsolute(path),
|
|
1060
|
-
prefix = "";
|
|
1061
|
-
if (absolute)
|
|
1062
|
-
prefix = parts.shift() + "/";
|
|
1063
|
-
for (var i = 0; i < parts.length;) {
|
|
1064
|
-
if (parts[i] === "..") {
|
|
1065
|
-
if (i > 0 && parts[i - 1] !== "..")
|
|
1066
|
-
parts.splice(--i, 2);
|
|
1067
|
-
else if (absolute)
|
|
1068
|
-
parts.splice(i, 1);
|
|
1069
|
-
else
|
|
1070
|
-
++i;
|
|
1071
|
-
} else if (parts[i] === ".")
|
|
1072
|
-
parts.splice(i, 1);
|
|
1073
|
-
else
|
|
1074
|
-
++i;
|
|
1075
|
-
}
|
|
1076
|
-
return prefix + parts.join("/");
|
|
1077
|
-
};
|
|
1078
|
-
|
|
1079
|
-
/**
|
|
1080
|
-
* Resolves the specified include path against the specified origin path.
|
|
1081
|
-
* @param {string} originPath Path to the origin file
|
|
1082
|
-
* @param {string} includePath Include path relative to origin path
|
|
1083
|
-
* @param {boolean} [alreadyNormalized=false] `true` if both paths are already known to be normalized
|
|
1084
|
-
* @returns {string} Path to the include file
|
|
1085
|
-
*/
|
|
1086
|
-
path.resolve = function resolve(originPath, includePath, alreadyNormalized) {
|
|
1087
|
-
if (!alreadyNormalized)
|
|
1088
|
-
includePath = normalize(includePath);
|
|
1089
|
-
if (isAbsolute(includePath))
|
|
1090
|
-
return includePath;
|
|
1091
|
-
if (!alreadyNormalized)
|
|
1092
|
-
originPath = normalize(originPath);
|
|
1093
|
-
return (originPath = originPath.replace(/(?:\/|^)[^/]+$/, "")).length ? normalize(originPath + "/" + includePath) : includePath;
|
|
1094
|
-
};
|
|
651
|
+
xhr.open("GET", filename);
|
|
652
|
+
xhr.send();
|
|
653
|
+
};
|
|
1095
654
|
|
|
1096
655
|
|
|
1097
656
|
/***/ }),
|
|
1098
657
|
|
|
1099
|
-
/***/
|
|
658
|
+
/***/ 945:
|
|
1100
659
|
/***/ ((module) => {
|
|
1101
660
|
|
|
1102
661
|
"use strict";
|
|
1103
|
-
|
|
1104
|
-
module.exports = pool;
|
|
1105
|
-
|
|
1106
|
-
/**
|
|
1107
|
-
* An allocator as used by {@link util.pool}.
|
|
1108
|
-
* @typedef PoolAllocator
|
|
1109
|
-
* @type {function}
|
|
1110
|
-
* @param {number} size Buffer size
|
|
1111
|
-
* @returns {Uint8Array} Buffer
|
|
1112
|
-
*/
|
|
1113
|
-
|
|
1114
|
-
/**
|
|
1115
|
-
* A slicer as used by {@link util.pool}.
|
|
1116
|
-
* @typedef PoolSlicer
|
|
1117
|
-
* @type {function}
|
|
1118
|
-
* @param {number} start Start offset
|
|
1119
|
-
* @param {number} end End offset
|
|
1120
|
-
* @returns {Uint8Array} Buffer slice
|
|
1121
|
-
* @this {Uint8Array}
|
|
1122
|
-
*/
|
|
1123
|
-
|
|
1124
|
-
/**
|
|
1125
|
-
* A general purpose buffer pool.
|
|
1126
|
-
* @memberof util
|
|
1127
|
-
* @function
|
|
1128
|
-
* @param {PoolAllocator} alloc Allocator
|
|
1129
|
-
* @param {PoolSlicer} slice Slicer
|
|
1130
|
-
* @param {number} [size=8192] Slab size
|
|
1131
|
-
* @returns {PoolAllocator} Pooled allocator
|
|
1132
|
-
*/
|
|
1133
|
-
function pool(alloc, slice, size) {
|
|
1134
|
-
var SIZE = size || 8192;
|
|
1135
|
-
var MAX = SIZE >>> 1;
|
|
1136
|
-
var slab = null;
|
|
1137
|
-
var offset = SIZE;
|
|
1138
|
-
return function pool_alloc(size) {
|
|
1139
|
-
if (size < 1 || size > MAX)
|
|
1140
|
-
return alloc(size);
|
|
1141
|
-
if (offset + size > SIZE) {
|
|
1142
|
-
slab = alloc(SIZE);
|
|
1143
|
-
offset = 0;
|
|
1144
|
-
}
|
|
1145
|
-
var buf = slice.call(slab, offset, offset += size);
|
|
1146
|
-
if (offset & 7) // align to 32 bit
|
|
1147
|
-
offset = (offset | 7) + 1;
|
|
1148
|
-
return buf;
|
|
1149
|
-
};
|
|
1150
|
-
}
|
|
1151
662
|
|
|
1152
663
|
|
|
1153
|
-
|
|
664
|
+
module.exports = factory(factory);
|
|
1154
665
|
|
|
1155
|
-
|
|
1156
|
-
|
|
666
|
+
/**
|
|
667
|
+
* Reads / writes floats / doubles from / to buffers.
|
|
668
|
+
* @name util.float
|
|
669
|
+
* @namespace
|
|
670
|
+
*/
|
|
1157
671
|
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
*
|
|
1163
|
-
* @
|
|
1164
|
-
* @
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
/**
|
|
1169
|
-
* Calculates the UTF8 byte length of a string.
|
|
1170
|
-
* @param {string} string String
|
|
1171
|
-
* @returns {number} Byte length
|
|
1172
|
-
*/
|
|
1173
|
-
utf8.length = function utf8_length(string) {
|
|
1174
|
-
var len = 0,
|
|
1175
|
-
c = 0;
|
|
1176
|
-
for (var i = 0; i < string.length; ++i) {
|
|
1177
|
-
c = string.charCodeAt(i);
|
|
1178
|
-
if (c < 128)
|
|
1179
|
-
len += 1;
|
|
1180
|
-
else if (c < 2048)
|
|
1181
|
-
len += 2;
|
|
1182
|
-
else if ((c & 0xFC00) === 0xD800 && (string.charCodeAt(i + 1) & 0xFC00) === 0xDC00) {
|
|
1183
|
-
++i;
|
|
1184
|
-
len += 4;
|
|
1185
|
-
} else
|
|
1186
|
-
len += 3;
|
|
1187
|
-
}
|
|
1188
|
-
return len;
|
|
1189
|
-
};
|
|
1190
|
-
|
|
1191
|
-
/**
|
|
1192
|
-
* Reads UTF8 bytes as a string.
|
|
1193
|
-
* @param {Uint8Array} buffer Source buffer
|
|
1194
|
-
* @param {number} start Source start
|
|
1195
|
-
* @param {number} end Source end
|
|
1196
|
-
* @returns {string} String read
|
|
1197
|
-
*/
|
|
1198
|
-
utf8.read = function utf8_read(buffer, start, end) {
|
|
1199
|
-
var len = end - start;
|
|
1200
|
-
if (len < 1)
|
|
1201
|
-
return "";
|
|
1202
|
-
var parts = null,
|
|
1203
|
-
chunk = [],
|
|
1204
|
-
i = 0, // char offset
|
|
1205
|
-
t; // temporary
|
|
1206
|
-
while (start < end) {
|
|
1207
|
-
t = buffer[start++];
|
|
1208
|
-
if (t < 128)
|
|
1209
|
-
chunk[i++] = t;
|
|
1210
|
-
else if (t > 191 && t < 224)
|
|
1211
|
-
chunk[i++] = (t & 31) << 6 | buffer[start++] & 63;
|
|
1212
|
-
else if (t > 239 && t < 365) {
|
|
1213
|
-
t = ((t & 7) << 18 | (buffer[start++] & 63) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63) - 0x10000;
|
|
1214
|
-
chunk[i++] = 0xD800 + (t >> 10);
|
|
1215
|
-
chunk[i++] = 0xDC00 + (t & 1023);
|
|
1216
|
-
} else
|
|
1217
|
-
chunk[i++] = (t & 15) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63;
|
|
1218
|
-
if (i > 8191) {
|
|
1219
|
-
(parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
|
|
1220
|
-
i = 0;
|
|
1221
|
-
}
|
|
1222
|
-
}
|
|
1223
|
-
if (parts) {
|
|
1224
|
-
if (i)
|
|
1225
|
-
parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
|
|
1226
|
-
return parts.join("");
|
|
1227
|
-
}
|
|
1228
|
-
return String.fromCharCode.apply(String, chunk.slice(0, i));
|
|
1229
|
-
};
|
|
1230
|
-
|
|
1231
|
-
/**
|
|
1232
|
-
* Writes a string as UTF8 bytes.
|
|
1233
|
-
* @param {string} string Source string
|
|
1234
|
-
* @param {Uint8Array} buffer Destination buffer
|
|
1235
|
-
* @param {number} offset Destination offset
|
|
1236
|
-
* @returns {number} Bytes written
|
|
1237
|
-
*/
|
|
1238
|
-
utf8.write = function utf8_write(string, buffer, offset) {
|
|
1239
|
-
var start = offset,
|
|
1240
|
-
c1, // character 1
|
|
1241
|
-
c2; // character 2
|
|
1242
|
-
for (var i = 0; i < string.length; ++i) {
|
|
1243
|
-
c1 = string.charCodeAt(i);
|
|
1244
|
-
if (c1 < 128) {
|
|
1245
|
-
buffer[offset++] = c1;
|
|
1246
|
-
} else if (c1 < 2048) {
|
|
1247
|
-
buffer[offset++] = c1 >> 6 | 192;
|
|
1248
|
-
buffer[offset++] = c1 & 63 | 128;
|
|
1249
|
-
} else if ((c1 & 0xFC00) === 0xD800 && ((c2 = string.charCodeAt(i + 1)) & 0xFC00) === 0xDC00) {
|
|
1250
|
-
c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF);
|
|
1251
|
-
++i;
|
|
1252
|
-
buffer[offset++] = c1 >> 18 | 240;
|
|
1253
|
-
buffer[offset++] = c1 >> 12 & 63 | 128;
|
|
1254
|
-
buffer[offset++] = c1 >> 6 & 63 | 128;
|
|
1255
|
-
buffer[offset++] = c1 & 63 | 128;
|
|
1256
|
-
} else {
|
|
1257
|
-
buffer[offset++] = c1 >> 12 | 224;
|
|
1258
|
-
buffer[offset++] = c1 >> 6 & 63 | 128;
|
|
1259
|
-
buffer[offset++] = c1 & 63 | 128;
|
|
1260
|
-
}
|
|
1261
|
-
}
|
|
1262
|
-
return offset - start;
|
|
1263
|
-
};
|
|
672
|
+
/**
|
|
673
|
+
* Writes a 32 bit float to a buffer using little endian byte order.
|
|
674
|
+
* @name util.float.writeFloatLE
|
|
675
|
+
* @function
|
|
676
|
+
* @param {number} val Value to write
|
|
677
|
+
* @param {Uint8Array} buf Target buffer
|
|
678
|
+
* @param {number} pos Target buffer offset
|
|
679
|
+
* @returns {undefined}
|
|
680
|
+
*/
|
|
1264
681
|
|
|
682
|
+
/**
|
|
683
|
+
* Writes a 32 bit float to a buffer using big endian byte order.
|
|
684
|
+
* @name util.float.writeFloatBE
|
|
685
|
+
* @function
|
|
686
|
+
* @param {number} val Value to write
|
|
687
|
+
* @param {Uint8Array} buf Target buffer
|
|
688
|
+
* @param {number} pos Target buffer offset
|
|
689
|
+
* @returns {undefined}
|
|
690
|
+
*/
|
|
1265
691
|
|
|
1266
|
-
|
|
692
|
+
/**
|
|
693
|
+
* Reads a 32 bit float from a buffer using little endian byte order.
|
|
694
|
+
* @name util.float.readFloatLE
|
|
695
|
+
* @function
|
|
696
|
+
* @param {Uint8Array} buf Source buffer
|
|
697
|
+
* @param {number} pos Source buffer offset
|
|
698
|
+
* @returns {number} Value read
|
|
699
|
+
*/
|
|
1267
700
|
|
|
1268
|
-
|
|
1269
|
-
|
|
701
|
+
/**
|
|
702
|
+
* Reads a 32 bit float from a buffer using big endian byte order.
|
|
703
|
+
* @name util.float.readFloatBE
|
|
704
|
+
* @function
|
|
705
|
+
* @param {Uint8Array} buf Source buffer
|
|
706
|
+
* @param {number} pos Source buffer offset
|
|
707
|
+
* @returns {number} Value read
|
|
708
|
+
*/
|
|
1270
709
|
|
|
1271
|
-
|
|
710
|
+
/**
|
|
711
|
+
* Writes a 64 bit double to a buffer using little endian byte order.
|
|
712
|
+
* @name util.float.writeDoubleLE
|
|
713
|
+
* @function
|
|
714
|
+
* @param {number} val Value to write
|
|
715
|
+
* @param {Uint8Array} buf Target buffer
|
|
716
|
+
* @param {number} pos Target buffer offset
|
|
717
|
+
* @returns {undefined}
|
|
718
|
+
*/
|
|
1272
719
|
|
|
1273
|
-
|
|
720
|
+
/**
|
|
721
|
+
* Writes a 64 bit double to a buffer using big endian byte order.
|
|
722
|
+
* @name util.float.writeDoubleBE
|
|
723
|
+
* @function
|
|
724
|
+
* @param {number} val Value to write
|
|
725
|
+
* @param {Uint8Array} buf Target buffer
|
|
726
|
+
* @param {number} pos Target buffer offset
|
|
727
|
+
* @returns {undefined}
|
|
728
|
+
*/
|
|
1274
729
|
|
|
1275
|
-
|
|
1276
|
-
|
|
730
|
+
/**
|
|
731
|
+
* Reads a 64 bit double from a buffer using little endian byte order.
|
|
732
|
+
* @name util.float.readDoubleLE
|
|
733
|
+
* @function
|
|
734
|
+
* @param {Uint8Array} buf Source buffer
|
|
735
|
+
* @param {number} pos Source buffer offset
|
|
736
|
+
* @returns {number} Value read
|
|
737
|
+
*/
|
|
1277
738
|
|
|
1278
|
-
|
|
739
|
+
/**
|
|
740
|
+
* Reads a 64 bit double from a buffer using big endian byte order.
|
|
741
|
+
* @name util.float.readDoubleBE
|
|
742
|
+
* @function
|
|
743
|
+
* @param {Uint8Array} buf Source buffer
|
|
744
|
+
* @param {number} pos Source buffer offset
|
|
745
|
+
* @returns {number} Value read
|
|
746
|
+
*/
|
|
1279
747
|
|
|
748
|
+
// Factory function for the purpose of node-based testing in modified global environments
|
|
749
|
+
function factory(exports) {
|
|
1280
750
|
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
var cookies = __webpack_require__(4372);
|
|
1284
|
-
var buildURL = __webpack_require__(5327);
|
|
1285
|
-
var buildFullPath = __webpack_require__(4097);
|
|
1286
|
-
var parseHeaders = __webpack_require__(4109);
|
|
1287
|
-
var isURLSameOrigin = __webpack_require__(7985);
|
|
1288
|
-
var createError = __webpack_require__(5061);
|
|
751
|
+
// float: typed array
|
|
752
|
+
if (typeof Float32Array !== "undefined") (function() {
|
|
1289
753
|
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
var requestHeaders = config.headers;
|
|
754
|
+
var f32 = new Float32Array([ -0 ]),
|
|
755
|
+
f8b = new Uint8Array(f32.buffer),
|
|
756
|
+
le = f8b[3] === 128;
|
|
1294
757
|
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
758
|
+
function writeFloat_f32_cpy(val, buf, pos) {
|
|
759
|
+
f32[0] = val;
|
|
760
|
+
buf[pos ] = f8b[0];
|
|
761
|
+
buf[pos + 1] = f8b[1];
|
|
762
|
+
buf[pos + 2] = f8b[2];
|
|
763
|
+
buf[pos + 3] = f8b[3];
|
|
764
|
+
}
|
|
1298
765
|
|
|
1299
|
-
|
|
766
|
+
function writeFloat_f32_rev(val, buf, pos) {
|
|
767
|
+
f32[0] = val;
|
|
768
|
+
buf[pos ] = f8b[3];
|
|
769
|
+
buf[pos + 1] = f8b[2];
|
|
770
|
+
buf[pos + 2] = f8b[1];
|
|
771
|
+
buf[pos + 3] = f8b[0];
|
|
772
|
+
}
|
|
1300
773
|
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
774
|
+
/* istanbul ignore next */
|
|
775
|
+
exports.writeFloatLE = le ? writeFloat_f32_cpy : writeFloat_f32_rev;
|
|
776
|
+
/* istanbul ignore next */
|
|
777
|
+
exports.writeFloatBE = le ? writeFloat_f32_rev : writeFloat_f32_cpy;
|
|
778
|
+
|
|
779
|
+
function readFloat_f32_cpy(buf, pos) {
|
|
780
|
+
f8b[0] = buf[pos ];
|
|
781
|
+
f8b[1] = buf[pos + 1];
|
|
782
|
+
f8b[2] = buf[pos + 2];
|
|
783
|
+
f8b[3] = buf[pos + 3];
|
|
784
|
+
return f32[0];
|
|
785
|
+
}
|
|
1307
786
|
|
|
1308
|
-
|
|
1309
|
-
|
|
787
|
+
function readFloat_f32_rev(buf, pos) {
|
|
788
|
+
f8b[3] = buf[pos ];
|
|
789
|
+
f8b[2] = buf[pos + 1];
|
|
790
|
+
f8b[1] = buf[pos + 2];
|
|
791
|
+
f8b[0] = buf[pos + 3];
|
|
792
|
+
return f32[0];
|
|
793
|
+
}
|
|
1310
794
|
|
|
1311
|
-
|
|
1312
|
-
|
|
795
|
+
/* istanbul ignore next */
|
|
796
|
+
exports.readFloatLE = le ? readFloat_f32_cpy : readFloat_f32_rev;
|
|
797
|
+
/* istanbul ignore next */
|
|
798
|
+
exports.readFloatBE = le ? readFloat_f32_rev : readFloat_f32_cpy;
|
|
799
|
+
|
|
800
|
+
// float: ieee754
|
|
801
|
+
})(); else (function() {
|
|
802
|
+
|
|
803
|
+
function writeFloat_ieee754(writeUint, val, buf, pos) {
|
|
804
|
+
var sign = val < 0 ? 1 : 0;
|
|
805
|
+
if (sign)
|
|
806
|
+
val = -val;
|
|
807
|
+
if (val === 0)
|
|
808
|
+
writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos);
|
|
809
|
+
else if (isNaN(val))
|
|
810
|
+
writeUint(2143289344, buf, pos);
|
|
811
|
+
else if (val > 3.4028234663852886e+38) // +-Infinity
|
|
812
|
+
writeUint((sign << 31 | 2139095040) >>> 0, buf, pos);
|
|
813
|
+
else if (val < 1.1754943508222875e-38) // denormal
|
|
814
|
+
writeUint((sign << 31 | Math.round(val / 1.401298464324817e-45)) >>> 0, buf, pos);
|
|
815
|
+
else {
|
|
816
|
+
var exponent = Math.floor(Math.log(val) / Math.LN2),
|
|
817
|
+
mantissa = Math.round(val * Math.pow(2, -exponent) * 8388608) & 8388607;
|
|
818
|
+
writeUint((sign << 31 | exponent + 127 << 23 | mantissa) >>> 0, buf, pos);
|
|
819
|
+
}
|
|
820
|
+
}
|
|
1313
821
|
|
|
1314
|
-
|
|
822
|
+
exports.writeFloatLE = writeFloat_ieee754.bind(null, writeUintLE);
|
|
823
|
+
exports.writeFloatBE = writeFloat_ieee754.bind(null, writeUintBE);
|
|
824
|
+
|
|
825
|
+
function readFloat_ieee754(readUint, buf, pos) {
|
|
826
|
+
var uint = readUint(buf, pos),
|
|
827
|
+
sign = (uint >> 31) * 2 + 1,
|
|
828
|
+
exponent = uint >>> 23 & 255,
|
|
829
|
+
mantissa = uint & 8388607;
|
|
830
|
+
return exponent === 255
|
|
831
|
+
? mantissa
|
|
832
|
+
? NaN
|
|
833
|
+
: sign * Infinity
|
|
834
|
+
: exponent === 0 // denormal
|
|
835
|
+
? sign * 1.401298464324817e-45 * mantissa
|
|
836
|
+
: sign * Math.pow(2, exponent - 150) * (mantissa + 8388608);
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
exports.readFloatLE = readFloat_ieee754.bind(null, readUintLE);
|
|
840
|
+
exports.readFloatBE = readFloat_ieee754.bind(null, readUintBE);
|
|
841
|
+
|
|
842
|
+
})();
|
|
843
|
+
|
|
844
|
+
// double: typed array
|
|
845
|
+
if (typeof Float64Array !== "undefined") (function() {
|
|
846
|
+
|
|
847
|
+
var f64 = new Float64Array([-0]),
|
|
848
|
+
f8b = new Uint8Array(f64.buffer),
|
|
849
|
+
le = f8b[7] === 128;
|
|
850
|
+
|
|
851
|
+
function writeDouble_f64_cpy(val, buf, pos) {
|
|
852
|
+
f64[0] = val;
|
|
853
|
+
buf[pos ] = f8b[0];
|
|
854
|
+
buf[pos + 1] = f8b[1];
|
|
855
|
+
buf[pos + 2] = f8b[2];
|
|
856
|
+
buf[pos + 3] = f8b[3];
|
|
857
|
+
buf[pos + 4] = f8b[4];
|
|
858
|
+
buf[pos + 5] = f8b[5];
|
|
859
|
+
buf[pos + 6] = f8b[6];
|
|
860
|
+
buf[pos + 7] = f8b[7];
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
function writeDouble_f64_rev(val, buf, pos) {
|
|
864
|
+
f64[0] = val;
|
|
865
|
+
buf[pos ] = f8b[7];
|
|
866
|
+
buf[pos + 1] = f8b[6];
|
|
867
|
+
buf[pos + 2] = f8b[5];
|
|
868
|
+
buf[pos + 3] = f8b[4];
|
|
869
|
+
buf[pos + 4] = f8b[3];
|
|
870
|
+
buf[pos + 5] = f8b[2];
|
|
871
|
+
buf[pos + 6] = f8b[1];
|
|
872
|
+
buf[pos + 7] = f8b[0];
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
/* istanbul ignore next */
|
|
876
|
+
exports.writeDoubleLE = le ? writeDouble_f64_cpy : writeDouble_f64_rev;
|
|
877
|
+
/* istanbul ignore next */
|
|
878
|
+
exports.writeDoubleBE = le ? writeDouble_f64_rev : writeDouble_f64_cpy;
|
|
879
|
+
|
|
880
|
+
function readDouble_f64_cpy(buf, pos) {
|
|
881
|
+
f8b[0] = buf[pos ];
|
|
882
|
+
f8b[1] = buf[pos + 1];
|
|
883
|
+
f8b[2] = buf[pos + 2];
|
|
884
|
+
f8b[3] = buf[pos + 3];
|
|
885
|
+
f8b[4] = buf[pos + 4];
|
|
886
|
+
f8b[5] = buf[pos + 5];
|
|
887
|
+
f8b[6] = buf[pos + 6];
|
|
888
|
+
f8b[7] = buf[pos + 7];
|
|
889
|
+
return f64[0];
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
function readDouble_f64_rev(buf, pos) {
|
|
893
|
+
f8b[7] = buf[pos ];
|
|
894
|
+
f8b[6] = buf[pos + 1];
|
|
895
|
+
f8b[5] = buf[pos + 2];
|
|
896
|
+
f8b[4] = buf[pos + 3];
|
|
897
|
+
f8b[3] = buf[pos + 4];
|
|
898
|
+
f8b[2] = buf[pos + 5];
|
|
899
|
+
f8b[1] = buf[pos + 6];
|
|
900
|
+
f8b[0] = buf[pos + 7];
|
|
901
|
+
return f64[0];
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
/* istanbul ignore next */
|
|
905
|
+
exports.readDoubleLE = le ? readDouble_f64_cpy : readDouble_f64_rev;
|
|
906
|
+
/* istanbul ignore next */
|
|
907
|
+
exports.readDoubleBE = le ? readDouble_f64_rev : readDouble_f64_cpy;
|
|
908
|
+
|
|
909
|
+
// double: ieee754
|
|
910
|
+
})(); else (function() {
|
|
911
|
+
|
|
912
|
+
function writeDouble_ieee754(writeUint, off0, off1, val, buf, pos) {
|
|
913
|
+
var sign = val < 0 ? 1 : 0;
|
|
914
|
+
if (sign)
|
|
915
|
+
val = -val;
|
|
916
|
+
if (val === 0) {
|
|
917
|
+
writeUint(0, buf, pos + off0);
|
|
918
|
+
writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos + off1);
|
|
919
|
+
} else if (isNaN(val)) {
|
|
920
|
+
writeUint(0, buf, pos + off0);
|
|
921
|
+
writeUint(2146959360, buf, pos + off1);
|
|
922
|
+
} else if (val > 1.7976931348623157e+308) { // +-Infinity
|
|
923
|
+
writeUint(0, buf, pos + off0);
|
|
924
|
+
writeUint((sign << 31 | 2146435072) >>> 0, buf, pos + off1);
|
|
925
|
+
} else {
|
|
926
|
+
var mantissa;
|
|
927
|
+
if (val < 2.2250738585072014e-308) { // denormal
|
|
928
|
+
mantissa = val / 5e-324;
|
|
929
|
+
writeUint(mantissa >>> 0, buf, pos + off0);
|
|
930
|
+
writeUint((sign << 31 | mantissa / 4294967296) >>> 0, buf, pos + off1);
|
|
931
|
+
} else {
|
|
932
|
+
var exponent = Math.floor(Math.log(val) / Math.LN2);
|
|
933
|
+
if (exponent === 1024)
|
|
934
|
+
exponent = 1023;
|
|
935
|
+
mantissa = val * Math.pow(2, -exponent);
|
|
936
|
+
writeUint(mantissa * 4503599627370496 >>> 0, buf, pos + off0);
|
|
937
|
+
writeUint((sign << 31 | exponent + 1023 << 20 | mantissa * 1048576 & 1048575) >>> 0, buf, pos + off1);
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
exports.writeDoubleLE = writeDouble_ieee754.bind(null, writeUintLE, 0, 4);
|
|
943
|
+
exports.writeDoubleBE = writeDouble_ieee754.bind(null, writeUintBE, 4, 0);
|
|
944
|
+
|
|
945
|
+
function readDouble_ieee754(readUint, off0, off1, buf, pos) {
|
|
946
|
+
var lo = readUint(buf, pos + off0),
|
|
947
|
+
hi = readUint(buf, pos + off1);
|
|
948
|
+
var sign = (hi >> 31) * 2 + 1,
|
|
949
|
+
exponent = hi >>> 20 & 2047,
|
|
950
|
+
mantissa = 4294967296 * (hi & 1048575) + lo;
|
|
951
|
+
return exponent === 2047
|
|
952
|
+
? mantissa
|
|
953
|
+
? NaN
|
|
954
|
+
: sign * Infinity
|
|
955
|
+
: exponent === 0 // denormal
|
|
956
|
+
? sign * 5e-324 * mantissa
|
|
957
|
+
: sign * Math.pow(2, exponent - 1075) * (mantissa + 4503599627370496);
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
exports.readDoubleLE = readDouble_ieee754.bind(null, readUintLE, 0, 4);
|
|
961
|
+
exports.readDoubleBE = readDouble_ieee754.bind(null, readUintBE, 4, 0);
|
|
962
|
+
|
|
963
|
+
})();
|
|
964
|
+
|
|
965
|
+
return exports;
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
// uint helpers
|
|
969
|
+
|
|
970
|
+
function writeUintLE(val, buf, pos) {
|
|
971
|
+
buf[pos ] = val & 255;
|
|
972
|
+
buf[pos + 1] = val >>> 8 & 255;
|
|
973
|
+
buf[pos + 2] = val >>> 16 & 255;
|
|
974
|
+
buf[pos + 3] = val >>> 24;
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
function writeUintBE(val, buf, pos) {
|
|
978
|
+
buf[pos ] = val >>> 24;
|
|
979
|
+
buf[pos + 1] = val >>> 16 & 255;
|
|
980
|
+
buf[pos + 2] = val >>> 8 & 255;
|
|
981
|
+
buf[pos + 3] = val & 255;
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
function readUintLE(buf, pos) {
|
|
985
|
+
return (buf[pos ]
|
|
986
|
+
| buf[pos + 1] << 8
|
|
987
|
+
| buf[pos + 2] << 16
|
|
988
|
+
| buf[pos + 3] << 24) >>> 0;
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
function readUintBE(buf, pos) {
|
|
992
|
+
return (buf[pos ] << 24
|
|
993
|
+
| buf[pos + 1] << 16
|
|
994
|
+
| buf[pos + 2] << 8
|
|
995
|
+
| buf[pos + 3]) >>> 0;
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
|
|
999
|
+
/***/ }),
|
|
1000
|
+
|
|
1001
|
+
/***/ 7199:
|
|
1002
|
+
/***/ ((module) => {
|
|
1003
|
+
|
|
1004
|
+
"use strict";
|
|
1005
|
+
|
|
1006
|
+
module.exports = inquire;
|
|
1007
|
+
|
|
1008
|
+
/**
|
|
1009
|
+
* Requires a module only if available.
|
|
1010
|
+
* @memberof util
|
|
1011
|
+
* @param {string} moduleName Module to require
|
|
1012
|
+
* @returns {?Object} Required module if available and not empty, otherwise `null`
|
|
1013
|
+
*/
|
|
1014
|
+
function inquire(moduleName) {
|
|
1015
|
+
try {
|
|
1016
|
+
var mod = eval("quire".replace(/^/,"re"))(moduleName); // eslint-disable-line no-eval
|
|
1017
|
+
if (mod && (mod.length || Object.keys(mod).length))
|
|
1018
|
+
return mod;
|
|
1019
|
+
} catch (e) {} // eslint-disable-line no-empty
|
|
1020
|
+
return null;
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
|
|
1024
|
+
/***/ }),
|
|
1025
|
+
|
|
1026
|
+
/***/ 8626:
|
|
1027
|
+
/***/ ((__unused_webpack_module, exports) => {
|
|
1028
|
+
|
|
1029
|
+
"use strict";
|
|
1030
|
+
|
|
1031
|
+
|
|
1032
|
+
/**
|
|
1033
|
+
* A minimal path module to resolve Unix, Windows and URL paths alike.
|
|
1034
|
+
* @memberof util
|
|
1035
|
+
* @namespace
|
|
1036
|
+
*/
|
|
1037
|
+
var path = exports;
|
|
1038
|
+
|
|
1039
|
+
var isAbsolute =
|
|
1040
|
+
/**
|
|
1041
|
+
* Tests if the specified path is absolute.
|
|
1042
|
+
* @param {string} path Path to test
|
|
1043
|
+
* @returns {boolean} `true` if path is absolute
|
|
1044
|
+
*/
|
|
1045
|
+
path.isAbsolute = function isAbsolute(path) {
|
|
1046
|
+
return /^(?:\/|\w+:)/.test(path);
|
|
1047
|
+
};
|
|
1048
|
+
|
|
1049
|
+
var normalize =
|
|
1050
|
+
/**
|
|
1051
|
+
* Normalizes the specified path.
|
|
1052
|
+
* @param {string} path Path to normalize
|
|
1053
|
+
* @returns {string} Normalized path
|
|
1054
|
+
*/
|
|
1055
|
+
path.normalize = function normalize(path) {
|
|
1056
|
+
path = path.replace(/\\/g, "/")
|
|
1057
|
+
.replace(/\/{2,}/g, "/");
|
|
1058
|
+
var parts = path.split("/"),
|
|
1059
|
+
absolute = isAbsolute(path),
|
|
1060
|
+
prefix = "";
|
|
1061
|
+
if (absolute)
|
|
1062
|
+
prefix = parts.shift() + "/";
|
|
1063
|
+
for (var i = 0; i < parts.length;) {
|
|
1064
|
+
if (parts[i] === "..") {
|
|
1065
|
+
if (i > 0 && parts[i - 1] !== "..")
|
|
1066
|
+
parts.splice(--i, 2);
|
|
1067
|
+
else if (absolute)
|
|
1068
|
+
parts.splice(i, 1);
|
|
1069
|
+
else
|
|
1070
|
+
++i;
|
|
1071
|
+
} else if (parts[i] === ".")
|
|
1072
|
+
parts.splice(i, 1);
|
|
1073
|
+
else
|
|
1074
|
+
++i;
|
|
1075
|
+
}
|
|
1076
|
+
return prefix + parts.join("/");
|
|
1077
|
+
};
|
|
1078
|
+
|
|
1079
|
+
/**
|
|
1080
|
+
* Resolves the specified include path against the specified origin path.
|
|
1081
|
+
* @param {string} originPath Path to the origin file
|
|
1082
|
+
* @param {string} includePath Include path relative to origin path
|
|
1083
|
+
* @param {boolean} [alreadyNormalized=false] `true` if both paths are already known to be normalized
|
|
1084
|
+
* @returns {string} Path to the include file
|
|
1085
|
+
*/
|
|
1086
|
+
path.resolve = function resolve(originPath, includePath, alreadyNormalized) {
|
|
1087
|
+
if (!alreadyNormalized)
|
|
1088
|
+
includePath = normalize(includePath);
|
|
1089
|
+
if (isAbsolute(includePath))
|
|
1090
|
+
return includePath;
|
|
1091
|
+
if (!alreadyNormalized)
|
|
1092
|
+
originPath = normalize(originPath);
|
|
1093
|
+
return (originPath = originPath.replace(/(?:\/|^)[^/]+$/, "")).length ? normalize(originPath + "/" + includePath) : includePath;
|
|
1094
|
+
};
|
|
1095
|
+
|
|
1096
|
+
|
|
1097
|
+
/***/ }),
|
|
1098
|
+
|
|
1099
|
+
/***/ 6662:
|
|
1100
|
+
/***/ ((module) => {
|
|
1101
|
+
|
|
1102
|
+
"use strict";
|
|
1103
|
+
|
|
1104
|
+
module.exports = pool;
|
|
1105
|
+
|
|
1106
|
+
/**
|
|
1107
|
+
* An allocator as used by {@link util.pool}.
|
|
1108
|
+
* @typedef PoolAllocator
|
|
1109
|
+
* @type {function}
|
|
1110
|
+
* @param {number} size Buffer size
|
|
1111
|
+
* @returns {Uint8Array} Buffer
|
|
1112
|
+
*/
|
|
1113
|
+
|
|
1114
|
+
/**
|
|
1115
|
+
* A slicer as used by {@link util.pool}.
|
|
1116
|
+
* @typedef PoolSlicer
|
|
1117
|
+
* @type {function}
|
|
1118
|
+
* @param {number} start Start offset
|
|
1119
|
+
* @param {number} end End offset
|
|
1120
|
+
* @returns {Uint8Array} Buffer slice
|
|
1121
|
+
* @this {Uint8Array}
|
|
1122
|
+
*/
|
|
1123
|
+
|
|
1124
|
+
/**
|
|
1125
|
+
* A general purpose buffer pool.
|
|
1126
|
+
* @memberof util
|
|
1127
|
+
* @function
|
|
1128
|
+
* @param {PoolAllocator} alloc Allocator
|
|
1129
|
+
* @param {PoolSlicer} slice Slicer
|
|
1130
|
+
* @param {number} [size=8192] Slab size
|
|
1131
|
+
* @returns {PoolAllocator} Pooled allocator
|
|
1132
|
+
*/
|
|
1133
|
+
function pool(alloc, slice, size) {
|
|
1134
|
+
var SIZE = size || 8192;
|
|
1135
|
+
var MAX = SIZE >>> 1;
|
|
1136
|
+
var slab = null;
|
|
1137
|
+
var offset = SIZE;
|
|
1138
|
+
return function pool_alloc(size) {
|
|
1139
|
+
if (size < 1 || size > MAX)
|
|
1140
|
+
return alloc(size);
|
|
1141
|
+
if (offset + size > SIZE) {
|
|
1142
|
+
slab = alloc(SIZE);
|
|
1143
|
+
offset = 0;
|
|
1144
|
+
}
|
|
1145
|
+
var buf = slice.call(slab, offset, offset += size);
|
|
1146
|
+
if (offset & 7) // align to 32 bit
|
|
1147
|
+
offset = (offset | 7) + 1;
|
|
1148
|
+
return buf;
|
|
1149
|
+
};
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
|
|
1153
|
+
/***/ }),
|
|
1154
|
+
|
|
1155
|
+
/***/ 4997:
|
|
1156
|
+
/***/ ((__unused_webpack_module, exports) => {
|
|
1157
|
+
|
|
1158
|
+
"use strict";
|
|
1159
|
+
|
|
1160
|
+
|
|
1161
|
+
/**
|
|
1162
|
+
* A minimal UTF8 implementation for number arrays.
|
|
1163
|
+
* @memberof util
|
|
1164
|
+
* @namespace
|
|
1165
|
+
*/
|
|
1166
|
+
var utf8 = exports;
|
|
1167
|
+
|
|
1168
|
+
/**
|
|
1169
|
+
* Calculates the UTF8 byte length of a string.
|
|
1170
|
+
* @param {string} string String
|
|
1171
|
+
* @returns {number} Byte length
|
|
1172
|
+
*/
|
|
1173
|
+
utf8.length = function utf8_length(string) {
|
|
1174
|
+
var len = 0,
|
|
1175
|
+
c = 0;
|
|
1176
|
+
for (var i = 0; i < string.length; ++i) {
|
|
1177
|
+
c = string.charCodeAt(i);
|
|
1178
|
+
if (c < 128)
|
|
1179
|
+
len += 1;
|
|
1180
|
+
else if (c < 2048)
|
|
1181
|
+
len += 2;
|
|
1182
|
+
else if ((c & 0xFC00) === 0xD800 && (string.charCodeAt(i + 1) & 0xFC00) === 0xDC00) {
|
|
1183
|
+
++i;
|
|
1184
|
+
len += 4;
|
|
1185
|
+
} else
|
|
1186
|
+
len += 3;
|
|
1187
|
+
}
|
|
1188
|
+
return len;
|
|
1189
|
+
};
|
|
1190
|
+
|
|
1191
|
+
/**
|
|
1192
|
+
* Reads UTF8 bytes as a string.
|
|
1193
|
+
* @param {Uint8Array} buffer Source buffer
|
|
1194
|
+
* @param {number} start Source start
|
|
1195
|
+
* @param {number} end Source end
|
|
1196
|
+
* @returns {string} String read
|
|
1197
|
+
*/
|
|
1198
|
+
utf8.read = function utf8_read(buffer, start, end) {
|
|
1199
|
+
var len = end - start;
|
|
1200
|
+
if (len < 1)
|
|
1201
|
+
return "";
|
|
1202
|
+
var parts = null,
|
|
1203
|
+
chunk = [],
|
|
1204
|
+
i = 0, // char offset
|
|
1205
|
+
t; // temporary
|
|
1206
|
+
while (start < end) {
|
|
1207
|
+
t = buffer[start++];
|
|
1208
|
+
if (t < 128)
|
|
1209
|
+
chunk[i++] = t;
|
|
1210
|
+
else if (t > 191 && t < 224)
|
|
1211
|
+
chunk[i++] = (t & 31) << 6 | buffer[start++] & 63;
|
|
1212
|
+
else if (t > 239 && t < 365) {
|
|
1213
|
+
t = ((t & 7) << 18 | (buffer[start++] & 63) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63) - 0x10000;
|
|
1214
|
+
chunk[i++] = 0xD800 + (t >> 10);
|
|
1215
|
+
chunk[i++] = 0xDC00 + (t & 1023);
|
|
1216
|
+
} else
|
|
1217
|
+
chunk[i++] = (t & 15) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63;
|
|
1218
|
+
if (i > 8191) {
|
|
1219
|
+
(parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
|
|
1220
|
+
i = 0;
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
if (parts) {
|
|
1224
|
+
if (i)
|
|
1225
|
+
parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
|
|
1226
|
+
return parts.join("");
|
|
1227
|
+
}
|
|
1228
|
+
return String.fromCharCode.apply(String, chunk.slice(0, i));
|
|
1229
|
+
};
|
|
1230
|
+
|
|
1231
|
+
/**
|
|
1232
|
+
* Writes a string as UTF8 bytes.
|
|
1233
|
+
* @param {string} string Source string
|
|
1234
|
+
* @param {Uint8Array} buffer Destination buffer
|
|
1235
|
+
* @param {number} offset Destination offset
|
|
1236
|
+
* @returns {number} Bytes written
|
|
1237
|
+
*/
|
|
1238
|
+
utf8.write = function utf8_write(string, buffer, offset) {
|
|
1239
|
+
var start = offset,
|
|
1240
|
+
c1, // character 1
|
|
1241
|
+
c2; // character 2
|
|
1242
|
+
for (var i = 0; i < string.length; ++i) {
|
|
1243
|
+
c1 = string.charCodeAt(i);
|
|
1244
|
+
if (c1 < 128) {
|
|
1245
|
+
buffer[offset++] = c1;
|
|
1246
|
+
} else if (c1 < 2048) {
|
|
1247
|
+
buffer[offset++] = c1 >> 6 | 192;
|
|
1248
|
+
buffer[offset++] = c1 & 63 | 128;
|
|
1249
|
+
} else if ((c1 & 0xFC00) === 0xD800 && ((c2 = string.charCodeAt(i + 1)) & 0xFC00) === 0xDC00) {
|
|
1250
|
+
c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF);
|
|
1251
|
+
++i;
|
|
1252
|
+
buffer[offset++] = c1 >> 18 | 240;
|
|
1253
|
+
buffer[offset++] = c1 >> 12 & 63 | 128;
|
|
1254
|
+
buffer[offset++] = c1 >> 6 & 63 | 128;
|
|
1255
|
+
buffer[offset++] = c1 & 63 | 128;
|
|
1256
|
+
} else {
|
|
1257
|
+
buffer[offset++] = c1 >> 12 | 224;
|
|
1258
|
+
buffer[offset++] = c1 >> 6 & 63 | 128;
|
|
1259
|
+
buffer[offset++] = c1 & 63 | 128;
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
return offset - start;
|
|
1263
|
+
};
|
|
1264
|
+
|
|
1265
|
+
|
|
1266
|
+
/***/ }),
|
|
1267
|
+
|
|
1268
|
+
/***/ 9669:
|
|
1269
|
+
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
1270
|
+
|
|
1271
|
+
module.exports = __webpack_require__(1609);
|
|
1272
|
+
|
|
1273
|
+
/***/ }),
|
|
1274
|
+
|
|
1275
|
+
/***/ 5448:
|
|
1276
|
+
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
1277
|
+
|
|
1278
|
+
"use strict";
|
|
1279
|
+
|
|
1280
|
+
|
|
1281
|
+
var utils = __webpack_require__(4867);
|
|
1282
|
+
var settle = __webpack_require__(6026);
|
|
1283
|
+
var cookies = __webpack_require__(4372);
|
|
1284
|
+
var buildURL = __webpack_require__(5327);
|
|
1285
|
+
var buildFullPath = __webpack_require__(4097);
|
|
1286
|
+
var parseHeaders = __webpack_require__(4109);
|
|
1287
|
+
var isURLSameOrigin = __webpack_require__(7985);
|
|
1288
|
+
var createError = __webpack_require__(5061);
|
|
1289
|
+
|
|
1290
|
+
module.exports = function xhrAdapter(config) {
|
|
1291
|
+
return new Promise(function dispatchXhrRequest(resolve, reject) {
|
|
1292
|
+
var requestData = config.data;
|
|
1293
|
+
var requestHeaders = config.headers;
|
|
1294
|
+
|
|
1295
|
+
if (utils.isFormData(requestData)) {
|
|
1296
|
+
delete requestHeaders['Content-Type']; // Let the browser set it
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1299
|
+
var request = new XMLHttpRequest();
|
|
1300
|
+
|
|
1301
|
+
// HTTP basic authentication
|
|
1302
|
+
if (config.auth) {
|
|
1303
|
+
var username = config.auth.username || '';
|
|
1304
|
+
var password = config.auth.password ? unescape(encodeURIComponent(config.auth.password)) : '';
|
|
1305
|
+
requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password);
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
var fullPath = buildFullPath(config.baseURL, config.url);
|
|
1309
|
+
request.open(config.method.toUpperCase(), buildURL(fullPath, config.params, config.paramsSerializer), true);
|
|
1310
|
+
|
|
1311
|
+
// Set the request timeout in MS
|
|
1312
|
+
request.timeout = config.timeout;
|
|
1313
|
+
|
|
1314
|
+
// Listen for ready state
|
|
1315
1315
|
request.onreadystatechange = function handleLoad() {
|
|
1316
1316
|
if (!request || request.readyState !== 4) {
|
|
1317
1317
|
return;
|
|
@@ -11507,390 +11507,303 @@ BufferWriter._configure();
|
|
|
11507
11507
|
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
11508
11508
|
|
|
11509
11509
|
"use strict";
|
|
11510
|
-
|
|
11511
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
11512
|
-
exports.Contract = void 0;
|
|
11513
|
-
const
|
|
11514
|
-
const utils_1 = __webpack_require__(8593);
|
|
11515
|
-
|
|
11516
|
-
|
|
11517
|
-
*
|
|
11518
|
-
*
|
|
11519
|
-
*
|
|
11520
|
-
*
|
|
11521
|
-
*
|
|
11522
|
-
*
|
|
11523
|
-
*
|
|
11524
|
-
|
|
11525
|
-
|
|
11526
|
-
|
|
11527
|
-
|
|
11528
|
-
|
|
11529
|
-
|
|
11530
|
-
|
|
11531
|
-
|
|
11532
|
-
*
|
|
11533
|
-
*
|
|
11534
|
-
*
|
|
11535
|
-
*
|
|
11536
|
-
*
|
|
11537
|
-
*
|
|
11538
|
-
*
|
|
11539
|
-
*
|
|
11540
|
-
*
|
|
11541
|
-
*
|
|
11542
|
-
*
|
|
11543
|
-
*
|
|
11544
|
-
*
|
|
11545
|
-
*
|
|
11546
|
-
*
|
|
11547
|
-
*
|
|
11548
|
-
*
|
|
11549
|
-
* });
|
|
11550
|
-
*
|
|
11551
|
-
*
|
|
11552
|
-
*
|
|
11553
|
-
*
|
|
11554
|
-
*
|
|
11555
|
-
*
|
|
11556
|
-
* });
|
|
11557
|
-
* console.log(
|
|
11558
|
-
*
|
|
11559
|
-
* //
|
|
11560
|
-
* const
|
|
11561
|
-
*
|
|
11562
|
-
*
|
|
11563
|
-
*
|
|
11564
|
-
*
|
|
11565
|
-
*
|
|
11566
|
-
|
|
11567
|
-
|
|
11568
|
-
|
|
11569
|
-
|
|
11570
|
-
|
|
11571
|
-
|
|
11572
|
-
|
|
11573
|
-
|
|
11574
|
-
|
|
11575
|
-
|
|
11576
|
-
|
|
11577
|
-
|
|
11578
|
-
|
|
11579
|
-
|
|
11580
|
-
|
|
11581
|
-
|
|
11582
|
-
this.
|
|
11583
|
-
|
|
11584
|
-
|
|
11585
|
-
|
|
11586
|
-
|
|
11587
|
-
|
|
11588
|
-
|
|
11589
|
-
|
|
11590
|
-
|
|
11591
|
-
|
|
11592
|
-
|
|
11593
|
-
|
|
11594
|
-
Object.keys(this.abi.methods).forEach((name) => {
|
|
11595
|
-
this.functions[name] = async (argu = {}, options) => {
|
|
11596
|
-
if (!this.provider)
|
|
11597
|
-
throw new Error("provider not found");
|
|
11598
|
-
if (!this.abi || !this.abi.methods)
|
|
11599
|
-
throw new Error("Methods are not defined");
|
|
11600
|
-
if (!this.abi.methods[name])
|
|
11601
|
-
throw new Error(`Method ${name} not defined in the ABI`);
|
|
11602
|
-
const opts = {
|
|
11603
|
-
...this.options,
|
|
11604
|
-
...options,
|
|
11605
|
-
};
|
|
11606
|
-
const { readOnly, output, defaultOutput, preformatInput, preformatOutput, } = this.abi.methods[name];
|
|
11607
|
-
let args;
|
|
11608
|
-
if (typeof preformatInput === "function") {
|
|
11609
|
-
args = preformatInput(argu);
|
|
11610
|
-
}
|
|
11611
|
-
else {
|
|
11612
|
-
args = argu;
|
|
11613
|
-
}
|
|
11614
|
-
const operation = this.encodeOperation({ name, args });
|
|
11615
|
-
if (readOnly) {
|
|
11616
|
-
if (!output)
|
|
11617
|
-
throw new Error(`No output defined for ${name}`);
|
|
11618
|
-
// read contract
|
|
11619
|
-
const { result: resultEncoded } = await this.provider.readContract({
|
|
11620
|
-
|
|
11621
|
-
|
|
11622
|
-
args: utils_1.encodeBase64(operation.
|
|
11623
|
-
});
|
|
11624
|
-
let result = defaultOutput;
|
|
11625
|
-
if (resultEncoded) {
|
|
11626
|
-
result = this.
|
|
11627
|
-
}
|
|
11628
|
-
if (typeof preformatOutput === "function") {
|
|
11629
|
-
result = preformatOutput(result);
|
|
11630
|
-
}
|
|
11631
|
-
return { operation, result };
|
|
11632
|
-
}
|
|
11633
|
-
// return operation if send is false
|
|
11634
|
-
if (!(opts === null || opts === void 0 ? void 0 : opts.sendTransaction))
|
|
11635
|
-
return { operation };
|
|
11636
|
-
// write contract (sign and send)
|
|
11637
|
-
if (!this.signer)
|
|
11638
|
-
throw new Error("signer not found");
|
|
11639
|
-
const transaction = await this.signer.encodeTransaction({
|
|
11640
|
-
...opts,
|
|
11641
|
-
operations: [operation],
|
|
11642
|
-
});
|
|
11643
|
-
const abis = {};
|
|
11644
|
-
if (opts === null || opts === void 0 ? void 0 : opts.sendAbis) {
|
|
11645
|
-
const contractId = utils_1.encodeBase58(this.id);
|
|
11646
|
-
abis[contractId] = this.abi;
|
|
11647
|
-
}
|
|
11648
|
-
const transactionResponse = await this.signer.sendTransaction(transaction, abis);
|
|
11649
|
-
return { operation, transaction, transactionResponse };
|
|
11650
|
-
};
|
|
11651
|
-
});
|
|
11652
|
-
}
|
|
11653
|
-
}
|
|
11654
|
-
/**
|
|
11655
|
-
* Compute contract Id
|
|
11656
|
-
*/
|
|
11657
|
-
static computeContractId(address) {
|
|
11658
|
-
return utils_1.decodeBase58(address);
|
|
11659
|
-
}
|
|
11660
|
-
/**
|
|
11661
|
-
* Get contract Id
|
|
11662
|
-
*/
|
|
11663
|
-
getId() {
|
|
11664
|
-
if (!this.id)
|
|
11665
|
-
throw new Error("id is not defined");
|
|
11666
|
-
return utils_1.encodeBase58(this.id);
|
|
11667
|
-
}
|
|
11668
|
-
/**
|
|
11669
|
-
* Function to deploy a new smart contract.
|
|
11670
|
-
* The Bytecode must be defined in the constructor of the class
|
|
11671
|
-
* @example
|
|
11672
|
-
* ```ts
|
|
11673
|
-
* const
|
|
11674
|
-
* const provider = new Provider(["http://api.koinos.io:8080"]);
|
|
11675
|
-
* const
|
|
11676
|
-
* const
|
|
11677
|
-
* const {
|
|
11678
|
-
*
|
|
11679
|
-
*
|
|
11680
|
-
*
|
|
11681
|
-
*
|
|
11682
|
-
|
|
11683
|
-
|
|
11684
|
-
|
|
11685
|
-
|
|
11686
|
-
|
|
11687
|
-
|
|
11688
|
-
|
|
11689
|
-
|
|
11690
|
-
...options,
|
|
11691
|
-
|
|
11692
|
-
|
|
11693
|
-
|
|
11694
|
-
|
|
11695
|
-
|
|
11696
|
-
|
|
11697
|
-
|
|
11698
|
-
|
|
11699
|
-
|
|
11700
|
-
|
|
11701
|
-
|
|
11702
|
-
|
|
11703
|
-
|
|
11704
|
-
|
|
11705
|
-
|
|
11706
|
-
|
|
11707
|
-
|
|
11708
|
-
|
|
11709
|
-
|
|
11710
|
-
*
|
|
11711
|
-
*
|
|
11712
|
-
* @
|
|
11713
|
-
* @
|
|
11714
|
-
*
|
|
11715
|
-
*
|
|
11716
|
-
*
|
|
11717
|
-
*
|
|
11718
|
-
*
|
|
11719
|
-
*
|
|
11720
|
-
*
|
|
11721
|
-
*
|
|
11722
|
-
*
|
|
11723
|
-
*
|
|
11724
|
-
*
|
|
11725
|
-
*
|
|
11726
|
-
* //
|
|
11727
|
-
* //
|
|
11728
|
-
* //
|
|
11729
|
-
* //
|
|
11730
|
-
* //
|
|
11731
|
-
* //
|
|
11732
|
-
*
|
|
11733
|
-
|
|
11734
|
-
|
|
11735
|
-
|
|
11736
|
-
|
|
11737
|
-
|
|
11738
|
-
|
|
11739
|
-
|
|
11740
|
-
|
|
11741
|
-
|
|
11742
|
-
|
|
11743
|
-
|
|
11744
|
-
|
|
11745
|
-
|
|
11746
|
-
|
|
11747
|
-
|
|
11748
|
-
|
|
11749
|
-
|
|
11750
|
-
|
|
11751
|
-
|
|
11752
|
-
|
|
11753
|
-
|
|
11754
|
-
|
|
11755
|
-
|
|
11756
|
-
|
|
11757
|
-
|
|
11758
|
-
*
|
|
11759
|
-
*
|
|
11760
|
-
*
|
|
11761
|
-
*
|
|
11762
|
-
*
|
|
11763
|
-
*
|
|
11764
|
-
*
|
|
11765
|
-
*
|
|
11766
|
-
*
|
|
11767
|
-
*
|
|
11768
|
-
*
|
|
11769
|
-
* //
|
|
11770
|
-
* //
|
|
11771
|
-
* //
|
|
11772
|
-
* //
|
|
11773
|
-
* //
|
|
11774
|
-
* //
|
|
11775
|
-
* //
|
|
11776
|
-
*
|
|
11777
|
-
|
|
11778
|
-
|
|
11779
|
-
|
|
11780
|
-
|
|
11781
|
-
|
|
11782
|
-
|
|
11783
|
-
|
|
11784
|
-
|
|
11785
|
-
|
|
11786
|
-
|
|
11787
|
-
|
|
11788
|
-
|
|
11789
|
-
|
|
11790
|
-
|
|
11791
|
-
|
|
11792
|
-
|
|
11793
|
-
|
|
11794
|
-
|
|
11795
|
-
|
|
11796
|
-
|
|
11797
|
-
|
|
11798
|
-
|
|
11799
|
-
|
|
11800
|
-
|
|
11801
|
-
|
|
11802
|
-
|
|
11803
|
-
|
|
11804
|
-
|
|
11805
|
-
|
|
11806
|
-
|
|
11807
|
-
throw new Error("Protobuffers are not defined");
|
|
11808
|
-
const protobufType = this.protobuffers.lookupType(typeName);
|
|
11809
|
-
const object = {};
|
|
11810
|
-
// TODO: format from Buffer to base58/base64 for nested fields
|
|
11811
|
-
Object.keys(protobufType.fields).forEach((fieldName) => {
|
|
11812
|
-
const { options, name, type } = protobufType.fields[fieldName];
|
|
11813
|
-
// No byte conversion
|
|
11814
|
-
if (type !== "bytes") {
|
|
11815
|
-
object[name] = copyValue(valueDecoded[name]);
|
|
11816
|
-
return;
|
|
11817
|
-
}
|
|
11818
|
-
// Default byte conversion
|
|
11819
|
-
if (!options || !options[OP_BYTES]) {
|
|
11820
|
-
object[name] = utils_1.decodeBase64(valueDecoded[name]);
|
|
11821
|
-
return;
|
|
11822
|
-
}
|
|
11823
|
-
// Specific byte conversion
|
|
11824
|
-
switch (options[OP_BYTES]) {
|
|
11825
|
-
case "BASE58":
|
|
11826
|
-
case "CONTRACT_ID":
|
|
11827
|
-
case "ADDRESS":
|
|
11828
|
-
object[name] = utils_1.decodeBase58(valueDecoded[name]);
|
|
11829
|
-
break;
|
|
11830
|
-
case "BASE64":
|
|
11831
|
-
object[name] = utils_1.decodeBase64(valueDecoded[name]);
|
|
11832
|
-
break;
|
|
11833
|
-
case "HEX":
|
|
11834
|
-
case "BLOCK_ID":
|
|
11835
|
-
case "TRANSACTION_ID":
|
|
11836
|
-
object[name] = utils_1.toUint8Array(valueDecoded[name].replace("0x", ""));
|
|
11837
|
-
break;
|
|
11838
|
-
default:
|
|
11839
|
-
throw new Error(`unknown koinos_byte_type ${options[OP_BYTES]}`);
|
|
11840
|
-
}
|
|
11841
|
-
});
|
|
11842
|
-
const message = protobufType.create(object);
|
|
11843
|
-
const buffer = protobufType.encode(message).finish();
|
|
11844
|
-
return buffer;
|
|
11845
|
-
}
|
|
11846
|
-
/**
|
|
11847
|
-
* Function to decode bytes using the protobuffer definitions
|
|
11848
|
-
* It also encodes the bytes for special cases (base58, hex string)
|
|
11849
|
-
*/
|
|
11850
|
-
decodeType(valueEncoded, typeName) {
|
|
11851
|
-
if (!this.protobuffers)
|
|
11852
|
-
throw new Error("Protobuffers are not defined");
|
|
11853
|
-
const valueBuffer = typeof valueEncoded === "string"
|
|
11854
|
-
? utils_1.decodeBase64(valueEncoded)
|
|
11855
|
-
: valueEncoded;
|
|
11856
|
-
const protobufType = this.protobuffers.lookupType(typeName);
|
|
11857
|
-
const message = protobufType.decode(valueBuffer);
|
|
11858
|
-
const object = protobufType.toObject(message, { longs: String });
|
|
11859
|
-
// TODO: format from Buffer to base58/base64 for nested fields
|
|
11860
|
-
Object.keys(protobufType.fields).forEach((fieldName) => {
|
|
11861
|
-
const { options, name, type } = protobufType.fields[fieldName];
|
|
11862
|
-
// No byte conversion
|
|
11863
|
-
if (type !== "bytes")
|
|
11864
|
-
return;
|
|
11865
|
-
// Default byte conversion
|
|
11866
|
-
if (!options || !options[OP_BYTES]) {
|
|
11867
|
-
object[name] = utils_1.encodeBase64(object[name]);
|
|
11868
|
-
return;
|
|
11869
|
-
}
|
|
11870
|
-
// Specific byte conversion
|
|
11871
|
-
switch (options[OP_BYTES]) {
|
|
11872
|
-
case "BASE58":
|
|
11873
|
-
case "CONTRACT_ID":
|
|
11874
|
-
case "ADDRESS":
|
|
11875
|
-
object[name] = utils_1.encodeBase58(object[name]);
|
|
11876
|
-
break;
|
|
11877
|
-
case "BASE64":
|
|
11878
|
-
object[name] = utils_1.encodeBase64(object[name]);
|
|
11879
|
-
break;
|
|
11880
|
-
case "HEX":
|
|
11881
|
-
case "BLOCK_ID":
|
|
11882
|
-
case "TRANSACTION_ID":
|
|
11883
|
-
object[name] = `0x${utils_1.toHexString(object[name])}`;
|
|
11884
|
-
break;
|
|
11885
|
-
default:
|
|
11886
|
-
throw new Error(`unknown koinos_byte_type ${options[OP_BYTES]}`);
|
|
11887
|
-
}
|
|
11888
|
-
});
|
|
11889
|
-
return object;
|
|
11890
|
-
}
|
|
11891
|
-
}
|
|
11892
|
-
exports.Contract = Contract;
|
|
11893
|
-
exports.default = Contract;
|
|
11510
|
+
|
|
11511
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
11512
|
+
exports.Contract = void 0;
|
|
11513
|
+
const Serializer_1 = __webpack_require__(7187);
|
|
11514
|
+
const utils_1 = __webpack_require__(8593);
|
|
11515
|
+
/**
|
|
11516
|
+
* The contract class contains the contract ID and contract entries
|
|
11517
|
+
* definition needed to encode/decode operations during the
|
|
11518
|
+
* interaction with the user and the communication with the RPC node.
|
|
11519
|
+
*
|
|
11520
|
+
* @example
|
|
11521
|
+
*
|
|
11522
|
+
* ```ts
|
|
11523
|
+
* const { Contract, Provider, Signer, utils } = require("koilib");
|
|
11524
|
+
* const rpcNodes = ["http://api.koinos.io:8080"];
|
|
11525
|
+
* const privateKey = "f186a5de49797bfd52dc42505c33d75a46822ed5b60046e09d7c336242e20200";
|
|
11526
|
+
* const provider = new Provider(rpcNodes);
|
|
11527
|
+
* const signer = new Signer({ privateKey, provider });
|
|
11528
|
+
* const koinContract = new Contract({
|
|
11529
|
+
* id: "19JntSm8pSNETT9aHTwAUHC5RMoaSmgZPJ",
|
|
11530
|
+
* abi: utils.Krc20Abi,
|
|
11531
|
+
* provider,
|
|
11532
|
+
* signer,
|
|
11533
|
+
* });
|
|
11534
|
+
* const koin = koinContract.functions;
|
|
11535
|
+
*
|
|
11536
|
+
* // optional: preformat input/output
|
|
11537
|
+
* koinContract.abi.methods.balanceOf.preformatInput = (owner) =>
|
|
11538
|
+
* ({ owner });
|
|
11539
|
+
* koinContract.abi.methods.balanceOf.preformatOutput = (res) =>
|
|
11540
|
+
* utils.formatUnits(res.value, 8);
|
|
11541
|
+
* koinContract.abi.methods.transfer.preformatInput = (input) => ({
|
|
11542
|
+
* from: signer.getAddress(),
|
|
11543
|
+
* to: input.to,
|
|
11544
|
+
* value: utils.parseUnits(input.value, 8),
|
|
11545
|
+
* });
|
|
11546
|
+
*
|
|
11547
|
+
* async funtion main() {
|
|
11548
|
+
* // Get balance
|
|
11549
|
+
* const { result } = await koin.balanceOf("12fN2CQnuJM8cMnWZ1hPtM4knjLME8E4PD");
|
|
11550
|
+
* console.log(result)
|
|
11551
|
+
*
|
|
11552
|
+
* // Transfer
|
|
11553
|
+
* const { transaction, transactionResponse } = await koin.transfer({
|
|
11554
|
+
* to: "172AB1FgCsYrRAW5cwQ8KjadgxofvgPFd6",
|
|
11555
|
+
* value: "10.0001",
|
|
11556
|
+
* });
|
|
11557
|
+
* console.log(`Transaction id ${transaction.id} submitted`);
|
|
11558
|
+
*
|
|
11559
|
+
* // wait to be mined
|
|
11560
|
+
* const blockId = await transactionResponse.wait();
|
|
11561
|
+
* console.log(`Transaction mined. Block id: ${blockId}`);
|
|
11562
|
+
* }
|
|
11563
|
+
*
|
|
11564
|
+
* main();
|
|
11565
|
+
* ```
|
|
11566
|
+
*/
|
|
11567
|
+
class Contract {
|
|
11568
|
+
constructor(c) {
|
|
11569
|
+
var _a;
|
|
11570
|
+
if (c.id)
|
|
11571
|
+
this.id = utils_1.decodeBase58(c.id);
|
|
11572
|
+
this.signer = c.signer;
|
|
11573
|
+
this.provider = c.provider || ((_a = c.signer) === null || _a === void 0 ? void 0 : _a.provider);
|
|
11574
|
+
this.abi = c.abi;
|
|
11575
|
+
this.bytecode = c.bytecode;
|
|
11576
|
+
if (c.serializer) {
|
|
11577
|
+
this.serializer = c.serializer;
|
|
11578
|
+
}
|
|
11579
|
+
else if (c.abi && c.abi.types) {
|
|
11580
|
+
this.serializer = new Serializer_1.Serializer(c.abi.types);
|
|
11581
|
+
}
|
|
11582
|
+
this.options = {
|
|
11583
|
+
rc_limit: 1e8,
|
|
11584
|
+
sendTransaction: true,
|
|
11585
|
+
sendAbis: true,
|
|
11586
|
+
...c.options,
|
|
11587
|
+
};
|
|
11588
|
+
this.functions = {};
|
|
11589
|
+
if (this.signer &&
|
|
11590
|
+
this.provider &&
|
|
11591
|
+
this.abi &&
|
|
11592
|
+
this.abi.methods &&
|
|
11593
|
+
this.serializer) {
|
|
11594
|
+
Object.keys(this.abi.methods).forEach((name) => {
|
|
11595
|
+
this.functions[name] = async (argu = {}, options) => {
|
|
11596
|
+
if (!this.provider)
|
|
11597
|
+
throw new Error("provider not found");
|
|
11598
|
+
if (!this.abi || !this.abi.methods)
|
|
11599
|
+
throw new Error("Methods are not defined");
|
|
11600
|
+
if (!this.abi.methods[name])
|
|
11601
|
+
throw new Error(`Method ${name} not defined in the ABI`);
|
|
11602
|
+
const opts = {
|
|
11603
|
+
...this.options,
|
|
11604
|
+
...options,
|
|
11605
|
+
};
|
|
11606
|
+
const { readOnly, output, defaultOutput, preformatInput, preformatOutput, } = this.abi.methods[name];
|
|
11607
|
+
let args;
|
|
11608
|
+
if (typeof preformatInput === "function") {
|
|
11609
|
+
args = preformatInput(argu);
|
|
11610
|
+
}
|
|
11611
|
+
else {
|
|
11612
|
+
args = argu;
|
|
11613
|
+
}
|
|
11614
|
+
const operation = await this.encodeOperation({ name, args });
|
|
11615
|
+
if (readOnly) {
|
|
11616
|
+
if (!output)
|
|
11617
|
+
throw new Error(`No output defined for ${name}`);
|
|
11618
|
+
// read contract
|
|
11619
|
+
const { result: resultEncoded } = await this.provider.readContract({
|
|
11620
|
+
contract_id: utils_1.encodeBase58(operation.call_contract.contract_id),
|
|
11621
|
+
entry_point: operation.call_contract.entry_point,
|
|
11622
|
+
args: utils_1.encodeBase64(operation.call_contract.args),
|
|
11623
|
+
});
|
|
11624
|
+
let result = defaultOutput;
|
|
11625
|
+
if (resultEncoded) {
|
|
11626
|
+
result = await this.serializer.deserialize(resultEncoded, output);
|
|
11627
|
+
}
|
|
11628
|
+
if (typeof preformatOutput === "function") {
|
|
11629
|
+
result = preformatOutput(result);
|
|
11630
|
+
}
|
|
11631
|
+
return { operation, result };
|
|
11632
|
+
}
|
|
11633
|
+
// return operation if send is false
|
|
11634
|
+
if (!(opts === null || opts === void 0 ? void 0 : opts.sendTransaction))
|
|
11635
|
+
return { operation };
|
|
11636
|
+
// write contract (sign and send)
|
|
11637
|
+
if (!this.signer)
|
|
11638
|
+
throw new Error("signer not found");
|
|
11639
|
+
const transaction = await this.signer.encodeTransaction({
|
|
11640
|
+
...opts,
|
|
11641
|
+
operations: [operation],
|
|
11642
|
+
});
|
|
11643
|
+
const abis = {};
|
|
11644
|
+
if (opts === null || opts === void 0 ? void 0 : opts.sendAbis) {
|
|
11645
|
+
const contractId = utils_1.encodeBase58(this.id);
|
|
11646
|
+
abis[contractId] = this.abi;
|
|
11647
|
+
}
|
|
11648
|
+
const transactionResponse = await this.signer.sendTransaction(transaction, abis);
|
|
11649
|
+
return { operation, transaction, transactionResponse };
|
|
11650
|
+
};
|
|
11651
|
+
});
|
|
11652
|
+
}
|
|
11653
|
+
}
|
|
11654
|
+
/**
|
|
11655
|
+
* Compute contract Id
|
|
11656
|
+
*/
|
|
11657
|
+
static computeContractId(address) {
|
|
11658
|
+
return utils_1.decodeBase58(address);
|
|
11659
|
+
}
|
|
11660
|
+
/**
|
|
11661
|
+
* Get contract Id
|
|
11662
|
+
*/
|
|
11663
|
+
getId() {
|
|
11664
|
+
if (!this.id)
|
|
11665
|
+
throw new Error("id is not defined");
|
|
11666
|
+
return utils_1.encodeBase58(this.id);
|
|
11667
|
+
}
|
|
11668
|
+
/**
|
|
11669
|
+
* Function to deploy a new smart contract.
|
|
11670
|
+
* The Bytecode must be defined in the constructor of the class
|
|
11671
|
+
* @example
|
|
11672
|
+
* ```ts
|
|
11673
|
+
* const privateKey = "f186a5de49797bfd52dc42505c33d75a46822ed5b60046e09d7c336242e20200";
|
|
11674
|
+
* const provider = new Provider(["http://api.koinos.io:8080"]);
|
|
11675
|
+
* const signer = new Signer({ privateKey, provider });
|
|
11676
|
+
* const bytecode = new Uint8Array([1, 2, 3, 4]);
|
|
11677
|
+
* const contract = new Contract({ signer, provider, bytecode });
|
|
11678
|
+
* const { transactionResponse } = await contract.deploy();
|
|
11679
|
+
* // wait to be mined
|
|
11680
|
+
* const blockId = await transactionResponse.wait();
|
|
11681
|
+
* console.log(`Contract uploaded in block id ${blockId}`);
|
|
11682
|
+
* ```
|
|
11683
|
+
*/
|
|
11684
|
+
async deploy(options) {
|
|
11685
|
+
if (!this.signer)
|
|
11686
|
+
throw new Error("signer not found");
|
|
11687
|
+
if (!this.bytecode)
|
|
11688
|
+
throw new Error("bytecode not found");
|
|
11689
|
+
const opts = {
|
|
11690
|
+
...this.options,
|
|
11691
|
+
...options,
|
|
11692
|
+
};
|
|
11693
|
+
const operation = {
|
|
11694
|
+
upload_contract: {
|
|
11695
|
+
contract_id: Contract.computeContractId(this.signer.getAddress()),
|
|
11696
|
+
bytecode: this.bytecode,
|
|
11697
|
+
},
|
|
11698
|
+
};
|
|
11699
|
+
// return operation if send is false
|
|
11700
|
+
if (!(opts === null || opts === void 0 ? void 0 : opts.sendTransaction))
|
|
11701
|
+
return { operation };
|
|
11702
|
+
const transaction = await this.signer.encodeTransaction({
|
|
11703
|
+
...opts,
|
|
11704
|
+
operations: [operation],
|
|
11705
|
+
});
|
|
11706
|
+
const transactionResponse = await this.signer.sendTransaction(transaction);
|
|
11707
|
+
return { operation, transaction, transactionResponse };
|
|
11708
|
+
}
|
|
11709
|
+
/**
|
|
11710
|
+
* Encondes a contract operation using Koinos serialization
|
|
11711
|
+
* and taking the contract entries as reference to build it
|
|
11712
|
+
* @param op - Operation to encode
|
|
11713
|
+
* @returns Operation encoded
|
|
11714
|
+
* @example
|
|
11715
|
+
* ```ts
|
|
11716
|
+
* const opEncoded = contract.encodeOperation({
|
|
11717
|
+
* name: "transfer",
|
|
11718
|
+
* args: {
|
|
11719
|
+
* from: "12fN2CQnuJM8cMnWZ1hPtM4knjLME8E4PD",
|
|
11720
|
+
* to: "172AB1FgCsYrRAW5cwQ8KjadgxofvgPFd6",
|
|
11721
|
+
* value: "1000",
|
|
11722
|
+
* }
|
|
11723
|
+
* });
|
|
11724
|
+
*
|
|
11725
|
+
* console.log(opEncoded);
|
|
11726
|
+
* // {
|
|
11727
|
+
* // call_contract: {
|
|
11728
|
+
* // contract_id: "19JntSm8pSNETT9aHTwAUHC5RMoaSmgZPJ",
|
|
11729
|
+
* // entry_point: 0x62efa292,
|
|
11730
|
+
* // args: "MBWFsaWNlA2JvYgAAAAAAAAPo",
|
|
11731
|
+
* // }
|
|
11732
|
+
* // }
|
|
11733
|
+
* ```
|
|
11734
|
+
*/
|
|
11735
|
+
async encodeOperation(op) {
|
|
11736
|
+
if (!this.abi || !this.abi.methods || !this.abi.methods[op.name])
|
|
11737
|
+
throw new Error(`Operation ${op.name} unknown`);
|
|
11738
|
+
if (!this.serializer)
|
|
11739
|
+
throw new Error("Serializer is not defined");
|
|
11740
|
+
if (!this.id)
|
|
11741
|
+
throw new Error("Contract id is not defined");
|
|
11742
|
+
const method = this.abi.methods[op.name];
|
|
11743
|
+
let bufferInputs = new Uint8Array(0);
|
|
11744
|
+
if (method.input) {
|
|
11745
|
+
if (!op.args)
|
|
11746
|
+
throw new Error(`No arguments defined for type '${method.input}'`);
|
|
11747
|
+
bufferInputs = await this.serializer.serialize(op.args, method.input);
|
|
11748
|
+
}
|
|
11749
|
+
return {
|
|
11750
|
+
call_contract: {
|
|
11751
|
+
contract_id: this.id,
|
|
11752
|
+
entry_point: method.entryPoint,
|
|
11753
|
+
args: bufferInputs,
|
|
11754
|
+
},
|
|
11755
|
+
};
|
|
11756
|
+
}
|
|
11757
|
+
/**
|
|
11758
|
+
* Decodes a contract operation to be human readable
|
|
11759
|
+
* @example
|
|
11760
|
+
* ```ts
|
|
11761
|
+
* const opDecoded = contract.decodeOperation({
|
|
11762
|
+
* call_contract: {
|
|
11763
|
+
* contract_id: "19JntSm8pSNETT9aHTwAUHC5RMoaSmgZPJ",
|
|
11764
|
+
* entry_point: 0x62efa292,
|
|
11765
|
+
* args: "MBWFsaWNlA2JvYgAAAAAAAAPo",
|
|
11766
|
+
* }
|
|
11767
|
+
* });
|
|
11768
|
+
* console.log(opDecoded);
|
|
11769
|
+
* // {
|
|
11770
|
+
* // name: "transfer",
|
|
11771
|
+
* // args: {
|
|
11772
|
+
* // from: "12fN2CQnuJM8cMnWZ1hPtM4knjLME8E4PD",
|
|
11773
|
+
* // to: "172AB1FgCsYrRAW5cwQ8KjadgxofvgPFd6",
|
|
11774
|
+
* // value: "1000",
|
|
11775
|
+
* // },
|
|
11776
|
+
* // }
|
|
11777
|
+
* ```
|
|
11778
|
+
*/
|
|
11779
|
+
async decodeOperation(op) {
|
|
11780
|
+
if (!this.id)
|
|
11781
|
+
throw new Error("Contract id is not defined");
|
|
11782
|
+
if (!this.abi || !this.abi.methods)
|
|
11783
|
+
throw new Error("Methods are not defined");
|
|
11784
|
+
if (!this.serializer)
|
|
11785
|
+
throw new Error("Serializer is not defined");
|
|
11786
|
+
if (!op.call_contract)
|
|
11787
|
+
throw new Error("Operation is not CallContractOperation");
|
|
11788
|
+
if (op.call_contract.contract_id !== this.id)
|
|
11789
|
+
throw new Error(`Invalid contract id. Expected: ${utils_1.encodeBase58(this.id)}. Received: ${utils_1.encodeBase58(op.call_contract.contract_id)}`);
|
|
11790
|
+
for (let i = 0; i < Object.keys(this.abi.methods).length; i += 1) {
|
|
11791
|
+
const opName = Object.keys(this.abi.methods)[i];
|
|
11792
|
+
const method = this.abi.methods[opName];
|
|
11793
|
+
if (op.call_contract.entry_point === method.entryPoint) {
|
|
11794
|
+
if (!method.input)
|
|
11795
|
+
return { name: opName };
|
|
11796
|
+
return {
|
|
11797
|
+
name: opName,
|
|
11798
|
+
args: await this.serializer.deserialize(op.call_contract.args, method.input),
|
|
11799
|
+
};
|
|
11800
|
+
}
|
|
11801
|
+
}
|
|
11802
|
+
throw new Error(`Unknown method id ${op.call_contract.entry_point}`);
|
|
11803
|
+
}
|
|
11804
|
+
}
|
|
11805
|
+
exports.Contract = Contract;
|
|
11806
|
+
exports.default = Contract;
|
|
11894
11807
|
|
|
11895
11808
|
|
|
11896
11809
|
/***/ }),
|
|
@@ -11899,210 +11812,386 @@ exports.default = Contract;
|
|
|
11899
11812
|
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
|
11900
11813
|
|
|
11901
11814
|
"use strict";
|
|
11902
|
-
|
|
11903
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
11904
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11905
|
-
};
|
|
11906
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
11907
|
-
exports.Provider = void 0;
|
|
11908
|
-
const axios_1 = __importDefault(__webpack_require__(9669));
|
|
11909
|
-
async function sleep(ms) {
|
|
11910
|
-
return new Promise((r) => setTimeout(r, ms));
|
|
11911
|
-
}
|
|
11912
|
-
/**
|
|
11913
|
-
* Class to connect with the RPC node
|
|
11914
|
-
*/
|
|
11915
|
-
class Provider {
|
|
11916
|
-
/**
|
|
11917
|
-
*
|
|
11918
|
-
* @param rpcNodes - URL of the rpc node, or array of urls
|
|
11919
|
-
* to switch between them when someone is down
|
|
11920
|
-
* @example
|
|
11921
|
-
* ```ts
|
|
11922
|
-
* const provider = new Provider([
|
|
11923
|
-
* "http://45.56.104.152:8080",
|
|
11924
|
-
* "http://159.203.119.0:8080"
|
|
11925
|
-
* ]);
|
|
11926
|
-
* ```
|
|
11927
|
-
*/
|
|
11928
|
-
constructor(rpcNodes) {
|
|
11929
|
-
if (Array.isArray(rpcNodes))
|
|
11930
|
-
this.rpcNodes = rpcNodes;
|
|
11931
|
-
else
|
|
11932
|
-
this.rpcNodes = [rpcNodes];
|
|
11933
|
-
this.currentNodeId = 0;
|
|
11934
|
-
this.onError = () => false;
|
|
11935
|
-
}
|
|
11936
|
-
/**
|
|
11937
|
-
* Function to make jsonrpc requests to the RPC node
|
|
11938
|
-
* @param method - jsonrpc method
|
|
11939
|
-
* @param params - jsonrpc params
|
|
11940
|
-
* @returns Result of jsonrpc response
|
|
11941
|
-
*/
|
|
11942
|
-
async call(method, params) {
|
|
11943
|
-
let response = {
|
|
11944
|
-
data: {},
|
|
11945
|
-
status: 0,
|
|
11946
|
-
statusText: "",
|
|
11947
|
-
headers: {},
|
|
11948
|
-
config: {},
|
|
11949
|
-
};
|
|
11950
|
-
let success = false;
|
|
11951
|
-
/* eslint-disable no-await-in-loop */
|
|
11952
|
-
while (!success) {
|
|
11953
|
-
try {
|
|
11954
|
-
const data = {
|
|
11955
|
-
id: Math.round(Math.random() * 1000),
|
|
11956
|
-
jsonrpc: "2.0",
|
|
11957
|
-
method,
|
|
11958
|
-
params,
|
|
11959
|
-
};
|
|
11960
|
-
const url = this.rpcNodes[this.currentNodeId];
|
|
11961
|
-
// TODO: search conditional to enable fetch for Browser
|
|
11962
|
-
/* const response = await fetch(url, {
|
|
11963
|
-
method: "POST",
|
|
11964
|
-
body: JSON.stringify(data),
|
|
11965
|
-
});
|
|
11966
|
-
const json = await response.json();
|
|
11967
|
-
if (json.error && json.error.message) throw new Error(json.error.message);
|
|
11968
|
-
return json.result; */
|
|
11969
|
-
response = await axios_1.default.post(url, data, { validateStatus: (s) => s < 400 });
|
|
11970
|
-
success = true;
|
|
11971
|
-
}
|
|
11972
|
-
catch (e) {
|
|
11973
|
-
const currentNode = this.rpcNodes[this.currentNodeId];
|
|
11974
|
-
this.currentNodeId = (this.currentNodeId + 1) % this.rpcNodes.length;
|
|
11975
|
-
const newNode = this.rpcNodes[this.currentNodeId];
|
|
11976
|
-
const abort = this.onError(e, currentNode, newNode);
|
|
11977
|
-
if (abort)
|
|
11978
|
-
throw e;
|
|
11979
|
-
}
|
|
11980
|
-
}
|
|
11981
|
-
if (response.data.error)
|
|
11982
|
-
throw new Error(response.data.error
|
|
11983
|
-
return response.data.result;
|
|
11984
|
-
}
|
|
11985
|
-
/**
|
|
11986
|
-
* Function to call "chain.get_account_nonce" to return the number of
|
|
11987
|
-
* transactions for a particular account. This call is used
|
|
11988
|
-
* when creating new transactions.
|
|
11989
|
-
* @param account - account address
|
|
11990
|
-
* @returns Nonce
|
|
11991
|
-
*/
|
|
11992
|
-
async getNonce(account) {
|
|
11993
|
-
const { nonce } = await this.call("chain.get_account_nonce", { account });
|
|
11994
|
-
if (!nonce)
|
|
11995
|
-
return 0;
|
|
11996
|
-
return Number(nonce);
|
|
11997
|
-
}
|
|
11998
|
-
async getAccountRc(account) {
|
|
11999
|
-
const { rc } = await this.call("chain.get_account_rc", {
|
|
12000
|
-
account,
|
|
12001
|
-
});
|
|
12002
|
-
if (!rc)
|
|
12003
|
-
return "0";
|
|
12004
|
-
return rc;
|
|
12005
|
-
}
|
|
12006
|
-
/**
|
|
12007
|
-
* Get transactions by id and their corresponding block ids
|
|
12008
|
-
*/
|
|
12009
|
-
async getTransactionsById(transactionIds) {
|
|
12010
|
-
return this.call("transaction_store.get_transactions_by_id", {
|
|
12011
|
-
transaction_ids: transactionIds,
|
|
12012
|
-
});
|
|
12013
|
-
}
|
|
12014
|
-
async getBlocksById(blockIds) {
|
|
12015
|
-
return this.call("block_store.get_blocks_by_id", {
|
|
12016
|
-
block_id: blockIds,
|
|
12017
|
-
return_block: true,
|
|
12018
|
-
return_receipt: false,
|
|
12019
|
-
});
|
|
12020
|
-
}
|
|
12021
|
-
/**
|
|
12022
|
-
* Function to get info from the head block in the blockchain
|
|
12023
|
-
*/
|
|
12024
|
-
async getHeadInfo() {
|
|
12025
|
-
return this.call("chain.get_head_info", {});
|
|
12026
|
-
}
|
|
12027
|
-
/**
|
|
12028
|
-
* Function to get consecutive blocks in descending order
|
|
12029
|
-
* @param height - Starting block height
|
|
12030
|
-
* @param numBlocks - Number of blocks to fetch
|
|
12031
|
-
* @param idRef - Block ID reference to speed up searching blocks.
|
|
12032
|
-
* This ID must be from a greater block height. By default it
|
|
12033
|
-
* gets the ID from the block head.
|
|
12034
|
-
*/
|
|
12035
|
-
async getBlocks(height, numBlocks = 1, idRef) {
|
|
12036
|
-
let blockIdRef = idRef;
|
|
12037
|
-
if (!blockIdRef) {
|
|
12038
|
-
const head = await this.getHeadInfo();
|
|
12039
|
-
blockIdRef = head.head_topology.id;
|
|
12040
|
-
}
|
|
12041
|
-
return (await this.call("block_store.get_blocks_by_height", {
|
|
12042
|
-
head_block_id: blockIdRef,
|
|
12043
|
-
ancestor_start_height: height,
|
|
12044
|
-
num_blocks: numBlocks,
|
|
12045
|
-
return_block: true,
|
|
12046
|
-
return_receipt: false,
|
|
12047
|
-
})).block_items;
|
|
12048
|
-
}
|
|
12049
|
-
/**
|
|
12050
|
-
* Function to get a block by its height
|
|
12051
|
-
*/
|
|
12052
|
-
async getBlock(height) {
|
|
12053
|
-
return (await this.getBlocks(height, 1))[0];
|
|
12054
|
-
}
|
|
12055
|
-
/**
|
|
12056
|
-
* Function to call "chain.submit_transaction" to send a signed
|
|
12057
|
-
* transaction to the blockchain. It returns an object with the async
|
|
12058
|
-
* function "wait", which can be called to wait for the
|
|
12059
|
-
* transaction to be mined.
|
|
12060
|
-
* @param transaction - Signed transaction
|
|
12061
|
-
* @example
|
|
12062
|
-
* ```ts
|
|
12063
|
-
* const { transactionResponse } = await provider.sendTransaction({
|
|
12064
|
-
* id: "1220...",
|
|
12065
|
-
* active: "...",
|
|
12066
|
-
* signatureData: "...",
|
|
12067
|
-
* });
|
|
12068
|
-
* console.log("Transaction submitted to the mempool");
|
|
12069
|
-
* // wait to be mined
|
|
12070
|
-
* const blockId = await transactionResponse.wait();
|
|
12071
|
-
* console.log("Transaction mined")
|
|
12072
|
-
* ```
|
|
12073
|
-
*/
|
|
12074
|
-
async sendTransaction(transaction) {
|
|
12075
|
-
await this.call("chain.submit_transaction", { transaction });
|
|
12076
|
-
const startTime = Date.now() + 10000;
|
|
12077
|
-
return {
|
|
12078
|
-
wait: async () => {
|
|
12079
|
-
// sleep some seconds before it gets mined
|
|
12080
|
-
await sleep(startTime - Date.now() - 1000);
|
|
12081
|
-
for (let i = 0; i < 30; i += 1) {
|
|
12082
|
-
await sleep(1000);
|
|
12083
|
-
const { transactions } = await this.getTransactionsById([
|
|
12084
|
-
transaction.id,
|
|
12085
|
-
]);
|
|
12086
|
-
if (transactions &&
|
|
12087
|
-
transactions[0] &&
|
|
12088
|
-
transactions[0].containing_blocks)
|
|
12089
|
-
return transactions[0].containing_blocks[0];
|
|
12090
|
-
}
|
|
12091
|
-
throw new Error(`Transaction not mined after 40 seconds`);
|
|
12092
|
-
},
|
|
12093
|
-
};
|
|
12094
|
-
}
|
|
12095
|
-
/**
|
|
12096
|
-
* Function to call "chain.read_contract" to read a contract.
|
|
12097
|
-
* This function is used by [[Contract]] class when read methods
|
|
12098
|
-
* are invoked.
|
|
12099
|
-
*/
|
|
12100
|
-
async readContract(operation) {
|
|
12101
|
-
return this.call("chain.read_contract", operation);
|
|
12102
|
-
}
|
|
12103
|
-
}
|
|
12104
|
-
exports.Provider = Provider;
|
|
12105
|
-
exports.default = Provider;
|
|
11815
|
+
|
|
11816
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
11817
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11818
|
+
};
|
|
11819
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
11820
|
+
exports.Provider = void 0;
|
|
11821
|
+
const axios_1 = __importDefault(__webpack_require__(9669));
|
|
11822
|
+
async function sleep(ms) {
|
|
11823
|
+
return new Promise((r) => setTimeout(r, ms));
|
|
11824
|
+
}
|
|
11825
|
+
/**
|
|
11826
|
+
* Class to connect with the RPC node
|
|
11827
|
+
*/
|
|
11828
|
+
class Provider {
|
|
11829
|
+
/**
|
|
11830
|
+
*
|
|
11831
|
+
* @param rpcNodes - URL of the rpc node, or array of urls
|
|
11832
|
+
* to switch between them when someone is down
|
|
11833
|
+
* @example
|
|
11834
|
+
* ```ts
|
|
11835
|
+
* const provider = new Provider([
|
|
11836
|
+
* "http://45.56.104.152:8080",
|
|
11837
|
+
* "http://159.203.119.0:8080"
|
|
11838
|
+
* ]);
|
|
11839
|
+
* ```
|
|
11840
|
+
*/
|
|
11841
|
+
constructor(rpcNodes) {
|
|
11842
|
+
if (Array.isArray(rpcNodes))
|
|
11843
|
+
this.rpcNodes = rpcNodes;
|
|
11844
|
+
else
|
|
11845
|
+
this.rpcNodes = [rpcNodes];
|
|
11846
|
+
this.currentNodeId = 0;
|
|
11847
|
+
this.onError = () => false;
|
|
11848
|
+
}
|
|
11849
|
+
/**
|
|
11850
|
+
* Function to make jsonrpc requests to the RPC node
|
|
11851
|
+
* @param method - jsonrpc method
|
|
11852
|
+
* @param params - jsonrpc params
|
|
11853
|
+
* @returns Result of jsonrpc response
|
|
11854
|
+
*/
|
|
11855
|
+
async call(method, params) {
|
|
11856
|
+
let response = {
|
|
11857
|
+
data: {},
|
|
11858
|
+
status: 0,
|
|
11859
|
+
statusText: "",
|
|
11860
|
+
headers: {},
|
|
11861
|
+
config: {},
|
|
11862
|
+
};
|
|
11863
|
+
let success = false;
|
|
11864
|
+
/* eslint-disable no-await-in-loop */
|
|
11865
|
+
while (!success) {
|
|
11866
|
+
try {
|
|
11867
|
+
const data = {
|
|
11868
|
+
id: Math.round(Math.random() * 1000),
|
|
11869
|
+
jsonrpc: "2.0",
|
|
11870
|
+
method,
|
|
11871
|
+
params,
|
|
11872
|
+
};
|
|
11873
|
+
const url = this.rpcNodes[this.currentNodeId];
|
|
11874
|
+
// TODO: search conditional to enable fetch for Browser
|
|
11875
|
+
/* const response = await fetch(url, {
|
|
11876
|
+
method: "POST",
|
|
11877
|
+
body: JSON.stringify(data),
|
|
11878
|
+
});
|
|
11879
|
+
const json = await response.json();
|
|
11880
|
+
if (json.error && json.error.message) throw new Error(json.error.message);
|
|
11881
|
+
return json.result; */
|
|
11882
|
+
response = await axios_1.default.post(url, data, { validateStatus: (s) => s < 400 });
|
|
11883
|
+
success = true;
|
|
11884
|
+
}
|
|
11885
|
+
catch (e) {
|
|
11886
|
+
const currentNode = this.rpcNodes[this.currentNodeId];
|
|
11887
|
+
this.currentNodeId = (this.currentNodeId + 1) % this.rpcNodes.length;
|
|
11888
|
+
const newNode = this.rpcNodes[this.currentNodeId];
|
|
11889
|
+
const abort = this.onError(e, currentNode, newNode);
|
|
11890
|
+
if (abort)
|
|
11891
|
+
throw e;
|
|
11892
|
+
}
|
|
11893
|
+
}
|
|
11894
|
+
if (response.data.error)
|
|
11895
|
+
throw new Error(JSON.stringify(response.data.error));
|
|
11896
|
+
return response.data.result;
|
|
11897
|
+
}
|
|
11898
|
+
/**
|
|
11899
|
+
* Function to call "chain.get_account_nonce" to return the number of
|
|
11900
|
+
* transactions for a particular account. This call is used
|
|
11901
|
+
* when creating new transactions.
|
|
11902
|
+
* @param account - account address
|
|
11903
|
+
* @returns Nonce
|
|
11904
|
+
*/
|
|
11905
|
+
async getNonce(account) {
|
|
11906
|
+
const { nonce } = await this.call("chain.get_account_nonce", { account });
|
|
11907
|
+
if (!nonce)
|
|
11908
|
+
return 0;
|
|
11909
|
+
return Number(nonce);
|
|
11910
|
+
}
|
|
11911
|
+
async getAccountRc(account) {
|
|
11912
|
+
const { rc } = await this.call("chain.get_account_rc", {
|
|
11913
|
+
account,
|
|
11914
|
+
});
|
|
11915
|
+
if (!rc)
|
|
11916
|
+
return "0";
|
|
11917
|
+
return rc;
|
|
11918
|
+
}
|
|
11919
|
+
/**
|
|
11920
|
+
* Get transactions by id and their corresponding block ids
|
|
11921
|
+
*/
|
|
11922
|
+
async getTransactionsById(transactionIds) {
|
|
11923
|
+
return this.call("transaction_store.get_transactions_by_id", {
|
|
11924
|
+
transaction_ids: transactionIds,
|
|
11925
|
+
});
|
|
11926
|
+
}
|
|
11927
|
+
async getBlocksById(blockIds) {
|
|
11928
|
+
return this.call("block_store.get_blocks_by_id", {
|
|
11929
|
+
block_id: blockIds,
|
|
11930
|
+
return_block: true,
|
|
11931
|
+
return_receipt: false,
|
|
11932
|
+
});
|
|
11933
|
+
}
|
|
11934
|
+
/**
|
|
11935
|
+
* Function to get info from the head block in the blockchain
|
|
11936
|
+
*/
|
|
11937
|
+
async getHeadInfo() {
|
|
11938
|
+
return this.call("chain.get_head_info", {});
|
|
11939
|
+
}
|
|
11940
|
+
/**
|
|
11941
|
+
* Function to get consecutive blocks in descending order
|
|
11942
|
+
* @param height - Starting block height
|
|
11943
|
+
* @param numBlocks - Number of blocks to fetch
|
|
11944
|
+
* @param idRef - Block ID reference to speed up searching blocks.
|
|
11945
|
+
* This ID must be from a greater block height. By default it
|
|
11946
|
+
* gets the ID from the block head.
|
|
11947
|
+
*/
|
|
11948
|
+
async getBlocks(height, numBlocks = 1, idRef) {
|
|
11949
|
+
let blockIdRef = idRef;
|
|
11950
|
+
if (!blockIdRef) {
|
|
11951
|
+
const head = await this.getHeadInfo();
|
|
11952
|
+
blockIdRef = head.head_topology.id;
|
|
11953
|
+
}
|
|
11954
|
+
return (await this.call("block_store.get_blocks_by_height", {
|
|
11955
|
+
head_block_id: blockIdRef,
|
|
11956
|
+
ancestor_start_height: height,
|
|
11957
|
+
num_blocks: numBlocks,
|
|
11958
|
+
return_block: true,
|
|
11959
|
+
return_receipt: false,
|
|
11960
|
+
})).block_items;
|
|
11961
|
+
}
|
|
11962
|
+
/**
|
|
11963
|
+
* Function to get a block by its height
|
|
11964
|
+
*/
|
|
11965
|
+
async getBlock(height) {
|
|
11966
|
+
return (await this.getBlocks(height, 1))[0];
|
|
11967
|
+
}
|
|
11968
|
+
/**
|
|
11969
|
+
* Function to call "chain.submit_transaction" to send a signed
|
|
11970
|
+
* transaction to the blockchain. It returns an object with the async
|
|
11971
|
+
* function "wait", which can be called to wait for the
|
|
11972
|
+
* transaction to be mined.
|
|
11973
|
+
* @param transaction - Signed transaction
|
|
11974
|
+
* @example
|
|
11975
|
+
* ```ts
|
|
11976
|
+
* const { transactionResponse } = await provider.sendTransaction({
|
|
11977
|
+
* id: "1220...",
|
|
11978
|
+
* active: "...",
|
|
11979
|
+
* signatureData: "...",
|
|
11980
|
+
* });
|
|
11981
|
+
* console.log("Transaction submitted to the mempool");
|
|
11982
|
+
* // wait to be mined
|
|
11983
|
+
* const blockId = await transactionResponse.wait();
|
|
11984
|
+
* console.log("Transaction mined")
|
|
11985
|
+
* ```
|
|
11986
|
+
*/
|
|
11987
|
+
async sendTransaction(transaction) {
|
|
11988
|
+
await this.call("chain.submit_transaction", { transaction });
|
|
11989
|
+
const startTime = Date.now() + 10000;
|
|
11990
|
+
return {
|
|
11991
|
+
wait: async () => {
|
|
11992
|
+
// sleep some seconds before it gets mined
|
|
11993
|
+
await sleep(startTime - Date.now() - 1000);
|
|
11994
|
+
for (let i = 0; i < 30; i += 1) {
|
|
11995
|
+
await sleep(1000);
|
|
11996
|
+
const { transactions } = await this.getTransactionsById([
|
|
11997
|
+
transaction.id,
|
|
11998
|
+
]);
|
|
11999
|
+
if (transactions &&
|
|
12000
|
+
transactions[0] &&
|
|
12001
|
+
transactions[0].containing_blocks)
|
|
12002
|
+
return transactions[0].containing_blocks[0];
|
|
12003
|
+
}
|
|
12004
|
+
throw new Error(`Transaction not mined after 40 seconds`);
|
|
12005
|
+
},
|
|
12006
|
+
};
|
|
12007
|
+
}
|
|
12008
|
+
/**
|
|
12009
|
+
* Function to call "chain.read_contract" to read a contract.
|
|
12010
|
+
* This function is used by [[Contract]] class when read methods
|
|
12011
|
+
* are invoked.
|
|
12012
|
+
*/
|
|
12013
|
+
async readContract(operation) {
|
|
12014
|
+
return this.call("chain.read_contract", operation);
|
|
12015
|
+
}
|
|
12016
|
+
}
|
|
12017
|
+
exports.Provider = Provider;
|
|
12018
|
+
exports.default = Provider;
|
|
12019
|
+
|
|
12020
|
+
|
|
12021
|
+
/***/ }),
|
|
12022
|
+
|
|
12023
|
+
/***/ 7187:
|
|
12024
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
12025
|
+
|
|
12026
|
+
"use strict";
|
|
12027
|
+
|
|
12028
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
12029
|
+
exports.Serializer = void 0;
|
|
12030
|
+
/* eslint-disable @typescript-eslint/require-await */
|
|
12031
|
+
const light_1 = __webpack_require__(4492);
|
|
12032
|
+
const utils_1 = __webpack_require__(8593);
|
|
12033
|
+
const OP_BYTES = "(koinos_bytes_type)";
|
|
12034
|
+
/**
|
|
12035
|
+
* Makes a copy of a value. The returned value can be modified
|
|
12036
|
+
* without altering the original one. Although this is not needed
|
|
12037
|
+
* for strings or numbers and only needed for objects and arrays,
|
|
12038
|
+
* all these options are covered in a single function
|
|
12039
|
+
*
|
|
12040
|
+
* It is assumed that the argument is number, string, or contructions
|
|
12041
|
+
* of these types inside objects or arrays.
|
|
12042
|
+
*/
|
|
12043
|
+
function copyValue(value) {
|
|
12044
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
12045
|
+
return value;
|
|
12046
|
+
}
|
|
12047
|
+
return JSON.parse(JSON.stringify(value));
|
|
12048
|
+
}
|
|
12049
|
+
/**
|
|
12050
|
+
* The serializer class serialize and deserialize data using
|
|
12051
|
+
* protocol buffers.
|
|
12052
|
+
*
|
|
12053
|
+
* NOTE: This class uses the [protobufjs/light](https://www.npmjs.com/package/protobufjs)
|
|
12054
|
+
* library internally, which uses reflection (use of _eval_
|
|
12055
|
+
* and _new Function_) for the construction of the types.
|
|
12056
|
+
* This could cause issues in environments where _eval_ is not
|
|
12057
|
+
* allowed, like in browser extensions. In such cases, this class
|
|
12058
|
+
* must be confined in a [sandbox environment](https://developer.chrome.com/docs/apps/app_external/#sandboxing)
|
|
12059
|
+
* where _eval_ is allowed. This is the principal reason of
|
|
12060
|
+
* having the serializer in a separate class.
|
|
12061
|
+
*
|
|
12062
|
+
* @example
|
|
12063
|
+
*
|
|
12064
|
+
* ```ts
|
|
12065
|
+
* const descriptorJson = {
|
|
12066
|
+
* nested: {
|
|
12067
|
+
* awesomepackage: {
|
|
12068
|
+
* nested: {
|
|
12069
|
+
* AwesomeMessage: {
|
|
12070
|
+
* fields: {
|
|
12071
|
+
* awesomeField: {
|
|
12072
|
+
* type: "string",
|
|
12073
|
+
* id: 1
|
|
12074
|
+
* }
|
|
12075
|
+
* }
|
|
12076
|
+
* }
|
|
12077
|
+
* }
|
|
12078
|
+
* }
|
|
12079
|
+
* }
|
|
12080
|
+
* }
|
|
12081
|
+
* const serializer = new Serializer(descriptorJson)
|
|
12082
|
+
* ```
|
|
12083
|
+
*/
|
|
12084
|
+
class Serializer {
|
|
12085
|
+
constructor(types, opts) {
|
|
12086
|
+
/**
|
|
12087
|
+
* Preformat bytes for base64, base58 or hex string
|
|
12088
|
+
*/
|
|
12089
|
+
this.bytesConversion = true;
|
|
12090
|
+
this.types = types;
|
|
12091
|
+
this.root = light_1.Root.fromJSON(this.types);
|
|
12092
|
+
if (opts === null || opts === void 0 ? void 0 : opts.defaultTypeName)
|
|
12093
|
+
this.defaultType = this.root.lookupType(opts.defaultTypeName);
|
|
12094
|
+
if (opts && typeof opts.bytesConversion !== "undefined")
|
|
12095
|
+
this.bytesConversion = opts.bytesConversion;
|
|
12096
|
+
}
|
|
12097
|
+
/**
|
|
12098
|
+
* Function to encode a type using the protobuffer definitions
|
|
12099
|
+
* It also prepares the bytes for special cases (base58, hex string)
|
|
12100
|
+
* when bytesConversion param is true.
|
|
12101
|
+
*/
|
|
12102
|
+
async serialize(valueDecoded, typeName) {
|
|
12103
|
+
const protobufType = this.defaultType || this.root.lookupType(typeName);
|
|
12104
|
+
let object = {};
|
|
12105
|
+
if (this.bytesConversion) {
|
|
12106
|
+
// TODO: format from Buffer to base58/base64 for nested fields
|
|
12107
|
+
Object.keys(protobufType.fields).forEach((fieldName) => {
|
|
12108
|
+
const { options, name, type } = protobufType.fields[fieldName];
|
|
12109
|
+
// No byte conversion
|
|
12110
|
+
if (type !== "bytes") {
|
|
12111
|
+
object[name] = copyValue(valueDecoded[name]);
|
|
12112
|
+
return;
|
|
12113
|
+
}
|
|
12114
|
+
// Default byte conversion
|
|
12115
|
+
if (!options || !options[OP_BYTES]) {
|
|
12116
|
+
object[name] = utils_1.decodeBase64(valueDecoded[name]);
|
|
12117
|
+
return;
|
|
12118
|
+
}
|
|
12119
|
+
// Specific byte conversion
|
|
12120
|
+
switch (options[OP_BYTES]) {
|
|
12121
|
+
case "BASE58":
|
|
12122
|
+
case "CONTRACT_ID":
|
|
12123
|
+
case "ADDRESS":
|
|
12124
|
+
object[name] = utils_1.decodeBase58(valueDecoded[name]);
|
|
12125
|
+
break;
|
|
12126
|
+
case "BASE64":
|
|
12127
|
+
object[name] = utils_1.decodeBase64(valueDecoded[name]);
|
|
12128
|
+
break;
|
|
12129
|
+
case "HEX":
|
|
12130
|
+
case "BLOCK_ID":
|
|
12131
|
+
case "TRANSACTION_ID":
|
|
12132
|
+
object[name] = utils_1.toUint8Array(valueDecoded[name].replace("0x", ""));
|
|
12133
|
+
break;
|
|
12134
|
+
default:
|
|
12135
|
+
throw new Error(`unknown koinos_byte_type ${options[OP_BYTES]}`);
|
|
12136
|
+
}
|
|
12137
|
+
});
|
|
12138
|
+
}
|
|
12139
|
+
else {
|
|
12140
|
+
object = valueDecoded;
|
|
12141
|
+
}
|
|
12142
|
+
const message = protobufType.create(object);
|
|
12143
|
+
const buffer = protobufType.encode(message).finish();
|
|
12144
|
+
return buffer;
|
|
12145
|
+
}
|
|
12146
|
+
/**
|
|
12147
|
+
* Function to decode bytes using the protobuffer definitions
|
|
12148
|
+
* It also encodes the bytes for special cases (base58, hex string)
|
|
12149
|
+
* when bytesConversion param is true.
|
|
12150
|
+
*/
|
|
12151
|
+
async deserialize(valueEncoded, typeName) {
|
|
12152
|
+
const valueBuffer = typeof valueEncoded === "string"
|
|
12153
|
+
? utils_1.decodeBase64(valueEncoded)
|
|
12154
|
+
: valueEncoded;
|
|
12155
|
+
const protobufType = this.defaultType || this.root.lookupType(typeName);
|
|
12156
|
+
const message = protobufType.decode(valueBuffer);
|
|
12157
|
+
const object = protobufType.toObject(message, { longs: String });
|
|
12158
|
+
if (!this.bytesConversion)
|
|
12159
|
+
return object;
|
|
12160
|
+
// TODO: format from Buffer to base58/base64 for nested fields
|
|
12161
|
+
Object.keys(protobufType.fields).forEach((fieldName) => {
|
|
12162
|
+
const { options, name, type } = protobufType.fields[fieldName];
|
|
12163
|
+
// No byte conversion
|
|
12164
|
+
if (type !== "bytes")
|
|
12165
|
+
return;
|
|
12166
|
+
// Default byte conversion
|
|
12167
|
+
if (!options || !options[OP_BYTES]) {
|
|
12168
|
+
object[name] = utils_1.encodeBase64(object[name]);
|
|
12169
|
+
return;
|
|
12170
|
+
}
|
|
12171
|
+
// Specific byte conversion
|
|
12172
|
+
switch (options[OP_BYTES]) {
|
|
12173
|
+
case "BASE58":
|
|
12174
|
+
case "CONTRACT_ID":
|
|
12175
|
+
case "ADDRESS":
|
|
12176
|
+
object[name] = utils_1.encodeBase58(object[name]);
|
|
12177
|
+
break;
|
|
12178
|
+
case "BASE64":
|
|
12179
|
+
object[name] = utils_1.encodeBase64(object[name]);
|
|
12180
|
+
break;
|
|
12181
|
+
case "HEX":
|
|
12182
|
+
case "BLOCK_ID":
|
|
12183
|
+
case "TRANSACTION_ID":
|
|
12184
|
+
object[name] = `0x${utils_1.toHexString(object[name])}`;
|
|
12185
|
+
break;
|
|
12186
|
+
default:
|
|
12187
|
+
throw new Error(`unknown koinos_byte_type ${options[OP_BYTES]}`);
|
|
12188
|
+
}
|
|
12189
|
+
});
|
|
12190
|
+
return object;
|
|
12191
|
+
}
|
|
12192
|
+
}
|
|
12193
|
+
exports.Serializer = Serializer;
|
|
12194
|
+
exports.default = Serializer;
|
|
12106
12195
|
|
|
12107
12196
|
|
|
12108
12197
|
/***/ }),
|
|
@@ -12111,323 +12200,427 @@ exports.default = Provider;
|
|
|
12111
12200
|
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
|
12112
12201
|
|
|
12113
12202
|
"use strict";
|
|
12114
|
-
|
|
12115
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
12116
|
-
if (k2 === undefined) k2 = k;
|
|
12117
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
12118
|
-
}) : (function(o, m, k, k2) {
|
|
12119
|
-
if (k2 === undefined) k2 = k;
|
|
12120
|
-
o[k2] = m[k];
|
|
12121
|
-
}));
|
|
12122
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
12123
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
12124
|
-
}) : function(o, v) {
|
|
12125
|
-
o["default"] = v;
|
|
12126
|
-
});
|
|
12127
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
12128
|
-
if (mod && mod.__esModule) return mod;
|
|
12129
|
-
var result = {};
|
|
12130
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
12131
|
-
__setModuleDefault(result, mod);
|
|
12132
|
-
return result;
|
|
12133
|
-
};
|
|
12134
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12135
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12136
|
-
};
|
|
12137
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
12138
|
-
exports.Signer = void 0;
|
|
12139
|
-
/* eslint-disable no-param-reassign */
|
|
12140
|
-
const js_sha256_1 = __webpack_require__(2023);
|
|
12141
|
-
const secp = __importStar(__webpack_require__(1795));
|
|
12142
|
-
const
|
|
12143
|
-
const
|
|
12144
|
-
const
|
|
12145
|
-
|
|
12146
|
-
|
|
12147
|
-
|
|
12148
|
-
*
|
|
12149
|
-
*
|
|
12150
|
-
*
|
|
12151
|
-
*
|
|
12152
|
-
*
|
|
12153
|
-
*
|
|
12154
|
-
*
|
|
12155
|
-
*
|
|
12156
|
-
*
|
|
12157
|
-
*
|
|
12158
|
-
*
|
|
12159
|
-
*
|
|
12160
|
-
*
|
|
12161
|
-
*
|
|
12162
|
-
*
|
|
12163
|
-
*
|
|
12164
|
-
*
|
|
12165
|
-
*
|
|
12166
|
-
*
|
|
12167
|
-
*
|
|
12168
|
-
*
|
|
12169
|
-
*
|
|
12170
|
-
*
|
|
12171
|
-
*
|
|
12172
|
-
*
|
|
12173
|
-
* var signer = new Signer(
|
|
12174
|
-
* ```
|
|
12175
|
-
*
|
|
12176
|
-
* <br>
|
|
12177
|
-
*
|
|
12178
|
-
* using the seed
|
|
12179
|
-
* ```ts
|
|
12180
|
-
* var signer = Signer.fromSeed("my seed");
|
|
12181
|
-
* ```
|
|
12182
|
-
*
|
|
12183
|
-
* <br>
|
|
12184
|
-
*
|
|
12185
|
-
* using private key in WIF format
|
|
12186
|
-
* ```ts
|
|
12187
|
-
* var signer = Signer.fromWif("L59UtJcTdNBnrH2QSBA5beSUhRufRu3g6tScDTite6Msuj7U93tM");
|
|
12188
|
-
* ```
|
|
12189
|
-
*
|
|
12190
|
-
* <br>
|
|
12191
|
-
*
|
|
12192
|
-
* defining a provider
|
|
12193
|
-
* ```ts
|
|
12194
|
-
* var provider = new Provider(["https://example.com/jsonrpc"]);
|
|
12195
|
-
* var
|
|
12196
|
-
*
|
|
12197
|
-
|
|
12198
|
-
|
|
12199
|
-
|
|
12200
|
-
|
|
12201
|
-
*
|
|
12202
|
-
*
|
|
12203
|
-
*
|
|
12204
|
-
*
|
|
12205
|
-
* @param
|
|
12206
|
-
* @param
|
|
12207
|
-
* @
|
|
12208
|
-
*
|
|
12209
|
-
*
|
|
12210
|
-
*
|
|
12211
|
-
*
|
|
12212
|
-
*
|
|
12213
|
-
|
|
12214
|
-
|
|
12215
|
-
|
|
12216
|
-
|
|
12217
|
-
this.
|
|
12218
|
-
|
|
12219
|
-
|
|
12220
|
-
|
|
12221
|
-
|
|
12222
|
-
|
|
12223
|
-
|
|
12224
|
-
this.
|
|
12225
|
-
|
|
12226
|
-
|
|
12227
|
-
|
|
12228
|
-
|
|
12229
|
-
|
|
12230
|
-
|
|
12231
|
-
|
|
12232
|
-
|
|
12233
|
-
|
|
12234
|
-
|
|
12235
|
-
|
|
12236
|
-
|
|
12237
|
-
|
|
12238
|
-
|
|
12239
|
-
|
|
12240
|
-
|
|
12241
|
-
|
|
12242
|
-
|
|
12243
|
-
|
|
12244
|
-
*
|
|
12245
|
-
*
|
|
12246
|
-
*
|
|
12247
|
-
* @
|
|
12248
|
-
|
|
12249
|
-
|
|
12250
|
-
|
|
12251
|
-
|
|
12252
|
-
|
|
12253
|
-
|
|
12254
|
-
|
|
12255
|
-
|
|
12256
|
-
|
|
12257
|
-
|
|
12258
|
-
|
|
12259
|
-
|
|
12260
|
-
* @param compressed -
|
|
12261
|
-
*
|
|
12262
|
-
*
|
|
12263
|
-
|
|
12264
|
-
|
|
12265
|
-
|
|
12266
|
-
|
|
12267
|
-
|
|
12268
|
-
|
|
12269
|
-
|
|
12270
|
-
|
|
12271
|
-
|
|
12272
|
-
|
|
12273
|
-
|
|
12274
|
-
* @param
|
|
12275
|
-
*
|
|
12276
|
-
*
|
|
12277
|
-
|
|
12278
|
-
|
|
12279
|
-
|
|
12280
|
-
|
|
12281
|
-
|
|
12282
|
-
|
|
12283
|
-
|
|
12284
|
-
|
|
12285
|
-
|
|
12286
|
-
|
|
12287
|
-
*
|
|
12288
|
-
*
|
|
12289
|
-
|
|
12290
|
-
|
|
12291
|
-
|
|
12292
|
-
|
|
12293
|
-
|
|
12294
|
-
|
|
12295
|
-
|
|
12296
|
-
|
|
12297
|
-
|
|
12298
|
-
|
|
12299
|
-
|
|
12300
|
-
|
|
12301
|
-
|
|
12302
|
-
|
|
12303
|
-
|
|
12304
|
-
|
|
12305
|
-
|
|
12306
|
-
|
|
12307
|
-
|
|
12308
|
-
|
|
12309
|
-
|
|
12310
|
-
|
|
12311
|
-
|
|
12312
|
-
|
|
12313
|
-
|
|
12314
|
-
|
|
12315
|
-
|
|
12316
|
-
|
|
12317
|
-
|
|
12318
|
-
|
|
12319
|
-
|
|
12320
|
-
|
|
12321
|
-
|
|
12322
|
-
|
|
12323
|
-
|
|
12324
|
-
|
|
12325
|
-
|
|
12326
|
-
|
|
12327
|
-
|
|
12328
|
-
|
|
12329
|
-
|
|
12330
|
-
|
|
12331
|
-
|
|
12332
|
-
|
|
12333
|
-
tx.
|
|
12334
|
-
|
|
12335
|
-
|
|
12336
|
-
|
|
12337
|
-
|
|
12338
|
-
|
|
12339
|
-
|
|
12340
|
-
|
|
12341
|
-
|
|
12342
|
-
|
|
12343
|
-
|
|
12344
|
-
|
|
12345
|
-
|
|
12346
|
-
|
|
12347
|
-
|
|
12348
|
-
|
|
12349
|
-
|
|
12350
|
-
|
|
12351
|
-
|
|
12352
|
-
|
|
12353
|
-
*
|
|
12354
|
-
*
|
|
12355
|
-
* @param
|
|
12356
|
-
*
|
|
12357
|
-
|
|
12358
|
-
|
|
12359
|
-
|
|
12360
|
-
|
|
12361
|
-
|
|
12362
|
-
|
|
12363
|
-
|
|
12364
|
-
|
|
12365
|
-
|
|
12366
|
-
|
|
12367
|
-
|
|
12368
|
-
|
|
12369
|
-
|
|
12370
|
-
|
|
12371
|
-
|
|
12372
|
-
|
|
12373
|
-
|
|
12374
|
-
|
|
12375
|
-
|
|
12376
|
-
|
|
12377
|
-
|
|
12378
|
-
|
|
12379
|
-
*
|
|
12380
|
-
*
|
|
12381
|
-
*
|
|
12382
|
-
*
|
|
12383
|
-
|
|
12384
|
-
|
|
12385
|
-
|
|
12386
|
-
|
|
12387
|
-
|
|
12388
|
-
|
|
12389
|
-
*
|
|
12390
|
-
*
|
|
12391
|
-
*
|
|
12392
|
-
*
|
|
12393
|
-
*
|
|
12394
|
-
*
|
|
12395
|
-
|
|
12396
|
-
|
|
12397
|
-
|
|
12398
|
-
|
|
12399
|
-
|
|
12400
|
-
|
|
12401
|
-
|
|
12402
|
-
|
|
12403
|
-
|
|
12404
|
-
|
|
12405
|
-
|
|
12406
|
-
|
|
12407
|
-
|
|
12408
|
-
|
|
12409
|
-
|
|
12410
|
-
|
|
12411
|
-
|
|
12412
|
-
|
|
12413
|
-
|
|
12414
|
-
|
|
12415
|
-
|
|
12416
|
-
|
|
12417
|
-
|
|
12418
|
-
|
|
12419
|
-
|
|
12420
|
-
|
|
12421
|
-
|
|
12422
|
-
|
|
12423
|
-
|
|
12424
|
-
|
|
12425
|
-
|
|
12426
|
-
|
|
12427
|
-
|
|
12428
|
-
|
|
12429
|
-
|
|
12430
|
-
|
|
12203
|
+
|
|
12204
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
12205
|
+
if (k2 === undefined) k2 = k;
|
|
12206
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
12207
|
+
}) : (function(o, m, k, k2) {
|
|
12208
|
+
if (k2 === undefined) k2 = k;
|
|
12209
|
+
o[k2] = m[k];
|
|
12210
|
+
}));
|
|
12211
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
12212
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
12213
|
+
}) : function(o, v) {
|
|
12214
|
+
o["default"] = v;
|
|
12215
|
+
});
|
|
12216
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
12217
|
+
if (mod && mod.__esModule) return mod;
|
|
12218
|
+
var result = {};
|
|
12219
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
12220
|
+
__setModuleDefault(result, mod);
|
|
12221
|
+
return result;
|
|
12222
|
+
};
|
|
12223
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12224
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12225
|
+
};
|
|
12226
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
12227
|
+
exports.Signer = void 0;
|
|
12228
|
+
/* eslint-disable no-param-reassign */
|
|
12229
|
+
const js_sha256_1 = __webpack_require__(2023);
|
|
12230
|
+
const secp = __importStar(__webpack_require__(1795));
|
|
12231
|
+
const protocol_proto_json_1 = __importDefault(__webpack_require__(6139));
|
|
12232
|
+
const utils_1 = __webpack_require__(8593);
|
|
12233
|
+
const Serializer_1 = __webpack_require__(7187);
|
|
12234
|
+
/**
|
|
12235
|
+
* The Signer Class contains the private key needed to sign transactions.
|
|
12236
|
+
* It can be created using the seed, wif, or private key
|
|
12237
|
+
*
|
|
12238
|
+
* @example
|
|
12239
|
+
* using private key as hex string
|
|
12240
|
+
* ```ts
|
|
12241
|
+
* var privateKey = "ec8601a24f81decd57f4b611b5ac6eb801cb3780bb02c0f9cdfe9d09daaddf9c";
|
|
12242
|
+
* var signer = new Signer({ privateKey });
|
|
12243
|
+
* ```
|
|
12244
|
+
* <br>
|
|
12245
|
+
*
|
|
12246
|
+
* using private key as Uint8Array
|
|
12247
|
+
* ```ts
|
|
12248
|
+
* var buffer = new Uint8Array([
|
|
12249
|
+
* 236, 134, 1, 162, 79, 129, 222, 205,
|
|
12250
|
+
* 87, 244, 182, 17, 181, 172, 110, 184,
|
|
12251
|
+
* 1, 203, 55, 128, 187, 2, 192, 249,
|
|
12252
|
+
* 205, 254, 157, 9, 218, 173, 223, 156
|
|
12253
|
+
* ]);
|
|
12254
|
+
* var signer = new Signer({ privateKey: buffer });
|
|
12255
|
+
* ```
|
|
12256
|
+
*
|
|
12257
|
+
* <br>
|
|
12258
|
+
*
|
|
12259
|
+
* using private key as bigint
|
|
12260
|
+
* ```ts
|
|
12261
|
+
* var privateKey = 106982601049961974618234078204952280507266494766432547312316920283818886029212n;
|
|
12262
|
+
* var signer = new Signer({ privateKey });
|
|
12263
|
+
* ```
|
|
12264
|
+
*
|
|
12265
|
+
* <br>
|
|
12266
|
+
*
|
|
12267
|
+
* using the seed
|
|
12268
|
+
* ```ts
|
|
12269
|
+
* var signer = Signer.fromSeed("my seed");
|
|
12270
|
+
* ```
|
|
12271
|
+
*
|
|
12272
|
+
* <br>
|
|
12273
|
+
*
|
|
12274
|
+
* using private key in WIF format
|
|
12275
|
+
* ```ts
|
|
12276
|
+
* var signer = Signer.fromWif("L59UtJcTdNBnrH2QSBA5beSUhRufRu3g6tScDTite6Msuj7U93tM");
|
|
12277
|
+
* ```
|
|
12278
|
+
*
|
|
12279
|
+
* <br>
|
|
12280
|
+
*
|
|
12281
|
+
* defining a provider
|
|
12282
|
+
* ```ts
|
|
12283
|
+
* var provider = new Provider(["https://example.com/jsonrpc"]);
|
|
12284
|
+
* var privateKey = "ec8601a24f81decd57f4b611b5ac6eb801cb3780bb02c0f9cdfe9d09daaddf9c";
|
|
12285
|
+
* var signer = new Signer({ privateKey, provider });
|
|
12286
|
+
* ```
|
|
12287
|
+
*/
|
|
12288
|
+
class Signer {
|
|
12289
|
+
/**
|
|
12290
|
+
* The constructor receives de private key as hexstring, bigint or Uint8Array.
|
|
12291
|
+
* See also the functions [[Signer.fromWif]] and [[Signer.fromSeed]]
|
|
12292
|
+
* to create the signer from the WIF or Seed respectively.
|
|
12293
|
+
*
|
|
12294
|
+
* @param privateKey - Private key as hexstring, bigint or Uint8Array
|
|
12295
|
+
* @param compressed - compressed format is true by default
|
|
12296
|
+
* @param provider - provider to connect with the blockchain
|
|
12297
|
+
* @example
|
|
12298
|
+
* ```ts
|
|
12299
|
+
* const privateKey = "ec8601a24f81decd57f4b611b5ac6eb801cb3780bb02c0f9cdfe9d09daaddf9c";
|
|
12300
|
+
* cons signer = new Signer({ privateKey });
|
|
12301
|
+
* console.log(signer.getAddress());
|
|
12302
|
+
* // 1MbL6mG8ASAvSYdoMnGUfG3ZXkmQ2dpL5b
|
|
12303
|
+
* ```
|
|
12304
|
+
*/
|
|
12305
|
+
constructor(c) {
|
|
12306
|
+
this.compressed = typeof c.compressed === "undefined" ? true : c.compressed;
|
|
12307
|
+
this.privateKey = c.privateKey;
|
|
12308
|
+
this.provider = c.provider;
|
|
12309
|
+
if (c.serializer) {
|
|
12310
|
+
this.serializer = c.serializer;
|
|
12311
|
+
}
|
|
12312
|
+
else {
|
|
12313
|
+
this.serializer = new Serializer_1.Serializer(protocol_proto_json_1.default, {
|
|
12314
|
+
defaultTypeName: "active_transaction_data",
|
|
12315
|
+
bytesConversion: false,
|
|
12316
|
+
});
|
|
12317
|
+
}
|
|
12318
|
+
if (typeof c.privateKey === "string") {
|
|
12319
|
+
this.publicKey = secp.getPublicKey(c.privateKey, this.compressed);
|
|
12320
|
+
this.address = utils_1.bitcoinAddress(utils_1.toUint8Array(this.publicKey));
|
|
12321
|
+
}
|
|
12322
|
+
else {
|
|
12323
|
+
this.publicKey = secp.getPublicKey(c.privateKey, this.compressed);
|
|
12324
|
+
this.address = utils_1.bitcoinAddress(this.publicKey);
|
|
12325
|
+
}
|
|
12326
|
+
}
|
|
12327
|
+
/**
|
|
12328
|
+
* Function to import a private key from the WIF
|
|
12329
|
+
* @param wif - Private key in WIF format
|
|
12330
|
+
* @example
|
|
12331
|
+
* ```ts
|
|
12332
|
+
* const signer = Signer.fromWif("L59UtJcTdNBnrH2QSBA5beSUhRufRu3g6tScDTite6Msuj7U93tM")
|
|
12333
|
+
* console.log(signer.getAddress());
|
|
12334
|
+
* // 1MbL6mG8ASAvSYdoMnGUfG3ZXkmQ2dpL5b
|
|
12335
|
+
* ```
|
|
12336
|
+
* @returns Signer object
|
|
12337
|
+
*/
|
|
12338
|
+
static fromWif(wif) {
|
|
12339
|
+
const compressed = wif[0] !== "5";
|
|
12340
|
+
const privateKey = utils_1.bitcoinDecode(wif);
|
|
12341
|
+
return new Signer({
|
|
12342
|
+
privateKey: utils_1.toHexString(privateKey),
|
|
12343
|
+
compressed,
|
|
12344
|
+
});
|
|
12345
|
+
}
|
|
12346
|
+
/**
|
|
12347
|
+
* Function to import a private key from the seed
|
|
12348
|
+
* @param seed - Seed words
|
|
12349
|
+
* @param compressed -
|
|
12350
|
+
* @example
|
|
12351
|
+
* ```ts
|
|
12352
|
+
* const signer = Signer.fromSeed("my seed");
|
|
12353
|
+
* console.log(signer.getAddress());
|
|
12354
|
+
* // 1BqtgWBcqm9cSZ97avLGZGJdgso7wx6pCA
|
|
12355
|
+
* ```
|
|
12356
|
+
* @returns Signer object
|
|
12357
|
+
*/
|
|
12358
|
+
static fromSeed(seed, compressed) {
|
|
12359
|
+
const privateKey = js_sha256_1.sha256(seed);
|
|
12360
|
+
return new Signer({ privateKey, compressed });
|
|
12361
|
+
}
|
|
12362
|
+
/**
|
|
12363
|
+
* @param compressed - determines if the address should be
|
|
12364
|
+
* derived from the compressed public key (default) or the public key
|
|
12365
|
+
* @returns Signer address
|
|
12366
|
+
*/
|
|
12367
|
+
getAddress(compressed = true) {
|
|
12368
|
+
if (typeof this.privateKey === "string") {
|
|
12369
|
+
const publicKey = secp.getPublicKey(this.privateKey, compressed);
|
|
12370
|
+
return utils_1.bitcoinAddress(utils_1.toUint8Array(publicKey));
|
|
12371
|
+
}
|
|
12372
|
+
const publicKey = secp.getPublicKey(this.privateKey, compressed);
|
|
12373
|
+
return utils_1.bitcoinAddress(publicKey);
|
|
12374
|
+
}
|
|
12375
|
+
/**
|
|
12376
|
+
* Function to get the private key in hex format or wif format
|
|
12377
|
+
* @param format - The format must be "hex" (default) or "wif"
|
|
12378
|
+
* @param compressed - Optional arg when using WIF format. By default it
|
|
12379
|
+
* uses the compressed value defined in the signer
|
|
12380
|
+
* @example
|
|
12381
|
+
* ```ts
|
|
12382
|
+
* const signer = Signer.fromSeed("one two three four five six");
|
|
12383
|
+
* console.log(signer.getPrivateKey());
|
|
12384
|
+
* // bab7fd6e5bd624f4ea0c33f7e7219262a6fa93a945a8964d9f110148286b7b37
|
|
12385
|
+
*
|
|
12386
|
+
* console.log(signer.getPrivateKey("wif"));
|
|
12387
|
+
* // L3UfgFJWmbVziGB1uZBjkG1UjKkF7hhpXWY7mbTUdmycmvXCVtiL
|
|
12388
|
+
*
|
|
12389
|
+
* console.log(signer.getPrivateKey("wif", false));
|
|
12390
|
+
* // 5KEX4TMHG66fT7cM9HMZLmdp4hVq4LC4X2Fkg6zeypM5UteWmtd
|
|
12391
|
+
* ```
|
|
12392
|
+
*/
|
|
12393
|
+
getPrivateKey(format = "hex", compressed) {
|
|
12394
|
+
let stringPrivateKey;
|
|
12395
|
+
if (this.privateKey instanceof Uint8Array) {
|
|
12396
|
+
stringPrivateKey = utils_1.toHexString(this.privateKey);
|
|
12397
|
+
}
|
|
12398
|
+
else if (typeof this.privateKey === "string") {
|
|
12399
|
+
stringPrivateKey = this.privateKey;
|
|
12400
|
+
}
|
|
12401
|
+
else {
|
|
12402
|
+
stringPrivateKey = BigInt(this.privateKey).toString(16).padStart(64, "0");
|
|
12403
|
+
}
|
|
12404
|
+
const comp = compressed === undefined ? this.compressed : compressed;
|
|
12405
|
+
switch (format) {
|
|
12406
|
+
case "hex":
|
|
12407
|
+
return stringPrivateKey;
|
|
12408
|
+
case "wif":
|
|
12409
|
+
return utils_1.bitcoinEncode(utils_1.toUint8Array(stringPrivateKey), "private", comp);
|
|
12410
|
+
default:
|
|
12411
|
+
/* eslint-disable-next-line @typescript-eslint/restrict-template-expressions */
|
|
12412
|
+
throw new Error(`Invalid format ${format}`);
|
|
12413
|
+
}
|
|
12414
|
+
}
|
|
12415
|
+
/**
|
|
12416
|
+
* Function to sign a transaction. It's important to remark that
|
|
12417
|
+
* the transaction parameter is modified inside this function.
|
|
12418
|
+
* @param tx - Unsigned transaction
|
|
12419
|
+
* @returns
|
|
12420
|
+
*/
|
|
12421
|
+
async signTransaction(tx) {
|
|
12422
|
+
if (!tx.active)
|
|
12423
|
+
throw new Error("Active data is not defined");
|
|
12424
|
+
const hash = js_sha256_1.sha256(utils_1.decodeBase64(tx.active));
|
|
12425
|
+
const [hex, recovery] = await secp.sign(hash, this.privateKey, {
|
|
12426
|
+
recovered: true,
|
|
12427
|
+
canonical: true,
|
|
12428
|
+
});
|
|
12429
|
+
// compact signature
|
|
12430
|
+
const { r, s } = secp.Signature.fromHex(hex);
|
|
12431
|
+
const rHex = r.toString(16).padStart(64, "0");
|
|
12432
|
+
const sHex = s.toString(16).padStart(64, "0");
|
|
12433
|
+
const recId = (recovery + 31).toString(16).padStart(2, "0");
|
|
12434
|
+
tx.signature_data = utils_1.encodeBase64(utils_1.toUint8Array(recId + rHex + sHex));
|
|
12435
|
+
const multihash = `0x1220${hash}`; // 12: code sha2-256. 20: length (32 bytes)
|
|
12436
|
+
tx.id = multihash;
|
|
12437
|
+
return tx;
|
|
12438
|
+
}
|
|
12439
|
+
/**
|
|
12440
|
+
* Function to sign and send a transaction. It internally uses
|
|
12441
|
+
* [[Provider.sendTransaction]]
|
|
12442
|
+
* @param tx - Transaction to send. It will be signed inside this function
|
|
12443
|
+
* if it is not signed yet
|
|
12444
|
+
* @param _abis - Collection of Abis to parse the operations in the
|
|
12445
|
+
* transaction. This parameter is optional.
|
|
12446
|
+
* @returns
|
|
12447
|
+
*/
|
|
12448
|
+
async sendTransaction(tx, _abis) {
|
|
12449
|
+
if (!tx.signature_data || !tx.id)
|
|
12450
|
+
await this.signTransaction(tx);
|
|
12451
|
+
if (!this.provider)
|
|
12452
|
+
throw new Error("provider is undefined");
|
|
12453
|
+
return this.provider.sendTransaction(tx);
|
|
12454
|
+
}
|
|
12455
|
+
/**
|
|
12456
|
+
* Function to recover the public key from a signed
|
|
12457
|
+
* transaction or block.
|
|
12458
|
+
* The output format can be compressed (default) or uncompressed.
|
|
12459
|
+
*
|
|
12460
|
+
* @example
|
|
12461
|
+
* ```ts
|
|
12462
|
+
* const publicKey = await Signer.recoverPublicKey(tx);
|
|
12463
|
+
* ```
|
|
12464
|
+
*
|
|
12465
|
+
* If the signature data contains more data, like in the
|
|
12466
|
+
* blocks for PoW consensus, use the "transformSignature"
|
|
12467
|
+
* function to extract the signature.
|
|
12468
|
+
*
|
|
12469
|
+
* @example
|
|
12470
|
+
* ```ts
|
|
12471
|
+
* const powDescriptorJson = {
|
|
12472
|
+
* nested: {
|
|
12473
|
+
* mypackage: {
|
|
12474
|
+
* nested: {
|
|
12475
|
+
* pow_signature_data: {
|
|
12476
|
+
* fields: {
|
|
12477
|
+
* nonce: {
|
|
12478
|
+
* type: "bytes",
|
|
12479
|
+
* id: 1,
|
|
12480
|
+
* },
|
|
12481
|
+
* recoverable_signature: {
|
|
12482
|
+
* type: "bytes",
|
|
12483
|
+
* id: 2,
|
|
12484
|
+
* },
|
|
12485
|
+
* },
|
|
12486
|
+
* },
|
|
12487
|
+
* },
|
|
12488
|
+
* },
|
|
12489
|
+
* },
|
|
12490
|
+
* };
|
|
12491
|
+
*
|
|
12492
|
+
* const serializer = new Serializer(powDescriptorJson, {
|
|
12493
|
+
* defaultTypeName: "pow_signature_data",
|
|
12494
|
+
* });
|
|
12495
|
+
*
|
|
12496
|
+
* const signer = await Signer.recoverPublicKey(block, {
|
|
12497
|
+
* transformSignature: async (signatureData) => {
|
|
12498
|
+
* const powSignatureData = await serializer.deserialize(signatureData);
|
|
12499
|
+
* return powSignatureData.recoverable_signature;
|
|
12500
|
+
* },
|
|
12501
|
+
* });
|
|
12502
|
+
* ```
|
|
12503
|
+
*/
|
|
12504
|
+
static async recoverPublicKey(txOrBlock, opts) {
|
|
12505
|
+
if (!txOrBlock.active)
|
|
12506
|
+
throw new Error("active is not defined");
|
|
12507
|
+
if (!txOrBlock.signature_data)
|
|
12508
|
+
throw new Error("signature_data is not defined");
|
|
12509
|
+
let signatureData = txOrBlock.signature_data;
|
|
12510
|
+
if (opts && typeof opts.transformSignature === "function") {
|
|
12511
|
+
signatureData = await opts.transformSignature(txOrBlock.signature_data);
|
|
12512
|
+
}
|
|
12513
|
+
let compressed = true;
|
|
12514
|
+
if (opts && typeof opts.compressed !== "undefined") {
|
|
12515
|
+
compressed = opts.compressed;
|
|
12516
|
+
}
|
|
12517
|
+
const hash = js_sha256_1.sha256(utils_1.decodeBase64(txOrBlock.active));
|
|
12518
|
+
const compactSignatureHex = utils_1.toHexString(utils_1.decodeBase64(signatureData));
|
|
12519
|
+
const recovery = Number(`0x${compactSignatureHex.slice(0, 2)}`) - 31;
|
|
12520
|
+
const rHex = compactSignatureHex.slice(2, 66);
|
|
12521
|
+
const sHex = compactSignatureHex.slice(66);
|
|
12522
|
+
const r = BigInt(`0x${rHex}`);
|
|
12523
|
+
const s = BigInt(`0x${sHex}`);
|
|
12524
|
+
const sig = new secp.Signature(r, s);
|
|
12525
|
+
const publicKey = secp.recoverPublicKey(hash, sig.toHex(), recovery);
|
|
12526
|
+
if (!publicKey)
|
|
12527
|
+
throw new Error("Public key cannot be recovered");
|
|
12528
|
+
if (!compressed)
|
|
12529
|
+
return publicKey;
|
|
12530
|
+
return secp.Point.fromHex(publicKey).toHex(true);
|
|
12531
|
+
}
|
|
12532
|
+
/**
|
|
12533
|
+
* Function to recover the signer address from a signed
|
|
12534
|
+
* transaction or block.
|
|
12535
|
+
* The output format can be compressed (default) or uncompressed.
|
|
12536
|
+
* @example
|
|
12537
|
+
* ```ts
|
|
12538
|
+
* const publicKey = await Signer.recoverAddress(tx);
|
|
12539
|
+
* ```
|
|
12540
|
+
*
|
|
12541
|
+
* If the signature data contains more data, like in the
|
|
12542
|
+
* blocks for PoW consensus, use the "transformSignature"
|
|
12543
|
+
* function to extract the signature.
|
|
12544
|
+
*
|
|
12545
|
+
* @example
|
|
12546
|
+
* ```ts
|
|
12547
|
+
* const powDescriptorJson = {
|
|
12548
|
+
* nested: {
|
|
12549
|
+
* mypackage: {
|
|
12550
|
+
* nested: {
|
|
12551
|
+
* pow_signature_data: {
|
|
12552
|
+
* fields: {
|
|
12553
|
+
* nonce: {
|
|
12554
|
+
* type: "bytes",
|
|
12555
|
+
* id: 1,
|
|
12556
|
+
* },
|
|
12557
|
+
* recoverable_signature: {
|
|
12558
|
+
* type: "bytes",
|
|
12559
|
+
* id: 2,
|
|
12560
|
+
* },
|
|
12561
|
+
* },
|
|
12562
|
+
* },
|
|
12563
|
+
* },
|
|
12564
|
+
* },
|
|
12565
|
+
* },
|
|
12566
|
+
* };
|
|
12567
|
+
*
|
|
12568
|
+
* const serializer = new Serializer(powDescriptorJson, {
|
|
12569
|
+
* defaultTypeName: "pow_signature_data",
|
|
12570
|
+
* });
|
|
12571
|
+
*
|
|
12572
|
+
* const signer = await Signer.recoverAddress(block, {
|
|
12573
|
+
* transformSignature: async (signatureData) => {
|
|
12574
|
+
* const powSignatureData = await serializer.deserialize(signatureData);
|
|
12575
|
+
* return powSignatureData.recoverable_signature;
|
|
12576
|
+
* },
|
|
12577
|
+
* });
|
|
12578
|
+
* ```
|
|
12579
|
+
*/
|
|
12580
|
+
static async recoverAddress(txOrBlock, opts) {
|
|
12581
|
+
const publicKey = await Signer.recoverPublicKey(txOrBlock, opts);
|
|
12582
|
+
return utils_1.bitcoinAddress(utils_1.toUint8Array(publicKey));
|
|
12583
|
+
}
|
|
12584
|
+
/**
|
|
12585
|
+
* Function to encode a transaction
|
|
12586
|
+
* @param activeData - Active data consists of nonce, rc_limit, and
|
|
12587
|
+
* operations. Do not set the nonce to get it from the blockchain
|
|
12588
|
+
* using the provider. The rc_limit is 1000000 by default.
|
|
12589
|
+
* @returns A transaction encoded. The active field is encoded in
|
|
12590
|
+
* base64url
|
|
12591
|
+
*/
|
|
12592
|
+
async encodeTransaction(activeData) {
|
|
12593
|
+
let { nonce } = activeData;
|
|
12594
|
+
if (activeData.nonce === undefined) {
|
|
12595
|
+
if (!this.provider)
|
|
12596
|
+
throw new Error("Cannot get the nonce because provider is undefined. To skip this call set a nonce in the parameters");
|
|
12597
|
+
// TODO: Option to resolve names
|
|
12598
|
+
// this depends on the final architecture for names on Koinos
|
|
12599
|
+
nonce = await this.provider.getNonce(this.getAddress());
|
|
12600
|
+
}
|
|
12601
|
+
const rcLimit = activeData.rc_limit === undefined ? 1000000 : activeData.rc_limit;
|
|
12602
|
+
const operations = activeData.operations ? activeData.operations : [];
|
|
12603
|
+
const activeData2 = {
|
|
12604
|
+
rc_limit: rcLimit,
|
|
12605
|
+
nonce,
|
|
12606
|
+
operations,
|
|
12607
|
+
};
|
|
12608
|
+
const buffer = await this.serializer.serialize(activeData2);
|
|
12609
|
+
return {
|
|
12610
|
+
active: utils_1.encodeBase64(buffer),
|
|
12611
|
+
};
|
|
12612
|
+
}
|
|
12613
|
+
/**
|
|
12614
|
+
* Function to decode a transaction
|
|
12615
|
+
*/
|
|
12616
|
+
async decodeTransaction(tx) {
|
|
12617
|
+
if (!tx.active)
|
|
12618
|
+
throw new Error("Active data is not defined");
|
|
12619
|
+
return this.serializer.deserialize(tx.active);
|
|
12620
|
+
}
|
|
12621
|
+
}
|
|
12622
|
+
exports.Signer = Signer;
|
|
12623
|
+
exports.default = Signer;
|
|
12431
12624
|
|
|
12432
12625
|
|
|
12433
12626
|
/***/ }),
|
|
@@ -12436,36 +12629,38 @@ exports.default = Signer;
|
|
|
12436
12629
|
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
|
12437
12630
|
|
|
12438
12631
|
"use strict";
|
|
12439
|
-
|
|
12440
|
-
/*! koilib - MIT License (c) Julian Gonzalez (joticajulian@gmail.com) */
|
|
12441
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
12442
|
-
if (k2 === undefined) k2 = k;
|
|
12443
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
12444
|
-
}) : (function(o, m, k, k2) {
|
|
12445
|
-
if (k2 === undefined) k2 = k;
|
|
12446
|
-
o[k2] = m[k];
|
|
12447
|
-
}));
|
|
12448
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
12449
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
12450
|
-
}) : function(o, v) {
|
|
12451
|
-
o["default"] = v;
|
|
12452
|
-
});
|
|
12453
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
12454
|
-
if (mod && mod.__esModule) return mod;
|
|
12455
|
-
var result = {};
|
|
12456
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
12457
|
-
__setModuleDefault(result, mod);
|
|
12458
|
-
return result;
|
|
12459
|
-
};
|
|
12460
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
12461
|
-
const utils = __importStar(__webpack_require__(8593));
|
|
12462
|
-
const Contract_1 = __webpack_require__(9822);
|
|
12463
|
-
const Signer_1 = __webpack_require__(6991);
|
|
12464
|
-
const Provider_1 = __webpack_require__(5635);
|
|
12465
|
-
|
|
12466
|
-
window.
|
|
12467
|
-
window.
|
|
12468
|
-
window.
|
|
12632
|
+
|
|
12633
|
+
/*! koilib - MIT License (c) Julian Gonzalez (joticajulian@gmail.com) */
|
|
12634
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
12635
|
+
if (k2 === undefined) k2 = k;
|
|
12636
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
12637
|
+
}) : (function(o, m, k, k2) {
|
|
12638
|
+
if (k2 === undefined) k2 = k;
|
|
12639
|
+
o[k2] = m[k];
|
|
12640
|
+
}));
|
|
12641
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
12642
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
12643
|
+
}) : function(o, v) {
|
|
12644
|
+
o["default"] = v;
|
|
12645
|
+
});
|
|
12646
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
12647
|
+
if (mod && mod.__esModule) return mod;
|
|
12648
|
+
var result = {};
|
|
12649
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
12650
|
+
__setModuleDefault(result, mod);
|
|
12651
|
+
return result;
|
|
12652
|
+
};
|
|
12653
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
12654
|
+
const utils = __importStar(__webpack_require__(8593));
|
|
12655
|
+
const Contract_1 = __webpack_require__(9822);
|
|
12656
|
+
const Signer_1 = __webpack_require__(6991);
|
|
12657
|
+
const Provider_1 = __webpack_require__(5635);
|
|
12658
|
+
const Serializer_1 = __webpack_require__(7187);
|
|
12659
|
+
window.utils = utils;
|
|
12660
|
+
window.Contract = Contract_1.Contract;
|
|
12661
|
+
window.Signer = Signer_1.Signer;
|
|
12662
|
+
window.Provider = Provider_1.Provider;
|
|
12663
|
+
window.Serializer = Serializer_1.Serializer;
|
|
12469
12664
|
|
|
12470
12665
|
|
|
12471
12666
|
/***/ }),
|
|
@@ -12474,262 +12669,264 @@ window.Provider = Provider_1.Provider;
|
|
|
12474
12669
|
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
|
12475
12670
|
|
|
12476
12671
|
"use strict";
|
|
12477
|
-
|
|
12478
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
12479
|
-
if (k2 === undefined) k2 = k;
|
|
12480
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
12481
|
-
}) : (function(o, m, k, k2) {
|
|
12482
|
-
if (k2 === undefined) k2 = k;
|
|
12483
|
-
o[k2] = m[k];
|
|
12484
|
-
}));
|
|
12485
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
12486
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
12487
|
-
}) : function(o, v) {
|
|
12488
|
-
o["default"] = v;
|
|
12489
|
-
});
|
|
12490
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
12491
|
-
if (mod && mod.__esModule) return mod;
|
|
12492
|
-
var result = {};
|
|
12493
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
12494
|
-
__setModuleDefault(result, mod);
|
|
12495
|
-
return result;
|
|
12496
|
-
};
|
|
12497
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12498
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12499
|
-
};
|
|
12500
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
12501
|
-
exports.Krc20Abi = exports.parseUnits = exports.formatUnits = exports.bitcoinAddress = exports.bitcoinDecode = exports.copyUint8Array = exports.bitcoinEncode = exports.decodeBase64 = exports.encodeBase64 = exports.decodeBase58 = exports.encodeBase58 = exports.toHexString = exports.toUint8Array = void 0;
|
|
12502
|
-
const multibase = __importStar(__webpack_require__(6957));
|
|
12503
|
-
const js_sha256_1 = __webpack_require__(2023);
|
|
12504
|
-
const noble_ripemd160_1 = __importDefault(__webpack_require__(6389));
|
|
12505
|
-
const krc20_proto_json_1 = __importDefault(__webpack_require__(
|
|
12506
|
-
|
|
12507
|
-
|
|
12508
|
-
|
|
12509
|
-
|
|
12510
|
-
|
|
12511
|
-
|
|
12512
|
-
|
|
12513
|
-
|
|
12514
|
-
)
|
|
12515
|
-
|
|
12516
|
-
|
|
12517
|
-
|
|
12518
|
-
|
|
12519
|
-
|
|
12520
|
-
|
|
12521
|
-
|
|
12522
|
-
|
|
12523
|
-
.
|
|
12524
|
-
|
|
12525
|
-
|
|
12526
|
-
|
|
12527
|
-
|
|
12528
|
-
|
|
12529
|
-
|
|
12530
|
-
|
|
12531
|
-
|
|
12532
|
-
|
|
12533
|
-
|
|
12534
|
-
|
|
12535
|
-
|
|
12536
|
-
|
|
12537
|
-
|
|
12538
|
-
}
|
|
12539
|
-
|
|
12540
|
-
|
|
12541
|
-
|
|
12542
|
-
|
|
12543
|
-
|
|
12544
|
-
|
|
12545
|
-
|
|
12546
|
-
|
|
12547
|
-
|
|
12548
|
-
|
|
12549
|
-
|
|
12550
|
-
|
|
12551
|
-
|
|
12552
|
-
}
|
|
12553
|
-
|
|
12554
|
-
|
|
12555
|
-
|
|
12556
|
-
*
|
|
12557
|
-
*
|
|
12558
|
-
*
|
|
12559
|
-
*
|
|
12560
|
-
*
|
|
12561
|
-
|
|
12562
|
-
|
|
12563
|
-
|
|
12564
|
-
let
|
|
12565
|
-
let
|
|
12566
|
-
|
|
12567
|
-
|
|
12568
|
-
|
|
12569
|
-
|
|
12570
|
-
|
|
12571
|
-
|
|
12572
|
-
|
|
12573
|
-
|
|
12574
|
-
|
|
12575
|
-
|
|
12576
|
-
|
|
12577
|
-
|
|
12578
|
-
|
|
12579
|
-
|
|
12580
|
-
|
|
12581
|
-
|
|
12582
|
-
|
|
12583
|
-
|
|
12584
|
-
|
|
12585
|
-
|
|
12586
|
-
|
|
12587
|
-
|
|
12588
|
-
|
|
12589
|
-
|
|
12590
|
-
|
|
12591
|
-
const
|
|
12592
|
-
const
|
|
12593
|
-
|
|
12594
|
-
bufferCheck.set(
|
|
12595
|
-
|
|
12596
|
-
|
|
12597
|
-
|
|
12598
|
-
|
|
12599
|
-
|
|
12600
|
-
|
|
12601
|
-
|
|
12602
|
-
|
|
12603
|
-
|
|
12604
|
-
}
|
|
12605
|
-
|
|
12606
|
-
|
|
12607
|
-
|
|
12608
|
-
*
|
|
12609
|
-
*
|
|
12610
|
-
*
|
|
12611
|
-
*
|
|
12612
|
-
*
|
|
12613
|
-
|
|
12614
|
-
|
|
12615
|
-
|
|
12616
|
-
const
|
|
12617
|
-
const
|
|
12618
|
-
|
|
12619
|
-
|
|
12620
|
-
|
|
12621
|
-
|
|
12622
|
-
|
|
12623
|
-
|
|
12624
|
-
|
|
12625
|
-
|
|
12626
|
-
|
|
12627
|
-
|
|
12628
|
-
|
|
12629
|
-
|
|
12630
|
-
|
|
12631
|
-
|
|
12632
|
-
|
|
12633
|
-
*
|
|
12634
|
-
*
|
|
12635
|
-
|
|
12636
|
-
|
|
12637
|
-
|
|
12638
|
-
const
|
|
12639
|
-
|
|
12640
|
-
|
|
12641
|
-
|
|
12642
|
-
|
|
12643
|
-
|
|
12644
|
-
*
|
|
12645
|
-
*
|
|
12646
|
-
*
|
|
12647
|
-
*
|
|
12648
|
-
*
|
|
12649
|
-
*
|
|
12650
|
-
|
|
12651
|
-
|
|
12652
|
-
|
|
12653
|
-
|
|
12654
|
-
|
|
12655
|
-
|
|
12656
|
-
|
|
12657
|
-
.
|
|
12658
|
-
|
|
12659
|
-
|
|
12660
|
-
}
|
|
12661
|
-
|
|
12662
|
-
|
|
12663
|
-
|
|
12664
|
-
*
|
|
12665
|
-
*
|
|
12666
|
-
*
|
|
12667
|
-
*
|
|
12668
|
-
*
|
|
12669
|
-
*
|
|
12670
|
-
|
|
12671
|
-
|
|
12672
|
-
|
|
12673
|
-
|
|
12674
|
-
|
|
12675
|
-
|
|
12676
|
-
.replace("
|
|
12677
|
-
.
|
|
12678
|
-
|
|
12679
|
-
|
|
12680
|
-
|
|
12681
|
-
|
|
12682
|
-
}
|
|
12683
|
-
|
|
12684
|
-
|
|
12685
|
-
|
|
12686
|
-
|
|
12687
|
-
|
|
12688
|
-
|
|
12689
|
-
|
|
12690
|
-
|
|
12691
|
-
|
|
12692
|
-
|
|
12693
|
-
|
|
12694
|
-
|
|
12695
|
-
|
|
12696
|
-
|
|
12697
|
-
|
|
12698
|
-
|
|
12699
|
-
|
|
12700
|
-
|
|
12701
|
-
|
|
12702
|
-
|
|
12703
|
-
|
|
12704
|
-
|
|
12705
|
-
|
|
12706
|
-
|
|
12707
|
-
|
|
12708
|
-
|
|
12709
|
-
|
|
12710
|
-
|
|
12711
|
-
|
|
12712
|
-
|
|
12713
|
-
|
|
12714
|
-
|
|
12715
|
-
|
|
12716
|
-
|
|
12717
|
-
|
|
12718
|
-
|
|
12719
|
-
|
|
12720
|
-
|
|
12721
|
-
|
|
12722
|
-
|
|
12723
|
-
|
|
12724
|
-
|
|
12725
|
-
|
|
12726
|
-
|
|
12727
|
-
|
|
12728
|
-
|
|
12729
|
-
|
|
12730
|
-
|
|
12731
|
-
|
|
12732
|
-
|
|
12672
|
+
|
|
12673
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
12674
|
+
if (k2 === undefined) k2 = k;
|
|
12675
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
12676
|
+
}) : (function(o, m, k, k2) {
|
|
12677
|
+
if (k2 === undefined) k2 = k;
|
|
12678
|
+
o[k2] = m[k];
|
|
12679
|
+
}));
|
|
12680
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
12681
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
12682
|
+
}) : function(o, v) {
|
|
12683
|
+
o["default"] = v;
|
|
12684
|
+
});
|
|
12685
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
12686
|
+
if (mod && mod.__esModule) return mod;
|
|
12687
|
+
var result = {};
|
|
12688
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
12689
|
+
__setModuleDefault(result, mod);
|
|
12690
|
+
return result;
|
|
12691
|
+
};
|
|
12692
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12693
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12694
|
+
};
|
|
12695
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
12696
|
+
exports.ProtocolTypes = exports.Krc20Abi = exports.parseUnits = exports.formatUnits = exports.bitcoinAddress = exports.bitcoinDecode = exports.copyUint8Array = exports.bitcoinEncode = exports.decodeBase64 = exports.encodeBase64 = exports.decodeBase58 = exports.encodeBase58 = exports.toHexString = exports.toUint8Array = void 0;
|
|
12697
|
+
const multibase = __importStar(__webpack_require__(6957));
|
|
12698
|
+
const js_sha256_1 = __webpack_require__(2023);
|
|
12699
|
+
const noble_ripemd160_1 = __importDefault(__webpack_require__(6389));
|
|
12700
|
+
const krc20_proto_json_1 = __importDefault(__webpack_require__(7177));
|
|
12701
|
+
const protocol_proto_json_1 = __importDefault(__webpack_require__(6139));
|
|
12702
|
+
/**
|
|
12703
|
+
* Converts an hex string to Uint8Array
|
|
12704
|
+
*/
|
|
12705
|
+
function toUint8Array(hex) {
|
|
12706
|
+
const pairs = hex.match(/[\dA-F]{2}/gi);
|
|
12707
|
+
if (!pairs)
|
|
12708
|
+
throw new Error("Invalid hex");
|
|
12709
|
+
return new Uint8Array(pairs.map((s) => parseInt(s, 16)) // convert to integers
|
|
12710
|
+
);
|
|
12711
|
+
}
|
|
12712
|
+
exports.toUint8Array = toUint8Array;
|
|
12713
|
+
/**
|
|
12714
|
+
* Converts Uint8Array to hex string
|
|
12715
|
+
*/
|
|
12716
|
+
function toHexString(buffer) {
|
|
12717
|
+
return Array.from(buffer)
|
|
12718
|
+
.map((n) => `0${Number(n).toString(16)}`.slice(-2))
|
|
12719
|
+
.join("");
|
|
12720
|
+
}
|
|
12721
|
+
exports.toHexString = toHexString;
|
|
12722
|
+
/**
|
|
12723
|
+
* Encodes an Uint8Array in base58
|
|
12724
|
+
*/
|
|
12725
|
+
function encodeBase58(buffer) {
|
|
12726
|
+
return new TextDecoder().decode(multibase.encode("z", buffer)).slice(1);
|
|
12727
|
+
}
|
|
12728
|
+
exports.encodeBase58 = encodeBase58;
|
|
12729
|
+
/**
|
|
12730
|
+
* Decodes a buffer formatted in base58
|
|
12731
|
+
*/
|
|
12732
|
+
function decodeBase58(bs58) {
|
|
12733
|
+
return multibase.decode(`z${bs58}`);
|
|
12734
|
+
}
|
|
12735
|
+
exports.decodeBase58 = decodeBase58;
|
|
12736
|
+
/**
|
|
12737
|
+
* Encodes an Uint8Array in base64
|
|
12738
|
+
*/
|
|
12739
|
+
function encodeBase64(buffer) {
|
|
12740
|
+
return new TextDecoder().decode(multibase.encode("U", buffer)).slice(1);
|
|
12741
|
+
}
|
|
12742
|
+
exports.encodeBase64 = encodeBase64;
|
|
12743
|
+
/**
|
|
12744
|
+
* Decodes a buffer formatted in base64
|
|
12745
|
+
*/
|
|
12746
|
+
function decodeBase64(bs64) {
|
|
12747
|
+
return multibase.decode(`U${bs64}`);
|
|
12748
|
+
}
|
|
12749
|
+
exports.decodeBase64 = decodeBase64;
|
|
12750
|
+
/**
|
|
12751
|
+
* Encodes a public or private key in base58 using
|
|
12752
|
+
* the bitcoin format (see [Bitcoin Base58Check encoding](https://en.bitcoin.it/wiki/Base58Check_encoding)
|
|
12753
|
+
* and [Bitcoin WIF](https://en.bitcoin.it/wiki/Wallet_import_format)).
|
|
12754
|
+
*
|
|
12755
|
+
* For private keys this encode is also known as
|
|
12756
|
+
* wallet import format (WIF).
|
|
12757
|
+
*/
|
|
12758
|
+
function bitcoinEncode(buffer, type, compressed = false) {
|
|
12759
|
+
let bufferCheck;
|
|
12760
|
+
let prefixBuffer;
|
|
12761
|
+
let offsetChecksum;
|
|
12762
|
+
if (type === "public") {
|
|
12763
|
+
bufferCheck = new Uint8Array(25);
|
|
12764
|
+
prefixBuffer = new Uint8Array(21);
|
|
12765
|
+
bufferCheck[0] = 0;
|
|
12766
|
+
prefixBuffer[0] = 0;
|
|
12767
|
+
offsetChecksum = 21;
|
|
12768
|
+
}
|
|
12769
|
+
else {
|
|
12770
|
+
if (compressed) {
|
|
12771
|
+
bufferCheck = new Uint8Array(38);
|
|
12772
|
+
prefixBuffer = new Uint8Array(34);
|
|
12773
|
+
offsetChecksum = 34;
|
|
12774
|
+
bufferCheck[33] = 1;
|
|
12775
|
+
prefixBuffer[33] = 1;
|
|
12776
|
+
}
|
|
12777
|
+
else {
|
|
12778
|
+
bufferCheck = new Uint8Array(37);
|
|
12779
|
+
prefixBuffer = new Uint8Array(33);
|
|
12780
|
+
offsetChecksum = 33;
|
|
12781
|
+
}
|
|
12782
|
+
bufferCheck[0] = 128;
|
|
12783
|
+
prefixBuffer[0] = 128;
|
|
12784
|
+
}
|
|
12785
|
+
prefixBuffer.set(buffer, 1);
|
|
12786
|
+
const firstHash = js_sha256_1.sha256(prefixBuffer);
|
|
12787
|
+
const doubleHash = js_sha256_1.sha256(toUint8Array(firstHash));
|
|
12788
|
+
const checksum = toUint8Array(doubleHash.substring(0, 8));
|
|
12789
|
+
bufferCheck.set(buffer, 1);
|
|
12790
|
+
bufferCheck.set(checksum, offsetChecksum);
|
|
12791
|
+
return encodeBase58(bufferCheck);
|
|
12792
|
+
}
|
|
12793
|
+
exports.bitcoinEncode = bitcoinEncode;
|
|
12794
|
+
function copyUint8Array(source, target, targetStart, sourceStart, sourceEnd) {
|
|
12795
|
+
for (let cursorSource = sourceStart; cursorSource < sourceEnd; cursorSource += 1) {
|
|
12796
|
+
const cursorTarget = targetStart + cursorSource - sourceStart;
|
|
12797
|
+
/* eslint-disable-next-line no-param-reassign */
|
|
12798
|
+
target[cursorTarget] = source[cursorSource];
|
|
12799
|
+
}
|
|
12800
|
+
}
|
|
12801
|
+
exports.copyUint8Array = copyUint8Array;
|
|
12802
|
+
/**
|
|
12803
|
+
* Decodes a public or private key formatted in base58 using
|
|
12804
|
+
* the bitcoin format (see [Bitcoin Base58Check encoding](https://en.bitcoin.it/wiki/Base58Check_encoding)
|
|
12805
|
+
* and [Bitcoin WIF](https://en.bitcoin.it/wiki/Wallet_import_format)).
|
|
12806
|
+
*
|
|
12807
|
+
* For private keys this encode is also known as
|
|
12808
|
+
* wallet import format (WIF).
|
|
12809
|
+
*/
|
|
12810
|
+
function bitcoinDecode(value) {
|
|
12811
|
+
const buffer = decodeBase58(value);
|
|
12812
|
+
const privateKey = new Uint8Array(32);
|
|
12813
|
+
const checksum = new Uint8Array(4);
|
|
12814
|
+
// const prefix = buffer[0];
|
|
12815
|
+
copyUint8Array(buffer, privateKey, 0, 1, 33);
|
|
12816
|
+
if (value[0] !== "5") {
|
|
12817
|
+
// compressed
|
|
12818
|
+
copyUint8Array(buffer, checksum, 0, 34, 38);
|
|
12819
|
+
}
|
|
12820
|
+
else {
|
|
12821
|
+
copyUint8Array(buffer, checksum, 0, 33, 37);
|
|
12822
|
+
}
|
|
12823
|
+
// TODO: verify prefix and checksum
|
|
12824
|
+
return privateKey;
|
|
12825
|
+
}
|
|
12826
|
+
exports.bitcoinDecode = bitcoinDecode;
|
|
12827
|
+
/**
|
|
12828
|
+
* Computes a bitcoin address, which is the format used in Koinos
|
|
12829
|
+
*
|
|
12830
|
+
* address = bitcoinEncode( ripemd160 ( sha256 ( publicKey ) ) )
|
|
12831
|
+
*/
|
|
12832
|
+
function bitcoinAddress(publicKey) {
|
|
12833
|
+
const hash = js_sha256_1.sha256(publicKey);
|
|
12834
|
+
const hash160 = noble_ripemd160_1.default(toUint8Array(hash));
|
|
12835
|
+
return bitcoinEncode(hash160, "public");
|
|
12836
|
+
}
|
|
12837
|
+
exports.bitcoinAddress = bitcoinAddress;
|
|
12838
|
+
/**
|
|
12839
|
+
* Function to format a number in a decimal point number
|
|
12840
|
+
* @example
|
|
12841
|
+
* ```js
|
|
12842
|
+
* const amount = formatUnits("123456", 8);
|
|
12843
|
+
* console.log(amount);
|
|
12844
|
+
* // '0.00123456'
|
|
12845
|
+
* ```
|
|
12846
|
+
*/
|
|
12847
|
+
function formatUnits(value, decimals) {
|
|
12848
|
+
let v = typeof value === "string" ? value : BigInt(value).toString();
|
|
12849
|
+
const sign = v[0] === "-" ? "-" : "";
|
|
12850
|
+
v = v.replace("-", "").padStart(decimals + 1, "0");
|
|
12851
|
+
const integerPart = v
|
|
12852
|
+
.substring(0, v.length - decimals)
|
|
12853
|
+
.replace(/^0+(?=\d)/, "");
|
|
12854
|
+
const decimalPart = v.substring(v.length - decimals);
|
|
12855
|
+
return `${sign}${integerPart}.${decimalPart}`.replace(/(\.0+)?(0+)$/, "");
|
|
12856
|
+
}
|
|
12857
|
+
exports.formatUnits = formatUnits;
|
|
12858
|
+
/**
|
|
12859
|
+
* Function to format a decimal point number in an integer
|
|
12860
|
+
* @example
|
|
12861
|
+
* ```js
|
|
12862
|
+
* const amount = parseUnits("0.00123456", 8);
|
|
12863
|
+
* console.log(amount);
|
|
12864
|
+
* // '123456'
|
|
12865
|
+
* ```
|
|
12866
|
+
*/
|
|
12867
|
+
function parseUnits(value, decimals) {
|
|
12868
|
+
const sign = value[0] === "-" ? "-" : "";
|
|
12869
|
+
// eslint-disable-next-line prefer-const
|
|
12870
|
+
let [integerPart, decimalPart] = value
|
|
12871
|
+
.replace("-", "")
|
|
12872
|
+
.replace(",", ".")
|
|
12873
|
+
.split(".");
|
|
12874
|
+
if (!decimalPart)
|
|
12875
|
+
decimalPart = "";
|
|
12876
|
+
decimalPart = decimalPart.padEnd(decimals, "0");
|
|
12877
|
+
return `${sign}${`${integerPart}${decimalPart}`.replace(/^0+(?=\d)/, "")}`;
|
|
12878
|
+
}
|
|
12879
|
+
exports.parseUnits = parseUnits;
|
|
12880
|
+
/**
|
|
12881
|
+
* ABI for tokens
|
|
12882
|
+
*/
|
|
12883
|
+
exports.Krc20Abi = {
|
|
12884
|
+
methods: {
|
|
12885
|
+
name: {
|
|
12886
|
+
entryPoint: 0x76ea4297,
|
|
12887
|
+
input: "name_arguments",
|
|
12888
|
+
output: "name_result",
|
|
12889
|
+
readOnly: true,
|
|
12890
|
+
},
|
|
12891
|
+
symbol: {
|
|
12892
|
+
entryPoint: 0x7e794b24,
|
|
12893
|
+
input: "symbol_arguments",
|
|
12894
|
+
output: "symbol_result",
|
|
12895
|
+
readOnly: true,
|
|
12896
|
+
},
|
|
12897
|
+
decimals: {
|
|
12898
|
+
entryPoint: 0x59dc15ce,
|
|
12899
|
+
input: "decimals_arguments",
|
|
12900
|
+
output: "decimals_result",
|
|
12901
|
+
readOnly: true,
|
|
12902
|
+
},
|
|
12903
|
+
totalSupply: {
|
|
12904
|
+
entryPoint: 0xcf2e8212,
|
|
12905
|
+
input: "total_supply_arguments",
|
|
12906
|
+
output: "total_supply_result",
|
|
12907
|
+
readOnly: true,
|
|
12908
|
+
},
|
|
12909
|
+
balanceOf: {
|
|
12910
|
+
entryPoint: 0x15619248,
|
|
12911
|
+
input: "balance_of_arguments",
|
|
12912
|
+
output: "balance_of_result",
|
|
12913
|
+
readOnly: true,
|
|
12914
|
+
defaultOutput: { value: "0" },
|
|
12915
|
+
},
|
|
12916
|
+
transfer: {
|
|
12917
|
+
entryPoint: 0x62efa292,
|
|
12918
|
+
input: "transfer_arguments",
|
|
12919
|
+
output: "transfer_result",
|
|
12920
|
+
},
|
|
12921
|
+
mint: {
|
|
12922
|
+
entryPoint: 0xc2f82bdc,
|
|
12923
|
+
input: "mint_argumnets",
|
|
12924
|
+
output: "mint_result",
|
|
12925
|
+
},
|
|
12926
|
+
},
|
|
12927
|
+
types: krc20_proto_json_1.default,
|
|
12928
|
+
};
|
|
12929
|
+
exports.ProtocolTypes = protocol_proto_json_1.default;
|
|
12733
12930
|
|
|
12734
12931
|
|
|
12735
12932
|
/***/ }),
|
|
@@ -12741,19 +12938,19 @@ exports.Krc20Abi = {
|
|
|
12741
12938
|
|
|
12742
12939
|
/***/ }),
|
|
12743
12940
|
|
|
12744
|
-
/***/
|
|
12941
|
+
/***/ 7177:
|
|
12745
12942
|
/***/ ((module) => {
|
|
12746
12943
|
|
|
12747
12944
|
"use strict";
|
|
12748
|
-
module.exports = JSON.parse('{"nested":{"koinos":{"nested":{"contracts":{"nested":{"token":{"options":{"go_package":"github.com/koinos/koinos-proto-golang/koinos/contracts/token"},"nested":{"name_arguments":{"fields":{}},"name_result":{"fields":{"value":{"type":"string","id":1}}},"symbol_arguments":{"fields":{}},"symbol_result":{"fields":{"value":{"type":"string","id":1}}},"decimals_arguments":{"fields":{}},"decimals_result":{"fields":{"value":{"type":"uint32","id":1}}},"total_supply_arguments":{"fields":{}},"total_supply_result":{"fields":{"value":{"type":"uint64","id":1,"options":{"jstype":"JS_STRING"}}}},"balance_of_arguments":{"fields":{"owner":{"type":"bytes","id":1,"options":{"(koinos_bytes_type)":"ADDRESS"}}}},"balance_of_result":{"fields":{"value":{"type":"uint64","id":1,"options":{"jstype":"JS_STRING"}}}},"transfer_arguments":{"fields":{"from":{"type":"bytes","id":1,"options":{"(koinos_bytes_type)":"ADDRESS"}},"to":{"type":"bytes","id":2,"options":{"(koinos_bytes_type)":"ADDRESS"}},"value":{"type":"uint64","id":3,"options":{"jstype":"JS_STRING"}}}},"transfer_result":{"fields":{"value":{"type":"bool","id":1}}},"mint_arguments":{"fields":{"to":{"type":"bytes","id":1,"options":{"(koinos_bytes_type)":"ADDRESS"}},"value":{"type":"uint64","id":2,"options":{"jstype":"JS_STRING"}}}},"mint_result":{"fields":{"value":{"type":"bool","id":1}}},"balance_object":{"fields":{"value":{"type":"uint64","id":1,"options":{"jstype":"JS_STRING"}}}},"mana_balance_object":{"fields":{"balance":{"type":"uint64","id":1,"options":{"jstype":"JS_STRING"}},"mana":{"type":"uint64","id":2,"options":{"jstype":"JS_STRING"}},"
|
|
12945
|
+
module.exports = JSON.parse('{"nested":{"koinos":{"nested":{"contracts":{"nested":{"token":{"options":{"go_package":"github.com/koinos/koinos-proto-golang/koinos/contracts/token"},"nested":{"name_arguments":{"fields":{}},"name_result":{"fields":{"value":{"type":"string","id":1}}},"symbol_arguments":{"fields":{}},"symbol_result":{"fields":{"value":{"type":"string","id":1}}},"decimals_arguments":{"fields":{}},"decimals_result":{"fields":{"value":{"type":"uint32","id":1}}},"total_supply_arguments":{"fields":{}},"total_supply_result":{"fields":{"value":{"type":"uint64","id":1,"options":{"jstype":"JS_STRING"}}}},"balance_of_arguments":{"fields":{"owner":{"type":"bytes","id":1,"options":{"(koinos_bytes_type)":"ADDRESS"}}}},"balance_of_result":{"fields":{"value":{"type":"uint64","id":1,"options":{"jstype":"JS_STRING"}}}},"transfer_arguments":{"fields":{"from":{"type":"bytes","id":1,"options":{"(koinos_bytes_type)":"ADDRESS"}},"to":{"type":"bytes","id":2,"options":{"(koinos_bytes_type)":"ADDRESS"}},"value":{"type":"uint64","id":3,"options":{"jstype":"JS_STRING"}}}},"transfer_result":{"fields":{"value":{"type":"bool","id":1}}},"mint_arguments":{"fields":{"to":{"type":"bytes","id":1,"options":{"(koinos_bytes_type)":"ADDRESS"}},"value":{"type":"uint64","id":2,"options":{"jstype":"JS_STRING"}}}},"mint_result":{"fields":{"value":{"type":"bool","id":1}}},"balance_object":{"fields":{"value":{"type":"uint64","id":1,"options":{"jstype":"JS_STRING"}}}},"mana_balance_object":{"fields":{"balance":{"type":"uint64","id":1,"options":{"jstype":"JS_STRING"}},"mana":{"type":"uint64","id":2,"options":{"jstype":"JS_STRING"}},"last_mana_update":{"type":"uint64","id":3,"options":{"jstype":"JS_STRING"}}}}}}}}}}}}');
|
|
12749
12946
|
|
|
12750
12947
|
/***/ }),
|
|
12751
12948
|
|
|
12752
|
-
/***/
|
|
12949
|
+
/***/ 6139:
|
|
12753
12950
|
/***/ ((module) => {
|
|
12754
12951
|
|
|
12755
12952
|
"use strict";
|
|
12756
|
-
module.exports = JSON.parse('{"nested":{"koinos":{"nested":{"protocol":{"options":{"go_package":"github.com/koinos/koinos-proto-golang/koinos/protocol"},"nested":{"contract_call_bundle":{"fields":{"
|
|
12953
|
+
module.exports = JSON.parse('{"nested":{"koinos":{"nested":{"protocol":{"options":{"go_package":"github.com/koinos/koinos-proto-golang/koinos/protocol"},"nested":{"contract_call_bundle":{"fields":{"contract_id":{"type":"bytes","id":1,"options":{"(koinos_bytes_type)":"CONTRACT_ID"}},"entry_point":{"type":"uint32","id":2}}},"system_call_target":{"oneofs":{"target":{"oneof":["thunk_id","system_call_bundle"]}},"fields":{"thunk_id":{"type":"uint32","id":1},"system_call_bundle":{"type":"contract_call_bundle","id":2}}},"upload_contract_operation":{"fields":{"contract_id":{"type":"bytes","id":1,"options":{"(koinos_bytes_type)":"CONTRACT_ID"}},"bytecode":{"type":"bytes","id":2}}},"call_contract_operation":{"fields":{"contract_id":{"type":"bytes","id":1,"options":{"(koinos_bytes_type)":"CONTRACT_ID"}},"entry_point":{"type":"uint32","id":2},"args":{"type":"bytes","id":3}}},"set_system_call_operation":{"fields":{"call_id":{"type":"uint32","id":1},"target":{"type":"system_call_target","id":2}}},"operation":{"oneofs":{"op":{"oneof":["upload_contract","call_contract","set_system_call"]}},"fields":{"upload_contract":{"type":"upload_contract_operation","id":1},"call_contract":{"type":"call_contract_operation","id":2},"set_system_call":{"type":"set_system_call_operation","id":3}}},"active_transaction_data":{"fields":{"rc_limit":{"type":"uint64","id":1,"options":{"jstype":"JS_STRING"}},"nonce":{"type":"uint64","id":2,"options":{"jstype":"JS_STRING"}},"operations":{"rule":"repeated","type":"operation","id":3}}},"passive_transaction_data":{"fields":{}},"transaction":{"fields":{"id":{"type":"bytes","id":1,"options":{"(koinos_bytes_type)":"TRANSACTION_ID"}},"active":{"type":"bytes","id":2},"passive":{"type":"bytes","id":3},"signature_data":{"type":"bytes","id":4}}},"active_block_data":{"fields":{"transaction_merkle_root":{"type":"bytes","id":1},"passive_data_merkle_root":{"type":"bytes","id":2},"signer":{"type":"bytes","id":3}}},"passive_block_data":{"fields":{}},"block_header":{"fields":{"previous":{"type":"bytes","id":1,"options":{"(koinos_bytes_type)":"BLOCK_ID"}},"height":{"type":"uint64","id":2,"options":{"jstype":"JS_STRING"}},"timestamp":{"type":"uint64","id":3,"options":{"jstype":"JS_STRING"}}}},"block":{"fields":{"id":{"type":"bytes","id":1,"options":{"(koinos_bytes_type)":"BLOCK_ID"}},"header":{"type":"block_header","id":2},"active":{"type":"bytes","id":3},"passive":{"type":"bytes","id":4},"signature_data":{"type":"bytes","id":5},"transactions":{"rule":"repeated","type":"transaction","id":6}}},"block_receipt":{"fields":{}}}}}}}}');
|
|
12757
12954
|
|
|
12758
12955
|
/***/ })
|
|
12759
12956
|
|