Skip to content

Commit 47ef14d

Browse files
authored
Merge pull request #310 from JoseRFelix/jose/add-sign-arbitrary-to-okx
feat: Add `signArbitrary` to OKX and Missing Sign Methods To Wallet Clients
2 parents 6888c73 + 0657840 commit 47ef14d

File tree

6 files changed

+65
-21
lines changed

6 files changed

+65
-21
lines changed

wallets/cosmostation-extension/src/extension/client.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { chainRegistryChainToCosmostation } from '@chain-registry/cosmostation';
2-
import { StdSignDoc, StdSignature } from '@cosmjs/amino';
2+
import { StdSignature, StdSignDoc } from '@cosmjs/amino';
33
import { OfflineDirectSigner } from '@cosmjs/proto-signing';
44
import {
55
BroadcastMode,
@@ -36,14 +36,14 @@ export class CosmostationClient implements WalletClient {
3636
async suggestToken({ chainName, tokens, type }: SuggestToken) {
3737
if (type === 'cw20') {
3838
await this.cosmos.request({
39-
method: "cos_addTokensCW20",
39+
method: 'cos_addTokensCW20',
4040
params: {
4141
chainName,
42-
tokens
42+
tokens,
4343
},
4444
});
4545
}
46-
};
46+
}
4747

4848
async getSimpleAccount(chainId: string) {
4949
const { address, username } = await this.getAccount(chainId);
@@ -115,9 +115,8 @@ export class CosmostationClient implements WalletClient {
115115
chainInfo.assetList ? [chainInfo.assetList] : []
116116
);
117117
if (chainInfo.preferredEndpoints?.rest?.[0]) {
118-
(suggestChain.restURL as
119-
| string
120-
| ExtendedHttpEndpoint) = chainInfo.preferredEndpoints?.rest?.[0];
118+
(suggestChain.restURL as string | ExtendedHttpEndpoint) =
119+
chainInfo.preferredEndpoints?.rest?.[0];
121120
}
122121
const result = (await this.cosmos.request({
123122
method: 'cos_addChain',
@@ -185,14 +184,15 @@ export class CosmostationClient implements WalletClient {
185184
return await this.ikeplr.signArbitrary(chainId, signer, data);
186185
} catch (error) {
187186
// https://github.com/cosmostation/cosmostation-chrome-extension-client/blob/main/src/cosmos.ts#LL70C17-L70C28
188-
const message = typeof data === 'string' ? data : new TextDecoder('utf-8').decode(data)
187+
const message =
188+
typeof data === 'string' ? data : new TextDecoder('utf-8').decode(data);
189189
return await this.cosmos.request({
190190
method: 'cos_signMessage',
191191
params: {
192192
chainName: chainId,
193193
signer,
194-
message
195-
}
194+
message,
195+
},
196196
});
197197
}
198198
}

wallets/keplr-extension/src/extension/client.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ export class KeplrClient implements WalletClient {
4343

4444
async getAccount(chainId: string) {
4545
const key = await this.client.getKey(chainId);
46-
console.log('%cclient.ts line:45 key', 'color: #007acc;', key);
4746
return {
4847
username: key.name,
4948
address: key.bech32Address,

wallets/okxwallet-extension/src/extension/client.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { StdSignature, StdSignDoc } from '@cosmjs/amino';
12
import { Algo } from '@cosmjs/proto-signing';
2-
import { WalletClient } from '@cosmos-kit/core';
3+
import { DirectSignDoc, SignOptions, WalletClient } from '@cosmos-kit/core';
34

45
import { Okxwallet } from './types';
56

@@ -34,6 +35,32 @@ export class OkxwalletClient implements WalletClient {
3435
};
3536
}
3637

38+
async signAmino(
39+
chainId: string,
40+
signer: string,
41+
signDoc: StdSignDoc,
42+
signOptions?: SignOptions
43+
) {
44+
return await this.client.signAmino(chainId, signer, signDoc, signOptions);
45+
}
46+
47+
async signDirect(
48+
chainId: string,
49+
signer: string,
50+
signDoc: DirectSignDoc,
51+
signOptions?: SignOptions
52+
) {
53+
return await this.client.signDirect(chainId, signer, signDoc, signOptions);
54+
}
55+
56+
async signArbitrary(
57+
chainId: string,
58+
signer: string,
59+
data: string | Uint8Array
60+
): Promise<StdSignature> {
61+
return await this.client.signArbitrary(chainId, signer, data);
62+
}
63+
3764
getOfflineSigner(chainId: string) {
3865
return this.client.getOfflineSigner(chainId);
3966
}

wallets/okxwallet-extension/src/extension/types.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { AminoSignResponse, StdSignDoc } from '@cosmjs/amino';
1+
import { AminoSignResponse, StdSignature, StdSignDoc } from '@cosmjs/amino';
22
import { OfflineDirectSigner, OfflineSigner } from '@cosmjs/proto-signing';
33
import { DirectSignResponse } from '@cosmjs/proto-signing';
4+
import { SignOptions } from '@cosmos-kit/core';
45
import { BroadcastMode, Key, StdTx } from '@keplr-wallet/types';
56

67
export interface Okxwallet {
@@ -15,7 +16,8 @@ export interface Okxwallet {
1516
signAmino(
1617
chainId: string,
1718
signerAddress: string,
18-
signDoc: StdSignDoc
19+
signDoc: StdSignDoc,
20+
signOptions?: SignOptions
1921
): Promise<AminoSignResponse>;
2022
signDirect(
2123
chainId: string,
@@ -29,8 +31,14 @@ export interface Okxwallet {
2931
chainId?: string | null;
3032
/** SignDoc accountNumber */
3133
accountNumber?: Long | null;
32-
}
34+
},
35+
signOptions?: SignOptions
3336
): Promise<DirectSignResponse>;
37+
signArbitrary: (
38+
chainId: string,
39+
signer: string,
40+
data: string | Uint8Array
41+
) => Promise<StdSignature>;
3442
sendTx(
3543
chainId: string,
3644
tx: StdTx | Uint8Array,

wallets/station-extension/src/extension/client.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { WalletClient, WalletAccount } from '@cosmos-kit/core';
1+
import { AminoSignResponse, StdSignDoc } from '@cosmjs/amino';
2+
import { SignOptions, WalletAccount, WalletClient } from '@cosmos-kit/core';
23
import Station from '@terra-money/station-connector';
34

45
export class StationClient implements WalletClient {
@@ -13,7 +14,7 @@ export class StationClient implements WalletClient {
1314
}
1415

1516
async getSimpleAccount(chainId: string) {
16-
const { name, addresses } = await this.client?.connect();
17+
const { name, addresses } = await this.client.connect();
1718

1819
const address = addresses[chainId];
1920

@@ -31,15 +32,15 @@ export class StationClient implements WalletClient {
3132
}
3233

3334
async getAccount(chainId: string): Promise<WalletAccount> {
34-
const info = (await this.client?.info())[chainId];
35+
const info = (await this.client.info())[chainId];
3536
if (!info)
3637
throw new Error(
3738
`The requested chainID (${chainId}) is not available, try to switch network on the Station extension.`
3839
);
3940

40-
let { name, addresses, pubkey: pubkeys } = await this.client?.connect();
41+
let { name, addresses, pubkey: pubkeys } = await this.client.connect();
4142
if (!pubkeys) {
42-
pubkeys = (await this.client?.getPublicKey()).pubkey;
43+
pubkeys = (await this.client.getPublicKey()).pubkey;
4344
}
4445
const pubkey = pubkeys?.[info.coinType];
4546
const address = addresses[chainId];
@@ -58,6 +59,15 @@ export class StationClient implements WalletClient {
5859
};
5960
}
6061

62+
async signAmino(
63+
chainId: string,
64+
signer: string,
65+
signDoc: StdSignDoc,
66+
_signOptions?: SignOptions
67+
): Promise<AminoSignResponse> {
68+
return await this.client.keplr.signAmino(chainId, signer, signDoc);
69+
}
70+
6171
async getOfflineSigner(chainId: string) {
6272
return await this.client.getOfflineSigner(chainId);
6373
}

wallets/xdefi-extension/src/extension/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { StdSignDoc, StdSignature } from '@cosmjs/amino';
1+
import { StdSignature, StdSignDoc } from '@cosmjs/amino';
22
import { Algo, OfflineDirectSigner } from '@cosmjs/proto-signing';
33
import { BroadcastMode, SignType } from '@cosmos-kit/core';
44
import { DirectSignDoc, SignOptions, WalletClient } from '@cosmos-kit/core';

0 commit comments

Comments
 (0)