@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.
- package/CHANGELOG.md +2 -2
- package/__tests__/clients/composite-client.test.ts +140 -0
- package/build/__tests__/clients/composite-client.test.d.ts +1 -0
- package/build/__tests__/clients/composite-client.test.js +130 -0
- package/build/examples/permissioned_keys_example.js +22 -8
- package/build/examples/websocket_orderbook_example.js +10 -12
- package/build/src/clients/composite-client.d.ts +2 -1
- package/build/src/clients/composite-client.js +38 -2
- package/build/src/clients/constants.d.ts +4 -0
- package/build/src/clients/constants.js +1 -1
- package/build/src/clients/modules/local-wallet.d.ts +4 -4
- package/build/src/clients/modules/local-wallet.js +1 -1
- package/build/src/clients/modules/signer.d.ts +3 -3
- package/build/src/clients/modules/signer.js +18 -8
- package/build/tsconfig.tsbuildinfo +1 -1
- package/examples/permissioned_keys_example.ts +38 -12
- package/examples/websocket_orderbook_example.ts +202 -215
- package/package.json +1 -1
- package/src/clients/composite-client.ts +60 -7
- package/src/clients/constants.ts +5 -0
- package/src/clients/modules/local-wallet.ts +4 -4
- package/src/clients/modules/signer.ts +33 -12
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
AccountData,
|
|
4
4
|
DirectSecp256k1HdWallet,
|
|
5
5
|
EncodeObject,
|
|
6
|
-
|
|
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?:
|
|
25
|
+
offlineSigner?: OfflineSigner;
|
|
26
26
|
|
|
27
|
-
static async fromOfflineSigner(signer:
|
|
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:
|
|
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 {
|
|
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:
|
|
32
|
+
readonly offlineSigner: OfflineSigner;
|
|
26
33
|
|
|
27
34
|
constructor(
|
|
28
35
|
address: string,
|
|
29
36
|
stargateSigningClient: SigningStargateClient,
|
|
30
|
-
offlineSigner:
|
|
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
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
}
|