Browse Source

ts: Use Signer instead of Keypair (#296)

Armani Ferrante 4 years ago
parent
commit
364f957c9a
5 changed files with 15 additions and 16 deletions
  1. 1 1
      CHANGELOG.md
  2. 1 1
      ts/package.json
  3. 2 2
      ts/src/program/context.ts
  4. 4 4
      ts/src/program/namespace/account.ts
  5. 7 8
      ts/src/provider.ts

+ 1 - 1
CHANGELOG.md

@@ -18,7 +18,7 @@ incremented for features.
 
 ## Breaking Changes
 
-* ts: Replace deprecated `web3.Account` with `web3.Keypair` ([#274](https://github.com/project-serum/anchor/pull/274)).
+* ts: Replace deprecated `web3.Account` with `web3.Signer` in public APIs ([#296](https://github.com/project-serum/anchor/pull/296)).
 
 ## [0.5.0] - 2021-05-07
 

+ 1 - 1
ts/package.json

@@ -1,6 +1,6 @@
 {
   "name": "@project-serum/anchor",
-  "version": "0.6.0-beta.1",
+  "version": "0.6.0-beta.2",
   "description": "Anchor client",
   "main": "dist/cjs/index.js",
   "module": "dist/esm/index.js",

+ 2 - 2
ts/src/program/context.ts

@@ -1,6 +1,6 @@
 import {
   AccountMeta,
-  Keypair,
+  Signer,
   PublicKey,
   ConfirmOptions,
   TransactionInstruction,
@@ -25,7 +25,7 @@ export type Context = {
   /**
    * Accounts that must sign a given transaction.
    */
-  signers?: Array<Keypair>;
+  signers?: Array<Signer>;
 
   /**
    * Instructions to run *before* a given method. Often this is used, for

+ 4 - 4
ts/src/program/namespace/account.ts

@@ -2,7 +2,7 @@ import camelCase from "camelcase";
 import EventEmitter from "eventemitter3";
 import * as bs58 from "bs58";
 import {
-  Keypair,
+  Signer,
   PublicKey,
   SystemProgram,
   TransactionInstruction,
@@ -38,7 +38,7 @@ type AccountProps = {
   all: (filter?: Buffer) => Promise<ProgramAccount<any>[]>;
   subscribe: (address: PublicKey, commitment?: Commitment) => EventEmitter;
   unsubscribe: (address: PublicKey) => void;
-  createInstruction: (keypair: Keypair) => Promise<TransactionInstruction>;
+  createInstruction: (signer: Signer) => Promise<TransactionInstruction>;
   associated: (...args: PublicKey[]) => Promise<any>;
   associatedAddress: (...args: PublicKey[]) => Promise<PublicKey>;
 };
@@ -93,7 +93,7 @@ export default class AccountFactory {
       // Returns an instruction for creating this account.
       // @ts-ignore
       accountsNamespace["createInstruction"] = async (
-        keypair: Keypair,
+        signer: Signer,
         sizeOverride?: number
       ): Promise<TransactionInstruction> => {
         // @ts-ignore
@@ -101,7 +101,7 @@ export default class AccountFactory {
 
         return SystemProgram.createAccount({
           fromPubkey: provider.wallet.publicKey,
-          newAccountPubkey: keypair.publicKey,
+          newAccountPubkey: signer.publicKey,
           space: sizeOverride ?? size,
           lamports: await provider.connection.getMinimumBalanceForRentExemption(
             sizeOverride ?? size

+ 7 - 8
ts/src/provider.ts

@@ -1,6 +1,7 @@
 import {
   Connection,
   Keypair,
+  Signer,
   PublicKey,
   Transaction,
   TransactionSignature,
@@ -81,7 +82,7 @@ export default class Provider {
    */
   async send(
     tx: Transaction,
-    signers?: Array<Keypair | undefined>,
+    signers?: Array<Signer | undefined>,
     opts?: ConfirmOptions
   ): Promise<TransactionSignature> {
     if (signers === undefined) {
@@ -91,7 +92,7 @@ export default class Provider {
       opts = this.opts;
     }
 
-    const signerKps = signers.filter((s) => s !== undefined) as Array<Keypair>;
+    const signerKps = signers.filter((s) => s !== undefined) as Array<Signer>;
     const signerPubkeys = [this.wallet.publicKey].concat(
       signerKps.map((s) => s.publicKey)
     );
@@ -139,9 +140,7 @@ export default class Provider {
         signers = [];
       }
 
-      const signerKps = signers.filter(
-        (s) => s !== undefined
-      ) as Array<Keypair>;
+      const signerKps = signers.filter((s) => s !== undefined) as Array<Signer>;
       const signerPubkeys = [this.wallet.publicKey].concat(
         signerKps.map((s) => s.publicKey)
       );
@@ -180,7 +179,7 @@ export default class Provider {
    */
   async simulate(
     tx: Transaction,
-    signers?: Array<Keypair | undefined>,
+    signers?: Array<Signer | undefined>,
     opts?: ConfirmOptions
   ): Promise<RpcResponseAndContext<SimulatedTransactionResponse>> {
     if (signers === undefined) {
@@ -190,7 +189,7 @@ export default class Provider {
       opts = this.opts;
     }
 
-    const signerKps = signers.filter((s) => s !== undefined) as Array<Keypair>;
+    const signerKps = signers.filter((s) => s !== undefined) as Array<Signer>;
     const signerPubkeys = [this.wallet.publicKey].concat(
       signerKps.map((s) => s.publicKey)
     );
@@ -216,7 +215,7 @@ export default class Provider {
 
 export type SendTxRequest = {
   tx: Transaction;
-  signers: Array<Keypair | undefined>;
+  signers: Array<Signer | undefined>;
 };
 
 /**