@solana/transactions 2.0.0-experimental.eeb355e → 2.0.0-experimental.ef09aec

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,6 +121,7 @@ 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) {
@@ -128,7 +129,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
128
129
  defaultDescription += littleEndian ? "(le)" : "(be)";
129
130
  }
130
131
  return {
131
- description: input.config.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,50 +166,56 @@ 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 = (config = {}) => ({
173
- description: config.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 = (config = {}) => ({
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: config.description ?? "shortU16",
209
- fixedSize: null,
210
- maxSize: 3
211
- });
212
+ return [value, offset + byteCount];
213
+ },
214
+ description: (_a = config.description) != null ? _a : "shortU16",
215
+ fixedSize: null,
216
+ maxSize: 3
217
+ };
218
+ };
212
219
  var getU32Encoder = (config = {}) => numberEncoderFactory({
213
220
  config,
214
221
  name: "u32",
@@ -346,9 +353,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
346
353
  };
347
354
  };
348
355
  var getStringEncoder = (config = {}) => {
349
- const size = config.size ?? getU32Encoder();
350
- const encoding = config.encoding ?? getUtf8Encoder();
351
- const description = config.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
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)})`;
352
360
  if (size === "variable") {
353
361
  return { ...encoding, description };
354
362
  }
@@ -367,9 +375,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
367
375
  };
368
376
  };
369
377
  var getStringDecoder = (config = {}) => {
370
- const size = config.size ?? getU32Decoder();
371
- const encoding = config.encoding ?? getUtf8Decoder();
372
- const description = config.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
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)})`;
373
382
  if (size === "variable") {
374
383
  return { ...encoding, description };
375
384
  }
@@ -505,9 +514,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
505
514
  };
506
515
  }
