@solana/transactions 2.0.0-experimental.2bae733 → 2.0.0-experimental.305b060

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 (47) hide show
  1. package/dist/index.browser.cjs +193 -56
  2. package/dist/index.browser.cjs.map +1 -1
  3. package/dist/index.browser.js +187 -59
  4. package/dist/index.browser.js.map +1 -1
  5. package/dist/index.development.js +237 -102
  6. package/dist/index.development.js.map +1 -1
  7. package/dist/index.native.js +187 -57
  8. package/dist/index.native.js.map +1 -1
  9. package/dist/index.node.cjs +193 -56
  10. package/dist/index.node.cjs.map +1 -1
  11. package/dist/index.node.js +187 -57
  12. package/dist/index.node.js.map +1 -1
  13. package/dist/index.production.min.js +11 -6
  14. package/dist/types/accounts.d.ts.map +1 -0
  15. package/dist/types/blockhash.d.ts +9 -1
  16. package/dist/types/blockhash.d.ts.map +1 -0
  17. package/dist/types/compile-address-table-lookups.d.ts.map +1 -0
  18. package/dist/types/compile-header.d.ts.map +1 -0
  19. package/dist/types/compile-instructions.d.ts.map +1 -0
  20. package/dist/types/compile-lifetime-token.d.ts.map +1 -0
  21. package/dist/types/compile-static-accounts.d.ts.map +1 -0
  22. package/dist/types/compile-transaction.d.ts +11 -0
  23. package/dist/types/compile-transaction.d.ts.map +1 -0
  24. package/dist/types/create-transaction.d.ts.map +1 -0
  25. package/dist/types/durable-nonce.d.ts +18 -6
  26. package/dist/types/durable-nonce.d.ts.map +1 -0
  27. package/dist/types/fee-payer.d.ts.map +1 -0
  28. package/dist/types/index.d.ts +1 -0
  29. package/dist/types/index.d.ts.map +1 -0
  30. package/dist/types/instructions.d.ts.map +1 -0
  31. package/dist/types/message.d.ts.map +1 -0
  32. package/dist/types/serializers/address-table-lookup.d.ts.map +1 -0
  33. package/dist/types/serializers/header.d.ts.map +1 -0
  34. package/dist/types/serializers/instruction.d.ts.map +1 -0
  35. package/dist/types/serializers/message.d.ts.map +1 -0
  36. package/dist/types/serializers/transaction-version.d.ts.map +1 -0
  37. package/dist/types/serializers/transaction.d.ts +6 -0
  38. package/dist/types/serializers/transaction.d.ts.map +1 -0
  39. package/dist/types/serializers/unimplemented.d.ts.map +1 -0
  40. package/dist/types/signatures.d.ts +1 -3
  41. package/dist/types/signatures.d.ts.map +1 -0
  42. package/dist/types/types.d.ts.map +1 -0
  43. package/dist/types/unsigned-transaction.d.ts +4 -0
  44. package/dist/types/unsigned-transaction.d.ts.map +1 -0
  45. package/dist/types/wire-transaction.d.ts +6 -0
  46. package/dist/types/wire-transaction.d.ts.map +1 -0
  47. package/package.json +7 -9
