@solana/web3.js 1.98.0 → 1.98.1

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.
package/lib/index.iife.js CHANGED
@@ -14074,106 +14074,227 @@ var solanaWeb3 = (function (exports) {
14074
14074
  }
14075
14075
  }
14076
14076
 
14077
- var browser$1 = {};
14078
-
14079
- var hasRequiredBrowser$1;
14080
-
14081
- function requireBrowser$1 () {
14082
- if (hasRequiredBrowser$1) return browser$1;
14083
- hasRequiredBrowser$1 = 1;
14077
+ // src/codes.ts
14078
+ var SOLANA_ERROR__CODECS__CANNOT_DECODE_EMPTY_BYTE_ARRAY = 8078e3;
14079
+ var SOLANA_ERROR__CODECS__INVALID_BYTE_LENGTH = 8078001;
14080
+ var SOLANA_ERROR__CODECS__ENCODER_DECODER_SIZE_COMPATIBILITY_MISMATCH = 8078004;
14081
+ var SOLANA_ERROR__CODECS__ENCODER_DECODER_FIXED_SIZE_MISMATCH = 8078005;
14082
+ var SOLANA_ERROR__CODECS__ENCODER_DECODER_MAX_SIZE_MISMATCH = 8078006;
14083
+ var SOLANA_ERROR__CODECS__NUMBER_OUT_OF_RANGE = 8078011;
14084
+
14085
+ // src/context.ts
14086
+ function encodeValue(value) {
14087
+ if (Array.isArray(value)) {
14088
+ const commaSeparatedValues = value.map(encodeValue).join(
14089
+ "%2C%20"
14090
+ /* ", " */
14091
+ );
14092
+ return "%5B" + commaSeparatedValues + /* "]" */
14093
+ "%5D";
14094
+ } else if (typeof value === "bigint") {
14095
+ return `${value}n`;
14096
+ } else {
14097
+ return encodeURIComponent(
14098
+ String(
14099
+ value != null && Object.getPrototypeOf(value) === null ? (
14100
+ // Plain objects with no prototype don't have a `toString` method.
14101
+ // Convert them before stringifying them.
14102
+ { ...value }
14103
+ ) : value
14104
+ )
14105
+ );
14106
+ }
14107
+ }
14108
+ function encodeObjectContextEntry([key, value]) {
14109
+ return `${key}=${encodeValue(value)}`;
14110
+ }
14111
+ function encodeContextObject(context) {
14112
+ const searchParamsString = Object.entries(context).map(encodeObjectContextEntry).join("&");
14113
+ return btoa(searchParamsString);
14114
+ }
14115
+ function getErrorMessage(code, context = {}) {
14116
+ {
14117
+ let decodingAdviceMessage = `Solana error #${code}; Decode this error by running \`npx @solana/errors decode -- ${code}`;
14118
+ if (Object.keys(context).length) {
14119
+ decodingAdviceMessage += ` '${encodeContextObject(context)}'`;
14120
+ }
14121
+ return `${decodingAdviceMessage}\``;
14122
+ }
14123
+ }
14124
+ var SolanaError = class extends Error {
14125
+ /**
14126
+ * Indicates the root cause of this {@link SolanaError}, if any.
14127
+ *
14128
+ * For example, a transaction error might have an instruction error as its root cause. In this
14129
+ * case, you will be able to access the instruction error on the transaction error as `cause`.
14130
+ */
14131
+ cause = this.cause;
14132
+ /**
14133
+ * Contains context that can assist in understanding or recovering from a {@link SolanaError}.
14134
+ */
14135
+ context;
14136
+ constructor(...[code, contextAndErrorOptions]) {
14137
+ let context;
14138
+ let errorOptions;
14139
+ if (contextAndErrorOptions) {
14140
+ const { cause, ...contextRest } = contextAndErrorOptions;
14141
+ if (cause) {
14142
+ errorOptions = { cause };
14143
+ }
14144
+ if (Object.keys(contextRest).length > 0) {
14145
+ context = contextRest;
14146
+ }
14147
+ }
14148
+ const message = getErrorMessage(code, context);
14149
+ super(message, errorOptions);
14150
+ this.context = {
14151
+ __code: code,
14152
+ ...context
14153
+ };
14154
+ this.name = "SolanaError";
14155
+ }
14156
+ };
14084
14157
 
14085
- Object.defineProperty(browser$1, "__esModule", { value: true });
14086
- /**
14087
- * Convert a little-endian buffer into a BigInt.
14088
- * @param buf The little-endian buffer to convert
14089
- * @returns A BigInt with the little-endian representation of buf.
14090
- */
14091
- function toBigIntLE(buf) {
14092
- {
14093
- const reversed = Buffer.from(buf);
14094
- reversed.reverse();
14095
- const hex = reversed.toString('hex');
14096
- if (hex.length === 0) {
14097
- return BigInt(0);
14098
- }
14099
- return BigInt(`0x${hex}`);
14100
- }
14101
- }
14102
- browser$1.toBigIntLE = toBigIntLE;
14103
- /**
14104
- * Convert a big-endian buffer into a BigInt
14105
- * @param buf The big-endian buffer to convert.
14106
- * @returns A BigInt with the big-endian representation of buf.
14107
- */
14108
- function toBigIntBE(buf) {
14109
- {
14110
- const hex = buf.toString('hex');
14111
- if (hex.length === 0) {
14112
- return BigInt(0);
14113
- }
14114
- return BigInt(`0x${hex}`);
14115
- }
14116
- }
14117
- browser$1.toBigIntBE = toBigIntBE;
14118
- /**
14119
- * Convert a BigInt to a little-endian buffer.
14120
- * @param num The BigInt to convert.
14121
- * @param width The number of bytes that the resulting buffer should be.
14122
- * @returns A little-endian buffer representation of num.
14123
- */
14124
- function toBufferLE(num, width) {
14125
- {
14126
- const hex = num.toString(16);
14127
- const buffer = Buffer.from(hex.padStart(width * 2, '0').slice(0, width * 2), 'hex');
14128
- buffer.reverse();
14129
- return buffer;
14130
- }
14131
- }
14132
- browser$1.toBufferLE = toBufferLE;
14133
- /**
14134
- * Convert a BigInt to a big-endian buffer.
14135
- * @param num The BigInt to convert.
14136
- * @param width The number of bytes that the resulting buffer should be.
14137
- * @returns A big-endian buffer representation of num.
14138
- */
14139
- function toBufferBE(num, width) {
14140
- {
14141
- const hex = num.toString(16);
14142
- return Buffer.from(hex.padStart(width * 2, '0').slice(0, width * 2), 'hex');
14143
- }
14144
- }
14145
- browser$1.toBufferBE = toBufferBE;
14146
- return browser$1;
14158
+ function getEncodedSize(value, encoder) {
14159
+ return "fixedSize" in encoder ? encoder.fixedSize : encoder.getSizeFromValue(value);
14160
+ }
14161
+ function createEncoder(encoder) {
14162
+ return Object.freeze({
14163
+ ...encoder,
14164
+ encode: (value) => {
14165
+ const bytes = new Uint8Array(getEncodedSize(value, encoder));
14166
+ encoder.write(value, bytes, 0);
14167
+ return bytes;
14168
+ }
14169
+ });
14170
+ }
14171
+ function createDecoder(decoder) {
14172
+ return Object.freeze({
14173
+ ...decoder,
14174
+ decode: (bytes, offset = 0) => decoder.read(bytes, offset)[0]
14175
+ });
14176
+ }
14177
+ function isFixedSize(codec) {
14178
+ return "fixedSize" in codec && typeof codec.fixedSize === "number";
14179
+ }
14180
+ function combineCodec(encoder, decoder) {
14181
+ if (isFixedSize(encoder) !== isFixedSize(decoder)) {
14182
+ throw new SolanaError(SOLANA_ERROR__CODECS__ENCODER_DECODER_SIZE_COMPATIBILITY_MISMATCH);
14183
+ }
14184
+ if (isFixedSize(encoder) && isFixedSize(decoder) && encoder.fixedSize !== decoder.fixedSize) {
14185
+ throw new SolanaError(SOLANA_ERROR__CODECS__ENCODER_DECODER_FIXED_SIZE_MISMATCH, {
14186
+ decoderFixedSize: decoder.fixedSize,
14187
+ encoderFixedSize: encoder.fixedSize
14188
+ });
14189
+ }
14190
+ if (!isFixedSize(encoder) && !isFixedSize(decoder) && encoder.maxSize !== decoder.maxSize) {
14191
+ throw new SolanaError(SOLANA_ERROR__CODECS__ENCODER_DECODER_MAX_SIZE_MISMATCH, {
14192
+ decoderMaxSize: decoder.maxSize,
14193
+ encoderMaxSize: encoder.maxSize
14194
+ });
14195
+ }
14196
+ return {
14197
+ ...decoder,
14198
+ ...encoder,
14199
+ decode: decoder.decode,
14200
+ encode: encoder.encode,
14201
+ read: decoder.read,
14202
+ write: encoder.write
14203
+ };
14204
+ }
14205
+ function assertByteArrayIsNotEmptyForCodec(codecDescription, bytes, offset = 0) {
14206
+ if (bytes.length - offset <= 0) {
14207
+ throw new SolanaError(SOLANA_ERROR__CODECS__CANNOT_DECODE_EMPTY_BYTE_ARRAY, {
14208
+ codecDescription
14209
+ });
14210
+ }
14211
+ }
14212
+ function assertByteArrayHasEnoughBytesForCodec(codecDescription, expected, bytes, offset = 0) {
14213
+ const bytesLength = bytes.length - offset;
14214
+ if (bytesLength < expected) {
14215
+ throw new SolanaError(SOLANA_ERROR__CODECS__INVALID_BYTE_LENGTH, {
14216
+ bytesLength,
14217
+ codecDescription,
14218
+ expected
14219
+ });
14220
+ }
14147
14221
  }
14148
14222
 
14149
- var browserExports$1 = /*@__PURE__*/ requireBrowser$1();
14223
+ // src/assertions.ts
14224
+ function assertNumberIsBetweenForCodec(codecDescription, min, max, value) {
14225
+ if (value < min || value > max) {
14226
+ throw new SolanaError(SOLANA_ERROR__CODECS__NUMBER_OUT_OF_RANGE, {
14227
+ codecDescription,
14228
+ max,
14229
+ min,
14230
+ value
14231
+ });
14232
+ }
14233
+ }
14234
+ function isLittleEndian(config) {
14235
+ return config?.endian === 1 /* Big */ ? false : true;
14236
+ }
14237
+ function numberEncoderFactory(input) {
14238
+ return createEncoder({
14239
+ fixedSize: input.size,
14240
+ write(value, bytes, offset) {
14241
+ if (input.range) {
14242
+ assertNumberIsBetweenForCodec(input.name, input.range[0], input.range[1], value);
14243
+ }
14244
+ const arrayBuffer = new ArrayBuffer(input.size);
14245
+ input.set(new DataView(arrayBuffer), value, isLittleEndian(input.config));
14246
+ bytes.set(new Uint8Array(arrayBuffer), offset);
14247
+ return offset + input.size;
14248
+ }
14249
+ });
14250
+ }
14251
+ function numberDecoderFactory(input) {
14252
+ return createDecoder({
14253
+ fixedSize: input.size,
14254
+ read(bytes, offset = 0) {
14255
+ assertByteArrayIsNotEmptyForCodec(input.name, bytes, offset);
14256
+ assertByteArrayHasEnoughBytesForCodec(input.name, input.size, bytes, offset);
14257
+ const view = new DataView(toArrayBuffer(bytes, offset, input.size));
14258
+ return [input.get(view, isLittleEndian(input.config)), offset + input.size];
14259
+ }
14260
+ });
14261
+ }
14262
+ function toArrayBuffer(bytes, offset, length) {
14263
+ const bytesOffset = bytes.byteOffset + (offset ?? 0);
14264
+ const bytesLength = length ?? bytes.byteLength;
14265
+ return bytes.buffer.slice(bytesOffset, bytesOffset + bytesLength);
14266
+ }
14267
+ var getU64Encoder = (config = {}) => numberEncoderFactory({
14268
+ config,
14269
+ name: "u64",
14270
+ range: [0n, BigInt("0xffffffffffffffff")],
14271
+ set: (view, value, le) => view.setBigUint64(0, BigInt(value), le),
14272
+ size: 8
14273
+ });
14274
+ var getU64Decoder = (config = {}) => numberDecoderFactory({
14275
+ config,
14276
+ get: (view, le) => view.getBigUint64(0, le),
14277
+ name: "u64",
14278
+ size: 8
14279
+ });
14280
+ var getU64Codec = (config = {}) => combineCodec(getU64Encoder(config), getU64Decoder(config));
14150
14281
 
14151
- const encodeDecode = layout => {
14282
+ function u64(property) {
14283
+ const layout = LayoutExports.blob(8 /* bytes */, property);
14152
14284
  const decode = layout.decode.bind(layout);
14153
14285
  const encode = layout.encode.bind(layout);
14154
- return {
14155
- decode,
14156
- encode
14157
- };
14158
- };
14159
- const bigInt = length => property => {
14160
- const layout = LayoutExports.blob(length, property);
14161
- const {
14162
- encode,
14163
- decode
14164
- } = encodeDecode(layout);
14165
14286
  const bigIntLayout = layout;
14287
+ const codec = getU64Codec();
14166
14288
  bigIntLayout.decode = (buffer, offset) => {
14167
14289
  const src = decode(buffer, offset);
14168
- return browserExports$1.toBigIntLE(bufferExports.Buffer.from(src));
14290
+ return codec.decode(src);
14169
14291
  };
14170
14292
  bigIntLayout.encode = (bigInt, buffer, offset) => {
14171
- const src = browserExports$1.toBufferLE(bigInt, length);
14293
+ const src = codec.encode(bigInt);
14172
14294
  return encode(src, buffer, offset);
14173
14295
  };
14174
14296
  return bigIntLayout;
14175
- };
14176
- const u64 = bigInt(8);
14297
+ }
14177
14298
 
14178
14299
  /**
14179
14300
  * Create account system transaction params
@@ -22270,7 +22391,7 @@ var solanaWeb3 = (function (exports) {
22270
22391
  */
22271
22392
  constructor() {}
22272
22393
  static createLookupTable(params) {
22273
- const [lookupTableAddress, bumpSeed] = PublicKey.findProgramAddressSync([params.authority.toBuffer(), browserExports$1.toBufferLE(BigInt(params.recentSlot), 8)], this.programId);
22394
+ const [lookupTableAddress, bumpSeed] = PublicKey.findProgramAddressSync([params.authority.toBuffer(), getU64Encoder().encode(params.recentSlot)], this.programId);
22274
22395
  const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.CreateLookupTable;
22275
22396
  const data = encodeData(type, {
22276
22397
  recentSlot: BigInt(params.recentSlot),