@solana/signers 2.0.0-experimental.efe6f4d → 2.0.0-experimental.fcff844

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.
Files changed (45) hide show
  1. package/README.md +214 -12
  2. package/dist/index.browser.cjs +197 -10
  3. package/dist/index.browser.cjs.map +1 -1
  4. package/dist/index.browser.js +189 -12
  5. package/dist/index.browser.js.map +1 -1
  6. package/dist/index.development.js +537 -387
  7. package/dist/index.development.js.map +1 -1
  8. package/dist/index.native.js +189 -10
  9. package/dist/index.native.js.map +1 -1
  10. package/dist/index.node.cjs +197 -10
  11. package/dist/index.node.cjs.map +1 -1
  12. package/dist/index.node.js +189 -10
  13. package/dist/index.node.js.map +1 -1
  14. package/dist/index.production.min.js +31 -21
  15. package/dist/types/account-signer-meta.d.ts +19 -0
  16. package/dist/types/account-signer-meta.d.ts.map +1 -0
  17. package/dist/types/add-signers.d.ts +9 -0
  18. package/dist/types/add-signers.d.ts.map +1 -0
  19. package/dist/types/deduplicate-signers.d.ts +5 -0
  20. package/dist/types/deduplicate-signers.d.ts.map +1 -0
  21. package/dist/types/index.d.ts +5 -0
  22. package/dist/types/index.d.ts.map +1 -0
  23. package/dist/types/keypair-signer.d.ts.map +1 -0
  24. package/dist/types/message-modifying-signer.d.ts +3 -1
  25. package/dist/types/message-modifying-signer.d.ts.map +1 -0
  26. package/dist/types/message-partial-signer.d.ts +3 -2
  27. package/dist/types/message-partial-signer.d.ts.map +1 -0
  28. package/dist/types/message-signer.d.ts.map +1 -0
  29. package/dist/types/noop-signer.d.ts +8 -0
  30. package/dist/types/noop-signer.d.ts.map +1 -0
  31. package/dist/types/sign-transaction.d.ts +33 -0
  32. package/dist/types/sign-transaction.d.ts.map +1 -0
  33. package/dist/types/signable-message.d.ts.map +1 -0
  34. package/dist/types/transaction-modifying-signer.d.ts +3 -1
  35. package/dist/types/transaction-modifying-signer.d.ts.map +1 -0
  36. package/dist/types/transaction-partial-signer.d.ts +3 -2
  37. package/dist/types/transaction-partial-signer.d.ts.map +1 -0
  38. package/dist/types/transaction-sending-signer.d.ts +3 -1
  39. package/dist/types/transaction-sending-signer.d.ts.map +1 -0
  40. package/dist/types/transaction-signer.d.ts.map +1 -0
  41. package/dist/types/transaction-with-single-sending-signer.d.ts +11 -0
  42. package/dist/types/transaction-with-single-sending-signer.d.ts.map +1 -0
  43. package/dist/types/types.d.ts +3 -0
  44. package/dist/types/types.d.ts.map +1 -0
  45. package/package.json +7 -6
@@ -2,6 +2,64 @@ this.globalThis = this.globalThis || {};
2
2
  this.globalThis.solanaWeb3 = (function (exports) {
3
3
  'use strict';
4
4
 
5
+ // src/deduplicate-signers.ts
6
+ function deduplicateSigners(signers) {
7
+ const deduplicated = {};
8
+ signers.forEach((signer) => {
9
+ if (!deduplicated[signer.address]) {
10
+ deduplicated[signer.address] = signer;
11
+ } else if (deduplicated[signer.address] !== signer) {
12
+ throw new Error(
13
+ `Multiple distinct signers were identified for address "${signer.address}". Please ensure that you are using the same signer instance for each address.`
14
+ );
15
+ }
16
+ });
17
+ return Object.values(deduplicated);
18
+ }
19
+
20
+ // src/account-signer-meta.ts
21
+ function getSignersFromInstruction(instruction) {
22
+ var _a;
23
+ return deduplicateSigners(
24
+ ((_a = instruction.accounts) != null ? _a : []).flatMap((account) => "signer" in account ? account.signer : [])
25
+ );
26
+ }
27
+ function getSignersFromTransaction(transaction) {
28
+ return deduplicateSigners(transaction.instructions.flatMap(getSignersFromInstruction));
29
+ }
30
+
31
+ // ../instructions/dist/index.browser.js
32
+ function isSignerRole(role) {
33
+ return role >= 2;
34
+ }
35
+
36
+ // src/add-signers.ts
37
+ function addSignersToInstruction(signers, instruction) {
38
+ if (!instruction.accounts || instruction.accounts.length === 0) {
39
+ return instruction;
40
+ }
41
+ const signerByAddress = new Map(deduplicateSigners(signers).map((signer) => [signer.address, signer]));
42
+ return Object.freeze({
43
+ ...instruction,
44
+ accounts: instruction.accounts.map((account) => {
45
+ const signer = signerByAddress.get(account.address);
46
+ if (!isSignerRole(account.role) || "signer" in account || !signer) {
47
+ return account;
48
+ }
49
+ return Object.freeze({ ...account, signer });
50
+ })
51
+ });
52
+ }
53
+ function addSignersToTransaction(signers, transaction) {
54
+ if (transaction.instructions.length === 0) {
55
+ return transaction;
56
+ }
57
+ return Object.freeze({
58
+ ...transaction,
59
+ instructions: transaction.instructions.map((instruction) => addSignersToInstruction(signers, instruction))
60
+ });
61
+ }
62
+
5
63
  // ../codecs-core/dist/index.browser.js
6
64
  function assertByteArrayIsNotEmptyForCodec(codecDescription, bytes, offset = 0) {
7
65
  if (bytes.length - offset <= 0) {
@@ -14,23 +72,6 @@ this.globalThis.solanaWeb3 = (function (exports) {
14
72
  throw new Error(`Codec [${codecDescription}] expected ${expected} bytes, got ${bytesLength}.`);
15
73
  }
16
74
  }
17
- var mergeBytes = (byteArrays) => {
18
- const nonEmptyByteArrays = byteArrays.filter((arr) => arr.length);
19
- if (nonEmptyByteArrays.length === 0) {
20
- return byteArrays.length ? byteArrays[0] : new Uint8Array();
21
- }
22
- if (nonEmptyByteArrays.length === 1) {
23
- return nonEmptyByteArrays[0];
24
- }
25
- const totalLength = nonEmptyByteArrays.reduce((total, arr) => total + arr.length, 0);
26
- const result = new Uint8Array(totalLength);
27
- let offset = 0;
28
- nonEmptyByteArrays.forEach((arr) => {
29
- result.set(arr, offset);
30
- offset += arr.length;
31
- });
32
- return result;
33
- };
34
75
  var padBytes = (bytes, length) => {
35
76
  if (bytes.length >= length)
36
77
  return bytes;
@@ -39,42 +80,68 @@ this.globalThis.solanaWeb3 = (function (exports) {
39
80
  return paddedBytes;
40
81
  };
41
82
  var fixBytes = (bytes, length) => padBytes(bytes.length <= length ? bytes : bytes.slice(0, length), length);
42
- function fixCodecHelper(data, fixedBytes, description) {
43
- return {
44
- description: description ?? `fixed(${fixedBytes}, ${data.description})`,
45
- fixedSize: fixedBytes,
46
- maxSize: fixedBytes
47
- };
83
+ function getEncodedSize(value, encoder) {
84
+ return "fixedSize" in encoder ? encoder.fixedSize : encoder.getSizeFromValue(value);
48
85
  }
49
- function fixEncoder(encoder, fixedBytes, description) {
50
- return {
51
- ...fixCodecHelper(encoder, fixedBytes, description),
52
- encode: (value) => fixBytes(encoder.encode(value), fixedBytes)
53
- };
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
+ });
54
95
  }
55
- function fixDecoder(decoder, fixedBytes, description) {
56
- return {
57
- ...fixCodecHelper(decoder, fixedBytes, description),
58
- 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) => {
59
128
  assertByteArrayHasEnoughBytesForCodec("fixCodec", fixedBytes, bytes, offset);
60
129
  if (offset > 0 || bytes.length > fixedBytes) {
61
130
  bytes = bytes.slice(offset, offset + fixedBytes);
62
131
  }
63
- if (decoder.fixedSize !== null) {
132
+ if (isFixedSize(decoder)) {
64
133
  bytes = fixBytes(bytes, decoder.fixedSize);
65
134
  }
66
- const [value] = decoder.decode(bytes, 0);
135
+ const [value] = decoder.read(bytes, 0);
67
136
  return [value, offset + fixedBytes];
68
137
  }
69
- };
138
+ });
70
139
  }
71
140
  function mapEncoder(encoder, unmap) {
72
- return {
73
- description: encoder.description,
74
- encode: (value) => encoder.encode(unmap(value)),
75
- fixedSize: encoder.fixedSize,
76
- maxSize: encoder.maxSize
77
- };
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
+ });
78
145
  }
79
146
 
80
147
  // ../codecs-numbers/dist/index.browser.js
@@ -85,75 +152,65 @@ this.globalThis.solanaWeb3 = (function (exports) {
85
152
  );
86
153
  }
87
154
  }