507
516
  function isAdvanceNonceAccountInstruction(instruction) {
517
+ var _a;
508
518
  return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
509
519
  instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts
510
- 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
511
521
  instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole.WRITABLE && // Second account is recent blockhashes sysvar
512
522
  instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole.READONLY && // Third account is nonce authority account
513
523
  instruction.accounts[2].address != null && isSignerRole(instruction.accounts[2].role);
@@ -589,184 +599,6 @@ this.globalThis.solanaWeb3 = (function (exports) {
589
599
  return out;
590
600
  }
591
601
 
592
- // ../codecs-data-structures/dist/index.browser.js
593
- function sumCodecSizes(sizes) {
594
- return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
595
- }
596
- function decodeArrayLikeCodecSize(size, childrenSizes, bytes, offset) {
597
- if (typeof size === "number") {
598
- return [size, offset];
599
- }
600
- if (typeof size === "object") {
601
- return size.decode(bytes, offset);
602
- }
603
- if (size === "remainder") {
604
- const childrenSize = sumCodecSizes(childrenSizes);
605
- if (childrenSize === null) {
606
- throw new Error('Codecs of "remainder" size must have fixed-size items.');
607
- }
608
- const remainder = bytes.slice(offset).length;
609
- if (remainder % childrenSize !== 0) {
610
- throw new Error(
611
- `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.`
612
- );
613
- }
614
- return [remainder / childrenSize, offset];
615
- }
616
- throw new Error(`Unrecognized array-like codec size: ${JSON.stringify(size)}`);
617
- }
618
- function getArrayLikeCodecSizeDescription(size) {
619
- return typeof size === "object" ? size.description : `${size}`;
620
- }
621
- function getArrayLikeCodecSizeFromChildren(size, childrenSizes) {
622
- if (typeof size !== "number")
623
- return null;
624
- if (size === 0)
625
- return 0;
626
- const childrenSize = sumCodecSizes(childrenSizes);
627
- return childrenSize === null ? null : childrenSize * size;
628
- }
629
- function getArrayLikeCodecSizePrefix(size, realSize) {
630
- return typeof size === "object" ? size.encode(realSize) : new Uint8Array();
631
- }
632
- function assertValidNumberOfItemsForCodec(codecDescription, expected, actual) {
633
- if (expected !== actual) {
634
- throw new Error(`Expected [${codecDescription}] to have ${expected} items, got ${actual}.`);
635
- }
636
- }
637
- function arrayCodecHelper(item, size, description) {
638
- if (size === "remainder" && item.fixedSize === null) {
639
- throw new Error('Codecs of "remainder" size must have fixed-size items.');
640
- }
641
- return {
642
- description: description ?? `array(${item.description}; ${getArrayLikeCodecSizeDescription(size)})`,
643
- fixedSize: getArrayLikeCodecSizeFromChildren(size, [item.fixedSize]),
644
- maxSize: getArrayLikeCodecSizeFromChildren(size, [item.maxSize])
645
- };
646
- }
647
- function getArrayEncoder(item, config = {}) {
648
- const size = config.size ?? getU32Encoder();
649
- return {
650
- ...arrayCodecHelper(item, size, config.description),
651
- encode: (value) => {
652
- if (typeof size === "number") {
653
- assertValidNumberOfItemsForCodec("array", size, value.length);
654
- }
655
- return mergeBytes([getArrayLikeCodecSizePrefix(size, value.length), ...value.map((v) => item.encode(v))]);
656
- }
657
- };
658
- }
659
- function getArrayDecoder(item, config = {}) {
660
- const size = config.size ?? getU32Decoder();
661
- return {
662
- ...arrayCodecHelper(item, size, config.description),
663
- decode: (bytes, offset = 0) => {
664
- if (typeof size === "object" && bytes.slice(offset).length === 0) {
665
- return [[], offset];
666
- }
667
- const [resolvedSize, newOffset] = decodeArrayLikeCodecSize(size, [item.fixedSize], bytes, offset);
668
- offset = newOffset;
669
- const values = [];
670
- for (let i = 0; i < resolvedSize; i += 1) {
671
- const [value, newOffset2] = item.decode(bytes, offset);
672
- values.push(value);
673
- offset = newOffset2;
674
- }
675
- return [values, offset];
676
- }
677
- };
678
- }
679
- function getBytesEncoder(config = {}) {
680
- const size = config.size ?? "variable";
681
- const sizeDescription = typeof size === "object" ? size.description : `${size}`;
682
- const description = config.description ?? `bytes(${sizeDescription})`;
683
- const byteEncoder = {
684
- description,
685
- encode: (value) => value,
686
- fixedSize: null,
687
- maxSize: null
688
- };
689
- if (size === "variable") {
690
- return byteEncoder;
691
- }
692
- if (typeof size === "number") {
693
- return fixEncoder(byteEncoder, size, description);
694
- }
695
- return {
696
- ...byteEncoder,
697
- encode: (value) => {
698
- const contentBytes = byteEncoder.encode(value);
699
- const lengthBytes = size.encode(contentBytes.length);
700
- return mergeBytes([lengthBytes, contentBytes]);
701
- }
702
- };
703
- }
704
- function getBytesDecoder(config = {}) {
705
- const size = config.size ?? "variable";
706
- const sizeDescription = typeof size === "object" ? size.description : `${size}`;
707
- const description = config.description ?? `bytes(${sizeDescription})`;
708
- const byteDecoder = {
709
- decode: (bytes, offset = 0) => {
710
- const slice = bytes.slice(offset);
711
- return [slice, offset + slice.length];
712
- },
713
- description,
714
- fixedSize: null,
715
- maxSize: null
716
- };
717
- if (size === "variable") {
718
- return byteDecoder;
719
- }
720
- if (typeof size === "number") {
721
- return fixDecoder(byteDecoder, size, description);
722
- }
723
- return {
724
- ...byteDecoder,
725
- decode: (bytes, offset = 0) => {
726
- assertByteArrayIsNotEmptyForCodec("bytes", bytes, offset);
727
- const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);
728
- const length = Number(lengthBigInt);
729
- offset = lengthOffset;
730
- const contentBytes = bytes.slice(offset, offset + length);
731
- assertByteArrayHasEnoughBytesForCodec("bytes", length, contentBytes);
732
- const [value, contentOffset] = byteDecoder.decode(contentBytes);
733
- offset += contentOffset;
734
- return [value, offset];
735
- }
736
- };
737
- }
738
- function structCodecHelper(fields, description) {
739
- const fieldDescriptions = fields.map(([name, codec]) => `${String(name)}: ${codec.description}`).join(", ");
740
- return {
741
- description: description ?? `struct(${fieldDescriptions})`,
742
- fixedSize: sumCodecSizes(fields.map(([, field]) => field.fixedSize)),
743
- maxSize: sumCodecSizes(fields.map(([, field]) => field.maxSize))
744
- };
745
- }
746
- function getStructEncoder(fields, config = {}) {
747
- return {
748
- ...structCodecHelper(fields, config.description),
749
- encode: (struct) => {
750
- const fieldBytes = fields.map(([key, codec]) => codec.encode(struct[key]));
751
- return mergeBytes(fieldBytes);
752
- }
753
- };
754
- }
755
- function getStructDecoder(fields, config = {}) {
756
- return {
757
- ...structCodecHelper(fields, config.description),
758
- decode: (bytes, offset = 0) => {
759
- const struct = {};
760
- fields.forEach(([key, codec]) => {
761
- const [value, newOffset] = codec.decode(bytes, offset);
762
- offset = newOffset;
763
- struct[key] = value;
764
- });
765
- return [struct, offset];
766
- }
767
- };
768
- }
769
-
770
602
  // ../assertions/dist/index.browser.js
771
603
  function assertIsSecureContext() {
772
604
  if (!globalThis.isSecureContext) {
@@ -776,14 +608,16 @@ this.globalThis.solanaWeb3 = (function (exports) {
776
608
  }
777
609
  }
778
610
  async function assertKeyExporterIsAvailable() {
611
+ var _a;
779
612
  assertIsSecureContext();
780
- 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") {
781
614
  throw new Error("No key export implementation could be found");
782
615
  }
783
616
  }
784
617
  async function assertSigningCapabilityIsAvailable() {
618
+ var _a;
785
619
  assertIsSecureContext();
786
- 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") {
787
621
  throw new Error("No signing implementation could be found");
788
622
  }
789
623
  }
@@ -827,9 +661,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
827
661
  return putativeAddress;
828
662
  }
