@solana/transactions 2.0.0-experimental.a9e6db3 → 2.0.0-experimental.ab12c29

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 (61) hide show
  1. package/README.md +272 -5
  2. package/dist/index.browser.cjs +496 -286
  3. package/dist/index.browser.cjs.map +1 -1
  4. package/dist/index.browser.js +491 -287
  5. package/dist/index.browser.js.map +1 -1
  6. package/dist/index.development.js +996 -1042
  7. package/dist/index.development.js.map +1 -1
  8. package/dist/index.native.js +491 -287
  9. package/dist/index.native.js.map +1 -1
  10. package/dist/index.node.cjs +496 -288
  11. package/dist/index.node.cjs.map +1 -1
  12. package/dist/index.node.js +491 -289
  13. package/dist/index.node.js.map +1 -1
  14. package/dist/index.production.min.js +22 -16
  15. package/dist/types/accounts.d.ts +2 -2
  16. package/dist/types/accounts.d.ts.map +1 -0
  17. package/dist/types/blockhash.d.ts.map +1 -0
  18. package/dist/types/compilable-transaction.d.ts +7 -0
  19. package/dist/types/compilable-transaction.d.ts.map +1 -0
  20. package/dist/types/compile-address-table-lookups.d.ts +2 -2
  21. package/dist/types/compile-address-table-lookups.d.ts.map +1 -0
  22. package/dist/types/compile-header.d.ts.map +1 -0
  23. package/dist/types/compile-instructions.d.ts.map +1 -0
  24. package/dist/types/compile-lifetime-token.d.ts.map +1 -0
  25. package/dist/types/compile-static-accounts.d.ts +2 -2
  26. package/dist/types/compile-static-accounts.d.ts.map +1 -0
  27. package/dist/types/compile-transaction.d.ts +5 -6
  28. package/dist/types/compile-transaction.d.ts.map +1 -0
  29. package/dist/types/create-transaction.d.ts.map +1 -0
  30. package/dist/types/decompile-transaction.d.ts +5 -0
  31. package/dist/types/decompile-transaction.d.ts.map +1 -0
  32. package/dist/types/durable-nonce.d.ts +6 -6
  33. package/dist/types/durable-nonce.d.ts.map +1 -0
  34. package/dist/types/fee-payer.d.ts +4 -4
  35. package/dist/types/fee-payer.d.ts.map +1 -0
  36. package/dist/types/index.d.ts +2 -0
  37. package/dist/types/index.d.ts.map +1 -0
  38. package/dist/types/instructions.d.ts.map +1 -0
  39. package/dist/types/message.d.ts +1 -5
  40. package/dist/types/message.d.ts.map +1 -0
  41. package/dist/types/serializers/address-table-lookup.d.ts +5 -3
  42. package/dist/types/serializers/address-table-lookup.d.ts.map +1 -0
  43. package/dist/types/serializers/header.d.ts.map +1 -0
  44. package/dist/types/serializers/index.d.ts +1 -0
  45. package/dist/types/serializers/index.d.ts.map +1 -0
  46. package/dist/types/serializers/instruction.d.ts +4 -2
  47. package/dist/types/serializers/instruction.d.ts.map +1 -0
  48. package/dist/types/serializers/message.d.ts +4 -4
  49. package/dist/types/serializers/message.d.ts.map +1 -0
  50. package/dist/types/serializers/transaction-version.d.ts.map +1 -0
  51. package/dist/types/serializers/transaction.d.ts +6 -5
  52. package/dist/types/serializers/transaction.d.ts.map +1 -0
  53. package/dist/types/signatures.d.ts +8 -12
  54. package/dist/types/signatures.d.ts.map +1 -0
  55. package/dist/types/types.d.ts +6 -13
  56. package/dist/types/types.d.ts.map +1 -0
  57. package/dist/types/unsigned-transaction.d.ts.map +1 -0
  58. package/dist/types/wire-transaction.d.ts +1 -1
  59. package/dist/types/wire-transaction.d.ts.map +1 -0
  60. package/package.json +14 -13
  61. package/dist/types/serializers/unimplemented.d.ts +0 -3
