@dydxprotocol/v4-client-js 1.18.0 → 1.20.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.
@@ -3,7 +3,7 @@ import {
3
3
  AccountData,
4
4
  DirectSecp256k1HdWallet,
5
5
  EncodeObject,
6
- OfflineDirectSigner,
6
+ OfflineSigner,
7
7
  } from '@cosmjs/proto-signing';
8
8
  import { SigningStargateClient } from '@cosmjs/stargate';
9
9
  import Long from 'long';
@@ -22,9 +22,9 @@ export default class LocalWallet {
22
22
  address?: string;
23
23
  pubKey?: Secp256k1Pubkey;
24
24
  signer?: TransactionSigner;
25
- offlineSigner?: OfflineDirectSigner;
25
+ offlineSigner?: OfflineSigner;
26
26
 
27
- static async fromOfflineSigner(signer: OfflineDirectSigner): Promise<LocalWallet> {
27
+ static async fromOfflineSigner(signer: OfflineSigner): Promise<LocalWallet> {
28
28
  const wallet = new LocalWallet();
29
29
  await wallet.setSigner(signer);
30
30
  return wallet;
@@ -36,7 +36,7 @@ export default class LocalWallet {
36
36
  return wallet;
37
37
  }
38
38
 
39
- async setSigner(signer: OfflineDirectSigner): Promise<void> {
39
+ async setSigner(signer: OfflineSigner): Promise<void> {
40
40
  this.offlineSigner = signer;
41
41
  const stargateClient = await SigningStargateClient.offline(signer, {
42
42
  registry: generateRegistry(),
@@ -1,7 +1,14 @@
1
1
  import { Secp256k1Pubkey } from '@cosmjs/amino';
2
2
  import { fromBase64 } from '@cosmjs/encoding';
3
3
  import { Int53 } from '@cosmjs/math';
4
- import { EncodeObject, encodePubkey, makeAuthInfoBytes, makeSignDoc, OfflineDirectSigner } from '@cosmjs/proto-signing';
4
+ import {
5
+ EncodeObject,
6
+ encodePubkey,
7
+ isOfflineDirectSigner,
8
+ makeAuthInfoBytes,
9
+ makeSignDoc,
10
+ OfflineSigner,
11
+ } from '@cosmjs/proto-signing';
5
12
  import { SigningStargateClient, StdFee } from '@cosmjs/stargate';
6
13
  import { TxExtension } from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/accountplus/tx';
7
14
  import { TxBody, TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx';
@@ -22,12 +29,12 @@ protobuf.configure();
22
29
  export class TransactionSigner {
23
30
  readonly address: string;
24
31
  readonly stargateSigningClient: SigningStargateClient;
25
- readonly offlineSigner: OfflineDirectSigner;
32
+ readonly offlineSigner: OfflineSigner;
26
33
 
27
34
  constructor(
28
35
  address: string,
29
36
  stargateSigningClient: SigningStargateClient,
30
- offlineSigner: OfflineDirectSigner,
37
+ offlineSigner: OfflineSigner,
31
38
  ) {
32
39
  this.address = address;
33
40
  this.stargateSigningClient = stargateSigningClient;
@@ -105,14 +112,28 @@ export class TransactionSigner {
105
112
 
106
113
  // Use OfflineSigner to sign the transaction
107
114
  const signerAddress = this.address;
108
- const { signed, signature } = await this.offlineSigner.signDirect(signerAddress, signDoc);
109
-
110
- const txRaw = TxRaw.fromPartial({
111
- bodyBytes: signed.bodyBytes,
112
- authInfoBytes: signed.authInfoBytes,
113
- signatures: [fromBase64(signature.signature)],
114
- });
115
-
116
- return Uint8Array.from(TxRaw.encode(txRaw).finish());
115
+ if (isOfflineDirectSigner(this.offlineSigner)) {
116
+ const { signed, signature } = await this.offlineSigner.signDirect(signerAddress, signDoc);
117
+
118
+ const txRaw = TxRaw.fromPartial({
119
+ bodyBytes: signed.bodyBytes,
120
+ authInfoBytes: signed.authInfoBytes,
121
+ signatures: [fromBase64(signature.signature)],
122
+ });
123
+ return Uint8Array.from(TxRaw.encode(txRaw).finish());
124
+ } else {
125
+ const rawTx: TxRaw = await this.stargateSigningClient.sign(
126
+ this.address,
127
+ messages,
128
+ fee,
129
+ memo,
130
+ {
131
+ accountNumber: transactionOptions.accountNumber,
132
+ sequence: transactionOptions.sequence,
133
+ chainId: transactionOptions.chainId,
134
+ },
135
+ );
136
+ return Uint8Array.from(TxRaw.encode(rawTx).finish());
137
+ }
117
138
  }
118
139
  }