koilib 2.6.0 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +5 -5
  2. package/dist/koinos.js +178 -688
  3. package/dist/koinos.min.js +1 -1
  4. package/lib/Contract.d.ts +9 -11
  5. package/lib/Contract.js +12 -12
  6. package/lib/Contract.js.map +1 -1
  7. package/lib/Provider.d.ts +24 -17
  8. package/lib/Provider.js +83 -81
  9. package/lib/Provider.js.map +1 -1
  10. package/lib/Serializer.d.ts +6 -2
  11. package/lib/Serializer.js +10 -4
  12. package/lib/Serializer.js.map +1 -1
  13. package/lib/Signer.d.ts +24 -10
  14. package/lib/Signer.js +71 -24
  15. package/lib/Signer.js.map +1 -1
  16. package/lib/browser/Contract.d.ts +200 -0
  17. package/lib/browser/Contract.js +298 -0
  18. package/lib/browser/Contract.js.map +1 -0
  19. package/lib/browser/Provider.d.ts +160 -0
  20. package/lib/browser/Provider.js +246 -0
  21. package/lib/browser/Provider.js.map +1 -0
  22. package/lib/browser/Serializer.d.ts +85 -0
  23. package/lib/browser/Serializer.js +175 -0
  24. package/lib/browser/Serializer.js.map +1 -0
  25. package/lib/browser/Signer.d.ts +310 -0
  26. package/lib/browser/Signer.js +468 -0
  27. package/lib/browser/Signer.js.map +1 -0
  28. package/lib/browser/index.d.ts +7 -0
  29. package/lib/browser/index.js +34 -0
  30. package/lib/browser/index.js.map +1 -0
  31. package/lib/browser/index2.d.ts +2 -0
  32. package/lib/browser/index2.js +33 -0
  33. package/lib/browser/index2.js.map +1 -0
  34. package/lib/browser/interface.d.ts +279 -0
  35. package/lib/browser/interface.js +3 -0
  36. package/lib/browser/interface.js.map +1 -0
  37. package/lib/browser/jsonDescriptors/krc20-proto.json +183 -0
  38. package/lib/browser/jsonDescriptors/protocol-proto.json +246 -0
  39. package/lib/browser/utils.d.ts +326 -0
  40. package/lib/browser/utils.js +252 -0
  41. package/lib/browser/utils.js.map +1 -0
  42. package/lib/interface.d.ts +22 -21
  43. package/package.json +9 -6
package/dist/koinos.js CHANGED
@@ -2887,567 +2887,6 @@ utf8.write = function utf8_write(string, buffer, offset) {
2887
2887
  };
2888
2888
 
2889
2889
 
