@solana/transactions 2.0.0-experimental.ee9f3d8 → 2.0.0-experimental.f07dced

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 (33) hide show
  1. package/dist/index.browser.cjs +632 -0
  2. package/dist/index.browser.cjs.map +1 -1
  3. package/dist/index.browser.js +630 -1
  4. package/dist/index.browser.js.map +1 -1
  5. package/dist/index.development.js +1179 -0
  6. package/dist/index.development.js.map +1 -1
  7. package/dist/index.native.js +630 -3
  8. package/dist/index.native.js.map +1 -1
  9. package/dist/index.node.cjs +632 -0
  10. package/dist/index.node.cjs.map +1 -1
  11. package/dist/index.node.js +632 -1
  12. package/dist/index.node.js.map +1 -1
  13. package/dist/index.production.min.js +8 -5
  14. package/dist/types/accounts.d.ts +28 -0
  15. package/dist/types/blockhash.d.ts +4 -1
  16. package/dist/types/compile-address-table-lookups.d.ts +10 -0
  17. package/dist/types/compile-header.d.ts +9 -0
  18. package/dist/types/compile-instructions.d.ts +10 -0
  19. package/dist/types/compile-lifetime-token.d.ts +3 -0
  20. package/dist/types/compile-static-accounts.d.ts +4 -0
  21. package/dist/types/compile-transaction.d.ts +11 -0
  22. package/dist/types/index.d.ts +1 -0
  23. package/dist/types/message.d.ts +30 -0
  24. package/dist/types/serializers/address-table-lookup.d.ts +6 -0
  25. package/dist/types/serializers/header.d.ts +6 -0
  26. package/dist/types/serializers/instruction.d.ts +6 -0
  27. package/dist/types/serializers/message.d.ts +6 -0
  28. package/dist/types/serializers/transaction-version.d.ts +6 -0
  29. package/dist/types/serializers/transaction.d.ts +6 -0
  30. package/dist/types/serializers/unimplemented.d.ts +3 -0
  31. package/dist/types/signatures.d.ts +6 -6
  32. package/dist/types/wire-transaction.d.ts +6 -0
  33. package/package.json +4 -6
@@ -1,3 +1,29 @@
1
+ import { base58, struct, array, bytes, shortU16, mapSerializer, string, u8 } from '@metaplex-foundation/umi-serializers';
2
+ import { getBase58EncodedAddressFromPublicKey, signBytes, getBase58EncodedAddressComparator, getBase58EncodedAddressCodec } from '@solana/keys';
3
+
4
+ // ../build-scripts/env-shim.ts
5
+ var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
6
+ function assertIsBlockhash(putativeBlockhash) {
7
+ try {
8
+ if (
9
+ // Lowest value (32 bytes of zeroes)
10
+ putativeBlockhash.length < 32 || // Highest value (32 bytes of 255)
11
+ putativeBlockhash.length > 44
12
+ ) {
13
+ throw new Error("Expected input string to decode to a byte array of length 32.");
14
+ }
15
+ const bytes3 = base58.serialize(putativeBlockhash);
16
+ const numBytes = bytes3.byteLength;
17
+ if (numBytes !== 32) {
18
+ throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
19
+ }
20
+ } catch (e) {
21
+ throw new Error(`\`${putativeBlockhash}\` is not a blockhash`, {
22
+ cause: e
23
+ });
24
+ }
25
+ }
26
+
1
27
  // src/create-transaction.ts