829
663
  function getAddressEncoder(config) {
664
+ var _a;
830
665
  return mapEncoder(
831
666
  getStringEncoder({
832
- description: config?.description ?? "Address",
667
+ description: (_a = config == null ? void 0 : config.description) != null ? _a : "Address",
833
668
  encoding: getMemoizedBase58Encoder(),
834
669
  size: 32
835
670
  }),
@@ -837,8 +672,9 @@ this.globalThis.solanaWeb3 = (function (exports) {
837
672
  );
838
673
  }
839
674
  function getAddressDecoder(config) {
675
+ var _a;
840
676
  return getStringDecoder({
841
- description: config?.description ?? "Address",
677
+ description: (_a = config == null ? void 0 : config.description) != null ? _a : "Address",
842
678
  encoding: getMemoizedBase58Decoder(),
843
679
  size: 32
844
680
  });
@@ -865,7 +701,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
865
701
 
866
702
  // src/accounts.ts
867
703
  function upsert(addressMap, address2, update) {
868
- addressMap[address2] = update(addressMap[address2] ?? { role: AccountRole.READONLY });
704
+ var _a;
705
+ addressMap[address2] = update((_a = addressMap[address2]) != null ? _a : { role: AccountRole.READONLY });
869
706
  }
870
707
  var TYPE = Symbol("AddressMapTypeProperty");
871
708
  function getAddressMapFromInstructions(feePayer, instructions) {
@@ -1133,139 +970,186 @@ this.globalThis.solanaWeb3 = (function (exports) {
1133
970
  };
1134
971
  }
1135
972
 
1136
- // src/compile-transaction.ts
1137
- function getCompiledTransaction(transaction) {
1138
- const compiledMessage = compileMessage(transaction);
1139
- let signatures;
1140
- if ("signatures" in transaction) {
1141
- signatures = [];
1142
- for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
1143
- 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.');
1144
988
  }
1145
- } else {
1146
- 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];
1147
996
  }
1148
- return {
1149
- compiledMessage,
1150
- signatures
1151
- };
997
+ throw new Error(`Unrecognized array-like codec size: ${JSON.stringify(size)}`);
1152
998
  }
1153
-
1154
- // ../functional/dist/index.browser.js
1155
- function pipe(init, ...fns) {
1156
- return fns.reduce((acc, fn) => fn(acc), init);
999
+ function getArrayLikeCodecSizeDescription(size) {
1000
+ return typeof size === "object" ? size.description : `${size}`;
1157
1001
  }
1158
-
1159
- // src/decompile-transaction.ts
1160
- function getAccountMetas(message) {
1161
- const { header } = message;
1162
- const numWritableSignerAccounts = header.numSignerAccounts - header.numReadonlySignerAccounts;
1163
- const numWritableNonSignerAccounts = message.staticAccounts.length - header.numSignerAccounts - header.numReadonlyNonSignerAccounts;
1164
- const accountMetas = [];
1165
- let accountIndex = 0;
1166
- for (let i = 0; i < numWritableSignerAccounts; i++) {
1167
- accountMetas.push({
1168
- address: message.staticAccounts[accountIndex],
1169
- role: AccountRole.WRITABLE_SIGNER
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.numReadonlySignerAccounts; i++) {
1174
- accountMetas.push({
1175
- address: message.staticAccounts[accountIndex],
1176
- role: AccountRole.READONLY_SIGNER
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
- for (let i = 0; i < numWritableNonSignerAccounts; i++) {
1181
- accountMetas.push({
1182
- address: message.staticAccounts[accountIndex],
1183
- role: AccountRole.WRITABLE
1184
- });
1185
- accountIndex++;
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
+ };
1027
+ }
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;
1186
1075
  }
1187
- for (let i = 0; i < header.numReadonlyNonSignerAccounts; i++) {
1188
- accountMetas.push({
1189
- address: message.staticAccounts[accountIndex],
1190
- role: AccountRole.READONLY
1191
- });
1192
- accountIndex++;
1076
+ if (typeof size === "number") {
1077
+ return fixEncoder(byteEncoder, size, description);
1193
1078
  }
1194
- return accountMetas;
1079
+ return {
1080
+ ...byteEncoder,
1081
+ encode: (value) => {
1082
+ const contentBytes = byteEncoder.encode(value);
1083
+ const lengthBytes = size.encode(contentBytes.length);
1084
+ return mergeBytes([lengthBytes, contentBytes]);
1085
+ }
1086
+ };
1195
1087
  }
1196
- function convertInstruction(instruction, accountMetas) {
1197
- const programAddress = accountMetas[instruction.programAddressIndex]?.address;
1198
- if (!programAddress) {
1199
- throw new Error(`Could not find program address at index ${instruction.programAddressIndex}`);
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);
1200
1107
  }
1201
- const accounts = instruction.accountIndices?.map((accountIndex) => accountMetas[accountIndex]);
1202
- const { data } = instruction;
1203
1108
  return {
1204
- programAddress,
1205
- ...accounts && accounts.length ? { accounts } : {},
1206
- ...data && data.length ? { data } : {}
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
+ }
1207
1121
  };
1208
1122
  }
1209
- function getLifetimeConstraint(messageLifetimeToken, firstInstruction, lastValidBlockHeight) {
1210
- if (!firstInstruction || !isAdvanceNonceAccountInstruction(firstInstruction)) {
1211
- return {
1212
- blockhash: messageLifetimeToken,
1213
- lastValidBlockHeight: lastValidBlockHeight ?? 2n ** 64n - 1n
1214
- // U64 MAX
1215
- };
1216
- } else {
1217
- const nonceAccountAddress = firstInstruction.accounts[0].address;
1218
- assertIsAddress(nonceAccountAddress);
1219
- const nonceAuthorityAddress = firstInstruction.accounts[2].address;
1220
- assertIsAddress(nonceAuthorityAddress);
1221
- return {
1222
- nonce: messageLifetimeToken,
1223
- nonceAccountAddress,
1224
- nonceAuthorityAddress
1225
- };
1226
- }
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
+ };
1227
1130
  }
1228
- function convertSignatures(compiledTransaction) {
1229
- const {
1230
- compiledMessage: { staticAccounts },
1231
- signatures
1232
- } = compiledTransaction;
1233
- return signatures.reduce((acc, sig, index) => {
1234
- const allZeros = sig.every((byte) => byte === 0);
1235
- if (allZeros)
1236
- return acc;
1237
- const address2 = staticAccounts[index];
1238
- return { ...acc, [address2]: sig };
1239
- }, {});
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
+ };
1240
1139
  }
1241
- function decompileTransaction(compiledTransaction, lastValidBlockHeight) {
1242
- const { compiledMessage } = compiledTransaction;
1243
- if ("addressTableLookups" in compiledMessage && compiledMessage.addressTableLookups.length > 0) {
1244
- throw new Error("Cannot convert transaction with addressTableLookups");
1245
- }
1246
- const feePayer = compiledMessage.staticAccounts[0];
1247
- if (!feePayer)
1248
- throw new Error("No fee payer set in CompiledTransaction");
1249
- const accountMetas = getAccountMetas(compiledMessage);
1250
- const instructions = compiledMessage.instructions.map(
1251
- (compiledInstruction) => convertInstruction(compiledInstruction, accountMetas)
1252
- );
1253
- const firstInstruction = instructions[0];
1254
- const lifetimeConstraint = getLifetimeConstraint(
1255
- compiledMessage.lifetimeToken,
1256
- firstInstruction,
1257
- lastValidBlockHeight
1258
- );
1259
- const signatures = convertSignatures(compiledTransaction);
1260
- return pipe(
1261
- createTransaction({ version: compiledMessage.version }),
1262
- (tx) => setTransactionFeePayer(feePayer, tx),
1263
- (tx) => instructions.reduce((acc, instruction) => {
1264
- return appendTransactionInstruction(instruction, acc);
1265
- }, tx),
1266
- (tx) => "blockhash" in lifetimeConstraint ? setTransactionLifetimeUsingBlockhash(lifetimeConstraint, tx) : setTransactionLifetimeUsingDurableNonce(lifetimeConstraint, tx),
1267
- (tx) => compiledTransaction.signatures.length ? { ...tx, signatures } : tx
1268
- );
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
+ };
1269
1153
  }
1270
1154
 
1271
1155
  // src/serializers/address-table-lookup.ts
@@ -1337,7 +1221,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
1337
1221
  const encoder = getMemoizedU8Encoder();
1338
1222
  return {
1339
1223
  ...encoder,
1340
- description: description ?? encoder.description
1224
+ description: description != null ? description : encoder.description
1341
1225
  };
1342
1226
  }
1343
1227
  var memoizedU8Decoder;
@@ -1350,7 +1234,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
1350
1234
  const decoder = getMemoizedU8Decoder();
1351
1235
  return {
1352
1236
  ...decoder,
1353
- description: description ?? decoder.description
1237
+ description: description != null ? description : decoder.description
1354
1238
  };
1355
1239
  }