@@ -2,682 +2,19 @@ this.globalThis = this.globalThis || {};
2
2
  this.globalThis.solanaWeb3 = (function (exports) {
3
3
  'use strict';
4
4
 
5
- var __defProp = Object.defineProperty;
6
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
- var __publicField = (obj, key, value) => {
8
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
9
- return value;
10
- };
11
-
12
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/bytes.mjs
13
- var mergeBytes = (bytesArr) => {
14
- const totalLength = bytesArr.reduce((total, arr) => total + arr.length, 0);
15
- const result = new Uint8Array(totalLength);
16
- let offset = 0;
17
- bytesArr.forEach((arr) => {
18
- result.set(arr, offset);
19
- offset += arr.length;
20
- });
21
- return result;
22
- };
23
- var padBytes = (bytes2, length) => {
24
- if (bytes2.length >= length)
25
- return bytes2;
26
- const paddedBytes = new Uint8Array(length).fill(0);
27
- paddedBytes.set(bytes2);
28
- return paddedBytes;
29
- };
30
- var fixBytes = (bytes2, length) => padBytes(bytes2.slice(0, length), length);
31
-
32
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/errors.mjs
33
- var DeserializingEmptyBufferError = class extends Error {
34
- constructor(serializer) {
35
- super(`Serializer [${serializer}] cannot deserialize empty buffers.`);
36
- __publicField(this, "name", "DeserializingEmptyBufferError");
37
- }
38
- };
39
- var NotEnoughBytesError = class extends Error {
40
- constructor(serializer, expected, actual) {
41
- super(`Serializer [${serializer}] expected ${expected} bytes, got ${actual}.`);
42
- __publicField(this, "name", "NotEnoughBytesError");
43
- }
44
- };
45
- var ExpectedFixedSizeSerializerError = class extends Error {
46
- constructor(message) {
47
- message ?? (message = "Expected a fixed-size serializer, got a variable-size one.");
48
- super(message);
49
- __publicField(this, "name", "ExpectedFixedSizeSerializerError");
50
- }
51
- };
52
-
53
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/fixSerializer.mjs
54
- function fixSerializer(serializer, fixedBytes, description) {
55
- return {
56
- description: description ?? `fixed(${fixedBytes}, ${serializer.description})`,
57
- fixedSize: fixedBytes,
58
- maxSize: fixedBytes,
59
- serialize: (value) => fixBytes(serializer.serialize(value), fixedBytes),
60
- deserialize: (buffer, offset = 0) => {
61
- buffer = buffer.slice(offset, offset + fixedBytes);
62
- if (buffer.length < fixedBytes) {
63
- throw new NotEnoughBytesError("fixSerializer", fixedBytes, buffer.length);
64
- }
65
- if (serializer.fixedSize !== null) {
66
- buffer = fixBytes(buffer, serializer.fixedSize);
67
- }
68
- const [value] = serializer.deserialize(buffer, 0);
69
- return [value, offset + fixedBytes];
70
- }
71
- };
72
- }
73
-
74
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/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.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/errors.mjs
89
- var InvalidBaseStringError = class extends Error {
90
- constructor(value, base, cause) {
91
- const message = `Expected a string of base ${base}, got [${value}].`;
92
- super(message);
93
- __publicField(this, "name", "InvalidBaseStringError");
94
- this.cause = cause;
95
- }
96
- };
97
-
98
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseX.mjs
99
- var baseX = (alphabet) => {
100
- const base = alphabet.length;
101
- const baseBigInt = BigInt(base);
102
- return {
103
- description: `base${base}`,
104
- fixedSize: null,
105
- maxSize: null,
106
- serialize(value) {
107
- if (!value.match(new RegExp(`^[${alphabet}]*$`))) {
108
- throw new InvalidBaseStringError(value, base);
109
- }
110
- if (value === "")
111
- return new Uint8Array();
112
- const chars = [...value];
113
- let trailIndex = chars.findIndex((c) => c !== alphabet[0]);
114
- trailIndex = trailIndex === -1 ? chars.length : trailIndex;
115
- const leadingZeroes = Array(trailIndex).fill(0);
116
- if (trailIndex === chars.length)
117
- return Uint8Array.from(leadingZeroes);
118
- const tailChars = chars.slice(trailIndex);
119
- let base10Number = 0n;
120
- let baseXPower = 1n;
121
- for (let i = tailChars.length - 1; i >= 0; i -= 1) {
122
- base10Number += baseXPower * BigInt(alphabet.indexOf(tailChars[i]));
123
- baseXPower *= baseBigInt;
124
- }
125
- const tailBytes = [];
126
- while (base10Number > 0n) {
127
- tailBytes.unshift(Number(base10Number % 256n));
128
- base10Number /= 256n;
129
- }
130
- return Uint8Array.from(leadingZeroes.concat(tailBytes));
131
- },
132
- deserialize(buffer, offset = 0) {
133
- if (buffer.length === 0)
134
- return ["", 0];
135
- const bytes2 = buffer.slice(offset);
136
- let trailIndex = bytes2.findIndex((n) => n !== 0);
137
- trailIndex = trailIndex === -1 ? bytes2.length : trailIndex;
138
- const leadingZeroes = alphabet[0].repeat(trailIndex);
139
- if (trailIndex === bytes2.length)
140
- return [leadingZeroes, buffer.length];
141
- let base10Number = bytes2.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
142
- const tailChars = [];
143
- while (base10Number > 0n) {
144
- tailChars.unshift(alphabet[Number(base10Number % baseBigInt)]);
145
- base10Number /= baseBigInt;
146
- }
147
- return [leadingZeroes + tailChars.join(""), buffer.length];
148
- }
149
- };
150
- };
151
-
152
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/base58.mjs
153
- var base58 = baseX("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
154
-
155
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/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.9/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.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/common.mjs
176
- var Endian;
177
- (function(Endian2) {
178
- Endian2["Little"] = "le";
179
- Endian2["Big"] = "be";
180
- })(Endian || (Endian = {}));
181
-
182
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/errors.mjs
183
- var NumberOutOfRangeError = class extends RangeError {
184
- constructor(serializer, min, max, actual) {
185
- super(`Serializer [${serializer}] expected number to be between ${min} and ${max}, got ${actual}.`);
186
- __publicField(this, "name", "NumberOutOfRangeError");
187
- }
188
- };
189
-
190
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/utils.mjs
191
- function numberFactory(input) {
192
- let littleEndian;
193
- let defaultDescription = input.name;
194
- if (input.size > 1) {
195
- littleEndian = !("endian" in input.options) || input.options.endian === Endian.Little;
196
- defaultDescription += littleEndian ? "(le)" : "(be)";
197
- }
198
- return {
199
- description: input.options.description ?? defaultDescription,
200
- fixedSize: input.size,
201
- maxSize: input.size,
202
- serialize(value) {
203
- if (input.range) {
204
- assertRange(input.name, input.range[0], input.range[1], value);
205
- }
206
- const buffer = new ArrayBuffer(input.size);
207
- input.set(new DataView(buffer), value, littleEndian);
208
- return new Uint8Array(buffer);
209
- },
210
- deserialize(bytes2, offset = 0) {
211
- const slice = bytes2.slice(offset, offset + input.size);
212
- assertEnoughBytes("i8", slice, input.size);
213
- const view = toDataView(slice);
214
- return [input.get(view, littleEndian), offset + input.size];
215
- }
216
- };
217
- }
218
- var toArrayBuffer = (array2) => array2.buffer.slice(array2.byteOffset, array2.byteLength + array2.byteOffset);
219
- var toDataView = (array2) => new DataView(toArrayBuffer(array2));
220
- var assertRange = (serializer, min, max, value) => {
221
- if (value < min || value > max) {
222
- throw new NumberOutOfRangeError(serializer, min, max, value);
223
- }
224
- };
225
- var assertEnoughBytes = (serializer, bytes2, expected) => {
226
- if (bytes2.length === 0) {
227
- throw new DeserializingEmptyBufferError(serializer);
228
- }
229
- if (bytes2.length < expected) {
230
- throw new NotEnoughBytesError(serializer, expected, bytes2.length);
231
- }
232
- };
233
-
234
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/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.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u32.mjs
245
- var u32 = (options = {}) => numberFactory({
246
- name: "u32",
247
- size: 4,
248
- range: [0, Number("0xffffffff")],
249
- set: (view, value, le) => view.setUint32(0, Number(value), le),
250
- get: (view, le) => view.getUint32(0, le),
251
- options
252
- });
253
-
254
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/shortU16.mjs
255
- var shortU16 = (options = {}) => ({
256
- description: options.description ?? "shortU16",
257
- fixedSize: null,
258
- maxSize: 3,
259
- serialize: (value) => {
260
- assertRange("shortU16", 0, 65535, value);
261
- const bytes2 = [0];
262
- for (let ii = 0; ; ii += 1) {
263
- const alignedValue = value >> ii * 7;
264
- if (alignedValue === 0) {
265
- break;
266
- }
267
- const nextSevenBits = 127 & alignedValue;
268
- bytes2[ii] = nextSevenBits;
269
- if (ii > 0) {
270
- bytes2[ii - 1] |= 128;
271
- }
272
- }
273
- return new Uint8Array(bytes2);
274
- },
275
- deserialize: (bytes2, offset = 0) => {
276
- let value = 0;
277
- let byteCount = 0;
278
- while (++byteCount) {
279
- const byteIndex = byteCount - 1;
280
- const currentByte = bytes2[offset + byteIndex];
281
- const nextSevenBits = 127 & currentByte;
282
- value |= nextSevenBits << byteIndex * 7;
283
- if ((currentByte & 128) === 0) {
284
- break;
285
- }
286
- }
287
- return [value, offset + byteCount];
288
- }
289
- });
290
-
291
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/errors.mjs
292
- var InvalidNumberOfItemsError = class extends Error {
293
- constructor(serializer, expected, actual) {
294
- super(`Expected [${serializer}] to have ${expected} items, got ${actual}.`);
295
- __publicField(this, "name", "InvalidNumberOfItemsError");
296
- }
297
- };
298
- var InvalidArrayLikeRemainderSizeError = class extends Error {
299
- constructor(remainderSize, itemSize) {
300
- 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.`);
301
- __publicField(this, "name", "InvalidArrayLikeRemainderSizeError");
302
- }
303
- };
304
- var UnrecognizedArrayLikeSerializerSizeError = class extends Error {
305
- constructor(size) {
306
- super(`Unrecognized array-like serializer size: ${JSON.stringify(size)}`);
307
- __publicField(this, "name", "UnrecognizedArrayLikeSerializerSizeError");
308
- }
309
- };
310
-
311
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/sumSerializerSizes.mjs
312
- function sumSerializerSizes(sizes) {
313
- return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
314
- }
315
-
316
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/utils.mjs
317
- function getResolvedSize(size, childrenSizes, bytes2, offset) {
318
- if (typeof size === "number") {
319
- return [size, offset];
320
- }
321
- if (typeof size === "object") {
322
- return size.deserialize(bytes2, offset);
323
- }
324
- if (size === "remainder") {
325
- const childrenSize = sumSerializerSizes(childrenSizes);
326
- if (childrenSize === null) {
327
- throw new ExpectedFixedSizeSerializerError('Serializers of "remainder" size must have fixed-size items.');
328
- }
329
- const remainder = bytes2.slice(offset).length;
330
- if (remainder % childrenSize !== 0) {
331
- throw new InvalidArrayLikeRemainderSizeError(remainder, childrenSize);
332
- }
333
- return [remainder / childrenSize, offset];
334
- }
335
- throw new UnrecognizedArrayLikeSerializerSizeError(size);
336
- }
337
- function getSizeDescription(size) {
338
- return typeof size === "object" ? size.description : `${size}`;
339
- }
340
- function getSizeFromChildren(size, childrenSizes) {
341
- if (typeof size !== "number")
342
- return null;
343
- if (size === 0)
344
- return 0;
345
- const childrenSize = sumSerializerSizes(childrenSizes);
346
- return childrenSize === null ? null : childrenSize * size;
347
- }
348
- function getSizePrefix(size, realSize) {
349
- return typeof size === "object" ? size.serialize(realSize) : new Uint8Array();
350
- }
351
-
352
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/array.mjs
353
- function array(item, options = {}) {
354
- const size = options.size ?? u32();
355
- if (size === "remainder" && item.fixedSize === null) {
356
- throw new ExpectedFixedSizeSerializerError('Serializers of "remainder" size must have fixed-size items.');
357
- }
358
- return {
359
- description: options.description ?? `array(${item.description}; ${getSizeDescription(size)})`,
360
- fixedSize: getSizeFromChildren(size, [item.fixedSize]),
361
- maxSize: getSizeFromChildren(size, [item.maxSize]),
362
- serialize: (value) => {
363
- if (typeof size === "number" && value.length !== size) {
364
- throw new InvalidNumberOfItemsError("array", size, value.length);
365
- }
366
- return mergeBytes([getSizePrefix(size, value.length), ...value.map((v) => item.serialize(v))]);
367
- },
368
- deserialize: (bytes2, offset = 0) => {
369
- if (typeof size === "object" && bytes2.slice(offset).length === 0) {
370
- return [[], offset];
371
- }
372
- const [resolvedSize, newOffset] = getResolvedSize(size, [item.fixedSize], bytes2, offset);
373
- offset = newOffset;
374
- const values = [];
375
- for (let i = 0; i < resolvedSize; i += 1) {
376
- const [value, newOffset2] = item.deserialize(bytes2, offset);
377
- values.push(value);
378
- offset = newOffset2;
379
- }
380
- return [values, offset];
381
- }
382
- };
383
- }
384
-
385
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/bytes.mjs
386
- function bytes(options = {}) {
387
- const size = options.size ?? "variable";
388
- const description = options.description ?? `bytes(${getSizeDescription(size)})`;
389
- const byteSerializer = {
390
- description,
391
- fixedSize: null,
392
- maxSize: null,
393
- serialize: (value) => new Uint8Array(value),
394
- deserialize: (bytes2, offset = 0) => {
395
- const slice = bytes2.slice(offset);
396
- return [slice, offset + slice.length];
397
- }
398
- };
399
- if (size === "variable") {
400
- return byteSerializer;
401
- }
402
- if (typeof size === "number") {
403
- return fixSerializer(byteSerializer, size, description);
404
- }
405
- return {
406
- description,
407
- fixedSize: null,
408
- maxSize: null,
409
- serialize: (value) => {
410
- const contentBytes = byteSerializer.serialize(value);
411
- const lengthBytes = size.serialize(contentBytes.length);
412
- return mergeBytes([lengthBytes, contentBytes]);
413
- },
414
- deserialize: (buffer, offset = 0) => {
415
- if (buffer.slice(offset).length === 0) {
416
- throw new DeserializingEmptyBufferError("bytes");
417
- }
418
- const [lengthBigInt, lengthOffset] = size.deserialize(buffer, offset);
419
- const length = Number(lengthBigInt);
420
- offset = lengthOffset;
421
- const contentBuffer = buffer.slice(offset, offset + length);
422
- if (contentBuffer.length < length) {
423
- throw new NotEnoughBytesError("bytes", length, contentBuffer.length);
424
- }
425
- const [value, contentOffset] = byteSerializer.deserialize(contentBuffer);
426
- offset += contentOffset;
427
- return [value, offset];
428
- }
429
- };
430
- }
431
-
432
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/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.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/struct.mjs
474
- function struct(fields, options = {}) {
475
- const fieldDescriptions = fields.map(([name, serializer]) => `${String(name)}: ${serializer.description}`).join(", ");
476
- return {
477
- description: options.description ?? `struct(${fieldDescriptions})`,
478
- fixedSize: sumSerializerSizes(fields.map(([, field]) => field.fixedSize)),
479
- maxSize: sumSerializerSizes(fields.map(([, field]) => field.maxSize)),
480
- serialize: (struct2) => {
481
- const fieldBytes = fields.map(([key, serializer]) => serializer.serialize(struct2[key]));
482
- return mergeBytes(fieldBytes);
483
- },
484
- deserialize: (bytes2, offset = 0) => {
485
- const struct2 = {};
486
- fields.forEach(([key, serializer]) => {
487
- const [value, newOffset] = serializer.deserialize(bytes2, offset);
488
- offset = newOffset;
489
- struct2[key] = value;
490
- });
491
- return [struct2, offset];
492
- }
493
- };
494
- }
495
-
496
- // src/unsigned-transaction.ts
497
- function getUnsignedTransaction(transaction) {
498
- if ("signatures" in transaction) {
499
- const {
500
- signatures: _,
501
- // eslint-disable-line @typescript-eslint/no-unused-vars
502
- ...unsignedTransaction
503
- } = transaction;
504
- return unsignedTransaction;
505
- } else {
506
- return transaction;
507
- }
508
- }
509
-
510
- // src/blockhash.ts
511
- function assertIsBlockhash(putativeBlockhash) {
512
- try {
513
- if (
514
- // Lowest value (32 bytes of zeroes)
515
- putativeBlockhash.length < 32 || // Highest value (32 bytes of 255)
516
- putativeBlockhash.length > 44
517
- ) {
518
- throw new Error("Expected input string to decode to a byte array of length 32.");
519
- }
520
- const bytes2 = base58.serialize(putativeBlockhash);
521
- const numBytes = bytes2.byteLength;
522
- if (numBytes !== 32) {
523
- throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
524
- }
525
- } catch (e2) {
526
- throw new Error(`\`${putativeBlockhash}\` is not a blockhash`, {
527
- cause: e2
528
- });
529
- }
530
- }
531
- function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {
532
- if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
533
- return transaction;
534
- }
535
- const out = {
536
- ...getUnsignedTransaction(transaction),
537
- lifetimeConstraint: blockhashLifetimeConstraint
538
- };
539
- Object.freeze(out);
540
- return out;
541
- }
542
-
543
- // src/create-transaction.ts
544
- function createTransaction({
545
- version
546
- }) {
547
- const out = {
548
- instructions: [],
549
- version
550
- };
551
- Object.freeze(out);
552
- return out;
553
- }
554
-
555
- // ../instructions/dist/index.browser.js
556
- var AccountRole = /* @__PURE__ */ ((AccountRole2) => {
557
- AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */
558
- 3] = "WRITABLE_SIGNER";
559
- AccountRole2[AccountRole2["READONLY_SIGNER"] = /* 2 */
560
- 2] = "READONLY_SIGNER";
561
- AccountRole2[AccountRole2["WRITABLE"] = /* 1 */
562
- 1] = "WRITABLE";
563
- AccountRole2[AccountRole2["READONLY"] = /* 0 */
564
- 0] = "READONLY";
565
- return AccountRole2;
566
- })(AccountRole || {});
567
- var IS_WRITABLE_BITMASK = 1;
568
- function isSignerRole(role) {
569
- return role >= 2;
570
- }
571
- function isWritableRole(role) {
572
- return (role & IS_WRITABLE_BITMASK) !== 0;
573
- }
574
- function mergeRoles(roleA, roleB) {
575
- return roleA | roleB;
576
- }
577
-
578
- // src/durable-nonce.ts
579
- var RECENT_BLOCKHASHES_SYSVAR_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111";
580
- var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
581
- function assertIsDurableNonceTransaction(transaction) {
582
- if (!isDurableNonceTransaction(transaction)) {
583
- throw new Error("Transaction is not a durable nonce transaction");
584
- }
585
- }
586
- function createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress) {
587
- return {
588
- accounts: [
589
- { address: nonceAccountAddress, role: AccountRole.WRITABLE },
590
- {
591
- address: RECENT_BLOCKHASHES_SYSVAR_ADDRESS,
592
- role: AccountRole.READONLY
593
- },
594
- { address: nonceAuthorityAddress, role: AccountRole.READONLY_SIGNER }
595
- ],
596
- data: new Uint8Array([4, 0, 0, 0]),
597
- programAddress: SYSTEM_PROGRAM_ADDRESS
598
- };
599
- }
600
- function isAdvanceNonceAccountInstruction(instruction) {
601
- return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
602
- instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts
603
- instruction.accounts?.length === 3 && // First account is nonce account address
604
- instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole.WRITABLE && // Second account is recent blockhashes sysvar
605
- instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole.READONLY && // Third account is nonce authority account
606
- instruction.accounts[2].address != null && instruction.accounts[2].role === AccountRole.READONLY_SIGNER;
607
- }
608
- function isAdvanceNonceAccountInstructionData(data) {
609
- return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
610
- }
611
- function isDurableNonceTransaction(transaction) {
612
- return "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.nonce === "string" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]);
613
- }
614
- function setTransactionLifetimeUsingDurableNonce({
615
- nonce,
616
- nonceAccountAddress,
617
- nonceAuthorityAddress
618
- }, transaction) {
619
- const isAlreadyDurableNonceTransaction = isDurableNonceTransaction(transaction);
620
- if (isAlreadyDurableNonceTransaction && transaction.lifetimeConstraint.nonce === nonce && transaction.instructions[0].accounts[0].address === nonceAccountAddress && transaction.instructions[0].accounts[2].address === nonceAuthorityAddress) {
621
- return transaction;
622
- }
623
- const out = {
624
- ...getUnsignedTransaction(transaction),
625
- instructions: [
626
- createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
627
- ...isAlreadyDurableNonceTransaction ? transaction.instructions.slice(1) : transaction.instructions
628
- ],
629
- lifetimeConstraint: {
630
- nonce
631
- }
632
- };
633
- Object.freeze(out);
634
- return out;
635
- }
636
-
637
- // src/fee-payer.ts
638
- function setTransactionFeePayer(feePayer, transaction) {
639
- if ("feePayer" in transaction && feePayer === transaction.feePayer) {
640
- return transaction;
641
- }
642
- const out = {
643
- ...getUnsignedTransaction(transaction),
644
- feePayer
645
- };
646
- Object.freeze(out);
647
- return out;
648
- }
649
-
650
- // src/instructions.ts
651
- function appendTransactionInstruction(instruction, transaction) {
652
- const out = {
653
- ...getUnsignedTransaction(transaction),
654
- instructions: [...transaction.instructions, instruction]
655
- };
656
- Object.freeze(out);
657
- return out;
658
- }
659
- function prependTransactionInstruction(instruction, transaction) {
660
- const out = {
661
- ...getUnsignedTransaction(transaction),
662
- instructions: [instruction, ...transaction.instructions]
663
- };
664
- Object.freeze(out);
665
- return out;
666
- }
667
-
668
5
  // ../codecs-core/dist/index.browser.js