@@ -9,78 +9,6 @@ this.globalThis.solanaWeb3 = (function (exports) {
9
9
  return value;
10
10
  };
11
11
 
12
- // src/create-transaction.ts
13
- function createTransaction({
14
- version
15
- }) {
16
- const out = {
17
- instructions: [],
18
- version
19
- };
20
- Object.freeze(out);
21
- return out;
22
- }
23
-
24
- // src/fee-payer.ts
25
- function setTransactionFeePayer(feePayer, transaction) {
26
- if ("feePayer" in transaction && feePayer === transaction.feePayer) {
27
- return transaction;
28
- }
29
- let out;
30
- if ("signatures" in transaction) {
31
- const {
32
- signatures: _,
33
- // eslint-disable-line @typescript-eslint/no-unused-vars
34
- ...unsignedTransaction
35
- } = transaction;
36
- out = {
37
- ...unsignedTransaction,
38
- feePayer
39
- };
40
- } else {
41
- out = {
42
- ...transaction,
43
- feePayer
44
- };
45
- }
46
- Object.freeze(out);
47
- return out;
48
- }
49
-
50
- // src/instructions.ts
51
- function replaceInstructions(transaction, nextInstructions) {
52
- let out;
53
- if ("signatures" in transaction) {
54
- const {
55
- signatures: _,
56
- // eslint-disable-line @typescript-eslint/no-unused-vars
57
- ...unsignedTransaction
58
- } = transaction;
59
- out = {
60
- ...unsignedTransaction,
61
- instructions: nextInstructions
62
- };
63
- } else {
64
- out = {
65
- ...transaction,
66
- instructions: nextInstructions
67
- };
68
- }
69
- return out;
70
- }
71
- function appendTransactionInstruction(instruction, transaction) {
72
- const nextInstructions = [...transaction.instructions, instruction];
73
- const out = replaceInstructions(transaction, nextInstructions);
74
- Object.freeze(out);
75
- return out;
76
- }
77
- function prependTransactionInstruction(instruction, transaction) {
78
- const nextInstructions = [instruction, ...transaction.instructions];
79
- const out = replaceInstructions(transaction, nextInstructions);
80
- Object.freeze(out);
81
- return out;
82
- }
83
-
84
12
  // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/bytes.mjs
85
13
  var mergeBytes = (bytesArr) => {
86
14
  const totalLength = bytesArr.reduce((total, arr) => total + arr.length, 0);
@@ -360,7 +288,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
360
288
  }
361
289
  });
362
290
 
