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