2890
- /***/ }),
2891
-
2892
- /***/ 4098:
2893
- /***/ (function(module, exports) {
2894
-
2895
- var global = typeof self !== 'undefined' ? self : this;
2896
- var __self__ = (function () {
2897
- function F() {
2898
- this.fetch = false;
2899
- this.DOMException = global.DOMException
2900
- }
2901
- F.prototype = global;
2902
- return new F();
2903
- })();
2904
- (function(self) {
2905
-
2906
- var irrelevant = (function (exports) {
2907
-
2908
- var support = {
2909
- searchParams: 'URLSearchParams' in self,
2910
- iterable: 'Symbol' in self && 'iterator' in Symbol,
2911
- blob:
2912
- 'FileReader' in self &&
2913
- 'Blob' in self &&
2914
- (function() {
2915
- try {
2916
- new Blob();
2917
- return true
2918
- } catch (e) {
2919
- return false
2920
- }
2921
- })(),
2922
- formData: 'FormData' in self,
2923
- arrayBuffer: 'ArrayBuffer' in self
2924
- };
2925
-
2926
- function isDataView(obj) {
2927
- return obj && DataView.prototype.isPrototypeOf(obj)
2928
- }
2929
-
2930
- if (support.arrayBuffer) {
2931
- var viewClasses = [
2932
- '[object Int8Array]',
2933
- '[object Uint8Array]',
2934
- '[object Uint8ClampedArray]',
2935
- '[object Int16Array]',
2936
- '[object Uint16Array]',
2937
- '[object Int32Array]',
2938
- '[object Uint32Array]',
2939
- '[object Float32Array]',
2940
- '[object Float64Array]'
2941
- ];
2942
-
2943
- var isArrayBufferView =
2944
- ArrayBuffer.isView ||
2945
- function(obj) {
2946
- return obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1
2947
- };
2948
- }
2949
-
2950
- function normalizeName(name) {
2951
- if (typeof name !== 'string') {
2952
- name = String(name);
2953
- }
2954
- if (/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(name)) {
2955
- throw new TypeError('Invalid character in header field name')
2956
- }
2957
- return name.toLowerCase()
2958
- }
2959
-
2960
- function normalizeValue(value) {
2961
- if (typeof value !== 'string') {
2962
- value = String(value);
2963
- }
2964
- return value
2965
- }
2966
-
2967
- // Build a destructive iterator for the value list
2968
- function iteratorFor(items) {
2969
- var iterator = {
2970
- next: function() {
2971
- var value = items.shift();
2972
- return {done: value === undefined, value: value}
2973
- }
2974
- };
2975
-
2976
- if (support.iterable) {
2977
- iterator[Symbol.iterator] = function() {
2978
- return iterator
2979
- };
2980
- }
2981
-
2982
- return iterator
2983
- }
2984
-
2985
- function Headers(headers) {
2986
- this.map = {};
2987
-
2988
- if (headers instanceof Headers) {
2989
- headers.forEach(function(value, name) {
2990
- this.append(name, value);
2991
- }, this);
2992
- } else if (Array.isArray(headers)) {
2993
- headers.forEach(function(header) {
2994
- this.append(header[0], header[1]);
2995
- }, this);
2996
- } else if (headers) {
2997
- Object.getOwnPropertyNames(headers).forEach(function(name) {
2998
- this.append(name, headers[name]);
2999
- }, this);
3000
- }
3001
- }
3002
-
3003
- Headers.prototype.append = function(name, value) {
3004
- name = normalizeName(name);
3005
- value = normalizeValue(value);
3006
- var oldValue = this.map[name];
3007
- this.map[name] = oldValue ? oldValue + ', ' + value : value;
3008
- };
3009
-
3010
- Headers.prototype['delete'] = function(name) {
3011
- delete this.map[normalizeName(name)];
3012
- };
3013
-
3014
- Headers.prototype.get = function(name) {
3015
- name = normalizeName(name);
3016
- return this.has(name) ? this.map[name] : null
3017
- };
3018
-
3019
- Headers.prototype.has = function(name) {
3020
- return this.map.hasOwnProperty(normalizeName(name))
3021
- };
3022
-
3023
- Headers.prototype.set = function(name, value) {
3024
- this.map[normalizeName(name)] = normalizeValue(value);
3025
- };
3026
-
3027
- Headers.prototype.forEach = function(callback, thisArg) {
3028
- for (var name in this.map) {
3029
- if (this.map.hasOwnProperty(name)) {
3030
- callback.call(thisArg, this.map[name], name, this);
3031
- }
3032
- }
3033
- };
3034
-
3035
- Headers.prototype.keys = function() {
3036
- var items = [];
3037
- this.forEach(function(value, name) {
3038
- items.push(name);
3039
- });
3040
- return iteratorFor(items)
3041
- };
3042
-
3043
- Headers.prototype.values = function() {
3044
- var items = [];
3045
- this.forEach(function(value) {
3046
- items.push(value);
3047
- });
3048
- return iteratorFor(items)
3049
- };
3050
-
3051
- Headers.prototype.entries = function() {
3052
- var items = [];
3053
- this.forEach(function(value, name) {
3054
- items.push([name, value]);
3055
- });
3056
- return iteratorFor(items)
3057
- };
3058
-
3059
- if (support.iterable) {
3060
- Headers.prototype[Symbol.iterator] = Headers.prototype.entries;
3061
- }
3062
-
3063
- function consumed(body) {
3064
- if (body.bodyUsed) {
3065
- return Promise.reject(new TypeError('Already read'))
3066
- }
3067
- body.bodyUsed = true;
3068
- }
3069
-
3070
- function fileReaderReady(reader) {
3071
- return new Promise(function(resolve, reject) {
3072
- reader.onload = function() {
3073
- resolve(reader.result);
3074
- };
3075
- reader.onerror = function() {
3076
- reject(reader.error);
3077
- };
3078
- })
3079
- }
3080
-
3081
- function readBlobAsArrayBuffer(blob) {
3082
- var reader = new FileReader();
3083
- var promise = fileReaderReady(reader);
3084
- reader.readAsArrayBuffer(blob);
3085
- return promise
3086
- }
3087
-
3088
- function readBlobAsText(blob) {
3089
- var reader = new FileReader();
3090
- var promise = fileReaderReady(reader);
3091
- reader.readAsText(blob);
3092
- return promise
3093
- }
3094
-
3095
- function readArrayBufferAsText(buf) {
3096
- var view = new Uint8Array(buf);
3097
- var chars = new Array(view.length);
3098
-
3099
- for (var i = 0; i < view.length; i++) {
3100
- chars[i] = String.fromCharCode(view[i]);
3101
- }
3102
- return chars.join('')
3103
- }
3104
-
3105
- function bufferClone(buf) {
3106
- if (buf.slice) {
3107
- return buf.slice(0)
3108
- } else {
3109
- var view = new Uint8Array(buf.byteLength);
3110
- view.set(new Uint8Array(buf));
3111
- return view.buffer
3112
- }
3113
- }
3114
-
3115
- function Body() {
3116
- this.bodyUsed = false;
3117
-
3118
- this._initBody = function(body) {
3119
- this._bodyInit = body;
3120
- if (!body) {
3121
- this._bodyText = '';
3122
- } else if (typeof body === 'string') {
3123
- this._bodyText = body;
3124
- } else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
3125
- this._bodyBlob = body;
3126
- } else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
3127
- this._bodyFormData = body;
3128
- } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
3129
- this._bodyText = body.toString();
3130
- } else if (support.arrayBuffer && support.blob && isDataView(body)) {
3131
- this._bodyArrayBuffer = bufferClone(body.buffer);
3132
- // IE 10-11 can't handle a DataView body.
3133
- this._bodyInit = new Blob([this._bodyArrayBuffer]);
3134
- } else if (support.arrayBuffer && (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))) {
3135
- this._bodyArrayBuffer = bufferClone(body);
3136
- } else {
3137
- this._bodyText = body = Object.prototype.toString.call(body);
3138
- }
3139
-
3140
- if (!this.headers.get('content-type')) {
3141
- if (typeof body === 'string') {
3142
- this.headers.set('content-type', 'text/plain;charset=UTF-8');
3143
- } else if (this._bodyBlob && this._bodyBlob.type) {
3144
- this.headers.set('content-type', this._bodyBlob.type);
3145
- } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
3146
- this.headers.set('content-type', 'application/x-www-form-urlencoded;charset=UTF-8');
3147
- }
3148
- }
3149
- };
3150
-
3151
- if (support.blob) {
3152
- this.blob = function() {
3153
- var rejected = consumed(this);
3154
- if (rejected) {
3155
- return rejected
3156
- }
3157
-
3158
- if (this._bodyBlob) {
3159
- return Promise.resolve(this._bodyBlob)
3160
- } else if (this._bodyArrayBuffer) {
3161
- return Promise.resolve(new Blob([this._bodyArrayBuffer]))
3162
- } else if (this._bodyFormData) {
3163
- throw new Error('could not read FormData body as blob')
3164
- } else {
3165
- return Promise.resolve(new Blob([this._bodyText]))
3166
- }
3167
- };
3168
-
3169
- this.arrayBuffer = function() {
3170
- if (this._bodyArrayBuffer) {
3171
- return consumed(this) || Promise.resolve(this._bodyArrayBuffer)
3172
- } else {
3173
- return this.blob().then(readBlobAsArrayBuffer)
3174
- }
3175
- };
3176
- }
3177
-
3178
- this.text = function() {
3179
- var rejected = consumed(this);
3180
- if (rejected) {
3181
- return rejected
3182
- }
3183
-
3184
- if (this._bodyBlob) {
3185
- return readBlobAsText(this._bodyBlob)
3186
- } else if (this._bodyArrayBuffer) {
3187
- return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer))
3188
- } else if (this._bodyFormData) {
3189
- throw new Error('could not read FormData body as text')
3190
- } else {
3191
- return Promise.resolve(this._bodyText)
3192
- }
3193
- };
3194
-
3195
- if (support.formData) {
3196
- this.formData = function() {
3197
- return this.text().then(decode)
3198
- };
3199
- }
3200
-
3201
- this.json = function() {
3202
- return this.text().then(JSON.parse)
3203
- };
3204
-
3205
- return this
3206
- }
3207
-
3208
- // HTTP methods whose capitalization should be normalized
3209
- var methods = ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT'];
3210
-
3211
- function normalizeMethod(method) {
3212
- var upcased = method.toUpperCase();
3213
- return methods.indexOf(upcased) > -1 ? upcased : method
3214
- }
3215
-
3216
- function Request(input, options) {
3217
- options = options || {};
3218
- var body = options.body;
3219
-
3220
- if (input instanceof Request) {
3221
- if (input.bodyUsed) {
3222
- throw new TypeError('Already read')
3223
- }
3224
- this.url = input.url;
3225
- this.credentials = input.credentials;
3226
- if (!options.headers) {
3227
- this.headers = new Headers(input.headers);
3228
- }
3229
- this.method = input.method;
3230
- this.mode = input.mode;
3231
- this.signal = input.signal;
3232
- if (!body && input._bodyInit != null) {
3233
- body = input._bodyInit;
3234
- input.bodyUsed = true;
3235
- }
3236
- } else {
3237
- this.url = String(input);
3238
- }
3239
-
3240
- this.credentials = options.credentials || this.credentials || 'same-origin';
3241
- if (options.headers || !this.headers) {
3242
- this.headers = new Headers(options.headers);
3243
- }
3244
- this.method = normalizeMethod(options.method || this.method || 'GET');
3245
- this.mode = options.mode || this.mode || null;
3246
- this.signal = options.signal || this.signal;
3247
- this.referrer = null;
3248
-
3249
- if ((this.method === 'GET' || this.method === 'HEAD') && body) {
3250
- throw new TypeError('Body not allowed for GET or HEAD requests')
3251
- }
3252
- this._initBody(body);
3253
- }
3254
-
3255
- Request.prototype.clone = function() {
3256
- return new Request(this, {body: this._bodyInit})
3257
- };
3258
-
3259
- function decode(body) {
3260
- var form = new FormData();
3261
- body
3262
- .trim()
3263
- .split('&')
3264
- .forEach(function(bytes) {
3265
- if (bytes) {
3266
- var split = bytes.split('=');
3267
- var name = split.shift().replace(/\+/g, ' ');
3268
- var value = split.join('=').replace(/\+/g, ' ');
3269
- form.append(decodeURIComponent(name), decodeURIComponent(value));
3270
- }
3271
- });
3272
- return form
3273
- }
3274
-
3275
- function parseHeaders(rawHeaders) {
3276
- var headers = new Headers();
3277
- // Replace instances of \r\n and \n followed by at least one space or horizontal tab with a space
3278
- // https://tools.ietf.org/html/rfc7230#section-3.2
3279
- var preProcessedHeaders = rawHeaders.replace(/\r?\n[\t ]+/g, ' ');
3280
- preProcessedHeaders.split(/\r?\n/).forEach(function(line) {
3281
- var parts = line.split(':');
3282
- var key = parts.shift().trim();
3283
- if (key) {
3284
- var value = parts.join(':').trim();
3285
- headers.append(key, value);
3286
- }
3287
- });
3288
- return headers
3289
- }
3290
-
3291
- Body.call(Request.prototype);
3292
-
3293
- function Response(bodyInit, options) {
3294
- if (!options) {
3295
- options = {};
3296
- }
3297
-
3298
- this.type = 'default';
3299
- this.status = options.status === undefined ? 200 : options.status;
3300
- this.ok = this.status >= 200 && this.status < 300;
3301
- this.statusText = 'statusText' in options ? options.statusText : 'OK';
3302
- this.headers = new Headers(options.headers);
3303
- this.url = options.url || '';
3304
- this._initBody(bodyInit);
3305
- }
3306
-
3307
- Body.call(Response.prototype);
3308
-
3309
- Response.prototype.clone = function() {
3310
- return new Response(this._bodyInit, {
3311
- status: this.status,
3312
- statusText: this.statusText,
3313
- headers: new Headers(this.headers),
3314
- url: this.url
3315
- })
3316
- };
3317
-
3318
- Response.error = function() {
3319
- var response = new Response(null, {status: 0, statusText: ''});
3320
- response.type = 'error';
3321
- return response
3322
- };
3323
-
3324
- var redirectStatuses = [301, 302, 303, 307, 308];
3325
-
3326
- Response.redirect = function(url, status) {
3327
- if (redirectStatuses.indexOf(status) === -1) {
3328
- throw new RangeError('Invalid status code')
3329
- }
3330
-
3331
- return new Response(null, {status: status, headers: {location: url}})
3332
- };
3333
-
3334
- exports.DOMException = self.DOMException;
3335
- try {
3336
- new exports.DOMException();
3337
- } catch (err) {
3338
- exports.DOMException = function(message, name) {
3339
- this.message = message;
3340
- this.name = name;
3341
- var error = Error(message);
3342
- this.stack = error.stack;
3343
- };
3344
- exports.DOMException.prototype = Object.create(Error.prototype);
3345
- exports.DOMException.prototype.constructor = exports.DOMException;
3346
- }
3347
-
3348
- function fetch(input, init) {
3349
- return new Promise(function(resolve, reject) {
3350
- var request = new Request(input, init);
3351
-
3352
- if (request.signal && request.signal.aborted) {
3353
- return reject(new exports.DOMException('Aborted', 'AbortError'))
3354
- }
3355
-
3356
- var xhr = new XMLHttpRequest();
3357
-
3358
- function abortXhr() {
3359
- xhr.abort();
3360
- }
3361
-
3362
- xhr.onload = function() {
3363
- var options = {
3364
- status: xhr.status,
3365
- statusText: xhr.statusText,
3366
- headers: parseHeaders(xhr.getAllResponseHeaders() || '')
3367
- };
3368
- options.url = 'responseURL' in xhr ? xhr.responseURL : options.headers.get('X-Request-URL');
3369
- var body = 'response' in xhr ? xhr.response : xhr.responseText;
3370
- resolve(new Response(body, options));
3371
- };
3372
-
3373
- xhr.onerror = function() {
3374
- reject(new TypeError('Network request failed'));
3375
- };
3376
-
3377
- xhr.ontimeout = function() {
3378
- reject(new TypeError('Network request failed'));
3379
- };
3380
-
3381
- xhr.onabort = function() {
3382
- reject(new exports.DOMException('Aborted', 'AbortError'));
3383
- };
3384
-
3385
- xhr.open(request.method, request.url, true);
3386
-
3387
- if (request.credentials === 'include') {
3388
- xhr.withCredentials = true;
3389
- } else if (request.credentials === 'omit') {
3390
- xhr.withCredentials = false;
3391
- }
3392
-
3393
- if ('responseType' in xhr && support.blob) {
3394
- xhr.responseType = 'blob';
3395
- }
3396
-
3397
- request.headers.forEach(function(value, name) {
3398
- xhr.setRequestHeader(name, value);
3399
- });
3400
-
3401
- if (request.signal) {
3402
- request.signal.addEventListener('abort', abortXhr);
3403
-
3404
- xhr.onreadystatechange = function() {
3405
- // DONE (success or failure)
3406
- if (xhr.readyState === 4) {
3407
- request.signal.removeEventListener('abort', abortXhr);
3408
- }
3409
- };
3410
- }
3411
-
3412
- xhr.send(typeof request._bodyInit === 'undefined' ? null : request._bodyInit);
3413
- })
3414
- }
3415
-
3416
- fetch.polyfill = true;
3417
-
3418
- if (!self.fetch) {
3419
- self.fetch = fetch;
3420
- self.Headers = Headers;
3421
- self.Request = Request;
3422
- self.Response = Response;
3423
- }
3424
-
3425
- exports.Headers = Headers;
3426
- exports.Request = Request;
3427
- exports.Response = Response;
3428
- exports.fetch = fetch;
3429
-
3430
- Object.defineProperty(exports, '__esModule', { value: true });
3431
-
3432
- return exports;
3433
-
3434
- }({}));
3435
- })(__self__);
3436
- __self__.fetch.ponyfill = true;
3437
- // Remove "polyfill" property added by whatwg-fetch
3438
- delete __self__.fetch.polyfill;
3439
- // Choose between native implementation (global) or custom implementation (__self__)
3440
- // var ctx = global.fetch ? global : __self__;
3441
- var ctx = __self__; // this line disable service worker support temporarily
3442
- exports = ctx.fetch // To enable: import fetch from 'cross-fetch'
3443
- exports["default"] = ctx.fetch // For TypeScript consumers without esModuleInterop.
3444
- exports.fetch = ctx.fetch // To enable: import {fetch} from 'cross-fetch'
3445
- exports.Headers = ctx.Headers
3446
- exports.Request = ctx.Request
3447
- exports.Response = ctx.Response
3448
- module.exports = exports
3449
-
3450
-
3451
2890
  /***/ }),
