@solana/transactions 2.0.0-experimental.0de6c3e → 2.0.0-experimental.0eb69ae

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 (64) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +272 -5
  3. package/dist/index.browser.cjs +650 -281
  4. package/dist/index.browser.cjs.map +1 -1
  5. package/dist/index.browser.js +637 -281
  6. package/dist/index.browser.js.map +1 -1
  7. package/dist/index.development.js +1317 -776
  8. package/dist/index.development.js.map +1 -1
  9. package/dist/index.native.js +637 -281
  10. package/dist/index.native.js.map +1 -1
  11. package/dist/index.node.cjs +652 -279
  12. package/dist/index.node.cjs.map +1 -1
  13. package/dist/index.node.js +637 -281
  14. package/dist/index.node.js.map +1 -1
  15. package/dist/index.production.min.js +22 -7
  16. package/dist/types/accounts.d.ts +3 -3
  17. package/dist/types/blockhash.d.ts +9 -1
  18. package/dist/types/compilable-transaction.d.ts +7 -0
  19. package/dist/types/compile-address-table-lookups.d.ts +2 -2
  20. package/dist/types/compile-instructions.d.ts +1 -1
  21. package/dist/types/compile-static-accounts.d.ts +2 -2
  22. package/dist/types/compile-transaction.d.ts +5 -6
  23. package/dist/types/decompile-transaction.d.ts +5 -0
  24. package/dist/types/durable-nonce.d.ts +23 -10
  25. package/dist/types/fee-payer.d.ts +4 -3
  26. package/dist/types/index.d.ts +3 -0
  27. package/dist/types/message.d.ts +1 -5
  28. package/dist/types/serializers/address-table-lookup.d.ts +5 -3
  29. package/dist/types/serializers/header.d.ts +4 -2
  30. package/dist/types/serializers/index.d.ts +3 -0
  31. package/dist/types/serializers/instruction.d.ts +4 -2
  32. package/dist/types/serializers/message.d.ts +4 -4
  33. package/dist/types/serializers/transaction-version.d.ts +4 -4
  34. package/dist/types/serializers/transaction.d.ts +6 -5
  35. package/dist/types/signatures.d.ts +10 -7
  36. package/dist/types/types.d.ts +13 -13
  37. package/dist/types/unsigned-transaction.d.ts +4 -0
  38. package/dist/types/wire-transaction.d.ts +2 -2
  39. package/package.json +24 -22
  40. package/dist/types/accounts.d.ts.map +0 -1
  41. package/dist/types/blockhash.d.ts.map +0 -1
  42. package/dist/types/compile-address-table-lookups.d.ts.map +0 -1
  43. package/dist/types/compile-header.d.ts.map +0 -1
  44. package/dist/types/compile-instructions.d.ts.map +0 -1
  45. package/dist/types/compile-lifetime-token.d.ts.map +0 -1
  46. package/dist/types/compile-static-accounts.d.ts.map +0 -1
  47. package/dist/types/compile-transaction.d.ts.map +0 -1
  48. package/dist/types/create-transaction.d.ts.map +0 -1
  49. package/dist/types/durable-nonce.d.ts.map +0 -1
  50. package/dist/types/fee-payer.d.ts.map +0 -1
  51. package/dist/types/index.d.ts.map +0 -1
  52. package/dist/types/instructions.d.ts.map +0 -1
  53. package/dist/types/message.d.ts.map +0 -1
  54. package/dist/types/serializers/address-table-lookup.d.ts.map +0 -1
  55. package/dist/types/serializers/header.d.ts.map +0 -1
  56. package/dist/types/serializers/instruction.d.ts.map +0 -1
  57. package/dist/types/serializers/message.d.ts.map +0 -1
  58. package/dist/types/serializers/transaction-version.d.ts.map +0 -1
  59. package/dist/types/serializers/transaction.d.ts.map +0 -1
  60. package/dist/types/serializers/unimplemented.d.ts +0 -3
  61. package/dist/types/serializers/unimplemented.d.ts.map +0 -1
  62. package/dist/types/signatures.d.ts.map +0 -1
  63. package/dist/types/types.d.ts.map +0 -1
  64. package/dist/types/wire-transaction.d.ts.map +0 -1
@@ -2,187 +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
- // src/create-transaction.ts
13
- function createTransaction({
14
- version
15
- }) {
16
- const out = {
17
- instructions: [],
18
- version
19
- };
20
- Object.freeze(out);
21
- return out;
22
- }
23
-
24
- // src/fee-payer.ts
25
- function setTransactionFeePayer(feePayer, transaction) {
26
- if ("feePayer" in transaction && feePayer === transaction.feePayer) {
27
- return transaction;
28
- }
29
- let out;
30
- if ("signatures" in transaction) {
31
- const {
32
- signatures: _,
33
- // eslint-disable-line @typescript-eslint/no-unused-vars
34
- ...unsignedTransaction
35
- } = transaction;
36
- out = {
37
- ...unsignedTransaction,
38
- feePayer
39
- };
40
- } else {
41
- out = {
42
- ...transaction,
43
- feePayer
44
- };
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.`);
45
9
  }
46
- Object.freeze(out);
47
- return out;
48
10
  }
49
-
50
- // src/instructions.ts
51
- function replaceInstructions(transaction, nextInstructions) {
52
- let out;
53
- if ("signatures" in transaction) {
54
- const {
55
- signatures: _,
56
- // eslint-disable-line @typescript-eslint/no-unused-vars
57
- ...unsignedTransaction
58
- } = transaction;
59
- out = {
60
- ...unsignedTransaction,
61
- instructions: nextInstructions
62
- };
63
- } else {
64
- out = {
65
- ...transaction,
66
- instructions: nextInstructions
67
- };
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}.`);
68
15
  }
69
- return out;
70
- }
71
- function appendTransactionInstruction(instruction, transaction) {
72
- const nextInstructions = [...transaction.instructions, instruction];
73
- const out = replaceInstructions(transaction, nextInstructions);
74
- Object.freeze(out);
75
- return out;
76
- }
77
- function prependTransactionInstruction(instruction, transaction) {
78
- const nextInstructions = [instruction, ...transaction.instructions];
79
- const out = replaceInstructions(transaction, nextInstructions);
80
- Object.freeze(out);
81
- return out;
82
16
  }
83
-
84
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/bytes.mjs
85
- var mergeBytes = (bytesArr) => {
86
- const totalLength = bytesArr.reduce((total, arr) => total + arr.length, 0);
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);
87
26
  const result = new Uint8Array(totalLength);
88
27
  let offset = 0;
