@solana/transactions 2.0.0-experimental.762ff13 → 2.0.0-experimental.76cf6b4

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 (69) hide show
  1. package/README.md +1 -43
  2. package/dist/index.browser.cjs +260 -429
  3. package/dist/index.browser.cjs.map +1 -1
  4. package/dist/index.browser.js +256 -430
  5. package/dist/index.browser.js.map +1 -1
  6. package/dist/index.development.js +679 -829
  7. package/dist/index.development.js.map +1 -1
  8. package/dist/index.native.js +256 -432
  9. package/dist/index.native.js.map +1 -1
  10. package/dist/index.node.cjs +260 -429
  11. package/dist/index.node.cjs.map +1 -1
  12. package/dist/index.node.js +256 -432
  13. package/dist/index.node.js.map +1 -1
  14. package/dist/index.production.min.js +23 -20
  15. package/dist/types/accounts.d.ts +2 -2
  16. package/dist/types/accounts.d.ts.map +1 -0
  17. package/dist/types/blockhash.d.ts +4 -3
  18. package/dist/types/blockhash.d.ts.map +1 -0
  19. package/dist/types/compilable-transaction.d.ts +7 -0
  20. package/dist/types/compilable-transaction.d.ts.map +1 -0
  21. package/dist/types/compile-address-table-lookups.d.ts +3 -3
  22. package/dist/types/compile-address-table-lookups.d.ts.map +1 -0
  23. package/dist/types/compile-header.d.ts +1 -1
  24. package/dist/types/compile-header.d.ts.map +1 -0
  25. package/dist/types/compile-instructions.d.ts +1 -1
  26. package/dist/types/compile-instructions.d.ts.map +1 -0
  27. package/dist/types/compile-lifetime-token.d.ts +1 -1
  28. package/dist/types/compile-lifetime-token.d.ts.map +1 -0
  29. package/dist/types/compile-static-accounts.d.ts +3 -3
  30. package/dist/types/compile-static-accounts.d.ts.map +1 -0
  31. package/dist/types/compile-transaction.d.ts +6 -7
  32. package/dist/types/compile-transaction.d.ts.map +1 -0
  33. package/dist/types/create-transaction.d.ts +1 -1
  34. package/dist/types/create-transaction.d.ts.map +1 -0
  35. package/dist/types/decompile-transaction.d.ts +3 -5
  36. package/dist/types/decompile-transaction.d.ts.map +1 -0
  37. package/dist/types/durable-nonce.d.ts +5 -5
  38. package/dist/types/durable-nonce.d.ts.map +1 -0
  39. package/dist/types/fee-payer.d.ts +6 -6
  40. package/dist/types/fee-payer.d.ts.map +1 -0
  41. package/dist/types/index.d.ts +11 -9
  42. package/dist/types/index.d.ts.map +1 -0
  43. package/dist/types/instructions.d.ts +2 -2
  44. package/dist/types/instructions.d.ts.map +1 -0
  45. package/dist/types/message.d.ts +6 -10
  46. package/dist/types/message.d.ts.map +1 -0
  47. package/dist/types/serializers/address-table-lookup.d.ts +5 -5
  48. package/dist/types/serializers/address-table-lookup.d.ts.map +1 -0
  49. package/dist/types/serializers/header.d.ts +5 -5
  50. package/dist/types/serializers/header.d.ts.map +1 -0
  51. package/dist/types/serializers/index.d.ts +2 -1
  52. package/dist/types/serializers/index.d.ts.map +1 -0
  53. package/dist/types/serializers/instruction.d.ts +5 -5
  54. package/dist/types/serializers/instruction.d.ts.map +1 -0
  55. package/dist/types/serializers/message.d.ts +5 -5
  56. package/dist/types/serializers/message.d.ts.map +1 -0
  57. package/dist/types/serializers/transaction-version.d.ts +5 -5
  58. package/dist/types/serializers/transaction-version.d.ts.map +1 -0
  59. package/dist/types/serializers/transaction.d.ts +6 -8
  60. package/dist/types/serializers/transaction.d.ts.map +1 -0
  61. package/dist/types/signatures.d.ts +9 -14
  62. package/dist/types/signatures.d.ts.map +1 -0
  63. package/dist/types/types.d.ts +6 -13
  64. package/dist/types/types.d.ts.map +1 -0
  65. package/dist/types/unsigned-transaction.d.ts +1 -1
  66. package/dist/types/unsigned-transaction.d.ts.map +1 -0
  67. package/dist/types/wire-transaction.d.ts +1 -1
  68. package/dist/types/wire-transaction.d.ts.map +1 -0
  69. package/package.json +15 -15
