@solana/transactions 2.0.0-experimental.7da1908 → 2.0.0-experimental.819422a

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 (59) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +272 -5
  3. package/dist/index.browser.cjs +518 -285
  4. package/dist/index.browser.cjs.map +1 -1
  5. package/dist/index.browser.js +510 -284
  6. package/dist/index.browser.js.map +1 -1
  7. package/dist/index.development.js +1103 -703
  8. package/dist/index.development.js.map +1 -1
  9. package/dist/index.native.js +510 -284
  10. package/dist/index.native.js.map +1 -1
  11. package/dist/index.node.cjs +520 -285
  12. package/dist/index.node.cjs.map +1 -1
  13. package/dist/index.node.js +510 -284
  14. package/dist/index.node.js.map +1 -1
  15. package/dist/index.production.min.js +22 -15
  16. package/dist/types/accounts.d.ts +2 -2
  17. package/dist/types/accounts.d.ts.map +1 -1
  18. package/dist/types/blockhash.d.ts.map +1 -1
  19. package/dist/types/compilable-transaction.d.ts +7 -0
  20. package/dist/types/compilable-transaction.d.ts.map +1 -0
  21. package/dist/types/compile-address-table-lookups.d.ts +2 -2
  22. package/dist/types/compile-address-table-lookups.d.ts.map +1 -1
  23. package/dist/types/compile-static-accounts.d.ts +2 -2
  24. package/dist/types/compile-static-accounts.d.ts.map +1 -1
  25. package/dist/types/compile-transaction.d.ts +5 -6
  26. package/dist/types/compile-transaction.d.ts.map +1 -1
  27. package/dist/types/decompile-transaction.d.ts +5 -0
  28. package/dist/types/decompile-transaction.d.ts.map +1 -0
  29. package/dist/types/durable-nonce.d.ts +6 -6
  30. package/dist/types/durable-nonce.d.ts.map +1 -1
  31. package/dist/types/fee-payer.d.ts +4 -4
  32. package/dist/types/fee-payer.d.ts.map +1 -1
  33. package/dist/types/index.d.ts +3 -0
  34. package/dist/types/index.d.ts.map +1 -1
  35. package/dist/types/message.d.ts +1 -5
  36. package/dist/types/message.d.ts.map +1 -1
  37. package/dist/types/serializers/address-table-lookup.d.ts +5 -3
  38. package/dist/types/serializers/address-table-lookup.d.ts.map +1 -1
  39. package/dist/types/serializers/header.d.ts +4 -2
  40. package/dist/types/serializers/header.d.ts.map +1 -1
  41. package/dist/types/serializers/index.d.ts +3 -0
  42. package/dist/types/serializers/index.d.ts.map +1 -0
  43. package/dist/types/serializers/instruction.d.ts +4 -2
  44. package/dist/types/serializers/instruction.d.ts.map +1 -1
  45. package/dist/types/serializers/message.d.ts +4 -4
  46. package/dist/types/serializers/message.d.ts.map +1 -1
  47. package/dist/types/serializers/transaction-version.d.ts +4 -4
  48. package/dist/types/serializers/transaction-version.d.ts.map +1 -1
  49. package/dist/types/serializers/transaction.d.ts +6 -5
  50. package/dist/types/serializers/transaction.d.ts.map +1 -1
  51. package/dist/types/signatures.d.ts +8 -12
  52. package/dist/types/signatures.d.ts.map +1 -1
  53. package/dist/types/types.d.ts +6 -13
  54. package/dist/types/types.d.ts.map +1 -1
  55. package/dist/types/wire-transaction.d.ts +1 -1
  56. package/dist/types/wire-transaction.d.ts.map +1 -1
  57. package/package.json +18 -14
  58. package/dist/types/serializers/unimplemented.d.ts +0 -3
  59. package/dist/types/serializers/unimplemented.d.ts.map +0 -1
