@solana/transactions 2.0.0-experimental.d49fb7f → 2.0.0-experimental.d4b2978

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/LICENSE +1 -1
  2. package/dist/index.browser.cjs +267 -232
  3. package/dist/index.browser.cjs.map +1 -1
  4. package/dist/index.browser.js +266 -235
  5. package/dist/index.browser.js.map +1 -1
  6. package/dist/index.development.js +759 -351
  7. package/dist/index.development.js.map +1 -1
  8. package/dist/index.native.js +264 -235
  9. package/dist/index.native.js.map +1 -1
  10. package/dist/index.node.cjs +267 -234
  11. package/dist/index.node.cjs.map +1 -1
  12. package/dist/index.node.js +264 -235
  13. package/dist/index.node.js.map +1 -1
  14. package/dist/index.production.min.js +17 -11
  15. package/dist/types/accounts.d.ts +1 -1
  16. package/dist/types/accounts.d.ts.map +1 -0
  17. package/dist/types/blockhash.d.ts +1 -1
  18. package/dist/types/blockhash.d.ts.map +1 -0
  19. package/dist/types/compile-address-table-lookups.d.ts.map +1 -0
  20. package/dist/types/compile-header.d.ts.map +1 -0
  21. package/dist/types/compile-instructions.d.ts +1 -1
  22. package/dist/types/compile-instructions.d.ts.map +1 -0
  23. package/dist/types/compile-lifetime-token.d.ts.map +1 -0
  24. package/dist/types/compile-static-accounts.d.ts.map +1 -0
  25. package/dist/types/compile-transaction.d.ts.map +1 -0
  26. package/dist/types/create-transaction.d.ts.map +1 -0
  27. package/dist/types/durable-nonce.d.ts +5 -3
  28. package/dist/types/durable-nonce.d.ts.map +1 -0
  29. package/dist/types/fee-payer.d.ts +2 -1
  30. package/dist/types/fee-payer.d.ts.map +1 -0
  31. package/dist/types/index.d.ts +1 -0
  32. package/dist/types/index.d.ts.map +1 -0
  33. package/dist/types/instructions.d.ts.map +1 -0
  34. package/dist/types/message.d.ts.map +1 -0
  35. package/dist/types/serializers/address-table-lookup.d.ts +5 -3
  36. package/dist/types/serializers/address-table-lookup.d.ts.map +1 -0
  37. package/dist/types/serializers/header.d.ts +4 -2
  38. package/dist/types/serializers/header.d.ts.map +1 -0
  39. package/dist/types/serializers/index.d.ts +2 -0
  40. package/dist/types/serializers/index.d.ts.map +1 -0
  41. package/dist/types/serializers/instruction.d.ts +4 -2
  42. package/dist/types/serializers/instruction.d.ts.map +1 -0
  43. package/dist/types/serializers/message.d.ts +4 -4
  44. package/dist/types/serializers/message.d.ts.map +1 -0
  45. package/dist/types/serializers/transaction-version.d.ts +4 -4
  46. package/dist/types/serializers/transaction-version.d.ts.map +1 -0
  47. package/dist/types/serializers/transaction.d.ts.map +1 -0
  48. package/dist/types/serializers/unimplemented.d.ts.map +1 -0
  49. package/dist/types/signatures.d.ts +10 -2
  50. package/dist/types/signatures.d.ts.map +1 -0
  51. package/dist/types/types.d.ts +7 -0
  52. package/dist/types/types.d.ts.map +1 -0
  53. package/dist/types/unsigned-transaction.d.ts.map +1 -0
  54. package/dist/types/wire-transaction.d.ts +1 -1
  55. package/dist/types/wire-transaction.d.ts.map +1 -0
  56. package/package.json +22 -16
@@ -9,7 +9,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
9
9
  return value;
10
10
  };
11
11
 
12
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/bytes.mjs
12
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/bytes.mjs
13
13
  var mergeBytes = (bytesArr) => {
14
14
  const totalLength = bytesArr.reduce((total, arr) => total + arr.length, 0);
15
15
  const result = new Uint8Array(totalLength);
@@ -29,7 +29,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
29
29
  };
30
30
  var fixBytes = (bytes2, length) => padBytes(bytes2.slice(0, length), length);
31
31
 
32
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/errors.mjs
32
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/errors.mjs
33
33
  var DeserializingEmptyBufferError = class extends Error {
34
34
  constructor(serializer) {
35
35
  super(`Serializer [${serializer}] cannot deserialize empty buffers.`);
@@ -50,7 +50,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
50
50
  }
51
51
  };
52
52
 
53
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/fixSerializer.mjs
53
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/fixSerializer.mjs
54
54
  function fixSerializer(serializer, fixedBytes, description) {
55
55
  return {
56
56
  description: description ?? `fixed(${fixedBytes}, ${serializer.description})`,
@@ -71,21 +71,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
71
71
  };
72
72
  }
73
73
 
74
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/mapSerializer.mjs
75
- function mapSerializer(serializer, unmap, map) {
76
- return {
77
- description: serializer.description,
78
- fixedSize: serializer.fixedSize,
79
- maxSize: serializer.maxSize,
80
- serialize: (value) => serializer.serialize(unmap(value)),
81
- deserialize: (buffer, offset = 0) => {
82
- const [value, length] = serializer.deserialize(buffer, offset);
83
- return map ? [map(value, buffer, offset), length] : [value, length];
84
- }
85
- };
86
- }
87
-
88
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/errors.mjs
74
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/errors.mjs
89
75
  var InvalidBaseStringError = class extends Error {
90
76
  constructor(value, base, cause) {
91
77
  const message = `Expected a string of base ${base}, got [${value}].`;
@@ -95,7 +81,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
95
81
  }
96
82
  };
97
83
 
98
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseX.mjs
84
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseX.mjs
99
85
  var baseX = (alphabet) => {
100
86
  const base = alphabet.length;
101
87
  const baseBigInt = BigInt(base);
@@ -149,37 +135,17 @@ this.globalThis.solanaWeb3 = (function (exports) {
149
135
  };
150
136
  };
151
137
 
152
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/base58.mjs
138
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/base58.mjs
153
139
  var base58 = baseX("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
154
140
 
155
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/nullCharacters.mjs
156
- var removeNullCharacters = (value) => (
157
- // eslint-disable-next-line no-control-regex
158
- value.replace(/\u0000/g, "")
159
- );
160
-
161
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/utf8.mjs
162
- var utf8 = {
163
- description: "utf8",
164
- fixedSize: null,
165
- maxSize: null,
166
- serialize(value) {
167
- return new TextEncoder().encode(value);
168
- },
169
- deserialize(buffer, offset = 0) {
170
- const value = new TextDecoder().decode(buffer.slice(offset));
171
- return [removeNullCharacters(value), buffer.length];
172
- }
173
- };
174
-
175
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/common.mjs
141
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/common.mjs
176
142
  var Endian;
177
143
  (function(Endian2) {
178
144
  Endian2["Little"] = "le";
179
145
  Endian2["Big"] = "be";
180
146
  })(Endian || (Endian = {}));
181
147
 
182
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/errors.mjs
148
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/errors.mjs
183
149
  var NumberOutOfRangeError = class extends RangeError {
184
150
  constructor(serializer, min, max, actual) {
185
151
  super(`Serializer [${serializer}] expected number to be between ${min} and ${max}, got ${actual}.`);
@@ -187,7 +153,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
187
153
  }
188
154
  };
189
155
 
190
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/utils.mjs
156
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/utils.mjs
191
157
  function numberFactory(input) {
192
158
  let littleEndian;
193
159
  let defaultDescription = input.name;
@@ -231,17 +197,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
231
197
  }
232
198
  };
233
199
 
234
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u8.mjs
235
- var u8 = (options = {}) => numberFactory({
236
- name: "u8",
237
- size: 1,
238
- range: [0, Number("0xff")],
239
- set: (view, value) => view.setUint8(0, Number(value)),
240
- get: (view) => view.getUint8(0),
241
- options
242
- });
243
-
244
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u32.mjs
200
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u32.mjs
245
201
  var u32 = (options = {}) => numberFactory({
246
202
  name: "u32",
247
203
  size: 4,
@@ -251,7 +207,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
251
207
  options
252
208
  });
253
209
 
254
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/shortU16.mjs
210
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/shortU16.mjs
255
211
  var shortU16 = (options = {}) => ({
256
212
  description: options.description ?? "shortU16",
257
213
  fixedSize: null,
@@ -288,7 +244,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
288
244
  }
289
245
  });
