@solana/transactions 2.0.0-experimental.be901cf → 2.0.0-experimental.bea19d2

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 (70) hide show
  1. package/README.md +276 -5
  2. package/dist/index.browser.cjs +466 -354
  3. package/dist/index.browser.cjs.map +1 -1
  4. package/dist/index.browser.js +457 -355
  5. package/dist/index.browser.js.map +1 -1
  6. package/dist/index.native.js +457 -355
  7. package/dist/index.native.js.map +1 -1
  8. package/dist/index.node.cjs +468 -354
  9. package/dist/index.node.cjs.map +1 -1
  10. package/dist/index.node.js +457 -355
  11. package/dist/index.node.js.map +1 -1
  12. package/dist/types/accounts.d.ts +2 -2
  13. package/dist/types/accounts.d.ts.map +1 -0
  14. package/dist/types/blockhash.d.ts +5 -7
  15. package/dist/types/blockhash.d.ts.map +1 -0
  16. package/dist/types/compilable-transaction.d.ts +7 -0
  17. package/dist/types/compilable-transaction.d.ts.map +1 -0
  18. package/dist/types/compile-address-table-lookups.d.ts +3 -3
  19. package/dist/types/compile-address-table-lookups.d.ts.map +1 -0
  20. package/dist/types/compile-header.d.ts +1 -1
  21. package/dist/types/compile-header.d.ts.map +1 -0
  22. package/dist/types/compile-instructions.d.ts +1 -1
  23. package/dist/types/compile-instructions.d.ts.map +1 -0
  24. package/dist/types/compile-lifetime-token.d.ts +1 -1
  25. package/dist/types/compile-lifetime-token.d.ts.map +1 -0
  26. package/dist/types/compile-static-accounts.d.ts +3 -3
  27. package/dist/types/compile-static-accounts.d.ts.map +1 -0
  28. package/dist/types/compile-transaction.d.ts +6 -7
  29. package/dist/types/compile-transaction.d.ts.map +1 -0
  30. package/dist/types/create-transaction.d.ts +1 -1
  31. package/dist/types/create-transaction.d.ts.map +1 -0
  32. package/dist/types/decompile-transaction.d.ts +13 -0
  33. package/dist/types/decompile-transaction.d.ts.map +1 -0
  34. package/dist/types/durable-nonce.d.ts +7 -8
  35. package/dist/types/durable-nonce.d.ts.map +1 -0
  36. package/dist/types/fee-payer.d.ts +6 -6
  37. package/dist/types/fee-payer.d.ts.map +1 -0
  38. package/dist/types/index.d.ts +13 -9
  39. package/dist/types/index.d.ts.map +1 -0
  40. package/dist/types/instructions.d.ts +4 -2
  41. package/dist/types/instructions.d.ts.map +1 -0
  42. package/dist/types/message.d.ts +6 -10
  43. package/dist/types/message.d.ts.map +1 -0
  44. package/dist/types/serializers/address-table-lookup.d.ts +5 -5
  45. package/dist/types/serializers/address-table-lookup.d.ts.map +1 -0
  46. package/dist/types/serializers/header.d.ts +5 -5
  47. package/dist/types/serializers/header.d.ts.map +1 -0
  48. package/dist/types/serializers/index.d.ts +2 -1
  49. package/dist/types/serializers/index.d.ts.map +1 -0
  50. package/dist/types/serializers/instruction.d.ts +5 -5
  51. package/dist/types/serializers/instruction.d.ts.map +1 -0
  52. package/dist/types/serializers/message.d.ts +5 -5
  53. package/dist/types/serializers/message.d.ts.map +1 -0
  54. package/dist/types/serializers/transaction-version.d.ts +5 -5
  55. package/dist/types/serializers/transaction-version.d.ts.map +1 -0
  56. package/dist/types/serializers/transaction.d.ts +9 -5
  57. package/dist/types/serializers/transaction.d.ts.map +1 -0
  58. package/dist/types/signatures.d.ts +9 -13
  59. package/dist/types/signatures.d.ts.map +1 -0
  60. package/dist/types/types.d.ts +6 -13
  61. package/dist/types/types.d.ts.map +1 -0
  62. package/dist/types/unsigned-transaction.d.ts +1 -1
  63. package/dist/types/unsigned-transaction.d.ts.map +1 -0
  64. package/dist/types/wire-transaction.d.ts +2 -2
  65. package/dist/types/wire-transaction.d.ts.map +1 -0
  66. package/package.json +18 -38
  67. package/dist/index.development.js +0 -2042
  68. package/dist/index.development.js.map +0 -1
  69. package/dist/index.production.min.js +0 -26
  70. package/dist/types/serializers/unimplemented.d.ts +0 -3