89
- bytesArr.forEach((arr) => {
28
+ nonEmptyByteArrays.forEach((arr) => {
90
29
  result.set(arr, offset);
91
30
  offset += arr.length;
92
31
  });
93
32
  return result;
94
33
  };
95
- var padBytes = (bytes2, length) => {
96
- if (bytes2.length >= length)
97
- return bytes2;
34
+ var padBytes = (bytes, length) => {
35
+ if (bytes.length >= length)
36
+ return bytes;
98
37
  const paddedBytes = new Uint8Array(length).fill(0);
99
- paddedBytes.set(bytes2);
38
+ paddedBytes.set(bytes);
100
39
  return paddedBytes;
101
40
  };
102
- var fixBytes = (bytes2, length) => padBytes(bytes2.slice(0, length), length);
103
-
104
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/errors.mjs
105
- var DeserializingEmptyBufferError = class extends Error {
106
- constructor(serializer) {
107
- super(`Serializer [${serializer}] cannot deserialize empty buffers.`);
108
- __publicField(this, "name", "DeserializingEmptyBufferError");
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
+ );
109
47
  }
110
- };
111
- var NotEnoughBytesError = class extends Error {
112
- constructor(serializer, expected, actual) {
113
- super(`Serializer [${serializer}] expected ${expected} bytes, got ${actual}.`);
114
- __publicField(this, "name", "NotEnoughBytesError");
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
+ );
115
52
  }
116
- };
117
- var ExpectedFixedSizeSerializerError = class extends Error {
118
- constructor(message) {
119
- message ?? (message = "Expected a fixed-size serializer, got a variable-size one.");
120
- super(message);
121
- __publicField(this, "name", "ExpectedFixedSizeSerializerError");
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
+ );
122
57
  }
123
- };
124
-
125
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/fixSerializer.mjs
126
- function fixSerializer(serializer, fixedBytes, description) {
127
58
  return {
128
- 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})`,
129
69
  fixedSize: fixedBytes,
130
- maxSize: fixedBytes,
131
- serialize: (value) => fixBytes(serializer.serialize(value), fixedBytes),
132
- deserialize: (buffer, offset = 0) => {
133
- buffer = buffer.slice(offset, offset + fixedBytes);
134
- if (buffer.length < fixedBytes) {
135
- throw new NotEnoughBytesError("fixSerializer", fixedBytes, buffer.length);
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);
136
86
  }
137
- if (serializer.fixedSize !== null) {
138
- buffer = fixBytes(buffer, serializer.fixedSize);
87
+ if (decoder.fixedSize !== null) {
88
+ bytes = fixBytes(bytes, decoder.fixedSize);
139
89
  }
140
- const [value] = serializer.deserialize(buffer, 0);
90
+ const [value] = decoder.decode(bytes, 0);
141
91
  return [value, offset + fixedBytes];
142
92
  }
143
93
  };
144
94
  }
145
-
146
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/mapSerializer.mjs
147
- function mapSerializer(serializer, unmap, map) {
95
+ function mapEncoder(encoder, unmap) {
148
96
  return {
149
- description: serializer.description,
150
- fixedSize: serializer.fixedSize,
151
- maxSize: serializer.maxSize,
152
- serialize: (value) => serializer.serialize(unmap(value)),
153
- deserialize: (buffer, offset = 0) => {
154
- const [value, length] = serializer.deserialize(buffer, offset);
155
- return map ? [map(value, buffer, offset), length] : [value, length];
156
- }
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
157
112
  };
158
113
  }
159
114
 
160
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/errors.mjs
161
- var InvalidBaseStringError = class extends Error {
162
- constructor(value, base, cause) {
163
- const message = `Expected a string of base ${base}, got [${value}].`;
164
- super(message);
165
- __publicField(this, "name", "InvalidBaseStringError");
166
- this.cause = cause;
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
+ );
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)";
167
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
+ };
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
+ };
168
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
+ });
169
245
 
170
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseX.mjs
171
- var baseX = (alphabet) => {
172
- const base = alphabet.length;
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;
173
254
  const baseBigInt = BigInt(base);
174
255
  return {
175
256
  description: `base${base}`,
176
- fixedSize: null,
177
- maxSize: null,
178
- serialize(value) {
179
- if (!value.match(new RegExp(`^[${alphabet}]*$`))) {
180
- throw new InvalidBaseStringError(value, base);
181
- }
257
+ encode(value) {
258
+ assertValidBaseString(alphabet4, value);
182
259
  if (value === "")
183
260
  return new Uint8Array();
184
261
  const chars = [...value];
185
- let trailIndex = chars.findIndex((c) => c !== alphabet[0]);
262
+ let trailIndex = chars.findIndex((c) => c !== alphabet4[0]);
186
263
  trailIndex = trailIndex === -1 ? chars.length : trailIndex;
187
264
  const leadingZeroes = Array(trailIndex).fill(0);
188
265
  if (trailIndex === chars.length)
@@ -191,7 +268,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
191
268
  let base10Number = 0n;
192
269
  let baseXPower = 1n;
193
270
  for (let i = tailChars.length - 1; i >= 0; i -= 1) {
194
- base10Number += baseXPower * BigInt(alphabet.indexOf(tailChars[i]));
271
+ base10Number += baseXPower * BigInt(alphabet4.indexOf(tailChars[i]));
195
272
  baseXPower *= baseBigInt;
196
273
  }
197
274
  const tailBytes = [];
@@ -201,386 +278,328 @@ this.globalThis.solanaWeb3 = (function (exports) {
201
278
  }
202
279
  return Uint8Array.from(leadingZeroes.concat(tailBytes));
203
280
  },
204
- deserialize(buffer, offset = 0) {
205
- 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)
206
292
  return ["", 0];
207
- const bytes2 = buffer.slice(offset);
208
- let trailIndex = bytes2.findIndex((n) => n !== 0);
209
- trailIndex = trailIndex === -1 ? bytes2.length : trailIndex;
210
- const leadingZeroes = alphabet[0].repeat(trailIndex);
211
- if (trailIndex === bytes2.length)
212
- return [leadingZeroes, buffer.length];
213
- let base10Number = bytes2.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
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);
214
299
  const tailChars = [];
215
300
  while (base10Number > 0n) {
216
- tailChars.unshift(alphabet[Number(base10Number % baseBigInt)]);
301
+ tailChars.unshift(alphabet4[Number(base10Number % baseBigInt)]);
217
302
  base10Number /= baseBigInt;
218
303
  }
219
- return [leadingZeroes + tailChars.join(""), buffer.length];
220
- }
304
+ return [leadingZeroes + tailChars.join(""), rawBytes.length];
305
+ },
306
+ description: `base${base}`,
307
+ fixedSize: null,
308
+ maxSize: null
221
309
  };
222
310
  };
223
-
224
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/base58.mjs
225
- var base58 = baseX("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
226
-
227
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/nullCharacters.mjs
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
+ };
228
328
  var removeNullCharacters = (value) => (
229
329
  // eslint-disable-next-line no-control-regex
230
330
  value.replace(/\u0000/g, "")
231
331
  );
232
-
233
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/utf8.mjs
234
- var utf8 = {
235
- description: "utf8",
236
- fixedSize: null,
237
- maxSize: null,
238
- serialize(value) {
239
- return new TextEncoder().encode(value);
240
- },
241
- deserialize(buffer, offset = 0) {
242
- const value = new TextDecoder().decode(buffer.slice(offset));
243
- return [removeNullCharacters(value), buffer.length];
244
- }
332
+ var e = globalThis.TextDecoder;
333
+ var o = globalThis.TextEncoder;
334
+ var getUtf8Encoder = () => {
335
+ let textEncoder;
336
+ return {
337
+ description: "utf8",
338
+ encode: (value) => new Uint8Array((textEncoder || (textEncoder = new o())).encode(value)),
339
+ fixedSize: null,
340
+ maxSize: null
341
+ };
245
342
  };
246
-
247
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/common.mjs
248
- var Endian;
249
- (function(Endian2) {
250
- Endian2["Little"] = "le";
251
- Endian2["Big"] = "be";
252
- })(Endian || (Endian = {}));
253
-
254
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/errors.mjs
255
- var NumberOutOfRangeError = class extends RangeError {
256
- constructor(serializer, min, max, actual) {
257
- super(`Serializer [${serializer}] expected number to be between ${min} and ${max}, got ${actual}.`);
258
- __publicField(this, "name", "NumberOutOfRangeError");
259
- }
343
+ var getUtf8Decoder = () => {
344
+ let textDecoder;
345
+ return {
346
+ decode(bytes, offset = 0) {
347
+ const value = (textDecoder || (textDecoder = new e())).decode(bytes.slice(offset));
348
+ return [removeNullCharacters(value), bytes.length];
349
+ },
350
+ description: "utf8",
351
+ fixedSize: null,
352
+ maxSize: null
353
+ };
260
354
  };
261
-
262
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/utils.mjs
263
- function numberFactory(input) {
264
- let littleEndian;
265
- let defaultDescription = input.name;
266
- if (input.size > 1) {
267
- littleEndian = !("endian" in input.options) || input.options.endian === Endian.Little;
268
- defaultDescription += littleEndian ? "(le)" : "(be)";
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)})`;
360
+ if (size === "variable") {
361
+ return { ...encoding, description };
362
+ }
363
+ if (typeof size === "number") {
364
+ return fixEncoder(encoding, size, description);
269
365
  }