3452
2891
 
3453
2892
  /***/ 556:
@@ -10357,15 +9796,15 @@ const utils_1 = __webpack_require__(8593);
10357
9796
  * console.log(result)
10358
9797
  *
10359
9798
  * // Transfer
10360
- * const { transaction, transactionResponse } = await koin.transfer({
9799
+ * const { transaction } = await koin.transfer({
10361
9800
  * to: "172AB1FgCsYrRAW5cwQ8KjadgxofvgPFd6",
10362
9801
  * value: "10.0001",
10363
9802
  * });
10364
9803
  * console.log(`Transaction id ${transaction.id} submitted`);
10365
9804
  *
10366
9805
  * // wait to be mined
10367
- * const blockId = await transactionResponse.wait();
10368
- * console.log(`Transaction mined. Block id: ${blockId}`);
9806
+ * const blockNumber = await transaction.wait();
9807
+ * console.log(`Transaction mined. Block number: ${blockNumber}`);
10369
9808
  * }
10370
9809
  *
10371
9810
  * main();
@@ -10443,7 +9882,7 @@ class Contract {
10443
9882
  // write contract (sign and send)
10444
9883
  if (!this.signer)
10445
9884
  throw new Error("signer not found");
10446
- const transaction = await this.signer.encodeTransaction({
9885
+ const tx = await this.signer.encodeTransaction({
10447
9886
  ...opts,
10448
9887
  operations: [operation],
10449
9888
  });
@@ -10452,8 +9891,8 @@ class Contract {
10452
9891
  const contractId = (0, utils_1.encodeBase58)(this.id);
10453
9892
  abis[contractId] = this.abi;
10454
9893
  }
10455
- const transactionResponse = await this.signer.sendTransaction(transaction, abis);
10456
- return { operation, transaction, transactionResponse };
9894
+ const transaction = await this.signer.sendTransaction(tx, abis);
9895
+ return { operation, transaction };
10457
9896
  };
10458
9897
  });
10459
9898
  }
