@solana/web3.js 2.0.0-experimental.e0b865d → 2.0.0-experimental.e4483d3

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 (54) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1155 -43
  3. package/dist/index.browser.cjs +447 -2
  4. package/dist/index.browser.cjs.map +1 -1
  5. package/dist/index.browser.js +431 -3
  6. package/dist/index.browser.js.map +1 -1
  7. package/dist/index.development.js +2003 -809
  8. package/dist/index.development.js.map +1 -1
  9. package/dist/index.native.js +431 -3
  10. package/dist/index.native.js.map +1 -1
  11. package/dist/index.node.cjs +447 -4
  12. package/dist/index.node.cjs.map +1 -1
  13. package/dist/index.node.js +431 -3
  14. package/dist/index.node.js.map +1 -1
  15. package/dist/index.production.min.js +80 -36
  16. package/dist/types/airdrop-confirmer.d.ts +19 -0
  17. package/dist/types/airdrop-confirmer.d.ts.map +1 -0
  18. package/dist/types/airdrop.d.ts +21 -0
  19. package/dist/types/airdrop.d.ts.map +1 -0
  20. package/dist/types/cached-abortable-iterable.d.ts.map +1 -0
  21. package/dist/types/index.d.ts +7 -0
  22. package/dist/types/index.d.ts.map +1 -0
  23. package/dist/types/rpc-default-config.d.ts.map +1 -0
  24. package/dist/types/rpc-integer-overflow-error.d.ts.map +1 -0
  25. package/dist/types/rpc-request-coalescer.d.ts +1 -1
  26. package/dist/types/rpc-request-coalescer.d.ts.map +1 -0
  27. package/dist/types/rpc-request-deduplication.d.ts.map +1 -0
  28. package/dist/types/rpc-subscription-coalescer.d.ts +1 -1
  29. package/dist/types/rpc-subscription-coalescer.d.ts.map +1 -0
  30. package/dist/types/rpc-transport.d.ts +1 -2
  31. package/dist/types/rpc-transport.d.ts.map +1 -0
  32. package/dist/types/rpc-websocket-autopinger.d.ts +1 -1
  33. package/dist/types/rpc-websocket-autopinger.d.ts.map +1 -0
  34. package/dist/types/rpc-websocket-connection-sharding.d.ts +1 -1
  35. package/dist/types/rpc-websocket-connection-sharding.d.ts.map +1 -0
  36. package/dist/types/rpc-websocket-transport.d.ts +1 -2
  37. package/dist/types/rpc-websocket-transport.d.ts.map +1 -0
  38. package/dist/types/rpc.d.ts +1 -2
  39. package/dist/types/rpc.d.ts.map +1 -0
  40. package/dist/types/send-transaction.d.ts +38 -0
  41. package/dist/types/send-transaction.d.ts.map +1 -0
  42. package/dist/types/transaction-confirmation-strategy-blockheight.d.ts +9 -0
  43. package/dist/types/transaction-confirmation-strategy-blockheight.d.ts.map +1 -0
  44. package/dist/types/transaction-confirmation-strategy-nonce.d.ts +14 -0
  45. package/dist/types/transaction-confirmation-strategy-nonce.d.ts.map +1 -0
  46. package/dist/types/transaction-confirmation-strategy-racer.d.ts +14 -0
  47. package/dist/types/transaction-confirmation-strategy-racer.d.ts.map +1 -0
  48. package/dist/types/transaction-confirmation-strategy-recent-signature.d.ts +12 -0
  49. package/dist/types/transaction-confirmation-strategy-recent-signature.d.ts.map +1 -0
  50. package/dist/types/transaction-confirmation-strategy-timeout.d.ts +8 -0
  51. package/dist/types/transaction-confirmation-strategy-timeout.d.ts.map +1 -0
  52. package/dist/types/transaction-confirmation.d.ts +32 -0
  53. package/dist/types/transaction-confirmation.d.ts.map +1 -0
  54. package/package.json +19 -17