88
- function sharedNumberFactory(input) {
89
- let littleEndian;
90
- let defaultDescription = input.name;
91
- if (input.size > 1) {
92
- littleEndian = !("endian" in input.config) || input.config.endian === 0;
93
- defaultDescription += littleEndian ? "(le)" : "(be)";
94
- }
95
- return {
96
- description: input.config.description ?? defaultDescription,
97
- fixedSize: input.size,
98
- littleEndian,
99
- maxSize: input.size
100
- };
155
+ function isLittleEndian(config) {
156
+ return (config == null ? void 0 : config.endian) === 1 ? false : true;
101
157
  }
102
158
  function numberEncoderFactory(input) {
103
- const codecData = sharedNumberFactory(input);
104
- return {
105
- description: codecData.description,
106
- encode(value) {
159
+ return createEncoder({
160
+ fixedSize: input.size,
161
+ write(value, bytes, offset) {
107
162
  if (input.range) {
108
163
  assertNumberIsBetweenForCodec(input.name, input.range[0], input.range[1], value);
109
164
  }
110
165
  const arrayBuffer = new ArrayBuffer(input.size);
111
- input.set(new DataView(arrayBuffer), value, codecData.littleEndian);
112
- return new Uint8Array(arrayBuffer);
113
- },
114
- fixedSize: codecData.fixedSize,
115
- maxSize: codecData.maxSize
116
- };
166
+ input.set(new DataView(arrayBuffer), value, isLittleEndian(input.config));
167
+ bytes.set(new Uint8Array(arrayBuffer), offset);
168
+ return offset + input.size;
169
+ }
170
+ });
117
171
  }
118
172
  function numberDecoderFactory(input) {
119
- const codecData = sharedNumberFactory(input);
120
- return {
121
- decode(bytes, offset = 0) {
122
- assertByteArrayIsNotEmptyForCodec(codecData.description, bytes, offset);
123
- 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);
124
178
  const view = new DataView(toArrayBuffer(bytes, offset, input.size));
125
- return [input.get(view, codecData.littleEndian), offset + input.size];
126
- },
127
- description: codecData.description,
128
- fixedSize: codecData.fixedSize,
129
- maxSize: codecData.maxSize
130
- };
179
+ return [input.get(view, isLittleEndian(input.config)), offset + input.size];
180
+ }
181
+ });
131
182
  }
132
183
  function toArrayBuffer(bytes, offset, length) {
133
- const bytesOffset = bytes.byteOffset + (offset ?? 0);
134
- const bytesLength = length ?? bytes.byteLength;
184
+ const bytesOffset = bytes.byteOffset + (offset != null ? offset : 0);
185
+ const bytesLength = length != null ? length : bytes.byteLength;
135
186
  return bytes.buffer.slice(bytesOffset, bytesOffset + bytesLength);
136
187
  }
137
- var getShortU16Encoder = (config = {}) => ({
138
- description: config.description ?? "shortU16",
139
- encode: (value) => {
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) => {
140
198
  assertNumberIsBetweenForCodec("shortU16", 0, 65535, value);
141
- const bytes = [0];
199
+ const shortU16Bytes = [0];
142
200
  for (let ii = 0; ; ii += 1) {
143
201
  const alignedValue = value >> ii * 7;
144
202
  if (alignedValue === 0) {
145
203
  break;
146
204
  }
147
205
  const nextSevenBits = 127 & alignedValue;
148
- bytes[ii] = nextSevenBits;
206
+ shortU16Bytes[ii] = nextSevenBits;
149
207
  if (ii > 0) {
150
- bytes[ii - 1] |= 128;
208
+ shortU16Bytes[ii - 1] |= 128;
151
209
  }
152
210
  }
153
- return new Uint8Array(bytes);
154
- },
155
- fixedSize: null,
156
- maxSize: 3
211
+ bytes.set(shortU16Bytes, offset);
212
+ return offset + shortU16Bytes.length;
213
+ }
157
214
  });
