@solana/transactions 2.0.0-experimental.10bfcd8 → 2.0.0-experimental.13ef878

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 (55) hide show
  1. package/README.md +1 -43
  2. package/dist/index.browser.cjs +17 -47
  3. package/dist/index.browser.cjs.map +1 -1
  4. package/dist/index.browser.js +17 -45
  5. package/dist/index.browser.js.map +1 -1
  6. package/dist/index.development.js +377 -480
  7. package/dist/index.development.js.map +1 -1
  8. package/dist/index.native.js +17 -45
  9. package/dist/index.native.js.map +1 -1
  10. package/dist/index.node.cjs +17 -47
  11. package/dist/index.node.cjs.map +1 -1
  12. package/dist/index.node.js +19 -45
  13. package/dist/index.node.js.map +1 -1
  14. package/dist/index.production.min.js +18 -20
  15. package/dist/types/accounts.d.ts +2 -2
  16. package/dist/types/accounts.d.ts.map +1 -0
  17. package/dist/types/blockhash.d.ts.map +1 -0
  18. package/dist/types/compilable-transaction.d.ts +7 -0
  19. package/dist/types/compilable-transaction.d.ts.map +1 -0
  20. package/dist/types/compile-address-table-lookups.d.ts +2 -2
  21. package/dist/types/compile-address-table-lookups.d.ts.map +1 -0
  22. package/dist/types/compile-header.d.ts.map +1 -0
  23. package/dist/types/compile-instructions.d.ts.map +1 -0
  24. package/dist/types/compile-lifetime-token.d.ts.map +1 -0
  25. package/dist/types/compile-static-accounts.d.ts +2 -2
  26. package/dist/types/compile-static-accounts.d.ts.map +1 -0
  27. package/dist/types/compile-transaction.d.ts +5 -6
  28. package/dist/types/compile-transaction.d.ts.map +1 -0
  29. package/dist/types/create-transaction.d.ts.map +1 -0
  30. package/dist/types/decompile-transaction.d.ts +2 -4
  31. package/dist/types/decompile-transaction.d.ts.map +1 -0
  32. package/dist/types/durable-nonce.d.ts +3 -3
  33. package/dist/types/durable-nonce.d.ts.map +1 -0
  34. package/dist/types/fee-payer.d.ts +4 -4
  35. package/dist/types/fee-payer.d.ts.map +1 -0
  36. package/dist/types/index.d.ts +1 -0
  37. package/dist/types/index.d.ts.map +1 -0
  38. package/dist/types/instructions.d.ts.map +1 -0
  39. package/dist/types/message.d.ts +1 -5
  40. package/dist/types/message.d.ts.map +1 -0
  41. package/dist/types/serializers/address-table-lookup.d.ts.map +1 -0
  42. package/dist/types/serializers/header.d.ts.map +1 -0
  43. package/dist/types/serializers/index.d.ts.map +1 -0
  44. package/dist/types/serializers/instruction.d.ts.map +1 -0
  45. package/dist/types/serializers/message.d.ts.map +1 -0
  46. package/dist/types/serializers/transaction-version.d.ts.map +1 -0
  47. package/dist/types/serializers/transaction.d.ts +1 -3
  48. package/dist/types/serializers/transaction.d.ts.map +1 -0
  49. package/dist/types/signatures.d.ts +8 -13
  50. package/dist/types/signatures.d.ts.map +1 -0
  51. package/dist/types/types.d.ts +6 -13
  52. package/dist/types/types.d.ts.map +1 -0
  53. package/dist/types/unsigned-transaction.d.ts.map +1 -0
  54. package/dist/types/wire-transaction.d.ts.map +1 -0
  55. package/package.json +9 -10
