@solana/signers 2.0.0-experimental.d3af599 → 2.0.0-experimental.e1ca396

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.
@@ -72,23 +72,6 @@ this.globalThis.solanaWeb3 = (function (exports) {
72
72
  throw new Error(`Codec [${codecDescription}] expected ${expected} bytes, got ${bytesLength}.`);
73
73
  }
74
74
  }
75
- var mergeBytes = (byteArrays) => {
76
- const nonEmptyByteArrays = byteArrays.filter((arr) => arr.length);
77
- if (nonEmptyByteArrays.length === 0) {
78
- return byteArrays.length ? byteArrays[0] : new Uint8Array();
79
- }
80
- if (nonEmptyByteArrays.length === 1) {
81
- return nonEmptyByteArrays[0];
82
- }
83
- const totalLength = nonEmptyByteArrays.reduce((total, arr) => total + arr.length, 0);
84
- const result = new Uint8Array(totalLength);
85
- let offset = 0;
86
- nonEmptyByteArrays.forEach((arr) => {
87
- result.set(arr, offset);
88
- offset += arr.length;
89
- });
90
- return result;
91
- };
92
75
  var padBytes = (bytes, length) => {
93
76
  if (bytes.length >= length)
94
77
  return bytes;
@@ -97,42 +80,68 @@ this.globalThis.solanaWeb3 = (function (exports) {
97
80
  return paddedBytes;
98
81
  };
99
82
  var fixBytes = (bytes, length) => padBytes(bytes.length <= length ? bytes : bytes.slice(0, length), length);
100
- function fixCodecHelper(data, fixedBytes, description) {
101
- return {
102
- description: description != null ? description : `fixed(${fixedBytes}, ${data.description})`,
103
- fixedSize: fixedBytes,
104
- maxSize: fixedBytes
105
- };
83
+ function getEncodedSize(value, encoder) {
84
+ return "fixedSize" in encoder ? encoder.fixedSize : encoder.getSizeFromValue(value);
106
85
  }
107
- function fixEncoder(encoder, fixedBytes, description) {
108
- return {
109
- ...fixCodecHelper(encoder, fixedBytes, description),
110
- encode: (value) => fixBytes(encoder.encode(value), fixedBytes)
111
- };
86
+ function createEncoder(encoder) {
87
+ return Object.freeze({
88
+ ...encoder,
89
+ encode: (value) => {
90
+ const bytes = new Uint8Array(getEncodedSize(value, encoder));
91
+ encoder.write(value, bytes, 0);
92
+ return bytes;
93
+ }
94
+ });
112
95
  }
113
- function fixDecoder(decoder, fixedBytes, description) {
114
- return {
115
- ...fixCodecHelper(decoder, fixedBytes, description),
116
- decode: (bytes, offset = 0) => {
96
+ function createDecoder(decoder) {
97
+ return Object.freeze({
98
+ ...decoder,
99
+ decode: (bytes, offset = 0) => decoder.read(bytes, offset)[0]
100
+ });
101
+ }
102
+ function isFixedSize(codec) {
103
+ return "fixedSize" in codec && typeof codec.fixedSize === "number";
104
+ }
105
+ function assertIsFixedSize(codec, message) {
106
+ if (!isFixedSize(codec)) {
107
+ throw new Error(message != null ? message : "Expected a fixed-size codec, got a variable-size one.");
108
+ }
109
+ }
110
+ function isVariableSize(codec) {
111
+ return !isFixedSize(codec);
112
+ }
113
+ function fixEncoder(encoder, fixedBytes) {
114
+ return createEncoder({
115
+ fixedSize: fixedBytes,
116
+ write: (value, bytes, offset) => {
117
+ const variableByteArray = encoder.encode(value);
118
+ const fixedByteArray = variableByteArray.length > fixedBytes ? variableByteArray.slice(0, fixedBytes) : variableByteArray;
119
+ bytes.set(fixedByteArray, offset);
120
+ return offset + fixedBytes;
121
+ }
122
+ });
123
+ }
124
+ function fixDecoder(decoder, fixedBytes) {
125
+ return createDecoder({
126
+ fixedSize: fixedBytes,
127
+ read: (bytes, offset) => {
117
128
  assertByteArrayHasEnoughBytesForCodec("fixCodec", fixedBytes, bytes, offset);
118
129
  if (offset > 0 || bytes.length > fixedBytes) {
119
130
  bytes = bytes.slice(offset, offset + fixedBytes);
120
131
  }
121
- if (decoder.fixedSize !== null) {
132
+ if (isFixedSize(decoder)) {
122
133
  bytes = fixBytes(bytes, decoder.fixedSize);
123
134
  }
124
- const [value] = decoder.decode(bytes, 0);
135
+ const [value] = decoder.read(bytes, 0);
125
136
  return [value, offset + fixedBytes];
126
137
  }
127
- };
138
+ });
128
139
  }
129
140
  function mapEncoder(encoder, unmap) {
130
- return {
131
- description: encoder.description,
132
- encode: (value) => encoder.encode(unmap(value)),
133
- fixedSize: encoder.fixedSize,
134
- maxSize: encoder.maxSize
135
- };
141
+ return createEncoder({
142
+ ...isVariableSize(encoder) ? { ...encoder, getSizeFromValue: (value) => encoder.getSizeFromValue(unmap(value)) } : encoder,
143
+ write: (value, bytes, offset) => encoder.write(unmap(value), bytes, offset)
144
+ });
136
145
  }
137
146
 
138
147
  // ../codecs-numbers/dist/index.browser.js
@@ -143,80 +152,66 @@ this.globalThis.solanaWeb3 = (function (exports) {
143
152
  );
144
153
  }
145
154
  }
146
- function sharedNumberFactory(input) {
147
- var _a;
148
- let littleEndian;
149
- let defaultDescription = input.name;
150
- if (input.size > 1) {
151
- littleEndian = !("endian" in input.config) || input.config.endian === 0;
152
- defaultDescription += littleEndian ? "(le)" : "(be)";
153
- }
154
- return {
155
- description: (_a = input.config.description) != null ? _a : defaultDescription,
156
- fixedSize: input.size,
157
- littleEndian,
158
- maxSize: input.size
159
- };
155
+ function isLittleEndian(config) {
156
+ return (config == null ? void 0 : config.endian) === 1 ? false : true;
160
157
  }
161
158
  function numberEncoderFactory(input) {
162
- const codecData = sharedNumberFactory(input);
163
- return {
164
- description: codecData.description,
165
- encode(value) {
159
+ return createEncoder({
160
+ fixedSize: input.size,
161
+ write(value, bytes, offset) {
166
162
  if (input.range) {
167
163
  assertNumberIsBetweenForCodec(input.name, input.range[0], input.range[1], value);
168
164
  }
169
165
  const arrayBuffer = new ArrayBuffer(input.size);
170
- input.set(new DataView(arrayBuffer), value, codecData.littleEndian);
171
- return new Uint8Array(arrayBuffer);
172
- },
173
- fixedSize: codecData.fixedSize,
174
- maxSize: codecData.maxSize
175
- };
166
+ input.set(new DataView(arrayBuffer), value, isLittleEndian(input.config));
167
+ bytes.set(new Uint8Array(arrayBuffer), offset);
168
+ return offset + input.size;
169
+ }
170
+ });
176
171
  }
177
172
  function numberDecoderFactory(input) {
178
- const codecData = sharedNumberFactory(input);
179
- return {
180
- decode(bytes, offset = 0) {
181
- assertByteArrayIsNotEmptyForCodec(codecData.description, bytes, offset);
182
- assertByteArrayHasEnoughBytesForCodec(codecData.description, input.size, bytes, offset);
173
+ return createDecoder({
174
+ fixedSize: input.size,
175
+ read(bytes, offset = 0) {
176
+ assertByteArrayIsNotEmptyForCodec(input.name, bytes, offset);
177
+ assertByteArrayHasEnoughBytesForCodec(input.name, input.size, bytes, offset);
183
178
  const view = new DataView(toArrayBuffer(bytes, offset, input.size));
184
- return [input.get(view, codecData.littleEndian), offset + input.size];
185
- },
186
- description: codecData.description,
187
- fixedSize: codecData.fixedSize,
188
- maxSize: codecData.maxSize
189
- };
179
+ return [input.get(view, isLittleEndian(input.config)), offset + input.size];
180
+ }
181
+ });
190
182
  }
191
183
  function toArrayBuffer(bytes, offset, length) {
192
184
  const bytesOffset = bytes.byteOffset + (offset != null ? offset : 0);
193
185
  const bytesLength = length != null ? length : bytes.byteLength;
194
186
  return bytes.buffer.slice(bytesOffset, bytesOffset + bytesLength);
195
187
  }
196
- var getShortU16Encoder = (config = {}) => {
197
- var _a;
198
- return {
199
- description: (_a = config.description) != null ? _a : "shortU16",
200
- encode: (value) => {
201
- assertNumberIsBetweenForCodec("shortU16", 0, 65535, value);
202
- const bytes = [0];
203
- for (let ii = 0; ; ii += 1) {
204
- const alignedValue = value >> ii * 7;
205
- if (alignedValue === 0) {
206
- break;
207
- }
208
- const nextSevenBits = 127 & alignedValue;
209
- bytes[ii] = nextSevenBits;
210
- if (ii > 0) {
211
- bytes[ii - 1] |= 128;
212
- }
188
+ var getShortU16Encoder = () => createEncoder({
189
+ getSizeFromValue: (value) => {
190
+ if (value <= 127)
191
+ return 1;
192
+ if (value <= 16383)
193
+ return 2;
194
+ return 3;
195
+ },
196
+ maxSize: 3,
197
+ write: (value, bytes, offset) => {
198
+ assertNumberIsBetweenForCodec("shortU16", 0, 65535, value);
199
+ const shortU16Bytes = [0];
200
+ for (let ii = 0; ; ii += 1) {
201
+ const alignedValue = value >> ii * 7;
202
+ if (alignedValue === 0) {
203
+ break;
213
204
  }
214
- return new Uint8Array(bytes);
215
- },
216
- fixedSize: null,
217
- maxSize: 3
218
- };
219
- };
205
+ const nextSevenBits = 127 & alignedValue;
206
+ shortU16Bytes[ii] = nextSevenBits;
207
+ if (ii > 0) {
208
+ shortU16Bytes[ii - 1] |= 128;
209
+ }
210
+ }
211
+ bytes.set(shortU16Bytes, offset);
212
+ return offset + shortU16Bytes.length;
213
+ }
214
+ });
220
215
  var getU32Encoder = (config = {}) => numberEncoderFactory({
221
216
  config,
222
217
  name: "u32",
@@ -230,8 +225,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
230
225
  name: "u32",
231
226
  size: 4
232
227
  });
233
- var getU8Encoder = (config = {}) => numberEncoderFactory({
234
- config,
228
+ var getU8Encoder = () => numberEncoderFactory({
235
229
  name: "u8",
236
230
  range: [0, Number("0xff")],
237
231
  set: (view, value) => view.setUint8(0, value),
@@ -245,43 +239,38 @@ this.globalThis.solanaWeb3 = (function (exports) {
245
239
  }
246
240
  }
247
241
  var getBaseXEncoder = (alphabet4) => {
248
- const base = alphabet4.length;
249
- const baseBigInt = BigInt(base);
250
- return {
251
- description: `base${base}`,
252
- encode(value) {
242
+ return createEncoder({
243
+ getSizeFromValue: (value) => {
244
+ const [leadingZeroes, tailChars] = partitionLeadingZeroes(value, alphabet4[0]);
245
+ if (tailChars === "")
246
+ return value.length;
247
+ const base10Number = getBigIntFromBaseX(tailChars, alphabet4);
248
+ return leadingZeroes.length + Math.ceil(base10Number.toString(16).length / 2);
249
+ },
250
+ write(value, bytes, offset) {
253
251
  assertValidBaseString(alphabet4, value);
254
252
  if (value === "")
255
- return new Uint8Array();
256
- const chars = [...value];
257
- let trailIndex = chars.findIndex((c) => c !== alphabet4[0]);
258
- trailIndex = trailIndex === -1 ? chars.length : trailIndex;
259
- const leadingZeroes = Array(trailIndex).fill(0);
260
- if (trailIndex === chars.length)
261
- return Uint8Array.from(leadingZeroes);
262
- const tailChars = chars.slice(trailIndex);
263
- let base10Number = 0n;
264
- let baseXPower = 1n;
265
- for (let i = tailChars.length - 1; i >= 0; i -= 1) {
266
- base10Number += baseXPower * BigInt(alphabet4.indexOf(tailChars[i]));
267
- baseXPower *= baseBigInt;
253
+ return offset;
254
+ const [leadingZeroes, tailChars] = partitionLeadingZeroes(value, alphabet4[0]);
255
+ if (tailChars === "") {
256
+ bytes.set(new Uint8Array(leadingZeroes.length).fill(0), offset);
257
+ return offset + leadingZeroes.length;
268
258
  }
259
+ let base10Number = getBigIntFromBaseX(tailChars, alphabet4);
269
260
  const tailBytes = [];
270
261
  while (base10Number > 0n) {
271
262
  tailBytes.unshift(Number(base10Number % 256n));
272
263
  base10Number /= 256n;
273
264
  }
274
- return Uint8Array.from(leadingZeroes.concat(tailBytes));
275
- },
276
- fixedSize: null,
277
- maxSize: null
278
- };
265
+ const bytesToAdd = [...Array(leadingZeroes.length).fill(0), ...tailBytes];
266
+ bytes.set(bytesToAdd, offset);
267
+ return offset + bytesToAdd.length;
268
+ }
269
+ });
279
270
  };
280
271
  var getBaseXDecoder = (alphabet4) => {
281
- const base = alphabet4.length;
282
- const baseBigInt = BigInt(base);
283
- return {
284
- decode(rawBytes, offset = 0) {
272
+ return createDecoder({
273
+ read(rawBytes, offset) {
285
274
  const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);
286
275
  if (bytes.length === 0)
287
276
  return ["", 0];
@@ -290,19 +279,29 @@ this.globalThis.solanaWeb3 = (function (exports) {
290
279
  const leadingZeroes = alphabet4[0].repeat(trailIndex);
291
280
  if (trailIndex === bytes.length)
292
281
  return [leadingZeroes, rawBytes.length];
293
- let base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
294
- const tailChars = [];
295
- while (base10Number > 0n) {
296
- tailChars.unshift(alphabet4[Number(base10Number % baseBigInt)]);
297
- base10Number /= baseBigInt;
298
- }
299
- return [leadingZeroes + tailChars.join(""), rawBytes.length];
300
- },
301
- description: `base${base}`,
302
- fixedSize: null,
303
- maxSize: null
304
- };
282
+ const base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
283
+ const tailChars = getBaseXFromBigInt(base10Number, alphabet4);
284
+ return [leadingZeroes + tailChars, rawBytes.length];
285
+ }
286
+ });
305
287
  };
288
+ function partitionLeadingZeroes(value, zeroCharacter) {
289
+ const leadingZeroIndex = [...value].findIndex((c) => c !== zeroCharacter);
290
+ return leadingZeroIndex === -1 ? [value, ""] : [value.slice(0, leadingZeroIndex), value.slice(leadingZeroIndex)];
291
+ }
292
+ function getBigIntFromBaseX(value, alphabet4) {
293
+ const base = BigInt(alphabet4.length);
294
+ return [...value].reduce((sum, char) => sum * base + BigInt(alphabet4.indexOf(char)), 0n);
295
+ }
296
+ function getBaseXFromBigInt(value, alphabet4) {
297
+ const base = BigInt(alphabet4.length);
298
+ const tailChars = [];
299
+ while (value > 0n) {
300
+ tailChars.unshift(alphabet4[Number(value % base)]);
301
+ value /= base;
302
+ }
303
+ return tailChars.join("");
304
+ }
306
305
  var alphabet2 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
307
306
  var getBase58Encoder = () => getBaseXEncoder(alphabet2);
308
307
  var getBase58Decoder = () => getBaseXDecoder(alphabet2);
@@ -314,77 +313,69 @@ this.globalThis.solanaWeb3 = (function (exports) {
314
313
  var o = globalThis.TextEncoder;
315
314
  var getUtf8Encoder = () => {
316
315
  let textEncoder;
317
- return {
318
- description: "utf8",
319
- encode: (value) => new Uint8Array((textEncoder || (textEncoder = new o())).encode(value)),
320
- fixedSize: null,
321
- maxSize: null
322
- };
316
+ return createEncoder({
317
+ getSizeFromValue: (value) => (textEncoder || (textEncoder = new o())).encode(value).length,
318
+ write: (value, bytes, offset) => {
319
+ const bytesToAdd = (textEncoder || (textEncoder = new o())).encode(value);
320
+ bytes.set(bytesToAdd, offset);
321
+ return offset + bytesToAdd.length;
322
+ }
323
+ });
323
324
  };
324
325
  var getUtf8Decoder = () => {
325
326
  let textDecoder;
326
- return {
327
- decode(bytes, offset = 0) {
327
+ return createDecoder({
328
+ read(bytes, offset) {
328
329
  const value = (textDecoder || (textDecoder = new e())).decode(bytes.slice(offset));
329
330
  return [removeNullCharacters(value), bytes.length];
330
- },
331
- description: "utf8",
332
- fixedSize: null,
333
- maxSize: null
334
- };
331
+ }
332
+ });
335
333
  };
336
- var getStringEncoder = (config = {}) => {
337
- var _a, _b, _c;
334
+ function getStringEncoder(config = {}) {
335
+ var _a, _b;
338
336
  const size = (_a = config.size) != null ? _a : getU32Encoder();
339
337
  const encoding = (_b = config.encoding) != null ? _b : getUtf8Encoder();
340
- const description = (_c = config.description) != null ? _c : `string(${encoding.description}; ${getSizeDescription(size)})`;
341
338
  if (size === "variable") {
342
- return { ...encoding, description };
339
+ return encoding;
343
340
  }
344
341
  if (typeof size === "number") {
345
- return fixEncoder(encoding, size, description);
342
+ return fixEncoder(encoding, size);
346
343
  }
347
- return {
348
- description,
349
- encode: (value) => {
350
- const contentBytes = encoding.encode(value);
351
- const lengthBytes = size.encode(contentBytes.length);
352
- return mergeBytes([lengthBytes, contentBytes]);
344
+ return createEncoder({
345
+ getSizeFromValue: (value) => {
346
+ const contentSize = getEncodedSize(value, encoding);
347
+ return getEncodedSize(contentSize, size) + contentSize;
353
348
  },
354
- fixedSize: null,
355
- maxSize: null
356
- };
357
- };
358
- var getStringDecoder = (config = {}) => {
359
- var _a, _b, _c;
349
+ write: (value, bytes, offset) => {
350
+ const contentSize = getEncodedSize(value, encoding);
351
+ offset = size.write(contentSize, bytes, offset);
352
+ return encoding.write(value, bytes, offset);
353
+ }
354
+ });
355
+ }
356
+ function getStringDecoder(config = {}) {
357
+ var _a, _b;
360
358
  const size = (_a = config.size) != null ? _a : getU32Decoder();
361
359
  const encoding = (_b = config.encoding) != null ? _b : getUtf8Decoder();
362
- const description = (_c = config.description) != null ? _c : `string(${encoding.description}; ${getSizeDescription(size)})`;
363
360
  if (size === "variable") {
364
- return { ...encoding, description };
361
+ return encoding;
365
362
  }
366
363
  if (typeof size === "number") {
367
- return fixDecoder(encoding, size, description);
364
+ return fixDecoder(encoding, size);
368
365
  }
369
- return {
370
- decode: (bytes, offset = 0) => {
366
+ return createDecoder({
367
+ read: (bytes, offset = 0) => {
371
368
  assertByteArrayIsNotEmptyForCodec("string", bytes, offset);
372
- const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);
369
+ const [lengthBigInt, lengthOffset] = size.read(bytes, offset);
373
370
  const length = Number(lengthBigInt);
374
371
  offset = lengthOffset;
375
372
  const contentBytes = bytes.slice(offset, offset + length);
376
373
  assertByteArrayHasEnoughBytesForCodec("string", length, contentBytes);
377
- const [value, contentOffset] = encoding.decode(contentBytes);
374
+ const [value, contentOffset] = encoding.read(contentBytes, 0);
378
375
  offset += contentOffset;
379
376
  return [value, offset];
380
- },
381
- description,
382
- fixedSize: null,
383
- maxSize: null
384
- };
385
- };
386
- function getSizeDescription(size) {
387
- return typeof size === "object" ? size.description : `${size}`;
377
+ }
378
+ });
388
379
  }
389
380
 
390
381
  // ../assertions/dist/index.browser.js
@@ -498,24 +489,14 @@ this.globalThis.solanaWeb3 = (function (exports) {
498
489
  assertIsAddress(putativeAddress);
499
490
  return putativeAddress;
500
491
  }
501
- function getAddressEncoder(config) {
502
- var _a;
492
+ function getAddressEncoder() {
503
493
  return mapEncoder(
504
- getStringEncoder({
505
- description: (_a = config == null ? void 0 : config.description) != null ? _a : "Address",
506
- encoding: getMemoizedBase58Encoder(),
507
- size: 32
508
- }),
494
+ getStringEncoder({ encoding: getMemoizedBase58Encoder(), size: 32 }),
509
495
  (putativeAddress) => address(putativeAddress)
510
496
  );
511
497
  }
512
- function getAddressDecoder(config) {
513
- var _a;
514
- return getStringDecoder({
515
- description: (_a = config == null ? void 0 : config.description) != null ? _a : "Address",
516
- encoding: getMemoizedBase58Decoder(),
517
- size: 32
518
- });
498
+ function getAddressDecoder() {
499
+ return getStringDecoder({ encoding: getMemoizedBase58Decoder(), size: 32 });
519
500
  }
520
501
  function getAddressComparator() {
521
502
  return new Intl.Collator("en", {
@@ -533,8 +514,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
533
514
  throw new Error("The `CryptoKey` must be an `Ed25519` public key");
534
515
  }
535
516
  const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
536
- const [base58EncodedAddress] = getAddressDecoder().decode(new Uint8Array(publicKeyBytes));
537
- return base58EncodedAddress;
517
+ return getAddressDecoder().decode(new Uint8Array(publicKeyBytes));
538
518
  }
539
519
 
540
520
  // ../keys/dist/index.browser.js
@@ -559,94 +539,102 @@ this.globalThis.solanaWeb3 = (function (exports) {
559
539
  }
560
540
 
561
541
  // ../codecs-data-structures/dist/index.browser.js
562
- function sumCodecSizes(sizes) {
563
- return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
564
- }
565
- function getArrayLikeCodecSizeDescription(size) {
566
- return typeof size === "object" ? size.description : `${size}`;
567
- }
568
- function getArrayLikeCodecSizeFromChildren(size, childrenSizes) {
569
- if (typeof size !== "number")
570
- return null;
571
- if (size === 0)
572
- return 0;
573
- const childrenSize = sumCodecSizes(childrenSizes);
574
- return childrenSize === null ? null : childrenSize * size;
575
- }
576
- function getArrayLikeCodecSizePrefix(size, realSize) {
577
- return typeof size === "object" ? size.encode(realSize) : new Uint8Array();
578
- }
579
542
  function assertValidNumberOfItemsForCodec(codecDescription, expected, actual) {
580
543
  if (expected !== actual) {
581
544
  throw new Error(`Expected [${codecDescription}] to have ${expected} items, got ${actual}.`);
582
545
  }
583
546
  }
584
- function arrayCodecHelper(item, size, description) {
585
- if (size === "remainder" && item.fixedSize === null) {
586
- throw new Error('Codecs of "remainder" size must have fixed-size items.');
587
- }
588
- return {
589
- description: description != null ? description : `array(${item.description}; ${getArrayLikeCodecSizeDescription(size)})`,
590
- fixedSize: getArrayLikeCodecSizeFromChildren(size, [item.fixedSize]),
591
- maxSize: getArrayLikeCodecSizeFromChildren(size, [item.maxSize])
592
- };
547
+ function sumCodecSizes(sizes) {
548
+ return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
593
549
  }
594
- function getArrayEncoder(item, config = {}) {
550
+ function getFixedSize(codec) {
551
+ return isFixedSize(codec) ? codec.fixedSize : null;
552
+ }
553
+ function getMaxSize(codec) {
595
554
  var _a;
555
+ return isFixedSize(codec) ? codec.fixedSize : (_a = codec.maxSize) != null ? _a : null;
556
+ }
557
+ function getArrayEncoder(item, config = {}) {
558
+ var _a, _b;
596
559
  const size = (_a = config.size) != null ? _a : getU32Encoder();
597
- return {
598
- ...arrayCodecHelper(item, size, config.description),
599
- encode: (value) => {
560
+ if (size === "remainder") {
561
+ assertIsFixedSize(item, 'Codecs of "remainder" size must have fixed-size items.');
562
+ }
563
+ const fixedSize = computeArrayLikeCodecSize(size, getFixedSize(item));
564
+ const maxSize = (_b = computeArrayLikeCodecSize(size, getMaxSize(item))) != null ? _b : void 0;
565
+ return createEncoder({
566
+ ...fixedSize !== null ? { fixedSize } : {
567
+ getSizeFromValue: (array) => {
568
+ const prefixSize = typeof size === "object" ? getEncodedSize(array.length, size) : 0;
569
+ return prefixSize + [...array].reduce((all, value) => all + getEncodedSize(value, item), 0);
570
+ },
571
+ maxSize
572
+ },
573
+ write: (array, bytes, offset) => {
600
574
  if (typeof size === "number") {
601
- assertValidNumberOfItemsForCodec("array", size, value.length);
575
+ assertValidNumberOfItemsForCodec("array", size, array.length);
576
+ }
577
+ if (typeof size === "object") {
578
+ offset = size.write(array.length, bytes, offset);
602
579
  }
603
- return mergeBytes([getArrayLikeCodecSizePrefix(size, value.length), ...value.map((v) => item.encode(v))]);
580
+ array.forEach((value) => {
581
+ offset = item.write(value, bytes, offset);
582
+ });
583
+ return offset;
604
584
  }
605
- };
585
+ });
586
+ }
587
+ function computeArrayLikeCodecSize(size, itemSize) {
588
+ if (typeof size !== "number")
589
+ return null;
590
+ if (size === 0)
591
+ return 0;
592
+ return itemSize === null ? null : itemSize * size;
606
593
  }
607
594
  function getBytesEncoder(config = {}) {
608
- var _a, _b;
595
+ var _a;
609
596
  const size = (_a = config.size) != null ? _a : "variable";
610
- const sizeDescription = typeof size === "object" ? size.description : `${size}`;
611
- const description = (_b = config.description) != null ? _b : `bytes(${sizeDescription})`;
612
- const byteEncoder = {
613
- description,
614
- encode: (value) => value,
615
- fixedSize: null,
616
- maxSize: null
617
- };
597
+ const byteEncoder = createEncoder({
598
+ getSizeFromValue: (value) => value.length,
599
+ write: (value, bytes, offset) => {
600
+ bytes.set(value, offset);
601
+ return offset + value.length;
602
+ }
603
+ });
618
604
  if (size === "variable") {
619
605
  return byteEncoder;
620
606
  }
621
607
  if (typeof size === "number") {
622
- return fixEncoder(byteEncoder, size, description);
608
+ return fixEncoder(byteEncoder, size);
623
609
  }
624
- return {
625
- ...byteEncoder,
626
- encode: (value) => {
627
- const contentBytes = byteEncoder.encode(value);
628
- const lengthBytes = size.encode(contentBytes.length);
629
- return mergeBytes([lengthBytes, contentBytes]);
610
+ return createEncoder({
611
+ getSizeFromValue: (value) => getEncodedSize(value.length, size) + value.length,
612
+ write: (value, bytes, offset) => {
613
+ offset = size.write(value.length, bytes, offset);
614
+ return byteEncoder.write(value, bytes, offset);
630
615
  }
631
- };
632
- }
633
- function structCodecHelper(fields, description) {
634
- const fieldDescriptions = fields.map(([name, codec]) => `${String(name)}: ${codec.description}`).join(", ");
635
- return {
636
- description: description != null ? description : `struct(${fieldDescriptions})`,
637
- fixedSize: sumCodecSizes(fields.map(([, field]) => field.fixedSize)),
638
- maxSize: sumCodecSizes(fields.map(([, field]) => field.maxSize))
639
- };
616
+ });
640
617
  }
641
- function getStructEncoder(fields, config = {}) {
642
- return {
643
- ...structCodecHelper(fields, config.description),
644
- encode: (struct) => {
645
- const fieldBytes = fields.map(([key, codec]) => codec.encode(struct[key]));
646
- return mergeBytes(fieldBytes);
618
+ function getStructEncoder(fields) {
619
+ var _a;
620
+ const fieldCodecs = fields.map(([, codec]) => codec);
621
+ const fixedSize = sumCodecSizes(fieldCodecs.map(getFixedSize));
622
+ const maxSize = (_a = sumCodecSizes(fieldCodecs.map(getMaxSize))) != null ? _a : void 0;
623
+ return createEncoder({
624
+ ...fixedSize === null ? {
625
+ getSizeFromValue: (value) => fields.map(([key, codec]) => getEncodedSize(value[key], codec)).reduce((all, one) => all + one, 0),
626
+ maxSize
627
+ } : { fixedSize },
628
+ write: (struct, bytes, offset) => {
629
+ fields.forEach(([key, codec]) => {
630
+ offset = codec.write(struct[key], bytes, offset);
631
+ });
632
+ return offset;
647
633
  }
648
- };
634
+ });
649
635
  }
636
+
637
+ // ../transactions/dist/index.browser.js
650
638
  var AccountRole = /* @__PURE__ */ ((AccountRole2) => {
651
639
  AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */
652
640
  3] = "WRITABLE_SIGNER";
@@ -927,33 +915,20 @@ this.globalThis.solanaWeb3 = (function (exports) {
927
915
  version: transaction.version
928
916
  };
929
917
  }
930
- var lookupTableAddressDescription = "The address of the address lookup table account from which instruction addresses should be looked up" ;
931
- var writableIndicesDescription = "The indices of the accounts in the lookup table that should be loaded as writeable" ;
932
- var readableIndicesDescription = "The indices of the accounts in the lookup table that should be loaded as read-only" ;
933
- 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" ;
934
918
  var memoizedAddressTableLookupEncoder;
935
919
  function getAddressTableLookupEncoder() {
936
920
  if (!memoizedAddressTableLookupEncoder) {
937
- memoizedAddressTableLookupEncoder = getStructEncoder(
921
+ memoizedAddressTableLookupEncoder = getStructEncoder([
922
+ ["lookupTableAddress", getAddressEncoder()],
938
923
  [
939
- ["lookupTableAddress", getAddressEncoder({ description: lookupTableAddressDescription })],
940
- [
941
- "writableIndices",
942
- getArrayEncoder(getU8Encoder(), {
943
- description: writableIndicesDescription,
944
- size: getShortU16Encoder()
945
- })
946
- ],
947
- [
948
- "readableIndices",
949
- getArrayEncoder(getU8Encoder(), {
950
- description: readableIndicesDescription,
951
- size: getShortU16Encoder()
952
- })
953
- ]
924
+ "writableIndices",
925
+ getArrayEncoder(getU8Encoder(), { size: getShortU16Encoder() })
954
926
  ],
955
- { description: addressTableLookupDescription }
956
- );
927
+ [
928
+ "readableIndices",
929
+ getArrayEncoder(getU8Encoder(), { size: getShortU16Encoder() })
930
+ ]
931
+ ]);
957
932
  }
958
933
  return memoizedAddressTableLookupEncoder;
959
934
  }
@@ -963,47 +938,21 @@ this.globalThis.solanaWeb3 = (function (exports) {
963
938
  memoizedU8Encoder = getU8Encoder();
964
939
  return memoizedU8Encoder;
965
940
  }
966
- function getMemoizedU8EncoderDescription(description) {
967
- const encoder = getMemoizedU8Encoder();
968
- return {
969
- ...encoder,
970
- description: description != null ? description : encoder.description
971
- };
972
- }
973
- var numSignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction" ;
974
- 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" ;
975
- var numReadonlyNonSignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable" ;
976
- var messageHeaderDescription = "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses" ;
977
941
  function getMessageHeaderEncoder() {
978
- return getStructEncoder(
979
- [
980
- ["numSignerAccounts", getMemoizedU8EncoderDescription(numSignerAccountsDescription)],
981
- ["numReadonlySignerAccounts", getMemoizedU8EncoderDescription(numReadonlySignerAccountsDescription)],
982
- ["numReadonlyNonSignerAccounts", getMemoizedU8EncoderDescription(numReadonlyNonSignerAccountsDescription)]
983
- ],
984
- {
985
- description: messageHeaderDescription
986
- }
987
- );
942
+ return getStructEncoder([
943
+ ["numSignerAccounts", getMemoizedU8Encoder()],
944
+ ["numReadonlySignerAccounts", getMemoizedU8Encoder()],
945
+ ["numReadonlyNonSignerAccounts", getMemoizedU8Encoder()]
946
+ ]);
988
947
  }
989
- var programAddressIndexDescription = "The index of the program being called, according to the well-ordered accounts list for this transaction" ;
990
- var accountIndexDescription = "The index of an account, according to the well-ordered accounts list for this transaction" ;
991
- 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" ;
992
- var dataDescription = "An optional buffer of data passed to the instruction" ;
993
948
  var memoizedGetInstructionEncoder;
994
949
  function getInstructionEncoder() {
995
950
  if (!memoizedGetInstructionEncoder) {
996
951
  memoizedGetInstructionEncoder = mapEncoder(
997
952
  getStructEncoder([
998
- ["programAddressIndex", getU8Encoder({ description: programAddressIndexDescription })],
999
- [
1000
- "accountIndices",
1001
- getArrayEncoder(getU8Encoder({ description: accountIndexDescription }), {
1002
- description: accountIndicesDescription,
1003
- size: getShortU16Encoder()
1004
- })
1005
- ],
1006
- ["data", getBytesEncoder({ description: dataDescription, size: getShortU16Encoder() })]
953
+ ["programAddressIndex", getU8Encoder()],
954
+ ["accountIndices", getArrayEncoder(getU8Encoder(), { size: getShortU16Encoder() })],
955
+ ["data", getBytesEncoder({ size: getShortU16Encoder() })]
1007
956
  ]),
1008
957
  // Convert an instruction to have all fields defined
1009
958
  (instruction) => {
@@ -1022,30 +971,22 @@ this.globalThis.solanaWeb3 = (function (exports) {
1022
971
  return memoizedGetInstructionEncoder;
1023
972
  }
1024
973
  var VERSION_FLAG_MASK = 128;
1025
- var BASE_CONFIG = {
1026
- description: "A single byte that encodes the version of the transaction" ,
1027
- fixedSize: null,
1028
- maxSize: 1
1029
- };
1030
- function encode(value) {
1031
- if (value === "legacy") {
1032
- return new Uint8Array();
1033
- }
1034
- if (value < 0 || value > 127) {
1035
- throw new Error(`Transaction version must be in the range [0, 127]. \`${value}\` given.`);
1036
- }
1037
- return new Uint8Array([value | VERSION_FLAG_MASK]);
1038
- }
1039
974
  function getTransactionVersionEncoder() {
1040
- return {
1041
- ...BASE_CONFIG,
1042
- encode
1043
- };
975
+ return createEncoder({
976
+ getSizeFromValue: (value) => value === "legacy" ? 0 : 1,
977
+ maxSize: 1,
978
+ write: (value, bytes, offset) => {
979
+ if (value === "legacy") {
980
+ return offset;
981
+ }
982
+ if (value < 0 || value > 127) {
983
+ throw new Error(`Transaction version must be in the range [0, 127]. \`${value}\` given.`);
984
+ }
985
+ bytes.set([value | VERSION_FLAG_MASK], offset);
986
+ return offset + 1;
987
+ }
988
+ });
1044
989
  }
1045
- var staticAccountsDescription = "A compact-array of static account addresses belonging to this transaction" ;
1046
- var lifetimeTokenDescription = "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" ;
1047
- var instructionsDescription = "A compact-array of instructions belonging to this transaction" ;
1048
- var addressTableLookupsDescription = "A compact array of address table lookups belonging to this transaction" ;
1049
990
  function getCompiledMessageLegacyEncoder() {
1050
991
  return getStructEncoder(getPreludeStructEncoderTuple());
1051
992
  }
@@ -1071,50 +1012,31 @@ this.globalThis.solanaWeb3 = (function (exports) {
1071
1012
  return [
1072
1013
  ["version", getTransactionVersionEncoder()],
1073
1014
  ["header", getMessageHeaderEncoder()],
1074
- [
1075
- "staticAccounts",
1076
- getArrayEncoder(getAddressEncoder(), {
1077
- description: staticAccountsDescription,
1078
- size: getShortU16Encoder()
1079
- })
1080
- ],
1081
- [
1082
- "lifetimeToken",
1083
- getStringEncoder({
1084
- description: lifetimeTokenDescription,
1085
- encoding: getBase58Encoder(),
1086
- size: 32
1087
- })
1088
- ],
1089
- [
1090
- "instructions",
1091
- getArrayEncoder(getInstructionEncoder(), {
1092
- description: instructionsDescription,
1093
- size: getShortU16Encoder()
1094
- })
1095
- ]
1015
+ ["staticAccounts", getArrayEncoder(getAddressEncoder(), { size: getShortU16Encoder() })],
1016
+ ["lifetimeToken", getStringEncoder({ encoding: getBase58Encoder(), size: 32 })],
1017
+ ["instructions", getArrayEncoder(getInstructionEncoder(), { size: getShortU16Encoder() })]
1096
1018
  ];
1097
1019
  }
1098
1020
  function getAddressTableLookupArrayEncoder() {
1099
- return getArrayEncoder(getAddressTableLookupEncoder(), {
1100
- description: addressTableLookupsDescription,
1101
- size: getShortU16Encoder()
1102
- });
1021
+ return getArrayEncoder(getAddressTableLookupEncoder(), { size: getShortU16Encoder() });
1103
1022
  }
1104
- var messageDescription = "The wire format of a Solana transaction message" ;
1105
1023
  function getCompiledMessageEncoder() {
1106
- return {
1107
- description: messageDescription,
1108
- encode: (compiledMessage) => {
1024
+ return createEncoder({
1025
+ getSizeFromValue: (compiledMessage) => {
1109
1026
  if (compiledMessage.version === "legacy") {
1110
- return getCompiledMessageLegacyEncoder().encode(compiledMessage);
1027
+ return getCompiledMessageLegacyEncoder().getSizeFromValue(compiledMessage);
1111
1028
  } else {
1112
- return getCompiledMessageVersionedEncoder().encode(compiledMessage);
1029
+ return getCompiledMessageVersionedEncoder().getSizeFromValue(compiledMessage);
1113
1030
  }
1114
1031
  },
1115
- fixedSize: null,
1116
- maxSize: null
1117
- };
1032
+ write: (compiledMessage, bytes, offset) => {
1033
+ if (compiledMessage.version === "legacy") {
1034
+ return getCompiledMessageLegacyEncoder().write(compiledMessage, bytes, offset);
1035
+ } else {
1036
+ return getCompiledMessageVersionedEncoder().write(compiledMessage, bytes, offset);
1037
+ }
1038
+ }
1039
+ });
1118
1040
  }
1119
1041
  async function partiallySignTransaction(keyPairs, transaction) {
1120
1042
  const compiledMessage = compileMessage(transaction);
@@ -1329,11 +1251,14 @@ this.globalThis.solanaWeb3 = (function (exports) {
1329
1251
  }
1330
1252
  async function signModifyingAndPartialTransactionSigners(transaction, modifyingSigners = [], partialSigners = [], abortSignal) {
1331
1253
  var _a;
1332
- const modifiedTransaction = await modifyingSigners.reduce(async (transaction2, modifyingSigner) => {
1333
- abortSignal == null ? void 0 : abortSignal.throwIfAborted();
1334
- const [tx] = await modifyingSigner.modifyAndSignTransactions([await transaction2], { abortSignal });
1335
- return Object.freeze(tx);
1336
- }, Promise.resolve(transaction));
1254
+ const modifiedTransaction = await modifyingSigners.reduce(
1255
+ async (transaction2, modifyingSigner) => {
1256
+ abortSignal == null ? void 0 : abortSignal.throwIfAborted();
1257
+ const [tx] = await modifyingSigner.modifyAndSignTransactions([await transaction2], { abortSignal });
1258
+ return Object.freeze(tx);
1259
+ },
1260
+ Promise.resolve(transaction)
1261
+ );
1337
1262
  abortSignal == null ? void 0 : abortSignal.throwIfAborted();
1338
1263
  const signatureDictionaries = await Promise.all(
1339
1264
  partialSigners.map(async (partialSigner) => {