158
215
  var getU32Encoder = (config = {}) => numberEncoderFactory({
159
216
  config,
@@ -168,8 +225,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
168
225
  name: "u32",
169
226
  size: 4
170
227
  });
171
- var getU8Encoder = (config = {}) => numberEncoderFactory({
172
- config,
228
+ var getU8Encoder = () => numberEncoderFactory({
173
229
  name: "u8",
174
230
  range: [0, Number("0xff")],
175
231
  set: (view, value) => view.setUint8(0, value),
@@ -183,43 +239,38 @@ this.globalThis.solanaWeb3 = (function (exports) {
183
239
  }
184
240
  }
185
241
  var getBaseXEncoder = (alphabet4) => {
186
- const base = alphabet4.length;
187
- const baseBigInt = BigInt(base);
188
- return {
189
- description: `base${base}`,
190
- 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) {
191
251
  assertValidBaseString(alphabet4, value);
192
252
  if (value === "")
193
- return new Uint8Array();
194
- const chars = [...value];
195
- let trailIndex = chars.findIndex((c) => c !== alphabet4[0]);
196
- trailIndex = trailIndex === -1 ? chars.length : trailIndex;
197
- const leadingZeroes = Array(trailIndex).fill(0);
198
- if (trailIndex === chars.length)
199
- return Uint8Array.from(leadingZeroes);
200
- const tailChars = chars.slice(trailIndex);
201
- let base10Number = 0n;
202
- let baseXPower = 1n;
203
- for (let i = tailChars.length - 1; i >= 0; i -= 1) {
204
- base10Number += baseXPower * BigInt(alphabet4.indexOf(tailChars[i]));
205
- 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;
206
258
  }
259
+ let base10Number = getBigIntFromBaseX(tailChars, alphabet4);
207
260
  const tailBytes = [];
208
261
  while (base10Number > 0n) {
209
262
  tailBytes.unshift(Number(base10Number % 256n));
210
263
  base10Number /= 256n;
211
264
  }
212
- return Uint8Array.from(leadingZeroes.concat(tailBytes));
213
- },
214
- fixedSize: null,
215
- maxSize: null
216
- };
265
+ const bytesToAdd = [...Array(leadingZeroes.length).fill(0), ...tailBytes];
266
+ bytes.set(bytesToAdd, offset);
267
+ return offset + bytesToAdd.length;
268
+ }
269
+ });
217
270
  };