@@ -125,125 +125,269 @@ this.globalThis.solanaWeb3 = (function (exports) {
125
125
  // ../addresses/dist/index.browser.js
126
126
  init_env_shim();
127
127
 
128
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/index.mjs
128
+ // ../codecs-core/dist/index.browser.js
129
129
  init_env_shim();
130
-
131
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/index.mjs
132
- init_env_shim();
133
-
134
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/bytes.mjs
135
- init_env_shim();
136
- var mergeBytes = (bytesArr) => {
137
- const totalLength = bytesArr.reduce((total, arr) => total + arr.length, 0);
130
+ function assertByteArrayIsNotEmptyForCodec(codecDescription, bytes, offset = 0) {
131
+ if (bytes.length - offset <= 0) {
132
+ throw new Error(`Codec [${codecDescription}] cannot decode empty byte arrays.`);
133
+ }
134
+ }
135
+ function assertByteArrayHasEnoughBytesForCodec(codecDescription, expected, bytes, offset = 0) {
136
+ const bytesLength = bytes.length - offset;
137
+ if (bytesLength < expected) {
138
+ throw new Error(`Codec [${codecDescription}] expected ${expected} bytes, got ${bytesLength}.`);
139
+ }
140
+ }
141
+ var mergeBytes = (byteArrays) => {
142
+ const nonEmptyByteArrays = byteArrays.filter((arr) => arr.length);
143
+ if (nonEmptyByteArrays.length === 0) {
144
+ return byteArrays.length ? byteArrays[0] : new Uint8Array();
145
+ }
146
+ if (nonEmptyByteArrays.length === 1) {
147
+ return nonEmptyByteArrays[0];
148
+ }
149
+ const totalLength = nonEmptyByteArrays.reduce((total, arr) => total + arr.length, 0);
138
150
  const result = new Uint8Array(totalLength);
139
151
  let offset = 0;
140
- bytesArr.forEach((arr) => {
152
+ nonEmptyByteArrays.forEach((arr) => {
141
153
  result.set(arr, offset);
142
154
  offset += arr.length;
143
155
  });
144
156
  return result;
145
157
  };
146
- var padBytes = (bytes2, length) => {
147
- if (bytes2.length >= length)
148
- return bytes2;
158
+ var padBytes = (bytes, length) => {
159
+ if (bytes.length >= length)
160
+ return bytes;
149
161
  const paddedBytes = new Uint8Array(length).fill(0);
150
- paddedBytes.set(bytes2);
162
+ paddedBytes.set(bytes);
151
163
  return paddedBytes;
152
164
  };
153
- var fixBytes = (bytes2, length) => padBytes(bytes2.slice(0, length), length);
154
-
155
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/errors.mjs
156
- init_env_shim();
157
- var DeserializingEmptyBufferError = class extends Error {
158
- constructor(serializer) {
159
- super(`Serializer [${serializer}] cannot deserialize empty buffers.`);
160
- __publicField(this, "name", "DeserializingEmptyBufferError");
165
+ var fixBytes = (bytes, length) => padBytes(bytes.length <= length ? bytes : bytes.slice(0, length), length);
166
+ function combineCodec(encoder, decoder, description) {
167
+ if (encoder.fixedSize !== decoder.fixedSize) {
168
+ throw new Error(
169
+ `Encoder and decoder must have the same fixed size, got [${encoder.fixedSize}] and [${decoder.fixedSize}].`
170
+ );
161
171
  }
162
- };
163
- var NotEnoughBytesError = class extends Error {
164
- constructor(serializer, expected, actual) {
165
- super(`Serializer [${serializer}] expected ${expected} bytes, got ${actual}.`);
166
- __publicField(this, "name", "NotEnoughBytesError");
172
+ if (encoder.maxSize !== decoder.maxSize) {
173
+ throw new Error(
174
+ `Encoder and decoder must have the same max size, got [${encoder.maxSize}] and [${decoder.maxSize}].`
175
+ );
167
176
  }
168
- };
169
- var ExpectedFixedSizeSerializerError = class extends Error {
170
- constructor(message) {
171
- message ?? (message = "Expected a fixed-size serializer, got a variable-size one.");
172
- super(message);
173
- __publicField(this, "name", "ExpectedFixedSizeSerializerError");
177
+ if (description === void 0 && encoder.description !== decoder.description) {
178
+ throw new Error(
179
+ `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.`
180
+ );
174
181
  }
175
- };
176
-
177
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/fixSerializer.mjs
178
- init_env_shim();
179
- function fixSerializer(serializer, fixedBytes, description) {
180
182
  return {
181
- description: description ?? `fixed(${fixedBytes}, ${serializer.description})`,
183
+ decode: decoder.decode,
184
+ description: description != null ? description : encoder.description,
185
+ encode: encoder.encode,
186
+ fixedSize: encoder.fixedSize,
187
+ maxSize: encoder.maxSize
188
+ };
189
+ }
190
+ function fixCodecHelper(data, fixedBytes, description) {
191
+ return {
192
+ description: description != null ? description : `fixed(${fixedBytes}, ${data.description})`,
182
193
  fixedSize: fixedBytes,
183
- maxSize: fixedBytes,
184
- serialize: (value) => fixBytes(serializer.serialize(value), fixedBytes),
185
- deserialize: (buffer, offset = 0) => {
186
- buffer = buffer.slice(offset, offset + fixedBytes);
187
- if (buffer.length < fixedBytes) {
188
- throw new NotEnoughBytesError("fixSerializer", fixedBytes, buffer.length);
194
+ maxSize: fixedBytes
195
+ };
196
+ }
197
+ function fixEncoder(encoder, fixedBytes, description) {
198
+ return {
199
+ ...fixCodecHelper(encoder, fixedBytes, description),
200
+ encode: (value) => fixBytes(encoder.encode(value), fixedBytes)
201
+ };
202
+ }
203
+ function fixDecoder(decoder, fixedBytes, description) {
204
+ return {
205
+ ...fixCodecHelper(decoder, fixedBytes, description),
206
+ decode: (bytes, offset = 0) => {
207
+ assertByteArrayHasEnoughBytesForCodec("fixCodec", fixedBytes, bytes, offset);
208
+ if (offset > 0 || bytes.length > fixedBytes) {
209
+ bytes = bytes.slice(offset, offset + fixedBytes);
189
210
  }
190
- if (serializer.fixedSize !== null) {
191
- buffer = fixBytes(buffer, serializer.fixedSize);
211
+ if (decoder.fixedSize !== null) {
212
+ bytes = fixBytes(bytes, decoder.fixedSize);
192
213
  }
193
- const [value] = serializer.deserialize(buffer, 0);
214
+ const [value] = decoder.decode(bytes, 0);
194
215
  return [value, offset + fixedBytes];
195
216
  }
196
217
  };
197
218
  }
198
-
199
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/mapSerializer.mjs
200
- init_env_shim();
201
- function mapSerializer(serializer, unmap, map) {
219
+ function mapEncoder(encoder, unmap) {
202
220
  return {
203
- description: serializer.description,
204
- fixedSize: serializer.fixedSize,
205
- maxSize: serializer.maxSize,
206
- serialize: (value) => serializer.serialize(unmap(value)),
207
- deserialize: (buffer, offset = 0) => {
208
- const [value, length] = serializer.deserialize(buffer, offset);
209
- return map ? [map(value, buffer, offset), length] : [value, length];
210
- }
221
+ description: encoder.description,
222
+ encode: (value) => encoder.encode(unmap(value)),
223
+ fixedSize: encoder.fixedSize,
224
+ maxSize: encoder.maxSize
225
+ };
226
+ }
227
+ function mapDecoder(decoder, map) {
228
+ return {
229
+ decode: (bytes, offset = 0) => {
230
+ const [value, length] = decoder.decode(bytes, offset);
231
+ return [map(value, bytes, offset), length];
232
+ },
233
+ description: decoder.description,
234
+ fixedSize: decoder.fixedSize,
235
+ maxSize: decoder.maxSize
211
236
  };
212
237
  }
213
238
 
214
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/index.mjs
215
- init_env_shim();
216
-
217
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseX.mjs
239
+ // ../codecs-strings/dist/index.browser.js
218
240
  init_env_shim();
219
241
 
220
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/errors.mjs
242
+ // ../codecs-numbers/dist/index.browser.js
221
243
  init_env_shim();
222
- var InvalidBaseStringError = class extends Error {
223
- constructor(value, base, cause) {
224
- const message = `Expected a string of base ${base}, got [${value}].`;
225
- super(message);
226
- __publicField(this, "name", "InvalidBaseStringError");
227
- this.cause = cause;
244
+ function assertNumberIsBetweenForCodec(codecDescription, min, max, value) {
245
+ if (value < min || value > max) {
246
+ throw new Error(
247
+ `Codec [${codecDescription}] expected number to be in the range [${min}, ${max}], got ${value}.`
248
+ );
228
249
  }
250
+ }
251
+ function sharedNumberFactory(input) {
252
+ var _a;
253
+ let littleEndian;
254
+ let defaultDescription = input.name;
255
+ if (input.size > 1) {
256
+ littleEndian = !("endian" in input.config) || input.config.endian === 0;
257
+ defaultDescription += littleEndian ? "(le)" : "(be)";
258
+ }
259
+ return {
260
+ description: (_a = input.config.description) != null ? _a : defaultDescription,
261
+ fixedSize: input.size,
262
+ littleEndian,
263
+ maxSize: input.size
264
+ };
265
+ }
266
+ function numberEncoderFactory(input) {
267
+ const codecData = sharedNumberFactory(input);
268
+ return {
269
+ description: codecData.description,
270
+ encode(value) {
271
+ if (input.range) {
272
+ assertNumberIsBetweenForCodec(input.name, input.range[0], input.range[1], value);
273
+ }
274
+ const arrayBuffer = new ArrayBuffer(input.size);
275
+ input.set(new DataView(arrayBuffer), value, codecData.littleEndian);
276
+ return new Uint8Array(arrayBuffer);
277
+ },
278
+ fixedSize: codecData.fixedSize,
279
+ maxSize: codecData.maxSize
280
+ };
281
+ }
282
+ function numberDecoderFactory(input) {
283
+ const codecData = sharedNumberFactory(input);
284
+ return {
285
+ decode(bytes, offset = 0) {
286
+ assertByteArrayIsNotEmptyForCodec(codecData.description, bytes, offset);
287
+ assertByteArrayHasEnoughBytesForCodec(codecData.description, input.size, bytes, offset);
288
+ const view = new DataView(toArrayBuffer(bytes, offset, input.size));
289
+ return [input.get(view, codecData.littleEndian), offset + input.size];
290
+ },
291
+ description: codecData.description,
292
+ fixedSize: codecData.fixedSize,
293
+ maxSize: codecData.maxSize
294
+ };
295
+ }
296
+ function toArrayBuffer(bytes, offset, length) {
297
+ const bytesOffset = bytes.byteOffset + (offset != null ? offset : 0);
298
+ const bytesLength = length != null ? length : bytes.byteLength;
299
+ return bytes.buffer.slice(bytesOffset, bytesOffset + bytesLength);
300
+ }
301
+ var getShortU16Encoder = (config = {}) => {
302
+ var _a;
303
+ return {
304
+ description: (_a = config.description) != null ? _a : "shortU16",
305
+ encode: (value) => {
306
+ assertNumberIsBetweenForCodec("shortU16", 0, 65535, value);
307
+ const bytes = [0];
308
+ for (let ii = 0; ; ii += 1) {
309
+ const alignedValue = value >> ii * 7;
310
+ if (alignedValue === 0) {
311
+ break;
312
+ }
313
+ const nextSevenBits = 127 & alignedValue;
314
+ bytes[ii] = nextSevenBits;
315
+ if (ii > 0) {
316
+ bytes[ii - 1] |= 128;
317
+ }
318
+ }
319
+ return new Uint8Array(bytes);
320
+ },
321
+ fixedSize: null,
322
+ maxSize: 3
323
+ };
229
324
  };
325
+ var getShortU16Decoder = (config = {}) => {
326
+ var _a;
327
+ return {
328
+ decode: (bytes, offset = 0) => {
329
+ let value = 0;
330
+ let byteCount = 0;
331
+ while (++byteCount) {
332
+ const byteIndex = byteCount - 1;
333
+ const currentByte = bytes[offset + byteIndex];
334
+ const nextSevenBits = 127 & currentByte;
335
+ value |= nextSevenBits << byteIndex * 7;
336
+ if ((currentByte & 128) === 0) {
337
+ break;
338
+ }
339
+ }
340
+ return [value, offset + byteCount];
341
+ },
342
+ description: (_a = config.description) != null ? _a : "shortU16",
343
+ fixedSize: null,
344
+ maxSize: 3
345
+ };
346
+ };
347
+ var getU32Encoder = (config = {}) => numberEncoderFactory({
348
+ config,
349
+ name: "u32",
350
+ range: [0, Number("0xffffffff")],
351
+ set: (view, value, le) => view.setUint32(0, value, le),
352
+ size: 4
353
+ });
354
+ var getU32Decoder = (config = {}) => numberDecoderFactory({
355
+ config,
356
+ get: (view, le) => view.getUint32(0, le),
357
+ name: "u32",
358
+ size: 4
359
+ });
360
+ var getU8Encoder = (config = {}) => numberEncoderFactory({
361
+ config,
362
+ name: "u8",
363
+ range: [0, Number("0xff")],
364
+ set: (view, value) => view.setUint8(0, value),
365
+ size: 1
366
+ });
367
+ var getU8Decoder = (config = {}) => numberDecoderFactory({
368
+ config,
369
+ get: (view) => view.getUint8(0),
370
+ name: "u8",
371
+ size: 1
372
+ });
230
373
 
231
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseX.mjs
232
- var baseX = (alphabet) => {
233
- const base = alphabet.length;
374
+ // ../codecs-strings/dist/index.browser.js
375
+ function assertValidBaseString(alphabet4, testValue, givenValue = testValue) {
376
+ if (!testValue.match(new RegExp(`^[${alphabet4}]*$`))) {
377
+ throw new Error(`Expected a string of base ${alphabet4.length}, got [${givenValue}].`);
378
+ }
379
+ }
380
+ var getBaseXEncoder = (alphabet4) => {
381
+ const base = alphabet4.length;
234
382
  const baseBigInt = BigInt(base);
235
383
  return {
236
384
  description: `base${base}`,
237
- fixedSize: null,
238
- maxSize: null,
239
- serialize(value) {
240
- if (!value.match(new RegExp(`^[${alphabet}]*$`))) {
241
- throw new InvalidBaseStringError(value, base);
242
- }
385
+ encode(value) {
386
+ assertValidBaseString(alphabet4, value);
243
387
  if (value === "")
244
388
  return new Uint8Array();
245
389
  const chars = [...value];
246
- let trailIndex = chars.findIndex((c) => c !== alphabet[0]);
390
+ let trailIndex = chars.findIndex((c) => c !== alphabet4[0]);
247
391
  trailIndex = trailIndex === -1 ? chars.length : trailIndex;
248
392
  const leadingZeroes = Array(trailIndex).fill(0);
249
393
  if (trailIndex === chars.length)
@@ -252,7 +396,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
252
396
  let base10Number = 0n;
253
397
  let baseXPower = 1n;
254
398
  for (let i = tailChars.length - 1; i >= 0; i -= 1) {
255
- base10Number += baseXPower * BigInt(alphabet.indexOf(tailChars[i]));
399
+ base10Number += baseXPower * BigInt(alphabet4.indexOf(tailChars[i]));
256
400
  baseXPower *= baseBigInt;
257
401
  }
258
402
  const tailBytes = [];
@@ -262,391 +406,149 @@ this.globalThis.solanaWeb3 = (function (exports) {
262
406
  }
263
407
  return Uint8Array.from(leadingZeroes.concat(tailBytes));
264
408
  },
265
- deserialize(buffer, offset = 0) {
266
- if (buffer.length === 0)
409
+ fixedSize: null,
410
+ maxSize: null
411
+ };
412
+ };
413
+ var getBaseXDecoder = (alphabet4) => {
414
+ const base = alphabet4.length;
415
+ const baseBigInt = BigInt(base);
416
+ return {
417
+ decode(rawBytes, offset = 0) {
418
+ const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);
419
+ if (bytes.length === 0)
267
420
  return ["", 0];
268
- const bytes2 = buffer.slice(offset);
269
- let trailIndex = bytes2.findIndex((n) => n !== 0);
270
- trailIndex = trailIndex === -1 ? bytes2.length : trailIndex;
271
- const leadingZeroes = alphabet[0].repeat(trailIndex);
272
- if (trailIndex === bytes2.length)
273
- return [leadingZeroes, buffer.length];
274
- let base10Number = bytes2.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
421
+ let trailIndex = bytes.findIndex((n) => n !== 0);
422
+ trailIndex = trailIndex === -1 ? bytes.length : trailIndex;
423
+ const leadingZeroes = alphabet4[0].repeat(trailIndex);
424
+ if (trailIndex === bytes.length)
425
+ return [leadingZeroes, rawBytes.length];
426
+ let base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
275
427
  const tailChars = [];
276
428
  while (base10Number > 0n) {
277
- tailChars.unshift(alphabet[Number(base10Number % baseBigInt)]);
429
+ tailChars.unshift(alphabet4[Number(base10Number % baseBigInt)]);
278
430
  base10Number /= baseBigInt;
279
431
  }
280
- return [leadingZeroes + tailChars.join(""), buffer.length];
281
- }
432
+ return [leadingZeroes + tailChars.join(""), rawBytes.length];
433
+ },
434
+ description: `base${base}`,
435
+ fixedSize: null,
436
+ maxSize: null
282
437
  };
283
438
  };
284
-
285
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/base58.mjs
286
- init_env_shim();
287
- var base58 = baseX("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
288
-
289
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/nullCharacters.mjs
290
- init_env_shim();
291
- var removeNullCharacters = (value) => (
292
- // eslint-disable-next-line no-control-regex
293
- value.replace(/\u0000/g, "")
294
- );
295
-
296
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/utf8.mjs
297
- init_env_shim();
298
- var utf8 = {
299
- description: "utf8",
300
- fixedSize: null,
301
- maxSize: null,
302
- serialize(value) {
303
- return new TextEncoder().encode(value);
304
- },
305
- deserialize(buffer, offset = 0) {
306
- const value = new TextDecoder().decode(buffer.slice(offset));
307
- return [removeNullCharacters(value), buffer.length];
439
+ var alphabet2 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
440
+ var getBase58Encoder = () => getBaseXEncoder(alphabet2);
441
+ var getBase58Decoder = () => getBaseXDecoder(alphabet2);
442
+ var getBase64Encoder = () => {
443
+ {
444
+ return {
445
+ description: `base64`,
446
+ encode(value) {
447
+ try {
448
+ const bytes = atob(value).split("").map((c) => c.charCodeAt(0));
449
+ return new Uint8Array(bytes);
450
+ } catch (e23) {
451
+ throw new Error(`Expected a string of base 64, got [${value}].`);
452
+ }
453
+ },
454
+ fixedSize: null,
455
+ maxSize: null
456
+ };
308
457
  }
309
458
  };
310
-
311
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/index.mjs
312
- init_env_shim();
313
-
314
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/common.mjs
315
- init_env_shim();
316
- var Endian;
317
- (function(Endian2) {
318
- Endian2["Little"] = "le";
319
- Endian2["Big"] = "be";
320
- })(Endian || (Endian = {}));
321
-
322
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/errors.mjs
323
- init_env_shim();
324
- var NumberOutOfRangeError = class extends RangeError {
325
- constructor(serializer, min, max, actual) {
326
- super(`Serializer [${serializer}] expected number to be between ${min} and ${max}, got ${actual}.`);
327
- __publicField(this, "name", "NumberOutOfRangeError");
459
+ var getBase64Decoder = () => {
460
+ {
461
+ return {
462
+ decode(bytes, offset = 0) {
463
+ const slice = bytes.slice(offset);
464
+ const value = btoa(String.fromCharCode(...slice));
465
+ return [value, bytes.length];
466
+ },
467
+ description: `base64`,
468
+ fixedSize: null,
469
+ maxSize: null
470
+ };
328
471
  }
329
472
  };
330
-
331
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/utils.mjs
332
- init_env_shim();
333
- function numberFactory(input) {
334
- let littleEndian;
335
- let defaultDescription = input.name;
336
- if (input.size > 1) {
337
- littleEndian = !("endian" in input.options) || input.options.endian === Endian.Little;
338
- defaultDescription += littleEndian ? "(le)" : "(be)";
339
- }
473
+ var removeNullCharacters = (value) => (
474
+ // eslint-disable-next-line no-control-regex
475
+ value.replace(/\u0000/g, "")
476
+ );
477
+ var e = globalThis.TextDecoder;
478
+ var o = globalThis.TextEncoder;
479
+ var getUtf8Encoder = () => {
480
+ let textEncoder;
340
481
  return {
341
- description: input.options.description ?? defaultDescription,
342
- fixedSize: input.size,
343
- maxSize: input.size,
344
- serialize(value) {
345
- if (input.range) {
346
- assertRange(input.name, input.range[0], input.range[1], value);
347
- }
348
- const buffer = new ArrayBuffer(input.size);
349
- input.set(new DataView(buffer), value, littleEndian);
350
- return new Uint8Array(buffer);
351
- },
352
- deserialize(bytes2, offset = 0) {
353
- const slice = bytes2.slice(offset, offset + input.size);
354
- assertEnoughBytes("i8", slice, input.size);
355
- const view = toDataView(slice);
356
- return [input.get(view, littleEndian), offset + input.size];
357
- }
482
+ description: "utf8",
483
+ encode: (value) => new Uint8Array((textEncoder || (textEncoder = new o())).encode(value)),
484
+ fixedSize: null,
485
+ maxSize: null
358
486
  };
359
- }
360
- var toArrayBuffer = (array2) => array2.buffer.slice(array2.byteOffset, array2.byteLength + array2.byteOffset);
361
- var toDataView = (array2) => new DataView(toArrayBuffer(array2));
362
- var assertRange = (serializer, min, max, value) => {
363
- if (value < min || value > max) {
364
- throw new NumberOutOfRangeError(serializer, min, max, value);
365
- }
366
487
  };
367
- var assertEnoughBytes = (serializer, bytes2, expected) => {
368
- if (bytes2.length === 0) {
369
- throw new DeserializingEmptyBufferError(serializer);
370
- }
371
- if (bytes2.length < expected) {
372
- throw new NotEnoughBytesError(serializer, expected, bytes2.length);
373
- }
374
- };
375
-
376
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u8.mjs
377
- init_env_shim();
378
- var u8 = (options = {}) => numberFactory({
379
- name: "u8",
380
- size: 1,
381
- range: [0, Number("0xff")],
382
- set: (view, value) => view.setUint8(0, Number(value)),
383
- get: (view) => view.getUint8(0),
384
- options
385
- });
386
-
387
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u32.mjs
388
- init_env_shim();
389
- var u32 = (options = {}) => numberFactory({
390
- name: "u32",
391
- size: 4,
392
- range: [0, Number("0xffffffff")],
393
- set: (view, value, le) => view.setUint32(0, Number(value), le),
394
- get: (view, le) => view.getUint32(0, le),
395
- options
396
- });
397
-
398
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/shortU16.mjs
399
- init_env_shim();
400
- var shortU16 = (options = {}) => ({
401
- description: options.description ?? "shortU16",
402
- fixedSize: null,
403
- maxSize: 3,
404
- serialize: (value) => {
405
- assertRange("shortU16", 0, 65535, value);
406
- const bytes2 = [0];
407
- for (let ii = 0; ; ii += 1) {
408
- const alignedValue = value >> ii * 7;
409
- if (alignedValue === 0) {
410
- break;
411
- }
412
- const nextSevenBits = 127 & alignedValue;
413
- bytes2[ii] = nextSevenBits;
414
- if (ii > 0) {
415
- bytes2[ii - 1] |= 128;
416
- }
417
- }
418
- return new Uint8Array(bytes2);
419
- },
420
- deserialize: (bytes2, offset = 0) => {
421
- let value = 0;
422
- let byteCount = 0;
423
- while (++byteCount) {
424
- const byteIndex = byteCount - 1;
425
- const currentByte = bytes2[offset + byteIndex];
426
- const nextSevenBits = 127 & currentByte;
427
- value |= nextSevenBits << byteIndex * 7;
428
- if ((currentByte & 128) === 0) {
429
- break;
430
- }
431
- }
432
- return [value, offset + byteCount];
433
- }
434
- });
435
-
436
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/array.mjs
437
- init_env_shim();
438
-
439
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/errors.mjs
440
- init_env_shim();
441
- var InvalidNumberOfItemsError = class extends Error {
442
- constructor(serializer, expected, actual) {
443
- super(`Expected [${serializer}] to have ${expected} items, got ${actual}.`);
444
- __publicField(this, "name", "InvalidNumberOfItemsError");
445
- }
446
- };
447
- var InvalidArrayLikeRemainderSizeError = class extends Error {
448
- constructor(remainderSize, itemSize) {
449
- 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.`);
450
- __publicField(this, "name", "InvalidArrayLikeRemainderSizeError");
451
- }
452
- };
453
- var UnrecognizedArrayLikeSerializerSizeError = class extends Error {
454
- constructor(size) {
455
- super(`Unrecognized array-like serializer size: ${JSON.stringify(size)}`);
456
- __publicField(this, "name", "UnrecognizedArrayLikeSerializerSizeError");
457
- }
458
- };
459
-
460
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/utils.mjs
461
- init_env_shim();
462
-
463
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/sumSerializerSizes.mjs
464
- init_env_shim();
465
- function sumSerializerSizes(sizes) {
466
- return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
467
- }
468
-
469
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/utils.mjs
470
- function getResolvedSize(size, childrenSizes, bytes2, offset) {
471
- if (typeof size === "number") {
472
- return [size, offset];
473
- }
474
- if (typeof size === "object") {
475
- return size.deserialize(bytes2, offset);
476
- }
477
- if (size === "remainder") {
478
- const childrenSize = sumSerializerSizes(childrenSizes);
479
- if (childrenSize === null) {
480
- throw new ExpectedFixedSizeSerializerError('Serializers of "remainder" size must have fixed-size items.');
481
- }
482
- const remainder = bytes2.slice(offset).length;
483
- if (remainder % childrenSize !== 0) {
484
- throw new InvalidArrayLikeRemainderSizeError(remainder, childrenSize);
485
- }
486
- return [remainder / childrenSize, offset];
487
- }
488
- throw new UnrecognizedArrayLikeSerializerSizeError(size);
489
- }
490
- function getSizeDescription(size) {
491
- return typeof size === "object" ? size.description : `${size}`;
492
- }
493
- function getSizeFromChildren(size, childrenSizes) {
494
- if (typeof size !== "number")
495
- return null;
496
- if (size === 0)
497
- return 0;
498
- const childrenSize = sumSerializerSizes(childrenSizes);
499
- return childrenSize === null ? null : childrenSize * size;
500
- }
501
- function getSizePrefix(size, realSize) {
502
- return typeof size === "object" ? size.serialize(realSize) : new Uint8Array();
503
- }
504
-
505
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/array.mjs
506
- function array(item, options = {}) {
507
- const size = options.size ?? u32();
508
- if (size === "remainder" && item.fixedSize === null) {
509
- throw new ExpectedFixedSizeSerializerError('Serializers of "remainder" size must have fixed-size items.');
510
- }
488
+ var getUtf8Decoder = () => {
489
+ let textDecoder;
511
490
  return {
512
- description: options.description ?? `array(${item.description}; ${getSizeDescription(size)})`,
513
- fixedSize: getSizeFromChildren(size, [item.fixedSize]),
514
- maxSize: getSizeFromChildren(size, [item.maxSize]),
515
- serialize: (value) => {
516
- if (typeof size === "number" && value.length !== size) {
517
- throw new InvalidNumberOfItemsError("array", size, value.length);
518
- }
519
- return mergeBytes([getSizePrefix(size, value.length), ...value.map((v) => item.serialize(v))]);
491
+ decode(bytes, offset = 0) {
492
+ const value = (textDecoder || (textDecoder = new e())).decode(bytes.slice(offset));
493
+ return [removeNullCharacters(value), bytes.length];
520
494
  },
521
- deserialize: (bytes2, offset = 0) => {
522
- if (typeof size === "object" && bytes2.slice(offset).length === 0) {
523
- return [[], offset];
524
- }
525
- const [resolvedSize, newOffset] = getResolvedSize(size, [item.fixedSize], bytes2, offset);
526
- offset = newOffset;
527
- const values = [];
528
- for (let i = 0; i < resolvedSize; i += 1) {
529
- const [value, newOffset2] = item.deserialize(bytes2, offset);
530
- values.push(value);
531
- offset = newOffset2;
532
- }
533
- return [values, offset];
534
- }
535
- };
536
- }
537
-
538
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/bytes.mjs
539
- init_env_shim();
540
- function bytes(options = {}) {
541
- const size = options.size ?? "variable";
542
- const description = options.description ?? `bytes(${getSizeDescription(size)})`;
543
- const byteSerializer = {
544
- description,
495
+ description: "utf8",
545
496
  fixedSize: null,
546
- maxSize: null,
547
- serialize: (value) => new Uint8Array(value),
548
- deserialize: (bytes2, offset = 0) => {
549
- const slice = bytes2.slice(offset);
550
- return [slice, offset + slice.length];
551
- }
497
+ maxSize: null
552
498
  };
499
+ };
500
+ var getStringEncoder = (config = {}) => {
501
+ var _a, _b, _c;
502
+ const size = (_a = config.size) != null ? _a : getU32Encoder();
503
+ const encoding = (_b = config.encoding) != null ? _b : getUtf8Encoder();
504
+ const description = (_c = config.description) != null ? _c : `string(${encoding.description}; ${getSizeDescription(size)})`;
553
505
  if (size === "variable") {
554
- return byteSerializer;
506
+ return { ...encoding, description };
555
507
  }
556
508
  if (typeof size === "number") {
557
- return fixSerializer(byteSerializer, size, description);
509
+ return fixEncoder(encoding, size, description);
558
510
  }
559
511
  return {
560
512
  description,
561
- fixedSize: null,
562
- maxSize: null,
563
- serialize: (value) => {
564
- const contentBytes = byteSerializer.serialize(value);
565
- const lengthBytes = size.serialize(contentBytes.length);
513
+ encode: (value) => {
514
+ const contentBytes = encoding.encode(value);
515
+ const lengthBytes = size.encode(contentBytes.length);
566
516
  return mergeBytes([lengthBytes, contentBytes]);
567
517
  },
568
- deserialize: (buffer, offset = 0) => {
569
- if (buffer.slice(offset).length === 0) {
570
- throw new DeserializingEmptyBufferError("bytes");
571
- }
572
- const [lengthBigInt, lengthOffset] = size.deserialize(buffer, offset);
573
- const length = Number(lengthBigInt);
574
- offset = lengthOffset;
575
- const contentBuffer = buffer.slice(offset, offset + length);
576
- if (contentBuffer.length < length) {
577
- throw new NotEnoughBytesError("bytes", length, contentBuffer.length);
578
- }
579
- const [value, contentOffset] = byteSerializer.deserialize(contentBuffer);
580
- offset += contentOffset;
581
- return [value, offset];
582
- }
518
+ fixedSize: null,
519
+ maxSize: null
583
520
  };
584
- }
585
-
586
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/string.mjs
587
- init_env_shim();
588
- function string(options = {}) {
589
- const size = options.size ?? u32();
590
- const encoding = options.encoding ?? utf8;
591
- const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
521
+ };
522
+ var getStringDecoder = (config = {}) => {
523
+ var _a, _b, _c;
524
+ const size = (_a = config.size) != null ? _a : getU32Decoder();
525
+ const encoding = (_b = config.encoding) != null ? _b : getUtf8Decoder();
526
+ const description = (_c = config.description) != null ? _c : `string(${encoding.description}; ${getSizeDescription(size)})`;
592
527
  if (size === "variable") {
593
- return {
594
- ...encoding,
595
- description
596
- };
528
+ return { ...encoding, description };
597
529
  }
598
530
  if (typeof size === "number") {
599
- return fixSerializer(encoding, size, description);
531
+ return fixDecoder(encoding, size, description);
600
532
  }
601
533
  return {
602
- description,
603
- fixedSize: null,
604
- maxSize: null,
605
- serialize: (value) => {
606
- const contentBytes = encoding.serialize(value);
607
- const lengthBytes = size.serialize(contentBytes.length);
608
- return mergeBytes([lengthBytes, contentBytes]);
609
- },
610
- deserialize: (buffer, offset = 0) => {
611
- if (buffer.slice(offset).length === 0) {
612
- throw new DeserializingEmptyBufferError("string");
613
- }
614
- const [lengthBigInt, lengthOffset] = size.deserialize(buffer, offset);
534
+ decode: (bytes, offset = 0) => {
535
+ assertByteArrayIsNotEmptyForCodec("string", bytes, offset);
536
+ const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);
615
537
  const length = Number(lengthBigInt);
616
538
  offset = lengthOffset;
617
- const contentBuffer = buffer.slice(offset, offset + length);
618
- if (contentBuffer.length < length) {
619
- throw new NotEnoughBytesError("string", length, contentBuffer.length);
620
- }
621
- const [value, contentOffset] = encoding.deserialize(contentBuffer);
539
+ const contentBytes = bytes.slice(offset, offset + length);
540
+ assertByteArrayHasEnoughBytesForCodec("string", length, contentBytes);
541
+ const [value, contentOffset] = encoding.decode(contentBytes);
622
542
  offset += contentOffset;
623
543
  return [value, offset];
624
- }
625
- };
626
- }
627
-
628
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/struct.mjs
629
- init_env_shim();
630
- function struct(fields, options = {}) {
631
- const fieldDescriptions = fields.map(([name, serializer]) => `${String(name)}: ${serializer.description}`).join(", ");
632
- return {
633
- description: options.description ?? `struct(${fieldDescriptions})`,
634
- fixedSize: sumSerializerSizes(fields.map(([, field]) => field.fixedSize)),
635
- maxSize: sumSerializerSizes(fields.map(([, field]) => field.maxSize)),
636
- serialize: (struct2) => {
637
- const fieldBytes = fields.map(([key, serializer]) => serializer.serialize(struct2[key]));
638
- return mergeBytes(fieldBytes);
639
544
  },
640
- deserialize: (bytes2, offset = 0) => {
641
- const struct2 = {};
642
- fields.forEach(([key, serializer]) => {
643
- const [value, newOffset] = serializer.deserialize(bytes2, offset);
644
- offset = newOffset;
645
- struct2[key] = value;
646
- });
647
- return [struct2, offset];
648
- }
545
+ description,
546
+ fixedSize: null,
547
+ maxSize: null
649
548
  };
549
+ };
550
+ function getSizeDescription(size) {
551
+ return typeof size === "object" ? size.description : `${size}`;
650
552
  }
651
553
 
652
554
  // ../assertions/dist/index.browser.js
@@ -681,14 +583,16 @@ this.globalThis.solanaWeb3 = (function (exports) {
681
583
  }
682
584
  }
683
585
  async function assertDigestCapabilityIsAvailable() {
586
+ var _a;
684
587
  assertIsSecureContext();
685
- if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.digest !== "function") {
588
+ if (typeof globalThis.crypto === "undefined" || typeof ((_a = globalThis.crypto.subtle) == null ? void 0 : _a.digest) !== "function") {
686
589
  throw new Error("No digest implementation could be found");
687
590
  }
688
591
  }
689
592
  async function assertKeyGenerationIsAvailable() {
593
+ var _a;
690
594
  assertIsSecureContext();
691
- if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.generateKey !== "function") {
595
+ if (typeof globalThis.crypto === "undefined" || typeof ((_a = globalThis.crypto.subtle) == null ? void 0 : _a.generateKey) !== "function") {
692
596
  throw new Error("No key generation implementation could be found");
693
597
  }
694
598
  if (!await isEd25519CurveSupported(globalThis.crypto.subtle)) {
@@ -698,70 +602,104 @@ this.globalThis.solanaWeb3 = (function (exports) {
698
602
  }
699
603
  }
700
604
  async function assertKeyExporterIsAvailable() {
605
+ var _a;
701
606
  assertIsSecureContext();
702
- if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.exportKey !== "function") {
607
+ if (typeof globalThis.crypto === "undefined" || typeof ((_a = globalThis.crypto.subtle) == null ? void 0 : _a.exportKey) !== "function") {
703
608
  throw new Error("No key export implementation could be found");
704
609
  }
705
610
  }
706
611
  async function assertSigningCapabilityIsAvailable() {
612
+ var _a;
707
613
  assertIsSecureContext();
708
- if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.sign !== "function") {
614
+ if (typeof globalThis.crypto === "undefined" || typeof ((_a = globalThis.crypto.subtle) == null ? void 0 : _a.sign) !== "function") {
709
615
  throw new Error("No signing implementation could be found");
710
616
  }
711
617
  }
712
618
  async function assertVerificationCapabilityIsAvailable() {
619
+ var _a;
713
620
  assertIsSecureContext();
714
- if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.verify !== "function") {
621
+ if (typeof globalThis.crypto === "undefined" || typeof ((_a = globalThis.crypto.subtle) == null ? void 0 : _a.verify) !== "function") {
715
622
  throw new Error("No signature verification implementation could be found");
716
623
  }
717
624
  }
718
- function isBase58EncodedAddress(putativeBase58EncodedAddress) {
625
+
626
+ // ../addresses/dist/index.browser.js
627
+ var memoizedBase58Encoder;
628
+ var memoizedBase58Decoder;
629
+ function getMemoizedBase58Encoder() {
630
+ if (!memoizedBase58Encoder)
631
+ memoizedBase58Encoder = getBase58Encoder();
632
+ return memoizedBase58Encoder;
633
+ }
634
+ function getMemoizedBase58Decoder() {
635
+ if (!memoizedBase58Decoder)
636
+ memoizedBase58Decoder = getBase58Decoder();
637
+ return memoizedBase58Decoder;
638
+ }
639
+ function isAddress(putativeAddress) {
719
640
  if (
720
641
  // Lowest address (32 bytes of zeroes)
721
- putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
722
- putativeBase58EncodedAddress.length > 44
642
+ putativeAddress.length < 32 || // Highest address (32 bytes of 255)
643
+ putativeAddress.length > 44
723
644
  ) {
724
645
  return false;
725
646
  }
726
- const bytes2 = base58.serialize(putativeBase58EncodedAddress);
727
- const numBytes = bytes2.byteLength;
647
+ const base58Encoder3 = getMemoizedBase58Encoder();
648
+ const bytes = base58Encoder3.encode(putativeAddress);
649
+ const numBytes = bytes.byteLength;
728
650
  if (numBytes !== 32) {
729
651
  return false;
730
652
  }
731
653
  return true;
732
654
  }
733
- function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) {
655
+ function assertIsAddress(putativeAddress) {
734
656
  try {
735
657
  if (
736
658
  // Lowest address (32 bytes of zeroes)
737
- putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
738
- putativeBase58EncodedAddress.length > 44
659
+ putativeAddress.length < 32 || // Highest address (32 bytes of 255)
660
+ putativeAddress.length > 44
739
661
  ) {
740
662
  throw new Error("Expected input string to decode to a byte array of length 32.");
741
663
  }
742
- const bytes2 = base58.serialize(putativeBase58EncodedAddress);
743
- const numBytes = bytes2.byteLength;
664
+ const base58Encoder3 = getMemoizedBase58Encoder();
665
+ const bytes = base58Encoder3.encode(putativeAddress);
666
+ const numBytes = bytes.byteLength;
744
667
  if (numBytes !== 32) {
745
668
  throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
746
669
  }
747
670
  } catch (e3) {
748
- throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
671
+ throw new Error(`\`${putativeAddress}\` is not a base-58 encoded address`, {
749
672
  cause: e3
750
673
  });
751
674
  }
752
675
  }
753
- function address(putativeBase58EncodedAddress) {
754
- assertIsBase58EncodedAddress(putativeBase58EncodedAddress);
755
- return putativeBase58EncodedAddress;
676
+ function address(putativeAddress) {
677
+ assertIsAddress(putativeAddress);
678
+ return putativeAddress;
679
+ }
680
+ function getAddressEncoder(config) {
681
+ var _a;
682
+ return mapEncoder(
683
+ getStringEncoder({
684
+ description: (_a = config == null ? void 0 : config.description) != null ? _a : "Address",
685
+ encoding: getMemoizedBase58Encoder(),
686
+ size: 32
687
+ }),
688
+ (putativeAddress) => address(putativeAddress)
689
+ );
756
690
  }
757
- function getBase58EncodedAddressCodec(config) {
758
- return string({
759
- description: config?.description ?? ("A 32-byte account address" ),
760
- encoding: base58,
691
+ function getAddressDecoder(config) {
692
+ var _a;
693
+ return getStringDecoder({
694
+ description: (_a = config == null ? void 0 : config.description) != null ? _a : "Address",
695
+ encoding: getMemoizedBase58Decoder(),
761
696
  size: 32
762
697
  });
763
698
  }
764
- function getBase58EncodedAddressComparator() {
699
+ function getAddressCodec(config) {
700
+ return combineCodec(getAddressEncoder(config), getAddressDecoder(config));
701
+ }
702
+ function getAddressComparator() {
765
703
  return new Intl.Collator("en", {
766
704
  caseFirst: "lower",
767
705
  ignorePunctuation: false,
@@ -845,17 +783,32 @@ this.globalThis.solanaWeb3 = (function (exports) {
845
783
  return hexString;
846
784
  }
847
785
  }
848
- function decompressPointBytes(bytes2) {
849
- const hexString = bytes2.reduce((acc, byte, ii) => `${byteToHex(ii === 31 ? byte & ~128 : byte)}${acc}`, "");
786
+ function decompressPointBytes(bytes) {
787
+ const hexString = bytes.reduce((acc, byte, ii) => `${byteToHex(ii === 31 ? byte & ~128 : byte)}${acc}`, "");
850
788
  const integerLiteralString = `0x${hexString}`;
851
789
  return BigInt(integerLiteralString);
852
790
  }
853
- async function compressedPointBytesAreOnCurve(bytes2) {
854
- if (bytes2.byteLength !== 32) {
791
+ async function compressedPointBytesAreOnCurve(bytes) {
792
+ if (bytes.byteLength !== 32) {
855
793
  return false;
856
794
  }
857
- const y = decompressPointBytes(bytes2);
858
- return pointIsOnCurve(y, bytes2[31]);
795
+ const y = decompressPointBytes(bytes);
796
+ return pointIsOnCurve(y, bytes[31]);
797
+ }
798
+ function isProgramDerivedAddress(value) {
799
+ return Array.isArray(value) && value.length === 2 && typeof value[0] === "string" && typeof value[1] === "number" && value[1] >= 0 && value[1] <= 255 && isAddress(value[0]);
800
+ }
801
+ function assertIsProgramDerivedAddress(value) {
802
+ const validFormat = Array.isArray(value) && value.length === 2 && typeof value[0] === "string" && typeof value[1] === "number";
803
+ if (!validFormat) {
804
+ throw new Error(
805
+ `Expected given program derived address to have the following format: [Address, ProgramDerivedAddressBump].`
806
+ );
807
+ }
808
+ if (value[1] < 0 || value[1] > 255) {
809
+ throw new Error(`Expected program derived address bump to be in the range [0, 255], got: ${value[1]}.`);
810
+ }
811
+ assertIsAddress(value[0]);
859
812
  }
860
813
  var MAX_SEED_LENGTH = 32;
861
814
  var MAX_SEEDS = 16;
@@ -892,15 +845,15 @@ this.globalThis.solanaWeb3 = (function (exports) {
892
845
  }
893
846
  let textEncoder;
894
847
  const seedBytes = seeds.reduce((acc, seed, ii) => {
895
- const bytes2 = typeof seed === "string" ? (textEncoder || (textEncoder = new TextEncoder())).encode(seed) : seed;
896
- if (bytes2.byteLength > MAX_SEED_LENGTH) {
848
+ const bytes = typeof seed === "string" ? (textEncoder || (textEncoder = new TextEncoder())).encode(seed) : seed;
849
+ if (bytes.byteLength > MAX_SEED_LENGTH) {
897
850
  throw new Error(`The seed at index ${ii} exceeds the maximum length of 32 bytes`);
898
851
  }
899
- acc.push(...bytes2);
852
+ acc.push(...bytes);
900
853
  return acc;
901
854
  }, []);
902
- const base58EncodedAddressCodec = getBase58EncodedAddressCodec();
903
- const programAddressBytes = base58EncodedAddressCodec.serialize(programAddress);
855
+ const base58EncodedAddressCodec = getAddressCodec();
856
+ const programAddressBytes = base58EncodedAddressCodec.encode(programAddress);
904
857
  const addressBytesBuffer = await crypto.subtle.digest(
905
858
  "SHA-256",
906
859
  new Uint8Array([...seedBytes, ...programAddressBytes, ...PDA_MARKER_BYTES])
@@ -909,19 +862,20 @@ this.globalThis.solanaWeb3 = (function (exports) {
909
862
  if (await compressedPointBytesAreOnCurve(addressBytes)) {
910
863
  throw new PointOnCurveError("Invalid seeds; point must fall off the Ed25519 curve");
911
864
  }
912
- return base58EncodedAddressCodec.deserialize(addressBytes)[0];
865
+ return base58EncodedAddressCodec.decode(addressBytes)[0];
913
866
  }
914
- async function getProgramDerivedAddress({ programAddress, seeds }) {
867
+ async function getProgramDerivedAddress({
868
+ programAddress,
869
+ seeds
870
+ }) {
915
871
  let bumpSeed = 255;
916
872
  while (bumpSeed > 0) {
917
873
  try {
918
- return {
919
- bumpSeed,
920
- pda: await createProgramDerivedAddress({
921
- programAddress,
922
- seeds: [...seeds, new Uint8Array([bumpSeed])]
923
- })
924
- };
874
+ const address2 = await createProgramDerivedAddress({
875
+ programAddress,
876
+ seeds: [...seeds, new Uint8Array([bumpSeed])]
877
+ });
878
+ return [address2, bumpSeed];
925
879
  } catch (e3) {
926
880
  if (e3 instanceof PointOnCurveError) {
927
881
  bumpSeed--;
@@ -932,26 +886,22 @@ this.globalThis.solanaWeb3 = (function (exports) {
932
886
  }
933
887
  throw new Error("Unable to find a viable program address bump seed");
934
888
  }
935
- async function createAddressWithSeed({
936
- baseAddress,
937
- programAddress,
938
- seed
939
- }) {
940
- const { serialize: serialize4, deserialize: deserialize2 } = getBase58EncodedAddressCodec();
889
+ async function createAddressWithSeed({ baseAddress, programAddress, seed }) {
890
+ const { encode: encode2, decode: decode2 } = getAddressCodec();
941
891
  const seedBytes = typeof seed === "string" ? new TextEncoder().encode(seed) : seed;
942
892
  if (seedBytes.byteLength > MAX_SEED_LENGTH) {
943
893
  throw new Error(`The seed exceeds the maximum length of 32 bytes`);
944
894
  }
945
- const programAddressBytes = serialize4(programAddress);
895
+ const programAddressBytes = encode2(programAddress);
946
896
  if (programAddressBytes.length >= PDA_MARKER_BYTES.length && programAddressBytes.slice(-PDA_MARKER_BYTES.length).every((byte, index) => byte === PDA_MARKER_BYTES[index])) {
947
897
  throw new Error(`programAddress cannot end with the PDA marker`);
948
898
  }
949
899
  const addressBytesBuffer = await crypto.subtle.digest(
950
900
  "SHA-256",
951
- new Uint8Array([...serialize4(baseAddress), ...seedBytes, ...programAddressBytes])
901
+ new Uint8Array([...encode2(baseAddress), ...seedBytes, ...programAddressBytes])
952
902
  );
953
903
  const addressBytes = new Uint8Array(addressBytesBuffer);
954
- return deserialize2(addressBytes)[0];
904
+ return decode2(addressBytes)[0];
955
905
  }
956
906
  async function getAddressFromPublicKey(publicKey) {
957
907
  await assertKeyExporterIsAvailable();
@@ -959,7 +909,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
959
909
  throw new Error("The `CryptoKey` must be an `Ed25519` public key");
960
910
  }
961
911
  const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
962
- const [base58EncodedAddress] = getBase58EncodedAddressCodec().deserialize(new Uint8Array(publicKeyBytes));
912
+ const [base58EncodedAddress] = getAddressDecoder().decode(new Uint8Array(publicKeyBytes));
963
913
  return base58EncodedAddress;
964
914
  }
965
915
 
@@ -1016,18 +966,344 @@ this.globalThis.solanaWeb3 = (function (exports) {
1016
966
  );
1017
967
  return keyPair;
1018
968
  }
969
+ var base58Encoder;
970
+ function assertIsSignature(putativeSignature) {
971
+ if (!base58Encoder)
972
+ base58Encoder = getBase58Encoder();
973
+ try {
974
+ if (
975
+ // Lowest value (64 bytes of zeroes)
976
+ putativeSignature.length < 64 || // Highest value (64 bytes of 255)
977
+ putativeSignature.length > 88
978
+ ) {
979
+ throw new Error("Expected input string to decode to a byte array of length 64.");
980
+ }
981
+ const bytes = base58Encoder.encode(putativeSignature);
982
+ const numBytes = bytes.byteLength;
983
+ if (numBytes !== 64) {
984
+ throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
985
+ }
986
+ } catch (e3) {
987
+ throw new Error(`\`${putativeSignature}\` is not a signature`, {
988
+ cause: e3
989
+ });
990
+ }
991
+ }
992
+ function isSignature(putativeSignature) {
993
+ if (!base58Encoder)
994
+ base58Encoder = getBase58Encoder();
995
+ if (
996
+ // Lowest value (64 bytes of zeroes)
997
+ putativeSignature.length < 64 || // Highest value (64 bytes of 255)
998
+ putativeSignature.length > 88
999
+ ) {
1000
+ return false;
1001
+ }
1002
+ const bytes = base58Encoder.encode(putativeSignature);
1003
+ const numBytes = bytes.byteLength;
1004
+ if (numBytes !== 64) {
1005
+ return false;
1006
+ }
1007
+ return true;
1008
+ }
1019
1009
  async function signBytes(key, data) {
1020
1010
  await assertSigningCapabilityIsAvailable();
1021
1011
  const signedData = await crypto.subtle.sign("Ed25519", key, data);
1022
1012
  return new Uint8Array(signedData);
1023
1013
  }
1024
- async function verifySignature(key, signature, data) {
1014
+ function signature(putativeSignature) {
1015
+ assertIsSignature(putativeSignature);
1016
+ return putativeSignature;
1017
+ }
1018
+ async function verifySignature(key, signature2, data) {
1025
1019
  await assertVerificationCapabilityIsAvailable();
1026
- return await crypto.subtle.verify("Ed25519", key, signature, data);
1020
+ return await crypto.subtle.verify("Ed25519", key, signature2, data);
1021
+ }
1022
+
1023
+ // ../rpc-types/dist/index.browser.js
1024
+ init_env_shim();
1025
+ function getCommitmentScore(commitment) {
1026
+ switch (commitment) {
1027
+ case "finalized":
1028
+ return 2;
1029
+ case "confirmed":
1030
+ return 1;
1031
+ case "processed":
1032
+ return 0;
1033
+ default:
1034
+ return ((_) => {
1035
+ throw new Error(`Unrecognized commitment \`${commitment}\`.`);
1036
+ })();
1037
+ }
1038
+ }
1039
+ function commitmentComparator(a, b) {
1040
+ if (a === b) {
1041
+ return 0;
1042
+ }
1043
+ return getCommitmentScore(a) < getCommitmentScore(b) ? -1 : 1;
1044
+ }
1045
+ var maxU64Value = 18446744073709551615n;
1046
+ function isLamports(putativeLamports) {
1047
+ return putativeLamports >= 0 && putativeLamports <= maxU64Value;
1048
+ }
1049
+ function assertIsLamports(putativeLamports) {
1050
+ if (putativeLamports < 0) {
1051
+ throw new Error("Input for 64-bit unsigned integer cannot be negative");
1052
+ }
1053
+ if (putativeLamports > maxU64Value) {
1054
+ throw new Error("Input number is too large to be represented as a 64-bit unsigned integer");
1055
+ }
1056
+ }
1057
+ function lamports(putativeLamports) {
1058
+ assertIsLamports(putativeLamports);
1059
+ return putativeLamports;
1060
+ }
1061
+ function isStringifiedBigInt(putativeBigInt) {
1062
+ try {
1063
+ BigInt(putativeBigInt);
1064
+ return true;
1065
+ } catch (_) {
1066
+ return false;
1067
+ }
1068
+ }
1069
+ function assertIsStringifiedBigInt(putativeBigInt) {
1070
+ try {
1071
+ BigInt(putativeBigInt);
1072
+ } catch (e3) {
1073
+ throw new Error(`\`${putativeBigInt}\` cannot be parsed as a BigInt`, {
1074
+ cause: e3
1075
+ });
1076
+ }
1077
+ }
1078
+ function stringifiedBigInt(putativeBigInt) {
1079
+ assertIsStringifiedBigInt(putativeBigInt);
1080
+ return putativeBigInt;
1081
+ }
1082
+ function isStringifiedNumber(putativeNumber) {
1083
+ return !Number.isNaN(Number(putativeNumber));
1084
+ }
1085
+ function assertIsStringifiedNumber(putativeNumber) {
1086
+ if (Number.isNaN(Number(putativeNumber))) {
1087
+ throw new Error(`\`${putativeNumber}\` cannot be parsed as a Number`);
1088
+ }
1089
+ }
1090
+ function stringifiedNumber(putativeNumber) {
1091
+ assertIsStringifiedNumber(putativeNumber);
1092
+ return putativeNumber;
1093
+ }
1094
+ function isUnixTimestamp(putativeTimestamp) {
1095
+ if (putativeTimestamp > 864e13 || putativeTimestamp < -864e13) {
1096
+ return false;
1097
+ }
1098
+ return true;
1099
+ }
1100
+ function assertIsUnixTimestamp(putativeTimestamp) {
1101
+ try {
1102
+ if (putativeTimestamp > 864e13 || putativeTimestamp < -864e13) {
1103
+ throw new Error("Expected input number to be in the range [-8.64e15, 8.64e15]");
1104
+ }
1105
+ } catch (e3) {
1106
+ throw new Error(`\`${putativeTimestamp}\` is not a timestamp`, {
1107
+ cause: e3
1108
+ });
1109
+ }
1110
+ }
1111
+ function unixTimestamp(putativeTimestamp) {
1112
+ assertIsUnixTimestamp(putativeTimestamp);
1113
+ return putativeTimestamp;
1027
1114
  }
1028
1115
 
1029
1116
  // ../transactions/dist/index.browser.js
1030
1117
  init_env_shim();
1118
+
1119
+ // ../codecs-data-structures/dist/index.browser.js
1120
+ init_env_shim();
1121
+ function sumCodecSizes(sizes) {
1122
+ return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
1123
+ }
1124
+ function decodeArrayLikeCodecSize(size, childrenSizes, bytes, offset) {
1125
+ if (typeof size === "number") {
1126
+ return [size, offset];
1127
+ }
1128
+ if (typeof size === "object") {
1129
+ return size.decode(bytes, offset);
1130
+ }
1131
+ if (size === "remainder") {
1132
+ const childrenSize = sumCodecSizes(childrenSizes);
1133
+ if (childrenSize === null) {
1134
+ throw new Error('Codecs of "remainder" size must have fixed-size items.');
1135
+ }
1136
+ const remainder = bytes.slice(offset).length;
1137
+ if (remainder % childrenSize !== 0) {
1138
+ throw new Error(
1139
+ `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.`
1140
+ );
1141
+ }
1142
+ return [remainder / childrenSize, offset];
1143
+ }
1144
+ throw new Error(`Unrecognized array-like codec size: ${JSON.stringify(size)}`);
1145
+ }
1146
+ function getArrayLikeCodecSizeDescription(size) {
1147
+ return typeof size === "object" ? size.description : `${size}`;
1148
+ }
1149
+ function getArrayLikeCodecSizeFromChildren(size, childrenSizes) {
1150
+ if (typeof size !== "number")
1151
+ return null;
1152
+ if (size === 0)
1153
+ return 0;
1154
+ const childrenSize = sumCodecSizes(childrenSizes);
1155
+ return childrenSize === null ? null : childrenSize * size;
1156
+ }
1157
+ function getArrayLikeCodecSizePrefix(size, realSize) {
1158
+ return typeof size === "object" ? size.encode(realSize) : new Uint8Array();
1159
+ }
1160
+ function assertValidNumberOfItemsForCodec(codecDescription, expected, actual) {
1161
+ if (expected !== actual) {
1162
+ throw new Error(`Expected [${codecDescription}] to have ${expected} items, got ${actual}.`);
1163
+ }
1164
+ }
1165
+ function arrayCodecHelper(item, size, description) {
1166
+ if (size === "remainder" && item.fixedSize === null) {
1167
+ throw new Error('Codecs of "remainder" size must have fixed-size items.');
1168
+ }
1169
+ return {
1170
+ description: description != null ? description : `array(${item.description}; ${getArrayLikeCodecSizeDescription(size)})`,
1171
+ fixedSize: getArrayLikeCodecSizeFromChildren(size, [item.fixedSize]),
1172
+ maxSize: getArrayLikeCodecSizeFromChildren(size, [item.maxSize])
1173
+ };
1174
+ }
1175
+ function getArrayEncoder(item, config = {}) {
1176
+ var _a;
1177
+ const size = (_a = config.size) != null ? _a : getU32Encoder();
1178
+ return {
1179
+ ...arrayCodecHelper(item, size, config.description),
1180
+ encode: (value) => {
1181
+ if (typeof size === "number") {
1182
+ assertValidNumberOfItemsForCodec("array", size, value.length);
1183
+ }
1184
+ return mergeBytes([getArrayLikeCodecSizePrefix(size, value.length), ...value.map((v) => item.encode(v))]);
1185
+ }
1186
+ };
1187
+ }
1188
+ function getArrayDecoder(item, config = {}) {
1189
+ var _a;
1190
+ const size = (_a = config.size) != null ? _a : getU32Decoder();
1191
+ return {
1192
+ ...arrayCodecHelper(item, size, config.description),
1193
+ decode: (bytes, offset = 0) => {
1194
+ if (typeof size === "object" && bytes.slice(offset).length === 0) {
1195
+ return [[], offset];
1196
+ }
1197
+ const [resolvedSize, newOffset] = decodeArrayLikeCodecSize(size, [item.fixedSize], bytes, offset);
1198
+ offset = newOffset;
1199
+ const values = [];
1200
+ for (let i = 0; i < resolvedSize; i += 1) {
1201
+ const [value, newOffset2] = item.decode(bytes, offset);
1202
+ values.push(value);
1203
+ offset = newOffset2;
1204
+ }
1205
+ return [values, offset];
1206
+ }
1207
+ };
1208
+ }
1209
+ function getBytesEncoder(config = {}) {
1210
+ var _a, _b;
1211
+ const size = (_a = config.size) != null ? _a : "variable";
1212
+ const sizeDescription = typeof size === "object" ? size.description : `${size}`;
1213
+ const description = (_b = config.description) != null ? _b : `bytes(${sizeDescription})`;
1214
+ const byteEncoder = {
1215
+ description,
1216
+ encode: (value) => value,
1217
+ fixedSize: null,
1218
+ maxSize: null
1219
+ };
1220
+ if (size === "variable") {
1221
+ return byteEncoder;
1222
+ }
1223
+ if (typeof size === "number") {
1224
+ return fixEncoder(byteEncoder, size, description);
1225
+ }
1226
+ return {
1227
+ ...byteEncoder,
1228
+ encode: (value) => {
1229
+ const contentBytes = byteEncoder.encode(value);
1230
+ const lengthBytes = size.encode(contentBytes.length);
1231
+ return mergeBytes([lengthBytes, contentBytes]);
1232
+ }
1233
+ };
1234
+ }
1235
+ function getBytesDecoder(config = {}) {
1236
+ var _a, _b;
1237
+ const size = (_a = config.size) != null ? _a : "variable";
1238
+ const sizeDescription = typeof size === "object" ? size.description : `${size}`;
1239
+ const description = (_b = config.description) != null ? _b : `bytes(${sizeDescription})`;
1240
+ const byteDecoder = {
1241
+ decode: (bytes, offset = 0) => {
1242
+ const slice = bytes.slice(offset);
1243
+ return [slice, offset + slice.length];
1244
+ },
1245
+ description,
1246
+ fixedSize: null,
1247
+ maxSize: null
1248
+ };
1249
+ if (size === "variable") {
1250
+ return byteDecoder;
1251
+ }
1252
+ if (typeof size === "number") {
1253
+ return fixDecoder(byteDecoder, size, description);
1254
+ }
1255
+ return {
1256
+ ...byteDecoder,
1257
+ decode: (bytes, offset = 0) => {
1258
+ assertByteArrayIsNotEmptyForCodec("bytes", bytes, offset);
1259
+ const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);
1260
+ const length = Number(lengthBigInt);
1261
+ offset = lengthOffset;
1262
+ const contentBytes = bytes.slice(offset, offset + length);
1263
+ assertByteArrayHasEnoughBytesForCodec("bytes", length, contentBytes);
1264
+ const [value, contentOffset] = byteDecoder.decode(contentBytes);
1265
+ offset += contentOffset;
1266
+ return [value, offset];
1267
+ }
1268
+ };
1269
+ }
1270
+ function structCodecHelper(fields, description) {
1271
+ const fieldDescriptions = fields.map(([name, codec]) => `${String(name)}: ${codec.description}`).join(", ");
1272
+ return {
1273
+ description: description != null ? description : `struct(${fieldDescriptions})`,
1274
+ fixedSize: sumCodecSizes(fields.map(([, field]) => field.fixedSize)),
1275
+ maxSize: sumCodecSizes(fields.map(([, field]) => field.maxSize))
1276
+ };
1277
+ }
1278
+ function getStructEncoder(fields, config = {}) {
1279
+ return {
1280
+ ...structCodecHelper(fields, config.description),
1281
+ encode: (struct) => {
1282
+ const fieldBytes = fields.map(([key, codec]) => codec.encode(struct[key]));
1283
+ return mergeBytes(fieldBytes);
1284
+ }
1285
+ };
1286
+ }
1287
+ function getStructDecoder(fields, config = {}) {
1288
+ return {
1289
+ ...structCodecHelper(fields, config.description),
1290
+ decode: (bytes, offset = 0) => {
1291
+ const struct = {};
1292
+ fields.forEach(([key, codec]) => {
1293
+ const [value, newOffset] = codec.decode(bytes, offset);
1294
+ offset = newOffset;
1295
+ struct[key] = value;
1296
+ });
1297
+ return [struct, offset];
1298
+ }
1299
+ };
1300
+ }
1301
+
1302
+ // ../functional/dist/index.browser.js
1303
+ init_env_shim();
1304
+ function pipe(init, ...fns) {
1305
+ return fns.reduce((acc, fn) => fn(acc), init);
1306
+ }
1031
1307
  function getUnsignedTransaction(transaction) {
1032
1308
  if ("signatures" in transaction) {
1033
1309
  const {
@@ -1040,7 +1316,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
1040
1316
  return transaction;
1041
1317
  }
1042
1318
  }
1319
+ var base58Encoder2;
1043
1320
  function assertIsBlockhash(putativeBlockhash) {
1321
+ if (!base58Encoder2)
1322
+ base58Encoder2 = getBase58Encoder();
1044
1323
  try {
1045
1324
  if (
1046
1325
  // Lowest value (32 bytes of zeroes)
@@ -1049,8 +1328,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
1049
1328
  ) {
1050
1329
  throw new Error("Expected input string to decode to a byte array of length 32.");
1051
1330
  }
1052
- const bytes3 = base58.serialize(putativeBlockhash);
1053
- const numBytes = bytes3.byteLength;
1331
+ const bytes = base58Encoder2.encode(putativeBlockhash);
1332
+ const numBytes = bytes.byteLength;
1054
1333
  if (numBytes !== 32) {
1055
1334
  throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
1056
1335
  }
@@ -1124,12 +1403,13 @@ this.globalThis.solanaWeb3 = (function (exports) {
1124
1403
  };
1125
1404
  }
1126
1405
  function isAdvanceNonceAccountInstruction(instruction) {
1406
+ var _a;
1127
1407
  return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
1128
1408
  instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts
1129
- instruction.accounts?.length === 3 && // First account is nonce account address
1409
+ ((_a = instruction.accounts) == null ? void 0 : _a.length) === 3 && // First account is nonce account address
1130
1410
  instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole2.WRITABLE && // Second account is recent blockhashes sysvar
1131
1411
  instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole2.READONLY && // Third account is nonce authority account
1132
- instruction.accounts[2].address != null && instruction.accounts[2].role === AccountRole2.READONLY_SIGNER;
1412
+ instruction.accounts[2].address != null && isSignerRole2(instruction.accounts[2].role);
1133
1413
  }
1134
1414
  function isAdvanceNonceAccountInstructionData(data) {
1135
1415
  return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
@@ -1137,21 +1417,38 @@ this.globalThis.solanaWeb3 = (function (exports) {
1137
1417
  function isDurableNonceTransaction(transaction) {
1138
1418
  return "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.nonce === "string" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]);
1139
1419
  }
1420
+ function isAdvanceNonceAccountInstructionForNonce(instruction, nonceAccountAddress, nonceAuthorityAddress) {
1421
+ return instruction.accounts[0].address === nonceAccountAddress && instruction.accounts[2].address === nonceAuthorityAddress;
1422
+ }
1140
1423
  function setTransactionLifetimeUsingDurableNonce({
1141
1424
  nonce,
1142
1425
  nonceAccountAddress,
1143
1426
  nonceAuthorityAddress
1144
1427
  }, transaction) {
1145
- const isAlreadyDurableNonceTransaction = isDurableNonceTransaction(transaction);
1146
- if (isAlreadyDurableNonceTransaction && transaction.lifetimeConstraint.nonce === nonce && transaction.instructions[0].accounts[0].address === nonceAccountAddress && transaction.instructions[0].accounts[2].address === nonceAuthorityAddress) {
1147
- return transaction;
1428
+ let newInstructions;
1429
+ const firstInstruction = transaction.instructions[0];
1430
+ if (firstInstruction && isAdvanceNonceAccountInstruction(firstInstruction)) {
1431
+ if (isAdvanceNonceAccountInstructionForNonce(firstInstruction, nonceAccountAddress, nonceAuthorityAddress)) {
1432
+ if (isDurableNonceTransaction(transaction) && transaction.lifetimeConstraint.nonce === nonce) {
1433
+ return transaction;
1434
+ } else {
1435
+ newInstructions = [firstInstruction, ...transaction.instructions.slice(1)];
1436
+ }
1437
+ } else {
1438
+ newInstructions = [
1439
+ createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
1440
+ ...transaction.instructions.slice(1)
1441
+ ];
1442
+ }
1443
+ } else {
1444
+ newInstructions = [
1445
+ createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
1446
+ ...transaction.instructions
1447
+ ];
1148
1448
  }
1149
1449
  const out = {
1150
1450
  ...getUnsignedTransaction(transaction),
1151
- instructions: [
1152
- createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
1153
- ...isAlreadyDurableNonceTransaction ? transaction.instructions.slice(1) : transaction.instructions
1154
- ],
1451
+ instructions: newInstructions,
1155
1452
  lifetimeConstraint: {
1156
1453
  nonce
1157
1454
  }
@@ -1187,7 +1484,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
1187
1484
  return out;
1188
1485
  }
1189
1486
  function upsert(addressMap, address2, update) {
1190
- addressMap[address2] = update(addressMap[address2] ?? { role: AccountRole2.READONLY });
1487
+ var _a;
1488
+ addressMap[address2] = update((_a = addressMap[address2]) != null ? _a : { role: AccountRole2.READONLY });
1191
1489
  }
1192
1490
  var TYPE = Symbol("AddressMapTypeProperty");
1193
1491
  function getAddressMapFromInstructions(feePayer, instructions) {
@@ -1238,7 +1536,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
1238
1536
  const shouldReplaceEntry = (
1239
1537
  // Consider using the new LOOKUP_TABLE if its address is different...
1240
1538
  entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
1241
- (addressComparator || (addressComparator = getBase58EncodedAddressComparator()))(
1539
+ (addressComparator || (addressComparator = getAddressComparator()))(
1242
1540
  accountMeta.lookupTableAddress,
1243
1541
  entry.lookupTableAddress
1244
1542
  ) < 0
@@ -1346,7 +1644,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
1346
1644
  if (leftIsWritable !== isWritableRole2(rightEntry.role)) {
1347
1645
  return leftIsWritable ? -1 : 1;
1348
1646
  }
1349
- addressComparator || (addressComparator = getBase58EncodedAddressComparator());
1647
+ addressComparator || (addressComparator = getAddressComparator());
1350
1648
  if (leftEntry[TYPE] === 1 && rightEntry[TYPE] === 1 && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
1351
1649
  return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
1352
1650
  } else {
@@ -1375,7 +1673,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
1375
1673
  entry.readableIndices.push(account.addressIndex);
1376
1674
  }
1377
1675
  }
1378
- return Object.keys(index).sort(getBase58EncodedAddressComparator()).map((lookupTableAddress) => ({
1676
+ return Object.keys(index).sort(getAddressComparator()).map((lookupTableAddress) => ({
1379
1677
  lookupTableAddress,
1380
1678
  ...index[lookupTableAddress]
1381
1679
  }));
@@ -1444,138 +1742,181 @@ this.globalThis.solanaWeb3 = (function (exports) {
1444
1742
  version: transaction.version
1445
1743
  };
1446
1744
  }
1447
- function getAddressTableLookupCodec() {
1448
- return struct(
1449
- [
1745
+ var lookupTableAddressDescription = "The address of the address lookup table account from which instruction addresses should be looked up" ;
1746
+ var writableIndicesDescription = "The indices of the accounts in the lookup table that should be loaded as writeable" ;
1747
+ var readableIndicesDescription = "The indices of the accounts in the lookup table that should be loaded as read-only" ;
1748
+ 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" ;
1749
+ var memoizedAddressTableLookupEncoder;
1750
+ function getAddressTableLookupEncoder() {
1751
+ if (!memoizedAddressTableLookupEncoder) {
1752
+ memoizedAddressTableLookupEncoder = getStructEncoder(
1450
1753
  [
1451
- "lookupTableAddress",
1452
- getBase58EncodedAddressCodec(
1453
- {
1454
- description: "The address of the address lookup table account from which instruction addresses should be looked up"
1455
- }
1456
- )
1754
+ ["lookupTableAddress", getAddressEncoder({ description: lookupTableAddressDescription })],
1755
+ [
1756
+ "writableIndices",
1757
+ getArrayEncoder(getU8Encoder(), {
1758
+ description: writableIndicesDescription,
1759
+ size: getShortU16Encoder()
1760
+ })
1761
+ ],
1762
+ [
1763
+ "readableIndices",
1764
+ getArrayEncoder(getU8Encoder(), {
1765
+ description: readableIndicesDescription,
1766
+ size: getShortU16Encoder()
1767
+ })
1768
+ ]
1457
1769
  ],
1770
+ { description: addressTableLookupDescription }
1771
+ );
1772
+ }
1773
+ return memoizedAddressTableLookupEncoder;
1774
+ }
1775
+ var memoizedAddressTableLookupDecoder;
1776
+ function getAddressTableLookupDecoder() {
1777
+ if (!memoizedAddressTableLookupDecoder) {
1778
+ memoizedAddressTableLookupDecoder = getStructDecoder(
1458
1779
  [
1459
- "writableIndices",
1460
- array(u8(), {
1461
- ...{
1462
- description: "The indices of the accounts in the lookup table that should be loaded as writeable"
1463
- } ,
1464
- size: shortU16()
1465
- })
1780
+ ["lookupTableAddress", getAddressDecoder({ description: lookupTableAddressDescription })],
1781
+ [
1782
+ "writableIndices",
1783
+ getArrayDecoder(getU8Decoder(), {
1784
+ description: writableIndicesDescription,
1785
+ size: getShortU16Decoder()
1786
+ })
1787
+ ],
1788
+ [
1789
+ "readableIndices",
1790
+ getArrayDecoder(getU8Decoder(), {
1791
+ description: readableIndicesDescription,
1792
+ size: getShortU16Decoder()
1793
+ })
1794
+ ]
1466
1795
  ],
1467
- [
1468
- "readableIndices",
1469
- array(u8(), {
1470
- ...{
1471
- description: "The indices of the accounts in the lookup table that should be loaded as read-only"
1472
- } ,
1473
- size: shortU16()
1474
- })
1475
- ]
1796
+ { description: addressTableLookupDescription }
1797
+ );
1798
+ }
1799
+ return memoizedAddressTableLookupDecoder;
1800
+ }
1801
+ var memoizedU8Encoder;
1802
+ function getMemoizedU8Encoder() {
1803
+ if (!memoizedU8Encoder)
1804
+ memoizedU8Encoder = getU8Encoder();
1805
+ return memoizedU8Encoder;
1806
+ }
1807
+ function getMemoizedU8EncoderDescription(description) {
1808
+ const encoder = getMemoizedU8Encoder();
1809
+ return {
1810
+ ...encoder,
1811
+ description: description != null ? description : encoder.description
1812
+ };
1813
+ }
1814
+ var memoizedU8Decoder;
1815
+ function getMemoizedU8Decoder() {
1816
+ if (!memoizedU8Decoder)
1817
+ memoizedU8Decoder = getU8Decoder();
1818
+ return memoizedU8Decoder;
1819
+ }
1820
+ function getMemoizedU8DecoderDescription(description) {
1821
+ const decoder = getMemoizedU8Decoder();
1822
+ return {
1823
+ ...decoder,
1824
+ description: description != null ? description : decoder.description
1825
+ };
1826
+ }
1827
+ var numSignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction" ;
1828
+ 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" ;
1829
+ var numReadonlyNonSignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable" ;
1830
+ var messageHeaderDescription = "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses" ;
1831
+ function getMessageHeaderEncoder() {
1832
+ return getStructEncoder(
1833
+ [
1834
+ ["numSignerAccounts", getMemoizedU8EncoderDescription(numSignerAccountsDescription)],
1835
+ ["numReadonlySignerAccounts", getMemoizedU8EncoderDescription(numReadonlySignerAccountsDescription)],
1836
+ ["numReadonlyNonSignerAccounts", getMemoizedU8EncoderDescription(numReadonlyNonSignerAccountsDescription)]
1476
1837
  ],
1477
1838
  {
1478
- 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"
1479
- }
1839
+ description: messageHeaderDescription
1840
+ }
1480
1841
  );
1481
1842
  }
1482
- function getMessageHeaderCodec() {
1483
- return struct(
1843
+ function getMessageHeaderDecoder() {
1844
+ return getStructDecoder(
1484
1845
  [
1485
- [
1486
- "numSignerAccounts",
1487
- u8(
1488
- {
1489
- description: "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction"
1490
- }
1491
- )
1492
- ],
1493
- [
1494
- "numReadonlySignerAccounts",
1495
- u8(
1496
- {
1497
- 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"
1498
- }
1499
- )
1500
- ],
1501
- [
1502
- "numReadonlyNonSignerAccounts",
1503
- u8(
1504
- {
1505
- description: "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable"
1506
- }
1507
- )
1508
- ]
1846
+ ["numSignerAccounts", getMemoizedU8DecoderDescription(numSignerAccountsDescription)],
1847
+ ["numReadonlySignerAccounts", getMemoizedU8DecoderDescription(numReadonlySignerAccountsDescription)],
1848
+ ["numReadonlyNonSignerAccounts", getMemoizedU8DecoderDescription(numReadonlyNonSignerAccountsDescription)]
1509
1849
  ],
1510
1850
  {
1511
- description: "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses"
1512
- }
1851
+ description: messageHeaderDescription
1852
+ }
1513
1853
  );
1514
1854
  }
1515
- function getInstructionCodec() {
1516
- return mapSerializer(
1517
- struct([
1518
- [
1519
- "programAddressIndex",
1520
- u8(
1521
- {
1522
- description: "The index of the program being called, according to the well-ordered accounts list for this transaction"
1523
- }
1524
- )
1525
- ],
1526
- [
1527
- "accountIndices",
1528
- array(
1529
- u8({
1530
- description: "The index of an account, according to the well-ordered accounts list for this transaction"
1531
- }),
1532
- {
1533
- 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" ,
1534
- size: shortU16()
1535
- }
1536
- )
1537
- ],
1538
- [
1539
- "data",
1540
- bytes({
1541
- description: "An optional buffer of data passed to the instruction" ,
1542
- size: shortU16()
1543
- })
1544
- ]
1545
- ]),
1546
- (value) => {
1547
- if (value.accountIndices !== void 0 && value.data !== void 0) {
1548
- return value;
1855
+ var programAddressIndexDescription = "The index of the program being called, according to the well-ordered accounts list for this transaction" ;
1856
+ var accountIndexDescription = "The index of an account, according to the well-ordered accounts list for this transaction" ;
1857
+ 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" ;
1858
+ var dataDescription = "An optional buffer of data passed to the instruction" ;
1859
+ var memoizedGetInstructionEncoder;
1860
+ function getInstructionEncoder() {
1861
+ if (!memoizedGetInstructionEncoder) {
1862
+ memoizedGetInstructionEncoder = mapEncoder(
1863
+ getStructEncoder([
1864
+ ["programAddressIndex", getU8Encoder({ description: programAddressIndexDescription })],
1865
+ [
1866
+ "accountIndices",
1867
+ getArrayEncoder(getU8Encoder({ description: accountIndexDescription }), {
1868
+ description: accountIndicesDescription,
1869
+ size: getShortU16Encoder()
1870
+ })
1871
+ ],
1872
+ ["data", getBytesEncoder({ description: dataDescription, size: getShortU16Encoder() })]
1873
+ ]),
1874
+ // Convert an instruction to have all fields defined
1875
+ (instruction) => {
1876
+ var _a, _b;
1877
+ if (instruction.accountIndices !== void 0 && instruction.data !== void 0) {
1878
+ return instruction;
1879
+ }
1880
+ return {
1881
+ ...instruction,
1882
+ accountIndices: (_a = instruction.accountIndices) != null ? _a : [],
1883
+ data: (_b = instruction.data) != null ? _b : new Uint8Array(0)
1884
+ };
1549
1885
  }
1550
- return {
1551
- ...value,
1552
- accountIndices: value.accountIndices ?? [],
1553
- data: value.data ?? new Uint8Array(0)
1554
- };
1555
- },
1556
- (value) => {
1557
- if (value.accountIndices.length && value.data.byteLength) {
1558
- return value;
1886
+ );
1887
+ }
1888
+ return memoizedGetInstructionEncoder;
1889
+ }
1890
+ var memoizedGetInstructionDecoder;
1891
+ function getInstructionDecoder() {
1892
+ if (!memoizedGetInstructionDecoder) {
1893
+ memoizedGetInstructionDecoder = mapDecoder(
1894
+ getStructDecoder([
1895
+ ["programAddressIndex", getU8Decoder({ description: programAddressIndexDescription })],
1896
+ [
1897
+ "accountIndices",
1898
+ getArrayDecoder(getU8Decoder({ description: accountIndexDescription }), {
1899
+ description: accountIndicesDescription,
1900
+ size: getShortU16Decoder()
1901
+ })
1902
+ ],
1903
+ ["data", getBytesDecoder({ description: dataDescription, size: getShortU16Decoder() })]
1904
+ ]),
1905
+ // Convert an instruction to exclude optional fields if they are empty
1906
+ (instruction) => {
1907
+ if (instruction.accountIndices.length && instruction.data.byteLength) {
1908
+ return instruction;
1909
+ }
1910
+ const { accountIndices, data, ...rest } = instruction;
1911
+ return {
1912
+ ...rest,
1913
+ ...accountIndices.length ? { accountIndices } : null,
1914
+ ...data.byteLength ? { data } : null
1915
+ };
1559
1916
  }
1560
- const { accountIndices, data, ...rest } = value;
1561
- return {
1562
- ...rest,
1563
- ...accountIndices.length ? { accountIndices } : null,
1564
- ...data.byteLength ? { data } : null
1565
- };
1566
- }
1567
- );
1568
- }
1569
- function getError(type, name) {
1570
- const functionSuffix = name + type[0].toUpperCase() + type.slice(1);
1571
- return new Error(
1572
- `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}`
1573
- );
1574
- }
1575
- function getUnimplementedDecoder(name) {
1576
- return () => {
1577
- throw getError("decoder", name);
1578
- };
1917
+ );
1918
+ }
1919
+ return memoizedGetInstructionDecoder;
1579
1920
  }
1580
1921
  var VERSION_FLAG_MASK = 128;
1581
1922
  var BASE_CONFIG = {
@@ -1583,8 +1924,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
1583
1924
  fixedSize: null,
1584
1925
  maxSize: 1
1585
1926
  };
1586
- function deserialize(bytes3, offset = 0) {
1587
- const firstByte = bytes3[offset];
1927
+ function decode(bytes, offset = 0) {
1928
+ const firstByte = bytes[offset];
1588
1929
  if ((firstByte & VERSION_FLAG_MASK) === 0) {
1589
1930
  return ["legacy", offset];
1590
1931
  } else {
@@ -1592,7 +1933,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
1592
1933
  return [version, offset + 1];
1593
1934
  }
1594
1935
  }
1595
- function serialize(value) {
1936
+ function encode(value) {
1596
1937
  if (value === "legacy") {
1597
1938
  return new Uint8Array();
1598
1939
  }
@@ -1601,98 +1942,346 @@ this.globalThis.solanaWeb3 = (function (exports) {
1601
1942
  }
1602
1943
  return new Uint8Array([value | VERSION_FLAG_MASK]);
1603
1944
  }
1604
- function getTransactionVersionCodec() {
1945
+ function getTransactionVersionDecoder() {
1605
1946
  return {
1606
1947
  ...BASE_CONFIG,
1607
- deserialize,
1608
- serialize
1948
+ decode
1609
1949
  };
1610
1950
  }
1611
- var BASE_CONFIG2 = {
1612
- description: "The wire format of a Solana transaction message" ,
1613
- fixedSize: null,
1614
- maxSize: null
1615
- };
1616
- function serialize2(compiledMessage) {
1617
- if (compiledMessage.version === "legacy") {
1618
- return struct(getPreludeStructSerializerTuple()).serialize(compiledMessage);
1619
- } else {
1620
- return mapSerializer(
1621
- struct([
1622
- ...getPreludeStructSerializerTuple(),
1623
- ["addressTableLookups", getAddressTableLookupsSerializer()]
1624
- ]),
1625
- (value) => {
1626
- if (value.version === "legacy") {
1627
- return value;
1628
- }
1629
- return {
1630
- ...value,
1631
- addressTableLookups: value.addressTableLookups ?? []
1632
- };
1951
+ function getTransactionVersionEncoder() {
1952
+ return {
1953
+ ...BASE_CONFIG,
1954
+ encode
1955
+ };
1956
+ }
1957
+ var staticAccountsDescription = "A compact-array of static account addresses belonging to this transaction" ;
1958
+ var lifetimeTokenDescription = "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" ;
1959
+ var instructionsDescription = "A compact-array of instructions belonging to this transaction" ;
1960
+ var addressTableLookupsDescription = "A compact array of address table lookups belonging to this transaction" ;
1961
+ function getCompiledMessageLegacyEncoder() {
1962
+ return getStructEncoder(getPreludeStructEncoderTuple());
1963
+ }
1964
+ function getCompiledMessageVersionedEncoder() {
1965
+ return mapEncoder(
1966
+ getStructEncoder([
1967
+ ...getPreludeStructEncoderTuple(),
1968
+ ["addressTableLookups", getAddressTableLookupArrayEncoder()]
1969
+ ]),
1970
+ (value) => {
1971
+ var _a;
1972
+ if (value.version === "legacy") {
1973
+ return value;
1633
1974
  }
1634
- ).serialize(compiledMessage);
1635
- }
1975
+ return {
1976
+ ...value,
1977
+ addressTableLookups: (_a = value.addressTableLookups) != null ? _a : []
1978
+ };
1979
+ }
1980
+ );
1636
1981
  }
1637
- function getPreludeStructSerializerTuple() {
1982
+ function getPreludeStructEncoderTuple() {
1638
1983
  return [
1639
- ["version", getTransactionVersionCodec()],
1640
- ["header", getMessageHeaderCodec()],
1984
+ ["version", getTransactionVersionEncoder()],
1985
+ ["header", getMessageHeaderEncoder()],
1641
1986
  [
1642
1987
  "staticAccounts",
1643
- array(getBase58EncodedAddressCodec(), {
1644
- description: "A compact-array of static account addresses belonging to this transaction" ,
1645
- size: shortU16()
1988
+ getArrayEncoder(getAddressEncoder(), {
1989
+ description: staticAccountsDescription,
1990
+ size: getShortU16Encoder()
1646
1991
  })
1647
1992
  ],
1648
1993
  [
1649
1994
  "lifetimeToken",
1650
- string({
1651
- description: "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" ,
1652
- encoding: base58,
1995
+ getStringEncoder({
1996
+ description: lifetimeTokenDescription,
1997
+ encoding: getBase58Encoder(),
1653
1998
  size: 32
1654
1999
  })
1655
2000
  ],
1656
2001
  [
1657
2002
  "instructions",
1658
- array(getInstructionCodec(), {
1659
- description: "A compact-array of instructions belonging to this transaction" ,
1660
- size: shortU16()
2003
+ getArrayEncoder(getInstructionEncoder(), {
2004
+ description: instructionsDescription,
2005
+ size: getShortU16Encoder()
1661
2006
  })
1662
2007
  ]
1663
2008
  ];
1664
2009
  }
1665
- function getAddressTableLookupsSerializer() {
1666
- return array(getAddressTableLookupCodec(), {
1667
- ...{ description: "A compact array of address table lookups belonging to this transaction" } ,
1668
- size: shortU16()
2010
+ function getPreludeStructDecoderTuple() {
2011
+ return [
2012
+ ["version", getTransactionVersionDecoder()],
2013
+ ["header", getMessageHeaderDecoder()],
2014
+ [
2015
+ "staticAccounts",
2016
+ getArrayDecoder(getAddressDecoder(), {
2017
+ description: staticAccountsDescription,
2018
+ size: getShortU16Decoder()
2019
+ })
2020
+ ],
2021
+ [
2022
+ "lifetimeToken",
2023
+ getStringDecoder({
2024
+ description: lifetimeTokenDescription,
2025
+ encoding: getBase58Decoder(),
2026
+ size: 32
2027
+ })
2028
+ ],
2029
+ [
2030
+ "instructions",
2031
+ getArrayDecoder(getInstructionDecoder(), {
2032
+ description: instructionsDescription,
2033
+ size: getShortU16Decoder()
2034
+ })
2035
+ ],
2036
+ ["addressTableLookups", getAddressTableLookupArrayDecoder()]
2037
+ ];
2038
+ }
2039
+ function getAddressTableLookupArrayEncoder() {
2040
+ return getArrayEncoder(getAddressTableLookupEncoder(), {
2041
+ description: addressTableLookupsDescription,
2042
+ size: getShortU16Encoder()
2043
+ });
2044
+ }
2045
+ function getAddressTableLookupArrayDecoder() {
2046
+ return getArrayDecoder(getAddressTableLookupDecoder(), {
2047
+ description: addressTableLookupsDescription,
2048
+ size: getShortU16Decoder()
1669
2049
  });
1670
2050
  }
2051
+ var messageDescription = "The wire format of a Solana transaction message" ;
1671
2052
  function getCompiledMessageEncoder() {
1672
2053
  return {
1673
- ...BASE_CONFIG2,
1674
- deserialize: getUnimplementedDecoder("CompiledMessage"),
1675
- serialize: serialize2
2054
+ description: messageDescription,
2055
+ encode: (compiledMessage) => {
2056
+ if (compiledMessage.version === "legacy") {
2057
+ return getCompiledMessageLegacyEncoder().encode(compiledMessage);
2058
+ } else {
2059
+ return getCompiledMessageVersionedEncoder().encode(compiledMessage);
2060
+ }
2061
+ },
2062
+ fixedSize: null,
2063
+ maxSize: null
1676
2064
  };
1677
2065
  }
1678
- async function getCompiledMessageSignature(message, secretKey) {
1679
- const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
1680
- const signature = await signBytes(secretKey, wireMessageBytes);
1681
- return signature;
2066
+ function getCompiledMessageDecoder() {
2067
+ return mapDecoder(
2068
+ getStructDecoder(getPreludeStructDecoderTuple(), {
2069
+ description: messageDescription
2070
+ }),
2071
+ ({ addressTableLookups, ...restOfMessage }) => {
2072
+ if (restOfMessage.version === "legacy" || !(addressTableLookups == null ? void 0 : addressTableLookups.length)) {
2073
+ return restOfMessage;
2074
+ }
2075
+ return { ...restOfMessage, addressTableLookups };
2076
+ }
2077
+ );
1682
2078
  }
1683
- async function signTransaction(keyPairs, transaction) {
2079
+ function getCompiledMessageCodec() {
2080
+ return combineCodec(getCompiledMessageEncoder(), getCompiledMessageDecoder());
2081
+ }
2082
+ function getCompiledTransaction(transaction) {
2083
+ var _a;
2084
+ const compiledMessage = compileMessage(transaction);
2085
+ let signatures;
2086
+ if ("signatures" in transaction) {
2087
+ signatures = [];
2088
+ for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
2089
+ signatures[ii] = (_a = transaction.signatures[compiledMessage.staticAccounts[ii]]) != null ? _a : new Uint8Array(Array(64).fill(0));
2090
+ }
2091
+ } else {
2092
+ signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
2093
+ }
2094
+ return {
2095
+ compiledMessage,
2096
+ signatures
2097
+ };
2098
+ }
2099
+ function getAccountMetas(message) {
2100
+ const { header } = message;
2101
+ const numWritableSignerAccounts = header.numSignerAccounts - header.numReadonlySignerAccounts;
2102
+ const numWritableNonSignerAccounts = message.staticAccounts.length - header.numSignerAccounts - header.numReadonlyNonSignerAccounts;
2103
+ const accountMetas = [];
2104
+ let accountIndex = 0;
2105
+ for (let i = 0; i < numWritableSignerAccounts; i++) {
2106
+ accountMetas.push({
2107
+ address: message.staticAccounts[accountIndex],
2108
+ role: AccountRole2.WRITABLE_SIGNER
2109
+ });
2110
+ accountIndex++;
2111
+ }
2112
+ for (let i = 0; i < header.numReadonlySignerAccounts; i++) {
2113
+ accountMetas.push({
2114
+ address: message.staticAccounts[accountIndex],
2115
+ role: AccountRole2.READONLY_SIGNER
2116
+ });
2117
+ accountIndex++;
2118
+ }
2119
+ for (let i = 0; i < numWritableNonSignerAccounts; i++) {
2120
+ accountMetas.push({
2121
+ address: message.staticAccounts[accountIndex],
2122
+ role: AccountRole2.WRITABLE
2123
+ });
2124
+ accountIndex++;
2125
+ }
2126
+ for (let i = 0; i < header.numReadonlyNonSignerAccounts; i++) {
2127
+ accountMetas.push({
2128
+ address: message.staticAccounts[accountIndex],
2129
+ role: AccountRole2.READONLY
2130
+ });
2131
+ accountIndex++;
2132
+ }
2133
+ return accountMetas;
2134
+ }
2135
+ function convertInstruction(instruction, accountMetas) {
2136
+ var _a, _b;
2137
+ const programAddress = (_a = accountMetas[instruction.programAddressIndex]) == null ? void 0 : _a.address;
2138
+ if (!programAddress) {
2139
+ throw new Error(`Could not find program address at index ${instruction.programAddressIndex}`);
2140
+ }
2141
+ const accounts = (_b = instruction.accountIndices) == null ? void 0 : _b.map((accountIndex) => accountMetas[accountIndex]);
2142
+ const { data } = instruction;
2143
+ return {
2144
+ programAddress,
2145
+ ...accounts && accounts.length ? { accounts } : {},
2146
+ ...data && data.length ? { data } : {}
2147
+ };
2148
+ }
2149
+ function getLifetimeConstraint(messageLifetimeToken, firstInstruction, lastValidBlockHeight) {
2150
+ if (!firstInstruction || !isAdvanceNonceAccountInstruction(firstInstruction)) {
2151
+ return {
2152
+ blockhash: messageLifetimeToken,
2153
+ lastValidBlockHeight: lastValidBlockHeight != null ? lastValidBlockHeight : 2n ** 64n - 1n
2154
+ // U64 MAX
2155
+ };
2156
+ } else {
2157
+ const nonceAccountAddress = firstInstruction.accounts[0].address;
2158
+ assertIsAddress(nonceAccountAddress);
2159
+ const nonceAuthorityAddress = firstInstruction.accounts[2].address;
2160
+ assertIsAddress(nonceAuthorityAddress);
2161
+ return {
2162
+ nonce: messageLifetimeToken,
2163
+ nonceAccountAddress,
2164
+ nonceAuthorityAddress
2165
+ };
2166
+ }
2167
+ }
2168
+ function convertSignatures(compiledTransaction) {
2169
+ const {
2170
+ compiledMessage: { staticAccounts },
2171
+ signatures
2172
+ } = compiledTransaction;
2173
+ return signatures.reduce((acc, sig, index) => {
2174
+ const allZeros = sig.every((byte) => byte === 0);
2175
+ if (allZeros)
2176
+ return acc;
2177
+ const address2 = staticAccounts[index];
2178
+ return { ...acc, [address2]: sig };
2179
+ }, {});
2180
+ }
2181
+ function decompileTransaction(compiledTransaction, lastValidBlockHeight) {
2182
+ const { compiledMessage } = compiledTransaction;
2183
+ if ("addressTableLookups" in compiledMessage && compiledMessage.addressTableLookups.length > 0) {
2184
+ throw new Error("Cannot convert transaction with addressTableLookups");
2185
+ }
2186
+ const feePayer = compiledMessage.staticAccounts[0];
2187
+ if (!feePayer)
2188
+ throw new Error("No fee payer set in CompiledTransaction");
2189
+ const accountMetas = getAccountMetas(compiledMessage);
2190
+ const instructions = compiledMessage.instructions.map(
2191
+ (compiledInstruction) => convertInstruction(compiledInstruction, accountMetas)
2192
+ );
2193
+ const firstInstruction = instructions[0];
2194
+ const lifetimeConstraint = getLifetimeConstraint(
2195
+ compiledMessage.lifetimeToken,
2196
+ firstInstruction,
2197
+ lastValidBlockHeight
2198
+ );
2199
+ const signatures = convertSignatures(compiledTransaction);
2200
+ return pipe(
2201
+ createTransaction({ version: compiledMessage.version }),
2202
+ (tx) => setTransactionFeePayer(feePayer, tx),
2203
+ (tx) => instructions.reduce((acc, instruction) => {
2204
+ return appendTransactionInstruction(instruction, acc);
2205
+ }, tx),
2206
+ (tx) => "blockhash" in lifetimeConstraint ? setTransactionLifetimeUsingBlockhash(lifetimeConstraint, tx) : setTransactionLifetimeUsingDurableNonce(lifetimeConstraint, tx),
2207
+ (tx) => compiledTransaction.signatures.length ? { ...tx, signatures } : tx
2208
+ );
2209
+ }
2210
+ var signaturesDescription = "A compact array of 64-byte, base-64 encoded Ed25519 signatures" ;
2211
+ var transactionDescription = "The wire format of a Solana transaction" ;
2212
+ function getCompiledTransactionEncoder() {
2213
+ return getStructEncoder(
2214
+ [
2215
+ [
2216
+ "signatures",
2217
+ getArrayEncoder(getBytesEncoder({ size: 64 }), {
2218
+ description: signaturesDescription,
2219
+ size: getShortU16Encoder()
2220
+ })
2221
+ ],
2222
+ ["compiledMessage", getCompiledMessageEncoder()]
2223
+ ],
2224
+ {
2225
+ description: transactionDescription
2226
+ }
2227
+ );
2228
+ }
2229
+ function getSignatureDecoder() {
2230
+ return mapDecoder(getBytesDecoder({ size: 64 }), (bytes) => bytes);
2231
+ }
2232
+ function getCompiledTransactionDecoder() {
2233
+ return getStructDecoder(
2234
+ [
2235
+ [
2236
+ "signatures",
2237
+ getArrayDecoder(getSignatureDecoder(), {
2238
+ description: signaturesDescription,
2239
+ size: getShortU16Decoder()
2240
+ })
2241
+ ],
2242
+ ["compiledMessage", getCompiledMessageDecoder()]
2243
+ ],
2244
+ {
2245
+ description: transactionDescription
2246
+ }
2247
+ );
2248
+ }
2249
+ function getTransactionEncoder() {
2250
+ return mapEncoder(getCompiledTransactionEncoder(), getCompiledTransaction);
2251
+ }
2252
+ function getTransactionDecoder(lastValidBlockHeight) {
2253
+ return mapDecoder(
2254
+ getCompiledTransactionDecoder(),
2255
+ (compiledTransaction) => decompileTransaction(compiledTransaction, lastValidBlockHeight)
2256
+ );
2257
+ }
2258
+ function getTransactionCodec(lastValidBlockHeight) {
2259
+ return combineCodec(getTransactionEncoder(), getTransactionDecoder(lastValidBlockHeight));
2260
+ }
2261
+ var base58Decoder;
2262
+ function getSignatureFromTransaction(transaction) {
2263
+ if (!base58Decoder)
2264
+ base58Decoder = getBase58Decoder();
2265
+ const signatureBytes = transaction.signatures[transaction.feePayer];
2266
+ if (!signatureBytes) {
2267
+ throw new Error(
2268
+ "Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
2269
+ );
2270
+ }
2271
+ const transactionSignature = base58Decoder.decode(signatureBytes)[0];
2272
+ return transactionSignature;
2273
+ }
2274
+ async function partiallySignTransaction(keyPairs, transaction) {
1684
2275
  const compiledMessage = compileMessage(transaction);
1685
2276
  const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
2277
+ const wireMessageBytes = getCompiledMessageEncoder().encode(compiledMessage);
1686
2278
  const publicKeySignaturePairs = await Promise.all(
1687
2279
  keyPairs.map(
1688
- (keyPair) => Promise.all([
1689
- getAddressFromPublicKey(keyPair.publicKey),
1690
- getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
1691
- ])
2280
+ (keyPair) => Promise.all([getAddressFromPublicKey(keyPair.publicKey), signBytes(keyPair.privateKey, wireMessageBytes)])
1692
2281
  )
1693
2282
  );
1694
- for (const [signerPublicKey, signature] of publicKeySignaturePairs) {
1695
- nextSignatures[signerPublicKey] = signature;
2283
+ for (const [signerPublicKey, signature2] of publicKeySignaturePairs) {
2284
+ nextSignatures[signerPublicKey] = signature2;
1696
2285
  }
1697
2286
  const out = {
1698
2287
  ...transaction,
@@ -1701,63 +2290,198 @@ this.globalThis.solanaWeb3 = (function (exports) {
1701
2290
  Object.freeze(out);
1702
2291
  return out;
1703
2292
  }
1704
- function getCompiledTransaction(transaction) {
1705
- const compiledMessage = compileMessage(transaction);
1706
- let signatures;
1707
- if ("signatures" in transaction) {
1708
- signatures = [];
1709
- for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
1710
- signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
2293
+ async function signTransaction(keyPairs, transaction) {
2294
+ const out = await partiallySignTransaction(keyPairs, transaction);
2295
+ assertTransactionIsFullySigned(out);
2296
+ Object.freeze(out);
2297
+ return out;
2298
+ }
2299
+ function assertTransactionIsFullySigned(transaction) {
2300
+ const signerAddressesFromInstructions = transaction.instructions.flatMap((i) => {
2301
+ var _a, _b;
2302
+ return (_b = (_a = i.accounts) == null ? void 0 : _a.filter((a) => isSignerRole2(a.role))) != null ? _b : [];
2303
+ }).map((a) => a.address);
2304
+ const requiredSigners = /* @__PURE__ */ new Set([transaction.feePayer, ...signerAddressesFromInstructions]);
2305
+ requiredSigners.forEach((address2) => {
2306
+ if (!transaction.signatures[address2]) {
2307
+ throw new Error(`Transaction is missing signature for address \`${address2}\``);
1711
2308
  }
1712
- } else {
1713
- signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
2309
+ });
2310
+ }
2311
+ function getBase64EncodedWireTransaction(transaction) {
2312
+ const wireTransactionBytes = getTransactionEncoder().encode(transaction);
2313
+ return getBase64Decoder().decode(wireTransactionBytes)[0];
2314
+ }
2315
+
2316
+ // src/airdrop.ts
2317
+ init_env_shim();
2318
+
2319
+ // src/airdrop-confirmer.ts
2320
+ init_env_shim();
2321
+
2322
+ // src/transaction-confirmation-strategy-racer.ts
2323
+ init_env_shim();
2324
+ async function raceStrategies(signature2, config, getSpecificStrategiesForRace) {
2325
+ const { abortSignal: callerAbortSignal, commitment, getRecentSignatureConfirmationPromise } = config;
2326
+ callerAbortSignal == null ? void 0 : callerAbortSignal.throwIfAborted();
2327
+ const abortController = new AbortController();
2328
+ if (callerAbortSignal) {
2329
+ const handleAbort = () => {
2330
+ abortController.abort();
2331
+ };
2332
+ callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
1714
2333
  }
1715
- return {
1716
- compiledMessage,
1717
- signatures
2334
+ try {
2335
+ const specificStrategies = getSpecificStrategiesForRace({
2336
+ ...config,
2337
+ abortSignal: abortController.signal
2338
+ });
2339
+ return await Promise.race([
2340
+ getRecentSignatureConfirmationPromise({
2341
+ abortSignal: abortController.signal,
2342
+ commitment,
2343
+ signature: signature2
2344
+ }),
2345
+ ...specificStrategies
2346
+ ]);
2347
+ } finally {
2348
+ abortController.abort();
2349
+ }
2350
+ }
2351
+
2352
+ // src/transaction-confirmation-strategy-recent-signature.ts
2353
+ init_env_shim();
2354
+ function createRecentSignatureConfirmationPromiseFactory(rpc, rpcSubscriptions) {
2355
+ return async function getRecentSignatureConfirmationPromise({
2356
+ abortSignal: callerAbortSignal,
2357
+ commitment,
2358
+ signature: signature2
2359
+ }) {
2360
+ const abortController = new AbortController();
2361
+ function handleAbort() {
2362
+ abortController.abort();
2363
+ }
2364
+ callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
2365
+ const signatureStatusNotifications = await rpcSubscriptions.signatureNotifications(signature2, { commitment }).subscribe({ abortSignal: abortController.signal });
2366
+ const signatureDidCommitPromise = (async () => {
2367
+ for await (const signatureStatusNotification of signatureStatusNotifications) {
2368
+ if (signatureStatusNotification.value.err) {
2369
+ throw new Error(`The transaction with signature \`${signature2}\` failed.`, {
2370
+ cause: signatureStatusNotification.value.err
2371
+ });
2372
+ } else {
2373
+ return;
2374
+ }
2375
+ }
2376
+ })();
2377
+ const signatureStatusLookupPromise = (async () => {
2378
+ const { value: signatureStatusResults } = await rpc.getSignatureStatuses([signature2]).send({ abortSignal: abortController.signal });
2379
+ const signatureStatus = signatureStatusResults[0];
2380
+ if (signatureStatus && signatureStatus.confirmationStatus && commitmentComparator(signatureStatus.confirmationStatus, commitment) >= 0) {
2381
+ return;
2382
+ } else {
2383
+ await new Promise(() => {
2384
+ });
2385
+ }
2386
+ })();
2387
+ try {
2388
+ return await Promise.race([signatureDidCommitPromise, signatureStatusLookupPromise]);
2389
+ } finally {
2390
+ abortController.abort();
2391
+ }
2392
+ };
2393
+ }
2394
+
2395
+ // src/transaction-confirmation-strategy-timeout.ts
2396
+ init_env_shim();
2397
+ async function getTimeoutPromise({ abortSignal: callerAbortSignal, commitment }) {
2398
+ return await new Promise((_, reject) => {
2399
+ const handleAbort = (e3) => {
2400
+ clearTimeout(timeoutId);
2401
+ const abortError = new DOMException(e3.target.reason, "AbortError");
2402
+ reject(abortError);
2403
+ };
2404
+ callerAbortSignal.addEventListener("abort", handleAbort);
2405
+ const timeoutMs = commitment === "processed" ? 3e4 : 6e4;
2406
+ const startMs = performance.now();
2407
+ const timeoutId = (
2408
+ // We use `setTimeout` instead of `AbortSignal.timeout()` because we want to measure
2409
+ // elapsed time instead of active time.
2410
+ // See https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/timeout_static
2411
+ setTimeout(() => {
2412
+ const elapsedMs = performance.now() - startMs;
2413
+ reject(new DOMException(`Timeout elapsed after ${elapsedMs} ms`, "TimeoutError"));
2414
+ }, timeoutMs)
2415
+ );
2416
+ });
2417
+ }
2418
+
2419
+ // src/airdrop-confirmer.ts
2420
+ function createDefaultSignatureOnlyRecentTransactionConfirmer({
2421
+ rpc,
2422
+ rpcSubscriptions
2423
+ }) {
2424
+ const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
2425
+ rpc,
2426
+ rpcSubscriptions
2427
+ );
2428
+ return async function confirmSignatureOnlyRecentTransaction(config) {
2429
+ await waitForRecentTransactionConfirmationUntilTimeout({
2430
+ ...config,
2431
+ getRecentSignatureConfirmationPromise,
2432
+ getTimeoutPromise
2433
+ });
1718
2434
  };
1719
2435
  }
1720
- var BASE_CONFIG3 = {
1721
- description: "The wire format of a Solana transaction" ,
1722
- fixedSize: null,
1723
- maxSize: null
1724
- };
1725
- function serialize3(transaction) {
1726
- const compiledTransaction = getCompiledTransaction(transaction);
1727
- return struct([
1728
- [
1729
- "signatures",
1730
- array(bytes({ size: 64 }), {
1731
- ...{ description: "A compact array of 64-byte, base-64 encoded Ed25519 signatures" } ,
1732
- size: shortU16()
1733
- })
1734
- ],
1735
- ["compiledMessage", getCompiledMessageEncoder()]
1736
- ]).serialize(compiledTransaction);
2436
+ async function waitForRecentTransactionConfirmationUntilTimeout(config) {
2437
+ await raceStrategies(
2438
+ config.signature,
2439
+ config,
2440
+ function getSpecificStrategiesForRace({ abortSignal, commitment, getTimeoutPromise: getTimeoutPromise2 }) {
2441
+ return [
2442
+ getTimeoutPromise2({
2443
+ abortSignal,
2444
+ commitment
2445
+ })
2446
+ ];
2447
+ }
2448
+ );
1737
2449
  }
1738
- function getTransactionEncoder() {
1739
- return {
1740
- ...BASE_CONFIG3,
1741
- deserialize: getUnimplementedDecoder("CompiledMessage"),
1742
- serialize: serialize3
2450
+
2451
+ // src/airdrop.ts
2452
+ function createDefaultAirdropRequester({ rpc, rpcSubscriptions }) {
2453
+ const confirmSignatureOnlyTransaction = createDefaultSignatureOnlyRecentTransactionConfirmer({
2454
+ rpc,
2455
+ rpcSubscriptions
2456
+ });
2457
+ return async function requestAirdrop(config) {
2458
+ return await requestAndConfirmAirdrop({
2459
+ ...config,
2460
+ confirmSignatureOnlyTransaction,
2461
+ rpc
2462
+ });
1743
2463
  };
1744
2464
  }
1745
- function getBase64EncodedWireTransaction(transaction) {
1746
- const wireTransactionBytes = getTransactionEncoder().serialize(transaction);
1747
- {
1748
- return btoa(String.fromCharCode(...wireTransactionBytes));
1749
- }
2465
+ async function requestAndConfirmAirdrop({
2466
+ abortSignal,
2467
+ commitment,
2468
+ confirmSignatureOnlyTransaction,
2469
+ lamports: lamports2,
2470
+ recipientAddress,
2471
+ rpc
2472
+ }) {
2473
+ const airdropTransactionSignature = await rpc.requestAirdrop(recipientAddress, lamports2, { commitment }).send({ abortSignal });
2474
+ await confirmSignatureOnlyTransaction({
2475
+ abortSignal,
2476
+ commitment,
2477
+ signature: airdropTransactionSignature
2478
+ });
2479
+ return airdropTransactionSignature;
1750
2480
  }
1751
2481
 
1752
2482
  // src/rpc.ts
1753
2483
  init_env_shim();
1754
2484
 
1755
- // ../functional/dist/index.browser.js
1756
- init_env_shim();
1757
- function pipe(init, ...fns) {
1758
- return fns.reduce((acc, fn) => fn(acc), init);
1759
- }
1760
-
1761
2485
  // ../rpc-core/dist/index.browser.js
1762
2486
  init_env_shim();
1763
2487
  function visitNode(value, keyPath, onIntegerOverflow) {
@@ -1786,68 +2510,215 @@ this.globalThis.solanaWeb3 = (function (exports) {
1786
2510
  return visitNode(params, [], onIntegerOverflow);
1787
2511
  }
1788
2512
  var KEYPATH_WILDCARD = {};
2513
+ var jsonParsedTokenAccountsConfigs = [
2514
+ // parsed Token/Token22 token account
2515
+ ["data", "parsed", "info", "tokenAmount", "decimals"],
2516
+ ["data", "parsed", "info", "tokenAmount", "uiAmount"],
2517
+ ["data", "parsed", "info", "rentExemptReserve", "decimals"],
2518
+ ["data", "parsed", "info", "rentExemptReserve", "uiAmount"],
2519
+ ["data", "parsed", "info", "delegatedAmount", "decimals"],
2520
+ ["data", "parsed", "info", "delegatedAmount", "uiAmount"],
2521
+ ["data", "parsed", "info", "extensions", KEYPATH_WILDCARD, "state", "olderTransferFee", "transferFeeBasisPoints"],
2522
+ ["data", "parsed", "info", "extensions", KEYPATH_WILDCARD, "state", "newerTransferFee", "transferFeeBasisPoints"],
2523
+ ["data", "parsed", "info", "extensions", KEYPATH_WILDCARD, "state", "preUpdateAverageRate"],
2524
+ ["data", "parsed", "info", "extensions", KEYPATH_WILDCARD, "state", "currentRate"]
2525
+ ];
2526
+ var jsonParsedAccountsConfigs = [
2527
+ ...jsonParsedTokenAccountsConfigs,
2528
+ // parsed AddressTableLookup account
2529
+ ["data", "parsed", "info", "lastExtendedSlotStartIndex"],
2530
+ // parsed Config account
2531
+ ["data", "parsed", "info", "slashPenalty"],
2532
+ ["data", "parsed", "info", "warmupCooldownRate"],
2533
+ // parsed Token/Token22 mint account
2534
+ ["data", "parsed", "info", "decimals"],
2535
+ // parsed Token/Token22 multisig account
2536
+ ["data", "parsed", "info", "numRequiredSigners"],
2537
+ ["data", "parsed", "info", "numValidSigners"],
2538
+ // parsed Stake account
2539
+ ["data", "parsed", "info", "stake", "delegation", "warmupCooldownRate"],
2540
+ // parsed Sysvar rent account
2541
+ ["data", "parsed", "info", "exemptionThreshold"],
2542
+ ["data", "parsed", "info", "burnPercent"],
2543
+ // parsed Vote account
2544
+ ["data", "parsed", "info", "commission"],
2545
+ ["data", "parsed", "info", "votes", KEYPATH_WILDCARD, "confirmationCount"]
2546
+ ];
1789
2547
  var memoizedNotificationKeypaths;
1790
2548
  var memoizedResponseKeypaths;
1791
2549
  function getAllowedNumericKeypathsForNotification() {
1792
2550
  if (!memoizedNotificationKeypaths) {
1793
- memoizedNotificationKeypaths = {};
2551
+ memoizedNotificationKeypaths = {
2552
+ accountNotifications: jsonParsedAccountsConfigs.map((c) => ["value", ...c]),
2553
+ blockNotifications: [
2554
+ ["value", "block", "blockTime"],
2555
+ [
2556
+ "value",
2557
+ "block",
2558
+ "transactions",
2559
+ KEYPATH_WILDCARD,
2560
+ "meta",
2561
+ "preTokenBalances",
2562
+ KEYPATH_WILDCARD,
2563
+ "accountIndex"
2564
+ ],
2565
+ [
2566
+ "value",
2567
+ "block",
2568
+ "transactions",
2569
+ KEYPATH_WILDCARD,
2570
+ "meta",
2571
+ "preTokenBalances",
2572
+ KEYPATH_WILDCARD,
2573
+ "uiTokenAmount",
2574
+ "decimals"
2575
+ ],
2576
+ [
2577
+ "value",
2578
+ "block",
2579
+ "transactions",
2580
+ KEYPATH_WILDCARD,
2581
+ "meta",
2582
+ "postTokenBalances",
2583
+ KEYPATH_WILDCARD,
2584
+ "accountIndex"
2585
+ ],
2586
+ [
2587
+ "value",
2588
+ "block",
2589
+ "transactions",
2590
+ KEYPATH_WILDCARD,
2591
+ "meta",
2592
+ "postTokenBalances",
2593
+ KEYPATH_WILDCARD,
2594
+ "uiTokenAmount",
2595
+ "decimals"
2596
+ ],
2597
+ ["value", "block", "transactions", KEYPATH_WILDCARD, "meta", "rewards", KEYPATH_WILDCARD, "commission"],
2598
+ [
2599
+ "value",
2600
+ "block",
2601
+ "transactions",
2602
+ KEYPATH_WILDCARD,
2603
+ "meta",
2604
+ "innerInstructions",
2605
+ KEYPATH_WILDCARD,
2606
+ "index"
2607
+ ],
2608
+ [
2609
+ "value",
2610
+ "block",
2611
+ "transactions",
2612
+ KEYPATH_WILDCARD,
2613
+ "meta",
2614
+ "innerInstructions",
2615
+ KEYPATH_WILDCARD,
2616
+ "instructions",
2617
+ KEYPATH_WILDCARD,
2618
+ "programIdIndex"
2619
+ ],
2620
+ [
2621
+ "value",
2622
+ "block",
2623
+ "transactions",
2624
+ KEYPATH_WILDCARD,
2625
+ "meta",
2626
+ "innerInstructions",
2627
+ KEYPATH_WILDCARD,
2628
+ "instructions",
2629
+ KEYPATH_WILDCARD,
2630
+ "accounts",
2631
+ KEYPATH_WILDCARD
2632
+ ],
2633
+ [
2634
+ "value",
2635
+ "block",
2636
+ "transactions",
2637
+ KEYPATH_WILDCARD,
2638
+ "transaction",
2639
+ "message",
2640
+ "addressTableLookups",
2641
+ KEYPATH_WILDCARD,
2642
+ "writableIndexes",
2643
+ KEYPATH_WILDCARD
2644
+ ],
2645
+ [
2646
+ "value",
2647
+ "block",
2648
+ "transactions",
2649
+ KEYPATH_WILDCARD,
2650
+ "transaction",
2651
+ "message",
2652
+ "addressTableLookups",
2653
+ KEYPATH_WILDCARD,
2654
+ "readonlyIndexes",
2655
+ KEYPATH_WILDCARD
2656
+ ],
2657
+ [
2658
+ "value",
2659
+ "block",
2660
+ "transactions",
2661
+ KEYPATH_WILDCARD,
2662
+ "transaction",
2663
+ "message",
2664
+ "instructions",
2665
+ KEYPATH_WILDCARD,
2666
+ "programIdIndex"
2667
+ ],
2668
+ [
2669
+ "value",
2670
+ "block",
2671
+ "transactions",
2672
+ KEYPATH_WILDCARD,
2673
+ "transaction",
2674
+ "message",
2675
+ "instructions",
2676
+ KEYPATH_WILDCARD,
2677
+ "accounts",
2678
+ KEYPATH_WILDCARD
2679
+ ],
2680
+ [
2681
+ "value",
2682
+ "block",
2683
+ "transactions",
2684
+ KEYPATH_WILDCARD,
2685
+ "transaction",
2686
+ "message",
2687
+ "header",
2688
+ "numReadonlySignedAccounts"
2689
+ ],
2690
+ [
2691
+ "value",
2692
+ "block",
2693
+ "transactions",
2694
+ KEYPATH_WILDCARD,
2695
+ "transaction",
2696
+ "message",
2697
+ "header",
2698
+ "numReadonlyUnsignedAccounts"
2699
+ ],
2700
+ [
2701
+ "value",
2702
+ "block",
2703
+ "transactions",
2704
+ KEYPATH_WILDCARD,
2705
+ "transaction",
2706
+ "message",
2707
+ "header",
2708
+ "numRequiredSignatures"
2709
+ ],
2710
+ ["value", "block", "rewards", KEYPATH_WILDCARD, "commission"]
2711
+ ],
2712
+ programNotifications: jsonParsedAccountsConfigs.flatMap((c) => [
2713
+ ["value", KEYPATH_WILDCARD, "account", ...c],
2714
+ [KEYPATH_WILDCARD, "account", ...c]
2715
+ ])
2716
+ };
1794
2717
  }
1795
2718
  return memoizedNotificationKeypaths;
1796
2719
  }
1797
2720
  function getAllowedNumericKeypathsForResponse() {
1798
2721
  if (!memoizedResponseKeypaths) {
1799
- const jsonParsedTokenAccountsConfigs = [
1800
- // parsed Token/Token22 token account
1801
- ["data", "parsed", "info", "tokenAmount", "decimals"],
1802
- ["data", "parsed", "info", "tokenAmount", "uiAmount"],
1803
- ["data", "parsed", "info", "rentExemptReserve", "decimals"],
1804
- ["data", "parsed", "info", "rentExemptReserve", "uiAmount"],
1805
- ["data", "parsed", "info", "delegatedAmount", "decimals"],
1806
- ["data", "parsed", "info", "delegatedAmount", "uiAmount"],
1807
- [
1808
- "data",
1809
- "parsed",
1810
- "info",
1811
- "extensions",
1812
- KEYPATH_WILDCARD,
1813
- "state",
1814
- "olderTransferFee",
1815
- "transferFeeBasisPoints"
1816
- ],
1817
- [
1818
- "data",
1819
- "parsed",
1820
- "info",
1821
- "extensions",
1822
- KEYPATH_WILDCARD,
1823
- "state",
1824
- "newerTransferFee",
1825
- "transferFeeBasisPoints"
1826
- ],
1827
- ["data", "parsed", "info", "extensions", KEYPATH_WILDCARD, "state", "preUpdateAverageRate"],
1828
- ["data", "parsed", "info", "extensions", KEYPATH_WILDCARD, "state", "currentRate"]
1829
- ];
1830
- const jsonParsedAccountsConfigs = [
1831
- ...jsonParsedTokenAccountsConfigs,
1832
- // parsed AddressTableLookup account
1833
- ["data", "parsed", "info", "lastExtendedSlotStartIndex"],
1834
- // parsed Config account
1835
- ["data", "parsed", "info", "slashPenalty"],
1836
- ["data", "parsed", "info", "warmupCooldownRate"],
1837
- // parsed Token/Token22 mint account
1838
- ["data", "parsed", "info", "decimals"],
1839
- // parsed Token/Token22 multisig account
1840
- ["data", "parsed", "info", "numRequiredSigners"],
1841
- ["data", "parsed", "info", "numValidSigners"],
1842
- // parsed Stake account
1843
- ["data", "parsed", "info", "stake", "delegation", "warmupCooldownRate"],
1844
- // parsed Sysvar rent account
1845
- ["data", "parsed", "info", "exemptionThreshold"],
1846
- ["data", "parsed", "info", "burnPercent"],
1847
- // parsed Vote account
1848
- ["data", "parsed", "info", "commission"],
1849
- ["data", "parsed", "info", "votes", KEYPATH_WILDCARD, "confirmationCount"]
1850
- ];
1851
2722
  memoizedResponseKeypaths = {
1852
2723
  getAccountInfo: jsonParsedAccountsConfigs.map((c) => ["value", ...c]),
1853
2724
  getBlock: [
@@ -2053,11 +2924,11 @@ this.globalThis.solanaWeb3 = (function (exports) {
2053
2924
  }
2054
2925
  function patchResponseForSolanaLabsRpc(rawResponse, methodName) {
2055
2926
  const allowedKeypaths = methodName ? getAllowedNumericKeypathsForResponse()[methodName] : void 0;
2056
- return visitNode2(rawResponse, allowedKeypaths ?? []);
2927
+ return visitNode2(rawResponse, allowedKeypaths != null ? allowedKeypaths : []);
2057
2928
  }
2058
2929
  function patchResponseForSolanaLabsRpcSubscriptions(rawResponse, methodName) {
2059
2930
  const allowedKeypaths = methodName ? getAllowedNumericKeypathsForNotification()[methodName] : void 0;
2060
- return visitNode2(rawResponse, allowedKeypaths ?? []);
2931
+ return visitNode2(rawResponse, allowedKeypaths != null ? allowedKeypaths : []);
2061
2932
  }
2062
2933
  function createSolanaRpcApi(config) {
2063
2934
  return new Proxy({}, {
@@ -2071,7 +2942,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
2071
2942
  const [_, p] = args;
2072
2943
  const methodName = p.toString();
2073
2944
  return function(...rawParams) {
2074
- const handleIntegerOverflow = config?.onIntegerOverflow;
2945
+ const handleIntegerOverflow = config == null ? void 0 : config.onIntegerOverflow;
2075
2946
  const params = patchParamsForSolanaLabsRpc(
2076
2947
  rawParams,
2077
2948
  handleIntegerOverflow ? (keyPath, value) => handleIntegerOverflow(methodName, keyPath, value) : void 0
@@ -2097,7 +2968,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
2097
2968
  const [_, p] = args;
2098
2969
  const notificationName = p.toString();
2099
2970
  return function(...rawParams) {
2100
- const handleIntegerOverflow = config?.onIntegerOverflow;
2971
+ const handleIntegerOverflow = config == null ? void 0 : config.onIntegerOverflow;
2101
2972
  const params = patchParamsForSolanaLabsRpc(
2102
2973
  rawParams,
2103
2974
  handleIntegerOverflow ? (keyPath, value) => handleIntegerOverflow(notificationName, keyPath, value) : void 0
@@ -2121,6 +2992,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
2121
2992
  var SolanaJsonRpcError = class extends Error {
2122
2993
  constructor(details) {
2123
2994
  super(`JSON-RPC 2.0 error (${details.code}): ${details.message}`);
2995
+ __publicField(this, "code");
2996
+ __publicField(this, "data");
2124
2997
  Error.captureStackTrace(this, this.constructor);
2125
2998
  this.code = details.code;
2126
2999
  this.data = details.data;
@@ -2150,7 +3023,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
2150
3023
  const payload = createJsonRpcMessage(methodName, params);
2151
3024
  const response = await rpcConfig.transport({
2152
3025
  payload,
2153
- signal: options?.abortSignal
3026
+ signal: options == null ? void 0 : options.abortSignal
2154
3027
  });
2155
3028
  if ("error" in response) {
2156
3029
  throw new SolanaJsonRpcError(response.error);
@@ -2275,10 +3148,11 @@ this.globalThis.solanaWeb3 = (function (exports) {
2275
3148
  function createJsonSubscriptionRpc(rpcConfig) {
2276
3149
  return makeProxy2(rpcConfig);
2277
3150
  }
2278
- var e = globalThis.fetch;
3151
+ var e2 = globalThis.fetch;
2279
3152
  var SolanaHttpError = class extends Error {
2280
3153
  constructor(details) {
2281
3154
  super(`HTTP error (${details.statusCode}): ${details.message}`);
3155
+ __publicField(this, "statusCode");
2282
3156
  Error.captureStackTrace(this, this.constructor);
2283
3157
  this.statusCode = details.statusCode;
2284
3158
  }
@@ -2334,16 +3208,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
2334
3208
  }
2335
3209
  return out;
2336
3210
  }
2337
- function createHttpTransport({ httpAgentNodeOnly, headers, url }) {
3211
+ function createHttpTransport({ headers, url }) {
2338
3212
  if (headers) {
2339
3213
  assertIsAllowedHttpRequestHeaders(headers);
2340
3214
  }
2341
- const agent = void 0;
2342
- if (httpAgentNodeOnly != null) {
2343
- console.warn(
2344
- "createHttpTransport(): The `httpAgentNodeOnly` config you supplied has been ignored; HTTP agents are only usable in Node environments."
2345
- );
2346
- }
2347
3215
  const customHeaders = headers && normalizeHeaders(headers);
2348
3216
  return async function makeHttpRequest({
2349
3217
  payload,
@@ -2351,7 +3219,6 @@ this.globalThis.solanaWeb3 = (function (exports) {
2351
3219
  }) {
2352
3220
  const body = JSON.stringify(payload);
2353
3221
  const requestInfo = {
2354
- agent,
2355
3222
  body,
2356
3223
  headers: {
2357
3224
  ...customHeaders,
@@ -2363,7 +3230,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
2363
3230
  method: "POST",
2364
3231
  signal
2365
3232
  };
2366
- const response = await e(url, requestInfo);
3233
+ const response = await e2(url, requestInfo);
2367
3234
  if (!response.ok) {
2368
3235
  throw new SolanaHttpError({
2369
3236
  message: response.statusText,
@@ -2373,9 +3240,9 @@ this.globalThis.solanaWeb3 = (function (exports) {
2373
3240
  return await response.json();
2374
3241
  };
2375
3242
  }
2376
- var e2 = globalThis.WebSocket;
3243
+ var e22 = globalThis.WebSocket;
2377
3244
  var EXPLICIT_ABORT_TOKEN = Symbol(
2378
- "This symbol is thrown from a socket's iterator when the connection is explicity aborted by the user"
3245
+ "This symbol is thrown from a socket's iterator when the connection is explicitly aborted by the user"
2379
3246
  );
2380
3247
  async function createWebSocketConnection({
2381
3248
  sendBufferHighWatermark,
@@ -2397,12 +3264,12 @@ this.globalThis.solanaWeb3 = (function (exports) {
2397
3264
  }
2398
3265
  function handleAbort() {
2399
3266
  errorAndClearAllIteratorStates(EXPLICIT_ABORT_TOKEN);
2400
- if (webSocket.readyState !== e2.CLOSED && webSocket.readyState !== e2.CLOSING) {
3267
+ if (webSocket.readyState !== e22.CLOSED && webSocket.readyState !== e22.CLOSING) {
2401
3268
  webSocket.close(1e3);
2402
3269
  }
2403
3270
  }
2404
3271
  function handleClose(ev) {
2405
- bufferDrainWatcher?.onCancel();
3272
+ bufferDrainWatcher == null ? void 0 : bufferDrainWatcher.onCancel();
2406
3273
  signal.removeEventListener("abort", handleAbort);
2407
3274
  webSocket.removeEventListener("close", handleClose);
2408
3275
  webSocket.removeEventListener("error", handleError);
@@ -2425,11 +3292,11 @@ this.globalThis.solanaWeb3 = (function (exports) {
2425
3292
  resolve({
2426
3293
  async send(payload) {
2427
3294
  const message = JSON.stringify(payload);
2428
- if (!bufferDrainWatcher && webSocket.readyState === e2.OPEN && webSocket.bufferedAmount > sendBufferHighWatermark) {
3295
+ if (!bufferDrainWatcher && webSocket.readyState === e22.OPEN && webSocket.bufferedAmount > sendBufferHighWatermark) {
2429
3296
  let onCancel;
2430
3297
  const promise = new Promise((resolve2, reject2) => {
2431
3298
  const intervalId = setInterval(() => {
2432
- if (webSocket.readyState !== e2.OPEN || !(webSocket.bufferedAmount > sendBufferHighWatermark)) {
3299
+ if (webSocket.readyState !== e22.OPEN || !(webSocket.bufferedAmount > sendBufferHighWatermark)) {
2433
3300
  clearInterval(intervalId);
2434
3301
  bufferDrainWatcher = void 0;
2435
3302
  resolve2();
@@ -2510,7 +3377,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
2510
3377
  }
2511
3378
  });
2512
3379
  }
2513
- const webSocket = new e2(url);
3380
+ const webSocket = new e22(url);
2514
3381
  webSocket.addEventListener("close", handleClose);
2515
3382
  webSocket.addEventListener("error", handleError);
2516
3383
  webSocket.addEventListener("open", handleOpen);
@@ -2525,13 +3392,13 @@ this.globalThis.solanaWeb3 = (function (exports) {
2525
3392
  );
2526
3393
  }
2527
3394
  return async function sendWebSocketMessage({ payload, signal }) {
2528
- signal?.throwIfAborted();
3395
+ signal == null ? void 0 : signal.throwIfAborted();
2529
3396
  const connection = await createWebSocketConnection({
2530
3397
  sendBufferHighWatermark,
2531
3398
  signal,
2532
3399
  url
2533
3400
  });
2534
- signal?.throwIfAborted();
3401
+ signal == null ? void 0 : signal.throwIfAborted();
2535
3402
  await connection.send(payload);
2536
3403
  return {
2537
3404
  [Symbol.asyncIterator]: connection[Symbol.asyncIterator].bind(connection),
@@ -2567,6 +3434,9 @@ this.globalThis.solanaWeb3 = (function (exports) {
2567
3434
  super(
2568
3435
  `The ${ordinal} argument to the \`${methodName}\` RPC method${path ? ` at path \`${path}\`` : ""} was \`${value}\`. This number is unsafe for use with the Solana JSON-RPC because it exceeds \`Number.MAX_SAFE_INTEGER\`.`
2569
3436
  );
3437
+ __publicField(this, "methodName");
3438
+ __publicField(this, "keyPath");
3439
+ __publicField(this, "value");
2570
3440
  this.keyPath = keyPath;
2571
3441
  this.methodName = methodName;
2572
3442
  this.value = value;
@@ -2713,7 +3583,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
2713
3583
  getAbortSignalFromInputArgs: ({ abortSignal }) => abortSignal,
2714
3584
  getCacheEntryMissingError(deduplicationKey2) {
2715
3585
  return new Error(
2716
- `Found no cache entry for subscription with deduplication key \`${deduplicationKey2?.toString()}\``
3586
+ `Found no cache entry for subscription with deduplication key \`${deduplicationKey2 == null ? void 0 : deduplicationKey2.toString()}\``
2717
3587
  );
2718
3588
  },
2719
3589
  getCacheKeyFromInputArgs: () => deduplicationKey,
@@ -2878,6 +3748,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
2878
3748
  return out;
2879
3749
  }
2880
3750
  function createDefaultRpcTransport(config) {
3751
+ var _a;
2881
3752
  return pipe(
2882
3753
  createHttpTransport({
2883
3754
  ...config,
@@ -2885,7 +3756,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
2885
3756
  ...config.headers ? normalizeHeaders2(config.headers) : void 0,
2886
3757
  ...{
2887
3758
  // Keep these headers lowercase so they will override any user-supplied headers above.
2888
- "solana-client": `js/${"2.0.0-development"}` ?? "UNKNOWN"
3759
+ "solana-client": (_a = `js/${"2.0.0-development"}`) != null ? _a : "UNKNOWN"
2889
3760
  }
2890
3761
  }
2891
3762
  }),
@@ -2969,7 +3840,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
2969
3840
  return getCachedAbortableIterableFactory({
2970
3841
  getAbortSignalFromInputArgs: ({ signal }) => signal,
2971
3842
  getCacheEntryMissingError(shardKey) {
2972
- return new Error(`Found no cache entry for connection with shard key \`${shardKey?.toString()}\``);
3843
+ return new Error(`Found no cache entry for connection with shard key \`${shardKey == null ? void 0 : shardKey.toString()}\``);
2973
3844
  },
2974
3845
  getCacheKeyFromInputArgs: ({ payload }) => getShard ? getShard(payload) : NULL_SHARD_CACHE_KEY,
2975
3846
  onCacheHit: (connection, { payload }) => connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(payload),
@@ -2982,15 +3853,18 @@ this.globalThis.solanaWeb3 = (function (exports) {
2982
3853
 
2983
3854
  // src/rpc-websocket-transport.ts
2984
3855
  function createDefaultRpcSubscriptionsTransport(config) {
3856
+ var _a;
2985
3857
  const { getShard, intervalMs, ...rest } = config;
2986
3858
  return pipe(
2987
3859
  createWebSocketTransport({
2988
3860
  ...rest,
2989
- sendBufferHighWatermark: config.sendBufferHighWatermark ?? // Let 128KB of data into the WebSocket buffer before buffering it in the app.
2990
- 131072
3861
+ sendBufferHighWatermark: (_a = config.sendBufferHighWatermark) != null ? _a : (
3862
+ // Let 128KB of data into the WebSocket buffer before buffering it in the app.
3863
+ 131072
3864
+ )
2991
3865
  }),
2992
3866
  (transport) => getWebSocketTransportWithAutoping({
2993
- intervalMs: intervalMs ?? 5e3,
3867
+ intervalMs: intervalMs != null ? intervalMs : 5e3,
2994
3868
  transport
2995
3869
  }),
2996
3870
  (transport) => getWebSocketTransportWithConnectionSharding({
@@ -3000,15 +3874,308 @@ this.globalThis.solanaWeb3 = (function (exports) {
3000
3874
  );
3001
3875
  }
3002
3876
 
3877
+ // src/send-transaction.ts
3878
+ init_env_shim();
3879
+
3880
+ // src/transaction-confirmation.ts
3881
+ init_env_shim();
3882
+
3883
+ // src/transaction-confirmation-strategy-blockheight.ts
3884
+ init_env_shim();
3885
+ function createBlockHeightExceedencePromiseFactory(rpcSubscriptions) {
3886
+ return async function getBlockHeightExceedencePromise({ abortSignal: callerAbortSignal, lastValidBlockHeight }) {
3887
+ const abortController = new AbortController();
3888
+ function handleAbort() {
3889
+ abortController.abort();
3890
+ }
3891
+ callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
3892
+ const slotNotifications = await rpcSubscriptions.slotNotifications().subscribe({ abortSignal: abortController.signal });
3893
+ try {
3894
+ for await (const slotNotification of slotNotifications) {
3895
+ if (slotNotification.slot > lastValidBlockHeight) {
3896
+ throw new Error(
3897
+ "The network has progressed past the last block for which this transaction could have committed."
3898
+ );
3899
+ }
3900
+ }
3901
+ } finally {
3902
+ abortController.abort();
3903
+ }
3904
+ };
3905
+ }
3906
+
3907
+ // src/transaction-confirmation-strategy-nonce.ts
3908
+ init_env_shim();
3909
+ var NONCE_VALUE_OFFSET = 4 + // version(u32)
3910
+ 4 + // state(u32)
3911
+ 32;
3912
+ function createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions) {
3913
+ return async function getNonceInvalidationPromise({
3914
+ abortSignal: callerAbortSignal,
3915
+ commitment,
3916
+ currentNonceValue,
3917
+ nonceAccountAddress
3918
+ }) {
3919
+ const abortController = new AbortController();
3920
+ function handleAbort() {
3921
+ abortController.abort();
3922
+ }
3923
+ callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
3924
+ const accountNotifications = await rpcSubscriptions.accountNotifications(nonceAccountAddress, { commitment, encoding: "base64" }).subscribe({ abortSignal: abortController.signal });
3925
+ const base58Decoder2 = getBase58Decoder();
3926
+ const base64Encoder = getBase64Encoder();
3927
+ function getNonceFromAccountData([base64EncodedBytes]) {
3928
+ const data = base64Encoder.encode(base64EncodedBytes);
3929
+ const nonceValueBytes = data.slice(NONCE_VALUE_OFFSET, NONCE_VALUE_OFFSET + 32);
3930
+ return base58Decoder2.decode(nonceValueBytes)[0];
3931
+ }
3932
+ const nonceAccountDidAdvancePromise = (async () => {
3933
+ for await (const accountNotification of accountNotifications) {
3934
+ const nonceValue = getNonceFromAccountData(accountNotification.value.data);
3935
+ if (nonceValue !== currentNonceValue) {
3936
+ throw new Error(
3937
+ `The nonce \`${currentNonceValue}\` is no longer valid. It has advanced to \`${nonceValue}\`.`
3938
+ );
3939
+ }
3940
+ }
3941
+ })();
3942
+ const nonceIsAlreadyInvalidPromise = (async () => {
3943
+ const { value: nonceAccount } = await rpc.getAccountInfo(nonceAccountAddress, {
3944
+ commitment,
3945
+ dataSlice: { length: 32, offset: NONCE_VALUE_OFFSET },
3946
+ encoding: "base58"
3947
+ }).send({ abortSignal: abortController.signal });
3948
+ if (!nonceAccount) {
3949
+ throw new Error(`No nonce account could be found at address \`${nonceAccountAddress}\`.`);
3950
+ }
3951
+ const nonceValue = (
3952
+ // This works because we asked for the exact slice of data representing the nonce
3953
+ // value, and furthermore asked for it in `base58` encoding.
3954
+ nonceAccount.data[0]
3955
+ );
3956
+ if (nonceValue !== currentNonceValue) {
3957
+ throw new Error(
3958
+ `The nonce \`${currentNonceValue}\` is no longer valid. It has advanced to \`${nonceValue}\`.`
3959
+ );
3960
+ } else {
3961
+ await new Promise(() => {
3962
+ });
3963
+ }
3964
+ })();
3965
+ try {
3966
+ return await Promise.race([nonceAccountDidAdvancePromise, nonceIsAlreadyInvalidPromise]);
3967
+ } finally {
3968
+ abortController.abort();
3969
+ }
3970
+ };
3971
+ }
3972
+
3973
+ // src/transaction-confirmation.ts
3974
+ function createDefaultDurableNonceTransactionConfirmer({
3975
+ rpc,
3976
+ rpcSubscriptions
3977
+ }) {
3978
+ const getNonceInvalidationPromise = createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions);
3979
+ const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
3980
+ rpc,
3981
+ rpcSubscriptions
3982
+ );
3983
+ return async function confirmDurableNonceTransaction(config) {
3984
+ await waitForDurableNonceTransactionConfirmation({
3985
+ ...config,
3986
+ getNonceInvalidationPromise,
3987
+ getRecentSignatureConfirmationPromise
3988
+ });
3989
+ };
3990
+ }
3991
+ function createDefaultRecentTransactionConfirmer({
3992
+ rpc,
3993
+ rpcSubscriptions
3994
+ }) {
3995
+ const getBlockHeightExceedencePromise = createBlockHeightExceedencePromiseFactory(rpcSubscriptions);
3996
+ const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
3997
+ rpc,
3998
+ rpcSubscriptions
3999
+ );
4000
+ return async function confirmRecentTransaction(config) {
4001
+ await waitForRecentTransactionConfirmation({
4002
+ ...config,
4003
+ getBlockHeightExceedencePromise,
4004
+ getRecentSignatureConfirmationPromise
4005
+ });
4006
+ };
4007
+ }
4008
+ async function waitForDurableNonceTransactionConfirmation(config) {
4009
+ await raceStrategies(
4010
+ getSignatureFromTransaction(config.transaction),
4011
+ config,
4012
+ function getSpecificStrategiesForRace({ abortSignal, commitment, getNonceInvalidationPromise, transaction }) {
4013
+ return [
4014
+ getNonceInvalidationPromise({
4015
+ abortSignal,
4016
+ commitment,
4017
+ currentNonceValue: transaction.lifetimeConstraint.nonce,
4018
+ nonceAccountAddress: transaction.instructions[0].accounts[0].address
4019
+ })
4020
+ ];
4021
+ }
4022
+ );
4023
+ }
4024
+ async function waitForRecentTransactionConfirmation(config) {
4025
+ await raceStrategies(
4026
+ getSignatureFromTransaction(config.transaction),
4027
+ config,
4028
+ function getSpecificStrategiesForRace({ abortSignal, getBlockHeightExceedencePromise, transaction }) {
4029
+ return [
4030
+ getBlockHeightExceedencePromise({
4031
+ abortSignal,
4032
+ lastValidBlockHeight: transaction.lifetimeConstraint.lastValidBlockHeight
4033
+ })
4034
+ ];
4035
+ }
4036
+ );
4037
+ }
4038
+
4039
+ // src/send-transaction.ts
4040
+ function getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, config) {
4041
+ if (
4042
+ // The developer has supplied no value for `preflightCommitment`.
4043
+ !(config == null ? void 0 : config.preflightCommitment) && // The value of `commitment` is lower than the server default of `preflightCommitment`.
4044
+ commitmentComparator(
4045
+ commitment,
4046
+ "finalized"
4047
+ /* default value of `preflightCommitment` */
4048
+ ) < 0
4049
+ ) {
4050
+ return {
4051
+ ...config,
4052
+ // In the common case, it is unlikely that you want to simulate a transaction at
4053
+ // `finalized` commitment when your standard of commitment for confirming the
4054
+ // transaction is lower. Cap the simulation commitment level to the level of the
4055
+ // confirmation commitment.
4056
+ preflightCommitment: commitment
4057
+ };
4058
+ }
4059
+ return config;
4060
+ }
4061
+ async function sendTransaction_INTERNAL({
4062
+ abortSignal,
4063
+ commitment,
4064
+ rpc,
4065
+ transaction,
4066
+ ...sendTransactionConfig
4067
+ }) {
4068
+ const base64EncodedWireTransaction = getBase64EncodedWireTransaction(transaction);
4069
+ return await rpc.sendTransaction(base64EncodedWireTransaction, {
4070
+ ...getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, sendTransactionConfig),
4071
+ encoding: "base64"
4072
+ }).send({ abortSignal });
4073
+ }
4074
+ function createDefaultDurableNonceTransactionSender({
4075
+ rpc,
4076
+ rpcSubscriptions
4077
+ }) {
4078
+ const confirmDurableNonceTransaction = createDefaultDurableNonceTransactionConfirmer({
4079
+ rpc,
4080
+ rpcSubscriptions
4081
+ });
4082
+ return async function sendDurableNonceTransaction(transaction, config) {
4083
+ await sendAndConfirmDurableNonceTransaction({
4084
+ ...config,
4085
+ confirmDurableNonceTransaction,
4086
+ rpc,
4087
+ transaction
4088
+ });
4089
+ };
4090
+ }
4091
+ function createDefaultTransactionSender({
4092
+ rpc,
4093
+ rpcSubscriptions
4094
+ }) {
4095
+ const confirmRecentTransaction = createDefaultRecentTransactionConfirmer({
4096
+ rpc,
4097
+ rpcSubscriptions
4098
+ });
4099
+ return async function sendTransaction(transaction, config) {
4100
+ await sendAndConfirmTransaction({
4101
+ ...config,
4102
+ confirmRecentTransaction,
4103
+ rpc,
4104
+ transaction
4105
+ });
4106
+ };
4107
+ }
4108
+ async function sendAndConfirmDurableNonceTransaction({
4109
+ abortSignal,
4110
+ commitment,
4111
+ confirmDurableNonceTransaction,
4112
+ rpc,
4113
+ transaction,
4114
+ ...sendTransactionConfig
4115
+ }) {
4116
+ const transactionSignature = await sendTransaction_INTERNAL({
4117
+ ...sendTransactionConfig,
4118
+ abortSignal,
4119
+ commitment,
4120
+ rpc,
4121
+ transaction
4122
+ });
4123
+ await confirmDurableNonceTransaction({
4124
+ abortSignal,
4125
+ commitment,
4126
+ transaction
4127
+ });
4128
+ return transactionSignature;
4129
+ }
4130
+ async function sendAndConfirmTransaction({
4131
+ abortSignal,
4132
+ commitment,
4133
+ confirmRecentTransaction,
4134
+ rpc,
4135
+ transaction,
4136
+ ...sendTransactionConfig
4137
+ }) {
4138
+ const transactionSignature = await sendTransaction_INTERNAL({
4139
+ ...sendTransactionConfig,
4140
+ abortSignal,
4141
+ commitment,
4142
+ rpc,
4143
+ transaction
4144
+ });
4145
+ await confirmRecentTransaction({
4146
+ abortSignal,
4147
+ commitment,
4148
+ transaction
4149
+ });
4150
+ return transactionSignature;
4151
+ }
4152
+
3003
4153
  exports.AccountRole = AccountRole;
3004
4154
  exports.address = address;
3005
4155
  exports.appendTransactionInstruction = appendTransactionInstruction;
3006
- exports.assertIsBase58EncodedAddress = assertIsBase58EncodedAddress;
4156
+ exports.assertIsAddress = assertIsAddress;
3007
4157
  exports.assertIsBlockhash = assertIsBlockhash;
3008
4158
  exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
4159
+ exports.assertIsLamports = assertIsLamports;
4160
+ exports.assertIsProgramDerivedAddress = assertIsProgramDerivedAddress;
4161
+ exports.assertIsSignature = assertIsSignature;
4162
+ exports.assertIsStringifiedBigInt = assertIsStringifiedBigInt;
4163
+ exports.assertIsStringifiedNumber = assertIsStringifiedNumber;
4164
+ exports.assertIsUnixTimestamp = assertIsUnixTimestamp;
4165
+ exports.assertTransactionIsFullySigned = assertTransactionIsFullySigned;
4166
+ exports.commitmentComparator = commitmentComparator;
4167
+ exports.compileMessage = compileMessage;
3009
4168
  exports.createAddressWithSeed = createAddressWithSeed;
4169
+ exports.createBlockHeightExceedencePromiseFactory = createBlockHeightExceedencePromiseFactory;
4170
+ exports.createDefaultAirdropRequester = createDefaultAirdropRequester;
4171
+ exports.createDefaultDurableNonceTransactionConfirmer = createDefaultDurableNonceTransactionConfirmer;
4172
+ exports.createDefaultDurableNonceTransactionSender = createDefaultDurableNonceTransactionSender;
4173
+ exports.createDefaultRecentTransactionConfirmer = createDefaultRecentTransactionConfirmer;
3010
4174
  exports.createDefaultRpcSubscriptionsTransport = createDefaultRpcSubscriptionsTransport;
3011
4175
  exports.createDefaultRpcTransport = createDefaultRpcTransport;
4176
+ exports.createDefaultTransactionSender = createDefaultTransactionSender;
4177
+ exports.createNonceInvalidationPromiseFactory = createNonceInvalidationPromiseFactory;
4178
+ exports.createRecentSignatureConfirmationPromiseFactory = createRecentSignatureConfirmationPromiseFactory;
3012
4179
  exports.createSolanaRpc = createSolanaRpc;
3013
4180
  exports.createSolanaRpcSubscriptions = createSolanaRpcSubscriptions;
3014
4181
  exports.createSolanaRpcSubscriptions_UNSTABLE = createSolanaRpcSubscriptions_UNSTABLE;
@@ -3016,24 +4183,51 @@ this.globalThis.solanaWeb3 = (function (exports) {
3016
4183
  exports.downgradeRoleToNonSigner = downgradeRoleToNonSigner;
3017
4184
  exports.downgradeRoleToReadonly = downgradeRoleToReadonly;
3018
4185
  exports.generateKeyPair = generateKeyPair;
4186
+ exports.getAddressCodec = getAddressCodec;
4187
+ exports.getAddressComparator = getAddressComparator;
4188
+ exports.getAddressDecoder = getAddressDecoder;
4189
+ exports.getAddressEncoder = getAddressEncoder;
3019
4190
  exports.getAddressFromPublicKey = getAddressFromPublicKey;
3020
- exports.getBase58EncodedAddressCodec = getBase58EncodedAddressCodec;
3021
- exports.getBase58EncodedAddressComparator = getBase58EncodedAddressComparator;
3022
4191
  exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
4192
+ exports.getCompiledMessageCodec = getCompiledMessageCodec;
4193
+ exports.getCompiledMessageDecoder = getCompiledMessageDecoder;
4194
+ exports.getCompiledMessageEncoder = getCompiledMessageEncoder;
3023
4195
  exports.getProgramDerivedAddress = getProgramDerivedAddress;
3024
- exports.isBase58EncodedAddress = isBase58EncodedAddress;
4196
+ exports.getSignatureFromTransaction = getSignatureFromTransaction;
4197
+ exports.getTransactionCodec = getTransactionCodec;
4198
+ exports.getTransactionDecoder = getTransactionDecoder;
4199
+ exports.getTransactionEncoder = getTransactionEncoder;
4200
+ exports.isAddress = isAddress;
4201
+ exports.isAdvanceNonceAccountInstruction = isAdvanceNonceAccountInstruction;
4202
+ exports.isLamports = isLamports;
4203
+ exports.isProgramDerivedAddress = isProgramDerivedAddress;
4204
+ exports.isSignature = isSignature;
3025
4205
  exports.isSignerRole = isSignerRole;
4206
+ exports.isStringifiedBigInt = isStringifiedBigInt;
4207
+ exports.isStringifiedNumber = isStringifiedNumber;
4208
+ exports.isUnixTimestamp = isUnixTimestamp;
3026
4209
  exports.isWritableRole = isWritableRole;
4210
+ exports.lamports = lamports;
3027
4211
  exports.mergeRoles = mergeRoles;
4212
+ exports.partiallySignTransaction = partiallySignTransaction;
3028
4213
  exports.prependTransactionInstruction = prependTransactionInstruction;
4214
+ exports.requestAndConfirmAirdrop = requestAndConfirmAirdrop;
4215
+ exports.sendAndConfirmDurableNonceTransaction = sendAndConfirmDurableNonceTransaction;
4216
+ exports.sendAndConfirmTransaction = sendAndConfirmTransaction;
3029
4217
  exports.setTransactionFeePayer = setTransactionFeePayer;
3030
4218
  exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
3031
4219
  exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
3032
4220
  exports.signBytes = signBytes;
3033
4221
  exports.signTransaction = signTransaction;
4222
+ exports.signature = signature;
4223
+ exports.stringifiedBigInt = stringifiedBigInt;
4224
+ exports.stringifiedNumber = stringifiedNumber;
4225
+ exports.unixTimestamp = unixTimestamp;
3034
4226
  exports.upgradeRoleToSigner = upgradeRoleToSigner;
3035
4227
  exports.upgradeRoleToWritable = upgradeRoleToWritable;
3036
4228
  exports.verifySignature = verifySignature;
4229
+ exports.waitForDurableNonceTransactionConfirmation = waitForDurableNonceTransactionConfirmation;
4230
+ exports.waitForRecentTransactionConfirmation = waitForRecentTransactionConfirmation;
3037
4231
 
3038
4232
  return exports;
3039
4233