@solana/transactions 2.0.0-experimental.0e113c0 → 2.0.0-experimental.1584fe6

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