218
271
  var getBaseXDecoder = (alphabet4) => {
219
- const base = alphabet4.length;
220
- const baseBigInt = BigInt(base);
221
- return {
222
- decode(rawBytes, offset = 0) {
272
+ return createDecoder({
273
+ read(rawBytes, offset) {
223
274
  const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);
224
275
  if (bytes.length === 0)
225
276
  return ["", 0];
@@ -228,19 +279,29 @@ this.globalThis.solanaWeb3 = (function (exports) {
228
279
  const leadingZeroes = alphabet4[0].repeat(trailIndex);
229
280
  if (trailIndex === bytes.length)
230
281
  return [leadingZeroes, rawBytes.length];
231
- let base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
232
- const tailChars = [];
233
- while (base10Number > 0n) {
234
- tailChars.unshift(alphabet4[Number(base10Number % baseBigInt)]);
235
- base10Number /= baseBigInt;
236
- }
237
- return [leadingZeroes + tailChars.join(""), rawBytes.length];
238
- },
239
- description: `base${base}`,
240
- fixedSize: null,
241
- maxSize: null
242
- };
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
+ });
243
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
+ }
244
305
  var alphabet2 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
245
306
  var getBase58Encoder = () => getBaseXEncoder(alphabet2);
246
307
  var getBase58Decoder = () => getBaseXDecoder(alphabet2);
@@ -252,75 +313,69 @@ this.globalThis.solanaWeb3 = (function (exports) {
252
313
  var o = globalThis.TextEncoder;
253
314
  var getUtf8Encoder = () => {
254
315
  let textEncoder;
255
- return {
256
- description: "utf8",
257
- encode: (value) => new Uint8Array((textEncoder || (textEncoder = new o())).encode(value)),
258
- fixedSize: null,
259
- maxSize: null
260
- };
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
+ });
261
324
  };
262
325
  var getUtf8Decoder = () => {
263
326
  let textDecoder;
264
- return {
265
- decode(bytes, offset = 0) {
327
+ return createDecoder({
328
+ read(bytes, offset) {
266
329
  const value = (textDecoder || (textDecoder = new e())).decode(bytes.slice(offset));
267
330
  return [removeNullCharacters(value), bytes.length];
268
- },
269
- description: "utf8",
270
- fixedSize: null,
271
- maxSize: null
272
- };
331
+ }
332
+ });
273
333
  };
274
- var getStringEncoder = (config = {}) => {
275
- const size = config.size ?? getU32Encoder();
276
- const encoding = config.encoding ?? getUtf8Encoder();
277
- const description = config.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
334
+ function getStringEncoder(config = {}) {
335
+ var _a, _b;
336
+ const size = (_a = config.size) != null ? _a : getU32Encoder();
337
+ const encoding = (_b = config.encoding) != null ? _b : getUtf8Encoder();
278
338
  if (size === "variable") {
279
- return { ...encoding, description };
339
+ return encoding;
280
340
  }
281
341
  if (typeof size === "number") {
282
- return fixEncoder(encoding, size, description);
342
+ return fixEncoder(encoding, size);
283
343
  }
284
- return {
285
- description,
286
- encode: (value) => {
287
- const contentBytes = encoding.encode(value);
288
- const lengthBytes = size.encode(contentBytes.length);
289
- return mergeBytes([lengthBytes, contentBytes]);
344
+ return createEncoder({
345
+ getSizeFromValue: (value) => {
346
+ const contentSize = getEncodedSize(value, encoding);
347
+ return getEncodedSize(contentSize, size) + contentSize;
290
348
  },
291
- fixedSize: null,
292
- maxSize: null
293
- };
294
- };
295
- var getStringDecoder = (config = {}) => {
296
- const size = config.size ?? getU32Decoder();
297
- const encoding = config.encoding ?? getUtf8Decoder();
298
- const description = config.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
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;
358
+ const size = (_a = config.size) != null ? _a : getU32Decoder();
359
+ const encoding = (_b = config.encoding) != null ? _b : getUtf8Decoder();
299
360
  if (size === "variable") {
300
- return { ...encoding, description };
361
+ return encoding;
301
362
  }
302
363
  if (typeof size === "number") {
303
- return fixDecoder(encoding, size, description);
364
+ return fixDecoder(encoding, size);
304
365
  }
305
- return {
306
- decode: (bytes, offset = 0) => {
366
+ return createDecoder({
367
+ read: (bytes, offset = 0) => {
307
368
  assertByteArrayIsNotEmptyForCodec("string", bytes, offset);
308
- const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);
369
+ const [lengthBigInt, lengthOffset] = size.read(bytes, offset);
309
370
  const length = Number(lengthBigInt);
310
371
  offset = lengthOffset;
311
372
  const contentBytes = bytes.slice(offset, offset + length);
312
373
  assertByteArrayHasEnoughBytesForCodec("string", length, contentBytes);
313
- const [value, contentOffset] = encoding.decode(contentBytes);
374
+ const [value, contentOffset] = encoding.read(contentBytes, 0);
314
375
  offset += contentOffset;
315
376
  return [value, offset];
316
- },
317
- description,
318
- fixedSize: null,
319
- maxSize: null
320
- };
321
- };
322
- function getSizeDescription(size) {
323
- return typeof size === "object" ? size.description : `${size}`;
377
+ }
378
+ });
324
379
  }
325
380
 
326
381
  // ../assertions/dist/index.browser.js
@@ -354,8 +409,9 @@ this.globalThis.solanaWeb3 = (function (exports) {
354
409
  }
355
410
  }
356
411
  async function assertKeyGenerationIsAvailable() {
412
+ var _a;
357
413
  assertIsSecureContext();
358
- if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.generateKey !== "function") {
414
+ if (typeof globalThis.crypto === "undefined" || typeof ((_a = globalThis.crypto.subtle) == null ? void 0 : _a.generateKey) !== "function") {
359
415
  throw new Error("No key generation implementation could be found");
360
416
  }
361
417
  if (!await isEd25519CurveSupported(globalThis.crypto.subtle)) {
@@ -365,14 +421,16 @@ this.globalThis.solanaWeb3 = (function (exports) {
365
421
  }
366
422
  }
367
423
  async function assertKeyExporterIsAvailable() {
424
+ var _a;
368
425
  assertIsSecureContext();
369
- if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.exportKey !== "function") {
426
+ if (typeof globalThis.crypto === "undefined" || typeof ((_a = globalThis.crypto.subtle) == null ? void 0 : _a.exportKey) !== "function") {
370
427
  throw new Error("No key export implementation could be found");
371
428
  }
372
429
  }
373
430
  async function assertSigningCapabilityIsAvailable() {
431
+ var _a;
374
432
  assertIsSecureContext();
375
- if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.sign !== "function") {
433
+ if (typeof globalThis.crypto === "undefined" || typeof ((_a = globalThis.crypto.subtle) == null ? void 0 : _a.sign) !== "function") {
376
434
  throw new Error("No signing implementation could be found");
377
435
  }
378
436
  }
@@ -431,22 +489,14 @@ this.globalThis.solanaWeb3 = (function (exports) {
431
489
  assertIsAddress(putativeAddress);
432
490
  return putativeAddress;
433
491
  }
434
- function getAddressEncoder(config) {
492
+ function getAddressEncoder() {
435
493
  return mapEncoder(
436
- getStringEncoder({
437
- description: config?.description ?? "Address",
438
- encoding: getMemoizedBase58Encoder(),
439
- size: 32
440
- }),
494
+ getStringEncoder({ encoding: getMemoizedBase58Encoder(), size: 32 }),
441
495
  (putativeAddress) => address(putativeAddress)
442
496
  );
443
497
  }
444
- function getAddressDecoder(config) {
445
- return getStringDecoder({
446
- description: config?.description ?? "Address",
447
- encoding: getMemoizedBase58Decoder(),
448
- size: 32
449
- });
498
+ function getAddressDecoder() {
499
+ return getStringDecoder({ encoding: getMemoizedBase58Decoder(), size: 32 });
450
500
  }
451
501
  function getAddressComparator() {
452
502
  return new Intl.Collator("en", {
@@ -464,8 +514,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
464
514
  throw new Error("The `CryptoKey` must be an `Ed25519` public key");
465
515
  }
466
516
  const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
467
- const [base58EncodedAddress] = getAddressDecoder().decode(new Uint8Array(publicKeyBytes));
468
- return base58EncodedAddress;
517
+ return getAddressDecoder().decode(new Uint8Array(publicKeyBytes));
469
518
  }
470
519
 
471
520
  // ../keys/dist/index.browser.js
@@ -490,92 +539,102 @@ this.globalThis.solanaWeb3 = (function (exports) {
490
539
  }
491
540
 
492
541
  // ../codecs-data-structures/dist/index.browser.js
493
- function sumCodecSizes(sizes) {
494
- return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
495
- }
496
- function getArrayLikeCodecSizeDescription(size) {
497
- return typeof size === "object" ? size.description : `${size}`;
498
- }
499
- function getArrayLikeCodecSizeFromChildren(size, childrenSizes) {
500
- if (typeof size !== "number")
501
- return null;
502
- if (size === 0)
503
- return 0;
504
- const childrenSize = sumCodecSizes(childrenSizes);
505
- return childrenSize === null ? null : childrenSize * size;
506
- }
507
- function getArrayLikeCodecSizePrefix(size, realSize) {
508
- return typeof size === "object" ? size.encode(realSize) : new Uint8Array();
509
- }
510
542
  function assertValidNumberOfItemsForCodec(codecDescription, expected, actual) {
511
543
  if (expected !== actual) {
512
544
  throw new Error(`Expected [${codecDescription}] to have ${expected} items, got ${actual}.`);
513
545
  }
514
546
  }
515
- function arrayCodecHelper(item, size, description) {
516
- if (size === "remainder" && item.fixedSize === null) {
517
- throw new Error('Codecs of "remainder" size must have fixed-size items.');
518
- }
519
- return {
520
- description: description ?? `array(${item.description}; ${getArrayLikeCodecSizeDescription(size)})`,
521
- fixedSize: getArrayLikeCodecSizeFromChildren(size, [item.fixedSize]),
522
- maxSize: getArrayLikeCodecSizeFromChildren(size, [item.maxSize])
523
- };
547
+ function sumCodecSizes(sizes) {
548
+ return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
549
+ }
550
+ function getFixedSize(codec) {
551
+ return isFixedSize(codec) ? codec.fixedSize : null;
552
+ }
553
+ function getMaxSize(codec) {
554
+ var _a;
555
+ return isFixedSize(codec) ? codec.fixedSize : (_a = codec.maxSize) != null ? _a : null;
524
556
  }
525
557
  function getArrayEncoder(item, config = {}) {
526
- const size = config.size ?? getU32Encoder();
527
- return {
528
- ...arrayCodecHelper(item, size, config.description),
529
- encode: (value) => {
558
+ var _a, _b;
559
+ const size = (_a = config.size) != null ? _a : getU32Encoder();
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) => {
530
574
  if (typeof size === "number") {
531
- 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);
532
579
  }
533
- 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;
534
584
  }
535
- };
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;
536
593
  }
537
594
  function getBytesEncoder(config = {}) {
538
- const size = config.size ?? "variable";
539
- const sizeDescription = typeof size === "object" ? size.description : `${size}`;
540
- const description = config.description ?? `bytes(${sizeDescription})`;
541
- const byteEncoder = {
542
- description,
543
- encode: (value) => value,
544
- fixedSize: null,
545
- maxSize: null
546
- };
595
+ var _a;
596
+ const size = (_a = config.size) != null ? _a : "variable";
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
+ });
547
604
  if (size === "variable") {
548
605
  return byteEncoder;
549
606
  }
550
607
  if (typeof size === "number") {
551
- return fixEncoder(byteEncoder, size, description);
608
+ return fixEncoder(byteEncoder, size);
552
609
  }
553
- return {
554
- ...byteEncoder,
555
- encode: (value) => {
556
- const contentBytes = byteEncoder.encode(value);
557
- const lengthBytes = size.encode(contentBytes.length);
558
- 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);
559
615
  }
560
- };
561
- }
562
- function structCodecHelper(fields, description) {
563
- const fieldDescriptions = fields.map(([name, codec]) => `${String(name)}: ${codec.description}`).join(", ");
564
- return {
565
- description: description ?? `struct(${fieldDescriptions})`,
566
- fixedSize: sumCodecSizes(fields.map(([, field]) => field.fixedSize)),
567
- maxSize: sumCodecSizes(fields.map(([, field]) => field.maxSize))
568
- };
616
+ });
569
617
  }
570
- function getStructEncoder(fields, config = {}) {
571
- return {
572
- ...structCodecHelper(fields, config.description),
573
- encode: (struct) => {
574
- const fieldBytes = fields.map(([key, codec]) => codec.encode(struct[key]));
575
- 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;
576
633
  }
577
- };
634
+ });
578
635
  }
636
+
637
+ // ../transactions/dist/index.browser.js
579
638
  var AccountRole = /* @__PURE__ */ ((AccountRole2) => {
580
639
  AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */
581
640
  3] = "WRITABLE_SIGNER";
@@ -588,7 +647,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
588
647
  return AccountRole2;
589
648
  })(AccountRole || {});
590
649
  var IS_WRITABLE_BITMASK = 1;
591
- function isSignerRole(role) {
650
+ function isSignerRole2(role) {
592
651
  return role >= 2;
593
652
  }
594
653
  function isWritableRole(role) {
@@ -598,7 +657,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
598
657
  return roleA | roleB;
599
658
  }
600
659
  function upsert(addressMap, address2, update) {
601
- addressMap[address2] = update(addressMap[address2] ?? { role: AccountRole.READONLY });
660
+ var _a;
661
+ addressMap[address2] = update((_a = addressMap[address2]) != null ? _a : { role: AccountRole.READONLY });
602
662
  }
603
663
  var TYPE = Symbol("AddressMapTypeProperty");
604
664
  function getAddressMapFromInstructions(feePayer, instructions) {
@@ -661,7 +721,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
661
721
  role: nextRole
662
722
  };
663
723
  }
664
- } else if (isSignerRole(accountMeta.role)) {
724
+ } else if (isSignerRole2(accountMeta.role)) {
665
725
  return {
666
726
  [TYPE]: 2,
667
727
  role: nextRole
@@ -698,7 +758,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
698
758
  }
699
759
  } else if ("lookupTableAddress" in accountMeta && // Static accounts can be 'upgraded' to lookup table accounts as
700
760
  // long as they are not require to sign the transaction.
701
- !isSignerRole(entry.role)) {
761
+ !isSignerRole2(entry.role)) {
702
762
  return {
703
763
  ...accountMeta,
704
764
  [TYPE]: 1,
@@ -749,8 +809,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
749
809
  return 1;
750
810
  }
751
811
  }
752
- const leftIsSigner = isSignerRole(leftEntry.role);
753
- if (leftIsSigner !== isSignerRole(rightEntry.role)) {
812
+ const leftIsSigner = isSignerRole2(leftEntry.role);
813
+ if (leftIsSigner !== isSignerRole2(rightEntry.role)) {
754
814
  return leftIsSigner ? -1 : 1;
755
815
  }
756
816
  const leftIsWritable = isWritableRole(leftEntry.role);
@@ -800,7 +860,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
800
860
  break;
801
861
  }
802
862
  const accountIsWritable = isWritableRole(account.role);
803
- if (isSignerRole(account.role)) {
863
+ if (isSignerRole2(account.role)) {
804
864
  numSignerAccounts++;
805
865
  if (!accountIsWritable) {
806
866
  numReadonlySignerAccounts++;
@@ -855,33 +915,20 @@ this.globalThis.solanaWeb3 = (function (exports) {
855
915
  version: transaction.version
856
916
  };
857
917
  }
858
- var lookupTableAddressDescription = "The address of the address lookup table account from which instruction addresses should be looked up" ;
859
- var writableIndicesDescription = "The indices of the accounts in the lookup table that should be loaded as writeable" ;
860
- var readableIndicesDescription = "The indices of the accounts in the lookup table that should be loaded as read-only" ;
861
- 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" ;
862
918
  var memoizedAddressTableLookupEncoder;
863
919
  function getAddressTableLookupEncoder() {
864
920
  if (!memoizedAddressTableLookupEncoder) {
865
- memoizedAddressTableLookupEncoder = getStructEncoder(
921
+ memoizedAddressTableLookupEncoder = getStructEncoder([
922
+ ["lookupTableAddress", getAddressEncoder()],
866
923
  [
867
- ["lookupTableAddress", getAddressEncoder({ description: lookupTableAddressDescription })],
868
- [
869
- "writableIndices",
870
- getArrayEncoder(getU8Encoder(), {
871
- description: writableIndicesDescription,
872
- size: getShortU16Encoder()
873
- })
874
- ],
875
- [
876
- "readableIndices",
877
- getArrayEncoder(getU8Encoder(), {
878
- description: readableIndicesDescription,
879
- size: getShortU16Encoder()
880
- })
881
- ]
924
+ "writableIndices",
925
+ getArrayEncoder(getU8Encoder(), { size: getShortU16Encoder() })
882
926
  ],
883
- { description: addressTableLookupDescription }
884
- );
927
+ [
928
+ "readableIndices",
929
+ getArrayEncoder(getU8Encoder(), { size: getShortU16Encoder() })
930
+ ]
931
+ ]);
885
932
  }
886
933
  return memoizedAddressTableLookupEncoder;
887
934
  }
@@ -891,57 +938,32 @@ this.globalThis.solanaWeb3 = (function (exports) {
891
938
  memoizedU8Encoder = getU8Encoder();
892
939
  return memoizedU8Encoder;
893
940
  }
894
- function getMemoizedU8EncoderDescription(description) {
895
- const encoder = getMemoizedU8Encoder();
896
- return {
897
- ...encoder,
898
- description: description ?? encoder.description
899
- };
900
- }
901
- var numSignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction" ;
902
- 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" ;
903
- var numReadonlyNonSignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable" ;
904
- var messageHeaderDescription = "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses" ;
905
941
  function getMessageHeaderEncoder() {
906
- return getStructEncoder(
907
- [
908
- ["numSignerAccounts", getMemoizedU8EncoderDescription(numSignerAccountsDescription)],
909
- ["numReadonlySignerAccounts", getMemoizedU8EncoderDescription(numReadonlySignerAccountsDescription)],
910
- ["numReadonlyNonSignerAccounts", getMemoizedU8EncoderDescription(numReadonlyNonSignerAccountsDescription)]
911
- ],
912
- {
913
- description: messageHeaderDescription
914
- }
915
- );
942
+ return getStructEncoder([
943
+ ["numSignerAccounts", getMemoizedU8Encoder()],
944
+ ["numReadonlySignerAccounts", getMemoizedU8Encoder()],
945
+ ["numReadonlyNonSignerAccounts", getMemoizedU8Encoder()]
946
+ ]);
916
947
  }
917
- var programAddressIndexDescription = "The index of the program being called, according to the well-ordered accounts list for this transaction" ;
918
- var accountIndexDescription = "The index of an account, according to the well-ordered accounts list for this transaction" ;
919
- 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" ;
920
- var dataDescription = "An optional buffer of data passed to the instruction" ;
921
948
  var memoizedGetInstructionEncoder;
922
949
  function getInstructionEncoder() {
923
950
  if (!memoizedGetInstructionEncoder) {
924
951
  memoizedGetInstructionEncoder = mapEncoder(
925
952
  getStructEncoder([
926
- ["programAddressIndex", getU8Encoder({ description: programAddressIndexDescription })],
927
- [
928
- "accountIndices",
929
- getArrayEncoder(getU8Encoder({ description: accountIndexDescription }), {
930
- description: accountIndicesDescription,
931
- size: getShortU16Encoder()
932
- })
933
- ],
934
- ["data", getBytesEncoder({ description: dataDescription, size: getShortU16Encoder() })]
953
+ ["programAddressIndex", getU8Encoder()],
954
+ ["accountIndices", getArrayEncoder(getU8Encoder(), { size: getShortU16Encoder() })],
955
+ ["data", getBytesEncoder({ size: getShortU16Encoder() })]
935
956
  ]),
936
957
  // Convert an instruction to have all fields defined
937
958
  (instruction) => {
959
+ var _a, _b;
938
960
  if (instruction.accountIndices !== void 0 && instruction.data !== void 0) {
939
961
  return instruction;
940
962
  }
941
963
  return {
942
964
  ...instruction,
943
- accountIndices: instruction.accountIndices ?? [],
944
- data: instruction.data ?? new Uint8Array(0)
965
+ accountIndices: (_a = instruction.accountIndices) != null ? _a : [],
966
+ data: (_b = instruction.data) != null ? _b : new Uint8Array(0)
945
967
  };
946
968
  }
947
969
  );
@@ -949,30 +971,22 @@ this.globalThis.solanaWeb3 = (function (exports) {
949
971
  return memoizedGetInstructionEncoder;
950
972
  }
951
973
  var VERSION_FLAG_MASK = 128;
952
- var BASE_CONFIG = {
953
- description: "A single byte that encodes the version of the transaction" ,
954
- fixedSize: null,
955
- maxSize: 1
956
- };
957
- function encode(value) {
958
- if (value === "legacy") {
959
- return new Uint8Array();
960
- }
961
- if (value < 0 || value > 127) {
962
- throw new Error(`Transaction version must be in the range [0, 127]. \`${value}\` given.`);
963
- }
964
- return new Uint8Array([value | VERSION_FLAG_MASK]);
965
- }
966
974
  function getTransactionVersionEncoder() {
967
- return {
968
- ...BASE_CONFIG,
969
- encode
970
- };
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
+ });
971
989
  }
972
- var staticAccountsDescription = "A compact-array of static account addresses belonging to this transaction" ;
973
- var lifetimeTokenDescription = "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" ;
974
- var instructionsDescription = "A compact-array of instructions belonging to this transaction" ;
975
- var addressTableLookupsDescription = "A compact array of address table lookups belonging to this transaction" ;
976
990
  function getCompiledMessageLegacyEncoder() {
977
991
  return getStructEncoder(getPreludeStructEncoderTuple());
978
992
  }
@@ -983,12 +997,13 @@ this.globalThis.solanaWeb3 = (function (exports) {
983
997
  ["addressTableLookups", getAddressTableLookupArrayEncoder()]
984
998
  ]),
985
999
  (value) => {
1000
+ var _a;
986
1001
  if (value.version === "legacy") {
987
1002
  return value;
988
1003
  }
989
1004
  return {
990
1005
  ...value,
991
- addressTableLookups: value.addressTableLookups ?? []
1006
+ addressTableLookups: (_a = value.addressTableLookups) != null ? _a : []
992
1007
  };
993
1008
  }
994
1009
  );
@@ -997,50 +1012,31 @@ this.globalThis.solanaWeb3 = (function (exports) {
997
1012
  return [
998
1013
  ["version", getTransactionVersionEncoder()],
999
1014
  ["header", getMessageHeaderEncoder()],
1000
- [
1001
- "staticAccounts",
1002
- getArrayEncoder(getAddressEncoder(), {
1003
- description: staticAccountsDescription,
1004
- size: getShortU16Encoder()
1005
- })
1006
- ],
1007
- [
1008
- "lifetimeToken",
1009
- getStringEncoder({
1010
- description: lifetimeTokenDescription,
1011
- encoding: getBase58Encoder(),
1012
- size: 32
1013
- })
1014
- ],
1015
- [
1016
- "instructions",
1017
- getArrayEncoder(getInstructionEncoder(), {
1018
- description: instructionsDescription,
1019
- size: getShortU16Encoder()
1020
- })
1021
- ]
1015
+ ["staticAccounts", getArrayEncoder(getAddressEncoder(), { size: getShortU16Encoder() })],
1016
+ ["lifetimeToken", getStringEncoder({ encoding: getBase58Encoder(), size: 32 })],
1017
+ ["instructions", getArrayEncoder(getInstructionEncoder(), { size: getShortU16Encoder() })]
1022
1018
  ];
1023
1019
  }
1024
1020
  function getAddressTableLookupArrayEncoder() {
1025
- return getArrayEncoder(getAddressTableLookupEncoder(), {
1026
- description: addressTableLookupsDescription,
1027
- size: getShortU16Encoder()
1028
- });
1021
+ return getArrayEncoder(getAddressTableLookupEncoder(), { size: getShortU16Encoder() });
1029
1022
  }
1030
- var messageDescription = "The wire format of a Solana transaction message" ;
1031
1023
  function getCompiledMessageEncoder() {
1032
- return {
1033
- description: messageDescription,
1034
- encode: (compiledMessage) => {
1024
+ return createEncoder({
1025
+ getSizeFromValue: (compiledMessage) => {
1035
1026
  if (compiledMessage.version === "legacy") {
1036
- return getCompiledMessageLegacyEncoder().encode(compiledMessage);
1027
+ return getCompiledMessageLegacyEncoder().getSizeFromValue(compiledMessage);
1037
1028
  } else {
1038
- return getCompiledMessageVersionedEncoder().encode(compiledMessage);
1029
+ return getCompiledMessageVersionedEncoder().getSizeFromValue(compiledMessage);
1039
1030
  }
1040
1031
  },
1041
- fixedSize: null,
1042
- maxSize: null
1043
- };
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
+ });
1044
1040
  }
1045
1041
  async function partiallySignTransaction(keyPairs, transaction) {
1046
1042
  const compiledMessage = compileMessage(transaction);
@@ -1061,6 +1057,18 @@ this.globalThis.solanaWeb3 = (function (exports) {
1061
1057
  Object.freeze(out);
1062
1058
  return out;
1063
1059
  }
1060
+ function assertTransactionIsFullySigned(transaction) {
1061
+ const signerAddressesFromInstructions = transaction.instructions.flatMap((i) => {
1062
+ var _a, _b;
1063
+ return (_b = (_a = i.accounts) == null ? void 0 : _a.filter((a) => isSignerRole2(a.role))) != null ? _b : [];
1064
+ }).map((a) => a.address);
1065
+ const requiredSigners = /* @__PURE__ */ new Set([transaction.feePayer, ...signerAddressesFromInstructions]);
1066
+ requiredSigners.forEach((address2) => {
1067
+ if (!transaction.signatures[address2]) {
1068
+ throw new Error(`Transaction is missing signature for address \`${address2}\``);
1069
+ }
1070
+ });
1071
+ }
1064
1072
 
1065
1073
  // src/message-partial-signer.ts
1066
1074
  function isMessagePartialSigner(value) {
@@ -1133,14 +1141,15 @@ this.globalThis.solanaWeb3 = (function (exports) {
1133
1141
  throw new Error("The provided value does not implement any of the MessageSigner interfaces");
1134
1142
  }
1135
1143
  }
1136
- var o2 = globalThis.TextEncoder;
1137
1144
 
1138
- // src/signable-message.ts
1139
- function createSignableMessage(content, signatures = {}) {
1140
- return Object.freeze({
1141
- content: typeof content === "string" ? new o2().encode(content) : content,
1142
- signatures: Object.freeze({ ...signatures })
1143
- });
1145
+ // src/noop-signer.ts
1146
+ function createNoopSigner(address2) {
1147
+ const out = {
1148
+ address: address2,
1149
+ signMessages: async (messages) => messages.map(() => Object.freeze({})),
1150
+ signTransactions: async (transactions) => transactions.map(() => Object.freeze({}))
1151
+ };
1152
+ return Object.freeze(out);
1144
1153
  }
1145
1154
 
1146
1155
  // src/transaction-modifying-signer.ts
@@ -1173,6 +1182,139 @@ this.globalThis.solanaWeb3 = (function (exports) {
1173
1182
  }
1174
1183
  }
1175
1184
 
1185
+ // src/sign-transaction.ts
1186
+ async function partiallySignTransactionWithSigners(transaction, config = {}) {
1187
+ const { partialSigners, modifyingSigners } = categorizeTransactionSigners(
1188
+ deduplicateSigners(getSignersFromTransaction(transaction).filter(isTransactionSigner)),
1189
+ { identifySendingSigner: false }
1190
+ );
1191
+ return signModifyingAndPartialTransactionSigners(transaction, modifyingSigners, partialSigners, config.abortSignal);
1192
+ }
1193
+ async function signTransactionWithSigners(transaction, config = {}) {
1194
+ const signedTransaction = await partiallySignTransactionWithSigners(transaction, config);
1195
+ assertTransactionIsFullySigned(signedTransaction);
1196
+ return signedTransaction;
1197
+ }
1198
+ async function signAndSendTransactionWithSigners(transaction, config = {}) {
1199
+ const abortSignal = config.abortSignal;
1200
+ const { partialSigners, modifyingSigners, sendingSigner } = categorizeTransactionSigners(
1201
+ deduplicateSigners(getSignersFromTransaction(transaction).filter(isTransactionSigner))
1202
+ );
1203
+ abortSignal == null ? void 0 : abortSignal.throwIfAborted();
1204
+ const signedTransaction = await signModifyingAndPartialTransactionSigners(
1205
+ transaction,
1206
+ modifyingSigners,
1207
+ partialSigners,
1208
+ abortSignal
1209
+ );
1210
+ if (!sendingSigner) {
1211
+ throw new Error(
1212
+ "No `TransactionSendingSigner` was identified. Please provide a valid `ITransactionWithSingleSendingSigner` transaction."
1213
+ );
1214
+ }
1215
+ abortSignal == null ? void 0 : abortSignal.throwIfAborted();
1216
+ const [signature] = await sendingSigner.signAndSendTransactions([signedTransaction], { abortSignal });
1217
+ abortSignal == null ? void 0 : abortSignal.throwIfAborted();
1218
+ return signature;
1219
+ }
1220
+ function categorizeTransactionSigners(signers, config = {}) {
1221
+ var _a;
1222
+ const identifySendingSigner = (_a = config.identifySendingSigner) != null ? _a : true;
1223
+ const sendingSigner = identifySendingSigner ? identifyTransactionSendingSigner(signers) : null;
1224
+ const otherSigners = signers.filter(
1225
+ (signer) => signer !== sendingSigner && (isTransactionModifyingSigner(signer) || isTransactionPartialSigner(signer))
1226
+ );
1227
+ const modifyingSigners = identifyTransactionModifyingSigners(otherSigners);
1228
+ const partialSigners = otherSigners.filter(isTransactionPartialSigner).filter((signer) => !modifyingSigners.includes(signer));
1229
+ return Object.freeze({ modifyingSigners, partialSigners, sendingSigner });
1230
+ }
1231
+ function identifyTransactionSendingSigner(signers) {
1232
+ const sendingSigners = signers.filter(isTransactionSendingSigner);
1233
+ if (sendingSigners.length === 0)
1234
+ return null;
1235
+ const sendingOnlySigners = sendingSigners.filter(
1236
+ (signer) => !isTransactionModifyingSigner(signer) && !isTransactionPartialSigner(signer)
1237
+ );
1238
+ if (sendingOnlySigners.length > 0) {
1239
+ return sendingOnlySigners[0];
1240
+ }
1241
+ return sendingSigners[0];
1242
+ }
1243
+ function identifyTransactionModifyingSigners(signers) {
1244
+ const modifyingSigners = signers.filter(isTransactionModifyingSigner);
1245
+ if (modifyingSigners.length === 0)
1246
+ return [];
1247
+ const nonPartialSigners = modifyingSigners.filter((signer) => !isTransactionPartialSigner(signer));
1248
+ if (nonPartialSigners.length > 0)
1249
+ return nonPartialSigners;
1250
+ return [modifyingSigners[0]];
1251
+ }
1252
+ async function signModifyingAndPartialTransactionSigners(transaction, modifyingSigners = [], partialSigners = [], abortSignal) {
1253
+ var _a;
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
+ );
1262
+ abortSignal == null ? void 0 : abortSignal.throwIfAborted();
1263
+ const signatureDictionaries = await Promise.all(
1264
+ partialSigners.map(async (partialSigner) => {
1265
+ const [signatures] = await partialSigner.signTransactions([modifiedTransaction], { abortSignal });
1266
+ return signatures;
1267
+ })
1268
+ );
1269
+ const signedTransaction = {
1270
+ ...modifiedTransaction,
1271
+ signatures: Object.freeze(
1272
+ signatureDictionaries.reduce((signatures, signatureDictionary) => {
1273
+ return { ...signatures, ...signatureDictionary };
1274
+ }, (_a = modifiedTransaction.signatures) != null ? _a : {})
1275
+ )
1276
+ };
1277
+ return Object.freeze(signedTransaction);
1278
+ }
1279
+ var o2 = globalThis.TextEncoder;
1280
+
1281
+ // src/signable-message.ts
1282
+ function createSignableMessage(content, signatures = {}) {
1283
+ return Object.freeze({
1284
+ content: typeof content === "string" ? new o2().encode(content) : content,
1285
+ signatures: Object.freeze({ ...signatures })
1286
+ });
1287
+ }
1288
+
1289
+ // src/transaction-with-single-sending-signer.ts
1290
+ function isTransactionWithSingleSendingSigner(transaction) {
1291
+ try {
1292
+ assertIsTransactionWithSingleSendingSigner(transaction);
1293
+ return true;
1294
+ } catch {
1295
+ return false;
1296
+ }
1297
+ }
1298
+ function assertIsTransactionWithSingleSendingSigner(transaction) {
1299
+ const signers = getSignersFromTransaction(transaction);
1300
+ const sendingSigners = signers.filter(isTransactionSendingSigner);
1301
+ if (sendingSigners.length === 0) {
1302
+ const error = new Error("No `TransactionSendingSigner` was identified.");
1303
+ error.name = "MissingTransactionSendingSignerError";
1304
+ throw error;
1305
+ }
1306
+ const sendingOnlySigners = sendingSigners.filter(
1307
+ (signer) => !isTransactionPartialSigner(signer) && !isTransactionModifyingSigner(signer)
1308
+ );
1309
+ if (sendingOnlySigners.length > 1) {
1310
+ const error = new Error("More than one `TransactionSendingSigner` was identified.");
1311
+ error.name = "MultipleTransactionSendingSignersError";
1312
+ throw error;
1313
+ }
1314
+ }
1315
+
1316
+ exports.addSignersToInstruction = addSignersToInstruction;
1317
+ exports.addSignersToTransaction = addSignersToTransaction;
1176
1318
  exports.assertIsKeyPairSigner = assertIsKeyPairSigner;
1177
1319
  exports.assertIsMessageModifyingSigner = assertIsMessageModifyingSigner;
1178
1320
  exports.assertIsMessagePartialSigner = assertIsMessagePartialSigner;
@@ -1181,9 +1323,13 @@ this.globalThis.solanaWeb3 = (function (exports) {
1181
1323
  exports.assertIsTransactionPartialSigner = assertIsTransactionPartialSigner;
1182
1324
  exports.assertIsTransactionSendingSigner = assertIsTransactionSendingSigner;
1183
1325
  exports.assertIsTransactionSigner = assertIsTransactionSigner;
1326
+ exports.assertIsTransactionWithSingleSendingSigner = assertIsTransactionWithSingleSendingSigner;
1327
+ exports.createNoopSigner = createNoopSigner;
1184
1328
  exports.createSignableMessage = createSignableMessage;
1185
1329
  exports.createSignerFromKeyPair = createSignerFromKeyPair;
1186
1330
  exports.generateKeyPairSigner = generateKeyPairSigner;
1331
+ exports.getSignersFromInstruction = getSignersFromInstruction;
1332
+ exports.getSignersFromTransaction = getSignersFromTransaction;
1187
1333
  exports.isKeyPairSigner = isKeyPairSigner;
1188
1334
  exports.isMessageModifyingSigner = isMessageModifyingSigner;
1189
1335
  exports.isMessagePartialSigner = isMessagePartialSigner;
@@ -1192,6 +1338,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
1192
1338
  exports.isTransactionPartialSigner = isTransactionPartialSigner;
1193
1339
  exports.isTransactionSendingSigner = isTransactionSendingSigner;
1194
1340
  exports.isTransactionSigner = isTransactionSigner;
1341
+ exports.isTransactionWithSingleSendingSigner = isTransactionWithSingleSendingSigner;
1342
+ exports.partiallySignTransactionWithSigners = partiallySignTransactionWithSigners;
1343
+ exports.signAndSendTransactionWithSigners = signAndSendTransactionWithSigners;
1344
+ exports.signTransactionWithSigners = signTransactionWithSigners;
1195
1345
 
1196
1346
  return exports;
1197
1347