290
246
 
291
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/errors.mjs
247
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/errors.mjs
292
248
  var InvalidNumberOfItemsError = class extends Error {
293
249
  constructor(serializer, expected, actual) {
294
250
  super(`Expected [${serializer}] to have ${expected} items, got ${actual}.`);
@@ -308,12 +264,12 @@ this.globalThis.solanaWeb3 = (function (exports) {
308
264
  }
309
265
  };
310
266
 
311
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/sumSerializerSizes.mjs
267
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/sumSerializerSizes.mjs
312
268
  function sumSerializerSizes(sizes) {
313
269
  return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
314
270
  }
315
271
 
316
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/utils.mjs
272
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/utils.mjs
317
273
  function getResolvedSize(size, childrenSizes, bytes2, offset) {
318
274
  if (typeof size === "number") {
319
275
  return [size, offset];
@@ -349,7 +305,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
349
305
  return typeof size === "object" ? size.serialize(realSize) : new Uint8Array();
350
306
  }
351
307
 
352
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/array.mjs
308
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/array.mjs
353
309
  function array(item, options = {}) {
354
310
  const size = options.size ?? u32();
355
311
  if (size === "remainder" && item.fixedSize === null) {
@@ -382,7 +338,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
382
338
  };
383
339
  }
384
340
 
385
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/bytes.mjs
341
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/bytes.mjs
386
342
  function bytes(options = {}) {
387
343
  const size = options.size ?? "variable";
388
344
  const description = options.description ?? `bytes(${getSizeDescription(size)})`;
@@ -429,48 +385,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
429
385
  };
430
386
  }
431
387
 
432
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/string.mjs
433
- function string(options = {}) {
434
- const size = options.size ?? u32();
435
- const encoding = options.encoding ?? utf8;
436
- const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
437
- if (size === "variable") {
438
- return {
439
- ...encoding,
440
- description
441
- };
442
- }
443
- if (typeof size === "number") {
444
- return fixSerializer(encoding, size, description);
445
- }
446
- return {
447
- description,
448
- fixedSize: null,
449
- maxSize: null,
450
- serialize: (value) => {
451
- const contentBytes = encoding.serialize(value);
452
- const lengthBytes = size.serialize(contentBytes.length);
453
- return mergeBytes([lengthBytes, contentBytes]);
454
- },
455
- deserialize: (buffer, offset = 0) => {
456
- if (buffer.slice(offset).length === 0) {
457
- throw new DeserializingEmptyBufferError("string");
458
- }
459
- const [lengthBigInt, lengthOffset] = size.deserialize(buffer, offset);
460
- const length = Number(lengthBigInt);
461
- offset = lengthOffset;
462
- const contentBuffer = buffer.slice(offset, offset + length);
463
- if (contentBuffer.length < length) {
464
- throw new NotEnoughBytesError("string", length, contentBuffer.length);
465
- }
466
- const [value, contentOffset] = encoding.deserialize(contentBuffer);
467
- offset += contentOffset;
468
- return [value, offset];
469
- }
470
- };
471
- }
472
-
473
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/struct.mjs
388
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/struct.mjs
474
389
  function struct(fields, options = {}) {
475
390
  const fieldDescriptions = fields.map(([name, serializer]) => `${String(name)}: ${serializer.description}`).join(", ");
476
391
  return {
@@ -522,9 +437,9 @@ this.globalThis.solanaWeb3 = (function (exports) {
522
437
  if (numBytes !== 32) {
523
438
  throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
524
439
  }
525
- } catch (e) {
440
+ } catch (e2) {
526
441
  throw new Error(`\`${putativeBlockhash}\` is not a blockhash`, {
527
- cause: e
442
+ cause: e2
528
443
  });
529
444
  }
530
445
  }
@@ -665,6 +580,327 @@ this.globalThis.solanaWeb3 = (function (exports) {
665
580
  return out;
666
581
  }
667
582
 
583
+ // ../codecs-core/dist/index.browser.js
584
+ function assertByteArrayIsNotEmptyForCodec(codecDescription, bytes2, offset = 0) {
585
+ if (bytes2.length - offset <= 0) {
586
+ throw new Error(`Codec [${codecDescription}] cannot decode empty byte arrays.`);
587
+ }
588
+ }
589
+ function assertByteArrayHasEnoughBytesForCodec(codecDescription, expected, bytes2, offset = 0) {
590
+ const bytesLength = bytes2.length - offset;
591
+ if (bytesLength < expected) {
592
+ throw new Error(`Codec [${codecDescription}] expected ${expected} bytes, got ${bytesLength}.`);
593
+ }
594
+ }
595
+ var mergeBytes2 = (byteArrays) => {
596
+ const nonEmptyByteArrays = byteArrays.filter((arr) => arr.length);
597
+ if (nonEmptyByteArrays.length === 0) {
598
+ return byteArrays.length ? byteArrays[0] : new Uint8Array();
599
+ }
600
+ if (nonEmptyByteArrays.length === 1) {
601
+ return nonEmptyByteArrays[0];
602
+ }
603
+ const totalLength = nonEmptyByteArrays.reduce((total, arr) => total + arr.length, 0);
604
+ const result = new Uint8Array(totalLength);
605
+ let offset = 0;
606
+ nonEmptyByteArrays.forEach((arr) => {
607
+ result.set(arr, offset);
608
+ offset += arr.length;
609
+ });
610
+ return result;
611
+ };
612
+ var padBytes2 = (bytes2, length) => {
613
+ if (bytes2.length >= length)
614
+ return bytes2;
615
+ const paddedBytes = new Uint8Array(length).fill(0);
616
+ paddedBytes.set(bytes2);
617
+ return paddedBytes;
618
+ };
619
+ var fixBytes2 = (bytes2, length) => padBytes2(bytes2.length <= length ? bytes2 : bytes2.slice(0, length), length);
620
+ function fixCodecHelper(data, fixedBytes, description) {
621
+ return {
622
+ description: description ?? `fixed(${fixedBytes}, ${data.description})`,
623
+ fixedSize: fixedBytes,
624
+ maxSize: fixedBytes
625
+ };
626
+ }
627
+ function fixEncoder(encoder, fixedBytes, description) {
628
+ return {
629
+ ...fixCodecHelper(encoder, fixedBytes, description),
630
+ encode: (value) => fixBytes2(encoder.encode(value), fixedBytes)
631
+ };
632
+ }
633
+ function fixDecoder(decoder, fixedBytes, description) {
634
+ return {
635
+ ...fixCodecHelper(decoder, fixedBytes, description),
636
+ decode: (bytes2, offset = 0) => {
637
+ assertByteArrayHasEnoughBytesForCodec("fixCodec", fixedBytes, bytes2, offset);
638
+ if (offset > 0 || bytes2.length > fixedBytes) {
639
+ bytes2 = bytes2.slice(offset, offset + fixedBytes);
640
+ }
641
+ if (decoder.fixedSize !== null) {
642
+ bytes2 = fixBytes2(bytes2, decoder.fixedSize);
643
+ }
644
+ const [value] = decoder.decode(bytes2, 0);
645
+ return [value, offset + fixedBytes];
646
+ }
647
+ };
648
+ }
649
+ function mapEncoder(encoder, unmap) {
650
+ return {
651
+ description: encoder.description,
652
+ encode: (value) => encoder.encode(unmap(value)),
653
+ fixedSize: encoder.fixedSize,
654
+ maxSize: encoder.maxSize
655
+ };
656
+ }
657
+
658
+ // ../codecs-numbers/dist/index.browser.js
659
+ function assertNumberIsBetweenForCodec(codecDescription, min, max, value) {
660
+ if (value < min || value > max) {
661
+ throw new Error(
662
+ `Codec [${codecDescription}] expected number to be in the range [${min}, ${max}], got ${value}.`
663
+ );
664
+ }
665
+ }
666
+ function sharedNumberFactory(input) {
667
+ let littleEndian;
668
+ let defaultDescription = input.name;
669
+ if (input.size > 1) {
670
+ littleEndian = !("endian" in input.options) || input.options.endian === 0;
671
+ defaultDescription += littleEndian ? "(le)" : "(be)";
672
+ }
673
+ return {
674
+ description: input.options.description ?? defaultDescription,
675
+ fixedSize: input.size,
676
+ littleEndian,
677
+ maxSize: input.size
678
+ };
679
+ }
680
+ function numberEncoderFactory(input) {
681
+ const codecData = sharedNumberFactory(input);
682
+ return {
683
+ description: codecData.description,
684
+ encode(value) {
685
+ if (input.range) {
686
+ assertNumberIsBetweenForCodec(input.name, input.range[0], input.range[1], value);
687
+ }
688
+ const arrayBuffer = new ArrayBuffer(input.size);
689
+ input.set(new DataView(arrayBuffer), value, codecData.littleEndian);
690
+ return new Uint8Array(arrayBuffer);
691
+ },
692
+ fixedSize: codecData.fixedSize,
693
+ maxSize: codecData.maxSize
694
+ };
695
+ }
696
+ function numberDecoderFactory(input) {
697
+ const codecData = sharedNumberFactory(input);
698
+ return {
699
+ decode(bytes2, offset = 0) {
700
+ assertByteArrayIsNotEmptyForCodec(codecData.description, bytes2, offset);
701
+ assertByteArrayHasEnoughBytesForCodec(codecData.description, input.size, bytes2, offset);
702
+ const view = new DataView(toArrayBuffer2(bytes2, offset, input.size));
703
+ return [input.get(view, codecData.littleEndian), offset + input.size];
704
+ },
705
+ description: codecData.description,
706
+ fixedSize: codecData.fixedSize,
707
+ maxSize: codecData.maxSize
708
+ };
709
+ }
710
+ function toArrayBuffer2(bytes2, offset, length) {
711
+ const bytesOffset = bytes2.byteOffset + (offset ?? 0);
712
+ const bytesLength = length ?? bytes2.byteLength;
713
+ return bytes2.buffer.slice(bytesOffset, bytesOffset + bytesLength);
714
+ }
715
+ var getShortU16Encoder = (options = {}) => ({
716
+ description: options.description ?? "shortU16",
717
+ encode: (value) => {
718
+ assertNumberIsBetweenForCodec("shortU16", 0, 65535, value);
719
+ const bytes2 = [0];
720
+ for (let ii = 0; ; ii += 1) {
721
+ const alignedValue = value >> ii * 7;
722
+ if (alignedValue === 0) {
723
+ break;
724
+ }
725
+ const nextSevenBits = 127 & alignedValue;
726
+ bytes2[ii] = nextSevenBits;
727
+ if (ii > 0) {
728
+ bytes2[ii - 1] |= 128;
729
+ }
730
+ }
731
+ return new Uint8Array(bytes2);
732
+ },
733
+ fixedSize: null,
734
+ maxSize: 3
735
+ });
736
+ var getU32Encoder = (options = {}) => numberEncoderFactory({
737
+ name: "u32",
738
+ options,
739
+ range: [0, Number("0xffffffff")],
740
+ set: (view, value, le) => view.setUint32(0, value, le),
741
+ size: 4
742
+ });
743
+ var getU32Decoder = (options = {}) => numberDecoderFactory({
744
+ get: (view, le) => view.getUint32(0, le),
745
+ name: "u32",
746
+ options,
747
+ size: 4
748
+ });
749
+ var getU8Encoder = (options = {}) => numberEncoderFactory({
750
+ name: "u8",
751
+ options,
752
+ range: [0, Number("0xff")],
753
+ set: (view, value) => view.setUint8(0, value),
754
+ size: 1
755
+ });
756
+
757
+ // ../codecs-strings/dist/index.browser.js
758
+ function assertValidBaseString(alphabet4, testValue, givenValue = testValue) {
759
+ if (!testValue.match(new RegExp(`^[${alphabet4}]*$`))) {
760
+ throw new Error(`Expected a string of base ${alphabet4.length}, got [${givenValue}].`);
761
+ }
762
+ }
763
+ var getBaseXEncoder = (alphabet4) => {
764
+ const base = alphabet4.length;
765
+ const baseBigInt = BigInt(base);
766
+ return {
767
+ description: `base${base}`,
768
+ encode(value) {
769
+ assertValidBaseString(alphabet4, value);
770
+ if (value === "")
771
+ return new Uint8Array();
772
+ const chars = [...value];
773
+ let trailIndex = chars.findIndex((c) => c !== alphabet4[0]);
774
+ trailIndex = trailIndex === -1 ? chars.length : trailIndex;
775
+ const leadingZeroes = Array(trailIndex).fill(0);
776
+ if (trailIndex === chars.length)
777
+ return Uint8Array.from(leadingZeroes);
778
+ const tailChars = chars.slice(trailIndex);
779
+ let base10Number = 0n;
780
+ let baseXPower = 1n;
781
+ for (let i = tailChars.length - 1; i >= 0; i -= 1) {
782
+ base10Number += baseXPower * BigInt(alphabet4.indexOf(tailChars[i]));
783
+ baseXPower *= baseBigInt;
784
+ }
785
+ const tailBytes = [];
786
+ while (base10Number > 0n) {
787
+ tailBytes.unshift(Number(base10Number % 256n));
788
+ base10Number /= 256n;
789
+ }
790
+ return Uint8Array.from(leadingZeroes.concat(tailBytes));
791
+ },
792
+ fixedSize: null,
793
+ maxSize: null
794
+ };
795
+ };
796
+ var getBaseXDecoder = (alphabet4) => {
797
+ const base = alphabet4.length;
798
+ const baseBigInt = BigInt(base);
799
+ return {
800
+ decode(rawBytes, offset = 0) {
801
+ const bytes2 = offset === 0 ? rawBytes : rawBytes.slice(offset);
802
+ if (bytes2.length === 0)
803
+ return ["", 0];
804
+ let trailIndex = bytes2.findIndex((n) => n !== 0);
805
+ trailIndex = trailIndex === -1 ? bytes2.length : trailIndex;
806
+ const leadingZeroes = alphabet4[0].repeat(trailIndex);
807
+ if (trailIndex === bytes2.length)
808
+ return [leadingZeroes, rawBytes.length];
809
+ let base10Number = bytes2.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
810
+ const tailChars = [];
811
+ while (base10Number > 0n) {
812
+ tailChars.unshift(alphabet4[Number(base10Number % baseBigInt)]);
813
+ base10Number /= baseBigInt;
814
+ }
815
+ return [leadingZeroes + tailChars.join(""), rawBytes.length];
816
+ },
817
+ description: `base${base}`,
818
+ fixedSize: null,
819
+ maxSize: null
820
+ };
821
+ };
822
+ var alphabet2 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
823
+ var getBase58Encoder = () => getBaseXEncoder(alphabet2);
824
+ var getBase58Decoder = () => getBaseXDecoder(alphabet2);
825
+ var removeNullCharacters = (value) => (
826
+ // eslint-disable-next-line no-control-regex
827
+ value.replace(/\u0000/g, "")
828
+ );
829
+ var e = globalThis.TextDecoder;
830
+ var o = globalThis.TextEncoder;
831
+ var getUtf8Encoder = () => {
832
+ let textEncoder;
833
+ return {
834
+ description: "utf8",
835
+ encode: (value) => new Uint8Array((textEncoder || (textEncoder = new o())).encode(value)),
836
+ fixedSize: null,
837
+ maxSize: null
838
+ };
839
+ };
840
+ var getUtf8Decoder = () => {
841
+ let textDecoder;
842
+ return {
843
+ decode(bytes2, offset = 0) {
844
+ const value = (textDecoder || (textDecoder = new e())).decode(bytes2.slice(offset));
845
+ return [removeNullCharacters(value), bytes2.length];
846
+ },
847
+ description: "utf8",
848
+ fixedSize: null,
849
+ maxSize: null
850
+ };
851
+ };
852
+ var getStringEncoder = (options = {}) => {
853
+ const size = options.size ?? getU32Encoder();
854
+ const encoding = options.encoding ?? getUtf8Encoder();
855
+ const description = options.description ?? `string(${encoding.description}; ${getSizeDescription2(size)})`;
856
+ if (size === "variable") {
857
+ return { ...encoding, description };
858
+ }
859
+ if (typeof size === "number") {
860
+ return fixEncoder(encoding, size, description);
861
+ }
862
+ return {
863
+ description,
864
+ encode: (value) => {
865
+ const contentBytes = encoding.encode(value);
866
+ const lengthBytes = size.encode(contentBytes.length);
867
+ return mergeBytes2([lengthBytes, contentBytes]);
868
+ },
869
+ fixedSize: null,
870
+ maxSize: null
871
+ };
872
+ };
873
+ var getStringDecoder = (options = {}) => {
874
+ const size = options.size ?? getU32Decoder();
875
+ const encoding = options.encoding ?? getUtf8Decoder();
876
+ const description = options.description ?? `string(${encoding.description}; ${getSizeDescription2(size)})`;
877
+ if (size === "variable") {
878
+ return { ...encoding, description };
879
+ }
880
+ if (typeof size === "number") {
881
+ return fixDecoder(encoding, size, description);
882
+ }
883
+ return {
884
+ decode: (bytes2, offset = 0) => {
885
+ assertByteArrayIsNotEmptyForCodec("string", bytes2, offset);
886
+ const [lengthBigInt, lengthOffset] = size.decode(bytes2, offset);
887
+ const length = Number(lengthBigInt);
888
+ offset = lengthOffset;
889
+ const contentBytes = bytes2.slice(offset, offset + length);
890
+ assertByteArrayHasEnoughBytesForCodec("string", length, contentBytes);
891
+ const [value, contentOffset] = encoding.decode(contentBytes);
892
+ offset += contentOffset;
893
+ return [value, offset];
894
+ },
895
+ description,
896
+ fixedSize: null,
897
+ maxSize: null
898
+ };
899
+ };
900
+ function getSizeDescription2(size) {
901
+ return typeof size === "object" ? size.description : `${size}`;
902
+ }
903
+
668
904
  // ../assertions/dist/index.browser.js
669
905
  function assertIsSecureContext() {
670
906
  if (!globalThis.isSecureContext) {
@@ -685,14 +921,63 @@ this.globalThis.solanaWeb3 = (function (exports) {
685
921
  throw new Error("No signing implementation could be found");
686
922
  }
687
923
  }
688
- function getBase58EncodedAddressCodec(config) {
689
- return string({
690
- description: config?.description ?? ("A 32-byte account address" ),
691
- encoding: base58,
924
+
925
+ // ../addresses/dist/index.browser.js
926
+ var memoizedBase58Encoder;
927
+ var memoizedBase58Decoder;
928
+ function getMemoizedBase58Encoder() {
929
+ if (!memoizedBase58Encoder)
930
+ memoizedBase58Encoder = getBase58Encoder();
931
+ return memoizedBase58Encoder;
932
+ }
933
+ function getMemoizedBase58Decoder() {
934
+ if (!memoizedBase58Decoder)
935
+ memoizedBase58Decoder = getBase58Decoder();
936
+ return memoizedBase58Decoder;
937
+ }
938
+ function assertIsAddress(putativeBase58EncodedAddress) {
939
+ try {
940
+ if (
941
+ // Lowest address (32 bytes of zeroes)
942
+ putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
943
+ putativeBase58EncodedAddress.length > 44
944
+ ) {
945
+ throw new Error("Expected input string to decode to a byte array of length 32.");
946
+ }
947
+ const base58Encoder = getMemoizedBase58Encoder();
948
+ const bytes2 = base58Encoder.encode(putativeBase58EncodedAddress);
949
+ const numBytes = bytes2.byteLength;
950
+ if (numBytes !== 32) {
951
+ throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
952
+ }
953
+ } catch (e2) {
954
+ throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
955
+ cause: e2
956
+ });
957
+ }
958
+ }
959
+ function address(putativeBase58EncodedAddress) {
960
+ assertIsAddress(putativeBase58EncodedAddress);
961
+ return putativeBase58EncodedAddress;
962
+ }
963
+ function getAddressEncoder(config) {
964
+ return mapEncoder(
965
+ getStringEncoder({
966
+ description: config?.description ?? "Base58EncodedAddress",
967
+ encoding: getMemoizedBase58Encoder(),
968
+ size: 32
969
+ }),
970
+ (putativeAddress) => address(putativeAddress)
971
+ );
972
+ }
973
+ function getAddressDecoder(config) {
974
+ return getStringDecoder({
975
+ description: config?.description ?? "Base58EncodedAddress",
976
+ encoding: getMemoizedBase58Decoder(),
692
977
  size: 32
693
978
  });
694
979
  }
695
- function getBase58EncodedAddressComparator() {
980
+ function getAddressComparator() {
696
981
  return new Intl.Collator("en", {
697
982
  caseFirst: "lower",
698
983
  ignorePunctuation: false,
@@ -702,26 +987,19 @@ this.globalThis.solanaWeb3 = (function (exports) {
702
987
  usage: "sort"
703
988
  }).compare;
704
989
  }
705
- async function getBase58EncodedAddressFromPublicKey(publicKey) {
990
+ async function getAddressFromPublicKey(publicKey) {
706
991
  await assertKeyExporterIsAvailable();
707
992
  if (publicKey.type !== "public" || publicKey.algorithm.name !== "Ed25519") {
708
993
  throw new Error("The `CryptoKey` must be an `Ed25519` public key");
709
994
  }
710
995
  const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
711
- const [base58EncodedAddress] = getBase58EncodedAddressCodec().deserialize(new Uint8Array(publicKeyBytes));
996
+ const [base58EncodedAddress] = getAddressDecoder().decode(new Uint8Array(publicKeyBytes));
712
997
  return base58EncodedAddress;
713
998
  }
714
999
 
715
- // ../keys/dist/index.browser.js
716
- async function signBytes(key, data) {
717
- await assertSigningCapabilityIsAvailable();
718
- const signedData = await crypto.subtle.sign("Ed25519", key, data);
719
- return new Uint8Array(signedData);
720
- }
721
-
722
1000
  // src/accounts.ts
723
- function upsert(addressMap, address, update) {
724
- addressMap[address] = update(addressMap[address] ?? { role: AccountRole.READONLY });
1001
+ function upsert(addressMap, address2, update) {
1002
+ addressMap[address2] = update(addressMap[address2] ?? { role: AccountRole.READONLY });
725
1003
  }
726
1004
  var TYPE = Symbol("AddressMapTypeProperty");
727
1005
  function getAddressMapFromInstructions(feePayer, instructions) {
@@ -772,7 +1050,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
772
1050
  const shouldReplaceEntry = (
773
1051
  // Consider using the new LOOKUP_TABLE if its address is different...
774
1052
  entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
775
- (addressComparator || (addressComparator = getBase58EncodedAddressComparator()))(
1053
+ (addressComparator || (addressComparator = getAddressComparator()))(
776
1054
  accountMeta.lookupTableAddress,
777
1055
  entry.lookupTableAddress
778
1056
  ) < 0
@@ -878,14 +1156,14 @@ this.globalThis.solanaWeb3 = (function (exports) {
878
1156
  if (leftIsWritable !== isWritableRole(rightEntry.role)) {
879
1157
  return leftIsWritable ? -1 : 1;
880
1158
  }
881
- addressComparator || (addressComparator = getBase58EncodedAddressComparator());
1159
+ addressComparator || (addressComparator = getAddressComparator());
882
1160
  if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
883
1161
  return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
884
1162
  } else {
885
1163
  return addressComparator(leftAddress, rightAddress);
886
1164
  }
887
- }).map(([address, addressMeta]) => ({
888
- address,
1165
+ }).map(([address2, addressMeta]) => ({
1166
+ address: address2,
889
1167
  ...addressMeta
890
1168
  }));
891
1169
  return orderedAccounts;
@@ -909,7 +1187,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
909
1187
  entry.readableIndices.push(account.addressIndex);
910
1188
  }
911
1189
  }
912
- return Object.keys(index).sort(getBase58EncodedAddressComparator()).map((lookupTableAddress) => ({
1190
+ return Object.keys(index).sort(getAddressComparator()).map((lookupTableAddress) => ({
913
1191
  lookupTableAddress,
914
1192
  ...index[lookupTableAddress]
915
1193
  }));
@@ -954,7 +1232,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
954
1232
  return instructions.map(({ accounts, data, programAddress }) => {
955
1233
  return {
956
1234
  programAddressIndex: accountIndex[programAddress],
957
- ...accounts ? { accountIndices: accounts.map(({ address }) => accountIndex[address]) } : null,
1235
+ ...accounts ? { accountIndices: accounts.map(({ address: address2 }) => accountIndex[address2]) } : null,
958
1236
  ...data ? { data } : null
959
1237
  };
960
1238
  });
@@ -972,7 +1250,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
972
1250
  function getCompiledStaticAccounts(orderedAccounts) {
973
1251
  const firstLookupTableAccountIndex = orderedAccounts.findIndex((account) => "lookupTableAddress" in account);
974
1252
  const orderedStaticAccounts = firstLookupTableAccountIndex === -1 ? orderedAccounts : orderedAccounts.slice(0, firstLookupTableAccountIndex);
975
- return orderedStaticAccounts.map(({ address }) => address);
1253
+ return orderedStaticAccounts.map(({ address: address2 }) => address2);
976
1254
  }
977
1255
 
978
1256
  // src/message.ts
@@ -989,145 +1267,209 @@ this.globalThis.solanaWeb3 = (function (exports) {
989
1267
  };
990
1268
  }
991
1269
 
1270
+ // src/compile-transaction.ts
1271
+ function getCompiledTransaction(transaction) {
1272
+ const compiledMessage = compileMessage(transaction);
1273
+ let signatures;
1274
+ if ("signatures" in transaction) {
1275
+ signatures = [];
1276
+ for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
1277
+ signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
1278
+ }
1279
+ } else {
1280
+ signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
1281
+ }
1282
+ return {
1283
+ compiledMessage,
1284
+ signatures
1285
+ };
1286
+ }
1287
+
1288
+ // ../codecs-data-structures/dist/index.browser.js
1289
+ function sumCodecSizes(sizes) {
1290
+ return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
1291
+ }
1292
+ function getArrayLikeCodecSizeDescription(size) {
1293
+ return typeof size === "object" ? size.description : `${size}`;
1294
+ }
1295
+ function getArrayLikeCodecSizeFromChildren(size, childrenSizes) {
1296
+ if (typeof size !== "number")
1297
+ return null;
1298
+ if (size === 0)
1299
+ return 0;
1300
+ const childrenSize = sumCodecSizes(childrenSizes);
1301
+ return childrenSize === null ? null : childrenSize * size;
1302
+ }
1303
+ function getArrayLikeCodecSizePrefix(size, realSize) {
1304
+ return typeof size === "object" ? size.encode(realSize) : new Uint8Array();
1305
+ }
1306
+ function assertValidNumberOfItemsForCodec(codecDescription, expected, actual) {
1307
+ if (expected !== actual) {
1308
+ throw new Error(`Expected [${codecDescription}] to have ${expected} items, got ${actual}.`);
1309
+ }
1310
+ }
1311
+ function arrayCodecHelper(item, size, description) {
1312
+ if (size === "remainder" && item.fixedSize === null) {
1313
+ throw new Error('Codecs of "remainder" size must have fixed-size items.');
1314
+ }
1315
+ return {
1316
+ description: description ?? `array(${item.description}; ${getArrayLikeCodecSizeDescription(size)})`,
1317
+ fixedSize: getArrayLikeCodecSizeFromChildren(size, [item.fixedSize]),
1318
+ maxSize: getArrayLikeCodecSizeFromChildren(size, [item.maxSize])
1319
+ };
1320
+ }
1321
+ function getArrayEncoder(item, options = {}) {
1322
+ const size = options.size ?? getU32Encoder();
1323
+ return {
1324
+ ...arrayCodecHelper(item, size, options.description),
1325
+ encode: (value) => {
1326
+ if (typeof size === "number") {
1327
+ assertValidNumberOfItemsForCodec("array", size, value.length);
1328
+ }
1329
+ return mergeBytes2([getArrayLikeCodecSizePrefix(size, value.length), ...value.map((v) => item.encode(v))]);
1330
+ }
1331
+ };
1332
+ }
1333
+ function getBytesEncoder(options = {}) {
1334
+ const size = options.size ?? "variable";
1335
+ const sizeDescription = typeof size === "object" ? size.description : `${size}`;
1336
+ const description = options.description ?? `bytes(${sizeDescription})`;
1337
+ const byteEncoder = {
1338
+ description,
1339
+ encode: (value) => value,
1340
+ fixedSize: null,
1341
+ maxSize: null
1342
+ };
1343
+ if (size === "variable") {
1344
+ return byteEncoder;
1345
+ }
1346
+ if (typeof size === "number") {
1347
+ return fixEncoder(byteEncoder, size, description);
1348
+ }
1349
+ return {
1350
+ ...byteEncoder,
1351
+ encode: (value) => {
1352
+ const contentBytes = byteEncoder.encode(value);
1353
+ const lengthBytes = size.encode(contentBytes.length);
1354
+ return mergeBytes2([lengthBytes, contentBytes]);
1355
+ }
1356
+ };
1357
+ }
1358
+ function structCodecHelper(fields, description) {
1359
+ const fieldDescriptions = fields.map(([name, codec]) => `${String(name)}: ${codec.description}`).join(", ");
1360
+ return {
1361
+ description: description ?? `struct(${fieldDescriptions})`,
1362
+ fixedSize: sumCodecSizes(fields.map(([, field]) => field.fixedSize)),
1363
+ maxSize: sumCodecSizes(fields.map(([, field]) => field.maxSize))
1364
+ };
1365
+ }
1366
+ function getStructEncoder(fields, options = {}) {
1367
+ return {
1368
+ ...structCodecHelper(fields, options.description),
1369
+ encode: (struct2) => {
1370
+ const fieldBytes = fields.map(([key, codec]) => codec.encode(struct2[key]));
1371
+ return mergeBytes2(fieldBytes);
1372
+ }
1373
+ };
1374
+ }
1375
+
992
1376
  // src/serializers/address-table-lookup.ts
993
- function getAddressTableLookupCodec() {
994
- return struct(
995
- [
996
- [
997
- "lookupTableAddress",
998
- getBase58EncodedAddressCodec(
999
- {
1000
- description: "The address of the address lookup table account from which instruction addresses should be looked up"
1001
- }
1002
- )
1003
- ],
1377
+ var lookupTableAddressDescription = "The address of the address lookup table account from which instruction addresses should be looked up" ;
1378
+ var writableIndicesDescription = "The indices of the accounts in the lookup table that should be loaded as writeable" ;
1379
+ var readableIndicesDescription = "The indices of the accounts in the lookup table that should be loaded as read-only" ;
1380
+ var addressTableLookupDescription = "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" ;
1381
+ var memoizedAddressTableLookupEncoder;
1382
+ function getAddressTableLookupEncoder() {
1383
+ if (!memoizedAddressTableLookupEncoder) {
1384
+ memoizedAddressTableLookupEncoder = getStructEncoder(
1004
1385
  [
1005
- "writableIndices",
1006
- array(u8(), {
1007
- ...{
1008
- description: "The indices of the accounts in the lookup table that should be loaded as writeable"
1009
- } ,
1010
- size: shortU16()
1011
- })
1386
+ ["lookupTableAddress", getAddressEncoder({ description: lookupTableAddressDescription })],
1387
+ [
1388
+ "writableIndices",
1389
+ getArrayEncoder(getU8Encoder(), {
1390
+ description: writableIndicesDescription,
1391
+ size: getShortU16Encoder()
1392
+ })
1393
+ ],
1394
+ [
1395
+ "readableIndices",
1396
+ getArrayEncoder(getU8Encoder(), {
1397
+ description: readableIndicesDescription,
1398
+ size: getShortU16Encoder()
1399
+ })
1400
+ ]
1012
1401
  ],
1013
- [
1014
- "readableIndices",
1015
- array(u8(), {
1016
- ...{
1017
- description: "The indices of the accounts in the lookup table that should be loaded as read-only"
1018
- } ,
1019
- size: shortU16()
1020
- })
1021
- ]
1022
- ],
1023
- {
1024
- 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"
1025
- }
1026
- );
1402
+ { description: addressTableLookupDescription }
1403
+ );
1404
+ }
1405
+ return memoizedAddressTableLookupEncoder;
1027
1406
  }
1028
1407
 
1029
1408
  // src/serializers/header.ts
1030
- function getMessageHeaderCodec() {
1031
- return struct(
1409
+ var memoizedU8Encoder;
1410
+ function getMemoizedU8Encoder() {
1411
+ if (!memoizedU8Encoder)
1412
+ memoizedU8Encoder = getU8Encoder();
1413
+ return memoizedU8Encoder;
1414
+ }
1415
+ function getMemoizedU8EncoderDescription(description) {
1416
+ const encoder = getMemoizedU8Encoder();
1417
+ return {
1418
+ ...encoder,
1419
+ description: description ?? encoder.description
1420
+ };
1421
+ }
1422
+ var numSignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction" ;
1423
+ var numReadonlySignerAccountsDescription = "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" ;
1424
+ var numReadonlyNonSignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable" ;
1425
+ var messageHeaderDescription = "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses" ;
1426
+ function getMessageHeaderEncoder() {
1427
+ return getStructEncoder(
1032
1428
  [
1033
- [
1034
- "numSignerAccounts",
1035
- u8(
1036
- {
1037
- description: "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction"
1038
- }
1039
- )
1040
- ],
1041
- [
1042
- "numReadonlySignerAccounts",
1043
- u8(
1044
- {
1045
- 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"
1046
- }
1047
- )
1048
- ],
1049
- [
1050
- "numReadonlyNonSignerAccounts",
1051
- u8(
1052
- {
1053
- description: "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable"
1054
- }
1055
- )
1056
- ]
1429
+ ["numSignerAccounts", getMemoizedU8EncoderDescription(numSignerAccountsDescription)],
1430
+ ["numReadonlySignerAccounts", getMemoizedU8EncoderDescription(numReadonlySignerAccountsDescription)],
1431
+ ["numReadonlyNonSignerAccounts", getMemoizedU8EncoderDescription(numReadonlyNonSignerAccountsDescription)]
1057
1432
  ],
1058
1433
  {
1059
- description: "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses"
1060
- }
1434
+ description: messageHeaderDescription
1435
+ }
1061
1436
  );
1062
1437
  }
1063
1438
 
1064
1439
  // src/serializers/instruction.ts
1065
- function getInstructionCodec() {
1066
- return mapSerializer(
1067
- struct([
1068
- [
1069
- "programAddressIndex",
1070
- u8(
1071
- {
1072
- description: "The index of the program being called, according to the well-ordered accounts list for this transaction"
1073
- }
1074
- )
1075
- ],
1076
- [
1077
- "addressIndices",
1078
- array(
1079
- u8({
1080
- description: "The index of an account, according to the well-ordered accounts list for this transaction"
1081
- }),
1082
- {
1083
- 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" ,
1084
- size: shortU16()
1085
- }
1086
- )
1087
- ],
1088
- [
1089
- "data",
1090
- bytes({
1091
- description: "An optional buffer of data passed to the instruction" ,
1092
- size: shortU16()
1093
- })
1094
- ]
1095
- ]),
1096
- (value) => {
1097
- if (value.addressIndices !== void 0 && value.data !== void 0) {
1098
- return value;
1099
- }
1100
- return {
1101
- ...value,
1102
- addressIndices: value.addressIndices ?? [],
1103
- data: value.data ?? new Uint8Array(0)
1104
- };
1105
- },
1106
- (value) => {
1107
- if (value.addressIndices.length && value.data.byteLength) {
1108
- return value;
1440
+ var programAddressIndexDescription = "The index of the program being called, according to the well-ordered accounts list for this transaction" ;
1441
+ var accountIndexDescription = "The index of an account, according to the well-ordered accounts list for this transaction" ;
1442
+ var accountIndicesDescription = "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" ;
1443
+ var dataDescription = "An optional buffer of data passed to the instruction" ;
1444
+ var memoizedGetInstructionEncoder;
1445
+ function getInstructionEncoder() {
1446
+ if (!memoizedGetInstructionEncoder) {
1447
+ memoizedGetInstructionEncoder = mapEncoder(
1448
+ getStructEncoder([
1449
+ ["programAddressIndex", getU8Encoder({ description: programAddressIndexDescription })],
1450
+ [
1451
+ "accountIndices",
1452
+ getArrayEncoder(getU8Encoder({ description: accountIndexDescription }), {
1453
+ description: accountIndicesDescription,
1454
+ size: getShortU16Encoder()
1455
+ })
1456
+ ],
1457
+ ["data", getBytesEncoder({ description: dataDescription, size: getShortU16Encoder() })]
1458
+ ]),
1459
+ // Convert an instruction to have all fields defined
1460
+ (instruction) => {
1461
+ if (instruction.accountIndices !== void 0 && instruction.data !== void 0) {
1462
+ return instruction;
1463
+ }
1464
+ return {
1465
+ ...instruction,
1466
+ accountIndices: instruction.accountIndices ?? [],
1467
+ data: instruction.data ?? new Uint8Array(0)
1468
+ };
1109
1469
  }
1110
- const { addressIndices, data, ...rest } = value;
1111
- return {
1112
- ...rest,
1113
- ...addressIndices.length ? { addressIndices } : null,
1114
- ...data.byteLength ? { data } : null
1115
- };
1116
- }
1117
- );
1118
- }
1119
-
1120
- // src/serializers/unimplemented.ts
1121
- function getError(type, name) {
1122
- const functionSuffix = name + type[0].toUpperCase() + type.slice(1);
1123
- return new Error(
1124
- `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}`
1125
- );
1126
- }
1127
- function getUnimplementedDecoder(name) {
1128
- return () => {
1129
- throw getError("decoder", name);
1130
- };
1470
+ );
1471
+ }
1472
+ return memoizedGetInstructionEncoder;
1131
1473
  }
1132
1474
 
1133
1475
  // src/serializers/transaction-version.ts
@@ -1137,16 +1479,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
1137
1479
  fixedSize: null,
1138
1480
  maxSize: 1
1139
1481
  };
1140
- function deserialize(bytes2, offset = 0) {
1141
- const firstByte = bytes2[offset];
1142
- if ((firstByte & VERSION_FLAG_MASK) === 0) {
1143
- return ["legacy", offset];
1144
- } else {
1145
- const version = firstByte ^ VERSION_FLAG_MASK;
1146
- return [version, offset + 1];
1147
- }
1148
- }
1149
- function serialize(value) {
1482
+ function encode(value) {
1150
1483
  if (value === "legacy") {
1151
1484
  return new Uint8Array();
1152
1485
  }
@@ -1155,132 +1488,117 @@ this.globalThis.solanaWeb3 = (function (exports) {
1155
1488
  }
1156
1489
  return new Uint8Array([value | VERSION_FLAG_MASK]);
1157
1490
  }
1158
- function getTransactionVersionCodec() {
1491
+ function getTransactionVersionEncoder() {
1159
1492
  return {
1160
1493
  ...BASE_CONFIG,
1161
- deserialize,
1162
- serialize
1494
+ encode
1163
1495
  };
1164
1496
  }
1165
1497
 
1166
1498
  // src/serializers/message.ts
1167
- var BASE_CONFIG2 = {
1168
- description: "The wire format of a Solana transaction message" ,
1169
- fixedSize: null,
1170
- maxSize: null
1171
- };
1172
- function serialize2(compiledMessage) {
1173
- if (compiledMessage.version === "legacy") {
1174
- return struct(getPreludeStructSerializerTuple()).serialize(compiledMessage);
1175
- } else {
1176
- return mapSerializer(
1177
- struct([
1178
- ...getPreludeStructSerializerTuple(),
1179
- ["addressTableLookups", getAddressTableLookupsSerializer()]
1180
- ]),
1181
- (value) => {
1182
- if (value.version === "legacy") {
1183
- return value;
1184
- }
1185
- return {
1186
- ...value,
1187
- addressTableLookups: value.addressTableLookups ?? []
1188
- };
1499
+ var staticAccountsDescription = "A compact-array of static account addresses belonging to this transaction" ;
1500
+ var lifetimeTokenDescription = "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" ;
1501
+ var instructionsDescription = "A compact-array of instructions belonging to this transaction" ;
1502
+ var addressTableLookupsDescription = "A compact array of address table lookups belonging to this transaction" ;
1503
+ function getCompiledMessageLegacyEncoder() {
1504
+ return getStructEncoder(getPreludeStructEncoderTuple());
1505
+ }
1506
+ function getCompiledMessageVersionedEncoder() {
1507
+ return mapEncoder(
1508
+ getStructEncoder([
1509
+ ...getPreludeStructEncoderTuple(),
1510
+ ["addressTableLookups", getAddressTableLookupArrayEncoder()]
1511
+ ]),
1512
+ (value) => {
1513
+ if (value.version === "legacy") {
1514
+ return value;
1189
1515
  }
1190
- ).serialize(compiledMessage);
1191
- }
1516
+ return {
1517
+ ...value,
1518
+ addressTableLookups: value.addressTableLookups ?? []
1519
+ };
1520
+ }
1521
+ );
1192
1522
  }
1193
- function getPreludeStructSerializerTuple() {
1523
+ function getPreludeStructEncoderTuple() {
1194
1524
  return [
1195
- ["version", getTransactionVersionCodec()],
1196
- ["header", getMessageHeaderCodec()],
1525
+ ["version", getTransactionVersionEncoder()],
1526
+ ["header", getMessageHeaderEncoder()],
1197
1527
  [
1198
1528
  "staticAccounts",
1199
- array(getBase58EncodedAddressCodec(), {
1200
- description: "A compact-array of static account addresses belonging to this transaction" ,
1201
- size: shortU16()
1529
+ getArrayEncoder(getAddressEncoder(), {
1530
+ description: staticAccountsDescription,
1531
+ size: getShortU16Encoder()
1202
1532
  })
1203
1533
  ],
1204
1534
  [
1205
1535
  "lifetimeToken",
1206
- string({
1207
- description: "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" ,
1208
- encoding: base58,
1536
+ getStringEncoder({
1537
+ description: lifetimeTokenDescription,
1538
+ encoding: getBase58Encoder(),
1209
1539
  size: 32
1210
1540
  })
1211
1541
  ],
1212
1542
  [
1213
1543
  "instructions",
1214
- array(getInstructionCodec(), {
1215
- description: "A compact-array of instructions belonging to this transaction" ,
1216
- size: shortU16()
1544
+ getArrayEncoder(getInstructionEncoder(), {
1545
+ description: instructionsDescription,
1546
+ size: getShortU16Encoder()
1217
1547
  })
1218
1548
  ]
1219
1549
  ];
1220
1550
  }
1221
- function getAddressTableLookupsSerializer() {
1222
- return array(getAddressTableLookupCodec(), {
1223
- ...{ description: "A compact array of address table lookups belonging to this transaction" } ,
1224
- size: shortU16()
1551
+ function getAddressTableLookupArrayEncoder() {
1552
+ return getArrayEncoder(getAddressTableLookupEncoder(), {
1553
+ description: addressTableLookupsDescription,
1554
+ size: getShortU16Encoder()
1225
1555
  });
1226
1556
  }
1557
+ var messageDescription = "The wire format of a Solana transaction message" ;
1227
1558
  function getCompiledMessageEncoder() {
1228
1559
  return {
1229
- ...BASE_CONFIG2,
1230
- deserialize: getUnimplementedDecoder("CompiledMessage"),
1231
- serialize: serialize2
1560
+ description: messageDescription,
1561
+ encode: (compiledMessage) => {
1562
+ if (compiledMessage.version === "legacy") {
1563
+ return getCompiledMessageLegacyEncoder().encode(compiledMessage);
1564
+ } else {
1565
+ return getCompiledMessageVersionedEncoder().encode(compiledMessage);
1566
+ }
1567
+ },
1568
+ fixedSize: null,
1569
+ maxSize: null
1232
1570
  };
1233
1571
  }
1234
1572
 
1235
- // src/signatures.ts
1236
- async function getCompiledMessageSignature(message, secretKey) {
1237
- const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
1238
- const signature = await signBytes(secretKey, wireMessageBytes);
1239
- return signature;
1240
- }
1241
- async function signTransaction(keyPair, transaction) {
1242
- const compiledMessage = compileMessage(transaction);
1243
- const [signerPublicKey, signature] = await Promise.all([
1244
- getBase58EncodedAddressFromPublicKey(keyPair.publicKey),
1245
- getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
1246
- ]);
1247
- const nextSignatures = {
1248
- ..."signatures" in transaction ? transaction.signatures : null,
1249
- ...{ [signerPublicKey]: signature }
1250
- };
1251
- const out = {
1252
- ...transaction,
1253
- signatures: nextSignatures
1254
- };
1255
- Object.freeze(out);
1256
- return out;
1573
+ // src/serializers/unimplemented.ts
1574
+ function getError(type, name) {
1575
+ const functionSuffix = name + type[0].toUpperCase() + type.slice(1);
1576
+ return new Error(
1577
+ `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}`
1578
+ );
1257
1579
  }
1258
-
1259
- // src/compile-transaction.ts
1260
- function getCompiledTransaction(transaction) {
1261
- const compiledMessage = compileMessage(transaction);
1262
- let signatures;
1263
- if ("signatures" in transaction) {
1264
- signatures = [];
1265
- for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
1266
- signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
1267
- }
1268
- } else {
1269
- signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
1270
- }
1271
- return {
1272
- compiledMessage,
1273
- signatures
1580
+ function getUnimplementedDecoder(name) {
1581
+ return () => {
1582
+ throw getError("decoder", name);
1274
1583
  };
1275
1584
  }
1276
1585
 
1277
1586
  // src/serializers/transaction.ts
1278
- var BASE_CONFIG3 = {
1587
+ var BASE_CONFIG2 = {
1279
1588
  description: "The wire format of a Solana transaction" ,
1280
1589
  fixedSize: null,
1281
1590
  maxSize: null
1282
1591
  };
1283
- function serialize3(transaction) {
1592
+ function toSerializer(encoder) {
1593
+ return {
1594
+ description: encoder.description,
1595
+ deserialize: getUnimplementedDecoder(encoder.description),
1596
+ fixedSize: encoder.fixedSize,
1597
+ maxSize: encoder.maxSize,
1598
+ serialize: encoder.encode
1599
+ };
1600
+ }
1601
+ function serialize(transaction) {
1284
1602
  const compiledTransaction = getCompiledTransaction(transaction);
1285
1603
  return struct([
1286
1604
  [
@@ -1290,15 +1608,99 @@ this.globalThis.solanaWeb3 = (function (exports) {
1290
1608
  size: shortU16()
1291
1609
  })
1292
1610
  ],
1293
- ["compiledMessage", getCompiledMessageEncoder()]
1611
+ ["compiledMessage", toSerializer(getCompiledMessageEncoder())]
1294
1612
  ]).serialize(compiledTransaction);
1295
1613
  }
1296
1614
  function getTransactionEncoder() {
1297
1615
  return {
1298
- ...BASE_CONFIG3,
1616
+ ...BASE_CONFIG2,
1299
1617
  deserialize: getUnimplementedDecoder("CompiledMessage"),
1300
- serialize: serialize3
1618
+ serialize
1619
+ };
1620
+ }
1621
+
1622
+ // ../keys/dist/index.browser.js
1623
+ async function signBytes(key, data) {
1624
+ await assertSigningCapabilityIsAvailable();
1625
+ const signedData = await crypto.subtle.sign("Ed25519", key, data);
1626
+ return new Uint8Array(signedData);
1627
+ }
1628
+
1629
+ // src/signatures.ts
1630
+ function assertIsTransactionSignature(putativeTransactionSignature) {
1631
+ try {
1632
+ if (
1633
+ // Lowest value (64 bytes of zeroes)
1634
+ putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
1635
+ putativeTransactionSignature.length > 88
1636
+ ) {
1637
+ throw new Error("Expected input string to decode to a byte array of length 64.");
1638
+ }
1639
+ const bytes2 = base58.serialize(putativeTransactionSignature);
1640
+ const numBytes = bytes2.byteLength;
1641
+ if (numBytes !== 64) {
1642
+ throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
1643
+ }
1644
+ } catch (e2) {
1645
+ throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
1646
+ cause: e2
1647
+ });
1648
+ }
1649
+ }
1650
+ function isTransactionSignature(putativeTransactionSignature) {
1651
+ if (
1652
+ // Lowest value (64 bytes of zeroes)
1653
+ putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
1654
+ putativeTransactionSignature.length > 88
1655
+ ) {
1656
+ return false;
1657
+ }
1658
+ const bytes2 = base58.serialize(putativeTransactionSignature);
1659
+ const numBytes = bytes2.byteLength;
1660
+ if (numBytes !== 64) {
1661
+ return false;
1662
+ }
1663
+ return true;
1664
+ }
1665
+ async function getCompiledMessageSignature(message, secretKey) {
1666
+ const wireMessageBytes = getCompiledMessageEncoder().encode(message);
1667
+ const signature = await signBytes(secretKey, wireMessageBytes);
1668
+ return signature;
1669
+ }
1670
+ function getSignatureFromTransaction(transaction) {
1671
+ const signatureBytes = transaction.signatures[transaction.feePayer];
1672
+ if (!signatureBytes) {
1673
+ throw new Error(
1674
+ "Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
1675
+ );
1676
+ }
1677
+ const transactionSignature2 = base58.deserialize(signatureBytes)[0];
1678
+ return transactionSignature2;
1679
+ }
1680
+ async function signTransaction(keyPairs, transaction) {
1681
+ const compiledMessage = compileMessage(transaction);
1682
+ const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
1683
+ const publicKeySignaturePairs = await Promise.all(
1684
+ keyPairs.map(
1685
+ (keyPair) => Promise.all([
1686
+ getAddressFromPublicKey(keyPair.publicKey),
1687
+ getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
1688
+ ])
1689
+ )
1690
+ );
1691
+ for (const [signerPublicKey, signature] of publicKeySignaturePairs) {
1692
+ nextSignatures[signerPublicKey] = signature;
1693
+ }
1694
+ const out = {
1695
+ ...transaction,
1696
+ signatures: nextSignatures
1301
1697
  };
1698
+ Object.freeze(out);
1699
+ return out;
1700
+ }
1701
+ function transactionSignature(putativeTransactionSignature) {
1702
+ assertIsTransactionSignature(putativeTransactionSignature);
1703
+ return putativeTransactionSignature;
1302
1704
  }
1303
1705
 
1304
1706
  // src/wire-transaction.ts
@@ -1312,13 +1714,19 @@ this.globalThis.solanaWeb3 = (function (exports) {
1312
1714
  exports.appendTransactionInstruction = appendTransactionInstruction;
1313
1715
  exports.assertIsBlockhash = assertIsBlockhash;
1314
1716
  exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
1717
+ exports.assertIsTransactionSignature = assertIsTransactionSignature;
1315
1718
  exports.createTransaction = createTransaction;
1316
1719
  exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
1720
+ exports.getSignatureFromTransaction = getSignatureFromTransaction;
1721
+ exports.getTransactionEncoder = getTransactionEncoder;
1722
+ exports.isAdvanceNonceAccountInstruction = isAdvanceNonceAccountInstruction;
1723
+ exports.isTransactionSignature = isTransactionSignature;
1317
1724
  exports.prependTransactionInstruction = prependTransactionInstruction;
1318
1725
  exports.setTransactionFeePayer = setTransactionFeePayer;
1319
1726
  exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
1320
1727
  exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
1321
1728
  exports.signTransaction = signTransaction;
1729
+ exports.transactionSignature = transactionSignature;
1322
1730
 
1323
1731
  return exports;
1324
1732