363
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.2/node_modules/@metaplex-foundation/umi-serializers/dist/esm/errors.mjs
291
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/errors.mjs
364
292
  var InvalidNumberOfItemsError = class extends Error {
365
293
  constructor(serializer, expected, actual) {
366
294
  super(`Expected [${serializer}] to have ${expected} items, got ${actual}.`);
@@ -380,12 +308,12 @@ this.globalThis.solanaWeb3 = (function (exports) {
380
308
  }
381
309
  };
382
310
 
383
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.2/node_modules/@metaplex-foundation/umi-serializers/dist/esm/sumSerializerSizes.mjs
311
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/sumSerializerSizes.mjs
384
312
  function sumSerializerSizes(sizes) {
385
313
  return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
386
314
  }
387
315
 
388
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.2/node_modules/@metaplex-foundation/umi-serializers/dist/esm/utils.mjs
316
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/utils.mjs
389
317
  function getResolvedSize(size, childrenSizes, bytes2, offset) {
390
318
  if (typeof size === "number") {
391
319
  return [size, offset];
@@ -421,7 +349,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
421
349
  return typeof size === "object" ? size.serialize(realSize) : new Uint8Array();
422
350
  }
423
351
 
424
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.2/node_modules/@metaplex-foundation/umi-serializers/dist/esm/array.mjs
352
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/array.mjs
425
353
  function array(item, options = {}) {
426
354
  const size = options.size ?? u32();
427
355
  if (size === "remainder" && item.fixedSize === null) {
@@ -454,7 +382,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
454
382
  };
455
383
  }
456
384
 
457
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.2/node_modules/@metaplex-foundation/umi-serializers/dist/esm/bytes.mjs
385
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/bytes.mjs
458
386
  function bytes(options = {}) {
459
387
  const size = options.size ?? "variable";
460
388
  const description = options.description ?? `bytes(${getSizeDescription(size)})`;
@@ -501,7 +429,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
501
429
  };
502
430
  }
503
431
 
504
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.2/node_modules/@metaplex-foundation/umi-serializers/dist/esm/string.mjs
432
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/string.mjs
505
433
  function string(options = {}) {
506
434
  const size = options.size ?? u32();
507
435
  const encoding = options.encoding ?? utf8;
@@ -542,7 +470,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
542
470
  };
543
471
  }
544
472
 
545
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.2/node_modules/@metaplex-foundation/umi-serializers/dist/esm/struct.mjs
473
+ // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/struct.mjs
546
474
  function struct(fields, options = {}) {
547
475
  const fieldDescriptions = fields.map(([name, serializer]) => `${String(name)}: ${serializer.description}`).join(", ");
548
476
  return {
@@ -564,6 +492,178 @@ this.globalThis.solanaWeb3 = (function (exports) {
564
492
  }
565
493
  };
566
494
  }
495
+
496
+ // src/unsigned-transaction.ts
497
+ function getUnsignedTransaction(transaction) {
498
+ if ("signatures" in transaction) {
499
+ const {
500
+ signatures: _,
501
+ // eslint-disable-line @typescript-eslint/no-unused-vars
502
+ ...unsignedTransaction
503
+ } = transaction;
504
+ return unsignedTransaction;
505
+ } else {
506
+ return transaction;
507
+ }
508
+ }
509
+
510
+ // src/blockhash.ts
511
+ function assertIsBlockhash(putativeBlockhash) {
512
+ try {
513
+ if (
514
+ // Lowest value (32 bytes of zeroes)
515
+ putativeBlockhash.length < 32 || // Highest value (32 bytes of 255)
516
+ putativeBlockhash.length > 44
517
+ ) {
518
+ throw new Error("Expected input string to decode to a byte array of length 32.");
519
+ }
520
+ const bytes2 = base58.serialize(putativeBlockhash);
521
+ const numBytes = bytes2.byteLength;
522
+ if (numBytes !== 32) {
523
+ throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
524
+ }
525
+ } catch (e) {
526
+ throw new Error(`\`${putativeBlockhash}\` is not a blockhash`, {
527
+ cause: e
528
+ });
529
+ }
530
+ }
531
+ function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {
532
+ if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
533
+ return transaction;
534
+ }
535
+ const out = {
536
+ ...getUnsignedTransaction(transaction),
537
+ lifetimeConstraint: blockhashLifetimeConstraint
538
+ };
539
+ Object.freeze(out);
540
+ return out;
541
+ }
542
+
543
+ // src/create-transaction.ts
544
+ function createTransaction({
545
+ version
546
+ }) {
547
+ const out = {
548
+ instructions: [],
549
+ version
550
+ };
551
+ Object.freeze(out);
552
+ return out;
553
+ }
554
+
555
+ // ../instructions/dist/index.browser.js
556
+ var AccountRole = /* @__PURE__ */ ((AccountRole2) => {
557
+ AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */
558
+ 3] = "WRITABLE_SIGNER";
559
+ AccountRole2[AccountRole2["READONLY_SIGNER"] = /* 2 */
560
+ 2] = "READONLY_SIGNER";
561
+ AccountRole2[AccountRole2["WRITABLE"] = /* 1 */
562
+ 1] = "WRITABLE";
563
+ AccountRole2[AccountRole2["READONLY"] = /* 0 */
564
+ 0] = "READONLY";
565
+ return AccountRole2;
566
+ })(AccountRole || {});
567
+ var IS_WRITABLE_BITMASK = 1;
568
+ function isSignerRole(role) {
569
+ return role >= 2;
570
+ }
571
+ function isWritableRole(role) {
572
+ return (role & IS_WRITABLE_BITMASK) !== 0;
573
+ }
574
+ function mergeRoles(roleA, roleB) {
575
+ return roleA | roleB;
576
+ }
577
+
578
+ // src/durable-nonce.ts
579
+ var RECENT_BLOCKHASHES_SYSVAR_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111";
580
+ var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
581
+ function assertIsDurableNonceTransaction(transaction) {
582
+ if (!isDurableNonceTransaction(transaction)) {
583
+ throw new Error("Transaction is not a durable nonce transaction");
584
+ }
585
+ }
586
+ function createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress) {
587
+ return {
588
+ accounts: [
589
+ { address: nonceAccountAddress, role: AccountRole.WRITABLE },
590
+ {
591
+ address: RECENT_BLOCKHASHES_SYSVAR_ADDRESS,
592
+ role: AccountRole.READONLY
593
+ },
594
+ { address: nonceAuthorityAddress, role: AccountRole.READONLY_SIGNER }
595
+ ],
596
+ data: new Uint8Array([4, 0, 0, 0]),
597
+ programAddress: SYSTEM_PROGRAM_ADDRESS
598
+ };
599
+ }
600
+ function isAdvanceNonceAccountInstruction(instruction) {
601
+ return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
602
+ instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts
603
+ instruction.accounts?.length === 3 && // First account is nonce account address
604
+ instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole.WRITABLE && // Second account is recent blockhashes sysvar
605
+ instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole.READONLY && // Third account is nonce authority account
606
+ instruction.accounts[2].address != null && instruction.accounts[2].role === AccountRole.READONLY_SIGNER;
607
+ }
608
+ function isAdvanceNonceAccountInstructionData(data) {
609
+ return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
610
+ }
611
+ function isDurableNonceTransaction(transaction) {
612
+ return "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.nonce === "string" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]);
613
+ }
614
+ function setTransactionLifetimeUsingDurableNonce({
615
+ nonce,
616
+ nonceAccountAddress,
617
+ nonceAuthorityAddress
618
+ }, transaction) {
619
+ const isAlreadyDurableNonceTransaction = isDurableNonceTransaction(transaction);
620
+ if (isAlreadyDurableNonceTransaction && transaction.lifetimeConstraint.nonce === nonce && transaction.instructions[0].accounts[0].address === nonceAccountAddress && transaction.instructions[0].accounts[2].address === nonceAuthorityAddress) {
621
+ return transaction;
622
+ }
623
+ const out = {
624
+ ...getUnsignedTransaction(transaction),
625
+ instructions: [
626
+ createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
627
+ ...isAlreadyDurableNonceTransaction ? transaction.instructions.slice(1) : transaction.instructions
628
+ ],
629
+ lifetimeConstraint: {
630
+ nonce
631
+ }
632
+ };
633
+ Object.freeze(out);
634
+ return out;
635
+ }
636
+
637
+ // src/fee-payer.ts
638
+ function setTransactionFeePayer(feePayer, transaction) {
639
+ if ("feePayer" in transaction && feePayer === transaction.feePayer) {
640
+ return transaction;
641
+ }
642
+ const out = {
643
+ ...getUnsignedTransaction(transaction),
644
+ feePayer
645
+ };
646
+ Object.freeze(out);
647
+ return out;
648
+ }
649
+
650
+ // src/instructions.ts
651
+ function appendTransactionInstruction(instruction, transaction) {
652
+ const out = {
653
+ ...getUnsignedTransaction(transaction),
654
+ instructions: [...transaction.instructions, instruction]
655
+ };
656
+ Object.freeze(out);
657
+ return out;
658
+ }
659
+ function prependTransactionInstruction(instruction, transaction) {
660
+ const out = {
661
+ ...getUnsignedTransaction(transaction),
662
+ instructions: [instruction, ...transaction.instructions]
663
+ };
664
+ Object.freeze(out);
665
+ return out;
666
+ }
567
667
  function getBase58EncodedAddressCodec(config) {
568
668
  return string({
569
669
  description: config?.description ?? ("A 32-byte account address" ),
@@ -615,29 +715,6 @@ this.globalThis.solanaWeb3 = (function (exports) {
615
715
  return new Uint8Array(signedData);
616
716
  }
617
717
 
618
- // ../instructions/dist/index.browser.js
619
- var AccountRole = /* @__PURE__ */ ((AccountRole2) => {
620
- AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */
621
- 3] = "WRITABLE_SIGNER";
622
- AccountRole2[AccountRole2["READONLY_SIGNER"] = /* 2 */
623
- 2] = "READONLY_SIGNER";
624
- AccountRole2[AccountRole2["WRITABLE"] = /* 1 */
625
- 1] = "WRITABLE";
626
- AccountRole2[AccountRole2["READONLY"] = /* 0 */
627
- 0] = "READONLY";
628
- return AccountRole2;
629
- })(AccountRole || {});
630
- var IS_WRITABLE_BITMASK = 1;
631
- function isSignerRole(role) {
632
- return role >= 2;
633
- }
634
- function isWritableRole(role) {
635
- return (role & IS_WRITABLE_BITMASK) !== 0;
636
- }
637
- function mergeRoles(roleA, roleB) {
638
- return roleA | roleB;
639
- }
640
-
641
718
  // src/accounts.ts
642
719
  function upsert(addressMap, address, update) {
643
720
  addressMap[address] = update(addressMap[address] ?? { role: AccountRole.READONLY });
@@ -1175,10 +1252,68 @@ this.globalThis.solanaWeb3 = (function (exports) {
1175
1252
  return out;
1176
1253
  }
1177
1254
 
1255
+ // src/compile-transaction.ts
1256
+ function getCompiledTransaction(transaction) {
1257
+ const compiledMessage = compileMessage(transaction);
1258
+ let signatures;
1259
+ if ("signatures" in transaction) {
1260
+ signatures = [];
1261
+ for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
1262
+ signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
1263
+ }
1264
+ } else {
1265
+ signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
1266
+ }
1267
+ return {
1268
+ compiledMessage,
1269
+ signatures
1270
+ };
1271
+ }
1272
+
1273
+ // src/serializers/transaction.ts
1274
+ var BASE_CONFIG3 = {
1275
+ description: "The wire format of a Solana transaction" ,
1276
+ fixedSize: null,
1277
+ maxSize: null
1278
+ };
1279
+ function serialize3(transaction) {
1280
+ const compiledTransaction = getCompiledTransaction(transaction);
1281
+ return struct([
1282
+ [
1283
+ "signatures",
1284
+ array(bytes({ size: 64 }), {
1285
+ ...{ description: "A compact array of 64-byte, base-64 encoded Ed25519 signatures" } ,
1286
+ size: shortU16()
1287
+ })
1288
+ ],
1289
+ ["compiledMessage", getCompiledMessageEncoder()]
1290
+ ]).serialize(compiledTransaction);
1291
+ }
1292
+ function getTransactionEncoder() {
1293
+ return {
1294
+ ...BASE_CONFIG3,
1295
+ deserialize: getUnimplementedDecoder("CompiledMessage"),
1296
+ serialize: serialize3
1297
+ };
1298
+ }
1299
+
1300
+ // src/wire-transaction.ts
1301
+ function getBase64EncodedWireTransaction(transaction) {
1302
+ const wireTransactionBytes = getTransactionEncoder().serialize(transaction);
1303
+ {
1304
+ return btoa(String.fromCharCode(...wireTransactionBytes));
1305
+ }
1306
+ }
1307
+
1178
1308
  exports.appendTransactionInstruction = appendTransactionInstruction;
1309
+ exports.assertIsBlockhash = assertIsBlockhash;
1310
+ exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
1179
1311
  exports.createTransaction = createTransaction;
1312
+ exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
1180
1313
  exports.prependTransactionInstruction = prependTransactionInstruction;
1181
1314
  exports.setTransactionFeePayer = setTransactionFeePayer;
1315
+ exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
1316
+ exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
1182
1317
  exports.signTransaction = signTransaction;
1183
1318
 
1184
1319
  return exports;