@@ -10482,10 +9921,10 @@ class Contract {
10482
9921
  * const signer = new Signer({ privateKey, provider });
10483
9922
  * const bytecode = new Uint8Array([1, 2, 3, 4]);
10484
9923
  * const contract = new Contract({ signer, provider, bytecode });
10485
- * const { transactionResponse } = await contract.deploy();
9924
+ * const { transaction } = await contract.deploy();
10486
9925
  * // wait to be mined
10487
- * const blockId = await transactionResponse.wait();
10488
- * console.log(`Contract uploaded in block id ${blockId}`);
9926
+ * const blockNumber = await transaction.wait();
9927
+ * console.log(`Contract uploaded in block number ${blockNumber}`);
10489
9928
  * ```
10490
9929
  */
10491
9930
  async deploy(options) {
@@ -10506,12 +9945,12 @@ class Contract {
10506
9945
  // return operation if send is false
10507
9946
  if (!(opts === null || opts === void 0 ? void 0 : opts.sendTransaction))
10508
9947
  return { operation };
10509
- const transaction = await this.signer.encodeTransaction({
9948
+ const tx = await this.signer.encodeTransaction({
10510
9949
  ...opts,
10511
9950
  operations: [operation],
10512
9951
  });
10513
- const transactionResponse = await this.signer.sendTransaction(transaction);
10514
- return { operation, transaction, transactionResponse };
9952
+ const transaction = await this.signer.sendTransaction(tx);
9953
+ return { operation, transaction };
10515
9954
  }
10516
9955
  /**
10517
9956
  * Encondes a contract operation using Koinos serialization
@@ -10616,16 +10055,12 @@ exports["default"] = Contract;
10616
10055
  /***/ }),
10617
10056
 
10618
10057
  /***/ 5635:
10619
- /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
10058
+ /***/ ((__unused_webpack_module, exports) => {
10620
10059
 
10621
10060
  "use strict";
10622
10061
 
10623
- var __importDefault = (this && this.__importDefault) || function (mod) {
10624
- return (mod && mod.__esModule) ? mod : { "default": mod };
10625
- };
10626
10062
  Object.defineProperty(exports, "__esModule", ({ value: true }));
10627
10063
  exports.Provider = void 0;
10628
- const cross_fetch_1 = __importDefault(__webpack_require__(4098));
10629
10064
  async function sleep(ms) {
10630
10065
  return new Promise((r) => setTimeout(r, ms));
10631
10066
  }
@@ -10671,7 +10106,7 @@ class Provider {
10671
10106
  params,
10672
10107
  };
10673
10108
  const url = this.rpcNodes[this.currentNodeId];
10674
- const response = await (0, cross_fetch_1.default)(url, {
10109
+ const response = await fetch(url, {
10675
10110
  method: "POST",
10676
10111
  body: JSON.stringify(data),
10677
10112
  });
@@ -10767,93 +10202,95 @@ class Provider {
10767
10202
  return (await this.getBlocks(height, 1))[0];
10768
10203
  }
10769
10204
  /**
10770
- * Function to call "chain.submit_transaction" to send a signed
10771
- * transaction to the blockchain. It returns an object with the async
10772
- * function "wait", which can be called to wait for the
10773
- * transaction to be mined (see [[SendTransactionResponse]]).
10774
- * @param transaction - Signed transaction
10205
+ * Function to wait for a transaction to be mined.
10206
+ * @param txId - transaction id
10207
+ * @param type - Type must be "byBlock" (default) or "byTransactionId".
10208
+ * _byBlock_ will query the blockchain to get blocks and search for the
10209
+ * transaction there. _byTransactionId_ will query the "transaction store"
10210
+ * microservice to search the transaction by its id. If non of them is
10211
+ * specified the function will use "byBlock" (as "byTransactionId"
10212
+ * requires the transaction store, which is an optional microservice).
10213
+ *
10214
+ * When _byBlock_ is used it returns the block number.
10215
+ *
10216
+ * When _byTransactionId_ is used it returns the block id.
10217
+ *
10218
+ * @param timeout - Timeout in milliseconds. By default it is 30000
10775
10219
  * @example
10776
10220
  * ```ts
10777
- * const { transactionResponse } = await provider.sendTransaction({
10778
- * id: "1220...",
10779
- * active: "...",
10780
- * signatureData: "...",
10781
- * });
10782
- * console.log("Transaction submitted to the mempool");
10783
- * // wait to be mined
10784
- * const blockNumber = await transactionResponse.wait();
10785
- * // const blockNumber = await transactionResponse.wait("byBlock", 30000);
10786
- * // const blockId = await transactionResponse.wait("byTransactionId", 30000);
10221
+ * const blockNumber = await provider.wait(txId);
10222
+ * // const blockNumber = await provider.wait(txId, "byBlock", 30000);
10223
+ * // const blockId = await provider.wait(txId, "byTransactionId", 30000);
10787
10224
  * console.log("Transaction mined")
10788
10225
  * ```
10789
10226
  */
10790
- async sendTransaction(transaction) {
10791
- await this.call("chain.submit_transaction", { transaction });
10792
- return {
10793
- wait: async (type = "byBlock", timeout = 30000) => {
10794
- const iniTime = Date.now();
10795
- if (type === "byTransactionId") {
10796
- while (Date.now() < iniTime + timeout) {
10797
- await sleep(1000);
10798
- const { transactions } = await this.getTransactionsById([
10799
- transaction.id,
10800
- ]);
10801
- if (transactions &&
10802
- transactions[0] &&
10803
- transactions[0].containing_blocks)
10804
- return transactions[0].containing_blocks[0];
10805
- }
10806
- throw new Error(`Transaction not mined after ${timeout} ms`);
10807
- }
10808
- // byBlock
10809
- const findTxInBlocks = async (ini, numBlocks, idRef) => {
10810
- const blocks = await this.getBlocks(ini, numBlocks, idRef);
10811
- let bNum = 0;
10812
- blocks.forEach((block) => {
10813
- if (!block ||
10814
- !block.block ||
10815
- !block.block_id ||
10816
- !block.block.transactions)
10817
- return;
10818
- const tx = block.block.transactions.find((t) => t.id === transaction.id);
10819
- if (tx)
10820
- bNum = Number(block.block_height);
10821
- });
10822
- const lastId = blocks[blocks.length - 1].block_id;
10823
- return [bNum, lastId];
10824
- };
10825
- let blockNumber = 0;
10826
- let iniBlock = 0;
10827
- let previousId = "";
10828
- while (Date.now() < iniTime + timeout) {
10829
- await sleep(1000);
10830
- const { head_topology: headTopology } = await this.getHeadInfo();
10831
- if (blockNumber === 0) {
10832
- blockNumber = Number(headTopology.height);
10833
- iniBlock = blockNumber;
10834
- }
10835
- if (Number(headTopology.height) === blockNumber - 1 &&
10836
- previousId &&
10837
- previousId !== headTopology.id) {
10838
- const [bNum, lastId] = await findTxInBlocks(iniBlock, Number(headTopology.height) - iniBlock + 1, headTopology.id);
10839
- if (bNum)
10840
- return bNum;
10841
- previousId = lastId;
10842
- blockNumber = Number(headTopology.height) + 1;
10843
- }
10844
- // eslint-disable-next-line no-continue
10845
- if (blockNumber > Number(headTopology.height))
10846
- continue;
10847
- const [bNum, lastId] = await findTxInBlocks(blockNumber, 1, headTopology.id);
10848
- if (bNum)
10849
- return bNum;
10850
- if (!previousId)
10851
- previousId = lastId;
10852
- blockNumber += 1;
10853
- }
10854
- throw new Error(`Transaction not mined after ${timeout} ms. Blocks checked from ${iniBlock} to ${blockNumber}`);
10855
- },
10227
+ async wait(txId, type = "byBlock", timeout = 30000) {
10228
+ const iniTime = Date.now();
10229
+ if (type === "byTransactionId") {
10230
+ while (Date.now() < iniTime + timeout) {
10231
+ await sleep(1000);
10232
+ const { transactions } = await this.getTransactionsById([txId]);
10233
+ if (transactions &&
10234
+ transactions[0] &&
10235
+ transactions[0].containing_blocks)
10236
+ return transactions[0].containing_blocks[0];
10237
+ }
10238
+ throw new Error(`Transaction not mined after ${timeout} ms`);
10239
+ }
10240
+ // byBlock
10241
+ const findTxInBlocks = async (ini, numBlocks, idRef) => {
10242
+ const blocks = await this.getBlocks(ini, numBlocks, idRef);
10243
+ let bNum = 0;
10244
+ blocks.forEach((block) => {
10245
+ if (!block ||
10246
+ !block.block ||
10247
+ !block.block_id ||
10248
+ !block.block.transactions)
10249
+ return;
10250
+ const tx = block.block.transactions.find((t) => t.id === txId);
10251
+ if (tx)
10252
+ bNum = Number(block.block_height);
10253
+ });
10254
+ const lastId = blocks[blocks.length - 1].block_id;
10255
+ return [bNum, lastId];
10856
10256
  };
10257
+ let blockNumber = 0;
10258
+ let iniBlock = 0;
10259
+ let previousId = "";
10260
+ while (Date.now() < iniTime + timeout) {
10261
+ await sleep(1000);
10262
+ const { head_topology: headTopology } = await this.getHeadInfo();
10263
+ if (blockNumber === 0) {
10264
+ blockNumber = Number(headTopology.height);
10265
+ iniBlock = blockNumber;
10266
+ }
10267
+ if (Number(headTopology.height) === blockNumber - 1 &&
10268
+ previousId &&
10269
+ previousId !== headTopology.id) {
10270
+ const [bNum, lastId] = await findTxInBlocks(iniBlock, Number(headTopology.height) - iniBlock + 1, headTopology.id);
10271
+ if (bNum)
10272
+ return bNum;
10273
+ previousId = lastId;
10274
+ blockNumber = Number(headTopology.height) + 1;
10275
+ }
10276
+ // eslint-disable-next-line no-continue
10277
+ if (blockNumber > Number(headTopology.height))
10278
+ continue;
10279
+ const [bNum, lastId] = await findTxInBlocks(blockNumber, 1, headTopology.id);
10280
+ if (bNum)
10281
+ return bNum;
10282
+ if (!previousId)
10283
+ previousId = lastId;
10284
+ blockNumber += 1;
10285
+ }
10286
+ throw new Error(`Transaction not mined after ${timeout} ms. Blocks checked from ${iniBlock} to ${blockNumber}`);
10287
+ }
10288
+ /**
10289
+ * Function to call "chain.submit_transaction" to send a signed
10290
+ * transaction to the blockchain.
10291
+ */
10292
+ async sendTransaction(transaction) {
10293
+ return this.call("chain.submit_transaction", { transaction });
10857
10294
  }
10858
10295
  /**
10859
10296
  * Function to call "chain.read_contract" to read a contract.
@@ -10949,10 +10386,13 @@ class Serializer {
10949
10386
  * It also prepares the bytes for special cases (base58, hex string)
10950
10387
  * when bytesConversion param is true.
10951
10388
  */
10952
- async serialize(valueDecoded, typeName) {
10389
+ async serialize(valueDecoded, typeName, opts) {
10953
10390
  const protobufType = this.defaultType || this.root.lookupType(typeName);
10954
10391
  let object = {};
10955
- if (this.bytesConversion) {
10392
+ const bytesConversion = (opts === null || opts === void 0 ? void 0 : opts.bytesConversion) === undefined
10393
+ ? this.bytesConversion
10394
+ : opts.bytesConversion;
10395
+ if (bytesConversion) {
10956
10396
  // TODO: format from Buffer to base58/base64 for nested fields
10957
10397
  Object.keys(protobufType.fields).forEach((fieldName) => {
10958
10398
  const { options, name, type } = protobufType.fields[fieldName];
@@ -10998,14 +10438,17 @@ class Serializer {
10998
10438
  * It also encodes the bytes for special cases (base58, hex string)
10999
10439
  * when bytesConversion param is true.
11000
10440
  */
11001
- async deserialize(valueEncoded, typeName) {
10441
+ async deserialize(valueEncoded, typeName, opts) {
11002
10442
  const valueBuffer = typeof valueEncoded === "string"
11003
10443
  ? (0, utils_1.decodeBase64)(valueEncoded)
11004
10444
  : valueEncoded;
11005
10445
  const protobufType = this.defaultType || this.root.lookupType(typeName);
11006
10446
  const message = protobufType.decode(valueBuffer);
11007
10447
  const object = protobufType.toObject(message, { longs: String });
11008
- if (!this.bytesConversion)
10448
+ const bytesConversion = (opts === null || opts === void 0 ? void 0 : opts.bytesConversion) === undefined
10449
+ ? this.bytesConversion
10450
+ : opts.bytesConversion;
10451
+ if (!bytesConversion)
11009
10452
  return object;
11010
10453
  // TODO: format from Buffer to base58/base64 for nested fields
11011
10454
  Object.keys(protobufType.fields).forEach((fieldName) => {
@@ -11161,7 +10604,6 @@ class Signer {
11161
10604
  }
11162
10605
  else {
11163
10606
  this.serializer = new Serializer_1.Serializer(protocol_proto_json_1.default, {
11164
- defaultTypeName: "active_transaction_data",
11165
10607
  bytesConversion: false,
11166
10608
  });
11167
10609
  }
@@ -11263,15 +10705,12 @@ class Signer {
11263
10705
  }
11264
10706
  }
11265
10707
  /**
11266
- * Function to sign a transaction. It's important to remark that
11267
- * the transaction parameter is modified inside this function.
11268
- * @param tx - Unsigned transaction
11269
- * @returns
10708
+ * Function to sign a hash value. It returns the signature encoded
10709
+ * in base64. The signature is in compact format with the
10710
+ * recovery byte
10711
+ * @param hash Hash value. Also known as digest
11270
10712
  */
11271
- async signTransaction(tx) {
11272
- if (!tx.active)
11273
- throw new Error("Active data is not defined");
11274
- const hash = (0, sha256_1.sha256)((0, utils_1.decodeBase64)(tx.active));
10713
+ async signHash(hash) {
11275
10714
  const [compSignature, recovery] = await secp.sign(hash, this.privateKey, {
11276
10715
  recovered: true,
11277
10716
  canonical: true,
@@ -11280,11 +10719,41 @@ class Signer {
11280
10719
  const compactSignature = new Uint8Array(65);
11281
10720
  compactSignature.set([recovery + 31], 0);
11282
10721
  compactSignature.set(compSignature, 1);
11283
- tx.signature_data = (0, utils_1.encodeBase64)(compactSignature);
11284
- const multihash = `0x1220${(0, utils_1.toHexString)(hash)}`; // 12: code sha2-256. 20: length (32 bytes)
11285
- tx.id = multihash;
10722
+ return (0, utils_1.encodeBase64)(compactSignature);
10723
+ }
10724
+ /**
10725
+ * Function to sign a transaction. It's important to remark that
10726
+ * the transaction parameter is modified inside this function.
10727
+ * @param tx - Unsigned transaction
10728
+ */
10729
+ async signTransaction(tx) {
10730
+ if (!tx.active)
10731
+ throw new Error("Active data is not defined");
10732
+ const hash = (0, sha256_1.sha256)((0, utils_1.decodeBase64)(tx.active));
10733
+ tx.signature_data = await this.signHash(hash);
10734
+ // multihash 0x1220. 12: code sha2-256. 20: length (32 bytes)
10735
+ tx.id = `0x1220${(0, utils_1.toHexString)(hash)}`;
11286
10736
  return tx;
11287
10737
  }
10738
+ /**
10739
+ * Function to sign a block for federated consensus. That is,
10740
+ * just the ecdsa signature. For other algorithms, like PoW,
10741
+ * you have to sign the block and then process the signature
10742
+ * to add the extra data (nonce in the case of PoW).
10743
+ * @param block - Unsigned block
10744
+ */
10745
+ async signBlock(block) {
10746
+ const activeBytes = (0, utils_1.decodeBase64)(block.active);
10747
+ const headerBytes = await this.serializer.serialize(block.header, "block_header", { bytesConversion: true });
10748
+ const headerActiveBytes = new Uint8Array(headerBytes.length + activeBytes.length);
10749
+ headerActiveBytes.set(headerBytes, 0);
10750
+ headerActiveBytes.set(activeBytes, headerBytes.length);
10751
+ const hash = (0, sha256_1.sha256)(headerActiveBytes);
10752
+ block.signature_data = await this.signHash(hash);
10753
+ // multihash 0x1220. 12: code sha2-256. 20: length (32 bytes)
10754
+ block.id = `0x1220${(0, utils_1.toHexString)(hash)}`;
10755
+ return block;
10756
+ }
11288
10757
  /**
11289
10758
  * Function to sign and send a transaction. It internally uses
11290
10759
  * [[Provider.sendTransaction]]
@@ -11299,7 +10768,15 @@ class Signer {
11299
10768
  await this.signTransaction(tx);
11300
10769
  if (!this.provider)
11301
10770
  throw new Error("provider is undefined");
11302
- return this.provider.sendTransaction(tx);
10771
+ await this.provider.sendTransaction(tx);
10772
+ return {
10773
+ ...tx,
10774
+ wait: async (type = "byBlock", timeout = 30000) => {
10775
+ if (!this.provider)
10776
+ throw new Error("provider is undefined");
10777
+ return this.provider.wait(tx.id, type, timeout);
10778
+ },
10779
+ };
11303
10780
  }
11304
10781
  /**
11305
10782
  * Function to recover the public key from a signed
@@ -11342,7 +10819,7 @@ class Signer {
11342
10819
  * defaultTypeName: "pow_signature_data",
11343
10820
  * });
11344
10821
  *
11345
- * const signer = await Signer.recoverPublicKey(block, {
10822
+ * const signer = await signer.recoverPublicKey(block, {
11346
10823
  * transformSignature: async (signatureData) => {
11347
10824
  * const powSignatureData = await serializer.deserialize(signatureData);
11348
10825
  * return powSignatureData.recoverable_signature;
@@ -11350,7 +10827,7 @@ class Signer {
11350
10827
  * });
11351
10828
  * ```
11352
10829
  */
11353
- static async recoverPublicKey(txOrBlock, opts) {
10830
+ async recoverPublicKey(txOrBlock, opts) {
11354
10831
  if (!txOrBlock.active)
11355
10832
  throw new Error("active is not defined");
11356
10833
  if (!txOrBlock.signature_data)
@@ -11363,7 +10840,20 @@ class Signer {
11363
10840
  if (opts && typeof opts.compressed !== "undefined") {
11364
10841
  compressed = opts.compressed;
11365
10842
  }
11366
- const hash = (0, sha256_1.sha256)((0, utils_1.decodeBase64)(txOrBlock.active));
10843
+ const block = txOrBlock;
10844
+ let hash;
10845
+ const activeBytes = (0, utils_1.decodeBase64)(block.active);
10846
+ if (block.header) {
10847
+ const headerBytes = await this.serializer.serialize(block.header, "block_header", { bytesConversion: true });
10848
+ const headerActiveBytes = new Uint8Array(headerBytes.length + activeBytes.length);
10849
+ headerActiveBytes.set(headerBytes, 0);
10850
+ headerActiveBytes.set(activeBytes, headerBytes.length);
10851
+ hash = (0, sha256_1.sha256)(headerActiveBytes);
10852
+ }
10853
+ else {
10854
+ // transaction
10855
+ hash = (0, sha256_1.sha256)(activeBytes);
10856
+ }
11367
10857
  const compactSignatureHex = (0, utils_1.toHexString)((0, utils_1.decodeBase64)(signatureData));
11368
10858
  const recovery = Number(`0x${compactSignatureHex.slice(0, 2)}`) - 31;
11369
10859
  const rHex = compactSignatureHex.slice(2, 66);
@@ -11384,7 +10874,7 @@ class Signer {
11384
10874
  * The output format can be compressed (default) or uncompressed.
11385
10875
  * @example
11386
10876
  * ```ts
11387
- * const publicKey = await Signer.recoverAddress(tx);
10877
+ * const publicKey = await signer.recoverAddress(tx);
11388
10878
  * ```
11389
10879
  *
11390
10880
  * If the signature data contains more data, like in the
@@ -11418,7 +10908,7 @@ class Signer {
11418
10908
  * defaultTypeName: "pow_signature_data",
11419
10909
  * });
11420
10910
  *
11421
- * const signer = await Signer.recoverAddress(block, {
10911
+ * const signer = await signer.recoverAddress(block, {
11422
10912
  * transformSignature: async (signatureData) => {
11423
10913
  * const powSignatureData = await serializer.deserialize(signatureData);
11424
10914
  * return powSignatureData.recoverable_signature;
@@ -11426,15 +10916,15 @@ class Signer {
11426
10916
  * });
11427
10917
  * ```
11428
10918
  */
11429
- static async recoverAddress(txOrBlock, opts) {
11430
- const publicKey = await Signer.recoverPublicKey(txOrBlock, opts);
10919
+ async recoverAddress(txOrBlock, opts) {
10920
+ const publicKey = await this.recoverPublicKey(txOrBlock, opts);
11431
10921
  return (0, utils_1.bitcoinAddress)((0, utils_1.toUint8Array)(publicKey));
11432
10922
  }
11433
10923
  /**
11434
10924
  * Function to encode a transaction
11435
10925
  * @param activeData - Active data consists of nonce, rc_limit, and
11436
10926
  * operations. Do not set the nonce to get it from the blockchain
11437
- * using the provider. The rc_limit is 1000000 by default.
10927
+ * using the provider. The rc_limit is 1e8 by default.
11438
10928
  * @returns A transaction encoded. The active field is encoded in
11439
10929
  * base64url
11440
10930
  */
@@ -11447,14 +10937,14 @@ class Signer {
11447
10937
  // this depends on the final architecture for names on Koinos
11448
10938
  nonce = await this.provider.getNonce(this.getAddress());
11449
10939
  }
11450
- const rcLimit = activeData.rc_limit === undefined ? 1000000 : activeData.rc_limit;
10940
+ const rcLimit = activeData.rc_limit === undefined ? 1e8 : activeData.rc_limit;
11451
10941
  const operations = activeData.operations ? activeData.operations : [];
11452
10942
  const activeData2 = {
11453
10943
  rc_limit: rcLimit,
11454
10944
  nonce,
11455
10945
  operations,
11456
10946
  };
11457
- const buffer = await this.serializer.serialize(activeData2);
10947
+ const buffer = await this.serializer.serialize(activeData2, "active_transaction_data");
11458
10948
  return {
11459
10949
  active: (0, utils_1.encodeBase64)(buffer),
11460
10950
  };
@@ -11465,7 +10955,7 @@ class Signer {
11465
10955
  async decodeTransaction(tx) {
11466
10956
  if (!tx.active)
11467
10957
  throw new Error("Active data is not defined");
11468
- return this.serializer.deserialize(tx.active);
10958
+ return this.serializer.deserialize(tx.active, "active_transaction_data");
11469
10959
  }
11470
10960
  }
11471
10961
  exports.Signer = Signer;