@solana/web3.js 1.20.1 → 1.20.3

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.
@@ -1,13 +1,12 @@
1
1
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
2
  import * as nacl from 'tweetnacl';
3
3
  import nacl__default from 'tweetnacl';
4
- import { Buffer, isBuffer } from 'buffer';
4
+ import { Buffer } from 'buffer';
5
5
  import BN from 'bn.js';
6
6
  import bs58 from 'bs58';
7
7
  import { sha256 } from 'crypto-hash';
8
8
  import { serialize, deserialize, deserializeUnchecked } from 'borsh';
9
9
  import * as BufferLayout from '@solana/buffer-layout';
10
- import fetch from 'node-fetch';
11
10
  import { coerce, instance, string, tuple, literal, unknown, union, type, optional, any, number, array, nullable, create, boolean, record, assert as assert$1 } from 'superstruct';
12
11
  import { Client } from 'rpc-websockets';
13
12
  import RpcClient from 'jayson/lib/client/browser';
@@ -341,900 +340,6 @@ class Account {
341
340
 
342
341
  const BPF_LOADER_DEPRECATED_PROGRAM_ID = new PublicKey('BPFLoader1111111111111111111111111111111111');
343
342
 
344
- var global$1 = (typeof global !== "undefined" ? global :
345
- typeof self !== "undefined" ? self :
346
- typeof window !== "undefined" ? window : {});
347
-
348
- var inherits;
349
- if (typeof Object.create === 'function'){
350
- inherits = function inherits(ctor, superCtor) {
351
- // implementation from standard node.js 'util' module
352
- ctor.super_ = superCtor;
353
- ctor.prototype = Object.create(superCtor.prototype, {
354
- constructor: {
355
- value: ctor,
356
- enumerable: false,
357
- writable: true,
358
- configurable: true
359
- }
360
- });
361
- };
362
- } else {
363
- inherits = function inherits(ctor, superCtor) {
364
- ctor.super_ = superCtor;
365
- var TempCtor = function () {};
366
- TempCtor.prototype = superCtor.prototype;
367
- ctor.prototype = new TempCtor();
368
- ctor.prototype.constructor = ctor;
369
- };
370
- }
371
- var inherits$1 = inherits;
372
-
373
- /**
374
- * Echos the value of a value. Trys to print the value out
375
- * in the best way possible given the different types.
376
- *
377
- * @param {Object} obj The object to print out.
378
- * @param {Object} opts Optional options object that alters the output.
379
- */
380
- /* legacy: obj, showHidden, depth, colors*/
381
- function inspect$1(obj, opts) {
382
- // default options
383
- var ctx = {
384
- seen: [],
385
- stylize: stylizeNoColor
386
- };
387
- // legacy...
388
- if (arguments.length >= 3) ctx.depth = arguments[2];
389
- if (arguments.length >= 4) ctx.colors = arguments[3];
390
- if (isBoolean(opts)) {
391
- // legacy...
392
- ctx.showHidden = opts;
393
- } else if (opts) {
394
- // got an "options" object
395
- _extend(ctx, opts);
396
- }
397
- // set default options
398
- if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
399
- if (isUndefined(ctx.depth)) ctx.depth = 2;
400
- if (isUndefined(ctx.colors)) ctx.colors = false;
401
- if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
402
- if (ctx.colors) ctx.stylize = stylizeWithColor;
403
- return formatValue(ctx, obj, ctx.depth);
404
- }
405
-
406
- // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
407
- inspect$1.colors = {
408
- 'bold' : [1, 22],
409
- 'italic' : [3, 23],
410
- 'underline' : [4, 24],
411
- 'inverse' : [7, 27],
412
- 'white' : [37, 39],
413
- 'grey' : [90, 39],
414
- 'black' : [30, 39],
415
- 'blue' : [34, 39],
416
- 'cyan' : [36, 39],
417
- 'green' : [32, 39],
418
- 'magenta' : [35, 39],
419
- 'red' : [31, 39],
420
- 'yellow' : [33, 39]
421
- };
422
-
423
- // Don't use 'blue' not visible on cmd.exe
424
- inspect$1.styles = {
425
- 'special': 'cyan',
426
- 'number': 'yellow',
427
- 'boolean': 'yellow',
428
- 'undefined': 'grey',
429
- 'null': 'bold',
430
- 'string': 'green',
431
- 'date': 'magenta',
432
- // "name": intentionally not styling
433
- 'regexp': 'red'
434
- };
435
-
436
-
437
- function stylizeWithColor(str, styleType) {
438
- var style = inspect$1.styles[styleType];
439
-
440
- if (style) {
441
- return '\u001b[' + inspect$1.colors[style][0] + 'm' + str +
442
- '\u001b[' + inspect$1.colors[style][1] + 'm';
443
- } else {
444
- return str;
445
- }
446
- }
447
-
448
-
449
- function stylizeNoColor(str, styleType) {
450
- return str;
451
- }
452
-
453
-
454
- function arrayToHash(array) {
455
- var hash = {};
456
-
457
- array.forEach(function(val, idx) {
458
- hash[val] = true;
459
- });
460
-
461
- return hash;
462
- }
463
-
464
-
465
- function formatValue(ctx, value, recurseTimes) {
466
- // Provide a hook for user-specified inspect functions.
467
- // Check that value is an object with an inspect function on it
468
- if (ctx.customInspect &&
469
- value &&
470
- isFunction(value.inspect) &&
471
- // Filter out the util module, it's inspect function is special
472
- value.inspect !== inspect$1 &&
473
- // Also filter out any prototype objects using the circular check.
474
- !(value.constructor && value.constructor.prototype === value)) {
475
- var ret = value.inspect(recurseTimes, ctx);
476
- if (!isString(ret)) {
477
- ret = formatValue(ctx, ret, recurseTimes);
478
- }
479
- return ret;
480
- }
481
-
482
- // Primitive types cannot have properties
483
- var primitive = formatPrimitive(ctx, value);
484
- if (primitive) {
485
- return primitive;
486
- }
487
-
488
- // Look up the keys of the object.
489
- var keys = Object.keys(value);
490
- var visibleKeys = arrayToHash(keys);
491
-
492
- if (ctx.showHidden) {
493
- keys = Object.getOwnPropertyNames(value);
494
- }
495
-
496
- // IE doesn't make error fields non-enumerable
497
- // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
498
- if (isError(value)
499
- && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
500
- return formatError(value);
501
- }
502
-
503
- // Some type of object without properties can be shortcutted.
504
- if (keys.length === 0) {
505
- if (isFunction(value)) {
506
- var name = value.name ? ': ' + value.name : '';
507
- return ctx.stylize('[Function' + name + ']', 'special');
508
- }
509
- if (isRegExp(value)) {
510
- return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
511
- }
512
- if (isDate(value)) {
513
- return ctx.stylize(Date.prototype.toString.call(value), 'date');
514
- }
515
- if (isError(value)) {
516
- return formatError(value);
517
- }
518
- }
519
-
520
- var base = '', array = false, braces = ['{', '}'];
521
-
522
- // Make Array say that they are Array
523
- if (isArray$1(value)) {
524
- array = true;
525
- braces = ['[', ']'];
526
- }
527
-
528
- // Make functions say that they are functions
529
- if (isFunction(value)) {
530
- var n = value.name ? ': ' + value.name : '';
531
- base = ' [Function' + n + ']';
532
- }
533
-
534
- // Make RegExps say that they are RegExps
535
- if (isRegExp(value)) {
536
- base = ' ' + RegExp.prototype.toString.call(value);
537
- }
538
-
539
- // Make dates with properties first say the date
540
- if (isDate(value)) {
541
- base = ' ' + Date.prototype.toUTCString.call(value);
542
- }
543
-
544
- // Make error with message first say the error
545
- if (isError(value)) {
546
- base = ' ' + formatError(value);
547
- }
548
-
549
- if (keys.length === 0 && (!array || value.length == 0)) {
550
- return braces[0] + base + braces[1];
551
- }
552
-
553
- if (recurseTimes < 0) {
554
- if (isRegExp(value)) {
555
- return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
556
- } else {
557
- return ctx.stylize('[Object]', 'special');
558
- }
559
- }
560
-
561
- ctx.seen.push(value);
562
-
563
- var output;
564
- if (array) {
565
- output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
566
- } else {
567
- output = keys.map(function(key) {
568
- return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
569
- });
570
- }
571
-
572
- ctx.seen.pop();
573
-
574
- return reduceToSingleString(output, base, braces);
575
- }
576
-
577
-
578
- function formatPrimitive(ctx, value) {
579
- if (isUndefined(value))
580
- return ctx.stylize('undefined', 'undefined');
581
- if (isString(value)) {
582
- var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
583
- .replace(/'/g, "\\'")
584
- .replace(/\\"/g, '"') + '\'';
585
- return ctx.stylize(simple, 'string');
586
- }
587
- if (isNumber(value))
588
- return ctx.stylize('' + value, 'number');
589
- if (isBoolean(value))
590
- return ctx.stylize('' + value, 'boolean');
591
- // For some reason typeof null is "object", so special case here.
592
- if (isNull(value))
593
- return ctx.stylize('null', 'null');
594
- }
595
-
596
-
597
- function formatError(value) {
598
- return '[' + Error.prototype.toString.call(value) + ']';
599
- }
600
-
601
-
602
- function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
603
- var output = [];
604
- for (var i = 0, l = value.length; i < l; ++i) {
605
- if (hasOwnProperty$1(value, String(i))) {
606
- output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
607
- String(i), true));
608
- } else {
609
- output.push('');
610
- }
611
- }
612
- keys.forEach(function(key) {
613
- if (!key.match(/^\d+$/)) {
614
- output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
615
- key, true));
616
- }
617
- });
618
- return output;
619
- }
620
-
621
-
622
- function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
623
- var name, str, desc;
624
- desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
625
- if (desc.get) {
626
- if (desc.set) {
627
- str = ctx.stylize('[Getter/Setter]', 'special');
628
- } else {
629
- str = ctx.stylize('[Getter]', 'special');
630
- }
631
- } else {
632
- if (desc.set) {
633
- str = ctx.stylize('[Setter]', 'special');
634
- }
635
- }
636
- if (!hasOwnProperty$1(visibleKeys, key)) {
637
- name = '[' + key + ']';
638
- }
639
- if (!str) {
640
- if (ctx.seen.indexOf(desc.value) < 0) {
641
- if (isNull(recurseTimes)) {
642
- str = formatValue(ctx, desc.value, null);
643
- } else {
644
- str = formatValue(ctx, desc.value, recurseTimes - 1);
645
- }
646
- if (str.indexOf('\n') > -1) {
647
- if (array) {
648
- str = str.split('\n').map(function(line) {
649
- return ' ' + line;
650
- }).join('\n').substr(2);
651
- } else {
652
- str = '\n' + str.split('\n').map(function(line) {
653
- return ' ' + line;
654
- }).join('\n');
655
- }
656
- }
657
- } else {
658
- str = ctx.stylize('[Circular]', 'special');
659
- }
660
- }
661
- if (isUndefined(name)) {
662
- if (array && key.match(/^\d+$/)) {
663
- return str;
664
- }
665
- name = JSON.stringify('' + key);
666
- if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
667
- name = name.substr(1, name.length - 2);
668
- name = ctx.stylize(name, 'name');
669
- } else {
670
- name = name.replace(/'/g, "\\'")
671
- .replace(/\\"/g, '"')
672
- .replace(/(^"|"$)/g, "'");
673
- name = ctx.stylize(name, 'string');
674
- }
675
- }
676
-
677
- return name + ': ' + str;
678
- }
679
-
680
-
681
- function reduceToSingleString(output, base, braces) {
682
- var length = output.reduce(function(prev, cur) {
683
- if (cur.indexOf('\n') >= 0) ;
684
- return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
685
- }, 0);
686
-
687
- if (length > 60) {
688
- return braces[0] +
689
- (base === '' ? '' : base + '\n ') +
690
- ' ' +
691
- output.join(',\n ') +
692
- ' ' +
693
- braces[1];
694
- }
695
-
696
- return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
697
- }
698
-
699
-
700
- // NOTE: These type checking functions intentionally don't use `instanceof`
701
- // because it is fragile and can be easily faked with `Object.create()`.
702
- function isArray$1(ar) {
703
- return Array.isArray(ar);
704
- }
705
-
706
- function isBoolean(arg) {
707
- return typeof arg === 'boolean';
708
- }
709
-
710
- function isNull(arg) {
711
- return arg === null;
712
- }
713
-
714
- function isNullOrUndefined(arg) {
715
- return arg == null;
716
- }
717
-
718
- function isNumber(arg) {
719
- return typeof arg === 'number';
720
- }
721
-
722
- function isString(arg) {
723
- return typeof arg === 'string';
724
- }
725
-
726
- function isUndefined(arg) {
727
- return arg === void 0;
728
- }
729
-
730
- function isRegExp(re) {
731
- return isObject(re) && objectToString(re) === '[object RegExp]';
732
- }
733
-
734
- function isObject(arg) {
735
- return typeof arg === 'object' && arg !== null;
736
- }
737
-
738
- function isDate(d) {
739
- return isObject(d) && objectToString(d) === '[object Date]';
740
- }
741
-
742
- function isError(e) {
743
- return isObject(e) &&
744
- (objectToString(e) === '[object Error]' || e instanceof Error);
745
- }
746
-
747
- function isFunction(arg) {
748
- return typeof arg === 'function';
749
- }
750
-
751
- function isPrimitive(arg) {
752
- return arg === null ||
753
- typeof arg === 'boolean' ||
754
- typeof arg === 'number' ||
755
- typeof arg === 'string' ||
756
- typeof arg === 'symbol' || // ES6 symbol
757
- typeof arg === 'undefined';
758
- }
759
-
760
- function objectToString(o) {
761
- return Object.prototype.toString.call(o);
762
- }
763
-
764
- function _extend(origin, add) {
765
- // Don't do anything if add isn't an object
766
- if (!add || !isObject(add)) return origin;
767
-
768
- var keys = Object.keys(add);
769
- var i = keys.length;
770
- while (i--) {
771
- origin[keys[i]] = add[keys[i]];
772
- }
773
- return origin;
774
- }
775
- function hasOwnProperty$1(obj, prop) {
776
- return Object.prototype.hasOwnProperty.call(obj, prop);
777
- }
778
-
779
- function compare(a, b) {
780
- if (a === b) {
781
- return 0;
782
- }
783
-
784
- var x = a.length;
785
- var y = b.length;
786
-
787
- for (var i = 0, len = Math.min(x, y); i < len; ++i) {
788
- if (a[i] !== b[i]) {
789
- x = a[i];
790
- y = b[i];
791
- break;
792
- }
793
- }
794
-
795
- if (x < y) {
796
- return -1;
797
- }
798
- if (y < x) {
799
- return 1;
800
- }
801
- return 0;
802
- }
803
- var hasOwn = Object.prototype.hasOwnProperty;
804
-
805
- var objectKeys$1 = Object.keys || function (obj) {
806
- var keys = [];
807
- for (var key in obj) {
808
- if (hasOwn.call(obj, key)) keys.push(key);
809
- }
810
- return keys;
811
- };
812
- var pSlice = Array.prototype.slice;
813
- var _functionsHaveNames;
814
- function functionsHaveNames() {
815
- if (typeof _functionsHaveNames !== 'undefined') {
816
- return _functionsHaveNames;
817
- }
818
- return _functionsHaveNames = (function () {
819
- return function foo() {}.name === 'foo';
820
- }());
821
- }
822
- function pToString (obj) {
823
- return Object.prototype.toString.call(obj);
824
- }
825
- function isView(arrbuf) {
826
- if (isBuffer(arrbuf)) {
827
- return false;
828
- }
829
- if (typeof global$1.ArrayBuffer !== 'function') {
830
- return false;
831
- }
832
- if (typeof ArrayBuffer.isView === 'function') {
833
- return ArrayBuffer.isView(arrbuf);
834
- }
835
- if (!arrbuf) {
836
- return false;
837
- }
838
- if (arrbuf instanceof DataView) {
839
- return true;
840
- }
841
- if (arrbuf.buffer && arrbuf.buffer instanceof ArrayBuffer) {
842
- return true;
843
- }
844
- return false;
845
- }
846
- // 1. The assert module provides functions that throw
847
- // AssertionError's when particular conditions are not met. The
848
- // assert module must conform to the following interface.
849
-
850
- function assert(value, message) {
851
- if (!value) fail(value, true, message, '==', ok);
852
- }
853
-
854
- // 2. The AssertionError is defined in assert.
855
- // new assert.AssertionError({ message: message,
856
- // actual: actual,
857
- // expected: expected })
858
-
859
- var regex = /\s*function\s+([^\(\s]*)\s*/;
860
- // based on https://github.com/ljharb/function.prototype.name/blob/adeeeec8bfcc6068b187d7d9fb3d5bb1d3a30899/implementation.js
861
- function getName(func) {
862
- if (!isFunction(func)) {
863
- return;
864
- }
865
- if (functionsHaveNames()) {
866
- return func.name;
867
- }
868
- var str = func.toString();
869
- var match = str.match(regex);
870
- return match && match[1];
871
- }
872
- assert.AssertionError = AssertionError;
873
- function AssertionError(options) {
874
- this.name = 'AssertionError';
875
- this.actual = options.actual;
876
- this.expected = options.expected;
877
- this.operator = options.operator;
878
- if (options.message) {
879
- this.message = options.message;
880
- this.generatedMessage = false;
881
- } else {
882
- this.message = getMessage(this);
883
- this.generatedMessage = true;
884
- }
885
- var stackStartFunction = options.stackStartFunction || fail;
886
- if (Error.captureStackTrace) {
887
- Error.captureStackTrace(this, stackStartFunction);
888
- } else {
889
- // non v8 browsers so we can have a stacktrace
890
- var err = new Error();
891
- if (err.stack) {
892
- var out = err.stack;
893
-
894
- // try to strip useless frames
895
- var fn_name = getName(stackStartFunction);
896
- var idx = out.indexOf('\n' + fn_name);
897
- if (idx >= 0) {
898
- // once we have located the function frame
899
- // we need to strip out everything before it (and its line)
900
- var next_line = out.indexOf('\n', idx + 1);
901
- out = out.substring(next_line + 1);
902
- }
903
-
904
- this.stack = out;
905
- }
906
- }
907
- }
908
-
909
- // assert.AssertionError instanceof Error
910
- inherits$1(AssertionError, Error);
911
-
912
- function truncate(s, n) {
913
- if (typeof s === 'string') {
914
- return s.length < n ? s : s.slice(0, n);
915
- } else {
916
- return s;
917
- }
918
- }
919
- function inspect(something) {
920
- if (functionsHaveNames() || !isFunction(something)) {
921
- return inspect$1(something);
922
- }
923
- var rawname = getName(something);
924
- var name = rawname ? ': ' + rawname : '';
925
- return '[Function' + name + ']';
926
- }
927
- function getMessage(self) {
928
- return truncate(inspect(self.actual), 128) + ' ' +
929
- self.operator + ' ' +
930
- truncate(inspect(self.expected), 128);
931
- }
932
-
933
- // At present only the three keys mentioned above are used and
934
- // understood by the spec. Implementations or sub modules can pass
935
- // other keys to the AssertionError's constructor - they will be
936
- // ignored.
937
-
938
- // 3. All of the following functions must throw an AssertionError
939
- // when a corresponding condition is not met, with a message that
940
- // may be undefined if not provided. All assertion methods provide
941
- // both the actual and expected values to the assertion error for
942
- // display purposes.
943
-
944
- function fail(actual, expected, message, operator, stackStartFunction) {
945
- throw new AssertionError({
946
- message: message,
947
- actual: actual,
948
- expected: expected,
949
- operator: operator,
950
- stackStartFunction: stackStartFunction
951
- });
952
- }
953
-
954
- // EXTENSION! allows for well behaved errors defined elsewhere.
955
- assert.fail = fail;
956
-
957
- // 4. Pure assertion tests whether a value is truthy, as determined
958
- // by !!guard.
959
- // assert.ok(guard, message_opt);
960
- // This statement is equivalent to assert.equal(true, !!guard,
961
- // message_opt);. To test strictly for the value true, use
962
- // assert.strictEqual(true, guard, message_opt);.
963
-
964
- function ok(value, message) {
965
- if (!value) fail(value, true, message, '==', ok);
966
- }
967
- assert.ok = ok;
968
-
969
- // 5. The equality assertion tests shallow, coercive equality with
970
- // ==.
971
- // assert.equal(actual, expected, message_opt);
972
- assert.equal = equal;
973
- function equal(actual, expected, message) {
974
- if (actual != expected) fail(actual, expected, message, '==', equal);
975
- }
976
-
977
- // 6. The non-equality assertion tests for whether two objects are not equal
978
- // with != assert.notEqual(actual, expected, message_opt);
979
- assert.notEqual = notEqual;
980
- function notEqual(actual, expected, message) {
981
- if (actual == expected) {
982
- fail(actual, expected, message, '!=', notEqual);
983
- }
984
- }
985
-
986
- // 7. The equivalence assertion tests a deep equality relation.
987
- // assert.deepEqual(actual, expected, message_opt);
988
- assert.deepEqual = deepEqual;
989
- function deepEqual(actual, expected, message) {
990
- if (!_deepEqual(actual, expected, false)) {
991
- fail(actual, expected, message, 'deepEqual', deepEqual);
992
- }
993
- }
994
- assert.deepStrictEqual = deepStrictEqual;
995
- function deepStrictEqual(actual, expected, message) {
996
- if (!_deepEqual(actual, expected, true)) {
997
- fail(actual, expected, message, 'deepStrictEqual', deepStrictEqual);
998
- }
999
- }
1000
-
1001
- function _deepEqual(actual, expected, strict, memos) {
1002
- // 7.1. All identical values are equivalent, as determined by ===.
1003
- if (actual === expected) {
1004
- return true;
1005
- } else if (isBuffer(actual) && isBuffer(expected)) {
1006
- return compare(actual, expected) === 0;
1007
-
1008
- // 7.2. If the expected value is a Date object, the actual value is
1009
- // equivalent if it is also a Date object that refers to the same time.
1010
- } else if (isDate(actual) && isDate(expected)) {
1011
- return actual.getTime() === expected.getTime();
1012
-
1013
- // 7.3 If the expected value is a RegExp object, the actual value is
1014
- // equivalent if it is also a RegExp object with the same source and
1015
- // properties (`global`, `multiline`, `lastIndex`, `ignoreCase`).
1016
- } else if (isRegExp(actual) && isRegExp(expected)) {
1017
- return actual.source === expected.source &&
1018
- actual.global === expected.global &&
1019
- actual.multiline === expected.multiline &&
1020
- actual.lastIndex === expected.lastIndex &&
1021
- actual.ignoreCase === expected.ignoreCase;
1022
-
1023
- // 7.4. Other pairs that do not both pass typeof value == 'object',
1024
- // equivalence is determined by ==.
1025
- } else if ((actual === null || typeof actual !== 'object') &&
1026
- (expected === null || typeof expected !== 'object')) {
1027
- return strict ? actual === expected : actual == expected;
1028
-
1029
- // If both values are instances of typed arrays, wrap their underlying
1030
- // ArrayBuffers in a Buffer each to increase performance
1031
- // This optimization requires the arrays to have the same type as checked by
1032
- // Object.prototype.toString (aka pToString). Never perform binary
1033
- // comparisons for Float*Arrays, though, since e.g. +0 === -0 but their
1034
- // bit patterns are not identical.
1035
- } else if (isView(actual) && isView(expected) &&
1036
- pToString(actual) === pToString(expected) &&
1037
- !(actual instanceof Float32Array ||
1038
- actual instanceof Float64Array)) {
1039
- return compare(new Uint8Array(actual.buffer),
1040
- new Uint8Array(expected.buffer)) === 0;
1041
-
1042
- // 7.5 For all other Object pairs, including Array objects, equivalence is
1043
- // determined by having the same number of owned properties (as verified
1044
- // with Object.prototype.hasOwnProperty.call), the same set of keys
1045
- // (although not necessarily the same order), equivalent values for every
1046
- // corresponding key, and an identical 'prototype' property. Note: this
1047
- // accounts for both named and indexed properties on Arrays.
1048
- } else if (isBuffer(actual) !== isBuffer(expected)) {
1049
- return false;
1050
- } else {
1051
- memos = memos || {actual: [], expected: []};
1052
-
1053
- var actualIndex = memos.actual.indexOf(actual);
1054
- if (actualIndex !== -1) {
1055
- if (actualIndex === memos.expected.indexOf(expected)) {
1056
- return true;
1057
- }
1058
- }
1059
-
1060
- memos.actual.push(actual);
1061
- memos.expected.push(expected);
1062
-
1063
- return objEquiv(actual, expected, strict, memos);
1064
- }
1065
- }
1066
-
1067
- function isArguments(object) {
1068
- return Object.prototype.toString.call(object) == '[object Arguments]';
1069
- }
1070
-
1071
- function objEquiv(a, b, strict, actualVisitedObjects) {
1072
- if (a === null || a === undefined || b === null || b === undefined)
1073
- return false;
1074
- // if one is a primitive, the other must be same
1075
- if (isPrimitive(a) || isPrimitive(b))
1076
- return a === b;
1077
- if (strict && Object.getPrototypeOf(a) !== Object.getPrototypeOf(b))
1078
- return false;
1079
- var aIsArgs = isArguments(a);
1080
- var bIsArgs = isArguments(b);
1081
- if ((aIsArgs && !bIsArgs) || (!aIsArgs && bIsArgs))
1082
- return false;
1083
- if (aIsArgs) {
1084
- a = pSlice.call(a);
1085
- b = pSlice.call(b);
1086
- return _deepEqual(a, b, strict);
1087
- }
1088
- var ka = objectKeys$1(a);
1089
- var kb = objectKeys$1(b);
1090
- var key, i;
1091
- // having the same number of owned properties (keys incorporates
1092
- // hasOwnProperty)
1093
- if (ka.length !== kb.length)
1094
- return false;
1095
- //the same set of keys (although not necessarily the same order),
1096
- ka.sort();
1097
- kb.sort();
1098
- //~~~cheap key test
1099
- for (i = ka.length - 1; i >= 0; i--) {
1100
- if (ka[i] !== kb[i])
1101
- return false;
1102
- }
1103
- //equivalent values for every corresponding key, and
1104
- //~~~possibly expensive deep test
1105
- for (i = ka.length - 1; i >= 0; i--) {
1106
- key = ka[i];
1107
- if (!_deepEqual(a[key], b[key], strict, actualVisitedObjects))
1108
- return false;
1109
- }
1110
- return true;
1111
- }
1112
-
1113
- // 8. The non-equivalence assertion tests for any deep inequality.
1114
- // assert.notDeepEqual(actual, expected, message_opt);
1115
- assert.notDeepEqual = notDeepEqual;
1116
- function notDeepEqual(actual, expected, message) {
1117
- if (_deepEqual(actual, expected, false)) {
1118
- fail(actual, expected, message, 'notDeepEqual', notDeepEqual);
1119
- }
1120
- }
1121
-
1122
- assert.notDeepStrictEqual = notDeepStrictEqual;
1123
- function notDeepStrictEqual(actual, expected, message) {
1124
- if (_deepEqual(actual, expected, true)) {
1125
- fail(actual, expected, message, 'notDeepStrictEqual', notDeepStrictEqual);
1126
- }
1127
- }
1128
-
1129
-
1130
- // 9. The strict equality assertion tests strict equality, as determined by ===.
1131
- // assert.strictEqual(actual, expected, message_opt);
1132
- assert.strictEqual = strictEqual;
1133
- function strictEqual(actual, expected, message) {
1134
- if (actual !== expected) {
1135
- fail(actual, expected, message, '===', strictEqual);
1136
- }
1137
- }
1138
-
1139
- // 10. The strict non-equality assertion tests for strict inequality, as
1140
- // determined by !==. assert.notStrictEqual(actual, expected, message_opt);
1141
- assert.notStrictEqual = notStrictEqual;
1142
- function notStrictEqual(actual, expected, message) {
1143
- if (actual === expected) {
1144
- fail(actual, expected, message, '!==', notStrictEqual);
1145
- }
1146
- }
1147
-
1148
- function expectedException(actual, expected) {
1149
- if (!actual || !expected) {
1150
- return false;
1151
- }
1152
-
1153
- if (Object.prototype.toString.call(expected) == '[object RegExp]') {
1154
- return expected.test(actual);
1155
- }
1156
-
1157
- try {
1158
- if (actual instanceof expected) {
1159
- return true;
1160
- }
1161
- } catch (e) {
1162
- // Ignore. The instanceof check doesn't work for arrow functions.
1163
- }
1164
-
1165
- if (Error.isPrototypeOf(expected)) {
1166
- return false;
1167
- }
1168
-
1169
- return expected.call({}, actual) === true;
1170
- }
1171
-
1172
- function _tryBlock(block) {
1173
- var error;
1174
- try {
1175
- block();
1176
- } catch (e) {
1177
- error = e;
1178
- }
1179
- return error;
1180
- }
1181
-
1182
- function _throws(shouldThrow, block, expected, message) {
1183
- var actual;
1184
-
1185
- if (typeof block !== 'function') {
1186
- throw new TypeError('"block" argument must be a function');
1187
- }
1188
-
1189
- if (typeof expected === 'string') {
1190
- message = expected;
1191
- expected = null;
1192
- }
1193
-
1194
- actual = _tryBlock(block);
1195
-
1196
- message = (expected && expected.name ? ' (' + expected.name + ').' : '.') +
1197
- (message ? ' ' + message : '.');
1198
-
1199
- if (shouldThrow && !actual) {
1200
- fail(actual, expected, 'Missing expected exception' + message);
1201
- }
1202
-
1203
- var userProvidedMessage = typeof message === 'string';
1204
- var isUnwantedException = !shouldThrow && isError(actual);
1205
- var isUnexpectedException = !shouldThrow && actual && !expected;
1206
-
1207
- if ((isUnwantedException &&
1208
- userProvidedMessage &&
1209
- expectedException(actual, expected)) ||
1210
- isUnexpectedException) {
1211
- fail(actual, expected, 'Got unwanted exception' + message);
1212
- }
1213
-
1214
- if ((shouldThrow && actual && expected &&
1215
- !expectedException(actual, expected)) || (!shouldThrow && actual)) {
1216
- throw actual;
1217
- }
1218
- }
1219
-
1220
- // 11. Expected to throw an error:
1221
- // assert.throws(block, Error_opt, message_opt);
1222
- assert.throws = throws;
1223
- function throws(block, /*optional*/error, /*optional*/message) {
1224
- _throws(true, block, error, message);
1225
- }
1226
-
1227
- // EXTENSION! This is annoying to write outside this module.
1228
- assert.doesNotThrow = doesNotThrow;
1229
- function doesNotThrow(block, /*optional*/error, /*optional*/message) {
1230
- _throws(false, block, error, message);
1231
- }
1232
-
1233
- assert.ifError = ifError;
1234
- function ifError(err) {
1235
- if (err) throw err;
1236
- }
1237
-
1238
343
  /**
1239
344
  * Layout for a public key
1240
345
  */
@@ -1331,6 +436,36 @@ function encodeLength(bytes, len) {
1331
436
  }
1332
437
  }
