@solana/transactions 2.0.0-experimental.d4b2978 → 2.0.0-experimental.d603013

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 (66) hide show
  1. package/README.md +276 -5
  2. package/dist/index.browser.cjs +435 -262
  3. package/dist/index.browser.cjs.map +1 -1
  4. package/dist/index.browser.js +424 -263
  5. package/dist/index.browser.js.map +1 -1
  6. package/dist/index.native.js +426 -263
  7. package/dist/index.native.js.map +1 -1
  8. package/dist/index.node.cjs +435 -262
  9. package/dist/index.node.cjs.map +1 -1
  10. package/dist/index.node.js +424 -263
  11. package/dist/index.node.js.map +1 -1
  12. package/dist/types/accounts.d.ts +2 -2
  13. package/dist/types/accounts.d.ts.map +1 -1
  14. package/dist/types/blockhash.d.ts +5 -7
  15. package/dist/types/blockhash.d.ts.map +1 -1
  16. package/dist/types/compilable-transaction.d.ts +7 -0
  17. package/dist/types/compilable-transaction.d.ts.map +1 -0
  18. package/dist/types/compile-address-table-lookups.d.ts +3 -3
  19. package/dist/types/compile-address-table-lookups.d.ts.map +1 -1
  20. package/dist/types/compile-header.d.ts +1 -1
  21. package/dist/types/compile-instructions.d.ts +1 -1
  22. package/dist/types/compile-lifetime-token.d.ts +1 -1
  23. package/dist/types/compile-static-accounts.d.ts +3 -3
  24. package/dist/types/compile-static-accounts.d.ts.map +1 -1
  25. package/dist/types/compile-transaction.d.ts +6 -7
  26. package/dist/types/compile-transaction.d.ts.map +1 -1
  27. package/dist/types/create-transaction.d.ts +1 -1
  28. package/dist/types/decompile-transaction.d.ts +13 -0
  29. package/dist/types/decompile-transaction.d.ts.map +1 -0
  30. package/dist/types/durable-nonce.d.ts +7 -8
  31. package/dist/types/durable-nonce.d.ts.map +1 -1
  32. package/dist/types/fee-payer.d.ts +6 -6
  33. package/dist/types/fee-payer.d.ts.map +1 -1
  34. package/dist/types/index.d.ts +13 -9
  35. package/dist/types/index.d.ts.map +1 -1
  36. package/dist/types/instructions.d.ts +4 -2
  37. package/dist/types/instructions.d.ts.map +1 -1
  38. package/dist/types/message.d.ts +6 -10
  39. package/dist/types/message.d.ts.map +1 -1
  40. package/dist/types/serializers/address-table-lookup.d.ts +5 -5
  41. package/dist/types/serializers/address-table-lookup.d.ts.map +1 -1
  42. package/dist/types/serializers/header.d.ts +5 -5
  43. package/dist/types/serializers/header.d.ts.map +1 -1
  44. package/dist/types/serializers/index.d.ts +2 -1
  45. package/dist/types/serializers/index.d.ts.map +1 -1
  46. package/dist/types/serializers/instruction.d.ts +5 -5
  47. package/dist/types/serializers/instruction.d.ts.map +1 -1
  48. package/dist/types/serializers/message.d.ts +5 -5
  49. package/dist/types/serializers/message.d.ts.map +1 -1
  50. package/dist/types/serializers/transaction-version.d.ts +5 -5
  51. package/dist/types/serializers/transaction-version.d.ts.map +1 -1
  52. package/dist/types/serializers/transaction.d.ts +9 -5
  53. package/dist/types/serializers/transaction.d.ts.map +1 -1
  54. package/dist/types/signatures.d.ts +9 -13
  55. package/dist/types/signatures.d.ts.map +1 -1
  56. package/dist/types/types.d.ts +6 -13
  57. package/dist/types/types.d.ts.map +1 -1
  58. package/dist/types/unsigned-transaction.d.ts +1 -1
  59. package/dist/types/wire-transaction.d.ts +2 -2
  60. package/dist/types/wire-transaction.d.ts.map +1 -1
  61. package/package.json +18 -16
  62. package/dist/index.development.js +0 -1735
  63. package/dist/index.development.js.map +0 -1
  64. package/dist/index.production.min.js +0 -26
  65. package/dist/types/serializers/unimplemented.d.ts +0 -3
  66. package/dist/types/serializers/unimplemented.d.ts.map +0 -1
