@solana/transactions 2.0.0-experimental.0108bc7

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 (66) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +25 -0
  3. package/dist/index.browser.cjs +771 -0
  4. package/dist/index.browser.cjs.map +1 -0
  5. package/dist/index.browser.js +760 -0
  6. package/dist/index.browser.js.map +1 -0
  7. package/dist/index.development.js +1327 -0
  8. package/dist/index.development.js.map +1 -0
  9. package/dist/index.native.js +760 -0
  10. package/dist/index.native.js.map +1 -0
  11. package/dist/index.node.cjs +773 -0
  12. package/dist/index.node.cjs.map +1 -0
  13. package/dist/index.node.js +762 -0
  14. package/dist/index.node.js.map +1 -0
  15. package/dist/index.production.min.js +20 -0
  16. package/dist/types/accounts.d.ts +28 -0
  17. package/dist/types/accounts.d.ts.map +1 -0
  18. package/dist/types/blockhash.d.ts +18 -0
  19. package/dist/types/blockhash.d.ts.map +1 -0
  20. package/dist/types/compile-address-table-lookups.d.ts +10 -0
  21. package/dist/types/compile-address-table-lookups.d.ts.map +1 -0
  22. package/dist/types/compile-header.d.ts +9 -0
  23. package/dist/types/compile-header.d.ts.map +1 -0
  24. package/dist/types/compile-instructions.d.ts +10 -0
  25. package/dist/types/compile-instructions.d.ts.map +1 -0
  26. package/dist/types/compile-lifetime-token.d.ts +3 -0
  27. package/dist/types/compile-lifetime-token.d.ts.map +1 -0
  28. package/dist/types/compile-static-accounts.d.ts +4 -0
  29. package/dist/types/compile-static-accounts.d.ts.map +1 -0
  30. package/dist/types/compile-transaction.d.ts +11 -0
  31. package/dist/types/compile-transaction.d.ts.map +1 -0
  32. package/dist/types/create-transaction.d.ts +9 -0
  33. package/dist/types/create-transaction.d.ts.map +1 -0
  34. package/dist/types/durable-nonce.d.ts +34 -0
  35. package/dist/types/durable-nonce.d.ts.map +1 -0
  36. package/dist/types/fee-payer.d.ts +8 -0
  37. package/dist/types/fee-payer.d.ts.map +1 -0
  38. package/dist/types/index.d.ts +9 -0
  39. package/dist/types/index.d.ts.map +1 -0
  40. package/dist/types/instructions.d.ts +5 -0
  41. package/dist/types/instructions.d.ts.map +1 -0
  42. package/dist/types/message.d.ts +30 -0
  43. package/dist/types/message.d.ts.map +1 -0
  44. package/dist/types/serializers/address-table-lookup.d.ts +6 -0
  45. package/dist/types/serializers/address-table-lookup.d.ts.map +1 -0
  46. package/dist/types/serializers/header.d.ts +6 -0
  47. package/dist/types/serializers/header.d.ts.map +1 -0
  48. package/dist/types/serializers/instruction.d.ts +6 -0
  49. package/dist/types/serializers/instruction.d.ts.map +1 -0
  50. package/dist/types/serializers/message.d.ts +6 -0
  51. package/dist/types/serializers/message.d.ts.map +1 -0
  52. package/dist/types/serializers/transaction-version.d.ts +6 -0
  53. package/dist/types/serializers/transaction-version.d.ts.map +1 -0
  54. package/dist/types/serializers/transaction.d.ts +6 -0
  55. package/dist/types/serializers/transaction.d.ts.map +1 -0
  56. package/dist/types/serializers/unimplemented.d.ts +3 -0
  57. package/dist/types/serializers/unimplemented.d.ts.map +1 -0
  58. package/dist/types/signatures.d.ts +11 -0
  59. package/dist/types/signatures.d.ts.map +1 -0
  60. package/dist/types/types.d.ts +19 -0
  61. package/dist/types/types.d.ts.map +1 -0
  62. package/dist/types/unsigned-transaction.d.ts +4 -0
  63. package/dist/types/unsigned-transaction.d.ts.map +1 -0
  64. package/dist/types/wire-transaction.d.ts +6 -0
  65. package/dist/types/wire-transaction.d.ts.map +1 -0
  66. package/package.json +97 -0
