@solana/web3.js 2.0.0-experimental.7b06723 → 2.0.0-experimental.835e62f

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.
@@ -124,16 +124,16 @@ this.globalThis.solanaWeb3 = (function (exports) {
124
124
 
125
125
  // ../instructions/dist/index.browser.js
126
126
  init_env_shim();
127
- var AccountRole = /* @__PURE__ */ ((AccountRole2) => {
128
- AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */
127
+ var AccountRole = /* @__PURE__ */ ((AccountRole22) => {
128
+ AccountRole22[AccountRole22["WRITABLE_SIGNER"] = /* 3 */
129
129
  3] = "WRITABLE_SIGNER";
130
- AccountRole2[AccountRole2["READONLY_SIGNER"] = /* 2 */
130
+ AccountRole22[AccountRole22["READONLY_SIGNER"] = /* 2 */
131
131
  2] = "READONLY_SIGNER";
132
- AccountRole2[AccountRole2["WRITABLE"] = /* 1 */
132
+ AccountRole22[AccountRole22["WRITABLE"] = /* 1 */
133
133
  1] = "WRITABLE";
134
- AccountRole2[AccountRole2["READONLY"] = /* 0 */
134
+ AccountRole22[AccountRole22["READONLY"] = /* 0 */
135
135
  0] = "READONLY";
136
- return AccountRole2;
136
+ return AccountRole22;
137
137
  })(AccountRole || {});
138
138
  var IS_SIGNER_BITMASK = 2;
139
139
  var IS_WRITABLE_BITMASK = 1;
@@ -162,6 +162,92 @@ this.globalThis.solanaWeb3 = (function (exports) {
162
162
  // ../keys/dist/index.browser.js
163
163
  init_env_shim();
164
164
 
165
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/index.mjs
166
+ init_env_shim();
167
+
168
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/index.mjs
169
+ init_env_shim();
170
+
171
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/bytes.mjs
172
+ init_env_shim();
173
+ var mergeBytes = (bytesArr) => {
174
+ const totalLength = bytesArr.reduce((total, arr) => total + arr.length, 0);
175
+ const result = new Uint8Array(totalLength);
176
+ let offset = 0;
177
+ bytesArr.forEach((arr) => {
178
+ result.set(arr, offset);
179
+ offset += arr.length;
180
+ });
181
+ return result;
182
+ };
183
+ var padBytes = (bytes2, length) => {
184
+ if (bytes2.length >= length)
185
+ return bytes2;
186
+ const paddedBytes = new Uint8Array(length).fill(0);
187
+ paddedBytes.set(bytes2);
188
+ return paddedBytes;
189
+ };
190
+ var fixBytes = (bytes2, length) => padBytes(bytes2.slice(0, length), length);
191
+
192
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/errors.mjs
193
+ init_env_shim();
194
+ var DeserializingEmptyBufferError = class extends Error {
195
+ constructor(serializer) {
196
+ super(`Serializer [${serializer}] cannot deserialize empty buffers.`);
197
+ __publicField(this, "name", "DeserializingEmptyBufferError");
198
+ }
199
+ };
200
+ var NotEnoughBytesError = class extends Error {
201
+ constructor(serializer, expected, actual) {
202
+ super(`Serializer [${serializer}] expected ${expected} bytes, got ${actual}.`);
203
+ __publicField(this, "name", "NotEnoughBytesError");
204
+ }
205
+ };
206
+ var ExpectedFixedSizeSerializerError = class extends Error {
207
+ constructor(message) {
208
+ message ?? (message = "Expected a fixed-size serializer, got a variable-size one.");
209
+ super(message);
210
+ __publicField(this, "name", "ExpectedFixedSizeSerializerError");
211
+ }
212
+ };
213
+
214
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/fixSerializer.mjs
215
+ init_env_shim();
216
+ function fixSerializer(serializer, fixedBytes, description) {
217
+ return {
218
+ description: description ?? `fixed(${fixedBytes}, ${serializer.description})`,
219
+ fixedSize: fixedBytes,
220
+ maxSize: fixedBytes,
221
+ serialize: (value) => fixBytes(serializer.serialize(value), fixedBytes),
222
+ deserialize: (buffer, offset = 0) => {
223
+ buffer = buffer.slice(offset, offset + fixedBytes);
224
+ if (buffer.length < fixedBytes) {
225
+ throw new NotEnoughBytesError("fixSerializer", fixedBytes, buffer.length);
226
+ }
227
+ if (serializer.fixedSize !== null) {
228
+ buffer = fixBytes(buffer, serializer.fixedSize);
229
+ }
230
+ const [value] = serializer.deserialize(buffer, 0);
231
+ return [value, offset + fixedBytes];
232
+ }
233
+ };
234
+ }
235
+
236
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/mapSerializer.mjs
237
+ init_env_shim();
238
+ function mapSerializer(serializer, unmap, map) {
239
+ return {
240
+ description: serializer.description,
241
+ fixedSize: serializer.fixedSize,
242
+ maxSize: serializer.maxSize,
243
+ serialize: (value) => serializer.serialize(unmap(value)),
244
+ deserialize: (buffer, offset = 0) => {
245
+ const [value, length] = serializer.deserialize(buffer, offset);
246
+ return map ? [map(value, buffer, offset), length] : [value, length];
247
+ }
248
+ };
249
+ }
250
+
165
251
  // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/index.mjs
166
252
  init_env_shim();
167
253
 
@@ -216,13 +302,13 @@ this.globalThis.solanaWeb3 = (function (exports) {
216
302
  deserialize(buffer, offset = 0) {
217
303
  if (buffer.length === 0)
218
304
  return ["", 0];
219
- const bytes = buffer.slice(offset);
220
- let trailIndex = bytes.findIndex((n) => n !== 0);
221
- trailIndex = trailIndex === -1 ? bytes.length : trailIndex;
305
+ const bytes2 = buffer.slice(offset);
306
+ let trailIndex = bytes2.findIndex((n) => n !== 0);
307
+ trailIndex = trailIndex === -1 ? bytes2.length : trailIndex;
222
308
  const leadingZeroes = alphabet[0].repeat(trailIndex);
223
- if (trailIndex === bytes.length)
309
+ if (trailIndex === bytes2.length)
224
310
  return [leadingZeroes, buffer.length];
225
- let base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
311
+ let base10Number = bytes2.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
226
312
  const tailChars = [];
227
313
  while (base10Number > 0n) {
228
314
  tailChars.unshift(alphabet[Number(base10Number % baseBigInt)]);
@@ -237,7 +323,368 @@ this.globalThis.solanaWeb3 = (function (exports) {
237
323
  init_env_shim();
238
324
  var base58 = baseX("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
239
325
 
240
- // ../keys/dist/index.browser.js
326
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/nullCharacters.mjs
327
+ init_env_shim();
328
+ var removeNullCharacters = (value) => (
329
+ // eslint-disable-next-line no-control-regex
330
+ value.replace(/\u0000/g, "")
331
+ );
332
+
333
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/utf8.mjs
334
+ init_env_shim();
335
+ var utf8 = {
336
+ description: "utf8",
337
+ fixedSize: null,
338
+ maxSize: null,
339
+ serialize(value) {
340
+ return new TextEncoder().encode(value);
341
+ },
342
+ deserialize(buffer, offset = 0) {
343
+ const value = new TextDecoder().decode(buffer.slice(offset));
344
+ return [removeNullCharacters(value), buffer.length];
345
+ }
346
+ };
347
+
348
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/index.mjs
349
+ init_env_shim();
350
+
351
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/common.mjs
352
+ init_env_shim();
353
+ var Endian;
354
+ (function(Endian2) {
355
+ Endian2["Little"] = "le";
356
+ Endian2["Big"] = "be";
357
+ })(Endian || (Endian = {}));
358
+
359
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/errors.mjs
360
+ init_env_shim();
361
+ var NumberOutOfRangeError = class extends RangeError {
362
+ constructor(serializer, min, max, actual) {
363
+ super(`Serializer [${serializer}] expected number to be between ${min} and ${max}, got ${actual}.`);
364
+ __publicField(this, "name", "NumberOutOfRangeError");
365
+ }
366
+ };
367
+
368
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/utils.mjs
369
+ init_env_shim();
370
+ function numberFactory(input) {
371
+ let littleEndian;
372
+ let defaultDescription = input.name;
373
+ if (input.size > 1) {
374
+ littleEndian = !("endian" in input.options) || input.options.endian === Endian.Little;
375
+ defaultDescription += littleEndian ? "(le)" : "(be)";
376
+ }
377
+ return {
378
+ description: input.options.description ?? defaultDescription,
379
+ fixedSize: input.size,
380
+ maxSize: input.size,
381
+ serialize(value) {
382
+ if (input.range) {
383
+ assertRange(input.name, input.range[0], input.range[1], value);
384
+ }
385
+ const buffer = new ArrayBuffer(input.size);
386
+ input.set(new DataView(buffer), value, littleEndian);
387
+ return new Uint8Array(buffer);
388
+ },
389
+ deserialize(bytes2, offset = 0) {
390
+ const slice = bytes2.slice(offset, offset + input.size);
391
+ assertEnoughBytes("i8", slice, input.size);
392
+ const view = toDataView(slice);
393
+ return [input.get(view, littleEndian), offset + input.size];
394
+ }
395
+ };
396
+ }
397
+ var toArrayBuffer = (array2) => array2.buffer.slice(array2.byteOffset, array2.byteLength + array2.byteOffset);
398
+ var toDataView = (array2) => new DataView(toArrayBuffer(array2));
399
+ var assertRange = (serializer, min, max, value) => {
400
+ if (value < min || value > max) {
401
+ throw new NumberOutOfRangeError(serializer, min, max, value);
402
+ }
403
+ };
404
+ var assertEnoughBytes = (serializer, bytes2, expected) => {
405
+ if (bytes2.length === 0) {
406
+ throw new DeserializingEmptyBufferError(serializer);
407
+ }
408
+ if (bytes2.length < expected) {
409
+ throw new NotEnoughBytesError(serializer, expected, bytes2.length);
410
+ }
411
+ };
412
+
413
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u8.mjs
414
+ init_env_shim();
415
+ var u8 = (options = {}) => numberFactory({
416
+ name: "u8",
417
+ size: 1,
418
+ range: [0, Number("0xff")],
419
+ set: (view, value) => view.setUint8(0, Number(value)),
420
+ get: (view) => view.getUint8(0),
421
+ options
422
+ });
423
+
424
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u32.mjs
425
+ init_env_shim();
426
+ var u32 = (options = {}) => numberFactory({
427
+ name: "u32",
428
+ size: 4,
429
+ range: [0, Number("0xffffffff")],
430
+ set: (view, value, le) => view.setUint32(0, Number(value), le),
431
+ get: (view, le) => view.getUint32(0, le),
432
+ options
433
+ });
434
+
435
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/shortU16.mjs
436
+ init_env_shim();
437
+ var shortU16 = (options = {}) => ({
438
+ description: options.description ?? "shortU16",
439
+ fixedSize: null,
440
+ maxSize: 3,
441
+ serialize: (value) => {
442
+ assertRange("shortU16", 0, 65535, value);
443
+ const bytes2 = [0];
444
+ for (let ii = 0; ; ii += 1) {
445
+ const alignedValue = value >> ii * 7;
446
+ if (alignedValue === 0) {
447
+ break;
448
+ }
449
+ const nextSevenBits = 127 & alignedValue;
450
+ bytes2[ii] = nextSevenBits;
451
+ if (ii > 0) {
452
+ bytes2[ii - 1] |= 128;
453
+ }
454
+ }
455
+ return new Uint8Array(bytes2);
456
+ },
457
+ deserialize: (bytes2, offset = 0) => {
458
+ let value = 0;
459
+ let byteCount = 0;
460
+ while (++byteCount) {
461
+ const byteIndex = byteCount - 1;
462
+ const currentByte = bytes2[offset + byteIndex];
463
+ const nextSevenBits = 127 & currentByte;
464
+ value |= nextSevenBits << byteIndex * 7;
465
+ if ((currentByte & 128) === 0) {
466
+ break;
467
+ }
468
+ }
469
+ return [value, offset + byteCount];
470
+ }
471
+ });
472
+
473
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/array.mjs
474
+ init_env_shim();
475
+
476
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/errors.mjs
477
+ init_env_shim();
478
+ var InvalidNumberOfItemsError = class extends Error {
479
+ constructor(serializer, expected, actual) {
480
+ super(`Expected [${serializer}] to have ${expected} items, got ${actual}.`);
481
+ __publicField(this, "name", "InvalidNumberOfItemsError");
482
+ }
483
+ };
484
+ var InvalidArrayLikeRemainderSizeError = class extends Error {
485
+ constructor(remainderSize, itemSize) {
486
+ super(`The remainder of the buffer (${remainderSize} bytes) cannot be split into chunks of ${itemSize} bytes. Serializers of "remainder" size must have a remainder that is a multiple of its item size. In other words, ${remainderSize} modulo ${itemSize} should be equal to zero.`);
487
+ __publicField(this, "name", "InvalidArrayLikeRemainderSizeError");
488
+ }
489
+ };
490
+ var UnrecognizedArrayLikeSerializerSizeError = class extends Error {
491
+ constructor(size) {
492
+ super(`Unrecognized array-like serializer size: ${JSON.stringify(size)}`);
493
+ __publicField(this, "name", "UnrecognizedArrayLikeSerializerSizeError");
494
+ }
495
+ };
496
+
497
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/utils.mjs
498
+ init_env_shim();
499
+
500
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/sumSerializerSizes.mjs
501
+ init_env_shim();
502
+ function sumSerializerSizes(sizes) {
503
+ return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
504
+ }
505
+
506
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/utils.mjs
507
+ function getResolvedSize(size, childrenSizes, bytes2, offset) {
508
+ if (typeof size === "number") {
509
+ return [size, offset];
510
+ }
511
+ if (typeof size === "object") {
512
+ return size.deserialize(bytes2, offset);
513
+ }
514
+ if (size === "remainder") {
515
+ const childrenSize = sumSerializerSizes(childrenSizes);
516
+ if (childrenSize === null) {
517
+ throw new ExpectedFixedSizeSerializerError('Serializers of "remainder" size must have fixed-size items.');
518
+ }
519
+ const remainder = bytes2.slice(offset).length;
520
+ if (remainder % childrenSize !== 0) {
521
+ throw new InvalidArrayLikeRemainderSizeError(remainder, childrenSize);
522
+ }
523
+ return [remainder / childrenSize, offset];
524
+ }
525
+ throw new UnrecognizedArrayLikeSerializerSizeError(size);
526
+ }
527
+ function getSizeDescription(size) {
528
+ return typeof size === "object" ? size.description : `${size}`;
529
+ }
530
+ function getSizeFromChildren(size, childrenSizes) {
531
+ if (typeof size !== "number")
532
+ return null;
533
+ if (size === 0)
534
+ return 0;
535
+ const childrenSize = sumSerializerSizes(childrenSizes);
536
+ return childrenSize === null ? null : childrenSize * size;
537
+ }
538
+ function getSizePrefix(size, realSize) {
539
+ return typeof size === "object" ? size.serialize(realSize) : new Uint8Array();
540
+ }
541
+
542
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/array.mjs
543
+ function array(item, options = {}) {
544
+ const size = options.size ?? u32();
545
+ if (size === "remainder" && item.fixedSize === null) {
546
+ throw new ExpectedFixedSizeSerializerError('Serializers of "remainder" size must have fixed-size items.');
547
+ }
548
+ return {
549
+ description: options.description ?? `array(${item.description}; ${getSizeDescription(size)})`,
550
+ fixedSize: getSizeFromChildren(size, [item.fixedSize]),
551
+ maxSize: getSizeFromChildren(size, [item.maxSize]),
552
+ serialize: (value) => {
553
+ if (typeof size === "number" && value.length !== size) {
554
+ throw new InvalidNumberOfItemsError("array", size, value.length);
555
+ }
556
+ return mergeBytes([getSizePrefix(size, value.length), ...value.map((v) => item.serialize(v))]);
557
+ },
558
+ deserialize: (bytes2, offset = 0) => {
559
+ if (typeof size === "object" && bytes2.slice(offset).length === 0) {
560
+ return [[], offset];
561
+ }
562
+ const [resolvedSize, newOffset] = getResolvedSize(size, [item.fixedSize], bytes2, offset);
563
+ offset = newOffset;
564
+ const values = [];
565
+ for (let i = 0; i < resolvedSize; i += 1) {
566
+ const [value, newOffset2] = item.deserialize(bytes2, offset);
567
+ values.push(value);
568
+ offset = newOffset2;
569
+ }
570
+ return [values, offset];
571
+ }
572
+ };
573
+ }
574
+
575
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/bytes.mjs
576
+ init_env_shim();
577
+ function bytes(options = {}) {
578
+ const size = options.size ?? "variable";
579
+ const description = options.description ?? `bytes(${getSizeDescription(size)})`;
580
+ const byteSerializer = {
581
+ description,
582
+ fixedSize: null,
583
+ maxSize: null,
584
+ serialize: (value) => new Uint8Array(value),
585
+ deserialize: (bytes2, offset = 0) => {
586
+ const slice = bytes2.slice(offset);
587
+ return [slice, offset + slice.length];
588
+ }
589
+ };
590
+ if (size === "variable") {
591
+ return byteSerializer;
592
+ }
593
+ if (typeof size === "number") {
594
+ return fixSerializer(byteSerializer, size, description);
595
+ }
596
+ return {
597
+ description,
598
+ fixedSize: null,
599
+ maxSize: null,
600
+ serialize: (value) => {
601
+ const contentBytes = byteSerializer.serialize(value);
602
+ const lengthBytes = size.serialize(contentBytes.length);
603
+ return mergeBytes([lengthBytes, contentBytes]);
604
+ },
605
+ deserialize: (buffer, offset = 0) => {
606
+ if (buffer.slice(offset).length === 0) {
607
+ throw new DeserializingEmptyBufferError("bytes");
608
+ }
609
+ const [lengthBigInt, lengthOffset] = size.deserialize(buffer, offset);
610
+ const length = Number(lengthBigInt);
611
+ offset = lengthOffset;
612
+ const contentBuffer = buffer.slice(offset, offset + length);
613
+ if (contentBuffer.length < length) {
614
+ throw new NotEnoughBytesError("bytes", length, contentBuffer.length);
615
+ }
616
+ const [value, contentOffset] = byteSerializer.deserialize(contentBuffer);
617
+ offset += contentOffset;
618
+ return [value, offset];
619
+ }
620
+ };
621
+ }
622
+
623
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/string.mjs
624
+ init_env_shim();
625
+ function string(options = {}) {
626
+ const size = options.size ?? u32();
627
+ const encoding = options.encoding ?? utf8;
628
+ const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
629
+ if (size === "variable") {
630
+ return {
631
+ ...encoding,
632
+ description
633
+ };
634
+ }
635
+ if (typeof size === "number") {
636
+ return fixSerializer(encoding, size, description);
637
+ }
638
+ return {
639
+ description,
640
+ fixedSize: null,
641
+ maxSize: null,
642
+ serialize: (value) => {
643
+ const contentBytes = encoding.serialize(value);
644
+ const lengthBytes = size.serialize(contentBytes.length);
645
+ return mergeBytes([lengthBytes, contentBytes]);
646
+ },
647
+ deserialize: (buffer, offset = 0) => {
648
+ if (buffer.slice(offset).length === 0) {
649
+ throw new DeserializingEmptyBufferError("string");
650
+ }
651
+ const [lengthBigInt, lengthOffset] = size.deserialize(buffer, offset);
652
+ const length = Number(lengthBigInt);
653
+ offset = lengthOffset;
654
+ const contentBuffer = buffer.slice(offset, offset + length);
655
+ if (contentBuffer.length < length) {
656
+ throw new NotEnoughBytesError("string", length, contentBuffer.length);
657
+ }
658
+ const [value, contentOffset] = encoding.deserialize(contentBuffer);
659
+ offset += contentOffset;
660
+ return [value, offset];
661
+ }
662
+ };
663
+ }
664
+
665
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/struct.mjs
666
+ init_env_shim();
667
+ function struct(fields, options = {}) {
668
+ const fieldDescriptions = fields.map(([name, serializer]) => `${String(name)}: ${serializer.description}`).join(", ");
669
+ return {
670
+ description: options.description ?? `struct(${fieldDescriptions})`,
671
+ fixedSize: sumSerializerSizes(fields.map(([, field]) => field.fixedSize)),
672
+ maxSize: sumSerializerSizes(fields.map(([, field]) => field.maxSize)),
673
+ serialize: (struct2) => {
674
+ const fieldBytes = fields.map(([key, serializer]) => serializer.serialize(struct2[key]));
675
+ return mergeBytes(fieldBytes);
676
+ },
677
+ deserialize: (bytes2, offset = 0) => {
678
+ const struct2 = {};
679
+ fields.forEach(([key, serializer]) => {
680
+ const [value, newOffset] = serializer.deserialize(bytes2, offset);
681
+ offset = newOffset;
682
+ struct2[key] = value;
683
+ });
684
+ return [struct2, offset];
685
+ }
686
+ };
687
+ }
241
688
  function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) {
242
689
  try {
243
690
  if (
@@ -247,8 +694,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
247
694
  ) {
248
695
  throw new Error("Expected input string to decode to a byte array of length 32.");
249
696
  }
250
- const bytes = base58.serialize(putativeBase58EncodedAddress);
251
- const numBytes = bytes.byteLength;
697
+ const bytes2 = base58.serialize(putativeBase58EncodedAddress);
698
+ const numBytes = bytes2.byteLength;
252
699
  if (numBytes !== 32) {
253
700
  throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
254
701
  }
@@ -258,6 +705,13 @@ this.globalThis.solanaWeb3 = (function (exports) {
258
705
  });
259
706
  }
260
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
+ }
261
715
  function getBase58EncodedAddressComparator() {
262
716
  return new Intl.Collator("en", {
263
717
  caseFirst: "lower",
@@ -268,6 +722,815 @@ this.globalThis.solanaWeb3 = (function (exports) {
268
722
  usage: "sort"
269
723
  }).compare;
270
724
  }
725
+ function assertIsSecureContext() {
726
+ if (!globalThis.isSecureContext) {
727
+ throw new Error(
728
+ "Cryptographic operations are only allowed in secure browser contexts. Read more here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts"
729
+ );
730
+ }
731
+ }
732
+ var cachedEd25519Decision;
733
+ async function isEd25519CurveSupported(subtle) {
734
+ if (cachedEd25519Decision === void 0) {
735
+ cachedEd25519Decision = new Promise((resolve) => {
736
+ subtle.generateKey(
737
+ "Ed25519",
738
+ /* extractable */
739
+ false,
740
+ ["sign", "verify"]
741
+ ).catch(() => {
742
+ resolve(cachedEd25519Decision = false);
743
+ }).then(() => {
744
+ resolve(cachedEd25519Decision = true);
745
+ });
746
+ });
747
+ }
748
+ if (typeof cachedEd25519Decision === "boolean") {
749
+ return cachedEd25519Decision;
750
+ } else {
751
+ return await cachedEd25519Decision;
752
+ }
753
+ }
754
+ async function assertKeyGenerationIsAvailable() {
755
+ assertIsSecureContext();
756
+ if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.generateKey !== "function") {
757
+ throw new Error("No key generation implementation could be found");
758
+ }
759
+ if (!await isEd25519CurveSupported(globalThis.crypto.subtle)) {
760
+ throw new Error(
761
+ "This runtime does not support the generation of Ed25519 key pairs.\n\nInstall and import `@solana/webcrypto-ed25519-polyfill` before generating keys in environments that do not support Ed25519.\n\nFor a list of runtimes that currently support Ed25519 operations, visit https://github.com/WICG/webcrypto-secure-curves/issues/20"
762
+ );
763
+ }
764
+ }
765
+ async function assertKeyExporterIsAvailable() {
766
+ assertIsSecureContext();
767
+ if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.exportKey !== "function") {
768
+ throw new Error("No key export implementation could be found");
769
+ }
770
+ }
771
+ async function assertSigningCapabilityIsAvailable() {
772
+ assertIsSecureContext();
773
+ if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.sign !== "function") {
774
+ throw new Error("No signing implementation could be found");
775
+ }
776
+ }
777
+ async function assertVerificationCapabilityIsAvailable() {
778
+ assertIsSecureContext();
779
+ if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.verify !== "function") {
780
+ throw new Error("No signature verification implementation could be found");
781
+ }
782
+ }
783
+ async function generateKeyPair() {
784
+ await assertKeyGenerationIsAvailable();
785
+ const keyPair = await crypto.subtle.generateKey(
786
+ /* algorithm */
787
+ "Ed25519",
788
+ // Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20
789
+ /* extractable */
790
+ false,
791
+ // Prevents the bytes of the private key from being visible to JS.
792
+ /* allowed uses */
793
+ ["sign", "verify"]
794
+ );
795
+ return keyPair;
796
+ }
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
+ async function signBytes(key, data) {
807
+ await assertSigningCapabilityIsAvailable();
808
+ const signedData = await crypto.subtle.sign("Ed25519", key, data);
809
+ return new Uint8Array(signedData);
810
+ }
811
+ async function verifySignature(key, signature, data) {
812
+ await assertVerificationCapabilityIsAvailable();
813
+ return await crypto.subtle.verify("Ed25519", key, signature, data);
814
+ }
815
+
816
+ // ../transactions/dist/index.browser.js
817
+ init_env_shim();
818
+ function getUnsignedTransaction(transaction) {
819
+ if ("signatures" in transaction) {
820
+ const {
821
+ signatures: _,
822
+ // eslint-disable-line @typescript-eslint/no-unused-vars
823
+ ...unsignedTransaction
824
+ } = transaction;
825
+ return unsignedTransaction;
826
+ } else {
827
+ return transaction;
828
+ }
829
+ }
830
+ function assertIsBlockhash(putativeBlockhash) {
831
+ try {
832
+ if (
833
+ // Lowest value (32 bytes of zeroes)
834
+ putativeBlockhash.length < 32 || // Highest value (32 bytes of 255)
835
+ putativeBlockhash.length > 44
836
+ ) {
837
+ throw new Error("Expected input string to decode to a byte array of length 32.");
838
+ }
839
+ const bytes3 = base58.serialize(putativeBlockhash);
840
+ const numBytes = bytes3.byteLength;
841
+ if (numBytes !== 32) {
842
+ throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
843
+ }
844
+ } catch (e2) {
845
+ throw new Error(`\`${putativeBlockhash}\` is not a blockhash`, {
846
+ cause: e2
847
+ });
848
+ }
849
+ }
850
+ function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {
851
+ if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
852
+ return transaction;
853
+ }
854
+ const out = {
855
+ ...getUnsignedTransaction(transaction),
856
+ lifetimeConstraint: blockhashLifetimeConstraint
857
+ };
858
+ Object.freeze(out);
859
+ return out;
860
+ }
861
+ function createTransaction({
862
+ version
863
+ }) {
864
+ const out = {
865
+ instructions: [],
866
+ version
867
+ };
868
+ Object.freeze(out);
869
+ return out;
870
+ }
871
+ var AccountRole2 = /* @__PURE__ */ ((AccountRole22) => {
872
+ AccountRole22[AccountRole22["WRITABLE_SIGNER"] = /* 3 */
873
+ 3] = "WRITABLE_SIGNER";
874
+ AccountRole22[AccountRole22["READONLY_SIGNER"] = /* 2 */
875
+ 2] = "READONLY_SIGNER";
876
+ AccountRole22[AccountRole22["WRITABLE"] = /* 1 */
877
+ 1] = "WRITABLE";
878
+ AccountRole22[AccountRole22["READONLY"] = /* 0 */
879
+ 0] = "READONLY";
880
+ return AccountRole22;
881
+ })(AccountRole2 || {});
882
+ var IS_WRITABLE_BITMASK2 = 1;
883
+ function isSignerRole2(role) {
884
+ return role >= 2;
885
+ }
886
+ function isWritableRole2(role) {
887
+ return (role & IS_WRITABLE_BITMASK2) !== 0;
888
+ }
889
+ function mergeRoles2(roleA, roleB) {
890
+ return roleA | roleB;
891
+ }
892
+ var RECENT_BLOCKHASHES_SYSVAR_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111";
893
+ var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
894
+ function assertIsDurableNonceTransaction(transaction) {
895
+ if (!isDurableNonceTransaction(transaction)) {
896
+ throw new Error("Transaction is not a durable nonce transaction");
897
+ }
898
+ }
899
+ function createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress) {
900
+ return {
901
+ accounts: [
902
+ { address: nonceAccountAddress, role: AccountRole2.WRITABLE },
903
+ {
904
+ address: RECENT_BLOCKHASHES_SYSVAR_ADDRESS,
905
+ role: AccountRole2.READONLY
906
+ },
907
+ { address: nonceAuthorityAddress, role: AccountRole2.READONLY_SIGNER }
908
+ ],
909
+ data: new Uint8Array([4, 0, 0, 0]),
910
+ programAddress: SYSTEM_PROGRAM_ADDRESS
911
+ };
912
+ }
913
+ function isAdvanceNonceAccountInstruction(instruction) {
914
+ return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
915
+ instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts
916
+ instruction.accounts?.length === 3 && // First account is nonce account address
917
+ instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole2.WRITABLE && // Second account is recent blockhashes sysvar
918
+ instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole2.READONLY && // Third account is nonce authority account
919
+ instruction.accounts[2].address != null && instruction.accounts[2].role === AccountRole2.READONLY_SIGNER;
920
+ }
921
+ function isAdvanceNonceAccountInstructionData(data) {
922
+ return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
923
+ }
924
+ function isDurableNonceTransaction(transaction) {
925
+ return "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.nonce === "string" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]);
926
+ }
927
+ function setTransactionLifetimeUsingDurableNonce({
928
+ nonce,
929
+ nonceAccountAddress,
930
+ nonceAuthorityAddress
931
+ }, transaction) {
932
+ const isAlreadyDurableNonceTransaction = isDurableNonceTransaction(transaction);
933
+ if (isAlreadyDurableNonceTransaction && transaction.lifetimeConstraint.nonce === nonce && transaction.instructions[0].accounts[0].address === nonceAccountAddress && transaction.instructions[0].accounts[2].address === nonceAuthorityAddress) {
934
+ return transaction;
935
+ }
936
+ const out = {
937
+ ...getUnsignedTransaction(transaction),
938
+ instructions: [
939
+ createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
940
+ ...isAlreadyDurableNonceTransaction ? transaction.instructions.slice(1) : transaction.instructions
941
+ ],
942
+ lifetimeConstraint: {
943
+ nonce
944
+ }
945
+ };
946
+ Object.freeze(out);
947
+ return out;
948
+ }
949
+ function setTransactionFeePayer(feePayer, transaction) {
950
+ if ("feePayer" in transaction && feePayer === transaction.feePayer) {
951
+ return transaction;
952
+ }
953
+ const out = {
954
+ ...getUnsignedTransaction(transaction),
955
+ feePayer
956
+ };
957
+ Object.freeze(out);
958
+ return out;
959
+ }
960
+ function appendTransactionInstruction(instruction, transaction) {
961
+ const out = {
962
+ ...getUnsignedTransaction(transaction),
963
+ instructions: [...transaction.instructions, instruction]
964
+ };
965
+ Object.freeze(out);
966
+ return out;
967
+ }
968
+ function prependTransactionInstruction(instruction, transaction) {
969
+ const out = {
970
+ ...getUnsignedTransaction(transaction),
971
+ instructions: [instruction, ...transaction.instructions]
972
+ };
973
+ Object.freeze(out);
974
+ return out;
975
+ }
976
+ function upsert(addressMap, address, update) {
977
+ addressMap[address] = update(addressMap[address] ?? { role: AccountRole2.READONLY });
978
+ }
979
+ var TYPE = Symbol("AddressMapTypeProperty");
980
+ function getAddressMapFromInstructions(feePayer, instructions) {
981
+ const addressMap = {
982
+ [feePayer]: { [TYPE]: 0, role: AccountRole2.WRITABLE_SIGNER }
983
+ };
984
+ const addressesOfInvokedPrograms = /* @__PURE__ */ new Set();
985
+ for (const instruction of instructions) {
986
+ upsert(addressMap, instruction.programAddress, (entry) => {
987
+ addressesOfInvokedPrograms.add(instruction.programAddress);
988
+ if (TYPE in entry) {
989
+ if (isWritableRole2(entry.role)) {
990
+ switch (entry[TYPE]) {
991
+ case 0:
992
+ throw new Error(
993
+ `This transaction includes an address (\`${instruction.programAddress}\`) which is both invoked and set as the fee payer. Program addresses may not pay fees.`
994
+ );
995
+ default:
996
+ throw new Error(
997
+ `This transaction includes an address (\`${instruction.programAddress}\`) which is both invoked and marked writable. Program addresses may not be writable.`
998
+ );
999
+ }
1000
+ }
1001
+ if (entry[TYPE] === 2) {
1002
+ return entry;
1003
+ }
1004
+ }
1005
+ return { [TYPE]: 2, role: AccountRole2.READONLY };
1006
+ });
1007
+ let addressComparator;
1008
+ if (!instruction.accounts) {
1009
+ continue;
1010
+ }
1011
+ for (const account of instruction.accounts) {
1012
+ upsert(addressMap, account.address, (entry) => {
1013
+ const {
1014
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1015
+ address: _,
1016
+ ...accountMeta
1017
+ } = account;
1018
+ if (TYPE in entry) {
1019
+ switch (entry[TYPE]) {
1020
+ case 0:
1021
+ return entry;
1022
+ case 1: {
1023
+ const nextRole = mergeRoles2(entry.role, accountMeta.role);
1024
+ if ("lookupTableAddress" in accountMeta) {
1025
+ const shouldReplaceEntry = (
1026
+ // Consider using the new LOOKUP_TABLE if its address is different...
1027
+ entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
1028
+ (addressComparator || (addressComparator = getBase58EncodedAddressComparator()))(
1029
+ accountMeta.lookupTableAddress,
1030
+ entry.lookupTableAddress
1031
+ ) < 0
1032
+ );
1033
+ if (shouldReplaceEntry) {
1034
+ return {
1035
+ [TYPE]: 1,
1036
+ ...accountMeta,
1037
+ role: nextRole
1038
+ };
1039
+ }
1040
+ } else if (isSignerRole2(accountMeta.role)) {
1041
+ return {
1042
+ [TYPE]: 2,
1043
+ role: nextRole
1044
+ };
1045
+ }
1046
+ if (entry.role !== nextRole) {
1047
+ return {
1048
+ ...entry,
1049
+ role: nextRole
1050
+ };
1051
+ } else {
1052
+ return entry;
1053
+ }
1054
+ }
1055
+ case 2: {
1056
+ const nextRole = mergeRoles2(entry.role, accountMeta.role);
1057
+ if (
1058
+ // Check to see if this address represents a program that is invoked
1059
+ // in this transaction.
1060
+ addressesOfInvokedPrograms.has(account.address)
1061
+ ) {
1062
+ if (isWritableRole2(accountMeta.role)) {
1063
+ throw new Error(
1064
+ `This transaction includes an address (\`${account.address}\`) which is both invoked and marked writable. Program addresses may not be writable.`
1065
+ );
1066
+ }
1067
+ if (entry.role !== nextRole) {
1068
+ return {
1069
+ ...entry,
1070
+ role: nextRole
1071
+ };
1072
+ } else {
1073
+ return entry;
1074
+ }
1075
+ } else if ("lookupTableAddress" in accountMeta && // Static accounts can be 'upgraded' to lookup table accounts as
1076
+ // long as they are not require to sign the transaction.
1077
+ !isSignerRole2(entry.role)) {
1078
+ return {
1079
+ ...accountMeta,
1080
+ [TYPE]: 1,
1081
+ role: nextRole
1082
+ };
1083
+ } else {
1084
+ if (entry.role !== nextRole) {
1085
+ return {
1086
+ ...entry,
1087
+ role: nextRole
1088
+ };
1089
+ } else {
1090
+ return entry;
1091
+ }
1092
+ }
1093
+ }
1094
+ }
1095
+ }
1096
+ if ("lookupTableAddress" in accountMeta) {
1097
+ return {
1098
+ ...accountMeta,
1099
+ [TYPE]: 1
1100
+ /* LOOKUP_TABLE */
1101
+ };
1102
+ } else {
1103
+ return {
1104
+ ...accountMeta,
1105
+ [TYPE]: 2
1106
+ /* STATIC */
1107
+ };
1108
+ }
1109
+ });
1110
+ }
1111
+ }
1112
+ return addressMap;
1113
+ }
1114
+ function getOrderedAccountsFromAddressMap(addressMap) {
1115
+ let addressComparator;
1116
+ const orderedAccounts = Object.entries(addressMap).sort(([leftAddress, leftEntry], [rightAddress, rightEntry]) => {
1117
+ if (leftEntry[TYPE] !== rightEntry[TYPE]) {
1118
+ if (leftEntry[TYPE] === 0) {
1119
+ return -1;
1120
+ } else if (rightEntry[TYPE] === 0) {
1121
+ return 1;
1122
+ } else if (leftEntry[TYPE] === 2) {
1123
+ return -1;
1124
+ } else if (rightEntry[TYPE] === 2) {
1125
+ return 1;
1126
+ }
1127
+ }
1128
+ const leftIsSigner = isSignerRole2(leftEntry.role);
1129
+ if (leftIsSigner !== isSignerRole2(rightEntry.role)) {
1130
+ return leftIsSigner ? -1 : 1;
1131
+ }
1132
+ const leftIsWritable = isWritableRole2(leftEntry.role);
1133
+ if (leftIsWritable !== isWritableRole2(rightEntry.role)) {
1134
+ return leftIsWritable ? -1 : 1;
1135
+ }
1136
+ addressComparator || (addressComparator = getBase58EncodedAddressComparator());
1137
+ if (leftEntry[TYPE] === 1 && rightEntry[TYPE] === 1 && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
1138
+ return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
1139
+ } else {
1140
+ return addressComparator(leftAddress, rightAddress);
1141
+ }
1142
+ }).map(([address, addressMeta]) => ({
1143
+ address,
1144
+ ...addressMeta
1145
+ }));
1146
+ return orderedAccounts;
1147
+ }
1148
+ function getCompiledAddressTableLookups(orderedAccounts) {
1149
+ var _a;
1150
+ const index = {};
1151
+ for (const account of orderedAccounts) {
1152
+ if (!("lookupTableAddress" in account)) {
1153
+ continue;
1154
+ }
1155
+ const entry = index[_a = account.lookupTableAddress] || (index[_a] = {
1156
+ readableIndices: [],
1157
+ writableIndices: []
1158
+ });
1159
+ if (account.role === AccountRole2.WRITABLE) {
1160
+ entry.writableIndices.push(account.addressIndex);
1161
+ } else {
1162
+ entry.readableIndices.push(account.addressIndex);
1163
+ }
1164
+ }
1165
+ return Object.keys(index).sort(getBase58EncodedAddressComparator()).map((lookupTableAddress) => ({
1166
+ lookupTableAddress,
1167
+ ...index[lookupTableAddress]
1168
+ }));
1169
+ }
1170
+ function getCompiledMessageHeader(orderedAccounts) {
1171
+ let numReadonlyNonSignerAccounts = 0;
1172
+ let numReadonlySignerAccounts = 0;
1173
+ let numSignerAccounts = 0;
1174
+ for (const account of orderedAccounts) {
1175
+ if ("lookupTableAddress" in account) {
1176
+ break;
1177
+ }
1178
+ const accountIsWritable = isWritableRole2(account.role);
1179
+ if (isSignerRole2(account.role)) {
1180
+ numSignerAccounts++;
1181
+ if (!accountIsWritable) {
1182
+ numReadonlySignerAccounts++;
1183
+ }
1184
+ } else if (!accountIsWritable) {
1185
+ numReadonlyNonSignerAccounts++;
1186
+ }
1187
+ }
1188
+ return {
1189
+ numReadonlyNonSignerAccounts,
1190
+ numReadonlySignerAccounts,
1191
+ numSignerAccounts
1192
+ };
1193
+ }
1194
+ function getAccountIndex(orderedAccounts) {
1195
+ const out = {};
1196
+ for (const [index, account] of orderedAccounts.entries()) {
1197
+ out[account.address] = index;
1198
+ }
1199
+ return out;
1200
+ }
1201
+ function getCompiledInstructions(instructions, orderedAccounts) {
1202
+ const accountIndex = getAccountIndex(orderedAccounts);
1203
+ return instructions.map(({ accounts, data, programAddress }) => {
1204
+ return {
1205
+ programAddressIndex: accountIndex[programAddress],
1206
+ ...accounts ? { accountIndices: accounts.map(({ address }) => accountIndex[address]) } : null,
1207
+ ...data ? { data } : null
1208
+ };
1209
+ });
1210
+ }
1211
+ function getCompiledLifetimeToken(lifetimeConstraint) {
1212
+ if ("nonce" in lifetimeConstraint) {
1213
+ return lifetimeConstraint.nonce;
1214
+ }
1215
+ return lifetimeConstraint.blockhash;
1216
+ }
1217
+ function getCompiledStaticAccounts(orderedAccounts) {
1218
+ const firstLookupTableAccountIndex = orderedAccounts.findIndex((account) => "lookupTableAddress" in account);
1219
+ const orderedStaticAccounts = firstLookupTableAccountIndex === -1 ? orderedAccounts : orderedAccounts.slice(0, firstLookupTableAccountIndex);
1220
+ return orderedStaticAccounts.map(({ address }) => address);
1221
+ }
1222
+ function compileMessage(transaction) {
1223
+ const addressMap = getAddressMapFromInstructions(transaction.feePayer, transaction.instructions);
1224
+ const orderedAccounts = getOrderedAccountsFromAddressMap(addressMap);
1225
+ return {
1226
+ ...transaction.version !== "legacy" ? { addressTableLookups: getCompiledAddressTableLookups(orderedAccounts) } : null,
1227
+ header: getCompiledMessageHeader(orderedAccounts),
1228
+ instructions: getCompiledInstructions(transaction.instructions, orderedAccounts),
1229
+ lifetimeToken: getCompiledLifetimeToken(transaction.lifetimeConstraint),
1230
+ staticAccounts: getCompiledStaticAccounts(orderedAccounts),
1231
+ version: transaction.version
1232
+ };
1233
+ }
1234
+ function getAddressTableLookupCodec() {
1235
+ return struct(
1236
+ [
1237
+ [
1238
+ "lookupTableAddress",
1239
+ getBase58EncodedAddressCodec(
1240
+ {
1241
+ description: "The address of the address lookup table account from which instruction addresses should be looked up"
1242
+ }
1243
+ )
1244
+ ],
1245
+ [
1246
+ "writableIndices",
1247
+ array(u8(), {
1248
+ ...{
1249
+ description: "The indices of the accounts in the lookup table that should be loaded as writeable"
1250
+ } ,
1251
+ size: shortU16()
1252
+ })
1253
+ ],
1254
+ [
1255
+ "readableIndices",
1256
+ array(u8(), {
1257
+ ...{
1258
+ description: "The indices of the accounts in the lookup table that should be loaded as read-only"
1259
+ } ,
1260
+ size: shortU16()
1261
+ })
1262
+ ]
1263
+ ],
1264
+ {
1265
+ description: "A pointer to the address of an address lookup table, along with the readonly/writeable indices of the addresses that should be loaded from it"
1266
+ }
1267
+ );
1268
+ }
1269
+ function getMessageHeaderCodec() {
1270
+ return struct(
1271
+ [
1272
+ [
1273
+ "numSignerAccounts",
1274
+ u8(
1275
+ {
1276
+ description: "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction"
1277
+ }
1278
+ )
1279
+ ],
1280
+ [
1281
+ "numReadonlySignerAccounts",
1282
+ u8(
1283
+ {
1284
+ description: "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction, but may not be writable"
1285
+ }
1286
+ )
1287
+ ],
1288
+ [
1289
+ "numReadonlyNonSignerAccounts",
1290
+ u8(
1291
+ {
1292
+ description: "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable"
1293
+ }
1294
+ )
1295
+ ]
1296
+ ],
1297
+ {
1298
+ description: "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses"
1299
+ }
1300
+ );
1301
+ }
1302
+ function getInstructionCodec() {
1303
+ return mapSerializer(
1304
+ struct([
1305
+ [
1306
+ "programAddressIndex",
1307
+ u8(
1308
+ {
1309
+ description: "The index of the program being called, according to the well-ordered accounts list for this transaction"
1310
+ }
1311
+ )
1312
+ ],
1313
+ [
1314
+ "addressIndices",
1315
+ array(
1316
+ u8({
1317
+ description: "The index of an account, according to the well-ordered accounts list for this transaction"
1318
+ }),
1319
+ {
1320
+ description: "An optional list of account indices, according to the well-ordered accounts list for this transaction, in the order in which the program being called expects them" ,
1321
+ size: shortU16()
1322
+ }
1323
+ )
1324
+ ],
1325
+ [
1326
+ "data",
1327
+ bytes({
1328
+ description: "An optional buffer of data passed to the instruction" ,
1329
+ size: shortU16()
1330
+ })
1331
+ ]
1332
+ ]),
1333
+ (value) => {
1334
+ if (value.addressIndices !== void 0 && value.data !== void 0) {
1335
+ return value;
1336
+ }
1337
+ return {
1338
+ ...value,
1339
+ addressIndices: value.addressIndices ?? [],
1340
+ data: value.data ?? new Uint8Array(0)
1341
+ };
1342
+ },
1343
+ (value) => {
1344
+ if (value.addressIndices.length && value.data.byteLength) {
1345
+ return value;
1346
+ }
1347
+ const { addressIndices, data, ...rest } = value;
1348
+ return {
1349
+ ...rest,
1350
+ ...addressIndices.length ? { addressIndices } : null,
1351
+ ...data.byteLength ? { data } : null
1352
+ };
1353
+ }
1354
+ );
1355
+ }
1356
+ function getError(type, name) {
1357
+ const functionSuffix = name + type[0].toUpperCase() + type.slice(1);
1358
+ return new Error(
1359
+ `No ${type} exists for ${name}. Use \`get${functionSuffix}()\` if you need a ${type}, and \`get${name}Codec()\` if you need to both encode and decode ${name}`
1360
+ );
1361
+ }
1362
+ function getUnimplementedDecoder(name) {
1363
+ return () => {
1364
+ throw getError("decoder", name);
1365
+ };
1366
+ }
1367
+ var VERSION_FLAG_MASK = 128;
1368
+ var BASE_CONFIG = {
1369
+ description: "A single byte that encodes the version of the transaction" ,
1370
+ fixedSize: null,
1371
+ maxSize: 1
1372
+ };
1373
+ function deserialize(bytes3, offset = 0) {
1374
+ const firstByte = bytes3[offset];
1375
+ if ((firstByte & VERSION_FLAG_MASK) === 0) {
1376
+ return ["legacy", offset];
1377
+ } else {
1378
+ const version = firstByte ^ VERSION_FLAG_MASK;
1379
+ return [version, offset + 1];
1380
+ }
1381
+ }
1382
+ function serialize(value) {
1383
+ if (value === "legacy") {
1384
+ return new Uint8Array();
1385
+ }
1386
+ if (value < 0 || value > 127) {
1387
+ throw new Error(`Transaction version must be in the range [0, 127]. \`${value}\` given.`);
1388
+ }
1389
+ return new Uint8Array([value | VERSION_FLAG_MASK]);
1390
+ }
1391
+ function getTransactionVersionCodec() {
1392
+ return {
1393
+ ...BASE_CONFIG,
1394
+ deserialize,
1395
+ serialize
1396
+ };
1397
+ }
1398
+ var BASE_CONFIG2 = {
1399
+ description: "The wire format of a Solana transaction message" ,
1400
+ fixedSize: null,
1401
+ maxSize: null
1402
+ };
1403
+ function serialize2(compiledMessage) {
1404
+ if (compiledMessage.version === "legacy") {
1405
+ return struct(getPreludeStructSerializerTuple()).serialize(compiledMessage);
1406
+ } else {
1407
+ return mapSerializer(
1408
+ struct([
1409
+ ...getPreludeStructSerializerTuple(),
1410
+ ["addressTableLookups", getAddressTableLookupsSerializer()]
1411
+ ]),
1412
+ (value) => {
1413
+ if (value.version === "legacy") {
1414
+ return value;
1415
+ }
1416
+ return {
1417
+ ...value,
1418
+ addressTableLookups: value.addressTableLookups ?? []
1419
+ };
1420
+ }
1421
+ ).serialize(compiledMessage);
1422
+ }
1423
+ }
1424
+ function getPreludeStructSerializerTuple() {
1425
+ return [
1426
+ ["version", getTransactionVersionCodec()],
1427
+ ["header", getMessageHeaderCodec()],
1428
+ [
1429
+ "staticAccounts",
1430
+ array(getBase58EncodedAddressCodec(), {
1431
+ description: "A compact-array of static account addresses belonging to this transaction" ,
1432
+ size: shortU16()
1433
+ })
1434
+ ],
1435
+ [
1436
+ "lifetimeToken",
1437
+ string({
1438
+ description: "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" ,
1439
+ encoding: base58,
1440
+ size: 32
1441
+ })
1442
+ ],
1443
+ [
1444
+ "instructions",
1445
+ array(getInstructionCodec(), {
1446
+ description: "A compact-array of instructions belonging to this transaction" ,
1447
+ size: shortU16()
1448
+ })
1449
+ ]
1450
+ ];
1451
+ }
1452
+ function getAddressTableLookupsSerializer() {
1453
+ return array(getAddressTableLookupCodec(), {
1454
+ ...{ description: "A compact array of address table lookups belonging to this transaction" } ,
1455
+ size: shortU16()
1456
+ });
1457
+ }
1458
+ function getCompiledMessageEncoder() {
1459
+ return {
1460
+ ...BASE_CONFIG2,
1461
+ deserialize: getUnimplementedDecoder("CompiledMessage"),
1462
+ serialize: serialize2
1463
+ };
1464
+ }
1465
+ async function getCompiledMessageSignature(message, secretKey) {
1466
+ const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
1467
+ const signature = await signBytes(secretKey, wireMessageBytes);
1468
+ return signature;
1469
+ }
1470
+ async function signTransaction(keyPair, transaction) {
1471
+ 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
+ };
1480
+ const out = {
1481
+ ...transaction,
1482
+ signatures: nextSignatures
1483
+ };
1484
+ Object.freeze(out);
1485
+ return out;
1486
+ }
1487
+ function getCompiledTransaction(transaction) {
1488
+ const compiledMessage = compileMessage(transaction);
1489
+ let signatures;
1490
+ if ("signatures" in transaction) {
1491
+ signatures = [];
1492
+ for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
1493
+ signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
1494
+ }
1495
+ } else {
1496
+ signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
1497
+ }
1498
+ return {
1499
+ compiledMessage,
1500
+ signatures
1501
+ };
1502
+ }
1503
+ var BASE_CONFIG3 = {
1504
+ description: "The wire format of a Solana transaction" ,
1505
+ fixedSize: null,
1506
+ maxSize: null
1507
+ };
1508
+ function serialize3(transaction) {
1509
+ const compiledTransaction = getCompiledTransaction(transaction);
1510
+ return struct([
1511
+ [
1512
+ "signatures",
1513
+ array(bytes({ size: 64 }), {
1514
+ ...{ description: "A compact array of 64-byte, base-64 encoded Ed25519 signatures" } ,
1515
+ size: shortU16()
1516
+ })
1517
+ ],
1518
+ ["compiledMessage", getCompiledMessageEncoder()]
1519
+ ]).serialize(compiledTransaction);
1520
+ }
1521
+ function getTransactionEncoder() {
1522
+ return {
1523
+ ...BASE_CONFIG3,
1524
+ deserialize: getUnimplementedDecoder("CompiledMessage"),
1525
+ serialize: serialize3
1526
+ };
1527
+ }
1528
+ function getBase64EncodedWireTransaction(transaction) {
1529
+ const wireTransactionBytes = getTransactionEncoder().serialize(transaction);
1530
+ {
1531
+ return btoa(String.fromCharCode(...wireTransactionBytes));
1532
+ }
1533
+ }
271
1534
 
272
1535
  // src/rpc.ts
273
1536
  init_env_shim();
@@ -301,6 +1564,55 @@ this.globalThis.solanaWeb3 = (function (exports) {
301
1564
  }
302
1565
  var KEYPATH_WILDCARD = {};
303
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
+ ],
304
1616
  getBlockTime: [[]],
305
1617
  getInflationReward: [[KEYPATH_WILDCARD, "commission"]],
306
1618
  getRecentPerformanceSamples: [[KEYPATH_WILDCARD, "samplePeriodSecs"]],
@@ -348,7 +1660,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
348
1660
  return out;
349
1661
  } else if (typeof value === "number" && // The presence of an allowed keypath on the route to this value implies it's allowlisted;
350
1662
  // Upcast the value to `bigint` unless an allowed keypath is present.
351
- allowedKeypaths.length === 0) {
1663
+ allowedKeypaths.length === 0 && // Only try to upcast an Integer to `bigint`
1664
+ Number.isInteger(value)) {
352
1665
  return BigInt(value);
353
1666
  } else {
354
1667
  return value;
@@ -690,17 +2003,32 @@ this.globalThis.solanaWeb3 = (function (exports) {
690
2003
  }
691
2004
 
692
2005
  exports.AccountRole = AccountRole;
2006
+ exports.appendTransactionInstruction = appendTransactionInstruction;
693
2007
  exports.assertIsBase58EncodedAddress = assertIsBase58EncodedAddress;
2008
+ exports.assertIsBlockhash = assertIsBlockhash;
2009
+ exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
694
2010
  exports.createDefaultRpcTransport = createDefaultRpcTransport;
695
2011
  exports.createSolanaRpc = createSolanaRpc;
2012
+ exports.createTransaction = createTransaction;
696
2013
  exports.downgradeRoleToNonSigner = downgradeRoleToNonSigner;
697
2014
  exports.downgradeRoleToReadonly = downgradeRoleToReadonly;
2015
+ exports.generateKeyPair = generateKeyPair;
2016
+ exports.getBase58EncodedAddressCodec = getBase58EncodedAddressCodec;
698
2017
  exports.getBase58EncodedAddressComparator = getBase58EncodedAddressComparator;
2018
+ exports.getBase58EncodedAddressFromPublicKey = getBase58EncodedAddressFromPublicKey;
2019
+ exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
699
2020
  exports.isSignerRole = isSignerRole;
700
2021
  exports.isWritableRole = isWritableRole;
701
2022
  exports.mergeRoles = mergeRoles;
2023
+ exports.prependTransactionInstruction = prependTransactionInstruction;
2024
+ exports.setTransactionFeePayer = setTransactionFeePayer;
2025
+ exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
2026
+ exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
2027
+ exports.signBytes = signBytes;
2028
+ exports.signTransaction = signTransaction;
702
2029
  exports.upgradeRoleToSigner = upgradeRoleToSigner;
703
2030
  exports.upgradeRoleToWritable = upgradeRoleToWritable;
2031
+ exports.verifySignature = verifySignature;
704
2032
 
705
2033
  return exports;
706
2034