@solana/web3.js 1.24.2 → 1.28.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.
@@ -66,6 +66,9 @@ const SOLANA_SCHEMA = new Map();
66
66
  */
67
67
 
68
68
  const MAX_SEED_LENGTH = 32;
69
+ /**
70
+ * Value to be converted into public key
71
+ */
69
72
 
70
73
  function isPublicKeyData(value) {
71
74
  return value._bn !== undefined;
@@ -455,16 +458,35 @@ class Message {
455
458
 
456
459
  _defineProperty(this, "instructions", void 0);
457
460
 
461
+ _defineProperty(this, "indexToProgramIds", new Map());
462
+
458
463
  this.header = args.header;
459
464
  this.accountKeys = args.accountKeys.map(account => new PublicKey(account));
460
465
  this.recentBlockhash = args.recentBlockhash;
461
466
  this.instructions = args.instructions;
467
+ this.instructions.forEach(ix => this.indexToProgramIds.set(ix.programIdIndex, this.accountKeys[ix.programIdIndex]));
468
+ }
469
+
470
+ isAccountSigner(index) {
471
+ return index < this.header.numRequiredSignatures;
462
472
  }
463
473
 
464
474
  isAccountWritable(index) {
465
475
  return index < this.header.numRequiredSignatures - this.header.numReadonlySignedAccounts || index >= this.header.numRequiredSignatures && index < this.accountKeys.length - this.header.numReadonlyUnsignedAccounts;
466
476
  }
467
477
 
478
+ isProgramId(index) {
479
+ return this.indexToProgramIds.has(index);
480
+ }
481
+
482
+ programIds() {
483
+ return [...this.indexToProgramIds.values()];
484
+ }
485
+
486
+ nonProgramIds() {
487
+ return this.accountKeys.filter((_, index) => !this.isProgramId(index));
488
+ }
489
+
468
490
  serialize() {
469
491
  const numKeys = this.accountKeys.length;
470
492
  let keyCount = [];
@@ -1179,7 +1201,7 @@ class Transaction {
1179
1201
  */
1180
1202
 
1181
1203
 
1182
- static populate(message, signatures) {
1204
+ static populate(message, signatures = []) {
1183
1205
  const transaction = new Transaction();
1184
1206
  transaction.recentBlockhash = message.recentBlockhash;
1185
1207
 
@@ -1199,7 +1221,7 @@ class Transaction {
1199
1221
  const pubkey = message.accountKeys[account];
1200
1222
  return {
1201
1223
  pubkey,
1202
- isSigner: transaction.signatures.some(keyObj => keyObj.publicKey.toString() === pubkey.toString()),
1224
+ isSigner: transaction.signatures.some(keyObj => keyObj.publicKey.toString() === pubkey.toString()) || message.isAccountSigner(account),
1203
1225
  isWritable: message.isAccountWritable(account)
1204
1226
  };
1205
1227
  });
@@ -2261,36 +2283,572 @@ class BpfLoader {
2261
2283
 
2262
2284
  }
2263
2285
 
2264
- var browser = {exports: {}};
2286
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
2287
+
2288
+ function getDefaultExportFromCjs (x) {
2289
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
2290
+ }
2291
+
2292
+ var browserPonyfill = {exports: {}};
2265
2293
 
2266
2294
  (function (module, exports) {
2295
+ var global = typeof self !== 'undefined' ? self : commonjsGlobal;
2296
+ var __self__ = (function () {
2297
+ function F() {
2298
+ this.fetch = false;
2299
+ this.DOMException = global.DOMException;
2300
+ }
2301
+ F.prototype = global;
2302
+ return new F();
2303
+ })();
2304
+ (function(self) {
2305
+
2306
+ ((function (exports) {
2307
+
2308
+ var support = {
2309
+ searchParams: 'URLSearchParams' in self,
2310
+ iterable: 'Symbol' in self && 'iterator' in Symbol,
2311
+ blob:
2312
+ 'FileReader' in self &&
2313
+ 'Blob' in self &&
2314
+ (function() {
2315
+ try {
2316
+ new Blob();
2317
+ return true
2318
+ } catch (e) {
2319
+ return false
2320
+ }
2321
+ })(),
2322
+ formData: 'FormData' in self,
2323
+ arrayBuffer: 'ArrayBuffer' in self
2324
+ };
2267
2325
 
2268
- // ref: https://github.com/tc39/proposal-global
2269
- var getGlobal = function () {
2270
- // the only reliable means to get the global object is
2271
- // `Function('return this')()`
2272
- // However, this causes CSP violations in Chrome apps.
2273
- if (typeof self !== 'undefined') { return self; }
2274
- if (typeof window !== 'undefined') { return window; }
2275
- if (typeof global !== 'undefined') { return global; }
2276
- throw new Error('unable to locate global object');
2277
- };
2326
+ function isDataView(obj) {
2327
+ return obj && DataView.prototype.isPrototypeOf(obj)
2328
+ }
2329
+
2330
+ if (support.arrayBuffer) {
2331
+ var viewClasses = [
2332
+ '[object Int8Array]',
2333
+ '[object Uint8Array]',
2334
+ '[object Uint8ClampedArray]',
2335
+ '[object Int16Array]',
2336
+ '[object Uint16Array]',
2337
+ '[object Int32Array]',
2338
+ '[object Uint32Array]',
2339
+ '[object Float32Array]',
2340
+ '[object Float64Array]'
2341
+ ];
2342
+
2343
+ var isArrayBufferView =
2344
+ ArrayBuffer.isView ||
2345
+ function(obj) {
2346
+ return obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1
2347
+ };
2348
+ }
2278
2349
 
2279
- var global = getGlobal();
2350
+ function normalizeName(name) {
2351
+ if (typeof name !== 'string') {
2352
+ name = String(name);
2353
+ }
2354
+ if (/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(name)) {
2355
+ throw new TypeError('Invalid character in header field name')
2356
+ }
2357
+ return name.toLowerCase()
2358
+ }
2280
2359
 
2281
- module.exports = exports = global.fetch;
2360
+ function normalizeValue(value) {
2361
+ if (typeof value !== 'string') {
2362
+ value = String(value);
2363
+ }
2364
+ return value
2365
+ }
2282
2366
 
2283
- // Needed for TypeScript and Webpack.
2284
- if (global.fetch) {
2285
- exports.default = global.fetch.bind(global);
2286
- }
2367
+ // Build a destructive iterator for the value list
2368
+ function iteratorFor(items) {
2369
+ var iterator = {
2370
+ next: function() {
2371
+ var value = items.shift();
2372
+ return {done: value === undefined, value: value}
2373
+ }
2374
+ };
2375
+
2376
+ if (support.iterable) {
2377
+ iterator[Symbol.iterator] = function() {
2378
+ return iterator
2379
+ };
2380
+ }
2381
+
2382
+ return iterator
2383
+ }
2384
+
2385
+ function Headers(headers) {
2386
+ this.map = {};
2387
+
2388
+ if (headers instanceof Headers) {
2389
+ headers.forEach(function(value, name) {
2390
+ this.append(name, value);
2391
+ }, this);
2392
+ } else if (Array.isArray(headers)) {
2393
+ headers.forEach(function(header) {
2394
+ this.append(header[0], header[1]);
2395
+ }, this);
2396
+ } else if (headers) {
2397
+ Object.getOwnPropertyNames(headers).forEach(function(name) {
2398
+ this.append(name, headers[name]);
2399
+ }, this);
2400
+ }
2401
+ }
2402
+
2403
+ Headers.prototype.append = function(name, value) {
2404
+ name = normalizeName(name);
2405
+ value = normalizeValue(value);
2406
+ var oldValue = this.map[name];
2407
+ this.map[name] = oldValue ? oldValue + ', ' + value : value;
2408
+ };
2409
+
2410
+ Headers.prototype['delete'] = function(name) {
2411
+ delete this.map[normalizeName(name)];
2412
+ };
2413
+
2414
+ Headers.prototype.get = function(name) {
2415
+ name = normalizeName(name);
2416
+ return this.has(name) ? this.map[name] : null
2417
+ };
2418
+
2419
+ Headers.prototype.has = function(name) {
2420
+ return this.map.hasOwnProperty(normalizeName(name))
2421
+ };
2422
+
2423
+ Headers.prototype.set = function(name, value) {
2424
+ this.map[normalizeName(name)] = normalizeValue(value);
2425
+ };
2426
+
2427
+ Headers.prototype.forEach = function(callback, thisArg) {
2428
+ for (var name in this.map) {
2429
+ if (this.map.hasOwnProperty(name)) {
2430
+ callback.call(thisArg, this.map[name], name, this);
2431
+ }
2432
+ }
2433
+ };
2434
+
2435
+ Headers.prototype.keys = function() {
2436
+ var items = [];
2437
+ this.forEach(function(value, name) {
2438
+ items.push(name);
2439
+ });
2440
+ return iteratorFor(items)
2441
+ };
2442
+
2443
+ Headers.prototype.values = function() {
2444
+ var items = [];
2445
+ this.forEach(function(value) {
2446
+ items.push(value);
2447
+ });
2448
+ return iteratorFor(items)
2449
+ };
2450
+
2451
+ Headers.prototype.entries = function() {
2452
+ var items = [];
2453
+ this.forEach(function(value, name) {
2454
+ items.push([name, value]);
2455
+ });
2456
+ return iteratorFor(items)
2457
+ };
2458
+
2459
+ if (support.iterable) {
2460
+ Headers.prototype[Symbol.iterator] = Headers.prototype.entries;
2461
+ }
2462
+
2463
+ function consumed(body) {
2464
+ if (body.bodyUsed) {
2465
+ return Promise.reject(new TypeError('Already read'))
2466
+ }
2467
+ body.bodyUsed = true;
2468
+ }
2469
+
2470
+ function fileReaderReady(reader) {
2471
+ return new Promise(function(resolve, reject) {
2472
+ reader.onload = function() {
2473
+ resolve(reader.result);
2474
+ };
2475
+ reader.onerror = function() {
2476
+ reject(reader.error);
2477
+ };
2478
+ })
2479
+ }
2480
+
2481
+ function readBlobAsArrayBuffer(blob) {
2482
+ var reader = new FileReader();
2483
+ var promise = fileReaderReady(reader);
2484
+ reader.readAsArrayBuffer(blob);
2485
+ return promise
2486
+ }
2487
+
2488
+ function readBlobAsText(blob) {
2489
+ var reader = new FileReader();
2490
+ var promise = fileReaderReady(reader);
2491
+ reader.readAsText(blob);
2492
+ return promise
2493
+ }
2494
+
2495
+ function readArrayBufferAsText(buf) {
2496
+ var view = new Uint8Array(buf);
2497
+ var chars = new Array(view.length);
2498
+
2499
+ for (var i = 0; i < view.length; i++) {
2500
+ chars[i] = String.fromCharCode(view[i]);
2501
+ }
2502
+ return chars.join('')
2503
+ }
2504
+
2505
+ function bufferClone(buf) {
2506
+ if (buf.slice) {
2507
+ return buf.slice(0)
2508
+ } else {
2509
+ var view = new Uint8Array(buf.byteLength);
2510
+ view.set(new Uint8Array(buf));
2511
+ return view.buffer
2512
+ }
2513
+ }
2514
+
2515
+ function Body() {
2516
+ this.bodyUsed = false;
2517
+
2518
+ this._initBody = function(body) {
2519
+ this._bodyInit = body;
2520
+ if (!body) {
2521
+ this._bodyText = '';
2522
+ } else if (typeof body === 'string') {
2523
+ this._bodyText = body;
2524
+ } else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
2525
+ this._bodyBlob = body;
2526
+ } else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
2527
+ this._bodyFormData = body;
2528
+ } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
2529
+ this._bodyText = body.toString();
2530
+ } else if (support.arrayBuffer && support.blob && isDataView(body)) {
2531
+ this._bodyArrayBuffer = bufferClone(body.buffer);
2532
+ // IE 10-11 can't handle a DataView body.
2533
+ this._bodyInit = new Blob([this._bodyArrayBuffer]);
2534
+ } else if (support.arrayBuffer && (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))) {
2535
+ this._bodyArrayBuffer = bufferClone(body);
2536
+ } else {
2537
+ this._bodyText = body = Object.prototype.toString.call(body);
2538
+ }
2539
+
2540
+ if (!this.headers.get('content-type')) {
2541
+ if (typeof body === 'string') {
2542
+ this.headers.set('content-type', 'text/plain;charset=UTF-8');
2543
+ } else if (this._bodyBlob && this._bodyBlob.type) {
2544
+ this.headers.set('content-type', this._bodyBlob.type);
2545
+ } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
2546
+ this.headers.set('content-type', 'application/x-www-form-urlencoded;charset=UTF-8');
2547
+ }
2548
+ }
2549
+ };
2550
+
2551
+ if (support.blob) {
2552
+ this.blob = function() {
2553
+ var rejected = consumed(this);
2554
+ if (rejected) {
2555
+ return rejected
2556
+ }
2557
+
2558
+ if (this._bodyBlob) {
2559
+ return Promise.resolve(this._bodyBlob)
2560
+ } else if (this._bodyArrayBuffer) {
2561
+ return Promise.resolve(new Blob([this._bodyArrayBuffer]))
2562
+ } else if (this._bodyFormData) {
2563
+ throw new Error('could not read FormData body as blob')
2564
+ } else {
2565
+ return Promise.resolve(new Blob([this._bodyText]))
2566
+ }
2567
+ };
2568
+
2569
+ this.arrayBuffer = function() {
2570
+ if (this._bodyArrayBuffer) {
2571
+ return consumed(this) || Promise.resolve(this._bodyArrayBuffer)
2572
+ } else {
2573
+ return this.blob().then(readBlobAsArrayBuffer)
2574
+ }
2575
+ };
2576
+ }
2577
+
2578
+ this.text = function() {
2579
+ var rejected = consumed(this);
2580
+ if (rejected) {
2581
+ return rejected
2582
+ }
2583
+
2584
+ if (this._bodyBlob) {
2585
+ return readBlobAsText(this._bodyBlob)
2586
+ } else if (this._bodyArrayBuffer) {
2587
+ return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer))
2588
+ } else if (this._bodyFormData) {
2589
+ throw new Error('could not read FormData body as text')
2590
+ } else {
2591
+ return Promise.resolve(this._bodyText)
2592
+ }
2593
+ };
2594
+
2595
+ if (support.formData) {
2596
+ this.formData = function() {
2597
+ return this.text().then(decode)
2598
+ };
2599
+ }
2600
+
2601
+ this.json = function() {
2602
+ return this.text().then(JSON.parse)
2603
+ };
2604
+
2605
+ return this
2606
+ }
2607
+
2608
+ // HTTP methods whose capitalization should be normalized
2609
+ var methods = ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT'];
2610
+
2611
+ function normalizeMethod(method) {
2612
+ var upcased = method.toUpperCase();
2613
+ return methods.indexOf(upcased) > -1 ? upcased : method
2614
+ }
2615
+
2616
+ function Request(input, options) {
2617
+ options = options || {};
2618
+ var body = options.body;
2619
+
2620
+ if (input instanceof Request) {
2621
+ if (input.bodyUsed) {
2622
+ throw new TypeError('Already read')
2623
+ }
2624
+ this.url = input.url;
2625
+ this.credentials = input.credentials;
2626
+ if (!options.headers) {
2627
+ this.headers = new Headers(input.headers);
2628
+ }
2629
+ this.method = input.method;
2630
+ this.mode = input.mode;
2631
+ this.signal = input.signal;
2632
+ if (!body && input._bodyInit != null) {
2633
+ body = input._bodyInit;
2634
+ input.bodyUsed = true;
2635
+ }
2636
+ } else {
2637
+ this.url = String(input);
2638
+ }
2639
+
2640
+ this.credentials = options.credentials || this.credentials || 'same-origin';
2641
+ if (options.headers || !this.headers) {
2642
+ this.headers = new Headers(options.headers);
2643
+ }
2644
+ this.method = normalizeMethod(options.method || this.method || 'GET');
2645
+ this.mode = options.mode || this.mode || null;
2646
+ this.signal = options.signal || this.signal;
2647
+ this.referrer = null;
2648
+
2649
+ if ((this.method === 'GET' || this.method === 'HEAD') && body) {
2650
+ throw new TypeError('Body not allowed for GET or HEAD requests')
2651
+ }
2652
+ this._initBody(body);
2653
+ }
2654
+
2655
+ Request.prototype.clone = function() {
2656
+ return new Request(this, {body: this._bodyInit})
2657
+ };
2658
+
2659
+ function decode(body) {
2660
+ var form = new FormData();
2661
+ body
2662
+ .trim()
2663
+ .split('&')
2664
+ .forEach(function(bytes) {
2665
+ if (bytes) {
2666
+ var split = bytes.split('=');
2667
+ var name = split.shift().replace(/\+/g, ' ');
2668
+ var value = split.join('=').replace(/\+/g, ' ');
2669
+ form.append(decodeURIComponent(name), decodeURIComponent(value));
2670
+ }
2671
+ });
2672
+ return form
2673
+ }
2674
+
2675
+ function parseHeaders(rawHeaders) {
2676
+ var headers = new Headers();
2677
+ // Replace instances of \r\n and \n followed by at least one space or horizontal tab with a space
2678
+ // https://tools.ietf.org/html/rfc7230#section-3.2
2679
+ var preProcessedHeaders = rawHeaders.replace(/\r?\n[\t ]+/g, ' ');
2680
+ preProcessedHeaders.split(/\r?\n/).forEach(function(line) {
2681
+ var parts = line.split(':');
2682
+ var key = parts.shift().trim();
2683
+ if (key) {
2684
+ var value = parts.join(':').trim();
2685
+ headers.append(key, value);
2686
+ }
2687
+ });
2688
+ return headers
2689
+ }
2690
+
2691
+ Body.call(Request.prototype);
2692
+
2693
+ function Response(bodyInit, options) {
2694
+ if (!options) {
2695
+ options = {};
2696
+ }
2697
+
2698
+ this.type = 'default';
2699
+ this.status = options.status === undefined ? 200 : options.status;
2700
+ this.ok = this.status >= 200 && this.status < 300;
2701
+ this.statusText = 'statusText' in options ? options.statusText : 'OK';
2702
+ this.headers = new Headers(options.headers);
2703
+ this.url = options.url || '';
2704
+ this._initBody(bodyInit);
2705
+ }
2706
+
2707
+ Body.call(Response.prototype);
2708
+
2709
+ Response.prototype.clone = function() {
2710
+ return new Response(this._bodyInit, {
2711
+ status: this.status,
2712
+ statusText: this.statusText,
2713
+ headers: new Headers(this.headers),
2714
+ url: this.url
2715
+ })
2716
+ };
2717
+
2718
+ Response.error = function() {
2719
+ var response = new Response(null, {status: 0, statusText: ''});
2720
+ response.type = 'error';
2721
+ return response
2722
+ };
2723
+
2724
+ var redirectStatuses = [301, 302, 303, 307, 308];
2725
+
2726
+ Response.redirect = function(url, status) {
2727
+ if (redirectStatuses.indexOf(status) === -1) {
2728
+ throw new RangeError('Invalid status code')
2729
+ }
2287
2730
 
2288
- exports.Headers = global.Headers;
2289
- exports.Request = global.Request;
2290
- exports.Response = global.Response;
2291
- }(browser, browser.exports));
2731
+ return new Response(null, {status: status, headers: {location: url}})
2732
+ };
2292
2733
 
2293
- var fetch = browser.exports;
2734
+ exports.DOMException = self.DOMException;
2735
+ try {
2736
+ new exports.DOMException();
2737
+ } catch (err) {
2738
+ exports.DOMException = function(message, name) {
2739
+ this.message = message;
2740
+ this.name = name;
2741
+ var error = Error(message);
2742
+ this.stack = error.stack;
2743
+ };
2744
+ exports.DOMException.prototype = Object.create(Error.prototype);
2745
+ exports.DOMException.prototype.constructor = exports.DOMException;
2746
+ }
2747
+
2748
+ function fetch(input, init) {
2749
+ return new Promise(function(resolve, reject) {
2750
+ var request = new Request(input, init);
2751
+
2752
+ if (request.signal && request.signal.aborted) {
2753
+ return reject(new exports.DOMException('Aborted', 'AbortError'))
2754
+ }
2755
+
2756
+ var xhr = new XMLHttpRequest();
2757
+
2758
+ function abortXhr() {
2759
+ xhr.abort();
2760
+ }
2761
+
2762
+ xhr.onload = function() {
2763
+ var options = {
2764
+ status: xhr.status,
2765
+ statusText: xhr.statusText,
2766
+ headers: parseHeaders(xhr.getAllResponseHeaders() || '')
2767
+ };
2768
+ options.url = 'responseURL' in xhr ? xhr.responseURL : options.headers.get('X-Request-URL');
2769
+ var body = 'response' in xhr ? xhr.response : xhr.responseText;
2770
+ resolve(new Response(body, options));
2771
+ };
2772
+
2773
+ xhr.onerror = function() {
2774
+ reject(new TypeError('Network request failed'));
2775
+ };
2776
+
2777
+ xhr.ontimeout = function() {
2778
+ reject(new TypeError('Network request failed'));
2779
+ };
2780
+
2781
+ xhr.onabort = function() {
2782
+ reject(new exports.DOMException('Aborted', 'AbortError'));
2783
+ };
2784
+
2785
+ xhr.open(request.method, request.url, true);
2786
+
2787
+ if (request.credentials === 'include') {
2788
+ xhr.withCredentials = true;
2789
+ } else if (request.credentials === 'omit') {
2790
+ xhr.withCredentials = false;
2791
+ }
2792
+
2793
+ if ('responseType' in xhr && support.blob) {
2794
+ xhr.responseType = 'blob';
2795
+ }
2796
+
2797
+ request.headers.forEach(function(value, name) {
2798
+ xhr.setRequestHeader(name, value);
2799
+ });
2800
+
2801
+ if (request.signal) {
2802
+ request.signal.addEventListener('abort', abortXhr);
2803
+
2804
+ xhr.onreadystatechange = function() {
2805
+ // DONE (success or failure)
2806
+ if (xhr.readyState === 4) {
2807
+ request.signal.removeEventListener('abort', abortXhr);
2808
+ }
2809
+ };
2810
+ }
2811
+
2812
+ xhr.send(typeof request._bodyInit === 'undefined' ? null : request._bodyInit);
2813
+ })
2814
+ }
2815
+
2816
+ fetch.polyfill = true;
2817
+
2818
+ if (!self.fetch) {
2819
+ self.fetch = fetch;
2820
+ self.Headers = Headers;
2821
+ self.Request = Request;
2822
+ self.Response = Response;
2823
+ }
2824
+
2825
+ exports.Headers = Headers;
2826
+ exports.Request = Request;
2827
+ exports.Response = Response;
2828
+ exports.fetch = fetch;
2829
+
2830
+ Object.defineProperty(exports, '__esModule', { value: true });
2831
+
2832
+ return exports;
2833
+
2834
+ })({}));
2835
+ })(__self__);
2836
+ __self__.fetch.ponyfill = true;
2837
+ // Remove "polyfill" property added by whatwg-fetch
2838
+ delete __self__.fetch.polyfill;
2839
+ // Choose between native implementation (global) or custom implementation (__self__)
2840
+ // var ctx = global.fetch ? global : __self__;
2841
+ var ctx = __self__; // this line disable service worker support temporarily
2842
+ exports = ctx.fetch; // To enable: import fetch from 'cross-fetch'
2843
+ exports.default = ctx.fetch; // For TypeScript consumers without esModuleInterop.
2844
+ exports.fetch = ctx.fetch; // To enable: import {fetch} from 'cross-fetch'
2845
+ exports.Headers = ctx.Headers;
2846
+ exports.Request = ctx.Request;
2847
+ exports.Response = ctx.Response;
2848
+ module.exports = exports;
2849
+ }(browserPonyfill, browserPonyfill.exports));
2850
+
2851
+ var fetch = /*@__PURE__*/getDefaultExportFromCjs(browserPonyfill.exports);
2294
2852
 