@@ -0,0 +1,1327 @@
1
+ this.globalThis = this.globalThis || {};
2
+ this.globalThis.solanaWeb3 = (function (exports) {
3
+ 'use strict';
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.2/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.2/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.2/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.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/mapSerializer.mjs
75
+ function mapSerializer(serializer, unmap, map) {
76
+ return {
77
+ description: serializer.description,
78
+ fixedSize: serializer.fixedSize,
79
+ maxSize: serializer.maxSize,
80
+ serialize: (value) => serializer.serialize(unmap(value)),
81
+ deserialize: (buffer, offset = 0) => {
82
+ const [value, length] = serializer.deserialize(buffer, offset);
83
+ return map ? [map(value, buffer, offset), length] : [value, length];
84
+ }
85
+ };
86
+ }
87
+
88
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/errors.mjs
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.2/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.2/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.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/nullCharacters.mjs
156
+ var removeNullCharacters = (value) => (
157
+ // eslint-disable-next-line no-control-regex
158
+ value.replace(/\u0000/g, "")
159
+ );
160
+
161
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/utf8.mjs
162
+ var utf8 = {
163
+ description: "utf8",
164
+ fixedSize: null,
165
+ maxSize: null,
166
+ serialize(value) {
167
+ return new TextEncoder().encode(value);
168
+ },
169
+ deserialize(buffer, offset = 0) {
170
+ const value = new TextDecoder().decode(buffer.slice(offset));
171
+ return [removeNullCharacters(value), buffer.length];
172
+ }
173
+ };
174
+
175
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/common.mjs
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.2/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.2/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.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u8.mjs
235
+ var u8 = (options = {}) => numberFactory({
236
+ name: "u8",
237
+ size: 1,
238
+ range: [0, Number("0xff")],
239
+ set: (view, value) => view.setUint8(0, Number(value)),
240
+ get: (view) => view.getUint8(0),
241
+ options
242
+ });
243
+
244
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u32.mjs
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.2/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.5/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.5/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.5/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.5/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.5/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.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/string.mjs
433
+ function string(options = {}) {
434
+ const size = options.size ?? u32();
435
+ const encoding = options.encoding ?? utf8;
436
+ const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
437
+ if (size === "variable") {
438
+ return {
439
+ ...encoding,
440
+ description
441
+ };
442
+ }
443
+ if (typeof size === "number") {
444
+ return fixSerializer(encoding, size, description);
445
+ }
446
+ return {
447
+ description,
448
+ fixedSize: null,
449
+ maxSize: null,
450
+ serialize: (value) => {
451
+ const contentBytes = encoding.serialize(value);
452
+ const lengthBytes = size.serialize(contentBytes.length);
453
+ return mergeBytes([lengthBytes, contentBytes]);
454
+ },
455
+ deserialize: (buffer, offset = 0) => {
456
+ if (buffer.slice(offset).length === 0) {
457
+ throw new DeserializingEmptyBufferError("string");
458
+ }
459
+ const [lengthBigInt, lengthOffset] = size.deserialize(buffer, offset);
460
+ const length = Number(lengthBigInt);
461
+ offset = lengthOffset;
462
+ const contentBuffer = buffer.slice(offset, offset + length);
463
+ if (contentBuffer.length < length) {
464
+ throw new NotEnoughBytesError("string", length, contentBuffer.length);
465
+ }
466
+ const [value, contentOffset] = encoding.deserialize(contentBuffer);
467
+ offset += contentOffset;
468
+ return [value, offset];
469
+ }
470
+ };
471
+ }
472
+
473
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/struct.mjs
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 (e) {
526
+ throw new Error(`\`${putativeBlockhash}\` is not a blockhash`, {
527
+ cause: e
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
+ // ../assertions/dist/index.browser.js
669
+ function assertIsSecureContext() {
670
+ if (!globalThis.isSecureContext) {
671
+ throw new Error(
672
+ "Cryptographic operations are only allowed in secure browser contexts. Read more here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts"
673
+ );
674
+ }
675
+ }
676
+ async function assertKeyExporterIsAvailable() {
677
+ assertIsSecureContext();
678
+ if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.exportKey !== "function") {
679
+ throw new Error("No key export implementation could be found");
680
+ }
681
+ }
682
+ async function assertSigningCapabilityIsAvailable() {
683
+ assertIsSecureContext();
684
+ if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.sign !== "function") {
685
+ throw new Error("No signing implementation could be found");
686
+ }
687
+ }
688
+ function getBase58EncodedAddressCodec(config) {
689
+ return string({
690
+ description: config?.description ?? ("A 32-byte account address" ),
691
+ encoding: base58,
692
+ size: 32
693
+ });
694
+ }
695
+ function getBase58EncodedAddressComparator() {
696
+ return new Intl.Collator("en", {
697
+ caseFirst: "lower",
698
+ ignorePunctuation: false,
699
+ localeMatcher: "best fit",
700
+ numeric: false,
701
+ sensitivity: "variant",
702
+ usage: "sort"
703
+ }).compare;
704
+ }
705
+ async function getBase58EncodedAddressFromPublicKey(publicKey) {
706
+ await assertKeyExporterIsAvailable();
707
+ if (publicKey.type !== "public" || publicKey.algorithm.name !== "Ed25519") {
708
+ throw new Error("The `CryptoKey` must be an `Ed25519` public key");
709
+ }
710
+ const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
711
+ const [base58EncodedAddress] = getBase58EncodedAddressCodec().deserialize(new Uint8Array(publicKeyBytes));
712
+ return base58EncodedAddress;
713
+ }
714
+
715
+ // ../keys/dist/index.browser.js
716
+ async function signBytes(key, data) {
717
+ await assertSigningCapabilityIsAvailable();
718
+ const signedData = await crypto.subtle.sign("Ed25519", key, data);
719
+ return new Uint8Array(signedData);
720
+ }
721
+
722
+ // src/accounts.ts
723
+ function upsert(addressMap, address, update) {
724
+ addressMap[address] = update(addressMap[address] ?? { role: AccountRole.READONLY });
725
+ }
726
+ var TYPE = Symbol("AddressMapTypeProperty");
727
+ function getAddressMapFromInstructions(feePayer, instructions) {
728
+ const addressMap = {
729
+ [feePayer]: { [TYPE]: 0 /* FEE_PAYER */, role: AccountRole.WRITABLE_SIGNER }
730
+ };
731
+ const addressesOfInvokedPrograms = /* @__PURE__ */ new Set();
732
+ for (const instruction of instructions) {
733
+ upsert(addressMap, instruction.programAddress, (entry) => {
734
+ addressesOfInvokedPrograms.add(instruction.programAddress);
735
+ if (TYPE in entry) {
736
+ if (isWritableRole(entry.role)) {
737
+ switch (entry[TYPE]) {
738
+ case 0 /* FEE_PAYER */:
739
+ throw new Error(
740
+ `This transaction includes an address (\`${instruction.programAddress}\`) which is both invoked and set as the fee payer. Program addresses may not pay fees.`
741
+ );
742
+ default:
743
+ throw new Error(
744
+ `This transaction includes an address (\`${instruction.programAddress}\`) which is both invoked and marked writable. Program addresses may not be writable.`
745
+ );
746
+ }
747
+ }
748
+ if (entry[TYPE] === 2 /* STATIC */) {
749
+ return entry;
750
+ }
751
+ }
752
+ return { [TYPE]: 2 /* STATIC */, role: AccountRole.READONLY };
753
+ });
754
+ let addressComparator;
755
+ if (!instruction.accounts) {
756
+ continue;
757
+ }
758
+ for (const account of instruction.accounts) {
759
+ upsert(addressMap, account.address, (entry) => {
760
+ const {
761
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
762
+ address: _,
763
+ ...accountMeta
764
+ } = account;
765
+ if (TYPE in entry) {
766
+ switch (entry[TYPE]) {
767
+ case 0 /* FEE_PAYER */:
768
+ return entry;
769
+ case 1 /* LOOKUP_TABLE */: {
770
+ const nextRole = mergeRoles(entry.role, accountMeta.role);
771
+ if ("lookupTableAddress" in accountMeta) {
772
+ const shouldReplaceEntry = (
773
+ // Consider using the new LOOKUP_TABLE if its address is different...
774
+ entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
775
+ (addressComparator || (addressComparator = getBase58EncodedAddressComparator()))(
776
+ accountMeta.lookupTableAddress,
777
+ entry.lookupTableAddress
778
+ ) < 0
779
+ );
780
+ if (shouldReplaceEntry) {
781
+ return {
782
+ [TYPE]: 1 /* LOOKUP_TABLE */,
783
+ ...accountMeta,
784
+ role: nextRole
785
+ };
786
+ }
787
+ } else if (isSignerRole(accountMeta.role)) {
788
+ return {
789
+ [TYPE]: 2 /* STATIC */,
790
+ role: nextRole
791
+ };
792
+ }
793
+ if (entry.role !== nextRole) {
794
+ return {
795
+ ...entry,
796
+ role: nextRole
797
+ };
798
+ } else {
799
+ return entry;
800
+ }
801
+ }
802
+ case 2 /* STATIC */: {
803
+ const nextRole = mergeRoles(entry.role, accountMeta.role);
804
+ if (
805
+ // Check to see if this address represents a program that is invoked
806
+ // in this transaction.
807
+ addressesOfInvokedPrograms.has(account.address)
808
+ ) {
809
+ if (isWritableRole(accountMeta.role)) {
810
+ throw new Error(
811
+ `This transaction includes an address (\`${account.address}\`) which is both invoked and marked writable. Program addresses may not be writable.`
812
+ );
813
+ }
814
+ if (entry.role !== nextRole) {
815
+ return {
816
+ ...entry,
817
+ role: nextRole
818
+ };
819
+ } else {
820
+ return entry;
821
+ }
822
+ } else if ("lookupTableAddress" in accountMeta && // Static accounts can be 'upgraded' to lookup table accounts as
823
+ // long as they are not require to sign the transaction.
824
+ !isSignerRole(entry.role)) {
825
+ return {
826
+ ...accountMeta,
827
+ [TYPE]: 1 /* LOOKUP_TABLE */,
828
+ role: nextRole
829
+ };
830
+ } else {
831
+ if (entry.role !== nextRole) {
832
+ return {
833
+ ...entry,
834
+ role: nextRole
835
+ };
836
+ } else {
837
+ return entry;
838
+ }
839
+ }
840
+ }
841
+ }
842
+ }
843
+ if ("lookupTableAddress" in accountMeta) {
844
+ return {
845
+ ...accountMeta,
846
+ [TYPE]: 1 /* LOOKUP_TABLE */
847
+ };
848
+ } else {
849
+ return {
850
+ ...accountMeta,
851
+ [TYPE]: 2 /* STATIC */
852
+ };
853
+ }
854
+ });
855
+ }
856
+ }
857
+ return addressMap;
858
+ }
859
+ function getOrderedAccountsFromAddressMap(addressMap) {
860
+ let addressComparator;
861
+ const orderedAccounts = Object.entries(addressMap).sort(([leftAddress, leftEntry], [rightAddress, rightEntry]) => {
862
+ if (leftEntry[TYPE] !== rightEntry[TYPE]) {
863
+ if (leftEntry[TYPE] === 0 /* FEE_PAYER */) {
864
+ return -1;
865
+ } else if (rightEntry[TYPE] === 0 /* FEE_PAYER */) {
866
+ return 1;
867
+ } else if (leftEntry[TYPE] === 2 /* STATIC */) {
868
+ return -1;
869
+ } else if (rightEntry[TYPE] === 2 /* STATIC */) {
870
+ return 1;
871
+ }
872
+ }
873
+ const leftIsSigner = isSignerRole(leftEntry.role);
874
+ if (leftIsSigner !== isSignerRole(rightEntry.role)) {
875
+ return leftIsSigner ? -1 : 1;
876
+ }
877
+ const leftIsWritable = isWritableRole(leftEntry.role);
878
+ if (leftIsWritable !== isWritableRole(rightEntry.role)) {
879
+ return leftIsWritable ? -1 : 1;
880
+ }
881
+ addressComparator || (addressComparator = getBase58EncodedAddressComparator());
882
+ if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
883
+ return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
884
+ } else {
885
+ return addressComparator(leftAddress, rightAddress);
886
+ }
887
+ }).map(([address, addressMeta]) => ({
888
+ address,
889
+ ...addressMeta
890
+ }));
891
+ return orderedAccounts;
892
+ }
893
+
894
+ // src/compile-address-table-lookups.ts
895
+ function getCompiledAddressTableLookups(orderedAccounts) {
896
+ var _a;
897
+ const index = {};
898
+ for (const account of orderedAccounts) {
899
+ if (!("lookupTableAddress" in account)) {
900
+ continue;
901
+ }
902
+ const entry = index[_a = account.lookupTableAddress] || (index[_a] = {
903
+ readableIndices: [],
904
+ writableIndices: []
905
+ });
906
+ if (account.role === AccountRole.WRITABLE) {
907
+ entry.writableIndices.push(account.addressIndex);
908
+ } else {
909
+ entry.readableIndices.push(account.addressIndex);
910
+ }
911
+ }
912
+ return Object.keys(index).sort(getBase58EncodedAddressComparator()).map((lookupTableAddress) => ({
913
+ lookupTableAddress,
914
+ ...index[lookupTableAddress]
915
+ }));
916
+ }
917
+
918
+ // src/compile-header.ts
919
+ function getCompiledMessageHeader(orderedAccounts) {
920
+ let numReadonlyNonSignerAccounts = 0;
921
+ let numReadonlySignerAccounts = 0;
922
+ let numSignerAccounts = 0;
923
+ for (const account of orderedAccounts) {
924
+ if ("lookupTableAddress" in account) {
925
+ break;
926
+ }
927
+ const accountIsWritable = isWritableRole(account.role);
928
+ if (isSignerRole(account.role)) {
929
+ numSignerAccounts++;
930
+ if (!accountIsWritable) {
931
+ numReadonlySignerAccounts++;
932
+ }
933
+ } else if (!accountIsWritable) {
934
+ numReadonlyNonSignerAccounts++;
935
+ }
936
+ }
937
+ return {
938
+ numReadonlyNonSignerAccounts,
939
+ numReadonlySignerAccounts,
940
+ numSignerAccounts
941
+ };
942
+ }
943
+
944
+ // src/compile-instructions.ts
945
+ function getAccountIndex(orderedAccounts) {
946
+ const out = {};
947
+ for (const [index, account] of orderedAccounts.entries()) {
948
+ out[account.address] = index;
949
+ }
950
+ return out;
951
+ }
952
+ function getCompiledInstructions(instructions, orderedAccounts) {
953
+ const accountIndex = getAccountIndex(orderedAccounts);
954
+ return instructions.map(({ accounts, data, programAddress }) => {
955
+ return {
956
+ programAddressIndex: accountIndex[programAddress],
957
+ ...accounts ? { accountIndices: accounts.map(({ address }) => accountIndex[address]) } : null,
958
+ ...data ? { data } : null
959
+ };
960
+ });
961
+ }
962
+
963
+ // src/compile-lifetime-token.ts
964
+ function getCompiledLifetimeToken(lifetimeConstraint) {
965
+ if ("nonce" in lifetimeConstraint) {
966
+ return lifetimeConstraint.nonce;
967
+ }
968
+ return lifetimeConstraint.blockhash;
969
+ }
970
+
971
+ // src/compile-static-accounts.ts
972
+ function getCompiledStaticAccounts(orderedAccounts) {
973
+ const firstLookupTableAccountIndex = orderedAccounts.findIndex((account) => "lookupTableAddress" in account);
974
+ const orderedStaticAccounts = firstLookupTableAccountIndex === -1 ? orderedAccounts : orderedAccounts.slice(0, firstLookupTableAccountIndex);
975
+ return orderedStaticAccounts.map(({ address }) => address);
976
+ }
977
+
978
+ // src/message.ts
979
+ function compileMessage(transaction) {
980
+ const addressMap = getAddressMapFromInstructions(transaction.feePayer, transaction.instructions);
981
+ const orderedAccounts = getOrderedAccountsFromAddressMap(addressMap);
982
+ return {
983
+ ...transaction.version !== "legacy" ? { addressTableLookups: getCompiledAddressTableLookups(orderedAccounts) } : null,
984
+ header: getCompiledMessageHeader(orderedAccounts),
985
+ instructions: getCompiledInstructions(transaction.instructions, orderedAccounts),
986
+ lifetimeToken: getCompiledLifetimeToken(transaction.lifetimeConstraint),
987
+ staticAccounts: getCompiledStaticAccounts(orderedAccounts),
988
+ version: transaction.version
989
+ };
990
+ }
991
+
992
+ // src/serializers/address-table-lookup.ts
993
+ function getAddressTableLookupCodec() {
994
+ return struct(
995
+ [
996
+ [
997
+ "lookupTableAddress",
998
+ getBase58EncodedAddressCodec(
999
+ {
1000
+ description: "The address of the address lookup table account from which instruction addresses should be looked up"
1001
+ }
1002
+ )
1003
+ ],
1004
+ [
1005
+ "writableIndices",
1006
+ array(u8(), {
1007
+ ...{
1008
+ description: "The indices of the accounts in the lookup table that should be loaded as writeable"
1009
+ } ,
1010
+ size: shortU16()
1011
+ })
1012
+ ],
1013
+ [
1014
+ "readableIndices",
1015
+ array(u8(), {
1016
+ ...{
1017
+ description: "The indices of the accounts in the lookup table that should be loaded as read-only"
1018
+ } ,
1019
+ size: shortU16()
1020
+ })
1021
+ ]
1022
+ ],
1023
+ {
1024
+ description: "A pointer to the address of an address lookup table, along with the readonly/writeable indices of the addresses that should be loaded from it"
1025
+ }
1026
+ );
1027
+ }
1028
+
1029
+ // src/serializers/header.ts
1030
+ function getMessageHeaderCodec() {
1031
+ return struct(
1032
+ [
1033
+ [
1034
+ "numSignerAccounts",
1035
+ u8(
1036
+ {
1037
+ description: "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction"
1038
+ }
1039
+ )
1040
+ ],
1041
+ [
1042
+ "numReadonlySignerAccounts",
1043
+ u8(
1044
+ {
1045
+ description: "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction, but may not be writable"
1046
+ }
1047
+ )
1048
+ ],
1049
+ [
1050
+ "numReadonlyNonSignerAccounts",
1051
+ u8(
1052
+ {
1053
+ description: "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable"
1054
+ }
1055
+ )
1056
+ ]
1057
+ ],
1058
+ {
1059
+ description: "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses"
1060
+ }
1061
+ );
1062
+ }
1063
+
1064
+ // src/serializers/instruction.ts
1065
+ function getInstructionCodec() {
1066
+ return mapSerializer(
1067
+ struct([
1068
+ [
1069
+ "programAddressIndex",
1070
+ u8(
1071
+ {
1072
+ description: "The index of the program being called, according to the well-ordered accounts list for this transaction"
1073
+ }
1074
+ )
1075
+ ],
1076
+ [
1077
+ "accountIndices",
1078
+ array(
1079
+ u8({
1080
+ description: "The index of an account, according to the well-ordered accounts list for this transaction"
1081
+ }),
1082
+ {
1083
+ description: "An optional list of account indices, according to the well-ordered accounts list for this transaction, in the order in which the program being called expects them" ,
1084
+ size: shortU16()
1085
+ }
1086
+ )
1087
+ ],
1088
+ [
1089
+ "data",
1090
+ bytes({
1091
+ description: "An optional buffer of data passed to the instruction" ,
1092
+ size: shortU16()
1093
+ })
1094
+ ]
1095
+ ]),
1096
+ (value) => {
1097
+ if (value.accountIndices !== void 0 && value.data !== void 0) {
1098
+ return value;
1099
+ }
1100
+ return {
1101
+ ...value,
1102
+ accountIndices: value.accountIndices ?? [],
1103
+ data: value.data ?? new Uint8Array(0)
1104
+ };
1105
+ },
1106
+ (value) => {
1107
+ if (value.accountIndices.length && value.data.byteLength) {
1108
+ return value;
1109
+ }
1110
+ const { accountIndices, data, ...rest } = value;
1111
+ return {
1112
+ ...rest,
1113
+ ...accountIndices.length ? { accountIndices } : null,
1114
+ ...data.byteLength ? { data } : null
1115
+ };
1116
+ }
1117
+ );
1118
+ }
1119
+
1120
+ // src/serializers/unimplemented.ts
1121
+ function getError(type, name) {
1122
+ const functionSuffix = name + type[0].toUpperCase() + type.slice(1);
1123
+ return new Error(
1124
+ `No ${type} exists for ${name}. Use \`get${functionSuffix}()\` if you need a ${type}, and \`get${name}Codec()\` if you need to both encode and decode ${name}`
1125
+ );
1126
+ }
1127
+ function getUnimplementedDecoder(name) {
1128
+ return () => {
1129
+ throw getError("decoder", name);
1130
+ };
1131
+ }
1132
+
1133
+ // src/serializers/transaction-version.ts
1134
+ var VERSION_FLAG_MASK = 128;
1135
+ var BASE_CONFIG = {
1136
+ description: "A single byte that encodes the version of the transaction" ,
1137
+ fixedSize: null,
1138
+ maxSize: 1
1139
+ };
1140
+ function deserialize(bytes2, offset = 0) {
1141
+ const firstByte = bytes2[offset];
1142
+ if ((firstByte & VERSION_FLAG_MASK) === 0) {
1143
+ return ["legacy", offset];
1144
+ } else {
1145
+ const version = firstByte ^ VERSION_FLAG_MASK;
1146
+ return [version, offset + 1];
1147
+ }
1148
+ }
1149
+ function serialize(value) {
1150
+ if (value === "legacy") {
1151
+ return new Uint8Array();
1152
+ }
1153
+ if (value < 0 || value > 127) {
1154
+ throw new Error(`Transaction version must be in the range [0, 127]. \`${value}\` given.`);
1155
+ }
1156
+ return new Uint8Array([value | VERSION_FLAG_MASK]);
1157
+ }
1158
+ function getTransactionVersionCodec() {
1159
+ return {
1160
+ ...BASE_CONFIG,
1161
+ deserialize,
1162
+ serialize
1163
+ };
1164
+ }
1165
+
1166
+ // src/serializers/message.ts
1167
+ var BASE_CONFIG2 = {
1168
+ description: "The wire format of a Solana transaction message" ,
1169
+ fixedSize: null,
1170
+ maxSize: null
1171
+ };
1172
+ function serialize2(compiledMessage) {
1173
+ if (compiledMessage.version === "legacy") {
1174
+ return struct(getPreludeStructSerializerTuple()).serialize(compiledMessage);
1175
+ } else {
1176
+ return mapSerializer(
1177
+ struct([
1178
+ ...getPreludeStructSerializerTuple(),
1179
+ ["addressTableLookups", getAddressTableLookupsSerializer()]
1180
+ ]),
1181
+ (value) => {
1182
+ if (value.version === "legacy") {
1183
+ return value;
1184
+ }
1185
+ return {
1186
+ ...value,
1187
+ addressTableLookups: value.addressTableLookups ?? []
1188
+ };
1189
+ }
1190
+ ).serialize(compiledMessage);
1191
+ }
1192
+ }
1193
+ function getPreludeStructSerializerTuple() {
1194
+ return [
1195
+ ["version", getTransactionVersionCodec()],
1196
+ ["header", getMessageHeaderCodec()],
1197
+ [
1198
+ "staticAccounts",
1199
+ array(getBase58EncodedAddressCodec(), {
1200
+ description: "A compact-array of static account addresses belonging to this transaction" ,
1201
+ size: shortU16()
1202
+ })
1203
+ ],
1204
+ [
1205
+ "lifetimeToken",
1206
+ string({
1207
+ description: "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" ,
1208
+ encoding: base58,
1209
+ size: 32
1210
+ })
1211
+ ],
1212
+ [
1213
+ "instructions",
1214
+ array(getInstructionCodec(), {
1215
+ description: "A compact-array of instructions belonging to this transaction" ,
1216
+ size: shortU16()
1217
+ })
1218
+ ]
1219
+ ];
1220
+ }
1221
+ function getAddressTableLookupsSerializer() {
1222
+ return array(getAddressTableLookupCodec(), {
1223
+ ...{ description: "A compact array of address table lookups belonging to this transaction" } ,
1224
+ size: shortU16()
1225
+ });
1226
+ }
1227
+ function getCompiledMessageEncoder() {
1228
+ return {
1229
+ ...BASE_CONFIG2,
1230
+ deserialize: getUnimplementedDecoder("CompiledMessage"),
1231
+ serialize: serialize2
1232
+ };
1233
+ }
1234
+
1235
+ // src/signatures.ts
1236
+ async function getCompiledMessageSignature(message, secretKey) {
1237
+ const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
1238
+ const signature = await signBytes(secretKey, wireMessageBytes);
1239
+ return signature;
1240
+ }
1241
+ async function signTransaction(keyPair, transaction) {
1242
+ const compiledMessage = compileMessage(transaction);
1243
+ const [signerPublicKey, signature] = await Promise.all([
1244
+ getBase58EncodedAddressFromPublicKey(keyPair.publicKey),
1245
+ getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
1246
+ ]);
1247
+ const nextSignatures = {
1248
+ ..."signatures" in transaction ? transaction.signatures : null,
1249
+ ...{ [signerPublicKey]: signature }
1250
+ };
1251
+ const out = {
1252
+ ...transaction,
1253
+ signatures: nextSignatures
1254
+ };
1255
+ Object.freeze(out);
1256
+ return out;
1257
+ }
1258
+
1259
+ // src/compile-transaction.ts
1260
+ function getCompiledTransaction(transaction) {
1261
+ const compiledMessage = compileMessage(transaction);
1262
+ let signatures;
1263
+ if ("signatures" in transaction) {
1264
+ signatures = [];
1265
+ for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
1266
+ signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
1267
+ }
1268
+ } else {
1269
+ signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
1270
+ }
1271
+ return {
1272
+ compiledMessage,
1273
+ signatures
1274
+ };
1275
+ }
1276
+
1277
+ // src/serializers/transaction.ts
1278
+ var BASE_CONFIG3 = {
1279
+ description: "The wire format of a Solana transaction" ,
1280
+ fixedSize: null,
1281
+ maxSize: null
1282
+ };
1283
+ function serialize3(transaction) {
1284
+ const compiledTransaction = getCompiledTransaction(transaction);
1285
+ return struct([
1286
+ [
1287
+ "signatures",
1288
+ array(bytes({ size: 64 }), {
1289
+ ...{ description: "A compact array of 64-byte, base-64 encoded Ed25519 signatures" } ,
1290
+ size: shortU16()
1291
+ })
1292
+ ],
1293
+ ["compiledMessage", getCompiledMessageEncoder()]
1294
+ ]).serialize(compiledTransaction);
1295
+ }
1296
+ function getTransactionEncoder() {
1297
+ return {
1298
+ ...BASE_CONFIG3,
1299
+ deserialize: getUnimplementedDecoder("CompiledMessage"),
1300
+ serialize: serialize3
1301
+ };
1302
+ }
1303
+
1304
+ // src/wire-transaction.ts
1305
+ function getBase64EncodedWireTransaction(transaction) {
1306
+ const wireTransactionBytes = getTransactionEncoder().serialize(transaction);
1307
+ {
1308
+ return btoa(String.fromCharCode(...wireTransactionBytes));
1309
+ }
1310
+ }
1311
+
1312
+ exports.appendTransactionInstruction = appendTransactionInstruction;
1313
+ exports.assertIsBlockhash = assertIsBlockhash;
1314
+ exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
1315
+ exports.createTransaction = createTransaction;
1316
+ exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
1317
+ exports.prependTransactionInstruction = prependTransactionInstruction;
1318
+ exports.setTransactionFeePayer = setTransactionFeePayer;
1319
+ exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
1320
+ exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
1321
+ exports.signTransaction = signTransaction;
1322
+
1323
+ return exports;
1324
+
1325
+ })({});
1326
+ //# sourceMappingURL=out.js.map
1327
+ //# sourceMappingURL=index.development.js.map