270
366
  return {
271
- description: input.options.description ?? defaultDescription,
272
- fixedSize: input.size,
273
- maxSize: input.size,
274
- serialize(value) {
275
- if (input.range) {
276
- assertRange(input.name, input.range[0], input.range[1], value);
277
- }
278
- const buffer = new ArrayBuffer(input.size);
279
- input.set(new DataView(buffer), value, littleEndian);
280
- return new Uint8Array(buffer);
367
+ description,
368
+ encode: (value) => {
369
+ const contentBytes = encoding.encode(value);
370
+ const lengthBytes = size.encode(contentBytes.length);
371
+ return mergeBytes([lengthBytes, contentBytes]);
281
372
  },
282
- deserialize(bytes2, offset = 0) {
283
- const slice = bytes2.slice(offset, offset + input.size);
284
- assertEnoughBytes("i8", slice, input.size);
285
- const view = toDataView(slice);
286
- return [input.get(view, littleEndian), offset + input.size];
287
- }
373
+ fixedSize: null,
374
+ maxSize: null
288
375
  };
289
- }
290
- var toArrayBuffer = (array2) => array2.buffer.slice(array2.byteOffset, array2.byteLength + array2.byteOffset);
291
- var toDataView = (array2) => new DataView(toArrayBuffer(array2));
292
- var assertRange = (serializer, min, max, value) => {
293
- if (value < min || value > max) {
294
- throw new NumberOutOfRangeError(serializer, min, max, value);
295
- }
296
376
  };
297
- var assertEnoughBytes = (serializer, bytes2, expected) => {
298
- if (bytes2.length === 0) {
299
- throw new DeserializingEmptyBufferError(serializer);
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)})`;
382
+ if (size === "variable") {
383
+ return { ...encoding, description };
300
384
  }
301
- if (bytes2.length < expected) {
302
- throw new NotEnoughBytesError(serializer, expected, bytes2.length);
385
+ if (typeof size === "number") {
386
+ return fixDecoder(encoding, size, description);
303
387
  }
388
+ return {
389
+ decode: (bytes, offset = 0) => {
390
+ assertByteArrayIsNotEmptyForCodec("string", bytes, offset);
391
+ const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);
392
+ const length = Number(lengthBigInt);
393
+ offset = lengthOffset;
394
+ const contentBytes = bytes.slice(offset, offset + length);
395
+ assertByteArrayHasEnoughBytesForCodec("string", length, contentBytes);
396
+ const [value, contentOffset] = encoding.decode(contentBytes);
397
+ offset += contentOffset;
398
+ return [value, offset];
399
+ },
400
+ description,
401
+ fixedSize: null,
402
+ maxSize: null
403
+ };
304
404
  };
405
+ function getSizeDescription(size) {
406
+ return typeof size === "object" ? size.description : `${size}`;
407
+ }
305
408
 
306
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u8.mjs
307
- var u8 = (options = {}) => numberFactory({
308
- name: "u8",
309
- size: 1,
310
- range: [0, Number("0xff")],
311
- set: (view, value) => view.setUint8(0, Number(value)),
312
- get: (view) => view.getUint8(0),
313
- options
314
- });
315
-
316
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u32.mjs
317
- var u32 = (options = {}) => numberFactory({
318
- name: "u32",
319
- size: 4,
320
- range: [0, Number("0xffffffff")],
321
- set: (view, value, le) => view.setUint32(0, Number(value), le),
322
- get: (view, le) => view.getUint32(0, le),
323
- options
324
- });
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
+ }
421
+ }
325
422
 
326
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/shortU16.mjs
327
- var shortU16 = (options = {}) => ({
328
- description: options.description ?? "shortU16",
329
- fixedSize: null,
330
- maxSize: 3,
331
- serialize: (value) => {
332
- assertRange("shortU16", 0, 65535, value);
333
- const bytes2 = [0];
334
- for (let ii = 0; ; ii += 1) {
335
- const alignedValue = value >> ii * 7;
336
- if (alignedValue === 0) {
337
- break;
338
- }
339
- const nextSevenBits = 127 & alignedValue;
340
- bytes2[ii] = nextSevenBits;
341
- if (ii > 0) {
342
- bytes2[ii - 1] |= 128;
343
- }
423
+ // src/blockhash.ts
424
+ var base58Encoder;
425
+ function assertIsBlockhash(putativeBlockhash) {
426
+ if (!base58Encoder)
427
+ base58Encoder = getBase58Encoder();
428
+ try {
429
+ if (
430
+ // Lowest value (32 bytes of zeroes)
431
+ putativeBlockhash.length < 32 || // Highest value (32 bytes of 255)
432
+ putativeBlockhash.length > 44
433
+ ) {
434
+ throw new Error("Expected input string to decode to a byte array of length 32.");
344
435
  }
345
- return new Uint8Array(bytes2);
346
- },
347
- deserialize: (bytes2, offset = 0) => {
348
- let value = 0;
349
- let byteCount = 0;
350
- while (++byteCount) {
351
- const byteIndex = byteCount - 1;
352
- const currentByte = bytes2[offset + byteIndex];
353
- const nextSevenBits = 127 & currentByte;
354
- value |= nextSevenBits << byteIndex * 7;
355
- if ((currentByte & 128) === 0) {
356
- break;
357
- }
436
+ const bytes = base58Encoder.encode(putativeBlockhash);
437
+ const numBytes = bytes.byteLength;
438
+ if (numBytes !== 32) {
439
+ throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
358
440
  }
359
- return [value, offset + byteCount];
360
- }
361
- });
362
-
363
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.2/node_modules/@metaplex-foundation/umi-serializers/dist/esm/errors.mjs
364
- var InvalidNumberOfItemsError = class extends Error {
365
- constructor(serializer, expected, actual) {
366
- super(`Expected [${serializer}] to have ${expected} items, got ${actual}.`);
367
- __publicField(this, "name", "InvalidNumberOfItemsError");
368
- }
369
- };
370
- var InvalidArrayLikeRemainderSizeError = class extends Error {
371
- constructor(remainderSize, itemSize) {
372
- super(`The remainder of the buffer (${remainderSize} bytes) cannot be split into chunks of ${itemSize} bytes. Serializers of "remainder" size must have a remainder that is a multiple of its item size. In other words, ${remainderSize} modulo ${itemSize} should be equal to zero.`);
373
- __publicField(this, "name", "InvalidArrayLikeRemainderSizeError");
441
+ } catch (e2) {
442
+ throw new Error(`\`${putativeBlockhash}\` is not a blockhash`, {
443
+ cause: e2
444
+ });
374
445
  }
