@solana/transactions 2.0.0-experimental.d554dd4 → 2.0.0-experimental.d93c93b

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