@solana/transactions 2.0.0-experimental.da22638 → 2.0.0-experimental.dacecb7

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.
@@ -685,14 +685,14 @@ this.globalThis.solanaWeb3 = (function (exports) {
685
685
  throw new Error("No signing implementation could be found");
686
686
  }
687
687
  }
688
- function getBase58EncodedAddressCodec(config) {
688
+ function getAddressCodec(config) {
689
689
  return string({
690
690
  description: config?.description ?? ("A 32-byte account address" ),
691
691
  encoding: base58,
692
692
  size: 32
693
693
  });
694
694
  }
695
- function getBase58EncodedAddressComparator() {
695
+ function getAddressComparator() {
696
696
  return new Intl.Collator("en", {
697
697
  caseFirst: "lower",
698
698
  ignorePunctuation: false,
@@ -708,17 +708,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
708
708
  throw new Error("The `CryptoKey` must be an `Ed25519` public key");
709
709
  }
710
710
  const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
711
- const [base58EncodedAddress] = getBase58EncodedAddressCodec().deserialize(new Uint8Array(publicKeyBytes));
711
+ const [base58EncodedAddress] = getAddressCodec().deserialize(new Uint8Array(publicKeyBytes));
712
712
  return base58EncodedAddress;
713
713
  }
714
714
 
715
- // ../keys/dist/index.browser.js
716
- async function signBytes(key, data) {
717
- await assertSigningCapabilityIsAvailable();
718
- const signedData = await crypto.subtle.sign("Ed25519", key, data);
719
- return new Uint8Array(signedData);
720
- }
721
-
722
715
  // src/accounts.ts
723
716
  function upsert(addressMap, address, update) {
724
717
  addressMap[address] = update(addressMap[address] ?? { role: AccountRole.READONLY });
@@ -772,7 +765,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
772
765
  const shouldReplaceEntry = (
773
766
  // Consider using the new LOOKUP_TABLE if its address is different...
774
767
  entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
775
- (addressComparator || (addressComparator = getBase58EncodedAddressComparator()))(
768
+ (addressComparator || (addressComparator = getAddressComparator()))(
776
769
  accountMeta.lookupTableAddress,
777
770
  entry.lookupTableAddress
778
771
  ) < 0
@@ -878,7 +871,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
878
871
  if (leftIsWritable !== isWritableRole(rightEntry.role)) {
879
872
  return leftIsWritable ? -1 : 1;
880
873
  }
881
- addressComparator || (addressComparator = getBase58EncodedAddressComparator());
874
+ addressComparator || (addressComparator = getAddressComparator());
882
875
  if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
883
876
  return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
884
877
  } else {
@@ -909,7 +902,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
909
902
  entry.readableIndices.push(account.addressIndex);
910
903
  }
911
904
  }
912
- return Object.keys(index).sort(getBase58EncodedAddressComparator()).map((lookupTableAddress) => ({
905
+ return Object.keys(index).sort(getAddressComparator()).map((lookupTableAddress) => ({
913
906
  lookupTableAddress,
914
907
  ...index[lookupTableAddress]
915
908
  }));
@@ -989,13 +982,31 @@ this.globalThis.solanaWeb3 = (function (exports) {
989
982
  };
990
983
  }
991
984
 
985
+ // src/compile-transaction.ts
986
+ function getCompiledTransaction(transaction) {
987
+ const compiledMessage = compileMessage(transaction);
988
+ let signatures;
989
+ if ("signatures" in transaction) {
990
+ signatures = [];
991
+ for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
992
+ signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
993
+ }
994
+ } else {
995
+ signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
996
+ }
997
+ return {
998
+ compiledMessage,
999
+ signatures
1000
+ };
1001
+ }
1002
+
992
1003
  // src/serializers/address-table-lookup.ts
993
1004
  function getAddressTableLookupCodec() {
994
1005
  return struct(
995
1006
  [
996
1007
  [
997
1008
  "lookupTableAddress",
998
- getBase58EncodedAddressCodec(
1009
+ getAddressCodec(
999
1010
  {
1000
1011
  description: "The address of the address lookup table account from which instruction addresses should be looked up"
1001
1012
  }
@@ -1196,7 +1207,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
1196
1207
  ["header", getMessageHeaderCodec()],
1197
1208
  [
1198
1209
  "staticAccounts",
1199
- array(getBase58EncodedAddressCodec(), {
1210
+ array(getAddressCodec(), {
1200
1211
  description: "A compact-array of static account addresses belonging to this transaction" ,
1201
1212
  size: shortU16()
1202
1213
  })
@@ -1232,12 +1243,90 @@ this.globalThis.solanaWeb3 = (function (exports) {
1232
1243
  };
1233
1244
  }
1234
1245
 
1246
+ // src/serializers/transaction.ts
1247
+ var BASE_CONFIG3 = {
1248
+ description: "The wire format of a Solana transaction" ,
1249
+ fixedSize: null,
1250
+ maxSize: null
1251
+ };
1252
+ function serialize3(transaction) {
1253
+ const compiledTransaction = getCompiledTransaction(transaction);
1254
+ return struct([
1255
+ [
1256
+ "signatures",
1257
+ array(bytes({ size: 64 }), {
1258
+ ...{ description: "A compact array of 64-byte, base-64 encoded Ed25519 signatures" } ,
1259
+ size: shortU16()
1260
+ })
1261
+ ],
1262
+ ["compiledMessage", getCompiledMessageEncoder()]
1263
+ ]).serialize(compiledTransaction);
1264
+ }
1265
+ function getTransactionEncoder() {
1266
+ return {
1267
+ ...BASE_CONFIG3,
1268
+ deserialize: getUnimplementedDecoder("CompiledMessage"),
1269
+ serialize: serialize3
1270
+ };
1271
+ }
1272
+
1273
+ // ../keys/dist/index.browser.js
1274
+ async function signBytes(key, data) {
1275
+ await assertSigningCapabilityIsAvailable();
1276
+ const signedData = await crypto.subtle.sign("Ed25519", key, data);
1277
+ return new Uint8Array(signedData);
1278
+ }
1279
+
1235
1280
  // src/signatures.ts
1281
+ function assertIsTransactionSignature(putativeTransactionSignature) {
1282
+ try {
1283
+ if (
1284
+ // Lowest value (64 bytes of zeroes)
1285
+ putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
1286
+ putativeTransactionSignature.length > 88
1287
+ ) {
1288
+ throw new Error("Expected input string to decode to a byte array of length 64.");
1289
+ }
1290
+ const bytes2 = base58.serialize(putativeTransactionSignature);
1291
+ const numBytes = bytes2.byteLength;
1292
+ if (numBytes !== 64) {
1293
+ throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
1294
+ }
1295
+ } catch (e) {
1296
+ throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
1297
+ cause: e
1298
+ });
1299
+ }
1300
+ }
1301
+ function isTransactionSignature(putativeTransactionSignature) {
1302
+ if (
1303
+ // Lowest value (64 bytes of zeroes)
1304
+ putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
1305
+ putativeTransactionSignature.length > 88
1306
+ ) {
1307
+ return false;
1308
+ }
1309
+ const bytes2 = base58.serialize(putativeTransactionSignature);
1310
+ const numBytes = bytes2.byteLength;
1311
+ if (numBytes !== 64) {
1312
+ return false;
1313
+ }
1314
+ return true;
1315
+ }
1236
1316
  async function getCompiledMessageSignature(message, secretKey) {
1237
1317
  const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
1238
1318
  const signature = await signBytes(secretKey, wireMessageBytes);
1239
1319
  return signature;
1240
1320
  }
1321
+ function getSignatureFromTransaction(transaction) {
1322
+ const signature = transaction.signatures[transaction.feePayer];
1323
+ if (!signature) {
1324
+ throw new Error(
1325
+ "Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
1326
+ );
1327
+ }
1328
+ return signature;
1329
+ }
1241
1330
  async function signTransaction(keyPairs, transaction) {
1242
1331
  const compiledMessage = compileMessage(transaction);
1243
1332
  const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
@@ -1259,50 +1348,9 @@ this.globalThis.solanaWeb3 = (function (exports) {
1259
1348
  Object.freeze(out);
1260
1349
  return out;
1261
1350
  }
1262
-
1263
- // src/compile-transaction.ts
1264
- function getCompiledTransaction(transaction) {
1265
- const compiledMessage = compileMessage(transaction);
1266
- let signatures;
1267
- if ("signatures" in transaction) {
1268
- signatures = [];
1269
- for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
1270
- signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
1271
- }
1272
- } else {
1273
- signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
1274
- }
1275
- return {
1276
- compiledMessage,
1277
- signatures
1278
- };
1279
- }
1280
-
1281
- // src/serializers/transaction.ts
1282
- var BASE_CONFIG3 = {
1283
- description: "The wire format of a Solana transaction" ,
1284
- fixedSize: null,
1285
- maxSize: null
1286
- };
1287
- function serialize3(transaction) {
1288
- const compiledTransaction = getCompiledTransaction(transaction);
1289
- return struct([
1290
- [
1291
- "signatures",
1292
- array(bytes({ size: 64 }), {
1293
- ...{ description: "A compact array of 64-byte, base-64 encoded Ed25519 signatures" } ,
1294
- size: shortU16()
1295
- })
1296
- ],
1297
- ["compiledMessage", getCompiledMessageEncoder()]
1298
- ]).serialize(compiledTransaction);
1299
- }
1300
- function getTransactionEncoder() {
1301
- return {
1302
- ...BASE_CONFIG3,
1303
- deserialize: getUnimplementedDecoder("CompiledMessage"),
1304
- serialize: serialize3
1305
- };
1351
+ function transactionSignature(putativeTransactionSignature) {
1352
+ assertIsTransactionSignature(putativeTransactionSignature);
1353
+ return putativeTransactionSignature;
1306
1354
  }
1307
1355
 
1308
1356
  // src/wire-transaction.ts
@@ -1316,13 +1364,18 @@ this.globalThis.solanaWeb3 = (function (exports) {
1316
1364
  exports.appendTransactionInstruction = appendTransactionInstruction;
1317
1365
  exports.assertIsBlockhash = assertIsBlockhash;
1318
1366
  exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
1367
+ exports.assertIsTransactionSignature = assertIsTransactionSignature;
1319
1368
  exports.createTransaction = createTransaction;
1320
1369
  exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
1370
+ exports.getSignatureFromTransaction = getSignatureFromTransaction;
1371
+ exports.getTransactionEncoder = getTransactionEncoder;
1372
+ exports.isTransactionSignature = isTransactionSignature;
1321
1373
  exports.prependTransactionInstruction = prependTransactionInstruction;
1322
1374
  exports.setTransactionFeePayer = setTransactionFeePayer;
1323
1375
  exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
1324
1376
  exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
1325
1377
  exports.signTransaction = signTransaction;
1378
+ exports.transactionSignature = transactionSignature;
1326
1379
 
1327
1380
  return exports;
1328
1381