1333
438
 
439
+ const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
440
+ /**
441
+ * Delegates to `Array#shift`, but throws if the array is zero-length.
442
+ */
443
+
444
+ function guardedShift(byteArray) {
445
+ if (byteArray.length === 0) {
446
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
447
+ }
448
+
449
+ return byteArray.shift();
450
+ }
451
+ /**
452
+ * Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
453
+ * the array.
454
+ */
455
+
456
+ function guardedSplice(byteArray, ...args) {
457
+ var _args$;
458
+
459
+ const [start] = args;
460
+
461
+ if (args.length === 2 // Implies that `deleteCount` was supplied
462
+ ? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
463
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
464
+ }
465
+
466
+ return byteArray.splice(...args);
467
+ }
468
+
1334
469
  /**
1335
470
  * The message header, identifying signed and read-only account
1336
471
  */
@@ -1415,32 +550,28 @@ class Message {
1415
550
  static from(buffer) {
1416
551
  // Slice up wire data
1417
552
  let byteArray = [...buffer];
1418
- const numRequiredSignatures = byteArray.shift();
1419
- const numReadonlySignedAccounts = byteArray.shift();
1420
- const numReadonlyUnsignedAccounts = byteArray.shift();
553
+ const numRequiredSignatures = guardedShift(byteArray);
554
+ const numReadonlySignedAccounts = guardedShift(byteArray);
555
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
1421
556
  const accountCount = decodeLength(byteArray);
1422
557
  let accountKeys = [];
1423
558
 
1424
559
  for (let i = 0; i < accountCount; i++) {
1425
- const account = byteArray.slice(0, PUBKEY_LENGTH);
1426
- byteArray = byteArray.slice(PUBKEY_LENGTH);
560
+ const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
1427
561
  accountKeys.push(bs58.encode(Buffer.from(account)));
1428
562
  }
1429
563
 
1430
- const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
1431
- byteArray = byteArray.slice(PUBKEY_LENGTH);
564
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
1432
565
  const instructionCount = decodeLength(byteArray);
1433
566
  let instructions = [];
1434
567
 
1435
568
  for (let i = 0; i < instructionCount; i++) {
1436
- const programIdIndex = byteArray.shift();
569
+ const programIdIndex = guardedShift(byteArray);
1437
570
  const accountCount = decodeLength(byteArray);
1438
- const accounts = byteArray.slice(0, accountCount);
1439
- byteArray = byteArray.slice(accountCount);
571
+ const accounts = guardedSplice(byteArray, 0, accountCount);
1440
572
  const dataLength = decodeLength(byteArray);
1441
- const dataSlice = byteArray.slice(0, dataLength);
573
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
1442
574
  const data = bs58.encode(Buffer.from(dataSlice));
1443
- byteArray = byteArray.slice(dataLength);
1444
575
  instructions.push({
1445
576
  programIdIndex,
1446
577
  accounts,
@@ -1463,6 +594,16 @@ class Message {
1463
594
 
1464
595
  }
1465
596
 
597
+ function assert (condition, message) {
598
+ if (!condition) {
599
+ throw new Error(message || 'Assertion failed');
600
+ }
601
+ }
602
+
603
+ /**
604
+ * Transaction signature as base-58 encoded string
605
+ */
606
+
1466
607
  /**
1467
608
  * Default (empty) signature
1468
609
  *
@@ -2056,8 +1197,7 @@ class Transaction {
2056
1197
  let signatures = [];
2057
1198
 
2058
1199
  for (let i = 0; i < signatureCount; i++) {
2059
- const signature = byteArray.slice(0, SIGNATURE_LENGTH);
2060
- byteArray = byteArray.slice(SIGNATURE_LENGTH);
1200
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
2061
1201
  signatures.push(bs58.encode(Buffer.from(signature)));
2062
1202
  }
2063
1203
 
@@ -3151,1110 +2291,36 @@ class BpfLoader {
3151
2291
 
3152
2292
  }
3153
2293
 
3154
- /** Highest positive signed 32-bit float value */
3155
- const maxInt = 2147483647; // aka. 0x7FFFFFFF or 2^31-1
3156
-
3157
- /** Bootstring parameters */
3158
- const base = 36;
3159
- const tMin = 1;
3160
- const tMax = 26;
3161
- const skew = 38;
3162
- const damp = 700;
3163
- const initialBias = 72;
3164
- const initialN = 128; // 0x80
3165
- const delimiter = '-'; // '\x2D'
3166
- const regexNonASCII = /[^\0-\x7E]/; // non-ASCII chars
3167
- const regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g; // RFC 3490 separators
3168
-
3169
- /** Error messages */
3170
- const errors = {
3171
- 'overflow': 'Overflow: input needs wider integers to process',
3172
- 'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
3173
- 'invalid-input': 'Invalid input'
3174
- };
3175
-
3176
- /** Convenience shortcuts */
3177
- const baseMinusTMin = base - tMin;
3178
- const floor = Math.floor;
3179
- const stringFromCharCode = String.fromCharCode;
3180
-
3181
- /*--------------------------------------------------------------------------*/
3182
-
3183
- /**
3184
- * A generic error utility function.
3185
- * @private
3186
- * @param {String} type The error type.
3187
- * @returns {Error} Throws a `RangeError` with the applicable error message.
3188
- */
3189
- function error(type) {
3190
- throw new RangeError(errors[type]);
3191
- }
3192
-
3193
- /**
3194
- * A generic `Array#map` utility function.
3195
- * @private
3196
- * @param {Array} array The array to iterate over.
3197
- * @param {Function} callback The function that gets called for every array
3198
- * item.
3199
- * @returns {Array} A new array of values returned by the callback function.
3200
- */
3201
- function map$1(array, fn) {
3202
- const result = [];
3203
- let length = array.length;
3204
- while (length--) {
3205
- result[length] = fn(array[length]);
3206
- }
3207
- return result;
3208
- }
3209
-
3210
- /**
3211
- * A simple `Array#map`-like wrapper to work with domain name strings or email
3212
- * addresses.
3213
- * @private
3214
- * @param {String} domain The domain name or email address.
3215
- * @param {Function} callback The function that gets called for every
3216
- * character.
3217
- * @returns {Array} A new string of characters returned by the callback
3218
- * function.
3219
- */
3220
- function mapDomain(string, fn) {
3221
- const parts = string.split('@');
3222
- let result = '';
3223
- if (parts.length > 1) {
3224
- // In email addresses, only the domain name should be punycoded. Leave
3225
- // the local part (i.e. everything up to `@`) intact.
3226
- result = parts[0] + '@';
3227
- string = parts[1];
3228
- }
3229
- // Avoid `split(regex)` for IE8 compatibility. See #17.
3230
- string = string.replace(regexSeparators, '\x2E');
3231
- const labels = string.split('.');
3232
- const encoded = map$1(labels, fn).join('.');
3233
- return result + encoded;
3234
- }
3235
-
3236
- /**
3237
- * Creates an array containing the numeric code points of each Unicode
3238
- * character in the string. While JavaScript uses UCS-2 internally,
3239
- * this function will convert a pair of surrogate halves (each of which
3240
- * UCS-2 exposes as separate characters) into a single code point,
3241
- * matching UTF-16.
3242
- * @see `punycode.ucs2.encode`
3243
- * @see <https://mathiasbynens.be/notes/javascript-encoding>
3244
- * @memberOf punycode.ucs2
3245
- * @name decode
3246
- * @param {String} string The Unicode input string (UCS-2).
3247
- * @returns {Array} The new array of code points.
3248
- */
3249
- function ucs2decode(string) {
3250
- const output = [];
3251
- let counter = 0;
3252
- const length = string.length;
3253
- while (counter < length) {
3254
- const value = string.charCodeAt(counter++);
3255
- if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
3256
- // It's a high surrogate, and there is a next character.
3257
- const extra = string.charCodeAt(counter++);
3258
- if ((extra & 0xFC00) == 0xDC00) { // Low surrogate.
3259
- output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
3260
- } else {
3261
- // It's an unmatched surrogate; only append this code unit, in case the
3262
- // next code unit is the high surrogate of a surrogate pair.
3263
- output.push(value);
3264
- counter--;
3265
- }
3266
- } else {
3267
- output.push(value);
3268
- }
3269
- }
3270
- return output;
3271
- }
3272
-
3273
- /**
3274
- * Converts a digit/integer into a basic code point.
3275
- * @see `basicToDigit()`
3276
- * @private
3277
- * @param {Number} digit The numeric value of a basic code point.
3278
- * @returns {Number} The basic code point whose value (when used for
3279
- * representing integers) is `digit`, which needs to be in the range
3280
- * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
3281
- * used; else, the lowercase form is used. The behavior is undefined
3282
- * if `flag` is non-zero and `digit` has no uppercase form.
3283
- */
3284
- const digitToBasic = function(digit, flag) {
3285
- // 0..25 map to ASCII a..z or A..Z
3286
- // 26..35 map to ASCII 0..9
3287
- return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
3288
- };
3289
-
3290
- /**
3291
- * Bias adaptation function as per section 3.4 of RFC 3492.
3292
- * https://tools.ietf.org/html/rfc3492#section-3.4
3293
- * @private
3294
- */
3295
- const adapt = function(delta, numPoints, firstTime) {
3296
- let k = 0;
3297
- delta = firstTime ? floor(delta / damp) : delta >> 1;
3298
- delta += floor(delta / numPoints);
3299
- for (/* no initialization */; delta > baseMinusTMin * tMax >> 1; k += base) {
3300
- delta = floor(delta / baseMinusTMin);
3301
- }
3302
- return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
3303
- };
3304
-
3305
- /**
3306
- * Converts a string of Unicode symbols (e.g. a domain name label) to a
3307
- * Punycode string of ASCII-only symbols.
3308
- * @memberOf punycode
3309
- * @param {String} input The string of Unicode symbols.
3310
- * @returns {String} The resulting Punycode string of ASCII-only symbols.
3311
- */
3312
- const encode = function(input) {
3313
- const output = [];
3314
-
3315
- // Convert the input in UCS-2 to an array of Unicode code points.
3316
- input = ucs2decode(input);
3317
-
3318
- // Cache the length.
3319
- let inputLength = input.length;
3320
-
3321
- // Initialize the state.
3322
- let n = initialN;
3323
- let delta = 0;
3324
- let bias = initialBias;
3325
-
3326
- // Handle the basic code points.
3327
- for (const currentValue of input) {
3328
- if (currentValue < 0x80) {
3329
- output.push(stringFromCharCode(currentValue));
3330
- }
3331
- }
3332
-
3333
- let basicLength = output.length;
3334
- let handledCPCount = basicLength;
3335
-
3336
- // `handledCPCount` is the number of code points that have been handled;
3337
- // `basicLength` is the number of basic code points.
3338
-
3339
- // Finish the basic string with a delimiter unless it's empty.
3340
- if (basicLength) {
3341
- output.push(delimiter);
3342
- }
3343
-
3344
- // Main encoding loop:
3345
- while (handledCPCount < inputLength) {
3346
-
3347
- // All non-basic code points < n have been handled already. Find the next
3348
- // larger one:
3349
- let m = maxInt;
3350
- for (const currentValue of input) {
3351
- if (currentValue >= n && currentValue < m) {
3352
- m = currentValue;
3353
- }
3354
- }
3355
-
3356
- // Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
3357
- // but guard against overflow.
3358
- const handledCPCountPlusOne = handledCPCount + 1;
3359
- if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
3360
- error('overflow');
3361
- }
3362
-
3363
- delta += (m - n) * handledCPCountPlusOne;
3364
- n = m;
3365
-
3366
- for (const currentValue of input) {
3367
- if (currentValue < n && ++delta > maxInt) {
3368
- error('overflow');
3369
- }
3370
- if (currentValue == n) {
3371
- // Represent delta as a generalized variable-length integer.
3372
- let q = delta;
3373
- for (let k = base; /* no condition */; k += base) {
3374
- const t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
3375
- if (q < t) {
3376
- break;
3377
- }
3378
- const qMinusT = q - t;
3379
- const baseMinusT = base - t;
3380
- output.push(
3381
- stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0))
3382
- );
3383
- q = floor(qMinusT / baseMinusT);
3384
- }
3385
-
3386
- output.push(stringFromCharCode(digitToBasic(q, 0)));
3387
- bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
3388
- delta = 0;
3389
- ++handledCPCount;
3390
- }
3391
- }
3392
-
3393
- ++delta;
3394
- ++n;
3395
-
3396
- }
3397
- return output.join('');
3398
- };
3399
-
3400
- /**
3401
- * Converts a Unicode string representing a domain name or an email address to
3402
- * Punycode. Only the non-ASCII parts of the domain name will be converted,
3403
- * i.e. it doesn't matter if you call it with a domain that's already in
3404
- * ASCII.
3405
- * @memberOf punycode
3406
- * @param {String} input The domain name or email address to convert, as a
3407
- * Unicode string.
3408
- * @returns {String} The Punycode representation of the given domain name or
3409
- * email address.
3410
- */
3411
- const toASCII = function(input) {
3412
- return mapDomain(input, function(string) {
3413
- return regexNonASCII.test(string)
3414
- ? 'xn--' + encode(string)
3415
- : string;
3416
- });
3417
- };
3418
-
3419
- // Copyright Joyent, Inc. and other Node contributors.
3420
- //
3421
- // Permission is hereby granted, free of charge, to any person obtaining a
3422
- // copy of this software and associated documentation files (the
3423
- // "Software"), to deal in the Software without restriction, including
3424
- // without limitation the rights to use, copy, modify, merge, publish,
3425
- // distribute, sublicense, and/or sell copies of the Software, and to permit
3426
- // persons to whom the Software is furnished to do so, subject to the
3427
- // following conditions:
3428
- //
3429
- // The above copyright notice and this permission notice shall be included
3430
- // in all copies or substantial portions of the Software.
3431
- //
3432
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
3433
- // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
3434
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
3435
- // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
3436
- // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
3437
- // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
3438
- // USE OR OTHER DEALINGS IN THE SOFTWARE.
3439
-
3440
-
3441
- // If obj.hasOwnProperty has been overridden, then calling
3442
- // obj.hasOwnProperty(prop) will break.
3443
- // See: https://github.com/joyent/node/issues/1707
3444
- function hasOwnProperty(obj, prop) {
3445
- return Object.prototype.hasOwnProperty.call(obj, prop);
3446
- }
3447
- var isArray = Array.isArray || function (xs) {
3448
- return Object.prototype.toString.call(xs) === '[object Array]';
3449
- };
3450
- function stringifyPrimitive(v) {
3451
- switch (typeof v) {
3452
- case 'string':
3453
- return v;
3454
-
3455
- case 'boolean':
3456
- return v ? 'true' : 'false';
3457
-
3458
- case 'number':
3459
- return isFinite(v) ? v : '';
3460
-
3461
- default:
3462
- return '';
3463
- }
3464
- }
3465
-
3466
- function stringify (obj, sep, eq, name) {
3467
- sep = sep || '&';
3468
- eq = eq || '=';
3469
- if (obj === null) {
3470
- obj = undefined;
3471
- }
3472
-
3473
- if (typeof obj === 'object') {
3474
- return map(objectKeys(obj), function(k) {
3475
- var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;
3476
- if (isArray(obj[k])) {
3477
- return map(obj[k], function(v) {
3478
- return ks + encodeURIComponent(stringifyPrimitive(v));
3479
- }).join(sep);
3480
- } else {
3481
- return ks + encodeURIComponent(stringifyPrimitive(obj[k]));
3482
- }
3483
- }).join(sep);
3484
-
3485
- }
3486
-
3487
- if (!name) return '';
3488
- return encodeURIComponent(stringifyPrimitive(name)) + eq +
3489
- encodeURIComponent(stringifyPrimitive(obj));
3490
- }
3491
- function map (xs, f) {
3492
- if (xs.map) return xs.map(f);
3493
- var res = [];
3494
- for (var i = 0; i < xs.length; i++) {
3495
- res.push(f(xs[i], i));
3496
- }
3497
- return res;
3498
- }
3499
-
3500
- var objectKeys = Object.keys || function (obj) {
3501
- var res = [];
3502
- for (var key in obj) {
3503
- if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key);
3504
- }
3505
- return res;
3506
- };
3507
-
3508
- function parse$1(qs, sep, eq, options) {
3509
- sep = sep || '&';
3510
- eq = eq || '=';
3511
- var obj = {};
3512
-
3513
- if (typeof qs !== 'string' || qs.length === 0) {
3514
- return obj;
3515
- }
3516
-
3517
- var regexp = /\+/g;
3518
- qs = qs.split(sep);
3519
-
3520
- var maxKeys = 1000;
3521
- if (options && typeof options.maxKeys === 'number') {
3522
- maxKeys = options.maxKeys;
3523
- }
3524
-
3525
- var len = qs.length;
3526
- // maxKeys <= 0 means that we should not limit keys count
3527
- if (maxKeys > 0 && len > maxKeys) {
3528
- len = maxKeys;
3529
- }
3530
-
3531
- for (var i = 0; i < len; ++i) {
3532
- var x = qs[i].replace(regexp, '%20'),
3533
- idx = x.indexOf(eq),
3534
- kstr, vstr, k, v;
3535
-
3536
- if (idx >= 0) {
3537
- kstr = x.substr(0, idx);
3538
- vstr = x.substr(idx + 1);
3539
- } else {
3540
- kstr = x;
3541
- vstr = '';
3542
- }
3543
-
3544
- k = decodeURIComponent(kstr);
3545
- v = decodeURIComponent(vstr);
3546
-
3547
- if (!hasOwnProperty(obj, k)) {
3548
- obj[k] = v;
3549
- } else if (isArray(obj[k])) {
3550
- obj[k].push(v);
3551
- } else {
3552
- obj[k] = [obj[k], v];
3553
- }
3554
- }
3555
-
3556
- return obj;
3557
- }
3558
-
3559
- // Copyright Joyent, Inc. and other Node contributors.
3560
- function Url() {
3561
- this.protocol = null;
3562
- this.slashes = null;
3563
- this.auth = null;
3564
- this.host = null;
3565
- this.port = null;
3566
- this.hostname = null;
3567
- this.hash = null;
3568
- this.search = null;
3569
- this.query = null;
3570
- this.pathname = null;
3571
- this.path = null;
3572
- this.href = null;
3573
- }
3574
-
3575
- // Reference: RFC 3986, RFC 1808, RFC 2396
3576
-
3577
- // define these here so at least they only have to be
3578
- // compiled once on the first module load.
3579
- var protocolPattern = /^([a-z0-9.+-]+:)/i,
3580
- portPattern = /:[0-9]*$/,
3581
-
3582
- // Special case for a simple path URL
3583
- simplePathPattern = /^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,
3584
-
3585
- // RFC 2396: characters reserved for delimiting URLs.
3586
- // We actually just auto-escape these.
3587
- delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'],
3588
-
3589
- // RFC 2396: characters not allowed for various reasons.
3590
- unwise = ['{', '}', '|', '\\', '^', '`'].concat(delims),
3591
-
3592
- // Allowed by RFCs, but cause of XSS attacks. Always escape these.
3593
- autoEscape = ['\''].concat(unwise),
3594
- // Characters that are never ever allowed in a hostname.
3595
- // Note that any invalid chars are also handled, but these
3596
- // are the ones that are *expected* to be seen, so we fast-path
3597
- // them.
3598
- nonHostChars = ['%', '/', '?', ';', '#'].concat(autoEscape),
3599
- hostEndingChars = ['/', '?', '#'],
3600
- hostnameMaxLen = 255,
3601
- hostnamePartPattern = /^[+a-z0-9A-Z_-]{0,63}$/,
3602
- hostnamePartStart = /^([+a-z0-9A-Z_-]{0,63})(.*)$/,
3603
- // protocols that can allow "unsafe" and "unwise" chars.
3604
- unsafeProtocol = {
3605
- 'javascript': true,
3606
- 'javascript:': true
3607
- },
3608
- // protocols that never have a hostname.
3609
- hostlessProtocol = {
3610
- 'javascript': true,
3611
- 'javascript:': true
3612
- },
3613
- // protocols that always contain a // bit.
3614
- slashedProtocol = {
3615
- 'http': true,
3616
- 'https': true,
3617
- 'ftp': true,
3618
- 'gopher': true,
3619
- 'file': true,
3620
- 'http:': true,
3621
- 'https:': true,
3622
- 'ftp:': true,
3623
- 'gopher:': true,
3624
- 'file:': true
3625
- };
2294
+ var browser = {exports: {}};
3626
2295
 
