@solana/web3.js 2.0.0-experimental.ba46ce1 → 2.0.0-experimental.ba9b4c7

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.
@@ -125,19 +125,31 @@ 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
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
128
+ // ../codecs-core/dist/index.browser.js
132
129
  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, bytes2, offset = 0) {
131
+ if (bytes2.length - offset <= 0) {
132
+ throw new Error(`Codec [${codecDescription}] cannot decode empty byte arrays.`);
133
+ }
134
+ }
135
+ function assertByteArrayHasEnoughBytesForCodec(codecDescription, expected, bytes2, offset = 0) {
136
+ const bytesLength = bytes2.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
  });
@@ -150,259 +162,145 @@ this.globalThis.solanaWeb3 = (function (exports) {
150
162
  paddedBytes.set(bytes2);
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 = (bytes2, length) => padBytes(bytes2.length <= length ? bytes2 : bytes2.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 ?? 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 ?? `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: (bytes2, offset = 0) => {
207
+ assertByteArrayHasEnoughBytesForCodec("fixCodec", fixedBytes, bytes2, offset);
208
+ if (offset > 0 || bytes2.length > fixedBytes) {
209
+ bytes2 = bytes2.slice(offset, offset + fixedBytes);
189
210
  }
190
- if (serializer.fixedSize !== null) {
191
- buffer = fixBytes(buffer, serializer.fixedSize);
211
+ if (decoder.fixedSize !== null) {
212
+ bytes2 = fixBytes(bytes2, decoder.fixedSize);
192
213
  }
193
- const [value] = serializer.deserialize(buffer, 0);
214
+ const [value] = decoder.decode(bytes2, 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
211
225
  };
212
226
  }
213
-
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
218
- init_env_shim();
219
-
220
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/errors.mjs
221
- 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;
228
- }
229
- };
230
-
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;
234
- const baseBigInt = BigInt(base);
227
+ function mapDecoder(decoder, map) {
235
228
  return {
236
- 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
- }
243
- if (value === "")
244
- return new Uint8Array();
245
- const chars = [...value];
246
- let trailIndex = chars.findIndex((c) => c !== alphabet[0]);
247
- trailIndex = trailIndex === -1 ? chars.length : trailIndex;
248
- const leadingZeroes = Array(trailIndex).fill(0);
249
- if (trailIndex === chars.length)
250
- return Uint8Array.from(leadingZeroes);
251
- const tailChars = chars.slice(trailIndex);
252
- let base10Number = 0n;
253
- let baseXPower = 1n;
254
- for (let i = tailChars.length - 1; i >= 0; i -= 1) {
255
- base10Number += baseXPower * BigInt(alphabet.indexOf(tailChars[i]));
256
- baseXPower *= baseBigInt;
257
- }
258
- const tailBytes = [];
259
- while (base10Number > 0n) {
260
- tailBytes.unshift(Number(base10Number % 256n));
261
- base10Number /= 256n;
262
- }
263
- return Uint8Array.from(leadingZeroes.concat(tailBytes));
229
+ decode: (bytes2, offset = 0) => {
230
+ const [value, length] = decoder.decode(bytes2, offset);
231
+ return [map(value, bytes2, offset), length];
264
232
  },
265
- deserialize(buffer, offset = 0) {
266
- if (buffer.length === 0)
267
- 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);
275
- const tailChars = [];
276
- while (base10Number > 0n) {
277
- tailChars.unshift(alphabet[Number(base10Number % baseBigInt)]);
278
- base10Number /= baseBigInt;
279
- }
280
- return [leadingZeroes + tailChars.join(""), buffer.length];
281
- }
233
+ description: decoder.description,
234
+ fixedSize: decoder.fixedSize,
235
+ maxSize: decoder.maxSize
282
236
  };
283
- };
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];
308
- }
309
- };
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();
237
+ }
313
238
 
314
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/common.mjs
239
+ // ../codecs-strings/dist/index.browser.js
315
240
  init_env_shim();
316
- var Endian;
317
- (function(Endian2) {
318
- Endian2["Little"] = "le";
319
- Endian2["Big"] = "be";
320
- })(Endian || (Endian = {}));
321
241
 
322
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/errors.mjs
242
+ // ../codecs-numbers/dist/index.browser.js
323
243
  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");
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
+ );
328
249
  }
329
- };
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) {
250
+ }
251
+ function sharedNumberFactory(input) {
334
252
  let littleEndian;
335
253
  let defaultDescription = input.name;
336
254
  if (input.size > 1) {
337
- littleEndian = !("endian" in input.options) || input.options.endian === Endian.Little;
255
+ littleEndian = !("endian" in input.options) || input.options.endian === 0;
338
256
  defaultDescription += littleEndian ? "(le)" : "(be)";
339
257
  }
340
258
  return {
341
259
  description: input.options.description ?? defaultDescription,
342
260
  fixedSize: input.size,
343
- maxSize: input.size,
344
- serialize(value) {
261
+ littleEndian,
262
+ maxSize: input.size
263
+ };
264
+ }
265
+ function numberEncoderFactory(input) {
266
+ const codecData = sharedNumberFactory(input);
267
+ return {
268
+ description: codecData.description,
269
+ encode(value) {
345
270
  if (input.range) {
346
- assertRange(input.name, input.range[0], input.range[1], value);
271
+ assertNumberIsBetweenForCodec(input.name, input.range[0], input.range[1], value);
347
272
  }
348
- const buffer = new ArrayBuffer(input.size);
349
- input.set(new DataView(buffer), value, littleEndian);
350
- return new Uint8Array(buffer);
273
+ const arrayBuffer = new ArrayBuffer(input.size);
274
+ input.set(new DataView(arrayBuffer), value, codecData.littleEndian);
275
+ return new Uint8Array(arrayBuffer);
351
276
  },
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
- }
277
+ fixedSize: codecData.fixedSize,
278
+ maxSize: codecData.maxSize
358
279
  };
359
280
  }
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
- };
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 = {}) => ({
281
+ function numberDecoderFactory(input) {
282
+ const codecData = sharedNumberFactory(input);
283
+ return {
284
+ decode(bytes2, offset = 0) {
285
+ assertByteArrayIsNotEmptyForCodec(codecData.description, bytes2, offset);
286
+ assertByteArrayHasEnoughBytesForCodec(codecData.description, input.size, bytes2, offset);
287
+ const view = new DataView(toArrayBuffer(bytes2, offset, input.size));
288
+ return [input.get(view, codecData.littleEndian), offset + input.size];
289
+ },
290
+ description: codecData.description,
291
+ fixedSize: codecData.fixedSize,
292
+ maxSize: codecData.maxSize
293
+ };
294
+ }
295
+ function toArrayBuffer(bytes2, offset, length) {
296
+ const bytesOffset = bytes2.byteOffset + (offset ?? 0);
297
+ const bytesLength = length ?? bytes2.byteLength;
298
+ return bytes2.buffer.slice(bytesOffset, bytesOffset + bytesLength);
299
+ }
300
+ var getShortU16Encoder = (options = {}) => ({
401
301
  description: options.description ?? "shortU16",
402
- fixedSize: null,
403
- maxSize: 3,
404
- serialize: (value) => {
405
- assertRange("shortU16", 0, 65535, value);
302
+ encode: (value) => {
303
+ assertNumberIsBetweenForCodec("shortU16", 0, 65535, value);
406
304
  const bytes2 = [0];
407
305
  for (let ii = 0; ; ii += 1) {
408
306
  const alignedValue = value >> ii * 7;
@@ -417,7 +315,11 @@ this.globalThis.solanaWeb3 = (function (exports) {
417
315
  }
418
316
  return new Uint8Array(bytes2);
419
317
  },
420
- deserialize: (bytes2, offset = 0) => {
318
+ fixedSize: null,
319
+ maxSize: 3
320
+ });
321
+ var getShortU16Decoder = (options = {}) => ({
322
+ decode: (bytes2, offset = 0) => {
421
323
  let value = 0;
422
324
  let byteCount = 0;
423
325
  while (++byteCount) {
@@ -430,223 +332,184 @@ this.globalThis.solanaWeb3 = (function (exports) {
430
332
  }
431
333
  }
432
334
  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
- }
335
+ },
336
+ description: options.description ?? "shortU16",
337
+ fixedSize: null,
338
+ maxSize: 3
339
+ });
340
+ var getU32Encoder = (options = {}) => numberEncoderFactory({
341
+ name: "u32",
342
+ options,
343
+ range: [0, Number("0xffffffff")],
344
+ set: (view, value, le) => view.setUint32(0, value, le),
345
+ size: 4
346
+ });
347
+ var getU32Decoder = (options = {}) => numberDecoderFactory({
348
+ get: (view, le) => view.getUint32(0, le),
349
+ name: "u32",
350
+ options,
351
+ size: 4
352
+ });
353
+ var getU8Encoder = (options = {}) => numberEncoderFactory({
354
+ name: "u8",
355
+ options,
356
+ range: [0, Number("0xff")],
357
+ set: (view, value) => view.setUint8(0, value),
358
+ size: 1
359
+ });
360
+ var getU8Decoder = (options = {}) => numberDecoderFactory({
361
+ get: (view) => view.getUint8(0),
362
+ name: "u8",
363
+ options,
364
+ size: 1
365
+ });
366
+ var getU8Codec = (options = {}) => combineCodec(getU8Encoder(options), getU8Decoder(options));
468
367
 
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];
368
+ // ../codecs-strings/dist/index.browser.js
369
+ function assertValidBaseString(alphabet4, testValue, givenValue = testValue) {
370
+ if (!testValue.match(new RegExp(`^[${alphabet4}]*$`))) {
371
+ throw new Error(`Expected a string of base ${alphabet4.length}, got [${givenValue}].`);
487
372
  }
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
373
  }
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
- }
374
+ var getBaseXEncoder = (alphabet4) => {
375
+ const base = alphabet4.length;
376
+ const baseBigInt = BigInt(base);
511
377
  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);
378
+ description: `base${base}`,
379
+ encode(value) {
380
+ assertValidBaseString(alphabet4, value);
381
+ if (value === "")
382
+ return new Uint8Array();
383
+ const chars = [...value];
384
+ let trailIndex = chars.findIndex((c) => c !== alphabet4[0]);
385
+ trailIndex = trailIndex === -1 ? chars.length : trailIndex;
386
+ const leadingZeroes = Array(trailIndex).fill(0);
387
+ if (trailIndex === chars.length)
388
+ return Uint8Array.from(leadingZeroes);
389
+ const tailChars = chars.slice(trailIndex);
390
+ let base10Number = 0n;
391
+ let baseXPower = 1n;
392
+ for (let i = tailChars.length - 1; i >= 0; i -= 1) {
393
+ base10Number += baseXPower * BigInt(alphabet4.indexOf(tailChars[i]));
394
+ baseXPower *= baseBigInt;
518
395
  }
519
- return mergeBytes([getSizePrefix(size, value.length), ...value.map((v) => item.serialize(v))]);
520
- },
521
- deserialize: (bytes2, offset = 0) => {
522
- if (typeof size === "object" && bytes2.slice(offset).length === 0) {
523
- return [[], offset];
396
+ const tailBytes = [];
397
+ while (base10Number > 0n) {
398
+ tailBytes.unshift(Number(base10Number % 256n));
399
+ base10Number /= 256n;
524
400
  }
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;
401
+ return Uint8Array.from(leadingZeroes.concat(tailBytes));
402
+ },
403
+ fixedSize: null,
404
+ maxSize: null
405
+ };
406
+ };
407
+ var getBaseXDecoder = (alphabet4) => {
408
+ const base = alphabet4.length;
409
+ const baseBigInt = BigInt(base);
410
+ return {
411
+ decode(rawBytes, offset = 0) {
412
+ const bytes2 = offset === 0 ? rawBytes : rawBytes.slice(offset);
413
+ if (bytes2.length === 0)
414
+ return ["", 0];
415
+ let trailIndex = bytes2.findIndex((n) => n !== 0);
416
+ trailIndex = trailIndex === -1 ? bytes2.length : trailIndex;
417
+ const leadingZeroes = alphabet4[0].repeat(trailIndex);
418
+ if (trailIndex === bytes2.length)
419
+ return [leadingZeroes, rawBytes.length];
420
+ let base10Number = bytes2.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
421
+ const tailChars = [];
422
+ while (base10Number > 0n) {
423
+ tailChars.unshift(alphabet4[Number(base10Number % baseBigInt)]);
424
+ base10Number /= baseBigInt;
532
425
  }
533
- return [values, offset];
534
- }
426
+ return [leadingZeroes + tailChars.join(""), rawBytes.length];
427
+ },
428
+ description: `base${base}`,
429
+ fixedSize: null,
430
+ maxSize: null
535
431
  };
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,
432
+ };
433
+ var alphabet2 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
434
+ var getBase58Encoder = () => getBaseXEncoder(alphabet2);
435
+ var getBase58Decoder = () => getBaseXDecoder(alphabet2);
436
+ var removeNullCharacters = (value) => (
437
+ // eslint-disable-next-line no-control-regex
438
+ value.replace(/\u0000/g, "")
439
+ );
440
+ var e = globalThis.TextDecoder;
441
+ var o = globalThis.TextEncoder;
442
+ var getUtf8Encoder = () => {
443
+ let textEncoder;
444
+ return {
445
+ description: "utf8",
446
+ encode: (value) => new Uint8Array((textEncoder || (textEncoder = new o())).encode(value)),
545
447
  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
- }
448
+ maxSize: null
449
+ };
450
+ };
451
+ var getUtf8Decoder = () => {
452
+ let textDecoder;
453
+ return {
454
+ decode(bytes2, offset = 0) {
455
+ const value = (textDecoder || (textDecoder = new e())).decode(bytes2.slice(offset));
456
+ return [removeNullCharacters(value), bytes2.length];
457
+ },
458
+ description: "utf8",
459
+ fixedSize: null,
460
+ maxSize: null
552
461
  };
462
+ };
463
+ var getStringEncoder = (options = {}) => {
464
+ const size = options.size ?? getU32Encoder();
465
+ const encoding = options.encoding ?? getUtf8Encoder();
466
+ const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
553
467
  if (size === "variable") {
554
- return byteSerializer;
468
+ return { ...encoding, description };
555
469
  }
556
470
  if (typeof size === "number") {
557
- return fixSerializer(byteSerializer, size, description);
471
+ return fixEncoder(encoding, size, description);
558
472
  }
559
473
  return {
560
474
  description,
561
- fixedSize: null,
562
- maxSize: null,
563
- serialize: (value) => {
564
- const contentBytes = byteSerializer.serialize(value);
565
- const lengthBytes = size.serialize(contentBytes.length);
475
+ encode: (value) => {
476
+ const contentBytes = encoding.encode(value);
477
+ const lengthBytes = size.encode(contentBytes.length);
566
478
  return mergeBytes([lengthBytes, contentBytes]);
567
479
  },
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
- }
480
+ fixedSize: null,
481
+ maxSize: null
583
482
  };
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;
483
+ };
484
+ var getStringDecoder = (options = {}) => {
485
+ const size = options.size ?? getU32Decoder();
486
+ const encoding = options.encoding ?? getUtf8Decoder();
591
487
  const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
592
488
  if (size === "variable") {
593
- return {
594
- ...encoding,
595
- description
596
- };
489
+ return { ...encoding, description };
597
490
  }
598
491
  if (typeof size === "number") {
599
- return fixSerializer(encoding, size, description);
492
+ return fixDecoder(encoding, size, description);
600
493
  }
601
494
  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);
495
+ decode: (bytes2, offset = 0) => {
496
+ assertByteArrayIsNotEmptyForCodec("string", bytes2, offset);
497
+ const [lengthBigInt, lengthOffset] = size.decode(bytes2, offset);
615
498
  const length = Number(lengthBigInt);
616
499
  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);
500
+ const contentBytes = bytes2.slice(offset, offset + length);
501
+ assertByteArrayHasEnoughBytesForCodec("string", length, contentBytes);
502
+ const [value, contentOffset] = encoding.decode(contentBytes);
622
503
  offset += contentOffset;
623
504
  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
505
  },
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
- }
506
+ description,
507
+ fixedSize: null,
508
+ maxSize: null
649
509
  };
510
+ };
511
+ function getSizeDescription(size) {
512
+ return typeof size === "object" ? size.description : `${size}`;
650
513
  }
651
514
 
652
515
  // ../assertions/dist/index.browser.js
@@ -715,7 +578,21 @@ this.globalThis.solanaWeb3 = (function (exports) {
715
578
  throw new Error("No signature verification implementation could be found");
716
579
  }
717
580
  }
718
- function isBase58EncodedAddress(putativeBase58EncodedAddress) {
581
+
582
+ // ../addresses/dist/index.browser.js
583
+ var memoizedBase58Encoder;
584
+ var memoizedBase58Decoder;
585
+ function getMemoizedBase58Encoder() {
586
+ if (!memoizedBase58Encoder)
587
+ memoizedBase58Encoder = getBase58Encoder();
588
+ return memoizedBase58Encoder;
589
+ }
590
+ function getMemoizedBase58Decoder() {
591
+ if (!memoizedBase58Decoder)
592
+ memoizedBase58Decoder = getBase58Decoder();
593
+ return memoizedBase58Decoder;
594
+ }
595
+ function isAddress(putativeBase58EncodedAddress) {
719
596
  if (
720
597
  // Lowest address (32 bytes of zeroes)
721
598
  putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
@@ -723,14 +600,15 @@ this.globalThis.solanaWeb3 = (function (exports) {
723
600
  ) {
724
601
  return false;
725
602
  }
726
- const bytes2 = base58.serialize(putativeBase58EncodedAddress);
603
+ const base58Encoder = getMemoizedBase58Encoder();
604
+ const bytes2 = base58Encoder.encode(putativeBase58EncodedAddress);
727
605
  const numBytes = bytes2.byteLength;
728
606
  if (numBytes !== 32) {
729
607
  return false;
730
608
  }
731
609
  return true;
732
610
  }
733
- function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) {
611
+ function assertIsAddress(putativeBase58EncodedAddress) {
734
612
  try {
735
613
  if (
736
614
  // Lowest address (32 bytes of zeroes)
@@ -739,7 +617,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
739
617
  ) {
740
618
  throw new Error("Expected input string to decode to a byte array of length 32.");
741
619
  }
742
- const bytes2 = base58.serialize(putativeBase58EncodedAddress);
620
+ const base58Encoder = getMemoizedBase58Encoder();
621
+ const bytes2 = base58Encoder.encode(putativeBase58EncodedAddress);
743
622
  const numBytes = bytes2.byteLength;
744
623
  if (numBytes !== 32) {
745
624
  throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
@@ -751,17 +630,30 @@ this.globalThis.solanaWeb3 = (function (exports) {
751
630
  }
752
631
  }
753
632
  function address(putativeBase58EncodedAddress) {
754
- assertIsBase58EncodedAddress(putativeBase58EncodedAddress);
633
+ assertIsAddress(putativeBase58EncodedAddress);
755
634
  return putativeBase58EncodedAddress;
756
635
  }
757
- function getBase58EncodedAddressCodec(config) {
758
- return string({
759
- description: config?.description ?? ("A 32-byte account address" ),
760
- encoding: base58,
761
- size: 32
636
+ function getAddressEncoder(config) {
637
+ return mapEncoder(
638
+ getStringEncoder({
639
+ description: config?.description ?? "Base58EncodedAddress",
640
+ encoding: getMemoizedBase58Encoder(),
641
+ size: 32
642
+ }),
643
+ (putativeAddress) => address(putativeAddress)
644
+ );
645
+ }
646
+ function getAddressDecoder(config) {
647
+ return getStringDecoder({
648
+ description: config?.description ?? "Base58EncodedAddress",
649
+ encoding: getMemoizedBase58Decoder(),
650
+ size: 32
762
651
  });
763
652
  }
764
- function getBase58EncodedAddressComparator() {
653
+ function getAddressCodec(config) {
654
+ return combineCodec(getAddressEncoder(config), getAddressDecoder(config));
655
+ }
656
+ function getAddressComparator() {
765
657
  return new Intl.Collator("en", {
766
658
  caseFirst: "lower",
767
659
  ignorePunctuation: false,
@@ -857,6 +749,21 @@ this.globalThis.solanaWeb3 = (function (exports) {
857
749
  const y = decompressPointBytes(bytes2);
858
750
  return pointIsOnCurve(y, bytes2[31]);
859
751
  }
752
+ function isProgramDerivedAddress(value) {
753
+ return Array.isArray(value) && value.length === 2 && typeof value[0] === "string" && typeof value[1] === "number" && value[1] >= 0 && value[1] <= 255 && isAddress(value[0]);
754
+ }
755
+ function assertIsProgramDerivedAddress(value) {
756
+ const validFormat = Array.isArray(value) && value.length === 2 && typeof value[0] === "string" && typeof value[1] === "number";
757
+ if (!validFormat) {
758
+ throw new Error(
759
+ `Expected given program derived address to have the following format: [Base58EncodedAddress, ProgramDerivedAddressBump].`
760
+ );
761
+ }
762
+ if (value[1] < 0 || value[1] > 255) {
763
+ throw new Error(`Expected program derived address bump to be in the range [0, 255], got: ${value[1]}.`);
764
+ }
765
+ assertIsAddress(value[0]);
766
+ }
860
767
  var MAX_SEED_LENGTH = 32;
861
768
  var MAX_SEEDS = 16;
862
769
  var PDA_MARKER_BYTES = [
@@ -885,7 +792,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
885
792
  ];
886
793
  var PointOnCurveError = class extends Error {
887
794
  };
888
- async function createProgramDerivedAddress({ programAddress, seeds }) {
795
+ async function createProgramDerivedAddress({
796
+ programAddress,
797
+ seeds
798
+ }) {
889
799
  await assertDigestCapabilityIsAvailable();
890
800
  if (seeds.length > MAX_SEEDS) {
891
801
  throw new Error(`A maximum of ${MAX_SEEDS} seeds may be supplied when creating an address`);
@@ -899,8 +809,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
899
809
  acc.push(...bytes2);
900
810
  return acc;
901
811
  }, []);
902
- const base58EncodedAddressCodec = getBase58EncodedAddressCodec();
903
- const programAddressBytes = base58EncodedAddressCodec.serialize(programAddress);
812
+ const base58EncodedAddressCodec = getAddressCodec();
813
+ const programAddressBytes = base58EncodedAddressCodec.encode(programAddress);
904
814
  const addressBytesBuffer = await crypto.subtle.digest(
905
815
  "SHA-256",
906
816
  new Uint8Array([...seedBytes, ...programAddressBytes, ...PDA_MARKER_BYTES])
@@ -909,19 +819,20 @@ this.globalThis.solanaWeb3 = (function (exports) {
909
819
  if (await compressedPointBytesAreOnCurve(addressBytes)) {
910
820
  throw new PointOnCurveError("Invalid seeds; point must fall off the Ed25519 curve");
911
821
  }
912
- return base58EncodedAddressCodec.deserialize(addressBytes)[0];
822
+ return base58EncodedAddressCodec.decode(addressBytes)[0];
913
823
  }
914
- async function getProgramDerivedAddress({ programAddress, seeds }) {
824
+ async function getProgramDerivedAddress({
825
+ programAddress,
826
+ seeds
827
+ }) {
915
828
  let bumpSeed = 255;
916
829
  while (bumpSeed > 0) {
917
830
  try {
918
- return {
919
- bumpSeed,
920
- pda: await createProgramDerivedAddress({
921
- programAddress,
922
- seeds: [...seeds, new Uint8Array([bumpSeed])]
923
- })
924
- };
831
+ const address2 = await createProgramDerivedAddress({
832
+ programAddress,
833
+ seeds: [...seeds, new Uint8Array([bumpSeed])]
834
+ });
835
+ return [address2, bumpSeed];
925
836
  } catch (e3) {
926
837
  if (e3 instanceof PointOnCurveError) {
927
838
  bumpSeed--;
@@ -932,102 +843,849 @@ this.globalThis.solanaWeb3 = (function (exports) {
932
843
  }
933
844
  throw new Error("Unable to find a viable program address bump seed");
934
845
  }
935
- async function createAddressWithSeed({
936
- baseAddress,
937
- programAddress,
938
- seed
939
- }) {
940
- const { serialize: serialize4, deserialize: deserialize2 } = getBase58EncodedAddressCodec();
941
- const seedBytes = typeof seed === "string" ? new TextEncoder().encode(seed) : seed;
942
- if (seedBytes.byteLength > MAX_SEED_LENGTH) {
943
- throw new Error(`The seed exceeds the maximum length of 32 bytes`);
846
+ async function createAddressWithSeed({
847
+ baseAddress,
848
+ programAddress,
849
+ seed
850
+ }) {
851
+ const { encode: encode2, decode: decode2 } = getAddressCodec();
852
+ const seedBytes = typeof seed === "string" ? new TextEncoder().encode(seed) : seed;
853
+ if (seedBytes.byteLength > MAX_SEED_LENGTH) {
854
+ throw new Error(`The seed exceeds the maximum length of 32 bytes`);
855
+ }
856
+ const programAddressBytes = encode2(programAddress);
857
+ if (programAddressBytes.length >= PDA_MARKER_BYTES.length && programAddressBytes.slice(-PDA_MARKER_BYTES.length).every((byte, index) => byte === PDA_MARKER_BYTES[index])) {
858
+ throw new Error(`programAddress cannot end with the PDA marker`);
859
+ }
860
+ const addressBytesBuffer = await crypto.subtle.digest(
861
+ "SHA-256",
862
+ new Uint8Array([...encode2(baseAddress), ...seedBytes, ...programAddressBytes])
863
+ );
864
+ const addressBytes = new Uint8Array(addressBytesBuffer);
865
+ return decode2(addressBytes)[0];
866
+ }
867
+ async function getAddressFromPublicKey(publicKey) {
868
+ await assertKeyExporterIsAvailable();
869
+ if (publicKey.type !== "public" || publicKey.algorithm.name !== "Ed25519") {
870
+ throw new Error("The `CryptoKey` must be an `Ed25519` public key");
871
+ }
872
+ const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
873
+ const [base58EncodedAddress] = getAddressDecoder().decode(new Uint8Array(publicKeyBytes));
874
+ return base58EncodedAddress;
875
+ }
876
+
877
+ // ../instructions/dist/index.browser.js
878
+ init_env_shim();
879
+ var AccountRole = /* @__PURE__ */ ((AccountRole22) => {
880
+ AccountRole22[AccountRole22["WRITABLE_SIGNER"] = /* 3 */
881
+ 3] = "WRITABLE_SIGNER";
882
+ AccountRole22[AccountRole22["READONLY_SIGNER"] = /* 2 */
883
+ 2] = "READONLY_SIGNER";
884
+ AccountRole22[AccountRole22["WRITABLE"] = /* 1 */
885
+ 1] = "WRITABLE";
886
+ AccountRole22[AccountRole22["READONLY"] = /* 0 */
887
+ 0] = "READONLY";
888
+ return AccountRole22;
889
+ })(AccountRole || {});
890
+ var IS_SIGNER_BITMASK = 2;
891
+ var IS_WRITABLE_BITMASK = 1;
892
+ function downgradeRoleToNonSigner(role) {
893
+ return role & ~IS_SIGNER_BITMASK;
894
+ }
895
+ function downgradeRoleToReadonly(role) {
896
+ return role & ~IS_WRITABLE_BITMASK;
897
+ }
898
+ function isSignerRole(role) {
899
+ return role >= 2;
900
+ }
901
+ function isWritableRole(role) {
902
+ return (role & IS_WRITABLE_BITMASK) !== 0;
903
+ }
904
+ function mergeRoles(roleA, roleB) {
905
+ return roleA | roleB;
906
+ }
907
+ function upgradeRoleToSigner(role) {
908
+ return role | IS_SIGNER_BITMASK;
909
+ }
910
+ function upgradeRoleToWritable(role) {
911
+ return role | IS_WRITABLE_BITMASK;
912
+ }
913
+
914
+ // ../keys/dist/index.browser.js
915
+ init_env_shim();
916
+ async function generateKeyPair() {
917
+ await assertKeyGenerationIsAvailable();
918
+ const keyPair = await crypto.subtle.generateKey(
919
+ /* algorithm */
920
+ "Ed25519",
921
+ // Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20
922
+ /* extractable */
923
+ false,
924
+ // Prevents the bytes of the private key from being visible to JS.
925
+ /* allowed uses */
926
+ ["sign", "verify"]
927
+ );
928
+ return keyPair;
929
+ }
930
+ async function signBytes(key, data) {
931
+ await assertSigningCapabilityIsAvailable();
932
+ const signedData = await crypto.subtle.sign("Ed25519", key, data);
933
+ return new Uint8Array(signedData);
934
+ }
935
+ async function verifySignature(key, signature, data) {
936
+ await assertVerificationCapabilityIsAvailable();
937
+ return await crypto.subtle.verify("Ed25519", key, signature, data);
938
+ }
939
+
940
+ // ../transactions/dist/index.browser.js
941
+ init_env_shim();
942
+
943
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/index.mjs
944
+ init_env_shim();
945
+
946
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/index.mjs
947
+ init_env_shim();
948
+
949
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/bytes.mjs
950
+ init_env_shim();
951
+ var mergeBytes2 = (bytesArr) => {
952
+ const totalLength = bytesArr.reduce((total, arr) => total + arr.length, 0);
953
+ const result = new Uint8Array(totalLength);
954
+ let offset = 0;
955
+ bytesArr.forEach((arr) => {
956
+ result.set(arr, offset);
957
+ offset += arr.length;
958
+ });
959
+ return result;
960
+ };
961
+ var padBytes2 = (bytes2, length) => {
962
+ if (bytes2.length >= length)
963
+ return bytes2;
964
+ const paddedBytes = new Uint8Array(length).fill(0);
965
+ paddedBytes.set(bytes2);
966
+ return paddedBytes;
967
+ };
968
+ var fixBytes2 = (bytes2, length) => padBytes2(bytes2.slice(0, length), length);
969
+
970
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/errors.mjs
971
+ init_env_shim();
972
+ var DeserializingEmptyBufferError = class extends Error {
973
+ constructor(serializer) {
974
+ super(`Serializer [${serializer}] cannot deserialize empty buffers.`);
975
+ __publicField(this, "name", "DeserializingEmptyBufferError");
976
+ }
977
+ };
978
+ var NotEnoughBytesError = class extends Error {
979
+ constructor(serializer, expected, actual) {
980
+ super(`Serializer [${serializer}] expected ${expected} bytes, got ${actual}.`);
981
+ __publicField(this, "name", "NotEnoughBytesError");
982
+ }
983
+ };
984
+ var ExpectedFixedSizeSerializerError = class extends Error {
985
+ constructor(message) {
986
+ message ?? (message = "Expected a fixed-size serializer, got a variable-size one.");
987
+ super(message);
988
+ __publicField(this, "name", "ExpectedFixedSizeSerializerError");
989
+ }
990
+ };
991
+
992
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/fixSerializer.mjs
993
+ init_env_shim();
994
+ function fixSerializer(serializer, fixedBytes, description) {
995
+ return {
996
+ description: description ?? `fixed(${fixedBytes}, ${serializer.description})`,
997
+ fixedSize: fixedBytes,
998
+ maxSize: fixedBytes,
999
+ serialize: (value) => fixBytes2(serializer.serialize(value), fixedBytes),
1000
+ deserialize: (buffer, offset = 0) => {
1001
+ buffer = buffer.slice(offset, offset + fixedBytes);
1002
+ if (buffer.length < fixedBytes) {
1003
+ throw new NotEnoughBytesError("fixSerializer", fixedBytes, buffer.length);
1004
+ }
1005
+ if (serializer.fixedSize !== null) {
1006
+ buffer = fixBytes2(buffer, serializer.fixedSize);
1007
+ }
1008
+ const [value] = serializer.deserialize(buffer, 0);
1009
+ return [value, offset + fixedBytes];
1010
+ }
1011
+ };
1012
+ }
1013
+
1014
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/mapSerializer.mjs
1015
+ init_env_shim();
1016
+ function mapSerializer(serializer, unmap, map) {
1017
+ return {
1018
+ description: serializer.description,
1019
+ fixedSize: serializer.fixedSize,
1020
+ maxSize: serializer.maxSize,
1021
+ serialize: (value) => serializer.serialize(unmap(value)),
1022
+ deserialize: (buffer, offset = 0) => {
1023
+ const [value, length] = serializer.deserialize(buffer, offset);
1024
+ return map ? [map(value, buffer, offset), length] : [value, length];
1025
+ }
1026
+ };
1027
+ }
1028
+
1029
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/index.mjs
1030
+ init_env_shim();
1031
+
1032
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseX.mjs
1033
+ init_env_shim();
1034
+
1035
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/errors.mjs
1036
+ init_env_shim();
1037
+ var InvalidBaseStringError = class extends Error {
1038
+ constructor(value, base, cause) {
1039
+ const message = `Expected a string of base ${base}, got [${value}].`;
1040
+ super(message);
1041
+ __publicField(this, "name", "InvalidBaseStringError");
1042
+ this.cause = cause;
1043
+ }
1044
+ };
1045
+
1046
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseX.mjs
1047
+ var baseX = (alphabet) => {
1048
+ const base = alphabet.length;
1049
+ const baseBigInt = BigInt(base);
1050
+ return {
1051
+ description: `base${base}`,
1052
+ fixedSize: null,
1053
+ maxSize: null,
1054
+ serialize(value) {
1055
+ if (!value.match(new RegExp(`^[${alphabet}]*$`))) {
1056
+ throw new InvalidBaseStringError(value, base);
1057
+ }
1058
+ if (value === "")
1059
+ return new Uint8Array();
1060
+ const chars = [...value];
1061
+ let trailIndex = chars.findIndex((c) => c !== alphabet[0]);
1062
+ trailIndex = trailIndex === -1 ? chars.length : trailIndex;
1063
+ const leadingZeroes = Array(trailIndex).fill(0);
1064
+ if (trailIndex === chars.length)
1065
+ return Uint8Array.from(leadingZeroes);
1066
+ const tailChars = chars.slice(trailIndex);
1067
+ let base10Number = 0n;
1068
+ let baseXPower = 1n;
1069
+ for (let i = tailChars.length - 1; i >= 0; i -= 1) {
1070
+ base10Number += baseXPower * BigInt(alphabet.indexOf(tailChars[i]));
1071
+ baseXPower *= baseBigInt;
1072
+ }
1073
+ const tailBytes = [];
1074
+ while (base10Number > 0n) {
1075
+ tailBytes.unshift(Number(base10Number % 256n));
1076
+ base10Number /= 256n;
1077
+ }
1078
+ return Uint8Array.from(leadingZeroes.concat(tailBytes));
1079
+ },
1080
+ deserialize(buffer, offset = 0) {
1081
+ if (buffer.length === 0)
1082
+ return ["", 0];
1083
+ const bytes2 = buffer.slice(offset);
1084
+ let trailIndex = bytes2.findIndex((n) => n !== 0);
1085
+ trailIndex = trailIndex === -1 ? bytes2.length : trailIndex;
1086
+ const leadingZeroes = alphabet[0].repeat(trailIndex);
1087
+ if (trailIndex === bytes2.length)
1088
+ return [leadingZeroes, buffer.length];
1089
+ let base10Number = bytes2.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
1090
+ const tailChars = [];
1091
+ while (base10Number > 0n) {
1092
+ tailChars.unshift(alphabet[Number(base10Number % baseBigInt)]);
1093
+ base10Number /= baseBigInt;
1094
+ }
1095
+ return [leadingZeroes + tailChars.join(""), buffer.length];
1096
+ }
1097
+ };
1098
+ };
1099
+
1100
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/base58.mjs
1101
+ init_env_shim();
1102
+ var base58 = baseX("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
1103
+
1104
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/base64.mjs
1105
+ init_env_shim();
1106
+
1107
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseXReslice.mjs
1108
+ init_env_shim();
1109
+ var baseXReslice = (alphabet, bits) => {
1110
+ const base = alphabet.length;
1111
+ const reslice = (input, inputBits, outputBits, useRemainder) => {
1112
+ const output = [];
1113
+ let accumulator = 0;
1114
+ let bitsInAccumulator = 0;
1115
+ const mask = (1 << outputBits) - 1;
1116
+ for (const value of input) {
1117
+ accumulator = accumulator << inputBits | value;
1118
+ bitsInAccumulator += inputBits;
1119
+ while (bitsInAccumulator >= outputBits) {
1120
+ bitsInAccumulator -= outputBits;
1121
+ output.push(accumulator >> bitsInAccumulator & mask);
1122
+ }
1123
+ }
1124
+ if (useRemainder && bitsInAccumulator > 0) {
1125
+ output.push(accumulator << outputBits - bitsInAccumulator & mask);
1126
+ }
1127
+ return output;
1128
+ };
1129
+ return {
1130
+ description: `base${base}`,
1131
+ fixedSize: null,
1132
+ maxSize: null,
1133
+ serialize(value) {
1134
+ if (!value.match(new RegExp(`^[${alphabet}]*$`))) {
1135
+ throw new InvalidBaseStringError(value, base);
1136
+ }
1137
+ if (value === "")
1138
+ return new Uint8Array();
1139
+ const charIndices = [...value].map((c) => alphabet.indexOf(c));
1140
+ const bytes2 = reslice(charIndices, bits, 8, false);
1141
+ return Uint8Array.from(bytes2);
1142
+ },
1143
+ deserialize(buffer, offset = 0) {
1144
+ if (buffer.length === 0)
1145
+ return ["", 0];
1146
+ const bytes2 = [...buffer.slice(offset)];
1147
+ const charIndices = reslice(bytes2, 8, bits, true);
1148
+ return [charIndices.map((i) => alphabet[i]).join(""), buffer.length];
1149
+ }
1150
+ };
1151
+ };
1152
+
1153
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/base64.mjs
1154
+ var base64 = mapSerializer(baseXReslice("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", 6), (value) => value.replace(/=/g, ""), (value) => value.padEnd(Math.ceil(value.length / 4) * 4, "="));
1155
+
1156
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/nullCharacters.mjs
1157
+ init_env_shim();
1158
+ var removeNullCharacters2 = (value) => (
1159
+ // eslint-disable-next-line no-control-regex
1160
+ value.replace(/\u0000/g, "")
1161
+ );
1162
+
1163
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/utf8.mjs
1164
+ init_env_shim();
1165
+ var utf8 = {
1166
+ description: "utf8",
1167
+ fixedSize: null,
1168
+ maxSize: null,
1169
+ serialize(value) {
1170
+ return new TextEncoder().encode(value);
1171
+ },
1172
+ deserialize(buffer, offset = 0) {
1173
+ const value = new TextDecoder().decode(buffer.slice(offset));
1174
+ return [removeNullCharacters2(value), buffer.length];
1175
+ }
1176
+ };
1177
+
1178
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/index.mjs
1179
+ init_env_shim();
1180
+
1181
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/common.mjs
1182
+ init_env_shim();
1183
+ var Endian;
1184
+ (function(Endian2) {
1185
+ Endian2["Little"] = "le";
1186
+ Endian2["Big"] = "be";
1187
+ })(Endian || (Endian = {}));
1188
+
1189
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/errors.mjs
1190
+ init_env_shim();
1191
+ var NumberOutOfRangeError = class extends RangeError {
1192
+ constructor(serializer, min, max, actual) {
1193
+ super(`Serializer [${serializer}] expected number to be between ${min} and ${max}, got ${actual}.`);
1194
+ __publicField(this, "name", "NumberOutOfRangeError");
1195
+ }
1196
+ };
1197
+
1198
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/utils.mjs
1199
+ init_env_shim();
1200
+ function numberFactory(input) {
1201
+ let littleEndian;
1202
+ let defaultDescription = input.name;
1203
+ if (input.size > 1) {
1204
+ littleEndian = !("endian" in input.options) || input.options.endian === Endian.Little;
1205
+ defaultDescription += littleEndian ? "(le)" : "(be)";
1206
+ }
1207
+ return {
1208
+ description: input.options.description ?? defaultDescription,
1209
+ fixedSize: input.size,
1210
+ maxSize: input.size,
1211
+ serialize(value) {
1212
+ if (input.range) {
1213
+ assertRange(input.name, input.range[0], input.range[1], value);
1214
+ }
1215
+ const buffer = new ArrayBuffer(input.size);
1216
+ input.set(new DataView(buffer), value, littleEndian);
1217
+ return new Uint8Array(buffer);
1218
+ },
1219
+ deserialize(bytes2, offset = 0) {
1220
+ const slice = bytes2.slice(offset, offset + input.size);
1221
+ assertEnoughBytes("i8", slice, input.size);
1222
+ const view = toDataView(slice);
1223
+ return [input.get(view, littleEndian), offset + input.size];
1224
+ }
1225
+ };
1226
+ }
1227
+ var toArrayBuffer2 = (array2) => array2.buffer.slice(array2.byteOffset, array2.byteLength + array2.byteOffset);
1228
+ var toDataView = (array2) => new DataView(toArrayBuffer2(array2));
1229
+ var assertRange = (serializer, min, max, value) => {
1230
+ if (value < min || value > max) {
1231
+ throw new NumberOutOfRangeError(serializer, min, max, value);
1232
+ }
1233
+ };
1234
+ var assertEnoughBytes = (serializer, bytes2, expected) => {
1235
+ if (bytes2.length === 0) {
1236
+ throw new DeserializingEmptyBufferError(serializer);
1237
+ }
1238
+ if (bytes2.length < expected) {
1239
+ throw new NotEnoughBytesError(serializer, expected, bytes2.length);
1240
+ }
1241
+ };
1242
+
1243
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u32.mjs
1244
+ init_env_shim();
1245
+ var u32 = (options = {}) => numberFactory({
1246
+ name: "u32",
1247
+ size: 4,
1248
+ range: [0, Number("0xffffffff")],
1249
+ set: (view, value, le) => view.setUint32(0, Number(value), le),
1250
+ get: (view, le) => view.getUint32(0, le),
1251
+ options
1252
+ });
1253
+
1254
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/shortU16.mjs
1255
+ init_env_shim();
1256
+ var shortU16 = (options = {}) => ({
1257
+ description: options.description ?? "shortU16",
1258
+ fixedSize: null,
1259
+ maxSize: 3,
1260
+ serialize: (value) => {
1261
+ assertRange("shortU16", 0, 65535, value);
1262
+ const bytes2 = [0];
1263
+ for (let ii = 0; ; ii += 1) {
1264
+ const alignedValue = value >> ii * 7;
1265
+ if (alignedValue === 0) {
1266
+ break;
1267
+ }
1268
+ const nextSevenBits = 127 & alignedValue;
1269
+ bytes2[ii] = nextSevenBits;
1270
+ if (ii > 0) {
1271
+ bytes2[ii - 1] |= 128;
1272
+ }
1273
+ }
1274
+ return new Uint8Array(bytes2);
1275
+ },
1276
+ deserialize: (bytes2, offset = 0) => {
1277
+ let value = 0;
1278
+ let byteCount = 0;
1279
+ while (++byteCount) {
1280
+ const byteIndex = byteCount - 1;
1281
+ const currentByte = bytes2[offset + byteIndex];
1282
+ const nextSevenBits = 127 & currentByte;
1283
+ value |= nextSevenBits << byteIndex * 7;
1284
+ if ((currentByte & 128) === 0) {
1285
+ break;
1286
+ }
1287
+ }
1288
+ return [value, offset + byteCount];
1289
+ }
1290
+ });
1291
+
1292
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/array.mjs
1293
+ init_env_shim();
1294
+
1295
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/errors.mjs
1296
+ init_env_shim();
1297
+ var InvalidNumberOfItemsError = class extends Error {
1298
+ constructor(serializer, expected, actual) {
1299
+ super(`Expected [${serializer}] to have ${expected} items, got ${actual}.`);
1300
+ __publicField(this, "name", "InvalidNumberOfItemsError");
1301
+ }
1302
+ };
1303
+ var InvalidArrayLikeRemainderSizeError = class extends Error {
1304
+ constructor(remainderSize, itemSize) {
1305
+ 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.`);
1306
+ __publicField(this, "name", "InvalidArrayLikeRemainderSizeError");
1307
+ }
1308
+ };
1309
+ var UnrecognizedArrayLikeSerializerSizeError = class extends Error {
1310
+ constructor(size) {
1311
+ super(`Unrecognized array-like serializer size: ${JSON.stringify(size)}`);
1312
+ __publicField(this, "name", "UnrecognizedArrayLikeSerializerSizeError");
1313
+ }
1314
+ };
1315
+
1316
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/utils.mjs
1317
+ init_env_shim();
1318
+
1319
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/sumSerializerSizes.mjs
1320
+ init_env_shim();
1321
+ function sumSerializerSizes(sizes) {
1322
+ return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
1323
+ }
1324
+
1325
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/utils.mjs
1326
+ function getResolvedSize(size, childrenSizes, bytes2, offset) {
1327
+ if (typeof size === "number") {
1328
+ return [size, offset];
1329
+ }
1330
+ if (typeof size === "object") {
1331
+ return size.deserialize(bytes2, offset);
1332
+ }
1333
+ if (size === "remainder") {
1334
+ const childrenSize = sumSerializerSizes(childrenSizes);
1335
+ if (childrenSize === null) {
1336
+ throw new ExpectedFixedSizeSerializerError('Serializers of "remainder" size must have fixed-size items.');
1337
+ }
1338
+ const remainder = bytes2.slice(offset).length;
1339
+ if (remainder % childrenSize !== 0) {
1340
+ throw new InvalidArrayLikeRemainderSizeError(remainder, childrenSize);
1341
+ }
1342
+ return [remainder / childrenSize, offset];
1343
+ }
1344
+ throw new UnrecognizedArrayLikeSerializerSizeError(size);
1345
+ }
1346
+ function getSizeDescription2(size) {
1347
+ return typeof size === "object" ? size.description : `${size}`;
1348
+ }
1349
+ function getSizeFromChildren(size, childrenSizes) {
1350
+ if (typeof size !== "number")
1351
+ return null;
1352
+ if (size === 0)
1353
+ return 0;
1354
+ const childrenSize = sumSerializerSizes(childrenSizes);
1355
+ return childrenSize === null ? null : childrenSize * size;
1356
+ }
1357
+ function getSizePrefix(size, realSize) {
1358
+ return typeof size === "object" ? size.serialize(realSize) : new Uint8Array();
1359
+ }
1360
+
1361
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/array.mjs
1362
+ function array(item, options = {}) {
1363
+ const size = options.size ?? u32();
1364
+ if (size === "remainder" && item.fixedSize === null) {
1365
+ throw new ExpectedFixedSizeSerializerError('Serializers of "remainder" size must have fixed-size items.');
1366
+ }
1367
+ return {
1368
+ description: options.description ?? `array(${item.description}; ${getSizeDescription2(size)})`,
1369
+ fixedSize: getSizeFromChildren(size, [item.fixedSize]),
1370
+ maxSize: getSizeFromChildren(size, [item.maxSize]),
1371
+ serialize: (value) => {
1372
+ if (typeof size === "number" && value.length !== size) {
1373
+ throw new InvalidNumberOfItemsError("array", size, value.length);
1374
+ }
1375
+ return mergeBytes2([getSizePrefix(size, value.length), ...value.map((v) => item.serialize(v))]);
1376
+ },
1377
+ deserialize: (bytes2, offset = 0) => {
1378
+ if (typeof size === "object" && bytes2.slice(offset).length === 0) {
1379
+ return [[], offset];
1380
+ }
1381
+ const [resolvedSize, newOffset] = getResolvedSize(size, [item.fixedSize], bytes2, offset);
1382
+ offset = newOffset;
1383
+ const values = [];
1384
+ for (let i = 0; i < resolvedSize; i += 1) {
1385
+ const [value, newOffset2] = item.deserialize(bytes2, offset);
1386
+ values.push(value);
1387
+ offset = newOffset2;
1388
+ }
1389
+ return [values, offset];
1390
+ }
1391
+ };
1392
+ }
1393
+
1394
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/bytes.mjs
1395
+ init_env_shim();
1396
+ function bytes(options = {}) {
1397
+ const size = options.size ?? "variable";
1398
+ const description = options.description ?? `bytes(${getSizeDescription2(size)})`;
1399
+ const byteSerializer = {
1400
+ description,
1401
+ fixedSize: null,
1402
+ maxSize: null,
1403
+ serialize: (value) => new Uint8Array(value),
1404
+ deserialize: (bytes2, offset = 0) => {
1405
+ const slice = bytes2.slice(offset);
1406
+ return [slice, offset + slice.length];
1407
+ }
1408
+ };
1409
+ if (size === "variable") {
1410
+ return byteSerializer;
1411
+ }
1412
+ if (typeof size === "number") {
1413
+ return fixSerializer(byteSerializer, size, description);
1414
+ }
1415
+ return {
1416
+ description,
1417
+ fixedSize: null,
1418
+ maxSize: null,
1419
+ serialize: (value) => {
1420
+ const contentBytes = byteSerializer.serialize(value);
1421
+ const lengthBytes = size.serialize(contentBytes.length);
1422
+ return mergeBytes2([lengthBytes, contentBytes]);
1423
+ },
1424
+ deserialize: (buffer, offset = 0) => {
1425
+ if (buffer.slice(offset).length === 0) {
1426
+ throw new DeserializingEmptyBufferError("bytes");
1427
+ }
1428
+ const [lengthBigInt, lengthOffset] = size.deserialize(buffer, offset);
1429
+ const length = Number(lengthBigInt);
1430
+ offset = lengthOffset;
1431
+ const contentBuffer = buffer.slice(offset, offset + length);
1432
+ if (contentBuffer.length < length) {
1433
+ throw new NotEnoughBytesError("bytes", length, contentBuffer.length);
1434
+ }
1435
+ const [value, contentOffset] = byteSerializer.deserialize(contentBuffer);
1436
+ offset += contentOffset;
1437
+ return [value, offset];
1438
+ }
1439
+ };
1440
+ }
1441
+
1442
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/string.mjs
1443
+ init_env_shim();
1444
+ function string(options = {}) {
1445
+ const size = options.size ?? u32();
1446
+ const encoding = options.encoding ?? utf8;
1447
+ const description = options.description ?? `string(${encoding.description}; ${getSizeDescription2(size)})`;
1448
+ if (size === "variable") {
1449
+ return {
1450
+ ...encoding,
1451
+ description
1452
+ };
1453
+ }
1454
+ if (typeof size === "number") {
1455
+ return fixSerializer(encoding, size, description);
1456
+ }
1457
+ return {
1458
+ description,
1459
+ fixedSize: null,
1460
+ maxSize: null,
1461
+ serialize: (value) => {
1462
+ const contentBytes = encoding.serialize(value);
1463
+ const lengthBytes = size.serialize(contentBytes.length);
1464
+ return mergeBytes2([lengthBytes, contentBytes]);
1465
+ },
1466
+ deserialize: (buffer, offset = 0) => {
1467
+ if (buffer.slice(offset).length === 0) {
1468
+ throw new DeserializingEmptyBufferError("string");
1469
+ }
1470
+ const [lengthBigInt, lengthOffset] = size.deserialize(buffer, offset);
1471
+ const length = Number(lengthBigInt);
1472
+ offset = lengthOffset;
1473
+ const contentBuffer = buffer.slice(offset, offset + length);
1474
+ if (contentBuffer.length < length) {
1475
+ throw new NotEnoughBytesError("string", length, contentBuffer.length);
1476
+ }
1477
+ const [value, contentOffset] = encoding.deserialize(contentBuffer);
1478
+ offset += contentOffset;
1479
+ return [value, offset];
1480
+ }
1481
+ };
1482
+ }
1483
+
1484
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/struct.mjs
1485
+ init_env_shim();
1486
+ function struct(fields, options = {}) {
1487
+ const fieldDescriptions = fields.map(([name, serializer]) => `${String(name)}: ${serializer.description}`).join(", ");
1488
+ return {
1489
+ description: options.description ?? `struct(${fieldDescriptions})`,
1490
+ fixedSize: sumSerializerSizes(fields.map(([, field]) => field.fixedSize)),
1491
+ maxSize: sumSerializerSizes(fields.map(([, field]) => field.maxSize)),
1492
+ serialize: (struct2) => {
1493
+ const fieldBytes = fields.map(([key, serializer]) => serializer.serialize(struct2[key]));
1494
+ return mergeBytes2(fieldBytes);
1495
+ },
1496
+ deserialize: (bytes2, offset = 0) => {
1497
+ const struct2 = {};
1498
+ fields.forEach(([key, serializer]) => {
1499
+ const [value, newOffset] = serializer.deserialize(bytes2, offset);
1500
+ offset = newOffset;
1501
+ struct2[key] = value;
1502
+ });
1503
+ return [struct2, offset];
1504
+ }
1505
+ };
1506
+ }
1507
+
1508
+ // ../codecs-data-structures/dist/index.browser.js
1509
+ init_env_shim();
1510
+ function sumCodecSizes(sizes) {
1511
+ return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
1512
+ }
1513
+ function decodeArrayLikeCodecSize(size, childrenSizes, bytes2, offset) {
1514
+ if (typeof size === "number") {
1515
+ return [size, offset];
944
1516
  }
945
- const programAddressBytes = serialize4(programAddress);
946
- if (programAddressBytes.length >= PDA_MARKER_BYTES.length && programAddressBytes.slice(-PDA_MARKER_BYTES.length).every((byte, index) => byte === PDA_MARKER_BYTES[index])) {
947
- throw new Error(`programAddress cannot end with the PDA marker`);
1517
+ if (typeof size === "object") {
1518
+ return size.decode(bytes2, offset);
948
1519
  }
949
- const addressBytesBuffer = await crypto.subtle.digest(
950
- "SHA-256",
951
- new Uint8Array([...serialize4(baseAddress), ...seedBytes, ...programAddressBytes])
952
- );
953
- const addressBytes = new Uint8Array(addressBytesBuffer);
954
- return deserialize2(addressBytes)[0];
955
- }
956
- async function getAddressFromPublicKey(publicKey) {
957
- await assertKeyExporterIsAvailable();
958
- if (publicKey.type !== "public" || publicKey.algorithm.name !== "Ed25519") {
959
- throw new Error("The `CryptoKey` must be an `Ed25519` public key");
1520
+ if (size === "remainder") {
1521
+ const childrenSize = sumCodecSizes(childrenSizes);
1522
+ if (childrenSize === null) {
1523
+ throw new Error('Codecs of "remainder" size must have fixed-size items.');
1524
+ }
1525
+ const remainder = bytes2.slice(offset).length;
1526
+ if (remainder % childrenSize !== 0) {
1527
+ throw new Error(
1528
+ `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.`
1529
+ );
1530
+ }
1531
+ return [remainder / childrenSize, offset];
960
1532
  }
961
- const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
962
- const [base58EncodedAddress] = getBase58EncodedAddressCodec().deserialize(new Uint8Array(publicKeyBytes));
963
- return base58EncodedAddress;
1533
+ throw new Error(`Unrecognized array-like codec size: ${JSON.stringify(size)}`);
964
1534
  }
965
-
966
- // ../instructions/dist/index.browser.js
967
- init_env_shim();
968
- var AccountRole = /* @__PURE__ */ ((AccountRole22) => {
969
- AccountRole22[AccountRole22["WRITABLE_SIGNER"] = /* 3 */
970
- 3] = "WRITABLE_SIGNER";
971
- AccountRole22[AccountRole22["READONLY_SIGNER"] = /* 2 */
972
- 2] = "READONLY_SIGNER";
973
- AccountRole22[AccountRole22["WRITABLE"] = /* 1 */
974
- 1] = "WRITABLE";
975
- AccountRole22[AccountRole22["READONLY"] = /* 0 */
976
- 0] = "READONLY";
977
- return AccountRole22;
978
- })(AccountRole || {});
979
- var IS_SIGNER_BITMASK = 2;
980
- var IS_WRITABLE_BITMASK = 1;
981
- function downgradeRoleToNonSigner(role) {
982
- return role & ~IS_SIGNER_BITMASK;
1535
+ function getArrayLikeCodecSizeDescription(size) {
1536
+ return typeof size === "object" ? size.description : `${size}`;
983
1537
  }
984
- function downgradeRoleToReadonly(role) {
985
- return role & ~IS_WRITABLE_BITMASK;
1538
+ function getArrayLikeCodecSizeFromChildren(size, childrenSizes) {
1539
+ if (typeof size !== "number")
1540
+ return null;
1541
+ if (size === 0)
1542
+ return 0;
1543
+ const childrenSize = sumCodecSizes(childrenSizes);
1544
+ return childrenSize === null ? null : childrenSize * size;
986
1545
  }
987
- function isSignerRole(role) {
988
- return role >= 2;
1546
+ function getArrayLikeCodecSizePrefix(size, realSize) {
1547
+ return typeof size === "object" ? size.encode(realSize) : new Uint8Array();
989
1548
  }
990
- function isWritableRole(role) {
991
- return (role & IS_WRITABLE_BITMASK) !== 0;
1549
+ function assertValidNumberOfItemsForCodec(codecDescription, expected, actual) {
1550
+ if (expected !== actual) {
1551
+ throw new Error(`Expected [${codecDescription}] to have ${expected} items, got ${actual}.`);
1552
+ }
992
1553
  }
993
- function mergeRoles(roleA, roleB) {
994
- return roleA | roleB;
1554
+ function arrayCodecHelper(item, size, description) {
1555
+ if (size === "remainder" && item.fixedSize === null) {
1556
+ throw new Error('Codecs of "remainder" size must have fixed-size items.');
1557
+ }
1558
+ return {
1559
+ description: description ?? `array(${item.description}; ${getArrayLikeCodecSizeDescription(size)})`,
1560
+ fixedSize: getArrayLikeCodecSizeFromChildren(size, [item.fixedSize]),
1561
+ maxSize: getArrayLikeCodecSizeFromChildren(size, [item.maxSize])
1562
+ };
995
1563
  }
996
- function upgradeRoleToSigner(role) {
997
- return role | IS_SIGNER_BITMASK;
1564
+ function getArrayEncoder(item, options = {}) {
1565
+ const size = options.size ?? getU32Encoder();
1566
+ return {
1567
+ ...arrayCodecHelper(item, size, options.description),
1568
+ encode: (value) => {
1569
+ if (typeof size === "number") {
1570
+ assertValidNumberOfItemsForCodec("array", size, value.length);
1571
+ }
1572
+ return mergeBytes([getArrayLikeCodecSizePrefix(size, value.length), ...value.map((v) => item.encode(v))]);
1573
+ }
1574
+ };
998
1575
  }
999
- function upgradeRoleToWritable(role) {
1000
- return role | IS_WRITABLE_BITMASK;
1576
+ function getArrayDecoder(item, options = {}) {
1577
+ const size = options.size ?? getU32Decoder();
1578
+ return {
1579
+ ...arrayCodecHelper(item, size, options.description),
1580
+ decode: (bytes2, offset = 0) => {
1581
+ if (typeof size === "object" && bytes2.slice(offset).length === 0) {
1582
+ return [[], offset];
1583
+ }
1584
+ const [resolvedSize, newOffset] = decodeArrayLikeCodecSize(size, [item.fixedSize], bytes2, offset);
1585
+ offset = newOffset;
1586
+ const values = [];
1587
+ for (let i = 0; i < resolvedSize; i += 1) {
1588
+ const [value, newOffset2] = item.decode(bytes2, offset);
1589
+ values.push(value);
1590
+ offset = newOffset2;
1591
+ }
1592
+ return [values, offset];
1593
+ }
1594
+ };
1001
1595
  }
1002
-
1003
- // ../keys/dist/index.browser.js
1004
- init_env_shim();
1005
- async function generateKeyPair() {
1006
- await assertKeyGenerationIsAvailable();
1007
- const keyPair = await crypto.subtle.generateKey(
1008
- /* algorithm */
1009
- "Ed25519",
1010
- // Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20
1011
- /* extractable */
1012
- false,
1013
- // Prevents the bytes of the private key from being visible to JS.
1014
- /* allowed uses */
1015
- ["sign", "verify"]
1016
- );
1017
- return keyPair;
1596
+ function getBytesEncoder(options = {}) {
1597
+ const size = options.size ?? "variable";
1598
+ const sizeDescription = typeof size === "object" ? size.description : `${size}`;
1599
+ const description = options.description ?? `bytes(${sizeDescription})`;
1600
+ const byteEncoder = {
1601
+ description,
1602
+ encode: (value) => value,
1603
+ fixedSize: null,
1604
+ maxSize: null
1605
+ };
1606
+ if (size === "variable") {
1607
+ return byteEncoder;
1608
+ }
1609
+ if (typeof size === "number") {
1610
+ return fixEncoder(byteEncoder, size, description);
1611
+ }
1612
+ return {
1613
+ ...byteEncoder,
1614
+ encode: (value) => {
1615
+ const contentBytes = byteEncoder.encode(value);
1616
+ const lengthBytes = size.encode(contentBytes.length);
1617
+ return mergeBytes([lengthBytes, contentBytes]);
1618
+ }
1619
+ };
1018
1620
  }
1019
- async function signBytes(key, data) {
1020
- await assertSigningCapabilityIsAvailable();
1021
- const signedData = await crypto.subtle.sign("Ed25519", key, data);
1022
- return new Uint8Array(signedData);
1621
+ function getBytesDecoder(options = {}) {
1622
+ const size = options.size ?? "variable";
1623
+ const sizeDescription = typeof size === "object" ? size.description : `${size}`;
1624
+ const description = options.description ?? `bytes(${sizeDescription})`;
1625
+ const byteDecoder = {
1626
+ decode: (bytes2, offset = 0) => {
1627
+ const slice = bytes2.slice(offset);
1628
+ return [slice, offset + slice.length];
1629
+ },
1630
+ description,
1631
+ fixedSize: null,
1632
+ maxSize: null
1633
+ };
1634
+ if (size === "variable") {
1635
+ return byteDecoder;
1636
+ }
1637
+ if (typeof size === "number") {
1638
+ return fixDecoder(byteDecoder, size, description);
1639
+ }
1640
+ return {
1641
+ ...byteDecoder,
1642
+ decode: (bytes2, offset = 0) => {
1643
+ assertByteArrayIsNotEmptyForCodec("bytes", bytes2, offset);
1644
+ const [lengthBigInt, lengthOffset] = size.decode(bytes2, offset);
1645
+ const length = Number(lengthBigInt);
1646
+ offset = lengthOffset;
1647
+ const contentBytes = bytes2.slice(offset, offset + length);
1648
+ assertByteArrayHasEnoughBytesForCodec("bytes", length, contentBytes);
1649
+ const [value, contentOffset] = byteDecoder.decode(contentBytes);
1650
+ offset += contentOffset;
1651
+ return [value, offset];
1652
+ }
1653
+ };
1023
1654
  }
1024
- async function verifySignature(key, signature, data) {
1025
- await assertVerificationCapabilityIsAvailable();
1026
- return await crypto.subtle.verify("Ed25519", key, signature, data);
1655
+ function structCodecHelper(fields, description) {
1656
+ const fieldDescriptions = fields.map(([name, codec]) => `${String(name)}: ${codec.description}`).join(", ");
1657
+ return {
1658
+ description: description ?? `struct(${fieldDescriptions})`,
1659
+ fixedSize: sumCodecSizes(fields.map(([, field]) => field.fixedSize)),
1660
+ maxSize: sumCodecSizes(fields.map(([, field]) => field.maxSize))
1661
+ };
1662
+ }
1663
+ function getStructEncoder(fields, options = {}) {
1664
+ return {
1665
+ ...structCodecHelper(fields, options.description),
1666
+ encode: (struct2) => {
1667
+ const fieldBytes = fields.map(([key, codec]) => codec.encode(struct2[key]));
1668
+ return mergeBytes(fieldBytes);
1669
+ }
1670
+ };
1671
+ }
1672
+ function getStructDecoder(fields, options = {}) {
1673
+ return {
1674
+ ...structCodecHelper(fields, options.description),
1675
+ decode: (bytes2, offset = 0) => {
1676
+ const struct2 = {};
1677
+ fields.forEach(([key, codec]) => {
1678
+ const [value, newOffset] = codec.decode(bytes2, offset);
1679
+ offset = newOffset;
1680
+ struct2[key] = value;
1681
+ });
1682
+ return [struct2, offset];
1683
+ }
1684
+ };
1685
+ }
1686
+ function getStructCodec(fields, options = {}) {
1687
+ return combineCodec(getStructEncoder(fields, options), getStructDecoder(fields, options));
1027
1688
  }
1028
-
1029
- // ../transactions/dist/index.browser.js
1030
- init_env_shim();
1031
1689
  function getUnsignedTransaction(transaction) {
1032
1690
  if ("signatures" in transaction) {
1033
1691
  const {
@@ -1049,8 +1707,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
1049
1707
  ) {
1050
1708
  throw new Error("Expected input string to decode to a byte array of length 32.");
1051
1709
  }
1052
- const bytes3 = base58.serialize(putativeBlockhash);
1053
- const numBytes = bytes3.byteLength;
1710
+ const bytes2 = base58.serialize(putativeBlockhash);
1711
+ const numBytes = bytes2.byteLength;
1054
1712
  if (numBytes !== 32) {
1055
1713
  throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
1056
1714
  }
@@ -1238,7 +1896,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
1238
1896
  const shouldReplaceEntry = (
1239
1897
  // Consider using the new LOOKUP_TABLE if its address is different...
1240
1898
  entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
1241
- (addressComparator || (addressComparator = getBase58EncodedAddressComparator()))(
1899
+ (addressComparator || (addressComparator = getAddressComparator()))(
1242
1900
  accountMeta.lookupTableAddress,
1243
1901
  entry.lookupTableAddress
1244
1902
  ) < 0
@@ -1346,7 +2004,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
1346
2004
  if (leftIsWritable !== isWritableRole2(rightEntry.role)) {
1347
2005
  return leftIsWritable ? -1 : 1;
1348
2006
  }
1349
- addressComparator || (addressComparator = getBase58EncodedAddressComparator());
2007
+ addressComparator || (addressComparator = getAddressComparator());
1350
2008
  if (leftEntry[TYPE] === 1 && rightEntry[TYPE] === 1 && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
1351
2009
  return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
1352
2010
  } else {
@@ -1375,7 +2033,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
1375
2033
  entry.readableIndices.push(account.addressIndex);
1376
2034
  }
1377
2035
  }
1378
- return Object.keys(index).sort(getBase58EncodedAddressComparator()).map((lookupTableAddress) => ({
2036
+ return Object.keys(index).sort(getAddressComparator()).map((lookupTableAddress) => ({
1379
2037
  lookupTableAddress,
1380
2038
  ...index[lookupTableAddress]
1381
2039
  }));
@@ -1444,138 +2102,177 @@ this.globalThis.solanaWeb3 = (function (exports) {
1444
2102
  version: transaction.version
1445
2103
  };
1446
2104
  }
1447
- function getAddressTableLookupCodec() {
1448
- return struct(
1449
- [
2105
+ function getCompiledTransaction(transaction) {
2106
+ const compiledMessage = compileMessage(transaction);
2107
+ let signatures;
2108
+ if ("signatures" in transaction) {
2109
+ signatures = [];
2110
+ for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
2111
+ signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
2112
+ }
2113
+ } else {
2114
+ signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
2115
+ }
2116
+ return {
2117
+ compiledMessage,
2118
+ signatures
2119
+ };
2120
+ }
2121
+ var lookupTableAddressDescription = "The address of the address lookup table account from which instruction addresses should be looked up" ;
2122
+ var writableIndicesDescription = "The indices of the accounts in the lookup table that should be loaded as writeable" ;
2123
+ var readableIndicesDescription = "The indices of the accounts in the lookup table that should be loaded as read-only" ;
2124
+ 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" ;
2125
+ var memoizedAddressTableLookupEncoder;
2126
+ function getAddressTableLookupEncoder() {
2127
+ if (!memoizedAddressTableLookupEncoder) {
2128
+ memoizedAddressTableLookupEncoder = getStructEncoder(
1450
2129
  [
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
- )
2130
+ ["lookupTableAddress", getAddressEncoder({ description: lookupTableAddressDescription })],
2131
+ [
2132
+ "writableIndices",
2133
+ getArrayEncoder(getU8Encoder(), {
2134
+ description: writableIndicesDescription,
2135
+ size: getShortU16Encoder()
2136
+ })
2137
+ ],
2138
+ [
2139
+ "readableIndices",
2140
+ getArrayEncoder(getU8Encoder(), {
2141
+ description: readableIndicesDescription,
2142
+ size: getShortU16Encoder()
2143
+ })
2144
+ ]
1457
2145
  ],
2146
+ { description: addressTableLookupDescription }
2147
+ );
2148
+ }
2149
+ return memoizedAddressTableLookupEncoder;
2150
+ }
2151
+ var memoizedAddressTableLookupDecoder;
2152
+ function getAddressTableLookupDecoder() {
2153
+ if (!memoizedAddressTableLookupDecoder) {
2154
+ memoizedAddressTableLookupDecoder = getStructDecoder(
1458
2155
  [
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
- })
2156
+ ["lookupTableAddress", getAddressDecoder({ description: lookupTableAddressDescription })],
2157
+ [
2158
+ "writableIndices",
2159
+ getArrayDecoder(getU8Decoder(), {
2160
+ description: writableIndicesDescription,
2161
+ size: getShortU16Decoder()
2162
+ })
2163
+ ],
2164
+ [
2165
+ "readableIndices",
2166
+ getArrayDecoder(getU8Decoder(), {
2167
+ description: readableIndicesDescription,
2168
+ size: getShortU16Decoder()
2169
+ })
2170
+ ]
1466
2171
  ],
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
- ]
1476
- ],
1477
- {
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
- }
1480
- );
2172
+ { description: addressTableLookupDescription }
2173
+ );
2174
+ }
2175
+ return memoizedAddressTableLookupDecoder;
1481
2176
  }
2177
+ function getAddressTableLookupCodec() {
2178
+ return combineCodec(getAddressTableLookupEncoder(), getAddressTableLookupDecoder());
2179
+ }
2180
+ var memoizedU8Codec;
2181
+ function getMemoizedU8Codec() {
2182
+ if (!memoizedU8Codec)
2183
+ memoizedU8Codec = getU8Codec();
2184
+ return memoizedU8Codec;
2185
+ }
2186
+ function getMemoizedU8CodecDescription(description) {
2187
+ const codec = getMemoizedU8Codec();
2188
+ return {
2189
+ ...codec,
2190
+ description: description ?? codec.description
2191
+ };
2192
+ }
2193
+ var numSignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction" ;
2194
+ 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" ;
2195
+ var numReadonlyNonSignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable" ;
2196
+ var messageHeaderDescription = "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses" ;
1482
2197
  function getMessageHeaderCodec() {
1483
- return struct(
2198
+ return getStructCodec(
1484
2199
  [
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
- ]
2200
+ ["numSignerAccounts", getMemoizedU8CodecDescription(numSignerAccountsDescription)],
2201
+ ["numReadonlySignerAccounts", getMemoizedU8CodecDescription(numReadonlySignerAccountsDescription)],
2202
+ ["numReadonlyNonSignerAccounts", getMemoizedU8CodecDescription(numReadonlyNonSignerAccountsDescription)]
1509
2203
  ],
1510
2204
  {
1511
- description: "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses"
1512
- }
2205
+ description: messageHeaderDescription
2206
+ }
1513
2207
  );
1514
2208
  }
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;
2209
+ var programAddressIndexDescription = "The index of the program being called, according to the well-ordered accounts list for this transaction" ;
2210
+ var accountIndexDescription = "The index of an account, according to the well-ordered accounts list for this transaction" ;
2211
+ 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" ;
2212
+ var dataDescription = "An optional buffer of data passed to the instruction" ;
2213
+ var memoizedGetInstructionEncoder;
2214
+ function getInstructionEncoder() {
2215
+ if (!memoizedGetInstructionEncoder) {
2216
+ memoizedGetInstructionEncoder = mapEncoder(
2217
+ getStructEncoder([
2218
+ ["programAddressIndex", getU8Encoder({ description: programAddressIndexDescription })],
2219
+ [
2220
+ "accountIndices",
2221
+ getArrayEncoder(getU8Encoder({ description: accountIndexDescription }), {
2222
+ description: accountIndicesDescription,
2223
+ size: getShortU16Encoder()
2224
+ })
2225
+ ],
2226
+ ["data", getBytesEncoder({ description: dataDescription, size: getShortU16Encoder() })]
2227
+ ]),
2228
+ // Convert an instruction to have all fields defined
2229
+ (instruction) => {
2230
+ if (instruction.accountIndices !== void 0 && instruction.data !== void 0) {
2231
+ return instruction;
2232
+ }
2233
+ return {
2234
+ ...instruction,
2235
+ accountIndices: instruction.accountIndices ?? [],
2236
+ data: instruction.data ?? new Uint8Array(0)
2237
+ };
1549
2238
  }
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;
2239
+ );
2240
+ }
2241
+ return memoizedGetInstructionEncoder;
2242
+ }
2243
+ var memoizedGetInstructionDecoder;
2244
+ function getInstructionDecoder() {
2245
+ if (!memoizedGetInstructionDecoder) {
2246
+ memoizedGetInstructionDecoder = mapDecoder(
2247
+ getStructDecoder([
2248
+ ["programAddressIndex", getU8Decoder({ description: programAddressIndexDescription })],
2249
+ [
2250
+ "accountIndices",
2251
+ getArrayDecoder(getU8Decoder({ description: accountIndexDescription }), {
2252
+ description: accountIndicesDescription,
2253
+ size: getShortU16Decoder()
2254
+ })
2255
+ ],
2256
+ ["data", getBytesDecoder({ description: dataDescription, size: getShortU16Decoder() })]
2257
+ ]),
2258
+ // Convert an instruction to exclude optional fields if they are empty
2259
+ (instruction) => {
2260
+ if (instruction.accountIndices.length && instruction.data.byteLength) {
2261
+ return instruction;
2262
+ }
2263
+ const { accountIndices, data, ...rest } = instruction;
2264
+ return {
2265
+ ...rest,
2266
+ ...accountIndices.length ? { accountIndices } : null,
2267
+ ...data.byteLength ? { data } : null
2268
+ };
1559
2269
  }
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
- );
2270
+ );
2271
+ }
2272
+ return memoizedGetInstructionDecoder;
1574
2273
  }
1575
- function getUnimplementedDecoder(name) {
1576
- return () => {
1577
- throw getError("decoder", name);
1578
- };
2274
+ function getInstructionCodec() {
2275
+ return combineCodec(getInstructionEncoder(), getInstructionDecoder());
1579
2276
  }
1580
2277
  var VERSION_FLAG_MASK = 128;
1581
2278
  var BASE_CONFIG = {
@@ -1583,8 +2280,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
1583
2280
  fixedSize: null,
1584
2281
  maxSize: 1
1585
2282
  };
1586
- function deserialize(bytes3, offset = 0) {
1587
- const firstByte = bytes3[offset];
2283
+ function decode(bytes2, offset = 0) {
2284
+ const firstByte = bytes2[offset];
1588
2285
  if ((firstByte & VERSION_FLAG_MASK) === 0) {
1589
2286
  return ["legacy", offset];
1590
2287
  } else {
@@ -1592,7 +2289,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
1592
2289
  return [version, offset + 1];
1593
2290
  }
1594
2291
  }
1595
- function serialize(value) {
2292
+ function encode(value) {
1596
2293
  if (value === "legacy") {
1597
2294
  return new Uint8Array();
1598
2295
  }
@@ -1601,11 +2298,30 @@ this.globalThis.solanaWeb3 = (function (exports) {
1601
2298
  }
1602
2299
  return new Uint8Array([value | VERSION_FLAG_MASK]);
1603
2300
  }
1604
- function getTransactionVersionCodec() {
2301
+ function getTransactionVersionDecoder() {
2302
+ return {
2303
+ ...BASE_CONFIG,
2304
+ decode
2305
+ };
2306
+ }
2307
+ function getTransactionVersionEncoder() {
1605
2308
  return {
1606
2309
  ...BASE_CONFIG,
1607
- deserialize,
1608
- serialize
2310
+ encode
2311
+ };
2312
+ }
2313
+ function getTransactionVersionCodec() {
2314
+ return combineCodec(getTransactionVersionEncoder(), getTransactionVersionDecoder());
2315
+ }
2316
+ function getError(type, name) {
2317
+ const functionSuffix = name + type[0].toUpperCase() + type.slice(1);
2318
+ return new Error(
2319
+ `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}`
2320
+ );
2321
+ }
2322
+ function getUnimplementedDecoder(name) {
2323
+ return () => {
2324
+ throw getError("decoder", name);
1609
2325
  };
1610
2326
  }
1611
2327
  var BASE_CONFIG2 = {
@@ -1613,7 +2329,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
1613
2329
  fixedSize: null,
1614
2330
  maxSize: null
1615
2331
  };
1616
- function serialize2(compiledMessage) {
2332
+ function serialize(compiledMessage) {
1617
2333
  if (compiledMessage.version === "legacy") {
1618
2334
  return struct(getPreludeStructSerializerTuple()).serialize(compiledMessage);
1619
2335
  } else {
@@ -1634,13 +2350,22 @@ this.globalThis.solanaWeb3 = (function (exports) {
1634
2350
  ).serialize(compiledMessage);
1635
2351
  }
1636
2352
  }
2353
+ function toSerializer(codec) {
2354
+ return {
2355
+ description: codec.description,
2356
+ deserialize: codec.decode,
2357
+ fixedSize: codec.fixedSize,
2358
+ maxSize: codec.maxSize,
2359
+ serialize: codec.encode
2360
+ };
2361
+ }
1637
2362
  function getPreludeStructSerializerTuple() {
1638
2363
  return [
1639
- ["version", getTransactionVersionCodec()],
1640
- ["header", getMessageHeaderCodec()],
2364
+ ["version", toSerializer(getTransactionVersionCodec())],
2365
+ ["header", toSerializer(getMessageHeaderCodec())],
1641
2366
  [
1642
2367
  "staticAccounts",
1643
- array(getBase58EncodedAddressCodec(), {
2368
+ array(toSerializer(getAddressCodec()), {
1644
2369
  description: "A compact-array of static account addresses belonging to this transaction" ,
1645
2370
  size: shortU16()
1646
2371
  })
@@ -1655,7 +2380,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
1655
2380
  ],
1656
2381
  [
1657
2382
  "instructions",
1658
- array(getInstructionCodec(), {
2383
+ array(toSerializer(getInstructionCodec()), {
1659
2384
  description: "A compact-array of instructions belonging to this transaction" ,
1660
2385
  size: shortU16()
1661
2386
  })
@@ -1663,7 +2388,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
1663
2388
  ];
1664
2389
  }
1665
2390
  function getAddressTableLookupsSerializer() {
1666
- return array(getAddressTableLookupCodec(), {
2391
+ return array(toSerializer(getAddressTableLookupCodec()), {
1667
2392
  ...{ description: "A compact array of address table lookups belonging to this transaction" } ,
1668
2393
  size: shortU16()
1669
2394
  });
@@ -1672,14 +2397,84 @@ this.globalThis.solanaWeb3 = (function (exports) {
1672
2397
  return {
1673
2398
  ...BASE_CONFIG2,
1674
2399
  deserialize: getUnimplementedDecoder("CompiledMessage"),
2400
+ serialize
2401
+ };
2402
+ }
2403
+ var BASE_CONFIG3 = {
2404
+ description: "The wire format of a Solana transaction" ,
2405
+ fixedSize: null,
2406
+ maxSize: null
2407
+ };
2408
+ function serialize2(transaction) {
2409
+ const compiledTransaction = getCompiledTransaction(transaction);
2410
+ return struct([
2411
+ [
2412
+ "signatures",
2413
+ array(bytes({ size: 64 }), {
2414
+ ...{ description: "A compact array of 64-byte, base-64 encoded Ed25519 signatures" } ,
2415
+ size: shortU16()
2416
+ })
2417
+ ],
2418
+ ["compiledMessage", getCompiledMessageEncoder()]
2419
+ ]).serialize(compiledTransaction);
2420
+ }
2421
+ function getTransactionEncoder() {
2422
+ return {
2423
+ ...BASE_CONFIG3,
2424
+ deserialize: getUnimplementedDecoder("CompiledMessage"),
1675
2425
  serialize: serialize2
1676
2426
  };
1677
2427
  }
2428
+ function assertIsTransactionSignature(putativeTransactionSignature) {
2429
+ try {
2430
+ if (
2431
+ // Lowest value (64 bytes of zeroes)
2432
+ putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
2433
+ putativeTransactionSignature.length > 88
2434
+ ) {
2435
+ throw new Error("Expected input string to decode to a byte array of length 64.");
2436
+ }
2437
+ const bytes2 = base58.serialize(putativeTransactionSignature);
2438
+ const numBytes = bytes2.byteLength;
2439
+ if (numBytes !== 64) {
2440
+ throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
2441
+ }
2442
+ } catch (e3) {
2443
+ throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
2444
+ cause: e3
2445
+ });
2446
+ }
2447
+ }
2448
+ function isTransactionSignature(putativeTransactionSignature) {
2449
+ if (
2450
+ // Lowest value (64 bytes of zeroes)
2451
+ putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
2452
+ putativeTransactionSignature.length > 88
2453
+ ) {
2454
+ return false;
2455
+ }
2456
+ const bytes2 = base58.serialize(putativeTransactionSignature);
2457
+ const numBytes = bytes2.byteLength;
2458
+ if (numBytes !== 64) {
2459
+ return false;
2460
+ }
2461
+ return true;
2462
+ }
1678
2463
  async function getCompiledMessageSignature(message, secretKey) {
1679
2464
  const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
1680
2465
  const signature = await signBytes(secretKey, wireMessageBytes);
1681
2466
  return signature;
1682
2467
  }
2468
+ function getSignatureFromTransaction(transaction) {
2469
+ const signatureBytes = transaction.signatures[transaction.feePayer];
2470
+ if (!signatureBytes) {
2471
+ throw new Error(
2472
+ "Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
2473
+ );
2474
+ }
2475
+ const transactionSignature2 = base58.deserialize(signatureBytes)[0];
2476
+ return transactionSignature2;
2477
+ }
1683
2478
  async function signTransaction(keyPairs, transaction) {
1684
2479
  const compiledMessage = compileMessage(transaction);
1685
2480
  const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
@@ -1689,165 +2484,323 @@ this.globalThis.solanaWeb3 = (function (exports) {
1689
2484
  getAddressFromPublicKey(keyPair.publicKey),
1690
2485
  getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
1691
2486
  ])
1692
- )
1693
- );
1694
- for (const [signerPublicKey, signature] of publicKeySignaturePairs) {
1695
- nextSignatures[signerPublicKey] = signature;
1696
- }
1697
- const out = {
1698
- ...transaction,
1699
- signatures: nextSignatures
1700
- };
1701
- Object.freeze(out);
1702
- return out;
1703
- }
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));
1711
- }
1712
- } else {
1713
- signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
1714
- }
1715
- return {
1716
- compiledMessage,
1717
- signatures
1718
- };
1719
- }
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);
1737
- }
1738
- function getTransactionEncoder() {
1739
- return {
1740
- ...BASE_CONFIG3,
1741
- deserialize: getUnimplementedDecoder("CompiledMessage"),
1742
- serialize: serialize3
1743
- };
1744
- }
1745
- function getBase64EncodedWireTransaction(transaction) {
1746
- const wireTransactionBytes = getTransactionEncoder().serialize(transaction);
1747
- {
1748
- return btoa(String.fromCharCode(...wireTransactionBytes));
1749
- }
1750
- }
1751
-
1752
- // src/rpc.ts
1753
- init_env_shim();
1754
-
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
- // ../rpc-core/dist/index.browser.js
1762
- init_env_shim();
1763
- function visitNode(value, keyPath, onIntegerOverflow) {
1764
- if (Array.isArray(value)) {
1765
- return value.map(
1766
- (element, ii) => visitNode(element, [...keyPath, ii], onIntegerOverflow)
1767
- );
1768
- } else if (typeof value === "object" && value !== null) {
1769
- const out = {};
1770
- for (const propName in value) {
1771
- if (Object.prototype.hasOwnProperty.call(value, propName)) {
1772
- out[propName] = visitNode(value[propName], [...keyPath, propName], onIntegerOverflow);
1773
- }
1774
- }
1775
- return out;
1776
- } else if (typeof value === "bigint") {
1777
- if (onIntegerOverflow && (value > Number.MAX_SAFE_INTEGER || value < -Number.MAX_SAFE_INTEGER)) {
1778
- onIntegerOverflow(keyPath, value);
1779
- }
1780
- return Number(value);
1781
- } else {
1782
- return value;
1783
- }
1784
- }
1785
- function patchParamsForSolanaLabsRpc(params, onIntegerOverflow) {
1786
- return visitNode(params, [], onIntegerOverflow);
1787
- }
1788
- var KEYPATH_WILDCARD = {};
1789
- var memoizedNotificationKeypaths;
1790
- var memoizedResponseKeypaths;
1791
- function getAllowedNumericKeypathsForNotification() {
1792
- if (!memoizedNotificationKeypaths) {
1793
- memoizedNotificationKeypaths = {};
2487
+ )
2488
+ );
2489
+ for (const [signerPublicKey, signature] of publicKeySignaturePairs) {
2490
+ nextSignatures[signerPublicKey] = signature;
2491
+ }
2492
+ const out = {
2493
+ ...transaction,
2494
+ signatures: nextSignatures
2495
+ };
2496
+ Object.freeze(out);
2497
+ return out;
2498
+ }
2499
+ function transactionSignature(putativeTransactionSignature) {
2500
+ assertIsTransactionSignature(putativeTransactionSignature);
2501
+ return putativeTransactionSignature;
2502
+ }
2503
+ function getBase64EncodedWireTransaction(transaction) {
2504
+ const wireTransactionBytes = getTransactionEncoder().serialize(transaction);
2505
+ {
2506
+ return btoa(String.fromCharCode(...wireTransactionBytes));
2507
+ }
2508
+ }
2509
+
2510
+ // src/airdrop.ts
2511
+ init_env_shim();
2512
+
2513
+ // src/airdrop-confirmer.ts
2514
+ init_env_shim();
2515
+
2516
+ // src/transaction-confirmation-strategy-racer.ts
2517
+ init_env_shim();
2518
+ async function raceStrategies(signature, config, getSpecificStrategiesForRace) {
2519
+ const { abortSignal: callerAbortSignal, commitment, getRecentSignatureConfirmationPromise } = config;
2520
+ callerAbortSignal.throwIfAborted();
2521
+ const abortController = new AbortController();
2522
+ function handleAbort() {
2523
+ abortController.abort();
2524
+ }
2525
+ callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
2526
+ try {
2527
+ const specificStrategies = getSpecificStrategiesForRace({
2528
+ ...config,
2529
+ abortSignal: abortController.signal
2530
+ });
2531
+ return await Promise.race([
2532
+ getRecentSignatureConfirmationPromise({
2533
+ abortSignal: abortController.signal,
2534
+ commitment,
2535
+ signature
2536
+ }),
2537
+ ...specificStrategies
2538
+ ]);
2539
+ } finally {
2540
+ abortController.abort();
2541
+ }
2542
+ }
2543
+
2544
+ // src/transaction-confirmation-strategy-recent-signature.ts
2545
+ init_env_shim();
2546
+
2547
+ // ../rpc-core/dist/index.browser.js
2548
+ init_env_shim();
2549
+ function getCommitmentScore(commitment) {
2550
+ switch (commitment) {
2551
+ case "finalized":
2552
+ return 2;
2553
+ case "confirmed":
2554
+ return 1;
2555
+ case "processed":
2556
+ return 0;
2557
+ default:
2558
+ return ((_) => {
2559
+ throw new Error(`Unrecognized commitment \`${commitment}\`.`);
2560
+ })();
2561
+ }
2562
+ }
2563
+ function commitmentComparator(a, b) {
2564
+ if (a === b) {
2565
+ return 0;
2566
+ }
2567
+ return getCommitmentScore(a) < getCommitmentScore(b) ? -1 : 1;
2568
+ }
2569
+ function visitNode(value, keyPath, onIntegerOverflow) {
2570
+ if (Array.isArray(value)) {
2571
+ return value.map(
2572
+ (element, ii) => visitNode(element, [...keyPath, ii], onIntegerOverflow)
2573
+ );
2574
+ } else if (typeof value === "object" && value !== null) {
2575
+ const out = {};
2576
+ for (const propName in value) {
2577
+ if (Object.prototype.hasOwnProperty.call(value, propName)) {
2578
+ out[propName] = visitNode(value[propName], [...keyPath, propName], onIntegerOverflow);
2579
+ }
2580
+ }
2581
+ return out;
2582
+ } else if (typeof value === "bigint") {
2583
+ if (onIntegerOverflow && (value > Number.MAX_SAFE_INTEGER || value < -Number.MAX_SAFE_INTEGER)) {
2584
+ onIntegerOverflow(keyPath, value);
2585
+ }
2586
+ return Number(value);
2587
+ } else {
2588
+ return value;
2589
+ }
2590
+ }
2591
+ function patchParamsForSolanaLabsRpc(params, onIntegerOverflow) {
2592
+ return visitNode(params, [], onIntegerOverflow);
2593
+ }
2594
+ var KEYPATH_WILDCARD = {};
2595
+ var jsonParsedTokenAccountsConfigs = [
2596
+ // parsed Token/Token22 token account
2597
+ ["data", "parsed", "info", "tokenAmount", "decimals"],
2598
+ ["data", "parsed", "info", "tokenAmount", "uiAmount"],
2599
+ ["data", "parsed", "info", "rentExemptReserve", "decimals"],
2600
+ ["data", "parsed", "info", "rentExemptReserve", "uiAmount"],
2601
+ ["data", "parsed", "info", "delegatedAmount", "decimals"],
2602
+ ["data", "parsed", "info", "delegatedAmount", "uiAmount"],
2603
+ ["data", "parsed", "info", "extensions", KEYPATH_WILDCARD, "state", "olderTransferFee", "transferFeeBasisPoints"],
2604
+ ["data", "parsed", "info", "extensions", KEYPATH_WILDCARD, "state", "newerTransferFee", "transferFeeBasisPoints"],
2605
+ ["data", "parsed", "info", "extensions", KEYPATH_WILDCARD, "state", "preUpdateAverageRate"],
2606
+ ["data", "parsed", "info", "extensions", KEYPATH_WILDCARD, "state", "currentRate"]
2607
+ ];
2608
+ var jsonParsedAccountsConfigs = [
2609
+ ...jsonParsedTokenAccountsConfigs,
2610
+ // parsed AddressTableLookup account
2611
+ ["data", "parsed", "info", "lastExtendedSlotStartIndex"],
2612
+ // parsed Config account
2613
+ ["data", "parsed", "info", "slashPenalty"],
2614
+ ["data", "parsed", "info", "warmupCooldownRate"],
2615
+ // parsed Token/Token22 mint account
2616
+ ["data", "parsed", "info", "decimals"],
2617
+ // parsed Token/Token22 multisig account
2618
+ ["data", "parsed", "info", "numRequiredSigners"],
2619
+ ["data", "parsed", "info", "numValidSigners"],
2620
+ // parsed Stake account
2621
+ ["data", "parsed", "info", "stake", "delegation", "warmupCooldownRate"],
2622
+ // parsed Sysvar rent account
2623
+ ["data", "parsed", "info", "exemptionThreshold"],
2624
+ ["data", "parsed", "info", "burnPercent"],
2625
+ // parsed Vote account
2626
+ ["data", "parsed", "info", "commission"],
2627
+ ["data", "parsed", "info", "votes", KEYPATH_WILDCARD, "confirmationCount"]
2628
+ ];
2629
+ var memoizedNotificationKeypaths;
2630
+ var memoizedResponseKeypaths;
2631
+ function getAllowedNumericKeypathsForNotification() {
2632
+ if (!memoizedNotificationKeypaths) {
2633
+ memoizedNotificationKeypaths = {
2634
+ accountNotifications: jsonParsedAccountsConfigs.map((c) => ["value", ...c]),
2635
+ blockNotifications: [
2636
+ ["value", "block", "blockTime"],
2637
+ [
2638
+ "value",
2639
+ "block",
2640
+ "transactions",
2641
+ KEYPATH_WILDCARD,
2642
+ "meta",
2643
+ "preTokenBalances",
2644
+ KEYPATH_WILDCARD,
2645
+ "accountIndex"
2646
+ ],
2647
+ [
2648
+ "value",
2649
+ "block",
2650
+ "transactions",
2651
+ KEYPATH_WILDCARD,
2652
+ "meta",
2653
+ "preTokenBalances",
2654
+ KEYPATH_WILDCARD,
2655
+ "uiTokenAmount",
2656
+ "decimals"
2657
+ ],
2658
+ [
2659
+ "value",
2660
+ "block",
2661
+ "transactions",
2662
+ KEYPATH_WILDCARD,
2663
+ "meta",
2664
+ "postTokenBalances",
2665
+ KEYPATH_WILDCARD,
2666
+ "accountIndex"
2667
+ ],
2668
+ [
2669
+ "value",
2670
+ "block",
2671
+ "transactions",
2672
+ KEYPATH_WILDCARD,
2673
+ "meta",
2674
+ "postTokenBalances",
2675
+ KEYPATH_WILDCARD,
2676
+ "uiTokenAmount",
2677
+ "decimals"
2678
+ ],
2679
+ ["value", "block", "transactions", KEYPATH_WILDCARD, "meta", "rewards", KEYPATH_WILDCARD, "commission"],
2680
+ [
2681
+ "value",
2682
+ "block",
2683
+ "transactions",
2684
+ KEYPATH_WILDCARD,
2685
+ "meta",
2686
+ "innerInstructions",
2687
+ KEYPATH_WILDCARD,
2688
+ "index"
2689
+ ],
2690
+ [
2691
+ "value",
2692
+ "block",
2693
+ "transactions",
2694
+ KEYPATH_WILDCARD,
2695
+ "meta",
2696
+ "innerInstructions",
2697
+ KEYPATH_WILDCARD,
2698
+ "instructions",
2699
+ KEYPATH_WILDCARD,
2700
+ "programIdIndex"
2701
+ ],
2702
+ [
2703
+ "value",
2704
+ "block",
2705
+ "transactions",
2706
+ KEYPATH_WILDCARD,
2707
+ "meta",
2708
+ "innerInstructions",
2709
+ KEYPATH_WILDCARD,
2710
+ "instructions",
2711
+ KEYPATH_WILDCARD,
2712
+ "accounts",
2713
+ KEYPATH_WILDCARD
2714
+ ],
2715
+ [
2716
+ "value",
2717
+ "block",
2718
+ "transactions",
2719
+ KEYPATH_WILDCARD,
2720
+ "transaction",
2721
+ "message",
2722
+ "addressTableLookups",
2723
+ KEYPATH_WILDCARD,
2724
+ "writableIndexes",
2725
+ KEYPATH_WILDCARD
2726
+ ],
2727
+ [
2728
+ "value",
2729
+ "block",
2730
+ "transactions",
2731
+ KEYPATH_WILDCARD,
2732
+ "transaction",
2733
+ "message",
2734
+ "addressTableLookups",
2735
+ KEYPATH_WILDCARD,
2736
+ "readonlyIndexes",
2737
+ KEYPATH_WILDCARD
2738
+ ],
2739
+ [
2740
+ "value",
2741
+ "block",
2742
+ "transactions",
2743
+ KEYPATH_WILDCARD,
2744
+ "transaction",
2745
+ "message",
2746
+ "instructions",
2747
+ KEYPATH_WILDCARD,
2748
+ "programIdIndex"
2749
+ ],
2750
+ [
2751
+ "value",
2752
+ "block",
2753
+ "transactions",
2754
+ KEYPATH_WILDCARD,
2755
+ "transaction",
2756
+ "message",
2757
+ "instructions",
2758
+ KEYPATH_WILDCARD,
2759
+ "accounts",
2760
+ KEYPATH_WILDCARD
2761
+ ],
2762
+ [
2763
+ "value",
2764
+ "block",
2765
+ "transactions",
2766
+ KEYPATH_WILDCARD,
2767
+ "transaction",
2768
+ "message",
2769
+ "header",
2770
+ "numReadonlySignedAccounts"
2771
+ ],
2772
+ [
2773
+ "value",
2774
+ "block",
2775
+ "transactions",
2776
+ KEYPATH_WILDCARD,
2777
+ "transaction",
2778
+ "message",
2779
+ "header",
2780
+ "numReadonlyUnsignedAccounts"
2781
+ ],
2782
+ [
2783
+ "value",
2784
+ "block",
2785
+ "transactions",
2786
+ KEYPATH_WILDCARD,
2787
+ "transaction",
2788
+ "message",
2789
+ "header",
2790
+ "numRequiredSignatures"
2791
+ ],
2792
+ ["value", "block", "rewards", KEYPATH_WILDCARD, "commission"]
2793
+ ],
2794
+ programNotifications: jsonParsedAccountsConfigs.flatMap((c) => [
2795
+ ["value", KEYPATH_WILDCARD, "account", ...c],
2796
+ [KEYPATH_WILDCARD, "account", ...c]
2797
+ ])
2798
+ };
1794
2799
  }
1795
2800
  return memoizedNotificationKeypaths;
1796
2801
  }
1797
2802
  function getAllowedNumericKeypathsForResponse() {
1798
2803
  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
2804
  memoizedResponseKeypaths = {
1852
2805
  getAccountInfo: jsonParsedAccountsConfigs.map((c) => ["value", ...c]),
1853
2806
  getBlock: [
@@ -2112,6 +3065,147 @@ this.globalThis.solanaWeb3 = (function (exports) {
2112
3065
  }
2113
3066
  });
2114
3067
  }
3068
+ function createSolanaRpcSubscriptionsApi_UNSTABLE(config) {
3069
+ return createSolanaRpcSubscriptionsApi(config);
3070
+ }
3071
+
3072
+ // src/transaction-confirmation-strategy-recent-signature.ts
3073
+ function createRecentSignatureConfirmationPromiseFactory(rpc, rpcSubscriptions) {
3074
+ return async function getRecentSignatureConfirmationPromise({
3075
+ abortSignal: callerAbortSignal,
3076
+ commitment,
3077
+ signature
3078
+ }) {
3079
+ const abortController = new AbortController();
3080
+ function handleAbort() {
3081
+ abortController.abort();
3082
+ }
3083
+ callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
3084
+ const signatureStatusNotifications = await rpcSubscriptions.signatureNotifications(signature, { commitment }).subscribe({ abortSignal: abortController.signal });
3085
+ const signatureDidCommitPromise = (async () => {
3086
+ for await (const signatureStatusNotification of signatureStatusNotifications) {
3087
+ if (signatureStatusNotification.value.err) {
3088
+ throw new Error(`The transaction with signature \`${signature}\` failed.`, {
3089
+ cause: signatureStatusNotification.value.err
3090
+ });
3091
+ } else {
3092
+ return;
3093
+ }
3094
+ }
3095
+ })();
3096
+ const signatureStatusLookupPromise = (async () => {
3097
+ const { value: signatureStatusResults } = await rpc.getSignatureStatuses([signature]).send({ abortSignal: abortController.signal });
3098
+ const signatureStatus = signatureStatusResults[0];
3099
+ if (signatureStatus && signatureStatus.confirmationStatus && commitmentComparator(signatureStatus.confirmationStatus, commitment) >= 0) {
3100
+ return;
3101
+ } else {
3102
+ await new Promise(() => {
3103
+ });
3104
+ }
3105
+ })();
3106
+ try {
3107
+ return await Promise.race([signatureDidCommitPromise, signatureStatusLookupPromise]);
3108
+ } finally {
3109
+ abortController.abort();
3110
+ }
3111
+ };
3112
+ }
3113
+
3114
+ // src/transaction-confirmation-strategy-timeout.ts
3115
+ init_env_shim();
3116
+ async function getTimeoutPromise({ abortSignal: callerAbortSignal, commitment }) {
3117
+ return await new Promise((_, reject) => {
3118
+ const handleAbort = (e3) => {
3119
+ clearTimeout(timeoutId);
3120
+ const abortError = new DOMException(e3.target.reason, "AbortError");
3121
+ reject(abortError);
3122
+ };
3123
+ callerAbortSignal.addEventListener("abort", handleAbort);
3124
+ const timeoutMs = commitment === "processed" ? 3e4 : 6e4;
3125
+ const startMs = performance.now();
3126
+ const timeoutId = (
3127
+ // We use `setTimeout` instead of `AbortSignal.timeout()` because we want to measure
3128
+ // elapsed time instead of active time.
3129
+ // See https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/timeout_static
3130
+ setTimeout(() => {
3131
+ const elapsedMs = performance.now() - startMs;
3132
+ reject(new DOMException(`Timeout elapsed after ${elapsedMs} ms`, "TimeoutError"));
3133
+ }, timeoutMs)
3134
+ );
3135
+ });
3136
+ }
3137
+
3138
+ // src/airdrop-confirmer.ts
3139
+ function createDefaultSignatureOnlyRecentTransactionConfirmer({
3140
+ rpc,
3141
+ rpcSubscriptions
3142
+ }) {
3143
+ const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
3144
+ rpc,
3145
+ rpcSubscriptions
3146
+ );
3147
+ return async function confirmSignatureOnlyRecentTransaction(config) {
3148
+ await waitForRecentTransactionConfirmationUntilTimeout({
3149
+ ...config,
3150
+ getRecentSignatureConfirmationPromise,
3151
+ getTimeoutPromise
3152
+ });
3153
+ };
3154
+ }
3155
+ async function waitForRecentTransactionConfirmationUntilTimeout(config) {
3156
+ await raceStrategies(
3157
+ config.signature,
3158
+ config,
3159
+ function getSpecificStrategiesForRace({ abortSignal, commitment, getTimeoutPromise: getTimeoutPromise2 }) {
3160
+ return [
3161
+ getTimeoutPromise2({
3162
+ abortSignal,
3163
+ commitment
3164
+ })
3165
+ ];
3166
+ }
3167
+ );
3168
+ }
3169
+
3170
+ // src/airdrop.ts
3171
+ function createDefaultAirdropRequester({ rpc, rpcSubscriptions }) {
3172
+ const confirmSignatureOnlyTransaction = createDefaultSignatureOnlyRecentTransactionConfirmer({
3173
+ rpc,
3174
+ rpcSubscriptions
3175
+ });
3176
+ return async function requestAirdrop(config) {
3177
+ return await requestAndConfirmAirdrop({
3178
+ ...config,
3179
+ confirmSignatureOnlyTransaction,
3180
+ rpc
3181
+ });
3182
+ };
3183
+ }
3184
+ async function requestAndConfirmAirdrop({
3185
+ abortSignal,
3186
+ commitment,
3187
+ confirmSignatureOnlyTransaction,
3188
+ lamports,
3189
+ recipientAddress,
3190
+ rpc
3191
+ }) {
3192
+ const airdropTransactionSignature = await rpc.requestAirdrop(recipientAddress, lamports, { commitment }).send({ abortSignal });
3193
+ await confirmSignatureOnlyTransaction({
3194
+ abortSignal,
3195
+ commitment,
3196
+ signature: airdropTransactionSignature
3197
+ });
3198
+ return airdropTransactionSignature;
3199
+ }
3200
+
3201
+ // src/rpc.ts
3202
+ init_env_shim();
3203
+
3204
+ // ../functional/dist/index.browser.js
3205
+ init_env_shim();
3206
+ function pipe(init, ...fns) {
3207
+ return fns.reduce((acc, fn) => fn(acc), init);
3208
+ }
2115
3209
 
2116
3210
  // ../rpc-transport/dist/index.browser.js
2117
3211
  init_env_shim();
@@ -2272,7 +3366,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
2272
3366
  function createJsonSubscriptionRpc(rpcConfig) {
2273
3367
  return makeProxy2(rpcConfig);
2274
3368
  }
2275
- var e = globalThis.fetch;
3369
+ var e2 = globalThis.fetch;
2276
3370
  var SolanaHttpError = class extends Error {
2277
3371
  constructor(details) {
2278
3372
  super(`HTTP error (${details.statusCode}): ${details.message}`);
@@ -2360,7 +3454,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
2360
3454
  method: "POST",
2361
3455
  signal
2362
3456
  };
2363
- const response = await e(url, requestInfo);
3457
+ const response = await e2(url, requestInfo);
2364
3458
  if (!response.ok) {
2365
3459
  throw new SolanaHttpError({
2366
3460
  message: response.statusText,
@@ -2370,7 +3464,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
2370
3464
  return await response.json();
2371
3465
  };
2372
3466
  }
2373
- var e2 = globalThis.WebSocket;
3467
+ var e22 = globalThis.WebSocket;
2374
3468
  var EXPLICIT_ABORT_TOKEN = Symbol(
2375
3469
  "This symbol is thrown from a socket's iterator when the connection is explicity aborted by the user"
2376
3470
  );
@@ -2394,7 +3488,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
2394
3488
  }
2395
3489
  function handleAbort() {
2396
3490
  errorAndClearAllIteratorStates(EXPLICIT_ABORT_TOKEN);
2397
- if (webSocket.readyState !== e2.CLOSED && webSocket.readyState !== e2.CLOSING) {
3491
+ if (webSocket.readyState !== e22.CLOSED && webSocket.readyState !== e22.CLOSING) {
2398
3492
  webSocket.close(1e3);
2399
3493
  }
2400
3494
  }
@@ -2422,11 +3516,11 @@ this.globalThis.solanaWeb3 = (function (exports) {
2422
3516
  resolve({
2423
3517
  async send(payload) {
2424
3518
  const message = JSON.stringify(payload);
2425
- if (!bufferDrainWatcher && webSocket.readyState === e2.OPEN && webSocket.bufferedAmount > sendBufferHighWatermark) {
3519
+ if (!bufferDrainWatcher && webSocket.readyState === e22.OPEN && webSocket.bufferedAmount > sendBufferHighWatermark) {
2426
3520
  let onCancel;
2427
3521
  const promise = new Promise((resolve2, reject2) => {
2428
3522
  const intervalId = setInterval(() => {
2429
- if (webSocket.readyState !== e2.OPEN || !(webSocket.bufferedAmount > sendBufferHighWatermark)) {
3523
+ if (webSocket.readyState !== e22.OPEN || !(webSocket.bufferedAmount > sendBufferHighWatermark)) {
2430
3524
  clearInterval(intervalId);
2431
3525
  bufferDrainWatcher = void 0;
2432
3526
  resolve2();
@@ -2507,7 +3601,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
2507
3601
  }
2508
3602
  });
2509
3603
  }
2510
- const webSocket = new e2(url);
3604
+ const webSocket = new e22(url);
2511
3605
  webSocket.addEventListener("close", handleClose);
2512
3606
  webSocket.addEventListener("error", handleError);
2513
3607
  webSocket.addEventListener("open", handleOpen);
@@ -2790,6 +3884,12 @@ this.globalThis.solanaWeb3 = (function (exports) {
2790
3884
  })
2791
3885
  );
2792
3886
  }
3887
+ function createSolanaRpcSubscriptions_UNSTABLE(config) {
3888
+ return createJsonSubscriptionRpc({
3889
+ ...config,
3890
+ api: createSolanaRpcSubscriptionsApi_UNSTABLE(DEFAULT_RPC_CONFIG)
3891
+ });
3892
+ }
2793
3893
 
2794
3894
  // src/rpc-transport.ts
2795
3895
  init_env_shim();
@@ -2991,39 +4091,334 @@ this.globalThis.solanaWeb3 = (function (exports) {
2991
4091
  );
2992
4092
  }
2993
4093
 
4094
+ // src/send-transaction.ts
4095
+ init_env_shim();
4096
+
4097
+ // src/transaction-confirmation.ts
4098
+ init_env_shim();
4099
+
4100
+ // src/transaction-confirmation-strategy-blockheight.ts
4101
+ init_env_shim();
4102
+ function createBlockHeightExceedencePromiseFactory(rpcSubscriptions) {
4103
+ return async function getBlockHeightExceedencePromise({ abortSignal: callerAbortSignal, lastValidBlockHeight }) {
4104
+ const abortController = new AbortController();
4105
+ function handleAbort() {
4106
+ abortController.abort();
4107
+ }
4108
+ callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
4109
+ const slotNotifications = await rpcSubscriptions.slotNotifications().subscribe({ abortSignal: abortController.signal });
4110
+ try {
4111
+ for await (const slotNotification of slotNotifications) {
4112
+ if (slotNotification.slot > lastValidBlockHeight) {
4113
+ throw new Error(
4114
+ "The network has progressed past the last block for which this transaction could have committed."
4115
+ );
4116
+ }
4117
+ }
4118
+ } finally {
4119
+ abortController.abort();
4120
+ }
4121
+ };
4122
+ }
4123
+
4124
+ // src/transaction-confirmation-strategy-nonce.ts
4125
+ init_env_shim();
4126
+ var NONCE_VALUE_OFFSET = 4 + // version(u32)
4127
+ 4 + // state(u32)
4128
+ 32;
4129
+ function createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions) {
4130
+ return async function getNonceInvalidationPromise({
4131
+ abortSignal: callerAbortSignal,
4132
+ commitment,
4133
+ currentNonceValue,
4134
+ nonceAccountAddress
4135
+ }) {
4136
+ const abortController = new AbortController();
4137
+ function handleAbort() {
4138
+ abortController.abort();
4139
+ }
4140
+ callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
4141
+ const accountNotifications = await rpcSubscriptions.accountNotifications(nonceAccountAddress, { commitment, encoding: "base64" }).subscribe({ abortSignal: abortController.signal });
4142
+ function getNonceFromAccountData([base64EncodedBytes]) {
4143
+ const data = base64.serialize(base64EncodedBytes);
4144
+ const nonceValueBytes = data.slice(NONCE_VALUE_OFFSET, NONCE_VALUE_OFFSET + 32);
4145
+ return base58.deserialize(nonceValueBytes)[0];
4146
+ }
4147
+ const nonceAccountDidAdvancePromise = (async () => {
4148
+ for await (const accountNotification of accountNotifications) {
4149
+ const nonceValue = getNonceFromAccountData(accountNotification.value.data);
4150
+ if (nonceValue !== currentNonceValue) {
4151
+ throw new Error(
4152
+ `The nonce \`${currentNonceValue}\` is no longer valid. It has advanced to \`${nonceValue}\`.`
4153
+ );
4154
+ }
4155
+ }
4156
+ })();
4157
+ const nonceIsAlreadyInvalidPromise = (async () => {
4158
+ const { value: nonceAccount } = await rpc.getAccountInfo(nonceAccountAddress, {
4159
+ commitment,
4160
+ dataSlice: { length: 32, offset: NONCE_VALUE_OFFSET },
4161
+ encoding: "base58"
4162
+ }).send({ abortSignal: abortController.signal });
4163
+ if (!nonceAccount) {
4164
+ throw new Error(`No nonce account could be found at address \`${nonceAccountAddress}\`.`);
4165
+ }
4166
+ const nonceValue = (
4167
+ // This works because we asked for the exact slice of data representing the nonce
4168
+ // value, and furthermore asked for it in `base58` encoding.
4169
+ nonceAccount.data[0]
4170
+ );
4171
+ if (nonceValue !== currentNonceValue) {
4172
+ throw new Error(
4173
+ `The nonce \`${currentNonceValue}\` is no longer valid. It has advanced to \`${nonceValue}\`.`
4174
+ );
4175
+ } else {
4176
+ await new Promise(() => {
4177
+ });
4178
+ }
4179
+ })();
4180
+ try {
4181
+ return await Promise.race([nonceAccountDidAdvancePromise, nonceIsAlreadyInvalidPromise]);
4182
+ } finally {
4183
+ abortController.abort();
4184
+ }
4185
+ };
4186
+ }
4187
+
4188
+ // src/transaction-confirmation.ts
4189
+ function createDefaultDurableNonceTransactionConfirmer({
4190
+ rpc,
4191
+ rpcSubscriptions
4192
+ }) {
4193
+ const getNonceInvalidationPromise = createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions);
4194
+ const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
4195
+ rpc,
4196
+ rpcSubscriptions
4197
+ );
4198
+ return async function confirmDurableNonceTransaction(config) {
4199
+ await waitForDurableNonceTransactionConfirmation({
4200
+ ...config,
4201
+ getNonceInvalidationPromise,
4202
+ getRecentSignatureConfirmationPromise
4203
+ });
4204
+ };
4205
+ }
4206
+ function createDefaultRecentTransactionConfirmer({
4207
+ rpc,
4208
+ rpcSubscriptions
4209
+ }) {
4210
+ const getBlockHeightExceedencePromise = createBlockHeightExceedencePromiseFactory(rpcSubscriptions);
4211
+ const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
4212
+ rpc,
4213
+ rpcSubscriptions
4214
+ );
4215
+ return async function confirmRecentTransaction(config) {
4216
+ await waitForRecentTransactionConfirmation({
4217
+ ...config,
4218
+ getBlockHeightExceedencePromise,
4219
+ getRecentSignatureConfirmationPromise
4220
+ });
4221
+ };
4222
+ }
4223
+ async function waitForDurableNonceTransactionConfirmation(config) {
4224
+ await raceStrategies(
4225
+ getSignatureFromTransaction(config.transaction),
4226
+ config,
4227
+ function getSpecificStrategiesForRace({ abortSignal, commitment, getNonceInvalidationPromise, transaction }) {
4228
+ return [
4229
+ getNonceInvalidationPromise({
4230
+ abortSignal,
4231
+ commitment,
4232
+ currentNonceValue: transaction.lifetimeConstraint.nonce,
4233
+ nonceAccountAddress: transaction.instructions[0].accounts[0].address
4234
+ })
4235
+ ];
4236
+ }
4237
+ );
4238
+ }
4239
+ async function waitForRecentTransactionConfirmation(config) {
4240
+ await raceStrategies(
4241
+ getSignatureFromTransaction(config.transaction),
4242
+ config,
4243
+ function getSpecificStrategiesForRace({ abortSignal, getBlockHeightExceedencePromise, transaction }) {
4244
+ return [
4245
+ getBlockHeightExceedencePromise({
4246
+ abortSignal,
4247
+ lastValidBlockHeight: transaction.lifetimeConstraint.lastValidBlockHeight
4248
+ })
4249
+ ];
4250
+ }
4251
+ );
4252
+ }
4253
+
4254
+ // src/send-transaction.ts
4255
+ function getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, config) {
4256
+ if (
4257
+ // The developer has supplied no value for `preflightCommitment`.
4258
+ !config?.preflightCommitment && // The value of `commitment` is lower than the server default of `preflightCommitment`.
4259
+ commitmentComparator(
4260
+ commitment,
4261
+ "finalized"
4262
+ /* default value of `preflightCommitment` */
4263
+ ) < 0
4264
+ ) {
4265
+ return {
4266
+ ...config,
4267
+ // In the common case, it is unlikely that you want to simulate a transaction at
4268
+ // `finalized` commitment when your standard of commitment for confirming the
4269
+ // transaction is lower. Cap the simulation commitment level to the level of the
4270
+ // confirmation commitment.
4271
+ preflightCommitment: commitment
4272
+ };
4273
+ }
4274
+ return config;
4275
+ }
4276
+ async function sendTransaction_INTERNAL({
4277
+ abortSignal,
4278
+ commitment,
4279
+ rpc,
4280
+ transaction,
4281
+ sendTransactionConfig
4282
+ }) {
4283
+ const base64EncodedWireTransaction = getBase64EncodedWireTransaction(transaction);
4284
+ return await rpc.sendTransaction(base64EncodedWireTransaction, {
4285
+ ...getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, sendTransactionConfig),
4286
+ encoding: "base64"
4287
+ }).send({ abortSignal });
4288
+ }
4289
+ function createDefaultDurableNonceTransactionSender({
4290
+ rpc,
4291
+ rpcSubscriptions
4292
+ }) {
4293
+ const confirmDurableNonceTransaction = createDefaultDurableNonceTransactionConfirmer({
4294
+ rpc,
4295
+ rpcSubscriptions
4296
+ });
4297
+ return async function sendDurableNonceTransaction(transaction, config) {
4298
+ await sendAndConfirmDurableNonceTransaction({
4299
+ ...config,
4300
+ confirmDurableNonceTransaction,
4301
+ rpc,
4302
+ transaction
4303
+ });
4304
+ };
4305
+ }
4306
+ function createDefaultTransactionSender({ rpc, rpcSubscriptions }) {
4307
+ const confirmRecentTransaction = createDefaultRecentTransactionConfirmer({
4308
+ rpc,
4309
+ rpcSubscriptions
4310
+ });
4311
+ return async function sendTransaction(transaction, config) {
4312
+ await sendAndConfirmTransaction({
4313
+ ...config,
4314
+ confirmRecentTransaction,
4315
+ rpc,
4316
+ transaction
4317
+ });
4318
+ };
4319
+ }
4320
+ async function sendAndConfirmDurableNonceTransaction({
4321
+ abortSignal,
4322
+ commitment,
4323
+ confirmDurableNonceTransaction,
4324
+ rpc,
4325
+ transaction,
4326
+ ...sendTransactionConfig
4327
+ }) {
4328
+ const transactionSignature2 = await sendTransaction_INTERNAL({
4329
+ abortSignal,
4330
+ commitment,
4331
+ rpc,
4332
+ sendTransactionConfig,
4333
+ transaction
4334
+ });
4335
+ await confirmDurableNonceTransaction({
4336
+ abortSignal,
4337
+ commitment,
4338
+ transaction
4339
+ });
4340
+ return transactionSignature2;
4341
+ }
4342
+ async function sendAndConfirmTransaction({
4343
+ abortSignal,
4344
+ commitment,
4345
+ confirmRecentTransaction,
4346
+ rpc,
4347
+ transaction,
4348
+ ...sendTransactionConfig
4349
+ }) {
4350
+ const transactionSignature2 = await sendTransaction_INTERNAL({
4351
+ abortSignal,
4352
+ commitment,
4353
+ rpc,
4354
+ sendTransactionConfig,
4355
+ transaction
4356
+ });
4357
+ await confirmRecentTransaction({
4358
+ abortSignal,
4359
+ commitment,
4360
+ transaction
4361
+ });
4362
+ return transactionSignature2;
4363
+ }
4364
+
2994
4365
  exports.AccountRole = AccountRole;
2995
4366
  exports.address = address;
2996
4367
  exports.appendTransactionInstruction = appendTransactionInstruction;
2997
- exports.assertIsBase58EncodedAddress = assertIsBase58EncodedAddress;
4368
+ exports.assertIsAddress = assertIsAddress;
2998
4369
  exports.assertIsBlockhash = assertIsBlockhash;
2999
4370
  exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
4371
+ exports.assertIsProgramDerivedAddress = assertIsProgramDerivedAddress;
4372
+ exports.assertIsTransactionSignature = assertIsTransactionSignature;
3000
4373
  exports.createAddressWithSeed = createAddressWithSeed;
4374
+ exports.createBlockHeightExceedencePromiseFactory = createBlockHeightExceedencePromiseFactory;
4375
+ exports.createDefaultAirdropRequester = createDefaultAirdropRequester;
4376
+ exports.createDefaultDurableNonceTransactionConfirmer = createDefaultDurableNonceTransactionConfirmer;
4377
+ exports.createDefaultDurableNonceTransactionSender = createDefaultDurableNonceTransactionSender;
4378
+ exports.createDefaultRecentTransactionConfirmer = createDefaultRecentTransactionConfirmer;
3001
4379
  exports.createDefaultRpcSubscriptionsTransport = createDefaultRpcSubscriptionsTransport;
3002
4380
  exports.createDefaultRpcTransport = createDefaultRpcTransport;
4381
+ exports.createDefaultTransactionSender = createDefaultTransactionSender;
4382
+ exports.createNonceInvalidationPromiseFactory = createNonceInvalidationPromiseFactory;
4383
+ exports.createRecentSignatureConfirmationPromiseFactory = createRecentSignatureConfirmationPromiseFactory;
3003
4384
  exports.createSolanaRpc = createSolanaRpc;
3004
4385
  exports.createSolanaRpcSubscriptions = createSolanaRpcSubscriptions;
4386
+ exports.createSolanaRpcSubscriptions_UNSTABLE = createSolanaRpcSubscriptions_UNSTABLE;
3005
4387
  exports.createTransaction = createTransaction;
3006
4388
  exports.downgradeRoleToNonSigner = downgradeRoleToNonSigner;
3007
4389
  exports.downgradeRoleToReadonly = downgradeRoleToReadonly;
3008
4390
  exports.generateKeyPair = generateKeyPair;
4391
+ exports.getAddressCodec = getAddressCodec;
4392
+ exports.getAddressComparator = getAddressComparator;
4393
+ exports.getAddressDecoder = getAddressDecoder;
4394
+ exports.getAddressEncoder = getAddressEncoder;
3009
4395
  exports.getAddressFromPublicKey = getAddressFromPublicKey;
3010
- exports.getBase58EncodedAddressCodec = getBase58EncodedAddressCodec;
3011
- exports.getBase58EncodedAddressComparator = getBase58EncodedAddressComparator;
3012
4396
  exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
3013
4397
  exports.getProgramDerivedAddress = getProgramDerivedAddress;
3014
- exports.isBase58EncodedAddress = isBase58EncodedAddress;
4398
+ exports.getSignatureFromTransaction = getSignatureFromTransaction;
4399
+ exports.getTransactionEncoder = getTransactionEncoder;
4400
+ exports.isAddress = isAddress;
4401
+ exports.isAdvanceNonceAccountInstruction = isAdvanceNonceAccountInstruction;
4402
+ exports.isProgramDerivedAddress = isProgramDerivedAddress;
3015
4403
  exports.isSignerRole = isSignerRole;
4404
+ exports.isTransactionSignature = isTransactionSignature;
3016
4405
  exports.isWritableRole = isWritableRole;
3017
4406
  exports.mergeRoles = mergeRoles;
3018
4407
  exports.prependTransactionInstruction = prependTransactionInstruction;
4408
+ exports.requestAndConfirmAirdrop = requestAndConfirmAirdrop;
4409
+ exports.sendAndConfirmDurableNonceTransaction = sendAndConfirmDurableNonceTransaction;
4410
+ exports.sendAndConfirmTransaction = sendAndConfirmTransaction;
3019
4411
  exports.setTransactionFeePayer = setTransactionFeePayer;
3020
4412
  exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
3021
4413
  exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
3022
4414
  exports.signBytes = signBytes;
3023
4415
  exports.signTransaction = signTransaction;
4416
+ exports.transactionSignature = transactionSignature;
3024
4417
  exports.upgradeRoleToSigner = upgradeRoleToSigner;
3025
4418
  exports.upgradeRoleToWritable = upgradeRoleToWritable;
3026
4419
  exports.verifySignature = verifySignature;
4420
+ exports.waitForDurableNonceTransactionConfirmation = waitForDurableNonceTransactionConfirmation;
4421
+ exports.waitForRecentTransactionConfirmation = waitForRecentTransactionConfirmation;
3027
4422
 
3028
4423
  return exports;
3029
4424