1356
1240
  var numSignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction" ;
@@ -1404,13 +1288,14 @@ this.globalThis.solanaWeb3 = (function (exports) {
1404
1288
  ]),
1405
1289
  // Convert an instruction to have all fields defined
1406
1290
  (instruction) => {
1291
+ var _a, _b;
1407
1292
  if (instruction.accountIndices !== void 0 && instruction.data !== void 0) {
1408
1293
  return instruction;
1409
1294
  }
1410
1295
  return {
1411
1296
  ...instruction,
1412
- accountIndices: instruction.accountIndices ?? [],
1413
- data: instruction.data ?? new Uint8Array(0)
1297
+ accountIndices: (_a = instruction.accountIndices) != null ? _a : [],
1298
+ data: (_b = instruction.data) != null ? _b : new Uint8Array(0)
1414
1299
  };
1415
1300
  }
1416
1301
  );
@@ -1502,12 +1387,13 @@ this.globalThis.solanaWeb3 = (function (exports) {
1502
1387
  ["addressTableLookups", getAddressTableLookupArrayEncoder()]
1503
1388
  ]),
1504
1389
  (value) => {
1390
+ var _a;
1505
1391
  if (value.version === "legacy") {
1506
1392
  return value;
1507
1393
  }
1508
1394
  return {
1509
1395
  ...value,
1510
- addressTableLookups: value.addressTableLookups ?? []
1396
+ addressTableLookups: (_a = value.addressTableLookups) != null ? _a : []
1511
1397
  };
1512
1398
  }
