@solana/transactions 2.0.0-experimental.e6fc977 → 2.0.0-experimental.e72afd8

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.
@@ -57,7 +57,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
57
57
  }
58
58
  return {
59
59
  decode: decoder.decode,
60
- description: description ?? encoder.description,
60
+ description: description != null ? description : encoder.description,
61
61
  encode: encoder.encode,
62
62
  fixedSize: encoder.fixedSize,
63
63
  maxSize: encoder.maxSize
@@ -65,7 +65,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
65
65
  }
66
66
  function fixCodecHelper(data, fixedBytes, description) {
67
67
  return {
68
- description: description ?? `fixed(${fixedBytes}, ${data.description})`,
68
+ description: description != null ? description : `fixed(${fixedBytes}, ${data.description})`,
69
69
  fixedSize: fixedBytes,
70
70
  maxSize: fixedBytes
71
71
  };
@@ -121,14 +121,15 @@ this.globalThis.solanaWeb3 = (function (exports) {
121
121
  }
122
122
  }
123
123
  function sharedNumberFactory(input) {
124
+ var _a;
124
125
  let littleEndian;
125
126
  let defaultDescription = input.name;
126
127
  if (input.size > 1) {
127
- littleEndian = !("endian" in input.options) || input.options.endian === 0;
128
+ littleEndian = !("endian" in input.config) || input.config.endian === 0;
128
129
  defaultDescription += littleEndian ? "(le)" : "(be)";
129
130
  }
130
131
  return {
131
- description: input.options.description ?? defaultDescription,
132
+ description: (_a = input.config.description) != null ? _a : defaultDescription,
132
133
  fixedSize: input.size,
133
134
  littleEndian,
134
135
  maxSize: input.size
@@ -165,74 +166,80 @@ this.globalThis.solanaWeb3 = (function (exports) {
165
166
  };
166
167
  }
167
168
  function toArrayBuffer(bytes, offset, length) {
168
- const bytesOffset = bytes.byteOffset + (offset ?? 0);
169
- const bytesLength = length ?? bytes.byteLength;
169
+ const bytesOffset = bytes.byteOffset + (offset != null ? offset : 0);
170
+ const bytesLength = length != null ? length : bytes.byteLength;
170
171
  return bytes.buffer.slice(bytesOffset, bytesOffset + bytesLength);
171
172
  }
172
- var getShortU16Encoder = (options = {}) => ({
173
- description: options.description ?? "shortU16",
174
- encode: (value) => {
175
- assertNumberIsBetweenForCodec("shortU16", 0, 65535, value);
176
- const bytes = [0];
177
- for (let ii = 0; ; ii += 1) {
178
- const alignedValue = value >> ii * 7;
179
- if (alignedValue === 0) {
180
- break;
181
- }
182
- const nextSevenBits = 127 & alignedValue;
183
- bytes[ii] = nextSevenBits;
184
- if (ii > 0) {
185
- bytes[ii - 1] |= 128;
173
+ var getShortU16Encoder = (config = {}) => {
174
+ var _a;
175
+ return {
176
+ description: (_a = config.description) != null ? _a : "shortU16",
177
+ encode: (value) => {
178
+ assertNumberIsBetweenForCodec("shortU16", 0, 65535, value);
179
+ const bytes = [0];
180
+ for (let ii = 0; ; ii += 1) {
181
+ const alignedValue = value >> ii * 7;
182
+ if (alignedValue === 0) {
183
+ break;
184
+ }
185
+ const nextSevenBits = 127 & alignedValue;
186
+ bytes[ii] = nextSevenBits;
187
+ if (ii > 0) {
188
+ bytes[ii - 1] |= 128;
189
+ }
186
190
  }
187
- }
188
- return new Uint8Array(bytes);
189
- },
190
- fixedSize: null,
191
- maxSize: 3
192
- });
193
- var getShortU16Decoder = (options = {}) => ({
194
- decode: (bytes, offset = 0) => {
195
- let value = 0;
196
- let byteCount = 0;
197
- while (++byteCount) {
198
- const byteIndex = byteCount - 1;
199
- const currentByte = bytes[offset + byteIndex];
200
- const nextSevenBits = 127 & currentByte;
201
- value |= nextSevenBits << byteIndex * 7;
202
- if ((currentByte & 128) === 0) {
203
- break;
191
+ return new Uint8Array(bytes);
192
+ },
193
+ fixedSize: null,
194
+ maxSize: 3
195
+ };
196
+ };
197
+ var getShortU16Decoder = (config = {}) => {
198
+ var _a;
199
+ return {
200
+ decode: (bytes, offset = 0) => {
201
+ let value = 0;
202
+ let byteCount = 0;
203
+ while (++byteCount) {
204
+ const byteIndex = byteCount - 1;
205
+ const currentByte = bytes[offset + byteIndex];
206
+ const nextSevenBits = 127 & currentByte;
207
+ value |= nextSevenBits << byteIndex * 7;
208
+ if ((currentByte & 128) === 0) {
209
+ break;
210
+ }
204
211
  }
205
- }
206
- return [value, offset + byteCount];
207
- },
208
- description: options.description ?? "shortU16",
209
- fixedSize: null,
210
- maxSize: 3
211
- });
212
- var getU32Encoder = (options = {}) => numberEncoderFactory({
212
+ return [value, offset + byteCount];
213
+ },
214
+ description: (_a = config.description) != null ? _a : "shortU16",
215
+ fixedSize: null,
216
+ maxSize: 3
217
+ };
218
+ };
219
+ var getU32Encoder = (config = {}) => numberEncoderFactory({
220
+ config,
213
221
  name: "u32",
214
- options,
215
222
  range: [0, Number("0xffffffff")],
216
223
  set: (view, value, le) => view.setUint32(0, value, le),
217
224
  size: 4
218
225
  });
219
- var getU32Decoder = (options = {}) => numberDecoderFactory({
226
+ var getU32Decoder = (config = {}) => numberDecoderFactory({
227
+ config,
220
228
  get: (view, le) => view.getUint32(0, le),
221
229
  name: "u32",
222
- options,
223
230
  size: 4
224
231
  });
225
- var getU8Encoder = (options = {}) => numberEncoderFactory({
232
+ var getU8Encoder = (config = {}) => numberEncoderFactory({
233
+ config,
226
234
  name: "u8",
227
- options,
228
235
  range: [0, Number("0xff")],
229
236
  set: (view, value) => view.setUint8(0, value),
230
237
  size: 1
231
238
  });
232
- var getU8Decoder = (options = {}) => numberDecoderFactory({
239
+ var getU8Decoder = (config = {}) => numberDecoderFactory({
240
+ config,
233
241
  get: (view) => view.getUint8(0),
234
242
  name: "u8",
235
- options,
236
243
  size: 1
237
244
  });
238
245
 
@@ -304,6 +311,20 @@ this.globalThis.solanaWeb3 = (function (exports) {
304
311
  var alphabet2 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
305
312
  var getBase58Encoder = () => getBaseXEncoder(alphabet2);
306
313
  var getBase58Decoder = () => getBaseXDecoder(alphabet2);
314
+ var getBase64Decoder = () => {
315
+ {
316
+ return {
317
+ decode(bytes, offset = 0) {
318
+ const slice = bytes.slice(offset);
319
+ const value = btoa(String.fromCharCode(...slice));
320
+ return [value, bytes.length];
321
+ },
322
+ description: `base64`,
323
+ fixedSize: null,
324
+ maxSize: null
325
+ };
326
+ }
327
+ };
307
328
  var removeNullCharacters = (value) => (
308
329
  // eslint-disable-next-line no-control-regex
309
330
  value.replace(/\u0000/g, "")
@@ -331,10 +352,11 @@ this.globalThis.solanaWeb3 = (function (exports) {
331
352
  maxSize: null
332
353
  };
333
354
  };
334
- var getStringEncoder = (options = {}) => {
335
- const size = options.size ?? getU32Encoder();
336
- const encoding = options.encoding ?? getUtf8Encoder();
337
- const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
355
+ var getStringEncoder = (config = {}) => {
356
+ var _a, _b, _c;
357
+ const size = (_a = config.size) != null ? _a : getU32Encoder();
358
+ const encoding = (_b = config.encoding) != null ? _b : getUtf8Encoder();
359
+ const description = (_c = config.description) != null ? _c : `string(${encoding.description}; ${getSizeDescription(size)})`;
338
360
  if (size === "variable") {
339
361
  return { ...encoding, description };
340
362
  }
@@ -352,10 +374,11 @@ this.globalThis.solanaWeb3 = (function (exports) {
352
374
  maxSize: null
353
375
  };
354
376
  };
355
- var getStringDecoder = (options = {}) => {
356
- const size = options.size ?? getU32Decoder();
357
- const encoding = options.encoding ?? getUtf8Decoder();
358
- const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
377
+ var getStringDecoder = (config = {}) => {
378
+ var _a, _b, _c;
379
+ const size = (_a = config.size) != null ? _a : getU32Decoder();
380
+ const encoding = (_b = config.encoding) != null ? _b : getUtf8Decoder();
381
+ const description = (_c = config.description) != null ? _c : `string(${encoding.description}; ${getSizeDescription(size)})`;
359
382
  if (size === "variable") {
360
383
  return { ...encoding, description };
361
384
  }
@@ -491,9 +514,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
491
514
  };
492
515
  }
493
516
  function isAdvanceNonceAccountInstruction(instruction) {
517
+ var _a;
494
518
  return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
495
519
  instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts
496
- instruction.accounts?.length === 3 && // First account is nonce account address
520
+ ((_a = instruction.accounts) == null ? void 0 : _a.length) === 3 && // First account is nonce account address
497
521
  instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole.WRITABLE && // Second account is recent blockhashes sysvar
498
522
  instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole.READONLY && // Third account is nonce authority account
499
523
  instruction.accounts[2].address != null && isSignerRole(instruction.accounts[2].role);
@@ -575,184 +599,6 @@ this.globalThis.solanaWeb3 = (function (exports) {
575
599
  return out;
576
600
  }
577
601
 
578
- // ../codecs-data-structures/dist/index.browser.js
579
- function sumCodecSizes(sizes) {
580
- return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
581
- }
582
- function decodeArrayLikeCodecSize(size, childrenSizes, bytes, offset) {
583
- if (typeof size === "number") {
584
- return [size, offset];
585
- }
586
- if (typeof size === "object") {
587
- return size.decode(bytes, offset);
588
- }
589
- if (size === "remainder") {
590
- const childrenSize = sumCodecSizes(childrenSizes);
591
- if (childrenSize === null) {
592
- throw new Error('Codecs of "remainder" size must have fixed-size items.');
593
- }
594
- const remainder = bytes.slice(offset).length;
595
- if (remainder % childrenSize !== 0) {
596
- throw new Error(
597
- `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.`
598
- );
599
- }
600
- return [remainder / childrenSize, offset];
601
- }
602
- throw new Error(`Unrecognized array-like codec size: ${JSON.stringify(size)}`);
603
- }
604
- function getArrayLikeCodecSizeDescription(size) {
605
- return typeof size === "object" ? size.description : `${size}`;
606
- }
607
- function getArrayLikeCodecSizeFromChildren(size, childrenSizes) {
608
- if (typeof size !== "number")
609
- return null;
610
- if (size === 0)
611
- return 0;
612
- const childrenSize = sumCodecSizes(childrenSizes);
613
- return childrenSize === null ? null : childrenSize * size;
614
- }
615
- function getArrayLikeCodecSizePrefix(size, realSize) {
616
- return typeof size === "object" ? size.encode(realSize) : new Uint8Array();
617
- }
618
- function assertValidNumberOfItemsForCodec(codecDescription, expected, actual) {
619
- if (expected !== actual) {
620
- throw new Error(`Expected [${codecDescription}] to have ${expected} items, got ${actual}.`);
621
- }
622
- }
623
- function arrayCodecHelper(item, size, description) {
624
- if (size === "remainder" && item.fixedSize === null) {
625
- throw new Error('Codecs of "remainder" size must have fixed-size items.');
626
- }
627
- return {
628
- description: description ?? `array(${item.description}; ${getArrayLikeCodecSizeDescription(size)})`,
629
- fixedSize: getArrayLikeCodecSizeFromChildren(size, [item.fixedSize]),
630
- maxSize: getArrayLikeCodecSizeFromChildren(size, [item.maxSize])
631
- };
632
- }
633
- function getArrayEncoder(item, options = {}) {
634
- const size = options.size ?? getU32Encoder();
635
- return {
636
- ...arrayCodecHelper(item, size, options.description),
637
- encode: (value) => {
638
- if (typeof size === "number") {
639
- assertValidNumberOfItemsForCodec("array", size, value.length);
640
- }
641
- return mergeBytes([getArrayLikeCodecSizePrefix(size, value.length), ...value.map((v) => item.encode(v))]);
642
- }
643
- };
644
- }
645
- function getArrayDecoder(item, options = {}) {
646
- const size = options.size ?? getU32Decoder();
647
- return {
648
- ...arrayCodecHelper(item, size, options.description),
649
- decode: (bytes, offset = 0) => {
650
- if (typeof size === "object" && bytes.slice(offset).length === 0) {
651
- return [[], offset];
652
- }
653
- const [resolvedSize, newOffset] = decodeArrayLikeCodecSize(size, [item.fixedSize], bytes, offset);
654
- offset = newOffset;
655
- const values = [];
656
- for (let i = 0; i < resolvedSize; i += 1) {
657
- const [value, newOffset2] = item.decode(bytes, offset);
658
- values.push(value);
659
- offset = newOffset2;
660
- }
661
- return [values, offset];
662
- }
663
- };
664
- }
665
- function getBytesEncoder(options = {}) {
666
- const size = options.size ?? "variable";
667
- const sizeDescription = typeof size === "object" ? size.description : `${size}`;
668
- const description = options.description ?? `bytes(${sizeDescription})`;
669
- const byteEncoder = {
670
- description,
671
- encode: (value) => value,
672
- fixedSize: null,
673
- maxSize: null
674
- };
675
- if (size === "variable") {
676
- return byteEncoder;
677
- }
678
- if (typeof size === "number") {
679
- return fixEncoder(byteEncoder, size, description);
680
- }
681
- return {
682
- ...byteEncoder,
683
- encode: (value) => {
684
- const contentBytes = byteEncoder.encode(value);
685
- const lengthBytes = size.encode(contentBytes.length);
686
- return mergeBytes([lengthBytes, contentBytes]);
687
- }
688
- };
689
- }
690
- function getBytesDecoder(options = {}) {
691
- const size = options.size ?? "variable";
692
- const sizeDescription = typeof size === "object" ? size.description : `${size}`;
693
- const description = options.description ?? `bytes(${sizeDescription})`;
694
- const byteDecoder = {
695
- decode: (bytes, offset = 0) => {
696
- const slice = bytes.slice(offset);
697
- return [slice, offset + slice.length];
698
- },
699
- description,
700
- fixedSize: null,
701
- maxSize: null
702
- };
703
- if (size === "variable") {
704
- return byteDecoder;
705
- }
706
- if (typeof size === "number") {
707
- return fixDecoder(byteDecoder, size, description);
708
- }
709
- return {
710
- ...byteDecoder,
711
- decode: (bytes, offset = 0) => {
712
- assertByteArrayIsNotEmptyForCodec("bytes", bytes, offset);
713
- const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);
714
- const length = Number(lengthBigInt);
715
- offset = lengthOffset;
716
- const contentBytes = bytes.slice(offset, offset + length);
717
- assertByteArrayHasEnoughBytesForCodec("bytes", length, contentBytes);
718
- const [value, contentOffset] = byteDecoder.decode(contentBytes);
719
- offset += contentOffset;
720
- return [value, offset];
721
- }
722
- };
723
- }
724
- function structCodecHelper(fields, description) {
725
- const fieldDescriptions = fields.map(([name, codec]) => `${String(name)}: ${codec.description}`).join(", ");
726
- return {
727
- description: description ?? `struct(${fieldDescriptions})`,
728
- fixedSize: sumCodecSizes(fields.map(([, field]) => field.fixedSize)),
729
- maxSize: sumCodecSizes(fields.map(([, field]) => field.maxSize))
730
- };
731
- }
732
- function getStructEncoder(fields, options = {}) {
733
- return {
734
- ...structCodecHelper(fields, options.description),
735
- encode: (struct) => {
736
- const fieldBytes = fields.map(([key, codec]) => codec.encode(struct[key]));
737
- return mergeBytes(fieldBytes);
738
- }
739
- };
740
- }
741
- function getStructDecoder(fields, options = {}) {
742
- return {
743
- ...structCodecHelper(fields, options.description),
744
- decode: (bytes, offset = 0) => {
745
- const struct = {};
746
- fields.forEach(([key, codec]) => {
747
- const [value, newOffset] = codec.decode(bytes, offset);
748
- offset = newOffset;
749
- struct[key] = value;
750
- });
751
- return [struct, offset];
752
- }
753
- };
754
- }
755
-
756
602
  // ../assertions/dist/index.browser.js
757
603
  function assertIsSecureContext() {
758
604
  if (!globalThis.isSecureContext) {
@@ -762,14 +608,16 @@ this.globalThis.solanaWeb3 = (function (exports) {
762
608
  }
763
609
  }
764
610
  async function assertKeyExporterIsAvailable() {
611
+ var _a;
765
612
  assertIsSecureContext();
766
- if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.exportKey !== "function") {
613
+ if (typeof globalThis.crypto === "undefined" || typeof ((_a = globalThis.crypto.subtle) == null ? void 0 : _a.exportKey) !== "function") {
767
614
  throw new Error("No key export implementation could be found");
768
615
  }
769
616
  }
770
617
  async function assertSigningCapabilityIsAvailable() {
618
+ var _a;
771
619
  assertIsSecureContext();
772
- if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.sign !== "function") {
620
+ if (typeof globalThis.crypto === "undefined" || typeof ((_a = globalThis.crypto.subtle) == null ? void 0 : _a.sign) !== "function") {
773
621
  throw new Error("No signing implementation could be found");
774
622
  }
775
623
  }
@@ -813,9 +661,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
813
661
  return putativeAddress;
814
662
  }
815
663
  function getAddressEncoder(config) {
664
+ var _a;
816
665
  return mapEncoder(
817
666
  getStringEncoder({
818
- description: config?.description ?? "Address",
667
+ description: (_a = config == null ? void 0 : config.description) != null ? _a : "Address",
819
668
  encoding: getMemoizedBase58Encoder(),
820
669
  size: 32
821
670
  }),
@@ -823,8 +672,9 @@ this.globalThis.solanaWeb3 = (function (exports) {
823
672
  );
824
673
  }
825
674
  function getAddressDecoder(config) {
675
+ var _a;
826
676
  return getStringDecoder({
827
- description: config?.description ?? "Address",
677
+ description: (_a = config == null ? void 0 : config.description) != null ? _a : "Address",
828
678
  encoding: getMemoizedBase58Decoder(),
829
679
  size: 32
830
680
  });
@@ -851,7 +701,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
851
701
 
852
702
  // src/accounts.ts
853
703
  function upsert(addressMap, address2, update) {
854
- addressMap[address2] = update(addressMap[address2] ?? { role: AccountRole.READONLY });
704
+ var _a;
705
+ addressMap[address2] = update((_a = addressMap[address2]) != null ? _a : { role: AccountRole.READONLY });
855
706
  }
856
707
  var TYPE = Symbol("AddressMapTypeProperty");
857
708
  function getAddressMapFromInstructions(feePayer, instructions) {
@@ -1119,139 +970,186 @@ this.globalThis.solanaWeb3 = (function (exports) {
1119
970
  };
1120
971
  }
1121
972
 
1122
- // src/compile-transaction.ts
1123
- function getCompiledTransaction(transaction) {
1124
- const compiledMessage = compileMessage(transaction);
1125
- let signatures;
1126
- if ("signatures" in transaction) {
1127
- signatures = [];
1128
- for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
1129
- signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
973
+ // ../codecs-data-structures/dist/index.browser.js
974
+ function sumCodecSizes(sizes) {
975
+ return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
976
+ }
977
+ function decodeArrayLikeCodecSize(size, childrenSizes, bytes, offset) {
978
+ if (typeof size === "number") {
979
+ return [size, offset];
980
+ }
981
+ if (typeof size === "object") {
982
+ return size.decode(bytes, offset);
983
+ }
984
+ if (size === "remainder") {
985
+ const childrenSize = sumCodecSizes(childrenSizes);
986
+ if (childrenSize === null) {
987
+ throw new Error('Codecs of "remainder" size must have fixed-size items.');
1130
988
  }
1131
- } else {
1132
- signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
989
+ const remainder = bytes.slice(offset).length;
990
+ if (remainder % childrenSize !== 0) {
991
+ throw new Error(
992
+ `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.`
993
+ );
994
+ }
995
+ return [remainder / childrenSize, offset];
1133
996
  }
1134
- return {
1135
- compiledMessage,
1136
- signatures
1137
- };
997
+ throw new Error(`Unrecognized array-like codec size: ${JSON.stringify(size)}`);
1138
998
  }
1139
-
1140
- // ../functional/dist/index.browser.js
1141
- function pipe(init, ...fns) {
1142
- return fns.reduce((acc, fn) => fn(acc), init);
999
+ function getArrayLikeCodecSizeDescription(size) {
1000
+ return typeof size === "object" ? size.description : `${size}`;
1143
1001
  }
1144
-
1145
- // src/decompile-transaction.ts
1146
- function getAccountMetas(message) {
1147
- const { header } = message;
1148
- const numWritableSignerAccounts = header.numSignerAccounts - header.numReadonlySignerAccounts;
1149
- const numWritableNonSignerAccounts = message.staticAccounts.length - header.numSignerAccounts - header.numReadonlyNonSignerAccounts;
1150
- const accountMetas = [];
1151
- let accountIndex = 0;
1152
- for (let i = 0; i < numWritableSignerAccounts; i++) {
1153
- accountMetas.push({
1154
- address: message.staticAccounts[accountIndex],
1155
- role: AccountRole.WRITABLE_SIGNER
1156
- });
1157
- accountIndex++;
1158
- }
1159
- for (let i = 0; i < header.numReadonlySignerAccounts; i++) {
1160
- accountMetas.push({
1161
- address: message.staticAccounts[accountIndex],
1162
- role: AccountRole.READONLY_SIGNER
1163
- });
1164
- accountIndex++;
1165
- }
1166
- for (let i = 0; i < numWritableNonSignerAccounts; i++) {
1167
- accountMetas.push({
1168
- address: message.staticAccounts[accountIndex],
1169
- role: AccountRole.WRITABLE
1170
- });
1171
- accountIndex++;
1002
+ function getArrayLikeCodecSizeFromChildren(size, childrenSizes) {
1003
+ if (typeof size !== "number")
1004
+ return null;
1005
+ if (size === 0)
1006
+ return 0;
1007
+ const childrenSize = sumCodecSizes(childrenSizes);
1008
+ return childrenSize === null ? null : childrenSize * size;
1009
+ }
1010
+ function getArrayLikeCodecSizePrefix(size, realSize) {
1011
+ return typeof size === "object" ? size.encode(realSize) : new Uint8Array();
1012
+ }
1013
+ function assertValidNumberOfItemsForCodec(codecDescription, expected, actual) {
1014
+ if (expected !== actual) {
1015
+ throw new Error(`Expected [${codecDescription}] to have ${expected} items, got ${actual}.`);
1172
1016
  }
1173
- for (let i = 0; i < header.numReadonlyNonSignerAccounts; i++) {
1174
- accountMetas.push({
1175
- address: message.staticAccounts[accountIndex],
1176
- role: AccountRole.READONLY
1177
- });
1178
- accountIndex++;
1017
+ }
1018
+ function arrayCodecHelper(item, size, description) {
1019
+ if (size === "remainder" && item.fixedSize === null) {
1020
+ throw new Error('Codecs of "remainder" size must have fixed-size items.');
1179
1021
  }
1180
- return accountMetas;
1022
+ return {
1023
+ description: description != null ? description : `array(${item.description}; ${getArrayLikeCodecSizeDescription(size)})`,
1024
+ fixedSize: getArrayLikeCodecSizeFromChildren(size, [item.fixedSize]),
1025
+ maxSize: getArrayLikeCodecSizeFromChildren(size, [item.maxSize])
1026
+ };
1181
1027
  }
1182
- function convertInstruction(instruction, accountMetas) {
1183
- const programAddress = accountMetas[instruction.programAddressIndex]?.address;
1184
- if (!programAddress) {
1185
- throw new Error(`Could not find program address at index ${instruction.programAddressIndex}`);
1028
+ function getArrayEncoder(item, config = {}) {
1029
+ var _a;
1030
+ const size = (_a = config.size) != null ? _a : getU32Encoder();
1031
+ return {
1032
+ ...arrayCodecHelper(item, size, config.description),
1033
+ encode: (value) => {
1034
+ if (typeof size === "number") {
1035
+ assertValidNumberOfItemsForCodec("array", size, value.length);
1036
+ }
1037
+ return mergeBytes([getArrayLikeCodecSizePrefix(size, value.length), ...value.map((v) => item.encode(v))]);
1038
+ }
1039
+ };
1040
+ }
1041
+ function getArrayDecoder(item, config = {}) {
1042
+ var _a;
1043
+ const size = (_a = config.size) != null ? _a : getU32Decoder();
1044
+ return {
1045
+ ...arrayCodecHelper(item, size, config.description),
1046
+ decode: (bytes, offset = 0) => {
1047
+ if (typeof size === "object" && bytes.slice(offset).length === 0) {
1048
+ return [[], offset];
1049
+ }
1050
+ const [resolvedSize, newOffset] = decodeArrayLikeCodecSize(size, [item.fixedSize], bytes, offset);
1051
+ offset = newOffset;
1052
+ const values = [];
1053
+ for (let i = 0; i < resolvedSize; i += 1) {
1054
+ const [value, newOffset2] = item.decode(bytes, offset);
1055
+ values.push(value);
1056
+ offset = newOffset2;
1057
+ }
1058
+ return [values, offset];
1059
+ }
1060
+ };
1061
+ }
1062
+ function getBytesEncoder(config = {}) {
1063
+ var _a, _b;
1064
+ const size = (_a = config.size) != null ? _a : "variable";
1065
+ const sizeDescription = typeof size === "object" ? size.description : `${size}`;
1066
+ const description = (_b = config.description) != null ? _b : `bytes(${sizeDescription})`;
1067
+ const byteEncoder = {
1068
+ description,
1069
+ encode: (value) => value,
1070
+ fixedSize: null,
1071
+ maxSize: null
1072
+ };
1073
+ if (size === "variable") {
1074
+ return byteEncoder;
1075
+ }
1076
+ if (typeof size === "number") {
1077
+ return fixEncoder(byteEncoder, size, description);
1186
1078
  }
1187
- const accounts = instruction.accountIndices?.map((accountIndex) => accountMetas[accountIndex]);
1188
- const { data } = instruction;
1189
1079
  return {
1190
- programAddress,
1191
- ...accounts && accounts.length ? { accounts } : {},
1192
- ...data && data.length ? { data } : {}
1080
+ ...byteEncoder,
1081
+ encode: (value) => {
1082
+ const contentBytes = byteEncoder.encode(value);
1083
+ const lengthBytes = size.encode(contentBytes.length);
1084
+ return mergeBytes([lengthBytes, contentBytes]);
1085
+ }
1193
1086
  };
1194
1087
  }
1195
- function getLifetimeConstraint(messageLifetimeToken, firstInstruction, lastValidBlockHeight) {
1196
- if (!firstInstruction || !isAdvanceNonceAccountInstruction(firstInstruction)) {
1197
- return {
1198
- blockhash: messageLifetimeToken,
1199
- lastValidBlockHeight: lastValidBlockHeight ?? 2n ** 64n - 1n
1200
- // U64 MAX
1201
- };
1202
- } else {
1203
- const nonceAccountAddress = firstInstruction.accounts[0].address;
1204
- assertIsAddress(nonceAccountAddress);
1205
- const nonceAuthorityAddress = firstInstruction.accounts[2].address;
1206
- assertIsAddress(nonceAuthorityAddress);
1207
- return {
1208
- nonce: messageLifetimeToken,
1209
- nonceAccountAddress,
1210
- nonceAuthorityAddress
1211
- };
1088
+ function getBytesDecoder(config = {}) {
1089
+ var _a, _b;
1090
+ const size = (_a = config.size) != null ? _a : "variable";
1091
+ const sizeDescription = typeof size === "object" ? size.description : `${size}`;
1092
+ const description = (_b = config.description) != null ? _b : `bytes(${sizeDescription})`;
1093
+ const byteDecoder = {
1094
+ decode: (bytes, offset = 0) => {
1095
+ const slice = bytes.slice(offset);
1096
+ return [slice, offset + slice.length];
1097
+ },
1098
+ description,
1099
+ fixedSize: null,
1100
+ maxSize: null
1101
+ };
1102
+ if (size === "variable") {
1103
+ return byteDecoder;
1104
+ }
1105
+ if (typeof size === "number") {
1106
+ return fixDecoder(byteDecoder, size, description);
1212
1107
  }
1108
+ return {
1109
+ ...byteDecoder,
1110
+ decode: (bytes, offset = 0) => {
1111
+ assertByteArrayIsNotEmptyForCodec("bytes", bytes, offset);
1112
+ const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);
1113
+ const length = Number(lengthBigInt);
1114
+ offset = lengthOffset;
1115
+ const contentBytes = bytes.slice(offset, offset + length);
1116
+ assertByteArrayHasEnoughBytesForCodec("bytes", length, contentBytes);
1117
+ const [value, contentOffset] = byteDecoder.decode(contentBytes);
1118
+ offset += contentOffset;
1119
+ return [value, offset];
1120
+ }
1121
+ };
1213
1122
  }
1214
- function convertSignatures(compiledTransaction) {
1215
- const {
1216
- compiledMessage: { staticAccounts },
1217
- signatures
1218
- } = compiledTransaction;
1219
- return signatures.reduce((acc, sig, index) => {
1220
- const allZeros = sig.every((byte) => byte === 0);
1221
- if (allZeros)
1222
- return acc;
1223
- const address2 = staticAccounts[index];
1224
- return { ...acc, [address2]: sig };
1225
- }, {});
1123
+ function structCodecHelper(fields, description) {
1124
+ const fieldDescriptions = fields.map(([name, codec]) => `${String(name)}: ${codec.description}`).join(", ");
1125
+ return {
1126
+ description: description != null ? description : `struct(${fieldDescriptions})`,
1127
+ fixedSize: sumCodecSizes(fields.map(([, field]) => field.fixedSize)),
1128
+ maxSize: sumCodecSizes(fields.map(([, field]) => field.maxSize))
1129
+ };
1226
1130
  }
1227
- function decompileTransaction(compiledTransaction, lastValidBlockHeight) {
1228
- const { compiledMessage } = compiledTransaction;
1229
- if ("addressTableLookups" in compiledMessage && compiledMessage.addressTableLookups.length > 0) {
1230
- throw new Error("Cannot convert transaction with addressTableLookups");
1231
- }
1232
- const feePayer = compiledMessage.staticAccounts[0];
1233
- if (!feePayer)
1234
- throw new Error("No fee payer set in CompiledTransaction");
1235
- const accountMetas = getAccountMetas(compiledMessage);
1236
- const instructions = compiledMessage.instructions.map(
1237
- (compiledInstruction) => convertInstruction(compiledInstruction, accountMetas)
1238
- );
1239
- const firstInstruction = instructions[0];
1240
- const lifetimeConstraint = getLifetimeConstraint(
1241
- compiledMessage.lifetimeToken,
1242
- firstInstruction,
1243
- lastValidBlockHeight
1244
- );
1245
- const signatures = convertSignatures(compiledTransaction);
1246
- return pipe(
1247
- createTransaction({ version: compiledMessage.version }),
1248
- (tx) => setTransactionFeePayer(feePayer, tx),
1249
- (tx) => instructions.reduce((acc, instruction) => {
1250
- return appendTransactionInstruction(instruction, acc);
1251
- }, tx),
1252
- (tx) => "blockhash" in lifetimeConstraint ? setTransactionLifetimeUsingBlockhash(lifetimeConstraint, tx) : setTransactionLifetimeUsingDurableNonce(lifetimeConstraint, tx),
1253
- (tx) => compiledTransaction.signatures.length ? { ...tx, signatures } : tx
1254
- );
1131
+ function getStructEncoder(fields, config = {}) {
1132
+ return {
1133
+ ...structCodecHelper(fields, config.description),
1134
+ encode: (struct) => {
1135
+ const fieldBytes = fields.map(([key, codec]) => codec.encode(struct[key]));
1136
+ return mergeBytes(fieldBytes);
1137
+ }
1138
+ };
1139
+ }
1140
+ function getStructDecoder(fields, config = {}) {
1141
+ return {
1142
+ ...structCodecHelper(fields, config.description),
1143
+ decode: (bytes, offset = 0) => {
1144
+ const struct = {};
1145
+ fields.forEach(([key, codec]) => {
1146
+ const [value, newOffset] = codec.decode(bytes, offset);
1147
+ offset = newOffset;
1148
+ struct[key] = value;
1149
+ });
1150
+ return [struct, offset];
1151
+ }
1152
+ };
1255
1153
  }
1256
1154
 
1257
1155
  // src/serializers/address-table-lookup.ts
@@ -1323,7 +1221,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
1323
1221
  const encoder = getMemoizedU8Encoder();
1324
1222
  return {
1325
1223
  ...encoder,
1326
- description: description ?? encoder.description
1224
+ description: description != null ? description : encoder.description
1327
1225
  };
1328
1226
  }
1329
1227
  var memoizedU8Decoder;
@@ -1336,7 +1234,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
1336
1234
  const decoder = getMemoizedU8Decoder();
1337
1235
  return {
1338
1236
  ...decoder,
1339
- description: description ?? decoder.description
1237
+ description: description != null ? description : decoder.description
1340
1238
  };
1341
1239
  }
1342
1240
  var numSignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction" ;
@@ -1390,13 +1288,14 @@ this.globalThis.solanaWeb3 = (function (exports) {
1390
1288
  ]),
1391
1289
  // Convert an instruction to have all fields defined
1392
1290
  (instruction) => {
1291
+ var _a, _b;
1393
1292
  if (instruction.accountIndices !== void 0 && instruction.data !== void 0) {
1394
1293
  return instruction;
1395
1294
  }
1396
1295
  return {
1397
1296
  ...instruction,
1398
- accountIndices: instruction.accountIndices ?? [],
1399
- data: instruction.data ?? new Uint8Array(0)
1297
+ accountIndices: (_a = instruction.accountIndices) != null ? _a : [],
1298
+ data: (_b = instruction.data) != null ? _b : new Uint8Array(0)
1400
1299
  };
1401
1300
  }
1402
1301
  );
@@ -1488,12 +1387,13 @@ this.globalThis.solanaWeb3 = (function (exports) {
1488
1387
  ["addressTableLookups", getAddressTableLookupArrayEncoder()]
1489
1388
  ]),
1490
1389
  (value) => {
1390
+ var _a;
1491
1391
  if (value.version === "legacy") {
1492
1392
  return value;
1493
1393
  }
1494
1394
  return {
1495
1395
  ...value,
1496
- addressTableLookups: value.addressTableLookups ?? []
1396
+ addressTableLookups: (_a = value.addressTableLookups) != null ? _a : []
1497
1397
  };
1498
1398
  }
1499
1399
  );
@@ -1588,13 +1488,153 @@ this.globalThis.solanaWeb3 = (function (exports) {
1588
1488
  description: messageDescription
1589
1489
  }),
1590
1490
  ({ addressTableLookups, ...restOfMessage }) => {
1591
- if (restOfMessage.version === "legacy" || !addressTableLookups?.length) {
1491
+ if (restOfMessage.version === "legacy" || !(addressTableLookups == null ? void 0 : addressTableLookups.length)) {
1592
1492
  return restOfMessage;
1593
1493
  }
1594
1494
  return { ...restOfMessage, addressTableLookups };
1595
1495
  }
1596
1496
  );
1597
1497
  }
1498
+ function getCompiledMessageCodec() {
1499
+ return combineCodec(getCompiledMessageEncoder(), getCompiledMessageDecoder());
1500
+ }
1501
+
1502
+ // src/compile-transaction.ts
1503
+ function getCompiledTransaction(transaction) {
1504
+ var _a;
1505
+ const compiledMessage = compileMessage(transaction);
1506
+ let signatures;
1507
+ if ("signatures" in transaction) {
1508
+ signatures = [];
1509
+ for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
1510
+ signatures[ii] = (_a = transaction.signatures[compiledMessage.staticAccounts[ii]]) != null ? _a : new Uint8Array(Array(64).fill(0));
1511
+ }
1512
+ } else {
1513
+ signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
1514
+ }
1515
+ return {
1516
+ compiledMessage,
1517
+ signatures
1518
+ };
1519
+ }
1520
+
1521
+ // ../functional/dist/index.browser.js
1522
+ function pipe(init, ...fns) {
1523
+ return fns.reduce((acc, fn) => fn(acc), init);
1524
+ }
1525
+
1526
+ // src/decompile-transaction.ts
1527
+ function getAccountMetas(message) {
1528
+ const { header } = message;
1529
+ const numWritableSignerAccounts = header.numSignerAccounts - header.numReadonlySignerAccounts;
1530
+ const numWritableNonSignerAccounts = message.staticAccounts.length - header.numSignerAccounts - header.numReadonlyNonSignerAccounts;
1531
+ const accountMetas = [];
1532
+ let accountIndex = 0;
1533
+ for (let i = 0; i < numWritableSignerAccounts; i++) {
1534
+ accountMetas.push({
1535
+ address: message.staticAccounts[accountIndex],
1536
+ role: AccountRole.WRITABLE_SIGNER
1537
+ });
1538
+ accountIndex++;
1539
+ }
1540
+ for (let i = 0; i < header.numReadonlySignerAccounts; i++) {
1541
+ accountMetas.push({
1542
+ address: message.staticAccounts[accountIndex],
1543
+ role: AccountRole.READONLY_SIGNER
1544
+ });
1545
+ accountIndex++;
1546
+ }
1547
+ for (let i = 0; i < numWritableNonSignerAccounts; i++) {
1548
+ accountMetas.push({
1549
+ address: message.staticAccounts[accountIndex],
1550
+ role: AccountRole.WRITABLE
1551
+ });
1552
+ accountIndex++;
1553
+ }
1554
+ for (let i = 0; i < header.numReadonlyNonSignerAccounts; i++) {
1555
+ accountMetas.push({
1556
+ address: message.staticAccounts[accountIndex],
1557
+ role: AccountRole.READONLY
1558
+ });
1559
+ accountIndex++;
1560
+ }
1561
+ return accountMetas;
1562
+ }
1563
+ function convertInstruction(instruction, accountMetas) {
1564
+ var _a, _b;
1565
+ const programAddress = (_a = accountMetas[instruction.programAddressIndex]) == null ? void 0 : _a.address;
1566
+ if (!programAddress) {
1567
+ throw new Error(`Could not find program address at index ${instruction.programAddressIndex}`);
1568
+ }
1569
+ const accounts = (_b = instruction.accountIndices) == null ? void 0 : _b.map((accountIndex) => accountMetas[accountIndex]);
1570
+ const { data } = instruction;
1571
+ return {
1572
+ programAddress,
1573
+ ...accounts && accounts.length ? { accounts } : {},
1574
+ ...data && data.length ? { data } : {}
1575
+ };
1576
+ }
1577
+ function getLifetimeConstraint(messageLifetimeToken, firstInstruction, lastValidBlockHeight) {
1578
+ if (!firstInstruction || !isAdvanceNonceAccountInstruction(firstInstruction)) {
1579
+ return {
1580
+ blockhash: messageLifetimeToken,
1581
+ lastValidBlockHeight: lastValidBlockHeight != null ? lastValidBlockHeight : 2n ** 64n - 1n
1582
+ // U64 MAX
1583
+ };
1584
+ } else {
1585
+ const nonceAccountAddress = firstInstruction.accounts[0].address;
1586
+ assertIsAddress(nonceAccountAddress);
1587
+ const nonceAuthorityAddress = firstInstruction.accounts[2].address;
1588
+ assertIsAddress(nonceAuthorityAddress);
1589
+ return {
1590
+ nonce: messageLifetimeToken,
1591
+ nonceAccountAddress,
1592
+ nonceAuthorityAddress
1593
+ };
1594
+ }
1595
+ }
1596
+ function convertSignatures(compiledTransaction) {
1597
+ const {
1598
+ compiledMessage: { staticAccounts },
1599
+ signatures
1600
+ } = compiledTransaction;
1601
+ return signatures.reduce((acc, sig, index) => {
1602
+ const allZeros = sig.every((byte) => byte === 0);
1603
+ if (allZeros)
1604
+ return acc;
1605
+ const address2 = staticAccounts[index];
1606
+ return { ...acc, [address2]: sig };
1607
+ }, {});
1608
+ }
1609
+ function decompileTransaction(compiledTransaction, lastValidBlockHeight) {
1610
+ const { compiledMessage } = compiledTransaction;
1611
+ if ("addressTableLookups" in compiledMessage && compiledMessage.addressTableLookups.length > 0) {
1612
+ throw new Error("Cannot convert transaction with addressTableLookups");
1613
+ }
1614
+ const feePayer = compiledMessage.staticAccounts[0];
1615
+ if (!feePayer)
1616
+ throw new Error("No fee payer set in CompiledTransaction");
1617
+ const accountMetas = getAccountMetas(compiledMessage);
1618
+ const instructions = compiledMessage.instructions.map(
1619
+ (compiledInstruction) => convertInstruction(compiledInstruction, accountMetas)
1620
+ );
1621
+ const firstInstruction = instructions[0];
1622
+ const lifetimeConstraint = getLifetimeConstraint(
1623
+ compiledMessage.lifetimeToken,
1624
+ firstInstruction,
1625
+ lastValidBlockHeight
1626
+ );
1627
+ const signatures = convertSignatures(compiledTransaction);
1628
+ return pipe(
1629
+ createTransaction({ version: compiledMessage.version }),
1630
+ (tx) => setTransactionFeePayer(feePayer, tx),
1631
+ (tx) => instructions.reduce((acc, instruction) => {
1632
+ return appendTransactionInstruction(instruction, acc);
1633
+ }, tx),
1634
+ (tx) => "blockhash" in lifetimeConstraint ? setTransactionLifetimeUsingBlockhash(lifetimeConstraint, tx) : setTransactionLifetimeUsingDurableNonce(lifetimeConstraint, tx),
1635
+ (tx) => compiledTransaction.signatures.length ? { ...tx, signatures } : tx
1636
+ );
1637
+ }
1598
1638
 
1599
1639
  // src/serializers/transaction.ts
1600
1640
  var signaturesDescription = "A compact array of 64-byte, base-64 encoded Ed25519 signatures" ;
@@ -1696,7 +1736,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
1696
1736
  return out;
1697
1737
  }
1698
1738
  function assertTransactionIsFullySigned(transaction) {
1699
- const signerAddressesFromInstructions = transaction.instructions.flatMap((i) => i.accounts?.filter((a) => isSignerRole(a.role)) ?? []).map((a) => a.address);
1739
+ const signerAddressesFromInstructions = transaction.instructions.flatMap((i) => {
1740
+ var _a, _b;
1741
+ return (_b = (_a = i.accounts) == null ? void 0 : _a.filter((a) => isSignerRole(a.role))) != null ? _b : [];
1742
+ }).map((a) => a.address);
1700
1743
  const requiredSigners = /* @__PURE__ */ new Set([transaction.feePayer, ...signerAddressesFromInstructions]);
1701
1744
  requiredSigners.forEach((address2) => {
1702
1745
  if (!transaction.signatures[address2]) {
@@ -1708,17 +1751,19 @@ this.globalThis.solanaWeb3 = (function (exports) {
1708
1751
  // src/wire-transaction.ts
1709
1752
  function getBase64EncodedWireTransaction(transaction) {
1710
1753
  const wireTransactionBytes = getTransactionEncoder().encode(transaction);
1711
- {
1712
- return btoa(String.fromCharCode(...wireTransactionBytes));
1713
- }
1754
+ return getBase64Decoder().decode(wireTransactionBytes)[0];
1714
1755
  }
1715
1756
 
1716
1757
  exports.appendTransactionInstruction = appendTransactionInstruction;
1717
1758
  exports.assertIsBlockhash = assertIsBlockhash;
1718
1759
  exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
1719
1760
  exports.assertTransactionIsFullySigned = assertTransactionIsFullySigned;
1761
+ exports.compileMessage = compileMessage;
1720
1762
  exports.createTransaction = createTransaction;
1721
1763
  exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
1764
+ exports.getCompiledMessageCodec = getCompiledMessageCodec;
1765
+ exports.getCompiledMessageDecoder = getCompiledMessageDecoder;
1766
+ exports.getCompiledMessageEncoder = getCompiledMessageEncoder;
1722
1767
  exports.getSignatureFromTransaction = getSignatureFromTransaction;
1723
1768
  exports.getTransactionCodec = getTransactionCodec;
1724
1769
  exports.getTransactionDecoder = getTransactionDecoder;