@@ -2,39 +2,257 @@ this.globalThis = this.globalThis || {};
2
2
  this.globalThis.solanaWeb3 = (function (exports) {
3
3
  'use strict';
4
4
 
5
- var __defProp = Object.defineProperty;
6
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
- var __publicField = (obj, key, value) => {
8
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
9
- return value;
5
+ // ../codecs-core/dist/index.browser.js
6
+ function assertByteArrayIsNotEmptyForCodec(codecDescription, bytes, offset = 0) {
7
+ if (bytes.length - offset <= 0) {
8
+ throw new Error(`Codec [${codecDescription}] cannot decode empty byte arrays.`);
9
+ }
10
+ }
11
+ function assertByteArrayHasEnoughBytesForCodec(codecDescription, expected, bytes, offset = 0) {
12
+ const bytesLength = bytes.length - offset;
13
+ if (bytesLength < expected) {
14
+ throw new Error(`Codec [${codecDescription}] expected ${expected} bytes, got ${bytesLength}.`);
15
+ }
16
+ }
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
+ var padBytes = (bytes, length) => {
35
+ if (bytes.length >= length)
36
+ return bytes;
37
+ const paddedBytes = new Uint8Array(length).fill(0);
38
+ paddedBytes.set(bytes);
39
+ return paddedBytes;
10
40
  };
41
+ var fixBytes = (bytes, length) => padBytes(bytes.length <= length ? bytes : bytes.slice(0, length), length);
42
+ function combineCodec(encoder, decoder, description) {
43
+ if (encoder.fixedSize !== decoder.fixedSize) {
44
+ throw new Error(
45
+ `Encoder and decoder must have the same fixed size, got [${encoder.fixedSize}] and [${decoder.fixedSize}].`
46
+ );
47
+ }
48
+ if (encoder.maxSize !== decoder.maxSize) {
49
+ throw new Error(
50
+ `Encoder and decoder must have the same max size, got [${encoder.maxSize}] and [${decoder.maxSize}].`
51
+ );
52
+ }
53
+ if (description === void 0 && encoder.description !== decoder.description) {
54
+ throw new Error(
55
+ `Encoder and decoder must have the same description, got [${encoder.description}] and [${decoder.description}]. Pass a custom description as a third argument if you want to override the description and bypass this error.`
56
+ );
57
+ }
58
+ return {
59
+ decode: decoder.decode,
60
+ description: description ?? encoder.description,
61
+ encode: encoder.encode,
62
+ fixedSize: encoder.fixedSize,
63
+ maxSize: encoder.maxSize
64
+ };
65
+ }
66
+ function fixCodecHelper(data, fixedBytes, description) {
67
+ return {
68
+ description: description ?? `fixed(${fixedBytes}, ${data.description})`,
69
+ fixedSize: fixedBytes,
70
+ maxSize: fixedBytes
71
+ };
72
+ }
73
+ function fixEncoder(encoder, fixedBytes, description) {
74
+ return {
75
+ ...fixCodecHelper(encoder, fixedBytes, description),
76
+ encode: (value) => fixBytes(encoder.encode(value), fixedBytes)
77
+ };
78
+ }
79
+ function fixDecoder(decoder, fixedBytes, description) {
80
+ return {
81
+ ...fixCodecHelper(decoder, fixedBytes, description),
82
+ decode: (bytes, offset = 0) => {
83
+ assertByteArrayHasEnoughBytesForCodec("fixCodec", fixedBytes, bytes, offset);
84
+ if (offset > 0 || bytes.length > fixedBytes) {
85
+ bytes = bytes.slice(offset, offset + fixedBytes);
86
+ }
87
+ if (decoder.fixedSize !== null) {
88
+ bytes = fixBytes(bytes, decoder.fixedSize);
89
+ }
90
+ const [value] = decoder.decode(bytes, 0);
91
+ return [value, offset + fixedBytes];
92
+ }
93
+ };
94
+ }
95
+ function mapEncoder(encoder, unmap) {
96
+ return {
97
+ description: encoder.description,
98
+ encode: (value) => encoder.encode(unmap(value)),
99
+ fixedSize: encoder.fixedSize,
100
+ maxSize: encoder.maxSize
101
+ };
102
+ }
103
+ function mapDecoder(decoder, map) {
104
+ return {
105
+ decode: (bytes, offset = 0) => {
106
+ const [value, length] = decoder.decode(bytes, offset);
107
+ return [map(value, bytes, offset), length];
108
+ },
109
+ description: decoder.description,
110
+ fixedSize: decoder.fixedSize,
111
+ maxSize: decoder.maxSize
112
+ };
113
+ }
11
114
 
12
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/errors.mjs
13
- var InvalidBaseStringError = class extends Error {
14
- constructor(value, base, cause) {
15
- const message = `Expected a string of base ${base}, got [${value}].`;
16
- super(message);
17
- __publicField(this, "name", "InvalidBaseStringError");
18
- this.cause = cause;
115
+ // ../codecs-numbers/dist/index.browser.js
116
+ function assertNumberIsBetweenForCodec(codecDescription, min, max, value) {
117
+ if (value < min || value > max) {
118
+ throw new Error(
119
+ `Codec [${codecDescription}] expected number to be in the range [${min}, ${max}], got ${value}.`
120
+ );
19
121
  }
20
- };
122
+ }
123
+ function sharedNumberFactory(input) {
124
+ let littleEndian;
125
+ let defaultDescription = input.name;
126
+ if (input.size > 1) {
127
+ littleEndian = !("endian" in input.options) || input.options.endian === 0;
128
+ defaultDescription += littleEndian ? "(le)" : "(be)";
129
+ }
130
+ return {
131
+ description: input.options.description ?? defaultDescription,
132
+ fixedSize: input.size,
133
+ littleEndian,
134
+ maxSize: input.size
135
+ };
136
+ }
137
+ function numberEncoderFactory(input) {
138
+ const codecData = sharedNumberFactory(input);
139
+ return {
140
+ description: codecData.description,
141
+ encode(value) {
142
+ if (input.range) {
143
+ assertNumberIsBetweenForCodec(input.name, input.range[0], input.range[1], value);
144
+ }
145
+ const arrayBuffer = new ArrayBuffer(input.size);
146
+ input.set(new DataView(arrayBuffer), value, codecData.littleEndian);
147
+ return new Uint8Array(arrayBuffer);
148
+ },
149
+ fixedSize: codecData.fixedSize,
150
+ maxSize: codecData.maxSize
151
+ };
152
+ }
153
+ function numberDecoderFactory(input) {
154
+ const codecData = sharedNumberFactory(input);
155
+ return {
156
+ decode(bytes, offset = 0) {
157
+ assertByteArrayIsNotEmptyForCodec(codecData.description, bytes, offset);
158
+ assertByteArrayHasEnoughBytesForCodec(codecData.description, input.size, bytes, offset);
159
+ const view = new DataView(toArrayBuffer(bytes, offset, input.size));
160
+ return [input.get(view, codecData.littleEndian), offset + input.size];
161
+ },
162
+ description: codecData.description,
163
+ fixedSize: codecData.fixedSize,
164
+ maxSize: codecData.maxSize
165
+ };
166
+ }
167
+ function toArrayBuffer(bytes, offset, length) {
168
+ const bytesOffset = bytes.byteOffset + (offset ?? 0);
169
+ const bytesLength = length ?? bytes.byteLength;
170
+ return bytes.buffer.slice(bytesOffset, bytesOffset + bytesLength);
171
+ }
172
+ var getShortU16Encoder = (options = {}) => ({
173
+ description: options.description ?? "shortU16",
174
+ encode: (value) => {
175
+ assertNumberIsBetweenForCodec("shortU16", 0, 65535, value);
176
+ const bytes = [0];
177
+ for (let ii = 0; ; ii += 1) {
178
+ const alignedValue = value >> ii * 7;
179
+ if (alignedValue === 0) {
180
+ break;
181
+ }
182
+ const nextSevenBits = 127 & alignedValue;
183
+ bytes[ii] = nextSevenBits;
184
+ if (ii > 0) {
185
+ bytes[ii - 1] |= 128;
186
+ }
187
+ }
188
+ return new Uint8Array(bytes);
189
+ },
190
+ fixedSize: null,
191
+ maxSize: 3
192
+ });
193
+ var getShortU16Decoder = (options = {}) => ({
194
+ decode: (bytes, offset = 0) => {
195
+ let value = 0;
196
+ let byteCount = 0;
197
+ while (++byteCount) {
198
+ const byteIndex = byteCount - 1;
199
+ const currentByte = bytes[offset + byteIndex];
200
+ const nextSevenBits = 127 & currentByte;
201
+ value |= nextSevenBits << byteIndex * 7;
202
+ if ((currentByte & 128) === 0) {
203
+ break;
204
+ }
205
+ }
206
+ return [value, offset + byteCount];
207
+ },
208
+ description: options.description ?? "shortU16",
209
+ fixedSize: null,
210
+ maxSize: 3
211
+ });
212
+ var getU32Encoder = (options = {}) => numberEncoderFactory({
213
+ name: "u32",
214
+ options,
215
+ range: [0, Number("0xffffffff")],
216
+ set: (view, value, le) => view.setUint32(0, value, le),
217
+ size: 4
218
+ });
219
+ var getU32Decoder = (options = {}) => numberDecoderFactory({
220
+ get: (view, le) => view.getUint32(0, le),
221
+ name: "u32",
222
+ options,
223
+ size: 4
224
+ });
225
+ var getU8Encoder = (options = {}) => numberEncoderFactory({
226
+ name: "u8",
227
+ options,
228
+ range: [0, Number("0xff")],
229
+ set: (view, value) => view.setUint8(0, value),
230
+ size: 1
231
+ });
232
+ var getU8Decoder = (options = {}) => numberDecoderFactory({
233
+ get: (view) => view.getUint8(0),
234
+ name: "u8",
235
+ options,
236
+ size: 1
237
+ });
21
238
 
22
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseX.mjs
23
- var baseX = (alphabet) => {
24
- const base = alphabet.length;
239
+ // ../codecs-strings/dist/index.browser.js
240
+ function assertValidBaseString(alphabet4, testValue, givenValue = testValue) {
241
+ if (!testValue.match(new RegExp(`^[${alphabet4}]*$`))) {
242
+ throw new Error(`Expected a string of base ${alphabet4.length}, got [${givenValue}].`);
243
+ }
244
+ }
245
+ var getBaseXEncoder = (alphabet4) => {
246
+ const base = alphabet4.length;
25
247
  const baseBigInt = BigInt(base);
26
248
  return {
27
249
  description: `base${base}`,
28
- fixedSize: null,
29
- maxSize: null,
30
- serialize(value) {
31
- if (!value.match(new RegExp(`^[${alphabet}]*$`))) {
32
- throw new InvalidBaseStringError(value, base);
33
- }
250
+ encode(value) {
251
+ assertValidBaseString(alphabet4, value);
34
252
  if (value === "")
35
253
  return new Uint8Array();
36
254
  const chars = [...value];
37
- let trailIndex = chars.findIndex((c) => c !== alphabet[0]);
255
+ let trailIndex = chars.findIndex((c) => c !== alphabet4[0]);
38
256
  trailIndex = trailIndex === -1 ? chars.length : trailIndex;
39
257
  const leadingZeroes = Array(trailIndex).fill(0);
40
258
  if (trailIndex === chars.length)
@@ -43,7 +261,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
43
261
  let base10Number = 0n;
44
262
  let baseXPower = 1n;
45
263
  for (let i = tailChars.length - 1; i >= 0; i -= 1) {
46
- base10Number += baseXPower * BigInt(alphabet.indexOf(tailChars[i]));
264
+ base10Number += baseXPower * BigInt(alphabet4.indexOf(tailChars[i]));
47
265
  baseXPower *= baseBigInt;
48
266
  }
49
267
  const tailBytes = [];
@@ -53,28 +271,117 @@ this.globalThis.solanaWeb3 = (function (exports) {
53
271
  }
54
272
  return Uint8Array.from(leadingZeroes.concat(tailBytes));
55
273
  },
56
- deserialize(buffer, offset = 0) {
57
- if (buffer.length === 0)
274
+ fixedSize: null,
275
+ maxSize: null
276
+ };
277
+ };
278
+ var getBaseXDecoder = (alphabet4) => {
279
+ const base = alphabet4.length;
280
+ const baseBigInt = BigInt(base);
281
+ return {
282
+ decode(rawBytes, offset = 0) {
283
+ const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);
284
+ if (bytes.length === 0)
58
285
  return ["", 0];
59
- const bytes = buffer.slice(offset);
60
286
  let trailIndex = bytes.findIndex((n) => n !== 0);
61
287
  trailIndex = trailIndex === -1 ? bytes.length : trailIndex;
62
- const leadingZeroes = alphabet[0].repeat(trailIndex);
288
+ const leadingZeroes = alphabet4[0].repeat(trailIndex);
63
289
  if (trailIndex === bytes.length)
64
- return [leadingZeroes, buffer.length];
290
+ return [leadingZeroes, rawBytes.length];
65
291
  let base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
66
292
  const tailChars = [];
67
293
  while (base10Number > 0n) {
68
- tailChars.unshift(alphabet[Number(base10Number % baseBigInt)]);
294
+ tailChars.unshift(alphabet4[Number(base10Number % baseBigInt)]);
69
295
  base10Number /= baseBigInt;
70
296
  }
71
- return [leadingZeroes + tailChars.join(""), buffer.length];
72
- }
297
+ return [leadingZeroes + tailChars.join(""), rawBytes.length];
298
+ },
299
+ description: `base${base}`,
300
+ fixedSize: null,
301
+ maxSize: null
73
302
  };
74
303
  };
75
-
76
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/base58.mjs
77
- var base58 = baseX("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
304
+ var alphabet2 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
305
+ var getBase58Encoder = () => getBaseXEncoder(alphabet2);
306
+ var getBase58Decoder = () => getBaseXDecoder(alphabet2);
307
+ var removeNullCharacters = (value) => (
308
+ // eslint-disable-next-line no-control-regex
309
+ value.replace(/\u0000/g, "")
310
+ );
311
+ var e = globalThis.TextDecoder;
312
+ var o = globalThis.TextEncoder;
313
+ var getUtf8Encoder = () => {
314
+ let textEncoder;
315
+ return {
316
+ description: "utf8",
317
+ encode: (value) => new Uint8Array((textEncoder || (textEncoder = new o())).encode(value)),
318
+ fixedSize: null,
319
+ maxSize: null
320
+ };
321
+ };
322
+ var getUtf8Decoder = () => {
323
+ let textDecoder;
324
+ return {
325
+ decode(bytes, offset = 0) {
326
+ const value = (textDecoder || (textDecoder = new e())).decode(bytes.slice(offset));
327
+ return [removeNullCharacters(value), bytes.length];
328
+ },
329
+ description: "utf8",
330
+ fixedSize: null,
331
+ maxSize: null
332
+ };
333
+ };
334
+ var getStringEncoder = (options = {}) => {
335
+ const size = options.size ?? getU32Encoder();
336
+ const encoding = options.encoding ?? getUtf8Encoder();
337
+ const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
338
+ if (size === "variable") {
339
+ return { ...encoding, description };
340
+ }
341
+ if (typeof size === "number") {
342
+ return fixEncoder(encoding, size, description);
343
+ }
344
+ return {
345
+ description,
346
+ encode: (value) => {
347
+ const contentBytes = encoding.encode(value);
348
+ const lengthBytes = size.encode(contentBytes.length);
349
+ return mergeBytes([lengthBytes, contentBytes]);
350
+ },
351
+ fixedSize: null,
352
+ maxSize: null
353
+ };
354
+ };
355
+ var getStringDecoder = (options = {}) => {
356
+ const size = options.size ?? getU32Decoder();
357
+ const encoding = options.encoding ?? getUtf8Decoder();
358
+ const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
359
+ if (size === "variable") {
360
+ return { ...encoding, description };
361
+ }
362
+ if (typeof size === "number") {
363
+ return fixDecoder(encoding, size, description);
364
+ }
365
+ return {
366
+ decode: (bytes, offset = 0) => {
367
+ assertByteArrayIsNotEmptyForCodec("string", bytes, offset);
368
+ const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);
369
+ const length = Number(lengthBigInt);
370
+ offset = lengthOffset;
371
+ const contentBytes = bytes.slice(offset, offset + length);
372
+ assertByteArrayHasEnoughBytesForCodec("string", length, contentBytes);
373
+ const [value, contentOffset] = encoding.decode(contentBytes);
374
+ offset += contentOffset;
375
+ return [value, offset];
376
+ },
377
+ description,
378
+ fixedSize: null,
379
+ maxSize: null
380
+ };
381
+ };
382
+ function getSizeDescription(size) {
383
+ return typeof size === "object" ? size.description : `${size}`;
384
+ }
78
385
 
79
386
  // src/unsigned-transaction.ts
80
387
  function getUnsignedTransaction(transaction) {
@@ -91,7 +398,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
91
398
  }
92
399
 
93
400
  // src/blockhash.ts
401
+ var base58Encoder;
94
402
  function assertIsBlockhash(putativeBlockhash) {
403
+ if (!base58Encoder)
404
+ base58Encoder = getBase58Encoder();
95
405
  try {
96
406
  if (
97
407
  // Lowest value (32 bytes of zeroes)
@@ -100,7 +410,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
100
410
  ) {
101
411
  throw new Error("Expected input string to decode to a byte array of length 32.");
102
412
  }
103
- const bytes = base58.serialize(putativeBlockhash);
413
+ const bytes = base58Encoder.encode(putativeBlockhash);
104
414
  const numBytes = bytes.byteLength;
105
415
  if (numBytes !== 32) {
106
416
  throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
@@ -253,251 +563,17 @@ this.globalThis.solanaWeb3 = (function (exports) {
253
563
  ...getUnsignedTransaction(transaction),
254
564
  instructions: [...transaction.instructions, instruction]
255
565
  };
256
- Object.freeze(out);
257
- return out;
258
- }
259
- function prependTransactionInstruction(instruction, transaction) {
260
- const out = {
261
- ...getUnsignedTransaction(transaction),
262
- instructions: [instruction, ...transaction.instructions]
263
- };
264
- Object.freeze(out);
265
- return out;
266
- }
267
-
268
- // ../codecs-core/dist/index.browser.js
269
- function assertByteArrayIsNotEmptyForCodec(codecDescription, bytes, offset = 0) {
270
- if (bytes.length - offset <= 0) {
271
- throw new Error(`Codec [${codecDescription}] cannot decode empty byte arrays.`);
272
- }
273
- }
274
- function assertByteArrayHasEnoughBytesForCodec(codecDescription, expected, bytes, offset = 0) {
275
- const bytesLength = bytes.length - offset;
276
- if (bytesLength < expected) {
277
- throw new Error(`Codec [${codecDescription}] expected ${expected} bytes, got ${bytesLength}.`);
278
- }
279
- }
280
- var mergeBytes = (byteArrays) => {
281
- const nonEmptyByteArrays = byteArrays.filter((arr) => arr.length);
282
- if (nonEmptyByteArrays.length === 0) {
283
- return byteArrays.length ? byteArrays[0] : new Uint8Array();
284
- }
285
- if (nonEmptyByteArrays.length === 1) {
286
- return nonEmptyByteArrays[0];
287
- }
288
- const totalLength = nonEmptyByteArrays.reduce((total, arr) => total + arr.length, 0);
289
- const result = new Uint8Array(totalLength);
290
- let offset = 0;
291
- nonEmptyByteArrays.forEach((arr) => {
292
- result.set(arr, offset);
293
- offset += arr.length;
294
- });
295
- return result;
296
- };
297
- var padBytes = (bytes, length) => {
298
- if (bytes.length >= length)
299
- return bytes;
300
- const paddedBytes = new Uint8Array(length).fill(0);
301
- paddedBytes.set(bytes);
302
- return paddedBytes;
303
- };
304
- var fixBytes = (bytes, length) => padBytes(bytes.length <= length ? bytes : bytes.slice(0, length), length);
305
- function combineCodec(encoder, decoder, description) {
306
- if (encoder.fixedSize !== decoder.fixedSize) {
307
- throw new Error(
308
- `Encoder and decoder must have the same fixed size, got [${encoder.fixedSize}] and [${decoder.fixedSize}].`
309
- );
310
- }
311
- if (encoder.maxSize !== decoder.maxSize) {
312
- throw new Error(
313
- `Encoder and decoder must have the same max size, got [${encoder.maxSize}] and [${decoder.maxSize}].`
314
- );
315
- }
316
- if (description === void 0 && encoder.description !== decoder.description) {
317
- throw new Error(
318
- `Encoder and decoder must have the same description, got [${encoder.description}] and [${decoder.description}]. Pass a custom description as a third argument if you want to override the description and bypass this error.`
319
- );
320
- }
321
- return {
322
- decode: decoder.decode,
323
- description: description ?? encoder.description,
324
- encode: encoder.encode,
325
- fixedSize: encoder.fixedSize,
326
- maxSize: encoder.maxSize
327
- };
328
- }
329
- function fixCodecHelper(data, fixedBytes, description) {
330
- return {
331
- description: description ?? `fixed(${fixedBytes}, ${data.description})`,
332
- fixedSize: fixedBytes,
333
- maxSize: fixedBytes
334
- };
335
- }
336
- function fixEncoder(encoder, fixedBytes, description) {
337
- return {
338
- ...fixCodecHelper(encoder, fixedBytes, description),
339
- encode: (value) => fixBytes(encoder.encode(value), fixedBytes)
340
- };
341
- }
342
- function fixDecoder(decoder, fixedBytes, description) {
343
- return {
344
- ...fixCodecHelper(decoder, fixedBytes, description),
345
- decode: (bytes, offset = 0) => {
346
- assertByteArrayHasEnoughBytesForCodec("fixCodec", fixedBytes, bytes, offset);
347
- if (offset > 0 || bytes.length > fixedBytes) {
348
- bytes = bytes.slice(offset, offset + fixedBytes);
349
- }
350
- if (decoder.fixedSize !== null) {
351
- bytes = fixBytes(bytes, decoder.fixedSize);
352
- }
353
- const [value] = decoder.decode(bytes, 0);
354
- return [value, offset + fixedBytes];
355
- }
356
- };
357
- }
358
- function mapEncoder(encoder, unmap) {
359
- return {
360
- description: encoder.description,
361
- encode: (value) => encoder.encode(unmap(value)),
362
- fixedSize: encoder.fixedSize,
363
- maxSize: encoder.maxSize
364
- };
365
- }
366
- function mapDecoder(decoder, map) {
367
- return {
368
- decode: (bytes, offset = 0) => {
369
- const [value, length] = decoder.decode(bytes, offset);
370
- return [map(value, bytes, offset), length];
371
- },
372
- description: decoder.description,
373
- fixedSize: decoder.fixedSize,
374
- maxSize: decoder.maxSize
375
- };
376
- }
377
-
378
- // ../codecs-numbers/dist/index.browser.js
379
- function assertNumberIsBetweenForCodec(codecDescription, min, max, value) {
380
- if (value < min || value > max) {
381
- throw new Error(
382
- `Codec [${codecDescription}] expected number to be in the range [${min}, ${max}], got ${value}.`
383
- );
384
- }
385
- }
386
- function sharedNumberFactory(input) {
387
- let littleEndian;
388
- let defaultDescription = input.name;
389
- if (input.size > 1) {
390
- littleEndian = !("endian" in input.options) || input.options.endian === 0;
391
- defaultDescription += littleEndian ? "(le)" : "(be)";
392
- }
393
- return {
394
- description: input.options.description ?? defaultDescription,
395
- fixedSize: input.size,
396
- littleEndian,
397
- maxSize: input.size
398
- };
399
- }
400
- function numberEncoderFactory(input) {
401
- const codecData = sharedNumberFactory(input);
402
- return {
403
- description: codecData.description,
404
- encode(value) {
405
- if (input.range) {
406
- assertNumberIsBetweenForCodec(input.name, input.range[0], input.range[1], value);
407
- }
408
- const arrayBuffer = new ArrayBuffer(input.size);
409
- input.set(new DataView(arrayBuffer), value, codecData.littleEndian);
410
- return new Uint8Array(arrayBuffer);
411
- },
412
- fixedSize: codecData.fixedSize,
413
- maxSize: codecData.maxSize
414
- };
566
+ Object.freeze(out);
567
+ return out;
415
568
  }
416
- function numberDecoderFactory(input) {
417
- const codecData = sharedNumberFactory(input);
418
- return {
419
- decode(bytes, offset = 0) {
420
- assertByteArrayIsNotEmptyForCodec(codecData.description, bytes, offset);
421
- assertByteArrayHasEnoughBytesForCodec(codecData.description, input.size, bytes, offset);
422
- const view = new DataView(toArrayBuffer(bytes, offset, input.size));
423
- return [input.get(view, codecData.littleEndian), offset + input.size];
424
- },
425
- description: codecData.description,
426
- fixedSize: codecData.fixedSize,
427
- maxSize: codecData.maxSize
569
+ function prependTransactionInstruction(instruction, transaction) {
570
+ const out = {
571
+ ...getUnsignedTransaction(transaction),
572
+ instructions: [instruction, ...transaction.instructions]
428
573
  };
574
+ Object.freeze(out);
575
+ return out;
429
576
  }
430
- function toArrayBuffer(bytes, offset, length) {
431
- const bytesOffset = bytes.byteOffset + (offset ?? 0);
432
- const bytesLength = length ?? bytes.byteLength;
433
- return bytes.buffer.slice(bytesOffset, bytesOffset + bytesLength);
434
- }
435
- var getShortU16Encoder = (options = {}) => ({
436
- description: options.description ?? "shortU16",
437
- encode: (value) => {
438
- assertNumberIsBetweenForCodec("shortU16", 0, 65535, value);
439
- const bytes = [0];
440
- for (let ii = 0; ; ii += 1) {
441
- const alignedValue = value >> ii * 7;
442
- if (alignedValue === 0) {
443
- break;
444
- }
445
- const nextSevenBits = 127 & alignedValue;
446
- bytes[ii] = nextSevenBits;
447
- if (ii > 0) {
448
- bytes[ii - 1] |= 128;
449
- }
450
- }
451
- return new Uint8Array(bytes);
452
- },
453
- fixedSize: null,
454
- maxSize: 3
455
- });
456
- var getShortU16Decoder = (options = {}) => ({
457
- decode: (bytes, offset = 0) => {
458
- let value = 0;
459
- let byteCount = 0;
460
- while (++byteCount) {
461
- const byteIndex = byteCount - 1;
462
- const currentByte = bytes[offset + byteIndex];
463
- const nextSevenBits = 127 & currentByte;
464
- value |= nextSevenBits << byteIndex * 7;
465
- if ((currentByte & 128) === 0) {
466
- break;
467
- }
468
- }
469
- return [value, offset + byteCount];
470
- },
471
- description: options.description ?? "shortU16",
472
- fixedSize: null,
473
- maxSize: 3
474
- });
475
- var getU32Encoder = (options = {}) => numberEncoderFactory({
476
- name: "u32",
477
- options,
478
- range: [0, Number("0xffffffff")],
479
- set: (view, value, le) => view.setUint32(0, value, le),
480
- size: 4
481
- });
482
- var getU32Decoder = (options = {}) => numberDecoderFactory({
483
- get: (view, le) => view.getUint32(0, le),
484
- name: "u32",
485
- options,
486
- size: 4
487
- });
488
- var getU8Encoder = (options = {}) => numberEncoderFactory({
489
- name: "u8",
490
- options,
491
- range: [0, Number("0xff")],
492
- set: (view, value) => view.setUint8(0, value),
493
- size: 1
494
- });
495
- var getU8Decoder = (options = {}) => numberDecoderFactory({
496
- get: (view) => view.getUint8(0),
497
- name: "u8",
498
- options,
499
- size: 1
500
- });
501
577
 
502
578
  // ../codecs-data-structures/dist/index.browser.js
503
579
  function sumCodecSizes(sizes) {
@@ -677,153 +753,6 @@ this.globalThis.solanaWeb3 = (function (exports) {
677
753
  };
678
754
  }
679
755
 
680
- // ../codecs-strings/dist/index.browser.js
681
- function assertValidBaseString(alphabet4, testValue, givenValue = testValue) {
682
- if (!testValue.match(new RegExp(`^[${alphabet4}]*$`))) {
683
- throw new Error(`Expected a string of base ${alphabet4.length}, got [${givenValue}].`);
684
- }
685
- }
686
- var getBaseXEncoder = (alphabet4) => {
687
- const base = alphabet4.length;
688
- const baseBigInt = BigInt(base);
689
- return {
690
- description: `base${base}`,
691
- encode(value) {
692
- assertValidBaseString(alphabet4, value);
693
- if (value === "")
694
- return new Uint8Array();
695
- const chars = [...value];
696
- let trailIndex = chars.findIndex((c) => c !== alphabet4[0]);
697
- trailIndex = trailIndex === -1 ? chars.length : trailIndex;
698
- const leadingZeroes = Array(trailIndex).fill(0);
699
- if (trailIndex === chars.length)
700
- return Uint8Array.from(leadingZeroes);
701
- const tailChars = chars.slice(trailIndex);
702
- let base10Number = 0n;
703
- let baseXPower = 1n;
704
- for (let i = tailChars.length - 1; i >= 0; i -= 1) {
705
- base10Number += baseXPower * BigInt(alphabet4.indexOf(tailChars[i]));
706
- baseXPower *= baseBigInt;
707
- }
708
- const tailBytes = [];
709
- while (base10Number > 0n) {
710
- tailBytes.unshift(Number(base10Number % 256n));
711
- base10Number /= 256n;
712
- }
713
- return Uint8Array.from(leadingZeroes.concat(tailBytes));
714
- },
715
- fixedSize: null,
716
- maxSize: null
717
- };
718
- };
719
- var getBaseXDecoder = (alphabet4) => {
720
- const base = alphabet4.length;
721
- const baseBigInt = BigInt(base);
722
- return {
723
- decode(rawBytes, offset = 0) {
724
- const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);
725
- if (bytes.length === 0)
726
- return ["", 0];
727
- let trailIndex = bytes.findIndex((n) => n !== 0);
728
- trailIndex = trailIndex === -1 ? bytes.length : trailIndex;
729
- const leadingZeroes = alphabet4[0].repeat(trailIndex);
730
- if (trailIndex === bytes.length)
731
- return [leadingZeroes, rawBytes.length];
732
- let base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
733
- const tailChars = [];
734
- while (base10Number > 0n) {
735
- tailChars.unshift(alphabet4[Number(base10Number % baseBigInt)]);
736
- base10Number /= baseBigInt;
737
- }
738
- return [leadingZeroes + tailChars.join(""), rawBytes.length];
739
- },
740
- description: `base${base}`,
741
- fixedSize: null,
742
- maxSize: null
743
- };
744
- };
745
- var alphabet2 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
746
- var getBase58Encoder = () => getBaseXEncoder(alphabet2);
747
- var getBase58Decoder = () => getBaseXDecoder(alphabet2);
748
- var removeNullCharacters = (value) => (
749
- // eslint-disable-next-line no-control-regex
750
- value.replace(/\u0000/g, "")
751
- );
752
- var e = globalThis.TextDecoder;
753
- var o = globalThis.TextEncoder;
754
- var getUtf8Encoder = () => {
755
- let textEncoder;
756
- return {
757
- description: "utf8",
758
- encode: (value) => new Uint8Array((textEncoder || (textEncoder = new o())).encode(value)),
759
- fixedSize: null,
760
- maxSize: null
761
- };
762
- };
763
- var getUtf8Decoder = () => {
764
- let textDecoder;
765
- return {
766
- decode(bytes, offset = 0) {
767
- const value = (textDecoder || (textDecoder = new e())).decode(bytes.slice(offset));
768
- return [removeNullCharacters(value), bytes.length];
769
- },
770
- description: "utf8",
771
- fixedSize: null,
772
- maxSize: null
773
- };
774
- };
775
- var getStringEncoder = (options = {}) => {
776
- const size = options.size ?? getU32Encoder();
777
- const encoding = options.encoding ?? getUtf8Encoder();
778
- const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
779
- if (size === "variable") {
780
- return { ...encoding, description };
781
- }
782
- if (typeof size === "number") {
783
- return fixEncoder(encoding, size, description);
784
- }
785
- return {
786
- description,
787
- encode: (value) => {
788
- const contentBytes = encoding.encode(value);
789
- const lengthBytes = size.encode(contentBytes.length);
790
- return mergeBytes([lengthBytes, contentBytes]);
791
- },
792
- fixedSize: null,
793
- maxSize: null
794
- };
795
- };
796
- var getStringDecoder = (options = {}) => {
797
- const size = options.size ?? getU32Decoder();
798
- const encoding = options.encoding ?? getUtf8Decoder();
799
- const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
800
- if (size === "variable") {
801
- return { ...encoding, description };
802
- }
803
- if (typeof size === "number") {
804
- return fixDecoder(encoding, size, description);
805
- }
806
- return {
807
- decode: (bytes, offset = 0) => {
808
- assertByteArrayIsNotEmptyForCodec("string", bytes, offset);
809
- const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);
810
- const length = Number(lengthBigInt);
811
- offset = lengthOffset;
812
- const contentBytes = bytes.slice(offset, offset + length);
813
- assertByteArrayHasEnoughBytesForCodec("string", length, contentBytes);
814
- const [value, contentOffset] = encoding.decode(contentBytes);
815
- offset += contentOffset;
816
- return [value, offset];
817
- },
818
- description,
819
- fixedSize: null,
820
- maxSize: null
821
- };
822
- };
823
- function getSizeDescription(size) {
824
- return typeof size === "object" ? size.description : `${size}`;
825
- }
826
-
827
756
  // ../assertions/dist/index.browser.js
828
757
  function assertIsSecureContext() {
829
758
  if (!globalThis.isSecureContext) {
@@ -858,35 +787,35 @@ this.globalThis.solanaWeb3 = (function (exports) {
858
787
  memoizedBase58Decoder = getBase58Decoder();
859
788
  return memoizedBase58Decoder;
860
789
  }
861
- function assertIsAddress(putativeBase58EncodedAddress) {
790
+ function assertIsAddress(putativeAddress) {
862
791
  try {
863
792
  if (
864
793
  // Lowest address (32 bytes of zeroes)
865
- putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
866
- putativeBase58EncodedAddress.length > 44
794
+ putativeAddress.length < 32 || // Highest address (32 bytes of 255)
795
+ putativeAddress.length > 44
867
796
  ) {
868
797
  throw new Error("Expected input string to decode to a byte array of length 32.");
869
798
  }
870
- const base58Encoder = getMemoizedBase58Encoder();
871
- const bytes = base58Encoder.encode(putativeBase58EncodedAddress);
799
+ const base58Encoder2 = getMemoizedBase58Encoder();
800
+ const bytes = base58Encoder2.encode(putativeAddress);
872
801
  const numBytes = bytes.byteLength;
873
802
  if (numBytes !== 32) {
874
803
  throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
875
804
  }
876
805
  } catch (e2) {
877
- throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
806
+ throw new Error(`\`${putativeAddress}\` is not a base-58 encoded address`, {
878
807
  cause: e2
879
808
  });
880
809
  }
881
810
  }
882
- function address(putativeBase58EncodedAddress) {
883
- assertIsAddress(putativeBase58EncodedAddress);
884
- return putativeBase58EncodedAddress;
811
+ function address(putativeAddress) {
812
+ assertIsAddress(putativeAddress);
813
+ return putativeAddress;
885
814
  }
886
815
  function getAddressEncoder(config) {
887
816
  return mapEncoder(
888
817
  getStringEncoder({
889
- description: config?.description ?? "Base58EncodedAddress",
818
+ description: config?.description ?? "Address",
890
819
  encoding: getMemoizedBase58Encoder(),
891
820
  size: 32
892
821
  }),
@@ -895,7 +824,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
895
824
  }
896
825
  function getAddressDecoder(config) {
897
826
  return getStringDecoder({
898
- description: config?.description ?? "Base58EncodedAddress",
827
+ description: config?.description ?? "Address",
899
828
  encoding: getMemoizedBase58Decoder(),
900
829
  size: 32
901
830
  });
@@ -1728,52 +1657,20 @@ this.globalThis.solanaWeb3 = (function (exports) {
1728
1657
  }
1729
1658
 
1730
1659
  // src/signatures.ts
1731
- function assertIsTransactionSignature(putativeTransactionSignature) {
1732
- try {
1733
- if (
1734
- // Lowest value (64 bytes of zeroes)
1735
- putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
1736
- putativeTransactionSignature.length > 88
1737
- ) {
1738
- throw new Error("Expected input string to decode to a byte array of length 64.");
1739
- }
1740
- const bytes = base58.serialize(putativeTransactionSignature);
1741
- const numBytes = bytes.byteLength;
1742
- if (numBytes !== 64) {
1743
- throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
1744
- }
1745
- } catch (e2) {
1746
- throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
1747
- cause: e2
1748
- });
1749
- }
1750
- }
1751
- function isTransactionSignature(putativeTransactionSignature) {
1752
- if (
1753
- // Lowest value (64 bytes of zeroes)
1754
- putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
1755
- putativeTransactionSignature.length > 88
1756
- ) {
1757
- return false;
1758
- }
1759
- const bytes = base58.serialize(putativeTransactionSignature);
1760
- const numBytes = bytes.byteLength;
1761
- if (numBytes !== 64) {
1762
- return false;
1763
- }
1764
- return true;
1765
- }
1660
+ var base58Decoder;
1766
1661
  function getSignatureFromTransaction(transaction) {
1662
+ if (!base58Decoder)
1663
+ base58Decoder = getBase58Decoder();
1767
1664
  const signatureBytes = transaction.signatures[transaction.feePayer];
1768
1665
  if (!signatureBytes) {
1769
1666
  throw new Error(
1770
1667
  "Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
1771
1668
  );
1772
1669
  }
1773
- const transactionSignature2 = base58.deserialize(signatureBytes)[0];
1774
- return transactionSignature2;
1670
+ const transactionSignature = base58Decoder.decode(signatureBytes)[0];
1671
+ return transactionSignature;
1775
1672
  }
1776
- async function signTransaction(keyPairs, transaction) {
1673
+ async function partiallySignTransaction(keyPairs, transaction) {
1777
1674
  const compiledMessage = compileMessage(transaction);
1778
1675
  const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
1779
1676
  const wireMessageBytes = getCompiledMessageEncoder().encode(compiledMessage);
@@ -1792,9 +1689,11 @@ this.globalThis.solanaWeb3 = (function (exports) {
1792
1689
  Object.freeze(out);
1793
1690
  return out;
1794
1691
  }
1795
- function transactionSignature(putativeTransactionSignature) {
1796
- assertIsTransactionSignature(putativeTransactionSignature);
1797
- return putativeTransactionSignature;
1692
+ async function signTransaction(keyPairs, transaction) {
1693
+ const out = await partiallySignTransaction(keyPairs, transaction);
1694
+ assertTransactionIsFullySigned(out);
1695
+ Object.freeze(out);
1696
+ return out;
1798
1697
  }
1799
1698
  function assertTransactionIsFullySigned(transaction) {
1800
1699
  const signerAddressesFromInstructions = transaction.instructions.flatMap((i) => i.accounts?.filter((a) => isSignerRole(a.role)) ?? []).map((a) => a.address);
@@ -1817,7 +1716,6 @@ this.globalThis.solanaWeb3 = (function (exports) {
1817
1716
  exports.appendTransactionInstruction = appendTransactionInstruction;
1818
1717
  exports.assertIsBlockhash = assertIsBlockhash;
1819
1718
  exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
1820
- exports.assertIsTransactionSignature = assertIsTransactionSignature;
1821
1719
  exports.assertTransactionIsFullySigned = assertTransactionIsFullySigned;
1822
1720
  exports.createTransaction = createTransaction;
1823
1721
  exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
@@ -1826,13 +1724,12 @@ this.globalThis.solanaWeb3 = (function (exports) {
1826
1724
  exports.getTransactionDecoder = getTransactionDecoder;
1827
1725
  exports.getTransactionEncoder = getTransactionEncoder;
1828
1726
  exports.isAdvanceNonceAccountInstruction = isAdvanceNonceAccountInstruction;
1829
- exports.isTransactionSignature = isTransactionSignature;
1727
+ exports.partiallySignTransaction = partiallySignTransaction;
1830
1728
  exports.prependTransactionInstruction = prependTransactionInstruction;
1831
1729
  exports.setTransactionFeePayer = setTransactionFeePayer;
1832
1730
  exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
1833
1731
  exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
1834
1732
  exports.signTransaction = signTransaction;
1835
- exports.transactionSignature = transactionSignature;
1836
1733
 
1837
1734
  return exports;
1838
1735