@@ -14,23 +14,6 @@ this.globalThis.solanaWeb3 = (function (exports) {
14
14
  throw new Error(`Codec [${codecDescription}] expected ${expected} bytes, got ${bytesLength}.`);
15
15
  }
16
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);
26
- const result = new Uint8Array(totalLength);
27
- let offset = 0;
28
- nonEmptyByteArrays.forEach((arr) => {
29
- result.set(arr, offset);
30
- offset += arr.length;
31
- });
32
- return result;
33
- };
34
17
  var padBytes = (bytes, length) => {
35
18
  if (bytes.length >= length)
36
19
  return bytes;
@@ -39,77 +22,100 @@ this.globalThis.solanaWeb3 = (function (exports) {
39
22
  return paddedBytes;
40
23
  };
41
24
  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) {
25
+ function getEncodedSize(value, encoder) {
26
+ return "fixedSize" in encoder ? encoder.fixedSize : encoder.getSizeFromValue(value);
27
+ }
28
+ function createEncoder(encoder) {
29
+ return Object.freeze({
30
+ ...encoder,
31
+ encode: (value) => {
32
+ const bytes = new Uint8Array(getEncodedSize(value, encoder));
33
+ encoder.write(value, bytes, 0);
34
+ return bytes;
35
+ }
36
+ });
37
+ }
38
+ function createDecoder(decoder) {
39
+ return Object.freeze({
40
+ ...decoder,
41
+ decode: (bytes, offset = 0) => decoder.read(bytes, offset)[0]
42
+ });
43
+ }
44
+ function isFixedSize(codec) {
45
+ return "fixedSize" in codec && typeof codec.fixedSize === "number";
46
+ }
47
+ function assertIsFixedSize(codec, message) {
48
+ if (!isFixedSize(codec)) {
49
+ throw new Error(message != null ? message : "Expected a fixed-size codec, got a variable-size one.");
50
+ }
51
+ }
52
+ function isVariableSize(codec) {
53
+ return !isFixedSize(codec);
54
+ }
55
+ function combineCodec(encoder, decoder) {
56
+ if (isFixedSize(encoder) !== isFixedSize(decoder)) {
57
+ throw new Error(`Encoder and decoder must either both be fixed-size or variable-size.`);
58
+ }
59
+ if (isFixedSize(encoder) && isFixedSize(decoder) && encoder.fixedSize !== decoder.fixedSize) {
44
60
  throw new Error(
45
61
  `Encoder and decoder must have the same fixed size, got [${encoder.fixedSize}] and [${decoder.fixedSize}].`
46
62
  );
47
63
  }
48
- if (encoder.maxSize !== decoder.maxSize) {
64
+ if (!isFixedSize(encoder) && !isFixedSize(decoder) && encoder.maxSize !== decoder.maxSize) {
49
65
  throw new Error(
50
66
  `Encoder and decoder must have the same max size, got [${encoder.maxSize}] and [${decoder.maxSize}].`
51
67
  );
52
68
  }
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
- );
57
- }
58
69
  return {
70
+ ...decoder,
71
+ ...encoder,
59
72
  decode: decoder.decode,
60
- description: description ?? encoder.description,
61
73
  encode: encoder.encode,
62
- fixedSize: encoder.fixedSize,
63
- maxSize: encoder.maxSize
74
+ read: decoder.read,
75
+ write: encoder.write
64
76
  };
65
77
  }
66
- function fixCodecHelper(data, fixedBytes, description) {
67
- return {
68
- description: description ?? `fixed(${fixedBytes}, ${data.description})`,
78
+ function fixEncoder(encoder, fixedBytes) {
79
+ return createEncoder({
69
80
  fixedSize: fixedBytes,
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
- };
81
+ write: (value, bytes, offset) => {
82
+ const variableByteArray = encoder.encode(value);
83
+ const fixedByteArray = variableByteArray.length > fixedBytes ? variableByteArray.slice(0, fixedBytes) : variableByteArray;
84
+ bytes.set(fixedByteArray, offset);
85
+ return offset + fixedBytes;
86
+ }
87
+ });
78
88
  }
79
- function fixDecoder(decoder, fixedBytes, description) {
80
- return {
81
- ...fixCodecHelper(decoder, fixedBytes, description),
82
- decode: (bytes, offset = 0) => {
89
+ function fixDecoder(decoder, fixedBytes) {
90
+ return createDecoder({
91
+ fixedSize: fixedBytes,
92
+ read: (bytes, offset) => {
83
93
  assertByteArrayHasEnoughBytesForCodec("fixCodec", fixedBytes, bytes, offset);
84
94
  if (offset > 0 || bytes.length > fixedBytes) {
85
95
  bytes = bytes.slice(offset, offset + fixedBytes);
86
96
  }
87
- if (decoder.fixedSize !== null) {
97
+ if (isFixedSize(decoder)) {
88
98
  bytes = fixBytes(bytes, decoder.fixedSize);
89
99
  }
90
- const [value] = decoder.decode(bytes, 0);
100
+ const [value] = decoder.read(bytes, 0);
91
101
  return [value, offset + fixedBytes];
92
102
  }
93
- };
103
+ });
94
104
  }
95
105
  function mapEncoder(encoder, unmap) {
96
- return {
97
- description: encoder.description,
98
- encode: (value) => encoder.encode(unmap(value)),
99
- fixedSize: encoder.fixedSize,
100
- maxSize: encoder.maxSize
101
- };
106
+ return createEncoder({
107
+ ...isVariableSize(encoder) ? { ...encoder, getSizeFromValue: (value) => encoder.getSizeFromValue(unmap(value)) } : encoder,
108
+ write: (value, bytes, offset) => encoder.write(unmap(value), bytes, offset)
109
+ });
102
110
  }
103
111
  function mapDecoder(decoder, map) {
104
- return {
105
- decode: (bytes, offset = 0) => {
106
- const [value, length] = decoder.decode(bytes, offset);
107
- return [map(value, bytes, offset), length];
108
- },
109
- description: decoder.description,
110
- fixedSize: decoder.fixedSize,
111
- maxSize: decoder.maxSize
112
- };
112
+ return createDecoder({
113
+ ...decoder,
114
+ read: (bytes, offset) => {
115
+ const [value, newOffset] = decoder.read(bytes, offset);
116
+ return [map(value, bytes, offset), newOffset];
117
+ }
118
+ });
113
119
  }
114
120
 
115
121
  // ../codecs-numbers/dist/index.browser.js
@@ -120,78 +126,69 @@ this.globalThis.solanaWeb3 = (function (exports) {
120
126
  );
121
127
  }
122
128
  }
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
- };
129
+ function isLittleEndian(config) {
130
+ return (config == null ? void 0 : config.endian) === 1 ? false : true;
136
131
  }
137
132
  function numberEncoderFactory(input) {
138
- const codecData = sharedNumberFactory(input);
139
- return {
140
- description: codecData.description,
141
- encode(value) {
133
+ return createEncoder({
134
+ fixedSize: input.size,
135
+ write(value, bytes, offset) {
142
136
  if (input.range) {
143
137
  assertNumberIsBetweenForCodec(input.name, input.range[0], input.range[1], value);
144
138
  }
145
139
  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
- };
140
+ input.set(new DataView(arrayBuffer), value, isLittleEndian(input.config));
141
+ bytes.set(new Uint8Array(arrayBuffer), offset);
142
+ return offset + input.size;
143
+ }
144
+ });
152
145
  }
153
146
  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);
147
+ return createDecoder({
148
+ fixedSize: input.size,
149
+ read(bytes, offset = 0) {
150
+ assertByteArrayIsNotEmptyForCodec(input.name, bytes, offset);
151
+ assertByteArrayHasEnoughBytesForCodec(input.name, input.size, bytes, offset);
159
152
  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
- };
153
+ return [input.get(view, isLittleEndian(input.config)), offset + input.size];
154
+ }
155
+ });
166
156
  }
167
157
  function toArrayBuffer(bytes, offset, length) {
168
- const bytesOffset = bytes.byteOffset + (offset ?? 0);
169
- const bytesLength = length ?? bytes.byteLength;
158
+ const bytesOffset = bytes.byteOffset + (offset != null ? offset : 0);
159
+ const bytesLength = length != null ? length : bytes.byteLength;
170
160
  return bytes.buffer.slice(bytesOffset, bytesOffset + bytesLength);
171
161
  }
172
- var getShortU16Encoder = (options = {}) => ({
173
- description: options.description ?? "shortU16",
174
- encode: (value) => {
162
+ var getShortU16Encoder = () => createEncoder({
163
+ getSizeFromValue: (value) => {
164
+ if (value <= 127)
165
+ return 1;
166
+ if (value <= 16383)
167
+ return 2;
168
+ return 3;
169
+ },
170
+ maxSize: 3,
171
+ write: (value, bytes, offset) => {
175
172
  assertNumberIsBetweenForCodec("shortU16", 0, 65535, value);
176
- const bytes = [0];
173
+ const shortU16Bytes = [0];
177
174
  for (let ii = 0; ; ii += 1) {
178
175
  const alignedValue = value >> ii * 7;
179
176
  if (alignedValue === 0) {
180
177
  break;
181
178
  }
182
179
  const nextSevenBits = 127 & alignedValue;
183
- bytes[ii] = nextSevenBits;
180
+ shortU16Bytes[ii] = nextSevenBits;
184
181
  if (ii > 0) {
185
- bytes[ii - 1] |= 128;
182
+ shortU16Bytes[ii - 1] |= 128;
186
183
  }
187
184
  }
188
- return new Uint8Array(bytes);
189
- },
190
- fixedSize: null,
191
- maxSize: 3
185
+ bytes.set(shortU16Bytes, offset);
186
+ return offset + shortU16Bytes.length;
187
+ }
192
188
  });
193
- var getShortU16Decoder = (options = {}) => ({
194
- decode: (bytes, offset = 0) => {
189
+ var getShortU16Decoder = () => createDecoder({
190
+ maxSize: 3,
191
+ read: (bytes, offset) => {
195
192
  let value = 0;
196
193
  let byteCount = 0;
197
194
  while (++byteCount) {
@@ -204,35 +201,30 @@ this.globalThis.solanaWeb3 = (function (exports) {
204
201
  }
205
202
  }
206
203
  return [value, offset + byteCount];
207
- },
208
- description: options.description ?? "shortU16",
209
- fixedSize: null,
210
- maxSize: 3
204
+ }
211
205
  });
212
- var getU32Encoder = (options = {}) => numberEncoderFactory({
206
+ var getU32Encoder = (config = {}) => numberEncoderFactory({
207
+ config,
213
208
  name: "u32",
214
- options,
215
209
  range: [0, Number("0xffffffff")],
216
210
  set: (view, value, le) => view.setUint32(0, value, le),
217
211
  size: 4
218
212
  });
219
- var getU32Decoder = (options = {}) => numberDecoderFactory({
213
+ var getU32Decoder = (config = {}) => numberDecoderFactory({
214
+ config,
220
215
  get: (view, le) => view.getUint32(0, le),
221
216
  name: "u32",
222
- options,
223
217
  size: 4
224
218
  });
225
- var getU8Encoder = (options = {}) => numberEncoderFactory({
219
+ var getU8Encoder = () => numberEncoderFactory({
226
220
  name: "u8",
227
- options,
228
221
  range: [0, Number("0xff")],
229
222
  set: (view, value) => view.setUint8(0, value),
230
223
  size: 1
231
224
  });
232
- var getU8Decoder = (options = {}) => numberDecoderFactory({
225
+ var getU8Decoder = () => numberDecoderFactory({
233
226
  get: (view) => view.getUint8(0),
234
227
  name: "u8",
235
- options,
236
228
  size: 1
237
229
  });
238
230
 
@@ -243,43 +235,38 @@ this.globalThis.solanaWeb3 = (function (exports) {
243
235
  }
244
236
  }
245
237
  var getBaseXEncoder = (alphabet4) => {
246
- const base = alphabet4.length;
247
- const baseBigInt = BigInt(base);
248
- return {
249
- description: `base${base}`,
250
- encode(value) {
238
+ return createEncoder({
239
+ getSizeFromValue: (value) => {
240
+ const [leadingZeroes, tailChars] = partitionLeadingZeroes(value, alphabet4[0]);
241
+ if (tailChars === "")
242
+ return value.length;
243
+ const base10Number = getBigIntFromBaseX(tailChars, alphabet4);
244
+ return leadingZeroes.length + Math.ceil(base10Number.toString(16).length / 2);
245
+ },
246
+ write(value, bytes, offset) {
251
247
  assertValidBaseString(alphabet4, value);
252
248
  if (value === "")
253
- return new Uint8Array();
254
- const chars = [...value];
255
- let trailIndex = chars.findIndex((c) => c !== alphabet4[0]);
256
- trailIndex = trailIndex === -1 ? chars.length : trailIndex;
257
- const leadingZeroes = Array(trailIndex).fill(0);
258
- if (trailIndex === chars.length)
259
- return Uint8Array.from(leadingZeroes);
260
- const tailChars = chars.slice(trailIndex);
261
- let base10Number = 0n;
262
- let baseXPower = 1n;
263
- for (let i = tailChars.length - 1; i >= 0; i -= 1) {
264
- base10Number += baseXPower * BigInt(alphabet4.indexOf(tailChars[i]));
265
- baseXPower *= baseBigInt;
249
+ return offset;
250
+ const [leadingZeroes, tailChars] = partitionLeadingZeroes(value, alphabet4[0]);
251
+ if (tailChars === "") {
252
+ bytes.set(new Uint8Array(leadingZeroes.length).fill(0), offset);
253
+ return offset + leadingZeroes.length;
266
254
  }
255
+ let base10Number = getBigIntFromBaseX(tailChars, alphabet4);
267
256
  const tailBytes = [];
268
257
  while (base10Number > 0n) {
269
258
  tailBytes.unshift(Number(base10Number % 256n));
270
259
  base10Number /= 256n;
271
260
  }
272
- return Uint8Array.from(leadingZeroes.concat(tailBytes));
273
- },
274
- fixedSize: null,
275
- maxSize: null
276
- };
261
+ const bytesToAdd = [...Array(leadingZeroes.length).fill(0), ...tailBytes];
262
+ bytes.set(bytesToAdd, offset);
263
+ return offset + bytesToAdd.length;
264
+ }
265
+ });
277
266
  };
278
267
  var getBaseXDecoder = (alphabet4) => {
279
- const base = alphabet4.length;
280
- const baseBigInt = BigInt(base);
281
- return {
282
- decode(rawBytes, offset = 0) {
268
+ return createDecoder({
269
+ read(rawBytes, offset) {
283
270
  const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);
284
271
  if (bytes.length === 0)
285
272
  return ["", 0];
@@ -288,22 +275,43 @@ this.globalThis.solanaWeb3 = (function (exports) {
288
275
  const leadingZeroes = alphabet4[0].repeat(trailIndex);
289
276
  if (trailIndex === bytes.length)
290
277
  return [leadingZeroes, rawBytes.length];
291
- let base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
292
- const tailChars = [];
293
- while (base10Number > 0n) {
294
- tailChars.unshift(alphabet4[Number(base10Number % baseBigInt)]);
295
- base10Number /= baseBigInt;
296
- }
297
- return [leadingZeroes + tailChars.join(""), rawBytes.length];
298
- },
299
- description: `base${base}`,
300
- fixedSize: null,
301
- maxSize: null
302
- };
278
+ const base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
279
+ const tailChars = getBaseXFromBigInt(base10Number, alphabet4);
280
+ return [leadingZeroes + tailChars, rawBytes.length];
281
+ }
282
+ });
303
283
  };
284
+ function partitionLeadingZeroes(value, zeroCharacter) {
285
+ const leadingZeroIndex = [...value].findIndex((c) => c !== zeroCharacter);
286
+ return leadingZeroIndex === -1 ? [value, ""] : [value.slice(0, leadingZeroIndex), value.slice(leadingZeroIndex)];
287
+ }
288
+ function getBigIntFromBaseX(value, alphabet4) {
289
+ const base = BigInt(alphabet4.length);
290
+ return [...value].reduce((sum, char) => sum * base + BigInt(alphabet4.indexOf(char)), 0n);
291
+ }
292
+ function getBaseXFromBigInt(value, alphabet4) {
293
+ const base = BigInt(alphabet4.length);
294
+ const tailChars = [];
295
+ while (value > 0n) {
296
+ tailChars.unshift(alphabet4[Number(value % base)]);
297
+ value /= base;
298
+ }
299
+ return tailChars.join("");
300
+ }
304
301
  var alphabet2 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
305
302
  var getBase58Encoder = () => getBaseXEncoder(alphabet2);
306
303
  var getBase58Decoder = () => getBaseXDecoder(alphabet2);
304
+ var getBase64Decoder = () => {
305
+ {
306
+ return createDecoder({
307
+ read(bytes, offset = 0) {
308
+ const slice = bytes.slice(offset);
309
+ const value = btoa(String.fromCharCode(...slice));
310
+ return [value, bytes.length];
311
+ }
312
+ });
313
+ }
314
+ };
307
315
  var removeNullCharacters = (value) => (
308
316
  // eslint-disable-next-line no-control-regex
309
317
  value.replace(/\u0000/g, "")
@@ -312,75 +320,69 @@ this.globalThis.solanaWeb3 = (function (exports) {
312
320
  var o = globalThis.TextEncoder;
313
321
  var getUtf8Encoder = () => {
314
322
  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
- };
323
+ return createEncoder({
324
+ getSizeFromValue: (value) => (textEncoder || (textEncoder = new o())).encode(value).length,
325
+ write: (value, bytes, offset) => {
326
+ const bytesToAdd = (textEncoder || (textEncoder = new o())).encode(value);
327
+ bytes.set(bytesToAdd, offset);
328
+ return offset + bytesToAdd.length;
329
+ }
330
+ });
321
331
  };
322
332
  var getUtf8Decoder = () => {
323
333
  let textDecoder;
324
- return {
325
- decode(bytes, offset = 0) {
334
+ return createDecoder({
335
+ read(bytes, offset) {
326
336
  const value = (textDecoder || (textDecoder = new e())).decode(bytes.slice(offset));
327
337
  return [removeNullCharacters(value), bytes.length];
328
- },
329
- description: "utf8",
330
- fixedSize: null,
331
- maxSize: null
332
- };
338
+ }
339
+ });
333
340
  };
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)})`;
341
+ function getStringEncoder(config = {}) {
342
+ var _a, _b;
343
+ const size = (_a = config.size) != null ? _a : getU32Encoder();
344
+ const encoding = (_b = config.encoding) != null ? _b : getUtf8Encoder();
338
345
  if (size === "variable") {
339
- return { ...encoding, description };
346
+ return encoding;
340
347
  }
341
348
  if (typeof size === "number") {
342
- return fixEncoder(encoding, size, description);
349
+ return fixEncoder(encoding, size);
343
350
  }
344
- return {
345
- description,
346
- encode: (value) => {
347
- const contentBytes = encoding.encode(value);
348
- const lengthBytes = size.encode(contentBytes.length);
349
- return mergeBytes([lengthBytes, contentBytes]);
351
+ return createEncoder({
352
+ getSizeFromValue: (value) => {
353
+ const contentSize = getEncodedSize(value, encoding);
354
+ return getEncodedSize(contentSize, size) + contentSize;
350
355
  },
351
- fixedSize: null,
352
- maxSize: null
353
- };
354
- };
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)})`;
356
+ write: (value, bytes, offset) => {
357
+ const contentSize = getEncodedSize(value, encoding);
358
+ offset = size.write(contentSize, bytes, offset);
359
+ return encoding.write(value, bytes, offset);
360
+ }
361
+ });
362
+ }
363
+ function getStringDecoder(config = {}) {
364
+ var _a, _b;
365
+ const size = (_a = config.size) != null ? _a : getU32Decoder();
366
+ const encoding = (_b = config.encoding) != null ? _b : getUtf8Decoder();
359
367
  if (size === "variable") {
360
- return { ...encoding, description };
368
+ return encoding;
361
369
  }
362
370
  if (typeof size === "number") {
363
- return fixDecoder(encoding, size, description);
371
+ return fixDecoder(encoding, size);
364
372
  }
365
- return {
366
- decode: (bytes, offset = 0) => {
373
+ return createDecoder({
374
+ read: (bytes, offset = 0) => {
367
375
  assertByteArrayIsNotEmptyForCodec("string", bytes, offset);
368
- const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);
376
+ const [lengthBigInt, lengthOffset] = size.read(bytes, offset);
369
377
  const length = Number(lengthBigInt);
370
378
  offset = lengthOffset;
371
379
  const contentBytes = bytes.slice(offset, offset + length);
372
380
  assertByteArrayHasEnoughBytesForCodec("string", length, contentBytes);
373
- const [value, contentOffset] = encoding.decode(contentBytes);
381
+ const [value, contentOffset] = encoding.read(contentBytes, 0);
374
382
  offset += contentOffset;
375
383
  return [value, offset];
376
- },
377
- description,
378
- fixedSize: null,
379
- maxSize: null
380
- };
381
- };
382
- function getSizeDescription(size) {
383
- return typeof size === "object" ? size.description : `${size}`;
384
+ }
385
+ });
384
386
  }
385
387
 
386
388
  // src/unsigned-transaction.ts
@@ -421,6 +423,22 @@ this.globalThis.solanaWeb3 = (function (exports) {
421
423
  });
422
424
  }
423
425
  }
426
+ function isTransactionWithBlockhashLifetime(transaction) {
427
+ const lifetimeConstraintShapeMatches = "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.blockhash === "string" && typeof transaction.lifetimeConstraint.lastValidBlockHeight === "bigint";
428
+ if (!lifetimeConstraintShapeMatches)
429
+ return false;
430
+ try {
431
+ assertIsBlockhash(transaction.lifetimeConstraint.blockhash);
432
+ return true;
433
+ } catch {
434
+ return false;
435
+ }
436
+ }
437
+ function assertIsTransactionWithBlockhashLifetime(transaction) {
438
+ if (!isTransactionWithBlockhashLifetime(transaction)) {
439
+ throw new Error("Transaction does not have a blockhash lifetime");
440
+ }
441
+ }
424
442
  function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {
425
443
  if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
426
444
  return transaction;
@@ -491,9 +509,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
491
509
  };
492
510
  }
493
511
  function isAdvanceNonceAccountInstruction(instruction) {
512
+ var _a;
494
513
  return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
495
514
  instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts
496
- instruction.accounts?.length === 3 && // First account is nonce account address
515
+ ((_a = instruction.accounts) == null ? void 0 : _a.length) === 3 && // First account is nonce account address
497
516
  instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole.WRITABLE && // Second account is recent blockhashes sysvar
498
517
  instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole.READONLY && // Third account is nonce authority account
499
518
  instruction.accounts[2].address != null && isSignerRole(instruction.accounts[2].role);
@@ -575,184 +594,6 @@ this.globalThis.solanaWeb3 = (function (exports) {
575
594
  return out;
576
595
  }
577
596
 
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) {
583
- if (typeof size === "number") {
584
- return [size, offset];
585
- }
586
- if (typeof size === "object") {
587
- return size.decode(bytes, offset);
588
- }
589
- if (size === "remainder") {
590
- const childrenSize = sumCodecSizes(childrenSizes);
591
- if (childrenSize === null) {
592
- throw new Error('Codecs of "remainder" size must have fixed-size items.');
593
- }
594
- const remainder = bytes.slice(offset).length;
595
- if (remainder % childrenSize !== 0) {
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
- );
599
- }
600
- return [remainder / childrenSize, offset];
601
- }
602
- throw new Error(`Unrecognized array-like codec size: ${JSON.stringify(size)}`);
603
- }
604
- function getArrayLikeCodecSizeDescription(size) {
605
- return typeof size === "object" ? size.description : `${size}`;
606
- }
607
- function getArrayLikeCodecSizeFromChildren(size, childrenSizes) {
608
- if (typeof size !== "number")
609
- return null;
610
- if (size === 0)
611
- return 0;
612
- const childrenSize = sumCodecSizes(childrenSizes);
613
- return childrenSize === null ? null : childrenSize * size;
614
- }
615
- function getArrayLikeCodecSizePrefix(size, realSize) {
616
- return typeof size === "object" ? size.encode(realSize) : new Uint8Array();
617
- }
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) {
624
- if (size === "remainder" && item.fixedSize === null) {
625
- throw new Error('Codecs of "remainder" size must have fixed-size items.');
626
- }
627
- return {
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);
640
- }
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) {
651
- return [[], offset];
652
- }
653
- const [resolvedSize, newOffset] = decodeArrayLikeCodecSize(size, [item.fixedSize], bytes, offset);
654
- offset = newOffset;
655
- const values = [];
656
- for (let i = 0; i < resolvedSize; i += 1) {
657
- const [value, newOffset2] = item.decode(bytes, offset);
658
- values.push(value);
659
- offset = newOffset2;
660
- }
661
- return [values, offset];
662
- }
663
- };
664
- }
665
- function getBytesEncoder(options = {}) {
666
- const size = options.size ?? "variable";
667
- const sizeDescription = typeof size === "object" ? size.description : `${size}`;
668
- const description = options.description ?? `bytes(${sizeDescription})`;
669
- const byteEncoder = {
670
- description,
671
- encode: (value) => value,
672
- fixedSize: null,
673
- maxSize: null
674
- };
675
- if (size === "variable") {
676
- return byteEncoder;
677
- }
678
- if (typeof size === "number") {
679
- return fixEncoder(byteEncoder, size, description);
680
- }
681
- return {
682
- ...byteEncoder,
683
- encode: (value) => {
684
- const contentBytes = byteEncoder.encode(value);
685
- const lengthBytes = size.encode(contentBytes.length);
686
- return mergeBytes([lengthBytes, contentBytes]);
687
- }
688
- };
689
- }
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
- };
703
- if (size === "variable") {
704
- return byteDecoder;
705
- }
706
- if (typeof size === "number") {
707
- return fixDecoder(byteDecoder, size, description);
708
- }
709
- return {
710
- ...byteDecoder,
711
- decode: (bytes, offset = 0) => {
712
- assertByteArrayIsNotEmptyForCodec("bytes", bytes, offset);
713
- const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);
714
- const length = Number(lengthBigInt);
715
- offset = lengthOffset;
716
- const contentBytes = bytes.slice(offset, offset + length);
717
- assertByteArrayHasEnoughBytesForCodec("bytes", length, contentBytes);
718
- const [value, contentOffset] = byteDecoder.decode(contentBytes);
719
- offset += contentOffset;
720
- return [value, offset];
721
- }
722
- };
723
- }
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 = {}) {
733
- return {
734
- ...structCodecHelper(fields, options.description),
735
- encode: (struct) => {
736
- const fieldBytes = fields.map(([key, codec]) => codec.encode(struct[key]));
737
- return mergeBytes(fieldBytes);
738
- }
739
- };
740
- }
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];
752
- }
753
- };
754
- }
755
-
756
597
  // ../assertions/dist/index.browser.js
