@solana/transactions 2.0.0-experimental.9ea7d74 → 2.0.0-experimental.a23ca33

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