375
- };
376
- var UnrecognizedArrayLikeSerializerSizeError = class extends Error {
377
- constructor(size) {
378
- super(`Unrecognized array-like serializer size: ${JSON.stringify(size)}`);
379
- __publicField(this, "name", "UnrecognizedArrayLikeSerializerSizeError");
446
+ }
447
+ function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {
448
+ if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
449
+ return transaction;
380
450
  }
381
- };
382
-
383
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.2/node_modules/@metaplex-foundation/umi-serializers/dist/esm/sumSerializerSizes.mjs
384
- function sumSerializerSizes(sizes) {
385
- return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
451
+ const out = {
452
+ ...getUnsignedTransaction(transaction),
453
+ lifetimeConstraint: blockhashLifetimeConstraint
454
+ };
455
+ Object.freeze(out);
456
+ return out;
386
457
  }
387
458
 
388
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.2/node_modules/@metaplex-foundation/umi-serializers/dist/esm/utils.mjs
389
- function getResolvedSize(size, childrenSizes, bytes2, offset) {
390
- if (typeof size === "number") {
391
- return [size, offset];
392
- }
393
- if (typeof size === "object") {
394
- return size.deserialize(bytes2, offset);
395
- }
396
- if (size === "remainder") {
397
- const childrenSize = sumSerializerSizes(childrenSizes);
398
- if (childrenSize === null) {
399
- throw new ExpectedFixedSizeSerializerError('Serializers of "remainder" size must have fixed-size items.');
400
- }
401
- const remainder = bytes2.slice(offset).length;
402
- if (remainder % childrenSize !== 0) {
403
- throw new InvalidArrayLikeRemainderSizeError(remainder, childrenSize);
404
- }
405
- return [remainder / childrenSize, offset];
406
- }
407
- throw new UnrecognizedArrayLikeSerializerSizeError(size);
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;
408
469
  }
409
- function getSizeDescription(size) {
410
- return typeof size === "object" ? size.description : `${size}`;
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;
411
486
  }
412
- function getSizeFromChildren(size, childrenSizes) {
413
- if (typeof size !== "number")
414
- return null;
415
- if (size === 0)
416
- return 0;
417
- const childrenSize = sumSerializerSizes(childrenSizes);
418
- return childrenSize === null ? null : childrenSize * size;
487
+ function isWritableRole(role) {
488
+ return (role & IS_WRITABLE_BITMASK) !== 0;
419
489
  }
420
- function getSizePrefix(size, realSize) {
421
- return typeof size === "object" ? size.serialize(realSize) : new Uint8Array();
490
+ function mergeRoles(roleA, roleB) {
491
+ return roleA | roleB;
422
492
  }
423
493
 
424
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.2/node_modules/@metaplex-foundation/umi-serializers/dist/esm/array.mjs
425
- function array(item, options = {}) {
426
- const size = options.size ?? u32();
427
- if (size === "remainder" && item.fixedSize === null) {
428
- throw new ExpectedFixedSizeSerializerError('Serializers of "remainder" size must have fixed-size items.');
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");
429
500
  }
501
+ }
502
+ function createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress) {
430
503
  return {
431
- description: options.description ?? `array(${item.description}; ${getSizeDescription(size)})`,
432
- fixedSize: getSizeFromChildren(size, [item.fixedSize]),
433
- maxSize: getSizeFromChildren(size, [item.maxSize]),
434
- serialize: (value) => {
435
- if (typeof size === "number" && value.length !== size) {
436
- throw new InvalidNumberOfItemsError("array", size, value.length);
437
- }
438
- return mergeBytes([getSizePrefix(size, value.length), ...value.map((v) => item.serialize(v))]);
439
- },
440
- deserialize: (bytes2, offset = 0) => {
441
- if (typeof size === "object" && bytes2.slice(offset).length === 0) {
442
- return [[], offset];
443
- }
444
- const [resolvedSize, newOffset] = getResolvedSize(size, [item.fixedSize], bytes2, offset);
445
- offset = newOffset;
446
- const values = [];
447
- for (let i = 0; i < resolvedSize; i += 1) {
448
- const [value, newOffset2] = item.deserialize(bytes2, offset);
449
- values.push(value);
450
- offset = newOffset2;
451
- }
452
- return [values, offset];
453
- }
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
454
514
  };
455
515
  }
456
-
457
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.2/node_modules/@metaplex-foundation/umi-serializers/dist/esm/bytes.mjs
458
- function bytes(options = {}) {
459
- const size = options.size ?? "variable";
460
- const description = options.description ?? `bytes(${getSizeDescription(size)})`;
461
- const byteSerializer = {
462
- description,
463
- fixedSize: null,
464
- maxSize: null,
465
- serialize: (value) => new Uint8Array(value),
466
- deserialize: (bytes2, offset = 0) => {
467
- const slice = bytes2.slice(offset);
468
- return [slice, offset + slice.length];
469
- }
470
- };
471
- if (size === "variable") {
472
- return byteSerializer;
473
- }
474
- if (typeof size === "number") {
475
- return fixSerializer(byteSerializer, size, description);
476
- }
477
- return {
478
- description,
479
- fixedSize: null,
480
- maxSize: null,
481
- serialize: (value) => {
482
- const contentBytes = byteSerializer.serialize(value);
483
- const lengthBytes = size.serialize(contentBytes.length);
484
- return mergeBytes([lengthBytes, contentBytes]);
485
- },
486
- deserialize: (buffer, offset = 0) => {
487
- if (buffer.slice(offset).length === 0) {
488
- throw new DeserializingEmptyBufferError("bytes");
489
- }
490
- const [lengthBigInt, lengthOffset] = size.deserialize(buffer, offset);
491
- const length = Number(lengthBigInt);
492
- offset = lengthOffset;
493
- const contentBuffer = buffer.slice(offset, offset + length);
494
- if (contentBuffer.length < length) {
495
- throw new NotEnoughBytesError("bytes", length, contentBuffer.length);
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)];
496
547
  }
497
- const [value, contentOffset] = byteSerializer.deserialize(contentBuffer);
498
- offset += contentOffset;
499
- return [value, offset];
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
+ ];
559
+ }
560
+ const out = {
561
+ ...getUnsignedTransaction(transaction),
562
+ instructions: newInstructions,
563
+ lifetimeConstraint: {
564
+ nonce
500
565
  }
501
566
  };
