@solana/transactions 2.0.0-experimental.835e62f → 2.0.0-experimental.85b7dfe

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