1513
1399
  );
@@ -1602,13 +1488,153 @@ this.globalThis.solanaWeb3 = (function (exports) {
1602
1488
  description: messageDescription
1603
1489
  }),
1604
1490
  ({ addressTableLookups, ...restOfMessage }) => {
1605
- if (restOfMessage.version === "legacy" || !addressTableLookups?.length) {
1491
+ if (restOfMessage.version === "legacy" || !(addressTableLookups == null ? void 0 : addressTableLookups.length)) {
1606
1492
  return restOfMessage;
1607
1493
  }
1608
1494
  return { ...restOfMessage, addressTableLookups };
1609
1495
  }
1610
1496
  );
1611
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
+ }
1612
1638
 
1613
1639
  // src/serializers/transaction.ts
1614
1640
  var signaturesDescription = "A compact array of 64-byte, base-64 encoded Ed25519 signatures" ;
@@ -1710,7 +1736,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
1710
1736
  return out;
1711
1737
  }
1712
1738
  function assertTransactionIsFullySigned(transaction) {
1713
- 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);
1714
1743
  const requiredSigners = /* @__PURE__ */ new Set([transaction.feePayer, ...signerAddressesFromInstructions]);
1715
1744
  requiredSigners.forEach((address2) => {
1716
1745
  if (!transaction.signatures[address2]) {
@@ -1729,8 +1758,12 @@ this.globalThis.solanaWeb3 = (function (exports) {
1729
1758
  exports.assertIsBlockhash = assertIsBlockhash;
1730
1759
  exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
1731
1760
  exports.assertTransactionIsFullySigned = assertTransactionIsFullySigned;
1761
+ exports.compileMessage = compileMessage;
1732
1762
  exports.createTransaction = createTransaction;
1733
1763
  exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
1764
+ exports.getCompiledMessageCodec = getCompiledMessageCodec;
1765
+ exports.getCompiledMessageDecoder = getCompiledMessageDecoder;
1766
+ exports.getCompiledMessageEncoder = getCompiledMessageEncoder;
1734
1767
  exports.getSignatureFromTransaction = getSignatureFromTransaction;
1735
1768
  exports.getTransactionCodec = getTransactionCodec;
1736
1769
  exports.getTransactionDecoder = getTransactionDecoder;