@solana/web3.js 2.0.0-experimental.b927e84 → 2.0.0-experimental.ba46ce1

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.
@@ -12,8 +12,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
12
12
  var __esm = (fn, res) => function __init() {
13
13
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
14
14
  };
15
- var __commonJS = (cb, mod) => function __require() {
16
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
15
+ var __commonJS = (cb, mod2) => function __require() {
16
+ return mod2 || (0, cb[__getOwnPropNames(cb)[0]])((mod2 = { exports: {} }).exports, mod2), mod2.exports;
17
17
  };
18
18
  var __copyProps = (to, from, except, desc) => {
19
19
  if (from && typeof from === "object" || typeof from === "function") {
@@ -23,13 +23,13 @@ this.globalThis.solanaWeb3 = (function (exports) {
23
23
  }
24
24
  return to;
25
25
  };
26
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
26
+ var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__getProtoOf(mod2)) : {}, __copyProps(
27
27
  // If the importer is in node compatibility mode or this is not an ESM
28
28
  // file that has been converted to a CommonJS file using a Babel-
29
29
  // compatible transform (i.e. "__esModule" has not been set), then set
30
30
  // "default" to the CommonJS "module.exports" for node compatibility.
31
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
32
- mod
31
+ isNodeMode || !mod2 || !mod2.__esModule ? __defProp(target, "default", { value: mod2, enumerable: true }) : target,
32
+ mod2
33
33
  ));
34
34
  var __publicField = (obj, key, value) => {
35
35
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
@@ -122,53 +122,16 @@ this.globalThis.solanaWeb3 = (function (exports) {
122
122
  // src/index.ts
123
123
  init_env_shim();
124
124
 
125
- // ../instructions/dist/index.browser.js
126
- init_env_shim();
127
- var AccountRole = /* @__PURE__ */ ((AccountRole22) => {
128
- AccountRole22[AccountRole22["WRITABLE_SIGNER"] = /* 3 */
129
- 3] = "WRITABLE_SIGNER";
130
- AccountRole22[AccountRole22["READONLY_SIGNER"] = /* 2 */
131
- 2] = "READONLY_SIGNER";
132
- AccountRole22[AccountRole22["WRITABLE"] = /* 1 */
133
- 1] = "WRITABLE";
134
- AccountRole22[AccountRole22["READONLY"] = /* 0 */
135
- 0] = "READONLY";
136
- return AccountRole22;
137
- })(AccountRole || {});
138
- var IS_SIGNER_BITMASK = 2;
139
- var IS_WRITABLE_BITMASK = 1;
140
- function downgradeRoleToNonSigner(role) {
141
- return role & ~IS_SIGNER_BITMASK;
142
- }
143
- function downgradeRoleToReadonly(role) {
144
- return role & ~IS_WRITABLE_BITMASK;
145
- }
146
- function isSignerRole(role) {
147
- return role >= 2;
148
- }
149
- function isWritableRole(role) {
150
- return (role & IS_WRITABLE_BITMASK) !== 0;
151
- }
152
- function mergeRoles(roleA, roleB) {
153
- return roleA | roleB;
154
- }
155
- function upgradeRoleToSigner(role) {
156
- return role | IS_SIGNER_BITMASK;
157
- }
158
- function upgradeRoleToWritable(role) {
159
- return role | IS_WRITABLE_BITMASK;
160
- }
161
-
162
- // ../keys/dist/index.browser.js
125
+ // ../addresses/dist/index.browser.js
163
126
  init_env_shim();
164
127
 
165
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/index.mjs
128
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/index.mjs
166
129
  init_env_shim();
167
130
 
168
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/index.mjs
131
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/index.mjs
169
132
  init_env_shim();
170
133
 
171
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/bytes.mjs
134
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/bytes.mjs
172
135
  init_env_shim();
173
136
  var mergeBytes = (bytesArr) => {
174
137
  const totalLength = bytesArr.reduce((total, arr) => total + arr.length, 0);
@@ -189,7 +152,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
189
152
  };
190
153
  var fixBytes = (bytes2, length) => padBytes(bytes2.slice(0, length), length);
191
154
 
192
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/errors.mjs
155
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/errors.mjs
193
156
  init_env_shim();
194
157
  var DeserializingEmptyBufferError = class extends Error {
195
158
  constructor(serializer) {
@@ -211,7 +174,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
211
174
  }
212
175
  };
213
176
 
214
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/fixSerializer.mjs
177
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/fixSerializer.mjs
215
178
  init_env_shim();
216
179
  function fixSerializer(serializer, fixedBytes, description) {
217
180
  return {
@@ -233,7 +196,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
233
196
  };
234
197
  }
235
198
 
236
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/mapSerializer.mjs
199
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/mapSerializer.mjs
237
200
  init_env_shim();
238
201
  function mapSerializer(serializer, unmap, map) {
239
202
  return {
@@ -248,13 +211,13 @@ this.globalThis.solanaWeb3 = (function (exports) {
248
211
  };
249
212
  }
250
213
 
251
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/index.mjs
214
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/index.mjs
252
215
  init_env_shim();
253
216
 
254
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseX.mjs
217
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseX.mjs
255
218
  init_env_shim();
256
219
 
257
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/errors.mjs
220
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/errors.mjs
258
221
  init_env_shim();
259
222
  var InvalidBaseStringError = class extends Error {
260
223
  constructor(value, base, cause) {
@@ -265,7 +228,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
265
228
  }
266
229
  };
267
230
 
268
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseX.mjs
231
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseX.mjs
269
232
  var baseX = (alphabet) => {
270
233
  const base = alphabet.length;
271
234
  const baseBigInt = BigInt(base);
@@ -319,18 +282,18 @@ this.globalThis.solanaWeb3 = (function (exports) {
319
282
  };
320
283
  };
321
284
 
322
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/base58.mjs
285
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/base58.mjs
323
286
  init_env_shim();
324
287
  var base58 = baseX("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
325
288
 
326
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/nullCharacters.mjs
289
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/nullCharacters.mjs
327
290
  init_env_shim();
328
291
  var removeNullCharacters = (value) => (
329
292
  // eslint-disable-next-line no-control-regex
330
293
  value.replace(/\u0000/g, "")
331
294
  );
332
295
 
333
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/utf8.mjs
296
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/utf8.mjs
334
297
  init_env_shim();
335
298
  var utf8 = {
336
299
  description: "utf8",
@@ -345,10 +308,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
345
308
  }
346
309
  };
347
310
 
348
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/index.mjs
311
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/index.mjs
349
312
  init_env_shim();
350
313
 
351
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/common.mjs
314
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/common.mjs
352
315
  init_env_shim();
353
316
  var Endian;
354
317
  (function(Endian2) {
@@ -356,7 +319,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
356
319
  Endian2["Big"] = "be";
357
320
  })(Endian || (Endian = {}));
358
321
 
359
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/errors.mjs
322
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/errors.mjs
360
323
  init_env_shim();
361
324
  var NumberOutOfRangeError = class extends RangeError {
362
325
  constructor(serializer, min, max, actual) {
@@ -365,7 +328,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
365
328
  }
366
329
  };
367
330
 
368
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/utils.mjs
331
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/utils.mjs
369
332
  init_env_shim();
370
333
  function numberFactory(input) {
371
334
  let littleEndian;
@@ -410,7 +373,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
410
373
  }
411
374
  };
412
375
 
413
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u8.mjs
376
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u8.mjs
414
377
  init_env_shim();
415
378
  var u8 = (options = {}) => numberFactory({
416
379
  name: "u8",
@@ -421,7 +384,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
421
384
  options
422
385
  });
423
386
 
424
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u32.mjs
387
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u32.mjs
425
388
  init_env_shim();
426
389
  var u32 = (options = {}) => numberFactory({
427
390
  name: "u32",
@@ -432,7 +395,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
432
395
  options
433
396
  });
434
397
 
435
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/shortU16.mjs
398
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/shortU16.mjs
436
399
  init_env_shim();
437
400
  var shortU16 = (options = {}) => ({
438
401
  description: options.description ?? "shortU16",
@@ -470,10 +433,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
470
433
  }
471
434
  });
472
435
 
473
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/array.mjs
436
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/array.mjs
474
437
  init_env_shim();
475
438
 
476
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/errors.mjs
439
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/errors.mjs
477
440
  init_env_shim();
478
441
  var InvalidNumberOfItemsError = class extends Error {
479
442
  constructor(serializer, expected, actual) {
@@ -494,16 +457,16 @@ this.globalThis.solanaWeb3 = (function (exports) {
494
457
  }
495
458
  };
496
459
 
497
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/utils.mjs
460
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/utils.mjs
498
461
  init_env_shim();
499
462
 
500
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/sumSerializerSizes.mjs
463
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/sumSerializerSizes.mjs
501
464
  init_env_shim();
502
465
  function sumSerializerSizes(sizes) {
503
466
  return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
504
467
  }
505
468
 
506
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/utils.mjs
469
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/utils.mjs
507
470
  function getResolvedSize(size, childrenSizes, bytes2, offset) {
508
471
  if (typeof size === "number") {
509
472
  return [size, offset];
@@ -539,7 +502,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
539
502
  return typeof size === "object" ? size.serialize(realSize) : new Uint8Array();
540
503
  }
541
504
 
542
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/array.mjs
505
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/array.mjs
543
506
  function array(item, options = {}) {
544
507
  const size = options.size ?? u32();
545
508
  if (size === "remainder" && item.fixedSize === null) {
@@ -572,7 +535,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
572
535
  };
573
536
  }
574
537
 
575
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/bytes.mjs
538
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/bytes.mjs
576
539
  init_env_shim();
577
540
  function bytes(options = {}) {
578
541
  const size = options.size ?? "variable";
@@ -620,7 +583,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
620
583
  };
621
584
  }
622
585
 
623
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/string.mjs
586
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/string.mjs
624
587
  init_env_shim();
625
588
  function string(options = {}) {
626
589
  const size = options.size ?? u32();
@@ -662,7 +625,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
662
625
  };
663
626
  }
664
627
 
665
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/struct.mjs
628
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/struct.mjs
666
629
  init_env_shim();
667
630
  function struct(fields, options = {}) {
668
631
  const fieldDescriptions = fields.map(([name, serializer]) => `${String(name)}: ${serializer.description}`).join(", ");
@@ -685,43 +648,9 @@ this.globalThis.solanaWeb3 = (function (exports) {
685
648
  }
686
649
  };
687
650
  }
688
- function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) {
689
- try {
690
- if (
691
- // Lowest address (32 bytes of zeroes)
692
- putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
693
- putativeBase58EncodedAddress.length > 44
694
- ) {
695
- throw new Error("Expected input string to decode to a byte array of length 32.");
696
- }
697
- const bytes2 = base58.serialize(putativeBase58EncodedAddress);
698
- const numBytes = bytes2.byteLength;
699
- if (numBytes !== 32) {
700
- throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
701
- }
702
- } catch (e2) {
703
- throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
704
- cause: e2
705
- });
706
- }
707
- }
708
- function getBase58EncodedAddressCodec(config) {
709
- return string({
710
- description: config?.description ?? ("A 32-byte account address" ),
711
- encoding: base58,
712
- size: 32
713
- });
714
- }
715
- function getBase58EncodedAddressComparator() {
716
- return new Intl.Collator("en", {
717
- caseFirst: "lower",
718
- ignorePunctuation: false,
719
- localeMatcher: "best fit",
720
- numeric: false,
721
- sensitivity: "variant",
722
- usage: "sort"
723
- }).compare;
724
- }
651
+
652
+ // ../assertions/dist/index.browser.js
653
+ init_env_shim();
725
654
  function assertIsSecureContext() {
726
655
  if (!globalThis.isSecureContext) {
727
656
  throw new Error(
@@ -751,6 +680,12 @@ this.globalThis.solanaWeb3 = (function (exports) {
751
680
  return await cachedEd25519Decision;
752
681
  }
753
682
  }
683
+ async function assertDigestCapabilityIsAvailable() {
684
+ assertIsSecureContext();
685
+ if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.digest !== "function") {
686
+ throw new Error("No digest implementation could be found");
687
+ }
688
+ }
754
689
  async function assertKeyGenerationIsAvailable() {
755
690
  assertIsSecureContext();
756
691
  if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.generateKey !== "function") {
@@ -780,6 +715,293 @@ this.globalThis.solanaWeb3 = (function (exports) {
780
715
  throw new Error("No signature verification implementation could be found");
781
716
  }
782
717
  }
718
+ function isBase58EncodedAddress(putativeBase58EncodedAddress) {
719
+ if (
720
+ // Lowest address (32 bytes of zeroes)
721
+ putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
722
+ putativeBase58EncodedAddress.length > 44
723
+ ) {
724
+ return false;
725
+ }
726
+ const bytes2 = base58.serialize(putativeBase58EncodedAddress);
727
+ const numBytes = bytes2.byteLength;
728
+ if (numBytes !== 32) {
729
+ return false;
730
+ }
731
+ return true;
732
+ }
733
+ function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) {
734
+ try {
735
+ if (
736
+ // Lowest address (32 bytes of zeroes)
737
+ putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
738
+ putativeBase58EncodedAddress.length > 44
739
+ ) {
740
+ throw new Error("Expected input string to decode to a byte array of length 32.");
741
+ }
742
+ const bytes2 = base58.serialize(putativeBase58EncodedAddress);
743
+ const numBytes = bytes2.byteLength;
744
+ if (numBytes !== 32) {
745
+ throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
746
+ }
747
+ } catch (e3) {
748
+ throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
749
+ cause: e3
750
+ });
751
+ }
752
+ }
753
+ function address(putativeBase58EncodedAddress) {
754
+ assertIsBase58EncodedAddress(putativeBase58EncodedAddress);
755
+ return putativeBase58EncodedAddress;
756
+ }
757
+ function getBase58EncodedAddressCodec(config) {
758
+ return string({
759
+ description: config?.description ?? ("A 32-byte account address" ),
760
+ encoding: base58,
761
+ size: 32
762
+ });
763
+ }
764
+ function getBase58EncodedAddressComparator() {
765
+ return new Intl.Collator("en", {
766
+ caseFirst: "lower",
767
+ ignorePunctuation: false,
768
+ localeMatcher: "best fit",
769
+ numeric: false,
770
+ sensitivity: "variant",
771
+ usage: "sort"
772
+ }).compare;
773
+ }
774
+ var D = 37095705934669439343138083508754565189542113879843219016388785533085940283555n;
775
+ var P = 57896044618658097711785492504343953926634992332820282019728792003956564819949n;
776
+ var RM1 = 19681161376707505956807079304988542015446066515923890162744021073123829784752n;
777
+ function mod(a) {
778
+ const r = a % P;
779
+ return r >= 0n ? r : P + r;
780
+ }
781
+ function pow2(x, power) {
782
+ let r = x;
783
+ while (power-- > 0n) {
784
+ r *= r;
785
+ r %= P;
786
+ }
787
+ return r;
788
+ }
789
+ function pow_2_252_3(x) {
790
+ const x2 = x * x % P;
791
+ const b2 = x2 * x % P;
792
+ const b4 = pow2(b2, 2n) * b2 % P;
793
+ const b5 = pow2(b4, 1n) * x % P;
794
+ const b10 = pow2(b5, 5n) * b5 % P;
795
+ const b20 = pow2(b10, 10n) * b10 % P;
796
+ const b40 = pow2(b20, 20n) * b20 % P;
797
+ const b80 = pow2(b40, 40n) * b40 % P;
798
+ const b160 = pow2(b80, 80n) * b80 % P;
799
+ const b240 = pow2(b160, 80n) * b80 % P;
800
+ const b250 = pow2(b240, 10n) * b10 % P;
801
+ const pow_p_5_8 = pow2(b250, 2n) * x % P;
802
+ return pow_p_5_8;
803
+ }
804
+ function uvRatio(u, v) {
805
+ const v3 = mod(v * v * v);
806
+ const v7 = mod(v3 * v3 * v);
807
+ const pow = pow_2_252_3(u * v7);
808
+ let x = mod(u * v3 * pow);
809
+ const vx2 = mod(v * x * x);
810
+ const root1 = x;
811
+ const root2 = mod(x * RM1);
812
+ const useRoot1 = vx2 === u;
813
+ const useRoot2 = vx2 === mod(-u);
814
+ const noRoot = vx2 === mod(-u * RM1);
815
+ if (useRoot1)
816
+ x = root1;
817
+ if (useRoot2 || noRoot)
818
+ x = root2;
819
+ if ((mod(x) & 1n) === 1n)
820
+ x = mod(-x);
821
+ if (!useRoot1 && !useRoot2) {
822
+ return null;
823
+ }
824
+ return x;
825
+ }
826
+ function pointIsOnCurve(y, lastByte) {
827
+ const y2 = mod(y * y);
828
+ const u = mod(y2 - 1n);
829
+ const v = mod(D * y2 + 1n);
830
+ const x = uvRatio(u, v);
831
+ if (x === null) {
832
+ return false;
833
+ }
834
+ const isLastByteOdd = (lastByte & 128) !== 0;
835
+ if (x === 0n && isLastByteOdd) {
836
+ return false;
837
+ }
838
+ return true;
839
+ }
840
+ function byteToHex(byte) {
841
+ const hexString = byte.toString(16);
842
+ if (hexString.length === 1) {
843
+ return `0${hexString}`;
844
+ } else {
845
+ return hexString;
846
+ }
847
+ }
848
+ function decompressPointBytes(bytes2) {
849
+ const hexString = bytes2.reduce((acc, byte, ii) => `${byteToHex(ii === 31 ? byte & ~128 : byte)}${acc}`, "");
850
+ const integerLiteralString = `0x${hexString}`;
851
+ return BigInt(integerLiteralString);
852
+ }
853
+ async function compressedPointBytesAreOnCurve(bytes2) {
854
+ if (bytes2.byteLength !== 32) {
855
+ return false;
856
+ }
857
+ const y = decompressPointBytes(bytes2);
858
+ return pointIsOnCurve(y, bytes2[31]);
859
+ }
860
+ var MAX_SEED_LENGTH = 32;
861
+ var MAX_SEEDS = 16;
862
+ var PDA_MARKER_BYTES = [
863
+ // The string 'ProgramDerivedAddress'
864
+ 80,
865
+ 114,
866
+ 111,
867
+ 103,
868
+ 114,
869
+ 97,
870
+ 109,
871
+ 68,
872
+ 101,
873
+ 114,
874
+ 105,
875
+ 118,
876
+ 101,
877
+ 100,
878
+ 65,
879
+ 100,
880
+ 100,
881
+ 114,
882
+ 101,
883
+ 115,
884
+ 115
885
+ ];
886
+ var PointOnCurveError = class extends Error {
887
+ };
888
+ async function createProgramDerivedAddress({ programAddress, seeds }) {
889
+ await assertDigestCapabilityIsAvailable();
890
+ if (seeds.length > MAX_SEEDS) {
891
+ throw new Error(`A maximum of ${MAX_SEEDS} seeds may be supplied when creating an address`);
892
+ }
893
+ let textEncoder;
894
+ const seedBytes = seeds.reduce((acc, seed, ii) => {
895
+ const bytes2 = typeof seed === "string" ? (textEncoder || (textEncoder = new TextEncoder())).encode(seed) : seed;
896
+ if (bytes2.byteLength > MAX_SEED_LENGTH) {
897
+ throw new Error(`The seed at index ${ii} exceeds the maximum length of 32 bytes`);
898
+ }
899
+ acc.push(...bytes2);
900
+ return acc;
901
+ }, []);
902
+ const base58EncodedAddressCodec = getBase58EncodedAddressCodec();
903
+ const programAddressBytes = base58EncodedAddressCodec.serialize(programAddress);
904
+ const addressBytesBuffer = await crypto.subtle.digest(
905
+ "SHA-256",
906
+ new Uint8Array([...seedBytes, ...programAddressBytes, ...PDA_MARKER_BYTES])
907
+ );
908
+ const addressBytes = new Uint8Array(addressBytesBuffer);
909
+ if (await compressedPointBytesAreOnCurve(addressBytes)) {
910
+ throw new PointOnCurveError("Invalid seeds; point must fall off the Ed25519 curve");
911
+ }
912
+ return base58EncodedAddressCodec.deserialize(addressBytes)[0];
913
+ }
914
+ async function getProgramDerivedAddress({ programAddress, seeds }) {
915
+ let bumpSeed = 255;
916
+ while (bumpSeed > 0) {
917
+ try {
918
+ return {
919
+ bumpSeed,
920
+ pda: await createProgramDerivedAddress({
921
+ programAddress,
922
+ seeds: [...seeds, new Uint8Array([bumpSeed])]
923
+ })
924
+ };
925
+ } catch (e3) {
926
+ if (e3 instanceof PointOnCurveError) {
927
+ bumpSeed--;
928
+ } else {
929
+ throw e3;
930
+ }
931
+ }
932
+ }
933
+ throw new Error("Unable to find a viable program address bump seed");
934
+ }
935
+ async function createAddressWithSeed({
936
+ baseAddress,
937
+ programAddress,
938
+ seed
939
+ }) {
940
+ const { serialize: serialize4, deserialize: deserialize2 } = getBase58EncodedAddressCodec();
941
+ const seedBytes = typeof seed === "string" ? new TextEncoder().encode(seed) : seed;
942
+ if (seedBytes.byteLength > MAX_SEED_LENGTH) {
943
+ throw new Error(`The seed exceeds the maximum length of 32 bytes`);
944
+ }
945
+ const programAddressBytes = serialize4(programAddress);
946
+ if (programAddressBytes.length >= PDA_MARKER_BYTES.length && programAddressBytes.slice(-PDA_MARKER_BYTES.length).every((byte, index) => byte === PDA_MARKER_BYTES[index])) {
947
+ throw new Error(`programAddress cannot end with the PDA marker`);
948
+ }
949
+ const addressBytesBuffer = await crypto.subtle.digest(
950
+ "SHA-256",
951
+ new Uint8Array([...serialize4(baseAddress), ...seedBytes, ...programAddressBytes])
952
+ );
953
+ const addressBytes = new Uint8Array(addressBytesBuffer);
954
+ return deserialize2(addressBytes)[0];
955
+ }
956
+ async function getAddressFromPublicKey(publicKey) {
957
+ await assertKeyExporterIsAvailable();
958
+ if (publicKey.type !== "public" || publicKey.algorithm.name !== "Ed25519") {
959
+ throw new Error("The `CryptoKey` must be an `Ed25519` public key");
960
+ }
961
+ const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
962
+ const [base58EncodedAddress] = getBase58EncodedAddressCodec().deserialize(new Uint8Array(publicKeyBytes));
963
+ return base58EncodedAddress;
964
+ }
965
+
966
+ // ../instructions/dist/index.browser.js
967
+ init_env_shim();
968
+ var AccountRole = /* @__PURE__ */ ((AccountRole22) => {
969
+ AccountRole22[AccountRole22["WRITABLE_SIGNER"] = /* 3 */
970
+ 3] = "WRITABLE_SIGNER";
971
+ AccountRole22[AccountRole22["READONLY_SIGNER"] = /* 2 */
972
+ 2] = "READONLY_SIGNER";
973
+ AccountRole22[AccountRole22["WRITABLE"] = /* 1 */
974
+ 1] = "WRITABLE";
975
+ AccountRole22[AccountRole22["READONLY"] = /* 0 */
976
+ 0] = "READONLY";
977
+ return AccountRole22;
978
+ })(AccountRole || {});
979
+ var IS_SIGNER_BITMASK = 2;
980
+ var IS_WRITABLE_BITMASK = 1;
981
+ function downgradeRoleToNonSigner(role) {
982
+ return role & ~IS_SIGNER_BITMASK;
983
+ }
984
+ function downgradeRoleToReadonly(role) {
985
+ return role & ~IS_WRITABLE_BITMASK;
986
+ }
987
+ function isSignerRole(role) {
988
+ return role >= 2;
989
+ }
990
+ function isWritableRole(role) {
991
+ return (role & IS_WRITABLE_BITMASK) !== 0;
992
+ }
993
+ function mergeRoles(roleA, roleB) {
994
+ return roleA | roleB;
995
+ }
996
+ function upgradeRoleToSigner(role) {
997
+ return role | IS_SIGNER_BITMASK;
998
+ }
999
+ function upgradeRoleToWritable(role) {
1000
+ return role | IS_WRITABLE_BITMASK;
1001
+ }
1002
+
1003
+ // ../keys/dist/index.browser.js
1004
+ init_env_shim();
783
1005
  async function generateKeyPair() {
784
1006
  await assertKeyGenerationIsAvailable();
785
1007
  const keyPair = await crypto.subtle.generateKey(
@@ -794,15 +1016,6 @@ this.globalThis.solanaWeb3 = (function (exports) {
794
1016
  );
795
1017
  return keyPair;
796
1018
  }
797
- async function getBase58EncodedAddressFromPublicKey(publicKey) {
798
- await assertKeyExporterIsAvailable();
799
- if (publicKey.type !== "public" || publicKey.algorithm.name !== "Ed25519") {
800
- throw new Error("The `CryptoKey` must be an `Ed25519` public key");
801
- }
802
- const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
803
- const [base58EncodedAddress] = getBase58EncodedAddressCodec().deserialize(new Uint8Array(publicKeyBytes));
804
- return base58EncodedAddress;
805
- }
806
1019
  async function signBytes(key, data) {
807
1020
  await assertSigningCapabilityIsAvailable();
808
1021
  const signedData = await crypto.subtle.sign("Ed25519", key, data);
@@ -841,9 +1054,9 @@ this.globalThis.solanaWeb3 = (function (exports) {
841
1054
  if (numBytes !== 32) {
842
1055
  throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
843
1056
  }
844
- } catch (e2) {
1057
+ } catch (e3) {
845
1058
  throw new Error(`\`${putativeBlockhash}\` is not a blockhash`, {
846
- cause: e2
1059
+ cause: e3
847
1060
  });
848
1061
  }
849
1062
  }
@@ -973,8 +1186,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
973
1186
  Object.freeze(out);
974
1187
  return out;
975
1188
  }
976
- function upsert(addressMap, address, update) {
977
- addressMap[address] = update(addressMap[address] ?? { role: AccountRole2.READONLY });
1189
+ function upsert(addressMap, address2, update) {
1190
+ addressMap[address2] = update(addressMap[address2] ?? { role: AccountRole2.READONLY });
978
1191
  }
979
1192
  var TYPE = Symbol("AddressMapTypeProperty");
980
1193
  function getAddressMapFromInstructions(feePayer, instructions) {
@@ -1139,8 +1352,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
1139
1352
  } else {
1140
1353
  return addressComparator(leftAddress, rightAddress);
1141
1354
  }
1142
- }).map(([address, addressMeta]) => ({
1143
- address,
1355
+ }).map(([address2, addressMeta]) => ({
1356
+ address: address2,
1144
1357
  ...addressMeta
1145
1358
  }));
1146
1359
  return orderedAccounts;
@@ -1203,7 +1416,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
1203
1416
  return instructions.map(({ accounts, data, programAddress }) => {
1204
1417
  return {
1205
1418
  programAddressIndex: accountIndex[programAddress],
1206
- ...accounts ? { accountIndices: accounts.map(({ address }) => accountIndex[address]) } : null,
1419
+ ...accounts ? { accountIndices: accounts.map(({ address: address2 }) => accountIndex[address2]) } : null,
1207
1420
  ...data ? { data } : null
1208
1421
  };
1209
1422
  });
@@ -1217,7 +1430,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
1217
1430
  function getCompiledStaticAccounts(orderedAccounts) {
1218
1431
  const firstLookupTableAccountIndex = orderedAccounts.findIndex((account) => "lookupTableAddress" in account);
1219
1432
  const orderedStaticAccounts = firstLookupTableAccountIndex === -1 ? orderedAccounts : orderedAccounts.slice(0, firstLookupTableAccountIndex);
1220
- return orderedStaticAccounts.map(({ address }) => address);
1433
+ return orderedStaticAccounts.map(({ address: address2 }) => address2);
1221
1434
  }
1222
1435
  function compileMessage(transaction) {
1223
1436
  const addressMap = getAddressMapFromInstructions(transaction.feePayer, transaction.instructions);
@@ -1311,7 +1524,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
1311
1524
  )
1312
1525
  ],
1313
1526
  [
1314
- "addressIndices",
1527
+ "accountIndices",
1315
1528
  array(
1316
1529
  u8({
1317
1530
  description: "The index of an account, according to the well-ordered accounts list for this transaction"
@@ -1331,23 +1544,23 @@ this.globalThis.solanaWeb3 = (function (exports) {
1331
1544
  ]
1332
1545
  ]),
1333
1546
  (value) => {
1334
- if (value.addressIndices !== void 0 && value.data !== void 0) {
1547
+ if (value.accountIndices !== void 0 && value.data !== void 0) {
1335
1548
  return value;
1336
1549
  }
1337
1550
  return {
1338
1551
  ...value,
1339
- addressIndices: value.addressIndices ?? [],
1552
+ accountIndices: value.accountIndices ?? [],
1340
1553
  data: value.data ?? new Uint8Array(0)
1341
1554
  };
1342
1555
  },
1343
1556
  (value) => {
1344
- if (value.addressIndices.length && value.data.byteLength) {
1557
+ if (value.accountIndices.length && value.data.byteLength) {
1345
1558
  return value;
1346
1559
  }
1347
- const { addressIndices, data, ...rest } = value;
1560
+ const { accountIndices, data, ...rest } = value;
1348
1561
  return {
1349
1562
  ...rest,
1350
- ...addressIndices.length ? { addressIndices } : null,
1563
+ ...accountIndices.length ? { accountIndices } : null,
1351
1564
  ...data.byteLength ? { data } : null
1352
1565
  };
1353
1566
  }
@@ -1467,16 +1680,20 @@ this.globalThis.solanaWeb3 = (function (exports) {
1467
1680
  const signature = await signBytes(secretKey, wireMessageBytes);
1468
1681
  return signature;
1469
1682
  }
1470
- async function signTransaction(keyPair, transaction) {
1683
+ async function signTransaction(keyPairs, transaction) {
1471
1684
  const compiledMessage = compileMessage(transaction);
1472
- const [signerPublicKey, signature] = await Promise.all([
1473
- getBase58EncodedAddressFromPublicKey(keyPair.publicKey),
1474
- getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
1475
- ]);
1476
- const nextSignatures = {
1477
- ..."signatures" in transaction ? transaction.signatures : null,
1478
- ...{ [signerPublicKey]: signature }
1479
- };
1685
+ const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
1686
+ const publicKeySignaturePairs = await Promise.all(
1687
+ keyPairs.map(
1688
+ (keyPair) => Promise.all([
1689
+ getAddressFromPublicKey(keyPair.publicKey),
1690
+ getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
1691
+ ])
1692
+ )
1693
+ );
1694
+ for (const [signerPublicKey, signature] of publicKeySignaturePairs) {
1695
+ nextSignatures[signerPublicKey] = signature;
1696
+ }
1480
1697
  const out = {
1481
1698
  ...transaction,
1482
1699
  signatures: nextSignatures
@@ -1535,6 +1752,12 @@ this.globalThis.solanaWeb3 = (function (exports) {
1535
1752
  // src/rpc.ts
1536
1753
  init_env_shim();
1537
1754
 
1755
+ // ../functional/dist/index.browser.js
1756
+ init_env_shim();
1757
+ function pipe(init, ...fns) {
1758
+ return fns.reduce((acc, fn) => fn(acc), init);
1759
+ }
1760
+
1538
1761
  // ../rpc-core/dist/index.browser.js
1539
1762
  init_env_shim();
1540
1763
  function visitNode(value, keyPath, onIntegerOverflow) {
@@ -1563,85 +1786,246 @@ this.globalThis.solanaWeb3 = (function (exports) {
1563
1786
  return visitNode(params, [], onIntegerOverflow);
1564
1787
  }
1565
1788
  var KEYPATH_WILDCARD = {};
1566
- var ALLOWED_NUMERIC_KEYPATHS = {
1567
- getAccountInfo: [
1568
- // parsed AddressTableLookup account
1569
- ["value", "data", "parsed", "info", "lastExtendedSlotStartIndex"],
1570
- // parsed Config account
1571
- ["value", "data", "parsed", "info", "slashPenalty"],
1572
- ["value", "data", "parsed", "info", "warmupCooldownRate"],
1573
- // parsed Token/Token22 token account
1574
- ["value", "data", "parsed", "info", "tokenAmount", "decimals"],
1575
- ["value", "data", "parsed", "info", "tokenAmount", "uiAmount"],
1576
- ["value", "data", "parsed", "info", "rentExemptReserve", "decimals"],
1577
- ["value", "data", "parsed", "info", "delegatedAmount", "decimals"],
1578
- [
1579
- "value",
1580
- "data",
1581
- "parsed",
1582
- "info",
1583
- "extensions",
1584
- KEYPATH_WILDCARD,
1585
- "state",
1586
- "olderTransferFee",
1587
- "transferFeeBasisPoints"
1588
- ],
1589
- [
1590
- "value",
1591
- "data",
1592
- "parsed",
1593
- "info",
1594
- "extensions",
1595
- KEYPATH_WILDCARD,
1596
- "state",
1597
- "newerTransferFee",
1598
- "transferFeeBasisPoints"
1599
- ],
1600
- ["value", "data", "parsed", "info", "extensions", KEYPATH_WILDCARD, "state", "preUpdateAverageRate"],
1601
- ["value", "data", "parsed", "info", "extensions", KEYPATH_WILDCARD, "state", "currentRate"],
1602
- // parsed Token/Token22 mint account
1603
- ["value", "data", "parsed", "info", "decimals"],
1604
- // parsed Token/Token22 multisig account
1605
- ["value", "data", "parsed", "info", "numRequiredSigners"],
1606
- ["value", "data", "parsed", "info", "numValidSigners"],
1607
- // parsed Stake account
1608
- ["value", "data", "parsed", "info", "stake", "delegation", "warmupCooldownRate"],
1609
- // parsed Sysvar rent account
1610
- ["value", "data", "parsed", "info", "exemptionThreshold"],
1611
- ["value", "data", "parsed", "info", "burnPercent"],
1612
- // parsed Vote account
1613
- ["value", "data", "parsed", "info", "commission"],
1614
- ["value", "data", "parsed", "info", "votes", KEYPATH_WILDCARD, "confirmationCount"]
1615
- ],
1616
- getBlockTime: [[]],
1617
- getInflationReward: [[KEYPATH_WILDCARD, "commission"]],
1618
- getRecentPerformanceSamples: [[KEYPATH_WILDCARD, "samplePeriodSecs"]],
1619
- getTokenLargestAccounts: [
1620
- ["value", KEYPATH_WILDCARD, "decimals"],
1621
- ["value", KEYPATH_WILDCARD, "uiAmount"]
1622
- ],
1623
- getTransaction: [
1624
- ["meta", "preTokenBalances", KEYPATH_WILDCARD, "accountIndex"],
1625
- ["meta", "preTokenBalances", KEYPATH_WILDCARD, "uiTokenAmount", "decimals"],
1626
- ["meta", "postTokenBalances", KEYPATH_WILDCARD, "accountIndex"],
1627
- ["meta", "postTokenBalances", KEYPATH_WILDCARD, "uiTokenAmount", "decimals"],
1628
- ["meta", "rewards", KEYPATH_WILDCARD, "commission"],
1629
- ["meta", "innerInstructions", KEYPATH_WILDCARD, "index"],
1630
- ["meta", "innerInstructions", KEYPATH_WILDCARD, "instructions", KEYPATH_WILDCARD, "programIdIndex"],
1631
- ["meta", "innerInstructions", KEYPATH_WILDCARD, "instructions", KEYPATH_WILDCARD, "accounts", KEYPATH_WILDCARD],
1632
- ["transaction", "message", "addressTableLookups", KEYPATH_WILDCARD, "writableIndexes", KEYPATH_WILDCARD],
1633
- ["transaction", "message", "addressTableLookups", KEYPATH_WILDCARD, "readonlyIndexes", KEYPATH_WILDCARD],
1634
- ["transaction", "message", "instructions", KEYPATH_WILDCARD, "programIdIndex"],
1635
- ["transaction", "message", "instructions", KEYPATH_WILDCARD, "accounts", KEYPATH_WILDCARD],
1636
- ["transaction", "message", "header", "numReadonlySignedAccounts"],
1637
- ["transaction", "message", "header", "numReadonlyUnsignedAccounts"],
1638
- ["transaction", "message", "header", "numRequiredSignatures"]
1639
- ],
1640
- getVoteAccounts: [
1641
- ["current", KEYPATH_WILDCARD, "commission"],
1642
- ["delinquent", KEYPATH_WILDCARD, "commission"]
1643
- ]
1644
- };
1789
+ var memoizedNotificationKeypaths;
1790
+ var memoizedResponseKeypaths;
1791
+ function getAllowedNumericKeypathsForNotification() {
1792
+ if (!memoizedNotificationKeypaths) {
1793
+ memoizedNotificationKeypaths = {};
1794
+ }
1795
+ return memoizedNotificationKeypaths;
1796
+ }
1797
+ function getAllowedNumericKeypathsForResponse() {
1798
+ if (!memoizedResponseKeypaths) {
1799
+ const jsonParsedTokenAccountsConfigs = [
1800
+ // parsed Token/Token22 token account
1801
+ ["data", "parsed", "info", "tokenAmount", "decimals"],
1802
+ ["data", "parsed", "info", "tokenAmount", "uiAmount"],
1803
+ ["data", "parsed", "info", "rentExemptReserve", "decimals"],
1804
+ ["data", "parsed", "info", "rentExemptReserve", "uiAmount"],
1805
+ ["data", "parsed", "info", "delegatedAmount", "decimals"],
1806
+ ["data", "parsed", "info", "delegatedAmount", "uiAmount"],
1807
+ [
1808
+ "data",
1809
+ "parsed",
1810
+ "info",
1811
+ "extensions",
1812
+ KEYPATH_WILDCARD,
1813
+ "state",
1814
+ "olderTransferFee",
1815
+ "transferFeeBasisPoints"
1816
+ ],
1817
+ [
1818
+ "data",
1819
+ "parsed",
1820
+ "info",
1821
+ "extensions",
1822
+ KEYPATH_WILDCARD,
1823
+ "state",
1824
+ "newerTransferFee",
1825
+ "transferFeeBasisPoints"
1826
+ ],
1827
+ ["data", "parsed", "info", "extensions", KEYPATH_WILDCARD, "state", "preUpdateAverageRate"],
1828
+ ["data", "parsed", "info", "extensions", KEYPATH_WILDCARD, "state", "currentRate"]
1829
+ ];
1830
+ const jsonParsedAccountsConfigs = [
1831
+ ...jsonParsedTokenAccountsConfigs,
1832
+ // parsed AddressTableLookup account
1833
+ ["data", "parsed", "info", "lastExtendedSlotStartIndex"],
1834
+ // parsed Config account
1835
+ ["data", "parsed", "info", "slashPenalty"],
1836
+ ["data", "parsed", "info", "warmupCooldownRate"],
1837
+ // parsed Token/Token22 mint account
1838
+ ["data", "parsed", "info", "decimals"],
1839
+ // parsed Token/Token22 multisig account
1840
+ ["data", "parsed", "info", "numRequiredSigners"],
1841
+ ["data", "parsed", "info", "numValidSigners"],
1842
+ // parsed Stake account
1843
+ ["data", "parsed", "info", "stake", "delegation", "warmupCooldownRate"],
1844
+ // parsed Sysvar rent account
1845
+ ["data", "parsed", "info", "exemptionThreshold"],
1846
+ ["data", "parsed", "info", "burnPercent"],
1847
+ // parsed Vote account
1848
+ ["data", "parsed", "info", "commission"],
1849
+ ["data", "parsed", "info", "votes", KEYPATH_WILDCARD, "confirmationCount"]
1850
+ ];
1851
+ memoizedResponseKeypaths = {
1852
+ getAccountInfo: jsonParsedAccountsConfigs.map((c) => ["value", ...c]),
1853
+ getBlock: [
1854
+ ["blockTime"],
1855
+ ["transactions", KEYPATH_WILDCARD, "meta", "preTokenBalances", KEYPATH_WILDCARD, "accountIndex"],
1856
+ [
1857
+ "transactions",
1858
+ KEYPATH_WILDCARD,
1859
+ "meta",
1860
+ "preTokenBalances",
1861
+ KEYPATH_WILDCARD,
1862
+ "uiTokenAmount",
1863
+ "decimals"
1864
+ ],
1865
+ ["transactions", KEYPATH_WILDCARD, "meta", "postTokenBalances", KEYPATH_WILDCARD, "accountIndex"],
1866
+ [
1867
+ "transactions",
1868
+ KEYPATH_WILDCARD,
1869
+ "meta",
1870
+ "postTokenBalances",
1871
+ KEYPATH_WILDCARD,
1872
+ "uiTokenAmount",
1873
+ "decimals"
1874
+ ],
1875
+ ["transactions", KEYPATH_WILDCARD, "meta", "rewards", KEYPATH_WILDCARD, "commission"],
1876
+ ["transactions", KEYPATH_WILDCARD, "meta", "innerInstructions", KEYPATH_WILDCARD, "index"],
1877
+ [
1878
+ "transactions",
1879
+ KEYPATH_WILDCARD,
1880
+ "meta",
1881
+ "innerInstructions",
1882
+ KEYPATH_WILDCARD,
1883
+ "instructions",
1884
+ KEYPATH_WILDCARD,
1885
+ "programIdIndex"
1886
+ ],
1887
+ [
1888
+ "transactions",
1889
+ KEYPATH_WILDCARD,
1890
+ "meta",
1891
+ "innerInstructions",
1892
+ KEYPATH_WILDCARD,
1893
+ "instructions",
1894
+ KEYPATH_WILDCARD,
1895
+ "accounts",
1896
+ KEYPATH_WILDCARD
1897
+ ],
1898
+ [
1899
+ "transactions",
1900
+ KEYPATH_WILDCARD,
1901
+ "transaction",
1902
+ "message",
1903
+ "addressTableLookups",
1904
+ KEYPATH_WILDCARD,
1905
+ "writableIndexes",
1906
+ KEYPATH_WILDCARD
1907
+ ],
1908
+ [
1909
+ "transactions",
1910
+ KEYPATH_WILDCARD,
1911
+ "transaction",
1912
+ "message",
1913
+ "addressTableLookups",
1914
+ KEYPATH_WILDCARD,
1915
+ "readonlyIndexes",
1916
+ KEYPATH_WILDCARD
1917
+ ],
1918
+ [
1919
+ "transactions",
1920
+ KEYPATH_WILDCARD,
1921
+ "transaction",
1922
+ "message",
1923
+ "instructions",
1924
+ KEYPATH_WILDCARD,
1925
+ "programIdIndex"
1926
+ ],
1927
+ [
1928
+ "transactions",
1929
+ KEYPATH_WILDCARD,
1930
+ "transaction",
1931
+ "message",
1932
+ "instructions",
1933
+ KEYPATH_WILDCARD,
1934
+ "accounts",
1935
+ KEYPATH_WILDCARD
1936
+ ],
1937
+ ["transactions", KEYPATH_WILDCARD, "transaction", "message", "header", "numReadonlySignedAccounts"],
1938
+ ["transactions", KEYPATH_WILDCARD, "transaction", "message", "header", "numReadonlyUnsignedAccounts"],
1939
+ ["transactions", KEYPATH_WILDCARD, "transaction", "message", "header", "numRequiredSignatures"],
1940
+ ["rewards", KEYPATH_WILDCARD, "commission"]
1941
+ ],
1942
+ getBlockTime: [[]],
1943
+ getClusterNodes: [
1944
+ [KEYPATH_WILDCARD, "featureSet"],
1945
+ [KEYPATH_WILDCARD, "shredVersion"]
1946
+ ],
1947
+ getInflationGovernor: [["initial"], ["foundation"], ["foundationTerm"], ["taper"], ["terminal"]],
1948
+ getInflationRate: [["foundation"], ["total"], ["validator"]],
1949
+ getInflationReward: [[KEYPATH_WILDCARD, "commission"]],
1950
+ getMultipleAccounts: jsonParsedAccountsConfigs.map((c) => ["value", KEYPATH_WILDCARD, ...c]),
1951
+ getProgramAccounts: jsonParsedAccountsConfigs.flatMap((c) => [
1952
+ ["value", KEYPATH_WILDCARD, "account", ...c],
1953
+ [KEYPATH_WILDCARD, "account", ...c]
1954
+ ]),
1955
+ getRecentPerformanceSamples: [[KEYPATH_WILDCARD, "samplePeriodSecs"]],
1956
+ getTokenAccountBalance: [
1957
+ ["value", "decimals"],
1958
+ ["value", "uiAmount"]
1959
+ ],
1960
+ getTokenAccountsByDelegate: jsonParsedTokenAccountsConfigs.map((c) => [
1961
+ "value",
1962
+ KEYPATH_WILDCARD,
1963
+ "account",
1964
+ ...c
1965
+ ]),
1966
+ getTokenAccountsByOwner: jsonParsedTokenAccountsConfigs.map((c) => [
1967
+ "value",
1968
+ KEYPATH_WILDCARD,
1969
+ "account",
1970
+ ...c
1971
+ ]),
1972
+ getTokenLargestAccounts: [
1973
+ ["value", KEYPATH_WILDCARD, "decimals"],
1974
+ ["value", KEYPATH_WILDCARD, "uiAmount"]
1975
+ ],
1976
+ getTokenSupply: [
1977
+ ["value", "decimals"],
1978
+ ["value", "uiAmount"]
1979
+ ],
1980
+ getTransaction: [
1981
+ ["meta", "preTokenBalances", KEYPATH_WILDCARD, "accountIndex"],
1982
+ ["meta", "preTokenBalances", KEYPATH_WILDCARD, "uiTokenAmount", "decimals"],
1983
+ ["meta", "postTokenBalances", KEYPATH_WILDCARD, "accountIndex"],
1984
+ ["meta", "postTokenBalances", KEYPATH_WILDCARD, "uiTokenAmount", "decimals"],
1985
+ ["meta", "rewards", KEYPATH_WILDCARD, "commission"],
1986
+ ["meta", "innerInstructions", KEYPATH_WILDCARD, "index"],
1987
+ ["meta", "innerInstructions", KEYPATH_WILDCARD, "instructions", KEYPATH_WILDCARD, "programIdIndex"],
1988
+ [
1989
+ "meta",
1990
+ "innerInstructions",
1991
+ KEYPATH_WILDCARD,
1992
+ "instructions",
1993
+ KEYPATH_WILDCARD,
1994
+ "accounts",
1995
+ KEYPATH_WILDCARD
1996
+ ],
1997
+ [
1998
+ "transaction",
1999
+ "message",
2000
+ "addressTableLookups",
2001
+ KEYPATH_WILDCARD,
2002
+ "writableIndexes",
2003
+ KEYPATH_WILDCARD
2004
+ ],
2005
+ [
2006
+ "transaction",
2007
+ "message",
2008
+ "addressTableLookups",
2009
+ KEYPATH_WILDCARD,
2010
+ "readonlyIndexes",
2011
+ KEYPATH_WILDCARD
2012
+ ],
2013
+ ["transaction", "message", "instructions", KEYPATH_WILDCARD, "programIdIndex"],
2014
+ ["transaction", "message", "instructions", KEYPATH_WILDCARD, "accounts", KEYPATH_WILDCARD],
2015
+ ["transaction", "message", "header", "numReadonlySignedAccounts"],
2016
+ ["transaction", "message", "header", "numReadonlyUnsignedAccounts"],
2017
+ ["transaction", "message", "header", "numRequiredSignatures"]
2018
+ ],
2019
+ getVersion: [["feature-set"]],
2020
+ getVoteAccounts: [
2021
+ ["current", KEYPATH_WILDCARD, "commission"],
2022
+ ["delinquent", KEYPATH_WILDCARD, "commission"]
2023
+ ],
2024
+ simulateTransaction: jsonParsedAccountsConfigs.map((c) => ["value", "accounts", KEYPATH_WILDCARD, ...c])
2025
+ };
2026
+ }
2027
+ return memoizedResponseKeypaths;
2028
+ }
1645
2029
  function getNextAllowedKeypaths(keyPaths, property) {
1646
2030
  return keyPaths.filter((keyPath) => keyPath[0] === KEYPATH_WILDCARD && typeof property === "number" || keyPath[0] === property).map((keyPath) => keyPath.slice(1));
1647
2031
  }
@@ -1668,7 +2052,11 @@ this.globalThis.solanaWeb3 = (function (exports) {
1668
2052
  }
1669
2053
  }
1670
2054
  function patchResponseForSolanaLabsRpc(rawResponse, methodName) {
1671
- const allowedKeypaths = methodName ? ALLOWED_NUMERIC_KEYPATHS[methodName] : void 0;
2055
+ const allowedKeypaths = methodName ? getAllowedNumericKeypathsForResponse()[methodName] : void 0;
2056
+ return visitNode2(rawResponse, allowedKeypaths ?? []);
2057
+ }
2058
+ function patchResponseForSolanaLabsRpcSubscriptions(rawResponse, methodName) {
2059
+ const allowedKeypaths = methodName ? getAllowedNumericKeypathsForNotification()[methodName] : void 0;
1672
2060
  return visitNode2(rawResponse, allowedKeypaths ?? []);
1673
2061
  }
1674
2062
  function createSolanaRpcApi(config) {
@@ -1697,6 +2085,33 @@ this.globalThis.solanaWeb3 = (function (exports) {
1697
2085
  }
1698
2086
  });
1699
2087
  }
2088
+ function createSolanaRpcSubscriptionsApi(config) {
2089
+ return new Proxy({}, {
2090
+ defineProperty() {
2091
+ return false;
2092
+ },
2093
+ deleteProperty() {
2094
+ return false;
2095
+ },
2096
+ get(...args) {
2097
+ const [_, p] = args;
2098
+ const notificationName = p.toString();
2099
+ return function(...rawParams) {
2100
+ const handleIntegerOverflow = config?.onIntegerOverflow;
2101
+ const params = patchParamsForSolanaLabsRpc(
2102
+ rawParams,
2103
+ handleIntegerOverflow ? (keyPath, value) => handleIntegerOverflow(notificationName, keyPath, value) : void 0
2104
+ );
2105
+ return {
2106
+ params,
2107
+ responseProcessor: (rawResponse) => patchResponseForSolanaLabsRpcSubscriptions(rawResponse, notificationName),
2108
+ subscribeMethodName: notificationName.replace(/Notifications$/, "Subscribe"),
2109
+ unsubscribeMethodName: notificationName.replace(/Notifications$/, "Unsubscribe")
2110
+ };
2111
+ };
2112
+ }
2113
+ });
2114
+ }
1700
2115
 
1701
2116
  // ../rpc-transport/dist/index.browser.js
1702
2117
  init_env_shim();
@@ -1763,6 +2178,100 @@ this.globalThis.solanaWeb3 = (function (exports) {
1763
2178
  function createJsonRpc(rpcConfig) {
1764
2179
  return makeProxy(rpcConfig);
1765
2180
  }
2181
+ function registerIterableCleanup(iterable, cleanupFn) {
2182
+ (async () => {
2183
+ try {
2184
+ for await (const _ of iterable)
2185
+ ;
2186
+ } catch {
2187
+ } finally {
2188
+ cleanupFn();
2189
+ }
2190
+ })();
2191
+ }
2192
+ function createPendingRpcSubscription(rpcConfig, { params, subscribeMethodName, unsubscribeMethodName, responseProcessor }) {
2193
+ return {
2194
+ async subscribe({ abortSignal }) {
2195
+ abortSignal.throwIfAborted();
2196
+ let subscriptionId;
2197
+ function handleCleanup() {
2198
+ if (subscriptionId !== void 0) {
2199
+ const payload = createJsonRpcMessage(unsubscribeMethodName, [subscriptionId]);
2200
+ connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(payload).finally(() => {
2201
+ connectionAbortController.abort();
2202
+ });
2203
+ } else {
2204
+ connectionAbortController.abort();
2205
+ }
2206
+ }
2207
+ abortSignal.addEventListener("abort", handleCleanup);
2208
+ const connectionAbortController = new AbortController();
2209
+ const subscribeMessage = createJsonRpcMessage(subscribeMethodName, params);
2210
+ const connection = await rpcConfig.transport({
2211
+ payload: subscribeMessage,
2212
+ signal: connectionAbortController.signal
2213
+ });
2214
+ function handleConnectionCleanup() {
2215
+ abortSignal.removeEventListener("abort", handleCleanup);
2216
+ }
2217
+ registerIterableCleanup(connection, handleConnectionCleanup);
2218
+ for await (const message of connection) {
2219
+ if ("id" in message && message.id === subscribeMessage.id) {
2220
+ if ("error" in message) {
2221
+ throw new SolanaJsonRpcError(message.error);
2222
+ } else {
2223
+ subscriptionId = message.result;
2224
+ break;
2225
+ }
2226
+ }
2227
+ }
2228
+ if (subscriptionId == null) {
2229
+ throw new Error("Failed to obtain a subscription id from the server");
2230
+ }
2231
+ return {
2232
+ async *[Symbol.asyncIterator]() {
2233
+ for await (const message of connection) {
2234
+ if (!("params" in message) || message.params.subscription !== subscriptionId) {
2235
+ continue;
2236
+ }
2237
+ const notification = message.params.result;
2238
+ yield responseProcessor ? responseProcessor(notification) : notification;
2239
+ }
2240
+ }
2241
+ };
2242
+ }
2243
+ };
2244
+ }
2245
+ function makeProxy2(rpcConfig) {
2246
+ return new Proxy(rpcConfig.api, {
2247
+ defineProperty() {
2248
+ return false;
2249
+ },
2250
+ deleteProperty() {
2251
+ return false;
2252
+ },
2253
+ get(target, p, receiver) {
2254
+ return function(...rawParams) {
2255
+ const methodName = p.toString();
2256
+ const createRpcSubscription = Reflect.get(target, methodName, receiver);
2257
+ if (p.toString().endsWith("Notifications") === false && !createRpcSubscription) {
2258
+ throw new Error(
2259
+ "Either the notification name must end in 'Notifications' or the API must supply a subscription creator function to map between the notification name and the subscribe/unsubscribe method names."
2260
+ );
2261
+ }
2262
+ const newRequest = createRpcSubscription ? createRpcSubscription(...rawParams) : {
2263
+ params: rawParams,
2264
+ subscribeMethodName: methodName.replace(/Notifications$/, "Subscribe"),
2265
+ unsubscribeMethodName: methodName.replace(/Notifications$/, "Unsubscribe")
2266
+ };
2267
+ return createPendingRpcSubscription(rpcConfig, newRequest);
2268
+ };
2269
+ }
2270
+ });
2271
+ }
2272
+ function createJsonSubscriptionRpc(rpcConfig) {
2273
+ return makeProxy2(rpcConfig);
2274
+ }
1766
2275
  var e = globalThis.fetch;
1767
2276
  var SolanaHttpError = class extends Error {
1768
2277
  constructor(details) {
@@ -1861,6 +2370,175 @@ this.globalThis.solanaWeb3 = (function (exports) {
1861
2370
  return await response.json();
1862
2371
  };
1863
2372
  }
2373
+ var e2 = globalThis.WebSocket;
2374
+ var EXPLICIT_ABORT_TOKEN = Symbol(
2375
+ "This symbol is thrown from a socket's iterator when the connection is explicity aborted by the user"
2376
+ );
2377
+ async function createWebSocketConnection({
2378
+ sendBufferHighWatermark,
2379
+ signal,
2380
+ url
2381
+ }) {
2382
+ return new Promise((resolve, reject) => {
2383
+ signal.addEventListener("abort", handleAbort, { once: true });
2384
+ const iteratorState = /* @__PURE__ */ new Map();
2385
+ function errorAndClearAllIteratorStates(reason) {
2386
+ const errorCallbacks = [...iteratorState.values()].filter((state) => state.__hasPolled).map(({ onError }) => onError);
2387
+ iteratorState.clear();
2388
+ errorCallbacks.forEach((cb) => {
2389
+ try {
2390
+ cb(reason);
2391
+ } catch {
2392
+ }
2393
+ });
2394
+ }
2395
+ function handleAbort() {
2396
+ errorAndClearAllIteratorStates(EXPLICIT_ABORT_TOKEN);
2397
+ if (webSocket.readyState !== e2.CLOSED && webSocket.readyState !== e2.CLOSING) {
2398
+ webSocket.close(1e3);
2399
+ }
2400
+ }
2401
+ function handleClose(ev) {
2402
+ bufferDrainWatcher?.onCancel();
2403
+ signal.removeEventListener("abort", handleAbort);
2404
+ webSocket.removeEventListener("close", handleClose);
2405
+ webSocket.removeEventListener("error", handleError);
2406
+ webSocket.removeEventListener("open", handleOpen);
2407
+ webSocket.removeEventListener("message", handleMessage);
2408
+ errorAndClearAllIteratorStates(ev);
2409
+ }
2410
+ function handleError(ev) {
2411
+ if (!hasConnected) {
2412
+ reject(
2413
+ // TODO: Coded error
2414
+ new Error("WebSocket failed to connect", { cause: ev })
2415
+ );
2416
+ }
2417
+ }
2418
+ let hasConnected = false;
2419
+ let bufferDrainWatcher;
2420
+ function handleOpen() {
2421
+ hasConnected = true;
2422
+ resolve({
2423
+ async send(payload) {
2424
+ const message = JSON.stringify(payload);
2425
+ if (!bufferDrainWatcher && webSocket.readyState === e2.OPEN && webSocket.bufferedAmount > sendBufferHighWatermark) {
2426
+ let onCancel;
2427
+ const promise = new Promise((resolve2, reject2) => {
2428
+ const intervalId = setInterval(() => {
2429
+ if (webSocket.readyState !== e2.OPEN || !(webSocket.bufferedAmount > sendBufferHighWatermark)) {
2430
+ clearInterval(intervalId);
2431
+ bufferDrainWatcher = void 0;
2432
+ resolve2();
2433
+ }
2434
+ }, 16);
2435
+ onCancel = () => {
2436
+ bufferDrainWatcher = void 0;
2437
+ clearInterval(intervalId);
2438
+ reject2(
2439
+ // TODO: Coded error
2440
+ new Error("WebSocket was closed before payload could be sent")
2441
+ );
2442
+ };
2443
+ });
2444
+ bufferDrainWatcher = {
2445
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2446
+ // @ts-ignore
2447
+ onCancel,
2448
+ promise
2449
+ };
2450
+ }
2451
+ if (bufferDrainWatcher) {
2452
+ await bufferDrainWatcher.promise;
2453
+ }
2454
+ webSocket.send(message);
2455
+ },
2456
+ async *[Symbol.asyncIterator]() {
2457
+ const iteratorKey = Symbol();
2458
+ iteratorState.set(iteratorKey, { __hasPolled: false, queuedMessages: [] });
2459
+ try {
2460
+ while (true) {
2461
+ const state = iteratorState.get(iteratorKey);
2462
+ if (!state) {
2463
+ throw new Error("Invariant: WebSocket message iterator is missing state storage");
2464
+ }
2465
+ if (state.__hasPolled) {
2466
+ throw new Error(
2467
+ "Invariant: WebSocket message iterator state is corrupt; iterated without first resolving existing message promise"
2468
+ );
2469
+ }
2470
+ const queuedMessages = state.queuedMessages;
2471
+ if (queuedMessages.length) {
2472
+ state.queuedMessages = [];
2473
+ yield* queuedMessages;
2474
+ } else {
2475
+ try {
2476
+ yield await new Promise((resolve2, reject2) => {
2477
+ iteratorState.set(iteratorKey, {
2478
+ __hasPolled: true,
2479
+ onError: reject2,
2480
+ onMessage: resolve2
2481
+ });
2482
+ });
2483
+ } catch (e3) {
2484
+ if (e3 === EXPLICIT_ABORT_TOKEN) {
2485
+ return;
2486
+ } else {
2487
+ throw new Error("WebSocket connection closed", { cause: e3 });
2488
+ }
2489
+ }
2490
+ }
2491
+ }
2492
+ } finally {
2493
+ iteratorState.delete(iteratorKey);
2494
+ }
2495
+ }
2496
+ });
2497
+ }
2498
+ function handleMessage({ data }) {
2499
+ const message = JSON.parse(data);
2500
+ iteratorState.forEach((state, iteratorKey) => {
2501
+ if (state.__hasPolled) {
2502
+ const { onMessage } = state;
2503
+ iteratorState.set(iteratorKey, { __hasPolled: false, queuedMessages: [] });
2504
+ onMessage(message);
2505
+ } else {
2506
+ state.queuedMessages.push(message);
2507
+ }
2508
+ });
2509
+ }
2510
+ const webSocket = new e2(url);
2511
+ webSocket.addEventListener("close", handleClose);
2512
+ webSocket.addEventListener("error", handleError);
2513
+ webSocket.addEventListener("open", handleOpen);
2514
+ webSocket.addEventListener("message", handleMessage);
2515
+ });
2516
+ }
2517
+ function createWebSocketTransport({ sendBufferHighWatermark, url }) {
2518
+ if (/^wss?:/i.test(url) === false) {
2519
+ const protocolMatch = url.match(/^([^:]+):/);
2520
+ throw new DOMException(
2521
+ protocolMatch ? `Failed to construct 'WebSocket': The URL's scheme must be either 'ws' or 'wss'. '${protocolMatch[1]}:' is not allowed.` : `Failed to construct 'WebSocket': The URL '${url}' is invalid.`
2522
+ );
2523
+ }
2524
+ return async function sendWebSocketMessage({ payload, signal }) {
2525
+ signal?.throwIfAborted();
2526
+ const connection = await createWebSocketConnection({
2527
+ sendBufferHighWatermark,
2528
+ signal,
2529
+ url
2530
+ });
2531
+ signal?.throwIfAborted();
2532
+ await connection.send(payload);
2533
+ return {
2534
+ [Symbol.asyncIterator]: connection[Symbol.asyncIterator].bind(connection),
2535
+ send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: connection.send.bind(connection)
2536
+ };
2537
+ };
2538
+ }
2539
+
2540
+ // src/rpc.ts
2541
+ var import_fast_stable_stringify = __toESM(require_fast_stable_stringify(), 1);
1864
2542
 
1865
2543
  // src/rpc-default-config.ts
1866
2544
  init_env_shim();
@@ -1902,6 +2580,197 @@ this.globalThis.solanaWeb3 = (function (exports) {
1902
2580
  }
1903
2581
  };
1904
2582
 
2583
+ // src/rpc-subscription-coalescer.ts
2584
+ init_env_shim();
2585
+
2586
+ // src/cached-abortable-iterable.ts
2587
+ init_env_shim();
2588
+ function registerIterableCleanup2(iterable, cleanupFn) {
2589
+ (async () => {
2590
+ try {
2591
+ for await (const _ of iterable)
2592
+ ;
2593
+ } catch {
2594
+ } finally {
2595
+ cleanupFn();
2596
+ }
2597
+ })();
2598
+ }
2599
+ function getCachedAbortableIterableFactory({
2600
+ getAbortSignalFromInputArgs,
2601
+ getCacheEntryMissingError,
2602
+ getCacheKeyFromInputArgs,
2603
+ onCacheHit,
2604
+ onCreateIterable
2605
+ }) {
2606
+ const cache = /* @__PURE__ */ new Map();
2607
+ function getCacheEntryOrThrow(cacheKey) {
2608
+ const currentCacheEntry = cache.get(cacheKey);
2609
+ if (!currentCacheEntry) {
2610
+ throw getCacheEntryMissingError(cacheKey);
2611
+ }
2612
+ return currentCacheEntry;
2613
+ }
2614
+ return async (...args) => {
2615
+ const cacheKey = getCacheKeyFromInputArgs(...args);
2616
+ const signal = getAbortSignalFromInputArgs(...args);
2617
+ if (cacheKey === void 0) {
2618
+ return await onCreateIterable(signal, ...args);
2619
+ }
2620
+ const cleanup = () => {
2621
+ cache.delete(cacheKey);
2622
+ signal.removeEventListener("abort", handleAbort);
2623
+ };
2624
+ const handleAbort = () => {
2625
+ const cacheEntry = getCacheEntryOrThrow(cacheKey);
2626
+ if (cacheEntry.purgeScheduled !== true) {
2627
+ cacheEntry.purgeScheduled = true;
2628
+ globalThis.queueMicrotask(() => {
2629
+ cacheEntry.purgeScheduled = false;
2630
+ if (cacheEntry.referenceCount === 0) {
2631
+ cacheEntry.abortController.abort();
2632
+ cleanup();
2633
+ }
2634
+ });
2635
+ }
2636
+ cacheEntry.referenceCount--;
2637
+ };
2638
+ signal.addEventListener("abort", handleAbort);
2639
+ try {
2640
+ const cacheEntry = cache.get(cacheKey);
2641
+ if (!cacheEntry) {
2642
+ const singletonAbortController = new AbortController();
2643
+ const newIterablePromise = onCreateIterable(singletonAbortController.signal, ...args);
2644
+ const newCacheEntry = {
2645
+ abortController: singletonAbortController,
2646
+ iterable: newIterablePromise,
2647
+ purgeScheduled: false,
2648
+ referenceCount: 1
2649
+ };
2650
+ cache.set(cacheKey, newCacheEntry);
2651
+ const newIterable = await newIterablePromise;
2652
+ registerIterableCleanup2(newIterable, cleanup);
2653
+ newCacheEntry.iterable = newIterable;
2654
+ return newIterable;
2655
+ } else {
2656
+ cacheEntry.referenceCount++;
2657
+ const iterableOrIterablePromise = cacheEntry.iterable;
2658
+ const cachedIterable = "then" in iterableOrIterablePromise ? await iterableOrIterablePromise : iterableOrIterablePromise;
2659
+ await onCacheHit(cachedIterable, ...args);
2660
+ return cachedIterable;
2661
+ }
2662
+ } catch (e3) {
2663
+ cleanup();
2664
+ throw e3;
2665
+ }
2666
+ };
2667
+ }
2668
+
2669
+ // src/rpc-subscription-coalescer.ts
2670
+ var EXPLICIT_ABORT_TOKEN2 = Symbol(
2671
+ "This symbol is thrown from a subscription's iterator when the subscription is explicitly aborted by the user"
2672
+ );
2673
+ function registerIterableCleanup3(iterable, cleanupFn) {
2674
+ (async () => {
2675
+ try {
2676
+ for await (const _ of iterable)
2677
+ ;
2678
+ } catch {
2679
+ } finally {
2680
+ cleanupFn();
2681
+ }
2682
+ })();
2683
+ }
2684
+ function getRpcSubscriptionsWithSubscriptionCoalescing({
2685
+ getDeduplicationKey,
2686
+ rpcSubscriptions
2687
+ }) {
2688
+ const cache = /* @__PURE__ */ new Map();
2689
+ return new Proxy(rpcSubscriptions, {
2690
+ defineProperty() {
2691
+ return false;
2692
+ },
2693
+ deleteProperty() {
2694
+ return false;
2695
+ },
2696
+ get(target, p, receiver) {
2697
+ const subscriptionMethod = Reflect.get(target, p, receiver);
2698
+ if (typeof subscriptionMethod !== "function") {
2699
+ return subscriptionMethod;
2700
+ }
2701
+ return function(...rawParams) {
2702
+ const deduplicationKey = getDeduplicationKey(p, rawParams);
2703
+ if (deduplicationKey === void 0) {
2704
+ return subscriptionMethod(...rawParams);
2705
+ }
2706
+ if (cache.has(deduplicationKey)) {
2707
+ return cache.get(deduplicationKey);
2708
+ }
2709
+ const iterableFactory = getCachedAbortableIterableFactory({
2710
+ getAbortSignalFromInputArgs: ({ abortSignal }) => abortSignal,
2711
+ getCacheEntryMissingError(deduplicationKey2) {
2712
+ return new Error(
2713
+ `Found no cache entry for subscription with deduplication key \`${deduplicationKey2?.toString()}\``
2714
+ );
2715
+ },
2716
+ getCacheKeyFromInputArgs: () => deduplicationKey,
2717
+ async onCacheHit(_iterable, _config) {
2718
+ },
2719
+ async onCreateIterable(abortSignal, config) {
2720
+ const pendingSubscription2 = subscriptionMethod(
2721
+ ...rawParams
2722
+ );
2723
+ const iterable = await pendingSubscription2.subscribe({
2724
+ ...config,
2725
+ abortSignal
2726
+ });
2727
+ registerIterableCleanup3(iterable, () => {
2728
+ cache.delete(deduplicationKey);
2729
+ });
2730
+ return iterable;
2731
+ }
2732
+ });
2733
+ const pendingSubscription = {
2734
+ async subscribe(...args) {
2735
+ const iterable = await iterableFactory(...args);
2736
+ const { abortSignal } = args[0];
2737
+ let abortPromise;
2738
+ return {
2739
+ ...iterable,
2740
+ async *[Symbol.asyncIterator]() {
2741
+ abortPromise || (abortPromise = abortSignal.aborted ? Promise.reject(EXPLICIT_ABORT_TOKEN2) : new Promise((_, reject) => {
2742
+ abortSignal.addEventListener("abort", () => {
2743
+ reject(EXPLICIT_ABORT_TOKEN2);
2744
+ });
2745
+ }));
2746
+ try {
2747
+ const iterator = iterable[Symbol.asyncIterator]();
2748
+ while (true) {
2749
+ const iteratorResult = await Promise.race([iterator.next(), abortPromise]);
2750
+ if (iteratorResult.done) {
2751
+ return;
2752
+ } else {
2753
+ yield iteratorResult.value;
2754
+ }
2755
+ }
2756
+ } catch (e3) {
2757
+ if (e3 === EXPLICIT_ABORT_TOKEN2) {
2758
+ return;
2759
+ }
2760
+ cache.delete(deduplicationKey);
2761
+ throw e3;
2762
+ }
2763
+ }
2764
+ };
2765
+ }
2766
+ };
2767
+ cache.set(deduplicationKey, pendingSubscription);
2768
+ return pendingSubscription;
2769
+ };
2770
+ }
2771
+ });
2772
+ }
2773
+
1905
2774
  // src/rpc.ts
1906
2775
  function createSolanaRpc(config) {
1907
2776
  return createJsonRpc({
@@ -1909,6 +2778,18 @@ this.globalThis.solanaWeb3 = (function (exports) {
1909
2778
  api: createSolanaRpcApi(DEFAULT_RPC_CONFIG)
1910
2779
  });
1911
2780
  }
2781
+ function createSolanaRpcSubscriptions(config) {
2782
+ return pipe(
2783
+ createJsonSubscriptionRpc({
2784
+ ...config,
2785
+ api: createSolanaRpcSubscriptionsApi(DEFAULT_RPC_CONFIG)
2786
+ }),
2787
+ (rpcSubscriptions) => getRpcSubscriptionsWithSubscriptionCoalescing({
2788
+ getDeduplicationKey: (...args) => (0, import_fast_stable_stringify.default)(args),
2789
+ rpcSubscriptions
2790
+ })
2791
+ );
2792
+ }
1912
2793
 
1913
2794
  // src/rpc-transport.ts
1914
2795
  init_env_shim();
@@ -1945,14 +2826,14 @@ this.globalThis.solanaWeb3 = (function (exports) {
1945
2826
  if (signal) {
1946
2827
  const responsePromise = coalescedRequest.responsePromise;
1947
2828
  return await new Promise((resolve, reject) => {
1948
- const handleAbort = (e2) => {
2829
+ const handleAbort = (e3) => {
1949
2830
  signal.removeEventListener("abort", handleAbort);
1950
2831
  coalescedRequest.numConsumers -= 1;
1951
2832
  if (coalescedRequest.numConsumers === 0) {
1952
2833
  const abortController = coalescedRequest.abortController;
1953
2834
  abortController.abort();
1954
2835
  }
1955
- const abortError = new DOMException(e2.target.reason, "AbortError");
2836
+ const abortError = new DOMException(e3.target.reason, "AbortError");
1956
2837
  reject(abortError);
1957
2838
  };
1958
2839
  signal.addEventListener("abort", handleAbort);
@@ -1968,14 +2849,15 @@ this.globalThis.solanaWeb3 = (function (exports) {
1968
2849
 
1969
2850
  // src/rpc-request-deduplication.ts
1970
2851
  init_env_shim();
1971
- var import_fast_stable_stringify = __toESM(require_fast_stable_stringify(), 1);
1972
- function getSolanaRpcPayloadDeduplicationKey(payload) {
2852
+ var import_fast_stable_stringify2 = __toESM(require_fast_stable_stringify(), 1);
2853
+ function isJsonRpcPayload(payload) {
1973
2854
  if (payload == null || typeof payload !== "object" || Array.isArray(payload)) {
1974
- return;
1975
- }
1976
- if ("jsonrpc" in payload && payload.jsonrpc === "2.0" && "method" in payload && "params" in payload) {
1977
- return (0, import_fast_stable_stringify.default)([payload.method, payload.params]);
2855
+ return false;
1978
2856
  }
2857
+ return "jsonrpc" in payload && payload.jsonrpc === "2.0" && "method" in payload && typeof payload.method === "string" && "params" in payload;
2858
+ }
2859
+ function getSolanaRpcPayloadDeduplicationKey(payload) {
2860
+ return isJsonRpcPayload(payload) ? (0, import_fast_stable_stringify2.default)([payload.method, payload.params]) : void 0;
1979
2861
  }
1980
2862
 
1981
2863
  // src/rpc-transport.ts
@@ -1987,7 +2869,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
1987
2869
  return out;
1988
2870
  }
1989
2871
  function createDefaultRpcTransport(config) {
1990
- return getRpcTransportWithRequestCoalescing(
2872
+ return pipe(
1991
2873
  createHttpTransport({
1992
2874
  ...config,
1993
2875
  headers: {
@@ -1998,25 +2880,138 @@ this.globalThis.solanaWeb3 = (function (exports) {
1998
2880
  }
1999
2881
  }
2000
2882
  }),
2001
- getSolanaRpcPayloadDeduplicationKey
2883
+ (transport) => getRpcTransportWithRequestCoalescing(transport, getSolanaRpcPayloadDeduplicationKey)
2884
+ );
2885
+ }
2886
+
2887
+ // src/rpc-websocket-transport.ts
2888
+ init_env_shim();
2889
+
2890
+ // src/rpc-websocket-autopinger.ts
2891
+ init_env_shim();
2892
+ var PING_PAYLOAD = {
2893
+ jsonrpc: "2.0",
2894
+ method: "ping"
2895
+ };
2896
+ function getWebSocketTransportWithAutoping({ intervalMs, transport }) {
2897
+ const pingableConnections = /* @__PURE__ */ new Map();
2898
+ return async (...args) => {
2899
+ const connection = await transport(...args);
2900
+ let intervalId;
2901
+ function sendPing() {
2902
+ connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(PING_PAYLOAD);
2903
+ }
2904
+ function restartPingTimer() {
2905
+ clearInterval(intervalId);
2906
+ intervalId = setInterval(sendPing, intervalMs);
2907
+ }
2908
+ if (pingableConnections.has(connection) === false) {
2909
+ pingableConnections.set(connection, {
2910
+ [Symbol.asyncIterator]: connection[Symbol.asyncIterator].bind(connection),
2911
+ send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: (...args2) => {
2912
+ restartPingTimer();
2913
+ return connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(...args2);
2914
+ }
2915
+ });
2916
+ (async () => {
2917
+ try {
2918
+ for await (const _ of connection) {
2919
+ restartPingTimer();
2920
+ }
2921
+ } catch {
2922
+ } finally {
2923
+ pingableConnections.delete(connection);
2924
+ clearInterval(intervalId);
2925
+ if (handleOffline) {
2926
+ globalThis.window.removeEventListener("offline", handleOffline);
2927
+ }
2928
+ if (handleOnline) {
2929
+ globalThis.window.removeEventListener("online", handleOnline);
2930
+ }
2931
+ }
2932
+ })();
2933
+ if (globalThis.navigator.onLine) {
2934
+ restartPingTimer();
2935
+ }
2936
+ let handleOffline;
2937
+ let handleOnline;
2938
+ {
2939
+ handleOffline = () => {
2940
+ clearInterval(intervalId);
2941
+ };
2942
+ handleOnline = () => {
2943
+ sendPing();
2944
+ restartPingTimer();
2945
+ };
2946
+ globalThis.window.addEventListener("offline", handleOffline);
2947
+ globalThis.window.addEventListener("online", handleOnline);
2948
+ }
2949
+ }
2950
+ return pingableConnections.get(connection);
2951
+ };
2952
+ }
2953
+
2954
+ // src/rpc-websocket-connection-sharding.ts
2955
+ init_env_shim();
2956
+ var NULL_SHARD_CACHE_KEY = Symbol(
2957
+ "Cache key to use when there is no connection sharding strategy"
2958
+ );
2959
+ function getWebSocketTransportWithConnectionSharding({ getShard, transport }) {
2960
+ return getCachedAbortableIterableFactory({
2961
+ getAbortSignalFromInputArgs: ({ signal }) => signal,
2962
+ getCacheEntryMissingError(shardKey) {
2963
+ return new Error(`Found no cache entry for connection with shard key \`${shardKey?.toString()}\``);
2964
+ },
2965
+ getCacheKeyFromInputArgs: ({ payload }) => getShard ? getShard(payload) : NULL_SHARD_CACHE_KEY,
2966
+ onCacheHit: (connection, { payload }) => connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(payload),
2967
+ onCreateIterable: (abortSignal, config) => transport({
2968
+ ...config,
2969
+ signal: abortSignal
2970
+ })
2971
+ });
2972
+ }
2973
+
2974
+ // src/rpc-websocket-transport.ts
2975
+ function createDefaultRpcSubscriptionsTransport(config) {
2976
+ const { getShard, intervalMs, ...rest } = config;
2977
+ return pipe(
2978
+ createWebSocketTransport({
2979
+ ...rest,
2980
+ sendBufferHighWatermark: config.sendBufferHighWatermark ?? // Let 128KB of data into the WebSocket buffer before buffering it in the app.
2981
+ 131072
2982
+ }),
2983
+ (transport) => getWebSocketTransportWithAutoping({
2984
+ intervalMs: intervalMs ?? 5e3,
2985
+ transport
2986
+ }),
2987
+ (transport) => getWebSocketTransportWithConnectionSharding({
2988
+ getShard,
2989
+ transport
2990
+ })
2002
2991
  );
2003
2992
  }
2004
2993
 
2005
2994
  exports.AccountRole = AccountRole;
2995
+ exports.address = address;
2006
2996
  exports.appendTransactionInstruction = appendTransactionInstruction;
2007
2997
  exports.assertIsBase58EncodedAddress = assertIsBase58EncodedAddress;
2008
2998
  exports.assertIsBlockhash = assertIsBlockhash;
2009
2999
  exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
3000
+ exports.createAddressWithSeed = createAddressWithSeed;
3001
+ exports.createDefaultRpcSubscriptionsTransport = createDefaultRpcSubscriptionsTransport;
2010
3002
  exports.createDefaultRpcTransport = createDefaultRpcTransport;
2011
3003
  exports.createSolanaRpc = createSolanaRpc;
3004
+ exports.createSolanaRpcSubscriptions = createSolanaRpcSubscriptions;
2012
3005
  exports.createTransaction = createTransaction;
2013
3006
  exports.downgradeRoleToNonSigner = downgradeRoleToNonSigner;
2014
3007
  exports.downgradeRoleToReadonly = downgradeRoleToReadonly;
2015
3008
  exports.generateKeyPair = generateKeyPair;
3009
+ exports.getAddressFromPublicKey = getAddressFromPublicKey;
2016
3010
  exports.getBase58EncodedAddressCodec = getBase58EncodedAddressCodec;
2017
3011
  exports.getBase58EncodedAddressComparator = getBase58EncodedAddressComparator;
2018
- exports.getBase58EncodedAddressFromPublicKey = getBase58EncodedAddressFromPublicKey;
2019
3012
  exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
3013
+ exports.getProgramDerivedAddress = getProgramDerivedAddress;
3014
+ exports.isBase58EncodedAddress = isBase58EncodedAddress;
2020
3015
  exports.isSignerRole = isSignerRole;
2021
3016
  exports.isWritableRole = isWritableRole;
2022
3017
  exports.mergeRoles = mergeRoles;