757
598
  function assertIsSecureContext() {
758
599
  if (!globalThis.isSecureContext) {
@@ -762,14 +603,16 @@ this.globalThis.solanaWeb3 = (function (exports) {
762
603
  }
763
604
  }
764
605
  async function assertKeyExporterIsAvailable() {
606
+ var _a;
765
607
  assertIsSecureContext();
766
- if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.exportKey !== "function") {
608
+ if (typeof globalThis.crypto === "undefined" || typeof ((_a = globalThis.crypto.subtle) == null ? void 0 : _a.exportKey) !== "function") {
767
609
  throw new Error("No key export implementation could be found");
768
610
  }
769
611
  }
770
612
  async function assertSigningCapabilityIsAvailable() {
613
+ var _a;
771
614
  assertIsSecureContext();
772
- if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.sign !== "function") {
615
+ if (typeof globalThis.crypto === "undefined" || typeof ((_a = globalThis.crypto.subtle) == null ? void 0 : _a.sign) !== "function") {
773
616
  throw new Error("No signing implementation could be found");
774
617
  }
775
618
  }
@@ -787,47 +630,39 @@ this.globalThis.solanaWeb3 = (function (exports) {
787
630
  memoizedBase58Decoder = getBase58Decoder();
788
631
  return memoizedBase58Decoder;
789
632
  }
790
- function assertIsAddress(putativeBase58EncodedAddress) {
633
+ function assertIsAddress(putativeAddress) {
791
634
  try {
792
635
  if (
793
636
  // Lowest address (32 bytes of zeroes)
794
- putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
795
- putativeBase58EncodedAddress.length > 44
637
+ putativeAddress.length < 32 || // Highest address (32 bytes of 255)
638
+ putativeAddress.length > 44
796
639
  ) {
797
640
  throw new Error("Expected input string to decode to a byte array of length 32.");
798
641
  }
799
- const base58Encoder3 = getMemoizedBase58Encoder();
800
- const bytes = base58Encoder3.encode(putativeBase58EncodedAddress);
642
+ const base58Encoder2 = getMemoizedBase58Encoder();
643
+ const bytes = base58Encoder2.encode(putativeAddress);
801
644
  const numBytes = bytes.byteLength;
802
645
  if (numBytes !== 32) {
803
646
  throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
804
647
  }
805
648
  } catch (e2) {
806
- throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
649
+ throw new Error(`\`${putativeAddress}\` is not a base-58 encoded address`, {
807
650
  cause: e2
808
651
  });
809
652
  }
810
653
  }
811
- function address(putativeBase58EncodedAddress) {
812
- assertIsAddress(putativeBase58EncodedAddress);
813
- return putativeBase58EncodedAddress;
654
+ function address(putativeAddress) {
655
+ assertIsAddress(putativeAddress);
656
+ return putativeAddress;
814
657
  }
815
- function getAddressEncoder(config) {
658
+ function getAddressEncoder() {
816
659
  return mapEncoder(
817
- getStringEncoder({
818
- description: config?.description ?? "Base58EncodedAddress",
819
- encoding: getMemoizedBase58Encoder(),
820
- size: 32
821
- }),
660
+ getStringEncoder({ encoding: getMemoizedBase58Encoder(), size: 32 }),
822
661
  (putativeAddress) => address(putativeAddress)
823
662
  );
824
663
  }
825
- function getAddressDecoder(config) {
826
- return getStringDecoder({
827
- description: config?.description ?? "Base58EncodedAddress",
828
- encoding: getMemoizedBase58Decoder(),
829
- size: 32
830
- });
664
+ function getAddressDecoder() {
665
+ return getStringDecoder({ encoding: getMemoizedBase58Decoder(), size: 32 });
831
666
  }
832
667
  function getAddressComparator() {
833
668
  return new Intl.Collator("en", {
@@ -845,13 +680,13 @@ this.globalThis.solanaWeb3 = (function (exports) {
845
680
  throw new Error("The `CryptoKey` must be an `Ed25519` public key");
846
681
  }
847
682
  const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
848
- const [base58EncodedAddress] = getAddressDecoder().decode(new Uint8Array(publicKeyBytes));
849
- return base58EncodedAddress;
683
+ return getAddressDecoder().decode(new Uint8Array(publicKeyBytes));
850
684
  }
851
685
 
852
686
  // src/accounts.ts
853
687
  function upsert(addressMap, address2, update) {
854
- addressMap[address2] = update(addressMap[address2] ?? { role: AccountRole.READONLY });
688
+ var _a;
689
+ addressMap[address2] = update((_a = addressMap[address2]) != null ? _a : { role: AccountRole.READONLY });
855
690
  }
856
691
  var TYPE = Symbol("AddressMapTypeProperty");
857
692
  function getAddressMapFromInstructions(feePayer, instructions) {
@@ -1119,195 +954,223 @@ this.globalThis.solanaWeb3 = (function (exports) {
1119
954
  };
1120
955
  }
1121
956
 
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)));
957
+ // ../codecs-data-structures/dist/index.browser.js
958
+ function assertValidNumberOfItemsForCodec(codecDescription, expected, actual) {
959
+ if (expected !== actual) {
960
+ throw new Error(`Expected [${codecDescription}] to have ${expected} items, got ${actual}.`);
1133
961
  }
1134
- return {
1135
- compiledMessage,
1136
- signatures
1137
- };
1138
962
  }
1139
-
1140
- // ../functional/dist/index.browser.js
1141
- function pipe(init, ...fns) {
1142
- return fns.reduce((acc, fn) => fn(acc), init);
963
+ function sumCodecSizes(sizes) {
964
+ return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
1143
965
  }
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++;
966
+ function getFixedSize(codec) {
967
+ return isFixedSize(codec) ? codec.fixedSize : null;
968
+ }
969
+ function getMaxSize(codec) {
970
+ var _a;
971
+ return isFixedSize(codec) ? codec.fixedSize : (_a = codec.maxSize) != null ? _a : null;
972
+ }
973
+ function getArrayEncoder(item, config = {}) {
974
+ var _a, _b;
975
+ const size = (_a = config.size) != null ? _a : getU32Encoder();
976
+ if (size === "remainder") {
977
+ assertIsFixedSize(item, 'Codecs of "remainder" size must have fixed-size items.');
1158
978
  }
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++;
979
+ const fixedSize = computeArrayLikeCodecSize(size, getFixedSize(item));
980
+ const maxSize = (_b = computeArrayLikeCodecSize(size, getMaxSize(item))) != null ? _b : void 0;
981
+ return createEncoder({
982
+ ...fixedSize !== null ? { fixedSize } : {
983
+ getSizeFromValue: (array) => {
984
+ const prefixSize = typeof size === "object" ? getEncodedSize(array.length, size) : 0;
985
+ return prefixSize + [...array].reduce((all, value) => all + getEncodedSize(value, item), 0);
986
+ },
987
+ maxSize
988
+ },
989
+ write: (array, bytes, offset) => {
990
+ if (typeof size === "number") {
991
+ assertValidNumberOfItemsForCodec("array", size, array.length);
992
+ }
993
+ if (typeof size === "object") {
994
+ offset = size.write(array.length, bytes, offset);
995
+ }
996
+ array.forEach((value) => {
997
+ offset = item.write(value, bytes, offset);
998
+ });
999
+ return offset;
1000
+ }
1001
+ });
1002
+ }
1003
+ function getArrayDecoder(item, config = {}) {
1004
+ var _a, _b;
1005
+ const size = (_a = config.size) != null ? _a : getU32Decoder();
1006
+ if (size === "remainder") {
1007
+ assertIsFixedSize(item, 'Codecs of "remainder" size must have fixed-size items.');
1165
1008
  }
1166
- for (let i = 0; i < numWritableNonSignerAccounts; i++) {
1167
- accountMetas.push({
1168
- address: message.staticAccounts[accountIndex],
1169
- role: AccountRole.WRITABLE
1170
- });
1171
- accountIndex++;
1009
+ const itemSize = getFixedSize(item);
1010
+ const fixedSize = computeArrayLikeCodecSize(size, itemSize);
1011
+ const maxSize = (_b = computeArrayLikeCodecSize(size, getMaxSize(item))) != null ? _b : void 0;
1012
+ return createDecoder({
1013
+ ...fixedSize !== null ? { fixedSize } : { maxSize },
1014
+ read: (bytes, offset) => {
1015
+ const array = [];
1016
+ if (typeof size === "object" && bytes.slice(offset).length === 0) {
1017
+ return [array, offset];
1018
+ }
1019
+ const [resolvedSize, newOffset] = readArrayLikeCodecSize(size, itemSize, bytes, offset);
1020
+ offset = newOffset;
1021
+ for (let i = 0; i < resolvedSize; i += 1) {
1022
+ const [value, newOffset2] = item.read(bytes, offset);
1023
+ offset = newOffset2;
1024
+ array.push(value);
1025
+ }
1026
+ return [array, offset];
1027
+ }
1028
+ });
1029
+ }
1030
+ function readArrayLikeCodecSize(size, itemSize, bytes, offset) {
1031
+ if (typeof size === "number") {
1032
+ return [size, offset];
1172
1033
  }
1173
- for (let i = 0; i < header.numReadonlyNonSignerAccounts; i++) {
1174
- accountMetas.push({
1175
- address: message.staticAccounts[accountIndex],
1176
- role: AccountRole.READONLY
1177
- });
1178
- accountIndex++;
1034
+ if (typeof size === "object") {
1035
+ return size.read(bytes, offset);
1179
1036
  }
1180
- return accountMetas;
1037
+ if (size === "remainder") {
1038
+ if (itemSize === null) {
1039
+ throw new Error('Codecs of "remainder" size must have fixed-size items.');
1040
+ }
1041
+ const remainder = Math.max(0, bytes.length - offset);
1042
+ if (remainder % itemSize !== 0) {
1043
+ throw new Error(
1044
+ `The remainder of the byte array (${remainder} bytes) cannot be split into chunks of ${itemSize} bytes. Codecs of "remainder" size must have a remainder that is a multiple of its item size. In other words, ${remainder} modulo ${itemSize} should be equal to zero.`
1045
+ );
1046
+ }
1047
+ return [remainder / itemSize, offset];
1048
+ }
1049
+ throw new Error(`Unrecognized array-like codec size: ${JSON.stringify(size)}`);
1181
1050
  }
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}`);
1051
+ function computeArrayLikeCodecSize(size, itemSize) {
1052
+ if (typeof size !== "number")
1053
+ return null;
1054
+ if (size === 0)
1055
+ return 0;
1056
+ return itemSize === null ? null : itemSize * size;
1057
+ }
1058
+ function getBytesEncoder(config = {}) {
1059
+ var _a;
1060
+ const size = (_a = config.size) != null ? _a : "variable";
1061
+ const byteEncoder = createEncoder({
1062
+ getSizeFromValue: (value) => value.length,
1063
+ write: (value, bytes, offset) => {
1064
+ bytes.set(value, offset);
1065
+ return offset + value.length;
1066
+ }
1067
+ });
1068
+ if (size === "variable") {
1069
+ return byteEncoder;
1186
1070
  }
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
- };
1071
+ if (typeof size === "number") {
1072
+ return fixEncoder(byteEncoder, size);
1073
+ }
1074
+ return createEncoder({
1075
+ getSizeFromValue: (value) => getEncodedSize(value.length, size) + value.length,
1076
+ write: (value, bytes, offset) => {
1077
+ offset = size.write(value.length, bytes, offset);
1078
+ return byteEncoder.write(value, bytes, offset);
1079
+ }
1080
+ });
1194
1081
  }
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
- };
1082
+ function getBytesDecoder(config = {}) {
1083
+ var _a;
1084
+ const size = (_a = config.size) != null ? _a : "variable";
1085
+ const byteDecoder = createDecoder({
1086
+ read: (bytes, offset) => {
1087
+ const slice = bytes.slice(offset);
1088
+ return [slice, offset + slice.length];
1089
+ }
1090
+ });
1091
+ if (size === "variable") {
1092
+ return byteDecoder;
1093
+ }
1094
+ if (typeof size === "number") {
1095
+ return fixDecoder(byteDecoder, size);
1212
1096
  }
1097
+ return createDecoder({
1098
+ read: (bytes, offset) => {
1099
+ assertByteArrayIsNotEmptyForCodec("bytes", bytes, offset);
1100
+ const [lengthBigInt, lengthOffset] = size.read(bytes, offset);
1101
+ const length = Number(lengthBigInt);
1102
+ offset = lengthOffset;
1103
+ const contentBytes = bytes.slice(offset, offset + length);
1104
+ assertByteArrayHasEnoughBytesForCodec("bytes", length, contentBytes);
1105
+ const [value, contentOffset] = byteDecoder.read(contentBytes, 0);
1106
+ offset += contentOffset;
1107
+ return [value, offset];
1108
+ }
1109
+ });
1213
1110
  }
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
- }, {});
1111
+ function getStructEncoder(fields) {
1112
+ var _a;
1113
+ const fieldCodecs = fields.map(([, codec]) => codec);
1114
+ const fixedSize = sumCodecSizes(fieldCodecs.map(getFixedSize));
1115
+ const maxSize = (_a = sumCodecSizes(fieldCodecs.map(getMaxSize))) != null ? _a : void 0;
1116
+ return createEncoder({
1117
+ ...fixedSize === null ? {
1118
+ getSizeFromValue: (value) => fields.map(([key, codec]) => getEncodedSize(value[key], codec)).reduce((all, one) => all + one, 0),
1119
+ maxSize
1120
+ } : { fixedSize },
1121
+ write: (struct, bytes, offset) => {
1122
+ fields.forEach(([key, codec]) => {
1123
+ offset = codec.write(struct[key], bytes, offset);
1124
+ });
1125
+ return offset;
1126
+ }
1127
+ });
1226
1128
  }
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
- );
1129
+ function getStructDecoder(fields) {
1130
+ var _a;
1131
+ const fieldCodecs = fields.map(([, codec]) => codec);
1132
+ const fixedSize = sumCodecSizes(fieldCodecs.map(getFixedSize));
1133
+ const maxSize = (_a = sumCodecSizes(fieldCodecs.map(getMaxSize))) != null ? _a : void 0;
1134
+ return createDecoder({
1135
+ ...fixedSize === null ? { maxSize } : { fixedSize },
1136
+ read: (bytes, offset) => {
1137
+ const struct = {};
1138
+ fields.forEach(([key, codec]) => {
1139
+ const [value, newOffset] = codec.read(bytes, offset);
1140
+ offset = newOffset;
1141
+ struct[key] = value;
1142
+ });
1143
+ return [struct, offset];
1144
+ }
1145
+ });
1255
1146
  }
1256
1147
 
1257
1148
  // src/serializers/address-table-lookup.ts
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
1149
  var memoizedAddressTableLookupEncoder;
1263
1150
  function getAddressTableLookupEncoder() {
1264
1151
  if (!memoizedAddressTableLookupEncoder) {
1265
- memoizedAddressTableLookupEncoder = getStructEncoder(
1152
+ memoizedAddressTableLookupEncoder = getStructEncoder([
1153
+ ["lookupTableAddress", getAddressEncoder()],
1266
1154
  [
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
- ]
1155
+ "writableIndices",
1156
+ getArrayEncoder(getU8Encoder(), { size: getShortU16Encoder() })
1282
1157
  ],
1283
- { description: addressTableLookupDescription }
1284
- );
1158
+ [
1159
+ "readableIndices",
1160
+ getArrayEncoder(getU8Encoder(), { size: getShortU16Encoder() })
1161
+ ]
1162
+ ]);
1285
1163
  }
1286
1164
  return memoizedAddressTableLookupEncoder;
1287
1165
  }
1288
1166
  var memoizedAddressTableLookupDecoder;
1289
1167
  function getAddressTableLookupDecoder() {
1290
1168
  if (!memoizedAddressTableLookupDecoder) {
1291
- memoizedAddressTableLookupDecoder = getStructDecoder(
1292
- [
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
- ]
1308
- ],
1309
- { description: addressTableLookupDescription }
1310
- );
1169
+ memoizedAddressTableLookupDecoder = getStructDecoder([
1170
+ ["lookupTableAddress", getAddressDecoder()],
1171
+ ["writableIndices", getArrayDecoder(getU8Decoder(), { size: getShortU16Decoder() })],
1172
+ ["readableIndices", getArrayDecoder(getU8Decoder(), { size: getShortU16Decoder() })]
1173
+ ]);
1311
1174
  }
1312
1175
  return memoizedAddressTableLookupDecoder;
1313
1176
  }
@@ -1319,84 +1182,47 @@ this.globalThis.solanaWeb3 = (function (exports) {
1319
1182
  memoizedU8Encoder = getU8Encoder();
1320
1183
  return memoizedU8Encoder;
1321
1184
  }
1322
- function getMemoizedU8EncoderDescription(description) {
1323
- const encoder = getMemoizedU8Encoder();
1324
- return {
1325
- ...encoder,
1326
- description: description ?? encoder.description
1327
- };
1328
- }
1329
1185
  var memoizedU8Decoder;
1330
1186
  function getMemoizedU8Decoder() {
1331
1187
  if (!memoizedU8Decoder)
1332
1188
  memoizedU8Decoder = getU8Decoder();
1333
1189
  return memoizedU8Decoder;
1334
1190
  }
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
1191
  function getMessageHeaderEncoder() {
1347
- return getStructEncoder(
1348
- [
1349
- ["numSignerAccounts", getMemoizedU8EncoderDescription(numSignerAccountsDescription)],
1350
- ["numReadonlySignerAccounts", getMemoizedU8EncoderDescription(numReadonlySignerAccountsDescription)],
1351
- ["numReadonlyNonSignerAccounts", getMemoizedU8EncoderDescription(numReadonlyNonSignerAccountsDescription)]
1352
- ],
1353
- {
1354
- description: messageHeaderDescription
1355
- }
1356
- );
1192
+ return getStructEncoder([
1193
+ ["numSignerAccounts", getMemoizedU8Encoder()],
1194
+ ["numReadonlySignerAccounts", getMemoizedU8Encoder()],
1195
+ ["numReadonlyNonSignerAccounts", getMemoizedU8Encoder()]
1196
+ ]);
1357
1197
  }
1358
1198
  function getMessageHeaderDecoder() {
1359
- return getStructDecoder(
1360
- [
1361
- ["numSignerAccounts", getMemoizedU8DecoderDescription(numSignerAccountsDescription)],
1362
- ["numReadonlySignerAccounts", getMemoizedU8DecoderDescription(numReadonlySignerAccountsDescription)],
1363
- ["numReadonlyNonSignerAccounts", getMemoizedU8DecoderDescription(numReadonlyNonSignerAccountsDescription)]
1364
- ],
1365
- {
1366
- description: messageHeaderDescription
1367
- }
1368
- );
1199
+ return getStructDecoder([
1200
+ ["numSignerAccounts", getMemoizedU8Decoder()],
1201
+ ["numReadonlySignerAccounts", getMemoizedU8Decoder()],
1202
+ ["numReadonlyNonSignerAccounts", getMemoizedU8Decoder()]
1203
+ ]);
1369
1204
  }
1370
1205
 
1371
1206
  // 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
1207
  var memoizedGetInstructionEncoder;
1377
1208
  function getInstructionEncoder() {
1378
1209
  if (!memoizedGetInstructionEncoder) {
1379
1210
  memoizedGetInstructionEncoder = mapEncoder(
1380
1211
  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() })]
1212
+ ["programAddressIndex", getU8Encoder()],
1213
+ ["accountIndices", getArrayEncoder(getU8Encoder(), { size: getShortU16Encoder() })],
1214
+ ["data", getBytesEncoder({ size: getShortU16Encoder() })]
1390
1215
  ]),
1391
1216
  // Convert an instruction to have all fields defined
1392
1217
  (instruction) => {
1218
+ var _a, _b;
1393
1219
  if (instruction.accountIndices !== void 0 && instruction.data !== void 0) {
1394
1220
  return instruction;
1395
1221
  }
1396
1222
  return {
1397
1223
  ...instruction,
1398
- accountIndices: instruction.accountIndices ?? [],
1399
- data: instruction.data ?? new Uint8Array(0)
1224
+ accountIndices: (_a = instruction.accountIndices) != null ? _a : [],
1225
+ data: (_b = instruction.data) != null ? _b : new Uint8Array(0)
1400
1226
  };
1401
1227
  }
1402
1228
  );
@@ -1408,15 +1234,9 @@ this.globalThis.solanaWeb3 = (function (exports) {
1408
1234
  if (!memoizedGetInstructionDecoder) {
1409
1235
  memoizedGetInstructionDecoder = mapDecoder(
1410
1236
  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() })]
1237
+ ["programAddressIndex", getU8Decoder()],
1238
+ ["accountIndices", getArrayDecoder(getU8Decoder(), { size: getShortU16Decoder() })],
1239
+ ["data", getBytesDecoder({ size: getShortU16Decoder() })]
1420
1240
  ]),
1421
1241
  // Convert an instruction to exclude optional fields if they are empty
1422
1242
  (instruction) => {
@@ -1437,47 +1257,38 @@ this.globalThis.solanaWeb3 = (function (exports) {
1437
1257
 
1438
1258
  // src/serializers/transaction-version.ts
1439
1259
  var VERSION_FLAG_MASK = 128;
1440
- var BASE_CONFIG = {
1441
- description: "A single byte that encodes the version of the transaction" ,
1442
- fixedSize: null,
1443
- maxSize: 1
1444
- };
1445
- function decode(bytes, offset = 0) {
1446
- const firstByte = bytes[offset];
1447
- if ((firstByte & VERSION_FLAG_MASK) === 0) {
1448
- return ["legacy", offset];
1449
- } else {
1450
- const version = firstByte ^ VERSION_FLAG_MASK;
1451
- return [version, offset + 1];
1452
- }
1453
- }
1454
- function encode(value) {
1455
- if (value === "legacy") {
1456
- return new Uint8Array();
1457
- }
1458
- if (value < 0 || value > 127) {
1459
- throw new Error(`Transaction version must be in the range [0, 127]. \`${value}\` given.`);
1460
- }
1461
- return new Uint8Array([value | VERSION_FLAG_MASK]);
1260
+ function getTransactionVersionEncoder() {
1261
+ return createEncoder({
1262
+ getSizeFromValue: (value) => value === "legacy" ? 0 : 1,
1263
+ maxSize: 1,
1264
+ write: (value, bytes, offset) => {
1265
+ if (value === "legacy") {
1266
+ return offset;
1267
+ }
1268
+ if (value < 0 || value > 127) {
1269
+ throw new Error(`Transaction version must be in the range [0, 127]. \`${value}\` given.`);
1270
+ }
1271
+ bytes.set([value | VERSION_FLAG_MASK], offset);
1272
+ return offset + 1;
1273
+ }
1274
+ });
1462
1275
  }
1463
1276
  function getTransactionVersionDecoder() {
1464
- return {
1465
- ...BASE_CONFIG,
1466
- decode
1467
- };
1468
- }
1469
- function getTransactionVersionEncoder() {
1470
- return {
1471
- ...BASE_CONFIG,
1472
- encode
1473
- };
1277
+ return createDecoder({
1278
+ maxSize: 1,
1279
+ read: (bytes, offset) => {
1280
+ const firstByte = bytes[offset];
1281
+ if ((firstByte & VERSION_FLAG_MASK) === 0) {
1282
+ return ["legacy", offset];
1283
+ } else {
1284
+ const version = firstByte ^ VERSION_FLAG_MASK;
1285
+ return [version, offset + 1];
1286
+ }
1287
+ }
1288
+ });
1474
1289
  }
1475
1290
 
1476
1291
  // src/serializers/message.ts
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
1292
  function getCompiledMessageLegacyEncoder() {
1482
1293
  return getStructEncoder(getPreludeStructEncoderTuple());
1483
1294
  }
@@ -1488,12 +1299,13 @@ this.globalThis.solanaWeb3 = (function (exports) {
1488
1299
  ["addressTableLookups", getAddressTableLookupArrayEncoder()]
1489
1300
  ]),
1490
1301
  (value) => {
1302
+ var _a;
1491
1303
  if (value.version === "legacy") {
1492
1304
  return value;
1493
1305
  }
1494
1306
  return {
1495
1307
  ...value,
1496
- addressTableLookups: value.addressTableLookups ?? []
1308
+ addressTableLookups: (_a = value.addressTableLookups) != null ? _a : []
1497
1309
  };
1498
1310
  }
1499
1311
  );
@@ -1502,139 +1314,211 @@ this.globalThis.solanaWeb3 = (function (exports) {
1502
1314
  return [
1503
1315
  ["version", getTransactionVersionEncoder()],
1504
1316
  ["header", getMessageHeaderEncoder()],
1505
- [
1506
- "staticAccounts",
1507
- getArrayEncoder(getAddressEncoder(), {
1508
- description: staticAccountsDescription,
1509
- size: getShortU16Encoder()
1510
- })
1511
- ],
1512
- [
1513
- "lifetimeToken",
1514
- getStringEncoder({
1515
- description: lifetimeTokenDescription,
1516
- encoding: getBase58Encoder(),
1517
- size: 32
1518
- })
1519
- ],
1520
- [
1521
- "instructions",
1522
- getArrayEncoder(getInstructionEncoder(), {
1523
- description: instructionsDescription,
1524
- size: getShortU16Encoder()
1525
- })
1526
- ]
1317
+ ["staticAccounts", getArrayEncoder(getAddressEncoder(), { size: getShortU16Encoder() })],
1318
+ ["lifetimeToken", getStringEncoder({ encoding: getBase58Encoder(), size: 32 })],
1319
+ ["instructions", getArrayEncoder(getInstructionEncoder(), { size: getShortU16Encoder() })]
1527
1320
  ];
1528
1321
  }
1529
1322
  function getPreludeStructDecoderTuple() {
1530
1323
  return [
1531
1324
  ["version", getTransactionVersionDecoder()],
1532
1325
  ["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
- ],
1326
+ ["staticAccounts", getArrayDecoder(getAddressDecoder(), { size: getShortU16Decoder() })],
1327
+ ["lifetimeToken", getStringDecoder({ encoding: getBase58Decoder(), size: 32 })],
1328
+ ["instructions", getArrayDecoder(getInstructionDecoder(), { size: getShortU16Decoder() })],
1555
1329
  ["addressTableLookups", getAddressTableLookupArrayDecoder()]
1556
1330
  ];
1557
1331
  }
1558
1332
  function getAddressTableLookupArrayEncoder() {
1559
- return getArrayEncoder(getAddressTableLookupEncoder(), {
1560
- description: addressTableLookupsDescription,
1561
- size: getShortU16Encoder()
1562
- });
1333
+ return getArrayEncoder(getAddressTableLookupEncoder(), { size: getShortU16Encoder() });
1563
1334
  }
1564
1335
  function getAddressTableLookupArrayDecoder() {
1565
- return getArrayDecoder(getAddressTableLookupDecoder(), {
1566
- description: addressTableLookupsDescription,
1567
- size: getShortU16Decoder()
1568
- });
1336
+ return getArrayDecoder(getAddressTableLookupDecoder(), { size: getShortU16Decoder() });
1569
1337
  }
1570
- var messageDescription = "The wire format of a Solana transaction message" ;
1571
1338
  function getCompiledMessageEncoder() {
1572
- return {
1573
- description: messageDescription,
1574
- encode: (compiledMessage) => {
1339
+ return createEncoder({
1340
+ getSizeFromValue: (compiledMessage) => {
1575
1341
  if (compiledMessage.version === "legacy") {
1576
- return getCompiledMessageLegacyEncoder().encode(compiledMessage);
1342
+ return getCompiledMessageLegacyEncoder().getSizeFromValue(compiledMessage);
1577
1343
  } else {
1578
- return getCompiledMessageVersionedEncoder().encode(compiledMessage);
1344
+ return getCompiledMessageVersionedEncoder().getSizeFromValue(compiledMessage);
1579
1345
  }
1580
1346
  },
1581
- fixedSize: null,
1582
- maxSize: null
1583
- };
1347
+ write: (compiledMessage, bytes, offset) => {
1348
+ if (compiledMessage.version === "legacy") {
1349
+ return getCompiledMessageLegacyEncoder().write(compiledMessage, bytes, offset);
1350
+ } else {
1351
+ return getCompiledMessageVersionedEncoder().write(compiledMessage, bytes, offset);
1352
+ }
1353
+ }
1354
+ });
1584
1355
  }
1585
1356
  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 };
1357
+ return mapDecoder(getStructDecoder(getPreludeStructDecoderTuple()), ({ addressTableLookups, ...restOfMessage }) => {
1358
+ if (restOfMessage.version === "legacy" || !(addressTableLookups == null ? void 0 : addressTableLookups.length)) {
1359
+ return restOfMessage;
1595
1360
  }
1596
- );
1361
+ return { ...restOfMessage, addressTableLookups };
1362
+ });
1363
+ }
1364
+ function getCompiledMessageCodec() {
1365
+ return combineCodec(getCompiledMessageEncoder(), getCompiledMessageDecoder());
1597
1366
  }
1598
1367
 
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
1368
+ // src/compile-transaction.ts
1369
+ function getCompiledTransaction(transaction) {
1370
+ var _a;
1371
+ const compiledMessage = compileMessage(transaction);
1372
+ let signatures;
1373
+ if ("signatures" in transaction) {
1374
+ signatures = [];
1375
+ for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
1376
+ signatures[ii] = (_a = transaction.signatures[compiledMessage.staticAccounts[ii]]) != null ? _a : new Uint8Array(Array(64).fill(0));
1616
1377
  }
1378
+ } else {
1379
+ signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
1380
+ }
1381
+ return {
1382
+ compiledMessage,
1383
+ signatures
1384
+ };
1385
+ }
1386
+
1387
+ // ../functional/dist/index.browser.js
1388
+ function pipe(init, ...fns) {
1389
+ return fns.reduce((acc, fn) => fn(acc), init);
1390
+ }
1391
+
1392
+ // src/decompile-transaction.ts
1393
+ function getAccountMetas(message) {
1394
+ const { header } = message;
1395
+ const numWritableSignerAccounts = header.numSignerAccounts - header.numReadonlySignerAccounts;
1396
+ const numWritableNonSignerAccounts = message.staticAccounts.length - header.numSignerAccounts - header.numReadonlyNonSignerAccounts;
1397
+ const accountMetas = [];
1398
+ let accountIndex = 0;
1399
+ for (let i = 0; i < numWritableSignerAccounts; i++) {
1400
+ accountMetas.push({
1401
+ address: message.staticAccounts[accountIndex],
1402
+ role: AccountRole.WRITABLE_SIGNER
1403
+ });
1404
+ accountIndex++;
1405
+ }
1406
+ for (let i = 0; i < header.numReadonlySignerAccounts; i++) {
1407
+ accountMetas.push({
1408
+ address: message.staticAccounts[accountIndex],
1409
+ role: AccountRole.READONLY_SIGNER
1410
+ });
1411
+ accountIndex++;
1412
+ }
1413
+ for (let i = 0; i < numWritableNonSignerAccounts; i++) {
1414
+ accountMetas.push({
1415
+ address: message.staticAccounts[accountIndex],
1416
+ role: AccountRole.WRITABLE
1417
+ });
1418
+ accountIndex++;
1419
+ }
1420
+ for (let i = 0; i < header.numReadonlyNonSignerAccounts; i++) {
1421
+ accountMetas.push({
1422
+ address: message.staticAccounts[accountIndex],
1423
+ role: AccountRole.READONLY
1424
+ });
1425
+ accountIndex++;
1426
+ }
1427
+ return accountMetas;
1428
+ }
1429
+ function convertInstruction(instruction, accountMetas) {
1430
+ var _a, _b;
1431
+ const programAddress = (_a = accountMetas[instruction.programAddressIndex]) == null ? void 0 : _a.address;
1432
+ if (!programAddress) {
1433
+ throw new Error(`Could not find program address at index ${instruction.programAddressIndex}`);
1434
+ }
1435
+ const accounts = (_b = instruction.accountIndices) == null ? void 0 : _b.map((accountIndex) => accountMetas[accountIndex]);
1436
+ const { data } = instruction;
1437
+ return {
1438
+ programAddress,
1439
+ ...accounts && accounts.length ? { accounts } : {},
1440
+ ...data && data.length ? { data } : {}
1441
+ };
1442
+ }
1443
+ function getLifetimeConstraint(messageLifetimeToken, firstInstruction, lastValidBlockHeight) {
1444
+ if (!firstInstruction || !isAdvanceNonceAccountInstruction(firstInstruction)) {
1445
+ return {
1446
+ blockhash: messageLifetimeToken,
1447
+ lastValidBlockHeight: lastValidBlockHeight != null ? lastValidBlockHeight : 2n ** 64n - 1n
1448
+ // U64 MAX
1449
+ };
1450
+ } else {
1451
+ const nonceAccountAddress = firstInstruction.accounts[0].address;
1452
+ assertIsAddress(nonceAccountAddress);
1453
+ const nonceAuthorityAddress = firstInstruction.accounts[2].address;
1454
+ assertIsAddress(nonceAuthorityAddress);
1455
+ return {
1456
+ nonce: messageLifetimeToken,
1457
+ nonceAccountAddress,
1458
+ nonceAuthorityAddress
1459
+ };
1460
+ }
1461
+ }
1462
+ function convertSignatures(compiledTransaction) {
1463
+ const {
1464
+ compiledMessage: { staticAccounts },
1465
+ signatures
1466
+ } = compiledTransaction;
1467
+ return signatures.reduce((acc, sig, index) => {
1468
+ const allZeros = sig.every((byte) => byte === 0);
1469
+ if (allZeros)
1470
+ return acc;
1471
+ const address2 = staticAccounts[index];
1472
+ return { ...acc, [address2]: sig };
1473
+ }, {});
1474
+ }
1475
+ function decompileTransaction(compiledTransaction, lastValidBlockHeight) {
1476
+ const { compiledMessage } = compiledTransaction;
1477
+ if ("addressTableLookups" in compiledMessage && compiledMessage.addressTableLookups.length > 0) {
1478
+ throw new Error("Cannot convert transaction with addressTableLookups");
1479
+ }
1480
+ const feePayer = compiledMessage.staticAccounts[0];
1481
+ if (!feePayer)
1482
+ throw new Error("No fee payer set in CompiledTransaction");
1483
+ const accountMetas = getAccountMetas(compiledMessage);
1484
+ const instructions = compiledMessage.instructions.map(
1485
+ (compiledInstruction) => convertInstruction(compiledInstruction, accountMetas)
1486
+ );
1487
+ const firstInstruction = instructions[0];
1488
+ const lifetimeConstraint = getLifetimeConstraint(
1489
+ compiledMessage.lifetimeToken,
1490
+ firstInstruction,
1491
+ lastValidBlockHeight
1492
+ );
1493
+ const signatures = convertSignatures(compiledTransaction);
1494
+ return pipe(
1495
+ createTransaction({ version: compiledMessage.version }),
1496
+ (tx) => setTransactionFeePayer(feePayer, tx),
1497
+ (tx) => instructions.reduce((acc, instruction) => {
1498
+ return appendTransactionInstruction(instruction, acc);
1499
+ }, tx),
1500
+ (tx) => "blockhash" in lifetimeConstraint ? setTransactionLifetimeUsingBlockhash(lifetimeConstraint, tx) : setTransactionLifetimeUsingDurableNonce(lifetimeConstraint, tx),
1501
+ (tx) => compiledTransaction.signatures.length ? { ...tx, signatures } : tx
1617
1502
  );
1618
1503
  }
1619
- function getSignatureDecoder() {
1620
- return mapDecoder(getBytesDecoder({ size: 64 }), (bytes) => bytes);
1504
+
1505
+ // src/serializers/transaction.ts
1506
+ function getCompiledTransactionEncoder() {
1507
+ return getStructEncoder([
1508
+ ["signatures", getArrayEncoder(getBytesEncoder({ size: 64 }), { size: getShortU16Encoder() })],
1509
+ ["compiledMessage", getCompiledMessageEncoder()]
1510
+ ]);
1621
1511
  }
1622
1512
  function getCompiledTransactionDecoder() {
1623
- return getStructDecoder(
1513
+ return getStructDecoder([
1624
1514
  [
1625
- [
1626
- "signatures",
1627
- getArrayDecoder(getSignatureDecoder(), {
1628
- description: signaturesDescription,
1629
- size: getShortU16Decoder()
1630
- })
1631
- ],
1632
- ["compiledMessage", getCompiledMessageDecoder()]
1515
+ "signatures",
1516
+ getArrayDecoder(getBytesDecoder({ size: 64 }), {
1517
+ size: getShortU16Decoder()
1518
+ })
1633
1519
  ],
1634
- {
1635
- description: transactionDescription
1636
- }
1637
- );
1520
+ ["compiledMessage", getCompiledMessageDecoder()]
1521
+ ]);
1638
1522
  }
1639
1523
  function getTransactionEncoder() {
1640
1524
  return mapEncoder(getCompiledTransactionEncoder(), getCompiledTransaction);
@@ -1657,47 +1541,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
1657
1541
  }
1658
1542
 
1659
1543
  // src/signatures.ts
1660
- var base58Encoder2;
1661
1544
  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
- }
1683
- }
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
1545
  function getSignatureFromTransaction(transaction) {
1702
1546
  if (!base58Decoder)
1703
1547
  base58Decoder = getBase58Decoder();
@@ -1707,10 +1551,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
1707
1551
  "Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
1708
1552
  );
1709
1553
  }
1710
- const transactionSignature2 = base58Decoder.decode(signatureBytes)[0];
1711
- return transactionSignature2;
1554
+ const transactionSignature = base58Decoder.decode(signatureBytes);
1555
+ return transactionSignature;
1712
1556
  }
1713
- async function signTransaction(keyPairs, transaction) {
1557
+ async function partiallySignTransaction(keyPairs, transaction) {
1714
1558
  const compiledMessage = compileMessage(transaction);
1715
1559
  const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
1716
1560
  const wireMessageBytes = getCompiledMessageEncoder().encode(compiledMessage);
@@ -1729,12 +1573,17 @@ this.globalThis.solanaWeb3 = (function (exports) {
1729
1573
  Object.freeze(out);
1730
1574
  return out;
1731
1575
  }
1732
- function transactionSignature(putativeTransactionSignature) {
1733
- assertIsTransactionSignature(putativeTransactionSignature);
1734
- return putativeTransactionSignature;
1576
+ async function signTransaction(keyPairs, transaction) {
1577
+ const out = await partiallySignTransaction(keyPairs, transaction);
1578
+ assertTransactionIsFullySigned(out);
1579
+ Object.freeze(out);
1580
+ return out;
1735
1581
  }
1736
1582
  function assertTransactionIsFullySigned(transaction) {
1737
- const signerAddressesFromInstructions = transaction.instructions.flatMap((i) => i.accounts?.filter((a) => isSignerRole(a.role)) ?? []).map((a) => a.address);
1583
+ const signerAddressesFromInstructions = transaction.instructions.flatMap((i) => {
1584
+ var _a, _b;
1585
+ return (_b = (_a = i.accounts) == null ? void 0 : _a.filter((a) => isSignerRole(a.role))) != null ? _b : [];
1586
+ }).map((a) => a.address);
1738
1587
  const requiredSigners = /* @__PURE__ */ new Set([transaction.feePayer, ...signerAddressesFromInstructions]);
1739
1588
  requiredSigners.forEach((address2) => {
1740
1589
  if (!transaction.signatures[address2]) {
@@ -1746,30 +1595,31 @@ this.globalThis.solanaWeb3 = (function (exports) {
1746
1595
  // src/wire-transaction.ts
1747
1596
  function getBase64EncodedWireTransaction(transaction) {
1748
1597
  const wireTransactionBytes = getTransactionEncoder().encode(transaction);
1749
- {
1750
- return btoa(String.fromCharCode(...wireTransactionBytes));
1751
- }
1598
+ return getBase64Decoder().decode(wireTransactionBytes);
1752
1599
  }
1753
1600
 
1754
1601
  exports.appendTransactionInstruction = appendTransactionInstruction;
1755
1602
  exports.assertIsBlockhash = assertIsBlockhash;
1756
1603
  exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
1757
- exports.assertIsTransactionSignature = assertIsTransactionSignature;
1604
+ exports.assertIsTransactionWithBlockhashLifetime = assertIsTransactionWithBlockhashLifetime;
1758
1605
  exports.assertTransactionIsFullySigned = assertTransactionIsFullySigned;
1606
+ exports.compileMessage = compileMessage;
1759
1607
  exports.createTransaction = createTransaction;
1760
1608
  exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
1609
+ exports.getCompiledMessageCodec = getCompiledMessageCodec;
1610
+ exports.getCompiledMessageDecoder = getCompiledMessageDecoder;
1611
+ exports.getCompiledMessageEncoder = getCompiledMessageEncoder;
1761
1612
  exports.getSignatureFromTransaction = getSignatureFromTransaction;
1762
1613
  exports.getTransactionCodec = getTransactionCodec;
1763
1614
  exports.getTransactionDecoder = getTransactionDecoder;
1764
1615
  exports.getTransactionEncoder = getTransactionEncoder;
1765
1616
  exports.isAdvanceNonceAccountInstruction = isAdvanceNonceAccountInstruction;
1766
- exports.isTransactionSignature = isTransactionSignature;
1617
+ exports.partiallySignTransaction = partiallySignTransaction;
1767
1618
  exports.prependTransactionInstruction = prependTransactionInstruction;
1768
1619
  exports.setTransactionFeePayer = setTransactionFeePayer;
1769
1620
  exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
1770
1621
  exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
1771
1622
  exports.signTransaction = signTransaction;
1772
- exports.transactionSignature = transactionSignature;
1773
1623
 
1774
1624
  return exports;
1775
1625