@solana/transactions 2.0.0-experimental.71b920d → 2.0.0-experimental.71dcc4e

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 (71) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +272 -5
  3. package/dist/index.browser.cjs +610 -278
  4. package/dist/index.browser.cjs.map +1 -1
  5. package/dist/index.browser.js +594 -280
  6. package/dist/index.browser.js.map +1 -1
  7. package/dist/index.native.js +594 -280
  8. package/dist/index.native.js.map +1 -1
  9. package/dist/index.node.cjs +610 -278
  10. package/dist/index.node.cjs.map +1 -1
  11. package/dist/index.node.js +594 -280
  12. package/dist/index.node.js.map +1 -1
  13. package/dist/types/accounts.d.ts +3 -3
  14. package/dist/types/accounts.d.ts.map +1 -0
  15. package/dist/types/blockhash.d.ts +7 -1
  16. package/dist/types/blockhash.d.ts.map +1 -0
  17. package/dist/types/compilable-transaction.d.ts +7 -0
  18. package/dist/types/compilable-transaction.d.ts.map +1 -0
  19. package/dist/types/compile-address-table-lookups.d.ts +3 -3
  20. package/dist/types/compile-address-table-lookups.d.ts.map +1 -0
  21. package/dist/types/compile-header.d.ts +1 -1
  22. package/dist/types/compile-header.d.ts.map +1 -0
  23. package/dist/types/compile-instructions.d.ts +2 -2
  24. package/dist/types/compile-instructions.d.ts.map +1 -0
  25. package/dist/types/compile-lifetime-token.d.ts +1 -1
  26. package/dist/types/compile-lifetime-token.d.ts.map +1 -0
  27. package/dist/types/compile-static-accounts.d.ts +3 -3
  28. package/dist/types/compile-static-accounts.d.ts.map +1 -0
  29. package/dist/types/compile-transaction.d.ts +10 -0
  30. package/dist/types/compile-transaction.d.ts.map +1 -0
  31. package/dist/types/create-transaction.d.ts +1 -1
  32. package/dist/types/create-transaction.d.ts.map +1 -0
  33. package/dist/types/decompile-transaction.d.ts +13 -0
  34. package/dist/types/decompile-transaction.d.ts.map +1 -0
  35. package/dist/types/durable-nonce.d.ts +23 -10
  36. package/dist/types/durable-nonce.d.ts.map +1 -0
  37. package/dist/types/fee-payer.d.ts +6 -5
  38. package/dist/types/fee-payer.d.ts.map +1 -0
  39. package/dist/types/index.d.ts +12 -7
  40. package/dist/types/index.d.ts.map +1 -0
  41. package/dist/types/instructions.d.ts +2 -2
  42. package/dist/types/instructions.d.ts.map +1 -0
  43. package/dist/types/message.d.ts +6 -10
  44. package/dist/types/message.d.ts.map +1 -0
  45. package/dist/types/serializers/address-table-lookup.d.ts +5 -3
  46. package/dist/types/serializers/address-table-lookup.d.ts.map +1 -0
  47. package/dist/types/serializers/header.d.ts +5 -3
  48. package/dist/types/serializers/header.d.ts.map +1 -0
  49. package/dist/types/serializers/index.d.ts +3 -0
  50. package/dist/types/serializers/index.d.ts.map +1 -0
  51. package/dist/types/serializers/instruction.d.ts +5 -3
  52. package/dist/types/serializers/instruction.d.ts.map +1 -0
  53. package/dist/types/serializers/message.d.ts +5 -5
  54. package/dist/types/serializers/message.d.ts.map +1 -0
  55. package/dist/types/serializers/transaction-version.d.ts +5 -5
  56. package/dist/types/serializers/transaction-version.d.ts.map +1 -0
  57. package/dist/types/serializers/transaction.d.ts +10 -0
  58. package/dist/types/serializers/transaction.d.ts.map +1 -0
  59. package/dist/types/signatures.d.ts +10 -7
  60. package/dist/types/signatures.d.ts.map +1 -0
  61. package/dist/types/types.d.ts +13 -13
  62. package/dist/types/types.d.ts.map +1 -0
  63. package/dist/types/unsigned-transaction.d.ts +4 -0
  64. package/dist/types/unsigned-transaction.d.ts.map +1 -0
  65. package/dist/types/wire-transaction.d.ts +6 -0
  66. package/dist/types/wire-transaction.d.ts.map +1 -0
  67. package/package.json +26 -23
  68. package/dist/index.development.js +0 -1188
  69. package/dist/index.development.js.map +0 -1
  70. package/dist/index.production.min.js +0 -15
  71. package/dist/types/serializers/unimplemented.d.ts +0 -3