2
28
  function createTransaction({
3
29
  version
@@ -70,6 +96,607 @@ function prependTransactionInstruction(instruction, transaction) {
70
96
  return out;
71
97
  }
72
98
 
73
- export { appendTransactionInstruction, createTransaction, prependTransactionInstruction, setTransactionFeePayer };
74
- //# sourceMappingURL=out.js.map
75
- //# sourceMappingURL=index.native.js.map
99
+ // ../instructions/dist/index.browser.js
100
+ var AccountRole = /* @__PURE__ */ ((AccountRole2) => {
101
+ AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */
102
+ 3] = "WRITABLE_SIGNER";
103
+ AccountRole2[AccountRole2["READONLY_SIGNER"] = /* 2 */
104
+ 2] = "READONLY_SIGNER";
105
+ AccountRole2[AccountRole2["WRITABLE"] = /* 1 */
106
+ 1] = "WRITABLE";
107
+ AccountRole2[AccountRole2["READONLY"] = /* 0 */
108
+ 0] = "READONLY";
109
+ return AccountRole2;
110
+ })(AccountRole || {});
111
+ var IS_WRITABLE_BITMASK = 1;
112
+ function isSignerRole(role) {
113
+ return role >= 2;
114
+ }
115
+ function isWritableRole(role) {
116
+ return (role & IS_WRITABLE_BITMASK) !== 0;
117
+ }
118
+ function mergeRoles(roleA, roleB) {
119
+ return roleA | roleB;
120
+ }
121
+ function upsert(addressMap, address, update) {
122
+ addressMap[address] = update(addressMap[address] ?? { role: AccountRole.READONLY });
123
+ }
124
+ var TYPE = Symbol("AddressMapTypeProperty");
125
+ function getAddressMapFromInstructions(feePayer, instructions) {
126
+ const addressMap = {
127
+ [feePayer]: { [TYPE]: 0 /* FEE_PAYER */, role: AccountRole.WRITABLE_SIGNER }
128
+ };
129
+ const addressesOfInvokedPrograms = /* @__PURE__ */ new Set();
130
+ for (const instruction of instructions) {
131
+ upsert(addressMap, instruction.programAddress, (entry) => {
132
+ addressesOfInvokedPrograms.add(instruction.programAddress);
133
+ if (TYPE in entry) {
134
+ if (isWritableRole(entry.role)) {
135
+ switch (entry[TYPE]) {
136
+ case 0 /* FEE_PAYER */:
137
+ throw new Error(
138
+ `This transaction includes an address (\`${instruction.programAddress}\`) which is both invoked and set as the fee payer. Program addresses may not pay fees.`
139
+ );
140
+ default:
141
+ throw new Error(
142
+ `This transaction includes an address (\`${instruction.programAddress}\`) which is both invoked and marked writable. Program addresses may not be writable.`
143
+ );
144
+ }
145
+ }
146
+ if (entry[TYPE] === 2 /* STATIC */) {
147
+ return entry;
148
+ }
149
+ }
150
+ return { [TYPE]: 2 /* STATIC */, role: AccountRole.READONLY };
151
+ });
152
+ let addressComparator;
153
+ if (!instruction.accounts) {
154
+ continue;
155
+ }
156
+ for (const account of instruction.accounts) {
157
+ upsert(addressMap, account.address, (entry) => {
158
+ const {
159
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
160
+ address: _,
161
+ ...accountMeta
162
+ } = account;
163
+ if (TYPE in entry) {
164
+ switch (entry[TYPE]) {
165
+ case 0 /* FEE_PAYER */:
166
+ return entry;
167
+ case 1 /* LOOKUP_TABLE */: {
168
+ const nextRole = mergeRoles(entry.role, accountMeta.role);
169
+ if ("lookupTableAddress" in accountMeta) {
170
+ const shouldReplaceEntry = (
171
+ // Consider using the new LOOKUP_TABLE if its address is different...
172
+ entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
173
+ (addressComparator || (addressComparator = getBase58EncodedAddressComparator()))(
174
+ accountMeta.lookupTableAddress,
175
+ entry.lookupTableAddress
176
+ ) < 0
177
+ );
178
+ if (shouldReplaceEntry) {
179
+ return {
180
+ [TYPE]: 1 /* LOOKUP_TABLE */,
181
+ ...accountMeta,
182
+ role: nextRole
183
+ };
184
+ }
185
+ } else if (isSignerRole(accountMeta.role)) {
186
+ return {
187
+ [TYPE]: 2 /* STATIC */,
188
+ role: nextRole
189
+ };
190
+ }
191
+ if (entry.role !== nextRole) {
192
+ return {
193
+ ...entry,
194
+ role: nextRole
195
+ };
196
+ } else {
197
+ return entry;
198
+ }
199
+ }
200
+ case 2 /* STATIC */: {
201
+ const nextRole = mergeRoles(entry.role, accountMeta.role);
202
+ if (
203
+ // Check to see if this address represents a program that is invoked
204
+ // in this transaction.
205
+ addressesOfInvokedPrograms.has(account.address)
206
+ ) {
207
+ if (isWritableRole(accountMeta.role)) {
208
+ throw new Error(
209
+ `This transaction includes an address (\`${account.address}\`) which is both invoked and marked writable. Program addresses may not be writable.`
210
+ );
211
+ }
212
+ if (entry.role !== nextRole) {
213
+ return {
214
+ ...entry,
215
+ role: nextRole
216
+ };
217
+ } else {
218
+ return entry;
219
+ }
220
+ } else if ("lookupTableAddress" in accountMeta && // Static accounts can be 'upgraded' to lookup table accounts as
221
+ // long as they are not require to sign the transaction.
222
+ !isSignerRole(entry.role)) {
223
+ return {
224
+ ...accountMeta,
225
+ [TYPE]: 1 /* LOOKUP_TABLE */,
226
+ role: nextRole
227
+ };
228
+ } else {
229
+ if (entry.role !== nextRole) {
230
+ return {
231
+ ...entry,
232
+ role: nextRole
233
+ };
234
+ } else {
235
+ return entry;
236
+ }
237
+ }
238
+ }
239
+ }
240
+ }
241
+ if ("lookupTableAddress" in accountMeta) {
242
+ return {
243
+ ...accountMeta,
244
+ [TYPE]: 1 /* LOOKUP_TABLE */
245
+ };
246
+ } else {
247
+ return {
248
+ ...accountMeta,
249
+ [TYPE]: 2 /* STATIC */
250
+ };
251
+ }
252
+ });
253
+ }
254
+ }
255
+ return addressMap;
256
+ }
257
+ function getOrderedAccountsFromAddressMap(addressMap) {
258
+ let addressComparator;
259
+ const orderedAccounts = Object.entries(addressMap).sort(([leftAddress, leftEntry], [rightAddress, rightEntry]) => {
260
+ if (leftEntry[TYPE] !== rightEntry[TYPE]) {
261
+ if (leftEntry[TYPE] === 0 /* FEE_PAYER */) {
262
+ return -1;
263
+ } else if (rightEntry[TYPE] === 0 /* FEE_PAYER */) {
264
+ return 1;
265
+ } else if (leftEntry[TYPE] === 2 /* STATIC */) {
266
+ return -1;
267
+ } else if (rightEntry[TYPE] === 2 /* STATIC */) {
268
+ return 1;
269
+ }
270
+ }
271
+ const leftIsSigner = isSignerRole(leftEntry.role);
272
+ if (leftIsSigner !== isSignerRole(rightEntry.role)) {
273
+ return leftIsSigner ? -1 : 1;
274
+ }
275
+ const leftIsWritable = isWritableRole(leftEntry.role);
276
+ if (leftIsWritable !== isWritableRole(rightEntry.role)) {
277
+ return leftIsWritable ? -1 : 1;
278
+ }
279
+ addressComparator || (addressComparator = getBase58EncodedAddressComparator());
280
+ if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
281
+ return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
282
+ } else {
283
+ return addressComparator(leftAddress, rightAddress);
284
+ }
285
+ }).map(([address, addressMeta]) => ({
286
+ address,
287
+ ...addressMeta
288
+ }));
289
+ return orderedAccounts;
290
+ }
291
+ function getCompiledAddressTableLookups(orderedAccounts) {
292
+ var _a;
293
+ const index = {};
294
+ for (const account of orderedAccounts) {
295
+ if (!("lookupTableAddress" in account)) {
296
+ continue;
297
+ }
298
+ const entry = index[_a = account.lookupTableAddress] || (index[_a] = {
299
+ readableIndices: [],
300
+ writableIndices: []
301
+ });
302
+ if (account.role === AccountRole.WRITABLE) {
303
+ entry.writableIndices.push(account.addressIndex);
304
+ } else {
305
+ entry.readableIndices.push(account.addressIndex);
306
+ }
307
+ }
308
+ return Object.keys(index).sort(getBase58EncodedAddressComparator()).map((lookupTableAddress) => ({
309
+ lookupTableAddress,
310
+ ...index[lookupTableAddress]
311
+ }));
312
+ }
313
+
314
+ // src/compile-header.ts
315
+ function getCompiledMessageHeader(orderedAccounts) {
316
+ let numReadonlyNonSignerAccounts = 0;
317
+ let numReadonlySignerAccounts = 0;
318
+ let numSignerAccounts = 0;
319
+ for (const account of orderedAccounts) {
320
+ if ("lookupTableAddress" in account) {
321
+ break;
322
+ }
323
+ const accountIsWritable = isWritableRole(account.role);
324
+ if (isSignerRole(account.role)) {
325
+ numSignerAccounts++;
326
+ if (!accountIsWritable) {
327
+ numReadonlySignerAccounts++;
328
+ }
329
+ } else if (!accountIsWritable) {
330
+ numReadonlyNonSignerAccounts++;
331
+ }
332
+ }
333
+ return {
334
+ numReadonlyNonSignerAccounts,
335
+ numReadonlySignerAccounts,
336
+ numSignerAccounts
337
+ };
338
+ }
339
+
340
+ // src/compile-instructions.ts
341
+ function getAccountIndex(orderedAccounts) {
342
+ const out = {};
343
+ for (const [index, account] of orderedAccounts.entries()) {
344
+ out[account.address] = index;
345
+ }
346
+ return out;
347
+ }
348
+ function getCompiledInstructions(instructions, orderedAccounts) {
349
+ const accountIndex = getAccountIndex(orderedAccounts);
350
+ return instructions.map(({ accounts, data, programAddress }) => {
351
+ return {
352
+ programAddressIndex: accountIndex[programAddress],
353
+ ...accounts ? { accountIndices: accounts.map(({ address }) => accountIndex[address]) } : null,
354
+ ...data ? { data } : null
355
+ };
356
+ });
357
+ }
358
+
359
+ // src/compile-lifetime-token.ts
360
+ function getCompiledLifetimeToken(lifetimeConstraint) {
361
+ if ("nonce" in lifetimeConstraint) {
362
+ return lifetimeConstraint.nonce;
363
+ }
364
+ return lifetimeConstraint.blockhash;
365
+ }
366
+
367
+ // src/compile-static-accounts.ts
368
+ function getCompiledStaticAccounts(orderedAccounts) {
369
+ const firstLookupTableAccountIndex = orderedAccounts.findIndex((account) => "lookupTableAddress" in account);
370
+ const orderedStaticAccounts = firstLookupTableAccountIndex === -1 ? orderedAccounts : orderedAccounts.slice(0, firstLookupTableAccountIndex);
371
+ return orderedStaticAccounts.map(({ address }) => address);
372
+ }
373
+
374
+ // src/message.ts
375
+ function compileMessage(transaction) {
376
+ const addressMap = getAddressMapFromInstructions(transaction.feePayer, transaction.instructions);
377
+ const orderedAccounts = getOrderedAccountsFromAddressMap(addressMap);
378
+ return {
379
+ ...transaction.version !== "legacy" ? { addressTableLookups: getCompiledAddressTableLookups(orderedAccounts) } : null,
380
+ header: getCompiledMessageHeader(orderedAccounts),
381
+ instructions: getCompiledInstructions(transaction.instructions, orderedAccounts),
382
+ lifetimeToken: getCompiledLifetimeToken(transaction.lifetimeConstraint),
383
+ staticAccounts: getCompiledStaticAccounts(orderedAccounts),
384
+ version: transaction.version
385
+ };
386
+ }
387
+ function getAddressTableLookupCodec() {
388
+ return struct(
389
+ [
390
+ [
391
+ "lookupTableAddress",
392
+ getBase58EncodedAddressCodec(
393
+ __DEV__ ? {
394
+ description: "The address of the address lookup table account from which instruction addresses should be looked up"
395
+ } : void 0
396
+ )
397
+ ],
398
+ [
399
+ "writableIndices",
400
+ array(u8(), {
401
+ ...__DEV__ ? {
402
+ description: "The indices of the accounts in the lookup table that should be loaded as writeable"
403
+ } : null,
404
+ size: shortU16()
405
+ })
406
+ ],
407
+ [
408
+ "readableIndices",
409
+ array(u8(), {
410
+ ...__DEV__ ? {
411
+ description: "The indices of the accounts in the lookup table that should be loaded as read-only"
412
+ } : void 0,
413
+ size: shortU16()
414
+ })
415
+ ]
416
+ ],
417
+ __DEV__ ? {
418
+ description: "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"
419
+ } : void 0
420
+ );
421
+ }
422
+ function getMessageHeaderCodec() {
423
+ return struct(
424
+ [
425
+ [
426
+ "numSignerAccounts",
427
+ u8(
428
+ __DEV__ ? {
429
+ description: "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction"
430
+ } : void 0
431
+ )
432
+ ],
433
+ [
434
+ "numReadonlySignerAccounts",
435
+ u8(
436
+ __DEV__ ? {
437
+ description: "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"
438
+ } : void 0
439
+ )
440
+ ],
441
+ [
442
+ "numReadonlyNonSignerAccounts",
443
+ u8(
444
+ __DEV__ ? {
445
+ description: "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable"
446
+ } : void 0
447
+ )
448
+ ]
449
+ ],
450
+ __DEV__ ? {
451
+ description: "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses"
452
+ } : void 0
453
+ );
454
+ }
455
+ function getInstructionCodec() {
456
+ return mapSerializer(
457
+ struct([
458
+ [
459
+ "programAddressIndex",
460
+ u8(
461
+ __DEV__ ? {
462
+ description: "The index of the program being called, according to the well-ordered accounts list for this transaction"
463
+ } : void 0
464
+ )
465
+ ],
466
+ [
467
+ "addressIndices",
468
+ array(
469
+ u8({
470
+ description: __DEV__ ? "The index of an account, according to the well-ordered accounts list for this transaction" : ""
471
+ }),
472
+ {
473
+ description: __DEV__ ? "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" : "",
474
+ size: shortU16()
475
+ }
476
+ )
477
+ ],
478
+ [
479
+ "data",
480
+ bytes({
481
+ description: __DEV__ ? "An optional buffer of data passed to the instruction" : "",
482
+ size: shortU16()
483
+ })
484
+ ]
485
+ ]),
486
+ (value) => {
487
+ if (value.addressIndices !== void 0 && value.data !== void 0) {
488
+ return value;
489
+ }
490
+ return {
491
+ ...value,
492
+ addressIndices: value.addressIndices ?? [],
493
+ data: value.data ?? new Uint8Array(0)
494
+ };
495
+ },
496
+ (value) => {
497
+ if (value.addressIndices.length && value.data.byteLength) {
498
+ return value;
499
+ }
500
+ const { addressIndices, data, ...rest } = value;
501
+ return {
502
+ ...rest,
503
+ ...addressIndices.length ? { addressIndices } : null,
504
+ ...data.byteLength ? { data } : null
505
+ };
506
+ }
507
+ );
508
+ }
509
+
510
+ // src/serializers/unimplemented.ts
511
+ function getError(type, name) {
512
+ const functionSuffix = name + type[0].toUpperCase() + type.slice(1);
513
+ return new Error(
514
+ `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}`
515
+ );
516
+ }
517
+ function getUnimplementedDecoder(name) {
518
+ return () => {
519
+ throw getError("decoder", name);
520
+ };
521
+ }
522
+
523
+ // src/serializers/transaction-version.ts
524
+ var VERSION_FLAG_MASK = 128;
525
+ var BASE_CONFIG = {
526
+ description: __DEV__ ? "A single byte that encodes the version of the transaction" : "",
527
+ fixedSize: null,
528
+ maxSize: 1
529
+ };
530
+ function deserialize(bytes3, offset = 0) {
531
+ const firstByte = bytes3[offset];
532
+ if ((firstByte & VERSION_FLAG_MASK) === 0) {
533
+ return ["legacy", offset];
534
+ } else {
535
+ const version = firstByte ^ VERSION_FLAG_MASK;
536
+ return [version, offset + 1];
537
+ }
538
+ }
539
+ function serialize(value) {
540
+ if (value === "legacy") {
541
+ return new Uint8Array();
542
+ }
543
+ if (value < 0 || value > 127) {
544
+ throw new Error(`Transaction version must be in the range [0, 127]. \`${value}\` given.`);
545
+ }
546
+ return new Uint8Array([value | VERSION_FLAG_MASK]);
547
+ }
548
+ function getTransactionVersionCodec() {
549
+ return {
550
+ ...BASE_CONFIG,
551
+ deserialize,
552
+ serialize
553
+ };
554
+ }
555
+
556
+ // src/serializers/message.ts
557
+ var BASE_CONFIG2 = {
558
+ description: __DEV__ ? "The wire format of a Solana transaction message" : "",
559
+ fixedSize: null,
560
+ maxSize: null
561
+ };
562
+ function serialize2(compiledMessage) {
563
+ if (compiledMessage.version === "legacy") {
564
+ return struct(getPreludeStructSerializerTuple()).serialize(compiledMessage);
565
+ } else {
566
+ return mapSerializer(
567
+ struct([
568
+ ...getPreludeStructSerializerTuple(),
569
+ ["addressTableLookups", getAddressTableLookupsSerializer()]
570
+ ]),
571
+ (value) => {
572
+ if (value.version === "legacy") {
573
+ return value;
574
+ }
575
+ return {
576
+ ...value,
577
+ addressTableLookups: value.addressTableLookups ?? []
578
+ };
579
+ }
580
+ ).serialize(compiledMessage);
581
+ }
582
+ }
583
+ function getPreludeStructSerializerTuple() {
584
+ return [
585
+ ["version", getTransactionVersionCodec()],
586
+ ["header", getMessageHeaderCodec()],
587
+ [
588
+ "staticAccounts",
589
+ array(getBase58EncodedAddressCodec(), {
590
+ description: __DEV__ ? "A compact-array of static account addresses belonging to this transaction" : "",
591
+ size: shortU16()
592
+ })
593
+ ],
594
+ [
595
+ "lifetimeToken",
596
+ string({
597
+ description: __DEV__ ? "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" : "",
598
+ encoding: base58,
599
+ size: 32
600
+ })
601
+ ],
602
+ [
603
+ "instructions",
604
+ array(getInstructionCodec(), {
605
+ description: __DEV__ ? "A compact-array of instructions belonging to this transaction" : "",
606
+ size: shortU16()
607
+ })
608
+ ]
609
+ ];
610
+ }
611
+ function getAddressTableLookupsSerializer() {
612
+ return array(getAddressTableLookupCodec(), {
613
+ ...__DEV__ ? { description: "A compact array of address table lookups belonging to this transaction" } : null,
614
+ size: shortU16()
615
+ });
616
+ }
617
+ function getCompiledMessageEncoder() {
618
+ return {
619
+ ...BASE_CONFIG2,
620
+ deserialize: getUnimplementedDecoder("CompiledMessage"),
621
+ serialize: serialize2
622
+ };
623
+ }
624
+
625
+ // src/signatures.ts
626
+ async function getCompiledMessageSignature(message, secretKey) {
627
+ const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
628
+ const signature = await signBytes(secretKey, wireMessageBytes);
629
+ return signature;
630
+ }
631
+ async function signTransaction(keyPair, transaction) {
632
+ const compiledMessage = compileMessage(transaction);
633
+ const [signerPublicKey, signature] = await Promise.all([
634
+ getBase58EncodedAddressFromPublicKey(keyPair.publicKey),
635
+ getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
636
+ ]);
637
+ const nextSignatures = {
638
+ ..."signatures" in transaction ? transaction.signatures : null,
639
+ ...{ [signerPublicKey]: signature }
640
+ };
641
+ const out = {
642
+ ...transaction,
643
+ signatures: nextSignatures
644
+ };
645
+ Object.freeze(out);
646
+ return out;
647
+ }
648
+
649
+ // src/compile-transaction.ts
650
+ function getCompiledTransaction(transaction) {
651
+ const compiledMessage = compileMessage(transaction);
652
+ let signatures;
653
+ if ("signatures" in transaction) {
654
+ signatures = [];
655
+ for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
656
+ signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
657
+ }
658
+ } else {
659
+ signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
660
+ }
661
+ return {
662
+ compiledMessage,
663
+ signatures
664
+ };
665
+ }
666
+
667
+ // src/serializers/transaction.ts
668
+ var BASE_CONFIG3 = {
669
+ description: __DEV__ ? "The wire format of a Solana transaction" : "",
670
+ fixedSize: null,
671
+ maxSize: null
672
+ };
673
+ function serialize3(transaction) {
674
+ const compiledTransaction = getCompiledTransaction(transaction);
675
+ return struct([
676
+ [
677
+ "signatures",
678
+ array(bytes({ size: 64 }), {
679
+ ...__DEV__ ? { description: "A compact array of 64-byte, base-64 encoded Ed25519 signatures" } : null,
680
+ size: shortU16()
681
+ })
682
+ ],
683
+ ["compiledMessage", getCompiledMessageEncoder()]
684
+ ]).serialize(compiledTransaction);
685
+ }
686
+ function getTransactionEncoder() {
687
+ return {
688
+ ...BASE_CONFIG3,
689
+ deserialize: getUnimplementedDecoder("CompiledMessage"),
690
+ serialize: serialize3
691
+ };
692
+ }
693
+
694
+ // src/wire-transaction.ts
695
+ function getBase64EncodedWireTransaction(transaction) {
696
+ const wireTransactionBytes = getTransactionEncoder().serialize(transaction);
697
+ {
698
+ return btoa(String.fromCharCode(...wireTransactionBytes));
699
+ }
700
+ }
701
+
702
+ export { appendTransactionInstruction, assertIsBlockhash, createTransaction, getBase64EncodedWireTransaction, prependTransactionInstruction, setTransactionFeePayer, signTransaction };