567
+ Object.freeze(out);
568
+ return out;
502
569
  }
503
570
 
504
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.2/node_modules/@metaplex-foundation/umi-serializers/dist/esm/string.mjs
505
- function string(options = {}) {
506
- const size = options.size ?? u32();
507
- const encoding = options.encoding ?? utf8;
508
- const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
509
- if (size === "variable") {
510
- return {
511
- ...encoding,
512
- description
513
- };
514
- }
515
- if (typeof size === "number") {
516
- return fixSerializer(encoding, size, description);
571
+ // src/fee-payer.ts
572
+ function setTransactionFeePayer(feePayer, transaction) {
573
+ if ("feePayer" in transaction && feePayer === transaction.feePayer) {
574
+ return transaction;
517
575
  }
518
- return {
519
- description,
520
- fixedSize: null,
521
- maxSize: null,
522
- serialize: (value) => {
523
- const contentBytes = encoding.serialize(value);
524
- const lengthBytes = size.serialize(contentBytes.length);
525
- return mergeBytes([lengthBytes, contentBytes]);
526
- },
527
- deserialize: (buffer, offset = 0) => {
528
- if (buffer.slice(offset).length === 0) {
529
- throw new DeserializingEmptyBufferError("string");
530
- }
531
- const [lengthBigInt, lengthOffset] = size.deserialize(buffer, offset);
532
- const length = Number(lengthBigInt);
533
- offset = lengthOffset;
534
- const contentBuffer = buffer.slice(offset, offset + length);
535
- if (contentBuffer.length < length) {
536
- throw new NotEnoughBytesError("string", length, contentBuffer.length);
537
- }
538
- const [value, contentOffset] = encoding.deserialize(contentBuffer);
539
- offset += contentOffset;
540
- return [value, offset];
541
- }
576
+ const out = {
577
+ ...getUnsignedTransaction(transaction),
578
+ feePayer
542
579
  };
580
+ Object.freeze(out);
581
+ return out;
543
582
  }
544
583
 
545
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.2/node_modules/@metaplex-foundation/umi-serializers/dist/esm/struct.mjs
546
- function struct(fields, options = {}) {
547
- const fieldDescriptions = fields.map(([name, serializer]) => `${String(name)}: ${serializer.description}`).join(", ");
548
- return {
549
- description: options.description ?? `struct(${fieldDescriptions})`,
550
- fixedSize: sumSerializerSizes(fields.map(([, field]) => field.fixedSize)),
551
- maxSize: sumSerializerSizes(fields.map(([, field]) => field.maxSize)),
552
- serialize: (struct2) => {
553
- const fieldBytes = fields.map(([key, serializer]) => serializer.serialize(struct2[key]));
554
- return mergeBytes(fieldBytes);
555
- },
556
- deserialize: (bytes2, offset = 0) => {
557
- const struct2 = {};
558
- fields.forEach(([key, serializer]) => {
559
- const [value, newOffset] = serializer.deserialize(bytes2, offset);
560
- offset = newOffset;
561
- struct2[key] = value;
562
- });
563
- return [struct2, offset];
564
- }
584
+ // src/instructions.ts
585
+ function appendTransactionInstruction(instruction, transaction) {
586
+ const out = {
587
+ ...getUnsignedTransaction(transaction),
588
+ instructions: [...transaction.instructions, instruction]
565
589
  };
590
+ Object.freeze(out);
591
+ return out;
566
592
  }
567
- function getBase58EncodedAddressCodec(config) {
568
- return string({
569
- description: config?.description ?? ("A 32-byte account address" ),
570
- encoding: base58,
571
- size: 32
572
- });
573
- }
574
- function getBase58EncodedAddressComparator() {
575
- return new Intl.Collator("en", {
576
- caseFirst: "lower",
577
- ignorePunctuation: false,
578
- localeMatcher: "best fit",
579
- numeric: false,
580
- sensitivity: "variant",
581
- usage: "sort"
582
- }).compare;
593
+ function prependTransactionInstruction(instruction, transaction) {
594
+ const out = {
595
+ ...getUnsignedTransaction(transaction),
596
+ instructions: [instruction, ...transaction.instructions]
597
+ };
598
+ Object.freeze(out);
599
+ return out;
583
600
  }
601
+
602
+ // ../assertions/dist/index.browser.js
584
603
  function assertIsSecureContext() {
585
604
  if (!globalThis.isSecureContext) {
586
605
  throw new Error(
@@ -589,58 +608,101 @@ this.globalThis.solanaWeb3 = (function (exports) {
589
608
  }
590
609
  }
591
610
  async function assertKeyExporterIsAvailable() {
611
+ var _a;
592
612
  assertIsSecureContext();
593
- 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") {
594
614
  throw new Error("No key export implementation could be found");
595
615
  }
596
616
  }
597
617
  async function assertSigningCapabilityIsAvailable() {
618
+ var _a;
598
619
  assertIsSecureContext();
599
- 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") {
600
621
  throw new Error("No signing implementation could be found");
601
622
  }
602
623
  }
603
- 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) {
604
693
  await assertKeyExporterIsAvailable();
605
694
  if (publicKey.type !== "public" || publicKey.algorithm.name !== "Ed25519") {
606
695
  throw new Error("The `CryptoKey` must be an `Ed25519` public key");
607
696
  }
608
697
  const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
609
- const [base58EncodedAddress] = getBase58EncodedAddressCodec().deserialize(new Uint8Array(publicKeyBytes));
698
+ const [base58EncodedAddress] = getAddressDecoder().decode(new Uint8Array(publicKeyBytes));
610
699
  return base58EncodedAddress;
611
700
  }
612
- async function signBytes(key, data) {
613
- await assertSigningCapabilityIsAvailable();
614
- const signedData = await crypto.subtle.sign("Ed25519", key, data);
615
- return new Uint8Array(signedData);
616
- }
617
-
618
- // ../instructions/dist/index.browser.js
619
- var AccountRole = /* @__PURE__ */ ((AccountRole2) => {
620
- AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */
621
- 3] = "WRITABLE_SIGNER";
622
- AccountRole2[AccountRole2["READONLY_SIGNER"] = /* 2 */
623
- 2] = "READONLY_SIGNER";
624
- AccountRole2[AccountRole2["WRITABLE"] = /* 1 */
625
- 1] = "WRITABLE";
626
- AccountRole2[AccountRole2["READONLY"] = /* 0 */
627
- 0] = "READONLY";
628
- return AccountRole2;
629
- })(AccountRole || {});
630
- var IS_WRITABLE_BITMASK = 1;
631
- function isSignerRole(role) {
632
- return role >= 2;
633
- }
634
- function isWritableRole(role) {
635
- return (role & IS_WRITABLE_BITMASK) !== 0;
636
- }
637
- function mergeRoles(roleA, roleB) {
638
- return roleA | roleB;
639
- }
640
701
 
641
702
  // src/accounts.ts
642
- function upsert(addressMap, address, update) {
643
- 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 });
644
706
  }
645
707
  var TYPE = Symbol("AddressMapTypeProperty");
646
708
  function getAddressMapFromInstructions(feePayer, instructions) {
@@ -691,7 +753,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
691
753
  const shouldReplaceEntry = (
692
754
  // Consider using the new LOOKUP_TABLE if its address is different...
693
755
  entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
694
- (addressComparator || (addressComparator = getBase58EncodedAddressComparator()))(
756
+ (addressComparator || (addressComparator = getAddressComparator()))(
695
757
  accountMeta.lookupTableAddress,
696
758
  entry.lookupTableAddress
697
759
  ) < 0
@@ -797,14 +859,14 @@ this.globalThis.solanaWeb3 = (function (exports) {
797
859
  if (leftIsWritable !== isWritableRole(rightEntry.role)) {
798
860
  return leftIsWritable ? -1 : 1;
799
861
  }
800
- addressComparator || (addressComparator = getBase58EncodedAddressComparator());
862
+ addressComparator || (addressComparator = getAddressComparator());
801
863
  if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
802
864
  return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
803
865
  } else {
804
866
  return addressComparator(leftAddress, rightAddress);
805
867
  }
806
- }).map(([address, addressMeta]) => ({
807
- address,
868
+ }).map(([address2, addressMeta]) => ({
869
+ address: address2,
808
870
  ...addressMeta
809
871
  }));
810
872
  return orderedAccounts;
@@ -828,7 +890,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
828
890
  entry.readableIndices.push(account.addressIndex);
829
891
  }
830
892
  }
831
- return Object.keys(index).sort(getBase58EncodedAddressComparator()).map((lookupTableAddress) => ({
893
+ return Object.keys(index).sort(getAddressComparator()).map((lookupTableAddress) => ({
832
894
  lookupTableAddress,
833
895
  ...index[lookupTableAddress]
834
896
  }));
@@ -852,201 +914,424 @@ this.globalThis.solanaWeb3 = (function (exports) {
852
914
  } else if (!accountIsWritable) {
853
915
  numReadonlyNonSignerAccounts++;
854
916
  }
855
- }
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 = {}) {
856
1141
  return {
857
- numReadonlyNonSignerAccounts,
858
- numReadonlySignerAccounts,
859
- 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
+ }
860
1152
  };
861
1153
  }
862
1154
 
863
- // src/compile-instructions.ts
864
- function getAccountIndex(orderedAccounts) {
865
- const out = {};
866
- for (const [index, account] of orderedAccounts.entries()) {
867
- out[account.address] = index;
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
+ );
868
1183
  }
869
- return out;
870
- }
871
- function getCompiledInstructions(instructions, orderedAccounts) {
872
- const accountIndex = getAccountIndex(orderedAccounts);
873
- return instructions.map(({ accounts, data, programAddress }) => {
874
- return {
875
- programAddressIndex: accountIndex[programAddress],
876
- ...accounts ? { accountIndices: accounts.map(({ address }) => accountIndex[address]) } : null,
877
- ...data ? { data } : null
878
- };
879
- });
1184
+ return memoizedAddressTableLookupEncoder;
880
1185
  }
881
-
882
- // src/compile-lifetime-token.ts
883
- function getCompiledLifetimeToken(lifetimeConstraint) {
884
- if ("nonce" in lifetimeConstraint) {
885
- 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
+ );
886
1209
  }
887
- return lifetimeConstraint.blockhash;
1210
+ return memoizedAddressTableLookupDecoder;
888
1211
  }
889
1212
 
890
- // src/compile-static-accounts.ts
891
- function getCompiledStaticAccounts(orderedAccounts) {
892
- const firstLookupTableAccountIndex = orderedAccounts.findIndex((account) => "lookupTableAddress" in account);
893
- const orderedStaticAccounts = firstLookupTableAccountIndex === -1 ? orderedAccounts : orderedAccounts.slice(0, firstLookupTableAccountIndex);
894
- return orderedStaticAccounts.map(({ address }) => address);
1213
+ // src/serializers/header.ts
1214
+ var memoizedU8Encoder;
1215
+ function getMemoizedU8Encoder() {
1216
+ if (!memoizedU8Encoder)
1217
+ memoizedU8Encoder = getU8Encoder();
1218
+ return memoizedU8Encoder;
895
1219
  }
896
-
897
- // src/message.ts
898
- function compileMessage(transaction) {
899
- const addressMap = getAddressMapFromInstructions(transaction.feePayer, transaction.instructions);
900
- const orderedAccounts = getOrderedAccountsFromAddressMap(addressMap);
1220
+ function getMemoizedU8EncoderDescription(description) {
1221
+ const encoder = getMemoizedU8Encoder();
901
1222
  return {
902
- ...transaction.version !== "legacy" ? { addressTableLookups: getCompiledAddressTableLookups(orderedAccounts) } : null,
903
- header: getCompiledMessageHeader(orderedAccounts),
904
- instructions: getCompiledInstructions(transaction.instructions, orderedAccounts),
905
- lifetimeToken: getCompiledLifetimeToken(transaction.lifetimeConstraint),
906
- staticAccounts: getCompiledStaticAccounts(orderedAccounts),
907
- version: transaction.version
1223
+ ...encoder,
1224
+ description: description != null ? description : encoder.description
908
1225
  };
909
1226
  }
910
-
911
- // src/serializers/address-table-lookup.ts
912
- function getAddressTableLookupCodec() {
913
- 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(
914
1246
  [
915
- [
916
- "lookupTableAddress",
917
- getBase58EncodedAddressCodec(
918
- {
919
- description: "The address of the address lookup table account from which instruction addresses should be looked up"
920
- }
921
- )
922
- ],
923
- [
924
- "writableIndices",
925
- array(u8(), {
926
- ...{
927
- description: "The indices of the accounts in the lookup table that should be loaded as writeable"
928
- } ,
929
- size: shortU16()
930
- })
931
- ],
932
- [
933
- "readableIndices",
934
- array(u8(), {
935
- ...{
936
- description: "The indices of the accounts in the lookup table that should be loaded as read-only"
937
- } ,
938
- size: shortU16()
939
- })
940
- ]
1247
+ ["numSignerAccounts", getMemoizedU8EncoderDescription(numSignerAccountsDescription)],
1248
+ ["numReadonlySignerAccounts", getMemoizedU8EncoderDescription(numReadonlySignerAccountsDescription)],
1249
+ ["numReadonlyNonSignerAccounts", getMemoizedU8EncoderDescription(numReadonlyNonSignerAccountsDescription)]
941
1250
  ],
942
1251
  {
943
- description: "A pointer to the address of an address lookup table, along with the readonly/writeable indices of the addresses that should be loaded from it"
944
- }
1252
+ description: messageHeaderDescription
1253
+ }
945
1254
  );
946
1255
  }
947
-
948
- // src/serializers/header.ts
949
- function getMessageHeaderCodec() {
950
- return struct(
1256
+ function getMessageHeaderDecoder() {
1257
+ return getStructDecoder(
951
1258
  [
952
- [
953
- "numSignerAccounts",
954
- u8(
955
- {
956
- description: "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction"
957
- }
958
- )
959
- ],
960
- [
961
- "numReadonlySignerAccounts",
962
- u8(
963
- {
964
- description: "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction, but may not be writable"
965
- }
966
- )
967
- ],
968
- [
969
- "numReadonlyNonSignerAccounts",
970
- u8(
971
- {
972
- description: "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable"
973
- }
974
- )
975
- ]
1259
+ ["numSignerAccounts", getMemoizedU8DecoderDescription(numSignerAccountsDescription)],
1260
+ ["numReadonlySignerAccounts", getMemoizedU8DecoderDescription(numReadonlySignerAccountsDescription)],
1261
+ ["numReadonlyNonSignerAccounts", getMemoizedU8DecoderDescription(numReadonlyNonSignerAccountsDescription)]
976
1262
  ],
977
1263
  {
978
- description: "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses"
979
- }
1264
+ description: messageHeaderDescription
1265
+ }
980
1266
  );
981
1267
  }
982
1268
 
983
1269
  // src/serializers/instruction.ts
984
- function getInstructionCodec() {
985
- return mapSerializer(
986
- struct([
987
- [
988
- "programAddressIndex",
989
- u8(
990
- {
991
- description: "The index of the program being called, according to the well-ordered accounts list for this transaction"
992
- }
993
- )
994
- ],
995
- [
996
- "addressIndices",
997
- array(
998
- u8({
999
- description: "The index of an account, according to the well-ordered accounts list for this transaction"
1000
- }),
1001
- {
1002
- description: "An optional list of account indices, according to the well-ordered accounts list for this transaction, in the order in which the program being called expects them" ,
1003
- size: shortU16()
1004
- }
1005
- )
1006
- ],
1007
- [
1008
- "data",
1009
- bytes({
1010
- description: "An optional buffer of data passed to the instruction" ,
1011
- size: shortU16()
1012
- })
1013
- ]
1014
- ]),
1015
- (value) => {
1016
- if (value.addressIndices !== void 0 && value.data !== void 0) {
1017
- return value;
1018
- }
1019
- return {
1020
- ...value,
1021
- addressIndices: value.addressIndices ?? [],
1022
- data: value.data ?? new Uint8Array(0)
1023
- };
1024
- },
1025
- (value) => {
1026
- if (value.addressIndices.length && value.data.byteLength) {
1027
- return value;
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
+ };
1028
1300
  }
1029
- const { addressIndices, data, ...rest } = value;
1030
- return {
1031
- ...rest,
1032
- ...addressIndices.length ? { addressIndices } : null,
1033
- ...data.byteLength ? { data } : null
1034
- };
1035
- }
1036
- );
1037
- }
1038
-
1039
- // src/serializers/unimplemented.ts
1040
- function getError(type, name) {
1041
- const functionSuffix = name + type[0].toUpperCase() + type.slice(1);
1042
- return new Error(
1043
- `No ${type} exists for ${name}. Use \`get${functionSuffix}()\` if you need a ${type}, and \`get${name}Codec()\` if you need to both encode and decode ${name}`
1044
- );
1301
+ );
1302
+ }
1303
+ return memoizedGetInstructionEncoder;
1045
1304
  }
1046
- function getUnimplementedDecoder(name) {
1047
- return () => {
1048
- throw getError("decoder", name);
1049
- };
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;
1050
1335
  }
1051
1336
 
1052
1337
  // src/serializers/transaction-version.ts
@@ -1056,8 +1341,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
1056
1341
  fixedSize: null,
1057
1342
  maxSize: 1
1058
1343
  };
1059
- function deserialize(bytes2, offset = 0) {
1060
- const firstByte = bytes2[offset];
1344
+ function decode(bytes, offset = 0) {
1345
+ const firstByte = bytes[offset];
1061
1346
  if ((firstByte & VERSION_FLAG_MASK) === 0) {
1062
1347
  return ["legacy", offset];
1063
1348
  } else {
@@ -1065,7 +1350,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
1065
1350
  return [version, offset + 1];
1066
1351
  }
1067
1352
  }
1068
- function serialize(value) {
1353
+ function encode(value) {
1069
1354
  if (value === "legacy") {
1070
1355
  return new Uint8Array();
1071
1356
  }
@@ -1074,115 +1359,155 @@ this.globalThis.solanaWeb3 = (function (exports) {
1074
1359
  }
1075
1360
  return new Uint8Array([value | VERSION_FLAG_MASK]);
1076
1361
  }
1077
- function getTransactionVersionCodec() {
1362
+ function getTransactionVersionDecoder() {
1363
+ return {
1364
+ ...BASE_CONFIG,
1365
+ decode
1366
+ };
1367
+ }
1368
+ function getTransactionVersionEncoder() {
1078
1369
  return {
1079
1370
  ...BASE_CONFIG,
1080
- deserialize,
1081
- serialize
1371
+ encode
1082
1372
  };
1083
1373
  }
1084
1374
 
1085
1375
  // src/serializers/message.ts
1086
- var BASE_CONFIG2 = {
1087
- description: "The wire format of a Solana transaction message" ,
1088
- fixedSize: null,
1089
- maxSize: null
1090
- };
1091
- function serialize2(compiledMessage) {
1092
- if (compiledMessage.version === "legacy") {
1093
- return struct(getPreludeStructSerializerTuple()).serialize(compiledMessage);
1094
- } else {
1095
- return mapSerializer(
1096
- struct([
1097
- ...getPreludeStructSerializerTuple(),
1098
- ["addressTableLookups", getAddressTableLookupsSerializer()]
1099
- ]),
1100
- (value) => {
1101
- if (value.version === "legacy") {
1102
- return value;
1103
- }
1104
- return {
1105
- ...value,
1106
- addressTableLookups: value.addressTableLookups ?? []
1107
- };
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;
1108
1393
  }
1109
- ).serialize(compiledMessage);
1110
- }
1394
+ return {
1395
+ ...value,
1396
+ addressTableLookups: (_a = value.addressTableLookups) != null ? _a : []
1397
+ };
1398
+ }
1399
+ );
1111
1400
  }
1112
- function getPreludeStructSerializerTuple() {
1401
+ function getPreludeStructEncoderTuple() {
1113
1402
  return [
1114
- ["version", getTransactionVersionCodec()],
1115
- ["header", getMessageHeaderCodec()],
1403
+ ["version", getTransactionVersionEncoder()],
1404
+ ["header", getMessageHeaderEncoder()],
1116
1405
  [
1117
1406
  "staticAccounts",
1118
- array(getBase58EncodedAddressCodec(), {
1119
- description: "A compact-array of static account addresses belonging to this transaction" ,
1120
- size: shortU16()
1407
+ getArrayEncoder(getAddressEncoder(), {
1408
+ description: staticAccountsDescription,
1409
+ size: getShortU16Encoder()
1121
1410
  })
1122
1411
  ],
1123
1412
  [
1124
1413
  "lifetimeToken",
1125
- string({
1126
- description: "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" ,
1127
- encoding: base58,
1414
+ getStringEncoder({
1415
+ description: lifetimeTokenDescription,
1416
+ encoding: getBase58Encoder(),
1128
1417
  size: 32
1129
1418
  })
1130
1419
  ],
1131
1420
  [
1132
1421
  "instructions",
1133
- array(getInstructionCodec(), {
1134
- description: "A compact-array of instructions belonging to this transaction" ,
1135
- size: shortU16()
1422
+ getArrayEncoder(getInstructionEncoder(), {
1423
+ description: instructionsDescription,
1424
+ size: getShortU16Encoder()
1136
1425
  })
1137
1426
  ]
1138
1427
  ];
1139
1428
  }
1140
- function getAddressTableLookupsSerializer() {
1141
- return array(getAddressTableLookupCodec(), {
1142
- ...{ description: "A compact array of address table lookups belonging to this transaction" } ,
1143
- 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()
1144
1468
  });
1145
1469
  }
1470
+ var messageDescription = "The wire format of a Solana transaction message" ;
1146
1471
  function getCompiledMessageEncoder() {
1147
1472
  return {
1148
- ...BASE_CONFIG2,
1149
- deserialize: getUnimplementedDecoder("CompiledMessage"),
1150
- 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
1151
1483
  };
1152
1484
  }
1153
-
1154
- // src/signatures.ts
1155
- async function getCompiledMessageSignature(message, secretKey) {
1156
- const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
1157
- const signature = await signBytes(secretKey, wireMessageBytes);
1158
- return signature;
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
+ );
1159
1497
  }
1160
- async function signTransaction(keyPair, transaction) {
1161
- const compiledMessage = compileMessage(transaction);
1162
- const [signerPublicKey, signature] = await Promise.all([
1163
- getBase58EncodedAddressFromPublicKey(keyPair.publicKey),
1164
- getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
1165
- ]);
1166
- const nextSignatures = {
1167
- ..."signatures" in transaction ? transaction.signatures : null,
1168
- ...{ [signerPublicKey]: signature }
1169
- };
1170
- const out = {
1171
- ...transaction,
1172
- signatures: nextSignatures
1173
- };
1174
- Object.freeze(out);
1175
- return out;
1498
+ function getCompiledMessageCodec() {
1499
+ return combineCodec(getCompiledMessageEncoder(), getCompiledMessageDecoder());
1176
1500
  }
1177
1501
 
1178
1502
  // src/compile-transaction.ts
1179
1503
  function getCompiledTransaction(transaction) {
1504
+ var _a;
1180
1505
  const compiledMessage = compileMessage(transaction);
1181
1506
  let signatures;
1182
1507
  if ("signatures" in transaction) {
1183
1508
  signatures = [];
1184
1509
  for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
1185
- 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));
1186
1511
  }
1187
1512
  } else {
1188
1513
  signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
@@ -1193,46 +1518,262 @@ this.globalThis.solanaWeb3 = (function (exports) {
1193
1518
  };
1194
1519
  }
1195
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
+
1196
1639
  // src/serializers/transaction.ts
1197
- var BASE_CONFIG3 = {
1198
- description: "The wire format of a Solana transaction" ,
1199
- fixedSize: null,
1200
- maxSize: null
1201
- };
1202
- function serialize3(transaction) {
1203
- const compiledTransaction = getCompiledTransaction(transaction);
1204
- 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(
1205
1644
  [
1206
- "signatures",
1207
- array(bytes({ size: 64 }), {
1208
- ...{ description: "A compact array of 64-byte, base-64 encoded Ed25519 signatures" } ,
1209
- size: shortU16()
1210
- })
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()]
1211
1673
  ],
1212
- ["compiledMessage", getCompiledMessageEncoder()]
1213
- ]).serialize(compiledTransaction);
1674
+ {
1675
+ description: transactionDescription
1676
+ }
1677
+ );
1214
1678
  }
1215
1679
  function getTransactionEncoder() {
1216
- return {
1217
- ...BASE_CONFIG3,
1218
- deserialize: getUnimplementedDecoder("CompiledMessage"),
1219
- 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
1220
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
+ });
1221
1749
  }
1222
1750
 
1223
1751
  // src/wire-transaction.ts
1224
1752
  function getBase64EncodedWireTransaction(transaction) {
1225
- const wireTransactionBytes = getTransactionEncoder().serialize(transaction);
1226
- {
1227
- return btoa(String.fromCharCode(...wireTransactionBytes));
1228
- }
1753
+ const wireTransactionBytes = getTransactionEncoder().encode(transaction);
1754
+ return getBase64Decoder().decode(wireTransactionBytes)[0];
1229
1755
  }
1230
1756
 
1231
1757
  exports.appendTransactionInstruction = appendTransactionInstruction;
1758
+ exports.assertIsBlockhash = assertIsBlockhash;
1759
+ exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
1760
+ exports.assertTransactionIsFullySigned = assertTransactionIsFullySigned;
1761
+ exports.compileMessage = compileMessage;
1232
1762
  exports.createTransaction = createTransaction;
1233
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;
1234
1773
  exports.prependTransactionInstruction = prependTransactionInstruction;
1235
1774
  exports.setTransactionFeePayer = setTransactionFeePayer;
1775
+ exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
1776
+ exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
1236
1777
  exports.signTransaction = signTransaction;
1237
1778
 
1238
1779
  return exports;