@solana/web3.js 1.87.5 → 1.88.0

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.
package/README.md CHANGED
@@ -73,7 +73,7 @@ This library requires a JavaScript runtime that supports [`BigInt`](https://deve
73
73
 
74
74
  #### Unit tests
75
75
 
76
- To run the full suite of unit tests, excute the following in the root:
76
+ To run the full suite of unit tests, execute the following in the root:
77
77
 
78
78
  ```shell
79
79
  $ npm test
@@ -1152,6 +1152,8 @@ const VersionedMessage = {
1152
1152
  }
1153
1153
  };
1154
1154
 
1155
+ /** @internal */
1156
+
1155
1157
  /**
1156
1158
  * Transaction signature as base-58 encoded string
1157
1159
  */
@@ -1767,29 +1769,31 @@ class Transaction {
1767
1769
  *
1768
1770
  * @param {boolean} [requireAllSignatures=true] Require a fully signed Transaction
1769
1771
  */
1770
- verifySignatures(requireAllSignatures) {
1771
- return this._verifySignatures(this.serializeMessage(), requireAllSignatures === undefined ? true : requireAllSignatures);
1772
+ verifySignatures(requireAllSignatures = true) {
1773
+ const signatureErrors = this._getMessageSignednessErrors(this.serializeMessage(), requireAllSignatures);
1774
+ return !signatureErrors;
1772
1775
  }
1773
1776
 
1774
1777
  /**
1775
1778
  * @internal
1776
1779
  */
1777
- _verifySignatures(signData, requireAllSignatures) {
1780
+ _getMessageSignednessErrors(message, requireAllSignatures) {
1781
+ const errors = {};
1778
1782
  for (const {
1779
1783
  signature,
1780
1784
  publicKey
1781
1785
  } of this.signatures) {
1782
1786
  if (signature === null) {
1783
1787
  if (requireAllSignatures) {
1784
- return false;
1788
+ (errors.missing ||= []).push(publicKey);
1785
1789
  }
1786
1790
  } else {
1787
- if (!verify(signature, signData, publicKey.toBytes())) {
1788
- return false;
1791
+ if (!verify(signature, message, publicKey.toBytes())) {
1792
+ (errors.invalid ||= []).push(publicKey);
1789
1793
  }
1790
1794
  }
1791
1795
  }
1792
- return true;
1796
+ return errors.invalid || errors.missing ? errors : undefined;
1793
1797
  }
1794
1798
 
1795
1799
  /**
@@ -1808,8 +1812,18 @@ class Transaction {
1808
1812
  verifySignatures: true
1809
1813
  }, config);
1810
1814
  const signData = this.serializeMessage();
1811
- if (verifySignatures && !this._verifySignatures(signData, requireAllSignatures)) {
1812
- throw new Error('Signature verification failed');
1815
+ if (verifySignatures) {
1816
+ const sigErrors = this._getMessageSignednessErrors(signData, requireAllSignatures);
1817
+ if (sigErrors) {
1818
+ let errorMessage = 'Signature verification failed.';
1819
+ if (sigErrors.invalid) {
1820
+ errorMessage += `\nInvalid signature for public key${sigErrors.invalid.length === 1 ? '' : '(s)'} [\`${sigErrors.invalid.map(p => p.toBase58()).join('`, `')}\`].`;
1821
+ }
1822
+ if (sigErrors.missing) {
1823
+ errorMessage += `\nMissing signature for public key${sigErrors.missing.length === 1 ? '' : '(s)'} [\`${sigErrors.missing.map(p => p.toBase58()).join('`, `')}\`].`;
1824
+ }
1825
+ throw new Error(errorMessage);
1826
+ }
1813
1827
  }
1814
1828
  return this._serialize(signData);
1815
1829
  }
@@ -3563,7 +3577,7 @@ function makeWebsocketUrl(endpoint) {
3563
3577
  const startPort = portWithColon == null ? null : parseInt(portWithColon.slice(1), 10);
3564
3578
  const websocketPort =
3565
3579
  // Only shift the port by +1 as a convention for ws(s) only if given endpoint
3566
- // is explictly specifying the endpoint port (HTTP-based RPC), assuming
3580
+ // is explicitly specifying the endpoint port (HTTP-based RPC), assuming
3567
3581
  // we're directly trying to connect to solana-validator's ws listening port.
3568
3582
  // When the endpoint omits the port, we're connecting to the protocol
3569
3583
  // default ports: http(80) or https(443) and it's assumed we're behind a reverse
@@ -9279,7 +9293,7 @@ class StakeProgram {
9279
9293
  if (custodianPubkey) {
9280
9294
  keys.push({
9281
9295
  pubkey: custodianPubkey,
9282
- isSigner: false,
9296
+ isSigner: true,
9283
9297
  isWritable: false
9284
9298
  });
9285
9299
  }
@@ -9327,7 +9341,7 @@ class StakeProgram {
9327
9341
  if (custodianPubkey) {
9328
9342
  keys.push({
9329
9343
  pubkey: custodianPubkey,
9330
- isSigner: false,
9344
+ isSigner: true,
9331
9345
  isWritable: false
9332
9346
  });
9333
9347
  }
@@ -9492,7 +9506,7 @@ class StakeProgram {
9492
9506
  if (custodianPubkey) {
9493
9507
  keys.push({
9494
9508
  pubkey: custodianPubkey,
9495
- isSigner: false,
9509
+ isSigner: true,
9496
9510
  isWritable: false
9497
9511
  });
9498
9512
  }