3627
- function urlParse(url, parseQueryString, slashesDenoteHost) {
3628
- if (url && isObject(url) && url instanceof Url) return url;
2296
+ (function (module, exports) {
3629
2297
 
3630
- var u = new Url;
3631
- u.parse(url, parseQueryString, slashesDenoteHost);
3632
- return u;
3633
- }
3634
- Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
3635
- return parse(this, url, parseQueryString, slashesDenoteHost);
2298
+ // ref: https://github.com/tc39/proposal-global
2299
+ var getGlobal = function () {
2300
+ // the only reliable means to get the global object is
2301
+ // `Function('return this')()`
2302
+ // However, this causes CSP violations in Chrome apps.
2303
+ if (typeof self !== 'undefined') { return self; }
2304
+ if (typeof window !== 'undefined') { return window; }
2305
+ if (typeof global !== 'undefined') { return global; }
2306
+ throw new Error('unable to locate global object');
3636
2307
  };
3637
2308
 
3638
- function parse(self, url, parseQueryString, slashesDenoteHost) {
3639
- if (!isString(url)) {
3640
- throw new TypeError('Parameter \'url\' must be a string, not ' + typeof url);
3641
- }
3642
-
3643
- // Copy chrome, IE, opera backslash-handling behavior.
3644
- // Back slashes before the query string get converted to forward slashes
3645
- // See: https://code.google.com/p/chromium/issues/detail?id=25916
3646
- var queryIndex = url.indexOf('?'),
3647
- splitter =
3648
- (queryIndex !== -1 && queryIndex < url.indexOf('#')) ? '?' : '#',
3649
- uSplit = url.split(splitter),
3650
- slashRegex = /\\/g;
3651
- uSplit[0] = uSplit[0].replace(slashRegex, '/');
3652
- url = uSplit.join(splitter);
3653
-
3654
- var rest = url;
3655
-
3656
- // trim before proceeding.
3657
- // This is to support parse stuff like " http://foo.com \n"
3658
- rest = rest.trim();
3659
-
3660
- if (!slashesDenoteHost && url.split('#').length === 1) {
3661
- // Try fast path regexp
3662
- var simplePath = simplePathPattern.exec(rest);
3663
- if (simplePath) {
3664
- self.path = rest;
3665
- self.href = rest;
3666
- self.pathname = simplePath[1];
3667
- if (simplePath[2]) {
3668
- self.search = simplePath[2];
3669
- if (parseQueryString) {
3670
- self.query = parse$1(self.search.substr(1));
3671
- } else {
3672
- self.query = self.search.substr(1);
3673
- }
3674
- } else if (parseQueryString) {
3675
- self.search = '';
3676
- self.query = {};
3677
- }
3678
- return self;
3679
- }
3680
- }
3681
-
3682
- var proto = protocolPattern.exec(rest);
3683
- if (proto) {
3684
- proto = proto[0];
3685
- var lowerProto = proto.toLowerCase();
3686
- self.protocol = lowerProto;
3687
- rest = rest.substr(proto.length);
3688
- }
3689
-
3690
- // figure out if it's got a host
3691
- // user@server is *always* interpreted as a hostname, and url
3692
- // resolution will treat //foo/bar as host=foo,path=bar because that's
3693
- // how the browser resolves relative URLs.
3694
- if (slashesDenoteHost || proto || rest.match(/^\/\/[^@\/]+@[^@\/]+/)) {
3695
- var slashes = rest.substr(0, 2) === '//';
3696
- if (slashes && !(proto && hostlessProtocol[proto])) {
3697
- rest = rest.substr(2);
3698
- self.slashes = true;
3699
- }
3700
- }
3701
- var i, hec, l, p;
3702
- if (!hostlessProtocol[proto] &&
3703
- (slashes || (proto && !slashedProtocol[proto]))) {
3704
-
3705
- // there's a hostname.
3706
- // the first instance of /, ?, ;, or # ends the host.
3707
- //
3708
- // If there is an @ in the hostname, then non-host chars *are* allowed
3709
- // to the left of the last @ sign, unless some host-ending character
3710
- // comes *before* the @-sign.
3711
- // URLs are obnoxious.
3712
- //
3713
- // ex:
3714
- // http://a@b@c/ => user:a@b host:c
3715
- // http://a@b?@c => user:a host:c path:/?@c
3716
-
3717
- // v0.12 TODO(isaacs): This is not quite how Chrome does things.
3718
- // Review our test case against browsers more comprehensively.
3719
-
3720
- // find the first instance of any hostEndingChars
3721
- var hostEnd = -1;
3722
- for (i = 0; i < hostEndingChars.length; i++) {
3723
- hec = rest.indexOf(hostEndingChars[i]);
3724
- if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
3725
- hostEnd = hec;
3726
- }
3727
-
3728
- // at this point, either we have an explicit point where the
3729
- // auth portion cannot go past, or the last @ char is the decider.
3730
- var auth, atSign;
3731
- if (hostEnd === -1) {
3732
- // atSign can be anywhere.
3733
- atSign = rest.lastIndexOf('@');
3734
- } else {
3735
- // atSign must be in auth portion.
3736
- // http://a@b/c@d => host:b auth:a path:/c@d
3737
- atSign = rest.lastIndexOf('@', hostEnd);
3738
- }
3739
-
3740
- // Now we have a portion which is definitely the auth.
3741
- // Pull that off.
3742
- if (atSign !== -1) {
3743
- auth = rest.slice(0, atSign);
3744
- rest = rest.slice(atSign + 1);
3745
- self.auth = decodeURIComponent(auth);
3746
- }
3747
-
3748
- // the host is the remaining to the left of the first non-host char
3749
- hostEnd = -1;
3750
- for (i = 0; i < nonHostChars.length; i++) {
3751
- hec = rest.indexOf(nonHostChars[i]);
3752
- if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
3753
- hostEnd = hec;
3754
- }
3755
- // if we still have not hit it, then the entire thing is a host.
3756
- if (hostEnd === -1)
3757
- hostEnd = rest.length;
3758
-
3759
- self.host = rest.slice(0, hostEnd);
3760
- rest = rest.slice(hostEnd);
3761
-
3762
- // pull out port.
3763
- parseHost(self);
3764
-
3765
- // we've indicated that there is a hostname,
3766
- // so even if it's empty, it has to be present.
3767
- self.hostname = self.hostname || '';
3768
-
3769
- // if hostname begins with [ and ends with ]
3770
- // assume that it's an IPv6 address.
3771
- var ipv6Hostname = self.hostname[0] === '[' &&
3772
- self.hostname[self.hostname.length - 1] === ']';
3773
-
3774
- // validate a little.
3775
- if (!ipv6Hostname) {
3776
- var hostparts = self.hostname.split(/\./);
3777
- for (i = 0, l = hostparts.length; i < l; i++) {
3778
- var part = hostparts[i];
3779
- if (!part) continue;
3780
- if (!part.match(hostnamePartPattern)) {
3781
- var newpart = '';
3782
- for (var j = 0, k = part.length; j < k; j++) {
3783
- if (part.charCodeAt(j) > 127) {
3784
- // we replace non-ASCII char with a temporary placeholder
3785
- // we need this to make sure size of hostname is not
3786
- // broken by replacing non-ASCII by nothing
3787
- newpart += 'x';
3788
- } else {
3789
- newpart += part[j];
3790
- }
3791
- }
3792
- // we test again with ASCII char only
3793
- if (!newpart.match(hostnamePartPattern)) {
3794
- var validParts = hostparts.slice(0, i);
3795
- var notHost = hostparts.slice(i + 1);
3796
- var bit = part.match(hostnamePartStart);
3797
- if (bit) {
3798
- validParts.push(bit[1]);
3799
- notHost.unshift(bit[2]);
3800
- }
3801
- if (notHost.length) {
3802
- rest = '/' + notHost.join('.') + rest;
3803
- }
3804
- self.hostname = validParts.join('.');
3805
- break;
3806
- }
3807
- }
3808
- }
3809
- }
3810
-
3811
- if (self.hostname.length > hostnameMaxLen) {
3812
- self.hostname = '';
3813
- } else {
3814
- // hostnames are always lower case.
3815
- self.hostname = self.hostname.toLowerCase();
3816
- }
3817
-
3818
- if (!ipv6Hostname) {
3819
- // IDNA Support: Returns a punycoded representation of "domain".
3820
- // It only converts parts of the domain name that
3821
- // have non-ASCII characters, i.e. it doesn't matter if
3822
- // you call it with a domain that already is ASCII-only.
3823
- self.hostname = toASCII(self.hostname);
3824
- }
3825
-
3826
- p = self.port ? ':' + self.port : '';
3827
- var h = self.hostname || '';
3828
- self.host = h + p;
3829
- self.href += self.host;
3830
-
3831
- // strip [ and ] from the hostname
3832
- // the host field still retains them, though
3833
- if (ipv6Hostname) {
3834
- self.hostname = self.hostname.substr(1, self.hostname.length - 2);
3835
- if (rest[0] !== '/') {
3836
- rest = '/' + rest;
3837
- }
3838
- }
3839
- }
2309
+ var global = getGlobal();
3840
2310
 
3841
- // now rest is set to the post-host stuff.
3842
- // chop off any delim chars.
3843
- if (!unsafeProtocol[lowerProto]) {
2311
+ module.exports = exports = global.fetch;
3844
2312
 
3845
- // First, make 100% sure that any "autoEscape" chars get
3846
- // escaped, even if encodeURIComponent doesn't think they
3847
- // need to be.
3848
- for (i = 0, l = autoEscape.length; i < l; i++) {
3849
- var ae = autoEscape[i];
3850
- if (rest.indexOf(ae) === -1)
3851
- continue;
3852
- var esc = encodeURIComponent(ae);
3853
- if (esc === ae) {
3854
- esc = escape(ae);
3855
- }
3856
- rest = rest.split(ae).join(esc);
3857
- }
3858
- }
3859
-
3860
-
3861
- // chop off from the tail first.
3862
- var hash = rest.indexOf('#');
3863
- if (hash !== -1) {
3864
- // got a fragment string.
3865
- self.hash = rest.substr(hash);
3866
- rest = rest.slice(0, hash);
3867
- }
3868
- var qm = rest.indexOf('?');
3869
- if (qm !== -1) {
3870
- self.search = rest.substr(qm);
3871
- self.query = rest.substr(qm + 1);
3872
- if (parseQueryString) {
3873
- self.query = parse$1(self.query);
3874
- }
3875
- rest = rest.slice(0, qm);
3876
- } else if (parseQueryString) {
3877
- // no query string, but parseQueryString still requested
3878
- self.search = '';
3879
- self.query = {};
3880
- }
3881
- if (rest) self.pathname = rest;
3882
- if (slashedProtocol[lowerProto] &&
3883
- self.hostname && !self.pathname) {
3884
- self.pathname = '/';
3885
- }
3886
-
3887
- //to support http.request
3888
- if (self.pathname || self.search) {
3889
- p = self.pathname || '';
3890
- var s = self.search || '';
3891
- self.path = p + s;
3892
- }
3893
-
3894
- // finally, reconstruct the href based on what has been validated.
3895
- self.href = format(self);
3896
- return self;
3897
- }
3898
-
3899
- // format a parsed object into a url string
3900
- function urlFormat(obj) {
3901
- // ensure it's an object, and not a string url.
3902
- // If it's an obj, this is a no-op.
3903
- // this way, you can call url_format() on strings
3904
- // to clean up potentially wonky urls.
3905
- if (isString(obj)) obj = parse({}, obj);
3906
- return format(obj);
2313
+ // Needed for TypeScript and Webpack.
2314
+ if (global.fetch) {
2315
+ exports.default = global.fetch.bind(global);
3907
2316
  }
3908
2317
 
3909
- function format(self) {
3910
- var auth = self.auth || '';
3911
- if (auth) {
3912
- auth = encodeURIComponent(auth);
3913
- auth = auth.replace(/%3A/i, ':');
3914
- auth += '@';
3915
- }
3916
-
3917
- var protocol = self.protocol || '',
3918
- pathname = self.pathname || '',
3919
- hash = self.hash || '',
3920
- host = false,
3921
- query = '';
3922
-
3923
- if (self.host) {
3924
- host = auth + self.host;
3925
- } else if (self.hostname) {
3926
- host = auth + (self.hostname.indexOf(':') === -1 ?
3927
- self.hostname :
3928
- '[' + this.hostname + ']');
3929
- if (self.port) {
3930
- host += ':' + self.port;
3931
- }
3932
- }
3933
-
3934
- if (self.query &&
3935
- isObject(self.query) &&
3936
- Object.keys(self.query).length) {
3937
- query = stringify(self.query);
3938
- }
3939
-
3940
- var search = self.search || (query && ('?' + query)) || '';
3941
-
3942
- if (protocol && protocol.substr(-1) !== ':') protocol += ':';
3943
-
3944
- // only the slashedProtocols get the //. Not mailto:, xmpp:, etc.
3945
- // unless they had them to begin with.
3946
- if (self.slashes ||
3947
- (!protocol || slashedProtocol[protocol]) && host !== false) {
3948
- host = '//' + (host || '');
3949
- if (pathname && pathname.charAt(0) !== '/') pathname = '/' + pathname;
3950
- } else if (!host) {
3951
- host = '';
3952
- }
3953
-
3954
- if (hash && hash.charAt(0) !== '#') hash = '#' + hash;
3955
- if (search && search.charAt(0) !== '?') search = '?' + search;
3956
-
3957
- pathname = pathname.replace(/[?#]/g, function(match) {
3958
- return encodeURIComponent(match);
3959
- });
3960
- search = search.replace('#', '%23');
3961
-
3962
- return protocol + host + pathname + search + hash;
3963
- }
3964
-
3965
- Url.prototype.format = function() {
3966
- return format(this);
3967
- };
2318
+ exports.Headers = global.Headers;
2319
+ exports.Request = global.Request;
2320
+ exports.Response = global.Response;
2321
+ }(browser, browser.exports));
3968
2322
 
3969
- Url.prototype.resolve = function(relative) {
3970
- return this.resolveObject(urlParse(relative, false, true)).format();
3971
- };
3972
-
3973
- Url.prototype.resolveObject = function(relative) {
3974
- if (isString(relative)) {
3975
- var rel = new Url();
3976
- rel.parse(relative, false, true);
3977
- relative = rel;
3978
- }
3979
-
3980
- var result = new Url();
3981
- var tkeys = Object.keys(this);
3982
- for (var tk = 0; tk < tkeys.length; tk++) {
3983
- var tkey = tkeys[tk];
3984
- result[tkey] = this[tkey];
3985
- }
3986
-
3987
- // hash is always overridden, no matter what.
3988
- // even href="" will remove it.
3989
- result.hash = relative.hash;
3990
-
3991
- // if the relative url is empty, then there's nothing left to do here.
3992
- if (relative.href === '') {
3993
- result.href = result.format();
3994
- return result;
3995
- }
3996
-
3997
- // hrefs like //foo/bar always cut to the protocol.
3998
- if (relative.slashes && !relative.protocol) {
3999
- // take everything except the protocol from relative
4000
- var rkeys = Object.keys(relative);
4001
- for (var rk = 0; rk < rkeys.length; rk++) {
4002
- var rkey = rkeys[rk];
4003
- if (rkey !== 'protocol')
4004
- result[rkey] = relative[rkey];
4005
- }
4006
-
4007
- //urlParse appends trailing / to urls like http://www.example.com
4008
- if (slashedProtocol[result.protocol] &&
4009
- result.hostname && !result.pathname) {
4010
- result.path = result.pathname = '/';
4011
- }
4012
-
4013
- result.href = result.format();
4014
- return result;
4015
- }
4016
- var relPath;
4017
- if (relative.protocol && relative.protocol !== result.protocol) {
4018
- // if it's a known url protocol, then changing
4019
- // the protocol does weird things
4020
- // first, if it's not file:, then we MUST have a host,
4021
- // and if there was a path
4022
- // to begin with, then we MUST have a path.
4023
- // if it is file:, then the host is dropped,
4024
- // because that's known to be hostless.
4025
- // anything else is assumed to be absolute.
4026
- if (!slashedProtocol[relative.protocol]) {
4027
- var keys = Object.keys(relative);
4028
- for (var v = 0; v < keys.length; v++) {
4029
- var k = keys[v];
4030
- result[k] = relative[k];
4031
- }
4032
- result.href = result.format();
4033
- return result;
4034
- }
4035
-
4036
- result.protocol = relative.protocol;
4037
- if (!relative.host && !hostlessProtocol[relative.protocol]) {
4038
- relPath = (relative.pathname || '').split('/');
4039
- while (relPath.length && !(relative.host = relPath.shift()));
4040
- if (!relative.host) relative.host = '';
4041
- if (!relative.hostname) relative.hostname = '';
4042
- if (relPath[0] !== '') relPath.unshift('');
4043
- if (relPath.length < 2) relPath.unshift('');
4044
- result.pathname = relPath.join('/');
4045
- } else {
4046
- result.pathname = relative.pathname;
4047
- }
4048
- result.search = relative.search;
4049
- result.query = relative.query;
4050
- result.host = relative.host || '';
4051
- result.auth = relative.auth;
4052
- result.hostname = relative.hostname || relative.host;
4053
- result.port = relative.port;
4054
- // to support http.request
4055
- if (result.pathname || result.search) {
4056
- var p = result.pathname || '';
4057
- var s = result.search || '';
4058
- result.path = p + s;
4059
- }
4060
- result.slashes = result.slashes || relative.slashes;
4061
- result.href = result.format();
4062
- return result;
4063
- }
4064
-
4065
- var isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/'),
4066
- isRelAbs = (
4067
- relative.host ||
4068
- relative.pathname && relative.pathname.charAt(0) === '/'
4069
- ),
4070
- mustEndAbs = (isRelAbs || isSourceAbs ||
4071
- (result.host && relative.pathname)),
4072
- removeAllDots = mustEndAbs,
4073
- srcPath = result.pathname && result.pathname.split('/') || [],
4074
- psychotic = result.protocol && !slashedProtocol[result.protocol];
4075
- relPath = relative.pathname && relative.pathname.split('/') || [];
4076
- // if the url is a non-slashed url, then relative
4077
- // links like ../.. should be able
4078
- // to crawl up to the hostname, as well. This is strange.
4079
- // result.protocol has already been set by now.
4080
- // Later on, put the first path part into the host field.
4081
- if (psychotic) {
4082
- result.hostname = '';
4083
- result.port = null;
4084
- if (result.host) {
4085
- if (srcPath[0] === '') srcPath[0] = result.host;
4086
- else srcPath.unshift(result.host);
4087
- }
4088
- result.host = '';
4089
- if (relative.protocol) {
4090
- relative.hostname = null;
4091
- relative.port = null;
4092
- if (relative.host) {
4093
- if (relPath[0] === '') relPath[0] = relative.host;
4094
- else relPath.unshift(relative.host);
4095
- }
4096
- relative.host = null;
4097
- }
4098
- mustEndAbs = mustEndAbs && (relPath[0] === '' || srcPath[0] === '');
4099
- }
4100
- var authInHost;
4101
- if (isRelAbs) {
4102
- // it's absolute.
4103
- result.host = (relative.host || relative.host === '') ?
4104
- relative.host : result.host;
4105
- result.hostname = (relative.hostname || relative.hostname === '') ?
4106
- relative.hostname : result.hostname;
4107
- result.search = relative.search;
4108
- result.query = relative.query;
4109
- srcPath = relPath;
4110
- // fall through to the dot-handling below.
4111
- } else if (relPath.length) {
4112
- // it's relative
4113
- // throw away the existing file, and take the new path instead.
4114
- if (!srcPath) srcPath = [];
4115
- srcPath.pop();
4116
- srcPath = srcPath.concat(relPath);
4117
- result.search = relative.search;
4118
- result.query = relative.query;
4119
- } else if (!isNullOrUndefined(relative.search)) {
4120
- // just pull out the search.
4121
- // like href='?foo'.
4122
- // Put this after the other two cases because it simplifies the booleans
4123
- if (psychotic) {
4124
- result.hostname = result.host = srcPath.shift();
4125
- //occationaly the auth can get stuck only in host
4126
- //this especially happens in cases like
4127
- //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
4128
- authInHost = result.host && result.host.indexOf('@') > 0 ?
4129
- result.host.split('@') : false;
4130
- if (authInHost) {
4131
- result.auth = authInHost.shift();
4132
- result.host = result.hostname = authInHost.shift();
4133
- }
4134
- }
4135
- result.search = relative.search;
4136
- result.query = relative.query;
4137
- //to support http.request
4138
- if (!isNull(result.pathname) || !isNull(result.search)) {
4139
- result.path = (result.pathname ? result.pathname : '') +
4140
- (result.search ? result.search : '');
4141
- }
4142
- result.href = result.format();
4143
- return result;
4144
- }
4145
-
4146
- if (!srcPath.length) {
4147
- // no path at all. easy.
4148
- // we've already handled the other stuff above.
4149
- result.pathname = null;
4150
- //to support http.request
4151
- if (result.search) {
4152
- result.path = '/' + result.search;
4153
- } else {
4154
- result.path = null;
4155
- }
4156
- result.href = result.format();
4157
- return result;
4158
- }
4159
-
4160
- // if a url ENDs in . or .., then it must get a trailing slash.
4161
- // however, if it ends in anything else non-slashy,
4162
- // then it must NOT get a trailing slash.
4163
- var last = srcPath.slice(-1)[0];
4164
- var hasTrailingSlash = (
4165
- (result.host || relative.host || srcPath.length > 1) &&
4166
- (last === '.' || last === '..') || last === '');
4167
-
4168
- // strip single dots, resolve double dots to parent dir
4169
- // if the path tries to go above the root, `up` ends up > 0
4170
- var up = 0;
4171
- for (var i = srcPath.length; i >= 0; i--) {
4172
- last = srcPath[i];
4173
- if (last === '.') {
4174
- srcPath.splice(i, 1);
4175
- } else if (last === '..') {
4176
- srcPath.splice(i, 1);
4177
- up++;
4178
- } else if (up) {
4179
- srcPath.splice(i, 1);
4180
- up--;
4181
- }
4182
- }
4183
-
4184
- // if the path is allowed to go above the root, restore leading ..s
4185
- if (!mustEndAbs && !removeAllDots) {
4186
- for (; up--; up) {
4187
- srcPath.unshift('..');
4188
- }
4189
- }
4190
-
4191
- if (mustEndAbs && srcPath[0] !== '' &&
4192
- (!srcPath[0] || srcPath[0].charAt(0) !== '/')) {
4193
- srcPath.unshift('');
4194
- }
4195
-
4196
- if (hasTrailingSlash && (srcPath.join('/').substr(-1) !== '/')) {
4197
- srcPath.push('');
4198
- }
4199
-
4200
- var isAbsolute = srcPath[0] === '' ||
4201
- (srcPath[0] && srcPath[0].charAt(0) === '/');
4202
-
4203
- // put the host back
4204
- if (psychotic) {
4205
- result.hostname = result.host = isAbsolute ? '' :
4206
- srcPath.length ? srcPath.shift() : '';
4207
- //occationaly the auth can get stuck only in host
4208
- //this especially happens in cases like
4209
- //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
4210
- authInHost = result.host && result.host.indexOf('@') > 0 ?
4211
- result.host.split('@') : false;
4212
- if (authInHost) {
4213
- result.auth = authInHost.shift();
4214
- result.host = result.hostname = authInHost.shift();
4215
- }
4216
- }
4217
-
4218
- mustEndAbs = mustEndAbs || (result.host && srcPath.length);
4219
-
4220
- if (mustEndAbs && !isAbsolute) {
4221
- srcPath.unshift('');
4222
- }
4223
-
4224
- if (!srcPath.length) {
4225
- result.pathname = null;
4226
- result.path = null;
4227
- } else {
4228
- result.pathname = srcPath.join('/');
4229
- }
4230
-
4231
- //to support request.http
4232
- if (!isNull(result.pathname) || !isNull(result.search)) {
4233
- result.path = (result.pathname ? result.pathname : '') +
4234
- (result.search ? result.search : '');
4235
- }
4236
- result.auth = relative.auth || result.auth;
4237
- result.slashes = result.slashes || relative.slashes;
4238
- result.href = result.format();
4239
- return result;
4240
- };
4241
-
4242
- Url.prototype.parseHost = function() {
4243
- return parseHost(this);
4244
- };
4245
-
4246
- function parseHost(self) {
4247
- var host = self.host;
4248
- var port = portPattern.exec(host);
4249
- if (port) {
4250
- port = port[0];
4251
- if (port !== ':') {
4252
- self.port = port.substr(1);
4253
- }
4254
- host = host.substr(0, host.length - port.length);
4255
- }
4256
- if (host) self.hostname = host;
4257
- }
2323
+ var fetch = browser.exports;
4258
2324
 
4259
2325
  const MINIMUM_SLOT_PER_EPOCH = 32; // Returns the number of trailing zeros in the binary representation of self.
4260
2326
 
@@ -4392,7 +2458,7 @@ function promiseTimeout(promise, timeoutMs) {
4392
2458
  }
4393
2459
 
4394
2460
  function makeWebsocketUrl(endpoint) {
4395
- let url = urlParse(endpoint);
2461
+ let url = new URL(endpoint);
4396
2462
  const useHttps = url.protocol === 'https:';
4397
2463
  url.protocol = useHttps ? 'wss:' : 'ws:';
4398
2464
  url.host = ''; // Only shift the port by +1 as a convention for ws(s) only if given endpoint
@@ -4402,11 +2468,11 @@ function makeWebsocketUrl(endpoint) {
4402
2468
  // default ports: http(80) or https(443) and it's assumed we're behind a reverse
4403
2469
  // proxy which manages WebSocket upgrade and backend port redirection.
4404
2470
 
4405
- if (url.port !== null) {
2471
+ if (url.port !== '') {
4406
2472
  url.port = String(Number(url.port) + 1);
4407
2473
  }
4408
2474
 
4409
- return urlFormat(url);
2475
+ return url.toString();
4410
2476
  }
4411
2477
 
4412
2478
  const PublicKeyFromString = coerce(instance(PublicKey), string(), value => new PublicKey(value));
@@ -5354,7 +3420,7 @@ class Connection {
5354
3420
 
5355
3421
  _defineProperty(this, "_slotUpdateSubscriptions", {});
5356
3422
 
5357
- let url = urlParse(endpoint);
3423
+ let url = new URL(endpoint);
5358
3424
  const useHttps = url.protocol === 'https:';
5359
3425
  let wsEndpoint;
5360
3426
  let httpHeaders;
@@ -5373,7 +3439,7 @@ class Connection {
5373
3439
 
5374
3440
  this._rpcEndpoint = endpoint;
5375
3441
  this._rpcWsEndpoint = wsEndpoint || makeWebsocketUrl(endpoint);
5376
- this._rpcClient = createRpcClient(url.href, useHttps, httpHeaders, fetchMiddleware, disableRetryOnRateLimit);
3442
+ this._rpcClient = createRpcClient(url.toString(), useHttps, httpHeaders, fetchMiddleware, disableRetryOnRateLimit);
5377
3443
  this._rpcRequest = createRpcRequest(this._rpcClient);
5378
3444
  this._rpcBatchRequest = createRpcBatchRequest(this._rpcClient);
5379
3445
  this._rpcWebSocket = new Client(this._rpcWsEndpoint, {
@@ -8395,10 +6461,8 @@ class ValidatorInfo {
8395
6461
  const configKeys = [];
8396
6462
 
8397
6463
  for (let i = 0; i < 2; i++) {
8398
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
8399
- byteArray = byteArray.slice(PUBKEY_LENGTH);
8400
- const isSigner = byteArray.slice(0, 1)[0] === 1;
8401
- byteArray = byteArray.slice(1);
6464
+ const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
6465
+ const isSigner = guardedShift(byteArray) === 1;
8402
6466
  configKeys.push({
8403
6467
  publicKey,
8404
6468
  isSigner