@@ -1,1735 +0,0 @@
1
- this.globalThis = this.globalThis || {};
2
- this.globalThis.solanaWeb3 = (function (exports) {
3
- 'use strict';
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;
10
- };
11
-
12
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/bytes.mjs
13
- var mergeBytes = (bytesArr) => {
14
- const totalLength = bytesArr.reduce((total, arr) => total + arr.length, 0);
15
- const result = new Uint8Array(totalLength);
16
- let offset = 0;
17
- bytesArr.forEach((arr) => {
18
- result.set(arr, offset);
19
- offset += arr.length;
20
- });
21
- return result;
22
- };
23
- var padBytes = (bytes2, length) => {
24
- if (bytes2.length >= length)
25
- return bytes2;
26
- const paddedBytes = new Uint8Array(length).fill(0);
27
- paddedBytes.set(bytes2);
28
- return paddedBytes;
29
- };
30
- var fixBytes = (bytes2, length) => padBytes(bytes2.slice(0, length), length);
31
-
32
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/errors.mjs
33
- var DeserializingEmptyBufferError = class extends Error {
34
- constructor(serializer) {
35
- super(`Serializer [${serializer}] cannot deserialize empty buffers.`);
36
- __publicField(this, "name", "DeserializingEmptyBufferError");
37
- }
38
- };
39
- var NotEnoughBytesError = class extends Error {
40
- constructor(serializer, expected, actual) {
41
- super(`Serializer [${serializer}] expected ${expected} bytes, got ${actual}.`);
42
- __publicField(this, "name", "NotEnoughBytesError");
43
- }
44
- };
45
- var ExpectedFixedSizeSerializerError = class extends Error {
46
- constructor(message) {
47
- message ?? (message = "Expected a fixed-size serializer, got a variable-size one.");
48
- super(message);
49
- __publicField(this, "name", "ExpectedFixedSizeSerializerError");
50
- }
51
- };
52
-
53
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/fixSerializer.mjs
54
- function fixSerializer(serializer, fixedBytes, description) {
55
- return {
56
- description: description ?? `fixed(${fixedBytes}, ${serializer.description})`,
57
- fixedSize: fixedBytes,
58
- maxSize: fixedBytes,
59
- serialize: (value) => fixBytes(serializer.serialize(value), fixedBytes),
60
- deserialize: (buffer, offset = 0) => {
61
- buffer = buffer.slice(offset, offset + fixedBytes);
62
- if (buffer.length < fixedBytes) {
63
- throw new NotEnoughBytesError("fixSerializer", fixedBytes, buffer.length);
64
- }
65
- if (serializer.fixedSize !== null) {
66
- buffer = fixBytes(buffer, serializer.fixedSize);
67
- }
68
- const [value] = serializer.deserialize(buffer, 0);
69
- return [value, offset + fixedBytes];
70
- }
71
- };
72
- }
73
-
74
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/errors.mjs
75
- var InvalidBaseStringError = class extends Error {
76
- constructor(value, base, cause) {
77
- const message = `Expected a string of base ${base}, got [${value}].`;
78
- super(message);
79
- __publicField(this, "name", "InvalidBaseStringError");
80
- this.cause = cause;
81
- }
82
- };
83
-
84
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseX.mjs
85
- var baseX = (alphabet) => {
86
- const base = alphabet.length;
87
- const baseBigInt = BigInt(base);
88
- return {
89
- description: `base${base}`,
90
- fixedSize: null,
91
- maxSize: null,
92
- serialize(value) {
93
- if (!value.match(new RegExp(`^[${alphabet}]*$`))) {
94
- throw new InvalidBaseStringError(value, base);
95
- }
96
- if (value === "")
97
- return new Uint8Array();
98
- const chars = [...value];
99
- let trailIndex = chars.findIndex((c) => c !== alphabet[0]);
100
- trailIndex = trailIndex === -1 ? chars.length : trailIndex;
101
- const leadingZeroes = Array(trailIndex).fill(0);
102
- if (trailIndex === chars.length)
103
- return Uint8Array.from(leadingZeroes);
104
- const tailChars = chars.slice(trailIndex);
105
- let base10Number = 0n;
106
- let baseXPower = 1n;
107
- for (let i = tailChars.length - 1; i >= 0; i -= 1) {
108
- base10Number += baseXPower * BigInt(alphabet.indexOf(tailChars[i]));
109
- baseXPower *= baseBigInt;
110
- }
111
- const tailBytes = [];
112
- while (base10Number > 0n) {
113
- tailBytes.unshift(Number(base10Number % 256n));
114
- base10Number /= 256n;
115
- }
116
- return Uint8Array.from(leadingZeroes.concat(tailBytes));
117
- },
118
- deserialize(buffer, offset = 0) {
119
- if (buffer.length === 0)
120
- return ["", 0];
121
- const bytes2 = buffer.slice(offset);
122
- let trailIndex = bytes2.findIndex((n) => n !== 0);
123
- trailIndex = trailIndex === -1 ? bytes2.length : trailIndex;
124
- const leadingZeroes = alphabet[0].repeat(trailIndex);
125
- if (trailIndex === bytes2.length)
126
- return [leadingZeroes, buffer.length];
127
- let base10Number = bytes2.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
128
- const tailChars = [];
129
- while (base10Number > 0n) {
130
- tailChars.unshift(alphabet[Number(base10Number % baseBigInt)]);
131
- base10Number /= baseBigInt;
132
- }
133
- return [leadingZeroes + tailChars.join(""), buffer.length];
134
- }
135
- };
136
- };
137
-
138
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/base58.mjs
139
- var base58 = baseX("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
140
-
141
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/common.mjs
142
- var Endian;
143
- (function(Endian2) {
144
- Endian2["Little"] = "le";
145
- Endian2["Big"] = "be";
146
- })(Endian || (Endian = {}));
147
-
148
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/errors.mjs
149
- var NumberOutOfRangeError = class extends RangeError {
150
- constructor(serializer, min, max, actual) {
151
- super(`Serializer [${serializer}] expected number to be between ${min} and ${max}, got ${actual}.`);
152
- __publicField(this, "name", "NumberOutOfRangeError");
153
- }
154
- };
155
-
156
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/utils.mjs
157
- function numberFactory(input) {
158
- let littleEndian;
159
- let defaultDescription = input.name;
160
- if (input.size > 1) {
161
- littleEndian = !("endian" in input.options) || input.options.endian === Endian.Little;
162
- defaultDescription += littleEndian ? "(le)" : "(be)";
163
- }
164
- return {
165
- description: input.options.description ?? defaultDescription,
166
- fixedSize: input.size,
167
- maxSize: input.size,
168
- serialize(value) {
169
- if (input.range) {
170
- assertRange(input.name, input.range[0], input.range[1], value);
171
- }
172
- const buffer = new ArrayBuffer(input.size);
173
- input.set(new DataView(buffer), value, littleEndian);
174
- return new Uint8Array(buffer);
175
- },
176
- deserialize(bytes2, offset = 0) {
177
- const slice = bytes2.slice(offset, offset + input.size);
178
- assertEnoughBytes("i8", slice, input.size);
179
- const view = toDataView(slice);
180
- return [input.get(view, littleEndian), offset + input.size];
181
- }
182
- };
183
- }
184
- var toArrayBuffer = (array2) => array2.buffer.slice(array2.byteOffset, array2.byteLength + array2.byteOffset);
185
- var toDataView = (array2) => new DataView(toArrayBuffer(array2));
186
- var assertRange = (serializer, min, max, value) => {
187
- if (value < min || value > max) {
188
- throw new NumberOutOfRangeError(serializer, min, max, value);
189
- }
190
- };
191
- var assertEnoughBytes = (serializer, bytes2, expected) => {
192
- if (bytes2.length === 0) {
193
- throw new DeserializingEmptyBufferError(serializer);
194
- }
195
- if (bytes2.length < expected) {
196
- throw new NotEnoughBytesError(serializer, expected, bytes2.length);
197
- }
198
- };
199
-
200
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u32.mjs
201
- var u32 = (options = {}) => numberFactory({
202
- name: "u32",
203
- size: 4,
204
- range: [0, Number("0xffffffff")],
205
- set: (view, value, le) => view.setUint32(0, Number(value), le),
206
- get: (view, le) => view.getUint32(0, le),
207
- options
208
- });
209
-
210
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/shortU16.mjs
211
- var shortU16 = (options = {}) => ({
212
- description: options.description ?? "shortU16",
213
- fixedSize: null,
214
- maxSize: 3,
215
- serialize: (value) => {
216
- assertRange("shortU16", 0, 65535, value);
217
- const bytes2 = [0];
218
- for (let ii = 0; ; ii += 1) {
219
- const alignedValue = value >> ii * 7;
220
- if (alignedValue === 0) {
221
- break;
222
- }
223
- const nextSevenBits = 127 & alignedValue;
224
- bytes2[ii] = nextSevenBits;
225
- if (ii > 0) {
226
- bytes2[ii - 1] |= 128;
227
- }
228
- }
229
- return new Uint8Array(bytes2);
230
- },
231
- deserialize: (bytes2, offset = 0) => {
232
- let value = 0;
233
- let byteCount = 0;
234
- while (++byteCount) {
235
- const byteIndex = byteCount - 1;
236
- const currentByte = bytes2[offset + byteIndex];
237
- const nextSevenBits = 127 & currentByte;
238
- value |= nextSevenBits << byteIndex * 7;
239
- if ((currentByte & 128) === 0) {
240
- break;
241
- }
242
- }
243
- return [value, offset + byteCount];
244
- }
245
- });
246
-
247
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/errors.mjs
248
- var InvalidNumberOfItemsError = class extends Error {
249
- constructor(serializer, expected, actual) {
250
- super(`Expected [${serializer}] to have ${expected} items, got ${actual}.`);
251
- __publicField(this, "name", "InvalidNumberOfItemsError");
252
- }
253
- };
254
- var InvalidArrayLikeRemainderSizeError = class extends Error {
255
- constructor(remainderSize, itemSize) {
256
- super(`The remainder of the buffer (${remainderSize} bytes) cannot be split into chunks of ${itemSize} bytes. Serializers of "remainder" size must have a remainder that is a multiple of its item size. In other words, ${remainderSize} modulo ${itemSize} should be equal to zero.`);
257
- __publicField(this, "name", "InvalidArrayLikeRemainderSizeError");
258
- }
259
- };
260
- var UnrecognizedArrayLikeSerializerSizeError = class extends Error {
261
- constructor(size) {
262
- super(`Unrecognized array-like serializer size: ${JSON.stringify(size)}`);
263
- __publicField(this, "name", "UnrecognizedArrayLikeSerializerSizeError");
264
- }
265
- };
266
-
267
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/sumSerializerSizes.mjs
268
- function sumSerializerSizes(sizes) {
269
- return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
270
- }
271
-
272
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/utils.mjs
273
- function getResolvedSize(size, childrenSizes, bytes2, offset) {
274
- if (typeof size === "number") {
275
- return [size, offset];
276
- }
277
- if (typeof size === "object") {
278
- return size.deserialize(bytes2, offset);
279
- }
280
- if (size === "remainder") {
281
- const childrenSize = sumSerializerSizes(childrenSizes);
282
- if (childrenSize === null) {
283
- throw new ExpectedFixedSizeSerializerError('Serializers of "remainder" size must have fixed-size items.');
284
- }
285
- const remainder = bytes2.slice(offset).length;
286
- if (remainder % childrenSize !== 0) {
287
- throw new InvalidArrayLikeRemainderSizeError(remainder, childrenSize);
288
- }
289
- return [remainder / childrenSize, offset];
290
- }
291
- throw new UnrecognizedArrayLikeSerializerSizeError(size);
292
- }
293
- function getSizeDescription(size) {
294
- return typeof size === "object" ? size.description : `${size}`;
295
- }
296
- function getSizeFromChildren(size, childrenSizes) {
297
- if (typeof size !== "number")
298
- return null;
299
- if (size === 0)
300
- return 0;
301
- const childrenSize = sumSerializerSizes(childrenSizes);
302
- return childrenSize === null ? null : childrenSize * size;
303
- }
304
- function getSizePrefix(size, realSize) {
305
- return typeof size === "object" ? size.serialize(realSize) : new Uint8Array();
306
- }
307
-
308
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/array.mjs
309
- function array(item, options = {}) {
310
- const size = options.size ?? u32();
311
- if (size === "remainder" && item.fixedSize === null) {
312
- throw new ExpectedFixedSizeSerializerError('Serializers of "remainder" size must have fixed-size items.');
313
- }
314
- return {
315
- description: options.description ?? `array(${item.description}; ${getSizeDescription(size)})`,
316
- fixedSize: getSizeFromChildren(size, [item.fixedSize]),
317
- maxSize: getSizeFromChildren(size, [item.maxSize]),
318
- serialize: (value) => {
319
- if (typeof size === "number" && value.length !== size) {
320
- throw new InvalidNumberOfItemsError("array", size, value.length);
321
- }
322
- return mergeBytes([getSizePrefix(size, value.length), ...value.map((v) => item.serialize(v))]);
323
- },
324
- deserialize: (bytes2, offset = 0) => {
325
- if (typeof size === "object" && bytes2.slice(offset).length === 0) {
326
- return [[], offset];
327
- }
328
- const [resolvedSize, newOffset] = getResolvedSize(size, [item.fixedSize], bytes2, offset);
329
- offset = newOffset;
330
- const values = [];
331
- for (let i = 0; i < resolvedSize; i += 1) {
332
- const [value, newOffset2] = item.deserialize(bytes2, offset);
333
- values.push(value);
334
- offset = newOffset2;
335
- }
336
- return [values, offset];
337
- }
338
- };
339
- }
340
-
341
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/bytes.mjs
342
- function bytes(options = {}) {
343
- const size = options.size ?? "variable";
344
- const description = options.description ?? `bytes(${getSizeDescription(size)})`;
345
- const byteSerializer = {
346
- description,
347
- fixedSize: null,
348
- maxSize: null,
349
- serialize: (value) => new Uint8Array(value),
350
- deserialize: (bytes2, offset = 0) => {
351
- const slice = bytes2.slice(offset);
352
- return [slice, offset + slice.length];
353
- }
354
- };
355
- if (size === "variable") {
356
- return byteSerializer;
357
- }
358
- if (typeof size === "number") {
359
- return fixSerializer(byteSerializer, size, description);
360
- }
361
- return {
362
- description,
363
- fixedSize: null,
364
- maxSize: null,
365
- serialize: (value) => {
366
- const contentBytes = byteSerializer.serialize(value);
367
- const lengthBytes = size.serialize(contentBytes.length);
368
- return mergeBytes([lengthBytes, contentBytes]);
369
- },
370
- deserialize: (buffer, offset = 0) => {
371
- if (buffer.slice(offset).length === 0) {
372
- throw new DeserializingEmptyBufferError("bytes");
373
- }
374
- const [lengthBigInt, lengthOffset] = size.deserialize(buffer, offset);
375
- const length = Number(lengthBigInt);
376
- offset = lengthOffset;
377
- const contentBuffer = buffer.slice(offset, offset + length);
378
- if (contentBuffer.length < length) {
379
- throw new NotEnoughBytesError("bytes", length, contentBuffer.length);
380
- }
381
- const [value, contentOffset] = byteSerializer.deserialize(contentBuffer);
382
- offset += contentOffset;
383
- return [value, offset];
384
- }
385
- };
386
- }
387
-
388
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/struct.mjs
389
- function struct(fields, options = {}) {
390
- const fieldDescriptions = fields.map(([name, serializer]) => `${String(name)}: ${serializer.description}`).join(", ");
391
- return {
392
- description: options.description ?? `struct(${fieldDescriptions})`,
393
- fixedSize: sumSerializerSizes(fields.map(([, field]) => field.fixedSize)),
394
- maxSize: sumSerializerSizes(fields.map(([, field]) => field.maxSize)),
395
- serialize: (struct2) => {
396
- const fieldBytes = fields.map(([key, serializer]) => serializer.serialize(struct2[key]));
397
- return mergeBytes(fieldBytes);
398
- },
399
- deserialize: (bytes2, offset = 0) => {
400
- const struct2 = {};
401
- fields.forEach(([key, serializer]) => {
402
- const [value, newOffset] = serializer.deserialize(bytes2, offset);
403
- offset = newOffset;
404
- struct2[key] = value;
405
- });
406
- return [struct2, offset];
407
- }
408
- };
409
- }
410
-
411
- // src/unsigned-transaction.ts
412
- function getUnsignedTransaction(transaction) {
413
- if ("signatures" in transaction) {
414
- const {
415
- signatures: _,
416
- // eslint-disable-line @typescript-eslint/no-unused-vars
417
- ...unsignedTransaction
418
- } = transaction;
419
- return unsignedTransaction;
420
- } else {
421
- return transaction;
422
- }
423
- }
424
-
425
- // src/blockhash.ts
426
- function assertIsBlockhash(putativeBlockhash) {
427
- try {
428
- if (
429
- // Lowest value (32 bytes of zeroes)
430
- putativeBlockhash.length < 32 || // Highest value (32 bytes of 255)
431
- putativeBlockhash.length > 44
432
- ) {
433
- throw new Error("Expected input string to decode to a byte array of length 32.");
434
- }
435
- const bytes2 = base58.serialize(putativeBlockhash);
436
- const numBytes = bytes2.byteLength;
437
- if (numBytes !== 32) {
438
- throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
439
- }
440
- } catch (e2) {
441
- throw new Error(`\`${putativeBlockhash}\` is not a blockhash`, {
442
- cause: e2
443
- });
444
- }
445
- }
446
- function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {
447
- if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
448
- return transaction;
449
- }
450
- const out = {
451
- ...getUnsignedTransaction(transaction),
452
- lifetimeConstraint: blockhashLifetimeConstraint
453
- };
454
- Object.freeze(out);
455
- return out;
456
- }
457
-
458
- // src/create-transaction.ts
459
- function createTransaction({
460
- version
461
- }) {
462
- const out = {
463
- instructions: [],
464
- version
465
- };
466
- Object.freeze(out);
467
- return out;
468
- }
469
-
470
- // ../instructions/dist/index.browser.js
471
- var AccountRole = /* @__PURE__ */ ((AccountRole2) => {
472
- AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */
473
- 3] = "WRITABLE_SIGNER";
474
- AccountRole2[AccountRole2["READONLY_SIGNER"] = /* 2 */
475
- 2] = "READONLY_SIGNER";
476
- AccountRole2[AccountRole2["WRITABLE"] = /* 1 */
477
- 1] = "WRITABLE";
478
- AccountRole2[AccountRole2["READONLY"] = /* 0 */
479
- 0] = "READONLY";
480
- return AccountRole2;
481
- })(AccountRole || {});
482
- var IS_WRITABLE_BITMASK = 1;
483
- function isSignerRole(role) {
484
- return role >= 2;
485
- }
486
- function isWritableRole(role) {
487
- return (role & IS_WRITABLE_BITMASK) !== 0;
488
- }
489
- function mergeRoles(roleA, roleB) {
490
- return roleA | roleB;
491
- }
492
-
493
- // src/durable-nonce.ts
494
- var RECENT_BLOCKHASHES_SYSVAR_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111";
495
- var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
496
- function assertIsDurableNonceTransaction(transaction) {
497
- if (!isDurableNonceTransaction(transaction)) {
498
- throw new Error("Transaction is not a durable nonce transaction");
499
- }
500
- }
501
- function createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress) {
502
- return {
503
- accounts: [
504
- { address: nonceAccountAddress, role: AccountRole.WRITABLE },
505
- {
506
- address: RECENT_BLOCKHASHES_SYSVAR_ADDRESS,
507
- role: AccountRole.READONLY
508
- },
509
- { address: nonceAuthorityAddress, role: AccountRole.READONLY_SIGNER }
510
- ],
511
- data: new Uint8Array([4, 0, 0, 0]),
512
- programAddress: SYSTEM_PROGRAM_ADDRESS
513
- };
514
- }
515
- function isAdvanceNonceAccountInstruction(instruction) {
516
- return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
517
- instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts
518
- instruction.accounts?.length === 3 && // First account is nonce account address
519
- instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole.WRITABLE && // Second account is recent blockhashes sysvar
520
- instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole.READONLY && // Third account is nonce authority account
521
- instruction.accounts[2].address != null && instruction.accounts[2].role === AccountRole.READONLY_SIGNER;
522
- }
523
- function isAdvanceNonceAccountInstructionData(data) {
524
- return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
525
- }
526
- function isDurableNonceTransaction(transaction) {
527
- return "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.nonce === "string" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]);
528
- }
529
- function setTransactionLifetimeUsingDurableNonce({
530
- nonce,
531
- nonceAccountAddress,
532
- nonceAuthorityAddress
533
- }, transaction) {
534
- const isAlreadyDurableNonceTransaction = isDurableNonceTransaction(transaction);
535
- if (isAlreadyDurableNonceTransaction && transaction.lifetimeConstraint.nonce === nonce && transaction.instructions[0].accounts[0].address === nonceAccountAddress && transaction.instructions[0].accounts[2].address === nonceAuthorityAddress) {
536
- return transaction;
537
- }
538
- const out = {
539
- ...getUnsignedTransaction(transaction),
540
- instructions: [
541
- createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
542
- ...isAlreadyDurableNonceTransaction ? transaction.instructions.slice(1) : transaction.instructions
543
- ],
544
- lifetimeConstraint: {
545
- nonce
546
- }
547
- };
548
- Object.freeze(out);
549
- return out;
550
- }
551
-
552
- // src/fee-payer.ts
553
- function setTransactionFeePayer(feePayer, transaction) {
554
- if ("feePayer" in transaction && feePayer === transaction.feePayer) {
555
- return transaction;
556
- }
557
- const out = {
558
- ...getUnsignedTransaction(transaction),
559
- feePayer
560
- };
561
- Object.freeze(out);
562
- return out;
563
- }
564
-
565
- // src/instructions.ts
566
- function appendTransactionInstruction(instruction, transaction) {
567
- const out = {
568
- ...getUnsignedTransaction(transaction),
569
- instructions: [...transaction.instructions, instruction]
570
- };
571
- Object.freeze(out);
572
- return out;
573
- }
574
- function prependTransactionInstruction(instruction, transaction) {
575
- const out = {
576
- ...getUnsignedTransaction(transaction),
577
- instructions: [instruction, ...transaction.instructions]
578
- };
579
- Object.freeze(out);
580
- return out;
581
- }
582
-
583
- // ../codecs-core/dist/index.browser.js
584
- function assertByteArrayIsNotEmptyForCodec(codecDescription, bytes2, offset = 0) {
585
- if (bytes2.length - offset <= 0) {
586
- throw new Error(`Codec [${codecDescription}] cannot decode empty byte arrays.`);
587
- }
588
- }
589
- function assertByteArrayHasEnoughBytesForCodec(codecDescription, expected, bytes2, offset = 0) {
590
- const bytesLength = bytes2.length - offset;
591
- if (bytesLength < expected) {
592
- throw new Error(`Codec [${codecDescription}] expected ${expected} bytes, got ${bytesLength}.`);
593
- }
594
- }
595
- var mergeBytes2 = (byteArrays) => {
596
- const nonEmptyByteArrays = byteArrays.filter((arr) => arr.length);
597
- if (nonEmptyByteArrays.length === 0) {
598
- return byteArrays.length ? byteArrays[0] : new Uint8Array();
599
- }
600
- if (nonEmptyByteArrays.length === 1) {
601
- return nonEmptyByteArrays[0];
602
- }
603
- const totalLength = nonEmptyByteArrays.reduce((total, arr) => total + arr.length, 0);
604
- const result = new Uint8Array(totalLength);
605
- let offset = 0;
606
- nonEmptyByteArrays.forEach((arr) => {
607
- result.set(arr, offset);
608
- offset += arr.length;
609
- });
610
- return result;
611
- };
612
- var padBytes2 = (bytes2, length) => {
613
- if (bytes2.length >= length)
614
- return bytes2;
615
- const paddedBytes = new Uint8Array(length).fill(0);
616
- paddedBytes.set(bytes2);
617
- return paddedBytes;
618
- };
619
- var fixBytes2 = (bytes2, length) => padBytes2(bytes2.length <= length ? bytes2 : bytes2.slice(0, length), length);
620
- function fixCodecHelper(data, fixedBytes, description) {
621
- return {
622
- description: description ?? `fixed(${fixedBytes}, ${data.description})`,
623
- fixedSize: fixedBytes,
624
- maxSize: fixedBytes
625
- };
626
- }
627
- function fixEncoder(encoder, fixedBytes, description) {
628
- return {
629
- ...fixCodecHelper(encoder, fixedBytes, description),
630
- encode: (value) => fixBytes2(encoder.encode(value), fixedBytes)
631
- };
632
- }
633
- function fixDecoder(decoder, fixedBytes, description) {
634
- return {
635
- ...fixCodecHelper(decoder, fixedBytes, description),
636
- decode: (bytes2, offset = 0) => {
637
- assertByteArrayHasEnoughBytesForCodec("fixCodec", fixedBytes, bytes2, offset);
638
- if (offset > 0 || bytes2.length > fixedBytes) {
639
- bytes2 = bytes2.slice(offset, offset + fixedBytes);
640
- }
641
- if (decoder.fixedSize !== null) {
642
- bytes2 = fixBytes2(bytes2, decoder.fixedSize);
643
- }
644
- const [value] = decoder.decode(bytes2, 0);
645
- return [value, offset + fixedBytes];
646
- }
647
- };
648
- }
649
- function mapEncoder(encoder, unmap) {
650
- return {
651
- description: encoder.description,
652
- encode: (value) => encoder.encode(unmap(value)),
653
- fixedSize: encoder.fixedSize,
654
- maxSize: encoder.maxSize
655
- };
656
- }
657
-
658
- // ../codecs-numbers/dist/index.browser.js
659
- function assertNumberIsBetweenForCodec(codecDescription, min, max, value) {
660
- if (value < min || value > max) {
661
- throw new Error(
662
- `Codec [${codecDescription}] expected number to be in the range [${min}, ${max}], got ${value}.`
663
- );
664
- }
665
- }
666
- function sharedNumberFactory(input) {
667
- let littleEndian;
668
- let defaultDescription = input.name;
669
- if (input.size > 1) {
670
- littleEndian = !("endian" in input.options) || input.options.endian === 0;
671
- defaultDescription += littleEndian ? "(le)" : "(be)";
672
- }
673
- return {
674
- description: input.options.description ?? defaultDescription,
675
- fixedSize: input.size,
676
- littleEndian,
677
- maxSize: input.size
678
- };
679
- }
680
- function numberEncoderFactory(input) {
681
- const codecData = sharedNumberFactory(input);
682
- return {
683
- description: codecData.description,
684
- encode(value) {
685
- if (input.range) {
686
- assertNumberIsBetweenForCodec(input.name, input.range[0], input.range[1], value);
687
- }
688
- const arrayBuffer = new ArrayBuffer(input.size);
689
- input.set(new DataView(arrayBuffer), value, codecData.littleEndian);
690
- return new Uint8Array(arrayBuffer);
691
- },
692
- fixedSize: codecData.fixedSize,
693
- maxSize: codecData.maxSize
694
- };
695
- }
696
- function numberDecoderFactory(input) {
697
- const codecData = sharedNumberFactory(input);
698
- return {
699
- decode(bytes2, offset = 0) {
700
- assertByteArrayIsNotEmptyForCodec(codecData.description, bytes2, offset);
701
- assertByteArrayHasEnoughBytesForCodec(codecData.description, input.size, bytes2, offset);
702
- const view = new DataView(toArrayBuffer2(bytes2, offset, input.size));
703
- return [input.get(view, codecData.littleEndian), offset + input.size];
704
- },
705
- description: codecData.description,
706
- fixedSize: codecData.fixedSize,
707
- maxSize: codecData.maxSize
708
- };
709
- }
710
- function toArrayBuffer2(bytes2, offset, length) {
711
- const bytesOffset = bytes2.byteOffset + (offset ?? 0);
712
- const bytesLength = length ?? bytes2.byteLength;
713
- return bytes2.buffer.slice(bytesOffset, bytesOffset + bytesLength);
714
- }
715
- var getShortU16Encoder = (options = {}) => ({
716
- description: options.description ?? "shortU16",
717
- encode: (value) => {
718
- assertNumberIsBetweenForCodec("shortU16", 0, 65535, value);
719
- const bytes2 = [0];
720
- for (let ii = 0; ; ii += 1) {
721
- const alignedValue = value >> ii * 7;
722
- if (alignedValue === 0) {
723
- break;
724
- }
725
- const nextSevenBits = 127 & alignedValue;
726
- bytes2[ii] = nextSevenBits;
727
- if (ii > 0) {
728
- bytes2[ii - 1] |= 128;
729
- }
730
- }
731
- return new Uint8Array(bytes2);
732
- },
733
- fixedSize: null,
734
- maxSize: 3
735
- });
736
- var getU32Encoder = (options = {}) => numberEncoderFactory({
737
- name: "u32",
738
- options,
739
- range: [0, Number("0xffffffff")],
740
- set: (view, value, le) => view.setUint32(0, value, le),
741
- size: 4
742
- });
743
- var getU32Decoder = (options = {}) => numberDecoderFactory({
744
- get: (view, le) => view.getUint32(0, le),
745
- name: "u32",
746
- options,
747
- size: 4
748
- });
749
- var getU8Encoder = (options = {}) => numberEncoderFactory({
750
- name: "u8",
751
- options,
752
- range: [0, Number("0xff")],
753
- set: (view, value) => view.setUint8(0, value),
754
- size: 1
755
- });
756
-
757
- // ../codecs-strings/dist/index.browser.js
758
- function assertValidBaseString(alphabet4, testValue, givenValue = testValue) {
759
- if (!testValue.match(new RegExp(`^[${alphabet4}]*$`))) {
760
- throw new Error(`Expected a string of base ${alphabet4.length}, got [${givenValue}].`);
761
- }
762
- }
763
- var getBaseXEncoder = (alphabet4) => {
764
- const base = alphabet4.length;
765
- const baseBigInt = BigInt(base);
766
- return {
767
- description: `base${base}`,
768
- encode(value) {
769
- assertValidBaseString(alphabet4, value);
770
- if (value === "")
771
- return new Uint8Array();
772
- const chars = [...value];
773
- let trailIndex = chars.findIndex((c) => c !== alphabet4[0]);
774
- trailIndex = trailIndex === -1 ? chars.length : trailIndex;
775
- const leadingZeroes = Array(trailIndex).fill(0);
776
- if (trailIndex === chars.length)
777
- return Uint8Array.from(leadingZeroes);
778
- const tailChars = chars.slice(trailIndex);
779
- let base10Number = 0n;
780
- let baseXPower = 1n;
781
- for (let i = tailChars.length - 1; i >= 0; i -= 1) {
782
- base10Number += baseXPower * BigInt(alphabet4.indexOf(tailChars[i]));
783
- baseXPower *= baseBigInt;
784
- }
785
- const tailBytes = [];
786
- while (base10Number > 0n) {
787
- tailBytes.unshift(Number(base10Number % 256n));
788
- base10Number /= 256n;
789
- }
790
- return Uint8Array.from(leadingZeroes.concat(tailBytes));
791
- },
792
- fixedSize: null,
793
- maxSize: null
794
- };
795
- };
796
- var getBaseXDecoder = (alphabet4) => {
797
- const base = alphabet4.length;
798
- const baseBigInt = BigInt(base);
799
- return {
800
- decode(rawBytes, offset = 0) {
801
- const bytes2 = offset === 0 ? rawBytes : rawBytes.slice(offset);
802
- if (bytes2.length === 0)
803
- return ["", 0];
804
- let trailIndex = bytes2.findIndex((n) => n !== 0);
805
- trailIndex = trailIndex === -1 ? bytes2.length : trailIndex;
806
- const leadingZeroes = alphabet4[0].repeat(trailIndex);
807
- if (trailIndex === bytes2.length)
808
- return [leadingZeroes, rawBytes.length];
809
- let base10Number = bytes2.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
810
- const tailChars = [];
811
- while (base10Number > 0n) {
812
- tailChars.unshift(alphabet4[Number(base10Number % baseBigInt)]);
813
- base10Number /= baseBigInt;
814
- }
815
- return [leadingZeroes + tailChars.join(""), rawBytes.length];
816
- },
817
- description: `base${base}`,
818
- fixedSize: null,
819
- maxSize: null
820
- };
821
- };
822
- var alphabet2 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
823
- var getBase58Encoder = () => getBaseXEncoder(alphabet2);
824
- var getBase58Decoder = () => getBaseXDecoder(alphabet2);
825
- var removeNullCharacters = (value) => (
826
- // eslint-disable-next-line no-control-regex
827
- value.replace(/\u0000/g, "")
828
- );
829
- var e = globalThis.TextDecoder;
830
- var o = globalThis.TextEncoder;
831
- var getUtf8Encoder = () => {
832
- let textEncoder;
833
- return {
834
- description: "utf8",
835
- encode: (value) => new Uint8Array((textEncoder || (textEncoder = new o())).encode(value)),
836
- fixedSize: null,
837
- maxSize: null
838
- };
839
- };
840
- var getUtf8Decoder = () => {
841
- let textDecoder;
842
- return {
843
- decode(bytes2, offset = 0) {
844
- const value = (textDecoder || (textDecoder = new e())).decode(bytes2.slice(offset));
845
- return [removeNullCharacters(value), bytes2.length];
846
- },
847
- description: "utf8",
848
- fixedSize: null,
849
- maxSize: null
850
- };
851
- };
852
- var getStringEncoder = (options = {}) => {
853
- const size = options.size ?? getU32Encoder();
854
- const encoding = options.encoding ?? getUtf8Encoder();
855
- const description = options.description ?? `string(${encoding.description}; ${getSizeDescription2(size)})`;
856
- if (size === "variable") {
857
- return { ...encoding, description };
858
- }
859
- if (typeof size === "number") {
860
- return fixEncoder(encoding, size, description);
861
- }
862
- return {
863
- description,
864
- encode: (value) => {
865
- const contentBytes = encoding.encode(value);
866
- const lengthBytes = size.encode(contentBytes.length);
867
- return mergeBytes2([lengthBytes, contentBytes]);
868
- },
869
- fixedSize: null,
870
- maxSize: null
871
- };
872
- };
873
- var getStringDecoder = (options = {}) => {
874
- const size = options.size ?? getU32Decoder();
875
- const encoding = options.encoding ?? getUtf8Decoder();
876
- const description = options.description ?? `string(${encoding.description}; ${getSizeDescription2(size)})`;
877
- if (size === "variable") {
878
- return { ...encoding, description };
879
- }
880
- if (typeof size === "number") {
881
- return fixDecoder(encoding, size, description);
882
- }
883
- return {
884
- decode: (bytes2, offset = 0) => {
885
- assertByteArrayIsNotEmptyForCodec("string", bytes2, offset);
886
- const [lengthBigInt, lengthOffset] = size.decode(bytes2, offset);
887
- const length = Number(lengthBigInt);
888
- offset = lengthOffset;
889
- const contentBytes = bytes2.slice(offset, offset + length);
890
- assertByteArrayHasEnoughBytesForCodec("string", length, contentBytes);
891
- const [value, contentOffset] = encoding.decode(contentBytes);
892
- offset += contentOffset;
893
- return [value, offset];
894
- },
895
- description,
896
- fixedSize: null,
897
- maxSize: null
898
- };
899
- };
900
- function getSizeDescription2(size) {
901
- return typeof size === "object" ? size.description : `${size}`;
902
- }
903
-
904
- // ../assertions/dist/index.browser.js
905
- function assertIsSecureContext() {
906
- if (!globalThis.isSecureContext) {
907
- throw new Error(
908
- "Cryptographic operations are only allowed in secure browser contexts. Read more here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts"
909
- );
910
- }
911
- }
912
- async function assertKeyExporterIsAvailable() {
913
- assertIsSecureContext();
914
- if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.exportKey !== "function") {
915
- throw new Error("No key export implementation could be found");
916
- }
917
- }
918
- async function assertSigningCapabilityIsAvailable() {
919
- assertIsSecureContext();
920
- if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.sign !== "function") {
921
- throw new Error("No signing implementation could be found");
922
- }
923
- }
924
-
925
- // ../addresses/dist/index.browser.js
926
- var memoizedBase58Encoder;
927
- var memoizedBase58Decoder;
928
- function getMemoizedBase58Encoder() {
929
- if (!memoizedBase58Encoder)
930
- memoizedBase58Encoder = getBase58Encoder();
931
- return memoizedBase58Encoder;
932
- }
933
- function getMemoizedBase58Decoder() {
934
- if (!memoizedBase58Decoder)
935
- memoizedBase58Decoder = getBase58Decoder();
936
- return memoizedBase58Decoder;
937
- }
938
- function assertIsAddress(putativeBase58EncodedAddress) {
939
- try {
940
- if (
941
- // Lowest address (32 bytes of zeroes)
942
- putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
943
- putativeBase58EncodedAddress.length > 44
944
- ) {
945
- throw new Error("Expected input string to decode to a byte array of length 32.");
946
- }
947
- const base58Encoder = getMemoizedBase58Encoder();
948
- const bytes2 = base58Encoder.encode(putativeBase58EncodedAddress);
949
- const numBytes = bytes2.byteLength;
950
- if (numBytes !== 32) {
951
- throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
952
- }
953
- } catch (e2) {
954
- throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
955
- cause: e2
956
- });
957
- }
958
- }
959
- function address(putativeBase58EncodedAddress) {
960
- assertIsAddress(putativeBase58EncodedAddress);
961
- return putativeBase58EncodedAddress;
962
- }
963
- function getAddressEncoder(config) {
964
- return mapEncoder(
965
- getStringEncoder({
966
- description: config?.description ?? "Base58EncodedAddress",
967
- encoding: getMemoizedBase58Encoder(),
968
- size: 32
969
- }),
970
- (putativeAddress) => address(putativeAddress)
971
- );
972
- }
973
- function getAddressDecoder(config) {
974
- return getStringDecoder({
975
- description: config?.description ?? "Base58EncodedAddress",
976
- encoding: getMemoizedBase58Decoder(),
977
- size: 32
978
- });
979
- }
980
- function getAddressComparator() {
981
- return new Intl.Collator("en", {
982
- caseFirst: "lower",
983
- ignorePunctuation: false,
984
- localeMatcher: "best fit",
985
- numeric: false,
986
- sensitivity: "variant",
987
- usage: "sort"
988
- }).compare;
989
- }
990
- async function getAddressFromPublicKey(publicKey) {
991
- await assertKeyExporterIsAvailable();
992
- if (publicKey.type !== "public" || publicKey.algorithm.name !== "Ed25519") {
993
- throw new Error("The `CryptoKey` must be an `Ed25519` public key");
994
- }
995
- const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
996
- const [base58EncodedAddress] = getAddressDecoder().decode(new Uint8Array(publicKeyBytes));
997
- return base58EncodedAddress;
998
- }
999
-
1000
- // src/accounts.ts
1001
- function upsert(addressMap, address2, update) {
1002
- addressMap[address2] = update(addressMap[address2] ?? { role: AccountRole.READONLY });
1003
- }
1004
- var TYPE = Symbol("AddressMapTypeProperty");
1005
- function getAddressMapFromInstructions(feePayer, instructions) {
1006
- const addressMap = {
1007
- [feePayer]: { [TYPE]: 0 /* FEE_PAYER */, role: AccountRole.WRITABLE_SIGNER }
1008
- };
1009
- const addressesOfInvokedPrograms = /* @__PURE__ */ new Set();
1010
- for (const instruction of instructions) {
1011
- upsert(addressMap, instruction.programAddress, (entry) => {
1012
- addressesOfInvokedPrograms.add(instruction.programAddress);
1013
- if (TYPE in entry) {
1014
- if (isWritableRole(entry.role)) {
1015
- switch (entry[TYPE]) {
1016
- case 0 /* FEE_PAYER */:
1017
- throw new Error(
1018
- `This transaction includes an address (\`${instruction.programAddress}\`) which is both invoked and set as the fee payer. Program addresses may not pay fees.`
1019
- );
1020
- default:
1021
- throw new Error(
1022
- `This transaction includes an address (\`${instruction.programAddress}\`) which is both invoked and marked writable. Program addresses may not be writable.`
1023
- );
1024
- }
1025
- }
1026
- if (entry[TYPE] === 2 /* STATIC */) {
1027
- return entry;
1028
- }
1029
- }
1030
- return { [TYPE]: 2 /* STATIC */, role: AccountRole.READONLY };
1031
- });
1032
- let addressComparator;
1033
- if (!instruction.accounts) {
1034
- continue;
1035
- }
1036
- for (const account of instruction.accounts) {
1037
- upsert(addressMap, account.address, (entry) => {
1038
- const {
1039
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1040
- address: _,
1041
- ...accountMeta
1042
- } = account;
1043
- if (TYPE in entry) {
1044
- switch (entry[TYPE]) {
1045
- case 0 /* FEE_PAYER */:
1046
- return entry;
1047
- case 1 /* LOOKUP_TABLE */: {
1048
- const nextRole = mergeRoles(entry.role, accountMeta.role);
1049
- if ("lookupTableAddress" in accountMeta) {
1050
- const shouldReplaceEntry = (
1051
- // Consider using the new LOOKUP_TABLE if its address is different...
1052
- entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
1053
- (addressComparator || (addressComparator = getAddressComparator()))(
1054
- accountMeta.lookupTableAddress,
1055
- entry.lookupTableAddress
1056
- ) < 0
1057
- );
1058
- if (shouldReplaceEntry) {
1059
- return {
1060
- [TYPE]: 1 /* LOOKUP_TABLE */,
1061
- ...accountMeta,
1062
- role: nextRole
1063
- };
1064
- }
1065
- } else if (isSignerRole(accountMeta.role)) {
1066
- return {
1067
- [TYPE]: 2 /* STATIC */,
1068
- role: nextRole
1069
- };
1070
- }
1071
- if (entry.role !== nextRole) {
1072
- return {
1073
- ...entry,
1074
- role: nextRole
1075
- };
1076
- } else {
1077
- return entry;
1078
- }
1079
- }
1080
- case 2 /* STATIC */: {
1081
- const nextRole = mergeRoles(entry.role, accountMeta.role);
1082
- if (
1083
- // Check to see if this address represents a program that is invoked
1084
- // in this transaction.
1085
- addressesOfInvokedPrograms.has(account.address)
1086
- ) {
1087
- if (isWritableRole(accountMeta.role)) {
1088
- throw new Error(
1089
- `This transaction includes an address (\`${account.address}\`) which is both invoked and marked writable. Program addresses may not be writable.`
1090
- );
1091
- }
1092
- if (entry.role !== nextRole) {
1093
- return {
1094
- ...entry,
1095
- role: nextRole
1096
- };
1097
- } else {
1098
- return entry;
1099
- }
1100
- } else if ("lookupTableAddress" in accountMeta && // Static accounts can be 'upgraded' to lookup table accounts as
1101
- // long as they are not require to sign the transaction.
1102
- !isSignerRole(entry.role)) {
1103
- return {
1104
- ...accountMeta,
1105
- [TYPE]: 1 /* LOOKUP_TABLE */,
1106
- role: nextRole
1107
- };
1108
- } else {
1109
- if (entry.role !== nextRole) {
1110
- return {
1111
- ...entry,
1112
- role: nextRole
1113
- };
1114
- } else {
1115
- return entry;
1116
- }
1117
- }
1118
- }
1119
- }
1120
- }
1121
- if ("lookupTableAddress" in accountMeta) {
1122
- return {
1123
- ...accountMeta,
1124
- [TYPE]: 1 /* LOOKUP_TABLE */
1125
- };
1126
- } else {
1127
- return {
1128
- ...accountMeta,
1129
- [TYPE]: 2 /* STATIC */
1130
- };
1131
- }
1132
- });
1133
- }
1134
- }
1135
- return addressMap;
1136
- }
1137
- function getOrderedAccountsFromAddressMap(addressMap) {
1138
- let addressComparator;
1139
- const orderedAccounts = Object.entries(addressMap).sort(([leftAddress, leftEntry], [rightAddress, rightEntry]) => {
1140
- if (leftEntry[TYPE] !== rightEntry[TYPE]) {
1141
- if (leftEntry[TYPE] === 0 /* FEE_PAYER */) {
1142
- return -1;
1143
- } else if (rightEntry[TYPE] === 0 /* FEE_PAYER */) {
1144
- return 1;
1145
- } else if (leftEntry[TYPE] === 2 /* STATIC */) {
1146
- return -1;
1147
- } else if (rightEntry[TYPE] === 2 /* STATIC */) {
1148
- return 1;
1149
- }
1150
- }
1151
- const leftIsSigner = isSignerRole(leftEntry.role);
1152
- if (leftIsSigner !== isSignerRole(rightEntry.role)) {
1153
- return leftIsSigner ? -1 : 1;
1154
- }
1155
- const leftIsWritable = isWritableRole(leftEntry.role);
1156
- if (leftIsWritable !== isWritableRole(rightEntry.role)) {
1157
- return leftIsWritable ? -1 : 1;
1158
- }
1159
- addressComparator || (addressComparator = getAddressComparator());
1160
- if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
1161
- return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
1162
- } else {
1163
- return addressComparator(leftAddress, rightAddress);
1164
- }
1165
- }).map(([address2, addressMeta]) => ({
1166
- address: address2,
1167
- ...addressMeta
1168
- }));
1169
- return orderedAccounts;
1170
- }
1171
-
1172
- // src/compile-address-table-lookups.ts
1173
- function getCompiledAddressTableLookups(orderedAccounts) {
1174
- var _a;
1175
- const index = {};
1176
- for (const account of orderedAccounts) {
1177
- if (!("lookupTableAddress" in account)) {
1178
- continue;
1179
- }
1180
- const entry = index[_a = account.lookupTableAddress] || (index[_a] = {
1181
- readableIndices: [],
1182
- writableIndices: []
1183
- });
1184
- if (account.role === AccountRole.WRITABLE) {
1185
- entry.writableIndices.push(account.addressIndex);
1186
- } else {
1187
- entry.readableIndices.push(account.addressIndex);
1188
- }
1189
- }
1190
- return Object.keys(index).sort(getAddressComparator()).map((lookupTableAddress) => ({
1191
- lookupTableAddress,
1192
- ...index[lookupTableAddress]
1193
- }));
1194
- }
1195
-
1196
- // src/compile-header.ts
1197
- function getCompiledMessageHeader(orderedAccounts) {
1198
- let numReadonlyNonSignerAccounts = 0;
1199
- let numReadonlySignerAccounts = 0;
1200
- let numSignerAccounts = 0;
1201
- for (const account of orderedAccounts) {
1202
- if ("lookupTableAddress" in account) {
1203
- break;
1204
- }
1205
- const accountIsWritable = isWritableRole(account.role);
1206
- if (isSignerRole(account.role)) {
1207
- numSignerAccounts++;
1208
- if (!accountIsWritable) {
1209
- numReadonlySignerAccounts++;
1210
- }
1211
- } else if (!accountIsWritable) {
1212
- numReadonlyNonSignerAccounts++;
1213
- }
1214
- }
1215
- return {
1216
- numReadonlyNonSignerAccounts,
1217
- numReadonlySignerAccounts,
1218
- numSignerAccounts
1219
- };
1220
- }
1221
-
1222
- // src/compile-instructions.ts
1223
- function getAccountIndex(orderedAccounts) {
1224
- const out = {};
1225
- for (const [index, account] of orderedAccounts.entries()) {
1226
- out[account.address] = index;
1227
- }
1228
- return out;
1229
- }
1230
- function getCompiledInstructions(instructions, orderedAccounts) {
1231
- const accountIndex = getAccountIndex(orderedAccounts);
1232
- return instructions.map(({ accounts, data, programAddress }) => {
1233
- return {
1234
- programAddressIndex: accountIndex[programAddress],
1235
- ...accounts ? { accountIndices: accounts.map(({ address: address2 }) => accountIndex[address2]) } : null,
1236
- ...data ? { data } : null
1237
- };
1238
- });
1239
- }
1240
-
1241
- // src/compile-lifetime-token.ts
1242
- function getCompiledLifetimeToken(lifetimeConstraint) {
1243
- if ("nonce" in lifetimeConstraint) {
1244
- return lifetimeConstraint.nonce;
1245
- }
1246
- return lifetimeConstraint.blockhash;
1247
- }
1248
-
1249
- // src/compile-static-accounts.ts
1250
- function getCompiledStaticAccounts(orderedAccounts) {
1251
- const firstLookupTableAccountIndex = orderedAccounts.findIndex((account) => "lookupTableAddress" in account);
1252
- const orderedStaticAccounts = firstLookupTableAccountIndex === -1 ? orderedAccounts : orderedAccounts.slice(0, firstLookupTableAccountIndex);
1253
- return orderedStaticAccounts.map(({ address: address2 }) => address2);
1254
- }
1255
-
1256
- // src/message.ts
1257
- function compileMessage(transaction) {
1258
- const addressMap = getAddressMapFromInstructions(transaction.feePayer, transaction.instructions);
1259
- const orderedAccounts = getOrderedAccountsFromAddressMap(addressMap);
1260
- return {
1261
- ...transaction.version !== "legacy" ? { addressTableLookups: getCompiledAddressTableLookups(orderedAccounts) } : null,
1262
- header: getCompiledMessageHeader(orderedAccounts),
1263
- instructions: getCompiledInstructions(transaction.instructions, orderedAccounts),
1264
- lifetimeToken: getCompiledLifetimeToken(transaction.lifetimeConstraint),
1265
- staticAccounts: getCompiledStaticAccounts(orderedAccounts),
1266
- version: transaction.version
1267
- };
1268
- }
1269
-
1270
- // src/compile-transaction.ts
1271
- function getCompiledTransaction(transaction) {
1272
- const compiledMessage = compileMessage(transaction);
1273
- let signatures;
1274
- if ("signatures" in transaction) {
1275
- signatures = [];
1276
- for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
1277
- signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
1278
- }
1279
- } else {
1280
- signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
1281
- }
1282
- return {
1283
- compiledMessage,
1284
- signatures
1285
- };
1286
- }
1287
-
1288
- // ../codecs-data-structures/dist/index.browser.js
1289
- function sumCodecSizes(sizes) {
1290
- return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
1291
- }
1292
- function getArrayLikeCodecSizeDescription(size) {
1293
- return typeof size === "object" ? size.description : `${size}`;
1294
- }
1295
- function getArrayLikeCodecSizeFromChildren(size, childrenSizes) {
1296
- if (typeof size !== "number")
1297
- return null;
1298
- if (size === 0)
1299
- return 0;
1300
- const childrenSize = sumCodecSizes(childrenSizes);
1301
- return childrenSize === null ? null : childrenSize * size;
1302
- }
1303
- function getArrayLikeCodecSizePrefix(size, realSize) {
1304
- return typeof size === "object" ? size.encode(realSize) : new Uint8Array();
1305
- }
1306
- function assertValidNumberOfItemsForCodec(codecDescription, expected, actual) {
1307
- if (expected !== actual) {
1308
- throw new Error(`Expected [${codecDescription}] to have ${expected} items, got ${actual}.`);
1309
- }
1310
- }
1311
- function arrayCodecHelper(item, size, description) {
1312
- if (size === "remainder" && item.fixedSize === null) {
1313
- throw new Error('Codecs of "remainder" size must have fixed-size items.');
1314
- }
1315
- return {
1316
- description: description ?? `array(${item.description}; ${getArrayLikeCodecSizeDescription(size)})`,
1317
- fixedSize: getArrayLikeCodecSizeFromChildren(size, [item.fixedSize]),
1318
- maxSize: getArrayLikeCodecSizeFromChildren(size, [item.maxSize])
1319
- };
1320
- }
1321
- function getArrayEncoder(item, options = {}) {
1322
- const size = options.size ?? getU32Encoder();
1323
- return {
1324
- ...arrayCodecHelper(item, size, options.description),
1325
- encode: (value) => {
1326
- if (typeof size === "number") {
1327
- assertValidNumberOfItemsForCodec("array", size, value.length);
1328
- }
1329
- return mergeBytes2([getArrayLikeCodecSizePrefix(size, value.length), ...value.map((v) => item.encode(v))]);
1330
- }
1331
- };
1332
- }
1333
- function getBytesEncoder(options = {}) {
1334
- const size = options.size ?? "variable";
1335
- const sizeDescription = typeof size === "object" ? size.description : `${size}`;
1336
- const description = options.description ?? `bytes(${sizeDescription})`;
1337
- const byteEncoder = {
1338
- description,
1339
- encode: (value) => value,
1340
- fixedSize: null,
1341
- maxSize: null
1342
- };
1343
- if (size === "variable") {
1344
- return byteEncoder;
1345
- }
1346
- if (typeof size === "number") {
1347
- return fixEncoder(byteEncoder, size, description);
1348
- }
1349
- return {
1350
- ...byteEncoder,
1351
- encode: (value) => {
1352
- const contentBytes = byteEncoder.encode(value);
1353
- const lengthBytes = size.encode(contentBytes.length);
1354
- return mergeBytes2([lengthBytes, contentBytes]);
1355
- }
1356
- };
1357
- }
1358
- function structCodecHelper(fields, description) {
1359
- const fieldDescriptions = fields.map(([name, codec]) => `${String(name)}: ${codec.description}`).join(", ");
1360
- return {
1361
- description: description ?? `struct(${fieldDescriptions})`,
1362
- fixedSize: sumCodecSizes(fields.map(([, field]) => field.fixedSize)),
1363
- maxSize: sumCodecSizes(fields.map(([, field]) => field.maxSize))
1364
- };
1365
- }
1366
- function getStructEncoder(fields, options = {}) {
1367
- return {
1368
- ...structCodecHelper(fields, options.description),
1369
- encode: (struct2) => {
1370
- const fieldBytes = fields.map(([key, codec]) => codec.encode(struct2[key]));
1371
- return mergeBytes2(fieldBytes);
1372
- }
1373
- };
1374
- }
1375
-
1376
- // src/serializers/address-table-lookup.ts
1377
- var lookupTableAddressDescription = "The address of the address lookup table account from which instruction addresses should be looked up" ;
1378
- var writableIndicesDescription = "The indices of the accounts in the lookup table that should be loaded as writeable" ;
1379
- var readableIndicesDescription = "The indices of the accounts in the lookup table that should be loaded as read-only" ;
1380
- 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" ;
1381
- var memoizedAddressTableLookupEncoder;
1382
- function getAddressTableLookupEncoder() {
1383
- if (!memoizedAddressTableLookupEncoder) {
1384
- memoizedAddressTableLookupEncoder = getStructEncoder(
1385
- [
1386
- ["lookupTableAddress", getAddressEncoder({ description: lookupTableAddressDescription })],
1387
- [
1388
- "writableIndices",
1389
- getArrayEncoder(getU8Encoder(), {
1390
- description: writableIndicesDescription,
1391
- size: getShortU16Encoder()
1392
- })
1393
- ],
1394
- [
1395
- "readableIndices",
1396
- getArrayEncoder(getU8Encoder(), {
1397
- description: readableIndicesDescription,
1398
- size: getShortU16Encoder()
1399
- })
1400
- ]
1401
- ],
1402
- { description: addressTableLookupDescription }
1403
- );
1404
- }
1405
- return memoizedAddressTableLookupEncoder;
1406
- }
1407
-
1408
- // src/serializers/header.ts
1409
- var memoizedU8Encoder;
1410
- function getMemoizedU8Encoder() {
1411
- if (!memoizedU8Encoder)
1412
- memoizedU8Encoder = getU8Encoder();
1413
- return memoizedU8Encoder;
1414
- }
1415
- function getMemoizedU8EncoderDescription(description) {
1416
- const encoder = getMemoizedU8Encoder();
1417
- return {
1418
- ...encoder,
1419
- description: description ?? encoder.description
1420
- };
1421
- }
1422
- var numSignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction" ;
1423
- 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" ;
1424
- var numReadonlyNonSignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable" ;
1425
- var messageHeaderDescription = "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses" ;
1426
- function getMessageHeaderEncoder() {
1427
- return getStructEncoder(
1428
- [
1429
- ["numSignerAccounts", getMemoizedU8EncoderDescription(numSignerAccountsDescription)],
1430
- ["numReadonlySignerAccounts", getMemoizedU8EncoderDescription(numReadonlySignerAccountsDescription)],
1431
- ["numReadonlyNonSignerAccounts", getMemoizedU8EncoderDescription(numReadonlyNonSignerAccountsDescription)]
1432
- ],
1433
- {
1434
- description: messageHeaderDescription
1435
- }
1436
- );
1437
- }
1438
-
1439
- // src/serializers/instruction.ts
1440
- var programAddressIndexDescription = "The index of the program being called, according to the well-ordered accounts list for this transaction" ;
1441
- var accountIndexDescription = "The index of an account, according to the well-ordered accounts list for this transaction" ;
1442
- 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" ;
1443
- var dataDescription = "An optional buffer of data passed to the instruction" ;
1444
- var memoizedGetInstructionEncoder;
1445
- function getInstructionEncoder() {
1446
- if (!memoizedGetInstructionEncoder) {
1447
- memoizedGetInstructionEncoder = mapEncoder(
1448
- getStructEncoder([
1449
- ["programAddressIndex", getU8Encoder({ description: programAddressIndexDescription })],
1450
- [
1451
- "accountIndices",
1452
- getArrayEncoder(getU8Encoder({ description: accountIndexDescription }), {
1453
- description: accountIndicesDescription,
1454
- size: getShortU16Encoder()
1455
- })
1456
- ],
1457
- ["data", getBytesEncoder({ description: dataDescription, size: getShortU16Encoder() })]
1458
- ]),
1459
- // Convert an instruction to have all fields defined
1460
- (instruction) => {
1461
- if (instruction.accountIndices !== void 0 && instruction.data !== void 0) {
1462
- return instruction;
1463
- }
1464
- return {
1465
- ...instruction,
1466
- accountIndices: instruction.accountIndices ?? [],
1467
- data: instruction.data ?? new Uint8Array(0)
1468
- };
1469
- }
1470
- );
1471
- }
1472
- return memoizedGetInstructionEncoder;
1473
- }
1474
-
1475
- // src/serializers/transaction-version.ts
1476
- var VERSION_FLAG_MASK = 128;
1477
- var BASE_CONFIG = {
1478
- description: "A single byte that encodes the version of the transaction" ,
1479
- fixedSize: null,
1480
- maxSize: 1
1481
- };
1482
- function encode(value) {
1483
- if (value === "legacy") {
1484
- return new Uint8Array();
1485
- }
1486
- if (value < 0 || value > 127) {
1487
- throw new Error(`Transaction version must be in the range [0, 127]. \`${value}\` given.`);
1488
- }
1489
- return new Uint8Array([value | VERSION_FLAG_MASK]);
1490
- }
1491
- function getTransactionVersionEncoder() {
1492
- return {
1493
- ...BASE_CONFIG,
1494
- encode
1495
- };
1496
- }
1497
-
1498
- // src/serializers/message.ts
1499
- var staticAccountsDescription = "A compact-array of static account addresses belonging to this transaction" ;
1500
- var lifetimeTokenDescription = "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" ;
1501
- var instructionsDescription = "A compact-array of instructions belonging to this transaction" ;
1502
- var addressTableLookupsDescription = "A compact array of address table lookups belonging to this transaction" ;
1503
- function getCompiledMessageLegacyEncoder() {
1504
- return getStructEncoder(getPreludeStructEncoderTuple());
1505
- }
1506
- function getCompiledMessageVersionedEncoder() {
1507
- return mapEncoder(
1508
- getStructEncoder([
1509
- ...getPreludeStructEncoderTuple(),
1510
- ["addressTableLookups", getAddressTableLookupArrayEncoder()]
1511
- ]),
1512
- (value) => {
1513
- if (value.version === "legacy") {
1514
- return value;
1515
- }
1516
- return {
1517
- ...value,
1518
- addressTableLookups: value.addressTableLookups ?? []
1519
- };
1520
- }
1521
- );
1522
- }
1523
- function getPreludeStructEncoderTuple() {
1524
- return [
1525
- ["version", getTransactionVersionEncoder()],
1526
- ["header", getMessageHeaderEncoder()],
1527
- [
1528
- "staticAccounts",
1529
- getArrayEncoder(getAddressEncoder(), {
1530
- description: staticAccountsDescription,
1531
- size: getShortU16Encoder()
1532
- })
1533
- ],
1534
- [
1535
- "lifetimeToken",
1536
- getStringEncoder({
1537
- description: lifetimeTokenDescription,
1538
- encoding: getBase58Encoder(),
1539
- size: 32
1540
- })
1541
- ],
1542
- [
1543
- "instructions",
1544
- getArrayEncoder(getInstructionEncoder(), {
1545
- description: instructionsDescription,
1546
- size: getShortU16Encoder()
1547
- })
1548
- ]
1549
- ];
1550
- }
1551
- function getAddressTableLookupArrayEncoder() {
1552
- return getArrayEncoder(getAddressTableLookupEncoder(), {
1553
- description: addressTableLookupsDescription,
1554
- size: getShortU16Encoder()
1555
- });
1556
- }
1557
- var messageDescription = "The wire format of a Solana transaction message" ;
1558
- function getCompiledMessageEncoder() {
1559
- return {
1560
- description: messageDescription,
1561
- encode: (compiledMessage) => {
1562
- if (compiledMessage.version === "legacy") {
1563
- return getCompiledMessageLegacyEncoder().encode(compiledMessage);
1564
- } else {
1565
- return getCompiledMessageVersionedEncoder().encode(compiledMessage);
1566
- }
1567
- },
1568
- fixedSize: null,
1569
- maxSize: null
1570
- };
1571
- }
1572
-
1573
- // src/serializers/unimplemented.ts
1574
- function getError(type, name) {
1575
- const functionSuffix = name + type[0].toUpperCase() + type.slice(1);
1576
- return new Error(
1577
- `No ${type} exists for ${name}. Use \`get${functionSuffix}()\` if you need a ${type}, and \`get${name}Codec()\` if you need to both encode and decode ${name}`
1578
- );
1579
- }
1580
- function getUnimplementedDecoder(name) {
1581
- return () => {
1582
- throw getError("decoder", name);
1583
- };
1584
- }
1585
-
1586
- // src/serializers/transaction.ts
1587
- var BASE_CONFIG2 = {
1588
- description: "The wire format of a Solana transaction" ,
1589
- fixedSize: null,
1590
- maxSize: null
1591
- };
1592
- function toSerializer(encoder) {
1593
- return {
1594
- description: encoder.description,
1595
- deserialize: getUnimplementedDecoder(encoder.description),
1596
- fixedSize: encoder.fixedSize,
1597
- maxSize: encoder.maxSize,
1598
- serialize: encoder.encode
1599
- };
1600
- }
1601
- function serialize(transaction) {
1602
- const compiledTransaction = getCompiledTransaction(transaction);
1603
- return struct([
1604
- [
1605
- "signatures",
1606
- array(bytes({ size: 64 }), {
1607
- ...{ description: "A compact array of 64-byte, base-64 encoded Ed25519 signatures" } ,
1608
- size: shortU16()
1609
- })
1610
- ],
1611
- ["compiledMessage", toSerializer(getCompiledMessageEncoder())]
1612
- ]).serialize(compiledTransaction);
1613
- }
1614
- function getTransactionEncoder() {
1615
- return {
1616
- ...BASE_CONFIG2,
1617
- deserialize: getUnimplementedDecoder("CompiledMessage"),
1618
- serialize
1619
- };
1620
- }
1621
-
1622
- // ../keys/dist/index.browser.js
1623
- async function signBytes(key, data) {
1624
- await assertSigningCapabilityIsAvailable();
1625
- const signedData = await crypto.subtle.sign("Ed25519", key, data);
1626
- return new Uint8Array(signedData);
1627
- }
1628
-
1629
- // src/signatures.ts
1630
- function assertIsTransactionSignature(putativeTransactionSignature) {
1631
- try {
1632
- if (
1633
- // Lowest value (64 bytes of zeroes)
1634
- putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
1635
- putativeTransactionSignature.length > 88
1636
- ) {
1637
- throw new Error("Expected input string to decode to a byte array of length 64.");
1638
- }
1639
- const bytes2 = base58.serialize(putativeTransactionSignature);
1640
- const numBytes = bytes2.byteLength;
1641
- if (numBytes !== 64) {
1642
- throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
1643
- }
1644
- } catch (e2) {
1645
- throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
1646
- cause: e2
1647
- });
1648
- }
1649
- }
1650
- function isTransactionSignature(putativeTransactionSignature) {
1651
- if (
1652
- // Lowest value (64 bytes of zeroes)
1653
- putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
1654
- putativeTransactionSignature.length > 88
1655
- ) {
1656
- return false;
1657
- }
1658
- const bytes2 = base58.serialize(putativeTransactionSignature);
1659
- const numBytes = bytes2.byteLength;
1660
- if (numBytes !== 64) {
1661
- return false;
1662
- }
1663
- return true;
1664
- }
1665
- async function getCompiledMessageSignature(message, secretKey) {
1666
- const wireMessageBytes = getCompiledMessageEncoder().encode(message);
1667
- const signature = await signBytes(secretKey, wireMessageBytes);
1668
- return signature;
1669
- }
1670
- function getSignatureFromTransaction(transaction) {
1671
- const signatureBytes = transaction.signatures[transaction.feePayer];
1672
- if (!signatureBytes) {
1673
- throw new Error(
1674
- "Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
1675
- );
1676
- }
1677
- const transactionSignature2 = base58.deserialize(signatureBytes)[0];
1678
- return transactionSignature2;
1679
- }
1680
- async function signTransaction(keyPairs, transaction) {
1681
- const compiledMessage = compileMessage(transaction);
1682
- const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
1683
- const publicKeySignaturePairs = await Promise.all(
1684
- keyPairs.map(
1685
- (keyPair) => Promise.all([
1686
- getAddressFromPublicKey(keyPair.publicKey),
1687
- getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
1688
- ])
1689
- )
1690
- );
1691
- for (const [signerPublicKey, signature] of publicKeySignaturePairs) {
1692
- nextSignatures[signerPublicKey] = signature;
1693
- }
1694
- const out = {
1695
- ...transaction,
1696
- signatures: nextSignatures
1697
- };
1698
- Object.freeze(out);
1699
- return out;
1700
- }
1701
- function transactionSignature(putativeTransactionSignature) {
1702
- assertIsTransactionSignature(putativeTransactionSignature);
1703
- return putativeTransactionSignature;
1704
- }
1705
-
1706
- // src/wire-transaction.ts
1707
- function getBase64EncodedWireTransaction(transaction) {
1708
- const wireTransactionBytes = getTransactionEncoder().serialize(transaction);
1709
- {
1710
- return btoa(String.fromCharCode(...wireTransactionBytes));
1711
- }
1712
- }
1713
-
1714
- exports.appendTransactionInstruction = appendTransactionInstruction;
1715
- exports.assertIsBlockhash = assertIsBlockhash;
1716
- exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
1717
- exports.assertIsTransactionSignature = assertIsTransactionSignature;
1718
- exports.createTransaction = createTransaction;
1719
- exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
1720
- exports.getSignatureFromTransaction = getSignatureFromTransaction;
1721
- exports.getTransactionEncoder = getTransactionEncoder;
1722
- exports.isAdvanceNonceAccountInstruction = isAdvanceNonceAccountInstruction;
1723
- exports.isTransactionSignature = isTransactionSignature;
1724
- exports.prependTransactionInstruction = prependTransactionInstruction;
1725
- exports.setTransactionFeePayer = setTransactionFeePayer;
1726
- exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
1727
- exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
1728
- exports.signTransaction = signTransaction;
1729
- exports.transactionSignature = transactionSignature;
1730
-
1731
- return exports;
1732
-
1733
- })({});
1734
- //# sourceMappingURL=out.js.map
1735
- //# sourceMappingURL=index.development.js.map