@solana/transactions 2.0.0-experimental.a48ebd2 → 2.0.0-experimental.a7a613a

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