@@ -2,115 +2,264 @@ this.globalThis = this.globalThis || {};
2
2
  this.globalThis.solanaWeb3 = (function (exports) {
3
3
  'use strict';
4
4
 
5
- var __defProp = Object.defineProperty;
6
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
- var __publicField = (obj, key, value) => {
8
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
9
- return value;
10
- };
11
-
12
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/bytes.mjs
13
- var mergeBytes = (bytesArr) => {
14
- const totalLength = bytesArr.reduce((total, arr) => total + arr.length, 0);
5
+ // ../codecs-core/dist/index.browser.js
6
+ function assertByteArrayIsNotEmptyForCodec(codecDescription, bytes, offset = 0) {
7
+ if (bytes.length - offset <= 0) {
8
+ throw new Error(`Codec [${codecDescription}] cannot decode empty byte arrays.`);
9
+ }
10
+ }
11
+ function assertByteArrayHasEnoughBytesForCodec(codecDescription, expected, bytes, offset = 0) {
12
+ const bytesLength = bytes.length - offset;
13
+ if (bytesLength < expected) {
14
+ throw new Error(`Codec [${codecDescription}] expected ${expected} bytes, got ${bytesLength}.`);
15
+ }
16
+ }
17
+ var mergeBytes = (byteArrays) => {
18
+ const nonEmptyByteArrays = byteArrays.filter((arr) => arr.length);
19
+ if (nonEmptyByteArrays.length === 0) {
20
+ return byteArrays.length ? byteArrays[0] : new Uint8Array();
21
+ }
22
+ if (nonEmptyByteArrays.length === 1) {
23
+ return nonEmptyByteArrays[0];
24
+ }
25
+ const totalLength = nonEmptyByteArrays.reduce((total, arr) => total + arr.length, 0);
15
26
  const result = new Uint8Array(totalLength);
16
27
  let offset = 0;
17
- bytesArr.forEach((arr) => {
28
+ nonEmptyByteArrays.forEach((arr) => {
18
29
  result.set(arr, offset);
19
30
  offset += arr.length;
20
31
  });
21
32
  return result;
22
33
  };
23
- var padBytes = (bytes2, length) => {
24
- if (bytes2.length >= length)
25
- return bytes2;
34
+ var padBytes = (bytes, length) => {
35
+ if (bytes.length >= length)
36
+ return bytes;
26
37
  const paddedBytes = new Uint8Array(length).fill(0);
27
- paddedBytes.set(bytes2);
38
+ paddedBytes.set(bytes);
28
39
  return paddedBytes;
29
40
  };
30
- var fixBytes = (bytes2, length) => padBytes(bytes2.slice(0, length), length);
31
-
32
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/errors.mjs
33
- var DeserializingEmptyBufferError = class extends Error {
34
- constructor(serializer) {
35
- super(`Serializer [${serializer}] cannot deserialize empty buffers.`);
36
- __publicField(this, "name", "DeserializingEmptyBufferError");
41
+ var fixBytes = (bytes, length) => padBytes(bytes.length <= length ? bytes : bytes.slice(0, length), length);
42
+ function combineCodec(encoder, decoder, description) {
43
+ if (encoder.fixedSize !== decoder.fixedSize) {
44
+ throw new Error(
45
+ `Encoder and decoder must have the same fixed size, got [${encoder.fixedSize}] and [${decoder.fixedSize}].`
46
+ );
37
47
  }
38
- };
39
- var NotEnoughBytesError = class extends Error {
40
- constructor(serializer, expected, actual) {
41
- super(`Serializer [${serializer}] expected ${expected} bytes, got ${actual}.`);
42
- __publicField(this, "name", "NotEnoughBytesError");
48
+ if (encoder.maxSize !== decoder.maxSize) {
49
+ throw new Error(
50
+ `Encoder and decoder must have the same max size, got [${encoder.maxSize}] and [${decoder.maxSize}].`
51
+ );
43
52
  }
44
- };
45
- var ExpectedFixedSizeSerializerError = class extends Error {
46
- constructor(message) {
47
- message ?? (message = "Expected a fixed-size serializer, got a variable-size one.");
48
- super(message);
49
- __publicField(this, "name", "ExpectedFixedSizeSerializerError");
53
+ if (description === void 0 && encoder.description !== decoder.description) {
54
+ throw new Error(
55
+ `Encoder and decoder must have the same description, got [${encoder.description}] and [${decoder.description}]. Pass a custom description as a third argument if you want to override the description and bypass this error.`
56
+ );
50
57
  }
51
- };
52
-
53
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/fixSerializer.mjs
54
- function fixSerializer(serializer, fixedBytes, description) {
55
58
  return {
56
- description: description ?? `fixed(${fixedBytes}, ${serializer.description})`,
59
+ decode: decoder.decode,
60
+ description: description != null ? description : encoder.description,
61
+ encode: encoder.encode,
62
+ fixedSize: encoder.fixedSize,
63
+ maxSize: encoder.maxSize
64
+ };
65
+ }
66
+ function fixCodecHelper(data, fixedBytes, description) {
67
+ return {
68
+ description: description != null ? description : `fixed(${fixedBytes}, ${data.description})`,
57
69
  fixedSize: fixedBytes,
58
- maxSize: fixedBytes,
59
- serialize: (value) => fixBytes(serializer.serialize(value), fixedBytes),
60
- deserialize: (buffer, offset = 0) => {
61
- buffer = buffer.slice(offset, offset + fixedBytes);
62
- if (buffer.length < fixedBytes) {
63
- throw new NotEnoughBytesError("fixSerializer", fixedBytes, buffer.length);
70
+ maxSize: fixedBytes
71
+ };
72
+ }
73
+ function fixEncoder(encoder, fixedBytes, description) {
74
+ return {
75
+ ...fixCodecHelper(encoder, fixedBytes, description),
76
+ encode: (value) => fixBytes(encoder.encode(value), fixedBytes)
77
+ };
78
+ }
79
+ function fixDecoder(decoder, fixedBytes, description) {
80
+ return {
81
+ ...fixCodecHelper(decoder, fixedBytes, description),
82
+ decode: (bytes, offset = 0) => {
83
+ assertByteArrayHasEnoughBytesForCodec("fixCodec", fixedBytes, bytes, offset);
84
+ if (offset > 0 || bytes.length > fixedBytes) {
85
+ bytes = bytes.slice(offset, offset + fixedBytes);
64
86
  }
65
- if (serializer.fixedSize !== null) {
66
- buffer = fixBytes(buffer, serializer.fixedSize);
87
+ if (decoder.fixedSize !== null) {
88
+ bytes = fixBytes(bytes, decoder.fixedSize);
67
89
  }
68
- const [value] = serializer.deserialize(buffer, 0);
90
+ const [value] = decoder.decode(bytes, 0);
69
91
  return [value, offset + fixedBytes];
70
92
  }
71
93
  };
72
94
  }
73
-
74
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/mapSerializer.mjs
75
- function mapSerializer(serializer, unmap, map) {
95
+ function mapEncoder(encoder, unmap) {
76
96
  return {
77
- description: serializer.description,
78
- fixedSize: serializer.fixedSize,
79
- maxSize: serializer.maxSize,
80
- serialize: (value) => serializer.serialize(unmap(value)),
81
- deserialize: (buffer, offset = 0) => {
82
- const [value, length] = serializer.deserialize(buffer, offset);
83
- return map ? [map(value, buffer, offset), length] : [value, length];
84
- }
97
+ description: encoder.description,
98
+ encode: (value) => encoder.encode(unmap(value)),
99
+ fixedSize: encoder.fixedSize,
100
+ maxSize: encoder.maxSize
101
+ };
102
+ }
103
+ function mapDecoder(decoder, map) {
104
+ return {
105
+ decode: (bytes, offset = 0) => {
106
+ const [value, length] = decoder.decode(bytes, offset);
107
+ return [map(value, bytes, offset), length];
108
+ },
109
+ description: decoder.description,
110
+ fixedSize: decoder.fixedSize,
111
+ maxSize: decoder.maxSize
85
112
  };
86
113
  }
87
114
 
88
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/errors.mjs
89
- var InvalidBaseStringError = class extends Error {
90
- constructor(value, base, cause) {
91
- const message = `Expected a string of base ${base}, got [${value}].`;
92
- super(message);
93
- __publicField(this, "name", "InvalidBaseStringError");
94
- this.cause = cause;
115
+ // ../codecs-numbers/dist/index.browser.js
116
+ function assertNumberIsBetweenForCodec(codecDescription, min, max, value) {
117
+ if (value < min || value > max) {
118
+ throw new Error(
119
+ `Codec [${codecDescription}] expected number to be in the range [${min}, ${max}], got ${value}.`
120
+ );
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)";
95
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
+ };
96
218
  };
219
+ var getU32Encoder = (config = {}) => numberEncoderFactory({
220
+ config,
221
+ name: "u32",
222
+ range: [0, Number("0xffffffff")],
223
+ set: (view, value, le) => view.setUint32(0, value, le),
224
+ size: 4
225
+ });
226
+ var getU32Decoder = (config = {}) => numberDecoderFactory({
227
+ config,
228
+ get: (view, le) => view.getUint32(0, le),
229
+ name: "u32",
230
+ size: 4
231
+ });
232
+ var getU8Encoder = (config = {}) => numberEncoderFactory({
233
+ config,
234
+ name: "u8",
235
+ range: [0, Number("0xff")],
236
+ set: (view, value) => view.setUint8(0, value),
237
+ size: 1
238
+ });
239
+ var getU8Decoder = (config = {}) => numberDecoderFactory({
240
+ config,
241
+ get: (view) => view.getUint8(0),
242
+ name: "u8",
243
+ size: 1
244
+ });
97
245
 
98
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseX.mjs
99
- var baseX = (alphabet) => {
100
- const base = alphabet.length;
246
+ // ../codecs-strings/dist/index.browser.js
247
+ function assertValidBaseString(alphabet4, testValue, givenValue = testValue) {
248
+ if (!testValue.match(new RegExp(`^[${alphabet4}]*$`))) {
249
+ throw new Error(`Expected a string of base ${alphabet4.length}, got [${givenValue}].`);
250
+ }
251
+ }
252
+ var getBaseXEncoder = (alphabet4) => {
253
+ const base = alphabet4.length;
101
254
  const baseBigInt = BigInt(base);
102
255
  return {
103
256
  description: `base${base}`,
104
- fixedSize: null,
105
- maxSize: null,
106
- serialize(value) {
107
- if (!value.match(new RegExp(`^[${alphabet}]*$`))) {
108
- throw new InvalidBaseStringError(value, base);
109
- }
257
+ encode(value) {
258
+ assertValidBaseString(alphabet4, value);
110
259
  if (value === "")
111
260
  return new Uint8Array();
112
261
  const chars = [...value];
113
- let trailIndex = chars.findIndex((c) => c !== alphabet[0]);
262
+ let trailIndex = chars.findIndex((c) => c !== alphabet4[0]);
114
263
  trailIndex = trailIndex === -1 ? chars.length : trailIndex;
115
264
  const leadingZeroes = Array(trailIndex).fill(0);
116
265
  if (trailIndex === chars.length)
@@ -119,7 +268,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
119
268
  let base10Number = 0n;
120
269
  let baseXPower = 1n;
121
270
  for (let i = tailChars.length - 1; i >= 0; i -= 1) {
122
- base10Number += baseXPower * BigInt(alphabet.indexOf(tailChars[i]));
271
+ base10Number += baseXPower * BigInt(alphabet4.indexOf(tailChars[i]));
123
272
  baseXPower *= baseBigInt;
124
273
  }
125
274
  const tailBytes = [];
@@ -129,368 +278,132 @@ this.globalThis.solanaWeb3 = (function (exports) {
129
278
  }
130
279
  return Uint8Array.from(leadingZeroes.concat(tailBytes));
131
280
  },
132
- deserialize(buffer, offset = 0) {
133
- if (buffer.length === 0)
281
+ fixedSize: null,
282
+ maxSize: null
283
+ };
284
+ };
285
+ var getBaseXDecoder = (alphabet4) => {
286
+ const base = alphabet4.length;
287
+ const baseBigInt = BigInt(base);
288
+ return {
289
+ decode(rawBytes, offset = 0) {
290
+ const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);
291
+ if (bytes.length === 0)
134
292
  return ["", 0];
135
- const bytes2 = buffer.slice(offset);
136
- let trailIndex = bytes2.findIndex((n) => n !== 0);
137
- trailIndex = trailIndex === -1 ? bytes2.length : trailIndex;
138
- const leadingZeroes = alphabet[0].repeat(trailIndex);
139
- if (trailIndex === bytes2.length)
140
- return [leadingZeroes, buffer.length];
141
- let base10Number = bytes2.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
293
+ let trailIndex = bytes.findIndex((n) => n !== 0);
294
+ trailIndex = trailIndex === -1 ? bytes.length : trailIndex;
295
+ const leadingZeroes = alphabet4[0].repeat(trailIndex);
296
+ if (trailIndex === bytes.length)
297
+ return [leadingZeroes, rawBytes.length];
298
+ let base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
142
299
  const tailChars = [];
143
300
  while (base10Number > 0n) {
144
- tailChars.unshift(alphabet[Number(base10Number % baseBigInt)]);
301
+ tailChars.unshift(alphabet4[Number(base10Number % baseBigInt)]);
145
302
  base10Number /= baseBigInt;
146
303
  }
147
- return [leadingZeroes + tailChars.join(""), buffer.length];
148
- }
304
+ return [leadingZeroes + tailChars.join(""), rawBytes.length];
305
+ },
306
+ description: `base${base}`,
307
+ fixedSize: null,
308
+ maxSize: null
149
309
  };
150
310
  };
151
-
152
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/base58.mjs
153
- var base58 = baseX("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
154
-
155
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/nullCharacters.mjs
311
+ var alphabet2 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
312
+ var getBase58Encoder = () => getBaseXEncoder(alphabet2);
313
+ var getBase58Decoder = () => getBaseXDecoder(alphabet2);
314
+ var getBase64Decoder = () => {
315
+ {
316
+ return {
317
+ decode(bytes, offset = 0) {
318
+ const slice = bytes.slice(offset);
319
+ const value = btoa(String.fromCharCode(...slice));
320
+ return [value, bytes.length];
321
+ },
322
+ description: `base64`,
323
+ fixedSize: null,
324
+ maxSize: null
325
+ };
326
+ }
327
+ };
156
328
  var removeNullCharacters = (value) => (
157
329
  // eslint-disable-next-line no-control-regex
158
330
  value.replace(/\u0000/g, "")
159
331
  );
160
-
161
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/utf8.mjs
162
- var utf8 = {
163
- description: "utf8",
164
- fixedSize: null,
165
- maxSize: null,
166
- serialize(value) {
167
- return new TextEncoder().encode(value);
168
- },
169
- deserialize(buffer, offset = 0) {
170
- const value = new TextDecoder().decode(buffer.slice(offset));
171
- return [removeNullCharacters(value), buffer.length];
172
- }
173
- };
174
-
175
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/common.mjs
176
- var Endian;
177
- (function(Endian2) {
178
- Endian2["Little"] = "le";
179
- Endian2["Big"] = "be";
180
- })(Endian || (Endian = {}));
181
-
182
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/errors.mjs
183
- var NumberOutOfRangeError = class extends RangeError {
184
- constructor(serializer, min, max, actual) {
185
- super(`Serializer [${serializer}] expected number to be between ${min} and ${max}, got ${actual}.`);
186
- __publicField(this, "name", "NumberOutOfRangeError");
187
- }
188
- };
189
-
190
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/utils.mjs
191
- function numberFactory(input) {
192
- let littleEndian;
193
- let defaultDescription = input.name;
194
- if (input.size > 1) {
195
- littleEndian = !("endian" in input.options) || input.options.endian === Endian.Little;
196
- defaultDescription += littleEndian ? "(le)" : "(be)";
197
- }
332
+ var e = globalThis.TextDecoder;
333
+ var o = globalThis.TextEncoder;
334
+ var getUtf8Encoder = () => {
335
+ let textEncoder;
198
336
  return {
199
- description: input.options.description ?? defaultDescription,
200
- fixedSize: input.size,
201
- maxSize: input.size,
202
- serialize(value) {
203
- if (input.range) {
204
- assertRange(input.name, input.range[0], input.range[1], value);
205
- }
206
- const buffer = new ArrayBuffer(input.size);
207
- input.set(new DataView(buffer), value, littleEndian);
208
- return new Uint8Array(buffer);
209
- },
210
- deserialize(bytes2, offset = 0) {
211
- const slice = bytes2.slice(offset, offset + input.size);
212
- assertEnoughBytes("i8", slice, input.size);
213
- const view = toDataView(slice);
214
- return [input.get(view, littleEndian), offset + input.size];
215
- }
337
+ description: "utf8",
338
+ encode: (value) => new Uint8Array((textEncoder || (textEncoder = new o())).encode(value)),
339
+ fixedSize: null,
340
+ maxSize: null
216
341
  };
217
- }
218
- var toArrayBuffer = (array2) => array2.buffer.slice(array2.byteOffset, array2.byteLength + array2.byteOffset);
219
- var toDataView = (array2) => new DataView(toArrayBuffer(array2));
220
- var assertRange = (serializer, min, max, value) => {
221
- if (value < min || value > max) {
222
- throw new NumberOutOfRangeError(serializer, min, max, value);
223
- }
224
- };
225
- var assertEnoughBytes = (serializer, bytes2, expected) => {
226
- if (bytes2.length === 0) {
227
- throw new DeserializingEmptyBufferError(serializer);
228
- }
229
- if (bytes2.length < expected) {
230
- throw new NotEnoughBytesError(serializer, expected, bytes2.length);
231
- }
232
- };
233
-
234
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u8.mjs
235
- var u8 = (options = {}) => numberFactory({
236
- name: "u8",
237
- size: 1,
238
- range: [0, Number("0xff")],
239
- set: (view, value) => view.setUint8(0, Number(value)),
240
- get: (view) => view.getUint8(0),
241
- options
242
- });
243
-
244
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u32.mjs
245
- var u32 = (options = {}) => numberFactory({
246
- name: "u32",
247
- size: 4,
248
- range: [0, Number("0xffffffff")],
249
- set: (view, value, le) => view.setUint32(0, Number(value), le),
250
- get: (view, le) => view.getUint32(0, le),
251
- options
252
- });
253
-
254
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/shortU16.mjs
255
- var shortU16 = (options = {}) => ({
256
- description: options.description ?? "shortU16",
257
- fixedSize: null,
258
- maxSize: 3,
259
- serialize: (value) => {
260
- assertRange("shortU16", 0, 65535, value);
261
- const bytes2 = [0];
262
- for (let ii = 0; ; ii += 1) {
263
- const alignedValue = value >> ii * 7;
264
- if (alignedValue === 0) {
265
- break;
266
- }
267
- const nextSevenBits = 127 & alignedValue;
268
- bytes2[ii] = nextSevenBits;
269
- if (ii > 0) {
270
- bytes2[ii - 1] |= 128;
271
- }
272
- }
273
- return new Uint8Array(bytes2);
274
- },
275
- deserialize: (bytes2, offset = 0) => {
276
- let value = 0;
277
- let byteCount = 0;
278
- while (++byteCount) {
279
- const byteIndex = byteCount - 1;
280
- const currentByte = bytes2[offset + byteIndex];
281
- const nextSevenBits = 127 & currentByte;
282
- value |= nextSevenBits << byteIndex * 7;
283
- if ((currentByte & 128) === 0) {
284
- break;
285
- }
286
- }
287
- return [value, offset + byteCount];
288
- }
289
- });
290
-
291
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/errors.mjs
292
- var InvalidNumberOfItemsError = class extends Error {
293
- constructor(serializer, expected, actual) {
294
- super(`Expected [${serializer}] to have ${expected} items, got ${actual}.`);
295
- __publicField(this, "name", "InvalidNumberOfItemsError");
296
- }
297
- };
298
- var InvalidArrayLikeRemainderSizeError = class extends Error {
299
- constructor(remainderSize, itemSize) {
300
- super(`The remainder of the buffer (${remainderSize} bytes) cannot be split into chunks of ${itemSize} bytes. Serializers of "remainder" size must have a remainder that is a multiple of its item size. In other words, ${remainderSize} modulo ${itemSize} should be equal to zero.`);
301
- __publicField(this, "name", "InvalidArrayLikeRemainderSizeError");
302
- }
303
- };
304
- var UnrecognizedArrayLikeSerializerSizeError = class extends Error {
305
- constructor(size) {
306
- super(`Unrecognized array-like serializer size: ${JSON.stringify(size)}`);
307
- __publicField(this, "name", "UnrecognizedArrayLikeSerializerSizeError");
308
- }
309
342
  };
310
-
311
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/sumSerializerSizes.mjs
312
- function sumSerializerSizes(sizes) {
313
- return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
314
- }
315
-
316
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/utils.mjs
317
- function getResolvedSize(size, childrenSizes, bytes2, offset) {
318
- if (typeof size === "number") {
319
- return [size, offset];
320
- }
321
- if (typeof size === "object") {
322
- return size.deserialize(bytes2, offset);
323
- }
324
- if (size === "remainder") {
325
- const childrenSize = sumSerializerSizes(childrenSizes);
326
- if (childrenSize === null) {
327
- throw new ExpectedFixedSizeSerializerError('Serializers of "remainder" size must have fixed-size items.');
328
- }
329
- const remainder = bytes2.slice(offset).length;
330
- if (remainder % childrenSize !== 0) {
331
- throw new InvalidArrayLikeRemainderSizeError(remainder, childrenSize);
332
- }
333
- return [remainder / childrenSize, offset];
334
- }
335
- throw new UnrecognizedArrayLikeSerializerSizeError(size);
336
- }
337
- function getSizeDescription(size) {
338
- return typeof size === "object" ? size.description : `${size}`;
339
- }
340
- function getSizeFromChildren(size, childrenSizes) {
341
- if (typeof size !== "number")
342
- return null;
343
- if (size === 0)
344
- return 0;
345
- const childrenSize = sumSerializerSizes(childrenSizes);
346
- return childrenSize === null ? null : childrenSize * size;
347
- }
348
- function getSizePrefix(size, realSize) {
349
- return typeof size === "object" ? size.serialize(realSize) : new Uint8Array();
350
- }
351
-
352
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/array.mjs
353
- function array(item, options = {}) {
354
- const size = options.size ?? u32();
355
- if (size === "remainder" && item.fixedSize === null) {
356
- throw new ExpectedFixedSizeSerializerError('Serializers of "remainder" size must have fixed-size items.');
357
- }
343
+ var getUtf8Decoder = () => {
344
+ let textDecoder;
358
345
  return {
359
- description: options.description ?? `array(${item.description}; ${getSizeDescription(size)})`,
360
- fixedSize: getSizeFromChildren(size, [item.fixedSize]),
361
- maxSize: getSizeFromChildren(size, [item.maxSize]),
362
- serialize: (value) => {
363
- if (typeof size === "number" && value.length !== size) {
364
- throw new InvalidNumberOfItemsError("array", size, value.length);
365
- }
366
- return mergeBytes([getSizePrefix(size, value.length), ...value.map((v) => item.serialize(v))]);
346
+ decode(bytes, offset = 0) {
347
+ const value = (textDecoder || (textDecoder = new e())).decode(bytes.slice(offset));
348
+ return [removeNullCharacters(value), bytes.length];
367
349
  },
368
- deserialize: (bytes2, offset = 0) => {
369
- if (typeof size === "object" && bytes2.slice(offset).length === 0) {
370
- return [[], offset];
371
- }
372
- const [resolvedSize, newOffset] = getResolvedSize(size, [item.fixedSize], bytes2, offset);
373
- offset = newOffset;
374
- const values = [];
375
- for (let i = 0; i < resolvedSize; i += 1) {
376
- const [value, newOffset2] = item.deserialize(bytes2, offset);
377
- values.push(value);
378
- offset = newOffset2;
379
- }
380
- return [values, offset];
381
- }
382
- };
383
- }
384
-
385
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/bytes.mjs
386
- function bytes(options = {}) {
387
- const size = options.size ?? "variable";
388
- const description = options.description ?? `bytes(${getSizeDescription(size)})`;
389
- const byteSerializer = {
390
- description,
350
+ description: "utf8",
391
351
  fixedSize: null,
392
- maxSize: null,
393
- serialize: (value) => new Uint8Array(value),
394
- deserialize: (bytes2, offset = 0) => {
395
- const slice = bytes2.slice(offset);
396
- return [slice, offset + slice.length];
397
- }
352
+ maxSize: null
398
353
  };
354
+ };
355
+ var getStringEncoder = (config = {}) => {
356
+ var _a, _b, _c;
357
+ const size = (_a = config.size) != null ? _a : getU32Encoder();
358
+ const encoding = (_b = config.encoding) != null ? _b : getUtf8Encoder();
359
+ const description = (_c = config.description) != null ? _c : `string(${encoding.description}; ${getSizeDescription(size)})`;
399
360
  if (size === "variable") {
400
- return byteSerializer;
361
+ return { ...encoding, description };
401
362
  }
402
363
  if (typeof size === "number") {
403
- return fixSerializer(byteSerializer, size, description);
364
+ return fixEncoder(encoding, size, description);
404
365
  }
405
366
  return {
406
367
  description,
407
- fixedSize: null,
408
- maxSize: null,
409
- serialize: (value) => {
410
- const contentBytes = byteSerializer.serialize(value);
411
- const lengthBytes = size.serialize(contentBytes.length);
368
+ encode: (value) => {
369
+ const contentBytes = encoding.encode(value);
370
+ const lengthBytes = size.encode(contentBytes.length);
412
371
  return mergeBytes([lengthBytes, contentBytes]);
413
372
  },
414
- deserialize: (buffer, offset = 0) => {
415
- if (buffer.slice(offset).length === 0) {
416
- throw new DeserializingEmptyBufferError("bytes");
417
- }
418
- const [lengthBigInt, lengthOffset] = size.deserialize(buffer, offset);
419
- const length = Number(lengthBigInt);
420
- offset = lengthOffset;
421
- const contentBuffer = buffer.slice(offset, offset + length);
422
- if (contentBuffer.length < length) {
423
- throw new NotEnoughBytesError("bytes", length, contentBuffer.length);
424
- }
425
- const [value, contentOffset] = byteSerializer.deserialize(contentBuffer);
426
- offset += contentOffset;
427
- return [value, offset];
428
- }
373
+ fixedSize: null,
374
+ maxSize: null
429
375
  };
430
- }
431
-
432
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/string.mjs
433
- function string(options = {}) {
434
- const size = options.size ?? u32();
435
- const encoding = options.encoding ?? utf8;
436
- const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
376
+ };
377
+ var getStringDecoder = (config = {}) => {
378
+ var _a, _b, _c;
379
+ const size = (_a = config.size) != null ? _a : getU32Decoder();
380
+ const encoding = (_b = config.encoding) != null ? _b : getUtf8Decoder();
381
+ const description = (_c = config.description) != null ? _c : `string(${encoding.description}; ${getSizeDescription(size)})`;
437
382
  if (size === "variable") {
438
- return {
439
- ...encoding,
440
- description
441
- };
383
+ return { ...encoding, description };
442
384
  }
443
385
  if (typeof size === "number") {
444
- return fixSerializer(encoding, size, description);
386
+ return fixDecoder(encoding, size, description);
445
387
  }
446
388
  return {
447
- description,
448
- fixedSize: null,
449
- maxSize: null,
450
- serialize: (value) => {
451
- const contentBytes = encoding.serialize(value);
452
- const lengthBytes = size.serialize(contentBytes.length);
453
- return mergeBytes([lengthBytes, contentBytes]);
454
- },
455
- deserialize: (buffer, offset = 0) => {
456
- if (buffer.slice(offset).length === 0) {
457
- throw new DeserializingEmptyBufferError("string");
458
- }
459
- const [lengthBigInt, lengthOffset] = size.deserialize(buffer, offset);
389
+ decode: (bytes, offset = 0) => {
390
+ assertByteArrayIsNotEmptyForCodec("string", bytes, offset);
391
+ const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);
460
392
  const length = Number(lengthBigInt);
461
393
  offset = lengthOffset;
462
- const contentBuffer = buffer.slice(offset, offset + length);
463
- if (contentBuffer.length < length) {
464
- throw new NotEnoughBytesError("string", length, contentBuffer.length);
465
- }
466
- const [value, contentOffset] = encoding.deserialize(contentBuffer);
394
+ const contentBytes = bytes.slice(offset, offset + length);
395
+ assertByteArrayHasEnoughBytesForCodec("string", length, contentBytes);
396
+ const [value, contentOffset] = encoding.decode(contentBytes);
467
397
  offset += contentOffset;
468
398
  return [value, offset];
469
- }
470
- };
471
- }
472
-
473
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/struct.mjs
474
- function struct(fields, options = {}) {
475
- const fieldDescriptions = fields.map(([name, serializer]) => `${String(name)}: ${serializer.description}`).join(", ");
476
- return {
477
- description: options.description ?? `struct(${fieldDescriptions})`,
478
- fixedSize: sumSerializerSizes(fields.map(([, field]) => field.fixedSize)),
479
- maxSize: sumSerializerSizes(fields.map(([, field]) => field.maxSize)),
480
- serialize: (struct2) => {
481
- const fieldBytes = fields.map(([key, serializer]) => serializer.serialize(struct2[key]));
482
- return mergeBytes(fieldBytes);
483
399
  },
484
- deserialize: (bytes2, offset = 0) => {
485
- const struct2 = {};
486
- fields.forEach(([key, serializer]) => {
487
- const [value, newOffset] = serializer.deserialize(bytes2, offset);
488
- offset = newOffset;
489
- struct2[key] = value;
490
- });
491
- return [struct2, offset];
492
- }
400
+ description,
401
+ fixedSize: null,
402
+ maxSize: null
493
403
  };
404
+ };
405
+ function getSizeDescription(size) {
406
+ return typeof size === "object" ? size.description : `${size}`;
494
407
  }
495
408
 
496
409
  // src/unsigned-transaction.ts
@@ -508,7 +421,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
508
421
  }
509
422
 
510
423
  // src/blockhash.ts
424
+ var base58Encoder;
511
425
  function assertIsBlockhash(putativeBlockhash) {
426
+ if (!base58Encoder)
427
+ base58Encoder = getBase58Encoder();
512
428
  try {
513
429
  if (
514
430
  // Lowest value (32 bytes of zeroes)
@@ -517,14 +433,14 @@ this.globalThis.solanaWeb3 = (function (exports) {
517
433
  ) {
518
434
  throw new Error("Expected input string to decode to a byte array of length 32.");
519
435
  }
520
- const bytes2 = base58.serialize(putativeBlockhash);
521
- const numBytes = bytes2.byteLength;
436
+ const bytes = base58Encoder.encode(putativeBlockhash);
437
+ const numBytes = bytes.byteLength;
522
438
  if (numBytes !== 32) {
523
439
  throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
524
440
  }
525
- } catch (e) {
441
+ } catch (e2) {
526
442
  throw new Error(`\`${putativeBlockhash}\` is not a blockhash`, {
527
- cause: e
443
+ cause: e2
528
444
  });
529
445
  }
530
446
  }
@@ -598,12 +514,13 @@ this.globalThis.solanaWeb3 = (function (exports) {
598
514
  };
599
515
  }
600
516
  function isAdvanceNonceAccountInstruction(instruction) {
517
+ var _a;
601
518
  return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
602
519
  instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts
603
- instruction.accounts?.length === 3 && // First account is nonce account address
520
+ ((_a = instruction.accounts) == null ? void 0 : _a.length) === 3 && // First account is nonce account address
604
521
  instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole.WRITABLE && // Second account is recent blockhashes sysvar
605
522
  instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole.READONLY && // Third account is nonce authority account
606
- instruction.accounts[2].address != null && instruction.accounts[2].role === AccountRole.READONLY_SIGNER;
523
+ instruction.accounts[2].address != null && isSignerRole(instruction.accounts[2].role);
607
524
  }
608
525
  function isAdvanceNonceAccountInstructionData(data) {
609
526
  return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
@@ -611,21 +528,38 @@ this.globalThis.solanaWeb3 = (function (exports) {
611
528
  function isDurableNonceTransaction(transaction) {
612
529
  return "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.nonce === "string" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]);
613
530
  }
531
+ function isAdvanceNonceAccountInstructionForNonce(instruction, nonceAccountAddress, nonceAuthorityAddress) {
532
+ return instruction.accounts[0].address === nonceAccountAddress && instruction.accounts[2].address === nonceAuthorityAddress;
533
+ }
614
534
  function setTransactionLifetimeUsingDurableNonce({
615
535
  nonce,
616
536
  nonceAccountAddress,
617
537
  nonceAuthorityAddress
618
538
  }, transaction) {
619
- const isAlreadyDurableNonceTransaction = isDurableNonceTransaction(transaction);
620
- if (isAlreadyDurableNonceTransaction && transaction.lifetimeConstraint.nonce === nonce && transaction.instructions[0].accounts[0].address === nonceAccountAddress && transaction.instructions[0].accounts[2].address === nonceAuthorityAddress) {
621
- return transaction;
539
+ let newInstructions;
540
+ const firstInstruction = transaction.instructions[0];
541
+ if (firstInstruction && isAdvanceNonceAccountInstruction(firstInstruction)) {
542
+ if (isAdvanceNonceAccountInstructionForNonce(firstInstruction, nonceAccountAddress, nonceAuthorityAddress)) {
543
+ if (isDurableNonceTransaction(transaction) && transaction.lifetimeConstraint.nonce === nonce) {
544
+ return transaction;
545
+ } else {
546
+ newInstructions = [firstInstruction, ...transaction.instructions.slice(1)];
547
+ }
548
+ } else {
549
+ newInstructions = [
550
+ createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
551
+ ...transaction.instructions.slice(1)
552
+ ];
553
+ }
554
+ } else {
555
+ newInstructions = [
556
+ createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
557
+ ...transaction.instructions
558
+ ];
622
559
  }
623
560
  const out = {
624
561
  ...getUnsignedTransaction(transaction),
625
- instructions: [
626
- createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
627
- ...isAlreadyDurableNonceTransaction ? transaction.instructions.slice(1) : transaction.instructions
628
- ],
562
+ instructions: newInstructions,
629
563
  lifetimeConstraint: {
630
564
  nonce
631
565
  }
@@ -674,25 +608,78 @@ this.globalThis.solanaWeb3 = (function (exports) {
674
608
  }
675
609
  }
676
610
  async function assertKeyExporterIsAvailable() {
611
+ var _a;
677
612
  assertIsSecureContext();
678
- 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") {
679
614
  throw new Error("No key export implementation could be found");
680
615
  }
681
616
  }
682
617
  async function assertSigningCapabilityIsAvailable() {
618
+ var _a;
683
619
  assertIsSecureContext();
684
- 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") {
685
621
  throw new Error("No signing implementation could be found");
686
622
  }
687
623
  }
688
- function getBase58EncodedAddressCodec(config) {
689
- return string({
690
- description: config?.description ?? ("A 32-byte account address" ),
691
- encoding: base58,
692
- size: 32
693
- });
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
+ }
694
658
  }
695
- function getBase58EncodedAddressComparator() {
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() {
696
683
  return new Intl.Collator("en", {
697
684
  caseFirst: "lower",
698
685
  ignorePunctuation: false,
@@ -708,20 +695,14 @@ this.globalThis.solanaWeb3 = (function (exports) {
708
695
  throw new Error("The `CryptoKey` must be an `Ed25519` public key");
709
696
  }
710
697
  const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
711
- const [base58EncodedAddress] = getBase58EncodedAddressCodec().deserialize(new Uint8Array(publicKeyBytes));
698
+ const [base58EncodedAddress] = getAddressDecoder().decode(new Uint8Array(publicKeyBytes));
712
699
  return base58EncodedAddress;
713
700
  }
714
701
 
715
- // ../keys/dist/index.browser.js
716
- async function signBytes(key, data) {
717
- await assertSigningCapabilityIsAvailable();
718
- const signedData = await crypto.subtle.sign("Ed25519", key, data);
719
- return new Uint8Array(signedData);
720
- }
721
-
722
702
  // src/accounts.ts
723
- function upsert(addressMap, address, update) {
724
- 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 });
725
706
  }
726
707
  var TYPE = Symbol("AddressMapTypeProperty");
727
708
  function getAddressMapFromInstructions(feePayer, instructions) {
@@ -772,7 +753,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
772
753
  const shouldReplaceEntry = (
773
754
  // Consider using the new LOOKUP_TABLE if its address is different...
774
755
  entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
775
- (addressComparator || (addressComparator = getBase58EncodedAddressComparator()))(
756
+ (addressComparator || (addressComparator = getAddressComparator()))(
776
757
  accountMeta.lookupTableAddress,
777
758
  entry.lookupTableAddress
778
759
  ) < 0
@@ -878,14 +859,14 @@ this.globalThis.solanaWeb3 = (function (exports) {
878
859
  if (leftIsWritable !== isWritableRole(rightEntry.role)) {
879
860
  return leftIsWritable ? -1 : 1;
880
861
  }
881
- addressComparator || (addressComparator = getBase58EncodedAddressComparator());
862
+ addressComparator || (addressComparator = getAddressComparator());
882
863
  if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
883
864
  return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
884
865
  } else {
885
866
  return addressComparator(leftAddress, rightAddress);
886
867
  }
887
- }).map(([address, addressMeta]) => ({
888
- address,
868
+ }).map(([address2, addressMeta]) => ({
869
+ address: address2,
889
870
  ...addressMeta
890
871
  }));
891
872
  return orderedAccounts;
@@ -909,7 +890,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
909
890
  entry.readableIndices.push(account.addressIndex);
910
891
  }
911
892
  }
912
- return Object.keys(index).sort(getBase58EncodedAddressComparator()).map((lookupTableAddress) => ({
893
+ return Object.keys(index).sort(getAddressComparator()).map((lookupTableAddress) => ({
913
894
  lookupTableAddress,
914
895
  ...index[lookupTableAddress]
915
896
  }));
@@ -954,7 +935,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
954
935
  return instructions.map(({ accounts, data, programAddress }) => {
955
936
  return {
956
937
  programAddressIndex: accountIndex[programAddress],
957
- ...accounts ? { accountIndices: accounts.map(({ address }) => accountIndex[address]) } : null,
938
+ ...accounts ? { accountIndices: accounts.map(({ address: address2 }) => accountIndex[address2]) } : null,
958
939
  ...data ? { data } : null
959
940
  };
960
941
  });
@@ -972,7 +953,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
972
953
  function getCompiledStaticAccounts(orderedAccounts) {
973
954
  const firstLookupTableAccountIndex = orderedAccounts.findIndex((account) => "lookupTableAddress" in account);
974
955
  const orderedStaticAccounts = firstLookupTableAccountIndex === -1 ? orderedAccounts : orderedAccounts.slice(0, firstLookupTableAccountIndex);
975
- return orderedStaticAccounts.map(({ address }) => address);
956
+ return orderedStaticAccounts.map(({ address: address2 }) => address2);
976
957
  }
977
958
 
978
959
  // src/message.ts
@@ -989,145 +970,368 @@ this.globalThis.solanaWeb3 = (function (exports) {
989
970
  };
990
971
  }
991
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 = {}) {
1141
+ return {
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
+ }
1152
+ };
1153
+ }
1154
+
992
1155
  // src/serializers/address-table-lookup.ts
993
- function getAddressTableLookupCodec() {
994
- return struct(
995
- [
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(
996
1164
  [
997
- "lookupTableAddress",
998
- getBase58EncodedAddressCodec(
999
- {
1000
- description: "The address of the address lookup table account from which instruction addresses should be looked up"
1001
- }
1002
- )
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
+ ]
1003
1180
  ],
1181
+ { description: addressTableLookupDescription }
1182
+ );
1183
+ }
1184
+ return memoizedAddressTableLookupEncoder;
1185
+ }
1186
+ var memoizedAddressTableLookupDecoder;
1187
+ function getAddressTableLookupDecoder() {
1188
+ if (!memoizedAddressTableLookupDecoder) {
1189
+ memoizedAddressTableLookupDecoder = getStructDecoder(
1004
1190
  [
1005
- "writableIndices",
1006
- array(u8(), {
1007
- ...{
1008
- description: "The indices of the accounts in the lookup table that should be loaded as writeable"
1009
- } ,
1010
- size: shortU16()
1011
- })
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
+ ]
1012
1206
  ],
1013
- [
1014
- "readableIndices",
1015
- array(u8(), {
1016
- ...{
1017
- description: "The indices of the accounts in the lookup table that should be loaded as read-only"
1018
- } ,
1019
- size: shortU16()
1020
- })
1021
- ]
1207
+ { description: addressTableLookupDescription }
1208
+ );
1209
+ }
1210
+ return memoizedAddressTableLookupDecoder;
1211
+ }
1212
+
1213
+ // src/serializers/header.ts
1214
+ var memoizedU8Encoder;
1215
+ function getMemoizedU8Encoder() {
1216
+ if (!memoizedU8Encoder)
1217
+ memoizedU8Encoder = getU8Encoder();
1218
+ return memoizedU8Encoder;
1219
+ }
1220
+ function getMemoizedU8EncoderDescription(description) {
1221
+ const encoder = getMemoizedU8Encoder();
1222
+ return {
1223
+ ...encoder,
1224
+ description: description != null ? description : encoder.description
1225
+ };
1226
+ }
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(
1246
+ [
1247
+ ["numSignerAccounts", getMemoizedU8EncoderDescription(numSignerAccountsDescription)],
1248
+ ["numReadonlySignerAccounts", getMemoizedU8EncoderDescription(numReadonlySignerAccountsDescription)],
1249
+ ["numReadonlyNonSignerAccounts", getMemoizedU8EncoderDescription(numReadonlyNonSignerAccountsDescription)]
1022
1250
  ],
1023
1251
  {
1024
- 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"
1025
- }
1252
+ description: messageHeaderDescription
1253
+ }
1026
1254
  );
1027
1255
  }
1028
-
1029
- // src/serializers/header.ts
1030
- function getMessageHeaderCodec() {
1031
- return struct(
1256
+ function getMessageHeaderDecoder() {
1257
+ return getStructDecoder(
1032
1258
  [
1033
- [
1034
- "numSignerAccounts",
1035
- u8(
1036
- {
1037
- description: "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction"
1038
- }
1039
- )
1040
- ],
1041
- [
1042
- "numReadonlySignerAccounts",
1043
- u8(
1044
- {
1045
- 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"
1046
- }
1047
- )
1048
- ],
1049
- [
1050
- "numReadonlyNonSignerAccounts",
1051
- u8(
1052
- {
1053
- description: "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable"
1054
- }
1055
- )
1056
- ]
1259
+ ["numSignerAccounts", getMemoizedU8DecoderDescription(numSignerAccountsDescription)],
1260
+ ["numReadonlySignerAccounts", getMemoizedU8DecoderDescription(numReadonlySignerAccountsDescription)],
1261
+ ["numReadonlyNonSignerAccounts", getMemoizedU8DecoderDescription(numReadonlyNonSignerAccountsDescription)]
1057
1262
  ],
1058
1263
  {
1059
- description: "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses"
1060
- }
1264
+ description: messageHeaderDescription
1265
+ }
1061
1266
  );
1062
1267
  }
1063
1268
 
1064
1269
  // src/serializers/instruction.ts
1065
- function getInstructionCodec() {
1066
- return mapSerializer(
1067
- struct([
1068
- [
1069
- "programAddressIndex",
1070
- u8(
1071
- {
1072
- description: "The index of the program being called, according to the well-ordered accounts list for this transaction"
1073
- }
1074
- )
1075
- ],
1076
- [
1077
- "accountIndices",
1078
- array(
1079
- u8({
1080
- description: "The index of an account, according to the well-ordered accounts list for this transaction"
1081
- }),
1082
- {
1083
- 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" ,
1084
- size: shortU16()
1085
- }
1086
- )
1087
- ],
1088
- [
1089
- "data",
1090
- bytes({
1091
- description: "An optional buffer of data passed to the instruction" ,
1092
- size: shortU16()
1093
- })
1094
- ]
1095
- ]),
1096
- (value) => {
1097
- if (value.accountIndices !== void 0 && value.data !== void 0) {
1098
- 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
+ };
1099
1300
  }
1100
- return {
1101
- ...value,
1102
- accountIndices: value.accountIndices ?? [],
1103
- data: value.data ?? new Uint8Array(0)
1104
- };
1105
- },
1106
- (value) => {
1107
- if (value.accountIndices.length && value.data.byteLength) {
1108
- return value;
1301
+ );
1302
+ }
1303
+ return memoizedGetInstructionEncoder;
1304
+ }
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
+ };
1109
1331
  }
1110
- const { accountIndices, data, ...rest } = value;
1111
- return {
1112
- ...rest,
1113
- ...accountIndices.length ? { accountIndices } : null,
1114
- ...data.byteLength ? { data } : null
1115
- };
1116
- }
1117
- );
1118
- }
1119
-
1120
- // src/serializers/unimplemented.ts
1121
- function getError(type, name) {
1122
- const functionSuffix = name + type[0].toUpperCase() + type.slice(1);
1123
- return new Error(
1124
- `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}`
1125
- );
1126
- }
1127
- function getUnimplementedDecoder(name) {
1128
- return () => {
1129
- throw getError("decoder", name);
1130
- };
1332
+ );
1333
+ }
1334
+ return memoizedGetInstructionDecoder;
1131
1335
  }
1132
1336
 
1133
1337
  // src/serializers/transaction-version.ts
@@ -1137,8 +1341,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
1137
1341
  fixedSize: null,
1138
1342
  maxSize: 1
1139
1343
  };
1140
- function deserialize(bytes2, offset = 0) {
1141
- const firstByte = bytes2[offset];
1344
+ function decode(bytes, offset = 0) {
1345
+ const firstByte = bytes[offset];
1142
1346
  if ((firstByte & VERSION_FLAG_MASK) === 0) {
1143
1347
  return ["legacy", offset];
1144
1348
  } else {
@@ -1146,7 +1350,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
1146
1350
  return [version, offset + 1];
1147
1351
  }
1148
1352
  }
1149
- function serialize(value) {
1353
+ function encode(value) {
1150
1354
  if (value === "legacy") {
1151
1355
  return new Uint8Array();
1152
1356
  }
@@ -1155,142 +1359,364 @@ this.globalThis.solanaWeb3 = (function (exports) {
1155
1359
  }
1156
1360
  return new Uint8Array([value | VERSION_FLAG_MASK]);
1157
1361
  }
1158
- function getTransactionVersionCodec() {
1362
+ function getTransactionVersionDecoder() {
1159
1363
  return {
1160
1364
  ...BASE_CONFIG,
1161
- deserialize,
1162
- serialize
1365
+ decode
1366
+ };
1367
+ }
1368
+ function getTransactionVersionEncoder() {
1369
+ return {
1370
+ ...BASE_CONFIG,
1371
+ encode
1163
1372
  };
1164
1373
  }
1165
1374
 
1166
1375
  // src/serializers/message.ts
1167
- var BASE_CONFIG2 = {
1168
- description: "The wire format of a Solana transaction message" ,
1169
- fixedSize: null,
1170
- maxSize: null
1171
- };
1172
- function serialize2(compiledMessage) {
1173
- if (compiledMessage.version === "legacy") {
1174
- return struct(getPreludeStructSerializerTuple()).serialize(compiledMessage);
1175
- } else {
1176
- return mapSerializer(
1177
- struct([
1178
- ...getPreludeStructSerializerTuple(),
1179
- ["addressTableLookups", getAddressTableLookupsSerializer()]
1180
- ]),
1181
- (value) => {
1182
- if (value.version === "legacy") {
1183
- return value;
1184
- }
1185
- return {
1186
- ...value,
1187
- addressTableLookups: value.addressTableLookups ?? []
1188
- };
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;
1189
1393
  }
1190
- ).serialize(compiledMessage);
1191
- }
1394
+ return {
1395
+ ...value,
1396
+ addressTableLookups: (_a = value.addressTableLookups) != null ? _a : []
1397
+ };
1398
+ }
1399
+ );
1192
1400
  }
1193
- function getPreludeStructSerializerTuple() {
1401
+ function getPreludeStructEncoderTuple() {
1194
1402
  return [
1195
- ["version", getTransactionVersionCodec()],
1196
- ["header", getMessageHeaderCodec()],
1403
+ ["version", getTransactionVersionEncoder()],
1404
+ ["header", getMessageHeaderEncoder()],
1197
1405
  [
1198
1406
  "staticAccounts",
1199
- array(getBase58EncodedAddressCodec(), {
1200
- description: "A compact-array of static account addresses belonging to this transaction" ,
1201
- size: shortU16()
1407
+ getArrayEncoder(getAddressEncoder(), {
1408
+ description: staticAccountsDescription,
1409
+ size: getShortU16Encoder()
1202
1410
  })
1203
1411
  ],
1204
1412
  [
1205
1413
  "lifetimeToken",
1206
- string({
1207
- description: "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" ,
1208
- encoding: base58,
1414
+ getStringEncoder({
1415
+ description: lifetimeTokenDescription,
1416
+ encoding: getBase58Encoder(),
1209
1417
  size: 32
1210
1418
  })
1211
1419
  ],
1212
1420
  [
1213
1421
  "instructions",
1214
- array(getInstructionCodec(), {
1215
- description: "A compact-array of instructions belonging to this transaction" ,
1216
- size: shortU16()
1422
+ getArrayEncoder(getInstructionEncoder(), {
1423
+ description: instructionsDescription,
1424
+ size: getShortU16Encoder()
1217
1425
  })
1218
1426
  ]
1219
1427
  ];
1220
1428
  }
1221
- function getAddressTableLookupsSerializer() {
1222
- return array(getAddressTableLookupCodec(), {
1223
- ...{ description: "A compact array of address table lookups belonging to this transaction" } ,
1224
- 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()
1225
1468
  });
1226
1469
  }
1470
+ var messageDescription = "The wire format of a Solana transaction message" ;
1227
1471
  function getCompiledMessageEncoder() {
1228
1472
  return {
1229
- ...BASE_CONFIG2,
1230
- deserialize: getUnimplementedDecoder("CompiledMessage"),
1231
- 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
1232
1483
  };
1233
1484
  }
1234
-
1235
- // src/signatures.ts
1236
- function assertIsTransactionSignature(putativeTransactionSignature) {
1237
- try {
1238
- if (
1239
- // Lowest value (64 bytes of zeroes)
1240
- putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
1241
- putativeTransactionSignature.length > 88
1242
- ) {
1243
- throw new Error("Expected input string to decode to a byte array of length 64.");
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 };
1244
1495
  }
1245
- const bytes2 = base58.serialize(putativeTransactionSignature);
1246
- const numBytes = bytes2.byteLength;
1247
- if (numBytes !== 64) {
1248
- throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
1496
+ );
1497
+ }
1498
+ function getCompiledMessageCodec() {
1499
+ return combineCodec(getCompiledMessageEncoder(), getCompiledMessageDecoder());
1500
+ }
1501
+
1502
+ // src/compile-transaction.ts
1503
+ function getCompiledTransaction(transaction) {
1504
+ var _a;
1505
+ const compiledMessage = compileMessage(transaction);
1506
+ let signatures;
1507
+ if ("signatures" in transaction) {
1508
+ signatures = [];
1509
+ for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
1510
+ signatures[ii] = (_a = transaction.signatures[compiledMessage.staticAccounts[ii]]) != null ? _a : new Uint8Array(Array(64).fill(0));
1249
1511
  }
1250
- } catch (e) {
1251
- throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
1252
- cause: e
1512
+ } else {
1513
+ signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
1514
+ }
1515
+ return {
1516
+ compiledMessage,
1517
+ signatures
1518
+ };
1519
+ }
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
1253
1544
  });
1545
+ accountIndex++;
1254
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;
1255
1562
  }
1256
- function isTransactionSignature(putativeTransactionSignature) {
1257
- if (
1258
- // Lowest value (64 bytes of zeroes)
1259
- putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
1260
- putativeTransactionSignature.length > 88
1261
- ) {
1262
- return false;
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
+ };
1263
1594
  }
1264
- const bytes2 = base58.serialize(putativeTransactionSignature);
1265
- const numBytes = bytes2.byteLength;
1266
- if (numBytes !== 64) {
1267
- return false;
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");
1268
1613
  }
1269
- return true;
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
+
1639
+ // src/serializers/transaction.ts
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(
1644
+ [
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()]
1673
+ ],
1674
+ {
1675
+ description: transactionDescription
1676
+ }
1677
+ );
1678
+ }
1679
+ function getTransactionEncoder() {
1680
+ return mapEncoder(getCompiledTransactionEncoder(), getCompiledTransaction);
1681
+ }
1682
+ function getTransactionDecoder(lastValidBlockHeight) {
1683
+ return mapDecoder(
1684
+ getCompiledTransactionDecoder(),
1685
+ (compiledTransaction) => decompileTransaction(compiledTransaction, lastValidBlockHeight)
1686
+ );
1270
1687
  }
1271
- async function getCompiledMessageSignature(message, secretKey) {
1272
- const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
1273
- const signature = await signBytes(secretKey, wireMessageBytes);
1274
- return signature;
1688
+ function getTransactionCodec(lastValidBlockHeight) {
1689
+ return combineCodec(getTransactionEncoder(), getTransactionDecoder(lastValidBlockHeight));
1275
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;
1276
1701
  function getSignatureFromTransaction(transaction) {
1277
- const signature = transaction.signatures[transaction.feePayer];
1278
- if (!signature) {
1702
+ if (!base58Decoder)
1703
+ base58Decoder = getBase58Decoder();
1704
+ const signatureBytes = transaction.signatures[transaction.feePayer];
1705
+ if (!signatureBytes) {
1279
1706
  throw new Error(
1280
1707
  "Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
1281
1708
  );
1282
1709
  }
1283
- return signature;
1710
+ const transactionSignature = base58Decoder.decode(signatureBytes)[0];
1711
+ return transactionSignature;
1284
1712
  }
1285
- async function signTransaction(keyPairs, transaction) {
1713
+ async function partiallySignTransaction(keyPairs, transaction) {
1286
1714
  const compiledMessage = compileMessage(transaction);
1287
1715
  const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
1716
+ const wireMessageBytes = getCompiledMessageEncoder().encode(compiledMessage);
1288
1717
  const publicKeySignaturePairs = await Promise.all(
1289
1718
  keyPairs.map(
1290
- (keyPair) => Promise.all([
1291
- getAddressFromPublicKey(keyPair.publicKey),
1292
- getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
1293
- ])
1719
+ (keyPair) => Promise.all([getAddressFromPublicKey(keyPair.publicKey), signBytes(keyPair.privateKey, wireMessageBytes)])
1294
1720
  )
1295
1721
  );
1296
1722
  for (const [signerPublicKey, signature] of publicKeySignaturePairs) {
@@ -1303,78 +1729,52 @@ this.globalThis.solanaWeb3 = (function (exports) {
1303
1729
  Object.freeze(out);
1304
1730
  return out;
1305
1731
  }
1306
- function transactionSignature(putativeTransactionSignature) {
1307
- assertIsTransactionSignature(putativeTransactionSignature);
1308
- return putativeTransactionSignature;
1732
+ async function signTransaction(keyPairs, transaction) {
1733
+ const out = await partiallySignTransaction(keyPairs, transaction);
1734
+ assertTransactionIsFullySigned(out);
1735
+ Object.freeze(out);
1736
+ return out;
1309
1737
  }
1310
-
1311
- // src/compile-transaction.ts
1312
- function getCompiledTransaction(transaction) {
1313
- const compiledMessage = compileMessage(transaction);
1314
- let signatures;
1315
- if ("signatures" in transaction) {
1316
- signatures = [];
1317
- for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
1318
- signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
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}\``);
1319
1747
  }
1320
- } else {
1321
- signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
1322
- }
1323
- return {
1324
- compiledMessage,
1325
- signatures
1326
- };
1327
- }
1328
-
1329
- // src/serializers/transaction.ts
1330
- var BASE_CONFIG3 = {
1331
- description: "The wire format of a Solana transaction" ,
1332
- fixedSize: null,
1333
- maxSize: null
1334
- };
1335
- function serialize3(transaction) {
1336
- const compiledTransaction = getCompiledTransaction(transaction);
1337
- return struct([
1338
- [
1339
- "signatures",
1340
- array(bytes({ size: 64 }), {
1341
- ...{ description: "A compact array of 64-byte, base-64 encoded Ed25519 signatures" } ,
1342
- size: shortU16()
1343
- })
1344
- ],
1345
- ["compiledMessage", getCompiledMessageEncoder()]
1346
- ]).serialize(compiledTransaction);
1347
- }
1348
- function getTransactionEncoder() {
1349
- return {
1350
- ...BASE_CONFIG3,
1351
- deserialize: getUnimplementedDecoder("CompiledMessage"),
1352
- serialize: serialize3
1353
- };
1748
+ });
1354
1749
  }
1355
1750
 
1356
1751
  // src/wire-transaction.ts
1357
1752
  function getBase64EncodedWireTransaction(transaction) {
1358
- const wireTransactionBytes = getTransactionEncoder().serialize(transaction);
1359
- {
1360
- return btoa(String.fromCharCode(...wireTransactionBytes));
1361
- }
1753
+ const wireTransactionBytes = getTransactionEncoder().encode(transaction);
1754
+ return getBase64Decoder().decode(wireTransactionBytes)[0];
1362
1755
  }
1363
1756
 
1364
1757
  exports.appendTransactionInstruction = appendTransactionInstruction;
1365
1758
  exports.assertIsBlockhash = assertIsBlockhash;
1366
1759
  exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
1367
- exports.assertIsTransactionSignature = assertIsTransactionSignature;
1760
+ exports.assertTransactionIsFullySigned = assertTransactionIsFullySigned;
1761
+ exports.compileMessage = compileMessage;
1368
1762
  exports.createTransaction = createTransaction;
1369
1763
  exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
1764
+ exports.getCompiledMessageCodec = getCompiledMessageCodec;
1765
+ exports.getCompiledMessageDecoder = getCompiledMessageDecoder;
1766
+ exports.getCompiledMessageEncoder = getCompiledMessageEncoder;
1370
1767
  exports.getSignatureFromTransaction = getSignatureFromTransaction;
1371
- exports.isTransactionSignature = isTransactionSignature;
1768
+ exports.getTransactionCodec = getTransactionCodec;
1769
+ exports.getTransactionDecoder = getTransactionDecoder;
1770
+ exports.getTransactionEncoder = getTransactionEncoder;
1771
+ exports.isAdvanceNonceAccountInstruction = isAdvanceNonceAccountInstruction;
1772
+ exports.partiallySignTransaction = partiallySignTransaction;
1372
1773
  exports.prependTransactionInstruction = prependTransactionInstruction;
1373
1774
  exports.setTransactionFeePayer = setTransactionFeePayer;
1374
1775
  exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
1375
1776
  exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
1376
1777
  exports.signTransaction = signTransaction;
1377
- exports.transactionSignature = transactionSignature;
1378
1778
 
1379
1779
  return exports;
1380
1780