669
- function assertByteArrayIsNotEmptyForCodec(codecDescription, bytes2, offset = 0) {
670
- if (bytes2.length - offset <= 0) {
6
+ function assertByteArrayIsNotEmptyForCodec(codecDescription, bytes, offset = 0) {
7
+ if (bytes.length - offset <= 0) {
671
8
  throw new Error(`Codec [${codecDescription}] cannot decode empty byte arrays.`);
672
9
  }
673
10
  }
674
- function assertByteArrayHasEnoughBytesForCodec(codecDescription, expected, bytes2, offset = 0) {
675
- const bytesLength = bytes2.length - offset;
11
+ function assertByteArrayHasEnoughBytesForCodec(codecDescription, expected, bytes, offset = 0) {
12
+ const bytesLength = bytes.length - offset;
676
13
  if (bytesLength < expected) {
677
14
  throw new Error(`Codec [${codecDescription}] expected ${expected} bytes, got ${bytesLength}.`);
678
15
  }
679
16
  }
680
- var mergeBytes2 = (byteArrays) => {
17
+ var mergeBytes = (byteArrays) => {
681
18
  const nonEmptyByteArrays = byteArrays.filter((arr) => arr.length);
682
19
  if (nonEmptyByteArrays.length === 0) {
683
20
  return byteArrays.length ? byteArrays[0] : new Uint8Array();
@@ -694,14 +31,14 @@ this.globalThis.solanaWeb3 = (function (exports) {
694
31
  });
695
32
  return result;
696
33
  };
697
- var padBytes2 = (bytes2, length) => {
698
- if (bytes2.length >= length)
699
- return bytes2;
34
+ var padBytes = (bytes, length) => {
35
+ if (bytes.length >= length)
36
+ return bytes;
700
37
  const paddedBytes = new Uint8Array(length).fill(0);
701
- paddedBytes.set(bytes2);
38
+ paddedBytes.set(bytes);
702
39
  return paddedBytes;
703
40
  };
704
- var fixBytes2 = (bytes2, length) => padBytes2(bytes2.length <= length ? bytes2 : bytes2.slice(0, length), length);
41
+ var fixBytes = (bytes, length) => padBytes(bytes.length <= length ? bytes : bytes.slice(0, length), length);
705
42
  function combineCodec(encoder, decoder, description) {
706
43
  if (encoder.fixedSize !== decoder.fixedSize) {
707
44
  throw new Error(
@@ -720,7 +57,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
720
57
  }
721
58
  return {
722
59
  decode: decoder.decode,
723
- description: description ?? encoder.description,
60
+ description: description != null ? description : encoder.description,
724
61
  encode: encoder.encode,
725
62
  fixedSize: encoder.fixedSize,
726
63
  maxSize: encoder.maxSize
@@ -728,7 +65,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
728
65
  }
729
66
  function fixCodecHelper(data, fixedBytes, description) {
730
67
  return {
731
- description: description ?? `fixed(${fixedBytes}, ${data.description})`,
68
+ description: description != null ? description : `fixed(${fixedBytes}, ${data.description})`,
732
69
  fixedSize: fixedBytes,
733
70
  maxSize: fixedBytes
734
71
  };
@@ -736,21 +73,21 @@ this.globalThis.solanaWeb3 = (function (exports) {
736
73
  function fixEncoder(encoder, fixedBytes, description) {
737
74
  return {
738
75
  ...fixCodecHelper(encoder, fixedBytes, description),
739
- encode: (value) => fixBytes2(encoder.encode(value), fixedBytes)
76
+ encode: (value) => fixBytes(encoder.encode(value), fixedBytes)
740
77
  };
741
78
  }
742
79
  function fixDecoder(decoder, fixedBytes, description) {
743
80
  return {
744
81
  ...fixCodecHelper(decoder, fixedBytes, description),
745
- decode: (bytes2, offset = 0) => {
746
- assertByteArrayHasEnoughBytesForCodec("fixCodec", fixedBytes, bytes2, offset);
747
- if (offset > 0 || bytes2.length > fixedBytes) {
748
- bytes2 = bytes2.slice(offset, offset + fixedBytes);
82
+ decode: (bytes, offset = 0) => {
83
+ assertByteArrayHasEnoughBytesForCodec("fixCodec", fixedBytes, bytes, offset);
84
+ if (offset > 0 || bytes.length > fixedBytes) {
85
+ bytes = bytes.slice(offset, offset + fixedBytes);
749
86
  }
750
87
  if (decoder.fixedSize !== null) {
751
- bytes2 = fixBytes2(bytes2, decoder.fixedSize);
88
+ bytes = fixBytes(bytes, decoder.fixedSize);
752
89
  }
753
- const [value] = decoder.decode(bytes2, 0);
90
+ const [value] = decoder.decode(bytes, 0);
754
91
  return [value, offset + fixedBytes];
755
92
  }
756
93
  };
@@ -763,6 +100,17 @@ this.globalThis.solanaWeb3 = (function (exports) {
763
100
  maxSize: encoder.maxSize
764
101
  };
765
102
  }
103
+ function mapDecoder(decoder, map) {
104
+ return {
105
+ decode: (bytes, offset = 0) => {
106
+ const [value, length] = decoder.decode(bytes, offset);
107
+ return [map(value, bytes, offset), length];
108
+ },
109
+ description: decoder.description,
110
+ fixedSize: decoder.fixedSize,
111
+ maxSize: decoder.maxSize
112
+ };
113
+ }
766
114
 
767
115
  // ../codecs-numbers/dist/index.browser.js
768
116
  function assertNumberIsBetweenForCodec(codecDescription, min, max, value) {
@@ -773,14 +121,15 @@ this.globalThis.solanaWeb3 = (function (exports) {
773
121
  }
774
122
  }
775
123
  function sharedNumberFactory(input) {
124
+ var _a;
776
125
  let littleEndian;
777
126
  let defaultDescription = input.name;
778
127
  if (input.size > 1) {
779
- littleEndian = !("endian" in input.options) || input.options.endian === 0;
128
+ littleEndian = !("endian" in input.config) || input.config.endian === 0;
780
129
  defaultDescription += littleEndian ? "(le)" : "(be)";
781
130
  }
782
131
  return {
783
- description: input.options.description ?? defaultDescription,
132
+ description: (_a = input.config.description) != null ? _a : defaultDescription,
784
133
  fixedSize: input.size,
785
134
  littleEndian,
786
135
  maxSize: input.size
@@ -801,53 +150,98 @@ this.globalThis.solanaWeb3 = (function (exports) {
801
150
  fixedSize: codecData.fixedSize,
802
151
  maxSize: codecData.maxSize
803
152
  };
804
- }
805
- function numberDecoderFactory(input) {
806
- const codecData = sharedNumberFactory(input);
153
+ }
154
+ function numberDecoderFactory(input) {
155
+ const codecData = sharedNumberFactory(input);
156
+ return {
157
+ decode(bytes, offset = 0) {
158
+ assertByteArrayIsNotEmptyForCodec(codecData.description, bytes, offset);
159
+ assertByteArrayHasEnoughBytesForCodec(codecData.description, input.size, bytes, offset);
160
+ const view = new DataView(toArrayBuffer(bytes, offset, input.size));
161
+ return [input.get(view, codecData.littleEndian), offset + input.size];
162
+ },
163
+ description: codecData.description,
164
+ fixedSize: codecData.fixedSize,
165
+ maxSize: codecData.maxSize
166
+ };
167
+ }
168
+ function toArrayBuffer(bytes, offset, length) {
169
+ const bytesOffset = bytes.byteOffset + (offset != null ? offset : 0);
170
+ const bytesLength = length != null ? length : bytes.byteLength;
171
+ return bytes.buffer.slice(bytesOffset, bytesOffset + bytesLength);
172
+ }
173
+ var getShortU16Encoder = (config = {}) => {
174
+ var _a;
175
+ return {
176
+ description: (_a = config.description) != null ? _a : "shortU16",
177
+ encode: (value) => {
178
+ assertNumberIsBetweenForCodec("shortU16", 0, 65535, value);
179
+ const bytes = [0];
180
+ for (let ii = 0; ; ii += 1) {
181
+ const alignedValue = value >> ii * 7;
182
+ if (alignedValue === 0) {
183
+ break;
184
+ }
185
+ const nextSevenBits = 127 & alignedValue;
186
+ bytes[ii] = nextSevenBits;
187
+ if (ii > 0) {
188
+ bytes[ii - 1] |= 128;
189
+ }
190
+ }
191
+ return new Uint8Array(bytes);
192
+ },
193
+ fixedSize: null,
194
+ maxSize: 3
195
+ };
196
+ };
197
+ var getShortU16Decoder = (config = {}) => {
198
+ var _a;
807
199
  return {
808
- decode(bytes2, offset = 0) {
809
- assertByteArrayIsNotEmptyForCodec(codecData.description, bytes2, offset);
810
- assertByteArrayHasEnoughBytesForCodec(codecData.description, input.size, bytes2, offset);
811
- const view = new DataView(toArrayBuffer2(bytes2, offset, input.size));
812
- return [input.get(view, codecData.littleEndian), offset + input.size];
200
+ decode: (bytes, offset = 0) => {
201
+ let value = 0;
202
+ let byteCount = 0;
203
+ while (++byteCount) {
204
+ const byteIndex = byteCount - 1;
205
+ const currentByte = bytes[offset + byteIndex];
206
+ const nextSevenBits = 127 & currentByte;
207
+ value |= nextSevenBits << byteIndex * 7;
208
+ if ((currentByte & 128) === 0) {
209
+ break;
210
+ }
211
+ }
212
+ return [value, offset + byteCount];
813
213
  },
814
- description: codecData.description,
815
- fixedSize: codecData.fixedSize,
816
- maxSize: codecData.maxSize
214
+ description: (_a = config.description) != null ? _a : "shortU16",
215
+ fixedSize: null,
216
+ maxSize: 3
817
217
  };
818
- }
819
- function toArrayBuffer2(bytes2, offset, length) {
820
- const bytesOffset = bytes2.byteOffset + (offset ?? 0);
821
- const bytesLength = length ?? bytes2.byteLength;
822
- return bytes2.buffer.slice(bytesOffset, bytesOffset + bytesLength);
823
- }
824
- var getU32Encoder = (options = {}) => numberEncoderFactory({
218
+ };
219
+ var getU32Encoder = (config = {}) => numberEncoderFactory({
220
+ config,
825
221
  name: "u32",
826
- options,
827
222
  range: [0, Number("0xffffffff")],
828
223
  set: (view, value, le) => view.setUint32(0, value, le),
829
224
  size: 4
830
225
  });
831
- var getU32Decoder = (options = {}) => numberDecoderFactory({
226
+ var getU32Decoder = (config = {}) => numberDecoderFactory({
227
+ config,
832
228
  get: (view, le) => view.getUint32(0, le),
833
229
  name: "u32",
834
- options,
835
230
  size: 4
836
231
  });
837
- var getU8Encoder = (options = {}) => numberEncoderFactory({
232
+ var getU8Encoder = (config = {}) => numberEncoderFactory({
233
+ config,
838
234
  name: "u8",
839
- options,
840
235
  range: [0, Number("0xff")],
841
236
  set: (view, value) => view.setUint8(0, value),
842
237
  size: 1
843
238
  });
844
- var getU8Decoder = (options = {}) => numberDecoderFactory({
239
+ var getU8Decoder = (config = {}) => numberDecoderFactory({
240
+ config,
845
241
  get: (view) => view.getUint8(0),
846
242
  name: "u8",
847
- options,
848
243
  size: 1
849
244
  });
850
- var getU8Codec = (options = {}) => combineCodec(getU8Encoder(options), getU8Decoder(options));
851
245
 
852
246
  // ../codecs-strings/dist/index.browser.js
853
247
  function assertValidBaseString(alphabet4, testValue, givenValue = testValue) {
@@ -893,15 +287,15 @@ this.globalThis.solanaWeb3 = (function (exports) {
893
287
  const baseBigInt = BigInt(base);
894
288
  return {
895
289
  decode(rawBytes, offset = 0) {
896
- const bytes2 = offset === 0 ? rawBytes : rawBytes.slice(offset);
897
- if (bytes2.length === 0)
290
+ const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);
291
+ if (bytes.length === 0)
898
292
  return ["", 0];
899
- let trailIndex = bytes2.findIndex((n) => n !== 0);
900
- trailIndex = trailIndex === -1 ? bytes2.length : trailIndex;
293
+ let trailIndex = bytes.findIndex((n) => n !== 0);
294
+ trailIndex = trailIndex === -1 ? bytes.length : trailIndex;
901
295
  const leadingZeroes = alphabet4[0].repeat(trailIndex);
902
- if (trailIndex === bytes2.length)
296
+ if (trailIndex === bytes.length)
903
297
  return [leadingZeroes, rawBytes.length];
904
- let base10Number = bytes2.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
298
+ let base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
905
299
  const tailChars = [];
906
300
  while (base10Number > 0n) {
907
301
  tailChars.unshift(alphabet4[Number(base10Number % baseBigInt)]);
@@ -917,7 +311,21 @@ this.globalThis.solanaWeb3 = (function (exports) {
917
311
  var alphabet2 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
918
312
  var getBase58Encoder = () => getBaseXEncoder(alphabet2);
919
313
  var getBase58Decoder = () => getBaseXDecoder(alphabet2);
920
- var removeNullCharacters2 = (value) => (
314
+ var getBase64Decoder = () => {
315
+ {
316
+ return {
317
+ decode(bytes, offset = 0) {
318
+ const slice = bytes.slice(offset);
319
+ const value = btoa(String.fromCharCode(...slice));
320
+ return [value, bytes.length];
321
+ },
322
+ description: `base64`,
323
+ fixedSize: null,
324
+ maxSize: null
325
+ };
326
+ }
327
+ };
328
+ var removeNullCharacters = (value) => (
921
329
  // eslint-disable-next-line no-control-regex
922
330
  value.replace(/\u0000/g, "")
923
331
  );
@@ -935,19 +343,20 @@ this.globalThis.solanaWeb3 = (function (exports) {
935
343
  var getUtf8Decoder = () => {
936
344
  let textDecoder;
937
345
  return {
938
- decode(bytes2, offset = 0) {
939
- const value = (textDecoder || (textDecoder = new e())).decode(bytes2.slice(offset));
940
- return [removeNullCharacters2(value), bytes2.length];
346
+ decode(bytes, offset = 0) {
347
+ const value = (textDecoder || (textDecoder = new e())).decode(bytes.slice(offset));
348
+ return [removeNullCharacters(value), bytes.length];
941
349
  },
942
350
  description: "utf8",
943
351
  fixedSize: null,
944
352
  maxSize: null
945
353
  };
946
354
  };
947
- var getStringEncoder = (options = {}) => {
948
- const size = options.size ?? getU32Encoder();
949
- const encoding = options.encoding ?? getUtf8Encoder();
950
- const description = options.description ?? `string(${encoding.description}; ${getSizeDescription2(size)})`;
355
+ var getStringEncoder = (config = {}) => {
356
+ var _a, _b, _c;
357
+ const size = (_a = config.size) != null ? _a : getU32Encoder();
358
+ const encoding = (_b = config.encoding) != null ? _b : getUtf8Encoder();
359
+ const description = (_c = config.description) != null ? _c : `string(${encoding.description}; ${getSizeDescription(size)})`;
951
360
  if (size === "variable") {
952
361
  return { ...encoding, description };
953
362
  }
@@ -959,16 +368,17 @@ this.globalThis.solanaWeb3 = (function (exports) {
959
368
  encode: (value) => {
960
369
  const contentBytes = encoding.encode(value);
961
370
  const lengthBytes = size.encode(contentBytes.length);
962
- return mergeBytes2([lengthBytes, contentBytes]);
371
+ return mergeBytes([lengthBytes, contentBytes]);
963
372
  },
964
373
  fixedSize: null,
965
374
  maxSize: null
966
375
  };
967
376
  };
968
- var getStringDecoder = (options = {}) => {
969
- const size = options.size ?? getU32Decoder();
970
- const encoding = options.encoding ?? getUtf8Decoder();
971
- const description = options.description ?? `string(${encoding.description}; ${getSizeDescription2(size)})`;
377
+ var getStringDecoder = (config = {}) => {
378
+ var _a, _b, _c;
379
+ const size = (_a = config.size) != null ? _a : getU32Decoder();
380
+ const encoding = (_b = config.encoding) != null ? _b : getUtf8Decoder();
381
+ const description = (_c = config.description) != null ? _c : `string(${encoding.description}; ${getSizeDescription(size)})`;
972
382
  if (size === "variable") {
973
383
  return { ...encoding, description };
974
384
  }
@@ -976,12 +386,12 @@ this.globalThis.solanaWeb3 = (function (exports) {
976
386
  return fixDecoder(encoding, size, description);
977
387
  }
978
388
  return {
979
- decode: (bytes2, offset = 0) => {
980
- assertByteArrayIsNotEmptyForCodec("string", bytes2, offset);
981
- const [lengthBigInt, lengthOffset] = size.decode(bytes2, offset);
389
+ decode: (bytes, offset = 0) => {
390
+ assertByteArrayIsNotEmptyForCodec("string", bytes, offset);
391
+ const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);
982
392
  const length = Number(lengthBigInt);
983
393
  offset = lengthOffset;
984
- const contentBytes = bytes2.slice(offset, offset + length);
394
+ const contentBytes = bytes.slice(offset, offset + length);
985
395
  assertByteArrayHasEnoughBytesForCodec("string", length, contentBytes);
986
396
  const [value, contentOffset] = encoding.decode(contentBytes);
987
397
  offset += contentOffset;
@@ -992,10 +402,203 @@ this.globalThis.solanaWeb3 = (function (exports) {
992
402
  maxSize: null
993
403
  };
994
404
  };
995
- function getSizeDescription2(size) {
405
+ function getSizeDescription(size) {
996
406
  return typeof size === "object" ? size.description : `${size}`;
997
407
  }
998
408
 
409
+ // src/unsigned-transaction.ts
410
+ function getUnsignedTransaction(transaction) {
411
+ if ("signatures" in transaction) {
412
+ const {
413
+ signatures: _,
414
+ // eslint-disable-line @typescript-eslint/no-unused-vars
415
+ ...unsignedTransaction
416
+ } = transaction;
417
+ return unsignedTransaction;
418
+ } else {
419
+ return transaction;
420
+ }
421
+ }
422
+
423
+ // src/blockhash.ts
424
+ var base58Encoder;
425
+ function assertIsBlockhash(putativeBlockhash) {
426
+ if (!base58Encoder)
427
+ base58Encoder = getBase58Encoder();
428
+ try {
429
+ if (
430
+ // Lowest value (32 bytes of zeroes)
431
+ putativeBlockhash.length < 32 || // Highest value (32 bytes of 255)
432
+ putativeBlockhash.length > 44
433
+ ) {
434
+ throw new Error("Expected input string to decode to a byte array of length 32.");
435
+ }
436
+ const bytes = base58Encoder.encode(putativeBlockhash);
437
+ const numBytes = bytes.byteLength;
438
+ if (numBytes !== 32) {
439
+ throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
440
+ }
441
+ } catch (e2) {
442
+ throw new Error(`\`${putativeBlockhash}\` is not a blockhash`, {
443
+ cause: e2
444
+ });
445
+ }
446
+ }
447
+ function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {
448
+ if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
449
+ return transaction;
450
+ }
451
+ const out = {
452
+ ...getUnsignedTransaction(transaction),
453
+ lifetimeConstraint: blockhashLifetimeConstraint
454
+ };
455
+ Object.freeze(out);
456
+ return out;
457
+ }
458
+
459
+ // src/create-transaction.ts
460
+ function createTransaction({
461
+ version
462
+ }) {
463
+ const out = {
464
+ instructions: [],
465
+ version
466
+ };
467
+ Object.freeze(out);
468
+ return out;
469
+ }
470
+
471
+ // ../instructions/dist/index.browser.js
472
+ var AccountRole = /* @__PURE__ */ ((AccountRole2) => {
473
+ AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */
474
+ 3] = "WRITABLE_SIGNER";
475
+ AccountRole2[AccountRole2["READONLY_SIGNER"] = /* 2 */
476
+ 2] = "READONLY_SIGNER";
477
+ AccountRole2[AccountRole2["WRITABLE"] = /* 1 */
478
+ 1] = "WRITABLE";
479
+ AccountRole2[AccountRole2["READONLY"] = /* 0 */
480
+ 0] = "READONLY";
481
+ return AccountRole2;
482
+ })(AccountRole || {});
483
+ var IS_WRITABLE_BITMASK = 1;
484
+ function isSignerRole(role) {
485
+ return role >= 2;
486
+ }
487
+ function isWritableRole(role) {
488
+ return (role & IS_WRITABLE_BITMASK) !== 0;
489
+ }
490
+ function mergeRoles(roleA, roleB) {
491
+ return roleA | roleB;
492
+ }
493
+
494
+ // src/durable-nonce.ts
495
+ var RECENT_BLOCKHASHES_SYSVAR_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111";
496
+ var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
497
+ function assertIsDurableNonceTransaction(transaction) {
498
+ if (!isDurableNonceTransaction(transaction)) {
499
+ throw new Error("Transaction is not a durable nonce transaction");
500
+ }
501
+ }
502
+ function createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress) {
503
+ return {
504
+ accounts: [
505
+ { address: nonceAccountAddress, role: AccountRole.WRITABLE },
506
+ {
507
+ address: RECENT_BLOCKHASHES_SYSVAR_ADDRESS,
508
+ role: AccountRole.READONLY
509
+ },
510
+ { address: nonceAuthorityAddress, role: AccountRole.READONLY_SIGNER }
511
+ ],
512
+ data: new Uint8Array([4, 0, 0, 0]),
513
+ programAddress: SYSTEM_PROGRAM_ADDRESS
514
+ };
515
+ }
516
+ function isAdvanceNonceAccountInstruction(instruction) {
517
+ var _a;
518
+ return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
519
+ instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts
520
+ ((_a = instruction.accounts) == null ? void 0 : _a.length) === 3 && // First account is nonce account address
521
+ instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole.WRITABLE && // Second account is recent blockhashes sysvar
522
+ instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole.READONLY && // Third account is nonce authority account
523
+ instruction.accounts[2].address != null && isSignerRole(instruction.accounts[2].role);
524
+ }
525
+ function isAdvanceNonceAccountInstructionData(data) {
526
+ return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
527
+ }
528
+ function isDurableNonceTransaction(transaction) {
529
+ return "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.nonce === "string" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]);
530
+ }
531
+ function isAdvanceNonceAccountInstructionForNonce(instruction, nonceAccountAddress, nonceAuthorityAddress) {
532
+ return instruction.accounts[0].address === nonceAccountAddress && instruction.accounts[2].address === nonceAuthorityAddress;
533
+ }
534
+ function setTransactionLifetimeUsingDurableNonce({
535
+ nonce,
536
+ nonceAccountAddress,
537
+ nonceAuthorityAddress
538
+ }, transaction) {
539
+ let newInstructions;
540
+ const firstInstruction = transaction.instructions[0];
541
+ if (firstInstruction && isAdvanceNonceAccountInstruction(firstInstruction)) {
542
+ if (isAdvanceNonceAccountInstructionForNonce(firstInstruction, nonceAccountAddress, nonceAuthorityAddress)) {
543
+ if (isDurableNonceTransaction(transaction) && transaction.lifetimeConstraint.nonce === nonce) {
544
+ return transaction;
545
+ } else {
546
+ newInstructions = [firstInstruction, ...transaction.instructions.slice(1)];
547
+ }
548
+ } else {
549
+ newInstructions = [
550
+ createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
551
+ ...transaction.instructions.slice(1)
552
+ ];
553
+ }
554
+ } else {
555
+ newInstructions = [
556
+ createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
557
+ ...transaction.instructions
558
+ ];
559
+ }
560
+ const out = {
561
+ ...getUnsignedTransaction(transaction),
562
+ instructions: newInstructions,
563
+ lifetimeConstraint: {
564
+ nonce
565
+ }
566
+ };
567
+ Object.freeze(out);
568
+ return out;
569
+ }
570
+
571
+ // src/fee-payer.ts
572
+ function setTransactionFeePayer(feePayer, transaction) {
573
+ if ("feePayer" in transaction && feePayer === transaction.feePayer) {
574
+ return transaction;
575
+ }
576
+ const out = {
577
+ ...getUnsignedTransaction(transaction),
578
+ feePayer
579
+ };
580
+ Object.freeze(out);
581
+ return out;
582
+ }
583
+
584
+ // src/instructions.ts
585
+ function appendTransactionInstruction(instruction, transaction) {
586
+ const out = {
587
+ ...getUnsignedTransaction(transaction),
588
+ instructions: [...transaction.instructions, instruction]
589
+ };
590
+ Object.freeze(out);
591
+ return out;
592
+ }
593
+ function prependTransactionInstruction(instruction, transaction) {
594
+ const out = {
595
+ ...getUnsignedTransaction(transaction),
596
+ instructions: [instruction, ...transaction.instructions]
597
+ };
598
+ Object.freeze(out);
599
+ return out;
600
+ }
601
+
999
602
  // ../assertions/dist/index.browser.js
1000
603
  function assertIsSecureContext() {
1001
604
  if (!globalThis.isSecureContext) {
@@ -1005,14 +608,16 @@ this.globalThis.solanaWeb3 = (function (exports) {
1005
608
  }
1006
609
  }
1007
610
  async function assertKeyExporterIsAvailable() {
611
+ var _a;
1008
612
  assertIsSecureContext();
1009
- if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.exportKey !== "function") {
613
+ if (typeof globalThis.crypto === "undefined" || typeof ((_a = globalThis.crypto.subtle) == null ? void 0 : _a.exportKey) !== "function") {
1010
614
  throw new Error("No key export implementation could be found");
1011
615
  }
1012
616
  }
1013
617
  async function assertSigningCapabilityIsAvailable() {
618
+ var _a;
1014
619
  assertIsSecureContext();
1015
- if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.sign !== "function") {
620
+ if (typeof globalThis.crypto === "undefined" || typeof ((_a = globalThis.crypto.subtle) == null ? void 0 : _a.sign) !== "function") {
1016
621
  throw new Error("No signing implementation could be found");
1017
622
  }
1018
623
  }
@@ -1030,35 +635,36 @@ this.globalThis.solanaWeb3 = (function (exports) {
1030
635
  memoizedBase58Decoder = getBase58Decoder();
1031
636
  return memoizedBase58Decoder;
1032
637
  }
1033
- function assertIsAddress(putativeBase58EncodedAddress) {
638
+ function assertIsAddress(putativeAddress) {
1034
639
  try {
1035
640
  if (
1036
641
  // Lowest address (32 bytes of zeroes)
1037
- putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
1038
- putativeBase58EncodedAddress.length > 44
642
+ putativeAddress.length < 32 || // Highest address (32 bytes of 255)
643
+ putativeAddress.length > 44
1039
644
  ) {
1040
645
  throw new Error("Expected input string to decode to a byte array of length 32.");
1041
646
  }
1042
- const base58Encoder = getMemoizedBase58Encoder();
1043
- const bytes2 = base58Encoder.encode(putativeBase58EncodedAddress);
1044
- const numBytes = bytes2.byteLength;
647
+ const base58Encoder2 = getMemoizedBase58Encoder();
648
+ const bytes = base58Encoder2.encode(putativeAddress);
649
+ const numBytes = bytes.byteLength;
1045
650
  if (numBytes !== 32) {
1046
651
  throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
1047
652
  }
1048
653
  } catch (e2) {
1049
- throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
654
+ throw new Error(`\`${putativeAddress}\` is not a base-58 encoded address`, {
1050
655
  cause: e2
1051
656
  });
1052
657
  }
1053
658
  }
1054
- function address(putativeBase58EncodedAddress) {
1055
- assertIsAddress(putativeBase58EncodedAddress);
1056
- return putativeBase58EncodedAddress;
659
+ function address(putativeAddress) {
660
+ assertIsAddress(putativeAddress);
661
+ return putativeAddress;
1057
662
  }
1058
663
  function getAddressEncoder(config) {
664
+ var _a;
1059
665
  return mapEncoder(
1060
666
  getStringEncoder({
1061
- description: config?.description ?? "Base58EncodedAddress",
667
+ description: (_a = config == null ? void 0 : config.description) != null ? _a : "Address",
1062
668
  encoding: getMemoizedBase58Encoder(),
1063
669
  size: 32
1064
670
  }),
@@ -1066,15 +672,13 @@ this.globalThis.solanaWeb3 = (function (exports) {
1066
672
  );
1067
673
  }
1068
674
  function getAddressDecoder(config) {
675
+ var _a;
1069
676
  return getStringDecoder({
1070
- description: config?.description ?? "Base58EncodedAddress",
677
+ description: (_a = config == null ? void 0 : config.description) != null ? _a : "Address",
1071
678
  encoding: getMemoizedBase58Decoder(),
1072
679
  size: 32
1073
680
  });
1074
681
  }
1075
- function getAddressCodec(config) {
1076
- return combineCodec(getAddressEncoder(config), getAddressDecoder(config));
1077
- }
1078
682
  function getAddressComparator() {
1079
683
  return new Intl.Collator("en", {
1080
684
  caseFirst: "lower",
@@ -1097,7 +701,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
1097
701
 
1098
702
  // src/accounts.ts
1099
703
  function upsert(addressMap, address2, update) {
1100
- addressMap[address2] = update(addressMap[address2] ?? { role: AccountRole.READONLY });
704
+ var _a;
705
+ addressMap[address2] = update((_a = addressMap[address2]) != null ? _a : { role: AccountRole.READONLY });
1101
706
  }
1102
707
  var TYPE = Symbol("AddressMapTypeProperty");
1103
708
  function getAddressMapFromInstructions(feePayer, instructions) {
@@ -1365,134 +970,295 @@ this.globalThis.solanaWeb3 = (function (exports) {
1365
970
  };
1366
971
  }
1367
972
 
1368
- // src/compile-transaction.ts
1369
- function getCompiledTransaction(transaction) {
1370
- const compiledMessage = compileMessage(transaction);
1371
- let signatures;
1372
- if ("signatures" in transaction) {
1373
- signatures = [];
1374
- for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
1375
- signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
973
+ // ../codecs-data-structures/dist/index.browser.js
974
+ function sumCodecSizes(sizes) {
975
+ return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
976
+ }
977
+ function decodeArrayLikeCodecSize(size, childrenSizes, bytes, offset) {
978
+ if (typeof size === "number") {
979
+ return [size, offset];
980
+ }
981
+ if (typeof size === "object") {
982
+ return size.decode(bytes, offset);
983
+ }
984
+ if (size === "remainder") {
985
+ const childrenSize = sumCodecSizes(childrenSizes);
986
+ if (childrenSize === null) {
987
+ throw new Error('Codecs of "remainder" size must have fixed-size items.');
988
+ }
989
+ const remainder = bytes.slice(offset).length;
990
+ if (remainder % childrenSize !== 0) {
991
+ throw new Error(
992
+ `The remainder of the byte array (${remainder} bytes) cannot be split into chunks of ${childrenSize} bytes. Codecs of "remainder" size must have a remainder that is a multiple of its item size. In other words, ${remainder} modulo ${childrenSize} should be equal to zero.`
993
+ );
994
+ }
995
+ return [remainder / childrenSize, offset];
996
+ }
997
+ throw new Error(`Unrecognized array-like codec size: ${JSON.stringify(size)}`);
998
+ }
999
+ function getArrayLikeCodecSizeDescription(size) {
1000
+ return typeof size === "object" ? size.description : `${size}`;
1001
+ }
1002
+ function getArrayLikeCodecSizeFromChildren(size, childrenSizes) {
1003
+ if (typeof size !== "number")
1004
+ return null;
1005
+ if (size === 0)
1006
+ return 0;
1007
+ const childrenSize = sumCodecSizes(childrenSizes);
1008
+ return childrenSize === null ? null : childrenSize * size;
1009
+ }
1010
+ function getArrayLikeCodecSizePrefix(size, realSize) {
1011
+ return typeof size === "object" ? size.encode(realSize) : new Uint8Array();
1012
+ }
1013
+ function assertValidNumberOfItemsForCodec(codecDescription, expected, actual) {
1014
+ if (expected !== actual) {
1015
+ throw new Error(`Expected [${codecDescription}] to have ${expected} items, got ${actual}.`);
1016
+ }
1017
+ }
1018
+ function arrayCodecHelper(item, size, description) {
1019
+ if (size === "remainder" && item.fixedSize === null) {
1020
+ throw new Error('Codecs of "remainder" size must have fixed-size items.');
1021
+ }
1022
+ return {
1023
+ description: description != null ? description : `array(${item.description}; ${getArrayLikeCodecSizeDescription(size)})`,
1024
+ fixedSize: getArrayLikeCodecSizeFromChildren(size, [item.fixedSize]),
1025
+ maxSize: getArrayLikeCodecSizeFromChildren(size, [item.maxSize])
1026
+ };
1027
+ }
1028
+ function getArrayEncoder(item, config = {}) {
1029
+ var _a;
1030
+ const size = (_a = config.size) != null ? _a : getU32Encoder();
1031
+ return {
1032
+ ...arrayCodecHelper(item, size, config.description),
1033
+ encode: (value) => {
1034
+ if (typeof size === "number") {
1035
+ assertValidNumberOfItemsForCodec("array", size, value.length);
1036
+ }
1037
+ return mergeBytes([getArrayLikeCodecSizePrefix(size, value.length), ...value.map((v) => item.encode(v))]);
1038
+ }
1039
+ };
1040
+ }
1041
+ function getArrayDecoder(item, config = {}) {
1042
+ var _a;
1043
+ const size = (_a = config.size) != null ? _a : getU32Decoder();
1044
+ return {
1045
+ ...arrayCodecHelper(item, size, config.description),
1046
+ decode: (bytes, offset = 0) => {
1047
+ if (typeof size === "object" && bytes.slice(offset).length === 0) {
1048
+ return [[], offset];
1049
+ }
1050
+ const [resolvedSize, newOffset] = decodeArrayLikeCodecSize(size, [item.fixedSize], bytes, offset);
1051
+ offset = newOffset;
1052
+ const values = [];
1053
+ for (let i = 0; i < resolvedSize; i += 1) {
1054
+ const [value, newOffset2] = item.decode(bytes, offset);
1055
+ values.push(value);
1056
+ offset = newOffset2;
1057
+ }
1058
+ return [values, offset];
1376
1059
  }
1377
- } else {
1378
- signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
1060
+ };
1061
+ }
1062
+ function getBytesEncoder(config = {}) {
1063
+ var _a, _b;
1064
+ const size = (_a = config.size) != null ? _a : "variable";
1065
+ const sizeDescription = typeof size === "object" ? size.description : `${size}`;
1066
+ const description = (_b = config.description) != null ? _b : `bytes(${sizeDescription})`;
1067
+ const byteEncoder = {
1068
+ description,
1069
+ encode: (value) => value,
1070
+ fixedSize: null,
1071
+ maxSize: null
1072
+ };
1073
+ if (size === "variable") {
1074
+ return byteEncoder;
1075
+ }
1076
+ if (typeof size === "number") {
1077
+ return fixEncoder(byteEncoder, size, description);
1379
1078
  }
1380
1079
  return {
1381
- compiledMessage,
1382
- signatures
1080
+ ...byteEncoder,
1081
+ encode: (value) => {
1082
+ const contentBytes = byteEncoder.encode(value);
1083
+ const lengthBytes = size.encode(contentBytes.length);
1084
+ return mergeBytes([lengthBytes, contentBytes]);
1085
+ }
1383
1086
  };
1384
1087
  }
1385
-
1386
- // src/serializers/address-table-lookup.ts
1387
- function addressSerializerCompat(compat) {
1388
- const codec = getAddressCodec();
1088
+ function getBytesDecoder(config = {}) {
1089
+ var _a, _b;
1090
+ const size = (_a = config.size) != null ? _a : "variable";
1091
+ const sizeDescription = typeof size === "object" ? size.description : `${size}`;
1092
+ const description = (_b = config.description) != null ? _b : `bytes(${sizeDescription})`;
1093
+ const byteDecoder = {
1094
+ decode: (bytes, offset = 0) => {
1095
+ const slice = bytes.slice(offset);
1096
+ return [slice, offset + slice.length];
1097
+ },
1098
+ description,
1099
+ fixedSize: null,
1100
+ maxSize: null
1101
+ };
1102
+ if (size === "variable") {
1103
+ return byteDecoder;
1104
+ }
1105
+ if (typeof size === "number") {
1106
+ return fixDecoder(byteDecoder, size, description);
1107
+ }
1389
1108
  return {
1390
- description: compat?.description ?? codec.description,
1391
- deserialize: codec.decode,
1392
- fixedSize: codec.fixedSize,
1393
- maxSize: codec.maxSize,
1394
- serialize: codec.encode
1109
+ ...byteDecoder,
1110
+ decode: (bytes, offset = 0) => {
1111
+ assertByteArrayIsNotEmptyForCodec("bytes", bytes, offset);
1112
+ const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);
1113
+ const length = Number(lengthBigInt);
1114
+ offset = lengthOffset;
1115
+ const contentBytes = bytes.slice(offset, offset + length);
1116
+ assertByteArrayHasEnoughBytesForCodec("bytes", length, contentBytes);
1117
+ const [value, contentOffset] = byteDecoder.decode(contentBytes);
1118
+ offset += contentOffset;
1119
+ return [value, offset];
1120
+ }
1395
1121
  };
1396
1122
  }
1397
- function getAddressTableLookupCodec() {
1398
- return struct(
1399
- [
1400
- [
1401
- "lookupTableAddress",
1402
- addressSerializerCompat(
1403
- {
1404
- description: "The address of the address lookup table account from which instruction addresses should be looked up"
1405
- }
1406
- )
1407
- ],
1408
- [
1409
- "writableIndices",
1410
- array(u8(), {
1411
- ...{
1412
- description: "The indices of the accounts in the lookup table that should be loaded as writeable"
1413
- } ,
1414
- size: shortU16()
1415
- })
1416
- ],
1417
- [
1418
- "readableIndices",
1419
- array(u8(), {
1420
- ...{
1421
- description: "The indices of the accounts in the lookup table that should be loaded as read-only"
1422
- } ,
1423
- size: shortU16()
1424
- })
1425
- ]
1426
- ],
1427
- {
1428
- 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"
1429
- }
1430
- );
1431
- }
1432
-
1433
- // ../codecs-data-structures/dist/index.browser.js
1434
- function sumCodecSizes(sizes) {
1435
- return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
1436
- }
1437
1123
  function structCodecHelper(fields, description) {
1438
1124
  const fieldDescriptions = fields.map(([name, codec]) => `${String(name)}: ${codec.description}`).join(", ");
1439
1125
  return {
1440
- description: description ?? `struct(${fieldDescriptions})`,
1126
+ description: description != null ? description : `struct(${fieldDescriptions})`,
1441
1127
  fixedSize: sumCodecSizes(fields.map(([, field]) => field.fixedSize)),
1442
1128
  maxSize: sumCodecSizes(fields.map(([, field]) => field.maxSize))
1443
1129
  };
1444
1130
  }
1445
- function getStructEncoder(fields, options = {}) {
1131
+ function getStructEncoder(fields, config = {}) {
1446
1132
  return {
1447
- ...structCodecHelper(fields, options.description),
1448
- encode: (struct2) => {
1449
- const fieldBytes = fields.map(([key, codec]) => codec.encode(struct2[key]));
1450
- return mergeBytes2(fieldBytes);
1133
+ ...structCodecHelper(fields, config.description),
1134
+ encode: (struct) => {
1135
+ const fieldBytes = fields.map(([key, codec]) => codec.encode(struct[key]));
1136
+ return mergeBytes(fieldBytes);
1451
1137
  }
1452
1138
  };
1453
1139
  }
1454
- function getStructDecoder(fields, options = {}) {
1140
+ function getStructDecoder(fields, config = {}) {
1455
1141
  return {
1456
- ...structCodecHelper(fields, options.description),
1457
- decode: (bytes2, offset = 0) => {
1458
- const struct2 = {};
1142
+ ...structCodecHelper(fields, config.description),
1143
+ decode: (bytes, offset = 0) => {
1144
+ const struct = {};
1459
1145
  fields.forEach(([key, codec]) => {
1460
- const [value, newOffset] = codec.decode(bytes2, offset);
1146
+ const [value, newOffset] = codec.decode(bytes, offset);
1461
1147
  offset = newOffset;
1462
- struct2[key] = value;
1148
+ struct[key] = value;
1463
1149
  });
1464
- return [struct2, offset];
1150
+ return [struct, offset];
1465
1151
  }
1466
1152
  };
1467
1153
  }
1468
- function getStructCodec(fields, options = {}) {
1469
- return combineCodec(getStructEncoder(fields, options), getStructDecoder(fields, options));
1154
+
1155
+ // src/serializers/address-table-lookup.ts
1156
+ var lookupTableAddressDescription = "The address of the address lookup table account from which instruction addresses should be looked up" ;
1157
+ var writableIndicesDescription = "The indices of the accounts in the lookup table that should be loaded as writeable" ;
1158
+ var readableIndicesDescription = "The indices of the accounts in the lookup table that should be loaded as read-only" ;
1159
+ 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" ;
1160
+ var memoizedAddressTableLookupEncoder;
1161
+ function getAddressTableLookupEncoder() {
1162
+ if (!memoizedAddressTableLookupEncoder) {
1163
+ memoizedAddressTableLookupEncoder = getStructEncoder(
1164
+ [
1165
+ ["lookupTableAddress", getAddressEncoder({ description: lookupTableAddressDescription })],
1166
+ [
1167
+ "writableIndices",
1168
+ getArrayEncoder(getU8Encoder(), {
1169
+ description: writableIndicesDescription,
1170
+ size: getShortU16Encoder()
1171
+ })
1172
+ ],
1173
+ [
1174
+ "readableIndices",
1175
+ getArrayEncoder(getU8Encoder(), {
1176
+ description: readableIndicesDescription,
1177
+ size: getShortU16Encoder()
1178
+ })
1179
+ ]
1180
+ ],
1181
+ { description: addressTableLookupDescription }
1182
+ );
1183
+ }
1184
+ return memoizedAddressTableLookupEncoder;
1185
+ }
1186
+ var memoizedAddressTableLookupDecoder;
1187
+ function getAddressTableLookupDecoder() {
1188
+ if (!memoizedAddressTableLookupDecoder) {
1189
+ memoizedAddressTableLookupDecoder = getStructDecoder(
1190
+ [
1191
+ ["lookupTableAddress", getAddressDecoder({ description: lookupTableAddressDescription })],
1192
+ [
1193
+ "writableIndices",
1194
+ getArrayDecoder(getU8Decoder(), {
1195
+ description: writableIndicesDescription,
1196
+ size: getShortU16Decoder()
1197
+ })
1198
+ ],
1199
+ [
1200
+ "readableIndices",
1201
+ getArrayDecoder(getU8Decoder(), {
1202
+ description: readableIndicesDescription,
1203
+ size: getShortU16Decoder()
1204
+ })
1205
+ ]
1206
+ ],
1207
+ { description: addressTableLookupDescription }
1208
+ );
1209
+ }
1210
+ return memoizedAddressTableLookupDecoder;
1470
1211
  }
1471
1212
 
1472
1213
  // src/serializers/header.ts
1473
- var memoizedU8Codec;
1474
- function getMemoizedU8Codec() {
1475
- if (!memoizedU8Codec)
1476
- memoizedU8Codec = getU8Codec();
1477
- return memoizedU8Codec;
1478
- }
1479
- function getMemoizedU8CodecDescription(description) {
1480
- const codec = getMemoizedU8Codec();
1214
+ var memoizedU8Encoder;
1215
+ function getMemoizedU8Encoder() {
1216
+ if (!memoizedU8Encoder)
1217
+ memoizedU8Encoder = getU8Encoder();
1218
+ return memoizedU8Encoder;
1219
+ }
1220
+ function getMemoizedU8EncoderDescription(description) {
1221
+ const encoder = getMemoizedU8Encoder();
1222
+ return {
1223
+ ...encoder,
1224
+ description: description != null ? description : encoder.description
1225
+ };
1226
+ }
1227
+ var memoizedU8Decoder;
1228
+ function getMemoizedU8Decoder() {
1229
+ if (!memoizedU8Decoder)
1230
+ memoizedU8Decoder = getU8Decoder();
1231
+ return memoizedU8Decoder;
1232
+ }
1233
+ function getMemoizedU8DecoderDescription(description) {
1234
+ const decoder = getMemoizedU8Decoder();
1481
1235
  return {
1482
- ...codec,
1483
- description: description ?? codec.description
1236
+ ...decoder,
1237
+ description: description != null ? description : decoder.description
1484
1238
  };
1485
1239
  }
1486
1240
  var numSignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction" ;
1487
1241
  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" ;
1488
1242
  var numReadonlyNonSignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable" ;
1489
1243
  var messageHeaderDescription = "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses" ;
1490
- function getMessageHeaderCodec() {
1491
- return getStructCodec(
1244
+ function getMessageHeaderEncoder() {
1245
+ return getStructEncoder(
1246
+ [
1247
+ ["numSignerAccounts", getMemoizedU8EncoderDescription(numSignerAccountsDescription)],
1248
+ ["numReadonlySignerAccounts", getMemoizedU8EncoderDescription(numReadonlySignerAccountsDescription)],
1249
+ ["numReadonlyNonSignerAccounts", getMemoizedU8EncoderDescription(numReadonlyNonSignerAccountsDescription)]
1250
+ ],
1251
+ {
1252
+ description: messageHeaderDescription
1253
+ }
1254
+ );
1255
+ }
1256
+ function getMessageHeaderDecoder() {
1257
+ return getStructDecoder(
1492
1258
  [
1493
- ["numSignerAccounts", getMemoizedU8CodecDescription(numSignerAccountsDescription)],
1494
- ["numReadonlySignerAccounts", getMemoizedU8CodecDescription(numReadonlySignerAccountsDescription)],
1495
- ["numReadonlyNonSignerAccounts", getMemoizedU8CodecDescription(numReadonlyNonSignerAccountsDescription)]
1259
+ ["numSignerAccounts", getMemoizedU8DecoderDescription(numSignerAccountsDescription)],
1260
+ ["numReadonlySignerAccounts", getMemoizedU8DecoderDescription(numReadonlySignerAccountsDescription)],
1261
+ ["numReadonlyNonSignerAccounts", getMemoizedU8DecoderDescription(numReadonlyNonSignerAccountsDescription)]
1496
1262
  ],
1497
1263
  {
1498
1264
  description: messageHeaderDescription
@@ -1501,59 +1267,71 @@ this.globalThis.solanaWeb3 = (function (exports) {
1501
1267
  }
1502
1268
 
1503
1269
  // src/serializers/instruction.ts
1504
- function getInstructionCodec() {
1505
- return mapSerializer(
1506
- struct([
1507
- [
1508
- "programAddressIndex",
1509
- u8(
1510
- {
1511
- description: "The index of the program being called, according to the well-ordered accounts list for this transaction"
1512
- }
1513
- )
1514
- ],
1515
- [
1516
- "accountIndices",
1517
- array(
1518
- u8({
1519
- description: "The index of an account, according to the well-ordered accounts list for this transaction"
1520
- }),
1521
- {
1522
- 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" ,
1523
- size: shortU16()
1524
- }
1525
- )
1526
- ],
1527
- [
1528
- "data",
1529
- bytes({
1530
- description: "An optional buffer of data passed to the instruction" ,
1531
- size: shortU16()
1532
- })
1533
- ]
1534
- ]),
1535
- (value) => {
1536
- if (value.accountIndices !== void 0 && value.data !== void 0) {
1537
- return value;
1270
+ var programAddressIndexDescription = "The index of the program being called, according to the well-ordered accounts list for this transaction" ;
1271
+ var accountIndexDescription = "The index of an account, according to the well-ordered accounts list for this transaction" ;
1272
+ 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" ;
1273
+ var dataDescription = "An optional buffer of data passed to the instruction" ;
1274
+ var memoizedGetInstructionEncoder;
1275
+ function getInstructionEncoder() {
1276
+ if (!memoizedGetInstructionEncoder) {
1277
+ memoizedGetInstructionEncoder = mapEncoder(
1278
+ getStructEncoder([
1279
+ ["programAddressIndex", getU8Encoder({ description: programAddressIndexDescription })],
1280
+ [
1281
+ "accountIndices",
1282
+ getArrayEncoder(getU8Encoder({ description: accountIndexDescription }), {
1283
+ description: accountIndicesDescription,
1284
+ size: getShortU16Encoder()
1285
+ })
1286
+ ],
1287
+ ["data", getBytesEncoder({ description: dataDescription, size: getShortU16Encoder() })]
1288
+ ]),
1289
+ // Convert an instruction to have all fields defined
1290
+ (instruction) => {
1291
+ var _a, _b;
1292
+ if (instruction.accountIndices !== void 0 && instruction.data !== void 0) {
1293
+ return instruction;
1294
+ }
1295
+ return {
1296
+ ...instruction,
1297
+ accountIndices: (_a = instruction.accountIndices) != null ? _a : [],
1298
+ data: (_b = instruction.data) != null ? _b : new Uint8Array(0)
1299
+ };
1538
1300
  }
1539
- return {
1540
- ...value,
1541
- accountIndices: value.accountIndices ?? [],
1542
- data: value.data ?? new Uint8Array(0)
1543
- };
1544
- },
1545
- (value) => {
1546
- if (value.accountIndices.length && value.data.byteLength) {
1547
- return value;
1301
+ );
1302
+ }
1303
+ return memoizedGetInstructionEncoder;
1304
+ }
1305
+ var memoizedGetInstructionDecoder;
1306
+ function getInstructionDecoder() {
1307
+ if (!memoizedGetInstructionDecoder) {
1308
+ memoizedGetInstructionDecoder = mapDecoder(
1309
+ getStructDecoder([
1310
+ ["programAddressIndex", getU8Decoder({ description: programAddressIndexDescription })],
1311
+ [
1312
+ "accountIndices",
1313
+ getArrayDecoder(getU8Decoder({ description: accountIndexDescription }), {
1314
+ description: accountIndicesDescription,
1315
+ size: getShortU16Decoder()
1316
+ })
1317
+ ],
1318
+ ["data", getBytesDecoder({ description: dataDescription, size: getShortU16Decoder() })]
1319
+ ]),
1320
+ // Convert an instruction to exclude optional fields if they are empty
1321
+ (instruction) => {
1322
+ if (instruction.accountIndices.length && instruction.data.byteLength) {
1323
+ return instruction;
1324
+ }
1325
+ const { accountIndices, data, ...rest } = instruction;
1326
+ return {
1327
+ ...rest,
1328
+ ...accountIndices.length ? { accountIndices } : null,
1329
+ ...data.byteLength ? { data } : null
1330
+ };
1548
1331
  }
1549
- const { accountIndices, data, ...rest } = value;
1550
- return {
1551
- ...rest,
1552
- ...accountIndices.length ? { accountIndices } : null,
1553
- ...data.byteLength ? { data } : null
1554
- };
1555
- }
1556
- );
1332
+ );
1333
+ }
1334
+ return memoizedGetInstructionDecoder;
1557
1335
  }
1558
1336
 
1559
1337
  // src/serializers/transaction-version.ts
@@ -1563,8 +1341,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
1563
1341
  fixedSize: null,
1564
1342
  maxSize: 1
1565
1343
  };
1566
- function decode(bytes2, offset = 0) {
1567
- const firstByte = bytes2[offset];
1344
+ function decode(bytes, offset = 0) {
1345
+ const firstByte = bytes[offset];
1568
1346
  if ((firstByte & VERSION_FLAG_MASK) === 0) {
1569
1347
  return ["legacy", offset];
1570
1348
  } else {
@@ -1593,126 +1371,322 @@ this.globalThis.solanaWeb3 = (function (exports) {
1593
1371
  encode
1594
1372
  };
1595
1373
  }
1596
- function getTransactionVersionCodec() {
1597
- return combineCodec(getTransactionVersionEncoder(), getTransactionVersionDecoder());
1598
- }
1599
-
1600
- // src/serializers/unimplemented.ts
1601
- function getError(type, name) {
1602
- const functionSuffix = name + type[0].toUpperCase() + type.slice(1);
1603
- return new Error(
1604
- `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}`
1605
- );
1606
- }
1607
- function getUnimplementedDecoder(name) {
1608
- return () => {
1609
- throw getError("decoder", name);
1610
- };
1611
- }
1612
1374
 
1613
1375
  // src/serializers/message.ts
1614
- var BASE_CONFIG2 = {
1615
- description: "The wire format of a Solana transaction message" ,
1616
- fixedSize: null,
1617
- maxSize: null
1618
- };
1619
- function serialize(compiledMessage) {
1620
- if (compiledMessage.version === "legacy") {
1621
- return struct(getPreludeStructSerializerTuple()).serialize(compiledMessage);
1622
- } else {
1623
- return mapSerializer(
1624
- struct([
1625
- ...getPreludeStructSerializerTuple(),
1626
- ["addressTableLookups", getAddressTableLookupsSerializer()]
1627
- ]),
1628
- (value) => {
1629
- if (value.version === "legacy") {
1630
- return value;
1631
- }
1632
- return {
1633
- ...value,
1634
- addressTableLookups: value.addressTableLookups ?? []
1635
- };
1376
+ var staticAccountsDescription = "A compact-array of static account addresses belonging to this transaction" ;
1377
+ var lifetimeTokenDescription = "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" ;
1378
+ var instructionsDescription = "A compact-array of instructions belonging to this transaction" ;
1379
+ var addressTableLookupsDescription = "A compact array of address table lookups belonging to this transaction" ;
1380
+ function getCompiledMessageLegacyEncoder() {
1381
+ return getStructEncoder(getPreludeStructEncoderTuple());
1382
+ }
1383
+ function getCompiledMessageVersionedEncoder() {
1384
+ return mapEncoder(
1385
+ getStructEncoder([
1386
+ ...getPreludeStructEncoderTuple(),
1387
+ ["addressTableLookups", getAddressTableLookupArrayEncoder()]
1388
+ ]),
1389
+ (value) => {
1390
+ var _a;
1391
+ if (value.version === "legacy") {
1392
+ return value;
1636
1393
  }
1637
- ).serialize(compiledMessage);
1638
- }
1639
- }
1640
- function toSerializer(codec) {
1641
- return {
1642
- description: codec.description,
1643
- deserialize: codec.decode,
1644
- fixedSize: codec.fixedSize,
1645
- maxSize: codec.maxSize,
1646
- serialize: codec.encode
1647
- };
1394
+ return {
1395
+ ...value,
1396
+ addressTableLookups: (_a = value.addressTableLookups) != null ? _a : []
1397
+ };
1398
+ }
1399
+ );
1648
1400
  }
1649
- function getPreludeStructSerializerTuple() {
1401
+ function getPreludeStructEncoderTuple() {
1650
1402
  return [
1651
- ["version", toSerializer(getTransactionVersionCodec())],
1652
- ["header", toSerializer(getMessageHeaderCodec())],
1403
+ ["version", getTransactionVersionEncoder()],
1404
+ ["header", getMessageHeaderEncoder()],
1653
1405
  [
1654
1406
  "staticAccounts",
1655
- array(toSerializer(getAddressCodec()), {
1656
- description: "A compact-array of static account addresses belonging to this transaction" ,
1657
- size: shortU16()
1407
+ getArrayEncoder(getAddressEncoder(), {
1408
+ description: staticAccountsDescription,
1409
+ size: getShortU16Encoder()
1658
1410
  })
1659
1411
  ],
1660
1412
  [
1661
1413
  "lifetimeToken",
1662
- string({
1663
- description: "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" ,
1664
- encoding: base58,
1414
+ getStringEncoder({
1415
+ description: lifetimeTokenDescription,
1416
+ encoding: getBase58Encoder(),
1665
1417
  size: 32
1666
1418
  })
1667
1419
  ],
1668
1420
  [
1669
1421
  "instructions",
1670
- array(getInstructionCodec(), {
1671
- description: "A compact-array of instructions belonging to this transaction" ,
1672
- size: shortU16()
1422
+ getArrayEncoder(getInstructionEncoder(), {
1423
+ description: instructionsDescription,
1424
+ size: getShortU16Encoder()
1673
1425
  })
1674
1426
  ]
1675
1427
  ];
1676
1428
  }
1677
- function getAddressTableLookupsSerializer() {
1678
- return array(getAddressTableLookupCodec(), {
1679
- ...{ description: "A compact array of address table lookups belonging to this transaction" } ,
1680
- size: shortU16()
1429
+ function getPreludeStructDecoderTuple() {
1430
+ return [
1431
+ ["version", getTransactionVersionDecoder()],
1432
+ ["header", getMessageHeaderDecoder()],
1433
+ [
1434
+ "staticAccounts",
1435
+ getArrayDecoder(getAddressDecoder(), {
1436
+ description: staticAccountsDescription,
1437
+ size: getShortU16Decoder()
1438
+ })
1439
+ ],
1440
+ [
1441
+ "lifetimeToken",
1442
+ getStringDecoder({
1443
+ description: lifetimeTokenDescription,
1444
+ encoding: getBase58Decoder(),
1445
+ size: 32
1446
+ })
1447
+ ],
1448
+ [
1449
+ "instructions",
1450
+ getArrayDecoder(getInstructionDecoder(), {
1451
+ description: instructionsDescription,
1452
+ size: getShortU16Decoder()
1453
+ })
1454
+ ],
1455
+ ["addressTableLookups", getAddressTableLookupArrayDecoder()]
1456
+ ];
1457
+ }
1458
+ function getAddressTableLookupArrayEncoder() {
1459
+ return getArrayEncoder(getAddressTableLookupEncoder(), {
1460
+ description: addressTableLookupsDescription,
1461
+ size: getShortU16Encoder()
1462
+ });
1463
+ }
1464
+ function getAddressTableLookupArrayDecoder() {
1465
+ return getArrayDecoder(getAddressTableLookupDecoder(), {
1466
+ description: addressTableLookupsDescription,
1467
+ size: getShortU16Decoder()
1681
1468
  });
1682
1469
  }
1470
+ var messageDescription = "The wire format of a Solana transaction message" ;
1683
1471
  function getCompiledMessageEncoder() {
1684
1472
  return {
1685
- ...BASE_CONFIG2,
1686
- deserialize: getUnimplementedDecoder("CompiledMessage"),
1687
- serialize
1473
+ description: messageDescription,
1474
+ encode: (compiledMessage) => {
1475
+ if (compiledMessage.version === "legacy") {
1476
+ return getCompiledMessageLegacyEncoder().encode(compiledMessage);
1477
+ } else {
1478
+ return getCompiledMessageVersionedEncoder().encode(compiledMessage);
1479
+ }
1480
+ },
1481
+ fixedSize: null,
1482
+ maxSize: null
1483
+ };
1484
+ }
1485
+ function getCompiledMessageDecoder() {
1486
+ return mapDecoder(
1487
+ getStructDecoder(getPreludeStructDecoderTuple(), {
1488
+ description: messageDescription
1489
+ }),
1490
+ ({ addressTableLookups, ...restOfMessage }) => {
1491
+ if (restOfMessage.version === "legacy" || !(addressTableLookups == null ? void 0 : addressTableLookups.length)) {
1492
+ return restOfMessage;
1493
+ }
1494
+ return { ...restOfMessage, addressTableLookups };
1495
+ }
1496
+ );
1497
+ }
1498
+ function getCompiledMessageCodec() {
1499
+ return combineCodec(getCompiledMessageEncoder(), getCompiledMessageDecoder());
1500
+ }
1501
+
1502
+ // src/compile-transaction.ts
1503
+ function getCompiledTransaction(transaction) {
1504
+ var _a;
1505
+ const compiledMessage = compileMessage(transaction);
1506
+ let signatures;
1507
+ if ("signatures" in transaction) {
1508
+ signatures = [];
1509
+ for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
1510
+ signatures[ii] = (_a = transaction.signatures[compiledMessage.staticAccounts[ii]]) != null ? _a : new Uint8Array(Array(64).fill(0));
1511
+ }
1512
+ } else {
1513
+ signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
1514
+ }
1515
+ return {
1516
+ compiledMessage,
1517
+ signatures
1518
+ };
1519
+ }
1520
+
1521
+ // ../functional/dist/index.browser.js
1522
+ function pipe(init, ...fns) {
1523
+ return fns.reduce((acc, fn) => fn(acc), init);
1524
+ }
1525
+
1526
+ // src/decompile-transaction.ts
1527
+ function getAccountMetas(message) {
1528
+ const { header } = message;
1529
+ const numWritableSignerAccounts = header.numSignerAccounts - header.numReadonlySignerAccounts;
1530
+ const numWritableNonSignerAccounts = message.staticAccounts.length - header.numSignerAccounts - header.numReadonlyNonSignerAccounts;
1531
+ const accountMetas = [];
1532
+ let accountIndex = 0;
1533
+ for (let i = 0; i < numWritableSignerAccounts; i++) {
1534
+ accountMetas.push({
1535
+ address: message.staticAccounts[accountIndex],
1536
+ role: AccountRole.WRITABLE_SIGNER
1537
+ });
1538
+ accountIndex++;
1539
+ }
1540
+ for (let i = 0; i < header.numReadonlySignerAccounts; i++) {
1541
+ accountMetas.push({
1542
+ address: message.staticAccounts[accountIndex],
1543
+ role: AccountRole.READONLY_SIGNER
1544
+ });
1545
+ accountIndex++;
1546
+ }
1547
+ for (let i = 0; i < numWritableNonSignerAccounts; i++) {
1548
+ accountMetas.push({
1549
+ address: message.staticAccounts[accountIndex],
1550
+ role: AccountRole.WRITABLE
1551
+ });
1552
+ accountIndex++;
1553
+ }
1554
+ for (let i = 0; i < header.numReadonlyNonSignerAccounts; i++) {
1555
+ accountMetas.push({
1556
+ address: message.staticAccounts[accountIndex],
1557
+ role: AccountRole.READONLY
1558
+ });
1559
+ accountIndex++;
1560
+ }
1561
+ return accountMetas;
1562
+ }
1563
+ function convertInstruction(instruction, accountMetas) {
1564
+ var _a, _b;
1565
+ const programAddress = (_a = accountMetas[instruction.programAddressIndex]) == null ? void 0 : _a.address;
1566
+ if (!programAddress) {
1567
+ throw new Error(`Could not find program address at index ${instruction.programAddressIndex}`);
1568
+ }
1569
+ const accounts = (_b = instruction.accountIndices) == null ? void 0 : _b.map((accountIndex) => accountMetas[accountIndex]);
1570
+ const { data } = instruction;
1571
+ return {
1572
+ programAddress,
1573
+ ...accounts && accounts.length ? { accounts } : {},
1574
+ ...data && data.length ? { data } : {}
1688
1575
  };
1689
1576
  }
1577
+ function getLifetimeConstraint(messageLifetimeToken, firstInstruction, lastValidBlockHeight) {
1578
+ if (!firstInstruction || !isAdvanceNonceAccountInstruction(firstInstruction)) {
1579
+ return {
1580
+ blockhash: messageLifetimeToken,
1581
+ lastValidBlockHeight: lastValidBlockHeight != null ? lastValidBlockHeight : 2n ** 64n - 1n
1582
+ // U64 MAX
1583
+ };
1584
+ } else {
1585
+ const nonceAccountAddress = firstInstruction.accounts[0].address;
1586
+ assertIsAddress(nonceAccountAddress);
1587
+ const nonceAuthorityAddress = firstInstruction.accounts[2].address;
1588
+ assertIsAddress(nonceAuthorityAddress);
1589
+ return {
1590
+ nonce: messageLifetimeToken,
1591
+ nonceAccountAddress,
1592
+ nonceAuthorityAddress
1593
+ };
1594
+ }
1595
+ }
1596
+ function convertSignatures(compiledTransaction) {
1597
+ const {
1598
+ compiledMessage: { staticAccounts },
1599
+ signatures
1600
+ } = compiledTransaction;
1601
+ return signatures.reduce((acc, sig, index) => {
1602
+ const allZeros = sig.every((byte) => byte === 0);
1603
+ if (allZeros)
1604
+ return acc;
1605
+ const address2 = staticAccounts[index];
1606
+ return { ...acc, [address2]: sig };
1607
+ }, {});
1608
+ }
1609
+ function decompileTransaction(compiledTransaction, lastValidBlockHeight) {
1610
+ const { compiledMessage } = compiledTransaction;
1611
+ if ("addressTableLookups" in compiledMessage && compiledMessage.addressTableLookups.length > 0) {
1612
+ throw new Error("Cannot convert transaction with addressTableLookups");
1613
+ }
1614
+ const feePayer = compiledMessage.staticAccounts[0];
1615
+ if (!feePayer)
1616
+ throw new Error("No fee payer set in CompiledTransaction");
1617
+ const accountMetas = getAccountMetas(compiledMessage);
1618
+ const instructions = compiledMessage.instructions.map(
1619
+ (compiledInstruction) => convertInstruction(compiledInstruction, accountMetas)
1620
+ );
1621
+ const firstInstruction = instructions[0];
1622
+ const lifetimeConstraint = getLifetimeConstraint(
1623
+ compiledMessage.lifetimeToken,
1624
+ firstInstruction,
1625
+ lastValidBlockHeight
1626
+ );
1627
+ const signatures = convertSignatures(compiledTransaction);
1628
+ return pipe(
1629
+ createTransaction({ version: compiledMessage.version }),
1630
+ (tx) => setTransactionFeePayer(feePayer, tx),
1631
+ (tx) => instructions.reduce((acc, instruction) => {
1632
+ return appendTransactionInstruction(instruction, acc);
1633
+ }, tx),
1634
+ (tx) => "blockhash" in lifetimeConstraint ? setTransactionLifetimeUsingBlockhash(lifetimeConstraint, tx) : setTransactionLifetimeUsingDurableNonce(lifetimeConstraint, tx),
1635
+ (tx) => compiledTransaction.signatures.length ? { ...tx, signatures } : tx
1636
+ );
1637
+ }
1690
1638
 
1691
1639
  // src/serializers/transaction.ts
1692
- var BASE_CONFIG3 = {
1693
- description: "The wire format of a Solana transaction" ,
1694
- fixedSize: null,
1695
- maxSize: null
1696
- };
1697
- function serialize2(transaction) {
1698
- const compiledTransaction = getCompiledTransaction(transaction);
1699
- return struct([
1640
+ var signaturesDescription = "A compact array of 64-byte, base-64 encoded Ed25519 signatures" ;
1641
+ var transactionDescription = "The wire format of a Solana transaction" ;
1642
+ function getCompiledTransactionEncoder() {
1643
+ return getStructEncoder(
1700
1644
  [
1701
- "signatures",
1702
- array(bytes({ size: 64 }), {
1703
- ...{ description: "A compact array of 64-byte, base-64 encoded Ed25519 signatures" } ,
1704
- size: shortU16()
1705
- })
1645
+ [
1646
+ "signatures",
1647
+ getArrayEncoder(getBytesEncoder({ size: 64 }), {
1648
+ description: signaturesDescription,
1649
+ size: getShortU16Encoder()
1650
+ })
1651
+ ],
1652
+ ["compiledMessage", getCompiledMessageEncoder()]
1653
+ ],
1654
+ {
1655
+ description: transactionDescription
1656
+ }
1657
+ );
1658
+ }
1659
+ function getSignatureDecoder() {
1660
+ return mapDecoder(getBytesDecoder({ size: 64 }), (bytes) => bytes);
1661
+ }
1662
+ function getCompiledTransactionDecoder() {
1663
+ return getStructDecoder(
1664
+ [
1665
+ [
1666
+ "signatures",
1667
+ getArrayDecoder(getSignatureDecoder(), {
1668
+ description: signaturesDescription,
1669
+ size: getShortU16Decoder()
1670
+ })
1671
+ ],
1672
+ ["compiledMessage", getCompiledMessageDecoder()]
1706
1673
  ],
1707
- ["compiledMessage", getCompiledMessageEncoder()]
1708
- ]).serialize(compiledTransaction);
1674
+ {
1675
+ description: transactionDescription
1676
+ }
1677
+ );
1709
1678
  }
1710
1679
  function getTransactionEncoder() {
1711
- return {
1712
- ...BASE_CONFIG3,
1713
- deserialize: getUnimplementedDecoder("CompiledMessage"),
1714
- serialize: serialize2
1715
- };
1680
+ return mapEncoder(getCompiledTransactionEncoder(), getCompiledTransaction);
1681
+ }
1682
+ function getTransactionDecoder(lastValidBlockHeight) {
1683
+ return mapDecoder(
1684
+ getCompiledTransactionDecoder(),
1685
+ (compiledTransaction) => decompileTransaction(compiledTransaction, lastValidBlockHeight)
1686
+ );
1687
+ }
1688
+ function getTransactionCodec(lastValidBlockHeight) {
1689
+ return combineCodec(getTransactionEncoder(), getTransactionDecoder(lastValidBlockHeight));
1716
1690
  }
1717
1691
 
1718
1692
  // ../keys/dist/index.browser.js
@@ -1723,64 +1697,26 @@ this.globalThis.solanaWeb3 = (function (exports) {
1723
1697
  }
1724
1698
 
1725
1699
  // src/signatures.ts
1726
- function assertIsTransactionSignature(putativeTransactionSignature) {
1727
- try {
1728
- if (
1729
- // Lowest value (64 bytes of zeroes)
1730
- putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
1731
- putativeTransactionSignature.length > 88
1732
- ) {
1733
- throw new Error("Expected input string to decode to a byte array of length 64.");
1734
- }
1735
- const bytes2 = base58.serialize(putativeTransactionSignature);
1736
- const numBytes = bytes2.byteLength;
1737
- if (numBytes !== 64) {
1738
- throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
1739
- }
1740
- } catch (e2) {
1741
- throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
1742
- cause: e2
1743
- });
1744
- }
1745
- }
1746
- function isTransactionSignature(putativeTransactionSignature) {
1747
- if (
1748
- // Lowest value (64 bytes of zeroes)
1749
- putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
1750
- putativeTransactionSignature.length > 88
1751
- ) {
1752
- return false;
1753
- }
1754
- const bytes2 = base58.serialize(putativeTransactionSignature);
1755
- const numBytes = bytes2.byteLength;
1756
- if (numBytes !== 64) {
1757
- return false;
1758
- }
1759
- return true;
1760
- }
1761
- async function getCompiledMessageSignature(message, secretKey) {
1762
- const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
1763
- const signature = await signBytes(secretKey, wireMessageBytes);
1764
- return signature;
1765
- }
1700
+ var base58Decoder;
1766
1701
  function getSignatureFromTransaction(transaction) {
1767
- const signature = transaction.signatures[transaction.feePayer];
1768
- if (!signature) {
1702
+ if (!base58Decoder)
1703
+ base58Decoder = getBase58Decoder();
1704
+ const signatureBytes = transaction.signatures[transaction.feePayer];
1705
+ if (!signatureBytes) {
1769
1706
  throw new Error(
1770
1707
  "Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
1771
1708
  );
1772
1709
  }
1773
- return signature;
1710
+ const transactionSignature = base58Decoder.decode(signatureBytes)[0];
1711
+ return transactionSignature;
1774
1712
  }
1775
- async function signTransaction(keyPairs, transaction) {
1713
+ async function partiallySignTransaction(keyPairs, transaction) {
1776
1714
  const compiledMessage = compileMessage(transaction);
1777
1715
  const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
1716
+ const wireMessageBytes = getCompiledMessageEncoder().encode(compiledMessage);
1778
1717
  const publicKeySignaturePairs = await Promise.all(
1779
1718
  keyPairs.map(
1780
- (keyPair) => Promise.all([
1781
- getAddressFromPublicKey(keyPair.publicKey),
1782
- getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
1783
- ])
1719
+ (keyPair) => Promise.all([getAddressFromPublicKey(keyPair.publicKey), signBytes(keyPair.privateKey, wireMessageBytes)])
1784
1720
  )
1785
1721
  );
1786
1722
  for (const [signerPublicKey, signature] of publicKeySignaturePairs) {
@@ -1793,34 +1729,52 @@ this.globalThis.solanaWeb3 = (function (exports) {
1793
1729
  Object.freeze(out);
1794
1730
  return out;
1795
1731
  }
1796
- function transactionSignature(putativeTransactionSignature) {
1797
- assertIsTransactionSignature(putativeTransactionSignature);
1798
- return putativeTransactionSignature;
1732
+ async function signTransaction(keyPairs, transaction) {
1733
+ const out = await partiallySignTransaction(keyPairs, transaction);
1734
+ assertTransactionIsFullySigned(out);
1735
+ Object.freeze(out);
1736
+ return out;
1737
+ }
1738
+ function assertTransactionIsFullySigned(transaction) {
1739
+ const signerAddressesFromInstructions = transaction.instructions.flatMap((i) => {
1740
+ var _a, _b;
1741
+ return (_b = (_a = i.accounts) == null ? void 0 : _a.filter((a) => isSignerRole(a.role))) != null ? _b : [];
1742
+ }).map((a) => a.address);
1743
+ const requiredSigners = /* @__PURE__ */ new Set([transaction.feePayer, ...signerAddressesFromInstructions]);
1744
+ requiredSigners.forEach((address2) => {
1745
+ if (!transaction.signatures[address2]) {
1746
+ throw new Error(`Transaction is missing signature for address \`${address2}\``);
1747
+ }
1748
+ });
1799
1749
  }
1800
1750
 
1801
1751
  // src/wire-transaction.ts
1802
1752
  function getBase64EncodedWireTransaction(transaction) {
1803
- const wireTransactionBytes = getTransactionEncoder().serialize(transaction);
1804
- {
1805
- return btoa(String.fromCharCode(...wireTransactionBytes));
1806
- }
1753
+ const wireTransactionBytes = getTransactionEncoder().encode(transaction);
1754
+ return getBase64Decoder().decode(wireTransactionBytes)[0];
1807
1755
  }
1808
1756
 
1809
1757
  exports.appendTransactionInstruction = appendTransactionInstruction;
1810
1758
  exports.assertIsBlockhash = assertIsBlockhash;
1811
1759
  exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
1812
- exports.assertIsTransactionSignature = assertIsTransactionSignature;
1760
+ exports.assertTransactionIsFullySigned = assertTransactionIsFullySigned;
1761
+ exports.compileMessage = compileMessage;
1813
1762
  exports.createTransaction = createTransaction;
1814
1763
  exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
1764
+ exports.getCompiledMessageCodec = getCompiledMessageCodec;
1765
+ exports.getCompiledMessageDecoder = getCompiledMessageDecoder;
1766
+ exports.getCompiledMessageEncoder = getCompiledMessageEncoder;
1815
1767
  exports.getSignatureFromTransaction = getSignatureFromTransaction;
1768
+ exports.getTransactionCodec = getTransactionCodec;
1769
+ exports.getTransactionDecoder = getTransactionDecoder;
1816
1770
  exports.getTransactionEncoder = getTransactionEncoder;
1817
- exports.isTransactionSignature = isTransactionSignature;
1771
+ exports.isAdvanceNonceAccountInstruction = isAdvanceNonceAccountInstruction;
1772
+ exports.partiallySignTransaction = partiallySignTransaction;
1818
1773
  exports.prependTransactionInstruction = prependTransactionInstruction;
1819
1774
  exports.setTransactionFeePayer = setTransactionFeePayer;
1820
1775
  exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
1821
1776
  exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
1822
1777
  exports.signTransaction = signTransaction;
1823
- exports.transactionSignature = transactionSignature;
1824
1778
 
1825
1779
  return exports;
1826
1780