@@ -1,2042 +0,0 @@
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.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/u32.mjs
235
- var u32 = (options = {}) => numberFactory({
236
- name: "u32",
237
- size: 4,
238
- range: [0, Number("0xffffffff")],
239
- set: (view, value, le) => view.setUint32(0, Number(value), le),
240
- get: (view, le) => view.getUint32(0, le),
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/shortU16.mjs
245
- var shortU16 = (options = {}) => ({
246
- description: options.description ?? "shortU16",
247
- fixedSize: null,
248
- maxSize: 3,
249
- serialize: (value) => {
250
- assertRange("shortU16", 0, 65535, value);
251
- const bytes2 = [0];
252
- for (let ii = 0; ; ii += 1) {
253
- const alignedValue = value >> ii * 7;
254
- if (alignedValue === 0) {
255
- break;
256
- }
257
- const nextSevenBits = 127 & alignedValue;
258
- bytes2[ii] = nextSevenBits;
259
- if (ii > 0) {
260
- bytes2[ii - 1] |= 128;
261
- }
262
- }
263
- return new Uint8Array(bytes2);
264
- },
265
- deserialize: (bytes2, offset = 0) => {
266
- let value = 0;
267
- let byteCount = 0;
268
- while (++byteCount) {
269
- const byteIndex = byteCount - 1;
270
- const currentByte = bytes2[offset + byteIndex];
271
- const nextSevenBits = 127 & currentByte;
272
- value |= nextSevenBits << byteIndex * 7;
273
- if ((currentByte & 128) === 0) {
274
- break;
275
- }
276
- }
277
- return [value, offset + byteCount];
278
- }
279
- });
280
-
281
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/errors.mjs
282
- var InvalidNumberOfItemsError = class extends Error {
283
- constructor(serializer, expected, actual) {
284
- super(`Expected [${serializer}] to have ${expected} items, got ${actual}.`);
285
- __publicField(this, "name", "InvalidNumberOfItemsError");
286
- }
287
- };
288
- var InvalidArrayLikeRemainderSizeError = class extends Error {
289
- constructor(remainderSize, itemSize) {
290
- 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.`);
291
- __publicField(this, "name", "InvalidArrayLikeRemainderSizeError");
292
- }
293
- };
294
- var UnrecognizedArrayLikeSerializerSizeError = class extends Error {
295
- constructor(size) {
296
- super(`Unrecognized array-like serializer size: ${JSON.stringify(size)}`);
297
- __publicField(this, "name", "UnrecognizedArrayLikeSerializerSizeError");
298
- }
299
- };
300
-
301
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/sumSerializerSizes.mjs
302
- function sumSerializerSizes(sizes) {
303
- return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
304
- }
305
-
306
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/utils.mjs
307
- function getResolvedSize(size, childrenSizes, bytes2, offset) {
308
- if (typeof size === "number") {
309
- return [size, offset];
310
- }
311
- if (typeof size === "object") {
312
- return size.deserialize(bytes2, offset);
313
- }
314
- if (size === "remainder") {
315
- const childrenSize = sumSerializerSizes(childrenSizes);
316
- if (childrenSize === null) {
317
- throw new ExpectedFixedSizeSerializerError('Serializers of "remainder" size must have fixed-size items.');
318
- }
319
- const remainder = bytes2.slice(offset).length;
320
- if (remainder % childrenSize !== 0) {
321
- throw new InvalidArrayLikeRemainderSizeError(remainder, childrenSize);
322
- }
323
- return [remainder / childrenSize, offset];
324
- }
325
- throw new UnrecognizedArrayLikeSerializerSizeError(size);
326
- }
327
- function getSizeDescription(size) {
328
- return typeof size === "object" ? size.description : `${size}`;
329
- }
330
- function getSizeFromChildren(size, childrenSizes) {
331
- if (typeof size !== "number")
332
- return null;
333
- if (size === 0)
334
- return 0;
335
- const childrenSize = sumSerializerSizes(childrenSizes);
336
- return childrenSize === null ? null : childrenSize * size;
337
- }
338
- function getSizePrefix(size, realSize) {
339
- return typeof size === "object" ? size.serialize(realSize) : new Uint8Array();
340
- }
341
-
342
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/array.mjs
343
- function array(item, options = {}) {
344
- const size = options.size ?? u32();
345
- if (size === "remainder" && item.fixedSize === null) {
346
- throw new ExpectedFixedSizeSerializerError('Serializers of "remainder" size must have fixed-size items.');
347
- }
348
- return {
349
- description: options.description ?? `array(${item.description}; ${getSizeDescription(size)})`,
350
- fixedSize: getSizeFromChildren(size, [item.fixedSize]),
351
- maxSize: getSizeFromChildren(size, [item.maxSize]),
352
- serialize: (value) => {
353
- if (typeof size === "number" && value.length !== size) {
354
- throw new InvalidNumberOfItemsError("array", size, value.length);
355
- }
356
- return mergeBytes([getSizePrefix(size, value.length), ...value.map((v) => item.serialize(v))]);
357
- },
358
- deserialize: (bytes2, offset = 0) => {
359
- if (typeof size === "object" && bytes2.slice(offset).length === 0) {
360
- return [[], offset];
361
- }
362
- const [resolvedSize, newOffset] = getResolvedSize(size, [item.fixedSize], bytes2, offset);
363
- offset = newOffset;
364
- const values = [];
365
- for (let i = 0; i < resolvedSize; i += 1) {
366
- const [value, newOffset2] = item.deserialize(bytes2, offset);
367
- values.push(value);
368
- offset = newOffset2;
369
- }
370
- return [values, offset];
371
- }
372
- };
373
- }
374
-
375
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/bytes.mjs
376
- function bytes(options = {}) {
377
- const size = options.size ?? "variable";
378
- const description = options.description ?? `bytes(${getSizeDescription(size)})`;
379
- const byteSerializer = {
380
- description,
381
- fixedSize: null,
382
- maxSize: null,
383
- serialize: (value) => new Uint8Array(value),
384
- deserialize: (bytes2, offset = 0) => {
385
- const slice = bytes2.slice(offset);
386
- return [slice, offset + slice.length];
387
- }
388
- };
389
- if (size === "variable") {
390
- return byteSerializer;
391
- }
392
- if (typeof size === "number") {
393
- return fixSerializer(byteSerializer, size, description);
394
- }
395
- return {
396
- description,
397
- fixedSize: null,
398
- maxSize: null,
399
- serialize: (value) => {
400
- const contentBytes = byteSerializer.serialize(value);
401
- const lengthBytes = size.serialize(contentBytes.length);
402
- return mergeBytes([lengthBytes, contentBytes]);
403
- },
404
- deserialize: (buffer, offset = 0) => {
405
- if (buffer.slice(offset).length === 0) {
406
- throw new DeserializingEmptyBufferError("bytes");
407
- }
408
- const [lengthBigInt, lengthOffset] = size.deserialize(buffer, offset);
409
- const length = Number(lengthBigInt);
410
- offset = lengthOffset;
411
- const contentBuffer = buffer.slice(offset, offset + length);
412
- if (contentBuffer.length < length) {
413
- throw new NotEnoughBytesError("bytes", length, contentBuffer.length);
414
- }
415
- const [value, contentOffset] = byteSerializer.deserialize(contentBuffer);
416
- offset += contentOffset;
417
- return [value, offset];
418
- }
419
- };
420
- }
421
-
422
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/string.mjs
423
- function string(options = {}) {
424
- const size = options.size ?? u32();
425
- const encoding = options.encoding ?? utf8;
426
- const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
427
- if (size === "variable") {
428
- return {
429
- ...encoding,
430
- description
431
- };
432
- }
433
- if (typeof size === "number") {
434
- return fixSerializer(encoding, size, description);
435
- }
436
- return {
437
- description,
438
- fixedSize: null,
439
- maxSize: null,
440
- serialize: (value) => {
441
- const contentBytes = encoding.serialize(value);
442
- const lengthBytes = size.serialize(contentBytes.length);
443
- return mergeBytes([lengthBytes, contentBytes]);
444
- },
445
- deserialize: (buffer, offset = 0) => {
446
- if (buffer.slice(offset).length === 0) {
447
- throw new DeserializingEmptyBufferError("string");
448
- }
449
- const [lengthBigInt, lengthOffset] = size.deserialize(buffer, offset);
450
- const length = Number(lengthBigInt);
451
- offset = lengthOffset;
452
- const contentBuffer = buffer.slice(offset, offset + length);
453
- if (contentBuffer.length < length) {
454
- throw new NotEnoughBytesError("string", length, contentBuffer.length);
455
- }
456
- const [value, contentOffset] = encoding.deserialize(contentBuffer);
457
- offset += contentOffset;
458
- return [value, offset];
459
- }
460
- };
461
- }
462
-
463
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/struct.mjs
464
- function struct(fields, options = {}) {
465
- const fieldDescriptions = fields.map(([name, serializer]) => `${String(name)}: ${serializer.description}`).join(", ");
466
- return {
467
- description: options.description ?? `struct(${fieldDescriptions})`,
468
- fixedSize: sumSerializerSizes(fields.map(([, field]) => field.fixedSize)),
469
- maxSize: sumSerializerSizes(fields.map(([, field]) => field.maxSize)),
470
- serialize: (struct2) => {
471
- const fieldBytes = fields.map(([key, serializer]) => serializer.serialize(struct2[key]));
472
- return mergeBytes(fieldBytes);
473
- },
474
- deserialize: (bytes2, offset = 0) => {
475
- const struct2 = {};
476
- fields.forEach(([key, serializer]) => {
477
- const [value, newOffset] = serializer.deserialize(bytes2, offset);
478
- offset = newOffset;
479
- struct2[key] = value;
480
- });
481
- return [struct2, offset];
482
- }
483
- };
484
- }
485
-
486
- // src/unsigned-transaction.ts
487
- function getUnsignedTransaction(transaction) {
488
- if ("signatures" in transaction) {
489
- const {
490
- signatures: _,
491
- // eslint-disable-line @typescript-eslint/no-unused-vars
492
- ...unsignedTransaction
493
- } = transaction;
494
- return unsignedTransaction;
495
- } else {
496
- return transaction;
497
- }
498
- }
499
-
500
- // src/blockhash.ts
501
- function assertIsBlockhash(putativeBlockhash) {
502
- try {
503
- if (
504
- // Lowest value (32 bytes of zeroes)
505
- putativeBlockhash.length < 32 || // Highest value (32 bytes of 255)
506
- putativeBlockhash.length > 44
507
- ) {
508
- throw new Error("Expected input string to decode to a byte array of length 32.");
509
- }
510
- const bytes2 = base58.serialize(putativeBlockhash);
511
- const numBytes = bytes2.byteLength;
512
- if (numBytes !== 32) {
513
- throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
514
- }
515
- } catch (e2) {
516
- throw new Error(`\`${putativeBlockhash}\` is not a blockhash`, {
517
- cause: e2
518
- });
519
- }
520
- }
521
- function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {
522
- if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
523
- return transaction;
524
- }
525
- const out = {
526
- ...getUnsignedTransaction(transaction),
527
- lifetimeConstraint: blockhashLifetimeConstraint
528
- };
529
- Object.freeze(out);
530
- return out;
531
- }
532
-
533
- // src/create-transaction.ts
534
- function createTransaction({
535
- version
536
- }) {
537
- const out = {
538
- instructions: [],
539
- version
540
- };
541
- Object.freeze(out);
542
- return out;
543
- }
544
-
545
- // ../instructions/dist/index.browser.js
546
- var AccountRole = /* @__PURE__ */ ((AccountRole2) => {
547
- AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */
548
- 3] = "WRITABLE_SIGNER";
549
- AccountRole2[AccountRole2["READONLY_SIGNER"] = /* 2 */
550
- 2] = "READONLY_SIGNER";
551
- AccountRole2[AccountRole2["WRITABLE"] = /* 1 */
552
- 1] = "WRITABLE";
553
- AccountRole2[AccountRole2["READONLY"] = /* 0 */
554
- 0] = "READONLY";
555
- return AccountRole2;
556
- })(AccountRole || {});
557
- var IS_WRITABLE_BITMASK = 1;
558
- function isSignerRole(role) {
559
- return role >= 2;
560
- }
561
- function isWritableRole(role) {
562
- return (role & IS_WRITABLE_BITMASK) !== 0;
563
- }
564
- function mergeRoles(roleA, roleB) {
565
- return roleA | roleB;
566
- }
567
-
568
- // src/durable-nonce.ts
569
- var RECENT_BLOCKHASHES_SYSVAR_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111";
570
- var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
571
- function assertIsDurableNonceTransaction(transaction) {
572
- if (!isDurableNonceTransaction(transaction)) {
573
- throw new Error("Transaction is not a durable nonce transaction");
574
- }
575
- }
576
- function createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress) {
577
- return {
578
- accounts: [
579
- { address: nonceAccountAddress, role: AccountRole.WRITABLE },
580
- {
581
- address: RECENT_BLOCKHASHES_SYSVAR_ADDRESS,
582
- role: AccountRole.READONLY
583
- },
584
- { address: nonceAuthorityAddress, role: AccountRole.READONLY_SIGNER }
585
- ],
586
- data: new Uint8Array([4, 0, 0, 0]),
587
- programAddress: SYSTEM_PROGRAM_ADDRESS
588
- };
589
- }
590
- function isAdvanceNonceAccountInstruction(instruction) {
591
- return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
592
- instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts
593
- instruction.accounts?.length === 3 && // First account is nonce account address
594
- instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole.WRITABLE && // Second account is recent blockhashes sysvar
595
- instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole.READONLY && // Third account is nonce authority account
596
- instruction.accounts[2].address != null && instruction.accounts[2].role === AccountRole.READONLY_SIGNER;
597
- }
598
- function isAdvanceNonceAccountInstructionData(data) {
599
- return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
600
- }
601
- function isDurableNonceTransaction(transaction) {
602
- return "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.nonce === "string" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]);
603
- }
604
- function setTransactionLifetimeUsingDurableNonce({
605
- nonce,
606
- nonceAccountAddress,
607
- nonceAuthorityAddress
608
- }, transaction) {
609
- const isAlreadyDurableNonceTransaction = isDurableNonceTransaction(transaction);
610
- if (isAlreadyDurableNonceTransaction && transaction.lifetimeConstraint.nonce === nonce && transaction.instructions[0].accounts[0].address === nonceAccountAddress && transaction.instructions[0].accounts[2].address === nonceAuthorityAddress) {
611
- return transaction;
612
- }
613
- const out = {
614
- ...getUnsignedTransaction(transaction),
615
- instructions: [
616
- createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
617
- ...isAlreadyDurableNonceTransaction ? transaction.instructions.slice(1) : transaction.instructions
618
- ],
619
- lifetimeConstraint: {
620
- nonce
621
- }
622
- };
623
- Object.freeze(out);
624
- return out;
625
- }
626
-
627
- // src/fee-payer.ts
628
- function setTransactionFeePayer(feePayer, transaction) {
629
- if ("feePayer" in transaction && feePayer === transaction.feePayer) {
630
- return transaction;
631
- }
632
- const out = {
633
- ...getUnsignedTransaction(transaction),
634
- feePayer
635
- };
636
- Object.freeze(out);
637
- return out;
638
- }
639
-
640
- // src/instructions.ts
641
- function appendTransactionInstruction(instruction, transaction) {
642
- const out = {
643
- ...getUnsignedTransaction(transaction),
644
- instructions: [...transaction.instructions, instruction]
645
- };
646
- Object.freeze(out);
647
- return out;
648
- }
649
- function prependTransactionInstruction(instruction, transaction) {
650
- const out = {
651
- ...getUnsignedTransaction(transaction),
652
- instructions: [instruction, ...transaction.instructions]
653
- };
654
- Object.freeze(out);
655
- return out;
656
- }
657
-
658
- // ../codecs-core/dist/index.browser.js
659
- function assertByteArrayIsNotEmptyForCodec(codecDescription, bytes2, offset = 0) {
660
- if (bytes2.length - offset <= 0) {
661
- throw new Error(`Codec [${codecDescription}] cannot decode empty byte arrays.`);
662
- }
663
- }
664
- function assertByteArrayHasEnoughBytesForCodec(codecDescription, expected, bytes2, offset = 0) {
665
- const bytesLength = bytes2.length - offset;
666
- if (bytesLength < expected) {
667
- throw new Error(`Codec [${codecDescription}] expected ${expected} bytes, got ${bytesLength}.`);
668
- }
669
- }
670
- var mergeBytes2 = (byteArrays) => {
671
- const nonEmptyByteArrays = byteArrays.filter((arr) => arr.length);
672
- if (nonEmptyByteArrays.length === 0) {
673
- return byteArrays.length ? byteArrays[0] : new Uint8Array();
674
- }
675
- if (nonEmptyByteArrays.length === 1) {
676
- return nonEmptyByteArrays[0];
677
- }
678
- const totalLength = nonEmptyByteArrays.reduce((total, arr) => total + arr.length, 0);
679
- const result = new Uint8Array(totalLength);
680
- let offset = 0;
681
- nonEmptyByteArrays.forEach((arr) => {
682
- result.set(arr, offset);
683
- offset += arr.length;
684
- });
685
- return result;
686
- };
687
- var padBytes2 = (bytes2, length) => {
688
- if (bytes2.length >= length)
689
- return bytes2;
690
- const paddedBytes = new Uint8Array(length).fill(0);
691
- paddedBytes.set(bytes2);
692
- return paddedBytes;
693
- };
694
- var fixBytes2 = (bytes2, length) => padBytes2(bytes2.length <= length ? bytes2 : bytes2.slice(0, length), length);
695
- function combineCodec(encoder, decoder, description) {
696
- if (encoder.fixedSize !== decoder.fixedSize) {
697
- throw new Error(
698
- `Encoder and decoder must have the same fixed size, got [${encoder.fixedSize}] and [${decoder.fixedSize}].`
699
- );
700
- }
701
- if (encoder.maxSize !== decoder.maxSize) {
702
- throw new Error(
703
- `Encoder and decoder must have the same max size, got [${encoder.maxSize}] and [${decoder.maxSize}].`
704
- );
705
- }
706
- if (description === void 0 && encoder.description !== decoder.description) {
707
- throw new Error(
708
- `Encoder and decoder must have the same description, got [${encoder.description}] and [${decoder.description}]. Pass a custom description as a third argument if you want to override the description and bypass this error.`
709
- );
710
- }
711
- return {
712
- decode: decoder.decode,
713
- description: description ?? encoder.description,
714
- encode: encoder.encode,
715
- fixedSize: encoder.fixedSize,
716
- maxSize: encoder.maxSize
717
- };
718
- }
719
- function fixCodecHelper(data, fixedBytes, description) {
720
- return {
721
- description: description ?? `fixed(${fixedBytes}, ${data.description})`,
722
- fixedSize: fixedBytes,
723
- maxSize: fixedBytes
724
- };
725
- }
726
- function fixEncoder(encoder, fixedBytes, description) {
727
- return {
728
- ...fixCodecHelper(encoder, fixedBytes, description),
729
- encode: (value) => fixBytes2(encoder.encode(value), fixedBytes)
730
- };
731
- }
732
- function fixDecoder(decoder, fixedBytes, description) {
733
- return {
734
- ...fixCodecHelper(decoder, fixedBytes, description),
735
- decode: (bytes2, offset = 0) => {
736
- assertByteArrayHasEnoughBytesForCodec("fixCodec", fixedBytes, bytes2, offset);
737
- if (offset > 0 || bytes2.length > fixedBytes) {
738
- bytes2 = bytes2.slice(offset, offset + fixedBytes);
739
- }
740
- if (decoder.fixedSize !== null) {
741
- bytes2 = fixBytes2(bytes2, decoder.fixedSize);
742
- }
743
- const [value] = decoder.decode(bytes2, 0);
744
- return [value, offset + fixedBytes];
745
- }
746
- };
747
- }
748
- function mapEncoder(encoder, unmap) {
749
- return {
750
- description: encoder.description,
751
- encode: (value) => encoder.encode(unmap(value)),
752
- fixedSize: encoder.fixedSize,
753
- maxSize: encoder.maxSize
754
- };
755
- }
756
- function mapDecoder(decoder, map) {
757
- return {
758
- decode: (bytes2, offset = 0) => {
759
- const [value, length] = decoder.decode(bytes2, offset);
760
- return [map(value, bytes2, offset), length];
761
- },
762
- description: decoder.description,
763
- fixedSize: decoder.fixedSize,
764
- maxSize: decoder.maxSize
765
- };
766
- }
767
-
768
- // ../codecs-numbers/dist/index.browser.js
769
- function assertNumberIsBetweenForCodec(codecDescription, min, max, value) {
770
- if (value < min || value > max) {
771
- throw new Error(
772
- `Codec [${codecDescription}] expected number to be in the range [${min}, ${max}], got ${value}.`
773
- );
774
- }
775
- }
776
- function sharedNumberFactory(input) {
777
- let littleEndian;
778
- let defaultDescription = input.name;
779
- if (input.size > 1) {
780
- littleEndian = !("endian" in input.options) || input.options.endian === 0;
781
- defaultDescription += littleEndian ? "(le)" : "(be)";
782
- }
783
- return {
784
- description: input.options.description ?? defaultDescription,
785
- fixedSize: input.size,
786
- littleEndian,
787
- maxSize: input.size
788
- };
789
- }
790
- function numberEncoderFactory(input) {
791
- const codecData = sharedNumberFactory(input);
792
- return {
793
- description: codecData.description,
794
- encode(value) {
795
- if (input.range) {
796
- assertNumberIsBetweenForCodec(input.name, input.range[0], input.range[1], value);
797
- }
798
- const arrayBuffer = new ArrayBuffer(input.size);
799
- input.set(new DataView(arrayBuffer), value, codecData.littleEndian);
800
- return new Uint8Array(arrayBuffer);
801
- },
802
- fixedSize: codecData.fixedSize,
803
- maxSize: codecData.maxSize
804
- };
805
- }
806
- function numberDecoderFactory(input) {
807
- const codecData = sharedNumberFactory(input);
808
- return {
809
- decode(bytes2, offset = 0) {
810
- assertByteArrayIsNotEmptyForCodec(codecData.description, bytes2, offset);
811
- assertByteArrayHasEnoughBytesForCodec(codecData.description, input.size, bytes2, offset);
812
- const view = new DataView(toArrayBuffer2(bytes2, offset, input.size));
813
- return [input.get(view, codecData.littleEndian), offset + input.size];
814
- },
815
- description: codecData.description,
816
- fixedSize: codecData.fixedSize,
817
- maxSize: codecData.maxSize
818
- };
819
- }
820
- function toArrayBuffer2(bytes2, offset, length) {
821
- const bytesOffset = bytes2.byteOffset + (offset ?? 0);
822
- const bytesLength = length ?? bytes2.byteLength;
823
- return bytes2.buffer.slice(bytesOffset, bytesOffset + bytesLength);
824
- }
825
- var getShortU16Encoder = (options = {}) => ({
826
- description: options.description ?? "shortU16",
827
- encode: (value) => {
828
- assertNumberIsBetweenForCodec("shortU16", 0, 65535, value);
829
- const bytes2 = [0];
830
- for (let ii = 0; ; ii += 1) {
831
- const alignedValue = value >> ii * 7;
832
- if (alignedValue === 0) {
833
- break;
834
- }
835
- const nextSevenBits = 127 & alignedValue;
836
- bytes2[ii] = nextSevenBits;
837
- if (ii > 0) {
838
- bytes2[ii - 1] |= 128;
839
- }
840
- }
841
- return new Uint8Array(bytes2);
842
- },
843
- fixedSize: null,
844
- maxSize: 3
845
- });
846
- var getShortU16Decoder = (options = {}) => ({
847
- decode: (bytes2, offset = 0) => {
848
- let value = 0;
849
- let byteCount = 0;
850
- while (++byteCount) {
851
- const byteIndex = byteCount - 1;
852
- const currentByte = bytes2[offset + byteIndex];
853
- const nextSevenBits = 127 & currentByte;
854
- value |= nextSevenBits << byteIndex * 7;
855
- if ((currentByte & 128) === 0) {
856
- break;
857
- }
858
- }
859
- return [value, offset + byteCount];
860
- },
861
- description: options.description ?? "shortU16",
862
- fixedSize: null,
863
- maxSize: 3
864
- });
865
- var getU32Encoder = (options = {}) => numberEncoderFactory({
866
- name: "u32",
867
- options,
868
- range: [0, Number("0xffffffff")],
869
- set: (view, value, le) => view.setUint32(0, value, le),
870
- size: 4
871
- });
872
- var getU32Decoder = (options = {}) => numberDecoderFactory({
873
- get: (view, le) => view.getUint32(0, le),
874
- name: "u32",
875
- options,
876
- size: 4
877
- });
878
- var getU8Encoder = (options = {}) => numberEncoderFactory({
879
- name: "u8",
880
- options,
881
- range: [0, Number("0xff")],
882
- set: (view, value) => view.setUint8(0, value),
883
- size: 1
884
- });
885
- var getU8Decoder = (options = {}) => numberDecoderFactory({
886
- get: (view) => view.getUint8(0),
887
- name: "u8",
888
- options,
889
- size: 1
890
- });
891
- var getU8Codec = (options = {}) => combineCodec(getU8Encoder(options), getU8Decoder(options));
892
-
893
- // ../codecs-strings/dist/index.browser.js
894
- function assertValidBaseString(alphabet4, testValue, givenValue = testValue) {
895
- if (!testValue.match(new RegExp(`^[${alphabet4}]*$`))) {
896
- throw new Error(`Expected a string of base ${alphabet4.length}, got [${givenValue}].`);
897
- }
898
- }
899
- var getBaseXEncoder = (alphabet4) => {
900
- const base = alphabet4.length;
901
- const baseBigInt = BigInt(base);
902
- return {
903
- description: `base${base}`,
904
- encode(value) {
905
- assertValidBaseString(alphabet4, value);
906
- if (value === "")
907
- return new Uint8Array();
908
- const chars = [...value];
909
- let trailIndex = chars.findIndex((c) => c !== alphabet4[0]);
910
- trailIndex = trailIndex === -1 ? chars.length : trailIndex;
911
- const leadingZeroes = Array(trailIndex).fill(0);
912
- if (trailIndex === chars.length)
913
- return Uint8Array.from(leadingZeroes);
914
- const tailChars = chars.slice(trailIndex);
915
- let base10Number = 0n;
916
- let baseXPower = 1n;
917
- for (let i = tailChars.length - 1; i >= 0; i -= 1) {
918
- base10Number += baseXPower * BigInt(alphabet4.indexOf(tailChars[i]));
919
- baseXPower *= baseBigInt;
920
- }
921
- const tailBytes = [];
922
- while (base10Number > 0n) {
923
- tailBytes.unshift(Number(base10Number % 256n));
924
- base10Number /= 256n;
925
- }
926
- return Uint8Array.from(leadingZeroes.concat(tailBytes));
927
- },
928
- fixedSize: null,
929
- maxSize: null
930
- };
931
- };
932
- var getBaseXDecoder = (alphabet4) => {
933
- const base = alphabet4.length;
934
- const baseBigInt = BigInt(base);
935
- return {
936
- decode(rawBytes, offset = 0) {
937
- const bytes2 = offset === 0 ? rawBytes : rawBytes.slice(offset);
938
- if (bytes2.length === 0)
939
- return ["", 0];
940
- let trailIndex = bytes2.findIndex((n) => n !== 0);
941
- trailIndex = trailIndex === -1 ? bytes2.length : trailIndex;
942
- const leadingZeroes = alphabet4[0].repeat(trailIndex);
943
- if (trailIndex === bytes2.length)
944
- return [leadingZeroes, rawBytes.length];
945
- let base10Number = bytes2.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
946
- const tailChars = [];
947
- while (base10Number > 0n) {
948
- tailChars.unshift(alphabet4[Number(base10Number % baseBigInt)]);
949
- base10Number /= baseBigInt;
950
- }
951
- return [leadingZeroes + tailChars.join(""), rawBytes.length];
952
- },
953
- description: `base${base}`,
954
- fixedSize: null,
955
- maxSize: null
956
- };
957
- };
958
- var alphabet2 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
959
- var getBase58Encoder = () => getBaseXEncoder(alphabet2);
960
- var getBase58Decoder = () => getBaseXDecoder(alphabet2);
961
- var removeNullCharacters2 = (value) => (
962
- // eslint-disable-next-line no-control-regex
963
- value.replace(/\u0000/g, "")
964
- );
965
- var e = globalThis.TextDecoder;
966
- var o = globalThis.TextEncoder;
967
- var getUtf8Encoder = () => {
968
- let textEncoder;
969
- return {
970
- description: "utf8",
971
- encode: (value) => new Uint8Array((textEncoder || (textEncoder = new o())).encode(value)),
972
- fixedSize: null,
973
- maxSize: null
974
- };
975
- };
976
- var getUtf8Decoder = () => {
977
- let textDecoder;
978
- return {
979
- decode(bytes2, offset = 0) {
980
- const value = (textDecoder || (textDecoder = new e())).decode(bytes2.slice(offset));
981
- return [removeNullCharacters2(value), bytes2.length];
982
- },
983
- description: "utf8",
984
- fixedSize: null,
985
- maxSize: null
986
- };
987
- };
988
- var getStringEncoder = (options = {}) => {
989
- const size = options.size ?? getU32Encoder();
990
- const encoding = options.encoding ?? getUtf8Encoder();
991
- const description = options.description ?? `string(${encoding.description}; ${getSizeDescription2(size)})`;
992
- if (size === "variable") {
993
- return { ...encoding, description };
994
- }
995
- if (typeof size === "number") {
996
- return fixEncoder(encoding, size, description);
997
- }
998
- return {
999
- description,
1000
- encode: (value) => {
1001
- const contentBytes = encoding.encode(value);
1002
- const lengthBytes = size.encode(contentBytes.length);
1003
- return mergeBytes2([lengthBytes, contentBytes]);
1004
- },
1005
- fixedSize: null,
1006
- maxSize: null
1007
- };
1008
- };
1009
- var getStringDecoder = (options = {}) => {
1010
- const size = options.size ?? getU32Decoder();
1011
- const encoding = options.encoding ?? getUtf8Decoder();
1012
- const description = options.description ?? `string(${encoding.description}; ${getSizeDescription2(size)})`;
1013
- if (size === "variable") {
1014
- return { ...encoding, description };
1015
- }
1016
- if (typeof size === "number") {
1017
- return fixDecoder(encoding, size, description);
1018
- }
1019
- return {
1020
- decode: (bytes2, offset = 0) => {
1021
- assertByteArrayIsNotEmptyForCodec("string", bytes2, offset);
1022
- const [lengthBigInt, lengthOffset] = size.decode(bytes2, offset);
1023
- const length = Number(lengthBigInt);
1024
- offset = lengthOffset;
1025
- const contentBytes = bytes2.slice(offset, offset + length);
1026
- assertByteArrayHasEnoughBytesForCodec("string", length, contentBytes);
1027
- const [value, contentOffset] = encoding.decode(contentBytes);
1028
- offset += contentOffset;
1029
- return [value, offset];
1030
- },
1031
- description,
1032
- fixedSize: null,
1033
- maxSize: null
1034
- };
1035
- };
1036
- function getSizeDescription2(size) {
1037
- return typeof size === "object" ? size.description : `${size}`;
1038
- }
1039
-
1040
- // ../assertions/dist/index.browser.js
1041
- function assertIsSecureContext() {
1042
- if (!globalThis.isSecureContext) {
1043
- throw new Error(
1044
- "Cryptographic operations are only allowed in secure browser contexts. Read more here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts"
1045
- );
1046
- }
1047
- }
1048
- async function assertKeyExporterIsAvailable() {
1049
- assertIsSecureContext();
1050
- if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.exportKey !== "function") {
1051
- throw new Error("No key export implementation could be found");
1052
- }
1053
- }
1054
- async function assertSigningCapabilityIsAvailable() {
1055
- assertIsSecureContext();
1056
- if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.sign !== "function") {
1057
- throw new Error("No signing implementation could be found");
1058
- }
1059
- }
1060
-
1061
- // ../addresses/dist/index.browser.js
1062
- var memoizedBase58Encoder;
1063
- var memoizedBase58Decoder;
1064
- function getMemoizedBase58Encoder() {
1065
- if (!memoizedBase58Encoder)
1066
- memoizedBase58Encoder = getBase58Encoder();
1067
- return memoizedBase58Encoder;
1068
- }
1069
- function getMemoizedBase58Decoder() {
1070
- if (!memoizedBase58Decoder)
1071
- memoizedBase58Decoder = getBase58Decoder();
1072
- return memoizedBase58Decoder;
1073
- }
1074
- function assertIsAddress(putativeBase58EncodedAddress) {
1075
- try {
1076
- if (
1077
- // Lowest address (32 bytes of zeroes)
1078
- putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
1079
- putativeBase58EncodedAddress.length > 44
1080
- ) {
1081
- throw new Error("Expected input string to decode to a byte array of length 32.");
1082
- }
1083
- const base58Encoder = getMemoizedBase58Encoder();
1084
- const bytes2 = base58Encoder.encode(putativeBase58EncodedAddress);
1085
- const numBytes = bytes2.byteLength;
1086
- if (numBytes !== 32) {
1087
- throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
1088
- }
1089
- } catch (e2) {
1090
- throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
1091
- cause: e2
1092
- });
1093
- }
1094
- }
1095
- function address(putativeBase58EncodedAddress) {
1096
- assertIsAddress(putativeBase58EncodedAddress);
1097
- return putativeBase58EncodedAddress;
1098
- }
1099
- function getAddressEncoder(config) {
1100
- return mapEncoder(
1101
- getStringEncoder({
1102
- description: config?.description ?? "Base58EncodedAddress",
1103
- encoding: getMemoizedBase58Encoder(),
1104
- size: 32
1105
- }),
1106
- (putativeAddress) => address(putativeAddress)
1107
- );
1108
- }
1109
- function getAddressDecoder(config) {
1110
- return getStringDecoder({
1111
- description: config?.description ?? "Base58EncodedAddress",
1112
- encoding: getMemoizedBase58Decoder(),
1113
- size: 32
1114
- });
1115
- }
1116
- function getAddressCodec(config) {
1117
- return combineCodec(getAddressEncoder(config), getAddressDecoder(config));
1118
- }
1119
- function getAddressComparator() {
1120
- return new Intl.Collator("en", {
1121
- caseFirst: "lower",
1122
- ignorePunctuation: false,
1123
- localeMatcher: "best fit",
1124
- numeric: false,
1125
- sensitivity: "variant",
1126
- usage: "sort"
1127
- }).compare;
1128
- }
1129
- async function getAddressFromPublicKey(publicKey) {
1130
- await assertKeyExporterIsAvailable();
1131
- if (publicKey.type !== "public" || publicKey.algorithm.name !== "Ed25519") {
1132
- throw new Error("The `CryptoKey` must be an `Ed25519` public key");
1133
- }
1134
- const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
1135
- const [base58EncodedAddress] = getAddressDecoder().decode(new Uint8Array(publicKeyBytes));
1136
- return base58EncodedAddress;
1137
- }
1138
-
1139
- // src/accounts.ts
1140
- function upsert(addressMap, address2, update) {
1141
- addressMap[address2] = update(addressMap[address2] ?? { role: AccountRole.READONLY });
1142
- }
1143
- var TYPE = Symbol("AddressMapTypeProperty");
1144
- function getAddressMapFromInstructions(feePayer, instructions) {
1145
- const addressMap = {
1146
- [feePayer]: { [TYPE]: 0 /* FEE_PAYER */, role: AccountRole.WRITABLE_SIGNER }
1147
- };
1148
- const addressesOfInvokedPrograms = /* @__PURE__ */ new Set();
1149
- for (const instruction of instructions) {
1150
- upsert(addressMap, instruction.programAddress, (entry) => {
1151
- addressesOfInvokedPrograms.add(instruction.programAddress);
1152
- if (TYPE in entry) {
1153
- if (isWritableRole(entry.role)) {
1154
- switch (entry[TYPE]) {
1155
- case 0 /* FEE_PAYER */:
1156
- throw new Error(
1157
- `This transaction includes an address (\`${instruction.programAddress}\`) which is both invoked and set as the fee payer. Program addresses may not pay fees.`
1158
- );
1159
- default:
1160
- throw new Error(
1161
- `This transaction includes an address (\`${instruction.programAddress}\`) which is both invoked and marked writable. Program addresses may not be writable.`
1162
- );
1163
- }
1164
- }
1165
- if (entry[TYPE] === 2 /* STATIC */) {
1166
- return entry;
1167
- }
1168
- }
1169
- return { [TYPE]: 2 /* STATIC */, role: AccountRole.READONLY };
1170
- });
1171
- let addressComparator;
1172
- if (!instruction.accounts) {
1173
- continue;
1174
- }
1175
- for (const account of instruction.accounts) {
1176
- upsert(addressMap, account.address, (entry) => {
1177
- const {
1178
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1179
- address: _,
1180
- ...accountMeta
1181
- } = account;
1182
- if (TYPE in entry) {
1183
- switch (entry[TYPE]) {
1184
- case 0 /* FEE_PAYER */:
1185
- return entry;
1186
- case 1 /* LOOKUP_TABLE */: {
1187
- const nextRole = mergeRoles(entry.role, accountMeta.role);
1188
- if ("lookupTableAddress" in accountMeta) {
1189
- const shouldReplaceEntry = (
1190
- // Consider using the new LOOKUP_TABLE if its address is different...
1191
- entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
1192
- (addressComparator || (addressComparator = getAddressComparator()))(
1193
- accountMeta.lookupTableAddress,
1194
- entry.lookupTableAddress
1195
- ) < 0
1196
- );
1197
- if (shouldReplaceEntry) {
1198
- return {
1199
- [TYPE]: 1 /* LOOKUP_TABLE */,
1200
- ...accountMeta,
1201
- role: nextRole
1202
- };
1203
- }
1204
- } else if (isSignerRole(accountMeta.role)) {
1205
- return {
1206
- [TYPE]: 2 /* STATIC */,
1207
- role: nextRole
1208
- };
1209
- }
1210
- if (entry.role !== nextRole) {
1211
- return {
1212
- ...entry,
1213
- role: nextRole
1214
- };
1215
- } else {
1216
- return entry;
1217
- }
1218
- }
1219
- case 2 /* STATIC */: {
1220
- const nextRole = mergeRoles(entry.role, accountMeta.role);
1221
- if (
1222
- // Check to see if this address represents a program that is invoked
1223
- // in this transaction.
1224
- addressesOfInvokedPrograms.has(account.address)
1225
- ) {
1226
- if (isWritableRole(accountMeta.role)) {
1227
- throw new Error(
1228
- `This transaction includes an address (\`${account.address}\`) which is both invoked and marked writable. Program addresses may not be writable.`
1229
- );
1230
- }
1231
- if (entry.role !== nextRole) {
1232
- return {
1233
- ...entry,
1234
- role: nextRole
1235
- };
1236
- } else {
1237
- return entry;
1238
- }
1239
- } else if ("lookupTableAddress" in accountMeta && // Static accounts can be 'upgraded' to lookup table accounts as
1240
- // long as they are not require to sign the transaction.
1241
- !isSignerRole(entry.role)) {
1242
- return {
1243
- ...accountMeta,
1244
- [TYPE]: 1 /* LOOKUP_TABLE */,
1245
- role: nextRole
1246
- };
1247
- } else {
1248
- if (entry.role !== nextRole) {
1249
- return {
1250
- ...entry,
1251
- role: nextRole
1252
- };
1253
- } else {
1254
- return entry;
1255
- }
1256
- }
1257
- }
1258
- }
1259
- }
1260
- if ("lookupTableAddress" in accountMeta) {
1261
- return {
1262
- ...accountMeta,
1263
- [TYPE]: 1 /* LOOKUP_TABLE */
1264
- };
1265
- } else {
1266
- return {
1267
- ...accountMeta,
1268
- [TYPE]: 2 /* STATIC */
1269
- };
1270
- }
1271
- });
1272
- }
1273
- }
1274
- return addressMap;
1275
- }
1276
- function getOrderedAccountsFromAddressMap(addressMap) {
1277
- let addressComparator;
1278
- const orderedAccounts = Object.entries(addressMap).sort(([leftAddress, leftEntry], [rightAddress, rightEntry]) => {
1279
- if (leftEntry[TYPE] !== rightEntry[TYPE]) {
1280
- if (leftEntry[TYPE] === 0 /* FEE_PAYER */) {
1281
- return -1;
1282
- } else if (rightEntry[TYPE] === 0 /* FEE_PAYER */) {
1283
- return 1;
1284
- } else if (leftEntry[TYPE] === 2 /* STATIC */) {
1285
- return -1;
1286
- } else if (rightEntry[TYPE] === 2 /* STATIC */) {
1287
- return 1;
1288
- }
1289
- }
1290
- const leftIsSigner = isSignerRole(leftEntry.role);
1291
- if (leftIsSigner !== isSignerRole(rightEntry.role)) {
1292
- return leftIsSigner ? -1 : 1;
1293
- }
1294
- const leftIsWritable = isWritableRole(leftEntry.role);
1295
- if (leftIsWritable !== isWritableRole(rightEntry.role)) {
1296
- return leftIsWritable ? -1 : 1;
1297
- }
1298
- addressComparator || (addressComparator = getAddressComparator());
1299
- if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
1300
- return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
1301
- } else {
1302
- return addressComparator(leftAddress, rightAddress);
1303
- }
1304
- }).map(([address2, addressMeta]) => ({
1305
- address: address2,
1306
- ...addressMeta
1307
- }));
1308
- return orderedAccounts;
1309
- }
1310
-
1311
- // src/compile-address-table-lookups.ts
1312
- function getCompiledAddressTableLookups(orderedAccounts) {
1313
- var _a;
1314
- const index = {};
1315
- for (const account of orderedAccounts) {
1316
- if (!("lookupTableAddress" in account)) {
1317
- continue;
1318
- }
1319
- const entry = index[_a = account.lookupTableAddress] || (index[_a] = {
1320
- readableIndices: [],
1321
- writableIndices: []
1322
- });
1323
- if (account.role === AccountRole.WRITABLE) {
1324
- entry.writableIndices.push(account.addressIndex);
1325
- } else {
1326
- entry.readableIndices.push(account.addressIndex);
1327
- }
1328
- }
1329
- return Object.keys(index).sort(getAddressComparator()).map((lookupTableAddress) => ({
1330
- lookupTableAddress,
1331
- ...index[lookupTableAddress]
1332
- }));
1333
- }
1334
-
1335
- // src/compile-header.ts
1336
- function getCompiledMessageHeader(orderedAccounts) {
1337
- let numReadonlyNonSignerAccounts = 0;
1338
- let numReadonlySignerAccounts = 0;
1339
- let numSignerAccounts = 0;
1340
- for (const account of orderedAccounts) {
1341
- if ("lookupTableAddress" in account) {
1342
- break;
1343
- }
1344
- const accountIsWritable = isWritableRole(account.role);
1345
- if (isSignerRole(account.role)) {
1346
- numSignerAccounts++;
1347
- if (!accountIsWritable) {
1348
- numReadonlySignerAccounts++;
1349
- }
1350
- } else if (!accountIsWritable) {
1351
- numReadonlyNonSignerAccounts++;
1352
- }
1353
- }
1354
- return {
1355
- numReadonlyNonSignerAccounts,
1356
- numReadonlySignerAccounts,
1357
- numSignerAccounts
1358
- };
1359
- }
1360
-
1361
- // src/compile-instructions.ts
1362
- function getAccountIndex(orderedAccounts) {
1363
- const out = {};
1364
- for (const [index, account] of orderedAccounts.entries()) {
1365
- out[account.address] = index;
1366
- }
1367
- return out;
1368
- }
1369
- function getCompiledInstructions(instructions, orderedAccounts) {
1370
- const accountIndex = getAccountIndex(orderedAccounts);
1371
- return instructions.map(({ accounts, data, programAddress }) => {
1372
- return {
1373
- programAddressIndex: accountIndex[programAddress],
1374
- ...accounts ? { accountIndices: accounts.map(({ address: address2 }) => accountIndex[address2]) } : null,
1375
- ...data ? { data } : null
1376
- };
1377
- });
1378
- }
1379
-
1380
- // src/compile-lifetime-token.ts
1381
- function getCompiledLifetimeToken(lifetimeConstraint) {
1382
- if ("nonce" in lifetimeConstraint) {
1383
- return lifetimeConstraint.nonce;
1384
- }
1385
- return lifetimeConstraint.blockhash;
1386
- }
1387
-
1388
- // src/compile-static-accounts.ts
1389
- function getCompiledStaticAccounts(orderedAccounts) {
1390
- const firstLookupTableAccountIndex = orderedAccounts.findIndex((account) => "lookupTableAddress" in account);
1391
- const orderedStaticAccounts = firstLookupTableAccountIndex === -1 ? orderedAccounts : orderedAccounts.slice(0, firstLookupTableAccountIndex);
1392
- return orderedStaticAccounts.map(({ address: address2 }) => address2);
1393
- }
1394
-
1395
- // src/message.ts
1396
- function compileMessage(transaction) {
1397
- const addressMap = getAddressMapFromInstructions(transaction.feePayer, transaction.instructions);
1398
- const orderedAccounts = getOrderedAccountsFromAddressMap(addressMap);
1399
- return {
1400
- ...transaction.version !== "legacy" ? { addressTableLookups: getCompiledAddressTableLookups(orderedAccounts) } : null,
1401
- header: getCompiledMessageHeader(orderedAccounts),
1402
- instructions: getCompiledInstructions(transaction.instructions, orderedAccounts),
1403
- lifetimeToken: getCompiledLifetimeToken(transaction.lifetimeConstraint),
1404
- staticAccounts: getCompiledStaticAccounts(orderedAccounts),
1405
- version: transaction.version
1406
- };
1407
- }
1408
-
1409
- // src/compile-transaction.ts
1410
- function getCompiledTransaction(transaction) {
1411
- const compiledMessage = compileMessage(transaction);
1412
- let signatures;
1413
- if ("signatures" in transaction) {
1414
- signatures = [];
1415
- for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
1416
- signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
1417
- }
1418
- } else {
1419
- signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
1420
- }
1421
- return {
1422
- compiledMessage,
1423
- signatures
1424
- };
1425
- }
1426
-
1427
- // ../codecs-data-structures/dist/index.browser.js
1428
- function sumCodecSizes(sizes) {
1429
- return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
1430
- }
1431
- function decodeArrayLikeCodecSize(size, childrenSizes, bytes2, offset) {
1432
- if (typeof size === "number") {
1433
- return [size, offset];
1434
- }
1435
- if (typeof size === "object") {
1436
- return size.decode(bytes2, offset);
1437
- }
1438
- if (size === "remainder") {
1439
- const childrenSize = sumCodecSizes(childrenSizes);
1440
- if (childrenSize === null) {
1441
- throw new Error('Codecs of "remainder" size must have fixed-size items.');
1442
- }
1443
- const remainder = bytes2.slice(offset).length;
1444
- if (remainder % childrenSize !== 0) {
1445
- throw new Error(
1446
- `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.`
1447
- );
1448
- }
1449
- return [remainder / childrenSize, offset];
1450
- }
1451
- throw new Error(`Unrecognized array-like codec size: ${JSON.stringify(size)}`);
1452
- }
1453
- function getArrayLikeCodecSizeDescription(size) {
1454
- return typeof size === "object" ? size.description : `${size}`;
1455
- }
1456
- function getArrayLikeCodecSizeFromChildren(size, childrenSizes) {
1457
- if (typeof size !== "number")
1458
- return null;
1459
- if (size === 0)
1460
- return 0;
1461
- const childrenSize = sumCodecSizes(childrenSizes);
1462
- return childrenSize === null ? null : childrenSize * size;
1463
- }
1464
- function getArrayLikeCodecSizePrefix(size, realSize) {
1465
- return typeof size === "object" ? size.encode(realSize) : new Uint8Array();
1466
- }
1467
- function assertValidNumberOfItemsForCodec(codecDescription, expected, actual) {
1468
- if (expected !== actual) {
1469
- throw new Error(`Expected [${codecDescription}] to have ${expected} items, got ${actual}.`);
1470
- }
1471
- }
1472
- function arrayCodecHelper(item, size, description) {
1473
- if (size === "remainder" && item.fixedSize === null) {
1474
- throw new Error('Codecs of "remainder" size must have fixed-size items.');
1475
- }
1476
- return {
1477
- description: description ?? `array(${item.description}; ${getArrayLikeCodecSizeDescription(size)})`,
1478
- fixedSize: getArrayLikeCodecSizeFromChildren(size, [item.fixedSize]),
1479
- maxSize: getArrayLikeCodecSizeFromChildren(size, [item.maxSize])
1480
- };
1481
- }
1482
- function getArrayEncoder(item, options = {}) {
1483
- const size = options.size ?? getU32Encoder();
1484
- return {
1485
- ...arrayCodecHelper(item, size, options.description),
1486
- encode: (value) => {
1487
- if (typeof size === "number") {
1488
- assertValidNumberOfItemsForCodec("array", size, value.length);
1489
- }
1490
- return mergeBytes2([getArrayLikeCodecSizePrefix(size, value.length), ...value.map((v) => item.encode(v))]);
1491
- }
1492
- };
1493
- }
1494
- function getArrayDecoder(item, options = {}) {
1495
- const size = options.size ?? getU32Decoder();
1496
- return {
1497
- ...arrayCodecHelper(item, size, options.description),
1498
- decode: (bytes2, offset = 0) => {
1499
- if (typeof size === "object" && bytes2.slice(offset).length === 0) {
1500
- return [[], offset];
1501
- }
1502
- const [resolvedSize, newOffset] = decodeArrayLikeCodecSize(size, [item.fixedSize], bytes2, offset);
1503
- offset = newOffset;
1504
- const values = [];
1505
- for (let i = 0; i < resolvedSize; i += 1) {
1506
- const [value, newOffset2] = item.decode(bytes2, offset);
1507
- values.push(value);
1508
- offset = newOffset2;
1509
- }
1510
- return [values, offset];
1511
- }
1512
- };
1513
- }
1514
- function getBytesEncoder(options = {}) {
1515
- const size = options.size ?? "variable";
1516
- const sizeDescription = typeof size === "object" ? size.description : `${size}`;
1517
- const description = options.description ?? `bytes(${sizeDescription})`;
1518
- const byteEncoder = {
1519
- description,
1520
- encode: (value) => value,
1521
- fixedSize: null,
1522
- maxSize: null
1523
- };
1524
- if (size === "variable") {
1525
- return byteEncoder;
1526
- }
1527
- if (typeof size === "number") {
1528
- return fixEncoder(byteEncoder, size, description);
1529
- }
1530
- return {
1531
- ...byteEncoder,
1532
- encode: (value) => {
1533
- const contentBytes = byteEncoder.encode(value);
1534
- const lengthBytes = size.encode(contentBytes.length);
1535
- return mergeBytes2([lengthBytes, contentBytes]);
1536
- }
1537
- };
1538
- }
1539
- function getBytesDecoder(options = {}) {
1540
- const size = options.size ?? "variable";
1541
- const sizeDescription = typeof size === "object" ? size.description : `${size}`;
1542
- const description = options.description ?? `bytes(${sizeDescription})`;
1543
- const byteDecoder = {
1544
- decode: (bytes2, offset = 0) => {
1545
- const slice = bytes2.slice(offset);
1546
- return [slice, offset + slice.length];
1547
- },
1548
- description,
1549
- fixedSize: null,
1550
- maxSize: null
1551
- };
1552
- if (size === "variable") {
1553
- return byteDecoder;
1554
- }
1555
- if (typeof size === "number") {
1556
- return fixDecoder(byteDecoder, size, description);
1557
- }
1558
- return {
1559
- ...byteDecoder,
1560
- decode: (bytes2, offset = 0) => {
1561
- assertByteArrayIsNotEmptyForCodec("bytes", bytes2, offset);
1562
- const [lengthBigInt, lengthOffset] = size.decode(bytes2, offset);
1563
- const length = Number(lengthBigInt);
1564
- offset = lengthOffset;
1565
- const contentBytes = bytes2.slice(offset, offset + length);
1566
- assertByteArrayHasEnoughBytesForCodec("bytes", length, contentBytes);
1567
- const [value, contentOffset] = byteDecoder.decode(contentBytes);
1568
- offset += contentOffset;
1569
- return [value, offset];
1570
- }
1571
- };
1572
- }
1573
- function structCodecHelper(fields, description) {
1574
- const fieldDescriptions = fields.map(([name, codec]) => `${String(name)}: ${codec.description}`).join(", ");
1575
- return {
1576
- description: description ?? `struct(${fieldDescriptions})`,
1577
- fixedSize: sumCodecSizes(fields.map(([, field]) => field.fixedSize)),
1578
- maxSize: sumCodecSizes(fields.map(([, field]) => field.maxSize))
1579
- };
1580
- }
1581
- function getStructEncoder(fields, options = {}) {
1582
- return {
1583
- ...structCodecHelper(fields, options.description),
1584
- encode: (struct2) => {
1585
- const fieldBytes = fields.map(([key, codec]) => codec.encode(struct2[key]));
1586
- return mergeBytes2(fieldBytes);
1587
- }
1588
- };
1589
- }
1590
- function getStructDecoder(fields, options = {}) {
1591
- return {
1592
- ...structCodecHelper(fields, options.description),
1593
- decode: (bytes2, offset = 0) => {
1594
- const struct2 = {};
1595
- fields.forEach(([key, codec]) => {
1596
- const [value, newOffset] = codec.decode(bytes2, offset);
1597
- offset = newOffset;
1598
- struct2[key] = value;
1599
- });
1600
- return [struct2, offset];
1601
- }
1602
- };
1603
- }
1604
- function getStructCodec(fields, options = {}) {
1605
- return combineCodec(getStructEncoder(fields, options), getStructDecoder(fields, options));
1606
- }
1607
-
1608
- // src/serializers/address-table-lookup.ts
1609
- var lookupTableAddressDescription = "The address of the address lookup table account from which instruction addresses should be looked up" ;
1610
- var writableIndicesDescription = "The indices of the accounts in the lookup table that should be loaded as writeable" ;
1611
- var readableIndicesDescription = "The indices of the accounts in the lookup table that should be loaded as read-only" ;
1612
- 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" ;
1613
- var memoizedAddressTableLookupEncoder;
1614
- function getAddressTableLookupEncoder() {
1615
- if (!memoizedAddressTableLookupEncoder) {
1616
- memoizedAddressTableLookupEncoder = getStructEncoder(
1617
- [
1618
- ["lookupTableAddress", getAddressEncoder({ description: lookupTableAddressDescription })],
1619
- [
1620
- "writableIndices",
1621
- getArrayEncoder(getU8Encoder(), {
1622
- description: writableIndicesDescription,
1623
- size: getShortU16Encoder()
1624
- })
1625
- ],
1626
- [
1627
- "readableIndices",
1628
- getArrayEncoder(getU8Encoder(), {
1629
- description: readableIndicesDescription,
1630
- size: getShortU16Encoder()
1631
- })
1632
- ]
1633
- ],
1634
- { description: addressTableLookupDescription }
1635
- );
1636
- }
1637
- return memoizedAddressTableLookupEncoder;
1638
- }
1639
- var memoizedAddressTableLookupDecoder;
1640
- function getAddressTableLookupDecoder() {
1641
- if (!memoizedAddressTableLookupDecoder) {
1642
- memoizedAddressTableLookupDecoder = getStructDecoder(
1643
- [
1644
- ["lookupTableAddress", getAddressDecoder({ description: lookupTableAddressDescription })],
1645
- [
1646
- "writableIndices",
1647
- getArrayDecoder(getU8Decoder(), {
1648
- description: writableIndicesDescription,
1649
- size: getShortU16Decoder()
1650
- })
1651
- ],
1652
- [
1653
- "readableIndices",
1654
- getArrayDecoder(getU8Decoder(), {
1655
- description: readableIndicesDescription,
1656
- size: getShortU16Decoder()
1657
- })
1658
- ]
1659
- ],
1660
- { description: addressTableLookupDescription }
1661
- );
1662
- }
1663
- return memoizedAddressTableLookupDecoder;
1664
- }
1665
- function getAddressTableLookupCodec() {
1666
- return combineCodec(getAddressTableLookupEncoder(), getAddressTableLookupDecoder());
1667
- }
1668
-
1669
- // src/serializers/header.ts
1670
- var memoizedU8Codec;
1671
- function getMemoizedU8Codec() {
1672
- if (!memoizedU8Codec)
1673
- memoizedU8Codec = getU8Codec();
1674
- return memoizedU8Codec;
1675
- }
1676
- function getMemoizedU8CodecDescription(description) {
1677
- const codec = getMemoizedU8Codec();
1678
- return {
1679
- ...codec,
1680
- description: description ?? codec.description
1681
- };
1682
- }
1683
- var numSignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction" ;
1684
- 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" ;
1685
- var numReadonlyNonSignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable" ;
1686
- var messageHeaderDescription = "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses" ;
1687
- function getMessageHeaderCodec() {
1688
- return getStructCodec(
1689
- [
1690
- ["numSignerAccounts", getMemoizedU8CodecDescription(numSignerAccountsDescription)],
1691
- ["numReadonlySignerAccounts", getMemoizedU8CodecDescription(numReadonlySignerAccountsDescription)],
1692
- ["numReadonlyNonSignerAccounts", getMemoizedU8CodecDescription(numReadonlyNonSignerAccountsDescription)]
1693
- ],
1694
- {
1695
- description: messageHeaderDescription
1696
- }
1697
- );
1698
- }
1699
-
1700
- // src/serializers/instruction.ts
1701
- var programAddressIndexDescription = "The index of the program being called, according to the well-ordered accounts list for this transaction" ;
1702
- var accountIndexDescription = "The index of an account, according to the well-ordered accounts list for this transaction" ;
1703
- 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" ;
1704
- var dataDescription = "An optional buffer of data passed to the instruction" ;
1705
- var memoizedGetInstructionEncoder;
1706
- function getInstructionEncoder() {
1707
- if (!memoizedGetInstructionEncoder) {
1708
- memoizedGetInstructionEncoder = mapEncoder(
1709
- getStructEncoder([
1710
- ["programAddressIndex", getU8Encoder({ description: programAddressIndexDescription })],
1711
- [
1712
- "accountIndices",
1713
- getArrayEncoder(getU8Encoder({ description: accountIndexDescription }), {
1714
- description: accountIndicesDescription,
1715
- size: getShortU16Encoder()
1716
- })
1717
- ],
1718
- ["data", getBytesEncoder({ description: dataDescription, size: getShortU16Encoder() })]
1719
- ]),
1720
- // Convert an instruction to have all fields defined
1721
- (instruction) => {
1722
- if (instruction.accountIndices !== void 0 && instruction.data !== void 0) {
1723
- return instruction;
1724
- }
1725
- return {
1726
- ...instruction,
1727
- accountIndices: instruction.accountIndices ?? [],
1728
- data: instruction.data ?? new Uint8Array(0)
1729
- };
1730
- }
1731
- );
1732
- }
1733
- return memoizedGetInstructionEncoder;
1734
- }
1735
- var memoizedGetInstructionDecoder;
1736
- function getInstructionDecoder() {
1737
- if (!memoizedGetInstructionDecoder) {
1738
- memoizedGetInstructionDecoder = mapDecoder(
1739
- getStructDecoder([
1740
- ["programAddressIndex", getU8Decoder({ description: programAddressIndexDescription })],
1741
- [
1742
- "accountIndices",
1743
- getArrayDecoder(getU8Decoder({ description: accountIndexDescription }), {
1744
- description: accountIndicesDescription,
1745
- size: getShortU16Decoder()
1746
- })
1747
- ],
1748
- ["data", getBytesDecoder({ description: dataDescription, size: getShortU16Decoder() })]
1749
- ]),
1750
- // Convert an instruction to exclude optional fields if they are empty
1751
- (instruction) => {
1752
- if (instruction.accountIndices.length && instruction.data.byteLength) {
1753
- return instruction;
1754
- }
1755
- const { accountIndices, data, ...rest } = instruction;
1756
- return {
1757
- ...rest,
1758
- ...accountIndices.length ? { accountIndices } : null,
1759
- ...data.byteLength ? { data } : null
1760
- };
1761
- }
1762
- );
1763
- }
1764
- return memoizedGetInstructionDecoder;
1765
- }
1766
- function getInstructionCodec() {
1767
- return combineCodec(getInstructionEncoder(), getInstructionDecoder());
1768
- }
1769
-
1770
- // src/serializers/transaction-version.ts
1771
- var VERSION_FLAG_MASK = 128;
1772
- var BASE_CONFIG = {
1773
- description: "A single byte that encodes the version of the transaction" ,
1774
- fixedSize: null,
1775
- maxSize: 1
1776
- };
1777
- function decode(bytes2, offset = 0) {
1778
- const firstByte = bytes2[offset];
1779
- if ((firstByte & VERSION_FLAG_MASK) === 0) {
1780
- return ["legacy", offset];
1781
- } else {
1782
- const version = firstByte ^ VERSION_FLAG_MASK;
1783
- return [version, offset + 1];
1784
- }
1785
- }
1786
- function encode(value) {
1787
- if (value === "legacy") {
1788
- return new Uint8Array();
1789
- }
1790
- if (value < 0 || value > 127) {
1791
- throw new Error(`Transaction version must be in the range [0, 127]. \`${value}\` given.`);
1792
- }
1793
- return new Uint8Array([value | VERSION_FLAG_MASK]);
1794
- }
1795
- function getTransactionVersionDecoder() {
1796
- return {
1797
- ...BASE_CONFIG,
1798
- decode
1799
- };
1800
- }
1801
- function getTransactionVersionEncoder() {
1802
- return {
1803
- ...BASE_CONFIG,
1804
- encode
1805
- };
1806
- }
1807
- function getTransactionVersionCodec() {
1808
- return combineCodec(getTransactionVersionEncoder(), getTransactionVersionDecoder());
1809
- }
1810
-
1811
- // src/serializers/unimplemented.ts
1812
- function getError(type, name) {
1813
- const functionSuffix = name + type[0].toUpperCase() + type.slice(1);
1814
- return new Error(
1815
- `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}`
1816
- );
1817
- }
1818
- function getUnimplementedDecoder(name) {
1819
- return () => {
1820
- throw getError("decoder", name);
1821
- };
1822
- }
1823
-
1824
- // src/serializers/message.ts
1825
- var BASE_CONFIG2 = {
1826
- description: "The wire format of a Solana transaction message" ,
1827
- fixedSize: null,
1828
- maxSize: null
1829
- };
1830
- function serialize(compiledMessage) {
1831
- if (compiledMessage.version === "legacy") {
1832
- return struct(getPreludeStructSerializerTuple()).serialize(compiledMessage);
1833
- } else {
1834
- return mapSerializer(
1835
- struct([
1836
- ...getPreludeStructSerializerTuple(),
1837
- ["addressTableLookups", getAddressTableLookupsSerializer()]
1838
- ]),
1839
- (value) => {
1840
- if (value.version === "legacy") {
1841
- return value;
1842
- }
1843
- return {
1844
- ...value,
1845
- addressTableLookups: value.addressTableLookups ?? []
1846
- };
1847
- }
1848
- ).serialize(compiledMessage);
1849
- }
1850
- }
1851
- function toSerializer(codec) {
1852
- return {
1853
- description: codec.description,
1854
- deserialize: codec.decode,
1855
- fixedSize: codec.fixedSize,
1856
- maxSize: codec.maxSize,
1857
- serialize: codec.encode
1858
- };
1859
- }
1860
- function getPreludeStructSerializerTuple() {
1861
- return [
1862
- ["version", toSerializer(getTransactionVersionCodec())],
1863
- ["header", toSerializer(getMessageHeaderCodec())],
1864
- [
1865
- "staticAccounts",
1866
- array(toSerializer(getAddressCodec()), {
1867
- description: "A compact-array of static account addresses belonging to this transaction" ,
1868
- size: shortU16()
1869
- })
1870
- ],
1871
- [
1872
- "lifetimeToken",
1873
- string({
1874
- description: "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" ,
1875
- encoding: base58,
1876
- size: 32
1877
- })
1878
- ],
1879
- [
1880
- "instructions",
1881
- array(toSerializer(getInstructionCodec()), {
1882
- description: "A compact-array of instructions belonging to this transaction" ,
1883
- size: shortU16()
1884
- })
1885
- ]
1886
- ];
1887
- }
1888
- function getAddressTableLookupsSerializer() {
1889
- return array(toSerializer(getAddressTableLookupCodec()), {
1890
- ...{ description: "A compact array of address table lookups belonging to this transaction" } ,
1891
- size: shortU16()
1892
- });
1893
- }
1894
- function getCompiledMessageEncoder() {
1895
- return {
1896
- ...BASE_CONFIG2,
1897
- deserialize: getUnimplementedDecoder("CompiledMessage"),
1898
- serialize
1899
- };
1900
- }
1901
-
1902
- // src/serializers/transaction.ts
1903
- var BASE_CONFIG3 = {
1904
- description: "The wire format of a Solana transaction" ,
1905
- fixedSize: null,
1906
- maxSize: null
1907
- };
1908
- function serialize2(transaction) {
1909
- const compiledTransaction = getCompiledTransaction(transaction);
1910
- return struct([
1911
- [
1912
- "signatures",
1913
- array(bytes({ size: 64 }), {
1914
- ...{ description: "A compact array of 64-byte, base-64 encoded Ed25519 signatures" } ,
1915
- size: shortU16()
1916
- })
1917
- ],
1918
- ["compiledMessage", getCompiledMessageEncoder()]
1919
- ]).serialize(compiledTransaction);
1920
- }
1921
- function getTransactionEncoder() {
1922
- return {
1923
- ...BASE_CONFIG3,
1924
- deserialize: getUnimplementedDecoder("CompiledMessage"),
1925
- serialize: serialize2
1926
- };
1927
- }
1928
-
1929
- // ../keys/dist/index.browser.js
1930
- async function signBytes(key, data) {
1931
- await assertSigningCapabilityIsAvailable();
1932
- const signedData = await crypto.subtle.sign("Ed25519", key, data);
1933
- return new Uint8Array(signedData);
1934
- }
1935
-
1936
- // src/signatures.ts
1937
- function assertIsTransactionSignature(putativeTransactionSignature) {
1938
- try {
1939
- if (
1940
- // Lowest value (64 bytes of zeroes)
1941
- putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
1942
- putativeTransactionSignature.length > 88
1943
- ) {
1944
- throw new Error("Expected input string to decode to a byte array of length 64.");
1945
- }
1946
- const bytes2 = base58.serialize(putativeTransactionSignature);
1947
- const numBytes = bytes2.byteLength;
1948
- if (numBytes !== 64) {
1949
- throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
1950
- }
1951
- } catch (e2) {
1952
- throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
1953
- cause: e2
1954
- });
1955
- }
1956
- }
1957
- function isTransactionSignature(putativeTransactionSignature) {
1958
- if (
1959
- // Lowest value (64 bytes of zeroes)
1960
- putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
1961
- putativeTransactionSignature.length > 88
1962
- ) {
1963
- return false;
1964
- }
1965
- const bytes2 = base58.serialize(putativeTransactionSignature);
1966
- const numBytes = bytes2.byteLength;
1967
- if (numBytes !== 64) {
1968
- return false;
1969
- }
1970
- return true;
1971
- }
1972
- async function getCompiledMessageSignature(message, secretKey) {
1973
- const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
1974
- const signature = await signBytes(secretKey, wireMessageBytes);
1975
- return signature;
1976
- }
1977
- function getSignatureFromTransaction(transaction) {
1978
- const signatureBytes = transaction.signatures[transaction.feePayer];
1979
- if (!signatureBytes) {
1980
- throw new Error(
1981
- "Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
1982
- );
1983
- }
1984
- const transactionSignature2 = base58.deserialize(signatureBytes)[0];
1985
- return transactionSignature2;
1986
- }
1987
- async function signTransaction(keyPairs, transaction) {
1988
- const compiledMessage = compileMessage(transaction);
1989
- const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
1990
- const publicKeySignaturePairs = await Promise.all(
1991
- keyPairs.map(
1992
- (keyPair) => Promise.all([
1993
- getAddressFromPublicKey(keyPair.publicKey),
1994
- getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
1995
- ])
1996
- )
1997
- );
1998
- for (const [signerPublicKey, signature] of publicKeySignaturePairs) {
1999
- nextSignatures[signerPublicKey] = signature;
2000
- }
2001
- const out = {
2002
- ...transaction,
2003
- signatures: nextSignatures
2004
- };
2005
- Object.freeze(out);
2006
- return out;
2007
- }
2008
- function transactionSignature(putativeTransactionSignature) {
2009
- assertIsTransactionSignature(putativeTransactionSignature);
2010
- return putativeTransactionSignature;
2011
- }
2012
-
2013
- // src/wire-transaction.ts
2014
- function getBase64EncodedWireTransaction(transaction) {
2015
- const wireTransactionBytes = getTransactionEncoder().serialize(transaction);
2016
- {
2017
- return btoa(String.fromCharCode(...wireTransactionBytes));
2018
- }
2019
- }
2020
-
2021
- exports.appendTransactionInstruction = appendTransactionInstruction;
2022
- exports.assertIsBlockhash = assertIsBlockhash;
2023
- exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
2024
- exports.assertIsTransactionSignature = assertIsTransactionSignature;
2025
- exports.createTransaction = createTransaction;
2026
- exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
2027
- exports.getSignatureFromTransaction = getSignatureFromTransaction;
2028
- exports.getTransactionEncoder = getTransactionEncoder;
2029
- exports.isAdvanceNonceAccountInstruction = isAdvanceNonceAccountInstruction;
2030
- exports.isTransactionSignature = isTransactionSignature;
2031
- exports.prependTransactionInstruction = prependTransactionInstruction;
2032
- exports.setTransactionFeePayer = setTransactionFeePayer;
2033
- exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
2034
- exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
2035
- exports.signTransaction = signTransaction;
2036
- exports.transactionSignature = transactionSignature;
2037
-
2038
- return exports;
2039
-
2040
- })({});
2041
- //# sourceMappingURL=out.js.map
2042
- //# sourceMappingURL=index.development.js.map