@@ -1,1188 +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
- // src/create-transaction.ts
13
- function createTransaction({
14
- version
15
- }) {
16
- const out = {
17
- instructions: [],
18
- version
19
- };
20
- Object.freeze(out);
21
- return out;
22
- }
23
-
24
- // src/fee-payer.ts
25
- function setTransactionFeePayer(feePayer, transaction) {
26
- if ("feePayer" in transaction && feePayer === transaction.feePayer) {
27
- return transaction;
28
- }
29
- let out;
30
- if ("signatures" in transaction) {
31
- const {
32
- signatures: _,
33
- // eslint-disable-line @typescript-eslint/no-unused-vars
34
- ...unsignedTransaction
35
- } = transaction;
36
- out = {
37
- ...unsignedTransaction,
38
- feePayer
39
- };
40
- } else {
41
- out = {
42
- ...transaction,
43
- feePayer
44
- };
45
- }
46
- Object.freeze(out);
47
- return out;
48
- }
49
-
50
- // src/instructions.ts
51
- function replaceInstructions(transaction, nextInstructions) {
52
- let out;
53
- if ("signatures" in transaction) {
54
- const {
55
- signatures: _,
56
- // eslint-disable-line @typescript-eslint/no-unused-vars
57
- ...unsignedTransaction
58
- } = transaction;
59
- out = {
60
- ...unsignedTransaction,
61
- instructions: nextInstructions
62
- };
63
- } else {
64
- out = {
65
- ...transaction,
66
- instructions: nextInstructions
67
- };
68
- }
69
- return out;
70
- }
71
- function appendTransactionInstruction(instruction, transaction) {
72
- const nextInstructions = [...transaction.instructions, instruction];
73
- const out = replaceInstructions(transaction, nextInstructions);
74
- Object.freeze(out);
75
- return out;
76
- }
77
- function prependTransactionInstruction(instruction, transaction) {
78
- const nextInstructions = [instruction, ...transaction.instructions];
79
- const out = replaceInstructions(transaction, nextInstructions);
80
- Object.freeze(out);
81
- return out;
82
- }
83
-
84
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/bytes.mjs
85
- var mergeBytes = (bytesArr) => {
86
- const totalLength = bytesArr.reduce((total, arr) => total + arr.length, 0);
87
- const result = new Uint8Array(totalLength);
88
- let offset = 0;
89
- bytesArr.forEach((arr) => {
90
- result.set(arr, offset);
91
- offset += arr.length;
92
- });
93
- return result;
94
- };
95
- var padBytes = (bytes2, length) => {
96
- if (bytes2.length >= length)
97
- return bytes2;
98
- const paddedBytes = new Uint8Array(length).fill(0);
99
- paddedBytes.set(bytes2);
100
- return paddedBytes;
101
- };
102
- var fixBytes = (bytes2, length) => padBytes(bytes2.slice(0, length), length);
103
-
104
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/errors.mjs
105
- var DeserializingEmptyBufferError = class extends Error {
106
- constructor(serializer) {
107
- super(`Serializer [${serializer}] cannot deserialize empty buffers.`);
108
- __publicField(this, "name", "DeserializingEmptyBufferError");
109
- }
110
- };
111
- var NotEnoughBytesError = class extends Error {
112
- constructor(serializer, expected, actual) {
113
- super(`Serializer [${serializer}] expected ${expected} bytes, got ${actual}.`);
114
- __publicField(this, "name", "NotEnoughBytesError");
115
- }
116
- };
117
- var ExpectedFixedSizeSerializerError = class extends Error {
118
- constructor(message) {
119
- message ?? (message = "Expected a fixed-size serializer, got a variable-size one.");
120
- super(message);
121
- __publicField(this, "name", "ExpectedFixedSizeSerializerError");
122
- }
123
- };
124
-
125
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/fixSerializer.mjs
126
- function fixSerializer(serializer, fixedBytes, description) {
127
- return {
128
- description: description ?? `fixed(${fixedBytes}, ${serializer.description})`,
129
- fixedSize: fixedBytes,
130
- maxSize: fixedBytes,
131
- serialize: (value) => fixBytes(serializer.serialize(value), fixedBytes),
132
- deserialize: (buffer, offset = 0) => {
133
- buffer = buffer.slice(offset, offset + fixedBytes);
134
- if (buffer.length < fixedBytes) {
135
- throw new NotEnoughBytesError("fixSerializer", fixedBytes, buffer.length);
136
- }
137
- if (serializer.fixedSize !== null) {
138
- buffer = fixBytes(buffer, serializer.fixedSize);
139
- }
140
- const [value] = serializer.deserialize(buffer, 0);
141
- return [value, offset + fixedBytes];
142
- }
143
- };
144
- }
145
-
146
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/mapSerializer.mjs
147
- function mapSerializer(serializer, unmap, map) {
148
- return {
149
- description: serializer.description,
150
- fixedSize: serializer.fixedSize,
151
- maxSize: serializer.maxSize,
152
- serialize: (value) => serializer.serialize(unmap(value)),
153
- deserialize: (buffer, offset = 0) => {
154
- const [value, length] = serializer.deserialize(buffer, offset);
155
- return map ? [map(value, buffer, offset), length] : [value, length];
156
- }
157
- };
158
- }
159
-
160
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/errors.mjs
161
- var InvalidBaseStringError = class extends Error {
162
- constructor(value, base, cause) {
163
- const message = `Expected a string of base ${base}, got [${value}].`;
164
- super(message);
165
- __publicField(this, "name", "InvalidBaseStringError");
166
- this.cause = cause;
167
- }
168
- };
169
-
170
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseX.mjs
171
- var baseX = (alphabet) => {
172
- const base = alphabet.length;
173
- const baseBigInt = BigInt(base);
174
- return {
175
- description: `base${base}`,
176
- fixedSize: null,
177
- maxSize: null,
178
- serialize(value) {
179
- if (!value.match(new RegExp(`^[${alphabet}]*$`))) {
180
- throw new InvalidBaseStringError(value, base);
181
- }
182
- if (value === "")
183
- return new Uint8Array();
184
- const chars = [...value];
185
- let trailIndex = chars.findIndex((c) => c !== alphabet[0]);
186
- trailIndex = trailIndex === -1 ? chars.length : trailIndex;
187
- const leadingZeroes = Array(trailIndex).fill(0);
188
- if (trailIndex === chars.length)
189
- return Uint8Array.from(leadingZeroes);
190
- const tailChars = chars.slice(trailIndex);
191
- let base10Number = 0n;
192
- let baseXPower = 1n;
193
- for (let i = tailChars.length - 1; i >= 0; i -= 1) {
194
- base10Number += baseXPower * BigInt(alphabet.indexOf(tailChars[i]));
195
- baseXPower *= baseBigInt;
196
- }
197
- const tailBytes = [];
198
- while (base10Number > 0n) {
199
- tailBytes.unshift(Number(base10Number % 256n));
200
- base10Number /= 256n;
201
- }
202
- return Uint8Array.from(leadingZeroes.concat(tailBytes));
203
- },
204
- deserialize(buffer, offset = 0) {
205
- if (buffer.length === 0)
206
- return ["", 0];
207
- const bytes2 = buffer.slice(offset);
208
- let trailIndex = bytes2.findIndex((n) => n !== 0);
209
- trailIndex = trailIndex === -1 ? bytes2.length : trailIndex;
210
- const leadingZeroes = alphabet[0].repeat(trailIndex);
211
- if (trailIndex === bytes2.length)
212
- return [leadingZeroes, buffer.length];
213
- let base10Number = bytes2.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
214
- const tailChars = [];
215
- while (base10Number > 0n) {
216
- tailChars.unshift(alphabet[Number(base10Number % baseBigInt)]);
217
- base10Number /= baseBigInt;
218
- }
219
- return [leadingZeroes + tailChars.join(""), buffer.length];
220
- }
221
- };
222
- };
223
-
224
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/base58.mjs
225
- var base58 = baseX("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
226
-
227
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/nullCharacters.mjs
228
- var removeNullCharacters = (value) => (
229
- // eslint-disable-next-line no-control-regex
230
- value.replace(/\u0000/g, "")
231
- );
232
-
233
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/utf8.mjs
234
- var utf8 = {
235
- description: "utf8",
236
- fixedSize: null,
237
- maxSize: null,
238
- serialize(value) {
239
- return new TextEncoder().encode(value);
240
- },
241
- deserialize(buffer, offset = 0) {
242
- const value = new TextDecoder().decode(buffer.slice(offset));
243
- return [removeNullCharacters(value), buffer.length];
244
- }
245
- };
246
-
247
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/common.mjs
248
- var Endian;
249
- (function(Endian2) {
250
- Endian2["Little"] = "le";
251
- Endian2["Big"] = "be";
252
- })(Endian || (Endian = {}));
253
-
254
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/errors.mjs
255
- var NumberOutOfRangeError = class extends RangeError {
256
- constructor(serializer, min, max, actual) {
257
- super(`Serializer [${serializer}] expected number to be between ${min} and ${max}, got ${actual}.`);
258
- __publicField(this, "name", "NumberOutOfRangeError");
259
- }
260
- };
261
-
262
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/utils.mjs
263
- function numberFactory(input) {
264
- let littleEndian;
265
- let defaultDescription = input.name;
266
- if (input.size > 1) {
267
- littleEndian = !("endian" in input.options) || input.options.endian === Endian.Little;
268
- defaultDescription += littleEndian ? "(le)" : "(be)";
269
- }
270
- return {
271
- description: input.options.description ?? defaultDescription,
272
- fixedSize: input.size,
273
- maxSize: input.size,
274
- serialize(value) {
275
- if (input.range) {
276
- assertRange(input.name, input.range[0], input.range[1], value);
277
- }
278
- const buffer = new ArrayBuffer(input.size);
279
- input.set(new DataView(buffer), value, littleEndian);
280
- return new Uint8Array(buffer);
281
- },
282
- deserialize(bytes2, offset = 0) {
283
- const slice = bytes2.slice(offset, offset + input.size);
284
- assertEnoughBytes("i8", slice, input.size);
285
- const view = toDataView(slice);
286
- return [input.get(view, littleEndian), offset + input.size];
287
- }
288
- };
289
- }
290
- var toArrayBuffer = (array2) => array2.buffer.slice(array2.byteOffset, array2.byteLength + array2.byteOffset);
291
- var toDataView = (array2) => new DataView(toArrayBuffer(array2));
292
- var assertRange = (serializer, min, max, value) => {
293
- if (value < min || value > max) {
294
- throw new NumberOutOfRangeError(serializer, min, max, value);
295
- }
296
- };
297
- var assertEnoughBytes = (serializer, bytes2, expected) => {
298
- if (bytes2.length === 0) {
299
- throw new DeserializingEmptyBufferError(serializer);
300
- }
301
- if (bytes2.length < expected) {
302
- throw new NotEnoughBytesError(serializer, expected, bytes2.length);
303
- }
304
- };
305
-
306
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u8.mjs
307
- var u8 = (options = {}) => numberFactory({
308
- name: "u8",
309
- size: 1,
310
- range: [0, Number("0xff")],
311
- set: (view, value) => view.setUint8(0, Number(value)),
312
- get: (view) => view.getUint8(0),
313
- options
314
- });
315
-
316
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u32.mjs
317
- var u32 = (options = {}) => numberFactory({
318
- name: "u32",
319
- size: 4,
320
- range: [0, Number("0xffffffff")],
321
- set: (view, value, le) => view.setUint32(0, Number(value), le),
322
- get: (view, le) => view.getUint32(0, le),
323
- options
324
- });
325
-
326
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/shortU16.mjs
327
- var shortU16 = (options = {}) => ({
328
- description: options.description ?? "shortU16",
329
- fixedSize: null,
330
- maxSize: 3,
331
- serialize: (value) => {
332
- assertRange("shortU16", 0, 65535, value);
333
- const bytes2 = [0];
334
- for (let ii = 0; ; ii += 1) {
335
- const alignedValue = value >> ii * 7;
336
- if (alignedValue === 0) {
337
- break;
338
- }
339
- const nextSevenBits = 127 & alignedValue;
340
- bytes2[ii] = nextSevenBits;
341
- if (ii > 0) {
342
- bytes2[ii - 1] |= 128;
343
- }
344
- }
345
- return new Uint8Array(bytes2);
346
- },
347
- deserialize: (bytes2, offset = 0) => {
348
- let value = 0;
349
- let byteCount = 0;
350
- while (++byteCount) {
351
- const byteIndex = byteCount - 1;
352
- const currentByte = bytes2[offset + byteIndex];
353
- const nextSevenBits = 127 & currentByte;
354
- value |= nextSevenBits << byteIndex * 7;
355
- if ((currentByte & 128) === 0) {
356
- break;
357
- }
358
- }
359
- return [value, offset + byteCount];
360
- }
361
- });
362
-
363
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.2/node_modules/@metaplex-foundation/umi-serializers/dist/esm/errors.mjs
364
- var InvalidNumberOfItemsError = class extends Error {
365
- constructor(serializer, expected, actual) {
366
- super(`Expected [${serializer}] to have ${expected} items, got ${actual}.`);
367
- __publicField(this, "name", "InvalidNumberOfItemsError");
368
- }
369
- };
370
- var InvalidArrayLikeRemainderSizeError = class extends Error {
371
- constructor(remainderSize, itemSize) {
372
- 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.`);
373
- __publicField(this, "name", "InvalidArrayLikeRemainderSizeError");
374
- }
375
- };
376
- var UnrecognizedArrayLikeSerializerSizeError = class extends Error {
377
- constructor(size) {
378
- super(`Unrecognized array-like serializer size: ${JSON.stringify(size)}`);
379
- __publicField(this, "name", "UnrecognizedArrayLikeSerializerSizeError");
380
- }
381
- };
382
-
383
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.2/node_modules/@metaplex-foundation/umi-serializers/dist/esm/sumSerializerSizes.mjs
384
- function sumSerializerSizes(sizes) {
385
- return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
386
- }
387
-
388
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.2/node_modules/@metaplex-foundation/umi-serializers/dist/esm/utils.mjs
389
- function getResolvedSize(size, childrenSizes, bytes2, offset) {
390
- if (typeof size === "number") {
391
- return [size, offset];
392
- }
393
- if (typeof size === "object") {
394
- return size.deserialize(bytes2, offset);
395
- }
396
- if (size === "remainder") {
397
- const childrenSize = sumSerializerSizes(childrenSizes);
398
- if (childrenSize === null) {
399
- throw new ExpectedFixedSizeSerializerError('Serializers of "remainder" size must have fixed-size items.');
400
- }
401
- const remainder = bytes2.slice(offset).length;
402
- if (remainder % childrenSize !== 0) {
403
- throw new InvalidArrayLikeRemainderSizeError(remainder, childrenSize);
404
- }
405
- return [remainder / childrenSize, offset];
406
- }
407
- throw new UnrecognizedArrayLikeSerializerSizeError(size);
408
- }
409
- function getSizeDescription(size) {
410
- return typeof size === "object" ? size.description : `${size}`;
411
- }
412
- function getSizeFromChildren(size, childrenSizes) {
413
- if (typeof size !== "number")
414
- return null;
415
- if (size === 0)
416
- return 0;
417
- const childrenSize = sumSerializerSizes(childrenSizes);
418
- return childrenSize === null ? null : childrenSize * size;
419
- }
420
- function getSizePrefix(size, realSize) {
421
- return typeof size === "object" ? size.serialize(realSize) : new Uint8Array();
422
- }
423
-
424
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.2/node_modules/@metaplex-foundation/umi-serializers/dist/esm/array.mjs
425
- function array(item, options = {}) {
426
- const size = options.size ?? u32();
427
- if (size === "remainder" && item.fixedSize === null) {
428
- throw new ExpectedFixedSizeSerializerError('Serializers of "remainder" size must have fixed-size items.');
429
- }
430
- return {
431
- description: options.description ?? `array(${item.description}; ${getSizeDescription(size)})`,
432
- fixedSize: getSizeFromChildren(size, [item.fixedSize]),
433
- maxSize: getSizeFromChildren(size, [item.maxSize]),
434
- serialize: (value) => {
435
- if (typeof size === "number" && value.length !== size) {
436
- throw new InvalidNumberOfItemsError("array", size, value.length);
437
- }
438
- return mergeBytes([getSizePrefix(size, value.length), ...value.map((v) => item.serialize(v))]);
439
- },
440
- deserialize: (bytes2, offset = 0) => {
441
- if (typeof size === "object" && bytes2.slice(offset).length === 0) {
442
- return [[], offset];
443
- }
444
- const [resolvedSize, newOffset] = getResolvedSize(size, [item.fixedSize], bytes2, offset);
445
- offset = newOffset;
446
- const values = [];
447
- for (let i = 0; i < resolvedSize; i += 1) {
448
- const [value, newOffset2] = item.deserialize(bytes2, offset);
449
- values.push(value);
450
- offset = newOffset2;
451
- }
452
- return [values, offset];
453
- }
454
- };
455
- }
456
-
457
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.2/node_modules/@metaplex-foundation/umi-serializers/dist/esm/bytes.mjs
458
- function bytes(options = {}) {
459
- const size = options.size ?? "variable";
460
- const description = options.description ?? `bytes(${getSizeDescription(size)})`;
461
- const byteSerializer = {
462
- description,
463
- fixedSize: null,
464
- maxSize: null,
465
- serialize: (value) => new Uint8Array(value),
466
- deserialize: (bytes2, offset = 0) => {
467
- const slice = bytes2.slice(offset);
468
- return [slice, offset + slice.length];
469
- }
470
- };
471
- if (size === "variable") {
472
- return byteSerializer;
473
- }
474
- if (typeof size === "number") {
475
- return fixSerializer(byteSerializer, size, description);
476
- }
477
- return {
478
- description,
479
- fixedSize: null,
480
- maxSize: null,
481
- serialize: (value) => {
482
- const contentBytes = byteSerializer.serialize(value);
483
- const lengthBytes = size.serialize(contentBytes.length);
484
- return mergeBytes([lengthBytes, contentBytes]);
485
- },
486
- deserialize: (buffer, offset = 0) => {
487
- if (buffer.slice(offset).length === 0) {
488
- throw new DeserializingEmptyBufferError("bytes");
489
- }
490
- const [lengthBigInt, lengthOffset] = size.deserialize(buffer, offset);
491
- const length = Number(lengthBigInt);
492
- offset = lengthOffset;
493
- const contentBuffer = buffer.slice(offset, offset + length);
494
- if (contentBuffer.length < length) {
495
- throw new NotEnoughBytesError("bytes", length, contentBuffer.length);
496
- }
497
- const [value, contentOffset] = byteSerializer.deserialize(contentBuffer);
498
- offset += contentOffset;
499
- return [value, offset];
500
- }
501
- };
502
- }
503
-
504
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.2/node_modules/@metaplex-foundation/umi-serializers/dist/esm/string.mjs
505
- function string(options = {}) {
506
- const size = options.size ?? u32();
507
- const encoding = options.encoding ?? utf8;
508
- const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
509
- if (size === "variable") {
510
- return {
511
- ...encoding,
512
- description
513
- };
514
- }
515
- if (typeof size === "number") {
516
- return fixSerializer(encoding, size, description);
517
- }
518
- return {
519
- description,
520
- fixedSize: null,
521
- maxSize: null,
522
- serialize: (value) => {
523
- const contentBytes = encoding.serialize(value);
524
- const lengthBytes = size.serialize(contentBytes.length);
525
- return mergeBytes([lengthBytes, contentBytes]);
526
- },
527
- deserialize: (buffer, offset = 0) => {
528
- if (buffer.slice(offset).length === 0) {
529
- throw new DeserializingEmptyBufferError("string");
530
- }
531
- const [lengthBigInt, lengthOffset] = size.deserialize(buffer, offset);
532
- const length = Number(lengthBigInt);
533
- offset = lengthOffset;
534
- const contentBuffer = buffer.slice(offset, offset + length);
535
- if (contentBuffer.length < length) {
536
- throw new NotEnoughBytesError("string", length, contentBuffer.length);
537
- }
538
- const [value, contentOffset] = encoding.deserialize(contentBuffer);
539
- offset += contentOffset;
540
- return [value, offset];
541
- }
542
- };
543
- }
544
-
545
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.2/node_modules/@metaplex-foundation/umi-serializers/dist/esm/struct.mjs
546
- function struct(fields, options = {}) {
547
- const fieldDescriptions = fields.map(([name, serializer]) => `${String(name)}: ${serializer.description}`).join(", ");
548
- return {
549
- description: options.description ?? `struct(${fieldDescriptions})`,
550
- fixedSize: sumSerializerSizes(fields.map(([, field]) => field.fixedSize)),
551
- maxSize: sumSerializerSizes(fields.map(([, field]) => field.maxSize)),
552
- serialize: (struct2) => {
553
- const fieldBytes = fields.map(([key, serializer]) => serializer.serialize(struct2[key]));
554
- return mergeBytes(fieldBytes);
555
- },
556
- deserialize: (bytes2, offset = 0) => {
557
- const struct2 = {};
558
- fields.forEach(([key, serializer]) => {
559
- const [value, newOffset] = serializer.deserialize(bytes2, offset);
560
- offset = newOffset;
561
- struct2[key] = value;
562
- });
563
- return [struct2, offset];
564
- }
565
- };
566
- }
567
- function getBase58EncodedAddressCodec(config) {
568
- return string({
569
- description: config?.description ?? ("A 32-byte account address" ),
570
- encoding: base58,
571
- size: 32
572
- });
573
- }
574
- function getBase58EncodedAddressComparator() {
575
- return new Intl.Collator("en", {
576
- caseFirst: "lower",
577
- ignorePunctuation: false,
578
- localeMatcher: "best fit",
579
- numeric: false,
580
- sensitivity: "variant",
581
- usage: "sort"
582
- }).compare;
583
- }
584
- function assertIsSecureContext() {
585
- if (!globalThis.isSecureContext) {
586
- throw new Error(
587
- "Cryptographic operations are only allowed in secure browser contexts. Read more here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts"
588
- );
589
- }
590
- }
591
- async function assertKeyExporterIsAvailable() {
592
- assertIsSecureContext();
593
- if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.exportKey !== "function") {
594
- throw new Error("No key export implementation could be found");
595
- }
596
- }
597
- async function assertSigningCapabilityIsAvailable() {
598
- assertIsSecureContext();
599
- if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.sign !== "function") {
600
- throw new Error("No signing implementation could be found");
601
- }
602
- }
603
- async function getBase58EncodedAddressFromPublicKey(publicKey) {
604
- await assertKeyExporterIsAvailable();
605
- if (publicKey.type !== "public" || publicKey.algorithm.name !== "Ed25519") {
606
- throw new Error("The `CryptoKey` must be an `Ed25519` public key");
607
- }
608
- const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
609
- const [base58EncodedAddress] = getBase58EncodedAddressCodec().deserialize(new Uint8Array(publicKeyBytes));
610
- return base58EncodedAddress;
611
- }
612
- async function signBytes(key, data) {
613
- await assertSigningCapabilityIsAvailable();
614
- const signedData = await crypto.subtle.sign("Ed25519", key, data);
615
- return new Uint8Array(signedData);
616
- }
617
-
618
- // ../instructions/dist/index.browser.js
619
- var AccountRole = /* @__PURE__ */ ((AccountRole2) => {
620
- AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */
621
- 3] = "WRITABLE_SIGNER";
622
- AccountRole2[AccountRole2["READONLY_SIGNER"] = /* 2 */
623
- 2] = "READONLY_SIGNER";
624
- AccountRole2[AccountRole2["WRITABLE"] = /* 1 */
625
- 1] = "WRITABLE";
626
- AccountRole2[AccountRole2["READONLY"] = /* 0 */
627
- 0] = "READONLY";
628
- return AccountRole2;
629
- })(AccountRole || {});
630
- var IS_WRITABLE_BITMASK = 1;
631
- function isSignerRole(role) {
632
- return role >= 2;
633
- }
634
- function isWritableRole(role) {
635
- return (role & IS_WRITABLE_BITMASK) !== 0;
636
- }
637
- function mergeRoles(roleA, roleB) {
638
- return roleA | roleB;
639
- }
640
-
641
- // src/accounts.ts
642
- function upsert(addressMap, address, update) {
643
- addressMap[address] = update(addressMap[address] ?? { role: AccountRole.READONLY });
644
- }
645
- var TYPE = Symbol("AddressMapTypeProperty");
646
- function getAddressMapFromInstructions(feePayer, instructions) {
647
- const addressMap = {
648
- [feePayer]: { [TYPE]: 0 /* FEE_PAYER */, role: AccountRole.WRITABLE_SIGNER }
649
- };
650
- const addressesOfInvokedPrograms = /* @__PURE__ */ new Set();
651
- for (const instruction of instructions) {
652
- upsert(addressMap, instruction.programAddress, (entry) => {
653
- addressesOfInvokedPrograms.add(instruction.programAddress);
654
- if (TYPE in entry) {
655
- if (isWritableRole(entry.role)) {
656
- switch (entry[TYPE]) {
657
- case 0 /* FEE_PAYER */:
658
- throw new Error(
659
- `This transaction includes an address (\`${instruction.programAddress}\`) which is both invoked and set as the fee payer. Program addresses may not pay fees.`
660
- );
661
- default:
662
- throw new Error(
663
- `This transaction includes an address (\`${instruction.programAddress}\`) which is both invoked and marked writable. Program addresses may not be writable.`
664
- );
665
- }
666
- }
667
- if (entry[TYPE] === 2 /* STATIC */) {
668
- return entry;
669
- }
670
- }
671
- return { [TYPE]: 2 /* STATIC */, role: AccountRole.READONLY };
672
- });
673
- let addressComparator;
674
- if (!instruction.accounts) {
675
- continue;
676
- }
677
- for (const account of instruction.accounts) {
678
- upsert(addressMap, account.address, (entry) => {
679
- const {
680
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
681
- address: _,
682
- ...accountMeta
683
- } = account;
684
- if (TYPE in entry) {
685
- switch (entry[TYPE]) {
686
- case 0 /* FEE_PAYER */:
687
- return entry;
688
- case 1 /* LOOKUP_TABLE */: {
689
- const nextRole = mergeRoles(entry.role, accountMeta.role);
690
- if ("lookupTableAddress" in accountMeta) {
691
- const shouldReplaceEntry = (
692
- // Consider using the new LOOKUP_TABLE if its address is different...
693
- entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
694
- (addressComparator || (addressComparator = getBase58EncodedAddressComparator()))(
695
- accountMeta.lookupTableAddress,
696
- entry.lookupTableAddress
697
- ) < 0
698
- );
699
- if (shouldReplaceEntry) {
700
- return {
701
- [TYPE]: 1 /* LOOKUP_TABLE */,
702
- ...accountMeta,
703
- role: nextRole
704
- };
705
- }
706
- } else if (isSignerRole(accountMeta.role)) {
707
- return {
708
- [TYPE]: 2 /* STATIC */,
709
- role: nextRole
710
- };
711
- }
712
- if (entry.role !== nextRole) {
713
- return {
714
- ...entry,
715
- role: nextRole
716
- };
717
- } else {
718
- return entry;
719
- }
720
- }
721
- case 2 /* STATIC */: {
722
- const nextRole = mergeRoles(entry.role, accountMeta.role);
723
- if (
724
- // Check to see if this address represents a program that is invoked
725
- // in this transaction.
726
- addressesOfInvokedPrograms.has(account.address)
727
- ) {
728
- if (isWritableRole(accountMeta.role)) {
729
- throw new Error(
730
- `This transaction includes an address (\`${account.address}\`) which is both invoked and marked writable. Program addresses may not be writable.`
731
- );
732
- }
733
- if (entry.role !== nextRole) {
734
- return {
735
- ...entry,
736
- role: nextRole
737
- };
738
- } else {
739
- return entry;
740
- }
741
- } else if ("lookupTableAddress" in accountMeta && // Static accounts can be 'upgraded' to lookup table accounts as
742
- // long as they are not require to sign the transaction.
743
- !isSignerRole(entry.role)) {
744
- return {
745
- ...accountMeta,
746
- [TYPE]: 1 /* LOOKUP_TABLE */,
747
- role: nextRole
748
- };
749
- } else {
750
- if (entry.role !== nextRole) {
751
- return {
752
- ...entry,
753
- role: nextRole
754
- };
755
- } else {
756
- return entry;
757
- }
758
- }
759
- }
760
- }
761
- }
762
- if ("lookupTableAddress" in accountMeta) {
763
- return {
764
- ...accountMeta,
765
- [TYPE]: 1 /* LOOKUP_TABLE */
766
- };
767
- } else {
768
- return {
769
- ...accountMeta,
770
- [TYPE]: 2 /* STATIC */
771
- };
772
- }
773
- });
774
- }
775
- }
776
- return addressMap;
777
- }
778
- function getOrderedAccountsFromAddressMap(addressMap) {
779
- let addressComparator;
780
- const orderedAccounts = Object.entries(addressMap).sort(([leftAddress, leftEntry], [rightAddress, rightEntry]) => {
781
- if (leftEntry[TYPE] !== rightEntry[TYPE]) {
782
- if (leftEntry[TYPE] === 0 /* FEE_PAYER */) {
783
- return -1;
784
- } else if (rightEntry[TYPE] === 0 /* FEE_PAYER */) {
785
- return 1;
786
- } else if (leftEntry[TYPE] === 2 /* STATIC */) {
787
- return -1;
788
- } else if (rightEntry[TYPE] === 2 /* STATIC */) {
789
- return 1;
790
- }
791
- }
792
- const leftIsSigner = isSignerRole(leftEntry.role);
793
- if (leftIsSigner !== isSignerRole(rightEntry.role)) {
794
- return leftIsSigner ? -1 : 1;
795
- }
796
- const leftIsWritable = isWritableRole(leftEntry.role);
797
- if (leftIsWritable !== isWritableRole(rightEntry.role)) {
798
- return leftIsWritable ? -1 : 1;
799
- }
800
- addressComparator || (addressComparator = getBase58EncodedAddressComparator());
801
- if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
802
- return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
803
- } else {
804
- return addressComparator(leftAddress, rightAddress);
805
- }
806
- }).map(([address, addressMeta]) => ({
807
- address,
808
- ...addressMeta
809
- }));
810
- return orderedAccounts;
811
- }
812
-
813
- // src/compile-address-table-lookups.ts
814
- function getCompiledAddressTableLookups(orderedAccounts) {
815
- var _a;
816
- const index = {};
817
- for (const account of orderedAccounts) {
818
- if (!("lookupTableAddress" in account)) {
819
- continue;
820
- }
821
- const entry = index[_a = account.lookupTableAddress] || (index[_a] = {
822
- readableIndices: [],
823
- writableIndices: []
824
- });
825
- if (account.role === AccountRole.WRITABLE) {
826
- entry.writableIndices.push(account.addressIndex);
827
- } else {
828
- entry.readableIndices.push(account.addressIndex);
829
- }
830
- }
831
- return Object.keys(index).sort(getBase58EncodedAddressComparator()).map((lookupTableAddress) => ({
832
- lookupTableAddress,
833
- ...index[lookupTableAddress]
834
- }));
835
- }
836
-
837
- // src/compile-header.ts
838
- function getCompiledMessageHeader(orderedAccounts) {
839
- let numReadonlyNonSignerAccounts = 0;
840
- let numReadonlySignerAccounts = 0;
841
- let numSignerAccounts = 0;
842
- for (const account of orderedAccounts) {
843
- if ("lookupTableAddress" in account) {
844
- break;
845
- }
846
- const accountIsWritable = isWritableRole(account.role);
847
- if (isSignerRole(account.role)) {
848
- numSignerAccounts++;
849
- if (!accountIsWritable) {
850
- numReadonlySignerAccounts++;
851
- }
852
- } else if (!accountIsWritable) {
853
- numReadonlyNonSignerAccounts++;
854
- }
855
- }
856
- return {
857
- numReadonlyNonSignerAccounts,
858
- numReadonlySignerAccounts,
859
- numSignerAccounts
860
- };
861
- }
862
-
863
- // src/compile-instructions.ts
864
- function getAccountIndex(orderedAccounts) {
865
- const out = {};
866
- for (const [index, account] of orderedAccounts.entries()) {
867
- out[account.address] = index;
868
- }
869
- return out;
870
- }
871
- function getCompiledInstructions(instructions, orderedAccounts) {
872
- const accountIndex = getAccountIndex(orderedAccounts);
873
- return instructions.map(({ accounts, data, programAddress }) => {
874
- return {
875
- programAddressIndex: accountIndex[programAddress],
876
- ...accounts ? { accountIndices: accounts.map(({ address }) => accountIndex[address]) } : null,
877
- ...data ? { data } : null
878
- };
879
- });
880
- }
881
-
882
- // src/compile-lifetime-token.ts
883
- function getCompiledLifetimeToken(lifetimeConstraint) {
884
- if ("nonce" in lifetimeConstraint) {
885
- return lifetimeConstraint.nonce;
886
- }
887
- return lifetimeConstraint.blockhash;
888
- }
889
-
890
- // src/compile-static-accounts.ts
891
- function getCompiledStaticAccounts(orderedAccounts) {
892
- const firstLookupTableAccountIndex = orderedAccounts.findIndex((account) => "lookupTableAddress" in account);
893
- const orderedStaticAccounts = firstLookupTableAccountIndex === -1 ? orderedAccounts : orderedAccounts.slice(0, firstLookupTableAccountIndex);
894
- return orderedStaticAccounts.map(({ address }) => address);
895
- }
896
-
897
- // src/message.ts
898
- function compileMessage(transaction) {
899
- const addressMap = getAddressMapFromInstructions(transaction.feePayer, transaction.instructions);
900
- const orderedAccounts = getOrderedAccountsFromAddressMap(addressMap);
901
- return {
902
- ...transaction.version !== "legacy" ? { addressTableLookups: getCompiledAddressTableLookups(orderedAccounts) } : null,
903
- header: getCompiledMessageHeader(orderedAccounts),
904
- instructions: getCompiledInstructions(transaction.instructions, orderedAccounts),
905
- lifetimeToken: getCompiledLifetimeToken(transaction.lifetimeConstraint),
906
- staticAccounts: getCompiledStaticAccounts(orderedAccounts),
907
- version: transaction.version
908
- };
909
- }
910
-
911
- // src/serializers/address-table-lookup.ts
912
- function getAddressTableLookupCodec() {
913
- return struct(
914
- [
915
- [
916
- "lookupTableAddress",
917
- getBase58EncodedAddressCodec(
918
- {
919
- description: "The address of the address lookup table account from which instruction addresses should be looked up"
920
- }
921
- )
922
- ],
923
- [
924
- "writableIndices",
925
- array(u8(), {
926
- ...{
927
- description: "The indices of the accounts in the lookup table that should be loaded as writeable"
928
- } ,
929
- size: shortU16()
930
- })
931
- ],
932
- [
933
- "readableIndices",
934
- array(u8(), {
935
- ...{
936
- description: "The indices of the accounts in the lookup table that should be loaded as read-only"
937
- } ,
938
- size: shortU16()
939
- })
940
- ]
941
- ],
942
- {
943
- 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"
944
- }
945
- );
946
- }
947
-
948
- // src/serializers/header.ts
949
- function getMessageHeaderCodec() {
950
- return struct(
951
- [
952
- [
953
- "numSignerAccounts",
954
- u8(
955
- {
956
- description: "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction"
957
- }
958
- )
959
- ],
960
- [
961
- "numReadonlySignerAccounts",
962
- u8(
963
- {
964
- 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"
965
- }
966
- )
967
- ],
968
- [
969
- "numReadonlyNonSignerAccounts",
970
- u8(
971
- {
972
- description: "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable"
973
- }
974
- )
975
- ]
976
- ],
977
- {
978
- description: "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses"
979
- }
980
- );
981
- }
982
-
983
- // src/serializers/instruction.ts
984
- function getInstructionCodec() {
985
- return mapSerializer(
986
- struct([
987
- [
988
- "programAddressIndex",
989
- u8(
990
- {
991
- description: "The index of the program being called, according to the well-ordered accounts list for this transaction"
992
- }
993
- )
994
- ],
995
- [
996
- "addressIndices",
997
- array(
998
- u8({
999
- description: "The index of an account, according to the well-ordered accounts list for this transaction"
1000
- }),
1001
- {
1002
- 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" ,
1003
- size: shortU16()
1004
- }
1005
- )
1006
- ],
1007
- [
1008
- "data",
1009
- bytes({
1010
- description: "An optional buffer of data passed to the instruction" ,
1011
- size: shortU16()
1012
- })
1013
- ]
1014
- ]),
1015
- (value) => {
1016
- if (value.addressIndices !== void 0 && value.data !== void 0) {
1017
- return value;
1018
- }
1019
- return {
1020
- ...value,
1021
- addressIndices: value.addressIndices ?? [],
1022
- data: value.data ?? new Uint8Array(0)
1023
- };
1024
- },
1025
- (value) => {
1026
- if (value.addressIndices.length && value.data.byteLength) {
1027
- return value;
1028
- }
1029
- const { addressIndices, data, ...rest } = value;
1030
- return {
1031
- ...rest,
1032
- ...addressIndices.length ? { addressIndices } : null,
1033
- ...data.byteLength ? { data } : null
1034
- };
1035
- }
1036
- );
1037
- }
1038
-
1039
- // src/serializers/unimplemented.ts
1040
- function getError(type, name) {
1041
- const functionSuffix = name + type[0].toUpperCase() + type.slice(1);
1042
- return new Error(
1043
- `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}`
1044
- );
1045
- }
1046
- function getUnimplementedDecoder(name) {
1047
- return () => {
1048
- throw getError("decoder", name);
1049
- };
1050
- }
1051
-
1052
- // src/serializers/transaction-version.ts
1053
- var VERSION_FLAG_MASK = 128;
1054
- var BASE_CONFIG = {
1055
- description: "A single byte that encodes the version of the transaction" ,
1056
- fixedSize: null,
1057
- maxSize: 1
1058
- };
1059
- function deserialize(bytes2, offset = 0) {
1060
- const firstByte = bytes2[offset];
1061
- if ((firstByte & VERSION_FLAG_MASK) === 0) {
1062
- return ["legacy", offset];
1063
- } else {
1064
- const version = firstByte ^ VERSION_FLAG_MASK;
1065
- return [version, offset + 1];
1066
- }
1067
- }
1068
- function serialize(value) {
1069
- if (value === "legacy") {
1070
- return new Uint8Array();
1071
- }
1072
- if (value < 0 || value > 127) {
1073
- throw new Error(`Transaction version must be in the range [0, 127]. \`${value}\` given.`);
1074
- }
1075
- return new Uint8Array([value | VERSION_FLAG_MASK]);
1076
- }
1077
- function getTransactionVersionCodec() {
1078
- return {
1079
- ...BASE_CONFIG,
1080
- deserialize,
1081
- serialize
1082
- };
1083
- }
1084
-
1085
- // src/serializers/message.ts
1086
- var BASE_CONFIG2 = {
1087
- description: "The wire format of a Solana transaction message" ,
1088
- fixedSize: null,
1089
- maxSize: null
1090
- };
1091
- function serialize2(compiledMessage) {
1092
- if (compiledMessage.version === "legacy") {
1093
- return struct(getPreludeStructSerializerTuple()).serialize(compiledMessage);
1094
- } else {
1095
- return mapSerializer(
1096
- struct([
1097
- ...getPreludeStructSerializerTuple(),
1098
- ["addressTableLookups", getAddressTableLookupsSerializer()]
1099
- ]),
1100
- (value) => {
1101
- if (value.version === "legacy") {
1102
- return value;
1103
- }
1104
- return {
1105
- ...value,
1106
- addressTableLookups: value.addressTableLookups ?? []
1107
- };
1108
- }
1109
- ).serialize(compiledMessage);
1110
- }
1111
- }
1112
- function getPreludeStructSerializerTuple() {
1113
- return [
1114
- ["version", getTransactionVersionCodec()],
1115
- ["header", getMessageHeaderCodec()],
1116
- [
1117
- "staticAccounts",
1118
- array(getBase58EncodedAddressCodec(), {
1119
- description: "A compact-array of static account addresses belonging to this transaction" ,
1120
- size: shortU16()
1121
- })
1122
- ],
1123
- [
1124
- "lifetimeToken",
1125
- string({
1126
- description: "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" ,
1127
- encoding: base58,
1128
- size: 32
1129
- })
1130
- ],
1131
- [
1132
- "instructions",
1133
- array(getInstructionCodec(), {
1134
- description: "A compact-array of instructions belonging to this transaction" ,
1135
- size: shortU16()
1136
- })
1137
- ]
1138
- ];
1139
- }
1140
- function getAddressTableLookupsSerializer() {
1141
- return array(getAddressTableLookupCodec(), {
1142
- ...{ description: "A compact array of address table lookups belonging to this transaction" } ,
1143
- size: shortU16()
1144
- });
1145
- }
1146
- function getCompiledMessageEncoder() {
1147
- return {
1148
- ...BASE_CONFIG2,
1149
- deserialize: getUnimplementedDecoder("CompiledMessage"),
1150
- serialize: serialize2
1151
- };
1152
- }
1153
-
1154
- // src/signatures.ts
1155
- async function getCompiledMessageSignature(message, secretKey) {
1156
- const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
1157
- const signature = await signBytes(secretKey, wireMessageBytes);
1158
- return signature;
1159
- }
1160
- async function signTransaction(keyPair, transaction) {
1161
- const compiledMessage = compileMessage(transaction);
1162
- const [signerPublicKey, signature] = await Promise.all([
1163
- getBase58EncodedAddressFromPublicKey(keyPair.publicKey),
1164
- getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
1165
- ]);
1166
- const nextSignatures = {
1167
- ..."signatures" in transaction ? transaction.signatures : null,
1168
- ...{ [signerPublicKey]: signature }
1169
- };
1170
- const out = {
1171
- ...transaction,
1172
- signatures: nextSignatures
1173
- };
1174
- Object.freeze(out);
1175
- return out;
1176
- }
1177
-
1178
- exports.appendTransactionInstruction = appendTransactionInstruction;
1179
- exports.createTransaction = createTransaction;
1180
- exports.prependTransactionInstruction = prependTransactionInstruction;
1181
- exports.setTransactionFeePayer = setTransactionFeePayer;
1182
- exports.signTransaction = signTransaction;
1183
-
1184
- return exports;
1185
-
1186
- })({});
1187
- //# sourceMappingURL=out.js.map
1188
- //# sourceMappingURL=index.development.js.map