2295
2853
  const MINIMUM_SLOT_PER_EPOCH = 32; // Returns the number of trailing zeros in the binary representation of self.
2296
2854
 
@@ -2609,7 +3167,15 @@ const VersionResult = type({
2609
3167
  });
2610
3168
  const SimulatedTransactionResponseStruct = jsonRpcResultAndContext(type({
2611
3169
  err: nullable(union([type({}), string()])),
2612
- logs: nullable(array(string()))
3170
+ logs: nullable(array(string())),
3171
+ accounts: optional(nullable(array(type({
3172
+ executable: boolean(),
3173
+ owner: string(),
3174
+ lamports: number(),
3175
+ data: array(string()),
3176
+ rentEpoch: optional(number())
3177
+ })))),
3178
+ unitsConsumed: optional(number())
2613
3179
  }));
2614
3180
 
2615
3181
  function createRpcClient(url, useHttps, httpHeaders, fetchMiddleware, disableRetryOnRateLimit) {
@@ -3335,6 +3901,8 @@ class Connection {
3335
3901
 
3336
3902
  /** @internal */
3337
3903
 
3904
+ /** @internal */
3905
+
3338
3906
  /**
3339
3907
  * Establish a JSON RPC connection
3340
3908
  *
@@ -3344,6 +3912,8 @@ class Connection {
3344
3912
  constructor(endpoint, commitmentOrConfig) {
3345
3913
  _defineProperty(this, "_commitment", void 0);
3346
3914
 
3915
+ _defineProperty(this, "_confirmTransactionInitialTimeout", void 0);
3916
+
3347
3917
  _defineProperty(this, "_rpcEndpoint", void 0);
3348
3918
 
3349
3919
  _defineProperty(this, "_rpcWsEndpoint", void 0);
@@ -3412,6 +3982,7 @@ class Connection {
3412
3982
  this._commitment = commitmentOrConfig;
3413
3983
  } else if (commitmentOrConfig) {
3414
3984
  this._commitment = commitmentOrConfig.commitment;
3985
+ this._confirmTransactionInitialTimeout = commitmentOrConfig.confirmTransactionInitialTimeout;
3415
3986
  wsEndpoint = commitmentOrConfig.wsEndpoint;
3416
3987
  httpHeaders = commitmentOrConfig.httpHeaders;
3417
3988
  fetchMiddleware = commitmentOrConfig.fetchMiddleware;
@@ -3871,7 +4442,7 @@ class Connection {
3871
4442
  reject(err);
3872
4443
  }
3873
4444
  });
3874
- let timeoutMs = 60 * 1000;
4445
+ let timeoutMs = this._confirmTransactionInitialTimeout || 60 * 1000;
3875
4446
 
3876
4447
  switch (subscriptionCommitment) {
3877
4448
  case 'processed':
@@ -3880,7 +4451,7 @@ class Connection {
3880
4451
  case 'confirmed':
3881
4452
  case 'singleGossip':
3882
4453
  {
3883
- timeoutMs = 30 * 1000;
4454
+ timeoutMs = this._confirmTransactionInitialTimeout || 30 * 1000;
3884
4455
  break;
3885
4456
  }
3886
4457
  }
@@ -4252,6 +4823,21 @@ class Connection {
4252
4823
 
4253
4824
  return res.result;
4254
4825
  }
4826
+ /**
4827
+ * Fetch the genesis hash
4828
+ */
4829
+
4830
+
4831
+ async getGenesisHash() {
4832
+ const unsafeRes = await this._rpcRequest('getGenesisHash', []);
4833
+ const res = create(unsafeRes, jsonRpcResult(string()));
4834
+
4835
+ if ('error' in res) {
4836
+ throw new Error('failed to get genesis hash: ' + res.error.message);
4837
+ }
4838
+
4839
+ return res.result;
4840
+ }
4255
4841
  /**
4256
4842
  * Fetch a processed block from the cluster.
4257
4843
  */
@@ -4652,7 +5238,15 @@ class Connection {
4652
5238
  */
4653
5239
 
4654
5240
 
4655
- async simulateTransaction(transaction, signers) {
5241
+ async simulateTransaction(transactionOrMessage, signers, includeAccounts) {
5242
+ let transaction;
5243
+
5244
+ if (transactionOrMessage instanceof Transaction) {
5245
+ transaction = transactionOrMessage;
5246
+ } else {
5247
+ transaction = Transaction.populate(transactionOrMessage);
5248
+ }
5249
+
4656
5250
  if (transaction.nonceInfo && signers) {
4657
5251
  transaction.sign(...signers);
4658
5252
  } else {
@@ -4685,7 +5279,9 @@ class Connection {
4685
5279
  }
4686
5280
  }
4687
5281
 
4688
- const signData = transaction.serializeMessage();
5282
+ const message = transaction._compile();
5283
+
5284
+ const signData = message.serialize();
4689
5285
 
4690
5286
  const wireTransaction = transaction._serialize(signData);
4691
5287
 
@@ -4695,6 +5291,14 @@ class Connection {
4695
5291
  commitment: this.commitment
4696
5292
  };
4697
5293
 
5294
+ if (includeAccounts) {
5295
+ const addresses = (Array.isArray(includeAccounts) ? includeAccounts : message.nonProgramIds()).map(key => key.toBase58());
5296
+ config['accounts'] = {
5297
+ encoding: 'base64',
5298
+ addresses
5299
+ };
5300
+ }
5301
+
4698
5302
  if (signers) {
4699
5303
  config.sigVerify = true;
4700
5304
  }
@@ -5575,6 +6179,96 @@ class Keypair {
5575
6179
 
5576
6180
  }
5577
6181
 
6182
+ const PRIVATE_KEY_BYTES$1 = 64;
6183
+ const PUBLIC_KEY_BYTES$1 = 32;
6184
+ const SIGNATURE_BYTES = 64;
6185
+ /**
6186
+ * Params for creating an ed25519 instruction using a public key
6187
+ */
6188
+
6189
+ const ED25519_INSTRUCTION_LAYOUT = BufferLayout.struct([BufferLayout.u8('numSignatures'), BufferLayout.u8('padding'), BufferLayout.u16('signatureOffset'), BufferLayout.u16('signatureInstructionIndex'), BufferLayout.u16('publicKeyOffset'), BufferLayout.u16('publicKeyInstructionIndex'), BufferLayout.u16('messageDataOffset'), BufferLayout.u16('messageDataSize'), BufferLayout.u16('messageInstructionIndex')]);
6190
+ class Ed25519Program {
6191
+ /**
6192
+ * @internal
6193
+ */
6194
+ constructor() {}
6195
+ /**
6196
+ * Public key that identifies the ed25519 program
6197
+ */
6198
+
6199
+
6200
+ /**
6201
+ * Create an ed25519 instruction with a public key and signature. The
6202
+ * public key must be a buffer that is 32 bytes long, and the signature
6203
+ * must be a buffer of 64 bytes.
6204
+ */
6205
+ static createInstructionWithPublicKey(params) {
6206
+ const {
6207
+ publicKey,
6208
+ message,
6209
+ signature,
6210
+ instructionIndex
6211
+ } = params;
6212
+ assert(publicKey.length === PUBLIC_KEY_BYTES$1, `Public Key must be ${PUBLIC_KEY_BYTES$1} bytes but received ${publicKey.length} bytes`);
6213
+ assert(signature.length === SIGNATURE_BYTES, `Signature must be ${SIGNATURE_BYTES} bytes but received ${signature.length} bytes`);
6214
+ const publicKeyOffset = ED25519_INSTRUCTION_LAYOUT.span;
6215
+ const signatureOffset = publicKeyOffset + publicKey.length;
6216
+ const messageDataOffset = signatureOffset + signature.length;
6217
+ const numSignatures = 1;
6218
+ const instructionData = Buffer.alloc(messageDataOffset + message.length);
6219
+ ED25519_INSTRUCTION_LAYOUT.encode({
6220
+ numSignatures,
6221
+ padding: 0,
6222
+ signatureOffset,
6223
+ signatureInstructionIndex: instructionIndex,
6224
+ publicKeyOffset,
6225
+ publicKeyInstructionIndex: instructionIndex,
6226
+ messageDataOffset,
6227
+ messageDataSize: message.length,
6228
+ messageInstructionIndex: instructionIndex
6229
+ }, instructionData);
6230
+ instructionData.fill(publicKey, publicKeyOffset);
6231
+ instructionData.fill(signature, signatureOffset);
6232
+ instructionData.fill(message, messageDataOffset);
6233
+ return new TransactionInstruction({
6234
+ keys: [],
6235
+ programId: Ed25519Program.programId,
6236
+ data: instructionData
6237
+ });
6238
+ }
6239
+ /**
6240
+ * Create an ed25519 instruction with a private key. The private key
6241
+ * must be a buffer that is 64 bytes long.
6242
+ */
6243
+
6244
+
6245
+ static createInstructionWithPrivateKey(params) {
6246
+ const {
6247
+ privateKey,
6248
+ message,
6249
+ instructionIndex
6250
+ } = params;
6251
+ assert(privateKey.length === PRIVATE_KEY_BYTES$1, `Private key must be ${PRIVATE_KEY_BYTES$1} bytes but received ${privateKey.length} bytes`);
6252
+
6253
+ try {
6254
+ const keypair = Keypair.fromSecretKey(privateKey);
6255
+ const publicKey = keypair.publicKey.toBytes();
6256
+ const signature = nacl__default.sign.detached(message, keypair.secretKey);
6257
+ return this.createInstructionWithPublicKey({
6258
+ publicKey,
6259
+ message,
6260
+ signature,
6261
+ instructionIndex
6262
+ });
6263
+ } catch (error) {
6264
+ throw new Error(`Error creating instruction; ${error}`);
6265
+ }
6266
+ }
6267
+
6268
+ }
6269
+
6270
+ _defineProperty(Ed25519Program, "programId", new PublicKey('Ed25519SigVerify111111111111111111111111111'));
6271
+
5578
6272
  /**
5579
6273
  * Address of the stake config account which configures the rate
5580
6274
  * of stake warmup and cooldown as well as the slashing penalty.
@@ -6707,5 +7401,5 @@ function clusterApiUrl(cluster, tls) {
6707
7401
 
6708
7402
  const LAMPORTS_PER_SOL = 1000000000;
6709
7403
 
6710
- export { Account, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, Connection, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PublicKey, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, SendTransactionError, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionInstruction, VALIDATOR_INFO_KEY, VOTE_PROGRAM_ID, ValidatorInfo, VoteAccount, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
7404
+ export { Account, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, Connection, Ed25519Program, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PublicKey, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, SendTransactionError, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionInstruction, VALIDATOR_INFO_KEY, VOTE_PROGRAM_ID, ValidatorInfo, VoteAccount, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
6711
7405
  //# sourceMappingURL=index.browser.esm.js.map